@dbml/parse 5.6.0-alpha.0 → 5.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dbml-parse.js +9 -28
- package/dist/dbml-parse.mjs +3021 -6308
- package/package.json +2 -2
package/dist/dbml-parse.js
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),n=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&&e(r,Symbol.toStringTag,{value:`Module`}),r},r=typeof global==`object`&&global&&global.Object===Object&&global,i=r,a=typeof self==`object`&&self&&self.Object===Object&&self,o=i||a||Function(`return this`)(),s=o,c=s.Symbol,l=c,u=Object.prototype,d=u.hasOwnProperty,f=u.toString,p=l?l.toStringTag:void 0;function m(e){var t=d.call(e,p),n=e[p];try{e[p]=void 0;var r=!0}catch{}var i=f.call(e);return r&&(t?e[p]=n:delete e[p]),i}var h=m,g=Object.prototype.toString;function _(e){return g.call(e)}var v=_,y=`[object Null]`,ee=`[object Undefined]`,te=l?l.toStringTag:void 0;function ne(e){return e==null?e===void 0?ee:y:te&&te in Object(e)?h(e):v(e)}var b=ne;function re(e){return typeof e==`object`&&!!e}var ie=re,ae=`[object Symbol]`;function oe(e){return typeof e==`symbol`||ie(e)&&b(e)==ae}var se=oe;function ce(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=ce,ue=Array.isArray,de=ue,fe=1/0,pe=l?l.prototype:void 0,me=pe?pe.toString:void 0;function he(e){if(typeof e==`string`)return e;if(de(e))return le(e,he)+``;if(se(e))return me?me.call(e):``;var t=e+``;return t==`0`&&1/e==-fe?`-0`:t}var ge=he,_e=/\s/;function ve(e){for(var t=e.length;t--&&_e.test(e.charAt(t)););return t}var ye=ve,be=/^\s+/;function xe(e){return e&&e.slice(0,ye(e)+1).replace(be,``)}var Se=xe;function Ce(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var we=Ce,Te=NaN,Ee=/^[-+]0x[0-9a-f]+$/i,De=/^0b[01]+$/i,Oe=/^0o[0-7]+$/i,ke=parseInt;function Ae(e){if(typeof e==`number`)return e;if(se(e))return Te;if(we(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=we(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Se(e);var n=De.test(e);return n||Oe.test(e)?ke(e.slice(2),n?2:8):Ee.test(e)?Te:+e}var je=Ae,Me=1/0,Ne=17976931348623157e292;function Pe(e){return e?(e=je(e),e===Me||e===-Me?(e<0?-1:1)*Ne:e===e?e:0):e===0?e:0}var Fe=Pe;function Ie(e){var t=Fe(e),n=t%1;return t===t?n?t-n:t:0}var Le=Ie;function Re(e){return e}var ze=Re,Be=`[object AsyncFunction]`,Ve=`[object Function]`,He=`[object GeneratorFunction]`,Ue=`[object Proxy]`;function We(e){if(!we(e))return!1;var t=b(e);return t==Ve||t==He||t==Be||t==Ue}var Ge=We,Ke=s[`__core-js_shared__`],qe=Ke,Je=function(){var e=/[^.]+$/.exec(qe&&qe.keys&&qe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Ye(e){return!!Je&&Je in e}var Xe=Ye,Ze=Function.prototype.toString;function Qe(e){if(e!=null){try{return Ze.call(e)}catch{}try{return e+``}catch{}}return``}var $e=Qe,et=/[\\^$.*+?()[\]{}|]/g,tt=/^\[object .+?Constructor\]$/,nt=Function.prototype,rt=Object.prototype,it=nt.toString,at=rt.hasOwnProperty,ot=RegExp(`^`+it.call(at).replace(et,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function st(e){return!we(e)||Xe(e)?!1:(Ge(e)?ot:tt).test($e(e))}var ct=st;function lt(e,t){return e?.[t]}var ut=lt;function dt(e,t){var n=ut(e,t);return ct(n)?n:void 0}var ft=dt,pt=ft(s,`WeakMap`),mt=pt;function ht(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=ht,_t=800,vt=16,yt=Date.now;function bt(e){var t=0,n=0;return function(){var r=yt(),i=vt-(r-n);if(n=r,i>0){if(++t>=_t)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var xt=bt;function St(e){return function(){return e}}var Ct=St,wt=function(){try{var e=ft(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Tt=wt,Et=Tt?function(e,t){return Tt(e,`toString`,{configurable:!0,enumerable:!1,value:Ct(t),writable:!0})}:ze,Dt=Et,Ot=xt(Dt),kt=Ot;function At(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 jt=At,Mt=9007199254740991,Nt=/^(?:0|[1-9]\d*)$/;function Pt(e,t){var n=typeof e;return t??=Mt,!!t&&(n==`number`||n!=`symbol`&&Nt.test(e))&&e>-1&&e%1==0&&e<t}var x=Pt;function Ft(e,t){return e===t||e!==e&&t!==t}var It=Ft,Lt=Math.max;function Rt(e,t,n){return t=Lt(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=Lt(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 zt=Rt;function Bt(e,t){return kt(zt(e,t,ze),e+``)}var Vt=Bt,Ht=9007199254740991;function S(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=Ht}var Ut=S;function Wt(e){return e!=null&&Ut(e.length)&&!Ge(e)}var Gt=Wt,Kt=Object.prototype;function qt(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||Kt)}var Jt=qt;function Yt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var Xt=Yt,Zt=`[object Arguments]`;function Qt(e){return ie(e)&&b(e)==Zt}var $t=Qt,en=Object.prototype,tn=en.hasOwnProperty,nn=en.propertyIsEnumerable,rn=$t(function(){return arguments}())?$t:function(e){return ie(e)&&tn.call(e,`callee`)&&!nn.call(e,`callee`)},an=rn;function on(){return!1}var sn=on,cn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,ln=cn&&typeof module==`object`&&module&&!module.nodeType&&module,un=ln&&ln.exports===cn?s.Buffer:void 0,dn=(un?un.isBuffer:void 0)||sn,fn=dn,pn=`[object Arguments]`,mn=`[object Array]`,hn=`[object Boolean]`,gn=`[object Date]`,_n=`[object Error]`,vn=`[object Function]`,yn=`[object Map]`,bn=`[object Number]`,xn=`[object Object]`,Sn=`[object RegExp]`,C=`[object Set]`,w=`[object String]`,Cn=`[object WeakMap]`,wn=`[object ArrayBuffer]`,Tn=`[object DataView]`,En=`[object Float32Array]`,Dn=`[object Float64Array]`,On=`[object Int8Array]`,kn=`[object Int16Array]`,An=`[object Int32Array]`,jn=`[object Uint8Array]`,Mn=`[object Uint8ClampedArray]`,Nn=`[object Uint16Array]`,Pn=`[object Uint32Array]`,T={};T[En]=T[Dn]=T[On]=T[kn]=T[An]=T[jn]=T[Mn]=T[Nn]=T[Pn]=!0,T[pn]=T[mn]=T[wn]=T[hn]=T[Tn]=T[gn]=T[_n]=T[vn]=T[yn]=T[bn]=T[xn]=T[Sn]=T[C]=T[w]=T[Cn]=!1;function Fn(e){return ie(e)&&Ut(e.length)&&!!T[b(e)]}var In=Fn;function Ln(e){return function(t){return e(t)}}var Rn=Ln,zn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Bn=zn&&typeof module==`object`&&module&&!module.nodeType&&module,Vn=Bn&&Bn.exports===zn&&i.process,Hn=function(){try{return Bn&&Bn.require&&Bn.require(`util`).types||Vn&&Vn.binding&&Vn.binding(`util`)}catch{}}(),Un=Hn,Wn=Un&&Un.isTypedArray,Gn=Wn?Rn(Wn):In,Kn=Gn,qn=Object.prototype.hasOwnProperty;function Jn(e,t){var n=de(e),r=!n&&an(e),i=!n&&!r&&fn(e),a=!n&&!r&&!i&&Kn(e),o=n||r||i||a,s=o?Xt(e.length,String):[],c=s.length;for(var l in e)(t||qn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||x(l,c)))&&s.push(l);return s}var Yn=Jn;function E(e,t){return function(n){return e(t(n))}}var Xn=E,Zn=Xn(Object.keys,Object),Qn=Zn,$n=Object.prototype.hasOwnProperty;function er(e){if(!Jt(e))return Qn(e);var t=[];for(var n in Object(e))$n.call(e,n)&&n!=`constructor`&&t.push(n);return t}var tr=er;function nr(e){return Gt(e)?Yn(e):tr(e)}var rr=nr;function ir(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var ar=ir,or=Object.prototype.hasOwnProperty;function sr(e){if(!we(e))return ar(e);var t=Jt(e),n=[];for(var r in e)r==`constructor`&&(t||!or.call(e,r))||n.push(r);return n}var cr=sr;function lr(e){return Gt(e)?Yn(e,!0):cr(e)}var ur=lr,dr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,fr=/^\w*$/;function pr(e,t){if(de(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||se(e)?!0:fr.test(e)||!dr.test(e)||t!=null&&e in Object(t)}var mr=pr,hr=ft(Object,`create`),gr=hr;function _r(){this.__data__=gr?gr(null):{},this.size=0}var vr=_r;function yr(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var br=yr,xr=`__lodash_hash_undefined__`,Sr=Object.prototype.hasOwnProperty;function Cr(e){var t=this.__data__;if(gr){var n=t[e];return n===xr?void 0:n}return Sr.call(t,e)?t[e]:void 0}var wr=Cr,Tr=Object.prototype.hasOwnProperty;function Er(e){var t=this.__data__;return gr?t[e]!==void 0:Tr.call(t,e)}var Dr=Er,Or=`__lodash_hash_undefined__`;function kr(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=gr&&t===void 0?Or:t,this}var Ar=kr;function jr(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])}}jr.prototype.clear=vr,jr.prototype.delete=br,jr.prototype.get=wr,jr.prototype.has=Dr,jr.prototype.set=Ar;var Mr=jr;function Nr(){this.__data__=[],this.size=0}var Pr=Nr;function Fr(e,t){for(var n=e.length;n--;)if(It(e[n][0],t))return n;return-1}var Ir=Fr,Lr=Array.prototype.splice;function Rr(e){var t=this.__data__,n=Ir(t,e);return n<0?!1:(n==t.length-1?t.pop():Lr.call(t,n,1),--this.size,!0)}var zr=Rr;function Br(e){var t=this.__data__,n=Ir(t,e);return n<0?void 0:t[n][1]}var Vr=Br;function Hr(e){return Ir(this.__data__,e)>-1}var Ur=Hr;function Wr(e,t){var n=this.__data__,r=Ir(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var Gr=Wr;function Kr(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])}}Kr.prototype.clear=Pr,Kr.prototype.delete=zr,Kr.prototype.get=Vr,Kr.prototype.has=Ur,Kr.prototype.set=Gr;var qr=Kr,Jr=ft(s,`Map`),Yr=Jr;function D(){this.size=0,this.__data__={hash:new Mr,map:new(Yr||qr),string:new Mr}}var Xr=D;function Zr(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var Qr=Zr;function O(e,t){var n=e.__data__;return Qr(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var $r=O;function ei(e){var t=$r(this,e).delete(e);return this.size-=t?1:0,t}var ti=ei;function ni(e){return $r(this,e).get(e)}var ri=ni;function ii(e){return $r(this,e).has(e)}var ai=ii;function oi(e,t){var n=$r(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var si=oi;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=Xr,ci.prototype.delete=ti,ci.prototype.get=ri,ci.prototype.has=ai,ci.prototype.set=si;var li=ci,ui=`Expected a function`;function di(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(ui);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(di.Cache||li),n}di.Cache=li;var fi=di,pi=500;function mi(e){var t=fi(e,function(e){return n.size===pi&&n.clear(),e}),n=t.cache;return t}var hi=mi,gi=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,_i=/\\(\\)?/g,vi=hi(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(gi,function(e,n,r,i){t.push(r?i.replace(_i,`$1`):n||e)}),t}),yi=vi;function bi(e){return e==null?``:ge(e)}var xi=bi;function Si(e,t){return de(e)?e:mr(e,t)?[e]:yi(xi(e))}var Ci=Si,wi=1/0;function Ti(e){if(typeof e==`string`||se(e))return e;var t=e+``;return t==`0`&&1/e==-wi?`-0`:t}var Ei=Ti;function Di(e,t){t=Ci(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[Ei(t[n++])];return n&&n==r?e:void 0}var Oi=Di;function ki(e,t,n){var r=e==null?void 0:Oi(e,t);return r===void 0?n:r}var Ai=ki;function ji(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var Mi=ji,Ni=l?l.isConcatSpreadable:void 0;function Pi(e){return de(e)||an(e)||!!(Ni&&e&&e[Ni])}var Fi=Pi;function Ii(e,t,n,r,i){var a=-1,o=e.length;for(n||=Fi,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?Ii(s,t-1,n,r,i):Mi(i,s):r||(i[i.length]=s)}return i}var Li=Ii;function Ri(e){return e!=null&&e.length?Li(e,1):[]}var zi=Ri;function Bi(){this.__data__=new qr,this.size=0}var Vi=Bi;function Hi(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var Ui=Hi;function Wi(e){return this.__data__.get(e)}var Gi=Wi;function Ki(e){return this.__data__.has(e)}var qi=Ki,Ji=200;function Yi(e,t){var n=this.__data__;if(n instanceof qr){var r=n.__data__;if(!Yr||r.length<Ji-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new li(r)}return n.set(e,t),this.size=n.size,this}var Xi=Yi;function Zi(e){this.size=(this.__data__=new qr(e)).size}Zi.prototype.clear=Vi,Zi.prototype.delete=Ui,Zi.prototype.get=Gi,Zi.prototype.has=qi,Zi.prototype.set=Xi;var Qi=Zi;function $i(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 ea=$i;function ta(){return[]}var na=ta,ra=Object.prototype.propertyIsEnumerable,ia=Object.getOwnPropertySymbols,aa=ia?function(e){return e==null?[]:(e=Object(e),ea(ia(e),function(t){return ra.call(e,t)}))}:na,oa=aa;function sa(e,t,n){var r=t(e);return de(e)?r:Mi(r,n(e))}var ca=sa;function la(e){return ca(e,rr,oa)}var ua=la,da=ft(s,`DataView`),fa=da,pa=ft(s,`Promise`),ma=pa,ha=ft(s,`Set`),ga=ha,_a=`[object Map]`,va=`[object Object]`,ya=`[object Promise]`,ba=`[object Set]`,xa=`[object WeakMap]`,Sa=`[object DataView]`,Ca=$e(fa),wa=$e(Yr),Ta=$e(ma),Ea=$e(ga),Da=$e(mt),Oa=b;(fa&&Oa(new fa(new ArrayBuffer(1)))!=Sa||Yr&&Oa(new Yr)!=_a||ma&&Oa(ma.resolve())!=ya||ga&&Oa(new ga)!=ba||mt&&Oa(new mt)!=xa)&&(Oa=function(e){var t=b(e),n=t==va?e.constructor:void 0,r=n?$e(n):``;if(r)switch(r){case Ca:return Sa;case wa:return _a;case Ta:return ya;case Ea:return ba;case Da:return xa}return t});var ka=Oa,Aa=s.Uint8Array,ja=Aa,Ma=`__lodash_hash_undefined__`;function Na(e){return this.__data__.set(e,Ma),this}var Pa=Na;function Fa(e){return this.__data__.has(e)}var Ia=Fa;function La(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new li;++t<n;)this.add(e[t])}La.prototype.add=La.prototype.push=Pa,La.prototype.has=Ia;var Ra=La;function za(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 Ba=za;function Va(e,t){return e.has(t)}var Ha=Va,Ua=1,Wa=2;function k(e,t,n,r,i,a){var o=n&Ua,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&Wa?new Ra:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var g=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(g!==void 0){if(g)continue;f=!1;break}if(p){if(!Ba(t,function(e,t){if(!Ha(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 Ga=k;function Ka(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var qa=Ka;function Ja(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var Ya=Ja,Xa=1,Za=2,Qa=`[object Boolean]`,$a=`[object Date]`,eo=`[object Error]`,to=`[object Map]`,no=`[object Number]`,ro=`[object RegExp]`,io=`[object Set]`,ao=`[object String]`,oo=`[object Symbol]`,so=`[object ArrayBuffer]`,co=`[object DataView]`,lo=l?l.prototype:void 0,uo=lo?lo.valueOf:void 0;function fo(e,t,n,r,i,a,o){switch(n){case co:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case so:return!(e.byteLength!=t.byteLength||!a(new ja(e),new ja(t)));case Qa:case $a:case no:return It(+e,+t);case eo:return e.name==t.name&&e.message==t.message;case ro:case ao:return e==t+``;case to:var s=qa;case io:var c=r&Xa;if(s||=Ya,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Za,o.set(e,t);var u=Ga(s(e),s(t),r,i,a,o);return o.delete(e),u;case oo:if(uo)return uo.call(e)==uo.call(t)}return!1}var po=fo,mo=1,ho=Object.prototype.hasOwnProperty;function go(e,t,n,r,i,a){var o=n&mo,s=ua(e),c=s.length;if(c!=ua(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:ho.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var h=e[u],g=t[u];if(r)var _=o?r(g,h,u,t,e,a):r(h,g,u,e,t,a);if(!(_===void 0?h===g||i(h,g,n,r,a):_)){p=!1;break}m||=u==`constructor`}if(p&&!m){var v=e.constructor,y=t.constructor;v!=y&&`constructor`in e&&`constructor`in t&&!(typeof v==`function`&&v instanceof v&&typeof y==`function`&&y instanceof y)&&(p=!1)}return a.delete(e),a.delete(t),p}var _o=go,vo=1,yo=`[object Arguments]`,bo=`[object Array]`,xo=`[object Object]`,So=Object.prototype.hasOwnProperty;function Co(e,t,n,r,i,a){var o=de(e),s=de(t),c=o?bo:ka(e),l=s?bo:ka(t);c=c==yo?xo:c,l=l==yo?xo:l;var u=c==xo,d=l==xo,f=c==l;if(f&&fn(e)){if(!fn(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Qi,o||Kn(e)?Ga(e,t,n,r,i,a):po(e,t,c,n,r,i,a);if(!(n&vo)){var p=u&&So.call(e,`__wrapped__`),m=d&&So.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,g=m?t.value():t;return a||=new Qi,i(h,g,n,r,a)}}return f?(a||=new Qi,_o(e,t,n,r,i,a)):!1}var wo=Co;function To(e,t,n,r,i){return e===t?!0:e==null||t==null||!ie(e)&&!ie(t)?e!==e&&t!==t:wo(e,t,n,r,To,i)}var Eo=To,Do=1,Oo=2;function ko(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 Qi;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Eo(u,l,Do|Oo,r,d):f))return!1}}return!0}var Ao=ko;function jo(e){return e===e&&!we(e)}var Mo=jo;function No(e){for(var t=rr(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Mo(i)]}return t}var Po=No;function Fo(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var Io=Fo;function Lo(e){var t=Po(e);return t.length==1&&t[0][2]?Io(t[0][0],t[0][1]):function(n){return n===e||Ao(n,e,t)}}var Ro=Lo;function zo(e,t){return e!=null&&t in Object(e)}var Bo=zo;function Vo(e,t,n){t=Ci(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=Ei(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&&Ut(i)&&x(o,i)&&(de(e)||an(e)))}var Ho=Vo;function Uo(e,t){return e!=null&&Ho(e,t,Bo)}var Wo=Uo,Go=1,Ko=2;function qo(e,t){return mr(e)&&Mo(t)?Io(Ei(e),t):function(n){var r=Ai(n,e);return r===void 0&&r===t?Wo(n,e):Eo(t,r,Go|Ko)}}var Jo=qo;function Yo(e){return function(t){return t?.[e]}}var Xo=Yo;function Zo(e){return function(t){return Oi(t,e)}}var Qo=Zo;function $o(e){return mr(e)?Xo(Ei(e)):Qo(e)}var es=$o;function ts(e){return typeof e==`function`?e:e==null?ze:typeof e==`object`?de(e)?Jo(e[0],e[1]):Ro(e):es(e)}var ns=ts;function rs(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 is=rs;function as(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 os=as,ss=os(),cs=ss;function ls(e,t){return e&&cs(e,t,rr)}var us=ls;function ds(e,t){return function(n,r){if(n==null)return n;if(!Gt(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 fs=ds,ps=fs(us),A=ps;function ms(e,t,n,r){return A(e,function(e,i,a){t(r,e,n(e),a)}),r}var hs=ms;function gs(e,t){return function(n,r){var i=de(n)?is:hs,a=t?t():{};return i(n,e,ns(r,2),a)}}var _s=gs;function vs(e){return ie(e)&&Gt(e)}var ys=vs;function bs(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var xs=bs;function Ss(e){return typeof e==`function`?e:ze}var Cs=Ss,ws=Math.max,Ts=Math.min;function Es(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Le(n),i=n<0?ws(r+i,0):Ts(i,r-1)),jt(e,ns(t,3),i,!0)}var Ds=Es;function Os(e){return e&&e.length?e[0]:void 0}var ks=Os;function As(e,t){return e==null?e:cs(e,Cs(t),ur)}var js=As,Ms=_s(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),Ns=Ms,Ps=Math.max;function Fs(e){if(!(e&&e.length))return[];var t=0;return e=ea(e,function(e){if(ys(e))return t=Ps(e.length,t),!0}),Xt(t,function(t){return le(e,Xo(t))})}var Is=Fs,Ls=Vt(Is),Rs=Ls;let j=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}({});function zs(e){switch(e.kind){case j.NEWLINE:case j.SPACE:case j.TAB:case j.SINGLE_LINE_COMMENT:case j.MULTILINE_COMMENT:return!0;default:return!1}}function Bs(e){if(!e)return!1;switch(e){case`+`:case`-`:case`*`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function Vs(e){return e!==void 0&&e.kind===j.OP}var Hs=class e{constructor(e,t,n,r,i){this.kind=e,this.startPos=t,this.endPos=n,this.value=r,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=i,this.start=t.offset,this.end=n.offset}static create(t,n,r,i,a){return new e(t,n,r,i,a)}};function Us(e){return e.trailingTrivia.find(({kind:e})=>e===j.NEWLINE)!==void 0}function Ws(e,t){return t.leadingTrivia.find(({kind:e})=>e===j.NEWLINE)!==void 0||Us(e)}function Gs(e){return e.trailingTrivia.find(({kind:e})=>[j.SPACE,j.TAB].includes(e))!==void 0}function Ks(e){return e.trailingTrivia.length===0?e.end:Ks(xs(e.trailingTrivia))}function qs(e){return e.leadingTrivia.length===0?e.start:qs(e.leadingTrivia[0])}function Js(e){return[j.SINGLE_LINE_COMMENT,j.MULTILINE_COMMENT].includes(e.kind)}var Ys=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},M=class{constructor(e,t,n){this.id=e,this.kind=t;let r=n.find(e=>e!==void 0&&!Number.isNaN(e.start));r?(this.startPos=r.startPos,this.fullStart=r instanceof Hs?qs(r):r.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let i=[...n].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));i?(this.endPos=i.endPos,this.fullEnd=i instanceof Hs?Ks(i):i.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}};let N=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.DUMMY=`<dummy>`,e.ARRAY=`<array>`,e}({});var Xs=class extends M{constructor({body:e=[],eof:t},n){super(n,N.PROGRAM,[...e,t]),this.body=e,this.eof=t}},P=class e extends M{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c){if(super(c,N.ELEMENT_DECLARATION,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof F||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}},Zs=class extends M{constructor({identifiers:e=[]},t){super(t,N.IDENTIFIER_STREAM,e||[]),this.identifiers=e}},Qs=class extends M{constructor({name:e,colon:t,value:n},r){super(r,N.ATTRIBUTE,[e,t,n]),this.name=e,this.value=n,this.colon=t}},$s=class extends M{constructor({op:e,expression:t},n){super(n,N.PREFIX_EXPRESSION,[e,t]),this.op=e,this.expression=t}},ec=class extends M{constructor({op:e,leftExpression:t,rightExpression:n},r){super(r,N.INFIX_EXPRESSION,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},tc=class extends M{constructor({op:e,expression:t},n){super(n,N.POSTFIX_EXPRESSION,[t,e]),this.op=e,this.expression=t}},nc=class extends M{constructor({value:e},t){super(t,N.FUNCTION_EXPRESSION,[e]),this.value=e}},F=class extends M{constructor({callee:e,args:t=[]},n){super(n,N.FUNCTION_APPLICATION,[e,...t]),this.callee=e,this.args=t}},rc=class extends M{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r){super(r,N.BLOCK_EXPRESSION,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},I=class extends M{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i){super(i,N.LIST_EXPRESSION,[e,...fc(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},ic=class extends M{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i){super(i,N.TUPLE_EXPRESSION,[e,...fc(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},ac=class extends ic{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r),this.kind=N.GROUP_EXPRESSION}},oc=class extends M{constructor({callee:e,argumentList:t},n){super(n,N.CALL_EXPRESSION,[e,t]),this.callee=e,this.argumentList=t}},sc=class extends M{constructor({literal:e},t){super(t,N.LITERAL,[e]),this.literal=e}},cc=class extends M{constructor({variable:e},t){super(t,N.VARIABLE,[e]),this.variable=e}},lc=class extends M{constructor({expression:e},t){super(t,N.PRIMARY_EXPRESSION,[e]),this.expression=e}},uc=class extends M{constructor({pre:e},t){let n=Hs.create(j.SPACE,e.endPos,e.endPos,` `,!1);super(t,N.DUMMY,[n])}},dc=class extends M{constructor({expression:e,indexer:t},n){super(n,N.ARRAY,[e,t]),this.array=e,this.indexer=t}};function fc(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?zi(Rs(e,t)):zi(Rs(t,e))).filter(e=>e!==null)}function pc(e,t=!1){return JSON.stringify(e,function(e,t){return!(this instanceof Xs)&&e===`symbol`?t?.id:e===`symbol`?{symbolTable:t?.symbolTable,id:t?.id,references:t?.references.map(e=>e.id),declaration:t?.declaration?.id}:e===`referee`||e===`parent`||e===`declaration`?t?.id:e===`symbolTable`?Object.fromEntries(t.table):t},t?2:0)}var mc=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},hc=class{constructor({symbolTable:e},t){this.references=[],this.id=t,this.symbolTable=e}},gc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},_c=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},vc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},yc=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},bc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},xc=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},Sc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Cc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},wc=class{constructor({declaration:e,tablePartialSymbol:t},n){this.references=[],this.id=n,this.declaration=e,this.tablePartialSymbol=t}};let L=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.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 R=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)}},Tc=class e{constructor(e,t){this.value=e,this.errors=t===void 0?[]:t}getValue(){return this.value}getErrors(){return this.errors}chain(t){let n=t(this.value),r=[...this.errors,...n.errors];return new e(n.value,r)}map(t){return new e(t(this.value),this.errors)}};function Ec(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Dc(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Oc(e){let[t]=e;return Dc(t)||Ec(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function kc(e){return Ec(e)||Dc(e)}function Ac(e){return e.split(``).every(kc)?e:`"${e}"`}function jc(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 Mc(e,t){return e>=t.start&&e<t.end}function Nc(e){return e instanceof $s?`${e.op?.value}${Nc(e.expression)}`:e.expression.literal.value}function Pc(e){return e instanceof $s?e.op?.value===`-`?-Pc(e.expression):Pc(e.expression):Number.parseFloat(e.expression.literal.value)}var Fc=class e{constructor(e){this.value=e}unwrap(){return this.value}unwrap_or(e){return this.value}and_then(e){return e(this.value)}map(t){return new e(t(this.value))}isOk(){return!0}},z=class e{constructor(){this.value=void 0}unwrap(){throw Error(`Trying to unwrap a None value`)}unwrap_or(e){return e}and_then(t){return new e}map(t){return new e}isOk(){return!1}};const Ic=[`null`,`true`,`false`],Lc=[`-`,`+`],Rc=`public`;let B=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}({}),V=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 zc=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Xs||wl(this.declarationNode.parent).unwrap_or(void 0)!==B.Project?[new R(L.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]:[]}validateName(e){return e?[new R(L.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new R(L.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new R(L.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof rc)return[new R(L.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return Ul(e.callee)||t.push(new R(L.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 R(L.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};let H=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.Note=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e}({});function Bc(e){return`${H.Schema}:${e}`}function Vc(e){return`${H.Table}:${e}`}function Hc(e){return`${H.Column}:${e}`}function Uc(e){return`${H.Enum}:${e}`}function Wc(e){return`${H.EnumField}:${e}`}function Gc(e){return`${H.TableGroup}:${e}`}function Kc(e){return`${H.TableGroupField}:${e}`}function qc(e){return`${H.Note}:${e}`}function Jc(e){return`${H.TablePartial}:${e}`}function Yc(e){return`${H.PartialInjection}:${e}`}function Xc(e,t){switch(t){case H.Column:return Hc(e);case H.Enum:return Uc(e);case H.EnumField:return Wc(e);case H.Schema:return Bc(e);case H.Table:return Vc(e);case H.TableGroup:return Gc(e);case H.TableGroupField:return Kc(e);case H.TablePartial:return Jc(e);case H.PartialInjection:return Yc(e);default:throw Error(`Unreachable`)}}function Zc(e){let[t,n]=e.split(`:`);return Object.values(H).includes(t)?new Fc({name:n,kind:t}):new z}var Qc=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)}},$c=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new R(L.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?dl(e)?[]:[new R(L.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new R(L.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new R(L.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(gc,{declaration:this.declarationNode,symbolTable:new Qc});let{name:t}=this.declarationNode,n=El(t);if(n.isOk()){let r=n.unwrap(),i=r.pop(),a=hl(r,this.publicSymbolTable,this.symbolFactory),o=Uc(i);a.has(o)&&e.push(new R(L.DUPLICATE_NAME,`Enum name ${i} already exists in schema '${r.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}return e}validateSettingList(e){return e?[new R(L.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof F)return this.validateFields([e]);let[t,n]=Ns(e.body,e=>e instanceof F);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.length===0?[new R(L.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)]:e.flatMap(e=>{let t=[];e.callee&&!Wl(e.callee)&&t.push(new R(L.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,e.callee));let n=[...e.args];return xs(n)instanceof I?(t.push(...this.validateFieldSettings(xs(n))),n.pop()):n[0]instanceof I&&(t.push(...this.validateFieldSettings(n[0])),n.shift()),n.length>0&&t.push(...n.map(e=>new R(L.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=U(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 R(L.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{Ul(e.value)||n.push(new R(L.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new R(L.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(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}registerField(e){if(e.callee&&Wl(e.callee)){let t=Al(e.callee).unwrap(),n=Wc(t),r=this.symbolFactory.create(_c,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new R(L.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,e),new R(L.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,r.declaration)]}i.set(n,r)}return[]}},el=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new R(L.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof Xs)return[e];let t=wl(this.declarationNode.parent).unwrap_or(void 0);return t&&[B.Table,B.TablePartial].includes(t)?[]:[e]}validateName(e){return e?[new R(L.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new R(L.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new R(L.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof F)return[new R(L.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=Ns(e.body,e=>e instanceof F);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 xs(n)instanceof I&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof oc;)e.argumentList&&!kl(e.argumentList).isOk()&&t.push(new R(L.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;kl(e).isOk()||t.push(new R(L.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=U(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 R(L.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Ul(t.value)||n.push(new R(L.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new R(L.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{vl(t.value)||n.push(new R(L.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new R(L.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{Wl(e.value)||n.push(new R(L.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new R(L.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},tl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return!(this.declarationNode.parent instanceof Xs)&&![B.Table,B.TableGroup,B.TablePartial,B.Project].includes(wl(this.declarationNode.parent).unwrap_or(void 0))?[new R(L.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 Xs))return e?[new R(L.UNEXPECTED_NAME,`A Note shouldn't have a name`,e)]:[];if(!e)return[new R(L.INVALID_NAME,`Sticky note must have a name`,this.declarationNode)];let t=El(e);if(!t.isOk())return[new R(L.INVALID_NAME,`Invalid name for sticky note `,this.declarationNode)];let n=t.unwrap().join(`.`),r=qc(n);return this.publicSymbolTable.has(r)?[new R(L.DUPLICATE_NAME,`Sticky note "${n}" has already been defined`,e)]:(this.publicSymbolTable.set(r,this.declarationNode.symbol),[])}validateAlias(e){return e?[new R(L.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new R(L.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof F)return this.validateFields([e]);let[t,n]=Ns(e.body,e=>e instanceof F);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new R(L.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new R(L.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),Ul(e[0].callee)||t.push(new R(L.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 R(L.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(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},nl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new R(L.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?pl(e)?[]:[new R(L.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new R(L.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new R(L.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof F)return[new R(L.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=Ns(e.body,e=>e instanceof F);return[...t.map(e=>new R(L.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(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},rl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Xs?[]:[new R(L.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?pl(e)?[]:[new R(L.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new R(L.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new R(L.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof F)return this.validateFields([e]);let[t,n]=Ns(e.body,e=>e instanceof F);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new R(L.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 R(L.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Ml(e.callee)&&t.push(new R(L.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Ml(e.callee)){let n=Dl(e.callee.leftExpression).unwrap_or({variables:[],tupleElements:[]}),r=n.variables.length+Math.min(n.tupleElements.length,1),i=Dl(e.callee.rightExpression).unwrap_or({variables:[],tupleElements:[]}),a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new R(L.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new R(L.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Nl(e.callee)&&t.push(new R(L.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(xs(n)instanceof I){let e=this.validateFieldSettings(xs(n));t.push(...e),n.pop()}else n[0]instanceof I&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new R(L.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){let t=U(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 R(L.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{il(t.value)||n.push(new R(L.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 R(L.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{_l(e.value)||n.push(new R(L.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))});break;default:t.forEach(t=>n.push(new R(L.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}};function il(e){if(!(Wl(e)&&e.expression.variable.kind!==j.QUOTED_STRING)&&!(e instanceof Zs))return!1;let t;if(t=e instanceof Zs?Jl(e).unwrap_or(``):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 al=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new R(L.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof dc?[new R(L.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:dl(e)?[]:[new R(L.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new R(L.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?fl(e)?[]:[new R(L.INVALID_ALIAS,`Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=U(e),n=t.getErrors();return js(t.getValue(),(e,t)=>{switch(t){case V.HeaderColor:e.length>1&&n.push(...e.map(e=>new R(L.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{_l(e.value)||n.push(new R(L.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case V.Note:e.length>1&&n.push(...e.map(e=>new R(L.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{Ul(e.value)||n.push(new R(L.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new R(L.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(vc,{declaration:this.declarationNode,symbolTable:new Qc});let{name:t,alias:n}=this.declarationNode,r=El(t);if(r.isOk()){let n=[...r.unwrap()],i=n.pop(),a=hl(n,this.publicSymbolTable,this.symbolFactory),o=Vc(i);a.has(o)&&e.push(new R(L.DUPLICATE_NAME,`Table name '${i}' already exists in schema '${n.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}if(n&&pl(n)&&!ol(n.expression.variable.value,r.unwrap_or([]))){let r=Al(n).unwrap(),i=Vc(r);this.publicSymbolTable.has(i)&&e.push(new R(L.DUPLICATE_NAME,`Table name '${r}' already exists`,t)),this.publicSymbolTable.set(i,this.declarationNode.symbol)}return e}validateBody(e){if(!e)return[];if(e instanceof F)return[new R(L.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=Ns(e.body,e=>e instanceof F);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 R(L.INVALID_COLUMN,`A column must have a type`,e.callee)),Wl(e.callee)||t.push(new R(L.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Cl(e.args[0])&&t.push(new R(L.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(!ml(e.callee))t.push(new R(L.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee));else{let t=Ol(e.callee.expression).unwrap_or(``),n=this.symbolFactory.create(Cc,{symbolTable:new Qc,declaration:e}),r=Yc(t),i=this.declarationNode.symbol.symbolTable;if(i.has(r)){let n=i.get(r);return[new R(L.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,e),new R(L.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 R(L.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t};return e.flatMap(e=>e.callee instanceof $s&&e.callee.op?.value===`~`?n(e):t(e))}registerField(e){if(e.callee&&Wl(e.callee)){let t=Al(e.callee).unwrap(),n=Hc(t),r=this.symbolFactory.create(yc,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new R(L.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new R(L.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}i.set(n,r)}return[]}validateFieldSetting(e){if(!e.slice(0,-1).every(Gl)||!e.slice(-1).every(e=>Gl(e)||e instanceof I))return[...e.map(e=>new R(L.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e))];if(e.length===0)return[];let t;xs(e)instanceof I&&(t=e.pop());let n=U(t),r=n.getErrors(),i=n.getValue();e.forEach(e=>{let t=Al(e).unwrap_or(``).toLowerCase();if(t!==`pk`&&t!==`unique`){r.push(new R(L.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[V.PK]||[],o=i[V.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),js(i,(e,t)=>{switch(t){case V.Note:e.length>1&&r.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{Ul(e.value)||r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case V.Ref:e.forEach(e=>{xl(e.value)||r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case V.PrimaryKey:e.length>1&&r.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{vl(e.value)||r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case V.PK:e.length>1&&r.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof Qs&&!vl(e.value)&&r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case V.NotNull:{e.length>1&&r.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=i[V.Null]||[];e.length>=1&&t.length>=1&&r.push(...[...e,...t].map(e=>new R(L.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{vl(e.value)||r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case V.Null:e.length>1&&r.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{vl(e.value)||r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case V.Unique:e.length>1&&r.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof Qs&&!vl(e.value)&&r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case V.Increment:e.length>1&&r.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof Qs&&!vl(e.value)&&r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case V.Default:e.length>1&&r.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{yl(e.value)||r.push(new R(L.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 V.Check:e.forEach(e=>{e.value instanceof nc||r.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new R(L.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),r}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===`note`);return n.length>1&&t.push(...n.map(e=>new R(L.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function ol(e,t){return t.length===1&&e===t[0]}var sl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new R(L.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?pl(e)?[]:[new R(L.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new R(L.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new R(L.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(bc,{declaration:this.declarationNode,symbolTable:new Qc});let t=El(e);if(t.isOk()){let n=t.unwrap(),r=n.pop(),i=hl(n,this.publicSymbolTable,this.symbolFactory),a=Gc(r);if(i.has(a))return[new R(L.DUPLICATE_NAME,`TableGroup name '${r}' already exists`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=U(e),n=t.getErrors();return js(t.getValue(),(e,t)=>{switch(t){case`color`:e.length>1&&n.push(...e.map(e=>new R(L.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{_l(e.value)||n.push(new R(L.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 R(L.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.filter(e=>!Ul(e.value)).forEach(e=>{n.push(new R(L.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new R(L.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)));break}}),n}validateBody(e){if(!e)return[];if(e instanceof F)return[new R(L.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=Ns(e.body,e=>e instanceof F);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&!El(e.callee).isOk()&&t.push(new R(L.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 R(L.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(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===`note`);return n.length>1&&t.push(...n.map(e=>new R(L.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}registerField(e){if(e.callee&&Wl(e.callee)){let t=Al(e.callee).unwrap(),n=Kc(t),r=this.symbolFactory.create(xc,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new R(L.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,e),new R(L.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,r.declaration)]}i.set(n,r)}return[]}},cl=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new R(L.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?pl(e)?[]:[new R(L.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new R(L.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new R(L.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=U(e),n=t.getErrors();return js(t.getValue(),(e,t)=>{switch(t){case V.HeaderColor:e.length>1&&n.push(...e.map(e=>new R(L.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{_l(e.value)||n.push(new R(L.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case V.Note:e.length>1&&n.push(...e.map(e=>new R(L.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Ul(e.value)||n.push(new R(L.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new R(L.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Sc,{declaration:this.declarationNode,symbolTable:new Qc});let t=El(e);if(!t.isOk())return[];let n=t.unwrap(),r=n.pop(),i=hl(n,this.publicSymbolTable,this.symbolFactory),a=Jc(r);return i.has(a)?[new R(L.DUPLICATE_NAME,`TablePartial name '${r}' already exists`,e)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(e){if(!e)return[];if(e instanceof F)return[new R(L.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=Ns(e.body,e=>e instanceof F);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 R(L.INVALID_COLUMN,`A column must have a type`,e.callee)),Wl(e.callee)||t.push(new R(L.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Cl(e.args[0])&&t.push(new R(L.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||!Wl(e.callee))return[];let t=Al(e.callee).unwrap(),n=Hc(t),r=this.symbolFactory.create(yc,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new R(L.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new R(L.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}return i.set(n,r),[]}validateFieldSetting(e){let t=xs(e);if(!e.slice(0,-1).every(Gl)||!(Gl(t)||t instanceof I))return[...e.map(e=>new R(L.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e))];if(e.length===0)return[];let n;xs(e)instanceof I&&(n=e.pop());let r=U(n),i=r.getErrors(),a=r.getValue();e.forEach(e=>{let t=Al(e).unwrap_or(``).toLowerCase();if(t!==V.PK&&t!==V.Unique){i.push(new R(L.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[V.PK]||[],s=a[V.PrimaryKey]||[];return o.length>=1&&s.length>=1&&i.push(...[...o,...s].map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),js(a,(e,t)=>{switch(t){case V.Note:e.length>1&&i.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Ul(e.value)||i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case V.Ref:e.forEach(e=>{xl(e.value)||i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case V.PrimaryKey:e.length>1&&i.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{vl(e.value)||i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case V.PK:e.length>1&&i.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Qs&&!vl(e.value)&&i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case V.NotNull:{e.length>1&&i.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=a[V.Null]||[];e.length>=1&&n.length>=1&&i.push(...[...e,...n].map(e=>new R(L.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{vl(e.value)||i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case V.Null:e.length>1&&i.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{vl(e.value)||i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case V.Unique:e.length>1&&i.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Qs&&!vl(e.value)&&i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case V.Increment:e.length>1&&i.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Qs&&!vl(e.value)&&i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case V.Default:e.length>1&&i.push(...e.map(e=>new R(L.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{yl(e.value)||i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case V.Check:e.forEach(e=>{e.value instanceof nc||i.push(new R(L.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>i.push(new R(L.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),i}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===B.Note);return n.length>1&&t.push(...n.map(e=>new R(L.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}},ll=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new R(L.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof Xs)return[e];let t=wl(this.declarationNode.parent).unwrap_or(void 0);return t&&[B.Table,B.TablePartial].includes(t)?[]:[e]}validateName(e){return e?[new R(L.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new R(L.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new R(L.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof F)return[new R(L.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=Ns(e.body,e=>e instanceof F);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 xs(n)instanceof I&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof nc))&&t.push(new R(L.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=U(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 R(L.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Ul(t.value)||n.push(new R(L.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new R(L.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(ul(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}};function ul(e){switch(e.type.value.toLowerCase()){case B.Enum:return $c;case B.Table:return al;case B.TableGroup:return sl;case B.Project:return nl;case B.Ref:return rl;case B.Note:return tl;case B.Indexes:return el;case B.TablePartial:return cl;case B.Check:return ll;default:return zc}}function dl(e){return!!El(e).unwrap_or(!1)}function fl(e){return pl(e)}function pl(e){return e instanceof lc&&e.expression instanceof cc}function ml(e){return e instanceof $s&&e.op?.value===`~`&&Wl(e.expression)}function hl(e,t,n){e[0]===`public`&&(e=e.slice(1));let r=t;for(let t of e){let e,i=Bc(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 Qc;let t=n.create(hc,{symbolTable:e});r.set(i,t)}r=e}return r}function gl(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function _l(e){if(!(e instanceof lc)||!(e.expression instanceof sc)||e.expression.literal?.kind!==j.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(!Oc(t[e]))return!1;return!0}function vl(e){return e===void 0}function yl(e){if(Ul(e)||bl(e)||Gl(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof $s&&Lc.includes(e.op?.value)&&bl(e.expression)||e instanceof nc)return!0;if(!e||!ql(e))return!1;let t=Tl(e).unwrap();return t.length===2||t.length===3}function bl(e){return e instanceof $s?Lc.includes(e.op.value)?bl(e.expression):!1:e instanceof lc&&e.expression instanceof sc&&e.expression.literal?.kind===j.NUMERIC_LITERAL}function xl(e){if(!(e instanceof $s)||!gl(e.op?.value))return!1;let t=El(e.expression).unwrap_or(void 0);return t!==void 0&&t.length>0}function Sl(e){return e instanceof ic&&e.elementList.every(Wl)}function Cl(e){if(!(e instanceof oc||Kl(e)||e instanceof lc||e instanceof dc))return!1;for(;e instanceof oc||e instanceof dc;)if(e instanceof oc){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>bl(e)||Ul(e)||Gl(e)))return!1;e=e.callee}else if(e instanceof dc){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&bl(e.name)))return!1;e=e.array}let t=El(e).unwrap_or(void 0);return t!==void 0&&t.length>0}function U(e){let t={},n=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof lc){n.push(new R(L.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let r=Jl(e.name).unwrap_or(void 0)?.toLowerCase();r&&(t[r]===void 0?t[r]=[e]:t[r].push(e))}),new Tc(t,n)):new Tc({})}function wl(e){let t=e?.type?.value.toLowerCase();switch(t){case B.Enum:case B.Table:case B.Indexes:case B.Note:case B.Project:case B.Ref:case B.TableGroup:case B.TablePartial:case B.Check:return new Fc(t);default:return new z}}function Tl(e){if(!e)return new z;if(!Kl(e))return new Fc([e]);let t=Tl(e.leftExpression).unwrap_or(void 0);return t?(t.push(e.rightExpression),new Fc(t)):new z}function El(e){if(e===void 0)return new z;let t=Tl(e).unwrap_or(void 0);if(!t)return new z;let n=[];for(let e of t){let t=Ol(e).unwrap_or(void 0);if(typeof t!=`string`)return new z;n.push(t)}return new Fc(n)}function Dl(e){if(e===void 0)return new z;let t=Tl(e).unwrap_or(void 0);if(!t||t.length===0)return new z;let n=[];if(!Wl(xs(t))){let e=t.pop();if(Sl(e))n=e.elementList;else return new z}let r=t;return r.every(Wl)?new Fc({variables:r,tupleElements:n}):new z}function Ol(e){return Wl(e)?new Fc(e.expression.variable.value):new z}function kl(e){return Pl(e)?e instanceof nc?new Fc({functional:[e],nonFunctional:[]}):new Fc({functional:[],nonFunctional:[e]}):e instanceof ic&&e.elementList.every(Pl)?new Fc({functional:e.elementList.filter(e=>e instanceof nc),nonFunctional:e.elementList.filter(Wl)}):new z}function Al(e){let t=e?.expression.variable?.value;return t===void 0?new z:new Fc(t)}function jl(e){return Ul(e)?e.expression instanceof cc?new Fc(e.expression.variable.value):new Fc(e.expression.literal.value):new z}function Ml(e){return!(e instanceof ec)||!gl(e.op?.value)?!1:Dl(e.leftExpression).and_then(()=>Dl(e.rightExpression)).unwrap_or(void 0)!==void 0}function Nl(e){let t=Dl(e.leftExpression),n=Dl(e.rightExpression);if(!t.isOk()||!n.isOk())return!1;let{tupleElements:r}=t.unwrap(),{tupleElements:i}=n.unwrap();return r?.length===i?.length}function Pl(e){return e instanceof lc&&e.expression instanceof cc||e instanceof nc}function Fl(e,t,n){if(!e||!Gl(e)||t.length===0)return new z;let r=[...t],i=Hl(e).unwrap(),a=r.pop();if(!(a instanceof rc))return new z;let o=xs(r)instanceof I?r.pop():void 0;if(r.length===3){let e=Hl(r[1]).value;return!e||!Il(e)?new z:new Fc(n.create(P,{type:i,name:r[0],as:e,alias:r[2],attributeList:o,body:a}))}return r.length===1?new Fc(n.create(P,{type:i,name:r[0],attributeList:o,body:a})):r.length===0?new Fc(n.create(P,{type:i,attributeList:o,body:a})):new z}function Il(e){return e?.kind===j.IDENTIFIER&&e.value.toLowerCase()===`as`}function W(e){e&&(e instanceof Hs?Ll(e):Rl(e))}function Ll(e){e.kind!==j.EOF&&(e.isInvalid=!0)}function Rl(e){if(e instanceof P)W(e.type),W(e.name),W(e.as),W(e.alias),W(e.bodyColon),W(e.attributeList),W(e.body);else if(e instanceof Zs)e.identifiers.forEach(W);else if(e instanceof Qs)W(e.name),W(e.colon),W(e.value);else if(e instanceof $s)W(e.op),W(e.expression);else if(e instanceof ec)W(e.leftExpression),W(e.op),W(e.rightExpression);else if(e instanceof tc)W(e.op),W(e.expression);else if(e instanceof rc)W(e.blockOpenBrace),e.body.forEach(W),W(e.blockCloseBrace);else if(e instanceof I)W(e.listOpenBracket),e.commaList.forEach(W),e.elementList.forEach(W),W(e.listCloseBracket);else if(e instanceof ic)W(e.tupleOpenParen),e.commaList.forEach(W),e.elementList.forEach(W),W(e.tupleCloseParen);else if(e instanceof oc)W(e.callee),W(e.argumentList);else if(e instanceof F)W(e.callee),e.args.forEach(W);else if(e instanceof lc)W(e.expression);else if(e instanceof nc)W(e.value);else if(e instanceof cc)W(e.variable);else if(e instanceof sc)W(e.literal);else if(e instanceof ac)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof dc)W(e.array),W(e.indexer);else if(e instanceof Xs)e.body.forEach(W),W(e.eof);else if(!(e instanceof uc))throw Error(`Unreachable case in markInvalidNode`)}function zl(e){return!!e?.isInvalid}function Bl(...e){return e.filter(e=>e!==void 0)}function Vl(e){if(e instanceof Xs)return Bl(...e.body,e.eof);if(e instanceof P)return Bl(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof Qs)return Bl(e.name,e.colon,e.value);if(e instanceof Zs)return e.identifiers;if(e instanceof sc)return e.literal?[e.literal]:[];if(e instanceof cc)return Bl(e.variable);if(e instanceof $s)return Bl(e.op,e.expression);if(e instanceof ec)return Bl(e.leftExpression,e.op,e.rightExpression);if(e instanceof tc)return Bl(e.expression,e.op);if(e instanceof nc)return Bl(e.value);if(e instanceof F)return Bl(e.callee,...e.args);if(e instanceof rc)return Bl(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof I)return Bl(e.listOpenBracket,...jc(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof ic)return Bl(e.tupleOpenParen,...jc(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof oc)return Bl(e.callee,e.argumentList);if(e instanceof lc)return Bl(e.expression);if(e instanceof dc)return Bl(e.array,e.indexer);throw e instanceof ac?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Hl(e){return Wl(e)?new Fc(e.expression.variable):new z}function Ul(e){return e instanceof lc&&(e.expression instanceof cc&&e.expression.variable instanceof Hs&&e.expression.variable.kind===j.QUOTED_STRING||e.expression instanceof sc&&e.expression.literal?.kind===j.STRING_LITERAL)}function Wl(e){return e instanceof lc&&e.expression instanceof cc&&e.expression.variable instanceof Hs}function Gl(e){return e instanceof lc&&e.expression instanceof cc&&e.expression.variable?.kind===j.IDENTIFIER}function Kl(e){return e instanceof ec&&e.leftExpression instanceof M&&e.rightExpression instanceof M&&e.op?.value===`.`}function ql(e){return Wl(e)?!0:Kl(e)&&Wl(e.rightExpression)&&ql(e.leftExpression)}function Jl(e){if(e===void 0)return new z;let t=e.identifiers.map(e=>e.value).join(` `);return t===``?new z:new Fc(t)}function Yl(e){return El(e.name).map(e=>e.join(`.`))}var Xl=class{constructor(e){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
|
|
2
|
-
`?(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
|
|
3
|
-
`:this.addToken(
|
|
4
|
-
`))&&!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
|
|
5
|
-
`)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new
|
|
6
|
-
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(
|
|
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=typeof global==`object`&&global&&global.Object===Object&&global,r=n,i=typeof self==`object`&&self&&self.Object===Object&&self,a=r||i||Function(`return this`)(),o=a,s=o.Symbol,c=s,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function ee(e){var t=u.call(e,f),n=e[f];try{e[f]=void 0;var r=!0}catch{}var i=d.call(e);return r&&(t?e[f]=n:delete e[f]),i}var te=ee,ne=Object.prototype.toString;function re(e){return ne.call(e)}var ie=re,ae=`[object Null]`,oe=`[object Undefined]`,se=c?c.toStringTag:void 0;function ce(e){return e==null?e===void 0?oe:ae:se&&se in Object(e)?te(e):ie(e)}var le=ce;function ue(e){return typeof e==`object`&&!!e}var de=ue,fe=`[object Symbol]`;function pe(e){return typeof e==`symbol`||de(e)&&le(e)==fe}var me=pe;function he(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 ge=he,_e=Array.isArray,ve=_e,ye=1/0,be=c?c.prototype:void 0,xe=be?be.toString:void 0;function Se(e){if(typeof e==`string`)return e;if(ve(e))return ge(e,Se)+``;if(me(e))return xe?xe.call(e):``;var t=e+``;return t==`0`&&1/e==-ye?`-0`:t}var Ce=Se,we=/\s/;function Te(e){for(var t=e.length;t--&&we.test(e.charAt(t)););return t}var Ee=Te,De=/^\s+/;function Oe(e){return e&&e.slice(0,Ee(e)+1).replace(De,``)}var ke=Oe;function Ae(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var je=Ae,Me=NaN,Ne=/^[-+]0x[0-9a-f]+$/i,Pe=/^0b[01]+$/i,Fe=/^0o[0-7]+$/i,Ie=parseInt;function Le(e){if(typeof e==`number`)return e;if(me(e))return Me;if(je(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=je(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=ke(e);var n=Pe.test(e);return n||Fe.test(e)?Ie(e.slice(2),n?2:8):Ne.test(e)?Me:+e}var Re=Le,ze=1/0,Be=17976931348623157e292;function Ve(e){return e?(e=Re(e),e===ze||e===-ze?(e<0?-1:1)*Be:e===e?e:0):e===0?e:0}var He=Ve;function Ue(e){var t=He(e),n=t%1;return t===t?n?t-n:t:0}var We=Ue;function Ge(e){return e}var Ke=Ge,qe=`[object AsyncFunction]`,Je=`[object Function]`,Ye=`[object GeneratorFunction]`,Xe=`[object Proxy]`;function Ze(e){if(!je(e))return!1;var t=le(e);return t==Je||t==Ye||t==qe||t==Xe}var Qe=Ze,$e=o[`__core-js_shared__`],et=$e,tt=function(){var e=/[^.]+$/.exec(et&&et.keys&&et.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function nt(e){return!!tt&&tt in e}var rt=nt,it=Function.prototype.toString;function at(e){if(e!=null){try{return it.call(e)}catch{}try{return e+``}catch{}}return``}var ot=at,st=/[\\^$.*+?()[\]{}|]/g,ct=/^\[object .+?Constructor\]$/,lt=Function.prototype,ut=Object.prototype,dt=lt.toString,ft=ut.hasOwnProperty,pt=RegExp(`^`+dt.call(ft).replace(st,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function mt(e){return!je(e)||rt(e)?!1:(Qe(e)?pt:ct).test(ot(e))}var ht=mt;function gt(e,t){return e?.[t]}var _t=gt;function vt(e,t){var n=_t(e,t);return ht(n)?n:void 0}var yt=vt,bt=yt(o,`WeakMap`),xt=bt;function St(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 Ct=St,wt=800,Tt=16,Et=Date.now;function Dt(e){var t=0,n=0;return function(){var r=Et(),i=Tt-(r-n);if(n=r,i>0){if(++t>=wt)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var Ot=Dt;function kt(e){return function(){return e}}var At=kt,jt=function(){try{var e=yt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Mt=jt,Nt=Mt?function(e,t){return Mt(e,`toString`,{configurable:!0,enumerable:!1,value:At(t),writable:!0})}:Ke,Pt=Nt,Ft=Ot(Pt),It=Ft;function Lt(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 Rt=Lt,zt=9007199254740991,Bt=/^(?:0|[1-9]\d*)$/;function Vt(e,t){var n=typeof e;return t??=zt,!!t&&(n==`number`||n!=`symbol`&&Bt.test(e))&&e>-1&&e%1==0&&e<t}var Ht=Vt;function Ut(e,t){return e===t||e!==e&&t!==t}var Wt=Ut,Gt=Math.max;function Kt(e,t,n){return t=Gt(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=Gt(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),Ct(e,this,s)}}var qt=Kt;function Jt(e,t){return It(qt(e,t,Ke),e+``)}var Yt=Jt,Xt=9007199254740991;function Zt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=Xt}var Qt=Zt;function $t(e){return e!=null&&Qt(e.length)&&!Qe(e)}var en=$t,tn=Object.prototype;function nn(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||tn)}var rn=nn;function an(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var on=an,sn=`[object Arguments]`;function cn(e){return de(e)&&le(e)==sn}var ln=cn,un=Object.prototype,dn=un.hasOwnProperty,fn=un.propertyIsEnumerable,pn=ln(function(){return arguments}())?ln:function(e){return de(e)&&dn.call(e,`callee`)&&!fn.call(e,`callee`)},mn=pn;function hn(){return!1}var gn=hn,_n=typeof exports==`object`&&exports&&!exports.nodeType&&exports,vn=_n&&typeof module==`object`&&module&&!module.nodeType&&module,yn=vn&&vn.exports===_n?o.Buffer:void 0,bn=(yn?yn.isBuffer:void 0)||gn,xn=bn,Sn=`[object Arguments]`,Cn=`[object Array]`,wn=`[object Boolean]`,Tn=`[object Date]`,En=`[object Error]`,Dn=`[object Function]`,On=`[object Map]`,kn=`[object Number]`,An=`[object Object]`,jn=`[object RegExp]`,Mn=`[object Set]`,Nn=`[object String]`,Pn=`[object WeakMap]`,Fn=`[object ArrayBuffer]`,In=`[object DataView]`,Ln=`[object Float32Array]`,Rn=`[object Float64Array]`,zn=`[object Int8Array]`,Bn=`[object Int16Array]`,Vn=`[object Int32Array]`,Hn=`[object Uint8Array]`,Un=`[object Uint8ClampedArray]`,Wn=`[object Uint16Array]`,Gn=`[object Uint32Array]`,p={};p[Ln]=p[Rn]=p[zn]=p[Bn]=p[Vn]=p[Hn]=p[Un]=p[Wn]=p[Gn]=!0,p[Sn]=p[Cn]=p[Fn]=p[wn]=p[In]=p[Tn]=p[En]=p[Dn]=p[On]=p[kn]=p[An]=p[jn]=p[Mn]=p[Nn]=p[Pn]=!1;function Kn(e){return de(e)&&Qt(e.length)&&!!p[le(e)]}var qn=Kn;function Jn(e){return function(t){return e(t)}}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&&r.process,$n=function(){try{return Zn&&Zn.require&&Zn.require(`util`).types||Qn&&Qn.binding&&Qn.binding(`util`)}catch{}}(),er=$n,tr=er&&er.isTypedArray,nr=tr?Yn(tr):qn,rr=nr,ir=Object.prototype.hasOwnProperty;function ar(e,t){var n=ve(e),r=!n&&mn(e),i=!n&&!r&&xn(e),a=!n&&!r&&!i&&rr(e),o=n||r||i||a,s=o?on(e.length,String):[],c=s.length;for(var l in e)(t||ir.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||Ht(l,c)))&&s.push(l);return s}var or=ar;function sr(e,t){return function(n){return e(t(n))}}var cr=sr,lr=cr(Object.keys,Object),ur=lr,dr=Object.prototype.hasOwnProperty;function fr(e){if(!rn(e))return ur(e);var t=[];for(var n in Object(e))dr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var pr=fr;function mr(e){return en(e)?or(e):pr(e)}var hr=mr;function gr(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var _r=gr,vr=Object.prototype.hasOwnProperty;function yr(e){if(!je(e))return _r(e);var t=rn(e),n=[];for(var r in e)r==`constructor`&&(t||!vr.call(e,r))||n.push(r);return n}var br=yr;function xr(e){return en(e)?or(e,!0):br(e)}var Sr=xr,Cr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,wr=/^\w*$/;function Tr(e,t){if(ve(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||me(e)?!0:wr.test(e)||!Cr.test(e)||t!=null&&e in Object(t)}var Er=Tr,Dr=yt(Object,`create`),Or=Dr;function kr(){this.__data__=Or?Or(null):{},this.size=0}var Ar=kr;function jr(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Mr=jr,Nr=`__lodash_hash_undefined__`,Pr=Object.prototype.hasOwnProperty;function Fr(e){var t=this.__data__;if(Or){var n=t[e];return n===Nr?void 0:n}return Pr.call(t,e)?t[e]:void 0}var Ir=Fr,Lr=Object.prototype.hasOwnProperty;function Rr(e){var t=this.__data__;return Or?t[e]!==void 0:Lr.call(t,e)}var zr=Rr,Br=`__lodash_hash_undefined__`;function Vr(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Or&&t===void 0?Br:t,this}var Hr=Vr;function Ur(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])}}Ur.prototype.clear=Ar,Ur.prototype.delete=Mr,Ur.prototype.get=Ir,Ur.prototype.has=zr,Ur.prototype.set=Hr;var Wr=Ur;function Gr(){this.__data__=[],this.size=0}var Kr=Gr;function qr(e,t){for(var n=e.length;n--;)if(Wt(e[n][0],t))return n;return-1}var Jr=qr,Yr=Array.prototype.splice;function Xr(e){var t=this.__data__,n=Jr(t,e);return n<0?!1:(n==t.length-1?t.pop():Yr.call(t,n,1),--this.size,!0)}var Zr=Xr;function Qr(e){var t=this.__data__,n=Jr(t,e);return n<0?void 0:t[n][1]}var $r=Qr;function ei(e){return Jr(this.__data__,e)>-1}var ti=ei;function ni(e,t){var n=this.__data__,r=Jr(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var ri=ni;function ii(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])}}ii.prototype.clear=Kr,ii.prototype.delete=Zr,ii.prototype.get=$r,ii.prototype.has=ti,ii.prototype.set=ri;var ai=ii,oi=yt(o,`Map`),si=oi;function ci(){this.size=0,this.__data__={hash:new Wr,map:new(si||ai),string:new Wr}}var li=ci;function ui(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var di=ui;function fi(e,t){var n=e.__data__;return di(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var pi=fi;function mi(e){var t=pi(this,e).delete(e);return this.size-=t?1:0,t}var hi=mi;function gi(e){return pi(this,e).get(e)}var _i=gi;function vi(e){return pi(this,e).has(e)}var yi=vi;function bi(e,t){var n=pi(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,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=hi,Si.prototype.get=_i,Si.prototype.has=yi,Si.prototype.set=xi;var Ci=Si,wi=`Expected a function`;function Ti(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(wi);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(Ti.Cache||Ci),n}Ti.Cache=Ci;var Ei=Ti,Di=500;function Oi(e){var t=Ei(e,function(e){return n.size===Di&&n.clear(),e}),n=t.cache;return t}var ki=Oi,Ai=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ji=/\\(\\)?/g,Mi=ki(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(Ai,function(e,n,r,i){t.push(r?i.replace(ji,`$1`):n||e)}),t}),Ni=Mi;function Pi(e){return e==null?``:Ce(e)}var Fi=Pi;function Ii(e,t){return ve(e)?e:Er(e,t)?[e]:Ni(Fi(e))}var Li=Ii,Ri=1/0;function zi(e){if(typeof e==`string`||me(e))return e;var t=e+``;return t==`0`&&1/e==-Ri?`-0`:t}var Bi=zi;function Vi(e,t){t=Li(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[Bi(t[n++])];return n&&n==r?e:void 0}var Hi=Vi;function Ui(e,t,n){var r=e==null?void 0:Hi(e,t);return r===void 0?n:r}var Wi=Ui;function Gi(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var Ki=Gi,qi=c?c.isConcatSpreadable:void 0;function Ji(e){return ve(e)||mn(e)||!!(qi&&e&&e[qi])}var Yi=Ji;function Xi(e,t,n,r,i){var a=-1,o=e.length;for(n||=Yi,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?Xi(s,t-1,n,r,i):Ki(i,s):r||(i[i.length]=s)}return i}var Zi=Xi;function Qi(e){return e!=null&&e.length?Zi(e,1):[]}var $i=Qi;function ea(){this.__data__=new ai,this.size=0}var ta=ea;function na(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var ra=na;function ia(e){return this.__data__.get(e)}var aa=ia;function oa(e){return this.__data__.has(e)}var sa=oa,ca=200;function la(e,t){var n=this.__data__;if(n instanceof ai){var r=n.__data__;if(!si||r.length<ca-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Ci(r)}return n.set(e,t),this.size=n.size,this}var ua=la;function da(e){this.size=(this.__data__=new ai(e)).size}da.prototype.clear=ta,da.prototype.delete=ra,da.prototype.get=aa,da.prototype.has=sa,da.prototype.set=ua;var fa=da;function pa(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 ma=pa;function ha(){return[]}var ga=ha,_a=Object.prototype.propertyIsEnumerable,va=Object.getOwnPropertySymbols,ya=va?function(e){return e==null?[]:(e=Object(e),ma(va(e),function(t){return _a.call(e,t)}))}:ga,ba=ya;function xa(e,t,n){var r=t(e);return ve(e)?r:Ki(r,n(e))}var Sa=xa;function Ca(e){return Sa(e,hr,ba)}var wa=Ca,Ta=yt(o,`DataView`),Ea=Ta,Da=yt(o,`Promise`),Oa=Da,ka=yt(o,`Set`),Aa=ka,ja=`[object Map]`,Ma=`[object Object]`,Na=`[object Promise]`,Pa=`[object Set]`,Fa=`[object WeakMap]`,Ia=`[object DataView]`,La=ot(Ea),Ra=ot(si),za=ot(Oa),Ba=ot(Aa),Va=ot(xt),Ha=le;(Ea&&Ha(new Ea(new ArrayBuffer(1)))!=Ia||si&&Ha(new si)!=ja||Oa&&Ha(Oa.resolve())!=Na||Aa&&Ha(new Aa)!=Pa||xt&&Ha(new xt)!=Fa)&&(Ha=function(e){var t=le(e),n=t==Ma?e.constructor:void 0,r=n?ot(n):``;if(r)switch(r){case La:return Ia;case Ra:return ja;case za:return Na;case Ba:return Pa;case Va:return Fa}return t});var Ua=Ha,Wa=o.Uint8Array,Ga=Wa,Ka=`__lodash_hash_undefined__`;function qa(e){return this.__data__.set(e,Ka),this}var Ja=qa;function Ya(e){return this.__data__.has(e)}var Xa=Ya;function Za(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Ci;++t<n;)this.add(e[t])}Za.prototype.add=Za.prototype.push=Ja,Za.prototype.has=Xa;var Qa=Za;function $a(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 eo=$a;function to(e,t){return e.has(t)}var no=to,ro=1,io=2;function ao(e,t,n,r,i,a){var o=n&ro,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,ee=n&io?new Qa:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var te=e[d],ne=t[d];if(r)var re=o?r(ne,te,d,t,e,a):r(te,ne,d,e,t,a);if(re!==void 0){if(re)continue;f=!1;break}if(ee){if(!eo(t,function(e,t){if(!no(ee,t)&&(te===e||i(te,e,n,r,a)))return ee.push(t)})){f=!1;break}}else if(!(te===ne||i(te,ne,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var oo=ao;function so(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var co=so;function lo(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var uo=lo,fo=1,po=2,mo=`[object Boolean]`,ho=`[object Date]`,go=`[object Error]`,_o=`[object Map]`,vo=`[object Number]`,yo=`[object RegExp]`,bo=`[object Set]`,xo=`[object String]`,So=`[object Symbol]`,Co=`[object ArrayBuffer]`,wo=`[object DataView]`,To=c?c.prototype:void 0,Eo=To?To.valueOf:void 0;function Do(e,t,n,r,i,a,o){switch(n){case wo:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Co:return!(e.byteLength!=t.byteLength||!a(new Ga(e),new Ga(t)));case mo:case ho:case vo:return Wt(+e,+t);case go:return e.name==t.name&&e.message==t.message;case yo:case xo:return e==t+``;case _o:var s=co;case bo:var c=r&fo;if(s||=uo,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=po,o.set(e,t);var u=oo(s(e),s(t),r,i,a,o);return o.delete(e),u;case So:if(Eo)return Eo.call(e)==Eo.call(t)}return!1}var Oo=Do,ko=1,Ao=Object.prototype.hasOwnProperty;function jo(e,t,n,r,i,a){var o=n&ko,s=wa(e),c=s.length;if(c!=wa(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Ao.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var ee=!0;a.set(e,t),a.set(t,e);for(var te=o;++l<c;){u=s[l];var ne=e[u],re=t[u];if(r)var ie=o?r(re,ne,u,t,e,a):r(ne,re,u,e,t,a);if(!(ie===void 0?ne===re||i(ne,re,n,r,a):ie)){ee=!1;break}te||=u==`constructor`}if(ee&&!te){var ae=e.constructor,oe=t.constructor;ae!=oe&&`constructor`in e&&`constructor`in t&&!(typeof ae==`function`&&ae instanceof ae&&typeof oe==`function`&&oe instanceof oe)&&(ee=!1)}return a.delete(e),a.delete(t),ee}var Mo=jo,No=1,Po=`[object Arguments]`,Fo=`[object Array]`,Io=`[object Object]`,Lo=Object.prototype.hasOwnProperty;function Ro(e,t,n,r,i,a){var o=ve(e),s=ve(t),c=o?Fo:Ua(e),l=s?Fo:Ua(t);c=c==Po?Io:c,l=l==Po?Io:l;var u=c==Io,d=l==Io,f=c==l;if(f&&xn(e)){if(!xn(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new fa,o||rr(e)?oo(e,t,n,r,i,a):Oo(e,t,c,n,r,i,a);if(!(n&No)){var ee=u&&Lo.call(e,`__wrapped__`),te=d&&Lo.call(t,`__wrapped__`);if(ee||te){var ne=ee?e.value():e,re=te?t.value():t;return a||=new fa,i(ne,re,n,r,a)}}return f?(a||=new fa,Mo(e,t,n,r,i,a)):!1}var zo=Ro;function Bo(e,t,n,r,i){return e===t?!0:e==null||t==null||!de(e)&&!de(t)?e!==e&&t!==t:zo(e,t,n,r,Bo,i)}var Vo=Bo,Ho=1,Uo=2;function Wo(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 fa;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Vo(u,l,Ho|Uo,r,d):f))return!1}}return!0}var Go=Wo;function Ko(e){return e===e&&!je(e)}var qo=Ko;function Jo(e){for(var t=hr(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,qo(i)]}return t}var Yo=Jo;function Xo(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var Zo=Xo;function Qo(e){var t=Yo(e);return t.length==1&&t[0][2]?Zo(t[0][0],t[0][1]):function(n){return n===e||Go(n,e,t)}}var $o=Qo;function es(e,t){return e!=null&&t in Object(e)}var ts=es;function ns(e,t,n){t=Li(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=Bi(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&&Qt(i)&&Ht(o,i)&&(ve(e)||mn(e)))}var rs=ns;function is(e,t){return e!=null&&rs(e,t,ts)}var as=is,os=1,ss=2;function cs(e,t){return Er(e)&&qo(t)?Zo(Bi(e),t):function(n){var r=Wi(n,e);return r===void 0&&r===t?as(n,e):Vo(t,r,os|ss)}}var ls=cs;function us(e){return function(t){return t?.[e]}}var ds=us;function fs(e){return function(t){return Hi(t,e)}}var ps=fs;function ms(e){return Er(e)?ds(Bi(e)):ps(e)}var hs=ms;function gs(e){return typeof e==`function`?e:e==null?Ke:typeof e==`object`?ve(e)?ls(e[0],e[1]):$o(e):hs(e)}var _s=gs;function vs(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 ys=vs;function bs(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 xs=bs,Ss=xs(),Cs=Ss;function ws(e,t){return e&&Cs(e,t,hr)}var Ts=ws;function Es(e,t){return function(n,r){if(n==null)return n;if(!en(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 Ds=Es,Os=Ds(Ts),ks=Os;function As(e,t,n,r){return ks(e,function(e,i,a){t(r,e,n(e),a)}),r}var js=As;function Ms(e,t){return function(n,r){var i=ve(n)?ys:js,a=t?t():{};return i(n,e,_s(r,2),a)}}var Ns=Ms;function Ps(e){return de(e)&&en(e)}var Fs=Ps;function Is(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var m=Is;function Ls(e){return typeof e==`function`?e:Ke}var Rs=Ls,zs=Math.max,Bs=Math.min;function Vs(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=We(n),i=n<0?zs(r+i,0):Bs(i,r-1)),Rt(e,_s(t,3),i,!0)}var Hs=Vs;function Us(e){return e&&e.length?e[0]:void 0}var Ws=Us;function Gs(e,t){return e==null?e:Cs(e,Rs(t),Sr)}var Ks=Gs,qs=Ns(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),h=qs,Js=Math.max;function Ys(e){if(!(e&&e.length))return[];var t=0;return e=ma(e,function(e){if(Fs(e))return t=Js(e.length,t),!0}),on(t,function(t){return ge(e,ds(t))})}var Xs=Ys,Zs=Yt(Xs),Qs=Zs;let g=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}({});function $s(e){switch(e.kind){case g.NEWLINE:case g.SPACE:case g.TAB:case g.SINGLE_LINE_COMMENT:case g.MULTILINE_COMMENT:return!0;default:return!1}}function ec(e){if(!e)return!1;switch(e){case`+`:case`-`:case`*`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function tc(e){return e!==void 0&&e.kind===g.OP}var _=class e{constructor(e,t,n,r,i){this.kind=e,this.startPos=t,this.endPos=n,this.value=r,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=i,this.start=t.offset,this.end=n.offset}static create(t,n,r,i,a){return new e(t,n,r,i,a)}};function nc(e){return e.trailingTrivia.find(({kind:e})=>e===g.NEWLINE)!==void 0}function rc(e,t){return t.leadingTrivia.find(({kind:e})=>e===g.NEWLINE)!==void 0||nc(e)}function ic(e){return e.trailingTrivia.find(({kind:e})=>[g.SPACE,g.TAB].includes(e))!==void 0}function ac(e){return e.trailingTrivia.length===0?e.end:ac(m(e.trailingTrivia))}function oc(e){return e.leadingTrivia.length===0?e.start:oc(e.leadingTrivia[0])}function sc(e){return[g.SINGLE_LINE_COMMENT,g.MULTILINE_COMMENT].includes(e.kind)}var cc=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},v=class{constructor(e,t,n){this.id=e,this.kind=t;let r=n.find(e=>e!==void 0&&!Number.isNaN(e.start));r?(this.startPos=r.startPos,this.fullStart=r instanceof _?oc(r):r.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let i=[...n].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));i?(this.endPos=i.endPos,this.fullEnd=i instanceof _?ac(i):i.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}};let y=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.DUMMY=`<dummy>`,e.ARRAY=`<array>`,e}({});var b=class extends v{constructor({body:e=[],eof:t},n){super(n,y.PROGRAM,[...e,t]),this.body=e,this.eof=t}},x=class e extends v{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c){if(super(c,y.ELEMENT_DECLARATION,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof w||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}},lc=class extends v{constructor({identifiers:e=[]},t){super(t,y.IDENTIFIER_STREAM,e||[]),this.identifiers=e}},uc=class extends v{constructor({name:e,colon:t,value:n},r){super(r,y.ATTRIBUTE,[e,t,n]),this.name=e,this.value=n,this.colon=t}},S=class extends v{constructor({op:e,expression:t},n){super(n,y.PREFIX_EXPRESSION,[e,t]),this.op=e,this.expression=t}},dc=class extends v{constructor({op:e,leftExpression:t,rightExpression:n},r){super(r,y.INFIX_EXPRESSION,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},fc=class extends v{constructor({op:e,expression:t},n){super(n,y.POSTFIX_EXPRESSION,[t,e]),this.op=e,this.expression=t}},C=class extends v{constructor({value:e},t){super(t,y.FUNCTION_EXPRESSION,[e]),this.value=e}},w=class extends v{constructor({callee:e,args:t=[]},n){super(n,y.FUNCTION_APPLICATION,[e,...t]),this.callee=e,this.args=t}},T=class extends v{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r){super(r,y.BLOCK_EXPRESSION,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},E=class extends v{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i){super(i,y.LIST_EXPRESSION,[e,...yc(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},pc=class extends v{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i){super(i,y.TUPLE_EXPRESSION,[e,...yc(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},mc=class extends pc{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r),this.kind=y.GROUP_EXPRESSION}},D=class extends v{constructor({callee:e,argumentList:t},n){super(n,y.CALL_EXPRESSION,[e,t]),this.callee=e,this.argumentList=t}},hc=class extends v{constructor({literal:e},t){super(t,y.LITERAL,[e]),this.literal=e}},gc=class extends v{constructor({variable:e},t){super(t,y.VARIABLE,[e]),this.variable=e}},O=class extends v{constructor({expression:e},t){super(t,y.PRIMARY_EXPRESSION,[e]),this.expression=e}},_c=class extends v{constructor({pre:e},t){let n=_.create(g.SPACE,e.endPos,e.endPos,` `,!1);super(t,y.DUMMY,[n])}},vc=class extends v{constructor({expression:e,indexer:t},n){super(n,y.ARRAY,[e,t]),this.array=e,this.indexer=t}};function yc(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?$i(Qs(e,t)):$i(Qs(t,e))).filter(e=>e!==null)}function bc(e,t=!1){return JSON.stringify(e,function(e,t){return!(this instanceof b)&&e===`symbol`?t?.id:e===`symbol`?{symbolTable:t?.symbolTable,id:t?.id,references:t?.references.map(e=>e.id),declaration:t?.declaration?.id}:e===`referee`||e===`parent`||e===`declaration`?t?.id:e===`symbolTable`?Object.fromEntries(t.table):t},t?2:0)}var xc=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Sc=class{constructor({symbolTable:e},t){this.references=[],this.id=t,this.symbolTable=e}},Cc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},wc=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},Tc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Ec=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},Dc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Oc=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},kc=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Ac=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},jc=class{constructor({declaration:e,tablePartialSymbol:t},n){this.references=[],this.id=n,this.declaration=e,this.tablePartialSymbol=t}};let k=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.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 A=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)}},Mc=class e{constructor(e,t){this.value=e,this.errors=t===void 0?[]:t}getValue(){return this.value}getErrors(){return this.errors}chain(t){let n=t(this.value),r=[...this.errors,...n.errors];return new e(n.value,r)}map(t){return new e(t(this.value),this.errors)}};function Nc(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Pc(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Fc(e){let[t]=e;return Pc(t)||Nc(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Ic(e){return Nc(e)||Pc(e)}function Lc(e){return e.split(``).every(Ic)?e:`"${e}"`}function Rc(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 zc(e,t){return e>=t.start&&e<t.end}function Bc(e){return e instanceof S?`${e.op?.value}${Bc(e.expression)}`:e.expression.literal.value}function Vc(e){return e instanceof S?e.op?.value===`-`?-Vc(e.expression):Vc(e.expression):Number.parseFloat(e.expression.literal.value)}var j=class e{constructor(e){this.value=e}unwrap(){return this.value}unwrap_or(e){return this.value}and_then(e){return e(this.value)}map(t){return new e(t(this.value))}isOk(){return!0}},M=class e{constructor(){this.value=void 0}unwrap(){throw Error(`Trying to unwrap a None value`)}unwrap_or(e){return e}and_then(t){return new e}map(t){return new e}isOk(){return!1}};const Hc=[`null`,`true`,`false`],Uc=[`-`,`+`],Wc=`public`;let N=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}({}),P=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 Gc=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b||kl(this.declarationNode.parent).unwrap_or(void 0)!==N.Project?[new A(k.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]:[]}validateName(e){return e?[new A(k.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new A(k.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new A(k.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof T)return[new A(k.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return G(e.callee)||t.push(new A(k.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 A(k.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};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.Note=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e}({});function Kc(e){return`${F.Schema}:${e}`}function qc(e){return`${F.Table}:${e}`}function Jc(e){return`${F.Column}:${e}`}function Yc(e){return`${F.Enum}:${e}`}function Xc(e){return`${F.EnumField}:${e}`}function Zc(e){return`${F.TableGroup}:${e}`}function Qc(e){return`${F.TableGroupField}:${e}`}function $c(e){return`${F.Note}:${e}`}function el(e){return`${F.TablePartial}:${e}`}function tl(e){return`${F.PartialInjection}:${e}`}function nl(e,t){switch(t){case F.Column:return Jc(e);case F.Enum:return Yc(e);case F.EnumField:return Xc(e);case F.Schema:return Kc(e);case F.Table:return qc(e);case F.TableGroup:return Zc(e);case F.TableGroupField:return Qc(e);case F.TablePartial:return el(e);case F.PartialInjection:return tl(e);default:throw Error(`Unreachable`)}}function rl(e){let[t,n]=e.split(`:`);return Object.values(F).includes(t)?new j({name:n,kind:t}):new M}var il=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)}},al=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new A(k.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?_l(e)?[]:[new A(k.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new A(k.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new A(k.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(Cc,{declaration:this.declarationNode,symbolTable:new il});let{name:t}=this.declarationNode,n=R(t);if(n.isOk()){let r=n.unwrap(),i=r.pop(),a=xl(r,this.publicSymbolTable,this.symbolFactory),o=Yc(i);a.has(o)&&e.push(new A(k.DUPLICATE_NAME,`Enum name ${i} already exists in schema '${r.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}return e}validateSettingList(e){return e?[new A(k.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof w)return this.validateFields([e]);let[t,n]=h(e.body,e=>e instanceof w);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.length===0?[new A(k.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)]:e.flatMap(e=>{let t=[];e.callee&&!K(e.callee)&&t.push(new A(k.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,e.callee));let n=[...e.args];return m(n)instanceof E?(t.push(...this.validateFieldSettings(m(n))),n.pop()):n[0]instanceof E&&(t.push(...this.validateFieldSettings(n[0])),n.shift()),n.length>0&&t.push(...n.map(e=>new A(k.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=L(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 A(k.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{G(e.value)||n.push(new A(k.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new A(k.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(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}registerField(e){if(e.callee&&K(e.callee)){let t=V(e.callee).unwrap(),n=Xc(t),r=this.symbolFactory.create(wc,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new A(k.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,e),new A(k.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,r.declaration)]}i.set(n,r)}return[]}},ol=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new A(k.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof b)return[e];let t=kl(this.declarationNode.parent).unwrap_or(void 0);return t&&[N.Table,N.TablePartial].includes(t)?[]:[e]}validateName(e){return e?[new A(k.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new A(k.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new A(k.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof w)return[new A(k.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=h(e.body,e=>e instanceof w);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 m(n)instanceof E&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof D;)e.argumentList&&!jl(e.argumentList).isOk()&&t.push(new A(k.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;jl(e).isOk()||t.push(new A(k.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=L(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 A(k.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{G(t.value)||n.push(new A(k.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new A(k.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{I(t.value)||n.push(new A(k.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new A(k.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{K(e.value)||n.push(new A(k.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new A(k.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},sl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return!(this.declarationNode.parent instanceof b)&&![N.Table,N.TableGroup,N.TablePartial,N.Project].includes(kl(this.declarationNode.parent).unwrap_or(void 0))?[new A(k.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 b))return e?[new A(k.UNEXPECTED_NAME,`A Note shouldn't have a name`,e)]:[];if(!e)return[new A(k.INVALID_NAME,`Sticky note must have a name`,this.declarationNode)];let t=R(e);if(!t.isOk())return[new A(k.INVALID_NAME,`Invalid name for sticky note `,this.declarationNode)];let n=t.unwrap().join(`.`),r=$c(n);return this.publicSymbolTable.has(r)?[new A(k.DUPLICATE_NAME,`Sticky note "${n}" has already been defined`,e)]:(this.publicSymbolTable.set(r,this.declarationNode.symbol),[])}validateAlias(e){return e?[new A(k.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new A(k.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof w)return this.validateFields([e]);let[t,n]=h(e.body,e=>e instanceof w);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new A(k.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new A(k.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),G(e[0].callee)||t.push(new A(k.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 A(k.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(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},cl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new A(k.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?yl(e)?[]:[new A(k.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new A(k.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new A(k.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof w)return[new A(k.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof w);return[...t.map(e=>new A(k.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(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},ll=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b?[]:[new A(k.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?yl(e)?[]:[new A(k.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new A(k.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new A(k.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof w)return this.validateFields([e]);let[t,n]=h(e.body,e=>e instanceof w);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new A(k.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 A(k.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Ml(e.callee)&&t.push(new A(k.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Ml(e.callee)){let n=z(e.callee.leftExpression).unwrap_or({variables:[],tupleElements:[]}),r=n.variables.length+Math.min(n.tupleElements.length,1),i=z(e.callee.rightExpression).unwrap_or({variables:[],tupleElements:[]}),a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new A(k.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new A(k.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Nl(e.callee)&&t.push(new A(k.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(m(n)instanceof E){let e=this.validateFieldSettings(m(n));t.push(...e),n.pop()}else n[0]instanceof E&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new A(k.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){let t=L(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 A(k.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{ul(t.value)||n.push(new A(k.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 A(k.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Cl(e.value)||n.push(new A(k.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))});break;default:t.forEach(t=>n.push(new A(k.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}};function ul(e){if(!(K(e)&&e.expression.variable.kind!==g.QUOTED_STRING)&&!(e instanceof lc))return!1;let t;if(t=e instanceof lc?Gl(e).unwrap_or(``):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 dl=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new A(k.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof vc?[new A(k.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:_l(e)?[]:[new A(k.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new A(k.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?vl(e)?[]:[new A(k.INVALID_ALIAS,`Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=L(e),n=t.getErrors();return Ks(t.getValue(),(e,t)=>{switch(t){case P.HeaderColor:e.length>1&&n.push(...e.map(e=>new A(k.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Cl(e.value)||n.push(new A(k.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case P.Note:e.length>1&&n.push(...e.map(e=>new A(k.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{G(e.value)||n.push(new A(k.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new A(k.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(Tc,{declaration:this.declarationNode,symbolTable:new il});let{name:t,alias:n}=this.declarationNode,r=R(t);if(r.isOk()){let n=[...r.unwrap()],i=n.pop(),a=xl(n,this.publicSymbolTable,this.symbolFactory),o=qc(i);a.has(o)&&e.push(new A(k.DUPLICATE_NAME,`Table name '${i}' already exists in schema '${n.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}if(n&&yl(n)&&!fl(n.expression.variable.value,r.unwrap_or([]))){let r=V(n).unwrap(),i=qc(r);this.publicSymbolTable.has(i)&&e.push(new A(k.DUPLICATE_NAME,`Table name '${r}' already exists`,t)),this.publicSymbolTable.set(i,this.declarationNode.symbol)}return e}validateBody(e){if(!e)return[];if(e instanceof w)return[new A(k.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof w);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 A(k.INVALID_COLUMN,`A column must have a type`,e.callee)),K(e.callee)||t.push(new A(k.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Ol(e.args[0])&&t.push(new A(k.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(!bl(e.callee))t.push(new A(k.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee));else{let t=B(e.callee.expression).unwrap_or(``),n=this.symbolFactory.create(Ac,{symbolTable:new il,declaration:e}),r=tl(t),i=this.declarationNode.symbol.symbolTable;if(i.has(r)){let n=i.get(r);return[new A(k.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,e),new A(k.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 A(k.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t};return e.flatMap(e=>e.callee instanceof S&&e.callee.op?.value===`~`?n(e):t(e))}registerField(e){if(e.callee&&K(e.callee)){let t=V(e.callee).unwrap(),n=Jc(t),r=this.symbolFactory.create(Ec,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new A(k.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new A(k.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}i.set(n,r)}return[]}validateFieldSetting(e){if(!e.slice(0,-1).every(Hl)||!e.slice(-1).every(e=>Hl(e)||e instanceof E))return[...e.map(e=>new A(k.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e))];if(e.length===0)return[];let t;m(e)instanceof E&&(t=e.pop());let n=L(t),r=n.getErrors(),i=n.getValue();e.forEach(e=>{let t=V(e).unwrap_or(``).toLowerCase();if(t!==`pk`&&t!==`unique`){r.push(new A(k.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[P.PK]||[],o=i[P.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ks(i,(e,t)=>{switch(t){case P.Note:e.length>1&&r.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{G(e.value)||r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case P.Ref:e.forEach(e=>{El(e.value)||r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case P.PrimaryKey:e.length>1&&r.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{I(e.value)||r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case P.PK:e.length>1&&r.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof uc&&!I(e.value)&&r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case P.NotNull:{e.length>1&&r.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=i[P.Null]||[];e.length>=1&&t.length>=1&&r.push(...[...e,...t].map(e=>new A(k.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{I(e.value)||r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case P.Null:e.length>1&&r.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{I(e.value)||r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case P.Unique:e.length>1&&r.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof uc&&!I(e.value)&&r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case P.Increment:e.length>1&&r.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof uc&&!I(e.value)&&r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case P.Default:e.length>1&&r.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{wl(e.value)||r.push(new A(k.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 P.Check:e.forEach(e=>{e.value instanceof C||r.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new A(k.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),r}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===`note`);return n.length>1&&t.push(...n.map(e=>new A(k.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function fl(e,t){return t.length===1&&e===t[0]}var pl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new A(k.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?yl(e)?[]:[new A(k.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new A(k.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new A(k.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Dc,{declaration:this.declarationNode,symbolTable:new il});let t=R(e);if(t.isOk()){let n=t.unwrap(),r=n.pop(),i=xl(n,this.publicSymbolTable,this.symbolFactory),a=Zc(r);if(i.has(a))return[new A(k.DUPLICATE_NAME,`TableGroup name '${r}' already exists`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=L(e),n=t.getErrors();return Ks(t.getValue(),(e,t)=>{switch(t){case`color`:e.length>1&&n.push(...e.map(e=>new A(k.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{Cl(e.value)||n.push(new A(k.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 A(k.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.filter(e=>!G(e.value)).forEach(e=>{n.push(new A(k.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new A(k.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)));break}}),n}validateBody(e){if(!e)return[];if(e instanceof w)return[new A(k.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof w);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&!R(e.callee).isOk()&&t.push(new A(k.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 A(k.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(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===`note`);return n.length>1&&t.push(...n.map(e=>new A(k.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}registerField(e){if(e.callee&&K(e.callee)){let t=V(e.callee).unwrap(),n=Qc(t),r=this.symbolFactory.create(Oc,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new A(k.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,e),new A(k.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,r.declaration)]}i.set(n,r)}return[]}},ml=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new A(k.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?yl(e)?[]:[new A(k.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new A(k.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new A(k.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=L(e),n=t.getErrors();return Ks(t.getValue(),(e,t)=>{switch(t){case P.HeaderColor:e.length>1&&n.push(...e.map(e=>new A(k.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Cl(e.value)||n.push(new A(k.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case P.Note:e.length>1&&n.push(...e.map(e=>new A(k.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{G(e.value)||n.push(new A(k.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new A(k.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(kc,{declaration:this.declarationNode,symbolTable:new il});let t=R(e);if(!t.isOk())return[];let n=t.unwrap(),r=n.pop(),i=xl(n,this.publicSymbolTable,this.symbolFactory),a=el(r);return i.has(a)?[new A(k.DUPLICATE_NAME,`TablePartial name '${r}' already exists`,e)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(e){if(!e)return[];if(e instanceof w)return[new A(k.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof w);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 A(k.INVALID_COLUMN,`A column must have a type`,e.callee)),K(e.callee)||t.push(new A(k.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Ol(e.args[0])&&t.push(new A(k.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||!K(e.callee))return[];let t=V(e.callee).unwrap(),n=Jc(t),r=this.symbolFactory.create(Ec,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new A(k.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new A(k.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}return i.set(n,r),[]}validateFieldSetting(e){let t=m(e);if(!e.slice(0,-1).every(Hl)||!(Hl(t)||t instanceof E))return[...e.map(e=>new A(k.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e))];if(e.length===0)return[];let n;m(e)instanceof E&&(n=e.pop());let r=L(n),i=r.getErrors(),a=r.getValue();e.forEach(e=>{let t=V(e).unwrap_or(``).toLowerCase();if(t!==P.PK&&t!==P.Unique){i.push(new A(k.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[P.PK]||[],s=a[P.PrimaryKey]||[];return o.length>=1&&s.length>=1&&i.push(...[...o,...s].map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ks(a,(e,t)=>{switch(t){case P.Note:e.length>1&&i.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{G(e.value)||i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case P.Ref:e.forEach(e=>{El(e.value)||i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case P.PrimaryKey:e.length>1&&i.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{I(e.value)||i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case P.PK:e.length>1&&i.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof uc&&!I(e.value)&&i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case P.NotNull:{e.length>1&&i.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=a[P.Null]||[];e.length>=1&&n.length>=1&&i.push(...[...e,...n].map(e=>new A(k.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{I(e.value)||i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case P.Null:e.length>1&&i.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{I(e.value)||i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case P.Unique:e.length>1&&i.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof uc&&!I(e.value)&&i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case P.Increment:e.length>1&&i.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof uc&&!I(e.value)&&i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case P.Default:e.length>1&&i.push(...e.map(e=>new A(k.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{wl(e.value)||i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case P.Check:e.forEach(e=>{e.value instanceof C||i.push(new A(k.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>i.push(new A(k.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),i}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===N.Note);return n.length>1&&t.push(...n.map(e=>new A(k.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}},hl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new A(k.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof b)return[e];let t=kl(this.declarationNode.parent).unwrap_or(void 0);return t&&[N.Table,N.TablePartial].includes(t)?[]:[e]}validateName(e){return e?[new A(k.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new A(k.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new A(k.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof w)return[new A(k.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=h(e.body,e=>e instanceof w);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 m(n)instanceof E&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof C))&&t.push(new A(k.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=L(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 A(k.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{G(t.value)||n.push(new A(k.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new A(k.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(gl(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}};function gl(e){switch(e.type.value.toLowerCase()){case N.Enum:return al;case N.Table:return dl;case N.TableGroup:return pl;case N.Project:return cl;case N.Ref:return ll;case N.Note:return sl;case N.Indexes:return ol;case N.TablePartial:return ml;case N.Check:return hl;default:return Gc}}function _l(e){return!!R(e).unwrap_or(!1)}function vl(e){return yl(e)}function yl(e){return e instanceof O&&e.expression instanceof gc}function bl(e){return e instanceof S&&e.op?.value===`~`&&K(e.expression)}function xl(e,t,n){e[0]===`public`&&(e=e.slice(1));let r=t;for(let t of e){let e,i=Kc(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 il;let t=n.create(Sc,{symbolTable:e});r.set(i,t)}r=e}return r}function Sl(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function Cl(e){if(!(e instanceof O)||!(e.expression instanceof hc)||e.expression.literal?.kind!==g.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(!Fc(t[e]))return!1;return!0}function I(e){return e===void 0}function wl(e){if(G(e)||Tl(e)||Hl(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof S&&Uc.includes(e.op?.value)&&Tl(e.expression)||e instanceof C)return!0;if(!e||!Wl(e))return!1;let t=Al(e).unwrap();return t.length===2||t.length===3}function Tl(e){return e instanceof S?Uc.includes(e.op.value)?Tl(e.expression):!1:e instanceof O&&e.expression instanceof hc&&e.expression.literal?.kind===g.NUMERIC_LITERAL}function El(e){if(!(e instanceof S)||!Sl(e.op?.value))return!1;let t=R(e.expression).unwrap_or(void 0);return t!==void 0&&t.length>0}function Dl(e){return e instanceof pc&&e.elementList.every(K)}function Ol(e){if(!(e instanceof D||Ul(e)||e instanceof O||e instanceof vc))return!1;for(;e instanceof D||e instanceof vc;)if(e instanceof D){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Tl(e)||G(e)||Hl(e)))return!1;e=e.callee}else if(e instanceof vc){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Tl(e.name)))return!1;e=e.array}let t=R(e).unwrap_or(void 0);return t!==void 0&&t.length>0}function L(e){let t={},n=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof O){n.push(new A(k.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let r=Gl(e.name).unwrap_or(void 0)?.toLowerCase();r&&(t[r]===void 0?t[r]=[e]:t[r].push(e))}),new Mc(t,n)):new Mc({})}function kl(e){let t=e?.type?.value.toLowerCase();switch(t){case N.Enum:case N.Table:case N.Indexes:case N.Note:case N.Project:case N.Ref:case N.TableGroup:case N.TablePartial:case N.Check:return new j(t);default:return new M}}function Al(e){if(!e)return new M;if(!Ul(e))return new j([e]);let t=Al(e.leftExpression).unwrap_or(void 0);return t?(t.push(e.rightExpression),new j(t)):new M}function R(e){if(e===void 0)return new M;let t=Al(e).unwrap_or(void 0);if(!t)return new M;let n=[];for(let e of t){let t=B(e).unwrap_or(void 0);if(typeof t!=`string`)return new M;n.push(t)}return new j(n)}function z(e){if(e===void 0)return new M;let t=Al(e).unwrap_or(void 0);if(!t||t.length===0)return new M;let n=[];if(!K(m(t))){let e=t.pop();if(Dl(e))n=e.elementList;else return new M}let r=t;return r.every(K)?new j({variables:r,tupleElements:n}):new M}function B(e){return K(e)?new j(e.expression.variable.value):new M}function jl(e){return Pl(e)?e instanceof C?new j({functional:[e],nonFunctional:[]}):new j({functional:[],nonFunctional:[e]}):e instanceof pc&&e.elementList.every(Pl)?new j({functional:e.elementList.filter(e=>e instanceof C),nonFunctional:e.elementList.filter(K)}):new M}function V(e){let t=e?.expression.variable?.value;return t===void 0?new M:new j(t)}function H(e){return G(e)?e.expression instanceof gc?new j(e.expression.variable.value):new j(e.expression.literal.value):new M}function Ml(e){return!(e instanceof dc)||!Sl(e.op?.value)?!1:z(e.leftExpression).and_then(()=>z(e.rightExpression)).unwrap_or(void 0)!==void 0}function Nl(e){let t=z(e.leftExpression),n=z(e.rightExpression);if(!t.isOk()||!n.isOk())return!1;let{tupleElements:r}=t.unwrap(),{tupleElements:i}=n.unwrap();return r?.length===i?.length}function Pl(e){return e instanceof O&&e.expression instanceof gc||e instanceof C}function Fl(e,t,n){if(!e||!Hl(e)||t.length===0)return new M;let r=[...t],i=Vl(e).unwrap(),a=r.pop();if(!(a instanceof T))return new M;let o=m(r)instanceof E?r.pop():void 0;if(r.length===3){let e=Vl(r[1]).value;return!e||!Il(e)?new M:new j(n.create(x,{type:i,name:r[0],as:e,alias:r[2],attributeList:o,body:a}))}return r.length===1?new j(n.create(x,{type:i,name:r[0],attributeList:o,body:a})):r.length===0?new j(n.create(x,{type:i,attributeList:o,body:a})):new M}function Il(e){return e?.kind===g.IDENTIFIER&&e.value.toLowerCase()===`as`}function U(e){e&&(e instanceof _?Ll(e):Rl(e))}function Ll(e){e.kind!==g.EOF&&(e.isInvalid=!0)}function Rl(e){if(e instanceof x)U(e.type),U(e.name),U(e.as),U(e.alias),U(e.bodyColon),U(e.attributeList),U(e.body);else if(e instanceof lc)e.identifiers.forEach(U);else if(e instanceof uc)U(e.name),U(e.colon),U(e.value);else if(e instanceof S)U(e.op),U(e.expression);else if(e instanceof dc)U(e.leftExpression),U(e.op),U(e.rightExpression);else if(e instanceof fc)U(e.op),U(e.expression);else if(e instanceof T)U(e.blockOpenBrace),e.body.forEach(U),U(e.blockCloseBrace);else if(e instanceof E)U(e.listOpenBracket),e.commaList.forEach(U),e.elementList.forEach(U),U(e.listCloseBracket);else if(e instanceof pc)U(e.tupleOpenParen),e.commaList.forEach(U),e.elementList.forEach(U),U(e.tupleCloseParen);else if(e instanceof D)U(e.callee),U(e.argumentList);else if(e instanceof w)U(e.callee),e.args.forEach(U);else if(e instanceof O)U(e.expression);else if(e instanceof C)U(e.value);else if(e instanceof gc)U(e.variable);else if(e instanceof hc)U(e.literal);else if(e instanceof mc)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof vc)U(e.array),U(e.indexer);else if(e instanceof b)e.body.forEach(U),U(e.eof);else if(!(e instanceof _c))throw Error(`Unreachable case in markInvalidNode`)}function zl(e){return!!e?.isInvalid}function W(...e){return e.filter(e=>e!==void 0)}function Bl(e){if(e instanceof b)return W(...e.body,e.eof);if(e instanceof x)return W(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof uc)return W(e.name,e.colon,e.value);if(e instanceof lc)return e.identifiers;if(e instanceof hc)return e.literal?[e.literal]:[];if(e instanceof gc)return W(e.variable);if(e instanceof S)return W(e.op,e.expression);if(e instanceof dc)return W(e.leftExpression,e.op,e.rightExpression);if(e instanceof fc)return W(e.expression,e.op);if(e instanceof C)return W(e.value);if(e instanceof w)return W(e.callee,...e.args);if(e instanceof T)return W(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof E)return W(e.listOpenBracket,...Rc(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof pc)return W(e.tupleOpenParen,...Rc(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof D)return W(e.callee,e.argumentList);if(e instanceof O)return W(e.expression);if(e instanceof vc)return W(e.array,e.indexer);throw e instanceof mc?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Vl(e){return K(e)?new j(e.expression.variable):new M}function G(e){return e instanceof O&&(e.expression instanceof gc&&e.expression.variable instanceof _&&e.expression.variable.kind===g.QUOTED_STRING||e.expression instanceof hc&&e.expression.literal?.kind===g.STRING_LITERAL)}function K(e){return e instanceof O&&e.expression instanceof gc&&e.expression.variable instanceof _}function Hl(e){return e instanceof O&&e.expression instanceof gc&&e.expression.variable?.kind===g.IDENTIFIER}function Ul(e){return e instanceof dc&&e.leftExpression instanceof v&&e.rightExpression instanceof v&&e.op?.value===`.`}function Wl(e){return K(e)?!0:Ul(e)&&K(e.rightExpression)&&Wl(e.leftExpression)}function Gl(e){if(e===void 0)return new M;let t=e.identifiers.map(e=>e.value).join(` `);return t===``?new M:new j(t)}function Kl(e){return R(e.name).map(e=>e.join(`.`))}var ql=class{constructor(e){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
|
|
2
|
+
`?(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 _.create(e,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),t)}lex(){return this.scanTokens(),this.tokens.push(_.create(g.EOF,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new Mc(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(g.SPACE);break;case`\r`:break;case`
|
|
3
|
+
`:this.addToken(g.NEWLINE);break;case` `:this.addToken(g.TAB);break;case`,`:this.addToken(g.COMMA);break;case`(`:this.addToken(g.LPAREN);break;case`)`:this.addToken(g.RPAREN);break;case`[`:this.addToken(g.LBRACKET);break;case`]`:this.addToken(g.RBRACKET);break;case`{`:this.addToken(g.LBRACE);break;case`}`:this.addToken(g.RBRACE);break;case`;`:this.addToken(g.SEMICOLON);break;case`:`:this.addToken(g.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;default:if(ec(e)){this.operator(e);break}if(Nc(e)){this.identifier();break}if(Pc(e)){this.numericLiteralOrIdentifier();break}this.addToken(g.OP,!0),this.errors.push(new A(k.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(g.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)$s(i)?(t.push(i),i.kind===g.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&&zl(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];zl(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(`
|
|
4
|
+
`))&&!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 A(k.UNEXPECTED_EOF,`EOF reached while parsing`,t));return}if(this.check(`
|
|
5
|
+
`)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new A(k.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(_.create(e,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(g.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(g.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(g.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(g.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(g.SINGLE_LINE_COMMENT,`
|
|
6
|
+
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(g.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Ic(this.peek());)this.advance();this.addToken(g.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(g.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(g.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=t?1:0,e>1)break;if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(g.NUMERIC_LITERAL);if(!t&&!Ic(this.peek()))return this.addToken(g.NUMERIC_LITERAL);if(!t&&!Pc(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||Ic(this.peek()));)this.advance();let e=this.createToken(g.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new A(k.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&Ic(this.peek());)this.advance();let e=this.createToken(g.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&Ic(this.peek());)this.advance();this.addToken(g.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
7
|
`)&&this.advance(),``;case`
|
|
8
8
|
`:return``;case`t`:return` `;case`n`:return`
|
|
9
|
-
`;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()||!kc(this.peek()))return this.errors.push(new R(L.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`,Hs.create(j.STRING_LITERAL,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 Zl=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({});var Ql=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===Zl.ListExpression&&(this.numberOfNestedLBrackets+=1),e===Zl.GroupExpression&&(this.numberOfNestedLParens+=1),e===Zl.BlockExpression&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===Zl.ListExpression&&--this.numberOfNestedLBrackets,e===Zl.GroupExpression&&--this.numberOfNestedLParens,e===Zl.BlockExpression&&--this.numberOfNestedLBraces,e}top(){return xs(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 j.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[Zl.GroupExpression,Zl.ListExpression].includes(e));break;case j.RPAREN:if(this.isWithinGroupExpressionContext())return Zl.GroupExpression;break;case j.RBRACE:if(this.isWithinBlockExpressionContext())return Zl.BlockExpression;break;case j.RBRACKET:if(this.isWithinListExpressionContext())return Zl.ListExpression;break;default:break}}},$l=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}},G=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},eu=class{constructor(e,t){this.current=0,this.errors=[],this.contextStack=new Ql,this.synchronizeProgram=()=>{let e=this.peek();e.kind===j.EOF?this.logError(e,L.UNEXPECTED_EOF,`Unexpected EOF`):W(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Il(e)||this.check(j.COLON,j.LBRACE,j.LBRACKET))break;W(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(j.COLON,j.LBRACE,j.LBRACKET))break;W(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Zl.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(rc,e);try{this.consume(`Expect an opening brace '{'`,j.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof G))throw e;if(!this.canHandle(e))throw new G(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(j.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof G))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new G(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,j.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof G))throw e;if(!this.canHandle(e))throw new G(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(j.RBRACE))for(W(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(j.RBRACE)||Ws(this.previous(),e))break;W(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Zl.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(ac,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ic,e);try{this.consume(`Expect an opening parenthesis '('`,j.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof G))throw e;if(!this.canHandle(e))throw new G(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(j.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof G))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new G(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(j.RPAREN);)try{this.consume(`Expect a comma ','`,j.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof G))throw t;if(t.partialNode instanceof M&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new G(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,j.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof G))throw e;if(!this.canHandle(e))throw new G(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(j.RPAREN,j.COMMA))break;W(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Zl.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(I,e);try{this.consume(`Expect an opening bracket '['`,j.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof G))throw e;if(!this.canHandle(e))throw new G(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(j.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof G))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new G(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(j.RBRACKET);)try{this.consume(`Expect a comma ','`,j.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof G))throw n;if(n.partialNode instanceof M&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new G(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,j.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof G))throw e;if(!this.canHandle(e))throw new G(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(j.COMMA,j.RBRACKET))break;W(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(j.COMMA,j.RBRACKET,j.COLON))break;W(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(j.COMMA,j.RBRACKET))break;W(e),this.advance()}},this.tokens=e,this.nodeFactory=new $l(t)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===j.EOF}advance(){return this.isAtEnd()?xs(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?xs(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(),L.UNEXPECTED_TOKEN,e),new G(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(W(this.peek()),this.logError(this.advance(),L.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)W(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(Xs,{body:e,eof:t});return this.gatherInvalid(),new Tc({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 G))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(P,e);try{this.consume(`Expect an identifier`,j.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof G?new G(e.token,t(),e.handlerContext):e}if(!this.check(j.COLON,j.LBRACE,j.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof G))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new G(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Il(this.peek()))if(e.as=this.advance(),this.check(j.COLON,j.LBRACE,j.LBRACKET))this.logError(this.peek(),L.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof G))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new G(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(j.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof G?(e.attributeList=n.partialNode,new G(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,j.LBRACE,j.COLON))return t();try{if(this.match(j.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof P?(W(t),this.logError(t,L.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 G?(e.body=n.partialNode,new G(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(P,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(P,e);try{this.consume(`Expect an identifier`,j.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof G?(e.type=n.partialNode,new G(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,j.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof G?(e.bodyColon=n.partialNode,new G(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof P?this.errors.push(new R(L.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof G?(e.body=n.partialNode,new G(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(P,e)}expression(){let e={args:[]},t=()=>Fl(e.callee,e.args,this.nodeFactory).unwrap_or(this.nodeFactory.create(F,e));try{e.callee=this.normalExpression()}catch(n){throw n instanceof G?(e.callee=n.partialNode,new G(n.token,t(),n.handlerContext)):n}if(this.shouldStopExpression())return t();let n=e.callee;for(;!this.shouldStopExpression();){Gs(this.previous())||this.logError(n,L.MISSING_SPACES,`Expect a following space`);try{n=this.normalExpression(),e.args.push(n)}catch(r){throw r instanceof G?(n=r.partialNode,e.args.push(n),new G(r.token,t(),r.handlerContext)):r}}return t()}shouldStopExpression(){if(this.isAtEnd()||Us(this.previous()))return!0;let e=this.peek().kind;return e===j.RBRACE||e===j.RBRACKET||e===j.RPAREN||e===j.COMMA||e===j.COLON}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===j.LPAREN){let{left:r}=ou(n);if(r<e||Ws(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(oc,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof G?(t=this.nodeFactory.create(oc,{callee:t,argumentList:e.partialNode}),new G(e.token,t,e.handlerContext)):e}}else if(n.kind===j.LBRACKET){if(Gs(this.previous()))break;try{t=this.nodeFactory.create(dc,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof G?(t=this.nodeFactory.create(dc,{expression:t,indexer:e.partialNode}),new G(e.token,t,e.handlerContext)):e}}else if(Vs(n)){let r=n,i=ou(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(tc,{expression:t,op:r})}else{let n=nu(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(ec,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof G?(t=this.nodeFactory.create(ec,{leftExpression:t,op:r,rightExpression:e.partialNode}),new G(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Vs(this.peek())){let t={};t.op=this.peek();let n=iu(t.op);if(n.right===null)throw this.logError(t.op,L.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new G(t.op,this.nodeFactory.create(uc,{pre:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof G?(t.expression=e.partialNode,new G(e.token,this.nodeFactory.create($s,t),e.handlerContext)):e}e=this.nodeFactory.create($s,t)}else if(e=this.extractOperand(),e instanceof uc)throw new G(this.peek(),this.nodeFactory.create(uc,{pre:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(j.NUMERIC_LITERAL,j.STRING_LITERAL,j.COLOR_LITERAL,j.QUOTED_STRING,j.IDENTIFIER)?this.primaryExpression():this.check(j.FUNCTION_EXPRESSION)?this.functionExpression():this.check(j.LBRACKET)?this.listExpression():this.check(j.LBRACE)?this.blockExpression():this.check(j.LPAREN)?this.tupleExpression():(this.peek().kind===j.EOF?this.logError(this.peek(),L.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),L.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(uc,{pre:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,j.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof G?new G(t.token,this.nodeFactory.create(nc,e),t.handlerContext):t}return this.nodeFactory.create(nc,e)}canBeField(){return this.peek().kind===j.IDENTIFIER&&this.peek(1).kind===j.COLON}primaryExpression(){if(this.match(j.COLOR_LITERAL,j.STRING_LITERAL,j.NUMERIC_LITERAL))return this.nodeFactory.create(lc,{expression:this.nodeFactory.create(sc,{literal:this.previous()})});if(this.match(j.QUOTED_STRING,j.IDENTIFIER))return this.nodeFactory.create(lc,{expression:this.nodeFactory.create(cc,{variable:this.previous()})});throw this.logError(this.peek(),L.UNEXPECTED_TOKEN,`Expect a variable or literal`),new G(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(j.COLON,j.RBRACKET,j.COMMA)){let t=this.peek();this.logError(t,L.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(Zs,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof G))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new G(t.token,this.nodeFactory.create(Qs,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(j.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(Qs,e)}attributeValue(){let e;try{e=this.peek().kind===j.IDENTIFIER&&this.peek(1).kind===j.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof G)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==j.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(j.COLON,j.COMMA,j.RBRACKET);)try{this.consume(`Expect an identifier`,j.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof G?new G(t.token,this.nodeFactory.create(Zs,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(Zs,{identifiers:e})}logError(e,t,n){this.errors.push(new R(t,n,e))}},tu={"+":{left:9,right:10},"*":{left:11,right:12},"-":{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 nu(e){return tu[e.value]||{left:null,right:null}}var ru={"+":{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 iu(e){return ru[e.value]||{left:null,right:null}}var au={"(":{left:14,right:null}};function ou(e){return au[e.value]||{left:null,right:null}}var su=class{constructor(e,t){this.ast=e,this.symbolFactory=t,this.publicSchemaSymbol=this.symbolFactory.create(hc,{symbolTable:new Qc}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){let e=[];this.ast.body.forEach(t=>{if(t.parent=this.ast,t.type===void 0)return;let n=new(ul(t))(t,this.publicSchemaSymbol.symbolTable,this.symbolFactory);e.push(...n.validate())});let t=this.ast.body.filter(e=>wl(e).unwrap_or(void 0)===B.Project);return t.length>1&&t.forEach(t=>e.push(new R(L.PROJECT_REDEFINED,`Only one project can exist`,t))),new Tc(this.ast,e)}},cu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return[]}},lu=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 F)return[];let t=e.body.filter(e=>e instanceof P);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}},uu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof rc?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof F)return[];let t=e.body.filter(e=>e instanceof F);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}},du=t(((e,t)=>{(function(){var n,r=`4.17.21`,i=200,a=`Unsupported core-js use. Try https://npms.io/search?q=ponyfill.`,o=`Expected a function`,s="Invalid `variable` option passed into `_.template`",c=`__lodash_hash_undefined__`,l=500,u=`__lodash_placeholder__`,d=1,f=2,p=4,m=1,h=2,g=1,_=2,v=4,y=8,ee=16,te=32,ne=64,b=128,re=256,ie=512,ae=30,oe=`...`,se=800,ce=16,le=1,ue=2,de=3,fe=1/0,pe=9007199254740991,me=17976931348623157e292,he=NaN,ge=4294967295,_e=ge-1,ve=ge>>>1,ye=[[`ary`,b],[`bind`,g],[`bindKey`,_],[`curry`,y],[`curryRight`,ee],[`flip`,ie],[`partial`,te],[`partialRight`,ne],[`rearg`,re]],be=`[object Arguments]`,xe=`[object Array]`,Se=`[object AsyncFunction]`,Ce=`[object Boolean]`,we=`[object Date]`,Te=`[object DOMException]`,Ee=`[object Error]`,De=`[object Function]`,Oe=`[object GeneratorFunction]`,ke=`[object Map]`,Ae=`[object Number]`,je=`[object Null]`,Me=`[object Object]`,Ne=`[object Promise]`,Pe=`[object Proxy]`,Fe=`[object RegExp]`,Ie=`[object Set]`,Le=`[object String]`,Re=`[object Symbol]`,ze=`[object Undefined]`,Be=`[object WeakMap]`,Ve=`[object WeakSet]`,He=`[object ArrayBuffer]`,Ue=`[object DataView]`,We=`[object Float32Array]`,Ge=`[object Float64Array]`,Ke=`[object Int8Array]`,qe=`[object Int16Array]`,Je=`[object Int32Array]`,Ye=`[object Uint8Array]`,Xe=`[object Uint8ClampedArray]`,Ze=`[object Uint16Array]`,Qe=`[object Uint32Array]`,$e=/\b__p \+= '';/g,et=/\b(__p \+=) '' \+/g,tt=/(__e\(.*?\)|\b__t\)) \+\n'';/g,nt=/&(?:amp|lt|gt|quot|#39);/g,rt=/[&<>"']/g,it=RegExp(nt.source),at=RegExp(rt.source),ot=/<%-([\s\S]+?)%>/g,st=/<%([\s\S]+?)%>/g,ct=/<%=([\s\S]+?)%>/g,lt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ut=/^\w*$/,dt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ft=/[\\^$.*+?()[\]{}|]/g,pt=RegExp(ft.source),mt=/^\s+/,ht=/\s/,gt=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,_t=/\{\n\/\* \[wrapped with (.+)\] \*/,vt=/,? & /,yt=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,bt=/[()=,{}\[\]\/\s]/,xt=/\\(\\)?/g,St=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Ct=/\w*$/,wt=/^[-+]0x[0-9a-f]+$/i,Tt=/^0b[01]+$/i,Et=/^\[object .+?Constructor\]$/,Dt=/^0o[0-7]+$/i,Ot=/^(?:0|[1-9]\d*)$/,kt=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,At=/($^)/,jt=/['\n\r\u2028\u2029\\]/g,Mt=`\\ud800-\\udfff`,Nt=`\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff`,Pt=`\\u2700-\\u27bf`,x=`a-z\\xdf-\\xf6\\xf8-\\xff`,Ft=`\\xac\\xb1\\xd7\\xf7`,It=`\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf`,Lt=`\\u2000-\\u206f`,Rt=` \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000`,zt=`A-Z\\xc0-\\xd6\\xd8-\\xde`,Bt=`\\ufe0e\\ufe0f`,Vt=Ft+It+Lt+Rt,Ht=`['’]`,S=`[`+Mt+`]`,Ut=`[`+Vt+`]`,Wt=`[`+Nt+`]`,Gt=`\\d+`,Kt=`[`+Pt+`]`,qt=`[`+x+`]`,Jt=`[^`+Mt+Vt+Gt+Pt+x+zt+`]`,Yt=`\\ud83c[\\udffb-\\udfff]`,Xt=`(?:`+Wt+`|`+Yt+`)`,Zt=`[^`+Mt+`]`,Qt=`(?:\\ud83c[\\udde6-\\uddff]){2}`,$t=`[\\ud800-\\udbff][\\udc00-\\udfff]`,en=`[`+zt+`]`,tn=`\\u200d`,nn=`(?:`+qt+`|`+Jt+`)`,rn=`(?:`+en+`|`+Jt+`)`,an=`(?:`+Ht+`(?:d|ll|m|re|s|t|ve))?`,on=`(?:`+Ht+`(?:D|LL|M|RE|S|T|VE))?`,sn=Xt+`?`,cn=`[`+Bt+`]?`,ln=`(?:`+tn+`(?:`+[Zt,Qt,$t].join(`|`)+`)`+cn+sn+`)*`,un=`\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])`,dn=`\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])`,fn=cn+sn+ln,pn=`(?:`+[Kt,Qt,$t].join(`|`)+`)`+fn,mn=`(?:`+[Zt+Wt+`?`,Wt,Qt,$t,S].join(`|`)+`)`,hn=RegExp(Ht,`g`),gn=RegExp(Wt,`g`),_n=RegExp(Yt+`(?=`+Yt+`)|`+mn+fn,`g`),vn=RegExp([en+`?`+qt+`+`+an+`(?=`+[Ut,en,`$`].join(`|`)+`)`,rn+`+`+on+`(?=`+[Ut,en+nn,`$`].join(`|`)+`)`,en+`?`+nn+`+`+an,en+`+`+on,dn,un,Gt,pn].join(`|`),`g`),yn=RegExp(`[`+tn+Mt+Nt+Bt+`]`),bn=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,xn=`Array.Buffer.DataView.Date.Error.Float32Array.Float64Array.Function.Int8Array.Int16Array.Int32Array.Map.Math.Object.Promise.RegExp.Set.String.Symbol.TypeError.Uint8Array.Uint8ClampedArray.Uint16Array.Uint32Array.WeakMap._.clearTimeout.isFinite.parseInt.setTimeout`.split(`.`),Sn=-1,C={};C[We]=C[Ge]=C[Ke]=C[qe]=C[Je]=C[Ye]=C[Xe]=C[Ze]=C[Qe]=!0,C[be]=C[xe]=C[He]=C[Ce]=C[Ue]=C[we]=C[Ee]=C[De]=C[ke]=C[Ae]=C[Me]=C[Fe]=C[Ie]=C[Le]=C[Be]=!1;var w={};w[be]=w[xe]=w[He]=w[Ue]=w[Ce]=w[we]=w[We]=w[Ge]=w[Ke]=w[qe]=w[Je]=w[ke]=w[Ae]=w[Me]=w[Fe]=w[Ie]=w[Le]=w[Re]=w[Ye]=w[Xe]=w[Ze]=w[Qe]=!0,w[Ee]=w[De]=w[Be]=!1;var Cn={À:`A`,Á:`A`,Â:`A`,Ã:`A`,Ä:`A`,Å:`A`,à:`a`,á:`a`,â:`a`,ã:`a`,ä:`a`,å:`a`,Ç:`C`,ç:`c`,Ð:`D`,ð:`d`,È:`E`,É:`E`,Ê:`E`,Ë:`E`,è:`e`,é:`e`,ê:`e`,ë:`e`,Ì:`I`,Í:`I`,Î:`I`,Ï:`I`,ì:`i`,í:`i`,î:`i`,ï:`i`,Ñ:`N`,ñ:`n`,Ò:`O`,Ó:`O`,Ô:`O`,Õ:`O`,Ö:`O`,Ø:`O`,ò:`o`,ó:`o`,ô:`o`,õ:`o`,ö:`o`,ø:`o`,Ù:`U`,Ú:`U`,Û:`U`,Ü:`U`,ù:`u`,ú:`u`,û:`u`,ü:`u`,Ý:`Y`,ý:`y`,ÿ:`y`,Æ:`Ae`,æ:`ae`,Þ:`Th`,þ:`th`,ß:`ss`,Ā:`A`,Ă:`A`,Ą:`A`,ā:`a`,ă:`a`,ą:`a`,Ć:`C`,Ĉ:`C`,Ċ:`C`,Č:`C`,ć:`c`,ĉ:`c`,ċ:`c`,č:`c`,Ď:`D`,Đ:`D`,ď:`d`,đ:`d`,Ē:`E`,Ĕ:`E`,Ė:`E`,Ę:`E`,Ě:`E`,ē:`e`,ĕ:`e`,ė:`e`,ę:`e`,ě:`e`,Ĝ:`G`,Ğ:`G`,Ġ:`G`,Ģ:`G`,ĝ:`g`,ğ:`g`,ġ:`g`,ģ:`g`,Ĥ:`H`,Ħ:`H`,ĥ:`h`,ħ:`h`,Ĩ:`I`,Ī:`I`,Ĭ:`I`,Į:`I`,İ:`I`,ĩ:`i`,ī:`i`,ĭ:`i`,į:`i`,ı:`i`,Ĵ:`J`,ĵ:`j`,Ķ:`K`,ķ:`k`,ĸ:`k`,Ĺ:`L`,Ļ:`L`,Ľ:`L`,Ŀ:`L`,Ł:`L`,ĺ:`l`,ļ:`l`,ľ:`l`,ŀ:`l`,ł:`l`,Ń:`N`,Ņ:`N`,Ň:`N`,Ŋ:`N`,ń:`n`,ņ:`n`,ň:`n`,ŋ:`n`,Ō:`O`,Ŏ:`O`,Ő:`O`,ō:`o`,ŏ:`o`,ő:`o`,Ŕ:`R`,Ŗ:`R`,Ř:`R`,ŕ:`r`,ŗ:`r`,ř:`r`,Ś:`S`,Ŝ:`S`,Ş:`S`,Š:`S`,ś:`s`,ŝ:`s`,ş:`s`,š:`s`,Ţ:`T`,Ť:`T`,Ŧ:`T`,ţ:`t`,ť:`t`,ŧ:`t`,Ũ:`U`,Ū:`U`,Ŭ:`U`,Ů:`U`,Ű:`U`,Ų:`U`,ũ:`u`,ū:`u`,ŭ:`u`,ů:`u`,ű:`u`,ų:`u`,Ŵ:`W`,ŵ:`w`,Ŷ:`Y`,ŷ:`y`,Ÿ:`Y`,Ź:`Z`,Ż:`Z`,Ž:`Z`,ź:`z`,ż:`z`,ž:`z`,IJ:`IJ`,ij:`ij`,Œ:`Oe`,œ:`oe`,ʼn:`'n`,ſ:`s`},wn={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},Tn={"&":`&`,"<":`<`,">":`>`,""":`"`,"'":`'`},En={"\\":`\\`,"'":`'`,"\n":`n`,"\r":`r`,"\u2028":`u2028`,"\u2029":`u2029`},Dn=parseFloat,On=parseInt,kn=typeof global==`object`&&global&&global.Object===Object&&global,An=typeof self==`object`&&self&&self.Object===Object&&self,jn=kn||An||Function(`return this`)(),Mn=typeof e==`object`&&e&&!e.nodeType&&e,Nn=Mn&&typeof t==`object`&&t&&!t.nodeType&&t,Pn=Nn&&Nn.exports===Mn,T=Pn&&kn.process,Fn=function(){try{return Nn&&Nn.require&&Nn.require(`util`).types||T&&T.binding&&T.binding(`util`)}catch{}}(),In=Fn&&Fn.isArrayBuffer,Ln=Fn&&Fn.isDate,Rn=Fn&&Fn.isMap,zn=Fn&&Fn.isRegExp,Bn=Fn&&Fn.isSet,Vn=Fn&&Fn.isTypedArray;function Hn(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)}function Un(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}function Wn(e,t){for(var n=-1,r=e==null?0:e.length;++n<r&&t(e[n],n,e)!==!1;);return e}function Gn(e,t){for(var n=e==null?0:e.length;n--&&t(e[n],n,e)!==!1;);return e}function Kn(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(!t(e[n],n,e))return!1;return!0}function qn(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}function Jn(e,t){return!!(e!=null&&e.length)&&ar(e,t,0)>-1}function Yn(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}function E(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}function Xn(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}function Zn(e,t,n,r){var i=-1,a=e==null?0:e.length;for(r&&a&&(n=e[++i]);++i<a;)n=t(n,e[i],i,e);return n}function Qn(e,t,n,r){var i=e==null?0:e.length;for(r&&i&&(n=e[--i]);i--;)n=t(n,e[i],i,e);return n}function $n(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 er=lr(`length`);function tr(e){return e.split(``)}function nr(e){return e.match(yt)||[]}function rr(e,t,n){var r;return n(e,function(e,n,i){if(t(e,n,i))return r=n,!1}),r}function ir(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}function ar(e,t,n){return t===t?Fr(e,t,n):ir(e,sr,n)}function or(e,t,n,r){for(var i=n-1,a=e.length;++i<a;)if(r(e[i],t))return i;return-1}function sr(e){return e!==e}function cr(e,t){var n=e==null?0:e.length;return n?pr(e,t)/n:he}function lr(e){return function(t){return t==null?n:t[e]}}function ur(e){return function(t){return e==null?n:e[t]}}function dr(e,t,n,r,i){return i(e,function(e,i,a){n=r?(r=!1,e):t(n,e,i,a)}),n}function fr(e,t){var n=e.length;for(e.sort(t);n--;)e[n]=e[n].value;return e}function pr(e,t){for(var r,i=-1,a=e.length;++i<a;){var o=t(e[i]);o!==n&&(r=r===n?o:r+o)}return r}function mr(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function hr(e,t){return E(t,function(t){return[t,e[t]]})}function gr(e){return e&&e.slice(0,zr(e)+1).replace(mt,``)}function _r(e){return function(t){return e(t)}}function vr(e,t){return E(t,function(t){return e[t]})}function yr(e,t){return e.has(t)}function br(e,t){for(var n=-1,r=e.length;++n<r&&ar(t,e[n],0)>-1;);return n}function xr(e,t){for(var n=e.length;n--&&ar(t,e[n],0)>-1;);return n}function Sr(e,t){for(var n=e.length,r=0;n--;)e[n]===t&&++r;return r}var Cr=ur(Cn),wr=ur(wn);function Tr(e){return`\\`+En[e]}function Er(e,t){return e==null?n:e[t]}function Dr(e){return yn.test(e)}function Or(e){return bn.test(e)}function kr(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n}function Ar(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function jr(e,t){return function(n){return e(t(n))}}function Mr(e,t){for(var n=-1,r=e.length,i=0,a=[];++n<r;){var o=e[n];(o===t||o===u)&&(e[n]=u,a[i++]=n)}return a}function Nr(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}function Pr(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=[e,e]}),n}function Fr(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function Ir(e,t,n){for(var r=n+1;r--;)if(e[r]===t)return r;return r}function Lr(e){return Dr(e)?Vr(e):er(e)}function Rr(e){return Dr(e)?Hr(e):tr(e)}function zr(e){for(var t=e.length;t--&&ht.test(e.charAt(t)););return t}var Br=ur(Tn);function Vr(e){for(var t=_n.lastIndex=0;_n.test(e);)++t;return t}function Hr(e){return e.match(_n)||[]}function Ur(e){return e.match(vn)||[]}var Wr=(function e(t){t=t==null?jn:Wr.defaults(jn.Object(),t,Wr.pick(jn,xn));var ht=t.Array,yt=t.Date,Mt=t.Error,Nt=t.Function,Pt=t.Math,x=t.Object,Ft=t.RegExp,It=t.String,Lt=t.TypeError,Rt=ht.prototype,zt=Nt.prototype,Bt=x.prototype,Vt=t[`__core-js_shared__`],Ht=zt.toString,S=Bt.hasOwnProperty,Ut=0,Wt=function(){var e=/[^.]+$/.exec(Vt&&Vt.keys&&Vt.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}(),Gt=Bt.toString,Kt=Ht.call(x),qt=jn._,Jt=Ft(`^`+Ht.call(S).replace(ft,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`),Yt=Pn?t.Buffer:n,Xt=t.Symbol,Zt=t.Uint8Array,Qt=Yt?Yt.allocUnsafe:n,$t=jr(x.getPrototypeOf,x),en=x.create,tn=Bt.propertyIsEnumerable,nn=Rt.splice,rn=Xt?Xt.isConcatSpreadable:n,an=Xt?Xt.iterator:n,on=Xt?Xt.toStringTag:n,sn=function(){try{var e=gs(x,`defineProperty`);return e({},``,{}),e}catch{}}(),cn=t.clearTimeout!==jn.clearTimeout&&t.clearTimeout,ln=yt&&yt.now!==jn.Date.now&&yt.now,un=t.setTimeout!==jn.setTimeout&&t.setTimeout,dn=Pt.ceil,fn=Pt.floor,pn=x.getOwnPropertySymbols,mn=Yt?Yt.isBuffer:n,_n=t.isFinite,vn=Rt.join,yn=jr(x.keys,x),bn=Pt.max,Cn=Pt.min,wn=yt.now,Tn=t.parseInt,En=Pt.random,kn=Rt.reverse,An=gs(t,`DataView`),Mn=gs(t,`Map`),Nn=gs(t,`Promise`),T=gs(t,`Set`),Fn=gs(t,`WeakMap`),er=gs(x,`create`),tr=Fn&&new Fn,ur={},Fr=Zs(An),Vr=Zs(Mn),Hr=Zs(Nn),Gr=Zs(T),Kr=Zs(Fn),qr=Xt?Xt.prototype:n,Jr=qr?qr.valueOf:n,Yr=qr?qr.toString:n;function D(e){if(J(e)&&!K(e)&&!(e instanceof O)){if(e instanceof Qr)return e;if(S.call(e,`__wrapped__`))return $s(e)}return new Qr(e)}var Xr=function(){function e(){}return function(t){if(!q(t))return{};if(en)return en(t);e.prototype=t;var r=new e;return e.prototype=n,r}}();function Zr(){}function Qr(e,t){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!t,this.__index__=0,this.__values__=n}D.templateSettings={escape:ot,evaluate:st,interpolate:ct,variable:``,imports:{_:D}},D.prototype=Zr.prototype,D.prototype.constructor=D,Qr.prototype=Xr(Zr.prototype),Qr.prototype.constructor=Qr;function O(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=ge,this.__views__=[]}function $r(){var e=new O(this.__wrapped__);return e.__actions__=Oo(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=Oo(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=Oo(this.__views__),e}function ei(){if(this.__filtered__){var e=new O(this);e.__dir__=-1,e.__filtered__=!0}else e=this.clone(),e.__dir__*=-1;return e}function ti(){var e=this.__wrapped__.value(),t=this.__dir__,n=K(e),r=t<0,i=n?e.length:0,a=xs(0,i,this.__views__),o=a.start,s=a.end,c=s-o,l=r?s:o-1,u=this.__iteratees__,d=u.length,f=0,p=Cn(c,this.__takeCount__);if(!n||!r&&i==c&&p==c)return co(e,this.__actions__);var m=[];outer:for(;c--&&f<p;){l+=t;for(var h=-1,g=e[l];++h<d;){var _=u[h],v=_.iteratee,y=_.type,ee=v(g);if(y==ue)g=ee;else if(!ee){if(y==le)continue outer;break outer}}m[f++]=g}return m}O.prototype=Xr(Zr.prototype),O.prototype.constructor=O;function ni(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])}}function ri(){this.__data__=er?er(null):{},this.size=0}function ii(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}function ai(e){var t=this.__data__;if(er){var r=t[e];return r===c?n:r}return S.call(t,e)?t[e]:n}function oi(e){var t=this.__data__;return er?t[e]!==n:S.call(t,e)}function si(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=er&&t===n?c:t,this}ni.prototype.clear=ri,ni.prototype.delete=ii,ni.prototype.get=ai,ni.prototype.has=oi,ni.prototype.set=si;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])}}function li(){this.__data__=[],this.size=0}function ui(e){var t=this.__data__,n=Fi(t,e);return n<0?!1:(n==t.length-1?t.pop():nn.call(t,n,1),--this.size,!0)}function di(e){var t=this.__data__,r=Fi(t,e);return r<0?n:t[r][1]}function fi(e){return Fi(this.__data__,e)>-1}function pi(e,t){var n=this.__data__,r=Fi(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}ci.prototype.clear=li,ci.prototype.delete=ui,ci.prototype.get=di,ci.prototype.has=fi,ci.prototype.set=pi;function mi(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])}}function hi(){this.size=0,this.__data__={hash:new ni,map:new(Mn||ci),string:new ni}}function gi(e){var t=ms(this,e).delete(e);return this.size-=t?1:0,t}function _i(e){return ms(this,e).get(e)}function vi(e){return ms(this,e).has(e)}function yi(e,t){var n=ms(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}mi.prototype.clear=hi,mi.prototype.delete=gi,mi.prototype.get=_i,mi.prototype.has=vi,mi.prototype.set=yi;function bi(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new mi;++t<n;)this.add(e[t])}function xi(e){return this.__data__.set(e,c),this}function Si(e){return this.__data__.has(e)}bi.prototype.add=bi.prototype.push=xi,bi.prototype.has=Si;function Ci(e){this.size=(this.__data__=new ci(e)).size}function wi(){this.__data__=new ci,this.size=0}function Ti(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Ei(e){return this.__data__.get(e)}function Di(e){return this.__data__.has(e)}function Oi(e,t){var n=this.__data__;if(n instanceof ci){var r=n.__data__;if(!Mn||r.length<i-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new mi(r)}return n.set(e,t),this.size=n.size,this}Ci.prototype.clear=wi,Ci.prototype.delete=Ti,Ci.prototype.get=Ei,Ci.prototype.has=Di,Ci.prototype.set=Oi;function ki(e,t){var n=K(e),r=!n&&hu(e),i=!n&&!r&&bu(e),a=!n&&!r&&!i&&Wu(e),o=n||r||i||a,s=o?mr(e.length,It):[],c=s.length;for(var l in e)(t||S.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||ks(l,c)))&&s.push(l);return s}function Ai(e){var t=e.length;return t?e[Ha(0,t-1)]:n}function ji(e,t){return N(Oo(e),Vi(t,0,e.length))}function Mi(e){return N(Oo(e))}function Ni(e,t,r){(r!==n&&!fu(e[t],r)||r===n&&!(t in e))&&zi(e,t,r)}function Pi(e,t,r){var i=e[t];(!(S.call(e,t)&&fu(i,r))||r===n&&!(t in e))&&zi(e,t,r)}function Fi(e,t){for(var n=e.length;n--;)if(fu(e[n][0],t))return n;return-1}function Ii(e,t,n,r){return qi(e,function(e,i,a){t(r,e,n(e),a)}),r}function Li(e,t){return e&&ko(t,Cd(t),e)}function Ri(e,t){return e&&ko(t,wd(t),e)}function zi(e,t,n){t==`__proto__`&&sn?sn(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function Bi(e,t){for(var r=-1,i=t.length,a=ht(i),o=e==null;++r<i;)a[r]=o?n:_d(e,t[r]);return a}function Vi(e,t,r){return e===e&&(r!==n&&(e=e<=r?e:r),t!==n&&(e=e>=t?e:t)),e}function Hi(e,t,r,i,a,o){var s,c=t&d,l=t&f,u=t&p;if(r&&(s=a?r(e,i,a,o):r(e)),s!==n)return s;if(!q(e))return e;var m=K(e);if(m){if(s=ws(e),!c)return Oo(e,s)}else{var h=bs(e),g=h==De||h==Oe;if(bu(e))return vo(e,c);if(h==Me||h==be||g&&!a){if(s=l||g?{}:Ts(e),!c)return l?jo(e,Ri(s,e)):Ao(e,Li(s,e))}else{if(!w[h])return a?e:{};s=Es(e,h,c)}}o||=new Ci;var _=o.get(e);if(_)return _;o.set(e,s),Vu(e)?e.forEach(function(n){s.add(Hi(n,t,r,n,e,o))}):Y(e)&&e.forEach(function(n,i){s.set(i,Hi(n,t,r,i,e,o))});var v=m?n:(u?l?us:ls:l?wd:Cd)(e);return Wn(v||e,function(n,i){v&&(i=n,n=e[i]),Pi(s,i,Hi(n,t,r,i,e,o))}),s}function Ui(e){var t=Cd(e);return function(n){return Wi(n,e,t)}}function Wi(e,t,r){var i=r.length;if(e==null)return!i;for(e=x(e);i--;){var a=r[i],o=t[a],s=e[a];if(s===n&&!(a in e)||!o(s))return!1}return!0}function Gi(e,t,r){if(typeof e!=`function`)throw new Lt(o);return qs(function(){e.apply(n,r)},t)}function Ki(e,t,n,r){var a=-1,o=Jn,s=!0,c=e.length,l=[],u=t.length;if(!c)return l;n&&(t=E(t,_r(n))),r?(o=Yn,s=!1):t.length>=i&&(o=yr,s=!1,t=new bi(t));outer:for(;++a<c;){var d=e[a],f=n==null?d:n(d);if(d=r||d!==0?d:0,s&&f===f){for(var p=u;p--;)if(t[p]===f)continue outer;l.push(d)}else o(t,f,r)||l.push(d)}return l}var qi=Po(na),Ji=Po(ra,!0);function Yi(e,t){var n=!0;return qi(e,function(e,r,i){return n=!!t(e,r,i),n}),n}function Xi(e,t,r){for(var i=-1,a=e.length;++i<a;){var o=e[i],s=t(o);if(s!=null&&(c===n?s===s&&!Uu(s):r(s,c)))var c=s,l=o}return l}function Zi(e,t,r,i){var a=e.length;for(r=Z(r),r<0&&(r=-r>a?0:a+r),i=i===n||i>a?a:Z(i),i<0&&(i+=a),i=r>i?0:Zu(i);r<i;)e[r++]=t;return e}function Qi(e,t){var n=[];return qi(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function $i(e,t,n,r,i){var a=-1,o=e.length;for(n||=Os,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?$i(s,t-1,n,r,i):Xn(i,s):r||(i[i.length]=s)}return i}var ea=Fo(),ta=Fo(!0);function na(e,t){return e&&ea(e,t,Cd)}function ra(e,t){return e&&ta(e,t,Cd)}function ia(e,t){return qn(t,function(t){return Ou(e[t])})}function aa(e,t){t=mo(t,e);for(var r=0,i=t.length;e!=null&&r<i;)e=e[P(t[r++])];return r&&r==i?e:n}function oa(e,t,n){var r=t(e);return K(e)?r:Xn(r,n(e))}function sa(e){return e==null?e===n?ze:je:on&&on in x(e)?_s(e):Vs(e)}function ca(e,t){return e>t}function la(e,t){return e!=null&&S.call(e,t)}function ua(e,t){return e!=null&&t in x(e)}function da(e,t,n){return e>=Cn(t,n)&&e<bn(t,n)}function fa(e,t,r){for(var i=r?Yn:Jn,a=e[0].length,o=e.length,s=o,c=ht(o),l=1/0,u=[];s--;){var d=e[s];s&&t&&(d=E(d,_r(t))),l=Cn(d.length,l),c[s]=!r&&(t||a>=120&&d.length>=120)?new bi(s&&d):n}d=e[0];var f=-1,p=c[0];outer:for(;++f<a&&u.length<l;){var m=d[f],h=t?t(m):m;if(m=r||m!==0?m:0,!(p?yr(p,h):i(u,h,r))){for(s=o;--s;){var g=c[s];if(!(g?yr(g,h):i(e[s],h,r)))continue outer}p&&p.push(h),u.push(m)}}return u}function pa(e,t,n,r){return na(e,function(e,i,a){t(r,n(e),i,a)}),r}function ma(e,t,r){t=mo(t,e),e=Us(e,t);var i=e==null?e:e[P(Sc(t))];return i==null?n:Hn(i,e,r)}function ha(e){return J(e)&&sa(e)==be}function ga(e){return J(e)&&sa(e)==He}function _a(e){return J(e)&&sa(e)==we}function va(e,t,n,r,i){return e===t?!0:e==null||t==null||!J(e)&&!J(t)?e!==e&&t!==t:ya(e,t,n,r,va,i)}function ya(e,t,n,r,i,a){var o=K(e),s=K(t),c=o?xe:bs(e),l=s?xe:bs(t);c=c==be?Me:c,l=l==be?Me:l;var u=c==Me,d=l==Me,f=c==l;if(f&&bu(e)){if(!bu(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Ci,o||Wu(e)?as(e,t,n,r,i,a):os(e,t,c,n,r,i,a);if(!(n&m)){var p=u&&S.call(e,`__wrapped__`),h=d&&S.call(t,`__wrapped__`);if(p||h){var g=p?e.value():e,_=h?t.value():t;return a||=new Ci,i(g,_,n,r,a)}}return f?(a||=new Ci,ss(e,t,n,r,i,a)):!1}function ba(e){return J(e)&&bs(e)==ke}function xa(e,t,r,i){var a=r.length,o=a,s=!i;if(e==null)return!o;for(e=x(e);a--;){var c=r[a];if(s&&c[2]?c[1]!==e[c[0]]:!(c[0]in e))return!1}for(;++a<o;){c=r[a];var l=c[0],u=e[l],d=c[1];if(s&&c[2]){if(u===n&&!(l in e))return!1}else{var f=new Ci;if(i)var p=i(u,d,l,e,t,f);if(!(p===n?va(d,u,m|h,i,f):p))return!1}}return!0}function Sa(e){return!q(e)||Ps(e)?!1:(Ou(e)?Jt:Et).test(Zs(e))}function Ca(e){return J(e)&&sa(e)==Fe}function wa(e){return J(e)&&bs(e)==Ie}function Ta(e){return J(e)&&Au(e.length)&&!!C[sa(e)]}function Ea(e){return typeof e==`function`?e:e==null?jf:typeof e==`object`?K(e)?Ma(e[0],e[1]):ja(e):Wf(e)}function Da(e){if(!Is(e))return yn(e);var t=[];for(var n in x(e))S.call(e,n)&&n!=`constructor`&&t.push(n);return t}function Oa(e){if(!q(e))return Bs(e);var t=Is(e),n=[];for(var r in e)r==`constructor`&&(t||!S.call(e,r))||n.push(r);return n}function ka(e,t){return e<t}function Aa(e,t){var n=-1,r=_u(e)?ht(e.length):[];return qi(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function ja(e){var t=hs(e);return t.length==1&&t[0][2]?Rs(t[0][0],t[0][1]):function(n){return n===e||xa(n,e,t)}}function Ma(e,t){return js(e)&&Ls(t)?Rs(P(e),t):function(r){var i=_d(r,e);return i===n&&i===t?yd(r,e):va(t,i,m|h)}}function Na(e,t,r,i,a){e!==t&&ea(t,function(o,s){if(a||=new Ci,q(o))Pa(e,t,s,r,Na,i,a);else{var c=i?i(Gs(e,s),o,s+``,e,t,a):n;c===n&&(c=o),Ni(e,s,c)}},wd)}function Pa(e,t,r,i,a,o,s){var c=Gs(e,r),l=Gs(t,r),u=s.get(l);if(u){Ni(e,r,u);return}var d=o?o(c,l,r+``,e,t,s):n,f=d===n;if(f){var p=K(l),m=!p&&bu(l),h=!p&&!m&&Wu(l);d=l,p||m||h?K(c)?d=c:vu(c)?d=Oo(c):m?(f=!1,d=vo(l,!0)):h?(f=!1,d=Co(l,!0)):d=[]:Ru(l)||hu(l)?(d=c,hu(c)?d=$u(c):(!q(c)||Ou(c))&&(d=Ts(l))):f=!1}f&&(s.set(l,d),a(d,l,i,o,s),s.delete(l)),Ni(e,r,d)}function Fa(e,t){var r=e.length;if(r)return t+=t<0?r:0,ks(t,r)?e[t]:n}function Ia(e,t,n){t=t.length?E(t,function(e){return K(e)?function(t){return aa(t,e.length===1?e[0]:e)}:e}):[jf];var r=-1;return t=E(t,_r(A())),fr(Aa(e,function(e,n,i){return{criteria:E(t,function(t){return t(e)}),index:++r,value:e}}),function(e,t){return To(e,t,n)})}function La(e,t){return Ra(e,t,function(t,n){return yd(e,n)})}function Ra(e,t,n){for(var r=-1,i=t.length,a={};++r<i;){var o=t[r],s=aa(e,o);n(s,o)&&qa(a,mo(o,e),s)}return a}function za(e){return function(t){return aa(t,e)}}function Ba(e,t,n,r){var i=r?or:ar,a=-1,o=t.length,s=e;for(e===t&&(t=Oo(t)),n&&(s=E(e,_r(n)));++a<o;)for(var c=0,l=t[a],u=n?n(l):l;(c=i(s,u,c,r))>-1;)s!==e&&nn.call(s,c,1),nn.call(e,c,1);return e}function Va(e,t){for(var n=e?t.length:0,r=n-1;n--;){var i=t[n];if(n==r||i!==a){var a=i;ks(i)?nn.call(e,i,1):ao(e,i)}}return e}function Ha(e,t){return e+fn(En()*(t-e+1))}function Ua(e,t,n,r){for(var i=-1,a=bn(dn((t-e)/(n||1)),0),o=ht(a);a--;)o[r?a:++i]=e,e+=n;return o}function Wa(e,t){var n=``;if(!e||t<1||t>pe)return n;do t%2&&(n+=e),t=fn(t/2),t&&(e+=e);while(t);return n}function k(e,t){return Js(Hs(e,t,jf),e+``)}function Ga(e){return Ai(Vd(e))}function Ka(e,t){var n=Vd(e);return N(n,Vi(t,0,n.length))}function qa(e,t,r,i){if(!q(e))return e;t=mo(t,e);for(var a=-1,o=t.length,s=o-1,c=e;c!=null&&++a<o;){var l=P(t[a]),u=r;if(l===`__proto__`||l===`constructor`||l===`prototype`)return e;if(a!=s){var d=c[l];u=i?i(d,l,c):n,u===n&&(u=q(d)?d:ks(t[a+1])?[]:{})}Pi(c,l,u),c=c[l]}return e}var Ja=tr?function(e,t){return tr.set(e,t),e}:jf,Ya=sn?function(e,t){return sn(e,`toString`,{configurable:!0,enumerable:!1,value:Df(t),writable:!0})}:jf;function Xa(e){return N(Vd(e))}function Za(e,t,n){var r=-1,i=e.length;t<0&&(t=-t>i?0:i+t),n=n>i?i:n,n<0&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0;for(var a=ht(i);++r<i;)a[r]=e[r+t];return a}function Qa(e,t){var n;return qi(e,function(e,r,i){return n=t(e,r,i),!n}),!!n}function $a(e,t,n){var r=0,i=e==null?r:e.length;if(typeof t==`number`&&t===t&&i<=ve){for(;r<i;){var a=r+i>>>1,o=e[a];o!==null&&!Uu(o)&&(n?o<=t:o<t)?r=a+1:i=a}return i}return eo(e,t,jf,n)}function eo(e,t,r,i){var a=0,o=e==null?0:e.length;if(o===0)return 0;t=r(t);for(var s=t!==t,c=t===null,l=Uu(t),u=t===n;a<o;){var d=fn((a+o)/2),f=r(e[d]),p=f!==n,m=f===null,h=f===f,g=Uu(f);if(s)var _=i||h;else _=u?h&&(i||p):c?h&&p&&(i||!m):l?h&&p&&!m&&(i||!g):m||g?!1:i?f<=t:f<t;_?a=d+1:o=d}return Cn(o,_e)}function to(e,t){for(var n=-1,r=e.length,i=0,a=[];++n<r;){var o=e[n],s=t?t(o):o;if(!n||!fu(s,c)){var c=s;a[i++]=o===0?0:o}}return a}function no(e){return typeof e==`number`?e:Uu(e)?he:+e}function ro(e){if(typeof e==`string`)return e;if(K(e))return E(e,ro)+``;if(Uu(e))return Yr?Yr.call(e):``;var t=e+``;return t==`0`&&1/e==-fe?`-0`:t}function io(e,t,n){var r=-1,a=Jn,o=e.length,s=!0,c=[],l=c;if(n)s=!1,a=Yn;else if(o>=i){var u=t?null:$o(e);if(u)return Nr(u);s=!1,a=yr,l=new bi}else l=t?[]:c;outer:for(;++r<o;){var d=e[r],f=t?t(d):d;if(d=n||d!==0?d:0,s&&f===f){for(var p=l.length;p--;)if(l[p]===f)continue outer;t&&l.push(f),c.push(d)}else a(l,f,n)||(l!==c&&l.push(f),c.push(d))}return c}function ao(e,t){return t=mo(t,e),e=Us(e,t),e==null||delete e[P(Sc(t))]}function oo(e,t,n,r){return qa(e,t,n(aa(e,t)),r)}function so(e,t,n,r){for(var i=e.length,a=r?i:-1;(r?a--:++a<i)&&t(e[a],a,e););return n?Za(e,r?0:a,r?a+1:i):Za(e,r?a+1:0,r?i:a)}function co(e,t){var n=e;return n instanceof O&&(n=n.value()),Zn(t,function(e,t){return t.func.apply(t.thisArg,Xn([e],t.args))},n)}function lo(e,t,n){var r=e.length;if(r<2)return r?io(e[0]):[];for(var i=-1,a=ht(r);++i<r;)for(var o=e[i],s=-1;++s<r;)s!=i&&(a[i]=Ki(a[i]||o,e[s],t,n));return io($i(a,1),t,n)}function uo(e,t,r){for(var i=-1,a=e.length,o=t.length,s={};++i<a;){var c=i<o?t[i]:n;r(s,e[i],c)}return s}function fo(e){return vu(e)?e:[]}function po(e){return typeof e==`function`?e:jf}function mo(e,t){return K(e)?e:js(e,t)?[e]:Xs(Q(e))}var ho=k;function go(e,t,r){var i=e.length;return r=r===n?i:r,!t&&r>=i?e:Za(e,t,r)}var _o=cn||function(e){return jn.clearTimeout(e)};function vo(e,t){if(t)return e.slice();var n=e.length,r=Qt?Qt(n):new e.constructor(n);return e.copy(r),r}function yo(e){var t=new e.constructor(e.byteLength);return new Zt(t).set(new Zt(e)),t}function bo(e,t){var n=t?yo(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}function xo(e){var t=new e.constructor(e.source,Ct.exec(e));return t.lastIndex=e.lastIndex,t}function So(e){return Jr?x(Jr.call(e)):{}}function Co(e,t){var n=t?yo(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}function wo(e,t){if(e!==t){var r=e!==n,i=e===null,a=e===e,o=Uu(e),s=t!==n,c=t===null,l=t===t,u=Uu(t);if(!c&&!u&&!o&&e>t||o&&s&&l&&!c&&!u||i&&s&&l||!r&&l||!a)return 1;if(!i&&!o&&!u&&e<t||u&&r&&a&&!i&&!o||c&&r&&a||!s&&a||!l)return-1}return 0}function To(e,t,n){for(var r=-1,i=e.criteria,a=t.criteria,o=i.length,s=n.length;++r<o;){var c=wo(i[r],a[r]);if(c)return r>=s?c:c*(n[r]==`desc`?-1:1)}return e.index-t.index}function Eo(e,t,n,r){for(var i=-1,a=e.length,o=n.length,s=-1,c=t.length,l=bn(a-o,0),u=ht(c+l),d=!r;++s<c;)u[s]=t[s];for(;++i<o;)(d||i<a)&&(u[n[i]]=e[i]);for(;l--;)u[s++]=e[i++];return u}function Do(e,t,n,r){for(var i=-1,a=e.length,o=-1,s=n.length,c=-1,l=t.length,u=bn(a-s,0),d=ht(u+l),f=!r;++i<u;)d[i]=e[i];for(var p=i;++c<l;)d[p+c]=t[c];for(;++o<s;)(f||i<a)&&(d[p+n[o]]=e[i++]);return d}function Oo(e,t){var n=-1,r=e.length;for(t||=ht(r);++n<r;)t[n]=e[n];return t}function ko(e,t,r,i){var a=!r;r||={};for(var o=-1,s=t.length;++o<s;){var c=t[o],l=i?i(r[c],e[c],c,r,e):n;l===n&&(l=e[c]),a?zi(r,c,l):Pi(r,c,l)}return r}function Ao(e,t){return ko(e,vs(e),t)}function jo(e,t){return ko(e,ys(e),t)}function Mo(e,t){return function(n,r){var i=K(n)?Un:Ii,a=t?t():{};return i(n,e,A(r,2),a)}}function No(e){return k(function(t,r){var i=-1,a=r.length,o=a>1?r[a-1]:n,s=a>2?r[2]:n;for(o=e.length>3&&typeof o==`function`?(a--,o):n,s&&As(r[0],r[1],s)&&(o=a<3?n:o,a=1),t=x(t);++i<a;){var c=r[i];c&&e(t,c,i,o)}return t})}function Po(e,t){return function(n,r){if(n==null)return n;if(!_u(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=x(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}function Fo(e){return function(t,n,r){for(var i=-1,a=x(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}function Io(e,t,n){var r=t&g,i=zo(e);function a(){return(this&&this!==jn&&this instanceof a?i:e).apply(r?n:this,arguments)}return a}function Lo(e){return function(t){t=Q(t);var r=Dr(t)?Rr(t):n,i=r?r[0]:t.charAt(0),a=r?go(r,1).join(``):t.slice(1);return i[e]()+a}}function Ro(e){return function(t){return Zn(Sf(Jd(t).replace(hn,``)),e,``)}}function zo(e){return function(){var t=arguments;switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3]);case 5:return new e(t[0],t[1],t[2],t[3],t[4]);case 6:return new e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return new e(t[0],t[1],t[2],t[3],t[4],t[5],t[6])}var n=Xr(e.prototype),r=e.apply(n,t);return q(r)?r:n}}function Bo(e,t,r){var i=zo(e);function a(){for(var o=arguments.length,s=ht(o),c=o,l=ps(a);c--;)s[c]=arguments[c];var u=o<3&&s[0]!==l&&s[o-1]!==l?[]:Mr(s,l);return o-=u.length,o<r?Zo(e,t,Uo,a.placeholder,n,s,u,n,n,r-o):Hn(this&&this!==jn&&this instanceof a?i:e,this,s)}return a}function Vo(e){return function(t,r,i){var a=x(t);if(!_u(t)){var o=A(r,3);t=Cd(t),r=function(e){return o(a[e],e,a)}}var s=e(t,r,i);return s>-1?a[o?t[s]:s]:n}}function Ho(e){return cs(function(t){var r=t.length,i=r,a=Qr.prototype.thru;for(e&&t.reverse();i--;){var s=t[i];if(typeof s!=`function`)throw new Lt(o);if(a&&!c&&fs(s)==`wrapper`)var c=new Qr([],!0)}for(i=c?i:r;++i<r;){s=t[i];var l=fs(s),u=l==`wrapper`?ds(s):n;c=u&&Ns(u[0])&&u[1]==(b|y|te|re)&&!u[4].length&&u[9]==1?c[fs(u[0])].apply(c,u[3]):s.length==1&&Ns(s)?c[l]():c.thru(s)}return function(){var e=arguments,n=e[0];if(c&&e.length==1&&K(n))return c.plant(n).value();for(var i=0,a=r?t[i].apply(this,e):n;++i<r;)a=t[i].call(this,a);return a}})}function Uo(e,t,r,i,a,o,s,c,l,u){var d=t&b,f=t&g,p=t&_,m=t&(y|ee),h=t&ie,v=p?n:zo(e);function te(){for(var n=arguments.length,g=ht(n),_=n;_--;)g[_]=arguments[_];if(m)var y=ps(te),ee=Sr(g,y);if(i&&(g=Eo(g,i,a,m)),o&&(g=Do(g,o,s,m)),n-=ee,m&&n<u){var ne=Mr(g,y);return Zo(e,t,Uo,te.placeholder,r,g,ne,c,l,u-n)}var b=f?r:this,re=p?b[e]:e;return n=g.length,c?g=Ws(g,c):h&&n>1&&g.reverse(),d&&l<n&&(g.length=l),this&&this!==jn&&this instanceof te&&(re=v||zo(re)),re.apply(b,g)}return te}function Wo(e,t){return function(n,r){return pa(n,e,t(r),{})}}function Go(e,t){return function(r,i){var a;if(r===n&&i===n)return t;if(r!==n&&(a=r),i!==n){if(a===n)return i;typeof r==`string`||typeof i==`string`?(r=ro(r),i=ro(i)):(r=no(r),i=no(i)),a=e(r,i)}return a}}function Ko(e){return cs(function(t){return t=E(t,_r(A())),k(function(n){var r=this;return e(t,function(e){return Hn(e,r,n)})})})}function qo(e,t){t=t===n?` `:ro(t);var r=t.length;if(r<2)return r?Wa(t,e):t;var i=Wa(t,dn(e/Lr(t)));return Dr(t)?go(Rr(i),0,e).join(``):i.slice(0,e)}function Jo(e,t,n,r){var i=t&g,a=zo(e);function o(){for(var t=-1,s=arguments.length,c=-1,l=r.length,u=ht(l+s),d=this&&this!==jn&&this instanceof o?a:e;++c<l;)u[c]=r[c];for(;s--;)u[c++]=arguments[++t];return Hn(d,i?n:this,u)}return o}function Yo(e){return function(t,r,i){return i&&typeof i!=`number`&&As(t,r,i)&&(r=i=n),t=Xu(t),r===n?(r=t,t=0):r=Xu(r),i=i===n?t<r?1:-1:Xu(i),Ua(t,r,i,e)}}function Xo(e){return function(t,n){return typeof t==`string`&&typeof n==`string`||(t=Qu(t),n=Qu(n)),e(t,n)}}function Zo(e,t,r,i,a,o,s,c,l,u){var d=t&y,f=d?s:n,p=d?n:s,m=d?o:n,h=d?n:o;t|=d?te:ne,t&=~(d?ne:te),t&v||(t&=~(g|_));var ee=[e,t,a,m,f,h,p,c,l,u],b=r.apply(n,ee);return Ns(e)&&Ks(b,ee),b.placeholder=i,Ys(b,e,t)}function Qo(e){var t=Pt[e];return function(e,n){if(e=Qu(e),n=n==null?0:Cn(Z(n),292),n&&_n(e)){var r=(Q(e)+`e`).split(`e`);return r=(Q(t(r[0]+`e`+(+r[1]+n)))+`e`).split(`e`),+(r[0]+`e`+(+r[1]-n))}return t(e)}}var $o=T&&1/Nr(new T([,-0]))[1]==fe?function(e){return new T(e)}:zf;function es(e){return function(t){var n=bs(t);return n==ke?Ar(t):n==Ie?Pr(t):hr(t,e(t))}}function ts(e,t,r,i,a,s,c,l){var u=t&_;if(!u&&typeof e!=`function`)throw new Lt(o);var d=i?i.length:0;if(d||(t&=~(te|ne),i=a=n),c=c===n?c:bn(Z(c),0),l=l===n?l:Z(l),d-=a?a.length:0,t&ne){var f=i,p=a;i=a=n}var m=u?n:ds(e),h=[e,t,r,i,a,f,p,s,c,l];if(m&&zs(h,m),e=h[0],t=h[1],r=h[2],i=h[3],a=h[4],l=h[9]=h[9]===n?u?0:e.length:bn(h[9]-d,0),!l&&t&(y|ee)&&(t&=~(y|ee)),!t||t==g)var v=Io(e,t,r);else v=t==y||t==ee?Bo(e,t,l):(t==te||t==(g|te))&&!a.length?Jo(e,t,r,i):Uo.apply(n,h);return Ys((m?Ja:Ks)(v,h),e,t)}function ns(e,t,r,i){return e===n||fu(e,Bt[r])&&!S.call(i,r)?t:e}function rs(e,t,r,i,a,o){return q(e)&&q(t)&&(o.set(t,e),Na(e,t,n,rs,o),o.delete(t)),e}function is(e){return Ru(e)?n:e}function as(e,t,r,i,a,o){var s=r&m,c=e.length,l=t.length;if(c!=l&&!(s&&l>c))return!1;var u=o.get(e),d=o.get(t);if(u&&d)return u==t&&d==e;var f=-1,p=!0,g=r&h?new bi:n;for(o.set(e,t),o.set(t,e);++f<c;){var _=e[f],v=t[f];if(i)var y=s?i(v,_,f,t,e,o):i(_,v,f,e,t,o);if(y!==n){if(y)continue;p=!1;break}if(g){if(!$n(t,function(e,t){if(!yr(g,t)&&(_===e||a(_,e,r,i,o)))return g.push(t)})){p=!1;break}}else if(!(_===v||a(_,v,r,i,o))){p=!1;break}}return o.delete(e),o.delete(t),p}function os(e,t,n,r,i,a,o){switch(n){case Ue:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case He:return!(e.byteLength!=t.byteLength||!a(new Zt(e),new Zt(t)));case Ce:case we:case Ae:return fu(+e,+t);case Ee:return e.name==t.name&&e.message==t.message;case Fe:case Le:return e==t+``;case ke:var s=Ar;case Ie:var c=r&m;if(s||=Nr,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=h,o.set(e,t);var u=as(s(e),s(t),r,i,a,o);return o.delete(e),u;case Re:if(Jr)return Jr.call(e)==Jr.call(t)}return!1}function ss(e,t,r,i,a,o){var s=r&m,c=ls(e),l=c.length;if(l!=ls(t).length&&!s)return!1;for(var u=l;u--;){var d=c[u];if(!(s?d in t:S.call(t,d)))return!1}var f=o.get(e),p=o.get(t);if(f&&p)return f==t&&p==e;var h=!0;o.set(e,t),o.set(t,e);for(var g=s;++u<l;){d=c[u];var _=e[d],v=t[d];if(i)var y=s?i(v,_,d,t,e,o):i(_,v,d,e,t,o);if(!(y===n?_===v||a(_,v,r,i,o):y)){h=!1;break}g||=d==`constructor`}if(h&&!g){var ee=e.constructor,te=t.constructor;ee!=te&&`constructor`in e&&`constructor`in t&&!(typeof ee==`function`&&ee instanceof ee&&typeof te==`function`&&te instanceof te)&&(h=!1)}return o.delete(e),o.delete(t),h}function cs(e){return Js(Hs(e,n,dc),e+``)}function ls(e){return oa(e,Cd,vs)}function us(e){return oa(e,wd,ys)}var ds=tr?function(e){return tr.get(e)}:zf;function fs(e){for(var t=e.name+``,n=ur[t],r=S.call(ur,t)?n.length:0;r--;){var i=n[r],a=i.func;if(a==null||a==e)return i.name}return t}function ps(e){return(S.call(D,`placeholder`)?D:e).placeholder}function A(){var e=D.iteratee||Mf;return e=e===Mf?Ea:e,arguments.length?e(arguments[0],arguments[1]):e}function ms(e,t){var n=e.__data__;return Ms(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function hs(e){for(var t=Cd(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Ls(i)]}return t}function gs(e,t){var r=Er(e,t);return Sa(r)?r:n}function _s(e){var t=S.call(e,on),r=e[on];try{e[on]=n;var i=!0}catch{}var a=Gt.call(e);return i&&(t?e[on]=r:delete e[on]),a}var vs=pn?function(e){return e==null?[]:(e=x(e),qn(pn(e),function(t){return tn.call(e,t)}))}:Jf,ys=pn?function(e){for(var t=[];e;)Xn(t,vs(e)),e=$t(e);return t}:Jf,bs=sa;(An&&bs(new An(new ArrayBuffer(1)))!=Ue||Mn&&bs(new Mn)!=ke||Nn&&bs(Nn.resolve())!=Ne||T&&bs(new T)!=Ie||Fn&&bs(new Fn)!=Be)&&(bs=function(e){var t=sa(e),r=t==Me?e.constructor:n,i=r?Zs(r):``;if(i)switch(i){case Fr:return Ue;case Vr:return ke;case Hr:return Ne;case Gr:return Ie;case Kr:return Be}return t});function xs(e,t,n){for(var r=-1,i=n.length;++r<i;){var a=n[r],o=a.size;switch(a.type){case`drop`:e+=o;break;case`dropRight`:t-=o;break;case`take`:t=Cn(t,e+o);break;case`takeRight`:e=bn(e,t-o);break}}return{start:e,end:t}}function Ss(e){var t=e.match(_t);return t?t[1].split(vt):[]}function Cs(e,t,n){t=mo(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=P(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&&Au(i)&&ks(o,i)&&(K(e)||hu(e)))}function ws(e){var t=e.length,n=new e.constructor(t);return t&&typeof e[0]==`string`&&S.call(e,`index`)&&(n.index=e.index,n.input=e.input),n}function Ts(e){return typeof e.constructor==`function`&&!Is(e)?Xr($t(e)):{}}function Es(e,t,n){var r=e.constructor;switch(t){case He:return yo(e);case Ce:case we:return new r(+e);case Ue:return bo(e,n);case We:case Ge:case Ke:case qe:case Je:case Ye:case Xe:case Ze:case Qe:return Co(e,n);case ke:return new r;case Ae:case Le:return new r(e);case Fe:return xo(e);case Ie:return new r;case Re:return So(e)}}function Ds(e,t){var n=t.length;if(!n)return e;var r=n-1;return t[r]=(n>1?`& `:``)+t[r],t=t.join(n>2?`, `:` `),e.replace(gt,`{
|
|
10
|
-
/* [wrapped with `+t+`] */
|
|
11
|
-
`)}function Os(e){return K(e)||hu(e)||!!(rn&&e&&e[rn])}function ks(e,t){var n=typeof e;return t??=pe,!!t&&(n==`number`||n!=`symbol`&&Ot.test(e))&&e>-1&&e%1==0&&e<t}function As(e,t,n){if(!q(n))return!1;var r=typeof t;return(r==`number`?_u(n)&&ks(t,n.length):r==`string`&&t in n)?fu(n[t],e):!1}function js(e,t){if(K(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||Uu(e)?!0:ut.test(e)||!lt.test(e)||t!=null&&e in x(t)}function Ms(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Ns(e){var t=fs(e),n=D[t];if(typeof n!=`function`||!(t in O.prototype))return!1;if(e===n)return!0;var r=ds(n);return!!r&&e===r[0]}function Ps(e){return!!Wt&&Wt in e}var Fs=Vt?Ou:Yf;function Is(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||Bt)}function Ls(e){return e===e&&!q(e)}function Rs(e,t){return function(r){return r==null?!1:r[e]===t&&(t!==n||e in x(r))}}function j(e){var t=Yl(e,function(e){return n.size===l&&n.clear(),e}),n=t.cache;return t}function zs(e,t){var n=e[1],r=t[1],i=n|r,a=i<(g|_|b),o=r==b&&n==y||r==b&&n==re&&e[7].length<=t[8]||r==(b|re)&&t[7].length<=t[8]&&n==y;if(!(a||o))return e;r&g&&(e[2]=t[2],i|=n&g?0:v);var s=t[3];if(s){var c=e[3];e[3]=c?Eo(c,s,t[4]):s,e[4]=c?Mr(e[3],u):t[4]}return s=t[5],s&&(c=e[5],e[5]=c?Do(c,s,t[6]):s,e[6]=c?Mr(e[5],u):t[6]),s=t[7],s&&(e[7]=s),r&b&&(e[8]=e[8]==null?t[8]:Cn(e[8],t[8])),e[9]??=t[9],e[0]=t[0],e[1]=i,e}function Bs(e){var t=[];if(e!=null)for(var n in x(e))t.push(n);return t}function Vs(e){return Gt.call(e)}function Hs(e,t,r){return t=bn(t===n?e.length-1:t,0),function(){for(var n=arguments,i=-1,a=bn(n.length-t,0),o=ht(a);++i<a;)o[i]=n[t+i];i=-1;for(var s=ht(t+1);++i<t;)s[i]=n[i];return s[t]=r(o),Hn(e,this,s)}}function Us(e,t){return t.length<2?e:aa(e,Za(t,0,-1))}function Ws(e,t){for(var r=e.length,i=Cn(t.length,r),a=Oo(e);i--;){var o=t[i];e[i]=ks(o,r)?a[o]:n}return e}function Gs(e,t){if(!(t===`constructor`&&typeof e[t]==`function`)&&t!=`__proto__`)return e[t]}var Ks=M(Ja),qs=un||function(e,t){return jn.setTimeout(e,t)},Js=M(Ya);function Ys(e,t,n){var r=t+``;return Js(e,Ds(r,Qs(Ss(r),n)))}function M(e){var t=0,r=0;return function(){var i=wn(),a=ce-(i-r);if(r=i,a>0){if(++t>=se)return arguments[0]}else t=0;return e.apply(n,arguments)}}function N(e,t){var r=-1,i=e.length,a=i-1;for(t=t===n?i:t;++r<t;){var o=Ha(r,a),s=e[o];e[o]=e[r],e[r]=s}return e.length=t,e}var Xs=j(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(dt,function(e,n,r,i){t.push(r?i.replace(xt,`$1`):n||e)}),t});function P(e){if(typeof e==`string`||Uu(e))return e;var t=e+``;return t==`0`&&1/e==-fe?`-0`:t}function Zs(e){if(e!=null){try{return Ht.call(e)}catch{}try{return e+``}catch{}}return``}function Qs(e,t){return Wn(ye,function(n){var r=`_.`+n[0];t&n[1]&&!Jn(e,r)&&e.push(r)}),e.sort()}function $s(e){if(e instanceof O)return e.clone();var t=new Qr(e.__wrapped__,e.__chain__);return t.__actions__=Oo(e.__actions__),t.__index__=e.__index__,t.__values__=e.__values__,t}function ec(e,t,r){t=(r?As(e,t,r):t===n)?1:bn(Z(t),0);var i=e==null?0:e.length;if(!i||t<1)return[];for(var a=0,o=0,s=ht(dn(i/t));a<i;)s[o++]=Za(e,a,a+=t);return s}function tc(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}function nc(){var e=arguments.length;if(!e)return[];for(var t=ht(e-1),n=arguments[0],r=e;r--;)t[r-1]=arguments[r];return Xn(K(n)?Oo(n):[n],$i(t,1))}var F=k(function(e,t){return vu(e)?Ki(e,$i(t,1,vu,!0)):[]}),rc=k(function(e,t){var r=Sc(t);return vu(r)&&(r=n),vu(e)?Ki(e,$i(t,1,vu,!0),A(r,2)):[]}),I=k(function(e,t){var r=Sc(t);return vu(r)&&(r=n),vu(e)?Ki(e,$i(t,1,vu,!0),n,r):[]});function ic(e,t,r){var i=e==null?0:e.length;return i?(t=r||t===n?1:Z(t),Za(e,t<0?0:t,i)):[]}function ac(e,t,r){var i=e==null?0:e.length;return i?(t=r||t===n?1:Z(t),t=i-t,Za(e,0,t<0?0:t)):[]}function oc(e,t){return e&&e.length?so(e,A(t,3),!0,!0):[]}function sc(e,t){return e&&e.length?so(e,A(t,3),!0):[]}function cc(e,t,n,r){var i=e==null?0:e.length;return i?(n&&typeof n!=`number`&&As(e,t,n)&&(n=0,r=i),Zi(e,t,n,r)):[]}function lc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=n==null?0:Z(n);return i<0&&(i=bn(r+i,0)),ir(e,A(t,3),i)}function uc(e,t,r){var i=e==null?0:e.length;if(!i)return-1;var a=i-1;return r!==n&&(a=Z(r),a=r<0?bn(i+a,0):Cn(a,i-1)),ir(e,A(t,3),a,!0)}function dc(e){return e!=null&&e.length?$i(e,1):[]}function fc(e){return e!=null&&e.length?$i(e,fe):[]}function pc(e,t){return e!=null&&e.length?(t=t===n?1:Z(t),$i(e,t)):[]}function mc(e){for(var t=-1,n=e==null?0:e.length,r={};++t<n;){var i=e[t];r[i[0]]=i[1]}return r}function hc(e){return e&&e.length?e[0]:n}function gc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=n==null?0:Z(n);return i<0&&(i=bn(r+i,0)),ar(e,t,i)}function _c(e){return e!=null&&e.length?Za(e,0,-1):[]}var vc=k(function(e){var t=E(e,fo);return t.length&&t[0]===e[0]?fa(t):[]}),yc=k(function(e){var t=Sc(e),r=E(e,fo);return t===Sc(r)?t=n:r.pop(),r.length&&r[0]===e[0]?fa(r,A(t,2)):[]}),bc=k(function(e){var t=Sc(e),r=E(e,fo);return t=typeof t==`function`?t:n,t&&r.pop(),r.length&&r[0]===e[0]?fa(r,n,t):[]});function xc(e,t){return e==null?``:vn.call(e,t)}function Sc(e){var t=e==null?0:e.length;return t?e[t-1]:n}function Cc(e,t,r){var i=e==null?0:e.length;if(!i)return-1;var a=i;return r!==n&&(a=Z(r),a=a<0?bn(i+a,0):Cn(a,i-1)),t===t?Ir(e,t,a):ir(e,sr,a,!0)}function wc(e,t){return e&&e.length?Fa(e,Z(t)):n}var L=k(R);function R(e,t){return e&&e.length&&t&&t.length?Ba(e,t):e}function Tc(e,t,n){return e&&e.length&&t&&t.length?Ba(e,t,A(n,2)):e}function Ec(e,t,r){return e&&e.length&&t&&t.length?Ba(e,t,n,r):e}var Dc=cs(function(e,t){var n=e==null?0:e.length,r=Bi(e,t);return Va(e,E(t,function(e){return ks(e,n)?+e:e}).sort(wo)),r});function Oc(e,t){var n=[];if(!(e&&e.length))return n;var r=-1,i=[],a=e.length;for(t=A(t,3);++r<a;){var o=e[r];t(o,r,e)&&(n.push(o),i.push(r))}return Va(e,i),n}function kc(e){return e==null?e:kn.call(e)}function Ac(e,t,r){var i=e==null?0:e.length;return i?(r&&typeof r!=`number`&&As(e,t,r)?(t=0,r=i):(t=t==null?0:Z(t),r=r===n?i:Z(r)),Za(e,t,r)):[]}function jc(e,t){return $a(e,t)}function Mc(e,t,n){return eo(e,t,A(n,2))}function Nc(e,t){var n=e==null?0:e.length;if(n){var r=$a(e,t);if(r<n&&fu(e[r],t))return r}return-1}function Pc(e,t){return $a(e,t,!0)}function Fc(e,t,n){return eo(e,t,A(n,2),!0)}function z(e,t){if(e!=null&&e.length){var n=$a(e,t,!0)-1;if(fu(e[n],t))return n}return-1}function Ic(e){return e&&e.length?to(e):[]}function Lc(e,t){return e&&e.length?to(e,A(t,2)):[]}function Rc(e){var t=e==null?0:e.length;return t?Za(e,1,t):[]}function B(e,t,r){return e&&e.length?(t=r||t===n?1:Z(t),Za(e,0,t<0?0:t)):[]}function V(e,t,r){var i=e==null?0:e.length;return i?(t=r||t===n?1:Z(t),t=i-t,Za(e,t<0?0:t,i)):[]}function zc(e,t){return e&&e.length?so(e,A(t,3),!1,!0):[]}function H(e,t){return e&&e.length?so(e,A(t,3)):[]}var Bc=k(function(e){return io($i(e,1,vu,!0))}),Vc=k(function(e){var t=Sc(e);return vu(t)&&(t=n),io($i(e,1,vu,!0),A(t,2))}),Hc=k(function(e){var t=Sc(e);return t=typeof t==`function`?t:n,io($i(e,1,vu,!0),n,t)});function Uc(e){return e&&e.length?io(e):[]}function Wc(e,t){return e&&e.length?io(e,A(t,2)):[]}function Gc(e,t){return t=typeof t==`function`?t:n,e&&e.length?io(e,n,t):[]}function Kc(e){if(!(e&&e.length))return[];var t=0;return e=qn(e,function(e){if(vu(e))return t=bn(e.length,t),!0}),mr(t,function(t){return E(e,lr(t))})}function qc(e,t){if(!(e&&e.length))return[];var r=Kc(e);return t==null?r:E(r,function(e){return Hn(t,n,e)})}var Jc=k(function(e,t){return vu(e)?Ki(e,t):[]}),Yc=k(function(e){return lo(qn(e,vu))}),Xc=k(function(e){var t=Sc(e);return vu(t)&&(t=n),lo(qn(e,vu),A(t,2))}),Zc=k(function(e){var t=Sc(e);return t=typeof t==`function`?t:n,lo(qn(e,vu),n,t)}),Qc=k(Kc);function $c(e,t){return uo(e||[],t||[],Pi)}function el(e,t){return uo(e||[],t||[],qa)}var tl=k(function(e){var t=e.length,r=t>1?e[t-1]:n;return r=typeof r==`function`?(e.pop(),r):n,qc(e,r)});function nl(e){var t=D(e);return t.__chain__=!0,t}function rl(e,t){return t(e),e}function il(e,t){return t(e)}var al=cs(function(e){var t=e.length,r=t?e[0]:0,i=this.__wrapped__,a=function(t){return Bi(t,e)};return t>1||this.__actions__.length||!(i instanceof O)||!ks(r)?this.thru(a):(i=i.slice(r,+r+(t?1:0)),i.__actions__.push({func:il,args:[a],thisArg:n}),new Qr(i,this.__chain__).thru(function(e){return t&&!e.length&&e.push(n),e}))});function ol(){return nl(this)}function sl(){return new Qr(this.value(),this.__chain__)}function cl(){this.__values__===n&&(this.__values__=Yu(this.value()));var e=this.__index__>=this.__values__.length;return{done:e,value:e?n:this.__values__[this.__index__++]}}function ll(){return this}function ul(e){for(var t,r=this;r instanceof Zr;){var i=$s(r);i.__index__=0,i.__values__=n,t?a.__wrapped__=i:t=i;var a=i;r=r.__wrapped__}return a.__wrapped__=e,t}function dl(){var e=this.__wrapped__;if(e instanceof O){var t=e;return this.__actions__.length&&(t=new O(this)),t=t.reverse(),t.__actions__.push({func:il,args:[kc],thisArg:n}),new Qr(t,this.__chain__)}return this.thru(kc)}function fl(){return co(this.__wrapped__,this.__actions__)}var pl=Mo(function(e,t,n){S.call(e,n)?++e[n]:zi(e,n,1)});function ml(e,t,r){var i=K(e)?Kn:Yi;return r&&As(e,t,r)&&(t=n),i(e,A(t,3))}function hl(e,t){return(K(e)?qn:Qi)(e,A(t,3))}var gl=Vo(lc),_l=Vo(uc);function vl(e,t){return $i(El(e,t),1)}function yl(e,t){return $i(El(e,t),fe)}function bl(e,t,r){return r=r===n?1:Z(r),$i(El(e,t),r)}function xl(e,t){return(K(e)?Wn:qi)(e,A(t,3))}function Sl(e,t){return(K(e)?Gn:Ji)(e,A(t,3))}var Cl=Mo(function(e,t,n){S.call(e,n)?e[n].push(t):zi(e,n,[t])});function U(e,t,n,r){e=_u(e)?e:Vd(e),n=n&&!r?Z(n):0;var i=e.length;return n<0&&(n=bn(i+n,0)),Hu(e)?n<=i&&e.indexOf(t,n)>-1:!!i&&ar(e,t,n)>-1}var wl=k(function(e,t,n){var r=-1,i=typeof t==`function`,a=_u(e)?ht(e.length):[];return qi(e,function(e){a[++r]=i?Hn(t,e,n):ma(e,t,n)}),a}),Tl=Mo(function(e,t,n){zi(e,n,t)});function El(e,t){return(K(e)?E:Aa)(e,A(t,3))}function Dl(e,t,r,i){return e==null?[]:(K(t)||(t=t==null?[]:[t]),r=i?n:r,K(r)||(r=r==null?[]:[r]),Ia(e,t,r))}var Ol=Mo(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]});function kl(e,t,n){var r=K(e)?Zn:dr,i=arguments.length<3;return r(e,A(t,4),n,i,qi)}function Al(e,t,n){var r=K(e)?Qn:dr,i=arguments.length<3;return r(e,A(t,4),n,i,Ji)}function jl(e,t){return(K(e)?qn:Qi)(e,Xl(A(t,3)))}function Ml(e){return(K(e)?Ai:Ga)(e)}function Nl(e,t,r){return t=(r?As(e,t,r):t===n)?1:Z(t),(K(e)?ji:Ka)(e,t)}function Pl(e){return(K(e)?Mi:Xa)(e)}function Fl(e){if(e==null)return 0;if(_u(e))return Hu(e)?Lr(e):e.length;var t=bs(e);return t==ke||t==Ie?e.size:Da(e).length}function Il(e,t,r){var i=K(e)?$n:Qa;return r&&As(e,t,r)&&(t=n),i(e,A(t,3))}var W=k(function(e,t){if(e==null)return[];var n=t.length;return n>1&&As(e,t[0],t[1])?t=[]:n>2&&As(t[0],t[1],t[2])&&(t=[t[0]]),Ia(e,$i(t,1),[])}),Ll=ln||function(){return jn.Date.now()};function Rl(e,t){if(typeof t!=`function`)throw new Lt(o);return e=Z(e),function(){if(--e<1)return t.apply(this,arguments)}}function zl(e,t,r){return t=r?n:t,t=e&&t==null?e.length:t,ts(e,b,n,n,n,n,t)}function Bl(e,t){var r;if(typeof t!=`function`)throw new Lt(o);return e=Z(e),function(){return--e>0&&(r=t.apply(this,arguments)),e<=1&&(t=n),r}}var Vl=k(function(e,t,n){var r=g;if(n.length){var i=Mr(n,ps(Vl));r|=te}return ts(e,r,t,n,i)}),Hl=k(function(e,t,n){var r=g|_;if(n.length){var i=Mr(n,ps(Hl));r|=te}return ts(t,r,e,n,i)});function Ul(e,t,r){t=r?n:t;var i=ts(e,y,n,n,n,n,n,t);return i.placeholder=Ul.placeholder,i}function Wl(e,t,r){t=r?n:t;var i=ts(e,ee,n,n,n,n,n,t);return i.placeholder=Wl.placeholder,i}function Gl(e,t,r){var i,a,s,c,l,u,d=0,f=!1,p=!1,m=!0;if(typeof e!=`function`)throw new Lt(o);t=Qu(t)||0,q(r)&&(f=!!r.leading,p=`maxWait`in r,s=p?bn(Qu(r.maxWait)||0,t):s,m=`trailing`in r?!!r.trailing:m);function h(t){var r=i,o=a;return i=a=n,d=t,c=e.apply(o,r),c}function g(e){return d=e,l=qs(y,t),f?h(e):c}function _(e){var n=e-u,r=e-d,i=t-n;return p?Cn(i,s-r):i}function v(e){var r=e-u,i=e-d;return u===n||r>=t||r<0||p&&i>=s}function y(){var e=Ll();if(v(e))return ee(e);l=qs(y,_(e))}function ee(e){return l=n,m&&i?h(e):(i=a=n,c)}function te(){l!==n&&_o(l),d=0,i=u=a=l=n}function ne(){return l===n?c:ee(Ll())}function b(){var e=Ll(),r=v(e);if(i=arguments,a=this,u=e,r){if(l===n)return g(u);if(p)return _o(l),l=qs(y,t),h(u)}return l===n&&(l=qs(y,t)),c}return b.cancel=te,b.flush=ne,b}var Kl=k(function(e,t){return Gi(e,1,t)}),ql=k(function(e,t,n){return Gi(e,Qu(t)||0,n)});function Jl(e){return ts(e,ie)}function Yl(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw new Lt(o);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(Yl.Cache||mi),n}Yl.Cache=mi;function Xl(e){if(typeof e!=`function`)throw new Lt(o);return function(){var t=arguments;switch(t.length){case 0:return!e.call(this);case 1:return!e.call(this,t[0]);case 2:return!e.call(this,t[0],t[1]);case 3:return!e.call(this,t[0],t[1],t[2])}return!e.apply(this,t)}}function Zl(e){return Bl(2,e)}var Ql=ho(function(e,t){t=t.length==1&&K(t[0])?E(t[0],_r(A())):E($i(t,1),_r(A()));var n=t.length;return k(function(r){for(var i=-1,a=Cn(r.length,n);++i<a;)r[i]=t[i].call(this,r[i]);return Hn(e,this,r)})}),$l=k(function(e,t){return ts(e,te,n,t,Mr(t,ps($l)))}),G=k(function(e,t){return ts(e,ne,n,t,Mr(t,ps(G)))}),eu=cs(function(e,t){return ts(e,re,n,n,n,t)});function tu(e,t){if(typeof e!=`function`)throw new Lt(o);return t=t===n?t:Z(t),k(e,t)}function nu(e,t){if(typeof e!=`function`)throw new Lt(o);return t=t==null?0:bn(Z(t),0),k(function(n){var r=n[t],i=go(n,0,t);return r&&Xn(i,r),Hn(e,this,i)})}function ru(e,t,n){var r=!0,i=!0;if(typeof e!=`function`)throw new Lt(o);return q(n)&&(r=`leading`in n?!!n.leading:r,i=`trailing`in n?!!n.trailing:i),Gl(e,t,{leading:r,maxWait:t,trailing:i})}function iu(e){return zl(e,1)}function au(e,t){return $l(po(t),e)}function ou(){if(!arguments.length)return[];var e=arguments[0];return K(e)?e:[e]}function su(e){return Hi(e,p)}function cu(e,t){return t=typeof t==`function`?t:n,Hi(e,p,t)}function lu(e){return Hi(e,d|p)}function uu(e,t){return t=typeof t==`function`?t:n,Hi(e,d|p,t)}function du(e,t){return t==null||Wi(e,t,Cd(t))}function fu(e,t){return e===t||e!==e&&t!==t}var pu=Xo(ca),mu=Xo(function(e,t){return e>=t}),hu=ha(function(){return arguments}())?ha:function(e){return J(e)&&S.call(e,`callee`)&&!tn.call(e,`callee`)},K=ht.isArray,gu=In?_r(In):ga;function _u(e){return e!=null&&Au(e.length)&&!Ou(e)}function vu(e){return J(e)&&_u(e)}function yu(e){return e===!0||e===!1||J(e)&&sa(e)==Ce}var bu=mn||Yf,xu=Ln?_r(Ln):_a;function Su(e){return J(e)&&e.nodeType===1&&!Ru(e)}function Cu(e){if(e==null)return!0;if(_u(e)&&(K(e)||typeof e==`string`||typeof e.splice==`function`||bu(e)||Wu(e)||hu(e)))return!e.length;var t=bs(e);if(t==ke||t==Ie)return!e.size;if(Is(e))return!Da(e).length;for(var n in e)if(S.call(e,n))return!1;return!0}function wu(e,t){return va(e,t)}function Tu(e,t,r){r=typeof r==`function`?r:n;var i=r?r(e,t):n;return i===n?va(e,t,n,r):!!i}function Eu(e){if(!J(e))return!1;var t=sa(e);return t==Ee||t==Te||typeof e.message==`string`&&typeof e.name==`string`&&!Ru(e)}function Du(e){return typeof e==`number`&&_n(e)}function Ou(e){if(!q(e))return!1;var t=sa(e);return t==De||t==Oe||t==Se||t==Pe}function ku(e){return typeof e==`number`&&e==Z(e)}function Au(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=pe}function q(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}function J(e){return typeof e==`object`&&!!e}var Y=Rn?_r(Rn):ba;function ju(e,t){return e===t||xa(e,t,hs(t))}function Mu(e,t,r){return r=typeof r==`function`?r:n,xa(e,t,hs(t),r)}function Nu(e){return Lu(e)&&e!=+e}function Pu(e){if(Fs(e))throw new Mt(a);return Sa(e)}function Fu(e){return e===null}function Iu(e){return e==null}function Lu(e){return typeof e==`number`||J(e)&&sa(e)==Ae}function Ru(e){if(!J(e)||sa(e)!=Me)return!1;var t=$t(e);if(t===null)return!0;var n=S.call(t,`constructor`)&&t.constructor;return typeof n==`function`&&n instanceof n&&Ht.call(n)==Kt}var zu=zn?_r(zn):Ca;function Bu(e){return ku(e)&&e>=-pe&&e<=pe}var Vu=Bn?_r(Bn):wa;function Hu(e){return typeof e==`string`||!K(e)&&J(e)&&sa(e)==Le}function Uu(e){return typeof e==`symbol`||J(e)&&sa(e)==Re}var Wu=Vn?_r(Vn):Ta;function Gu(e){return e===n}function Ku(e){return J(e)&&bs(e)==Be}function qu(e){return J(e)&&sa(e)==Ve}var X=Xo(ka),Ju=Xo(function(e,t){return e<=t});function Yu(e){if(!e)return[];if(_u(e))return Hu(e)?Rr(e):Oo(e);if(an&&e[an])return kr(e[an]());var t=bs(e);return(t==ke?Ar:t==Ie?Nr:Vd)(e)}function Xu(e){return e?(e=Qu(e),e===fe||e===-fe?(e<0?-1:1)*me:e===e?e:0):e===0?e:0}function Z(e){var t=Xu(e),n=t%1;return t===t?n?t-n:t:0}function Zu(e){return e?Vi(Z(e),0,ge):0}function Qu(e){if(typeof e==`number`)return e;if(Uu(e))return he;if(q(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=q(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=gr(e);var n=Tt.test(e);return n||Dt.test(e)?On(e.slice(2),n?2:8):wt.test(e)?he:+e}function $u(e){return ko(e,wd(e))}function ed(e){return e?Vi(Z(e),-pe,pe):e===0?e:0}function Q(e){return e==null?``:ro(e)}var td=No(function(e,t){if(Is(t)||_u(t)){ko(t,Cd(t),e);return}for(var n in t)S.call(t,n)&&Pi(e,n,t[n])}),nd=No(function(e,t){ko(t,wd(t),e)}),rd=No(function(e,t,n,r){ko(t,wd(t),e,r)}),id=No(function(e,t,n,r){ko(t,Cd(t),e,r)}),ad=cs(Bi);function od(e,t){var n=Xr(e);return t==null?n:Li(n,t)}var sd=k(function(e,t){e=x(e);var r=-1,i=t.length,a=i>2?t[2]:n;for(a&&As(t[0],t[1],a)&&(i=1);++r<i;)for(var o=t[r],s=wd(o),c=-1,l=s.length;++c<l;){var u=s[c],d=e[u];(d===n||fu(d,Bt[u])&&!S.call(e,u))&&(e[u]=o[u])}return e}),cd=k(function(e){return e.push(n,rs),Hn(Od,n,e)});function ld(e,t){return rr(e,A(t,3),na)}function ud(e,t){return rr(e,A(t,3),ra)}function dd(e,t){return e==null?e:ea(e,A(t,3),wd)}function fd(e,t){return e==null?e:ta(e,A(t,3),wd)}function pd(e,t){return e&&na(e,A(t,3))}function md(e,t){return e&&ra(e,A(t,3))}function hd(e){return e==null?[]:ia(e,Cd(e))}function gd(e){return e==null?[]:ia(e,wd(e))}function _d(e,t,r){var i=e==null?n:aa(e,t);return i===n?r:i}function vd(e,t){return e!=null&&Cs(e,t,la)}function yd(e,t){return e!=null&&Cs(e,t,ua)}var bd=Wo(function(e,t,n){t!=null&&typeof t.toString!=`function`&&(t=Gt.call(t)),e[t]=n},Df(jf)),xd=Wo(function(e,t,n){t!=null&&typeof t.toString!=`function`&&(t=Gt.call(t)),S.call(e,t)?e[t].push(n):e[t]=[n]},A),Sd=k(ma);function Cd(e){return _u(e)?ki(e):Da(e)}function wd(e){return _u(e)?ki(e,!0):Oa(e)}function Td(e,t){var n={};return t=A(t,3),na(e,function(e,r,i){zi(n,t(e,r,i),e)}),n}function Ed(e,t){var n={};return t=A(t,3),na(e,function(e,r,i){zi(n,r,t(e,r,i))}),n}var Dd=No(function(e,t,n){Na(e,t,n)}),Od=No(function(e,t,n,r){Na(e,t,n,r)}),kd=cs(function(e,t){var n={};if(e==null)return n;var r=!1;t=E(t,function(t){return t=mo(t,e),r||=t.length>1,t}),ko(e,us(e),n),r&&(n=Hi(n,d|f|p,is));for(var i=t.length;i--;)ao(n,t[i]);return n});function Ad(e,t){return Md(e,Xl(A(t)))}var jd=cs(function(e,t){return e==null?{}:La(e,t)});function Md(e,t){if(e==null)return{};var n=E(us(e),function(e){return[e]});return t=A(t),Ra(e,n,function(e,n){return t(e,n[0])})}function Nd(e,t,r){t=mo(t,e);var i=-1,a=t.length;for(a||(a=1,e=n);++i<a;){var o=e==null?n:e[P(t[i])];o===n&&(i=a,o=r),e=Ou(o)?o.call(e):o}return e}function Pd(e,t,n){return e==null?e:qa(e,t,n)}function Fd(e,t,r,i){return i=typeof i==`function`?i:n,e==null?e:qa(e,t,r,i)}var $=es(Cd),Id=es(wd);function Ld(e,t,n){var r=K(e),i=r||bu(e)||Wu(e);if(t=A(t,4),n==null){var a=e&&e.constructor;n=i?r?new a:[]:q(e)&&Ou(a)?Xr($t(e)):{}}return(i?Wn:na)(e,function(e,r,i){return t(n,e,r,i)}),n}function Rd(e,t){return e==null?!0:ao(e,t)}function zd(e,t,n){return e==null?e:oo(e,t,po(n))}function Bd(e,t,r,i){return i=typeof i==`function`?i:n,e==null?e:oo(e,t,po(r),i)}function Vd(e){return e==null?[]:vr(e,Cd(e))}function Hd(e){return e==null?[]:vr(e,wd(e))}function Ud(e,t,r){return r===n&&(r=t,t=n),r!==n&&(r=Qu(r),r=r===r?r:0),t!==n&&(t=Qu(t),t=t===t?t:0),Vi(Qu(e),t,r)}function Wd(e,t,r){return t=Xu(t),r===n?(r=t,t=0):r=Xu(r),e=Qu(e),da(e,t,r)}function Gd(e,t,r){if(r&&typeof r!=`boolean`&&As(e,t,r)&&(t=r=n),r===n&&(typeof t==`boolean`?(r=t,t=n):typeof e==`boolean`&&(r=e,e=n)),e===n&&t===n?(e=0,t=1):(e=Xu(e),t===n?(t=e,e=0):t=Xu(t)),e>t){var i=e;e=t,t=i}if(r||e%1||t%1){var a=En();return Cn(e+a*(t-e+Dn(`1e-`+((a+``).length-1))),t)}return Ha(e,t)}var Kd=Ro(function(e,t,n){return t=t.toLowerCase(),e+(n?qd(t):t)});function qd(e){return xf(Q(e).toLowerCase())}function Jd(e){return e=Q(e),e&&e.replace(kt,Cr).replace(gn,``)}function Yd(e,t,r){e=Q(e),t=ro(t);var i=e.length;r=r===n?i:Vi(Z(r),0,i);var a=r;return r-=t.length,r>=0&&e.slice(r,a)==t}function Xd(e){return e=Q(e),e&&at.test(e)?e.replace(rt,wr):e}function Zd(e){return e=Q(e),e&&pt.test(e)?e.replace(ft,`\\$&`):e}var Qd=Ro(function(e,t,n){return e+(n?`-`:``)+t.toLowerCase()}),$d=Ro(function(e,t,n){return e+(n?` `:``)+t.toLowerCase()}),ef=Lo(`toLowerCase`);function tf(e,t,n){e=Q(e),t=Z(t);var r=t?Lr(e):0;if(!t||r>=t)return e;var i=(t-r)/2;return qo(fn(i),n)+e+qo(dn(i),n)}function nf(e,t,n){e=Q(e),t=Z(t);var r=t?Lr(e):0;return t&&r<t?e+qo(t-r,n):e}function rf(e,t,n){e=Q(e),t=Z(t);var r=t?Lr(e):0;return t&&r<t?qo(t-r,n)+e:e}function af(e,t,n){return n||t==null?t=0:t&&=+t,Tn(Q(e).replace(mt,``),t||0)}function of(e,t,r){return t=(r?As(e,t,r):t===n)?1:Z(t),Wa(Q(e),t)}function sf(){var e=arguments,t=Q(e[0]);return e.length<3?t:t.replace(e[1],e[2])}var cf=Ro(function(e,t,n){return e+(n?`_`:``)+t.toLowerCase()});function lf(e,t,r){return r&&typeof r!=`number`&&As(e,t,r)&&(t=r=n),r=r===n?ge:r>>>0,r?(e=Q(e),e&&(typeof t==`string`||t!=null&&!zu(t))&&(t=ro(t),!t&&Dr(e))?go(Rr(e),0,r):e.split(t,r)):[]}var uf=Ro(function(e,t,n){return e+(n?` `:``)+xf(t)});function df(e,t,n){return e=Q(e),n=n==null?0:Vi(Z(n),0,e.length),t=ro(t),e.slice(n,n+t.length)==t}function ff(e,t,r){var i=D.templateSettings;r&&As(e,t,r)&&(t=n),e=Q(e),t=rd({},t,i,ns);var a=rd({},t.imports,i.imports,ns),o=Cd(a),c=vr(a,o),l,u,d=0,f=t.interpolate||At,p=`__p += '`,m=Ft((t.escape||At).source+`|`+f.source+`|`+(f===ct?St:At).source+`|`+(t.evaluate||At).source+`|$`,`g`),h=`//# sourceURL=`+(S.call(t,`sourceURL`)?(t.sourceURL+``).replace(/\s/g,` `):`lodash.templateSources[`+ ++Sn+`]`)+`
|
|
12
|
-
`;e.replace(m,function(t,n,r,i,a,o){return r||=i,p+=e.slice(d,o).replace(jt,Tr),n&&(l=!0,p+=`' +
|
|
13
|
-
__e(`+n+`) +
|
|
14
|
-
'`),a&&(u=!0,p+=`';
|
|
15
|
-
`+a+`;
|
|
16
|
-
__p += '`),r&&(p+=`' +
|
|
17
|
-
((__t = (`+r+`)) == null ? '' : __t) +
|
|
18
|
-
'`),d=o+t.length,t}),p+=`';
|
|
19
|
-
`;var g=S.call(t,`variable`)&&t.variable;if(!g)p=`with (obj) {
|
|
20
|
-
`+p+`
|
|
21
|
-
}
|
|
22
|
-
`;else if(bt.test(g))throw new Mt(s);p=(u?p.replace($e,``):p).replace(et,`$1`).replace(tt,`$1;`),p=`function(`+(g||`obj`)+`) {
|
|
23
|
-
`+(g?``:`obj || (obj = {});
|
|
24
|
-
`)+`var __t, __p = ''`+(l?`, __e = _.escape`:``)+(u?`, __j = Array.prototype.join;
|
|
25
|
-
function print() { __p += __j.call(arguments, '') }
|
|
26
|
-
`:`;
|
|
27
|
-
`)+p+`return __p
|
|
28
|
-
}`;var _=Cf(function(){return Nt(o,h+`return `+p).apply(n,c)});if(_.source=p,Eu(_))throw _;return _}function pf(e){return Q(e).toLowerCase()}function mf(e){return Q(e).toUpperCase()}function hf(e,t,r){if(e=Q(e),e&&(r||t===n))return gr(e);if(!e||!(t=ro(t)))return e;var i=Rr(e),a=Rr(t);return go(i,br(i,a),xr(i,a)+1).join(``)}function gf(e,t,r){if(e=Q(e),e&&(r||t===n))return e.slice(0,zr(e)+1);if(!e||!(t=ro(t)))return e;var i=Rr(e);return go(i,0,xr(i,Rr(t))+1).join(``)}function _f(e,t,r){if(e=Q(e),e&&(r||t===n))return e.replace(mt,``);if(!e||!(t=ro(t)))return e;var i=Rr(e);return go(i,br(i,Rr(t))).join(``)}function vf(e,t){var r=ae,i=oe;if(q(t)){var a=`separator`in t?t.separator:a;r=`length`in t?Z(t.length):r,i=`omission`in t?ro(t.omission):i}e=Q(e);var o=e.length;if(Dr(e)){var s=Rr(e);o=s.length}if(r>=o)return e;var c=r-Lr(i);if(c<1)return i;var l=s?go(s,0,c).join(``):e.slice(0,c);if(a===n)return l+i;if(s&&(c+=l.length-c),zu(a)){if(e.slice(c).search(a)){var u,d=l;for(a.global||(a=Ft(a.source,Q(Ct.exec(a))+`g`)),a.lastIndex=0;u=a.exec(d);)var f=u.index;l=l.slice(0,f===n?c:f)}}else if(e.indexOf(ro(a),c)!=c){var p=l.lastIndexOf(a);p>-1&&(l=l.slice(0,p))}return l+i}function yf(e){return e=Q(e),e&&it.test(e)?e.replace(nt,Br):e}var bf=Ro(function(e,t,n){return e+(n?` `:``)+t.toUpperCase()}),xf=Lo(`toUpperCase`);function Sf(e,t,r){return e=Q(e),t=r?n:t,t===n?Or(e)?Ur(e):nr(e):e.match(t)||[]}var Cf=k(function(e,t){try{return Hn(e,n,t)}catch(e){return Eu(e)?e:new Mt(e)}}),wf=cs(function(e,t){return Wn(t,function(t){t=P(t),zi(e,t,Vl(e[t],e))}),e});function Tf(e){var t=e==null?0:e.length,n=A();return e=t?E(e,function(e){if(typeof e[1]!=`function`)throw new Lt(o);return[n(e[0]),e[1]]}):[],k(function(n){for(var r=-1;++r<t;){var i=e[r];if(Hn(i[0],this,n))return Hn(i[1],this,n)}})}function Ef(e){return Ui(Hi(e,d))}function Df(e){return function(){return e}}function Of(e,t){return e==null||e!==e?t:e}var kf=Ho(),Af=Ho(!0);function jf(e){return e}function Mf(e){return Ea(typeof e==`function`?e:Hi(e,d))}function Nf(e){return ja(Hi(e,d))}function Pf(e,t){return Ma(e,Hi(t,d))}var Ff=k(function(e,t){return function(n){return ma(n,e,t)}}),If=k(function(e,t){return function(n){return ma(e,n,t)}});function Lf(e,t,n){var r=Cd(t),i=ia(t,r);n==null&&!(q(t)&&(i.length||!r.length))&&(n=t,t=e,e=this,i=ia(t,Cd(t)));var a=!(q(n)&&`chain`in n)||!!n.chain,o=Ou(e);return Wn(i,function(n){var r=t[n];e[n]=r,o&&(e.prototype[n]=function(){var t=this.__chain__;if(a||t){var n=e(this.__wrapped__);return(n.__actions__=Oo(this.__actions__)).push({func:r,args:arguments,thisArg:e}),n.__chain__=t,n}return r.apply(e,Xn([this.value()],arguments))})}),e}function Rf(){return jn._===this&&(jn._=qt),this}function zf(){}function Bf(e){return e=Z(e),k(function(t){return Fa(t,e)})}var Vf=Ko(E),Hf=Ko(Kn),Uf=Ko($n);function Wf(e){return js(e)?lr(P(e)):za(e)}function Gf(e){return function(t){return e==null?n:aa(e,t)}}var Kf=Yo(),qf=Yo(!0);function Jf(){return[]}function Yf(){return!1}function Xf(){return{}}function Zf(){return``}function Qf(){return!0}function $f(e,t){if(e=Z(e),e<1||e>pe)return[];var n=ge,r=Cn(e,ge);t=A(t),e-=ge;for(var i=mr(r,t);++n<e;)t(n);return i}function ep(e){return K(e)?E(e,P):Uu(e)?[e]:Oo(Xs(Q(e)))}function tp(e){var t=++Ut;return Q(e)+t}var np=Go(function(e,t){return e+t},0),rp=Qo(`ceil`),ip=Go(function(e,t){return e/t},1),ap=Qo(`floor`);function op(e){return e&&e.length?Xi(e,jf,ca):n}function sp(e,t){return e&&e.length?Xi(e,A(t,2),ca):n}function cp(e){return cr(e,jf)}function lp(e,t){return cr(e,A(t,2))}function up(e){return e&&e.length?Xi(e,jf,ka):n}function dp(e,t){return e&&e.length?Xi(e,A(t,2),ka):n}var fp=Go(function(e,t){return e*t},1),pp=Qo(`round`),mp=Go(function(e,t){return e-t},0);function hp(e){return e&&e.length?pr(e,jf):0}function gp(e,t){return e&&e.length?pr(e,A(t,2)):0}return D.after=Rl,D.ary=zl,D.assign=td,D.assignIn=nd,D.assignInWith=rd,D.assignWith=id,D.at=ad,D.before=Bl,D.bind=Vl,D.bindAll=wf,D.bindKey=Hl,D.castArray=ou,D.chain=nl,D.chunk=ec,D.compact=tc,D.concat=nc,D.cond=Tf,D.conforms=Ef,D.constant=Df,D.countBy=pl,D.create=od,D.curry=Ul,D.curryRight=Wl,D.debounce=Gl,D.defaults=sd,D.defaultsDeep=cd,D.defer=Kl,D.delay=ql,D.difference=F,D.differenceBy=rc,D.differenceWith=I,D.drop=ic,D.dropRight=ac,D.dropRightWhile=oc,D.dropWhile=sc,D.fill=cc,D.filter=hl,D.flatMap=vl,D.flatMapDeep=yl,D.flatMapDepth=bl,D.flatten=dc,D.flattenDeep=fc,D.flattenDepth=pc,D.flip=Jl,D.flow=kf,D.flowRight=Af,D.fromPairs=mc,D.functions=hd,D.functionsIn=gd,D.groupBy=Cl,D.initial=_c,D.intersection=vc,D.intersectionBy=yc,D.intersectionWith=bc,D.invert=bd,D.invertBy=xd,D.invokeMap=wl,D.iteratee=Mf,D.keyBy=Tl,D.keys=Cd,D.keysIn=wd,D.map=El,D.mapKeys=Td,D.mapValues=Ed,D.matches=Nf,D.matchesProperty=Pf,D.memoize=Yl,D.merge=Dd,D.mergeWith=Od,D.method=Ff,D.methodOf=If,D.mixin=Lf,D.negate=Xl,D.nthArg=Bf,D.omit=kd,D.omitBy=Ad,D.once=Zl,D.orderBy=Dl,D.over=Vf,D.overArgs=Ql,D.overEvery=Hf,D.overSome=Uf,D.partial=$l,D.partialRight=G,D.partition=Ol,D.pick=jd,D.pickBy=Md,D.property=Wf,D.propertyOf=Gf,D.pull=L,D.pullAll=R,D.pullAllBy=Tc,D.pullAllWith=Ec,D.pullAt=Dc,D.range=Kf,D.rangeRight=qf,D.rearg=eu,D.reject=jl,D.remove=Oc,D.rest=tu,D.reverse=kc,D.sampleSize=Nl,D.set=Pd,D.setWith=Fd,D.shuffle=Pl,D.slice=Ac,D.sortBy=W,D.sortedUniq=Ic,D.sortedUniqBy=Lc,D.split=lf,D.spread=nu,D.tail=Rc,D.take=B,D.takeRight=V,D.takeRightWhile=zc,D.takeWhile=H,D.tap=rl,D.throttle=ru,D.thru=il,D.toArray=Yu,D.toPairs=$,D.toPairsIn=Id,D.toPath=ep,D.toPlainObject=$u,D.transform=Ld,D.unary=iu,D.union=Bc,D.unionBy=Vc,D.unionWith=Hc,D.uniq=Uc,D.uniqBy=Wc,D.uniqWith=Gc,D.unset=Rd,D.unzip=Kc,D.unzipWith=qc,D.update=zd,D.updateWith=Bd,D.values=Vd,D.valuesIn=Hd,D.without=Jc,D.words=Sf,D.wrap=au,D.xor=Yc,D.xorBy=Xc,D.xorWith=Zc,D.zip=Qc,D.zipObject=$c,D.zipObjectDeep=el,D.zipWith=tl,D.entries=$,D.entriesIn=Id,D.extend=nd,D.extendWith=rd,Lf(D,D),D.add=np,D.attempt=Cf,D.camelCase=Kd,D.capitalize=qd,D.ceil=rp,D.clamp=Ud,D.clone=su,D.cloneDeep=lu,D.cloneDeepWith=uu,D.cloneWith=cu,D.conformsTo=du,D.deburr=Jd,D.defaultTo=Of,D.divide=ip,D.endsWith=Yd,D.eq=fu,D.escape=Xd,D.escapeRegExp=Zd,D.every=ml,D.find=gl,D.findIndex=lc,D.findKey=ld,D.findLast=_l,D.findLastIndex=uc,D.findLastKey=ud,D.floor=ap,D.forEach=xl,D.forEachRight=Sl,D.forIn=dd,D.forInRight=fd,D.forOwn=pd,D.forOwnRight=md,D.get=_d,D.gt=pu,D.gte=mu,D.has=vd,D.hasIn=yd,D.head=hc,D.identity=jf,D.includes=U,D.indexOf=gc,D.inRange=Wd,D.invoke=Sd,D.isArguments=hu,D.isArray=K,D.isArrayBuffer=gu,D.isArrayLike=_u,D.isArrayLikeObject=vu,D.isBoolean=yu,D.isBuffer=bu,D.isDate=xu,D.isElement=Su,D.isEmpty=Cu,D.isEqual=wu,D.isEqualWith=Tu,D.isError=Eu,D.isFinite=Du,D.isFunction=Ou,D.isInteger=ku,D.isLength=Au,D.isMap=Y,D.isMatch=ju,D.isMatchWith=Mu,D.isNaN=Nu,D.isNative=Pu,D.isNil=Iu,D.isNull=Fu,D.isNumber=Lu,D.isObject=q,D.isObjectLike=J,D.isPlainObject=Ru,D.isRegExp=zu,D.isSafeInteger=Bu,D.isSet=Vu,D.isString=Hu,D.isSymbol=Uu,D.isTypedArray=Wu,D.isUndefined=Gu,D.isWeakMap=Ku,D.isWeakSet=qu,D.join=xc,D.kebabCase=Qd,D.last=Sc,D.lastIndexOf=Cc,D.lowerCase=$d,D.lowerFirst=ef,D.lt=X,D.lte=Ju,D.max=op,D.maxBy=sp,D.mean=cp,D.meanBy=lp,D.min=up,D.minBy=dp,D.stubArray=Jf,D.stubFalse=Yf,D.stubObject=Xf,D.stubString=Zf,D.stubTrue=Qf,D.multiply=fp,D.nth=wc,D.noConflict=Rf,D.noop=zf,D.now=Ll,D.pad=tf,D.padEnd=nf,D.padStart=rf,D.parseInt=af,D.random=Gd,D.reduce=kl,D.reduceRight=Al,D.repeat=of,D.replace=sf,D.result=Nd,D.round=pp,D.runInContext=e,D.sample=Ml,D.size=Fl,D.snakeCase=cf,D.some=Il,D.sortedIndex=jc,D.sortedIndexBy=Mc,D.sortedIndexOf=Nc,D.sortedLastIndex=Pc,D.sortedLastIndexBy=Fc,D.sortedLastIndexOf=z,D.startCase=uf,D.startsWith=df,D.subtract=mp,D.sum=hp,D.sumBy=gp,D.template=ff,D.times=$f,D.toFinite=Xu,D.toInteger=Z,D.toLength=Zu,D.toLower=pf,D.toNumber=Qu,D.toSafeInteger=ed,D.toString=Q,D.toUpper=mf,D.trim=hf,D.trimEnd=gf,D.trimStart=_f,D.truncate=vf,D.unescape=yf,D.uniqueId=tp,D.upperCase=bf,D.upperFirst=xf,D.each=xl,D.eachRight=Sl,D.first=hc,Lf(D,function(){var e={};return na(D,function(t,n){S.call(D.prototype,n)||(e[n]=t)}),e}(),{chain:!1}),D.VERSION=r,Wn([`bind`,`bindKey`,`curry`,`curryRight`,`partial`,`partialRight`],function(e){D[e].placeholder=D}),Wn([`drop`,`take`],function(e,t){O.prototype[e]=function(r){r=r===n?1:bn(Z(r),0);var i=this.__filtered__&&!t?new O(this):this.clone();return i.__filtered__?i.__takeCount__=Cn(r,i.__takeCount__):i.__views__.push({size:Cn(r,ge),type:e+(i.__dir__<0?`Right`:``)}),i},O.prototype[e+`Right`]=function(t){return this.reverse()[e](t).reverse()}}),Wn([`filter`,`map`,`takeWhile`],function(e,t){var n=t+1,r=n==le||n==de;O.prototype[e]=function(e){var t=this.clone();return t.__iteratees__.push({iteratee:A(e,3),type:n}),t.__filtered__=t.__filtered__||r,t}}),Wn([`head`,`last`],function(e,t){var n=`take`+(t?`Right`:``);O.prototype[e]=function(){return this[n](1).value()[0]}}),Wn([`initial`,`tail`],function(e,t){var n=`drop`+(t?``:`Right`);O.prototype[e]=function(){return this.__filtered__?new O(this):this[n](1)}}),O.prototype.compact=function(){return this.filter(jf)},O.prototype.find=function(e){return this.filter(e).head()},O.prototype.findLast=function(e){return this.reverse().find(e)},O.prototype.invokeMap=k(function(e,t){return typeof e==`function`?new O(this):this.map(function(n){return ma(n,e,t)})}),O.prototype.reject=function(e){return this.filter(Xl(A(e)))},O.prototype.slice=function(e,t){e=Z(e);var r=this;return r.__filtered__&&(e>0||t<0)?new O(r):(e<0?r=r.takeRight(-e):e&&(r=r.drop(e)),t!==n&&(t=Z(t),r=t<0?r.dropRight(-t):r.take(t-e)),r)},O.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},O.prototype.toArray=function(){return this.take(ge)},na(O.prototype,function(e,t){var r=/^(?:filter|find|map|reject)|While$/.test(t),i=/^(?:head|last)$/.test(t),a=D[i?`take`+(t==`last`?`Right`:``):t],o=i||/^find/.test(t);a&&(D.prototype[t]=function(){var t=this.__wrapped__,s=i?[1]:arguments,c=t instanceof O,l=s[0],u=c||K(t),d=function(e){var t=a.apply(D,Xn([e],s));return i&&f?t[0]:t};u&&r&&typeof l==`function`&&l.length!=1&&(c=u=!1);var f=this.__chain__,p=!!this.__actions__.length,m=o&&!f,h=c&&!p;if(!o&&u){t=h?t:new O(this);var g=e.apply(t,s);return g.__actions__.push({func:il,args:[d],thisArg:n}),new Qr(g,f)}return m&&h?e.apply(this,s):(g=this.thru(d),m?i?g.value()[0]:g.value():g)})}),Wn([`pop`,`push`,`shift`,`sort`,`splice`,`unshift`],function(e){var t=Rt[e],n=/^(?:push|sort|unshift)$/.test(e)?`tap`:`thru`,r=/^(?:pop|shift)$/.test(e);D.prototype[e]=function(){var e=arguments;if(r&&!this.__chain__){var i=this.value();return t.apply(K(i)?i:[],e)}return this[n](function(n){return t.apply(K(n)?n:[],e)})}}),na(O.prototype,function(e,t){var n=D[t];if(n){var r=n.name+``;S.call(ur,r)||(ur[r]=[]),ur[r].push({name:t,func:n})}}),ur[Uo(n,_).name]=[{name:`wrapper`,func:n}],O.prototype.clone=$r,O.prototype.reverse=ei,O.prototype.value=ti,D.prototype.at=al,D.prototype.chain=ol,D.prototype.commit=sl,D.prototype.next=cl,D.prototype.plant=ul,D.prototype.reverse=dl,D.prototype.toJSON=D.prototype.valueOf=D.prototype.value=fl,D.prototype.first=D.prototype.head,an&&(D.prototype[an]=ll),D})();typeof define==`function`&&typeof define.amd==`object`&&define.amd?(jn._=Wr,define(function(){return Wr})):Nn?((Nn.exports=Wr)._=Wr,Mn._=Wr):jn._=Wr}).call(e)})),fu=du(),pu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof P)||wl(this.declarationNode.parent).unwrap_or(void 0)!==B.Table||!(this.declarationNode.body instanceof rc)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof F)return this.bindFields([e]);let[t,n]=(0,fu.partition)(e.body,e=>e instanceof F);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=El(this.declarationNode.parent.name).map(e=>e.join(`.`)).unwrap_or(`<unnamed>`),n=this.declarationNode.parent.symbol.symbolTable;return[e.callee,...e.args].flatMap(Eu).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=Al(e).unwrap_or(void 0);if(r===void 0)return[];let i=Hc(r),a=n.get(i);return a?(e.referee=a,a.references.push(e),[]):new R(L.BINDING_ERROR,`No column named '${r}' inside Table '${t}'`,e)})})}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}},mu=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 F)return[];let t=e.body.filter(e=>e instanceof P);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}},hu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof rc?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof F)return[];let t=e.body.filter(e=>e instanceof P);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}},K=du(),gu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof Xs)&&wl(this.declarationNode.parent).unwrap_or(void 0)!==B.Project?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof F)return this.bindFields([e]);let[t,n]=(0,K.partition)(e.body,e=>e instanceof F);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Eu).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=>Du(this.ast,[...r.map(e=>({node:e,kind:H.Schema})),{node:n,kind:H.Table},{node:e,kind:H.Column}]))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}},_u=du(),vu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof rc?this.bindBody(this.declarationNode.body):[]}resolvePartialInjections(){let{body:e}=this.declarationNode;return(e?e instanceof rc?e.body:[e]:[]).filter(e=>e instanceof F&&ml(e.callee)).reverse().flatMap(e=>{let t=Dl(e.callee.expression).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=Du(this.ast,[...r.map(e=>({node:e,kind:H.Schema})),{node:n,kind:H.TablePartial}]);return i.length?i:(n.referee?.symbolTable?.forEach(t=>{let r=Ol(t.declaration.callee).unwrap_or(void 0);if(r===void 0)return;let i=this.symbolFactory.create(wc,{declaration:e,tablePartialSymbol:n.referee}),a=Hc(r),o=this.declarationNode.symbol?.symbolTable;o?.has(a)||o?.set(a,i)}),[])})}bindBody(e){if(!e)return[];if(e instanceof F)return this.bindFields([e]);let[t,n]=(0,_u.partition)(e.body,e=>e instanceof F);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((0,_u.last)(n)instanceof I){let e=U((0,_u.last)(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=>!ml(e.callee)))}tryToBindColumnType(e){let t=Dl(e).unwrap_or(void 0);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&Du(this.ast,[...r.map(e=>({node:e,kind:H.Schema})),{node:n,kind:H.Enum}])}tryToBindEnumFieldRef(e){if(Ul(e))return[];if(Wl(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&Ic.includes(t))return[]}let t=Dl(e).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=t.variables;return Du(this.ast,[...i.map(e=>({node:e,kind:H.Schema})),{node:r,kind:H.Enum},{node:n,kind:H.EnumField}])}bindInlineRef(e){return Eu(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?Du(this.ast,[...r.map(e=>({node:e,kind:H.Schema})),{node:n,kind:H.Table},{node:t,kind:H.Column}]):Du(this.declarationNode,[{node:t,kind:H.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}},yu=du(),bu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof rc?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof F)return this.bindFields([e]);let[t,n]=(0,yu.partition)(e.body,e=>e instanceof F);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Eu).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Du(this.ast,[...n.map(e=>({node:e,kind:H.Schema})),{node:t,kind:H.Table}])}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}},xu=du(),Su=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof rc?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof F)return this.bindFields([e]);let[t,n]=(0,xu.partition)(e.body,e=>e instanceof F);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((0,xu.last)(n)instanceof I){let e=U((0,xu.last)(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=Dl(e).unwrap_or(void 0);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&Du(this.ast,[...r.map(e=>({node:e,kind:H.Schema})),{node:n,kind:H.Enum}])}bindInlineRef(e){return Eu(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?Du(this.ast,[...r.map(e=>({node:e,kind:H.Schema})),{node:n,kind:H.Table},{node:t,kind:H.Column}]):Du(this.declarationNode,[{node:t,kind:H.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(Tu(e))(e,this.ast,this.symbolFactory).bind():[])}};function Cu(e){return[Bc,Vc,Uc,Gc,Hc,Wc,Kc,Jc,Yc].map(t=>t(e))}function wu(e){if(e instanceof hc)return H.Schema;if(e instanceof vc)return H.Table;if(e instanceof yc)return H.Column;if(e instanceof gc)return H.Enum;if(e instanceof _c)return H.EnumField;if(e instanceof bc)return H.TableGroup;if(e instanceof xc)return H.TableGroupField;if(e instanceof Sc)return H.TablePartial;if(e instanceof wc)return H.Column;if(e instanceof Cc)return H.PartialInjection;throw Error(`No other possible symbol kind in getSymbolKind`)}function Tu(e){switch(e.type.value.toLowerCase()){case B.Enum:return uu;case B.Table:return vu;case B.TableGroup:return bu;case B.Project:return hu;case B.Ref:return gu;case B.Note:return mu;case B.Indexes:return pu;case B.TablePartial:return Su;case B.Check:return cu;default:return lu}}function Eu(e){if(!e)return[];if(Wl(e))return[{variables:[e],tupleElements:[]}];if(e instanceof ec){let t=Dl(e).unwrap_or(void 0);return t?[t]:[...Eu(e.leftExpression),...Eu(e.rightExpression)]}if(e instanceof $s||e instanceof tc)return Eu(e.expression);if(e instanceof ic){let t=Dl(e).unwrap_or(void 0);return t?[t]:e.elementList.flatMap(Eu)}return[]}function Du(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=wu(e.symbol),i=e instanceof P?Yl(e).unwrap_or(`<invalid name>`):Rc;if(e instanceof Xs&&t.length){let{node:e,kind:n}=t[0];Al(e).unwrap_or(`<unnamed>`)===`public`&&n===H.Schema&&t.shift()}for(let e of t){let{node:t,kind:a}=e,o=Al(t).unwrap_or(`<unnamed>`),s=Xc(o,a),c=n.get(s);if(!c)return[new R(L.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 Ou=class{constructor(e,t){this.ast=e,this.symbolFactory=t}resolvePartialInjections(){return this.ast.body.filter(e=>wl(e).unwrap_or(``)===B.Table).flatMap(e=>new vu(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(Tu(t))(t,this.ast,this.symbolFactory);e.push(...n.bind())}return new Tc(this.ast,e)}},ku=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}},Au=class{constructor(e,t){this.ast=e,this.symbolFactory=new ku(t)}analyze(){return new su(this.ast,this.symbolFactory).validate().chain(e=>new Ou(e,this.symbolFactory).resolve())}validate(){return new su(this.ast,this.symbolFactory).validate().chain(e=>new Tc(e,[]))}};function q(e,t){let{variables:n,tupleElements:r}=Dl(e).unwrap(),i=r.map(e=>Al(e).unwrap()),a=n.map(e=>Al(e).unwrap());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 J(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:throw Error(`Invalid relation op`)}}function Y(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}}}function ju(e){let t=Tl(e).unwrap_or(void 0)?.pop();return t instanceof ic?t.elementList.map(e=>e.referee):[t.referee]}function Mu(e){let t=El(e).unwrap();return{name:t.pop(),schemaName:t}}function Nu(e){return e.expression.literal.value}function Pu(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 Fu(e,t){return Array.isArray(e)?Rs(e.map(({id:e})=>e).sort(),t.map(({id:e})=>e).sort()).every(([e,t])=>e===t):e.id===t.id}function Iu(e){let t=e.split(`
|
|
9
|
+
`;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()||!Ic(this.peek()))return this.errors.push(new A(k.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`,_.create(g.STRING_LITERAL,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 q=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({});var Jl=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===q.ListExpression&&(this.numberOfNestedLBrackets+=1),e===q.GroupExpression&&(this.numberOfNestedLParens+=1),e===q.BlockExpression&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===q.ListExpression&&--this.numberOfNestedLBrackets,e===q.GroupExpression&&--this.numberOfNestedLParens,e===q.BlockExpression&&--this.numberOfNestedLBraces,e}top(){return m(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 g.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[q.GroupExpression,q.ListExpression].includes(e));break;case g.RPAREN:if(this.isWithinGroupExpressionContext())return q.GroupExpression;break;case g.RBRACE:if(this.isWithinBlockExpressionContext())return q.BlockExpression;break;case g.RBRACKET:if(this.isWithinListExpressionContext())return q.ListExpression;break;default:break}}},Yl=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}},J=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},Xl=class{constructor(e,t){this.current=0,this.errors=[],this.contextStack=new Jl,this.synchronizeProgram=()=>{let e=this.peek();e.kind===g.EOF?this.logError(e,k.UNEXPECTED_EOF,`Unexpected EOF`):U(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Il(e)||this.check(g.COLON,g.LBRACE,g.LBRACKET))break;U(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(g.COLON,g.LBRACE,g.LBRACKET))break;U(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(q.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(T,e);try{this.consume(`Expect an opening brace '{'`,g.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof J))throw e;if(!this.canHandle(e))throw new J(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(g.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof J))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new J(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,g.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof J))throw e;if(!this.canHandle(e))throw new J(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(g.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(g.RBRACE)||rc(this.previous(),e))break;U(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(q.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(mc,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(pc,e);try{this.consume(`Expect an opening parenthesis '('`,g.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof J))throw e;if(!this.canHandle(e))throw new J(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(g.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof J))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new J(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(g.RPAREN);)try{this.consume(`Expect a comma ','`,g.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof J))throw t;if(t.partialNode instanceof v&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new J(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,g.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof J))throw e;if(!this.canHandle(e))throw new J(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(g.RPAREN,g.COMMA))break;U(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(q.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(E,e);try{this.consume(`Expect an opening bracket '['`,g.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof J))throw e;if(!this.canHandle(e))throw new J(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(g.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof J))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new J(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(g.RBRACKET);)try{this.consume(`Expect a comma ','`,g.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof J))throw n;if(n.partialNode instanceof v&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new J(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,g.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof J))throw e;if(!this.canHandle(e))throw new J(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(g.COMMA,g.RBRACKET))break;U(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(g.COMMA,g.RBRACKET,g.COLON))break;U(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(g.COMMA,g.RBRACKET))break;U(e),this.advance()}},this.tokens=e,this.nodeFactory=new Yl(t)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===g.EOF}advance(){return this.isAtEnd()?m(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?m(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(),k.UNEXPECTED_TOKEN,e),new J(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(U(this.peek()),this.logError(this.advance(),k.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)U(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(b,{body:e,eof:t});return this.gatherInvalid(),new Mc({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 J))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(x,e);try{this.consume(`Expect an identifier`,g.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof J?new J(e.token,t(),e.handlerContext):e}if(!this.check(g.COLON,g.LBRACE,g.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof J))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new J(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Il(this.peek()))if(e.as=this.advance(),this.check(g.COLON,g.LBRACE,g.LBRACKET))this.logError(this.peek(),k.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof J))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new J(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(g.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof J?(e.attributeList=n.partialNode,new J(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,g.LBRACE,g.COLON))return t();try{if(this.match(g.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof x?(U(t),this.logError(t,k.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 J?(e.body=n.partialNode,new J(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(x,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(x,e);try{this.consume(`Expect an identifier`,g.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof J?(e.type=n.partialNode,new J(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,g.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof J?(e.bodyColon=n.partialNode,new J(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof x?this.errors.push(new A(k.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof J?(e.body=n.partialNode,new J(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(x,e)}expression(){let e={args:[]},t=()=>Fl(e.callee,e.args,this.nodeFactory).unwrap_or(this.nodeFactory.create(w,e));try{e.callee=this.normalExpression()}catch(n){throw n instanceof J?(e.callee=n.partialNode,new J(n.token,t(),n.handlerContext)):n}if(this.shouldStopExpression())return t();let n=e.callee;for(;!this.shouldStopExpression();){ic(this.previous())||this.logError(n,k.MISSING_SPACES,`Expect a following space`);try{n=this.normalExpression(),e.args.push(n)}catch(r){throw r instanceof J?(n=r.partialNode,e.args.push(n),new J(r.token,t(),r.handlerContext)):r}}return t()}shouldStopExpression(){if(this.isAtEnd()||nc(this.previous()))return!0;let e=this.peek().kind;return e===g.RBRACE||e===g.RBRACKET||e===g.RPAREN||e===g.COMMA||e===g.COLON}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===g.LPAREN){let{left:r}=nu(n);if(r<e||rc(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(D,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof J?(t=this.nodeFactory.create(D,{callee:t,argumentList:e.partialNode}),new J(e.token,t,e.handlerContext)):e}}else if(n.kind===g.LBRACKET){if(ic(this.previous()))break;try{t=this.nodeFactory.create(vc,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof J?(t=this.nodeFactory.create(vc,{expression:t,indexer:e.partialNode}),new J(e.token,t,e.handlerContext)):e}}else if(tc(n)){let r=n,i=nu(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(fc,{expression:t,op:r})}else{let n=Ql(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(dc,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof J?(t=this.nodeFactory.create(dc,{leftExpression:t,op:r,rightExpression:e.partialNode}),new J(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(tc(this.peek())){let t={};t.op=this.peek();let n=eu(t.op);if(n.right===null)throw this.logError(t.op,k.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new J(t.op,this.nodeFactory.create(_c,{pre:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof J?(t.expression=e.partialNode,new J(e.token,this.nodeFactory.create(S,t),e.handlerContext)):e}e=this.nodeFactory.create(S,t)}else if(e=this.extractOperand(),e instanceof _c)throw new J(this.peek(),this.nodeFactory.create(_c,{pre:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(g.NUMERIC_LITERAL,g.STRING_LITERAL,g.COLOR_LITERAL,g.QUOTED_STRING,g.IDENTIFIER)?this.primaryExpression():this.check(g.FUNCTION_EXPRESSION)?this.functionExpression():this.check(g.LBRACKET)?this.listExpression():this.check(g.LBRACE)?this.blockExpression():this.check(g.LPAREN)?this.tupleExpression():(this.peek().kind===g.EOF?this.logError(this.peek(),k.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),k.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(_c,{pre:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,g.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof J?new J(t.token,this.nodeFactory.create(C,e),t.handlerContext):t}return this.nodeFactory.create(C,e)}canBeField(){return this.peek().kind===g.IDENTIFIER&&this.peek(1).kind===g.COLON}primaryExpression(){if(this.match(g.COLOR_LITERAL,g.STRING_LITERAL,g.NUMERIC_LITERAL))return this.nodeFactory.create(O,{expression:this.nodeFactory.create(hc,{literal:this.previous()})});if(this.match(g.QUOTED_STRING,g.IDENTIFIER))return this.nodeFactory.create(O,{expression:this.nodeFactory.create(gc,{variable:this.previous()})});throw this.logError(this.peek(),k.UNEXPECTED_TOKEN,`Expect a variable or literal`),new J(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(g.COLON,g.RBRACKET,g.COMMA)){let t=this.peek();this.logError(t,k.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(lc,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof J))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new J(t.token,this.nodeFactory.create(uc,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(g.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(uc,e)}attributeValue(){let e;try{e=this.peek().kind===g.IDENTIFIER&&this.peek(1).kind===g.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof J)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==g.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(g.COLON,g.COMMA,g.RBRACKET);)try{this.consume(`Expect an identifier`,g.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof J?new J(t.token,this.nodeFactory.create(lc,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(lc,{identifiers:e})}logError(e,t,n){this.errors.push(new A(t,n,e))}},Zl={"+":{left:9,right:10},"*":{left:11,right:12},"-":{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 Ql(e){return Zl[e.value]||{left:null,right:null}}var $l={"+":{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 eu(e){return $l[e.value]||{left:null,right:null}}var tu={"(":{left:14,right:null}};function nu(e){return tu[e.value]||{left:null,right:null}}var ru=class{constructor(e,t){this.ast=e,this.symbolFactory=t,this.publicSchemaSymbol=this.symbolFactory.create(Sc,{symbolTable:new il}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){let e=[];this.ast.body.forEach(t=>{if(t.parent=this.ast,t.type===void 0)return;let n=new(gl(t))(t,this.publicSchemaSymbol.symbolTable,this.symbolFactory);e.push(...n.validate())});let t=this.ast.body.filter(e=>kl(e).unwrap_or(void 0)===N.Project);return t.length>1&&t.forEach(t=>e.push(new A(k.PROJECT_REDEFINED,`Only one project can exist`,t))),new Mc(this.ast,e)}},iu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return[]}},au=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 w)return[];let t=e.body.filter(e=>e instanceof x);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(gu(e))(e,this.ast,this.symbolFactory).bind():[])}},ou=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof T?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof w)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(gu(e))(e,this.ast,this.symbolFactory).bind():[])}},su=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof x)||kl(this.declarationNode.parent).unwrap_or(void 0)!==N.Table||!(this.declarationNode.body instanceof T)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof w)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof w);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=R(this.declarationNode.parent.name).map(e=>e.join(`.`)).unwrap_or(`<unnamed>`),n=this.declarationNode.parent.symbol.symbolTable;return[e.callee,...e.args].flatMap(_u).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=V(e).unwrap_or(void 0);if(r===void 0)return[];let i=Jc(r),a=n.get(i);return a?(e.referee=a,a.references.push(e),[]):new A(k.BINDING_ERROR,`No column named '${r}' inside Table '${t}'`,e)})})}bindSubElements(e){return e.flatMap(e=>e.type?new(gu(e))(e,this.ast,this.symbolFactory).bind():[])}},cu=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 w)return[];let t=e.body.filter(e=>e instanceof x);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(gu(e))(e,this.ast,this.symbolFactory).bind():[])}},lu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof T?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof w)return[];let t=e.body.filter(e=>e instanceof x);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(gu(e))(e,this.ast,this.symbolFactory).bind():[])}},uu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof b)&&kl(this.declarationNode.parent).unwrap_or(void 0)!==N.Project?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof w)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof w);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(_u).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=>vu(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(gu(e))(e,this.ast,this.symbolFactory).bind():[])}},du=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof T?this.bindBody(this.declarationNode.body):[]}resolvePartialInjections(){let{body:e}=this.declarationNode;return(e?e instanceof T?e.body:[e]:[]).filter(e=>e instanceof w&&bl(e.callee)).reverse().flatMap(e=>{let t=z(e.callee.expression).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=vu(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=B(t.declaration.callee).unwrap_or(void 0);if(r===void 0)return;let i=this.symbolFactory.create(jc,{declaration:e,tablePartialSymbol:n.referee}),a=Jc(r),o=this.declarationNode.symbol?.symbolTable;o?.has(a)||o?.set(a,i)}),[])})}bindBody(e){if(!e)return[];if(e instanceof w)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof w);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(m(n)instanceof E){let e=L(m(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=>!bl(e.callee)))}tryToBindColumnType(e){let t=z(e).unwrap_or(void 0);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&vu(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Enum}])}tryToBindEnumFieldRef(e){if(G(e))return[];if(K(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&Hc.includes(t))return[]}let t=z(e).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=t.variables;return vu(this.ast,[...i.map(e=>({node:e,kind:F.Schema})),{node:r,kind:F.Enum},{node:n,kind:F.EnumField}])}bindInlineRef(e){return _u(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?vu(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table},{node:t,kind:F.Column}]):vu(this.declarationNode,[{node:t,kind:F.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(gu(e))(e,this.ast,this.symbolFactory).bind():[])}},fu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof T?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof w)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof w);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(_u).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return vu(this.ast,[...n.map(e=>({node:e,kind:F.Schema})),{node:t,kind:F.Table}])}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(gu(e))(e,this.ast,this.symbolFactory).bind():[])}},pu=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof T?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof w)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof w);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(m(n)instanceof E){let e=L(m(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=z(e).unwrap_or(void 0);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&vu(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Enum}])}bindInlineRef(e){return _u(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?vu(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table},{node:t,kind:F.Column}]):vu(this.declarationNode,[{node:t,kind:F.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(gu(e))(e,this.ast,this.symbolFactory).bind():[])}};function mu(e){return[Kc,qc,Yc,Zc,Jc,Xc,Qc,el,tl].map(t=>t(e))}function hu(e){if(e instanceof Sc)return F.Schema;if(e instanceof Tc)return F.Table;if(e instanceof Ec)return F.Column;if(e instanceof Cc)return F.Enum;if(e instanceof wc)return F.EnumField;if(e instanceof Dc)return F.TableGroup;if(e instanceof Oc)return F.TableGroupField;if(e instanceof kc)return F.TablePartial;if(e instanceof jc)return F.Column;if(e instanceof Ac)return F.PartialInjection;throw Error(`No other possible symbol kind in getSymbolKind`)}function gu(e){switch(e.type.value.toLowerCase()){case N.Enum:return ou;case N.Table:return du;case N.TableGroup:return fu;case N.Project:return lu;case N.Ref:return uu;case N.Note:return cu;case N.Indexes:return su;case N.TablePartial:return pu;case N.Check:return iu;default:return au}}function _u(e){if(!e)return[];if(K(e))return[{variables:[e],tupleElements:[]}];if(e instanceof dc){let t=z(e).unwrap_or(void 0);return t?[t]:[..._u(e.leftExpression),..._u(e.rightExpression)]}if(e instanceof S||e instanceof fc)return _u(e.expression);if(e instanceof pc){let t=z(e).unwrap_or(void 0);return t?[t]:e.elementList.flatMap(_u)}return[]}function vu(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=hu(e.symbol),i=e instanceof x?Kl(e).unwrap_or(`<invalid name>`):Wc;if(e instanceof b&&t.length){let{node:e,kind:n}=t[0];V(e).unwrap_or(`<unnamed>`)===`public`&&n===F.Schema&&t.shift()}for(let e of t){let{node:t,kind:a}=e,o=V(t).unwrap_or(`<unnamed>`),s=nl(o,a),c=n.get(s);if(!c)return[new A(k.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 yu=class{constructor(e,t){this.ast=e,this.symbolFactory=t}resolvePartialInjections(){return this.ast.body.filter(e=>kl(e).unwrap_or(``)===N.Table).flatMap(e=>new du(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(gu(t))(t,this.ast,this.symbolFactory);e.push(...n.bind())}return new Mc(this.ast,e)}},bu=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}},xu=class{constructor(e,t){this.ast=e,this.symbolFactory=new bu(t)}analyze(){return new ru(this.ast,this.symbolFactory).validate().chain(e=>new yu(e,this.symbolFactory).resolve())}validate(){return new ru(this.ast,this.symbolFactory).validate().chain(e=>new Mc(e,[]))}};function Su(e,t){let{variables:n,tupleElements:r}=z(e).unwrap(),i=r.map(e=>V(e).unwrap()),a=n.map(e=>V(e).unwrap());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 Cu(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:throw Error(`Invalid relation op`)}}function Y(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}}}function wu(e){let t=Al(e).unwrap_or(void 0)?.pop();return t instanceof pc?t.elementList.map(e=>e.referee):[t.referee]}function Tu(e){let t=R(e).unwrap();return{name:t.pop(),schemaName:t}}function Eu(e){return e.expression.literal.value}function Du(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 Ou(e,t){return Array.isArray(e)?Qs(e.map(({id:e})=>e).sort(),t.map(({id:e})=>e).sort()).every(([e,t])=>e===t):e.id===t.id}function ku(e){let t=e.split(`
|
|
29
10
|
`),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(`
|
|
30
|
-
`)}function Lu(e){if(e){if(Ul(e))return{value:jl(e).unwrap(),type:`string`};if(bl(e))return{type:`number`,value:Pc(e)};if(Gl(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof nc&&e.value)return{value:e.value.value,type:`expression`};if(ql(e))return{value:Tl(e).map(xs).and_then(Ol).unwrap(),type:`string`};throw Error(`Unreachable`)}}function Ru(e){let t=``,n=null;for(e instanceof oc&&(n=e.argumentList.elementList.map(e=>bl(e)?Nc(e):Ul(e)?jl(e).unwrap():Ol(e).unwrap()).join(`,`),t=`(${n})`,e=e.callee);e instanceof oc||e instanceof dc;)e instanceof oc?(t=`(${e.argumentList.elementList.map(e=>bl(e)?Nc(e):Ul(e)?jl(e).unwrap():Ol(e).unwrap()).join(`,`)})${t}`,e=e.callee):e instanceof dc&&(t=`${`[${e.indexer.elementList.map(e=>e.name.expression.literal.value).join(`,`)}]`}${t}`,e=e.array);let{name:r,schemaName:i}=Mu(e);return i.length>1?new Tc({schemaName:i.length===0?null:i[0],type_name:`${r}${t}`,args:n},[new R(L.UNSUPPORTED,`Nested schema is not supported`,e)]):new Tc({schemaName:i.length===0?null:i[0],type_name:`${r}${t}`,args:n})}var zu=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=Y(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}},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),e}interpretName(e){let{name:t,schemaName:n}=Mu(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new R(L.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=Al(e).unwrap_or(null);return t&&(this.env.aliases.push({name:t,kind:`table`,value:{tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=t),[]}interpretSettingList(e){let t=U(e).getValue();this.table.headerColor=t[V.HeaderColor]?.length?Nu(t[V.HeaderColor]?.at(0)?.value):void 0;let[n]=t[V.Note]||[];return this.table.note=n&&{value:jl(n?.value).map(Iu).unwrap(),token:Y(n)},[]}interpretBody(e){let[t,n]=Ns(e.body,e=>e instanceof F);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case B.Note:return this.table.note={value:jl(e.body instanceof rc?e.body.body[0].callee:e.body.callee).map(Iu).unwrap(),token:Y(e)},[];case B.Indexes:return this.interpretIndexes(e);case B.Check:return this.interpretChecks(e);default:return[]}})}interpretInjection(e,t){let n={order:t,token:Y(e)};return n.name=Ol(e.expression).unwrap_or(``),this.table.partials.push(n),[]}interpretFields(e){let t=(this.declarationNode.symbol?.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([e])=>Zc(e).unwrap_or(null)?.kind===H.Column).length?[]:[new R(L.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],n=e.flatMap((e,t)=>ml(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...t,...n]}interpretColumn(e){let t=[],n={};n.name=Al(e.callee).unwrap();let r=Ru(e.args[0]);n.type=r.getValue(),t.push(...r.getErrors()),n.token=Y(e),n.inline_refs=[];let i=e.args.slice(1);if(xs(i)instanceof I){let r=U(i.pop()).getValue();n.pk=!!r[V.PK]?.length||!!r[V.PrimaryKey]?.length,n.increment=!!r[V.Increment]?.length,n.unique=!!r[V.Unique]?.length,n.not_null=r[V.NotNull]?.length?!0:r[V.Null]?.length?!1:void 0,n.dbdefault=Lu(r[V.Default]?.at(0)?.value);let a=r[V.Note]?.at(0);n.note=a&&{value:jl(a.value).map(Iu).unwrap(),token:Y(a)},n.inline_refs=(r[V.Ref]||[]).flatMap(n=>{let[r]=ju(n.value.expression);if(Fu(r,e.symbol))return t.push(new R(L.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=El(n.value.expression).unwrap(),o;if(a.length===1){let[e]=a;o={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[e],relation:i.value,token:Y(n)}}else if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:Y(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:Y(n)}}else{t.push(new R(L.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:Y(n)}}let s=this.registerInlineRefToEnv(e,r,o,n);return t.push(...s),s.length===0?o:[]}),n.checks=(r[V.Check]||[]).map(e=>({token:Y(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>Ol(e).unwrap().toLowerCase()===`pk`),n.unique||=i.some(e=>Ol(e).unwrap().toLowerCase()===`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=Y(n);let r=[n.callee,...n.args];if(xs(r)instanceof I){let e=U(r.pop()).getValue();t.pk=!!e[V.PK]?.length,t.unique=!!e[V.Unique]?.length,t.name=jl(e[V.Name]?.at(0)?.value).unwrap_or(void 0);let n=e[V.Note]?.at(0);t.note=n&&{value:jl(n.value).unwrap(),token:Y(n)},t.type=Ol(e[V.Type]?.at(0)?.value).unwrap_or(void 0)}return r.flatMap(e=>{if(!(e instanceof oc))return e;let t=[];for(;e instanceof oc;)t.push(e.argumentList),e=e.callee;return t.push(e),t}).forEach(e=>{let{functional:n,nonFunctional:r}=kl(e).unwrap();t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:Y(e)})),...r.map(e=>({value:Al(e).unwrap(),type:`column`,token:Y(e)})))}),t})),[]}interpretChecks(e){return this.table.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=Y(n),n.args[0]instanceof I&&(t.name=jl(U(n.args[0]).getValue()[V.Name]?.at(0)?.value).unwrap_or(void 0)),t.expression=n.callee.value.value,t})),[]}registerInlineRefToEnv(e,t,n,r){let i=Pu(e.symbol,t);if(this.env.refIds[i])return[new R(L.CIRCULAR_REF,`References with same endpoints exist`,r),new R(L.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[i])];let a=J(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:[Ol(e.callee).unwrap()],token:Y(e),relation:a[0]}]}),[]}},Bu=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=Y(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}=Mu(e);return this.note.name=t,[]}interpretSettingList(e){let t=U(e).getValue();return this.note.headerColor=t.headercolor?.length?Nu(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=Ns(e.body,e=>e instanceof F);return t.length!==1||n.length>0?[new R(L.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=Ai(e,`callee.expression.literal.value`,``);return this.note.content=Iu(t),[]}},Vu=class{constructor(e,t){this.declarationNode=e,this.env=t,this.container=this.declarationNode.parent instanceof P?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=Y(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=El(this.declarationNode.name).unwrap_or([]);return this.ref.name=n.pop()||null,n.length>1&&t.push(new R(L.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=n.join(`.`)||null,t}interpretBody(e){return e instanceof F?this.interpretField(e):this.interpretField(e.body[0])}interpretField(e){let t=e.callee.op.value,{leftExpression:n,rightExpression:r}=e.callee,i=ju(n),a=ju(r);if(Fu(i,a))return[new R(L.SAME_ENDPOINT,`Two endpoints are the same`,e)];let o=Pu(i,a);if(this.env.refIds[o])return[new R(L.CIRCULAR_REF,`References with same endpoints exist`,this.declarationNode),new R(L.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[o])];if(e.args[0]){let t=U(e.args[0]).getValue(),n=t.delete?.at(0)?.value;this.ref.onDelete=n instanceof Zs?Jl(n).unwrap_or(void 0):Ol(n).unwrap_or(void 0);let r=t.update?.at(0)?.value;this.ref.onUpdate=r instanceof Zs?Jl(r).unwrap_or(void 0):Ol(r).unwrap_or(void 0),this.ref.color=t.color?.length?Nu(t.color?.at(0)?.value):void 0}let s=J(t);return this.ref.endpoints=[{...q(n,this.container),relation:s[0],token:Y(n)},{...q(r,this.container),relation:s[1],token:Y(r)}],this.env.refIds[o]=this.declarationNode,[]}},Hu=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=Y(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}=Mu(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new R(L.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]=Ns(e.body,e=>e instanceof F);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case`note`:this.tableGroup.note={value:jl(e.body instanceof rc?e.body.body[0].callee:e.body.callee).map(Iu).unwrap(),token:Y(e)};break;default:break}return[]})}interpretFields(e){let t=[];return this.tableGroup.tables=e.map(e=>{let n=El(e.callee).unwrap();n.length>2&&t.push(new R(L.UNSUPPORTED,`Nested schema is not supported`,e));let r=Tl(e.callee).unwrap().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 R(L.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(`.`)}}),t}interpretSettingList(e){let t=U(e).getValue();this.tableGroup.color=t.color?.length?Nu(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:jl(n?.value).map(Iu).unwrap(),token:Y(n)},[]}},Uu=class{constructor(e,t){this.declarationNode=e,this.env=t,this.enum={values:[]}}interpret(){return this.enum.token=Y(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}=Mu(e);return n.length>1?(this.enum.name=t,this.enum.schemaName=n.join(`.`),[new R(L.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=Y(t),n.name=Ol(t.callee).unwrap();let r=U(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:jl(r.value).map(Iu).unwrap(),token:Y(r)},this.enum.values.push(n),[]})}},Wu=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=Y(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}},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),e}interpretName(e){let{name:t}=Mu(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=U(e).getValue(),n=ks(t[V.HeaderColor]);this.tablePartial.headerColor=n?Nu(n.value):void 0;let[r]=t[V.Note]||[];return this.tablePartial.note=r&&{value:jl(r?.value).map(Iu).unwrap(),token:Y(r)},[]}interpretBody(e){let[t,n]=Ns(e.body,e=>e instanceof F);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case B.Note:return this.tablePartial.note={value:jl(e.body instanceof rc?e.body.body[0].callee:e.body.callee).map(Iu).unwrap(),token:Y(e)},[];case B.Indexes:return this.interpretIndexes(e);case B.Check:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let t=[],n={};n.name=Al(e.callee).unwrap();let r=Ru(e.args[0]);n.type=r.getValue(),t.push(...r.getErrors()),n.token=Y(e),n.inline_refs=[];let i=e.args.slice(1);if(xs(i)instanceof I){let r=U(i.pop()).getValue();n.pk=!!r[V.PK]?.length||!!r[V.PrimaryKey]?.length,n.increment=!!r[V.Increment]?.length,n.unique=!!r[V.Unique]?.length,n.not_null=r[V.NotNull]?.length?!0:r[V.Null]?.length?!1:void 0,n.dbdefault=Lu(r[V.Default]?.at(0)?.value);let a=r[V.Note]?.at(0);n.note=a&&{value:jl(a.value).map(Iu).unwrap(),token:Y(a)},n.inline_refs=(r[V.Ref]||[]).flatMap(n=>{let[r]=ju(n.value.expression);if(Fu(r,e.symbol))return t.push(new R(L.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=El(n.value.expression).unwrap(),o;if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:Y(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:Y(n)}}else{t.push(new R(L.UNSUPPORTED,`Unsupported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:Y(n)}}return o}),n.checks=(r[V.Check]||[]).map(e=>({token:Y(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>Ol(e).unwrap().toLowerCase()===`pk`),n.unique||=i.some(e=>Ol(e).unwrap().toLowerCase()===`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=Y(n);let r=[n.callee,...n.args];if(xs(r)instanceof I){let e=U(r.pop()).getValue();t.pk=!!e[V.PK]?.length,t.unique=!!e[V.Unique]?.length,t.name=jl(e[V.Name]?.at(0)?.value).unwrap_or(void 0);let n=e[V.Note]?.at(0);t.note=n&&{value:jl(n.value).unwrap(),token:Y(n)},t.type=Ol(e[V.Type]?.at(0)?.value).unwrap_or(void 0)}return r.flatMap(e=>{if(!(e instanceof oc))return e;let t=[],n=e;for(;n instanceof oc;)t.push(n.argumentList),n=n.callee;return t.push(n),t}).forEach(e=>{let{functional:n,nonFunctional:r}=kl(e).unwrap();t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:Y(e)})),...r.map(e=>({value:Al(e).unwrap(),type:`column`,token:Y(e)})))}),t})),[]}interpretChecks(e){return this.tablePartial.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=Y(n),n.args[0]instanceof I&&(t.name=jl(U(n.args[0]).getValue()[V.Name]?.at(0)?.value).unwrap_or(void 0)),t.expression=n.callee.value.value,t})),[]}},Gu=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=Y(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=Mu(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 zu(t,this.env).interpret();return this.project.tables.push(this.env.tables.get(t)),e}case`ref`:{let e=new Vu(t,this.env).interpret();return this.project.refs.push(this.env.ref.get(t)),e}case`tablegroup`:{let e=new Hu(t,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(t)),e}case`enum`:{let e=new Uu(t,this.env).interpret();return this.project.enums.push(this.env.enums.get(t)),e}case`note`:return this.project.note={value:jl(t.body instanceof rc?t.body.body[0].callee:t.body.callee).map(Iu).unwrap(),token:Y(t)},[];case`tablepartial`:{let e=new Wu(t,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(t)),e}default:return this.project[t.type.value.toLowerCase()]=jl(t.body.callee).unwrap(),[]}})}};function Ku(e){return{schemas:[],tables:Array.from(e.tables.values()),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())}}var qu=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}}interpret(){let e=this.ast.body.flatMap(e=>{switch(wl(e).unwrap_or(void 0)){case B.Table:return new zu(e,this.env).interpret();case B.Note:return new Bu(e,this.env).interpret();case B.Ref:return new Vu(e,this.env).interpret();case B.TableGroup:return new Hu(e,this.env).interpret();case B.TablePartial:return new Wu(e,this.env).interpret();case B.Enum:return new Uu(e,this.env).interpret();case B.Project:return new Gu(e,this.env).interpret();default:return[]}});return new Tc(Ku(this.env),e)}};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}({}),Ju=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({});function Yu(e){switch(e){case H.Schema:return X.Module;case H.Table:case H.TablePartial:return X.Class;case H.Column:case H.TableGroupField:return X.Field;case H.Enum:return X.Enum;case H.EnumField:return X.EnumMember;case H.TableGroup:return X.Struct;default:return X.Text}}function Xu(e,t){if(!e||Gs(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===j.NEWLINE&&n.end<=t)return!1}return!0}function Z(){return{suggestions:[]}}function Zu(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function Qu(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:!e.insertText||!e.insertText.split(``).every(Ec)?`"${e.insertText??``}"`:e.insertText}))}}function $u(e,t){return e.getOffsetAt(t)}var ed=class{constructor(e,t=[]){this.compiler=e,this.triggerCharacters=t}provideCompletionItems(e,t){let n=$u(e,t),r=this.compiler.token.flatStream(),{token:i,index:a}=this.compiler.container.token(n),o=a===void 0?r[0]:r[a+1];if([...i?.trailingTrivia||[],...i?.leadingTrivia||[],...o?.leadingTrivia||[]].find(e=>Js(e)&&Mc(n,e)))return Z();if(a===void 0)return ld();if([j.STRING_LITERAL,j.QUOTED_STRING].includes(i.kind)&&Mc(n,i))return Z();let s=this.compiler.container.element(n);if(this.compiler.container.scopeKind(n)===$.TOPLEVEL||s instanceof P&&s.type&&s.type.start<=n&&s.type.end>=n)return ld();let c=[...this.compiler.container.stack(n)].reverse();for(let e of c)if(e instanceof $s)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return td(this.compiler,n,e);case`~`:return Q(this.compiler,n);default:}else if(e instanceof ec)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return td(this.compiler,n,e);case`.`:return sd(this.compiler,n,e);default:}else if(e instanceof Qs)return id(this.compiler,n,e);else if(e instanceof I)return id(this.compiler,n,e);else if(e instanceof ic)return rd(this.compiler,n);else if(e instanceof F)return cd(this.compiler,n,e);else if(e instanceof P&&(e.bodyColon&&n>=e.bodyColon.end||e.body&&Mc(n,e.body)))return cd(this.compiler,n,void 0);return Z()}};function Q(e,t){return nd(e,t,e.parse.ast(),[H.TablePartial])}function td(e,t,n){let r=e.container.scopeKind(t);if([$.REF,$.TABLE,$.TABLEPARTIAL].includes(r)){let r=nd(e,t,e.container.element(t),[H.Table,H.Schema,H.Column]);return Xu(n.op,t)?Zu(r):r}return Z()}function nd(e,t,n,r){if(n===void 0)return Z();let i=n,a={suggestions:[]};for(;i;){if(i?.symbol?.symbolTable){let{symbol:t}=i;a.suggestions.push(...e.symbol.members(t).filter(({kind:e})=>r.includes(e)).map(({name:e,kind:t})=>({label:e,insertText:e,insertTextRules:Ju.KeepWhitespace,kind:Yu(t),sortText:Yu(t).toString().padStart(2,`0`),range:void 0})))}i=i instanceof P?i.parent:void 0}return Qu(a)}function rd(e,t){switch(e.container.scopeKind(t)){case $.INDEXES:return _d(e,t);case $.REF:{let n=[...e.container.stack(t)];for(;n.length>0;){let r=n.pop();if(r instanceof ec&&r.op?.value===`.`)return sd(e,t,r)}}return pd(e,t);default:break}return Z()}function id(e,t,n){let{token:r}=e.container.token(t);if([j.COMMA,j.LBRACKET].includes(r?.kind)){let n=ad(e,t);return r?.kind===j.COMMA&&Xu(r,t)?Zu(n):n}if(n.name&&n.name.start<=t&&n.name.end>=t)return ad(e,t);if(n.name instanceof Zs){let i=od(e,t,Jl(n.name).unwrap_or(``));return r?.kind===j.COLON&&Xu(r,t)?Zu(i):i}return Z()}function ad(e,t){let n=e.container.element(t);if(n instanceof Xs)return Z();let r=e.container.scopeKind(t);if(n.body&&!Mc(t,n.body)){let e;switch(r){case $.TABLE:case $.TABLEPARTIAL:e=[V.HeaderColor,V.Note];break;case $.TABLEGROUP:e=[V.Color,V.Note];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:X.Field,insertTextRules:Ju.KeepWhitespace,range:void 0}))}}switch(r){case $.TABLE:case $.TABLEPARTIAL:return{suggestions:[...[V.PK,V.PrimaryKey,V.Null,V.NotNull,V.Increment,V.Unique].map(e=>({label:e,insertText:e,kind:X.Property,insertTextRules:Ju.KeepWhitespace,range:void 0})),...[V.Ref,V.Default,V.Note,V.Check].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Ju.KeepWhitespace,range:void 0}))]};case $.ENUM:return{suggestions:[...[V.Note].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Ju.KeepWhitespace,range:void 0}))]};case $.INDEXES:return{suggestions:[...[V.Unique,V.PK].map(e=>({label:e,insertText:e,insertTextRules:Ju.KeepWhitespace,kind:X.Property,range:void 0})),...[V.Note,V.Name,V.Type].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Ju.KeepWhitespace,range:void 0}))]};case $.REF:return{suggestions:[V.Update,V.Delete,V.Color].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Ju.KeepWhitespace,range:void 0}))};case $.CHECKS:return{suggestions:[V.Name].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Ju.KeepWhitespace,range:void 0}))};default:break}return Z()}function od(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:Ju.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:X.Value,insertTextRules:Ju.KeepWhitespace,range:void 0}))};case`default`:return nd(e,t,e.container.element(t),[H.Schema,H.Enum]);default:break}return Z()}function sd(e,t,n){let r=Tl(n).unwrap_or([]);if(r.pop(),r.some(e=>!Wl(e)))return Z();let i=r.map(e=>Ol(e).unwrap());return Qu({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:Yu(e),range:void 0}))})}function cd(e,t,n){switch(e.container.scopeKind(t)){case $.TABLE:case $.TABLEPARTIAL:return dd(e,t,n);case $.PROJECT:return fd(e,t,n);case $.INDEXES:return hd(e,t);case $.ENUM:return ud(e,t,n);case $.REF:{let n=pd(e,t);return e.container.token(t).token?.kind===j.COLON&&Xu(e.container.token(t).token,t)?Zu(n):n}case $.TABLEGROUP:return md(e);default:return Z()}}function ld(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Ju.KeepWhitespace,kind:X.Keyword,range:void 0}))}}function ud(e,t,n){return n?.callee&&vd(t,n)===1?nd(e,t,e.container.element(t),[H.Schema,H.Table,H.Column]):Z()}function dd(e,t,n){let r=[`Note`,`indexes`,`checks`];if(!n?.callee)return{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Ju.KeepWhitespace,kind:X.Keyword,range:void 0}))};let i=vd(t,n);return i===0?{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Ju.KeepWhitespace,kind:X.Keyword,range:void 0}))}:i===1?gd(e,t):Z()}function fd(e,t,n){return!n?.callee||vd(t,n)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Ju.KeepWhitespace,kind:X.Keyword,range:void 0}))}:Z()}function pd(e,t){return nd(e,t,e.container.element(t),[H.Schema,H.Table,H.Column])}function md(e){return{suggestions:[...Qu({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=Zc(e).unwrap_or(void 0);if(t===void 0)return[];let{kind:n,name:r}=t;return n!==H.Table&&n!==H.Schema?[]:{label:r,insertText:r,insertTextRules:Ju.KeepWhitespace,kind:Yu(n),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:Ju.KeepWhitespace,kind:X.Keyword,range:void 0}))]}}function hd(e,t){return _d(e,t)}function gd(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:Ju.KeepWhitespace,kind:X.TypeParameter,sortText:X.TypeParameter.toString().padStart(2,`0`),range:void 0})),...nd(e,t,e.container.element(t),[H.Enum,H.Schema]).suggestions]}}function _d(e,t){let n=e.container.element(t)?.parent;if(!(n?.symbol instanceof vc))return Z();let{symbolTable:r}=n.symbol;return Qu({suggestions:[...r.entries()].flatMap(([e])=>{let t=Zc(e).unwrap_or(void 0);if(t===void 0)return[];let{name:n}=t;return{label:n,insertText:n,insertTextRules:Ju.KeepWhitespace,kind:Yu(H.Column),range:void 0}})})}function vd(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 yd=class{constructor(e){this.compiler=e}provideDefinition(e,t){let{uri:n}=e,r=$u(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&&[N.PRIMARY_EXPRESSION,N.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[]}},bd=class{constructor(e){this.compiler=e}provideReferences(e,t){let{uri:n}=e,r=$u(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(e&&[N.ELEMENT_DECLARATION,N.FUNCTION_APPLICATION,N.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[]}},xd=n({CompletionItemInsertTextRule:()=>Ju,CompletionItemKind:()=>X,DBMLCompletionItemProvider:()=>ed,DBMLDefinitionProvider:()=>yd,DBMLReferencesProvider:()=>bd},1);function Sd(){return this.parse._().getValue().ast}function Cd(){return this.parse._().getErrors()}function wd(){return this.parse._().getValue().tokens}function Td(){return this.parse._().getValue().rawDb}function Ed(){return this.parse._().getValue().ast.symbol.symbolTable}function Dd(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function Od(){return this.parse.tokens().filter(zl)}function kd(e){return e.symbolTable?[...e.symbolTable.entries()].map(([e,t])=>({...Zc(e).unwrap(),symbol:t})):[]}function Ad(e,t){if(e.length===0)return[];let n=[];for(let r=t;r;r=r instanceof P?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=>Cu(t).flatMap(t=>{let n=e.get(t),r=Zc(t).unwrap_or(void 0);return!n||!r?[]:{...r,symbol:n}})),i=a.flatMap(e=>e.symbol.symbolTable?e.symbol.symbolTable:[]);n.push(...a)}return n}function jd(e,t){return`${e.join(`.`)}@${t.id}`}function Md(e){let t=this.token.flatStream(),{index:n,token:r}=this.container.token(e),i=n===void 0?-1:Ds(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=Vl(o).find(e=>Mc(a,e));if(e===void 0||e instanceof Hs)break;s.push(e),o=e}if(r?.kind===j.COLON)return s;for(;s.length>0;){let t=!1,n=xs(s);if(n instanceof F){let r=this.parse.source();for(let i=n.end;i<e;i+=1)r[i]===`
|
|
31
|
-
`&&(s.pop(),t=!0)}else n instanceof
|
|
11
|
+
`)}function Au(e){if(e){if(G(e))return{value:H(e).unwrap(),type:`string`};if(Tl(e))return{type:`number`,value:Vc(e)};if(Hl(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof C&&e.value)return{value:e.value.value,type:`expression`};if(Wl(e))return{value:Al(e).map(m).and_then(B).unwrap(),type:`string`};throw Error(`Unreachable`)}}function ju(e){let t=``,n=null;for(e instanceof D&&(n=e.argumentList.elementList.map(e=>Tl(e)?Bc(e):G(e)?H(e).unwrap():B(e).unwrap()).join(`,`),t=`(${n})`,e=e.callee);e instanceof D||e instanceof vc;)e instanceof D?(t=`(${e.argumentList.elementList.map(e=>Tl(e)?Bc(e):G(e)?H(e).unwrap():B(e).unwrap()).join(`,`)})${t}`,e=e.callee):e instanceof vc&&(t=`${`[${e.indexer.elementList.map(e=>e.name.expression.literal.value).join(`,`)}]`}${t}`,e=e.array);let{name:r,schemaName:i}=Tu(e);return i.length>1?new Mc({schemaName:i.length===0?null:i[0],type_name:`${r}${t}`,args:n},[new A(k.UNSUPPORTED,`Nested schema is not supported`,e)]):new Mc({schemaName:i.length===0?null:i[0],type_name:`${r}${t}`,args:n})}var Mu=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=Y(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}},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),e}interpretName(e){let{name:t,schemaName:n}=Tu(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new A(k.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=V(e).unwrap_or(null);return t&&(this.env.aliases.push({name:t,kind:`table`,value:{tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=t),[]}interpretSettingList(e){let t=L(e).getValue();this.table.headerColor=t[P.HeaderColor]?.length?Eu(t[P.HeaderColor]?.at(0)?.value):void 0;let[n]=t[P.Note]||[];return this.table.note=n&&{value:H(n?.value).map(ku).unwrap(),token:Y(n)},[]}interpretBody(e){let[t,n]=h(e.body,e=>e instanceof w);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case N.Note:return this.table.note={value:H(e.body instanceof T?e.body.body[0].callee:e.body.callee).map(ku).unwrap(),token:Y(e)},[];case N.Indexes:return this.interpretIndexes(e);case N.Check:return this.interpretChecks(e);default:return[]}})}interpretInjection(e,t){let n={order:t,token:Y(e)};return n.name=B(e.expression).unwrap_or(``),this.table.partials.push(n),[]}interpretFields(e){let t=(this.declarationNode.symbol?.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([e])=>rl(e).unwrap_or(null)?.kind===F.Column).length?[]:[new A(k.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],n=e.flatMap((e,t)=>bl(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...t,...n]}interpretColumn(e){let t=[],n={};n.name=V(e.callee).unwrap();let r=ju(e.args[0]);n.type=r.getValue(),t.push(...r.getErrors()),n.token=Y(e),n.inline_refs=[];let i=e.args.slice(1);if(m(i)instanceof E){let r=L(i.pop()).getValue();n.pk=!!r[P.PK]?.length||!!r[P.PrimaryKey]?.length,n.increment=!!r[P.Increment]?.length,n.unique=!!r[P.Unique]?.length,n.not_null=r[P.NotNull]?.length?!0:r[P.Null]?.length?!1:void 0,n.dbdefault=Au(r[P.Default]?.at(0)?.value);let a=r[P.Note]?.at(0);n.note=a&&{value:H(a.value).map(ku).unwrap(),token:Y(a)},n.inline_refs=(r[P.Ref]||[]).flatMap(n=>{let[r]=wu(n.value.expression);if(Ou(r,e.symbol))return t.push(new A(k.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=R(n.value.expression).unwrap(),o;if(a.length===1){let[e]=a;o={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[e],relation:i.value,token:Y(n)}}else if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:Y(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:Y(n)}}else{t.push(new A(k.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:Y(n)}}let s=this.registerInlineRefToEnv(e,r,o,n);return t.push(...s),s.length===0?o:[]}),n.checks=(r[P.Check]||[]).map(e=>({token:Y(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>B(e).unwrap().toLowerCase()===`pk`),n.unique||=i.some(e=>B(e).unwrap().toLowerCase()===`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=Y(n);let r=[n.callee,...n.args];if(m(r)instanceof E){let e=L(r.pop()).getValue();t.pk=!!e[P.PK]?.length,t.unique=!!e[P.Unique]?.length,t.name=H(e[P.Name]?.at(0)?.value).unwrap_or(void 0);let n=e[P.Note]?.at(0);t.note=n&&{value:H(n.value).unwrap(),token:Y(n)},t.type=B(e[P.Type]?.at(0)?.value).unwrap_or(void 0)}return r.flatMap(e=>{if(!(e instanceof D))return e;let t=[];for(;e instanceof D;)t.push(e.argumentList),e=e.callee;return t.push(e),t}).forEach(e=>{let{functional:n,nonFunctional:r}=jl(e).unwrap();t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:Y(e)})),...r.map(e=>({value:V(e).unwrap(),type:`column`,token:Y(e)})))}),t})),[]}interpretChecks(e){return this.table.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=Y(n),n.args[0]instanceof E&&(t.name=H(L(n.args[0]).getValue()[P.Name]?.at(0)?.value).unwrap_or(void 0)),t.expression=n.callee.value.value,t})),[]}registerInlineRefToEnv(e,t,n,r){let i=Du(e.symbol,t);if(this.env.refIds[i])return[new A(k.CIRCULAR_REF,`References with same endpoints exist`,r),new A(k.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[i])];let a=Cu(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:[B(e.callee).unwrap()],token:Y(e),relation:a[0]}]}),[]}},Nu=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=Y(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}=Tu(e);return this.note.name=t,[]}interpretSettingList(e){let t=L(e).getValue();return this.note.headerColor=t.headercolor?.length?Eu(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=h(e.body,e=>e instanceof w);return t.length!==1||n.length>0?[new A(k.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=Wi(e,`callee.expression.literal.value`,``);return this.note.content=ku(t),[]}},Pu=class{constructor(e,t){this.declarationNode=e,this.env=t,this.container=this.declarationNode.parent instanceof x?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=Y(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=R(this.declarationNode.name).unwrap_or([]);return this.ref.name=n.pop()||null,n.length>1&&t.push(new A(k.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=n.join(`.`)||null,t}interpretBody(e){return e instanceof w?this.interpretField(e):this.interpretField(e.body[0])}interpretField(e){let t=e.callee.op.value,{leftExpression:n,rightExpression:r}=e.callee,i=wu(n),a=wu(r);if(Ou(i,a))return[new A(k.SAME_ENDPOINT,`Two endpoints are the same`,e)];let o=Du(i,a);if(this.env.refIds[o])return[new A(k.CIRCULAR_REF,`References with same endpoints exist`,this.declarationNode),new A(k.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[o])];if(e.args[0]){let t=L(e.args[0]).getValue(),n=t.delete?.at(0)?.value;this.ref.onDelete=n instanceof lc?Gl(n).unwrap_or(void 0):B(n).unwrap_or(void 0);let r=t.update?.at(0)?.value;this.ref.onUpdate=r instanceof lc?Gl(r).unwrap_or(void 0):B(r).unwrap_or(void 0),this.ref.color=t.color?.length?Eu(t.color?.at(0)?.value):void 0}let s=Cu(t);return this.ref.endpoints=[{...Su(n,this.container),relation:s[0],token:Y(n)},{...Su(r,this.container),relation:s[1],token:Y(r)}],this.env.refIds[o]=this.declarationNode,[]}},Fu=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=Y(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}=Tu(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new A(k.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]=h(e.body,e=>e instanceof w);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case`note`:this.tableGroup.note={value:H(e.body instanceof T?e.body.body[0].callee:e.body.callee).map(ku).unwrap(),token:Y(e)};break;default:break}return[]})}interpretFields(e){let t=[];return this.tableGroup.tables=e.map(e=>{let n=R(e.callee).unwrap();n.length>2&&t.push(new A(k.UNSUPPORTED,`Nested schema is not supported`,e));let r=Al(e.callee).unwrap().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 A(k.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(`.`)}}),t}interpretSettingList(e){let t=L(e).getValue();this.tableGroup.color=t.color?.length?Eu(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:H(n?.value).map(ku).unwrap(),token:Y(n)},[]}},Iu=class{constructor(e,t){this.declarationNode=e,this.env=t,this.enum={values:[]}}interpret(){return this.enum.token=Y(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}=Tu(e);return n.length>1?(this.enum.name=t,this.enum.schemaName=n.join(`.`),[new A(k.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=Y(t),n.name=B(t.callee).unwrap();let r=L(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:H(r.value).map(ku).unwrap(),token:Y(r)},this.enum.values.push(n),[]})}},Lu=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=Y(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}},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),e}interpretName(e){let{name:t}=Tu(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=L(e).getValue(),n=Ws(t[P.HeaderColor]);this.tablePartial.headerColor=n?Eu(n.value):void 0;let[r]=t[P.Note]||[];return this.tablePartial.note=r&&{value:H(r?.value).map(ku).unwrap(),token:Y(r)},[]}interpretBody(e){let[t,n]=h(e.body,e=>e instanceof w);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case N.Note:return this.tablePartial.note={value:H(e.body instanceof T?e.body.body[0].callee:e.body.callee).map(ku).unwrap(),token:Y(e)},[];case N.Indexes:return this.interpretIndexes(e);case N.Check:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let t=[],n={};n.name=V(e.callee).unwrap();let r=ju(e.args[0]);n.type=r.getValue(),t.push(...r.getErrors()),n.token=Y(e),n.inline_refs=[];let i=e.args.slice(1);if(m(i)instanceof E){let r=L(i.pop()).getValue();n.pk=!!r[P.PK]?.length||!!r[P.PrimaryKey]?.length,n.increment=!!r[P.Increment]?.length,n.unique=!!r[P.Unique]?.length,n.not_null=r[P.NotNull]?.length?!0:r[P.Null]?.length?!1:void 0,n.dbdefault=Au(r[P.Default]?.at(0)?.value);let a=r[P.Note]?.at(0);n.note=a&&{value:H(a.value).map(ku).unwrap(),token:Y(a)},n.inline_refs=(r[P.Ref]||[]).flatMap(n=>{let[r]=wu(n.value.expression);if(Ou(r,e.symbol))return t.push(new A(k.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=R(n.value.expression).unwrap(),o;if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:Y(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:Y(n)}}else{t.push(new A(k.UNSUPPORTED,`Unsupported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:Y(n)}}return o}),n.checks=(r[P.Check]||[]).map(e=>({token:Y(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>B(e).unwrap().toLowerCase()===`pk`),n.unique||=i.some(e=>B(e).unwrap().toLowerCase()===`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=Y(n);let r=[n.callee,...n.args];if(m(r)instanceof E){let e=L(r.pop()).getValue();t.pk=!!e[P.PK]?.length,t.unique=!!e[P.Unique]?.length,t.name=H(e[P.Name]?.at(0)?.value).unwrap_or(void 0);let n=e[P.Note]?.at(0);t.note=n&&{value:H(n.value).unwrap(),token:Y(n)},t.type=B(e[P.Type]?.at(0)?.value).unwrap_or(void 0)}return r.flatMap(e=>{if(!(e instanceof D))return e;let t=[],n=e;for(;n instanceof D;)t.push(n.argumentList),n=n.callee;return t.push(n),t}).forEach(e=>{let{functional:n,nonFunctional:r}=jl(e).unwrap();t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:Y(e)})),...r.map(e=>({value:V(e).unwrap(),type:`column`,token:Y(e)})))}),t})),[]}interpretChecks(e){return this.tablePartial.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=Y(n),n.args[0]instanceof E&&(t.name=H(L(n.args[0]).getValue()[P.Name]?.at(0)?.value).unwrap_or(void 0)),t.expression=n.callee.value.value,t})),[]}},Ru=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=Y(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=Tu(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 Mu(t,this.env).interpret();return this.project.tables.push(this.env.tables.get(t)),e}case`ref`:{let e=new Pu(t,this.env).interpret();return this.project.refs.push(this.env.ref.get(t)),e}case`tablegroup`:{let e=new Fu(t,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(t)),e}case`enum`:{let e=new Iu(t,this.env).interpret();return this.project.enums.push(this.env.enums.get(t)),e}case`note`:return this.project.note={value:H(t.body instanceof T?t.body.body[0].callee:t.body.callee).map(ku).unwrap(),token:Y(t)},[];case`tablepartial`:{let e=new Lu(t,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(t)),e}default:return this.project[t.type.value.toLowerCase()]=H(t.body.callee).unwrap(),[]}})}};function zu(e){return{schemas:[],tables:Array.from(e.tables.values()),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())}}var Bu=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}}interpret(){let e=this.ast.body.flatMap(e=>{switch(kl(e).unwrap_or(void 0)){case N.Table:return new Mu(e,this.env).interpret();case N.Note:return new Nu(e,this.env).interpret();case N.Ref:return new Pu(e,this.env).interpret();case N.TableGroup:return new Fu(e,this.env).interpret();case N.TablePartial:return new Lu(e,this.env).interpret();case N.Enum:return new Iu(e,this.env).interpret();case N.Project:return new Ru(e,this.env).interpret();default:return[]}});return new Mc(zu(this.env),e)}};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}({});function Vu(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 Hu(e,t){if(!e||ic(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===g.NEWLINE&&n.end<=t)return!1}return!0}function Q(){return{suggestions:[]}}function Uu(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function Wu(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:!e.insertText||!e.insertText.split(``).every(Nc)?`"${e.insertText??``}"`:e.insertText}))}}function Gu(e,t){return e.getOffsetAt(t)}var Ku=class{constructor(e,t=[]){this.compiler=e,this.triggerCharacters=t}provideCompletionItems(e,t){let n=Gu(e,t),r=this.compiler.token.flatStream(),{token:i,index:a}=this.compiler.container.token(n),o=a===void 0?r[0]:r[a+1];if([...i?.trailingTrivia||[],...i?.leadingTrivia||[],...o?.leadingTrivia||[]].find(e=>sc(e)&&zc(n,e)))return Q();if(a===void 0)return nd();if([g.STRING_LITERAL,g.QUOTED_STRING].includes(i.kind)&&zc(n,i))return Q();let s=this.compiler.container.element(n);if(this.compiler.container.scopeKind(n)===$.TOPLEVEL||s instanceof x&&s.type&&s.type.start<=n&&s.type.end>=n)return nd();let c=[...this.compiler.container.stack(n)].reverse();for(let e of c)if(e instanceof S)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return Ju(this.compiler,n,e);case`~`:return qu(this.compiler,n);default:}else if(e instanceof dc)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return Ju(this.compiler,n,e);case`.`:return ed(this.compiler,n,e);default:}else if(e instanceof uc)return Zu(this.compiler,n,e);else if(e instanceof E)return Zu(this.compiler,n,e);else if(e instanceof pc)return Xu(this.compiler,n);else if(e instanceof w)return td(this.compiler,n,e);else if(e instanceof x&&(e.bodyColon&&n>=e.bodyColon.end||e.body&&zc(n,e.body)))return td(this.compiler,n,void 0);return Q()}};function qu(e,t){return Yu(e,t,e.parse.ast(),[F.TablePartial])}function Ju(e,t,n){let r=e.container.scopeKind(t);if([$.REF,$.TABLE,$.TABLEPARTIAL].includes(r)){let r=Yu(e,t,e.container.element(t),[F.Table,F.Schema,F.Column]);return Hu(n.op,t)?Uu(r):r}return Q()}function Yu(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(...e.symbol.members(t).filter(({kind:e})=>r.includes(e)).map(({name:e,kind:t})=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:Vu(t),sortText:Vu(t).toString().padStart(2,`0`),range:void 0})))}i=i instanceof x?i.parent:void 0}return Wu(a)}function Xu(e,t){switch(e.container.scopeKind(t)){case $.INDEXES:return ud(e,t);case $.REF:{let n=[...e.container.stack(t)];for(;n.length>0;){let r=n.pop();if(r instanceof dc&&r.op?.value===`.`)return ed(e,t,r)}}return od(e,t);default:break}return Q()}function Zu(e,t,n){let{token:r}=e.container.token(t);if([g.COMMA,g.LBRACKET].includes(r?.kind)){let n=Qu(e,t);return r?.kind===g.COMMA&&Hu(r,t)?Uu(n):n}if(n.name&&n.name.start<=t&&n.name.end>=t)return Qu(e,t);if(n.name instanceof lc){let i=$u(e,t,Gl(n.name).unwrap_or(``));return r?.kind===g.COLON&&Hu(r,t)?Uu(i):i}return Q()}function Qu(e,t){let n=e.container.element(t);if(n instanceof b)return Q();let r=e.container.scopeKind(t);if(n.body&&!zc(t,n.body)){let e;switch(r){case $.TABLE:case $.TABLEPARTIAL:e=[P.HeaderColor,P.Note];break;case $.TABLEGROUP:e=[P.Color,P.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:[...[P.PK,P.PrimaryKey,P.Null,P.NotNull,P.Increment,P.Unique].map(e=>({label:e,insertText:e,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0})),...[P.Ref,P.Default,P.Note,P.Check].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.ENUM:return{suggestions:[...[P.Note].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.INDEXES:return{suggestions:[...[P.Unique,P.PK].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Property,range:void 0})),...[P.Note,P.Name,P.Type].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.REF:return{suggestions:[P.Update,P.Delete,P.Color].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};case $.CHECKS:return{suggestions:[P.Name].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};default:break}return Q()}function $u(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 Yu(e,t,e.container.element(t),[F.Schema,F.Enum]);default:break}return Q()}function ed(e,t,n){let r=Al(n).unwrap_or([]);if(r.pop(),r.some(e=>!K(e)))return Q();let i=r.map(e=>B(e).unwrap());return Wu({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:Vu(e),range:void 0}))})}function td(e,t,n){switch(e.container.scopeKind(t)){case $.TABLE:case $.TABLEPARTIAL:return id(e,t,n);case $.PROJECT:return ad(e,t,n);case $.INDEXES:return cd(e,t);case $.ENUM:return rd(e,t,n);case $.REF:{let n=od(e,t);return e.container.token(t).token?.kind===g.COLON&&Hu(e.container.token(t).token,t)?Uu(n):n}case $.TABLEGROUP:return sd(e);default:return Q()}}function nd(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}}function rd(e,t,n){return n?.callee&&dd(t,n)===1?Yu(e,t,e.container.element(t),[F.Schema,F.Table,F.Column]):Q()}function id(e,t,n){let r=[`Note`,`indexes`,`checks`];if(!n?.callee)return{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))};let i=dd(t,n);return i===0?{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:i===1?ld(e,t):Q()}function ad(e,t,n){return!n?.callee||dd(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 od(e,t){return Yu(e,t,e.container.element(t),[F.Schema,F.Table,F.Column])}function sd(e){return{suggestions:[...Wu({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=rl(e).unwrap_or(void 0);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:Vu(n),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))]}}function cd(e,t){return ud(e,t)}function ld(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})),...Yu(e,t,e.container.element(t),[F.Enum,F.Schema]).suggestions]}}function ud(e,t){let n=e.container.element(t)?.parent;if(!(n?.symbol instanceof Tc))return Q();let{symbolTable:r}=n.symbol;return Wu({suggestions:[...r.entries()].flatMap(([e])=>{let t=rl(e).unwrap_or(void 0);if(t===void 0)return[];let{name:n}=t;return{label:n,insertText:n,insertTextRules:Z.KeepWhitespace,kind:Vu(F.Column),range:void 0}})})}function dd(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 fd=class{constructor(e){this.compiler=e}provideDefinition(e,t){let{uri:n}=e,r=Gu(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&&[y.PRIMARY_EXPRESSION,y.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[]}},pd=class{constructor(e){this.compiler=e}provideReferences(e,t){let{uri:n}=e,r=Gu(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(e&&[y.ELEMENT_DECLARATION,y.FUNCTION_APPLICATION,y.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[]}},md=t({CompletionItemInsertTextRule:()=>Z,CompletionItemKind:()=>X,DBMLCompletionItemProvider:()=>Ku,DBMLDefinitionProvider:()=>fd,DBMLReferencesProvider:()=>pd},1);function hd(){return this.parse._().getValue().ast}function gd(){return this.parse._().getErrors()}function _d(){return this.parse._().getValue().tokens}function vd(){return this.parse._().getValue().rawDb}function yd(){return this.parse._().getValue().ast.symbol.symbolTable}function bd(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function xd(){return this.parse.tokens().filter(zl)}function Sd(e){return e.symbolTable?[...e.symbolTable.entries()].map(([e,t])=>({...rl(e).unwrap(),symbol:t})):[]}function Cd(e,t){if(e.length===0)return[];let n=[];for(let r=t;r;r=r instanceof x?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=>mu(t).flatMap(t=>{let n=e.get(t),r=rl(t).unwrap_or(void 0);return!n||!r?[]:{...r,symbol:n}})),i=a.flatMap(e=>e.symbol.symbolTable?e.symbol.symbolTable:[]);n.push(...a)}return n}function wd(e,t){return`${e.join(`.`)}@${t.id}`}function Td(e){let t=this.token.flatStream(),{index:n,token:r}=this.container.token(e),i=n===void 0?-1:Hs(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=Bl(o).find(e=>zc(a,e));if(e===void 0||e instanceof _)break;s.push(e),o=e}if(r?.kind===g.COLON)return s;for(;s.length>0;){let t=!1,n=m(s);if(n instanceof w){let r=this.parse.source();for(let i=n.end;i<e;i+=1)r[i]===`
|
|
12
|
+
`&&(s.pop(),t=!0)}else n instanceof S||n instanceof dc?this.container.token(e).token!==n.op&&(s.pop(),t=!0):n instanceof E?n.listCloseBracket&&n.end<=e&&(s.pop(),t=!0):n instanceof pc?n.tupleCloseParen&&n.end<=e&&(s.pop(),t=!0):n instanceof T?n.blockCloseBrace&&n.end<=e&&(s.pop(),t=!0):n instanceof lc||n.end<e&&(s.pop(),t=!0);if(t){let t=m(s);t instanceof x&&t.end<=e&&s.pop()}if(!t)break}return s}function Ed(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 Dd(e){let t=this.container.stack(e);for(let e=t.length-1;e>=0;--e)if(t[e]instanceof x)return t[e];return this.parse.ast()}function Od(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}({});function kd(e){let t=this.container.element(e);if(t instanceof b)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;default:return $.CUSTOM}}function Ad(e,t){let n=[...t].sort((e,t)=>t.start-e.start),r=e;for(let{start:e,end:t,newText:i}of n)r=r.substring(0,e)+i+r.substring(t);return r}function jd(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function Md(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=e.split(`.`);if(t.length===1)return{schema:Wc,table:jd(t[0])};if(t.length===2)return{schema:jd(t[0]),table:jd(t[1])};let n=t.pop();return{schema:jd(t.join(`.`)),table:jd(n)}}function Nd(e){return e?e.split(``).every(e=>Nc(e)||Pc(e))&&!Pc(e[0]):!1}function Pd(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 Fd(e,t,n){let r=!Nd(t),i=!Nd(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 Id(e,t,n){let r=qc(n);if(t===`public`){let t=e.get(r);return t instanceof Tc?t:null}let i=Kc(t),a=e.get(i);if(!a||!a.symbolTable)return null;let o=a.symbolTable.get(r);return o instanceof Tc?o:null}function Ld(e,t,n,r,i){let a=qc(i),o;if(r===`public`)o=e.get(a);else{let t=Kc(r),n=e.get(t);if(!n||!n.symbolTable)return!1;o=n.symbolTable.get(a)}return!(!o||t===r&&n===i)}function Rd(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 jd(n.substring(i,a))===t?{start:i,end:e.end}:null}function zd(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=Rd(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 Bd(e,t){let n=this.parse.source(),r=this.parse.publicSymbolTable(),i=Md(e),a=Md(t),o=i.schema,s=i.table,c=a.schema,l=a.table,u=Id(r,o,s);if(!u||Ld(r,o,s,c,l))return n;let d=Fd(c,l,Pd(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 Ad(n,zd(f,o,d,n))}var Vd=class{constructor(){this.source=``,this.cache=new Map,this.nodeIdGenerator=new cc,this.symbolIdGenerator=new xc,this.token={invalidStream:this.query(xd),flatStream:this.query(bd)},this.parse={source:()=>this.source,_:this.query(this.interpret),ast:this.query(hd),errors:this.query(gd),tokens:this.query(_d),rawDb:this.query(vd),publicSymbolTable:this.query(yd)},this.container={stack:this.query(Td),token:this.query(Ed),element:this.query(Dd),scope:this.query(Od),scopeKind:this.query(kd)},this.symbol={ofName:this.query(Cd,wd),members:this.query(Sd)}}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=new ql(this.source).lex().chain(e=>new Xl(e,this.nodeIdGenerator).parse()).chain(({ast:e,tokens:t})=>new xu(e,this.symbolIdGenerator).analyze().map(()=>({ast:e,tokens:t})));return e.getErrors().length>0?e:e.chain(({ast:e,tokens:t})=>new Bu(e).interpret().map(n=>({ast:e,tokens:t,rawDb:n})))}renameTable(e,t){return Bd.call(this,e,t)}applyTextEdits(e){return Ad(this.parse.source(),e)}initMonacoServices(){return{definitionProvider:new fd(this),referenceProvider:new pd(this),autocompletionProvider:new Ku(this)}}};exports.CompileError=A,exports.CompileErrorCode=k,exports.Compiler=Vd,exports.ElementDeclarationNode=x,exports.ElementKind=N,exports.ProgramNode=b,exports.ScopeKind=$,exports.SyntaxNode=v,exports.SyntaxNodeKind=y,exports.SyntaxToken=_,exports.SyntaxTokenKind=g,exports.addQuoteIfNeeded=Lc,exports.serialize=bc,Object.defineProperty(exports,`services`,{enumerable:!0,get:function(){return md}});
|