@dbml/parse 11.0.0-alpha.5 → 11.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +1,52 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(`PASS_THROUGH`),t=Symbol(`UNHANDLED`),n=class e{static create(t,n,r,i){return new e(t,n,r,i)}constructor(e,t,n,r){this.value=e,this.errors=t??[],this.warnings=n,this.infos=r}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings,this.infos):this}hasValue(e){return this.value===e}getFiltered(e){return this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings??[]}getInfos(){return this.infos??[]}chainFiltered(t,n){if(this.value===n)return new e(void 0,this.errors,this.warnings,this.infos);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()],o=[...this.getInfos(),...r.getInfos()];return new e(r.value,i,a,o)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()],a=[...this.getInfos(),...n.getInfos()];return new e(n.value,r,i,a)}mapFiltered(t,n){return this.value===n?new e(void 0,this.errors,this.warnings,this.infos):new e(t(this.value),this.errors,this.warnings,this.infos)}map(t){return new e(t(this.value),this.errors,this.warnings,this.infos)}},r=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Dep=`dep`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e.Metadata=`metadata`,e}({}),i=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.Dep=`dep`,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.Inactive=`inactive`,e.Example=`example`,e}({}),a=typeof global==`object`&&global&&global.Object===Object&&global,o=typeof self==`object`&&self&&self.Object===Object&&self,s=a||o||Function(`return this`)(),c=s.Symbol,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function p(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 m=Object.prototype.toString;function h(e){return m.call(e)}var ee=`[object Null]`,te=`[object Undefined]`,ne=c?c.toStringTag:void 0;function re(e){return e==null?e===void 0?te:ee:ne&&ne in Object(e)?p(e):h(e)}function ie(e){return typeof e==`object`&&!!e}var ae=`[object Symbol]`;function oe(e){return typeof e==`symbol`||ie(e)&&re(e)==ae}function se(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 ce=Array.isArray,le=1/0,ue=c?c.prototype:void 0,de=ue?ue.toString:void 0;function fe(e){if(typeof e==`string`)return e;if(ce(e))return se(e,fe)+``;if(oe(e))return de?de.call(e):``;var t=e+``;return t==`0`&&1/e==-le?`-0`:t}var pe=/\s/;function me(e){for(var t=e.length;t--&&pe.test(e.charAt(t)););return t}var he=/^\s+/;function ge(e){return e&&e.slice(0,me(e)+1).replace(he,``)}function _e(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var ve=NaN,ye=/^[-+]0x[0-9a-f]+$/i,be=/^0b[01]+$/i,xe=/^0o[0-7]+$/i,Se=parseInt;function Ce(e){if(typeof e==`number`)return e;if(oe(e))return ve;if(_e(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=_e(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=ge(e);var n=be.test(e);return n||xe.test(e)?Se(e.slice(2),n?2:8):ye.test(e)?ve:+e}var we=1/0,Te=17976931348623157e292;function Ee(e){return e?(e=Ce(e),e===we||e===-we?(e<0?-1:1)*Te:e===e?e:0):e===0?e:0}function De(e){var t=Ee(e),n=t%1;return t===t?n?t-n:t:0}function Oe(e){return e}var ke=`[object AsyncFunction]`,Ae=`[object Function]`,je=`[object GeneratorFunction]`,Me=`[object Proxy]`;function Ne(e){if(!_e(e))return!1;var t=re(e);return t==Ae||t==je||t==ke||t==Me}var Pe=s[`__core-js_shared__`],Fe=function(){var e=/[^.]+$/.exec(Pe&&Pe.keys&&Pe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Ie(e){return!!Fe&&Fe in e}var Le=Function.prototype.toString;function Re(e){if(e!=null){try{return Le.call(e)}catch{}try{return e+``}catch{}}return``}var ze=/[\\^$.*+?()[\]{}|]/g,Be=/^\[object .+?Constructor\]$/,Ve=Function.prototype,He=Object.prototype,Ue=Ve.toString,We=He.hasOwnProperty,Ge=RegExp(`^`+Ue.call(We).replace(ze,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function Ke(e){return!_e(e)||Ie(e)?!1:(Ne(e)?Ge:Be).test(Re(e))}function qe(e,t){return e?.[t]}function Je(e,t){var n=qe(e,t);return Ke(n)?n:void 0}var Ye=Je(s,`WeakMap`);function Xe(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 Ze(){}var Qe=800,$e=16,et=Date.now;function tt(e){var t=0,n=0;return function(){var r=et(),i=$e-(r-n);if(n=r,i>0){if(++t>=Qe)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function nt(e){return function(){return e}}var rt=function(){try{var e=Je(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),it=tt(rt?function(e,t){return rt(e,`toString`,{configurable:!0,enumerable:!1,value:nt(t),writable:!0})}:Oe);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}function ot(e){return e!==e}function st(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function ct(e,t,n){return t===t?st(e,t,n):at(e,ot,n)}function lt(e,t){return!!(e!=null&&e.length)&&ct(e,t,0)>-1}var ut=9007199254740991,dt=/^(?:0|[1-9]\d*)$/;function ft(e,t){var n=typeof e;return t??=ut,!!t&&(n==`number`||n!=`symbol`&&dt.test(e))&&e>-1&&e%1==0&&e<t}function pt(e,t,n){t==`__proto__`&&rt?rt(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function mt(e,t){return e===t||e!==e&&t!==t}var ht=Math.max;function gt(e,t,n){return t=ht(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=ht(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),Xe(e,this,s)}}function _t(e,t){return it(gt(e,t,Oe),e+``)}var vt=9007199254740991;function yt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=vt}function bt(e){return e!=null&&yt(e.length)&&!Ne(e)}var xt=Object.prototype;function St(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||xt)}function Ct(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var wt=`[object Arguments]`;function Tt(e){return ie(e)&&re(e)==wt}var Et=Object.prototype,Dt=Et.hasOwnProperty,Ot=Et.propertyIsEnumerable,kt=Tt(function(){return arguments}())?Tt:function(e){return ie(e)&&Dt.call(e,`callee`)&&!Ot.call(e,`callee`)};function At(){return!1}var jt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Mt=jt&&typeof module==`object`&&module&&!module.nodeType&&module,Nt=Mt&&Mt.exports===jt?s.Buffer:void 0,Pt=(Nt?Nt.isBuffer:void 0)||At,Ft=`[object Arguments]`,It=`[object Array]`,Lt=`[object Boolean]`,Rt=`[object Date]`,zt=`[object Error]`,Bt=`[object Function]`,Vt=`[object Map]`,Ht=`[object Number]`,Ut=`[object Object]`,Wt=`[object RegExp]`,Gt=`[object Set]`,Kt=`[object String]`,qt=`[object WeakMap]`,Jt=`[object ArrayBuffer]`,Yt=`[object DataView]`,Xt=`[object Float32Array]`,Zt=`[object Float64Array]`,Qt=`[object Int8Array]`,$t=`[object Int16Array]`,en=`[object Int32Array]`,tn=`[object Uint8Array]`,nn=`[object Uint8ClampedArray]`,rn=`[object Uint16Array]`,an=`[object Uint32Array]`,on={};on[Xt]=on[Zt]=on[Qt]=on[$t]=on[en]=on[tn]=on[nn]=on[rn]=on[an]=!0,on[Ft]=on[It]=on[Jt]=on[Lt]=on[Yt]=on[Rt]=on[zt]=on[Bt]=on[Vt]=on[Ht]=on[Ut]=on[Wt]=on[Gt]=on[Kt]=on[qt]=!1;function sn(e){return ie(e)&&yt(e.length)&&!!on[re(e)]}function cn(e){return function(t){return e(t)}}var ln=typeof exports==`object`&&exports&&!exports.nodeType&&exports,un=ln&&typeof module==`object`&&module&&!module.nodeType&&module,dn=un&&un.exports===ln&&a.process,fn=function(){try{return un&&un.require&&un.require(`util`).types||dn&&dn.binding&&dn.binding(`util`)}catch{}}(),pn=fn&&fn.isTypedArray,mn=pn?cn(pn):sn,hn=Object.prototype.hasOwnProperty;function gn(e,t){var n=ce(e),r=!n&&kt(e),i=!n&&!r&&Pt(e),a=!n&&!r&&!i&&mn(e),o=n||r||i||a,s=o?Ct(e.length,String):[],c=s.length;for(var l in e)(t||hn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||ft(l,c)))&&s.push(l);return s}function _n(e,t){return function(n){return e(t(n))}}var vn=_n(Object.keys,Object),yn=Object.prototype.hasOwnProperty;function bn(e){if(!St(e))return vn(e);var t=[];for(var n in Object(e))yn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function xn(e){return bt(e)?gn(e):bn(e)}function Sn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Cn=Object.prototype.hasOwnProperty;function wn(e){if(!_e(e))return Sn(e);var t=St(e),n=[];for(var r in e)r==`constructor`&&(t||!Cn.call(e,r))||n.push(r);return n}function Tn(e){return bt(e)?gn(e,!0):wn(e)}var En=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Dn=/^\w*$/;function On(e,t){if(ce(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||oe(e)?!0:Dn.test(e)||!En.test(e)||t!=null&&e in Object(t)}var kn=Je(Object,`create`);function An(){this.__data__=kn?kn(null):{},this.size=0}function jn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Mn=`__lodash_hash_undefined__`,Nn=Object.prototype.hasOwnProperty;function Pn(e){var t=this.__data__;if(kn){var n=t[e];return n===Mn?void 0:n}return Nn.call(t,e)?t[e]:void 0}var Fn=Object.prototype.hasOwnProperty;function In(e){var t=this.__data__;return kn?t[e]!==void 0:Fn.call(t,e)}var Ln=`__lodash_hash_undefined__`;function Rn(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=kn&&t===void 0?Ln:t,this}function zn(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])}}zn.prototype.clear=An,zn.prototype.delete=jn,zn.prototype.get=Pn,zn.prototype.has=In,zn.prototype.set=Rn;function Bn(){this.__data__=[],this.size=0}function Vn(e,t){for(var n=e.length;n--;)if(mt(e[n][0],t))return n;return-1}var Hn=Array.prototype.splice;function Un(e){var t=this.__data__,n=Vn(t,e);return n<0?!1:(n==t.length-1?t.pop():Hn.call(t,n,1),--this.size,!0)}function Wn(e){var t=this.__data__,n=Vn(t,e);return n<0?void 0:t[n][1]}function Gn(e){return Vn(this.__data__,e)>-1}function Kn(e,t){var n=this.__data__,r=Vn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function qn(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])}}qn.prototype.clear=Bn,qn.prototype.delete=Un,qn.prototype.get=Wn,qn.prototype.has=Gn,qn.prototype.set=Kn;var Jn=Je(s,`Map`);function Yn(){this.size=0,this.__data__={hash:new zn,map:new(Jn||qn),string:new zn}}function Xn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Zn(e,t){var n=e.__data__;return Xn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function Qn(e){var t=Zn(this,e).delete(e);return this.size-=+!!t,t}function $n(e){return Zn(this,e).get(e)}function er(e){return Zn(this,e).has(e)}function tr(e,t){var n=Zn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function nr(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])}}nr.prototype.clear=Yn,nr.prototype.delete=Qn,nr.prototype.get=$n,nr.prototype.has=er,nr.prototype.set=tr;var rr=`Expected a function`;function ir(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(rr);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(ir.Cache||nr),n}ir.Cache=nr;var ar=500;function or(e){var t=ir(e,function(e){return n.size===ar&&n.clear(),e}),n=t.cache;return t}var sr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,cr=/\\(\\)?/g,lr=or(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(sr,function(e,n,r,i){t.push(r?i.replace(cr,`$1`):n||e)}),t});function ur(e){return e==null?``:fe(e)}function dr(e,t){return ce(e)?e:On(e,t)?[e]:lr(ur(e))}var fr=1/0;function pr(e){if(typeof e==`string`||oe(e))return e;var t=e+``;return t==`0`&&1/e==-fr?`-0`:t}function mr(e,t){t=dr(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[pr(t[n++])];return n&&n==r?e:void 0}function hr(e,t,n){var r=e==null?void 0:mr(e,t);return r===void 0?n:r}function gr(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var _r=c?c.isConcatSpreadable:void 0;function vr(e){return ce(e)||kt(e)||!!(_r&&e&&e[_r])}function yr(e,t,n,r,i){var a=-1,o=e.length;for(n||=vr,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?yr(s,t-1,n,r,i):gr(i,s):r||(i[i.length]=s)}return i}function br(e){return e!=null&&e.length?yr(e,1):[]}function xr(){this.__data__=new qn,this.size=0}function Sr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Cr(e){return this.__data__.get(e)}function wr(e){return this.__data__.has(e)}var Tr=200;function Er(e,t){var n=this.__data__;if(n instanceof qn){var r=n.__data__;if(!Jn||r.length<Tr-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new nr(r)}return n.set(e,t),this.size=n.size,this}function Dr(e){var t=this.__data__=new qn(e);this.size=t.size}Dr.prototype.clear=xr,Dr.prototype.delete=Sr,Dr.prototype.get=Cr,Dr.prototype.has=wr,Dr.prototype.set=Er;function Or(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 kr(){return[]}var Ar=Object.prototype.propertyIsEnumerable,jr=Object.getOwnPropertySymbols,Mr=jr?function(e){return e==null?[]:(e=Object(e),Or(jr(e),function(t){return Ar.call(e,t)}))}:kr;function Nr(e,t,n){var r=t(e);return ce(e)?r:gr(r,n(e))}function Pr(e){return Nr(e,xn,Mr)}var Fr=Je(s,`DataView`),Ir=Je(s,`Promise`),Lr=Je(s,`Set`),Rr=`[object Map]`,zr=`[object Object]`,Br=`[object Promise]`,Vr=`[object Set]`,Hr=`[object WeakMap]`,Ur=`[object DataView]`,Wr=Re(Fr),Gr=Re(Jn),Kr=Re(Ir),qr=Re(Lr),Jr=Re(Ye),Yr=re;(Fr&&Yr(new Fr(new ArrayBuffer(1)))!=Ur||Jn&&Yr(new Jn)!=Rr||Ir&&Yr(Ir.resolve())!=Br||Lr&&Yr(new Lr)!=Vr||Ye&&Yr(new Ye)!=Hr)&&(Yr=function(e){var t=re(e),n=t==zr?e.constructor:void 0,r=n?Re(n):``;if(r)switch(r){case Wr:return Ur;case Gr:return Rr;case Kr:return Br;case qr:return Vr;case Jr:return Hr}return t});var Xr=Yr,Zr=s.Uint8Array;function Qr(e){for(var t=-1,n=e==null?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i}var $r=`__lodash_hash_undefined__`;function ei(e){return this.__data__.set(e,$r),this}function ti(e){return this.__data__.has(e)}function ni(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new nr;++t<n;)this.add(e[t])}ni.prototype.add=ni.prototype.push=ei,ni.prototype.has=ti;function ri(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function ii(e,t){return e.has(t)}var ai=1,oi=2;function si(e,t,n,r,i,a){var o=n&ai,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&oi?new ni:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var ee=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(ee!==void 0){if(ee)continue;f=!1;break}if(p){if(!ri(t,function(e,t){if(!ii(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}function ci(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function li(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var ui=1,di=2,fi=`[object Boolean]`,pi=`[object Date]`,mi=`[object Error]`,hi=`[object Map]`,gi=`[object Number]`,_i=`[object RegExp]`,vi=`[object Set]`,yi=`[object String]`,bi=`[object Symbol]`,xi=`[object ArrayBuffer]`,Si=`[object DataView]`,Ci=c?c.prototype:void 0,wi=Ci?Ci.valueOf:void 0;function Ti(e,t,n,r,i,a,o){switch(n){case Si:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case xi:return!(e.byteLength!=t.byteLength||!a(new Zr(e),new Zr(t)));case fi:case pi:case gi:return mt(+e,+t);case mi:return e.name==t.name&&e.message==t.message;case _i:case yi:return e==t+``;case hi:var s=ci;case vi:var c=r&ui;if(s||=li,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=di,o.set(e,t);var u=si(s(e),s(t),r,i,a,o);return o.delete(e),u;case bi:if(wi)return wi.call(e)==wi.call(t)}return!1}var Ei=1,Di=Object.prototype.hasOwnProperty;function Oi(e,t,n,r,i,a){var o=n&Ei,s=Pr(e),c=s.length;if(c!=Pr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Di.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var h=e[u],ee=t[u];if(r)var te=o?r(ee,h,u,t,e,a):r(h,ee,u,e,t,a);if(!(te===void 0?h===ee||i(h,ee,n,r,a):te)){p=!1;break}m||=u==`constructor`}if(p&&!m){var ne=e.constructor,re=t.constructor;ne!=re&&`constructor`in e&&`constructor`in t&&!(typeof ne==`function`&&ne instanceof ne&&typeof re==`function`&&re instanceof re)&&(p=!1)}return a.delete(e),a.delete(t),p}var ki=1,Ai=`[object Arguments]`,ji=`[object Array]`,Mi=`[object Object]`,Ni=Object.prototype.hasOwnProperty;function Pi(e,t,n,r,i,a){var o=ce(e),s=ce(t),c=o?ji:Xr(e),l=s?ji:Xr(t);c=c==Ai?Mi:c,l=l==Ai?Mi:l;var u=c==Mi,d=l==Mi,f=c==l;if(f&&Pt(e)){if(!Pt(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Dr,o||mn(e)?si(e,t,n,r,i,a):Ti(e,t,c,n,r,i,a);if(!(n&ki)){var p=u&&Ni.call(e,`__wrapped__`),m=d&&Ni.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,ee=m?t.value():t;return a||=new Dr,i(h,ee,n,r,a)}}return f?(a||=new Dr,Oi(e,t,n,r,i,a)):!1}function Fi(e,t,n,r,i){return e===t?!0:e==null||t==null||!ie(e)&&!ie(t)?e!==e&&t!==t:Pi(e,t,n,r,Fi,i)}var Ii=1,Li=2;function Ri(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 Dr;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Fi(u,l,Ii|Li,r,d):f))return!1}}return!0}function zi(e){return e===e&&!_e(e)}function Bi(e){for(var t=xn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,zi(i)]}return t}function Vi(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function Hi(e){var t=Bi(e);return t.length==1&&t[0][2]?Vi(t[0][0],t[0][1]):function(n){return n===e||Ri(n,e,t)}}function Ui(e,t){return e!=null&&t in Object(e)}function Wi(e,t,n){t=dr(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=pr(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&&yt(i)&&ft(o,i)&&(ce(e)||kt(e)))}function Gi(e,t){return e!=null&&Wi(e,t,Ui)}var Ki=1,qi=2;function Ji(e,t){return On(e)&&zi(t)?Vi(pr(e),t):function(n){var r=hr(n,e);return r===void 0&&r===t?Gi(n,e):Fi(t,r,Ki|qi)}}function Yi(e){return function(t){return t?.[e]}}function Xi(e){return function(t){return mr(t,e)}}function Zi(e){return On(e)?Yi(pr(e)):Xi(e)}function Qi(e){return typeof e==`function`?e:e==null?Oe:typeof e==`object`?ce(e)?Ji(e[0],e[1]):Hi(e):Zi(e)}function $i(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 ea(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 ta=ea();function na(e,t){return e&&ta(e,t,xn)}function ra(e,t){return function(n,r){if(n==null)return n;if(!bt(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 ia=ra(na);function aa(e,t,n,r){return ia(e,function(e,i,a){t(r,e,n(e),a)}),r}function oa(e,t){return function(n,r){var i=ce(n)?$i:aa,a=t?t():{};return i(n,e,Qi(r,2),a)}}function sa(e){return ie(e)&&bt(e)}function ca(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}var la=200;function ua(e,t,n,r){var i=-1,a=lt,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=se(t,cn(n))),r?(a=ca,o=!1):t.length>=la&&(a=ii,o=!1,t=new ni(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var da=_t(function(e,t){return sa(e)?ua(e,yr(t,1,sa,!0)):[]});function g(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function fa(e){return typeof e==`function`?e:Oe}function pa(e,t){var n=[];return ia(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ma(e,t){return(ce(e)?Or:pa)(e,Qi(t,3))}var ha=Math.max,ga=Math.min;function _a(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=De(n),i=n<0?ha(r+i,0):ga(i,r-1)),at(e,Qi(t,3),i,!0)}function va(e){return e&&e.length?e[0]:void 0}function ya(e,t){var n=-1,r=bt(e)?Array(e.length):[];return ia(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function ba(e,t){return(ce(e)?se:ya)(e,Qi(t,3))}function xa(e,t){return yr(ba(e,t),1)}function Sa(e,t){return e==null?e:ta(e,fa(t),Tn)}var Ca=Object.prototype.hasOwnProperty,wa=oa(function(e,t,n){Ca.call(e,n)?e[n].push(t):pt(e,n,[t])}),Ta=`[object Map]`,Ea=`[object Set]`,Da=Object.prototype.hasOwnProperty;function Oa(e){if(e==null)return!0;if(bt(e)&&(ce(e)||typeof e==`string`||typeof e.splice==`function`||Pt(e)||mn(e)||kt(e)))return!e.length;var t=Xr(e);if(t==Ta||t==Ea)return!e.size;if(St(e))return!bn(e).length;for(var n in e)if(Da.call(e,n))return!1;return!0}var ka=oa(function(e,t,n){pt(e,n,t)}),_=oa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),Aa=Lr&&1/li(new Lr([,-0]))[1]==1/0?function(e){return new Lr(e)}:Ze,ja=200;function Ma(e,t,n){var r=-1,i=lt,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=ca;else if(a>=ja){var l=t?null:Aa(e);if(l)return li(l);o=!1,i=ii,c=new ni}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}function Na(e){return e&&e.length?Ma(e):[]}function Pa(e,t){return e&&e.length?Ma(e,Qi(t,2)):[]}var Fa=Math.max;function Ia(e){if(!(e&&e.length))return[];var t=0;return e=Or(e,function(e){if(sa(e))return t=Fa(e.length,t),!0}),Ct(t,function(t){return se(e,Yi(t))})}var La=_t(Ia),v=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.FRONT_MATTER=`<front-matter>`,e.WILDCARD=`<wildcard>`,e}({});function Ra(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:case`<front-matter>`:return!0;default:return!1}}function za(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 Ba(e){return e!==void 0&&e.kind===`<op>`}var Va=class e{constructor(e,t,n,r,i,a){this.kind=e,this.filepath=t,this.startPos=n,this.endPos=r,this.value=i,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=a,this.start=n.offset,this.end=r.offset}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}};function Ha(e){return e.trailingTrivia.find(({kind:e})=>e===v.NEWLINE)!==void 0}function Ua(e,t){return t.leadingTrivia.find(({kind:e})=>e===v.NEWLINE)!==void 0||Ha(e)}function Wa(e){return e.trailingTrivia.find(({kind:e})=>[v.SPACE,v.TAB].includes(e))!==void 0}function Ga(e){return e.trailingTrivia.length===0?e.end:Ga(g(e.trailingTrivia))}function Ka(e){return e.leadingTrivia.length===0?e.start:Ka(e.leadingTrivia[0])}function qa(e){return[v.SINGLE_LINE_COMMENT,v.MULTILINE_COMMENT].includes(e.kind)}var Ja=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},Ya=/^[A-Za-z]:\//;function Xa(e=``){return e&&e.replace(/\\/g,`/`).replace(Ya,e=>e.toUpperCase())}var Za=/^[/\\]{2}/,Qa=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,$a=/^[A-Za-z]:$/,eo=/^\/([A-Za-z]:)?$/,to=/.(\.[^./]+|\.)$/,no=function(e){if(e.length===0)return`.`;e=Xa(e);let t=e.match(Za),n=so(e),r=e[e.length-1]===`/`;return e=oo(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),$a.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!so(e)?`/${e}`:e)},ro=function(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return no(t)};function io(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var ao=function(...e){e=e.map(e=>Xa(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:io();!i||i.length===0||(t=`${i}/${t}`,n=so(i))}return t=oo(t,!n),n&&!so(t)?`/${t}`:t.length>0?t:`.`};function oo(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}var so=function(e){return Qa.test(e)},co=function(e){if(e===`..`)return``;let t=to.exec(Xa(e));return t&&t[1]||``},lo=function(e,t){let n=ao(e).replace(eo,`$1`).split(`/`),r=ao(t).replace(eo,`$1`).split(`/`);if(r[0][1]===`:`&&n[0][1]===`:`&&n[0]!==r[0])return r.join(`/`);let i=[...n];for(let e of i){if(r[0]!==e)break;n.shift(),r.shift()}return[...n.map(()=>`..`),...r].join(`/`)},uo=function(e){let t=Xa(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&$a.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(so(e)?`/`:`.`)},fo=function(e,t){let n=Xa(e).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return t&&r.endsWith(t)?r.slice(0,-t.length):r},po=/^[a-zA-Z]:\//,mo=class e{constructor(e,t={}){e=e.split(`/`).map(ho).join(`/`);let n=no(e);if(!so(n))throw Error(`FilePath requires an absolute path, got: "${e}"`);this.path=n,this.protocol=t.protocol}intern(){return this.protocol,`filepath@${this.path}`}static from(t){return new e(t)}static resolve(t,n){return new e(ao(t,n))}static fromUri(t){try{let n=new URL(t);return new e(no(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(no(t))}}get absolute(){return this.path}get fsPath(){return this.path.split(`/`).map(decodeURIComponent).join(`/`)}get dirname(){return uo(this.fsPath)}get basename(){return fo(this.fsPath)}get extname(){return co(this.fsPath)}resolve(t){return new e(ao(this.dirname,t))}join(...t){return new e(ro(this.path,...t))}relativeTo(e){let t=lo(e,this.fsPath);return!t.startsWith(`./`)&&!t.startsWith(`../`)&&![`.`,`..`].includes(t)?`./${t}`:t}toKey(){return this.path}equals(e){return this.toKey()===e.toKey()}isParentOf(e){if(this.path===e.path)return!1;let t=this.path.endsWith(`/`)?this.path:`${this.path}/`;return e.path.startsWith(t)}toUri(e={}){let t=e.protocol||this.protocol;if(!t)return this.path;let n=po.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!so(no(e))}};function ho(e){try{return encodeURIComponent(decodeURIComponent(e))}catch{return encodeURIComponent(e)}}var go=[`null`,`true`,`false`],_o=`none`,vo=`.dbml`,yo=[`-`,`+`],y=`public`,bo=mo.from(`/main.dbml`),xo={mysql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`,`mediumint`]),postgres:new Set([`int`,`integer`,`smallint`,`bigint`,`serial`,`bigserial`,`smallserial`]),mssql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`]),oracle:new Set([`int`,`integer`,`smallint`]),snowflake:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`])},So={mysql:new Set([`decimal`,`numeric`,`float`,`double`,`real`]),postgres:new Set([`decimal`,`numeric`,`real`,`float`,`double precision`]),mssql:new Set([`decimal`,`numeric`,`real`,`float`]),oracle:new Set([`number`,`decimal`,`numeric`,`float`,`real`]),snowflake:new Set([`number`,`decimal`,`numeric`,`float`,`double`,`real`])},Co={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},wo={mysql:new Set([`varchar`,`char`,`text`,`tinytext`,`mediumtext`,`longtext`,`string`]),postgres:new Set([`varchar`,`char`,`character`,`character varying`,`text`,`string`]),mssql:new Set([`varchar`,`char`,`nvarchar`,`nchar`,`text`,`ntext`,`string`]),oracle:new Set([`varchar`,`varchar2`,`char`,`nvarchar2`,`nchar`,`string`]),snowflake:new Set([`varchar`,`char`,`text`,`string`])},To={mysql:new Set([`binary`,`varbinary`,`blob`,`tinyblob`,`mediumblob`,`longblob`]),postgres:new Set([`bytea`]),mssql:new Set([`binary`,`varbinary`]),oracle:new Set([`blob`,`raw`]),snowflake:new Set([`binary`,`varbinary`])},Eo={mysql:new Set([`date`,`datetime`,`timestamp`,`time`]),postgres:new Set([`date`,`timestamp`,`timestamptz`,`timestamp with time zone`,`timestamp without time zone`,`time`,`timetz`,`time with time zone`,`time without time zone`]),mssql:new Set([`date`,`datetime`,`datetime2`,`smalldatetime`,`time`]),oracle:new Set([`date`,`timestamp`,`timestamp with time zone`,`timestamp with local time zone`]),snowflake:new Set([`date`,`datetime`,`timestamp`,`time`])},Do={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function Oo(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function ko(e,t){let n=Oo(e);return t?xo[t].has(n):Object.values(xo).some(e=>e.has(n))}function Ao(e,t){let n=Oo(e);return t?So[t].has(n):Object.values(So).some(e=>e.has(n))}function jo(e,t){return ko(e,t)||Ao(e,t)}function Mo(e,t){let n=Oo(e);return t?Co[t].has(n):Object.values(Co).some(e=>e.has(n))}function No(e,t){let n=Oo(e);return t?wo[t].has(n):Object.values(wo).some(e=>e.has(n))}function Po(e,t){let n=Oo(e);return t?To[t].has(n):Object.values(To).some(e=>e.has(n))}function Fo(e,t){let n=Oo(e);return t?Eo[t].has(n):Object.values(Eo).some(e=>e.has(n))}function Io(e,t){let n=Oo(e);return t?Do[t].has(n):Object.values(Do).some(e=>e.has(n))}function Lo(e,t){if(t)return`string`;if(ko(e))return`integer`;if(Ao(e))return`real`;if(Mo(e))return`bool`;if(No(e))return`string`;let n=Oo(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:Fo(e)?`datetime`:e}var Ro=class extends Error{},zo=class extends Ro{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Bo=class extends Ro{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Vo=class extends Ro{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Ho=class extends Ro{},Uo=class extends Ro{constructor(e){super(`Invalid unit ${e}`)}},Wo=class extends Ro{},Go=class extends Ro{constructor(){super(`Zone is an abstract class`)}},b=`numeric`,Ko=`short`,qo=`long`,Jo={year:b,month:b,day:b},Yo={year:b,month:Ko,day:b},Xo={year:b,month:Ko,day:b,weekday:Ko},Zo={year:b,month:qo,day:b},Qo={year:b,month:qo,day:b,weekday:qo},$o={hour:b,minute:b},es={hour:b,minute:b,second:b},ts={hour:b,minute:b,second:b,timeZoneName:Ko},ns={hour:b,minute:b,second:b,timeZoneName:qo},rs={hour:b,minute:b,hourCycle:`h23`},is={hour:b,minute:b,second:b,hourCycle:`h23`},as={hour:b,minute:b,second:b,hourCycle:`h23`,timeZoneName:Ko},os={hour:b,minute:b,second:b,hourCycle:`h23`,timeZoneName:qo},ss={year:b,month:b,day:b,hour:b,minute:b},cs={year:b,month:b,day:b,hour:b,minute:b,second:b},ls={year:b,month:Ko,day:b,hour:b,minute:b},us={year:b,month:Ko,day:b,hour:b,minute:b,second:b},ds={year:b,month:Ko,day:b,weekday:Ko,hour:b,minute:b},fs={year:b,month:qo,day:b,hour:b,minute:b,timeZoneName:Ko},ps={year:b,month:qo,day:b,hour:b,minute:b,second:b,timeZoneName:Ko},ms={year:b,month:qo,day:b,weekday:qo,hour:b,minute:b,timeZoneName:qo},hs={year:b,month:qo,day:b,weekday:qo,hour:b,minute:b,second:b,timeZoneName:qo},gs=class{get type(){throw new Go}get name(){throw new Go}get ianaName(){return this.name}get isUniversal(){throw new Go}offsetName(e,t){throw new Go}formatOffset(e,t){throw new Go}offset(e){throw new Go}equals(e){throw new Go}get isValid(){throw new Go}},_s=null,vs=class e extends gs{static get instance(){return _s===null&&(_s=new e),_s}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return al(e,t,n)}formatOffset(e,t){return ll(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},ys=new Map;function bs(e){let t=ys.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(`en-US`,{hour12:!1,timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,era:`short`}),ys.set(e,t)),t}var xs={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function Ss(e,t){let n=e.format(t).replace(/\u200E/g,``),[,r,i,a,o,s,c,l]=/(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(n);return[a,r,i,o,s,c,l]}function Cs(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=xs[t];t===`era`?r[a]=i:x(a)||(r[a]=parseInt(i,10))}return r}var ws=new Map,Ts=class e extends gs{static create(t){let n=ws.get(t);return n===void 0&&ws.set(t,n=new e(t)),n}static resetCache(){ws.clear(),ys.clear()}static isValidSpecifier(e){return this.isValidZone(e)}static isValidZone(e){if(!e)return!1;try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).format(),!0}catch{return!1}}constructor(t){super(),this.zoneName=t,this.valid=e.isValidZone(t)}get type(){return`iana`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return al(e,t,n,this.name)}formatOffset(e,t){return ll(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=bs(this.name),[r,i,a,o,s,c,l]=n.formatToParts?Cs(n,t):Ss(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=tl({year:r,month:i,day:a,hour:s===24?0:s,minute:c,second:l,millisecond:0}),d=+t,f=d%1e3;return d-=f>=0?f:1e3+f,(u-d)/(60*1e3)}equals(e){return e.type===`iana`&&e.name===this.name}get isValid(){return this.valid}},Es={};function Ds(e,t={}){let n=JSON.stringify([e,t]),r=Es[n];return r||(r=new Intl.ListFormat(e,t),Es[n]=r),r}var Os=new Map;function ks(e,t={}){let n=JSON.stringify([e,t]),r=Os.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),Os.set(n,r)),r}var As=new Map;function js(e,t={}){let n=JSON.stringify([e,t]),r=As.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),As.set(n,r)),r}var Ms=new Map;function Ns(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=Ms.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),Ms.set(i,a)),a}var Ps=null;function Fs(){return Ps||(Ps=new Intl.DateTimeFormat().resolvedOptions().locale,Ps)}var Is=new Map;function Ls(e){let t=Is.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Is.set(e,t)),t}var Rs=new Map;function zs(e){let t=Rs.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Ys,...t}),Rs.set(e,t)}return t}function Bs(e){let t=e.indexOf(`-x-`);t!==-1&&(e=e.substring(0,t));let n=e.indexOf(`-u-`);if(n===-1)return[e];{let t,r;try{t=ks(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=ks(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Vs(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Hs(e){let t=[];for(let n=1;n<=12;n++){let r=Yd.utc(2009,n,1);t.push(e(r))}return t}function Us(e){let t=[];for(let n=1;n<=7;n++){let r=Yd.utc(2016,11,13+n);t.push(e(r))}return t}function Ws(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Gs(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Ls(e.locale).numberingSystem===`latn`}var Ks=class{constructor(e,t,n){this.padTo=n.padTo||0,this.floor=n.floor||!1;let{padTo:r,floor:i,...a}=n;if(!t||Object.keys(a).length>0){let t={useGrouping:!1,...n};n.padTo>0&&(t.minimumIntegerDigits=n.padTo),this.inf=js(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return qc(this.floor?Math.floor(e):Zc(e,3),this.padTo)}},qs=class{constructor(e,t,n){this.opts=n,this.originalZone=void 0;let r;if(this.opts.timeZone)this.dt=e;else if(e.zone.type===`fixed`){let t=-1*(e.offset/60),n=t>=0?`Etc/GMT+${t}`:`Etc/GMT${t}`;e.offset!==0&&Ts.create(n).valid?(r=n,this.dt=e):(r=`UTC`,this.dt=e.offset===0?e:e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone)}else e.zone.type===`system`?this.dt=e:e.zone.type===`iana`?(this.dt=e,r=e.zone.name):(r=`UTC`,this.dt=e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone);let i={...this.opts};i.timeZone=i.timeZone||r,this.dtf=ks(t,i)}format(){return this.originalZone?this.formatToParts().map(({value:e})=>e).join(``):this.dtf.format(this.dt.toJSDate())}formatToParts(){let e=this.dtf.formatToParts(this.dt.toJSDate());return this.originalZone?e.map(e=>{if(e.type===`timeZoneName`){let t=this.originalZone.offsetName(this.dt.ts,{locale:this.dt.locale,format:this.opts.timeZoneName});return{...e,value:t}}else return e}):e}resolvedOptions(){return this.dtf.resolvedOptions()}},Js=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Rc()&&(this.rtf=Ns(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):Ol(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Ys={firstDay:1,minimalDays:4,weekend:[6,7]},Xs=class e{static fromOpts(t){return e.create(t.locale,t.numberingSystem,t.outputCalendar,t.weekSettings,t.defaultToEN)}static create(t,n,r,i,a=!1){let o=t||gc.defaultLocale;return new e(o||(a?`en-US`:Fs()),n||gc.defaultNumberingSystem,r||gc.defaultOutputCalendar,Wc(i)||gc.defaultWeekSettings,o)}static resetCache(){Ps=null,Os.clear(),As.clear(),Ms.clear(),Is.clear(),Rs.clear()}static fromObject({locale:t,numberingSystem:n,outputCalendar:r,weekSettings:i}={}){return e.create(t,n,r,i)}constructor(e,t,n,r,i){let[a,o,s]=Bs(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Vs(this.locale,this.numberingSystem,this.outputCalendar),this.weekdaysCache={format:{},standalone:{}},this.monthsCache={format:{},standalone:{}},this.meridiemCache=null,this.eraCache={},this.specifiedLocale=i,this.fastNumbersCached=null}get fastNumbers(){return this.fastNumbersCached??=Gs(this),this.fastNumbersCached}listingMode(){let e=this.isEnglish(),t=(this.numberingSystem===null||this.numberingSystem===`latn`)&&(this.outputCalendar===null||this.outputCalendar===`gregory`);return e&&t?`en`:`intl`}clone(t){return!t||Object.getOwnPropertyNames(t).length===0?this:e.create(t.locale||this.specifiedLocale,t.numberingSystem||this.numberingSystem,t.outputCalendar||this.outputCalendar,Wc(t.weekSettings)||this.weekSettings,t.defaultToEN||!1)}redefaultToEN(e={}){return this.clone({...e,defaultToEN:!0})}redefaultToSystem(e={}){return this.clone({...e,defaultToEN:!1})}months(e,t=!1){return Ws(this,e,ml,()=>{let n=this.intl===`ja`||this.intl.startsWith(`ja-`);t&=!n;let r=t?{month:e,day:`numeric`}:{month:e},i=t?`format`:`standalone`;if(!this.monthsCache[i][e]){let t=n?e=>this.dtFormatter(e,r).format():e=>this.extract(e,r,`month`);this.monthsCache[i][e]=Hs(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Ws(this,e,vl,()=>{let n=t?{weekday:e,year:`numeric`,month:`long`,day:`numeric`}:{weekday:e},r=t?`format`:`standalone`;return this.weekdaysCache[r][e]||(this.weekdaysCache[r][e]=Us(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Ws(this,void 0,()=>yl,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[Yd.utc(2016,11,13,9),Yd.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Ws(this,e,Cl,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[Yd.utc(-40,1,1),Yd.utc(2017,1,1)].map(e=>this.extract(e,t,`era`))),this.eraCache[e]})}extract(e,t,n){let r=this.dtFormatter(e,t).formatToParts().find(e=>e.type.toLowerCase()===n);return r?r.value:null}numberFormatter(e={}){return new Ks(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new qs(e,this.intl,t)}relFormatter(e={}){return new Js(this.intl,this.isEnglish(),e)}listFormatter(e={}){return Ds(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Ls(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:zc()?zs(this.locale):Ys}getStartOfWeek(){return this.getWeekSettings().firstDay}getMinDaysInFirstWeek(){return this.getWeekSettings().minimalDays}getWeekendDays(){return this.getWeekSettings().weekend}equals(e){return this.locale===e.locale&&this.numberingSystem===e.numberingSystem&&this.outputCalendar===e.outputCalendar}toString(){return`Locale(${this.locale}, ${this.numberingSystem}, ${this.outputCalendar})`}},Zs=null,Qs=class e extends gs{static get utcInstance(){return Zs===null&&(Zs=new e(0)),Zs}static instance(t){return t===0?e.utcInstance:new e(t)}static parseSpecifier(t){if(t){let n=t.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);if(n)return new e(ol(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${ll(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${ll(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return ll(this.fixed,t)}get isUniversal(){return!0}offset(){return this.fixed}equals(e){return e.type===`fixed`&&e.fixed===this.fixed}get isValid(){return!0}},$s=class extends gs{constructor(e){super(),this.zoneName=e}get type(){return`invalid`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(){return null}formatOffset(){return``}offset(){return NaN}equals(){return!1}get isValid(){return!1}};function ec(e,t){if(x(e)||e===null)return t;if(e instanceof gs)return e;if(Ic(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?vs.instance:n===`utc`||n===`gmt`?Qs.utcInstance:Qs.parseSpecifier(n)||Ts.create(e)}else if(Pc(e))return Qs.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new $s(e)}var tc={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},nc={arab:[1632,1641],arabext:[1776,1785],bali:[6992,7001],beng:[2534,2543],deva:[2406,2415],fullwide:[65296,65303],gujr:[2790,2799],khmr:[6112,6121],knda:[3302,3311],laoo:[3792,3801],limb:[6470,6479],mlym:[3430,3439],mong:[6160,6169],mymr:[4160,4169],orya:[2918,2927],tamldec:[3046,3055],telu:[3174,3183],thai:[3664,3673],tibt:[3872,3881]},rc=tc.hanidec.replace(/[\[|\]]/g,``).split(``);function ic(e){let t=parseInt(e,10);if(isNaN(t)){t=``;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(e[n].search(tc.hanidec)!==-1)t+=rc.indexOf(e[n]);else for(let e in nc){let[n,i]=nc[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var ac=new Map;function oc(){ac.clear()}function sc({numberingSystem:e},t=``){let n=e||`latn`,r=ac.get(n);r===void 0&&(r=new Map,ac.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${tc[n]}${t}`),r.set(t,i)),i}var cc=()=>Date.now(),lc=`system`,uc=null,dc=null,fc=null,pc=60,mc,hc=null,gc=class{static get now(){return cc}static set now(e){cc=e}static set defaultZone(e){lc=e}static get defaultZone(){return ec(lc,vs.instance)}static get defaultLocale(){return uc}static set defaultLocale(e){uc=e}static get defaultNumberingSystem(){return dc}static set defaultNumberingSystem(e){dc=e}static get defaultOutputCalendar(){return fc}static set defaultOutputCalendar(e){fc=e}static get defaultWeekSettings(){return hc}static set defaultWeekSettings(e){hc=Wc(e)}static get twoDigitCutoffYear(){return pc}static set twoDigitCutoffYear(e){pc=e%100}static get throwOnInvalid(){return mc}static set throwOnInvalid(e){mc=e}static resetCaches(){Xs.resetCache(),Ts.resetCache(),Yd.resetCache(),oc()}},_c=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},vc=[0,31,59,90,120,151,181,212,243,273,304,334],yc=[0,31,60,91,121,152,182,213,244,274,305,335];function bc(e,t){return new _c(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function xc(e,t,n){let r=new Date(Date.UTC(e,t-1,n));e<100&&e>=0&&r.setUTCFullYear(r.getUTCFullYear()-1900);let i=r.getUTCDay();return i===0?7:i}function Sc(e,t,n){return n+(Qc(e)?yc:vc)[t-1]}function Cc(e,t){let n=Qc(e)?yc:vc,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function wc(e,t){return(e-t+7)%7+1}function Tc(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Sc(r,i,a),s=wc(xc(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=rl(l,t,n)):c>rl(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...ul(e)}}function Ec(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=wc(xc(r,1,t),n),s=$c(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=$c(l)):c>s?(l=r+1,c-=$c(r)):l=r;let{month:u,day:d}=Cc(l,c);return{year:l,month:u,day:d,...ul(e)}}function Dc(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Sc(t,n,r),...ul(e)}}function Oc(e){let{year:t,ordinal:n}=e,{month:r,day:i}=Cc(t,n);return{year:t,month:r,day:i,...ul(e)}}function kc(e,t){if(!x(e.localWeekday)||!x(e.localWeekNumber)||!x(e.localWeekYear)){if(!x(e.weekday)||!x(e.weekNumber)||!x(e.weekYear))throw new Ho(`Cannot mix locale-based week fields with ISO-based week fields`);return x(e.localWeekday)||(e.weekday=e.localWeekday),x(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),x(e.localWeekYear)||(e.weekYear=e.localWeekYear),delete e.localWeekday,delete e.localWeekNumber,delete e.localWeekYear,{minDaysInFirstWeek:t.getMinDaysInFirstWeek(),startOfWeek:t.getStartOfWeek()}}else return{minDaysInFirstWeek:4,startOfWeek:1}}function Ac(e,t=4,n=1){let r=Fc(e.weekYear),i=Gc(e.weekNumber,1,rl(e.weekYear,t,n)),a=Gc(e.weekday,1,7);return r?i?a?!1:bc(`weekday`,e.weekday):bc(`week`,e.weekNumber):bc(`weekYear`,e.weekYear)}function jc(e){let t=Fc(e.year),n=Gc(e.ordinal,1,$c(e.year));return t?n?!1:bc(`ordinal`,e.ordinal):bc(`year`,e.year)}function Mc(e){let t=Fc(e.year),n=Gc(e.month,1,12),r=Gc(e.day,1,el(e.year,e.month));return t?n?r?!1:bc(`day`,e.day):bc(`month`,e.month):bc(`year`,e.year)}function Nc(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Gc(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Gc(n,0,59),s=Gc(r,0,59),c=Gc(i,0,999);return a?o?s?c?!1:bc(`millisecond`,i):bc(`second`,r):bc(`minute`,n):bc(`hour`,t)}function x(e){return e===void 0}function Pc(e){return typeof e==`number`}function Fc(e){return typeof e==`number`&&e%1==0}function Ic(e){return typeof e==`string`}function Lc(e){return Object.prototype.toString.call(e)===`[object Date]`}function Rc(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function zc(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Bc(e){return Array.isArray(e)?e:[e]}function Vc(e,t,n){if(e.length!==0)return e.reduce((e,r)=>{let i=[t(r),r];return e&&n(e[0],i[0])===e[0]?e:i},null)[1]}function Hc(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Uc(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Wc(e){if(e==null)return null;if(typeof e!=`object`)throw new Wo(`Week settings must be an object`);if(!Gc(e.firstDay,1,7)||!Gc(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Gc(e,1,7)))throw new Wo(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Gc(e,t,n){return Fc(e)&&e>=t&&e<=n}function Kc(e,t){return e-t*Math.floor(e/t)}function qc(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Jc(e){if(!(x(e)||e===null||e===``))return parseInt(e,10)}function Yc(e){if(!(x(e)||e===null||e===``))return parseFloat(e)}function Xc(e){if(!(x(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Zc(e,t,n=`round`){let r=10**t;switch(n){case`expand`:return e>0?Math.ceil(e*r)/r:Math.floor(e*r)/r;case`trunc`:return Math.trunc(e*r)/r;case`round`:return Math.round(e*r)/r;case`floor`:return Math.floor(e*r)/r;case`ceil`:return Math.ceil(e*r)/r;default:throw RangeError(`Value rounding ${n} is out of range`)}}function Qc(e){return e%4==0&&(e%100!=0||e%400==0)}function $c(e){return Qc(e)?366:365}function el(e,t){let n=Kc(t-1,12)+1,r=e+(t-n)/12;return n===2?Qc(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function tl(e){let t=Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second,e.millisecond);return e.year<100&&e.year>=0&&(t=new Date(t),t.setUTCFullYear(e.year,e.month-1,e.day)),+t}function nl(e,t,n){return-wc(xc(e,1,t),n)+t-1}function rl(e,t=4,n=1){let r=nl(e,t,n),i=nl(e+1,t,n);return($c(e)-r+i)/7}function il(e){return e>99?e:e>gc.twoDigitCutoffYear?1900+e:2e3+e}function al(e,t,n,r=null){let i=new Date(e),a={hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};r&&(a.timeZone=r);let o={timeZoneName:t,...a},s=new Intl.DateTimeFormat(n,o).formatToParts(i).find(e=>e.type.toLowerCase()===`timezonename`);return s?s.value:null}function ol(e,t){let n=parseInt(e,10);Number.isNaN(n)&&(n=0);let r=parseInt(t,10)||0,i=n<0||Object.is(n,-0)?-r:r;return n*60+i}function sl(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Wo(`Invalid unit value ${e}`);return t}function cl(e,t){let n={};for(let r in e)if(Uc(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=sl(i)}return n}function ll(e,t){let n=Math.trunc(Math.abs(e/60)),r=Math.trunc(Math.abs(e%60)),i=e>=0?`+`:`-`;switch(t){case`short`:return`${i}${qc(n,2)}:${qc(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${qc(n,2)}${qc(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function ul(e){return Hc(e,[`hour`,`minute`,`second`,`millisecond`])}var dl=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],fl=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],pl=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function ml(e){switch(e){case`narrow`:return[...pl];case`short`:return[...fl];case`long`:return[...dl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`,`12`];case`2-digit`:return[`01`,`02`,`03`,`04`,`05`,`06`,`07`,`08`,`09`,`10`,`11`,`12`];default:return null}}var hl=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],gl=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],_l=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function vl(e){switch(e){case`narrow`:return[..._l];case`short`:return[...gl];case`long`:return[...hl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var yl=[`AM`,`PM`],bl=[`Before Christ`,`Anno Domini`],xl=[`BC`,`AD`],Sl=[`B`,`A`];function Cl(e){switch(e){case`narrow`:return[...Sl];case`short`:return[...xl];case`long`:return[...bl];default:return null}}function wl(e){return yl[e.hour<12?0:1]}function Tl(e,t){return vl(t)[e.weekday-1]}function El(e,t){return ml(t)[e.month-1]}function Dl(e,t){return Cl(t)[e.year<0?0:1]}function Ol(e,t,n=`always`,r=!1){let i={years:[`year`,`yr.`],quarters:[`quarter`,`qtr.`],months:[`month`,`mo.`],weeks:[`week`,`wk.`],days:[`day`,`day`,`days`],hours:[`hour`,`hr.`],minutes:[`minute`,`min.`],seconds:[`second`,`sec.`]},a=[`hours`,`minutes`,`seconds`].indexOf(e)===-1;if(n===`auto`&&a){let n=e===`days`;switch(t){case 1:return n?`tomorrow`:`next ${i[e][0]}`;case-1:return n?`yesterday`:`last ${i[e][0]}`;case 0:return n?`today`:`this ${i[e][0]}`}}let o=Object.is(t,-0)||t<0,s=Math.abs(t),c=s===1,l=i[e],u=r?c?l[1]:l[2]||l[1]:c?i[e][0]:e;return o?`${s} ${u} ago`:`in ${s} ${u}`}function kl(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var Al={D:Jo,DD:Yo,DDD:Zo,DDDD:Qo,t:$o,tt:es,ttt:ts,tttt:ns,T:rs,TT:is,TTT:as,TTTT:os,f:ss,ff:ls,fff:fs,ffff:ms,F:cs,FF:us,FFF:ps,FFFF:hs},jl=class e{static create(t,n={}){return new e(t,n)}static parseFormat(e){let t=null,n=``,r=!1,i=[];for(let a=0;a<e.length;a++){let o=e.charAt(a);o===`'`?((n.length>0||r)&&i.push({literal:r||/^\s+$/.test(n),val:n===``?`'`:n}),t=null,n=``,r=!r):r||o===t?n+=o:(n.length>0&&i.push({literal:/^\s+$/.test(n),val:n}),n=o,t=o)}return n.length>0&&i.push({literal:r||/^\s+$/.test(n),val:n}),i}static macroTokenToFormatOpts(e){return Al[e]}constructor(e,t){this.opts=t,this.loc=e,this.systemLoc=null}formatWithSystemDefault(e,t){return this.systemLoc===null&&(this.systemLoc=this.loc.redefaultToSystem()),this.systemLoc.dtFormatter(e,{...this.opts,...t}).format()}dtFormatter(e,t={}){return this.loc.dtFormatter(e,{...this.opts,...t})}formatDateTime(e,t){return this.dtFormatter(e,t).format()}formatDateTimeParts(e,t){return this.dtFormatter(e,t).formatToParts()}formatInterval(e,t){return this.dtFormatter(e.start,t).dtf.formatRange(e.start.toJSDate(),e.end.toJSDate())}resolvedOptions(e,t){return this.dtFormatter(e,t).resolvedOptions()}num(e,t=0,n=void 0){if(this.opts.forceSimple)return qc(e,t);let r={...this.opts};return t>0&&(r.padTo=t),n&&(r.signDisplay=n),this.loc.numberFormatter(r).format(e)}formatDateTimeFromString(t,n){let r=this.loc.listingMode()===`en`,i=this.loc.outputCalendar&&this.loc.outputCalendar!==`gregory`,a=(e,n)=>this.loc.extract(t,e,n),o=e=>t.isOffsetFixed&&t.offset===0&&e.allowZ?`Z`:t.isValid?t.zone.formatOffset(t.ts,e.format):``,s=()=>r?wl(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?El(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?Tl(t,e):a(n?{weekday:e}:{weekday:e,month:`long`,day:`numeric`},`weekday`),u=n=>{let r=e.macroTokenToFormatOpts(n);return r?this.formatWithSystemDefault(t,r):n},d=e=>r?Dl(t,e):a({era:e},`era`);return kl(e.parseFormat(n),e=>{switch(e){case`S`:return this.num(t.millisecond);case`u`:case`SSS`:return this.num(t.millisecond,3);case`s`:return this.num(t.second);case`ss`:return this.num(t.second,2);case`uu`:return this.num(Math.floor(t.millisecond/10),2);case`uuu`:return this.num(Math.floor(t.millisecond/100));case`m`:return this.num(t.minute);case`mm`:return this.num(t.minute,2);case`h`:return this.num(t.hour%12==0?12:t.hour%12);case`hh`:return this.num(t.hour%12==0?12:t.hour%12,2);case`H`:return this.num(t.hour);case`HH`:return this.num(t.hour,2);case`Z`:return o({format:`narrow`,allowZ:this.opts.allowZ});case`ZZ`:return o({format:`short`,allowZ:this.opts.allowZ});case`ZZZ`:return o({format:`techie`,allowZ:this.opts.allowZ});case`ZZZZ`:return t.zone.offsetName(t.ts,{format:`short`,locale:this.loc.locale});case`ZZZZZ`:return t.zone.offsetName(t.ts,{format:`long`,locale:this.loc.locale});case`z`:return t.zoneName;case`a`:return s();case`d`:return i?a({day:`numeric`},`day`):this.num(t.day);case`dd`:return i?a({day:`2-digit`},`day`):this.num(t.day,2);case`c`:return this.num(t.weekday);case`ccc`:return l(`short`,!0);case`cccc`:return l(`long`,!0);case`ccccc`:return l(`narrow`,!0);case`E`:return this.num(t.weekday);case`EEE`:return l(`short`,!1);case`EEEE`:return l(`long`,!1);case`EEEEE`:return l(`narrow`,!1);case`L`:return i?a({month:`numeric`,day:`numeric`},`month`):this.num(t.month);case`LL`:return i?a({month:`2-digit`,day:`numeric`},`month`):this.num(t.month,2);case`LLL`:return c(`short`,!0);case`LLLL`:return c(`long`,!0);case`LLLLL`:return c(`narrow`,!0);case`M`:return i?a({month:`numeric`},`month`):this.num(t.month);case`MM`:return i?a({month:`2-digit`},`month`):this.num(t.month,2);case`MMM`:return c(`short`,!1);case`MMMM`:return c(`long`,!1);case`MMMMM`:return c(`narrow`,!1);case`y`:return i?a({year:`numeric`},`year`):this.num(t.year);case`yy`:return i?a({year:`2-digit`},`year`):this.num(t.year.toString().slice(-2),2);case`yyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,4);case`yyyyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,6);case`G`:return d(`short`);case`GG`:return d(`long`);case`GGGGG`:return d(`narrow`);case`kk`:return this.num(t.weekYear.toString().slice(-2),2);case`kkkk`:return this.num(t.weekYear,4);case`W`:return this.num(t.weekNumber);case`WW`:return this.num(t.weekNumber,2);case`n`:return this.num(t.localWeekNumber);case`nn`:return this.num(t.localWeekNumber,2);case`ii`:return this.num(t.localWeekYear.toString().slice(-2),2);case`iiii`:return this.num(t.localWeekYear,4);case`o`:return this.num(t.ordinal);case`ooo`:return this.num(t.ordinal,3);case`q`:return this.num(t.quarter);case`qq`:return this.num(t.quarter,2);case`X`:return this.num(Math.floor(t.ts/1e3));case`x`:return this.num(t.ts);default:return u(e)}})}formatDurationFromString(t,n){let r=this.opts.signMode===`negativeLargestOnly`?-1:1,i=e=>{switch(e[0]){case`S`:return`milliseconds`;case`s`:return`seconds`;case`m`:return`minutes`;case`h`:return`hours`;case`d`:return`days`;case`w`:return`weeks`;case`M`:return`months`;case`y`:return`years`;default:return null}},a=(e,t)=>n=>{let a=i(n);if(a){let i=t.isNegativeDuration&&a!==t.largestUnit?r:1,o;return o=this.opts.signMode===`negativeLargestOnly`&&a!==t.largestUnit?`never`:this.opts.signMode===`all`?`always`:`auto`,this.num(e.get(a)*i,n.length,o)}else return n},o=e.parseFormat(n),s=o.reduce((e,{literal:t,val:n})=>t?e:e.concat(n),[]),c=t.shiftTo(...s.map(i).filter(e=>e));return kl(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Ml=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Nl(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Pl(...e){return t=>e.reduce(([e,n,r],i)=>{let[a,o,s]=i(t,r);return[{...e,...a},o||n,s]},[{},null,1]).slice(0,2)}function Fl(e,...t){if(e==null)return[null,null];for(let[n,r]of t){let t=n.exec(e);if(t)return r(t)}return[null,null]}function Il(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Jc(t[n+i]);return[r,null,n+i]}}var Ll=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Rl=`(?:${Ll.source}?(?:\\[(${Ml.source})\\])?)?`,zl=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Bl=RegExp(`${zl.source}${Rl}`),Vl=RegExp(`(?:[Tt]${Bl.source})?`),Hl=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Ul=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Wl=/(\d{4})-?(\d{3})/,Gl=Il(`weekYear`,`weekNumber`,`weekDay`),Kl=Il(`year`,`ordinal`),ql=/(\d{4})-(\d\d)-(\d\d)/,Jl=RegExp(`${zl.source} ?(?:${Ll.source}|(${Ml.source}))?`),Yl=RegExp(`(?: ${Jl.source})?`);function Xl(e,t,n){let r=e[t];return x(r)?n:Jc(r)}function Zl(e,t){return[{year:Xl(e,t),month:Xl(e,t+1,1),day:Xl(e,t+2,1)},null,t+3]}function Ql(e,t){return[{hours:Xl(e,t,0),minutes:Xl(e,t+1,0),seconds:Xl(e,t+2,0),milliseconds:Xc(e[t+3])},null,t+4]}function $l(e,t){let n=!e[t]&&!e[t+1],r=ol(e[t+1],e[t+2]);return[{},n?null:Qs.instance(r),t+3]}function eu(e,t){return[{},e[t]?Ts.create(e[t]):null,t+1]}var tu=RegExp(`^T?${zl.source}$`),nu=/^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;function ru(e){let[t,n,r,i,a,o,s,c,l]=e,u=t[0]===`-`,d=c&&c[0]===`-`,f=(e,t=!1)=>e!==void 0&&(t||e&&u)?-e:e;return[{years:f(Yc(n)),months:f(Yc(r)),weeks:f(Yc(i)),days:f(Yc(a)),hours:f(Yc(o)),minutes:f(Yc(s)),seconds:f(Yc(c),c===`-0`),milliseconds:f(Xc(l),d)}]}var iu={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function au(e,t,n,r,i,a,o){let s={year:t.length===2?il(Jc(t)):Jc(t),month:fl.indexOf(n)+1,day:Jc(r),hour:Jc(i),minute:Jc(a)};return o&&(s.second=Jc(o)),e&&(s.weekday=e.length>3?hl.indexOf(e)+1:gl.indexOf(e)+1),s}var ou=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;function su(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=au(t,i,r,n,a,o,s),p;return p=c?iu[c]:l?0:ol(u,d),[f,new Qs(p)]}function cu(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var lu=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,uu=/^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,du=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;function fu(e){let[,t,n,r,i,a,o,s]=e;return[au(t,i,r,n,a,o,s),Qs.utcInstance]}function pu(e){let[,t,n,r,i,a,o,s]=e;return[au(t,s,n,r,i,a,o),Qs.utcInstance]}var mu=Nl(Hl,Vl),hu=Nl(Ul,Vl),gu=Nl(Wl,Vl),_u=Nl(Bl),vu=Pl(Zl,Ql,$l,eu),yu=Pl(Gl,Ql,$l,eu),bu=Pl(Kl,Ql,$l,eu),xu=Pl(Ql,$l,eu);function Su(e){return Fl(e,[mu,vu],[hu,yu],[gu,bu],[_u,xu])}function Cu(e){return Fl(cu(e),[ou,su])}function wu(e){return Fl(e,[lu,fu],[uu,fu],[du,pu])}function Tu(e){return Fl(e,[nu,ru])}var Eu=Pl(Ql);function Du(e){return Fl(e,[tu,Eu])}var Ou=Nl(ql,Yl),ku=Nl(Jl),Au=Pl(Ql,$l,eu);function ju(e){return Fl(e,[Ou,vu],[ku,Au])}var Mu=`Invalid Duration`,Nu={weeks:{days:7,hours:168,minutes:10080,seconds:10080*60,milliseconds:10080*60*1e3},days:{hours:24,minutes:1440,seconds:1440*60,milliseconds:1440*60*1e3},hours:{minutes:60,seconds:3600,milliseconds:3600*1e3},minutes:{seconds:60,milliseconds:60*1e3},seconds:{milliseconds:1e3}},Pu={years:{quarters:4,months:12,weeks:52,days:365,hours:365*24,minutes:365*24*60,seconds:365*24*60*60,milliseconds:365*24*60*60*1e3},quarters:{months:3,weeks:13,days:91,hours:2184,minutes:2184*60,seconds:2184*60*60,milliseconds:2184*60*60*1e3},months:{weeks:4,days:30,hours:720,minutes:720*60,seconds:720*60*60,milliseconds:720*60*60*1e3},...Nu},Fu=146097/400,Iu=146097/4800,Lu={years:{quarters:4,months:12,weeks:Fu/7,days:Fu,hours:Fu*24,minutes:Fu*24*60,seconds:Fu*24*60*60,milliseconds:Fu*24*60*60*1e3},quarters:{months:3,weeks:Fu/28,days:Fu/4,hours:Fu*24/4,minutes:Fu*24*60/4,seconds:Fu*24*60*60/4,milliseconds:Fu*24*60*60*1e3/4},months:{weeks:Iu/7,days:Iu,hours:Iu*24,minutes:Iu*24*60,seconds:Iu*24*60*60,milliseconds:Iu*24*60*60*1e3},...Nu},Ru=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],zu=Ru.slice(0).reverse();function Bu(e,t,n=!1){return new Wu({values:n?t.values:{...e.values,...t.values||{}},loc:e.loc.clone(t.loc),conversionAccuracy:t.conversionAccuracy||e.conversionAccuracy,matrix:t.matrix||e.matrix})}function Vu(e,t){let n=t.milliseconds??0;for(let r of zu.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Hu(e,t){let n=Vu(e,t)<0?-1:1;Ru.reduceRight((r,i)=>{if(x(t[i]))return r;if(r){let a=t[r]*n,o=e[i][r],s=Math.floor(a/o);t[i]+=s*n,t[r]-=s*o*n}return i},null),Ru.reduce((n,r)=>{if(x(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Uu(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Wu=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Lu:Pu;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||Xs.create(),this.conversionAccuracy=t?`longterm`:`casual`,this.invalid=e.invalid||null,this.matrix=n,this.isLuxonDuration=!0}static fromMillis(t,n){return e.fromObject({milliseconds:t},n)}static fromObject(t,n={}){if(typeof t!=`object`||!t)throw new Wo(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:cl(t,e.normalizeUnit),loc:Xs.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Pc(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Wo(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=Tu(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static fromISOTime(t,n){let[r]=Du(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static invalid(t,n=null){if(!t)throw new Wo(`need to specify a reason the Duration is invalid`);let r=t instanceof _c?t:new _c(t,n);if(gc.throwOnInvalid)throw new Vo(r);return new e({invalid:r})}static normalizeUnit(e){let t={year:`years`,years:`years`,quarter:`quarters`,quarters:`quarters`,month:`months`,months:`months`,week:`weeks`,weeks:`weeks`,day:`days`,days:`days`,hour:`hours`,hours:`hours`,minute:`minutes`,minutes:`minutes`,second:`seconds`,seconds:`seconds`,millisecond:`milliseconds`,milliseconds:`milliseconds`}[e&&e.toLowerCase()];if(!t)throw new Uo(e);return t}static isDuration(e){return e&&e.isLuxonDuration||!1}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}toFormat(e,t={}){let n={...t,floor:t.round!==!1&&t.floor!==!1};return this.isValid?jl.create(this.loc,n).formatDurationFromString(this,e):Mu}toHuman(e={}){if(!this.isValid)return Mu;let t=e.showZeros!==!1,n=Ru.map(n=>{let r=this.values[n];return x(r)||r===0&&!t?null:this.loc.numberFormatter({style:`unit`,unitDisplay:`long`,...e,unit:n.slice(0,-1)}).format(r)}).filter(e=>e);return this.loc.listFormatter({type:`conjunction`,style:e.listStyle||`narrow`,...e}).format(n)}toObject(){return this.isValid?{...this.values}:{}}toISO(){if(!this.isValid)return null;let e=`P`;return this.years!==0&&(e+=this.years+`Y`),(this.months!==0||this.quarters!==0)&&(e+=this.months+this.quarters*3+`M`),this.weeks!==0&&(e+=this.weeks+`W`),this.days!==0&&(e+=this.days+`D`),(this.hours!==0||this.minutes!==0||this.seconds!==0||this.milliseconds!==0)&&(e+=`T`),this.hours!==0&&(e+=this.hours+`H`),this.minutes!==0&&(e+=this.minutes+`M`),(this.seconds!==0||this.milliseconds!==0)&&(e+=Zc(this.seconds+this.milliseconds/1e3,3)+`S`),e===`P`&&(e+=`T0S`),e}toISOTime(e={}){if(!this.isValid)return null;let t=this.toMillis();return t<0||t>=864e5?null:(e={suppressMilliseconds:!1,suppressSeconds:!1,includePrefix:!1,format:`extended`,...e,includeOffset:!1},Yd.fromMillis(t,{zone:`UTC`}).toISOTime(e))}toJSON(){return this.toISO()}toString(){return this.toISO()}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Duration { values: ${JSON.stringify(this.values)} }`:`Duration { Invalid, reason: ${this.invalidReason} }`}toMillis(){return this.isValid?Vu(this.matrix,this.values):NaN}valueOf(){return this.toMillis()}plus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t),r={};for(let e of Ru)(Uc(n.values,e)||Uc(this.values,e))&&(r[e]=n.get(e)+this.get(e));return Bu(this,{values:r},!0)}minus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t);return this.plus(n.negate())}mapUnits(e){if(!this.isValid)return this;let t={};for(let n of Object.keys(this.values))t[n]=sl(e(this.values[n],n));return Bu(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...cl(t,e.normalizeUnit)};return Bu(this,{values:n})}reconfigure({locale:e,numberingSystem:t,conversionAccuracy:n,matrix:r}={}){let i={loc:this.loc.clone({locale:e,numberingSystem:t}),matrix:r,conversionAccuracy:n};return Bu(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Hu(this.matrix,e),Bu(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Uu(this.normalize().shiftToAll().toObject());return Bu(this,{values:e},!0)}shiftTo(...t){if(!this.isValid||t.length===0)return this;t=t.map(t=>e.normalizeUnit(t));let n={},r={},i=this.toObject(),a;for(let e of Ru)if(t.indexOf(e)>=0){a=e;let t=0;for(let n in r)t+=this.matrix[n][e]*r[n],r[n]=0;Pc(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Pc(i[e])&&(r[e]=i[e]);for(let e in r)r[e]!==0&&(n[a]+=e===a?r[e]:r[e]/this.matrix[a][e]);return Hu(this.matrix,n),Bu(this,{values:n},!0)}shiftToAll(){return this.isValid?this.shiftTo(`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`):this}negate(){if(!this.isValid)return this;let e={};for(let t of Object.keys(this.values))e[t]=this.values[t]===0?0:-this.values[t];return Bu(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Uu(this.values);return Bu(this,{values:e},!0)}get years(){return this.isValid?this.values.years||0:NaN}get quarters(){return this.isValid?this.values.quarters||0:NaN}get months(){return this.isValid?this.values.months||0:NaN}get weeks(){return this.isValid?this.values.weeks||0:NaN}get days(){return this.isValid?this.values.days||0:NaN}get hours(){return this.isValid?this.values.hours||0:NaN}get minutes(){return this.isValid?this.values.minutes||0:NaN}get seconds(){return this.isValid?this.values.seconds||0:NaN}get milliseconds(){return this.isValid?this.values.milliseconds||0:NaN}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}equals(e){if(!this.isValid||!e.isValid||!this.loc.equals(e.loc))return!1;function t(e,t){return e===void 0||e===0?t===void 0||t===0:e===t}for(let n of Ru)if(!t(this.values[n],e.values[n]))return!1;return!0}},Gu=`Invalid Interval`;function Ku(e,t){return!e||!e.isValid?qu.invalid(`missing or invalid start`):!t||!t.isValid?qu.invalid(`missing or invalid end`):t<e?qu.invalid(`end before start`,`The end of an interval must be after its start, but you had start=${e.toISO()} and end=${t.toISO()}`):null}var qu=class e{constructor(e){this.s=e.start,this.e=e.end,this.invalid=e.invalid||null,this.isLuxonInterval=!0}static invalid(t,n=null){if(!t)throw new Wo(`need to specify a reason the Interval is invalid`);let r=t instanceof _c?t:new _c(t,n);if(gc.throwOnInvalid)throw new Bo(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=Xd(t),i=Xd(n);return Ku(r,i)??new e({start:r,end:i})}static after(t,n){let r=Wu.fromDurationLike(n),i=Xd(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Wu.fromDurationLike(n),i=Xd(t);return e.fromDateTimes(i.minus(r),i)}static fromISO(t,n){let[r,i]=(t||``).split(`/`,2);if(r&&i){let t,a;try{t=Yd.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=Yd.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Wu.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Wu.fromISO(r,n);if(t.isValid)return e.before(o,t)}}return e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static isInterval(e){return e&&e.isLuxonInterval||!1}get start(){return this.isValid?this.s:null}get end(){return this.isValid?this.e:null}get lastDateTime(){return this.isValid&&this.e?this.e.minus(1):null}get isValid(){return this.invalidReason===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}length(e=`milliseconds`){return this.isValid?this.toDuration(e).get(e):NaN}count(e=`milliseconds`,t){if(!this.isValid)return NaN;let n=this.start.startOf(e,t),r;return r=t?.useLocaleWeeks?this.end.reconfigure({locale:n.locale}):this.end,r=r.startOf(e,t),Math.floor(r.diff(n,e).get(e))+(r.valueOf()!==this.end.valueOf())}hasSame(e){return this.isValid?this.isEmpty()||this.e.minus(1).hasSame(this.s,e):!1}isEmpty(){return this.s.valueOf()===this.e.valueOf()}isAfter(e){return this.isValid?this.s>e:!1}isBefore(e){return this.isValid?this.e<=e:!1}contains(e){return this.isValid?this.s<=e&&this.e>e:!1}set({start:t,end:n}={}){return this.isValid?e.fromDateTimes(t||this.s,n||this.e):this}splitAt(...t){if(!this.isValid)return[];let n=t.map(Xd).filter(e=>this.contains(e)).sort((e,t)=>e.toMillis()-t.toMillis()),r=[],{s:i}=this,a=0;for(;i<this.e;){let t=n[a]||this.e,o=+t>+this.e?this.e:t;r.push(e.fromDateTimes(i,o)),i=o,a+=1}return r}splitBy(t){let n=Wu.fromDurationLike(t);if(!this.isValid||!n.isValid||n.as(`milliseconds`)===0)return[];let{s:r}=this,i=1,a,o=[];for(;r<this.e;){let t=this.start.plus(n.mapUnits(e=>e*i));a=+t>+this.e?this.e:t,o.push(e.fromDateTimes(r,a)),r=a,i+=1}return o}divideEqually(e){return this.isValid?this.splitBy(this.length()/e).slice(0,e):[]}overlaps(e){return this.e>e.s&&this.s<e.e}abutsStart(e){return this.isValid?+this.e==+e.s:!1}abutsEnd(e){return this.isValid?+e.e==+this.s:!1}engulfs(e){return this.isValid?this.s<=e.s&&this.e>=e.e:!1}equals(e){return!this.isValid||!e.isValid?!1:this.s.equals(e.s)&&this.e.equals(e.e)}intersection(t){if(!this.isValid)return this;let n=this.s>t.s?this.s:t.s,r=this.e<t.e?this.e:t.e;return n>=r?null:e.fromDateTimes(n,r)}union(t){if(!this.isValid)return this;let n=this.s<t.s?this.s:t.s,r=this.e>t.e?this.e:t.e;return e.fromDateTimes(n,r)}static merge(e){let[t,n]=e.sort((e,t)=>e.s-t.s).reduce(([e,t],n)=>t?t.overlaps(n)||t.abutsStart(n)?[e,t.union(n)]:[e.concat([t]),n]:[e,n],[[],null]);return n&&t.push(n),t}static xor(t){let n=null,r=0,i=[],a=t.map(e=>[{time:e.s,type:`s`},{time:e.e,type:`e`}]),o=Array.prototype.concat(...a).sort((e,t)=>e.time-t.time);for(let t of o)r+=t.type===`s`?1:-1,r===1?n=t.time:(n&&+n!=+t.time&&i.push(e.fromDateTimes(n,t.time)),n=null);return e.merge(i)}difference(...t){return e.xor([this].concat(t)).map(e=>this.intersection(e)).filter(e=>e&&!e.isEmpty())}toString(){return this.isValid?`[${this.s.toISO()} – ${this.e.toISO()})`:Gu}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`:`Interval { Invalid, reason: ${this.invalidReason} }`}toLocaleString(e=Jo,t={}){return this.isValid?jl.create(this.s.loc.clone(t),e).formatInterval(this):Gu}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Gu}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Gu}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Gu}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Gu}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Wu.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Ju=class{static hasDST(e=gc.defaultZone){let t=Yd.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return Ts.isValidZone(e)}static normalizeZone(e){return ec(e,gc.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||Xs.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||Xs.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||Xs.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||Xs.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||Xs.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||Xs.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||Xs.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return Xs.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return Xs.create(t,null,`gregory`).eras(e)}static features(){return{relative:Rc(),localeWeek:zc()}}};function Yu(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Wu.fromMillis(r).as(`days`))}function Xu(e,t,n){let r=[[`years`,(e,t)=>t.year-e.year],[`quarters`,(e,t)=>t.quarter-e.quarter+(t.year-e.year)*4],[`months`,(e,t)=>t.month-e.month+(t.year-e.year)*12],[`weeks`,(e,t)=>{let n=Yu(e,t);return(n-n%7)/7}],[`days`,Yu]],i={},a=e,o,s;for(let[c,l]of r)n.indexOf(c)>=0&&(o=c,i[c]=l(e,t),s=a.plus(i),s>t?(i[c]--,e=a.plus(i),e>t&&(s=e,i[c]--,e=a.plus(i))):e=s);return[e,i,s,o]}function Zu(e,t,n,r){let[i,a,o,s]=Xu(e,t,n),c=t-i,l=n.filter(e=>[`hours`,`minutes`,`seconds`,`milliseconds`].indexOf(e)>=0);l.length===0&&(o<t&&(o=i.plus({[s]:1})),o!==i&&(a[s]=(a[s]||0)+c/(o-i)));let u=Wu.fromObject(a,r);return l.length>0?Wu.fromMillis(c,r).shiftTo(...l).plus(u):u}var Qu=`missing Intl.DateTimeFormat.formatToParts support`;function S(e,t=e=>e){return{regex:e,deser:([e])=>t(ic(e))}}var $u=`[ \xA0]`,ed=new RegExp($u,`g`);function td(e){return e.replace(/\./g,`\\.?`).replace(ed,$u)}function nd(e){return e.replace(/\./g,``).replace(ed,` `).toLowerCase()}function rd(e,t){return e===null?null:{regex:RegExp(e.map(td).join(`|`)),deser:([n])=>e.findIndex(e=>nd(n)===nd(e))+t}}function id(e,t){return{regex:e,deser:([,e,t])=>ol(e,t),groups:t}}function ad(e){return{regex:e,deser:([e])=>e}}function od(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function sd(e,t){let n=sc(t),r=sc(t,`{2}`),i=sc(t,`{3}`),a=sc(t,`{4}`),o=sc(t,`{6}`),s=sc(t,`{1,2}`),c=sc(t,`{1,3}`),l=sc(t,`{1,6}`),u=sc(t,`{1,9}`),d=sc(t,`{2,4}`),f=sc(t,`{4,6}`),p=e=>({regex:RegExp(od(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return rd(t.eras(`short`),0);case`GG`:return rd(t.eras(`long`),0);case`y`:return S(l);case`yy`:return S(d,il);case`yyyy`:return S(a);case`yyyyy`:return S(f);case`yyyyyy`:return S(o);case`M`:return S(s);case`MM`:return S(r);case`MMM`:return rd(t.months(`short`,!0),1);case`MMMM`:return rd(t.months(`long`,!0),1);case`L`:return S(s);case`LL`:return S(r);case`LLL`:return rd(t.months(`short`,!1),1);case`LLLL`:return rd(t.months(`long`,!1),1);case`d`:return S(s);case`dd`:return S(r);case`o`:return S(c);case`ooo`:return S(i);case`HH`:return S(r);case`H`:return S(s);case`hh`:return S(r);case`h`:return S(s);case`mm`:return S(r);case`m`:return S(s);case`q`:return S(s);case`qq`:return S(r);case`s`:return S(s);case`ss`:return S(r);case`S`:return S(c);case`SSS`:return S(i);case`u`:return ad(u);case`uu`:return ad(s);case`uuu`:return S(n);case`a`:return rd(t.meridiems(),0);case`kkkk`:return S(a);case`kk`:return S(d,il);case`W`:return S(s);case`WW`:return S(r);case`E`:case`c`:return S(n);case`EEE`:return rd(t.weekdays(`short`,!1),1);case`EEEE`:return rd(t.weekdays(`long`,!1),1);case`ccc`:return rd(t.weekdays(`short`,!0),1);case`cccc`:return rd(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return id(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return id(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return ad(/[a-z_+-/]{1,256}?/i);case` `:return ad(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:Qu};return m.token=e,m}var cd={year:{"2-digit":`yy`,numeric:`yyyyy`},month:{numeric:`M`,"2-digit":`MM`,short:`MMM`,long:`MMMM`},day:{numeric:`d`,"2-digit":`dd`},weekday:{short:`EEE`,long:`EEEE`},dayperiod:`a`,dayPeriod:`a`,hour12:{numeric:`h`,"2-digit":`hh`},hour24:{numeric:`H`,"2-digit":`HH`},minute:{numeric:`m`,"2-digit":`mm`},second:{numeric:`s`,"2-digit":`ss`},timeZoneName:{long:`ZZZZZ`,short:`ZZZ`}};function ld(e,t,n){let{type:r,value:i}=e;if(r===`literal`){let e=/^\s+$/.test(i);return{literal:!e,val:e?` `:i}}let a=t[r],o=r;r===`hour`&&(o=t.hour12==null?t.hourCycle==null?n.hour12?`hour12`:`hour24`:t.hourCycle===`h11`||t.hourCycle===`h12`?`hour12`:`hour24`:t.hour12?`hour12`:`hour24`);let s=cd[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function ud(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function dd(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Uc(n,i)){let a=n[i],o=a.groups?a.groups+1:1;!a.literal&&a.token&&(e[a.token.val[0]]=a.deser(r.slice(t,t+o))),t+=o}return[r,e]}else return[r,{}]}function fd(e){let t=e=>{switch(e){case`S`:return`millisecond`;case`s`:return`second`;case`m`:return`minute`;case`h`:case`H`:return`hour`;case`d`:return`day`;case`o`:return`ordinal`;case`L`:case`M`:return`month`;case`y`:return`year`;case`E`:case`c`:return`weekday`;case`W`:return`weekNumber`;case`k`:return`weekYear`;case`q`:return`quarter`;default:return null}},n=null,r;return x(e.z)||(n=Ts.create(e.z)),x(e.Z)||(n||=new Qs(e.Z),r=e.Z),x(e.q)||(e.M=(e.q-1)*3+1),x(e.h)||(e.h<12&&e.a===1?e.h+=12:e.h===12&&e.a===0&&(e.h=0)),e.G===0&&e.y&&(e.y=-e.y),x(e.u)||(e.S=Xc(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var pd=null;function md(){return pd||=Yd.fromMillis(1555555555555),pd}function hd(e,t){if(e.literal)return e;let n=bd(jl.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function gd(e,t){return Array.prototype.concat(...e.map(e=>hd(e,t)))}var _d=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=gd(jl.parseFormat(t),e),this.units=this.tokens.map(t=>sd(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=ud(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=dd(e,this.regex,this.handlers),[r,i,a]=n?fd(n):[null,null,void 0];if(Uc(n,`a`)&&Uc(n,`H`))throw new Ho(`Can't include meridiem when specifying 24-hour format`);return{input:e,tokens:this.tokens,regex:this.regex,rawMatches:t,matches:n,result:r,zone:i,specificOffset:a}}else return{input:e,tokens:this.tokens,invalidReason:this.invalidReason}}get isValid(){return!this.disqualifyingUnit}get invalidReason(){return this.disqualifyingUnit?this.disqualifyingUnit.invalidReason:null}};function vd(e,t,n){return new _d(e,n).explainFromTokens(t)}function yd(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=vd(e,t,n);return[r,i,a,o]}function bd(e,t){if(!e)return null;let n=jl.create(t,e).dtFormatter(md()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>ld(t,e,i))}var xd=`Invalid DateTime`,Sd=864e13;function Cd(e){return new _c(`unsupported zone`,`the zone "${e.name}" is not supported`)}function wd(e){return e.weekData===null&&(e.weekData=Tc(e.c)),e.weekData}function Td(e){return e.localWeekData===null&&(e.localWeekData=Tc(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function Ed(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new Yd({...n,...t,old:n})}function Dd(e,t,n){let r=e-t*60*1e3,i=n.offset(r);if(t===i)return[r,t];r-=(i-t)*60*1e3;let a=n.offset(r);return i===a?[r,i]:[e-Math.min(i,a)*60*1e3,Math.max(i,a)]}function Od(e,t){e+=t*60*1e3;let n=new Date(e);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),millisecond:n.getUTCMilliseconds()}}function kd(e,t,n){return Dd(tl(e),t,n)}function Ad(e,t){let n=e.o,r=e.c.year+Math.trunc(t.years),i=e.c.month+Math.trunc(t.months)+Math.trunc(t.quarters)*3,a={...e.c,year:r,month:i,day:Math.min(e.c.day,el(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Wu.fromObject({years:t.years-Math.trunc(t.years),quarters:t.quarters-Math.trunc(t.quarters),months:t.months-Math.trunc(t.months),weeks:t.weeks-Math.trunc(t.weeks),days:t.days-Math.trunc(t.days),hours:t.hours,minutes:t.minutes,seconds:t.seconds,milliseconds:t.milliseconds}).as(`milliseconds`),[s,c]=Dd(tl(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function jd(e,t,n,r,i,a){let{setZone:o,zone:s}=n;if(e&&Object.keys(e).length!==0||t){let r=t||s,i=Yd.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return Yd.invalid(new _c(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function Md(e,t,n=!0){return e.isValid?jl.create(Xs.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function Nd(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=qc(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=qc(e.c.month),n===`month`)return i;i+=`-`}else if(i+=qc(e.c.month),n===`month`)return i;return i+=qc(e.c.day),i}function Pd(e,t,n,r,i,a,o){let s=!n||e.c.millisecond!==0||e.c.second!==0,c=``;switch(o){case`day`:case`month`:case`year`:break;default:if(c+=qc(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=qc(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=qc(e.c.second))}else{if(c+=qc(e.c.minute),o===`minute`)break;s&&(c+=qc(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=qc(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=qc(Math.trunc(-e.o/60)),c+=`:`,c+=qc(Math.trunc(-e.o%60))):(c+=`+`,c+=qc(Math.trunc(e.o/60)),c+=`:`,c+=qc(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Fd={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Id={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Ld={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Rd=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],zd=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],Bd=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function Vd(e){let t={year:`year`,years:`year`,month:`month`,months:`month`,day:`day`,days:`day`,hour:`hour`,hours:`hour`,minute:`minute`,minutes:`minute`,quarter:`quarter`,quarters:`quarter`,second:`second`,seconds:`second`,millisecond:`millisecond`,milliseconds:`millisecond`,weekday:`weekday`,weekdays:`weekday`,weeknumber:`weekNumber`,weeksnumber:`weekNumber`,weeknumbers:`weekNumber`,weekyear:`weekYear`,weekyears:`weekYear`,ordinal:`ordinal`}[e.toLowerCase()];if(!t)throw new Uo(e);return t}function Hd(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return Vd(e)}}function Ud(e){if(qd===void 0&&(qd=gc.now()),e.type!==`iana`)return e.offset(qd);let t=e.name,n=Jd.get(t);return n===void 0&&(n=e.offset(qd),Jd.set(t,n)),n}function Wd(e,t){let n=ec(t.zone,gc.defaultZone);if(!n.isValid)return Yd.invalid(Cd(n));let r=Xs.fromObject(t),i,a;if(x(e.year))i=gc.now();else{for(let t of Rd)x(e[t])&&(e[t]=Fd[t]);let t=Mc(e)||Nc(e);if(t)return Yd.invalid(t);let r=Ud(n);[i,a]=kd(e,r,n)}return new Yd({ts:i,zone:n,loc:r,o:a})}function Gd(e,t,n){let r=x(n.round)?!0:n.round,i=x(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Zc(e,r||n.calendary?0:2,n.calendary?`round`:i),t.loc.clone(n).relFormatter(n).format(e,a)),o=r=>n.calendary?t.hasSame(e,r)?0:t.startOf(r).diff(e.startOf(r),r).get(r):t.diff(e,r).get(r);if(n.unit)return a(o(n.unit),n.unit);for(let e of n.units){let t=o(e);if(Math.abs(t)>=1)return a(t,e)}return a(e>t?-0:0,n.units[n.units.length-1])}function Kd(e){let t={},n;return e.length>0&&typeof e[e.length-1]==`object`?(t=e[e.length-1],n=Array.from(e).slice(0,e.length-1)):n=Array.from(e),[t,n]}var qd,Jd=new Map,Yd=class e{constructor(e){let t=e.zone||gc.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new _c(`invalid input`):null)||(t.isValid?null:Cd(t));this.ts=x(e.ts)?gc.now():e.ts;let r=null,i=null;if(!n)if(e.old&&e.old.ts===this.ts&&e.old.zone.equals(t))[r,i]=[e.old.c,e.old.o];else{let a=Pc(e.o)&&!e.old?e.o:t.offset(this.ts);r=Od(this.ts,a),n=Number.isNaN(r.year)?new _c(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||Xs.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=Kd(arguments),[n,r,i,a,o,s,c]=t;return Wd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=Kd(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Qs.utcInstance,Wd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Lc(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=ec(n.zone,gc.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:Xs.fromObject(n)}):e.invalid(Cd(i))}static fromMillis(t,n={}){if(!Pc(t))throw new Wo(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>Sd?e.invalid(`Timestamp out of range`):new e({ts:t,zone:ec(n.zone,gc.defaultZone),loc:Xs.fromObject(n)})}static fromSeconds(t,n={}){if(Pc(t))return new e({ts:t*1e3,zone:ec(n.zone,gc.defaultZone),loc:Xs.fromObject(n)});throw new Wo(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=ec(n.zone,gc.defaultZone);if(!r.isValid)return e.invalid(Cd(r));let i=Xs.fromObject(n),a=cl(t,Hd),{minDaysInFirstWeek:o,startOfWeek:s}=kc(a,i),c=gc.now(),l=x(n.specificOffset)?r.offset(c):n.specificOffset,u=!x(a.ordinal),d=!x(a.year),f=!x(a.month)||!x(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new Ho(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Ho(`Can't mix ordinal dates with month/day`);let h=m||a.weekday&&!p,ee,te,ne=Od(c,l);h?(ee=zd,te=Id,ne=Tc(ne,o,s)):u?(ee=Bd,te=Ld,ne=Dc(ne)):(ee=Rd,te=Fd);let re=!1;for(let e of ee){let t=a[e];x(t)?re?a[e]=te[e]:a[e]=ne[e]:re=!0}let ie=(h?Ac(a,o,s):u?jc(a):Mc(a))||Nc(a);if(ie)return e.invalid(ie);let[ae,oe]=kd(h?Ec(a,o,s):u?Oc(a):a,l,r),se=new e({ts:ae,zone:r,o:oe,loc:i});return a.weekday&&p&&t.weekday!==se.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${se.toISO()}`):se.isValid?se:e.invalid(se.invalid)}static fromISO(e,t={}){let[n,r]=Su(e);return jd(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=Cu(e);return jd(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=wu(e);return jd(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(x(t)||x(n))throw new Wo(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=yd(Xs.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):jd(o,s,r,`format ${n}`,t,c)}static fromString(t,n,r={}){return e.fromFormat(t,n,r)}static fromSQL(e,t={}){let[n,r]=ju(e);return jd(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Wo(`need to specify a reason the DateTime is invalid`);let r=t instanceof _c?t:new _c(t,n);if(gc.throwOnInvalid)throw new zo(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=bd(e,Xs.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return gd(jl.parseFormat(e),Xs.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){qd=void 0,Jd.clear()}get(e){return this[e]}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}get outputCalendar(){return this.isValid?this.loc.outputCalendar:null}get zone(){return this._zone}get zoneName(){return this.isValid?this.zone.name:null}get year(){return this.isValid?this.c.year:NaN}get quarter(){return this.isValid?Math.ceil(this.c.month/3):NaN}get month(){return this.isValid?this.c.month:NaN}get day(){return this.isValid?this.c.day:NaN}get hour(){return this.isValid?this.c.hour:NaN}get minute(){return this.isValid?this.c.minute:NaN}get second(){return this.isValid?this.c.second:NaN}get millisecond(){return this.isValid?this.c.millisecond:NaN}get weekYear(){return this.isValid?wd(this).weekYear:NaN}get weekNumber(){return this.isValid?wd(this).weekNumber:NaN}get weekday(){return this.isValid?wd(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?Td(this).weekday:NaN}get localWeekNumber(){return this.isValid?Td(this).weekNumber:NaN}get localWeekYear(){return this.isValid?Td(this).weekYear:NaN}get ordinal(){return this.isValid?Dc(this.c).ordinal:NaN}get monthShort(){return this.isValid?Ju.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Ju.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Ju.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Ju.weekdays(`long`,{locObj:this.loc})[this.weekday-1]:null}get offset(){return this.isValid?+this.o:NaN}get offsetNameShort(){return this.isValid?this.zone.offsetName(this.ts,{format:`short`,locale:this.locale}):null}get offsetNameLong(){return this.isValid?this.zone.offsetName(this.ts,{format:`long`,locale:this.locale}):null}get isOffsetFixed(){return this.isValid?this.zone.isUniversal:null}get isInDST(){return this.isOffsetFixed?!1:this.offset>this.set({month:1,day:1}).offset||this.offset>this.set({month:5}).offset}getPossibleOffsets(){if(!this.isValid||this.isOffsetFixed)return[this];let e=864e5,t=6e4,n=tl(this.c),r=this.zone.offset(n-e),i=this.zone.offset(n+e),a=this.zone.offset(n-r*t),o=this.zone.offset(n-i*t);if(a===o)return[this];let s=n-a*t,c=n-o*t,l=Od(s,a),u=Od(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[Ed(this,{ts:s}),Ed(this,{ts:c})]:[this]}get isInLeapYear(){return Qc(this.year)}get daysInMonth(){return el(this.year,this.month)}get daysInYear(){return this.isValid?$c(this.year):NaN}get weeksInWeekYear(){return this.isValid?rl(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?rl(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=jl.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Qs.instance(e),t)}toLocal(){return this.setZone(gc.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=ec(t,gc.defaultZone),t.equals(this.zone))return this;if(t.isValid){let e=this.ts;if(n||r){let n=t.offset(this.ts),r=this.toObject();[e]=kd(r,n,t)}return Ed(this,{ts:e,zone:t})}else return e.invalid(Cd(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return Ed(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=cl(e,Hd),{minDaysInFirstWeek:n,startOfWeek:r}=kc(t,this.loc),i=!x(t.weekYear)||!x(t.weekNumber)||!x(t.weekday),a=!x(t.ordinal),o=!x(t.year),s=!x(t.month)||!x(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new Ho(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Ho(`Can't mix ordinal dates with month/day`);let u;i?u=Ec({...Tc(this.c,n,r),...t},n,r):x(t.ordinal)?(u={...this.toObject(),...t},x(t.day)&&(u.day=Math.min(el(u.year,u.month),u.day))):u=Oc({...Dc(this.c),...t});let[d,f]=kd(u,this.o,this.zone);return Ed(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Wu.fromDurationLike(e);return Ed(this,Ad(this,t))}minus(e){if(!this.isValid)return this;let t=Wu.fromDurationLike(e).negate();return Ed(this,Ad(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Wu.normalizeUnit(e);switch(r){case`years`:n.month=1;case`quarters`:case`months`:n.day=1;case`weeks`:case`days`:n.hour=0;case`hours`:n.minute=0;case`minutes`:n.second=0;case`seconds`:n.millisecond=0;break}if(r===`weeks`)if(t){let e=this.loc.getStartOfWeek(),{weekday:t}=this;t<e&&(n.weekNumber=this.weekNumber-1),n.weekday=e}else n.weekday=1;return r===`quarters`&&(n.month=(Math.ceil(this.month/3)-1)*3+1),this.set(n)}endOf(e,t){return this.isValid?this.plus({[e]:1}).startOf(e,t).minus(1):this}toFormat(e,t={}){return this.isValid?jl.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):xd}toLocaleString(e=Jo,t={}){return this.isValid?jl.create(this.loc.clone(t),e).formatDateTime(this):xd}toLocaleParts(e={}){return this.isValid?jl.create(this.loc.clone(e),e).formatDateTimeParts(this):[]}toISO({format:e=`extended`,suppressSeconds:t=!1,suppressMilliseconds:n=!1,includeOffset:r=!0,extendedZone:i=!1,precision:a=`milliseconds`}={}){if(!this.isValid)return null;a=Vd(a);let o=e===`extended`,s=Nd(this,o,a);return Rd.indexOf(a)>=3&&(s+=`T`),s+=Pd(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?Nd(this,e===`extended`,Vd(t)):null}toISOWeekDate(){return Md(this,`kkkk-'W'WW-c`)}toISOTime({suppressMilliseconds:e=!1,suppressSeconds:t=!1,includeOffset:n=!0,includePrefix:r=!1,extendedZone:i=!1,format:a=`extended`,precision:o=`milliseconds`}={}){return this.isValid?(o=Vd(o),(r&&Rd.indexOf(o)>=3?`T`:``)+Pd(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return Md(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return Md(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?Nd(this,!0):null}toSQLTime({includeOffset:e=!0,includeZone:t=!1,includeOffsetSpace:n=!0}={}){let r=`HH:mm:ss.SSS`;return(t||e)&&(n&&(r+=` `),t?r+=`z`:e&&(r+=`ZZ`)),Md(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():xd}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`:`DateTime { Invalid, reason: ${this.invalidReason} }`}valueOf(){return this.toMillis()}toMillis(){return this.isValid?this.ts:NaN}toSeconds(){return this.isValid?this.ts/1e3:NaN}toUnixInteger(){return this.isValid?Math.floor(this.ts/1e3):NaN}toJSON(){return this.toISO()}toBSON(){return this.toJSDate()}toObject(e={}){if(!this.isValid)return{};let t={...this.c};return e.includeConfig&&(t.outputCalendar=this.outputCalendar,t.numberingSystem=this.loc.numberingSystem,t.locale=this.loc.locale),t}toJSDate(){return new Date(this.isValid?this.ts:NaN)}diff(e,t=`milliseconds`,n={}){if(!this.isValid||!e.isValid)return Wu.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Bc(t).map(Wu.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Zu(a?this:e,a?e:this,i,r);return a?o.negate():o}diffNow(t=`milliseconds`,n={}){return this.diff(e.now(),t,n)}until(e){return this.isValid?qu.fromDateTimes(this,e):this}hasSame(e,t,n){if(!this.isValid)return!1;let r=e.valueOf(),i=this.setZone(e.zone,{keepLocalTime:!0});return i.startOf(t,n)<=r&&r<=i.endOf(t,n)}equals(e){return this.isValid&&e.isValid&&this.valueOf()===e.valueOf()&&this.zone.equals(e.zone)&&this.loc.equals(e.loc)}toRelative(t={}){if(!this.isValid)return null;let n=t.base||e.fromObject({},{zone:this.zone}),r=t.padding?this<n?-t.padding:t.padding:0,i=[`years`,`months`,`days`,`hours`,`minutes`,`seconds`],a=t.unit;return Array.isArray(t.unit)&&(i=t.unit,a=void 0),Gd(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?Gd(t.base||e.fromObject({},{zone:this.zone}),this,{...t,numeric:`auto`,units:[`years`,`months`,`days`],calendary:!0}):null}static min(...t){if(!t.every(e.isDateTime))throw new Wo(`min requires all arguments be DateTimes`);return Vc(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Wo(`max requires all arguments be DateTimes`);return Vc(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return vd(Xs.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new _d(Xs.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(x(t)||x(n))throw new Wo(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=Xs.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Wo(`fromFormatParser called with a locale of ${o}, but the format parser was created for ${n.locale}`);let{result:s,zone:c,specificOffset:l,invalidReason:u}=n.explainFromTokens(t);return u?e.invalid(u):jd(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Jo}static get DATE_MED(){return Yo}static get DATE_MED_WITH_WEEKDAY(){return Xo}static get DATE_FULL(){return Zo}static get DATE_HUGE(){return Qo}static get TIME_SIMPLE(){return $o}static get TIME_WITH_SECONDS(){return es}static get TIME_WITH_SHORT_OFFSET(){return ts}static get TIME_WITH_LONG_OFFSET(){return ns}static get TIME_24_SIMPLE(){return rs}static get TIME_24_WITH_SECONDS(){return is}static get TIME_24_WITH_SHORT_OFFSET(){return as}static get TIME_24_WITH_LONG_OFFSET(){return os}static get DATETIME_SHORT(){return ss}static get DATETIME_SHORT_WITH_SECONDS(){return cs}static get DATETIME_MED(){return ls}static get DATETIME_MED_WITH_SECONDS(){return us}static get DATETIME_MED_WITH_WEEKDAY(){return ds}static get DATETIME_FULL(){return fs}static get DATETIME_FULL_WITH_SECONDS(){return ps}static get DATETIME_HUGE(){return ms}static get DATETIME_HUGE_WITH_SECONDS(){return hs}};function Xd(e){if(Yd.isDateTime(e))return e;if(e&&e.valueOf&&Pc(e.valueOf()))return Yd.fromJSDate(e);if(e&&typeof e==`object`)return Yd.fromObject(e);throw new Wo(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function Zd(e){if(e===`*`)return{min:1,max:`*`};let[t,n]=e.split(`..`),r=Number(t);return n===void 0?{min:r,max:r}:{min:r,max:n===`*`?`*`:Number(n)}}var Qd=`1`,$d=`0..1`,ef=`*`,tf=`0..*`,nf=new Map([[`-`,[`1`,`1`]],[`<>`,[`*`,`*`]],[`>`,[`*`,`1`]],[`<`,[`1`,`*`]],[`-?`,[`1`,$d]],[`?-`,[$d,`1`]],[`?-?`,[$d,$d]],[`?>`,[tf,`1`]],[`>?`,[`*`,$d]],[`?>?`,[tf,$d]],[`?<`,[$d,`*`]],[`<?`,[`1`,tf]],[`?<?`,[$d,tf]],[`?<>`,[tf,`*`]],[`<>?`,[`*`,tf]],[`?<>?`,[tf,tf]]]),rf=new Map([...nf.entries()].map(([e,[t,n]])=>[`${t}-${n}`,e]));function af(e){return nf.get(e)}function of(e){return Zd(e).max===1}function sf(e){return Zd(e).max===`*`}function cf(e){return Zd(e).min===0}function lf(e){return Zd(e).min>=1}function uf(e){return e.replace(/\?/g,``)}function df(e,t){return rf.get(`${e}-${t}`)??`<>`}function ff(e){let{min:t,max:n}=Zd(e);return t===0?e:n===`*`?tf:$d}function pf(e){let{min:t,max:n}=Zd(e);return t>=1?e:n===`*`?`*`:`1`}function mf(e){let{min:t,max:n}=Zd(e);return n===`*`?e:t===0?tf:`*`}var C=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_DEP_CONTEXT=3042]=`INVALID_DEP_CONTEXT`,e[e.INVALID_DEP_FIELD=3043]=`INVALID_DEP_FIELD`,e[e.INVALID_NOTE_CONTEXT=3044]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3045]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3046]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3047]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3048]=`EMPTY_NOTE`,e[e.UNKNOWN_NOTE_SETTING=3049]=`UNKNOWN_NOTE_SETTING`,e[e.DUPLICATE_NOTE_SETTING=3050]=`DUPLICATE_NOTE_SETTING`,e[e.INVALID_NOTE_SETTING_VALUE=3051]=`INVALID_NOTE_SETTING_VALUE`,e[e.INVALID_INDEXES_CONTEXT=3052]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3053]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3054]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3055]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3056]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3057]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3058]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3059]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3060]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3061]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3062]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3063]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3064]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3065]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3066]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3067]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3069]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3070]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3071]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3072]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3073]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3074]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3075]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3076]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3077]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3078]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3079]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3080]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3081]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3082]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3083]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3084]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3085]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3086]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.UNKNOWN_RECORDS_SETTING=3087]=`UNKNOWN_RECORDS_SETTING`,e[e.DUPLICATE_RECORDS_SETTING=3088]=`DUPLICATE_RECORDS_SETTING`,e[e.INVALID_RECORDS_SETTING_VALUE=3089]=`INVALID_RECORDS_SETTING_VALUE`,e[e.INVALID_USE_CONTEXT=3090]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3091]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3092]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3093]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3094]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3095]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3096]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.DEP_SELF_LOOP=5003]=`DEP_SELF_LOOP`,e[e.DEP_MIXED_DOWNSTREAM_TABLES=5004]=`DEP_MIXED_DOWNSTREAM_TABLES`,e[e.DEP_DUPLICATE_DOWNSTREAM_TABLE=5005]=`DEP_DUPLICATE_DOWNSTREAM_TABLE`,e[e.DEP_MIXED_LEVEL=5006]=`DEP_MIXED_LEVEL`,e[e.UNEQUAL_FIELDS_BINARY_REF=5007]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5008]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5009]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e[e.INVALID_METADATA_TARGET_KIND=5010]=`INVALID_METADATA_TARGET_KIND`,e[e.INVALID_METADATA_FIELD=5011]=`INVALID_METADATA_FIELD`,e[e.DUPLICATE_METADATA_FIELD=5012]=`DUPLICATE_METADATA_FIELD`,e[e.UNKNOWN_KIND=6e3]=`UNKNOWN_KIND`,e[e.MISSING_NAME=6001]=`MISSING_NAME`,e[e.RESERVED_KIND=6002]=`RESERVED_KIND`,e[e.UNKNOWN_ENDPOINT=6003]=`UNKNOWN_ENDPOINT`,e[e.EMPTY_LINK=6004]=`EMPTY_LINK`,e[e.BAD_LINK=6005]=`BAD_LINK`,e[e.UNKNOWN_METADATA_TARGET=6006]=`UNKNOWN_METADATA_TARGET`,e[e.BAD_PROPERTY=6007]=`BAD_PROPERTY`,e[e.DUPLICATE_PROPERTY=6008]=`DUPLICATE_PROPERTY`,e[e.DIAGRAM_TYPE_NOT_HERE=6009]=`DIAGRAM_TYPE_NOT_HERE`,e[e.METADATA_KIND_MISMATCH=6010]=`METADATA_KIND_MISMATCH`,e[e.UNKNOWN_TYPE=6011]=`UNKNOWN_TYPE`,e[e.UNKNOWN_ICON=6012]=`UNKNOWN_ICON`,e[e.BAD_IMAGE=6013]=`BAD_IMAGE`,e[e.DUPLICATE_LINK=6014]=`DUPLICATE_LINK`,e[e.NESTED_ENDPOINTS=6015]=`NESTED_ENDPOINTS`,e}({}),hf=function(e){return e.RefColumnMismatch=`Mismatched optional ref constraints`,e.RecordValueTypeMismatch=`Record type errors`,e.RecordConstraintViolation=`Record constraint violations`,e.Other=`Other`,e}({}),w=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.details=i,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new gf(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},gf=class extends Error{constructor(e,t,n,r){super(t),this.code=e,this.diagnostic=t,this.details=r,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,w.prototype)}get filepath(){return this.nodeOrToken.filepath}},_f=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.details=i,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}get quickFixes(){return this.details?.quickFixes}get filepath(){return this.nodeOrToken.filepath}};function vf(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function yf(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function bf(e){let[t]=e;return yf(t)||vf(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function xf(e){return vf(e)||yf(e)}function Sf(e){let t=j(e);return t!==void 0&&t.length>0}function Cf(e){return wf(e)}function wf(e){return e instanceof km&&e.expression instanceof Om}function Tf(e){return!!e.bodyColon}function Ef(e){return e instanceof B&&e.op?.value===`~`&&D(e.expression)}function Df(e){return e!==void 0&&nf.has(e)}function Of(e){return e===`<-`||e===`->`}function kf(e){if(!(e instanceof km)||!(e.expression instanceof Em)||e.expression.literal?.kind!==v.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(!bf(t[e]))return!1;return!0}function Af(e){return kf(e)?!0:zf(e)&&e.expression.variable.value.toLowerCase()===`none`}function jf(e){if(E(e)||Mf(e)||zf(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof B&&yo.includes(e.op?.value)&&Mf(e.expression)||e instanceof xm)return!0;if(!e||!Bf(e))return!1;let t=ip(e);return t.length===2||t.length===3}function Mf(e){return e instanceof B?yo.includes(e.op.value)?Mf(e.expression):!1:e instanceof km&&e.expression instanceof Em&&e.expression.literal?.kind===v.NUMERIC_LITERAL}function Nf(e){if(!(e instanceof B)||!Df(e.op?.value))return!1;let t=j(e.expression);return t!==void 0&&t.length>0}function Pf(e){if(!(e instanceof B)||!Of(e.op?.value))return!1;let t=j(e.expression);return t!==void 0&&t.length>0}function Ff(e){return e instanceof Sm&&e.elementList.every(D)}function If(e){if(!(e instanceof Tm||O(e)||e instanceof km||e instanceof jm))return!1;for(;e instanceof Tm||e instanceof jm;)if(e instanceof Tm){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Mf(e)||E(e)||zf(e)))return!1;e=e.callee}else if(e instanceof jm){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Mf(e.name)))return!1;e=e.array}let t=j(e);return t!==void 0&&t.length>0}function Lf(e){return E(e)||kf(e)}function T(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof km){r.push(new w(C.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=ep(e.name)?.toLowerCase();if(!n)return;let i=t[n];i?i.push(e):t[n]=[e]}),new n(t,r)):new n(t)}function E(e){return e instanceof km&&(e.expression instanceof Om&&e.expression.variable instanceof Va&&e.expression.variable.kind===v.QUOTED_STRING||e.expression instanceof Em&&e.expression.literal?.kind===v.STRING_LITERAL)}function D(e){return e instanceof km&&e.expression instanceof Om&&e.expression.variable instanceof Va}function Rf(e){return e?e instanceof Dm:!1}function zf(e){return e instanceof km&&e.expression instanceof Om&&e.expression.variable?.kind===v.IDENTIFIER}function O(e){return e instanceof ym&&e.leftExpression instanceof I&&e.rightExpression instanceof I&&e.op?.value===`.`}function Bf(e){return D(e)?!0:O(e)&&D(e.rightExpression)&&Bf(e.leftExpression)}function k(e,t){return e instanceof R&&e.isKind(t)}function Vf(e){return e instanceof hm}function Hf(e,t){return e instanceof gm&&(t===void 0||e.isKind(t))}function Uf(e){return e instanceof L}function A(e,...t){return e instanceof V&&e.parent instanceof R&&e.parent.isKind(...t)}function Wf(e,t){let n=e.parent;return n instanceof R&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Gf(e,t){let n=e.parentOfKind(V);if(!n||t<0)return!1;if(t===0)return n.callee?n.callee.containsEq(e):!1;let r=n.args[t-1];return r?r.containsEq(e):!1}function Kf(e){return!!e.parentOfKind(U)}function qf(e,t){let n=e.parentOfKind(z);return!n||(n.name instanceof km?N(n.name):ep(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function Jf(e){return!(e instanceof ym)||!Df(e.op?.value)?!1:ap(e.leftExpression)!==void 0&&ap(e.rightExpression)!==void 0}function Yf(e){let t=ap(e.leftExpression),n=ap(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function Xf(e){return e instanceof km&&e.expression instanceof Om||e instanceof xm}function Zf(e){if(D(e))return e;if(O(e)){let t=e.rightExpression;if(t&&D(t))return t}}function Qf(e){let t=e.parentNode;return!O(t)||t.rightExpression!==e?!1:!(O(t.parentNode)&&t.parentNode.leftExpression===t)}function $f(e){if(D(e))return e.expression.variable}function ep(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function tp(e){if(!(e instanceof R))return;let t=j(e?.name);return t===void 0?void 0:t.join(`.`)}function np(e){return e.elementList.length===0}function rp(e){return e?.body?e.body instanceof H?e.body.body:[e.body]:[]}function ip(e){if(!e)return;if(!O(e))return[e];let t=ip(e.leftExpression);if(t)return t.push(e.rightExpression),t}function j(e){if(e===void 0)return;let t=ip(e);if(!t)return;let n=[];for(let e of t){let t=N(e);if(typeof t!=`string`)return;n.push(t)}return n}function ap(e){if(e===void 0)return;let t=ip(e);if(!t||t.length===0)return;let n=[];if(!D(g(t))){let e=t.pop();if(Ff(e))n=e.elementList;else return}let r=t;if(r.every(D))return{variables:r,tupleElements:n}}function op(e){if(Xf(e))return e instanceof xm?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof Sm&&e.elementList.every(Xf))return{functional:e.elementList.filter(e=>e instanceof xm),nonFunctional:e.elementList.filter(D)}}function M(e){if(E(e))return e.expression instanceof Om?e?.expression?.variable?.value:e.expression.literal.value}function sp(e){return e instanceof km&&e.expression instanceof Em&&e.expression.literal?.kind===v.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function cp(e){if(!(e instanceof Tm)||!e.callee)return;let t=ip(e.callee);if(!t||t.length===0||!t.every(D))return;let n=[];return Ff(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function N(e){if(D(e))return e.expression.variable.value}function lp(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function up(e){if(e.name instanceof vm)return ep(e.name)?.toLowerCase();if(e.name instanceof km)return N(e.name)}function dp(e){return zf(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Am}function fp(e){return M(e)===``}function pp(e){return e instanceof xm}function mp(e){let t=sp(e);if(t!==null)return t;if(Mf(e)&&e instanceof B&&e.expression){let t=e.op?.value,n=sp(e.expression);if(n!==null)return t===`-`?-n:n}return null}function hp(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return+!!e;let t=mp(e);if(t!==null)return t;let n=M(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function gp(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return+!!e;let t=mp(e);if(t!==null)return Number.isInteger(t)?t:null;let n=M(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var _p=[`true`,`yes`,`y`,`t`,`1`],vp=[`false`,`no`,`n`,`f`,`0`];function yp(e){if(e==null)return null;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===0?!1:e===1?!0:null;if(typeof e==`string`){let t=e.toLowerCase();return _p.includes(t)?!0:vp.includes(t)?!1:null}if(zf(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=sp(e);if(t===0)return!1;if(t===1)return!0;let n=M(e)?.toLowerCase();if(n){if(_p.includes(n))return!0;if(vp.includes(n))return!1}return null}function bp(e){if(e==null)return null;if(typeof e==`string`)return e;let t=j(e);return t?g(t):M(e)??null}function xp(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=M(e)??null??hp(e)??yp(e);return t===null?null:t.toString()}var Sp=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Cp=[`yyyy-MM-dd HH:mm:ss`,`yyyy-MM-dd HH:mm:ss.SSS`,`yyyy-MM-dd HH:mm:ss.SSSZZ`,`yyyy-MM-dd HH:mm:ssZZ`],wp=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Tp(e){if(e==null)return null;let t=typeof e==`string`?e:M(e)??null;if(t===null)return null;for(let e of wp){let n=Yd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of Sp){let n=Yd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Cp){let n=Yd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=Yd.fromISO(t,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)});return null;function r(e){return e.zone.type!==`system`}}function Ep(e){return e instanceof B?`${e.op?.value}${Ep(e.expression)}`:e.expression.literal.value}function Dp(e){return e instanceof B?e.op?.value===`-`?-Dp(e.expression):Dp(e.expression):Number.parseFloat(e.expression.literal.value)}function P(e){return{start:{offset:e.startPos.offset,line:e.startPos.line+1,column:e.startPos.column+1},end:{offset:e.endPos.offset,line:e.endPos.line+1,column:e.endPos.column+1},filepath:e.filepath}}function Op(e){let t=e.split(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(`PASS_THROUGH`),t=Symbol(`UNHANDLED`),n=class e{static create(t,n,r,i){return new e(t,n,r,i)}constructor(e,t,n,r){this.value=e,this.errors=t??[],this.warnings=n,this.infos=r}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings,this.infos):this}hasValue(e){return this.value===e}getFiltered(e){return this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings??[]}getInfos(){return this.infos??[]}chainFiltered(t,n){if(this.value===n)return new e(void 0,this.errors,this.warnings,this.infos);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()],o=[...this.getInfos(),...r.getInfos()];return new e(r.value,i,a,o)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()],a=[...this.getInfos(),...n.getInfos()];return new e(n.value,r,i,a)}mapFiltered(t,n){return this.value===n?new e(void 0,this.errors,this.warnings,this.infos):new e(t(this.value),this.errors,this.warnings,this.infos)}map(t){return new e(t(this.value),this.errors,this.warnings,this.infos)}},r=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Dep=`dep`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e.Metadata=`metadata`,e}({}),i=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.Dep=`dep`,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.Inactive=`inactive`,e.Example=`example`,e}({}),a=typeof global==`object`&&global&&global.Object===Object&&global,o=typeof self==`object`&&self&&self.Object===Object&&self,s=a||o||Function(`return this`)(),c=s.Symbol,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function p(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 m=Object.prototype.toString;function h(e){return m.call(e)}var ee=`[object Null]`,te=`[object Undefined]`,ne=c?c.toStringTag:void 0;function re(e){return e==null?e===void 0?te:ee:ne&&ne in Object(e)?p(e):h(e)}function ie(e){return typeof e==`object`&&!!e}var ae=`[object Symbol]`;function oe(e){return typeof e==`symbol`||ie(e)&&re(e)==ae}function se(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 ce=Array.isArray,le=1/0,ue=c?c.prototype:void 0,de=ue?ue.toString:void 0;function fe(e){if(typeof e==`string`)return e;if(ce(e))return se(e,fe)+``;if(oe(e))return de?de.call(e):``;var t=e+``;return t==`0`&&1/e==-le?`-0`:t}var pe=/\s/;function me(e){for(var t=e.length;t--&&pe.test(e.charAt(t)););return t}var he=/^\s+/;function ge(e){return e&&e.slice(0,me(e)+1).replace(he,``)}function _e(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var ve=NaN,ye=/^[-+]0x[0-9a-f]+$/i,be=/^0b[01]+$/i,xe=/^0o[0-7]+$/i,Se=parseInt;function Ce(e){if(typeof e==`number`)return e;if(oe(e))return ve;if(_e(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=_e(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=ge(e);var n=be.test(e);return n||xe.test(e)?Se(e.slice(2),n?2:8):ye.test(e)?ve:+e}var we=1/0,Te=17976931348623157e292;function Ee(e){return e?(e=Ce(e),e===we||e===-we?(e<0?-1:1)*Te:e===e?e:0):e===0?e:0}function De(e){var t=Ee(e),n=t%1;return t===t?n?t-n:t:0}function Oe(e){return e}var ke=`[object AsyncFunction]`,Ae=`[object Function]`,je=`[object GeneratorFunction]`,Me=`[object Proxy]`;function Ne(e){if(!_e(e))return!1;var t=re(e);return t==Ae||t==je||t==ke||t==Me}var Pe=s[`__core-js_shared__`],Fe=function(){var e=/[^.]+$/.exec(Pe&&Pe.keys&&Pe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Ie(e){return!!Fe&&Fe in e}var Le=Function.prototype.toString;function Re(e){if(e!=null){try{return Le.call(e)}catch{}try{return e+``}catch{}}return``}var ze=/[\\^$.*+?()[\]{}|]/g,Be=/^\[object .+?Constructor\]$/,Ve=Function.prototype,He=Object.prototype,Ue=Ve.toString,We=He.hasOwnProperty,Ge=RegExp(`^`+Ue.call(We).replace(ze,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function Ke(e){return!_e(e)||Ie(e)?!1:(Ne(e)?Ge:Be).test(Re(e))}function qe(e,t){return e?.[t]}function Je(e,t){var n=qe(e,t);return Ke(n)?n:void 0}var Ye=Je(s,`WeakMap`);function Xe(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 Ze(){}var Qe=800,$e=16,et=Date.now;function tt(e){var t=0,n=0;return function(){var r=et(),i=$e-(r-n);if(n=r,i>0){if(++t>=Qe)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function nt(e){return function(){return e}}var rt=function(){try{var e=Je(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),it=tt(rt?function(e,t){return rt(e,`toString`,{configurable:!0,enumerable:!1,value:nt(t),writable:!0})}:Oe);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}function ot(e){return e!==e}function st(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function ct(e,t,n){return t===t?st(e,t,n):at(e,ot,n)}function lt(e,t){return!!(e!=null&&e.length)&&ct(e,t,0)>-1}var ut=9007199254740991,dt=/^(?:0|[1-9]\d*)$/;function ft(e,t){var n=typeof e;return t??=ut,!!t&&(n==`number`||n!=`symbol`&&dt.test(e))&&e>-1&&e%1==0&&e<t}function pt(e,t,n){t==`__proto__`&&rt?rt(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function mt(e,t){return e===t||e!==e&&t!==t}var ht=Math.max;function gt(e,t,n){return t=ht(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=ht(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),Xe(e,this,s)}}function _t(e,t){return it(gt(e,t,Oe),e+``)}var vt=9007199254740991;function yt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=vt}function bt(e){return e!=null&&yt(e.length)&&!Ne(e)}var xt=Object.prototype;function St(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||xt)}function Ct(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var wt=`[object Arguments]`;function Tt(e){return ie(e)&&re(e)==wt}var Et=Object.prototype,Dt=Et.hasOwnProperty,Ot=Et.propertyIsEnumerable,kt=Tt(function(){return arguments}())?Tt:function(e){return ie(e)&&Dt.call(e,`callee`)&&!Ot.call(e,`callee`)};function At(){return!1}var jt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Mt=jt&&typeof module==`object`&&module&&!module.nodeType&&module,Nt=Mt&&Mt.exports===jt?s.Buffer:void 0,Pt=(Nt?Nt.isBuffer:void 0)||At,Ft=`[object Arguments]`,It=`[object Array]`,Lt=`[object Boolean]`,Rt=`[object Date]`,zt=`[object Error]`,Bt=`[object Function]`,Vt=`[object Map]`,Ht=`[object Number]`,Ut=`[object Object]`,Wt=`[object RegExp]`,Gt=`[object Set]`,Kt=`[object String]`,qt=`[object WeakMap]`,Jt=`[object ArrayBuffer]`,Yt=`[object DataView]`,Xt=`[object Float32Array]`,Zt=`[object Float64Array]`,Qt=`[object Int8Array]`,$t=`[object Int16Array]`,en=`[object Int32Array]`,tn=`[object Uint8Array]`,nn=`[object Uint8ClampedArray]`,rn=`[object Uint16Array]`,an=`[object Uint32Array]`,on={};on[Xt]=on[Zt]=on[Qt]=on[$t]=on[en]=on[tn]=on[nn]=on[rn]=on[an]=!0,on[Ft]=on[It]=on[Jt]=on[Lt]=on[Yt]=on[Rt]=on[zt]=on[Bt]=on[Vt]=on[Ht]=on[Ut]=on[Wt]=on[Gt]=on[Kt]=on[qt]=!1;function sn(e){return ie(e)&&yt(e.length)&&!!on[re(e)]}function cn(e){return function(t){return e(t)}}var ln=typeof exports==`object`&&exports&&!exports.nodeType&&exports,un=ln&&typeof module==`object`&&module&&!module.nodeType&&module,dn=un&&un.exports===ln&&a.process,fn=function(){try{return un&&un.require&&un.require(`util`).types||dn&&dn.binding&&dn.binding(`util`)}catch{}}(),pn=fn&&fn.isTypedArray,mn=pn?cn(pn):sn,hn=Object.prototype.hasOwnProperty;function gn(e,t){var n=ce(e),r=!n&&kt(e),i=!n&&!r&&Pt(e),a=!n&&!r&&!i&&mn(e),o=n||r||i||a,s=o?Ct(e.length,String):[],c=s.length;for(var l in e)(t||hn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||ft(l,c)))&&s.push(l);return s}function _n(e,t){return function(n){return e(t(n))}}var vn=_n(Object.keys,Object),yn=Object.prototype.hasOwnProperty;function bn(e){if(!St(e))return vn(e);var t=[];for(var n in Object(e))yn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function xn(e){return bt(e)?gn(e):bn(e)}function Sn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Cn=Object.prototype.hasOwnProperty;function wn(e){if(!_e(e))return Sn(e);var t=St(e),n=[];for(var r in e)r==`constructor`&&(t||!Cn.call(e,r))||n.push(r);return n}function Tn(e){return bt(e)?gn(e,!0):wn(e)}var En=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Dn=/^\w*$/;function On(e,t){if(ce(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||oe(e)?!0:Dn.test(e)||!En.test(e)||t!=null&&e in Object(t)}var kn=Je(Object,`create`);function An(){this.__data__=kn?kn(null):{},this.size=0}function jn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Mn=`__lodash_hash_undefined__`,Nn=Object.prototype.hasOwnProperty;function Pn(e){var t=this.__data__;if(kn){var n=t[e];return n===Mn?void 0:n}return Nn.call(t,e)?t[e]:void 0}var Fn=Object.prototype.hasOwnProperty;function In(e){var t=this.__data__;return kn?t[e]!==void 0:Fn.call(t,e)}var Ln=`__lodash_hash_undefined__`;function Rn(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=kn&&t===void 0?Ln:t,this}function zn(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])}}zn.prototype.clear=An,zn.prototype.delete=jn,zn.prototype.get=Pn,zn.prototype.has=In,zn.prototype.set=Rn;function Bn(){this.__data__=[],this.size=0}function Vn(e,t){for(var n=e.length;n--;)if(mt(e[n][0],t))return n;return-1}var Hn=Array.prototype.splice;function Un(e){var t=this.__data__,n=Vn(t,e);return n<0?!1:(n==t.length-1?t.pop():Hn.call(t,n,1),--this.size,!0)}function Wn(e){var t=this.__data__,n=Vn(t,e);return n<0?void 0:t[n][1]}function Gn(e){return Vn(this.__data__,e)>-1}function Kn(e,t){var n=this.__data__,r=Vn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function qn(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])}}qn.prototype.clear=Bn,qn.prototype.delete=Un,qn.prototype.get=Wn,qn.prototype.has=Gn,qn.prototype.set=Kn;var Jn=Je(s,`Map`);function Yn(){this.size=0,this.__data__={hash:new zn,map:new(Jn||qn),string:new zn}}function Xn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Zn(e,t){var n=e.__data__;return Xn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function Qn(e){var t=Zn(this,e).delete(e);return this.size-=+!!t,t}function $n(e){return Zn(this,e).get(e)}function er(e){return Zn(this,e).has(e)}function tr(e,t){var n=Zn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function nr(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])}}nr.prototype.clear=Yn,nr.prototype.delete=Qn,nr.prototype.get=$n,nr.prototype.has=er,nr.prototype.set=tr;var rr=`Expected a function`;function ir(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(rr);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(ir.Cache||nr),n}ir.Cache=nr;var ar=500;function or(e){var t=ir(e,function(e){return n.size===ar&&n.clear(),e}),n=t.cache;return t}var sr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,cr=/\\(\\)?/g,lr=or(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(sr,function(e,n,r,i){t.push(r?i.replace(cr,`$1`):n||e)}),t});function ur(e){return e==null?``:fe(e)}function dr(e,t){return ce(e)?e:On(e,t)?[e]:lr(ur(e))}var fr=1/0;function pr(e){if(typeof e==`string`||oe(e))return e;var t=e+``;return t==`0`&&1/e==-fr?`-0`:t}function mr(e,t){t=dr(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[pr(t[n++])];return n&&n==r?e:void 0}function hr(e,t,n){var r=e==null?void 0:mr(e,t);return r===void 0?n:r}function gr(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var _r=c?c.isConcatSpreadable:void 0;function vr(e){return ce(e)||kt(e)||!!(_r&&e&&e[_r])}function yr(e,t,n,r,i){var a=-1,o=e.length;for(n||=vr,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?yr(s,t-1,n,r,i):gr(i,s):r||(i[i.length]=s)}return i}function br(e){return e!=null&&e.length?yr(e,1):[]}function xr(){this.__data__=new qn,this.size=0}function Sr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Cr(e){return this.__data__.get(e)}function wr(e){return this.__data__.has(e)}var Tr=200;function Er(e,t){var n=this.__data__;if(n instanceof qn){var r=n.__data__;if(!Jn||r.length<Tr-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new nr(r)}return n.set(e,t),this.size=n.size,this}function Dr(e){var t=this.__data__=new qn(e);this.size=t.size}Dr.prototype.clear=xr,Dr.prototype.delete=Sr,Dr.prototype.get=Cr,Dr.prototype.has=wr,Dr.prototype.set=Er;function Or(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 kr(){return[]}var Ar=Object.prototype.propertyIsEnumerable,jr=Object.getOwnPropertySymbols,Mr=jr?function(e){return e==null?[]:(e=Object(e),Or(jr(e),function(t){return Ar.call(e,t)}))}:kr;function Nr(e,t,n){var r=t(e);return ce(e)?r:gr(r,n(e))}function Pr(e){return Nr(e,xn,Mr)}var Fr=Je(s,`DataView`),Ir=Je(s,`Promise`),Lr=Je(s,`Set`),Rr=`[object Map]`,zr=`[object Object]`,Br=`[object Promise]`,Vr=`[object Set]`,Hr=`[object WeakMap]`,Ur=`[object DataView]`,Wr=Re(Fr),Gr=Re(Jn),Kr=Re(Ir),qr=Re(Lr),Jr=Re(Ye),Yr=re;(Fr&&Yr(new Fr(new ArrayBuffer(1)))!=Ur||Jn&&Yr(new Jn)!=Rr||Ir&&Yr(Ir.resolve())!=Br||Lr&&Yr(new Lr)!=Vr||Ye&&Yr(new Ye)!=Hr)&&(Yr=function(e){var t=re(e),n=t==zr?e.constructor:void 0,r=n?Re(n):``;if(r)switch(r){case Wr:return Ur;case Gr:return Rr;case Kr:return Br;case qr:return Vr;case Jr:return Hr}return t});var Xr=Yr,Zr=s.Uint8Array;function Qr(e){for(var t=-1,n=e==null?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i}var $r=`__lodash_hash_undefined__`;function ei(e){return this.__data__.set(e,$r),this}function ti(e){return this.__data__.has(e)}function ni(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new nr;++t<n;)this.add(e[t])}ni.prototype.add=ni.prototype.push=ei,ni.prototype.has=ti;function ri(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function ii(e,t){return e.has(t)}var ai=1,oi=2;function si(e,t,n,r,i,a){var o=n&ai,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&oi?new ni:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var ee=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(ee!==void 0){if(ee)continue;f=!1;break}if(p){if(!ri(t,function(e,t){if(!ii(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}function ci(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function li(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var ui=1,di=2,fi=`[object Boolean]`,pi=`[object Date]`,mi=`[object Error]`,hi=`[object Map]`,gi=`[object Number]`,_i=`[object RegExp]`,vi=`[object Set]`,yi=`[object String]`,bi=`[object Symbol]`,xi=`[object ArrayBuffer]`,Si=`[object DataView]`,Ci=c?c.prototype:void 0,wi=Ci?Ci.valueOf:void 0;function Ti(e,t,n,r,i,a,o){switch(n){case Si:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case xi:return!(e.byteLength!=t.byteLength||!a(new Zr(e),new Zr(t)));case fi:case pi:case gi:return mt(+e,+t);case mi:return e.name==t.name&&e.message==t.message;case _i:case yi:return e==t+``;case hi:var s=ci;case vi:var c=r&ui;if(s||=li,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=di,o.set(e,t);var u=si(s(e),s(t),r,i,a,o);return o.delete(e),u;case bi:if(wi)return wi.call(e)==wi.call(t)}return!1}var Ei=1,Di=Object.prototype.hasOwnProperty;function Oi(e,t,n,r,i,a){var o=n&Ei,s=Pr(e),c=s.length;if(c!=Pr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Di.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var h=e[u],ee=t[u];if(r)var te=o?r(ee,h,u,t,e,a):r(h,ee,u,e,t,a);if(!(te===void 0?h===ee||i(h,ee,n,r,a):te)){p=!1;break}m||=u==`constructor`}if(p&&!m){var ne=e.constructor,re=t.constructor;ne!=re&&`constructor`in e&&`constructor`in t&&!(typeof ne==`function`&&ne instanceof ne&&typeof re==`function`&&re instanceof re)&&(p=!1)}return a.delete(e),a.delete(t),p}var ki=1,Ai=`[object Arguments]`,ji=`[object Array]`,Mi=`[object Object]`,Ni=Object.prototype.hasOwnProperty;function Pi(e,t,n,r,i,a){var o=ce(e),s=ce(t),c=o?ji:Xr(e),l=s?ji:Xr(t);c=c==Ai?Mi:c,l=l==Ai?Mi:l;var u=c==Mi,d=l==Mi,f=c==l;if(f&&Pt(e)){if(!Pt(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Dr,o||mn(e)?si(e,t,n,r,i,a):Ti(e,t,c,n,r,i,a);if(!(n&ki)){var p=u&&Ni.call(e,`__wrapped__`),m=d&&Ni.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,ee=m?t.value():t;return a||=new Dr,i(h,ee,n,r,a)}}return f?(a||=new Dr,Oi(e,t,n,r,i,a)):!1}function Fi(e,t,n,r,i){return e===t?!0:e==null||t==null||!ie(e)&&!ie(t)?e!==e&&t!==t:Pi(e,t,n,r,Fi,i)}var Ii=1,Li=2;function Ri(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 Dr;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Fi(u,l,Ii|Li,r,d):f))return!1}}return!0}function zi(e){return e===e&&!_e(e)}function Bi(e){for(var t=xn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,zi(i)]}return t}function Vi(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function Hi(e){var t=Bi(e);return t.length==1&&t[0][2]?Vi(t[0][0],t[0][1]):function(n){return n===e||Ri(n,e,t)}}function Ui(e,t){return e!=null&&t in Object(e)}function Wi(e,t,n){t=dr(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=pr(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&&yt(i)&&ft(o,i)&&(ce(e)||kt(e)))}function Gi(e,t){return e!=null&&Wi(e,t,Ui)}var Ki=1,qi=2;function Ji(e,t){return On(e)&&zi(t)?Vi(pr(e),t):function(n){var r=hr(n,e);return r===void 0&&r===t?Gi(n,e):Fi(t,r,Ki|qi)}}function Yi(e){return function(t){return t?.[e]}}function Xi(e){return function(t){return mr(t,e)}}function Zi(e){return On(e)?Yi(pr(e)):Xi(e)}function Qi(e){return typeof e==`function`?e:e==null?Oe:typeof e==`object`?ce(e)?Ji(e[0],e[1]):Hi(e):Zi(e)}function $i(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 ea(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 ta=ea();function na(e,t){return e&&ta(e,t,xn)}function ra(e,t){return function(n,r){if(n==null)return n;if(!bt(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 ia=ra(na);function aa(e,t,n,r){return ia(e,function(e,i,a){t(r,e,n(e),a)}),r}function oa(e,t){return function(n,r){var i=ce(n)?$i:aa,a=t?t():{};return i(n,e,Qi(r,2),a)}}function sa(e){return ie(e)&&bt(e)}function ca(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}var la=200;function ua(e,t,n,r){var i=-1,a=lt,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=se(t,cn(n))),r?(a=ca,o=!1):t.length>=la&&(a=ii,o=!1,t=new ni(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var da=_t(function(e,t){return sa(e)?ua(e,yr(t,1,sa,!0)):[]});function g(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function fa(e){return typeof e==`function`?e:Oe}function pa(e,t){var n=[];return ia(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ma(e,t){return(ce(e)?Or:pa)(e,Qi(t,3))}var ha=Math.max,ga=Math.min;function _a(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=De(n),i=n<0?ha(r+i,0):ga(i,r-1)),at(e,Qi(t,3),i,!0)}function va(e){return e&&e.length?e[0]:void 0}function ya(e,t){var n=-1,r=bt(e)?Array(e.length):[];return ia(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function ba(e,t){return(ce(e)?se:ya)(e,Qi(t,3))}function xa(e,t){return yr(ba(e,t),1)}function Sa(e,t){return e==null?e:ta(e,fa(t),Tn)}var Ca=Object.prototype.hasOwnProperty,wa=oa(function(e,t,n){Ca.call(e,n)?e[n].push(t):pt(e,n,[t])}),Ta=`[object Map]`,Ea=`[object Set]`,Da=Object.prototype.hasOwnProperty;function Oa(e){if(e==null)return!0;if(bt(e)&&(ce(e)||typeof e==`string`||typeof e.splice==`function`||Pt(e)||mn(e)||kt(e)))return!e.length;var t=Xr(e);if(t==Ta||t==Ea)return!e.size;if(St(e))return!bn(e).length;for(var n in e)if(Da.call(e,n))return!1;return!0}var ka=oa(function(e,t,n){pt(e,n,t)}),_=oa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),Aa=Lr&&1/li(new Lr([,-0]))[1]==1/0?function(e){return new Lr(e)}:Ze,ja=200;function Ma(e,t,n){var r=-1,i=lt,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=ca;else if(a>=ja){var l=t?null:Aa(e);if(l)return li(l);o=!1,i=ii,c=new ni}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}function Na(e){return e&&e.length?Ma(e):[]}function Pa(e,t){return e&&e.length?Ma(e,Qi(t,2)):[]}var Fa=Math.max;function Ia(e){if(!(e&&e.length))return[];var t=0;return e=Or(e,function(e){if(sa(e))return t=Fa(e.length,t),!0}),Ct(t,function(t){return se(e,Yi(t))})}var La=_t(Ia),v=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.FRONT_MATTER=`<front-matter>`,e.WILDCARD=`<wildcard>`,e}({});function Ra(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:case`<front-matter>`:return!0;default:return!1}}function za(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 Ba(e){return e!==void 0&&e.kind===`<op>`}var Va=class e{constructor(e,t,n,r,i,a){this.kind=e,this.filepath=t,this.startPos=n,this.endPos=r,this.value=i,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=a,this.start=n.offset,this.end=r.offset}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}};function Ha(e){return e.trailingTrivia.find(({kind:e})=>e===v.NEWLINE)!==void 0}function Ua(e,t){return t.leadingTrivia.find(({kind:e})=>e===v.NEWLINE)!==void 0||Ha(e)}function Wa(e){return e.trailingTrivia.find(({kind:e})=>[v.SPACE,v.TAB].includes(e))!==void 0}function Ga(e){return e.trailingTrivia.length===0?e.end:Ga(g(e.trailingTrivia))}function Ka(e){return e.leadingTrivia.length===0?e.start:Ka(e.leadingTrivia[0])}function qa(e){return[v.SINGLE_LINE_COMMENT,v.MULTILINE_COMMENT].includes(e.kind)}var Ja=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},Ya=/^[A-Za-z]:\//;function Xa(e=``){return e&&e.replace(/\\/g,`/`).replace(Ya,e=>e.toUpperCase())}var Za=/^[/\\]{2}/,Qa=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,$a=/^[A-Za-z]:$/,eo=/^\/([A-Za-z]:)?$/,to=/.(\.[^./]+|\.)$/,no=function(e){if(e.length===0)return`.`;e=Xa(e);let t=e.match(Za),n=so(e),r=e[e.length-1]===`/`;return e=oo(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),$a.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!so(e)?`/${e}`:e)},ro=function(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return no(t)};function io(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var ao=function(...e){e=e.map(e=>Xa(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:io();!i||i.length===0||(t=`${i}/${t}`,n=so(i))}return t=oo(t,!n),n&&!so(t)?`/${t}`:t.length>0?t:`.`};function oo(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}var so=function(e){return Qa.test(e)},co=function(e){if(e===`..`)return``;let t=to.exec(Xa(e));return t&&t[1]||``},lo=function(e,t){let n=ao(e).replace(eo,`$1`).split(`/`),r=ao(t).replace(eo,`$1`).split(`/`);if(r[0][1]===`:`&&n[0][1]===`:`&&n[0]!==r[0])return r.join(`/`);let i=[...n];for(let e of i){if(r[0]!==e)break;n.shift(),r.shift()}return[...n.map(()=>`..`),...r].join(`/`)},uo=function(e){let t=Xa(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&$a.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(so(e)?`/`:`.`)},fo=function(e,t){let n=Xa(e).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return t&&r.endsWith(t)?r.slice(0,-t.length):r},po=/^[a-zA-Z]:\//,mo=class e{constructor(e,t={}){e=e.split(`/`).map(ho).join(`/`);let n=no(e);if(!so(n))throw Error(`FilePath requires an absolute path, got: "${e}"`);this.path=n,this.protocol=t.protocol}intern(){return this.protocol,`filepath@${this.path}`}static from(t){return new e(t)}static resolve(t,n){return new e(ao(t,n))}static fromUri(t){try{let n=new URL(t);return new e(no(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(no(t))}}get absolute(){return this.path}get fsPath(){return this.path.split(`/`).map(decodeURIComponent).join(`/`)}get dirname(){return uo(this.fsPath)}get basename(){return fo(this.fsPath)}get extname(){return co(this.fsPath)}resolve(t){return new e(ao(this.dirname,t))}join(...t){return new e(ro(this.path,...t))}relativeTo(e){let t=lo(e,this.fsPath);return!t.startsWith(`./`)&&!t.startsWith(`../`)&&![`.`,`..`].includes(t)?`./${t}`:t}toKey(){return this.path}equals(e){return this.toKey()===e.toKey()}isParentOf(e){if(this.path===e.path)return!1;let t=this.path.endsWith(`/`)?this.path:`${this.path}/`;return e.path.startsWith(t)}toUri(e={}){let t=e.protocol||this.protocol;if(!t)return this.path;let n=po.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!so(no(e))}};function ho(e){try{return encodeURIComponent(decodeURIComponent(e))}catch{return encodeURIComponent(e)}}var go=[`null`,`true`,`false`],_o=`none`,vo=`.dbml`,yo=[`-`,`+`],y=`public`,bo=mo.from(`/main.dbml`),xo={mysql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`,`mediumint`]),postgres:new Set([`int`,`integer`,`smallint`,`bigint`,`serial`,`bigserial`,`smallserial`]),mssql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`]),oracle:new Set([`int`,`integer`,`smallint`]),snowflake:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`])},So={mysql:new Set([`decimal`,`numeric`,`float`,`double`,`real`]),postgres:new Set([`decimal`,`numeric`,`real`,`float`,`double precision`]),mssql:new Set([`decimal`,`numeric`,`real`,`float`]),oracle:new Set([`number`,`decimal`,`numeric`,`float`,`real`]),snowflake:new Set([`number`,`decimal`,`numeric`,`float`,`double`,`real`])},Co={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},wo={mysql:new Set([`varchar`,`char`,`text`,`tinytext`,`mediumtext`,`longtext`,`string`]),postgres:new Set([`varchar`,`char`,`character`,`character varying`,`text`,`string`]),mssql:new Set([`varchar`,`char`,`nvarchar`,`nchar`,`text`,`ntext`,`string`]),oracle:new Set([`varchar`,`varchar2`,`char`,`nvarchar2`,`nchar`,`string`]),snowflake:new Set([`varchar`,`char`,`text`,`string`])},To={mysql:new Set([`binary`,`varbinary`,`blob`,`tinyblob`,`mediumblob`,`longblob`]),postgres:new Set([`bytea`]),mssql:new Set([`binary`,`varbinary`]),oracle:new Set([`blob`,`raw`]),snowflake:new Set([`binary`,`varbinary`])},Eo={mysql:new Set([`date`,`datetime`,`timestamp`,`time`]),postgres:new Set([`date`,`timestamp`,`timestamptz`,`timestamp with time zone`,`timestamp without time zone`,`time`,`timetz`,`time with time zone`,`time without time zone`]),mssql:new Set([`date`,`datetime`,`datetime2`,`smalldatetime`,`time`]),oracle:new Set([`date`,`timestamp`,`timestamp with time zone`,`timestamp with local time zone`]),snowflake:new Set([`date`,`datetime`,`timestamp`,`time`])},Do={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function Oo(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function ko(e,t){let n=Oo(e);return t?xo[t].has(n):Object.values(xo).some(e=>e.has(n))}function Ao(e,t){let n=Oo(e);return t?So[t].has(n):Object.values(So).some(e=>e.has(n))}function jo(e,t){return ko(e,t)||Ao(e,t)}function Mo(e,t){let n=Oo(e);return t?Co[t].has(n):Object.values(Co).some(e=>e.has(n))}function No(e,t){let n=Oo(e);return t?wo[t].has(n):Object.values(wo).some(e=>e.has(n))}function Po(e,t){let n=Oo(e);return t?To[t].has(n):Object.values(To).some(e=>e.has(n))}function Fo(e,t){let n=Oo(e);return t?Eo[t].has(n):Object.values(Eo).some(e=>e.has(n))}function Io(e,t){let n=Oo(e);return t?Do[t].has(n):Object.values(Do).some(e=>e.has(n))}function Lo(e,t){if(t)return`string`;if(ko(e))return`integer`;if(Ao(e))return`real`;if(Mo(e))return`bool`;if(No(e))return`string`;let n=Oo(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:Fo(e)?`datetime`:e}var Ro=class extends Error{},zo=class extends Ro{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Bo=class extends Ro{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Vo=class extends Ro{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Ho=class extends Ro{},Uo=class extends Ro{constructor(e){super(`Invalid unit ${e}`)}},Wo=class extends Ro{},Go=class extends Ro{constructor(){super(`Zone is an abstract class`)}},b=`numeric`,Ko=`short`,qo=`long`,Jo={year:b,month:b,day:b},Yo={year:b,month:Ko,day:b},Xo={year:b,month:Ko,day:b,weekday:Ko},Zo={year:b,month:qo,day:b},Qo={year:b,month:qo,day:b,weekday:qo},$o={hour:b,minute:b},es={hour:b,minute:b,second:b},ts={hour:b,minute:b,second:b,timeZoneName:Ko},ns={hour:b,minute:b,second:b,timeZoneName:qo},rs={hour:b,minute:b,hourCycle:`h23`},is={hour:b,minute:b,second:b,hourCycle:`h23`},as={hour:b,minute:b,second:b,hourCycle:`h23`,timeZoneName:Ko},os={hour:b,minute:b,second:b,hourCycle:`h23`,timeZoneName:qo},ss={year:b,month:b,day:b,hour:b,minute:b},cs={year:b,month:b,day:b,hour:b,minute:b,second:b},ls={year:b,month:Ko,day:b,hour:b,minute:b},us={year:b,month:Ko,day:b,hour:b,minute:b,second:b},ds={year:b,month:Ko,day:b,weekday:Ko,hour:b,minute:b},fs={year:b,month:qo,day:b,hour:b,minute:b,timeZoneName:Ko},ps={year:b,month:qo,day:b,hour:b,minute:b,second:b,timeZoneName:Ko},ms={year:b,month:qo,day:b,weekday:qo,hour:b,minute:b,timeZoneName:qo},hs={year:b,month:qo,day:b,weekday:qo,hour:b,minute:b,second:b,timeZoneName:qo},gs=class{get type(){throw new Go}get name(){throw new Go}get ianaName(){return this.name}get isUniversal(){throw new Go}offsetName(e,t){throw new Go}formatOffset(e,t){throw new Go}offset(e){throw new Go}equals(e){throw new Go}get isValid(){throw new Go}},_s=null,vs=class e extends gs{static get instance(){return _s===null&&(_s=new e),_s}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return al(e,t,n)}formatOffset(e,t){return ll(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},ys=new Map;function bs(e){let t=ys.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(`en-US`,{hour12:!1,timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,era:`short`}),ys.set(e,t)),t}var xs={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function Ss(e,t){let n=e.format(t).replace(/\u200E/g,``),[,r,i,a,o,s,c,l]=/(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(n);return[a,r,i,o,s,c,l]}function Cs(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=xs[t];t===`era`?r[a]=i:x(a)||(r[a]=parseInt(i,10))}return r}var ws=new Map,Ts=class e extends gs{static create(t){let n=ws.get(t);return n===void 0&&ws.set(t,n=new e(t)),n}static resetCache(){ws.clear(),ys.clear()}static isValidSpecifier(e){return this.isValidZone(e)}static isValidZone(e){if(!e)return!1;try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).format(),!0}catch{return!1}}constructor(t){super(),this.zoneName=t,this.valid=e.isValidZone(t)}get type(){return`iana`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return al(e,t,n,this.name)}formatOffset(e,t){return ll(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=bs(this.name),[r,i,a,o,s,c,l]=n.formatToParts?Cs(n,t):Ss(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=tl({year:r,month:i,day:a,hour:s===24?0:s,minute:c,second:l,millisecond:0}),d=+t,f=d%1e3;return d-=f>=0?f:1e3+f,(u-d)/(60*1e3)}equals(e){return e.type===`iana`&&e.name===this.name}get isValid(){return this.valid}},Es={};function Ds(e,t={}){let n=JSON.stringify([e,t]),r=Es[n];return r||(r=new Intl.ListFormat(e,t),Es[n]=r),r}var Os=new Map;function ks(e,t={}){let n=JSON.stringify([e,t]),r=Os.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),Os.set(n,r)),r}var As=new Map;function js(e,t={}){let n=JSON.stringify([e,t]),r=As.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),As.set(n,r)),r}var Ms=new Map;function Ns(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=Ms.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),Ms.set(i,a)),a}var Ps=null;function Fs(){return Ps||(Ps=new Intl.DateTimeFormat().resolvedOptions().locale,Ps)}var Is=new Map;function Ls(e){let t=Is.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Is.set(e,t)),t}var Rs=new Map;function zs(e){let t=Rs.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Ys,...t}),Rs.set(e,t)}return t}function Bs(e){let t=e.indexOf(`-x-`);t!==-1&&(e=e.substring(0,t));let n=e.indexOf(`-u-`);if(n===-1)return[e];{let t,r;try{t=ks(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=ks(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Vs(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Hs(e){let t=[];for(let n=1;n<=12;n++){let r=Yd.utc(2009,n,1);t.push(e(r))}return t}function Us(e){let t=[];for(let n=1;n<=7;n++){let r=Yd.utc(2016,11,13+n);t.push(e(r))}return t}function Ws(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Gs(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Ls(e.locale).numberingSystem===`latn`}var Ks=class{constructor(e,t,n){this.padTo=n.padTo||0,this.floor=n.floor||!1;let{padTo:r,floor:i,...a}=n;if(!t||Object.keys(a).length>0){let t={useGrouping:!1,...n};n.padTo>0&&(t.minimumIntegerDigits=n.padTo),this.inf=js(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return qc(this.floor?Math.floor(e):Zc(e,3),this.padTo)}},qs=class{constructor(e,t,n){this.opts=n,this.originalZone=void 0;let r;if(this.opts.timeZone)this.dt=e;else if(e.zone.type===`fixed`){let t=-1*(e.offset/60),n=t>=0?`Etc/GMT+${t}`:`Etc/GMT${t}`;e.offset!==0&&Ts.create(n).valid?(r=n,this.dt=e):(r=`UTC`,this.dt=e.offset===0?e:e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone)}else e.zone.type===`system`?this.dt=e:e.zone.type===`iana`?(this.dt=e,r=e.zone.name):(r=`UTC`,this.dt=e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone);let i={...this.opts};i.timeZone=i.timeZone||r,this.dtf=ks(t,i)}format(){return this.originalZone?this.formatToParts().map(({value:e})=>e).join(``):this.dtf.format(this.dt.toJSDate())}formatToParts(){let e=this.dtf.formatToParts(this.dt.toJSDate());return this.originalZone?e.map(e=>{if(e.type===`timeZoneName`){let t=this.originalZone.offsetName(this.dt.ts,{locale:this.dt.locale,format:this.opts.timeZoneName});return{...e,value:t}}else return e}):e}resolvedOptions(){return this.dtf.resolvedOptions()}},Js=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Rc()&&(this.rtf=Ns(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):Ol(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Ys={firstDay:1,minimalDays:4,weekend:[6,7]},Xs=class e{static fromOpts(t){return e.create(t.locale,t.numberingSystem,t.outputCalendar,t.weekSettings,t.defaultToEN)}static create(t,n,r,i,a=!1){let o=t||gc.defaultLocale;return new e(o||(a?`en-US`:Fs()),n||gc.defaultNumberingSystem,r||gc.defaultOutputCalendar,Wc(i)||gc.defaultWeekSettings,o)}static resetCache(){Ps=null,Os.clear(),As.clear(),Ms.clear(),Is.clear(),Rs.clear()}static fromObject({locale:t,numberingSystem:n,outputCalendar:r,weekSettings:i}={}){return e.create(t,n,r,i)}constructor(e,t,n,r,i){let[a,o,s]=Bs(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Vs(this.locale,this.numberingSystem,this.outputCalendar),this.weekdaysCache={format:{},standalone:{}},this.monthsCache={format:{},standalone:{}},this.meridiemCache=null,this.eraCache={},this.specifiedLocale=i,this.fastNumbersCached=null}get fastNumbers(){return this.fastNumbersCached??=Gs(this),this.fastNumbersCached}listingMode(){let e=this.isEnglish(),t=(this.numberingSystem===null||this.numberingSystem===`latn`)&&(this.outputCalendar===null||this.outputCalendar===`gregory`);return e&&t?`en`:`intl`}clone(t){return!t||Object.getOwnPropertyNames(t).length===0?this:e.create(t.locale||this.specifiedLocale,t.numberingSystem||this.numberingSystem,t.outputCalendar||this.outputCalendar,Wc(t.weekSettings)||this.weekSettings,t.defaultToEN||!1)}redefaultToEN(e={}){return this.clone({...e,defaultToEN:!0})}redefaultToSystem(e={}){return this.clone({...e,defaultToEN:!1})}months(e,t=!1){return Ws(this,e,ml,()=>{let n=this.intl===`ja`||this.intl.startsWith(`ja-`);t&=!n;let r=t?{month:e,day:`numeric`}:{month:e},i=t?`format`:`standalone`;if(!this.monthsCache[i][e]){let t=n?e=>this.dtFormatter(e,r).format():e=>this.extract(e,r,`month`);this.monthsCache[i][e]=Hs(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Ws(this,e,vl,()=>{let n=t?{weekday:e,year:`numeric`,month:`long`,day:`numeric`}:{weekday:e},r=t?`format`:`standalone`;return this.weekdaysCache[r][e]||(this.weekdaysCache[r][e]=Us(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Ws(this,void 0,()=>yl,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[Yd.utc(2016,11,13,9),Yd.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Ws(this,e,Cl,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[Yd.utc(-40,1,1),Yd.utc(2017,1,1)].map(e=>this.extract(e,t,`era`))),this.eraCache[e]})}extract(e,t,n){let r=this.dtFormatter(e,t).formatToParts().find(e=>e.type.toLowerCase()===n);return r?r.value:null}numberFormatter(e={}){return new Ks(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new qs(e,this.intl,t)}relFormatter(e={}){return new Js(this.intl,this.isEnglish(),e)}listFormatter(e={}){return Ds(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Ls(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:zc()?zs(this.locale):Ys}getStartOfWeek(){return this.getWeekSettings().firstDay}getMinDaysInFirstWeek(){return this.getWeekSettings().minimalDays}getWeekendDays(){return this.getWeekSettings().weekend}equals(e){return this.locale===e.locale&&this.numberingSystem===e.numberingSystem&&this.outputCalendar===e.outputCalendar}toString(){return`Locale(${this.locale}, ${this.numberingSystem}, ${this.outputCalendar})`}},Zs=null,Qs=class e extends gs{static get utcInstance(){return Zs===null&&(Zs=new e(0)),Zs}static instance(t){return t===0?e.utcInstance:new e(t)}static parseSpecifier(t){if(t){let n=t.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);if(n)return new e(ol(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${ll(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${ll(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return ll(this.fixed,t)}get isUniversal(){return!0}offset(){return this.fixed}equals(e){return e.type===`fixed`&&e.fixed===this.fixed}get isValid(){return!0}},$s=class extends gs{constructor(e){super(),this.zoneName=e}get type(){return`invalid`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(){return null}formatOffset(){return``}offset(){return NaN}equals(){return!1}get isValid(){return!1}};function ec(e,t){if(x(e)||e===null)return t;if(e instanceof gs)return e;if(Ic(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?vs.instance:n===`utc`||n===`gmt`?Qs.utcInstance:Qs.parseSpecifier(n)||Ts.create(e)}else if(Pc(e))return Qs.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new $s(e)}var tc={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},nc={arab:[1632,1641],arabext:[1776,1785],bali:[6992,7001],beng:[2534,2543],deva:[2406,2415],fullwide:[65296,65303],gujr:[2790,2799],khmr:[6112,6121],knda:[3302,3311],laoo:[3792,3801],limb:[6470,6479],mlym:[3430,3439],mong:[6160,6169],mymr:[4160,4169],orya:[2918,2927],tamldec:[3046,3055],telu:[3174,3183],thai:[3664,3673],tibt:[3872,3881]},rc=tc.hanidec.replace(/[\[|\]]/g,``).split(``);function ic(e){let t=parseInt(e,10);if(isNaN(t)){t=``;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(e[n].search(tc.hanidec)!==-1)t+=rc.indexOf(e[n]);else for(let e in nc){let[n,i]=nc[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var ac=new Map;function oc(){ac.clear()}function sc({numberingSystem:e},t=``){let n=e||`latn`,r=ac.get(n);r===void 0&&(r=new Map,ac.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${tc[n]}${t}`),r.set(t,i)),i}var cc=()=>Date.now(),lc=`system`,uc=null,dc=null,fc=null,pc=60,mc,hc=null,gc=class{static get now(){return cc}static set now(e){cc=e}static set defaultZone(e){lc=e}static get defaultZone(){return ec(lc,vs.instance)}static get defaultLocale(){return uc}static set defaultLocale(e){uc=e}static get defaultNumberingSystem(){return dc}static set defaultNumberingSystem(e){dc=e}static get defaultOutputCalendar(){return fc}static set defaultOutputCalendar(e){fc=e}static get defaultWeekSettings(){return hc}static set defaultWeekSettings(e){hc=Wc(e)}static get twoDigitCutoffYear(){return pc}static set twoDigitCutoffYear(e){pc=e%100}static get throwOnInvalid(){return mc}static set throwOnInvalid(e){mc=e}static resetCaches(){Xs.resetCache(),Ts.resetCache(),Yd.resetCache(),oc()}},_c=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},vc=[0,31,59,90,120,151,181,212,243,273,304,334],yc=[0,31,60,91,121,152,182,213,244,274,305,335];function bc(e,t){return new _c(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function xc(e,t,n){let r=new Date(Date.UTC(e,t-1,n));e<100&&e>=0&&r.setUTCFullYear(r.getUTCFullYear()-1900);let i=r.getUTCDay();return i===0?7:i}function Sc(e,t,n){return n+(Qc(e)?yc:vc)[t-1]}function Cc(e,t){let n=Qc(e)?yc:vc,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function wc(e,t){return(e-t+7)%7+1}function Tc(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Sc(r,i,a),s=wc(xc(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=rl(l,t,n)):c>rl(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...ul(e)}}function Ec(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=wc(xc(r,1,t),n),s=$c(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=$c(l)):c>s?(l=r+1,c-=$c(r)):l=r;let{month:u,day:d}=Cc(l,c);return{year:l,month:u,day:d,...ul(e)}}function Dc(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Sc(t,n,r),...ul(e)}}function Oc(e){let{year:t,ordinal:n}=e,{month:r,day:i}=Cc(t,n);return{year:t,month:r,day:i,...ul(e)}}function kc(e,t){if(!x(e.localWeekday)||!x(e.localWeekNumber)||!x(e.localWeekYear)){if(!x(e.weekday)||!x(e.weekNumber)||!x(e.weekYear))throw new Ho(`Cannot mix locale-based week fields with ISO-based week fields`);return x(e.localWeekday)||(e.weekday=e.localWeekday),x(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),x(e.localWeekYear)||(e.weekYear=e.localWeekYear),delete e.localWeekday,delete e.localWeekNumber,delete e.localWeekYear,{minDaysInFirstWeek:t.getMinDaysInFirstWeek(),startOfWeek:t.getStartOfWeek()}}else return{minDaysInFirstWeek:4,startOfWeek:1}}function Ac(e,t=4,n=1){let r=Fc(e.weekYear),i=Gc(e.weekNumber,1,rl(e.weekYear,t,n)),a=Gc(e.weekday,1,7);return r?i?a?!1:bc(`weekday`,e.weekday):bc(`week`,e.weekNumber):bc(`weekYear`,e.weekYear)}function jc(e){let t=Fc(e.year),n=Gc(e.ordinal,1,$c(e.year));return t?n?!1:bc(`ordinal`,e.ordinal):bc(`year`,e.year)}function Mc(e){let t=Fc(e.year),n=Gc(e.month,1,12),r=Gc(e.day,1,el(e.year,e.month));return t?n?r?!1:bc(`day`,e.day):bc(`month`,e.month):bc(`year`,e.year)}function Nc(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Gc(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Gc(n,0,59),s=Gc(r,0,59),c=Gc(i,0,999);return a?o?s?c?!1:bc(`millisecond`,i):bc(`second`,r):bc(`minute`,n):bc(`hour`,t)}function x(e){return e===void 0}function Pc(e){return typeof e==`number`}function Fc(e){return typeof e==`number`&&e%1==0}function Ic(e){return typeof e==`string`}function Lc(e){return Object.prototype.toString.call(e)===`[object Date]`}function Rc(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function zc(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Bc(e){return Array.isArray(e)?e:[e]}function Vc(e,t,n){if(e.length!==0)return e.reduce((e,r)=>{let i=[t(r),r];return e&&n(e[0],i[0])===e[0]?e:i},null)[1]}function Hc(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Uc(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Wc(e){if(e==null)return null;if(typeof e!=`object`)throw new Wo(`Week settings must be an object`);if(!Gc(e.firstDay,1,7)||!Gc(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Gc(e,1,7)))throw new Wo(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Gc(e,t,n){return Fc(e)&&e>=t&&e<=n}function Kc(e,t){return e-t*Math.floor(e/t)}function qc(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Jc(e){if(!(x(e)||e===null||e===``))return parseInt(e,10)}function Yc(e){if(!(x(e)||e===null||e===``))return parseFloat(e)}function Xc(e){if(!(x(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Zc(e,t,n=`round`){let r=10**t;switch(n){case`expand`:return e>0?Math.ceil(e*r)/r:Math.floor(e*r)/r;case`trunc`:return Math.trunc(e*r)/r;case`round`:return Math.round(e*r)/r;case`floor`:return Math.floor(e*r)/r;case`ceil`:return Math.ceil(e*r)/r;default:throw RangeError(`Value rounding ${n} is out of range`)}}function Qc(e){return e%4==0&&(e%100!=0||e%400==0)}function $c(e){return Qc(e)?366:365}function el(e,t){let n=Kc(t-1,12)+1,r=e+(t-n)/12;return n===2?Qc(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function tl(e){let t=Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second,e.millisecond);return e.year<100&&e.year>=0&&(t=new Date(t),t.setUTCFullYear(e.year,e.month-1,e.day)),+t}function nl(e,t,n){return-wc(xc(e,1,t),n)+t-1}function rl(e,t=4,n=1){let r=nl(e,t,n),i=nl(e+1,t,n);return($c(e)-r+i)/7}function il(e){return e>99?e:e>gc.twoDigitCutoffYear?1900+e:2e3+e}function al(e,t,n,r=null){let i=new Date(e),a={hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};r&&(a.timeZone=r);let o={timeZoneName:t,...a},s=new Intl.DateTimeFormat(n,o).formatToParts(i).find(e=>e.type.toLowerCase()===`timezonename`);return s?s.value:null}function ol(e,t){let n=parseInt(e,10);Number.isNaN(n)&&(n=0);let r=parseInt(t,10)||0,i=n<0||Object.is(n,-0)?-r:r;return n*60+i}function sl(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Wo(`Invalid unit value ${e}`);return t}function cl(e,t){let n={};for(let r in e)if(Uc(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=sl(i)}return n}function ll(e,t){let n=Math.trunc(Math.abs(e/60)),r=Math.trunc(Math.abs(e%60)),i=e>=0?`+`:`-`;switch(t){case`short`:return`${i}${qc(n,2)}:${qc(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${qc(n,2)}${qc(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function ul(e){return Hc(e,[`hour`,`minute`,`second`,`millisecond`])}var dl=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],fl=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],pl=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function ml(e){switch(e){case`narrow`:return[...pl];case`short`:return[...fl];case`long`:return[...dl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`,`12`];case`2-digit`:return[`01`,`02`,`03`,`04`,`05`,`06`,`07`,`08`,`09`,`10`,`11`,`12`];default:return null}}var hl=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],gl=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],_l=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function vl(e){switch(e){case`narrow`:return[..._l];case`short`:return[...gl];case`long`:return[...hl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var yl=[`AM`,`PM`],bl=[`Before Christ`,`Anno Domini`],xl=[`BC`,`AD`],Sl=[`B`,`A`];function Cl(e){switch(e){case`narrow`:return[...Sl];case`short`:return[...xl];case`long`:return[...bl];default:return null}}function wl(e){return yl[e.hour<12?0:1]}function Tl(e,t){return vl(t)[e.weekday-1]}function El(e,t){return ml(t)[e.month-1]}function Dl(e,t){return Cl(t)[e.year<0?0:1]}function Ol(e,t,n=`always`,r=!1){let i={years:[`year`,`yr.`],quarters:[`quarter`,`qtr.`],months:[`month`,`mo.`],weeks:[`week`,`wk.`],days:[`day`,`day`,`days`],hours:[`hour`,`hr.`],minutes:[`minute`,`min.`],seconds:[`second`,`sec.`]},a=[`hours`,`minutes`,`seconds`].indexOf(e)===-1;if(n===`auto`&&a){let n=e===`days`;switch(t){case 1:return n?`tomorrow`:`next ${i[e][0]}`;case-1:return n?`yesterday`:`last ${i[e][0]}`;case 0:return n?`today`:`this ${i[e][0]}`}}let o=Object.is(t,-0)||t<0,s=Math.abs(t),c=s===1,l=i[e],u=r?c?l[1]:l[2]||l[1]:c?i[e][0]:e;return o?`${s} ${u} ago`:`in ${s} ${u}`}function kl(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var Al={D:Jo,DD:Yo,DDD:Zo,DDDD:Qo,t:$o,tt:es,ttt:ts,tttt:ns,T:rs,TT:is,TTT:as,TTTT:os,f:ss,ff:ls,fff:fs,ffff:ms,F:cs,FF:us,FFF:ps,FFFF:hs},jl=class e{static create(t,n={}){return new e(t,n)}static parseFormat(e){let t=null,n=``,r=!1,i=[];for(let a=0;a<e.length;a++){let o=e.charAt(a);o===`'`?((n.length>0||r)&&i.push({literal:r||/^\s+$/.test(n),val:n===``?`'`:n}),t=null,n=``,r=!r):r||o===t?n+=o:(n.length>0&&i.push({literal:/^\s+$/.test(n),val:n}),n=o,t=o)}return n.length>0&&i.push({literal:r||/^\s+$/.test(n),val:n}),i}static macroTokenToFormatOpts(e){return Al[e]}constructor(e,t){this.opts=t,this.loc=e,this.systemLoc=null}formatWithSystemDefault(e,t){return this.systemLoc===null&&(this.systemLoc=this.loc.redefaultToSystem()),this.systemLoc.dtFormatter(e,{...this.opts,...t}).format()}dtFormatter(e,t={}){return this.loc.dtFormatter(e,{...this.opts,...t})}formatDateTime(e,t){return this.dtFormatter(e,t).format()}formatDateTimeParts(e,t){return this.dtFormatter(e,t).formatToParts()}formatInterval(e,t){return this.dtFormatter(e.start,t).dtf.formatRange(e.start.toJSDate(),e.end.toJSDate())}resolvedOptions(e,t){return this.dtFormatter(e,t).resolvedOptions()}num(e,t=0,n=void 0){if(this.opts.forceSimple)return qc(e,t);let r={...this.opts};return t>0&&(r.padTo=t),n&&(r.signDisplay=n),this.loc.numberFormatter(r).format(e)}formatDateTimeFromString(t,n){let r=this.loc.listingMode()===`en`,i=this.loc.outputCalendar&&this.loc.outputCalendar!==`gregory`,a=(e,n)=>this.loc.extract(t,e,n),o=e=>t.isOffsetFixed&&t.offset===0&&e.allowZ?`Z`:t.isValid?t.zone.formatOffset(t.ts,e.format):``,s=()=>r?wl(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?El(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?Tl(t,e):a(n?{weekday:e}:{weekday:e,month:`long`,day:`numeric`},`weekday`),u=n=>{let r=e.macroTokenToFormatOpts(n);return r?this.formatWithSystemDefault(t,r):n},d=e=>r?Dl(t,e):a({era:e},`era`);return kl(e.parseFormat(n),e=>{switch(e){case`S`:return this.num(t.millisecond);case`u`:case`SSS`:return this.num(t.millisecond,3);case`s`:return this.num(t.second);case`ss`:return this.num(t.second,2);case`uu`:return this.num(Math.floor(t.millisecond/10),2);case`uuu`:return this.num(Math.floor(t.millisecond/100));case`m`:return this.num(t.minute);case`mm`:return this.num(t.minute,2);case`h`:return this.num(t.hour%12==0?12:t.hour%12);case`hh`:return this.num(t.hour%12==0?12:t.hour%12,2);case`H`:return this.num(t.hour);case`HH`:return this.num(t.hour,2);case`Z`:return o({format:`narrow`,allowZ:this.opts.allowZ});case`ZZ`:return o({format:`short`,allowZ:this.opts.allowZ});case`ZZZ`:return o({format:`techie`,allowZ:this.opts.allowZ});case`ZZZZ`:return t.zone.offsetName(t.ts,{format:`short`,locale:this.loc.locale});case`ZZZZZ`:return t.zone.offsetName(t.ts,{format:`long`,locale:this.loc.locale});case`z`:return t.zoneName;case`a`:return s();case`d`:return i?a({day:`numeric`},`day`):this.num(t.day);case`dd`:return i?a({day:`2-digit`},`day`):this.num(t.day,2);case`c`:return this.num(t.weekday);case`ccc`:return l(`short`,!0);case`cccc`:return l(`long`,!0);case`ccccc`:return l(`narrow`,!0);case`E`:return this.num(t.weekday);case`EEE`:return l(`short`,!1);case`EEEE`:return l(`long`,!1);case`EEEEE`:return l(`narrow`,!1);case`L`:return i?a({month:`numeric`,day:`numeric`},`month`):this.num(t.month);case`LL`:return i?a({month:`2-digit`,day:`numeric`},`month`):this.num(t.month,2);case`LLL`:return c(`short`,!0);case`LLLL`:return c(`long`,!0);case`LLLLL`:return c(`narrow`,!0);case`M`:return i?a({month:`numeric`},`month`):this.num(t.month);case`MM`:return i?a({month:`2-digit`},`month`):this.num(t.month,2);case`MMM`:return c(`short`,!1);case`MMMM`:return c(`long`,!1);case`MMMMM`:return c(`narrow`,!1);case`y`:return i?a({year:`numeric`},`year`):this.num(t.year);case`yy`:return i?a({year:`2-digit`},`year`):this.num(t.year.toString().slice(-2),2);case`yyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,4);case`yyyyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,6);case`G`:return d(`short`);case`GG`:return d(`long`);case`GGGGG`:return d(`narrow`);case`kk`:return this.num(t.weekYear.toString().slice(-2),2);case`kkkk`:return this.num(t.weekYear,4);case`W`:return this.num(t.weekNumber);case`WW`:return this.num(t.weekNumber,2);case`n`:return this.num(t.localWeekNumber);case`nn`:return this.num(t.localWeekNumber,2);case`ii`:return this.num(t.localWeekYear.toString().slice(-2),2);case`iiii`:return this.num(t.localWeekYear,4);case`o`:return this.num(t.ordinal);case`ooo`:return this.num(t.ordinal,3);case`q`:return this.num(t.quarter);case`qq`:return this.num(t.quarter,2);case`X`:return this.num(Math.floor(t.ts/1e3));case`x`:return this.num(t.ts);default:return u(e)}})}formatDurationFromString(t,n){let r=this.opts.signMode===`negativeLargestOnly`?-1:1,i=e=>{switch(e[0]){case`S`:return`milliseconds`;case`s`:return`seconds`;case`m`:return`minutes`;case`h`:return`hours`;case`d`:return`days`;case`w`:return`weeks`;case`M`:return`months`;case`y`:return`years`;default:return null}},a=(e,t)=>n=>{let a=i(n);if(a){let i=t.isNegativeDuration&&a!==t.largestUnit?r:1,o;return o=this.opts.signMode===`negativeLargestOnly`&&a!==t.largestUnit?`never`:this.opts.signMode===`all`?`always`:`auto`,this.num(e.get(a)*i,n.length,o)}else return n},o=e.parseFormat(n),s=o.reduce((e,{literal:t,val:n})=>t?e:e.concat(n),[]),c=t.shiftTo(...s.map(i).filter(e=>e));return kl(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Ml=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Nl(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Pl(...e){return t=>e.reduce(([e,n,r],i)=>{let[a,o,s]=i(t,r);return[{...e,...a},o||n,s]},[{},null,1]).slice(0,2)}function Fl(e,...t){if(e==null)return[null,null];for(let[n,r]of t){let t=n.exec(e);if(t)return r(t)}return[null,null]}function Il(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Jc(t[n+i]);return[r,null,n+i]}}var Ll=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Rl=`(?:${Ll.source}?(?:\\[(${Ml.source})\\])?)?`,zl=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Bl=RegExp(`${zl.source}${Rl}`),Vl=RegExp(`(?:[Tt]${Bl.source})?`),Hl=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Ul=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Wl=/(\d{4})-?(\d{3})/,Gl=Il(`weekYear`,`weekNumber`,`weekDay`),Kl=Il(`year`,`ordinal`),ql=/(\d{4})-(\d\d)-(\d\d)/,Jl=RegExp(`${zl.source} ?(?:${Ll.source}|(${Ml.source}))?`),Yl=RegExp(`(?: ${Jl.source})?`);function Xl(e,t,n){let r=e[t];return x(r)?n:Jc(r)}function Zl(e,t){return[{year:Xl(e,t),month:Xl(e,t+1,1),day:Xl(e,t+2,1)},null,t+3]}function Ql(e,t){return[{hours:Xl(e,t,0),minutes:Xl(e,t+1,0),seconds:Xl(e,t+2,0),milliseconds:Xc(e[t+3])},null,t+4]}function $l(e,t){let n=!e[t]&&!e[t+1],r=ol(e[t+1],e[t+2]);return[{},n?null:Qs.instance(r),t+3]}function eu(e,t){return[{},e[t]?Ts.create(e[t]):null,t+1]}var tu=RegExp(`^T?${zl.source}$`),nu=/^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;function ru(e){let[t,n,r,i,a,o,s,c,l]=e,u=t[0]===`-`,d=c&&c[0]===`-`,f=(e,t=!1)=>e!==void 0&&(t||e&&u)?-e:e;return[{years:f(Yc(n)),months:f(Yc(r)),weeks:f(Yc(i)),days:f(Yc(a)),hours:f(Yc(o)),minutes:f(Yc(s)),seconds:f(Yc(c),c===`-0`),milliseconds:f(Xc(l),d)}]}var iu={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function au(e,t,n,r,i,a,o){let s={year:t.length===2?il(Jc(t)):Jc(t),month:fl.indexOf(n)+1,day:Jc(r),hour:Jc(i),minute:Jc(a)};return o&&(s.second=Jc(o)),e&&(s.weekday=e.length>3?hl.indexOf(e)+1:gl.indexOf(e)+1),s}var ou=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;function su(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=au(t,i,r,n,a,o,s),p;return p=c?iu[c]:l?0:ol(u,d),[f,new Qs(p)]}function cu(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var lu=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,uu=/^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,du=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;function fu(e){let[,t,n,r,i,a,o,s]=e;return[au(t,i,r,n,a,o,s),Qs.utcInstance]}function pu(e){let[,t,n,r,i,a,o,s]=e;return[au(t,s,n,r,i,a,o),Qs.utcInstance]}var mu=Nl(Hl,Vl),hu=Nl(Ul,Vl),gu=Nl(Wl,Vl),_u=Nl(Bl),vu=Pl(Zl,Ql,$l,eu),yu=Pl(Gl,Ql,$l,eu),bu=Pl(Kl,Ql,$l,eu),xu=Pl(Ql,$l,eu);function Su(e){return Fl(e,[mu,vu],[hu,yu],[gu,bu],[_u,xu])}function Cu(e){return Fl(cu(e),[ou,su])}function wu(e){return Fl(e,[lu,fu],[uu,fu],[du,pu])}function Tu(e){return Fl(e,[nu,ru])}var Eu=Pl(Ql);function Du(e){return Fl(e,[tu,Eu])}var Ou=Nl(ql,Yl),ku=Nl(Jl),Au=Pl(Ql,$l,eu);function ju(e){return Fl(e,[Ou,vu],[ku,Au])}var Mu=`Invalid Duration`,Nu={weeks:{days:7,hours:168,minutes:10080,seconds:10080*60,milliseconds:10080*60*1e3},days:{hours:24,minutes:1440,seconds:1440*60,milliseconds:1440*60*1e3},hours:{minutes:60,seconds:3600,milliseconds:3600*1e3},minutes:{seconds:60,milliseconds:60*1e3},seconds:{milliseconds:1e3}},Pu={years:{quarters:4,months:12,weeks:52,days:365,hours:365*24,minutes:365*24*60,seconds:365*24*60*60,milliseconds:365*24*60*60*1e3},quarters:{months:3,weeks:13,days:91,hours:2184,minutes:2184*60,seconds:2184*60*60,milliseconds:2184*60*60*1e3},months:{weeks:4,days:30,hours:720,minutes:720*60,seconds:720*60*60,milliseconds:720*60*60*1e3},...Nu},Fu=146097/400,Iu=146097/4800,Lu={years:{quarters:4,months:12,weeks:Fu/7,days:Fu,hours:Fu*24,minutes:Fu*24*60,seconds:Fu*24*60*60,milliseconds:Fu*24*60*60*1e3},quarters:{months:3,weeks:Fu/28,days:Fu/4,hours:Fu*24/4,minutes:Fu*24*60/4,seconds:Fu*24*60*60/4,milliseconds:Fu*24*60*60*1e3/4},months:{weeks:Iu/7,days:Iu,hours:Iu*24,minutes:Iu*24*60,seconds:Iu*24*60*60,milliseconds:Iu*24*60*60*1e3},...Nu},Ru=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],zu=Ru.slice(0).reverse();function Bu(e,t,n=!1){return new Wu({values:n?t.values:{...e.values,...t.values||{}},loc:e.loc.clone(t.loc),conversionAccuracy:t.conversionAccuracy||e.conversionAccuracy,matrix:t.matrix||e.matrix})}function Vu(e,t){let n=t.milliseconds??0;for(let r of zu.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Hu(e,t){let n=Vu(e,t)<0?-1:1;Ru.reduceRight((r,i)=>{if(x(t[i]))return r;if(r){let a=t[r]*n,o=e[i][r],s=Math.floor(a/o);t[i]+=s*n,t[r]-=s*o*n}return i},null),Ru.reduce((n,r)=>{if(x(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Uu(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Wu=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Lu:Pu;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||Xs.create(),this.conversionAccuracy=t?`longterm`:`casual`,this.invalid=e.invalid||null,this.matrix=n,this.isLuxonDuration=!0}static fromMillis(t,n){return e.fromObject({milliseconds:t},n)}static fromObject(t,n={}){if(typeof t!=`object`||!t)throw new Wo(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:cl(t,e.normalizeUnit),loc:Xs.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Pc(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Wo(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=Tu(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static fromISOTime(t,n){let[r]=Du(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static invalid(t,n=null){if(!t)throw new Wo(`need to specify a reason the Duration is invalid`);let r=t instanceof _c?t:new _c(t,n);if(gc.throwOnInvalid)throw new Vo(r);return new e({invalid:r})}static normalizeUnit(e){let t={year:`years`,years:`years`,quarter:`quarters`,quarters:`quarters`,month:`months`,months:`months`,week:`weeks`,weeks:`weeks`,day:`days`,days:`days`,hour:`hours`,hours:`hours`,minute:`minutes`,minutes:`minutes`,second:`seconds`,seconds:`seconds`,millisecond:`milliseconds`,milliseconds:`milliseconds`}[e&&e.toLowerCase()];if(!t)throw new Uo(e);return t}static isDuration(e){return e&&e.isLuxonDuration||!1}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}toFormat(e,t={}){let n={...t,floor:t.round!==!1&&t.floor!==!1};return this.isValid?jl.create(this.loc,n).formatDurationFromString(this,e):Mu}toHuman(e={}){if(!this.isValid)return Mu;let t=e.showZeros!==!1,n=Ru.map(n=>{let r=this.values[n];return x(r)||r===0&&!t?null:this.loc.numberFormatter({style:`unit`,unitDisplay:`long`,...e,unit:n.slice(0,-1)}).format(r)}).filter(e=>e);return this.loc.listFormatter({type:`conjunction`,style:e.listStyle||`narrow`,...e}).format(n)}toObject(){return this.isValid?{...this.values}:{}}toISO(){if(!this.isValid)return null;let e=`P`;return this.years!==0&&(e+=this.years+`Y`),(this.months!==0||this.quarters!==0)&&(e+=this.months+this.quarters*3+`M`),this.weeks!==0&&(e+=this.weeks+`W`),this.days!==0&&(e+=this.days+`D`),(this.hours!==0||this.minutes!==0||this.seconds!==0||this.milliseconds!==0)&&(e+=`T`),this.hours!==0&&(e+=this.hours+`H`),this.minutes!==0&&(e+=this.minutes+`M`),(this.seconds!==0||this.milliseconds!==0)&&(e+=Zc(this.seconds+this.milliseconds/1e3,3)+`S`),e===`P`&&(e+=`T0S`),e}toISOTime(e={}){if(!this.isValid)return null;let t=this.toMillis();return t<0||t>=864e5?null:(e={suppressMilliseconds:!1,suppressSeconds:!1,includePrefix:!1,format:`extended`,...e,includeOffset:!1},Yd.fromMillis(t,{zone:`UTC`}).toISOTime(e))}toJSON(){return this.toISO()}toString(){return this.toISO()}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Duration { values: ${JSON.stringify(this.values)} }`:`Duration { Invalid, reason: ${this.invalidReason} }`}toMillis(){return this.isValid?Vu(this.matrix,this.values):NaN}valueOf(){return this.toMillis()}plus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t),r={};for(let e of Ru)(Uc(n.values,e)||Uc(this.values,e))&&(r[e]=n.get(e)+this.get(e));return Bu(this,{values:r},!0)}minus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t);return this.plus(n.negate())}mapUnits(e){if(!this.isValid)return this;let t={};for(let n of Object.keys(this.values))t[n]=sl(e(this.values[n],n));return Bu(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...cl(t,e.normalizeUnit)};return Bu(this,{values:n})}reconfigure({locale:e,numberingSystem:t,conversionAccuracy:n,matrix:r}={}){let i={loc:this.loc.clone({locale:e,numberingSystem:t}),matrix:r,conversionAccuracy:n};return Bu(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Hu(this.matrix,e),Bu(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Uu(this.normalize().shiftToAll().toObject());return Bu(this,{values:e},!0)}shiftTo(...t){if(!this.isValid||t.length===0)return this;t=t.map(t=>e.normalizeUnit(t));let n={},r={},i=this.toObject(),a;for(let e of Ru)if(t.indexOf(e)>=0){a=e;let t=0;for(let n in r)t+=this.matrix[n][e]*r[n],r[n]=0;Pc(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Pc(i[e])&&(r[e]=i[e]);for(let e in r)r[e]!==0&&(n[a]+=e===a?r[e]:r[e]/this.matrix[a][e]);return Hu(this.matrix,n),Bu(this,{values:n},!0)}shiftToAll(){return this.isValid?this.shiftTo(`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`):this}negate(){if(!this.isValid)return this;let e={};for(let t of Object.keys(this.values))e[t]=this.values[t]===0?0:-this.values[t];return Bu(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Uu(this.values);return Bu(this,{values:e},!0)}get years(){return this.isValid?this.values.years||0:NaN}get quarters(){return this.isValid?this.values.quarters||0:NaN}get months(){return this.isValid?this.values.months||0:NaN}get weeks(){return this.isValid?this.values.weeks||0:NaN}get days(){return this.isValid?this.values.days||0:NaN}get hours(){return this.isValid?this.values.hours||0:NaN}get minutes(){return this.isValid?this.values.minutes||0:NaN}get seconds(){return this.isValid?this.values.seconds||0:NaN}get milliseconds(){return this.isValid?this.values.milliseconds||0:NaN}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}equals(e){if(!this.isValid||!e.isValid||!this.loc.equals(e.loc))return!1;function t(e,t){return e===void 0||e===0?t===void 0||t===0:e===t}for(let n of Ru)if(!t(this.values[n],e.values[n]))return!1;return!0}},Gu=`Invalid Interval`;function Ku(e,t){return!e||!e.isValid?qu.invalid(`missing or invalid start`):!t||!t.isValid?qu.invalid(`missing or invalid end`):t<e?qu.invalid(`end before start`,`The end of an interval must be after its start, but you had start=${e.toISO()} and end=${t.toISO()}`):null}var qu=class e{constructor(e){this.s=e.start,this.e=e.end,this.invalid=e.invalid||null,this.isLuxonInterval=!0}static invalid(t,n=null){if(!t)throw new Wo(`need to specify a reason the Interval is invalid`);let r=t instanceof _c?t:new _c(t,n);if(gc.throwOnInvalid)throw new Bo(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=Xd(t),i=Xd(n);return Ku(r,i)??new e({start:r,end:i})}static after(t,n){let r=Wu.fromDurationLike(n),i=Xd(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Wu.fromDurationLike(n),i=Xd(t);return e.fromDateTimes(i.minus(r),i)}static fromISO(t,n){let[r,i]=(t||``).split(`/`,2);if(r&&i){let t,a;try{t=Yd.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=Yd.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Wu.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Wu.fromISO(r,n);if(t.isValid)return e.before(o,t)}}return e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static isInterval(e){return e&&e.isLuxonInterval||!1}get start(){return this.isValid?this.s:null}get end(){return this.isValid?this.e:null}get lastDateTime(){return this.isValid&&this.e?this.e.minus(1):null}get isValid(){return this.invalidReason===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}length(e=`milliseconds`){return this.isValid?this.toDuration(e).get(e):NaN}count(e=`milliseconds`,t){if(!this.isValid)return NaN;let n=this.start.startOf(e,t),r;return r=t?.useLocaleWeeks?this.end.reconfigure({locale:n.locale}):this.end,r=r.startOf(e,t),Math.floor(r.diff(n,e).get(e))+(r.valueOf()!==this.end.valueOf())}hasSame(e){return this.isValid?this.isEmpty()||this.e.minus(1).hasSame(this.s,e):!1}isEmpty(){return this.s.valueOf()===this.e.valueOf()}isAfter(e){return this.isValid?this.s>e:!1}isBefore(e){return this.isValid?this.e<=e:!1}contains(e){return this.isValid?this.s<=e&&this.e>e:!1}set({start:t,end:n}={}){return this.isValid?e.fromDateTimes(t||this.s,n||this.e):this}splitAt(...t){if(!this.isValid)return[];let n=t.map(Xd).filter(e=>this.contains(e)).sort((e,t)=>e.toMillis()-t.toMillis()),r=[],{s:i}=this,a=0;for(;i<this.e;){let t=n[a]||this.e,o=+t>+this.e?this.e:t;r.push(e.fromDateTimes(i,o)),i=o,a+=1}return r}splitBy(t){let n=Wu.fromDurationLike(t);if(!this.isValid||!n.isValid||n.as(`milliseconds`)===0)return[];let{s:r}=this,i=1,a,o=[];for(;r<this.e;){let t=this.start.plus(n.mapUnits(e=>e*i));a=+t>+this.e?this.e:t,o.push(e.fromDateTimes(r,a)),r=a,i+=1}return o}divideEqually(e){return this.isValid?this.splitBy(this.length()/e).slice(0,e):[]}overlaps(e){return this.e>e.s&&this.s<e.e}abutsStart(e){return this.isValid?+this.e==+e.s:!1}abutsEnd(e){return this.isValid?+e.e==+this.s:!1}engulfs(e){return this.isValid?this.s<=e.s&&this.e>=e.e:!1}equals(e){return!this.isValid||!e.isValid?!1:this.s.equals(e.s)&&this.e.equals(e.e)}intersection(t){if(!this.isValid)return this;let n=this.s>t.s?this.s:t.s,r=this.e<t.e?this.e:t.e;return n>=r?null:e.fromDateTimes(n,r)}union(t){if(!this.isValid)return this;let n=this.s<t.s?this.s:t.s,r=this.e>t.e?this.e:t.e;return e.fromDateTimes(n,r)}static merge(e){let[t,n]=e.sort((e,t)=>e.s-t.s).reduce(([e,t],n)=>t?t.overlaps(n)||t.abutsStart(n)?[e,t.union(n)]:[e.concat([t]),n]:[e,n],[[],null]);return n&&t.push(n),t}static xor(t){let n=null,r=0,i=[],a=t.map(e=>[{time:e.s,type:`s`},{time:e.e,type:`e`}]),o=Array.prototype.concat(...a).sort((e,t)=>e.time-t.time);for(let t of o)r+=t.type===`s`?1:-1,r===1?n=t.time:(n&&+n!=+t.time&&i.push(e.fromDateTimes(n,t.time)),n=null);return e.merge(i)}difference(...t){return e.xor([this].concat(t)).map(e=>this.intersection(e)).filter(e=>e&&!e.isEmpty())}toString(){return this.isValid?`[${this.s.toISO()} – ${this.e.toISO()})`:Gu}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`:`Interval { Invalid, reason: ${this.invalidReason} }`}toLocaleString(e=Jo,t={}){return this.isValid?jl.create(this.s.loc.clone(t),e).formatInterval(this):Gu}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Gu}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Gu}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Gu}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Gu}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Wu.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Ju=class{static hasDST(e=gc.defaultZone){let t=Yd.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return Ts.isValidZone(e)}static normalizeZone(e){return ec(e,gc.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||Xs.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||Xs.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||Xs.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||Xs.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||Xs.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||Xs.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||Xs.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return Xs.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return Xs.create(t,null,`gregory`).eras(e)}static features(){return{relative:Rc(),localeWeek:zc()}}};function Yu(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Wu.fromMillis(r).as(`days`))}function Xu(e,t,n){let r=[[`years`,(e,t)=>t.year-e.year],[`quarters`,(e,t)=>t.quarter-e.quarter+(t.year-e.year)*4],[`months`,(e,t)=>t.month-e.month+(t.year-e.year)*12],[`weeks`,(e,t)=>{let n=Yu(e,t);return(n-n%7)/7}],[`days`,Yu]],i={},a=e,o,s;for(let[c,l]of r)n.indexOf(c)>=0&&(o=c,i[c]=l(e,t),s=a.plus(i),s>t?(i[c]--,e=a.plus(i),e>t&&(s=e,i[c]--,e=a.plus(i))):e=s);return[e,i,s,o]}function Zu(e,t,n,r){let[i,a,o,s]=Xu(e,t,n),c=t-i,l=n.filter(e=>[`hours`,`minutes`,`seconds`,`milliseconds`].indexOf(e)>=0);l.length===0&&(o<t&&(o=i.plus({[s]:1})),o!==i&&(a[s]=(a[s]||0)+c/(o-i)));let u=Wu.fromObject(a,r);return l.length>0?Wu.fromMillis(c,r).shiftTo(...l).plus(u):u}var Qu=`missing Intl.DateTimeFormat.formatToParts support`;function S(e,t=e=>e){return{regex:e,deser:([e])=>t(ic(e))}}var $u=`[ \xA0]`,ed=new RegExp($u,`g`);function td(e){return e.replace(/\./g,`\\.?`).replace(ed,$u)}function nd(e){return e.replace(/\./g,``).replace(ed,` `).toLowerCase()}function rd(e,t){return e===null?null:{regex:RegExp(e.map(td).join(`|`)),deser:([n])=>e.findIndex(e=>nd(n)===nd(e))+t}}function id(e,t){return{regex:e,deser:([,e,t])=>ol(e,t),groups:t}}function ad(e){return{regex:e,deser:([e])=>e}}function od(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function sd(e,t){let n=sc(t),r=sc(t,`{2}`),i=sc(t,`{3}`),a=sc(t,`{4}`),o=sc(t,`{6}`),s=sc(t,`{1,2}`),c=sc(t,`{1,3}`),l=sc(t,`{1,6}`),u=sc(t,`{1,9}`),d=sc(t,`{2,4}`),f=sc(t,`{4,6}`),p=e=>({regex:RegExp(od(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return rd(t.eras(`short`),0);case`GG`:return rd(t.eras(`long`),0);case`y`:return S(l);case`yy`:return S(d,il);case`yyyy`:return S(a);case`yyyyy`:return S(f);case`yyyyyy`:return S(o);case`M`:return S(s);case`MM`:return S(r);case`MMM`:return rd(t.months(`short`,!0),1);case`MMMM`:return rd(t.months(`long`,!0),1);case`L`:return S(s);case`LL`:return S(r);case`LLL`:return rd(t.months(`short`,!1),1);case`LLLL`:return rd(t.months(`long`,!1),1);case`d`:return S(s);case`dd`:return S(r);case`o`:return S(c);case`ooo`:return S(i);case`HH`:return S(r);case`H`:return S(s);case`hh`:return S(r);case`h`:return S(s);case`mm`:return S(r);case`m`:return S(s);case`q`:return S(s);case`qq`:return S(r);case`s`:return S(s);case`ss`:return S(r);case`S`:return S(c);case`SSS`:return S(i);case`u`:return ad(u);case`uu`:return ad(s);case`uuu`:return S(n);case`a`:return rd(t.meridiems(),0);case`kkkk`:return S(a);case`kk`:return S(d,il);case`W`:return S(s);case`WW`:return S(r);case`E`:case`c`:return S(n);case`EEE`:return rd(t.weekdays(`short`,!1),1);case`EEEE`:return rd(t.weekdays(`long`,!1),1);case`ccc`:return rd(t.weekdays(`short`,!0),1);case`cccc`:return rd(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return id(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return id(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return ad(/[a-z_+-/]{1,256}?/i);case` `:return ad(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:Qu};return m.token=e,m}var cd={year:{"2-digit":`yy`,numeric:`yyyyy`},month:{numeric:`M`,"2-digit":`MM`,short:`MMM`,long:`MMMM`},day:{numeric:`d`,"2-digit":`dd`},weekday:{short:`EEE`,long:`EEEE`},dayperiod:`a`,dayPeriod:`a`,hour12:{numeric:`h`,"2-digit":`hh`},hour24:{numeric:`H`,"2-digit":`HH`},minute:{numeric:`m`,"2-digit":`mm`},second:{numeric:`s`,"2-digit":`ss`},timeZoneName:{long:`ZZZZZ`,short:`ZZZ`}};function ld(e,t,n){let{type:r,value:i}=e;if(r===`literal`){let e=/^\s+$/.test(i);return{literal:!e,val:e?` `:i}}let a=t[r],o=r;r===`hour`&&(o=t.hour12==null?t.hourCycle==null?n.hour12?`hour12`:`hour24`:t.hourCycle===`h11`||t.hourCycle===`h12`?`hour12`:`hour24`:t.hour12?`hour12`:`hour24`);let s=cd[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function ud(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function dd(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Uc(n,i)){let a=n[i],o=a.groups?a.groups+1:1;!a.literal&&a.token&&(e[a.token.val[0]]=a.deser(r.slice(t,t+o))),t+=o}return[r,e]}else return[r,{}]}function fd(e){let t=e=>{switch(e){case`S`:return`millisecond`;case`s`:return`second`;case`m`:return`minute`;case`h`:case`H`:return`hour`;case`d`:return`day`;case`o`:return`ordinal`;case`L`:case`M`:return`month`;case`y`:return`year`;case`E`:case`c`:return`weekday`;case`W`:return`weekNumber`;case`k`:return`weekYear`;case`q`:return`quarter`;default:return null}},n=null,r;return x(e.z)||(n=Ts.create(e.z)),x(e.Z)||(n||=new Qs(e.Z),r=e.Z),x(e.q)||(e.M=(e.q-1)*3+1),x(e.h)||(e.h<12&&e.a===1?e.h+=12:e.h===12&&e.a===0&&(e.h=0)),e.G===0&&e.y&&(e.y=-e.y),x(e.u)||(e.S=Xc(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var pd=null;function md(){return pd||=Yd.fromMillis(1555555555555),pd}function hd(e,t){if(e.literal)return e;let n=bd(jl.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function gd(e,t){return Array.prototype.concat(...e.map(e=>hd(e,t)))}var _d=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=gd(jl.parseFormat(t),e),this.units=this.tokens.map(t=>sd(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=ud(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=dd(e,this.regex,this.handlers),[r,i,a]=n?fd(n):[null,null,void 0];if(Uc(n,`a`)&&Uc(n,`H`))throw new Ho(`Can't include meridiem when specifying 24-hour format`);return{input:e,tokens:this.tokens,regex:this.regex,rawMatches:t,matches:n,result:r,zone:i,specificOffset:a}}else return{input:e,tokens:this.tokens,invalidReason:this.invalidReason}}get isValid(){return!this.disqualifyingUnit}get invalidReason(){return this.disqualifyingUnit?this.disqualifyingUnit.invalidReason:null}};function vd(e,t,n){return new _d(e,n).explainFromTokens(t)}function yd(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=vd(e,t,n);return[r,i,a,o]}function bd(e,t){if(!e)return null;let n=jl.create(t,e).dtFormatter(md()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>ld(t,e,i))}var xd=`Invalid DateTime`,Sd=864e13;function Cd(e){return new _c(`unsupported zone`,`the zone "${e.name}" is not supported`)}function wd(e){return e.weekData===null&&(e.weekData=Tc(e.c)),e.weekData}function Td(e){return e.localWeekData===null&&(e.localWeekData=Tc(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function Ed(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new Yd({...n,...t,old:n})}function Dd(e,t,n){let r=e-t*60*1e3,i=n.offset(r);if(t===i)return[r,t];r-=(i-t)*60*1e3;let a=n.offset(r);return i===a?[r,i]:[e-Math.min(i,a)*60*1e3,Math.max(i,a)]}function Od(e,t){e+=t*60*1e3;let n=new Date(e);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),millisecond:n.getUTCMilliseconds()}}function kd(e,t,n){return Dd(tl(e),t,n)}function Ad(e,t){let n=e.o,r=e.c.year+Math.trunc(t.years),i=e.c.month+Math.trunc(t.months)+Math.trunc(t.quarters)*3,a={...e.c,year:r,month:i,day:Math.min(e.c.day,el(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Wu.fromObject({years:t.years-Math.trunc(t.years),quarters:t.quarters-Math.trunc(t.quarters),months:t.months-Math.trunc(t.months),weeks:t.weeks-Math.trunc(t.weeks),days:t.days-Math.trunc(t.days),hours:t.hours,minutes:t.minutes,seconds:t.seconds,milliseconds:t.milliseconds}).as(`milliseconds`),[s,c]=Dd(tl(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function jd(e,t,n,r,i,a){let{setZone:o,zone:s}=n;if(e&&Object.keys(e).length!==0||t){let r=t||s,i=Yd.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return Yd.invalid(new _c(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function Md(e,t,n=!0){return e.isValid?jl.create(Xs.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function Nd(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=qc(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=qc(e.c.month),n===`month`)return i;i+=`-`}else if(i+=qc(e.c.month),n===`month`)return i;return i+=qc(e.c.day),i}function Pd(e,t,n,r,i,a,o){let s=!n||e.c.millisecond!==0||e.c.second!==0,c=``;switch(o){case`day`:case`month`:case`year`:break;default:if(c+=qc(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=qc(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=qc(e.c.second))}else{if(c+=qc(e.c.minute),o===`minute`)break;s&&(c+=qc(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=qc(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=qc(Math.trunc(-e.o/60)),c+=`:`,c+=qc(Math.trunc(-e.o%60))):(c+=`+`,c+=qc(Math.trunc(e.o/60)),c+=`:`,c+=qc(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Fd={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Id={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Ld={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Rd=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],zd=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],Bd=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function Vd(e){let t={year:`year`,years:`year`,month:`month`,months:`month`,day:`day`,days:`day`,hour:`hour`,hours:`hour`,minute:`minute`,minutes:`minute`,quarter:`quarter`,quarters:`quarter`,second:`second`,seconds:`second`,millisecond:`millisecond`,milliseconds:`millisecond`,weekday:`weekday`,weekdays:`weekday`,weeknumber:`weekNumber`,weeksnumber:`weekNumber`,weeknumbers:`weekNumber`,weekyear:`weekYear`,weekyears:`weekYear`,ordinal:`ordinal`}[e.toLowerCase()];if(!t)throw new Uo(e);return t}function Hd(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return Vd(e)}}function Ud(e){if(qd===void 0&&(qd=gc.now()),e.type!==`iana`)return e.offset(qd);let t=e.name,n=Jd.get(t);return n===void 0&&(n=e.offset(qd),Jd.set(t,n)),n}function Wd(e,t){let n=ec(t.zone,gc.defaultZone);if(!n.isValid)return Yd.invalid(Cd(n));let r=Xs.fromObject(t),i,a;if(x(e.year))i=gc.now();else{for(let t of Rd)x(e[t])&&(e[t]=Fd[t]);let t=Mc(e)||Nc(e);if(t)return Yd.invalid(t);let r=Ud(n);[i,a]=kd(e,r,n)}return new Yd({ts:i,zone:n,loc:r,o:a})}function Gd(e,t,n){let r=x(n.round)?!0:n.round,i=x(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Zc(e,r||n.calendary?0:2,n.calendary?`round`:i),t.loc.clone(n).relFormatter(n).format(e,a)),o=r=>n.calendary?t.hasSame(e,r)?0:t.startOf(r).diff(e.startOf(r),r).get(r):t.diff(e,r).get(r);if(n.unit)return a(o(n.unit),n.unit);for(let e of n.units){let t=o(e);if(Math.abs(t)>=1)return a(t,e)}return a(e>t?-0:0,n.units[n.units.length-1])}function Kd(e){let t={},n;return e.length>0&&typeof e[e.length-1]==`object`?(t=e[e.length-1],n=Array.from(e).slice(0,e.length-1)):n=Array.from(e),[t,n]}var qd,Jd=new Map,Yd=class e{constructor(e){let t=e.zone||gc.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new _c(`invalid input`):null)||(t.isValid?null:Cd(t));this.ts=x(e.ts)?gc.now():e.ts;let r=null,i=null;if(!n)if(e.old&&e.old.ts===this.ts&&e.old.zone.equals(t))[r,i]=[e.old.c,e.old.o];else{let a=Pc(e.o)&&!e.old?e.o:t.offset(this.ts);r=Od(this.ts,a),n=Number.isNaN(r.year)?new _c(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||Xs.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=Kd(arguments),[n,r,i,a,o,s,c]=t;return Wd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=Kd(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Qs.utcInstance,Wd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Lc(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=ec(n.zone,gc.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:Xs.fromObject(n)}):e.invalid(Cd(i))}static fromMillis(t,n={}){if(!Pc(t))throw new Wo(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>Sd?e.invalid(`Timestamp out of range`):new e({ts:t,zone:ec(n.zone,gc.defaultZone),loc:Xs.fromObject(n)})}static fromSeconds(t,n={}){if(Pc(t))return new e({ts:t*1e3,zone:ec(n.zone,gc.defaultZone),loc:Xs.fromObject(n)});throw new Wo(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=ec(n.zone,gc.defaultZone);if(!r.isValid)return e.invalid(Cd(r));let i=Xs.fromObject(n),a=cl(t,Hd),{minDaysInFirstWeek:o,startOfWeek:s}=kc(a,i),c=gc.now(),l=x(n.specificOffset)?r.offset(c):n.specificOffset,u=!x(a.ordinal),d=!x(a.year),f=!x(a.month)||!x(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new Ho(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Ho(`Can't mix ordinal dates with month/day`);let h=m||a.weekday&&!p,ee,te,ne=Od(c,l);h?(ee=zd,te=Id,ne=Tc(ne,o,s)):u?(ee=Bd,te=Ld,ne=Dc(ne)):(ee=Rd,te=Fd);let re=!1;for(let e of ee){let t=a[e];x(t)?re?a[e]=te[e]:a[e]=ne[e]:re=!0}let ie=(h?Ac(a,o,s):u?jc(a):Mc(a))||Nc(a);if(ie)return e.invalid(ie);let[ae,oe]=kd(h?Ec(a,o,s):u?Oc(a):a,l,r),se=new e({ts:ae,zone:r,o:oe,loc:i});return a.weekday&&p&&t.weekday!==se.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${se.toISO()}`):se.isValid?se:e.invalid(se.invalid)}static fromISO(e,t={}){let[n,r]=Su(e);return jd(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=Cu(e);return jd(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=wu(e);return jd(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(x(t)||x(n))throw new Wo(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=yd(Xs.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):jd(o,s,r,`format ${n}`,t,c)}static fromString(t,n,r={}){return e.fromFormat(t,n,r)}static fromSQL(e,t={}){let[n,r]=ju(e);return jd(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Wo(`need to specify a reason the DateTime is invalid`);let r=t instanceof _c?t:new _c(t,n);if(gc.throwOnInvalid)throw new zo(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=bd(e,Xs.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return gd(jl.parseFormat(e),Xs.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){qd=void 0,Jd.clear()}get(e){return this[e]}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}get outputCalendar(){return this.isValid?this.loc.outputCalendar:null}get zone(){return this._zone}get zoneName(){return this.isValid?this.zone.name:null}get year(){return this.isValid?this.c.year:NaN}get quarter(){return this.isValid?Math.ceil(this.c.month/3):NaN}get month(){return this.isValid?this.c.month:NaN}get day(){return this.isValid?this.c.day:NaN}get hour(){return this.isValid?this.c.hour:NaN}get minute(){return this.isValid?this.c.minute:NaN}get second(){return this.isValid?this.c.second:NaN}get millisecond(){return this.isValid?this.c.millisecond:NaN}get weekYear(){return this.isValid?wd(this).weekYear:NaN}get weekNumber(){return this.isValid?wd(this).weekNumber:NaN}get weekday(){return this.isValid?wd(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?Td(this).weekday:NaN}get localWeekNumber(){return this.isValid?Td(this).weekNumber:NaN}get localWeekYear(){return this.isValid?Td(this).weekYear:NaN}get ordinal(){return this.isValid?Dc(this.c).ordinal:NaN}get monthShort(){return this.isValid?Ju.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Ju.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Ju.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Ju.weekdays(`long`,{locObj:this.loc})[this.weekday-1]:null}get offset(){return this.isValid?+this.o:NaN}get offsetNameShort(){return this.isValid?this.zone.offsetName(this.ts,{format:`short`,locale:this.locale}):null}get offsetNameLong(){return this.isValid?this.zone.offsetName(this.ts,{format:`long`,locale:this.locale}):null}get isOffsetFixed(){return this.isValid?this.zone.isUniversal:null}get isInDST(){return this.isOffsetFixed?!1:this.offset>this.set({month:1,day:1}).offset||this.offset>this.set({month:5}).offset}getPossibleOffsets(){if(!this.isValid||this.isOffsetFixed)return[this];let e=864e5,t=6e4,n=tl(this.c),r=this.zone.offset(n-e),i=this.zone.offset(n+e),a=this.zone.offset(n-r*t),o=this.zone.offset(n-i*t);if(a===o)return[this];let s=n-a*t,c=n-o*t,l=Od(s,a),u=Od(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[Ed(this,{ts:s}),Ed(this,{ts:c})]:[this]}get isInLeapYear(){return Qc(this.year)}get daysInMonth(){return el(this.year,this.month)}get daysInYear(){return this.isValid?$c(this.year):NaN}get weeksInWeekYear(){return this.isValid?rl(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?rl(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=jl.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Qs.instance(e),t)}toLocal(){return this.setZone(gc.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=ec(t,gc.defaultZone),t.equals(this.zone))return this;if(t.isValid){let e=this.ts;if(n||r){let n=t.offset(this.ts),r=this.toObject();[e]=kd(r,n,t)}return Ed(this,{ts:e,zone:t})}else return e.invalid(Cd(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return Ed(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=cl(e,Hd),{minDaysInFirstWeek:n,startOfWeek:r}=kc(t,this.loc),i=!x(t.weekYear)||!x(t.weekNumber)||!x(t.weekday),a=!x(t.ordinal),o=!x(t.year),s=!x(t.month)||!x(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new Ho(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Ho(`Can't mix ordinal dates with month/day`);let u;i?u=Ec({...Tc(this.c,n,r),...t},n,r):x(t.ordinal)?(u={...this.toObject(),...t},x(t.day)&&(u.day=Math.min(el(u.year,u.month),u.day))):u=Oc({...Dc(this.c),...t});let[d,f]=kd(u,this.o,this.zone);return Ed(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Wu.fromDurationLike(e);return Ed(this,Ad(this,t))}minus(e){if(!this.isValid)return this;let t=Wu.fromDurationLike(e).negate();return Ed(this,Ad(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Wu.normalizeUnit(e);switch(r){case`years`:n.month=1;case`quarters`:case`months`:n.day=1;case`weeks`:case`days`:n.hour=0;case`hours`:n.minute=0;case`minutes`:n.second=0;case`seconds`:n.millisecond=0;break}if(r===`weeks`)if(t){let e=this.loc.getStartOfWeek(),{weekday:t}=this;t<e&&(n.weekNumber=this.weekNumber-1),n.weekday=e}else n.weekday=1;return r===`quarters`&&(n.month=(Math.ceil(this.month/3)-1)*3+1),this.set(n)}endOf(e,t){return this.isValid?this.plus({[e]:1}).startOf(e,t).minus(1):this}toFormat(e,t={}){return this.isValid?jl.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):xd}toLocaleString(e=Jo,t={}){return this.isValid?jl.create(this.loc.clone(t),e).formatDateTime(this):xd}toLocaleParts(e={}){return this.isValid?jl.create(this.loc.clone(e),e).formatDateTimeParts(this):[]}toISO({format:e=`extended`,suppressSeconds:t=!1,suppressMilliseconds:n=!1,includeOffset:r=!0,extendedZone:i=!1,precision:a=`milliseconds`}={}){if(!this.isValid)return null;a=Vd(a);let o=e===`extended`,s=Nd(this,o,a);return Rd.indexOf(a)>=3&&(s+=`T`),s+=Pd(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?Nd(this,e===`extended`,Vd(t)):null}toISOWeekDate(){return Md(this,`kkkk-'W'WW-c`)}toISOTime({suppressMilliseconds:e=!1,suppressSeconds:t=!1,includeOffset:n=!0,includePrefix:r=!1,extendedZone:i=!1,format:a=`extended`,precision:o=`milliseconds`}={}){return this.isValid?(o=Vd(o),(r&&Rd.indexOf(o)>=3?`T`:``)+Pd(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return Md(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return Md(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?Nd(this,!0):null}toSQLTime({includeOffset:e=!0,includeZone:t=!1,includeOffsetSpace:n=!0}={}){let r=`HH:mm:ss.SSS`;return(t||e)&&(n&&(r+=` `),t?r+=`z`:e&&(r+=`ZZ`)),Md(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():xd}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`:`DateTime { Invalid, reason: ${this.invalidReason} }`}valueOf(){return this.toMillis()}toMillis(){return this.isValid?this.ts:NaN}toSeconds(){return this.isValid?this.ts/1e3:NaN}toUnixInteger(){return this.isValid?Math.floor(this.ts/1e3):NaN}toJSON(){return this.toISO()}toBSON(){return this.toJSDate()}toObject(e={}){if(!this.isValid)return{};let t={...this.c};return e.includeConfig&&(t.outputCalendar=this.outputCalendar,t.numberingSystem=this.loc.numberingSystem,t.locale=this.loc.locale),t}toJSDate(){return new Date(this.isValid?this.ts:NaN)}diff(e,t=`milliseconds`,n={}){if(!this.isValid||!e.isValid)return Wu.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Bc(t).map(Wu.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Zu(a?this:e,a?e:this,i,r);return a?o.negate():o}diffNow(t=`milliseconds`,n={}){return this.diff(e.now(),t,n)}until(e){return this.isValid?qu.fromDateTimes(this,e):this}hasSame(e,t,n){if(!this.isValid)return!1;let r=e.valueOf(),i=this.setZone(e.zone,{keepLocalTime:!0});return i.startOf(t,n)<=r&&r<=i.endOf(t,n)}equals(e){return this.isValid&&e.isValid&&this.valueOf()===e.valueOf()&&this.zone.equals(e.zone)&&this.loc.equals(e.loc)}toRelative(t={}){if(!this.isValid)return null;let n=t.base||e.fromObject({},{zone:this.zone}),r=t.padding?this<n?-t.padding:t.padding:0,i=[`years`,`months`,`days`,`hours`,`minutes`,`seconds`],a=t.unit;return Array.isArray(t.unit)&&(i=t.unit,a=void 0),Gd(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?Gd(t.base||e.fromObject({},{zone:this.zone}),this,{...t,numeric:`auto`,units:[`years`,`months`,`days`],calendary:!0}):null}static min(...t){if(!t.every(e.isDateTime))throw new Wo(`min requires all arguments be DateTimes`);return Vc(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Wo(`max requires all arguments be DateTimes`);return Vc(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return vd(Xs.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new _d(Xs.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(x(t)||x(n))throw new Wo(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=Xs.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Wo(`fromFormatParser called with a locale of ${o}, but the format parser was created for ${n.locale}`);let{result:s,zone:c,specificOffset:l,invalidReason:u}=n.explainFromTokens(t);return u?e.invalid(u):jd(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Jo}static get DATE_MED(){return Yo}static get DATE_MED_WITH_WEEKDAY(){return Xo}static get DATE_FULL(){return Zo}static get DATE_HUGE(){return Qo}static get TIME_SIMPLE(){return $o}static get TIME_WITH_SECONDS(){return es}static get TIME_WITH_SHORT_OFFSET(){return ts}static get TIME_WITH_LONG_OFFSET(){return ns}static get TIME_24_SIMPLE(){return rs}static get TIME_24_WITH_SECONDS(){return is}static get TIME_24_WITH_SHORT_OFFSET(){return as}static get TIME_24_WITH_LONG_OFFSET(){return os}static get DATETIME_SHORT(){return ss}static get DATETIME_SHORT_WITH_SECONDS(){return cs}static get DATETIME_MED(){return ls}static get DATETIME_MED_WITH_SECONDS(){return us}static get DATETIME_MED_WITH_WEEKDAY(){return ds}static get DATETIME_FULL(){return fs}static get DATETIME_FULL_WITH_SECONDS(){return ps}static get DATETIME_HUGE(){return ms}static get DATETIME_HUGE_WITH_SECONDS(){return hs}};function Xd(e){if(Yd.isDateTime(e))return e;if(e&&e.valueOf&&Pc(e.valueOf()))return Yd.fromJSDate(e);if(e&&typeof e==`object`)return Yd.fromObject(e);throw new Wo(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function Zd(e){if(e===`*`)return{min:1,max:`*`};let[t,n]=e.split(`..`),r=Number(t);return n===void 0?{min:r,max:r}:{min:r,max:n===`*`?`*`:Number(n)}}var Qd=`1`,$d=`0..1`,ef=`*`,tf=`0..*`,nf=new Map([[`-`,[`1`,`1`]],[`<>`,[`*`,`*`]],[`>`,[`*`,`1`]],[`<`,[`1`,`*`]],[`-?`,[`1`,$d]],[`?-`,[$d,`1`]],[`?-?`,[$d,$d]],[`?>`,[tf,`1`]],[`>?`,[`*`,$d]],[`?>?`,[tf,$d]],[`?<`,[$d,`*`]],[`<?`,[`1`,tf]],[`?<?`,[$d,tf]],[`?<>`,[tf,`*`]],[`<>?`,[`*`,tf]],[`?<>?`,[tf,tf]]]),rf=new Map([...nf.entries()].map(([e,[t,n]])=>[`${t}-${n}`,e]));function af(e){return nf.get(e)}function of(e){return Zd(e).max===1}function sf(e){return Zd(e).max===`*`}function cf(e){return Zd(e).min===0}function lf(e){return Zd(e).min>=1}function uf(e){return e.replace(/\?/g,``)}function df(e,t){return rf.get(`${e}-${t}`)??`<>`}function ff(e){let{min:t,max:n}=Zd(e);return t===0?e:n===`*`?tf:$d}function pf(e){let{min:t,max:n}=Zd(e);return t>=1?e:n===`*`?`*`:`1`}function mf(e){let{min:t,max:n}=Zd(e);return n===`*`?e:t===0?tf:`*`}var C=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_DEP_CONTEXT=3042]=`INVALID_DEP_CONTEXT`,e[e.INVALID_DEP_FIELD=3043]=`INVALID_DEP_FIELD`,e[e.INVALID_NOTE_CONTEXT=3044]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3045]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3046]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3047]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3048]=`EMPTY_NOTE`,e[e.UNKNOWN_NOTE_SETTING=3049]=`UNKNOWN_NOTE_SETTING`,e[e.DUPLICATE_NOTE_SETTING=3050]=`DUPLICATE_NOTE_SETTING`,e[e.INVALID_NOTE_SETTING_VALUE=3051]=`INVALID_NOTE_SETTING_VALUE`,e[e.INVALID_INDEXES_CONTEXT=3052]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3053]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3054]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3055]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3056]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3057]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3058]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3059]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3060]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3061]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3062]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3063]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3064]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3065]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3066]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3067]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3069]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3070]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3071]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3072]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3073]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3074]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3075]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3076]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3077]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3078]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3079]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3080]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3081]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3082]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3083]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3084]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3085]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3086]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.UNKNOWN_RECORDS_SETTING=3087]=`UNKNOWN_RECORDS_SETTING`,e[e.DUPLICATE_RECORDS_SETTING=3088]=`DUPLICATE_RECORDS_SETTING`,e[e.INVALID_RECORDS_SETTING_VALUE=3089]=`INVALID_RECORDS_SETTING_VALUE`,e[e.INVALID_USE_CONTEXT=3090]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3091]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3092]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3093]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3094]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3095]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3096]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.DEP_SELF_LOOP=5003]=`DEP_SELF_LOOP`,e[e.DEP_MIXED_DOWNSTREAM_TABLES=5004]=`DEP_MIXED_DOWNSTREAM_TABLES`,e[e.DEP_DUPLICATE_DOWNSTREAM_TABLE=5005]=`DEP_DUPLICATE_DOWNSTREAM_TABLE`,e[e.DEP_MIXED_LEVEL=5006]=`DEP_MIXED_LEVEL`,e[e.UNEQUAL_FIELDS_BINARY_REF=5007]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5008]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5009]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e[e.INVALID_METADATA_TARGET_KIND=5010]=`INVALID_METADATA_TARGET_KIND`,e[e.INVALID_METADATA_FIELD=5011]=`INVALID_METADATA_FIELD`,e[e.DUPLICATE_METADATA_FIELD=5012]=`DUPLICATE_METADATA_FIELD`,e[e.UNKNOWN_ROLE=6e3]=`UNKNOWN_ROLE`,e[e.MISSING_NAME=6001]=`MISSING_NAME`,e[e.NO_CUSTOM_ROLE=6002]=`NO_CUSTOM_ROLE`,e[e.UNKNOWN_ENDPOINT=6003]=`UNKNOWN_ENDPOINT`,e[e.EMPTY_LINK=6004]=`EMPTY_LINK`,e[e.BAD_LINK=6005]=`BAD_LINK`,e[e.UNKNOWN_METADATA_TARGET=6006]=`UNKNOWN_METADATA_TARGET`,e[e.BAD_PROPERTY=6007]=`BAD_PROPERTY`,e[e.DUPLICATE_PROPERTY=6008]=`DUPLICATE_PROPERTY`,e[e.DIAGRAM_TYPE_NOT_HERE=6009]=`DIAGRAM_TYPE_NOT_HERE`,e[e.METADATA_ROLE_MISMATCH=6010]=`METADATA_ROLE_MISMATCH`,e[e.UNKNOWN_TYPE=6011]=`UNKNOWN_TYPE`,e[e.UNKNOWN_ICON=6012]=`UNKNOWN_ICON`,e[e.BAD_IMAGE=6013]=`BAD_IMAGE`,e[e.DUPLICATE_LINK=6014]=`DUPLICATE_LINK`,e[e.NESTED_ENDPOINTS=6015]=`NESTED_ENDPOINTS`,e}({}),hf=function(e){return e.RefColumnMismatch=`Mismatched optional ref constraints`,e.RecordValueTypeMismatch=`Record type errors`,e.RecordConstraintViolation=`Record constraint violations`,e.Other=`Other`,e}({}),w=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.details=i,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new gf(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},gf=class extends Error{constructor(e,t,n,r){super(t),this.code=e,this.diagnostic=t,this.details=r,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,w.prototype)}get filepath(){return this.nodeOrToken.filepath}},_f=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.details=i,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}get quickFixes(){return this.details?.quickFixes}get filepath(){return this.nodeOrToken.filepath}};function vf(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function yf(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function bf(e){let[t]=e;return yf(t)||vf(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function xf(e){return vf(e)||yf(e)}function Sf(e){let t=j(e);return t!==void 0&&t.length>0}function Cf(e){return wf(e)}function wf(e){return e instanceof Dm&&e.expression instanceof Em}function Tf(e){return!!e.bodyColon}function Ef(e){return e instanceof B&&e.op?.value===`~`&&D(e.expression)}function Df(e){return e!==void 0&&nf.has(e)}function Of(e){return e===`<-`||e===`->`}function kf(e){if(!(e instanceof Dm)||!(e.expression instanceof wm)||e.expression.literal?.kind!==v.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(!bf(t[e]))return!1;return!0}function Af(e){return kf(e)?!0:zf(e)&&e.expression.variable.value.toLowerCase()===`none`}function jf(e){if(E(e)||Mf(e)||zf(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof B&&yo.includes(e.op?.value)&&Mf(e.expression)||e instanceof ym)return!0;if(!e||!Bf(e))return!1;let t=ip(e);return t.length===2||t.length===3}function Mf(e){return e instanceof B?yo.includes(e.op.value)?Mf(e.expression):!1:e instanceof Dm&&e.expression instanceof wm&&e.expression.literal?.kind===v.NUMERIC_LITERAL}function Nf(e){if(!(e instanceof B)||!Df(e.op?.value))return!1;let t=j(e.expression);return t!==void 0&&t.length>0}function Pf(e){if(!(e instanceof B)||!Of(e.op?.value))return!1;let t=j(e.expression);return t!==void 0&&t.length>0}function Ff(e){return e instanceof bm&&e.elementList.every(D)}function If(e){if(!(e instanceof Cm||O(e)||e instanceof Dm||e instanceof km))return!1;for(;e instanceof Cm||e instanceof km;)if(e instanceof Cm){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Mf(e)||E(e)||zf(e)))return!1;e=e.callee}else if(e instanceof km){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Mf(e.name)))return!1;e=e.array}let t=j(e);return t!==void 0&&t.length>0}function Lf(e){return E(e)||kf(e)}function T(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof Dm){r.push(new w(C.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=ep(e.name)?.toLowerCase();if(!n)return;let i=t[n];i?i.push(e):t[n]=[e]}),new n(t,r)):new n(t)}function E(e){return e instanceof Dm&&(e.expression instanceof Em&&e.expression.variable instanceof Va&&e.expression.variable.kind===v.QUOTED_STRING||e.expression instanceof wm&&e.expression.literal?.kind===v.STRING_LITERAL)}function D(e){return e instanceof Dm&&e.expression instanceof Em&&e.expression.variable instanceof Va}function Rf(e){return e?e instanceof Tm:!1}function zf(e){return e instanceof Dm&&e.expression instanceof Em&&e.expression.variable?.kind===v.IDENTIFIER}function O(e){return e instanceof V&&e.leftExpression instanceof I&&e.rightExpression instanceof I&&e.op?.value===`.`}function Bf(e){return D(e)?!0:O(e)&&D(e.rightExpression)&&Bf(e.leftExpression)}function k(e,t){return e instanceof R&&e.isKind(t)}function Vf(e){return e instanceof mm}function Hf(e,t){return e instanceof hm&&(t===void 0||e.isKind(t))}function Uf(e){return e instanceof L}function A(e,...t){return e instanceof H&&e.parent instanceof R&&e.parent.isKind(...t)}function Wf(e,t){let n=e.parent;return n instanceof R&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Gf(e,t){let n=e.parentOfKind(H);if(!n||t<0)return!1;if(t===0)return n.callee?n.callee.containsEq(e):!1;let r=n.args[t-1];return r?r.containsEq(e):!1}function Kf(e){return!!e.parentOfKind(W)}function qf(e,t){let n=e.parentOfKind(z);return!n||(n.name instanceof Dm?N(n.name):ep(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function Jf(e){return!(e instanceof V)||!Df(e.op?.value)?!1:ap(e.leftExpression)!==void 0&&ap(e.rightExpression)!==void 0}function Yf(e){let t=ap(e.leftExpression),n=ap(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function Xf(e){return e instanceof Dm&&e.expression instanceof Em||e instanceof ym}function Zf(e){if(D(e))return e;if(O(e)){let t=e.rightExpression;if(t&&D(t))return t}}function Qf(e){let t=e.parentNode;return!O(t)||t.rightExpression!==e?!1:!(O(t.parentNode)&&t.parentNode.leftExpression===t)}function $f(e){if(D(e))return e.expression.variable}function ep(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function tp(e){if(!(e instanceof R))return;let t=j(e?.name);return t===void 0?void 0:t.join(`.`)}function np(e){return e.elementList.length===0}function rp(e){return e?.body?e.body instanceof U?e.body.body:[e.body]:[]}function ip(e){if(!e)return;if(!O(e))return[e];let t=ip(e.leftExpression);if(t)return t.push(e.rightExpression),t}function j(e){if(e===void 0)return;let t=ip(e);if(!t)return;let n=[];for(let e of t){let t=N(e);if(typeof t!=`string`)return;n.push(t)}return n}function ap(e){if(e===void 0)return;let t=ip(e);if(!t||t.length===0)return;let n=[];if(!D(g(t))){let e=t.pop();if(Ff(e))n=e.elementList;else return}let r=t;if(r.every(D))return{variables:r,tupleElements:n}}function op(e){if(Xf(e))return e instanceof ym?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof bm&&e.elementList.every(Xf))return{functional:e.elementList.filter(e=>e instanceof ym),nonFunctional:e.elementList.filter(D)}}function M(e){if(E(e))return e.expression instanceof Em?e?.expression?.variable?.value:e.expression.literal.value}function sp(e){return e instanceof Dm&&e.expression instanceof wm&&e.expression.literal?.kind===v.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function cp(e){if(!(e instanceof Cm)||!e.callee)return;let t=ip(e.callee);if(!t||t.length===0||!t.every(D))return;let n=[];return Ff(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function N(e){if(D(e))return e.expression.variable.value}function lp(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function up(e){if(e.name instanceof _m)return ep(e.name)?.toLowerCase();if(e.name instanceof Dm)return N(e.name)}function dp(e){return zf(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Om}function fp(e){return M(e)===``}function pp(e){return e instanceof ym}function mp(e){let t=sp(e);if(t!==null)return t;if(Mf(e)&&e instanceof B&&e.expression){let t=e.op?.value,n=sp(e.expression);if(n!==null)return t===`-`?-n:n}return null}function hp(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return+!!e;let t=mp(e);if(t!==null)return t;let n=M(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function gp(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return+!!e;let t=mp(e);if(t!==null)return Number.isInteger(t)?t:null;let n=M(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var _p=[`true`,`yes`,`y`,`t`,`1`],vp=[`false`,`no`,`n`,`f`,`0`];function yp(e){if(e==null)return null;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===0?!1:e===1?!0:null;if(typeof e==`string`){let t=e.toLowerCase();return _p.includes(t)?!0:vp.includes(t)?!1:null}if(zf(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=sp(e);if(t===0)return!1;if(t===1)return!0;let n=M(e)?.toLowerCase();if(n){if(_p.includes(n))return!0;if(vp.includes(n))return!1}return null}function bp(e){if(e==null)return null;if(typeof e==`string`)return e;let t=j(e);return t?g(t):M(e)??null}function xp(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=M(e)??null??hp(e)??yp(e);return t===null?null:t.toString()}var Sp=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Cp=[`yyyy-MM-dd HH:mm:ss`,`yyyy-MM-dd HH:mm:ss.SSS`,`yyyy-MM-dd HH:mm:ss.SSSZZ`,`yyyy-MM-dd HH:mm:ssZZ`],wp=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Tp(e){if(e==null)return null;let t=typeof e==`string`?e:M(e)??null;if(t===null)return null;for(let e of wp){let n=Yd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of Sp){let n=Yd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Cp){let n=Yd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=Yd.fromISO(t,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)});return null;function r(e){return e.zone.type!==`system`}}function Ep(e){return e instanceof B?`${e.op?.value}${Ep(e.expression)}`:e.expression.literal.value}function Dp(e){return e instanceof B?e.op?.value===`-`?-Dp(e.expression):Dp(e.expression):Number.parseFloat(e.expression.literal.value)}function P(e){return{start:{offset:e.startPos.offset,line:e.startPos.line+1,column:e.startPos.column+1},end:{offset:e.endPos.offset,line:e.endPos.line+1,column:e.endPos.column+1},filepath:e.filepath}}function Op(e){let t=e.split(`
2
2
  `),n=t.slice(t.findIndex(e=>e.trimStart()!==``)),r=n.filter(e=>e.trimStart());if(r.length===0)return n.join(`
3
3
  `);let i=Math.min(...r.map(e=>e.length-e.trimStart().length));return n.map(e=>e.slice(i)).join(`
4
- `)}function kp(e){let t=j(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function Ap(e){if(kf(e))return e.expression.literal.value;if(zf(e)&&N(e)?.toLowerCase()===`none`)return _o}function jp(e){if(e){if(E(e)){let t=M(e);if(t!==void 0)return{value:t,type:`string`}}if(Mf(e))return{type:`number`,value:Dp(e)};if(zf(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof xm&&e.value)return{value:e.value.value,type:`expression`};if(Bf(e)){let t=ip(e)?.at(-1),n=t?N(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function Mp(e,t){let r=``,i=null;if(t instanceof Tm){if(i=(t.argumentList?.elementList??[]).map(e=>Mf(e)?Ep(e):E(e)?M(e):N(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof Tm||t instanceof jm;)if(t instanceof Tm){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Mf(e)?Ep(e):E(e)?M(e):N(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof jm){if(r=`${`[${(t.indexer?.elementList??[]).map(e=>e?.name?.expression?.literal?.value??``).join(`,`)}]`}${r}`,!t.array)break;t=t.array}let{name:a,schemaName:o}=kp(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new w(C.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}function Np(e,t){let n=new Set(t.map(e=>e.toLowerCase())),r={};for(let[t,i]of Object.entries(e)){if(n.has(t.toLowerCase()))continue;let e=i[0],a=Pp(e.value);a!==void 0&&(r[t]=a)}return r}function Pp(e){if(!e)return;let t=M(e);if(t!==void 0)return t;let n=Ap(e);if(n!==void 0)return n}var F=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.StickyNote=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewTopLevelWildcard=`DiagramView top-level wildcard`,e.DiagramViewTable=`DiagramView table`,e.DiagramViewTableGroup=`DiagramView tablegroup`,e.DiagramViewNote=`DiagramView note`,e.DiagramViewSchema=`DiagramView schema`,e.Metadata=`Metadata`,e.Element=`Element`,e.Kind=`Kind`,e.Program=`Program`,e}({}),Fp={Table:`Table`,Enum:`Enum`,TableGroup:`TableGroup`,TablePartial:`TablePartial`,Note:`Note`,Schema:`Schema`},Ip=function(e){return e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.Note=`Note`,e}({}),Lp=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Rp=class{constructor({kind:e,declaration:t,name:n},r,i){this.id=r,this.kind=e,this.declaration=t,this.filepath=i,this.name=n}get originalFilepath(){return this.originalSymbol.filepath}intern(){return`symbol@${this.filepath.intern()}:${this.id}`}isKind(...e){return e.includes(this.kind)}canonicalName(e,t){return e.canonicalName(t,this).getValue()}interpretedName(e,t){if(!t)return{schema:null,name:this.name??``};let n=this.canonicalName(e,t);return n?{schema:n.schema===`public`?null:n.schema,name:n.name}:{schema:null,name:this.name??``}}settings(e){if(this.declaration)return e.nodeSettings(this.declaration).getFiltered(t)}get token(){if(this.declaration)return P(this.declaration)}references(e){return e.symbolReferences(this)}metadata(e){return e.symbolMetadata(this)}members(e){let n=e.symbolMembers(this);return n.hasValue(t)?[]:n.getValue()}},zp=class e extends Rp{constructor({name:e,parent:t},n,r){super({kind:`Schema`},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===y}inNestedSchema(t,n){let r=this.members(t);if(r.some(e=>e.originalSymbol===n.originalSymbol))return!0;for(let i of r)if(i instanceof e&&i.inNestedSchema(t,n))return!0;return!1}},Bp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Enum`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Vp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Enum field`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Op(M(i));if(a)return{value:a,token:P(r)}}},Hp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Table`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}schema(e){let t=this.canonicalName(e,this.filepath);return t?t.schema===`public`?null:t.schema:null}columns(e){return this.mergedColumns(e).filter(e=>!(e instanceof om))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(`Column`))}partialInjections(e){return this.members(e).filter(e=>e.isKind(`PartialInjection`))}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Op(M(i));if(a)return{value:a,token:P(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?Ap(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===Vh.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===Vh.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===Vh.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===Vh.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof V)||!Ef(n.declaration.callee))return[];let r=n.declaration.callee.expression;if(!r)return[];let i=e.nodeReferee(r).getFiltered(t);return i?[i]:[]})}mergedIndexes(e){let t=this.indexes(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===Vh.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===Vh.TableChecks));return[...t,...n]}mergedHeadercolor(e){let n=this.headercolor(e);for(let r of this.resolvedPartials(e)){if(!r.declaration)continue;let a=e.nodeSettings(r.declaration).getFiltered(t);a?.[i.HeaderColor]?.length&&(n=Ap(a[i.HeaderColor].at(0)?.value))}return n}mergedNote(e){let n=n=>{if(!n.declaration)return;let r=e.nodeSettings(n.declaration).getFiltered(t);if(!r?.note?.length)return;let i=r.note[0],a=i?.value;if(!a)return;let o=Op(M(a));if(o)return{value:o,token:P(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Up=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Column`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}qualifiedName(e){let n=this.name??``,r=(this instanceof om?this.injectionDeclaration:this.declaration)?.parentOfKind(R);if(!r)return[n];let i=e.nodeSymbol(r).getFiltered(t);if(!i)return[n];let{schema:a,name:o}=i.interpretedName(e,this.filepath);return a?[a,o,n]:[o,n]}pk(e){if(!this.declaration)return!1;let n=e.nodeSettings(this.declaration).getFiltered(t);return!!(n?.[i.PK]?.length||n?.[i.PrimaryKey]?.length)}isUniqueSet(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Unique]?.length:!1}unique(e){return this.isUniqueSet(e)||this.pk(e)||this.increment(e)}nullable(e){return this.declaration?!(this.pk(e)||this.increment(e)||this.isInPkIndex(e)||e.nodeSettings(this.declaration).getFiltered(t)?.[i.NotNull]?.length):!0}isInPkIndex(e){if(!this.declaration||!this.name)return!1;let n=(this instanceof om?this.injectionDeclaration:this.declaration).parentOfKind(R);if(!n)return!1;let r=e.nodeSymbol(n).getFiltered(t);if(!(r instanceof Hp))return!1;for(let t of r.mergedIndexes(e)){let n=e.interpretMetadata(t,this.filepath).getValue();if(!(!n||!Array.isArray(n))){for(let e of n)if(e.pk&&e.columns.some(e=>e.value===this.name))return!0}}return!1}isNotNullSet(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(n?.[i.NotNull]?.length)return!0;if(n?.[i.Null]?.length)return!1}isIncrementSet(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Increment]?.length:!1}increment(e){return this.isIncrementSet(e)||Io(this.type(e)?.name??``)}default(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t)?.[i.Default]?.at(0)?.value;if(n)return jp(n)}type(e){if(!(this.declaration instanceof V))return;let n=Mp(e,this.declaration.args[0]).getValue();if(!n)return;let r=n.args?n.args.split(`,`).map(e=>{let t=Number(e);return Number.isNaN(t)?e:t}):void 0,i=[],a=/\[([^\]]*)\]/g,o,s=n.type_name;for(;(o=a.exec(s))!==null;){let e=o[1];if(e===``)i.push(void 0);else{let t=Number(e);i.push(Number.isNaN(t)?e:t)}}let c=s.replace(/\[[^\]]*\]/g,``),l=e.nodeReferee(this.declaration.args[0]).getFiltered(t);return{name:c,enumSymbol:l instanceof Bp?l:void 0,args:r?.length?r:void 0,schema:n.schemaName??void 0,array:i.length?i:void 0}}checks(e){return this.metadata(e).filter(e=>e.kind===Vh.TableChecks)}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Op(M(i));if(a)return{value:a,token:P(r)}}},Wp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`TableGroup`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}fields(e){return this.members(e).filter(e=>e.isKind(`TableGroup field`))}color(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.color?.length?Ap(n.color.at(0)?.value):void 0}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Op(M(i));if(a)return{value:a,token:P(r)}}},Gp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`TableGroup field`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Kp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Element`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},qp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Kind`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Jp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Note`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Yp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`TablePartial`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Xp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`PartialInjection`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Zp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Qp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView top-level wildcard`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},$p=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView table`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},em=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView tablegroup`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},tm=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView note`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},nm=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView schema`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},rm=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Program`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}inNestedSchema(e,t){let n=this.members(e);if(n.some(e=>e.originalSymbol===t.originalSymbol))return!0;for(let r of n)if(r instanceof zp&&r.inNestedSchema(e,t))return!0;return!1}},im=class extends Rp{constructor({kind:e,declaration:t,aliasedSymbol:n,name:r},i,a){super({kind:e,declaration:t,name:r},i,a),this.aliasedSymbol=n}get canBeImported(){return this.aliasedSymbol.canBeImported}get originalSymbol(){return this.aliasedSymbol.originalSymbol}},am=class extends Rp{constructor({kind:e,declaration:t,useSpecifierDeclaration:n,usedSymbol:r,name:i},a,o){super({kind:e,declaration:t,name:i},a,o),this.useSpecifierDeclaration=n,this.usedSymbol=r}get canBeImported(){let e=this.useSpecifierDeclaration?.parentOfKind(hm);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},om=class extends Up{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}};function sm(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`as`}function cm(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`use`}function lm(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`metadata`}function um(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`from`}function dm(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function fm(e){return!!e?.isInvalid}var pm=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},I=class{constructor(e,t,n,r){this.id=e,this.kind=t,this.filepath=n;let i=r.find(e=>e!==void 0&&!Number.isNaN(e.start));i?(this.startPos=i.startPos,this.fullStart=i instanceof Va?Ka(i):i.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let a=[...r].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));a?(this.endPos=a.endPos,this.fullEnd=a instanceof Va?Ga(a):a.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}intern(){return`node@${this.filepath.intern()}:${this.id}`}get parent(){let e=this.parentNode;for(;e;){if(e instanceof R||e instanceof L)return e;e=e.parentNode}}parentOfKind(e){let t=this;for(;t;){if(t instanceof e)return t;t=t.parentNode}}strictlyContains(e){if(typeof e==`number`)return this.start<e&&this.end>e;let{start:t,end:n}=e,r=this.start<t,i=r||this.start===t,a=this.end>n,o=a||this.end===n;return r&&o||i&&a}containsEq(e){if(typeof e==`number`)return this.start<=e&&this.end>=e;let{start:t,end:n}=e;return this.start<=t&&this.end>=n}},mm=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.USE_DECLARATION=`<use-declaration>`,e.USE_SPECIFIER=`<use-specifier>`,e.USE_SPECIFIER_LIST=`<use-specifier-list>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifier-stream>`,e.LITERAL=`<literal>`,e.VARIABLE=`<variable>`,e.PREFIX_EXPRESSION=`<prefix-expression>`,e.INFIX_EXPRESSION=`<infix-expression>`,e.POSTFIX_EXPRESSION=`<postfix-expression>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.FUNCTION_APPLICATION=`<function-application>`,e.BLOCK_EXPRESSION=`<block-expression>`,e.LIST_EXPRESSION=`<list-expression>`,e.TUPLE_EXPRESSION=`<tuple-expression>`,e.CALL_EXPRESSION=`<call-expression>`,e.PRIMARY_EXPRESSION=`<primary-expression>`,e.GROUP_EXPRESSION=`<group-expression>`,e.COMMA_EXPRESSION=`<comma-expression>`,e.EMPTY=`<dummy>`,e.ARRAY=`<array>`,e.WILDCARD=`<wildcard>`,e}({}),L=class extends I{constructor({body:e=[],eof:t,source:n},r,i){super(r,`<program>`,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===`<element-declaration>`)}get uses(){return this.body.filter(e=>e.kind===`<use-declaration>`)}},hm=class extends I{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,`<use-declaration>`,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return dm(this.useKeyword)}},gm=class extends I{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,`<use-specifier>`,a,[e,t,n,r]),this.importKind=e,this.name=t,this.asKeyword=n,this.alias=r}isKind(...e){return this.importKind?.value!==void 0&&e.map(e=>e.toLowerCase()).includes(this.importKind.value.toLowerCase())}getSymbolKind(){let e=this.importKind?.value?.toLowerCase();if(e!==void 0)return this.archImport?e===`kind`?F.Kind:Object.values(Fp).find(t=>t.toLowerCase()===e)??F.Element:Object.values(F).find(t=>t.toLowerCase()===e)}},_m=class extends I{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,`<use-specifier-list>`,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},R=class e extends I{constructor({type:t,targetKind:n,name:r,as:i,alias:a,attributeList:o,bodyColon:s,body:c},l,u){if(super(l,`<element-declaration>`,u,[t,n,r,i,a,o,s,c]),c&&s&&!(c instanceof V||c instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.targetKind=n,this.name=r,this.as=i,this.alias=a,this.attributeList=o,this.bodyColon=s,this.body=c}isKind(...e){return e.some(e=>this.type?.value.toLowerCase()===e)}getElementKind(){return Object.values(r).find(e=>this.isKind(e))}},vm=class extends I{constructor({identifiers:e=[]},t,n){super(t,`<identifier-stream>`,n,e||[]),this.identifiers=e}},z=class extends I{constructor({name:e,colon:t,value:n},r,i){super(r,`<attribute>`,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},B=class extends I{constructor({op:e,expression:t},n,r){super(n,`<prefix-expression>`,r,[e,t]),this.op=e,this.expression=t}},ym=class extends I{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,`<infix-expression>`,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},bm=class extends I{constructor({op:e,expression:t},n,r){super(n,`<postfix-expression>`,r,[t,e]),this.op=e,this.expression=t}},xm=class extends I{constructor({value:e},t,n){super(t,`<function-expression>`,n,[e]),this.value=e}},V=class extends I{constructor({callee:e,args:t=[]},n,r){super(n,`<function-application>`,r,[e,...t]),this.callee=e,this.args=t}},H=class extends I{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,`<block-expression>`,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},U=class extends I{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,`<list-expression>`,a,[e,...Mm(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},Sm=class extends I{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,`<tuple-expression>`,a,[e,...Mm(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},Cm=class extends I{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,`<comma-expression>`,r,[...Mm(e,t)]),this.elementList=e,this.commaList=t}},wm=class extends Sm{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=`<group-expression>`}},Tm=class extends I{constructor({callee:e,argumentList:t},n,r){super(n,`<call-expression>`,r,[e,t]),this.callee=e,this.argumentList=t}},Em=class extends I{constructor({literal:e},t,n){super(t,`<literal>`,n,[e]),this.literal=e}},Dm=class extends I{constructor({token:e},t,n){super(t,`<wildcard>`,n,[e]),this.token=e}},Om=class extends I{constructor({variable:e},t,n){super(t,`<variable>`,n,[e]),this.variable=e}},km=class extends I{constructor({expression:e},t,n){super(t,`<primary-expression>`,n,[e]),this.expression=e}},Am=class extends I{constructor({prevToken:e},t,n){let r=Va.create(v.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,`<dummy>`,n,[r])}},jm=class extends I{constructor({expression:e,indexer:t},n,r){super(n,`<array>`,r,[e,t]),this.array=e,this.indexer=t}};function Mm(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?br(La(e,t)):br(La(t,e))).filter(e=>e!==null)}var Nm=function(e){return e.Table=`table`,e}({});function Pm(e,t,n){let r=t,i=e;if(i instanceof Tm&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!zf(i)||r.length===0)return;let a=[...r],o=$f(i),s=a.pop();if(!(s instanceof H))return;let c=g(a)instanceof U?a.pop():void 0;if(a.length===3){let e=$f(a[1]);return!e||!sm(e)?void 0:n.create(R,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(R,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(R,{type:o,attributeList:c,body:s})}function W(e){e&&(e instanceof Va?Fm(e):Im(e))}function Fm(e){e.kind!==v.EOF&&(e.isInvalid=!0)}function Im(e){if(e instanceof R)W(e.type),W(e.targetKind),W(e.name),W(e.as),W(e.alias),W(e.bodyColon),W(e.attributeList),W(e.body);else if(e instanceof vm)e.identifiers.forEach(W);else if(e instanceof z)W(e.name),W(e.colon),W(e.value);else if(e instanceof B)W(e.op),W(e.expression);else if(e instanceof ym)W(e.leftExpression),W(e.op),W(e.rightExpression);else if(e instanceof bm)W(e.op),W(e.expression);else if(e instanceof H)W(e.blockOpenBrace),e.body.forEach(W),W(e.blockCloseBrace);else if(e instanceof U)W(e.listOpenBracket),e.commaList.forEach(W),e.elementList.forEach(W),W(e.listCloseBracket);else if(e instanceof Sm)W(e.tupleOpenParen),e.commaList.forEach(W),e.elementList.forEach(W),W(e.tupleCloseParen);else if(e instanceof Cm)e.commaList.forEach(W),e.elementList.forEach(W);else if(e instanceof Tm)W(e.callee),W(e.argumentList);else if(e instanceof V)W(e.callee),e.args.forEach(W);else if(e instanceof km)W(e.expression);else if(e instanceof xm)W(e.value);else if(e instanceof Om)W(e.variable);else if(e instanceof Em)W(e.literal);else if(e instanceof wm)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof jm)W(e.array),W(e.indexer);else if(e instanceof L)e.body.forEach(W),W(e.eof);else if(!(e instanceof Am))if(e instanceof hm)W(e.useKeyword),W(e.specifiers),W(e.fromKeyword),W(e.importPath);else if(e instanceof _m)W(e.openBrace),e.specifiers.forEach(W),W(e.closeBrace);else if(e instanceof gm)W(e.importKind),W(e.name),W(e.asKeyword),W(e.alias);else if(e instanceof Dm)W(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Lm(...e){return e.filter(e=>e!==void 0)}function Rm(e){if(e instanceof L)return Lm(...e.body,e.eof);if(e instanceof R)return Lm(e.type,e.targetKind,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof z)return Lm(e.name,e.colon,e.value);if(e instanceof vm)return e.identifiers;if(e instanceof Em)return e.literal?[e.literal]:[];if(e instanceof Om)return Lm(e.variable);if(e instanceof B)return Lm(e.op,e.expression);if(e instanceof ym)return Lm(e.leftExpression,e.op,e.rightExpression);if(e instanceof bm)return Lm(e.expression,e.op);if(e instanceof xm)return Lm(e.value);if(e instanceof V)return Lm(e.callee,...e.args);if(e instanceof H)return Lm(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof U)return Lm(e.listOpenBracket,...zm(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof Sm)return Lm(e.tupleOpenParen,...zm(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof Cm)return Lm(...zm(e.elementList,e.commaList));if(e instanceof Tm)return Lm(e.callee,e.argumentList);if(e instanceof km)return Lm(e.expression);if(e instanceof jm)return Lm(e.array,e.indexer);if(e instanceof Am)return[];if(e instanceof hm)return Lm(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof _m)return Lm(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof gm)return Lm(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof Dm)return Lm(e.token);throw e instanceof wm?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function zm(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 Bm(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function Vm(e){if(!e)return[];if(D(e))return[{variables:[e],tupleElements:[]}];if(e instanceof ym){let t=ap(e);return t?[t]:[...Vm(e.leftExpression),...Vm(e.rightExpression)]}if(e instanceof B||e instanceof bm)return Vm(e.expression);if(e instanceof Sm){let t=ap(e);return t?[t]:e.elementList.flatMap(Vm)}return[]}function Hm(e,n){let r=n.parentNode;if(!r||!O(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;O(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Um(e,t,r,i){if(!D(r))return new n(void 0);let a=lp(r)??``;if(O(r.parentNode)&&r.parentNode.rightExpression===r&&Qf(r)){let t=Hm(e,r);if(!t)return new n(void 0);if(i===F.Column){if(t.isKind(F.Table)){let i=e.lookupMembers(t,F.Column,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${t.name}'`,r)])}return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist`,r)])}else{if(t.isKind(F.Schema)){let i=e.lookupMembers(t,F.Table,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist`,r)])}}let o=Hm(e,r);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,r)])}if(i===F.Column&&o.isKind(F.Table)){let t=e.lookupMembers(o,F.Column,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${o.name}'`,r)])}return new n(void 0)}let s=r.parentNode;if(s.leftExpression===r){if(O(s.parentNode)&&s.parentNode.leftExpression===s||i===F.Table){let i=e.lookupMembers(t,F.Schema,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist in Schema 'public'`,r)])}let o=e.lookupMembers(t,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Wm(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof zp&&e.isPublicSchema())}function Gm(e,n){let r=e.parseFile(n).getValue().ast;return e.nodeSymbol(r).getFiltered(t)}var Km=`server.function.container.database.cache.queue.disk.bucket.balancer.proxy.lock.key.gateway.globe.cloud.firewall.shield.router.switch.pipeline.chip.box.person.users.browser.mobile.laptop.desktop.terminal.mail.pulse.chart.clock.bell.search.settings.file.folder.tag.warning.check.rocket.webhook.stream.graph.robot.azure.windows.haproxy`.split(`.`),qm=`aws.gcp.digitalocean.hetzner.vultr.alibabacloud.oracle.heroku.railway.fly.render.postgres.mysql.mariadb.mongodb.sqlite.cockroachdb.cassandra.dynamodb.neo4j.influxdb.clickhouse.couchbase.planetscale.supabase.firebase.duckdb.rds.spanner.redis.kafka.rabbitmq.nats.sqs.celery.pubsub.elastic.opensearch.algolia.meilisearch.solr.snowflake.bigquery.redshift.databricks.hive.s3.minio.gcs.ceph.nginx.envoy.traefik.caddy.cloudflare.kong.fastly.akamai.docker.podman.kubernetes.openshift.containerd.nomad.consul.istio.lambda.workers.vercel.netlify.linux.ubuntu.debian.redhat.alpine.apple.apache.jfrog.harbor.grafana.prometheus.datadog.newrelic.sentry.opentelemetry.splunk.fluentd.logstash.pagerduty.opsgenie.slack.discord.jenkins.githubactions.gitlab.github.circleci.argo.airflow.dbt.airbyte.travisci.teamcity.buildkite.temporal.prefect.terraform.vault.onepassword.hashicorp.tailscale.wireguard.openvpn.zerotier.pfsense.chrome.firefox.safari.brave.android.ios.flutter.nodejs.python.golang.java.rust.ruby.php.dotnet.elixir.deno.bun.springboot.stripe`.split(`.`),Jm=[...Km,...qm],Ym={k8s:`kubernetes`,k9s:`kubernetes`,k8sio:`kubernetes`,postgresql:`postgres`,pg:`postgres`,psql:`postgres`,mongo:`mongodb`,node:`nodejs`,go:`golang`,elasticsearch:`elastic`,es:`elastic`,mq:`rabbitmq`,amqp:`rabbitmq`,tf:`terraform`,otel:`opentelemetry`,gha:`githubactions`,"1password":`onepassword`,do:`digitalocean`,google:`gcp`,gcloud:`gcp`,amazon:`aws`,ec2:`aws`,cdn:`globe`,internet:`cloud`,user:`person`,team:`users`,vpn:`lock`,monitor:`pulse`,metrics:`chart`,log:`file`,ci:`pipeline`,cron:`clock`,ai:`chip`,ml:`chip`},Xm=e=>Ym[e]??e,Zm=new Set(Jm),Qm=e=>Zm.has(Xm(e)),$m={Server:{icon:`server`,category:`compute`},Function:{icon:`function`,category:`compute`},Container:{icon:`container`,category:`compute`},Service:{icon:`chip`,category:`compute`},Registry:{icon:`container`,category:`compute`},Database:{icon:`database`,category:`data`},Cache:{icon:`cache`,category:`data`},Queue:{icon:`queue`,category:`data`},Topic:{icon:`stream`,category:`data`},Storage:{icon:`disk`,category:`data`},Bucket:{icon:`bucket`,category:`data`},Warehouse:{icon:`graph`,category:`data`},Search:{icon:`search`,category:`data`},LoadBalancer:{icon:`balancer`,category:`net`},Proxy:{icon:`proxy`,category:`net`},VPN:{icon:`lock`,category:`net`},Gateway:{icon:`gateway`,category:`net`},Firewall:{icon:`firewall`,category:`net`},Router:{icon:`router`,category:`net`},Secret:{icon:`key`,category:`net`},CDN:{icon:`globe`,category:`edge`},Internet:{icon:`cloud`,category:`edge`},Client:{icon:`person`,category:`people`},Browser:{icon:`browser`,category:`people`},Mobile:{icon:`mobile`,category:`people`},Team:{icon:`users`,category:`people`},Monitoring:{icon:`pulse`,category:`ops`},Logging:{icon:`file`,category:`ops`},Alerting:{icon:`bell`,category:`ops`},Scheduler:{icon:`clock`,category:`ops`},Pipeline:{icon:`pipeline`,category:`ops`}},eh=new Map(Object.keys($m).map(e=>[e.toLowerCase(),e])),th=e=>eh.get(e.toLowerCase());function nh(e){let t=e.toLowerCase();if(Qm(t))return`${e} is a brand, and a brand is a setting: Database name [type: '${t}']`;let n=Object.keys($m).filter(e=>{let n=e.toLowerCase();return n.startsWith(t)||t.startsWith(n)||n.includes(t)?!0:rh(n,t,2)}).slice(0,6);return n.length?`Did you mean: ${n.join(`, `)}?`:`Declare it: Kind ${e} [icon: box]`}function rh(e,t,n){if(Math.abs(e.length-t.length)>n)return!1;let r=Array.from({length:t.length+1},(e,t)=>t);for(let i=1;i<=e.length;i+=1){let a=[i],o=i;for(let n=1;n<=t.length;n+=1)a[n]=e[i-1]===t[n-1]?r[n-1]:1+Math.min(r[n-1],r[n],a[n-1]),o=Math.min(o,a[n]);if(o>n)return!1;r=a}return r[t.length]<=n}var ih=new Set([`Kind`,`Group`,`Note`,`Metadata`,`Link`,`Ref`,`use`,`Project`]),ah=new Set([...ih].map(e=>e.toLowerCase())),oh=e=>ah.has(e.toLowerCase());function sh(e){let t=e.toLowerCase(),n=[...Jm,...Object.keys(Ym)].filter(e=>e.startsWith(t)||t.startsWith(e)||e.includes(t)).slice(0,6);return n.length?`Did you mean: ${n.join(`, `)}?`:`The pack has ${Jm.length} marks; draw your own with [glyph: 'M...'].`}var ch={group:`group`,kind:`kind`,link:`link`,ref:`link`,metadata:`metadata`,project:`project`},lh=e=>e.type?.value;function uh(e){return e instanceof R&&e.parentNode instanceof L&&!!e.type}function dh(e){if(!uh(e))return;let t=e.type.value.toLowerCase();if(t!==`note`)return ch[t]??`node`}var fh=e=>uh(e)&&e.type.value.toLowerCase()===`note`;function ph(e){let t=e;for(;t;){if(uh(t))return t;t=t.parentNode}}function G(e){if(e){if(e instanceof km){if(e.expression instanceof Om)return e.expression.variable?.value;if(e.expression instanceof Em)return String(e.expression.literal?.value)}if(e instanceof vm)return e.identifiers?.map(e=>e.value).join(` `)}}var mh=e=>G(e.alias)??G(e.name);function hh(e){if(!(e instanceof km)||!(e.expression instanceof Em))return null;let t=e.expression.literal;if(t?.kind!==v.NUMERIC_LITERAL)return null;let n=Number(t.value);return Number.isFinite(n)?n:null}function gh(e){let t=hh(e);if(t!==null)return t;let n=G(e);if(n!==void 0)return n===`true`?!0:n===`false`?!1:n}var _h=new Set([`link`,`ref`]),vh=e=>_h.has(e.toLowerCase());function yh(e){let t={};for(let n of e?.elementList??[]){if(!(n instanceof z))continue;let e=G(n.name)?.toLowerCase();!e||_h.has(e)||(t[e]=n.value===void 0?!0:gh(n.value)??!0)}return t}function bh(e){return e.body?e.body instanceof H?[...e.body.body]:[e.body]:[]}function xh(e){if(!(e instanceof V))return;let t=[...e.args??[]],n=t[t.length-1]instanceof U?t.pop():void 0;return{callee:e.callee,args:t,settings:n}}function Sh(e){if(!(e instanceof ym))return;let t=e.op?.value;if(!(!t||!e.leftExpression||!e.rightExpression))return{left:e.leftExpression,op:t,right:e.rightExpression}}function Ch(e){let t=Sh(e);return t&&t.op===`.`?t.left:e}var wh=new Set([`>`,`<`,`<>`,`-`]);function Th(e){let[t]=bh(e);if(!t)return;let n=xh(t),r=Sh(n?.callee??t);if(!(!r||!wh.has(r.op)))return{row:n,infix:r}}function Eh(e){return _h.has(G(e.name)?.toLowerCase()??``)}function Dh(e){return(e.attributeList?.elementList??[]).filter(e=>e instanceof z&&Eh(e))}function Oh(e){let{value:t}=e;if(!(t instanceof B)||!t.expression)return;let n=t.op?.value;if(!(!n||!wh.has(n)))return{op:n,target:Ch(t.expression)}}function kh(e){if(e instanceof R){let t=lh(e);if(!t)return;let[n]=bh(e);if(!n)return{key:t,value:void 0};let r=xh(n);return{key:t,value:gh(r?r.callee??n:n)}}let t=xh(e),n=G(t?.callee);if(!n)return;let[r]=t?.args??[];return{key:n,value:r===void 0?void 0:gh(r)}}var Ah=e=>e instanceof R&&e.type?.value.toLowerCase()===`note`;function jh(e){return bh(e).find(Ah)}function Mh(e){return Nh(bh(e).map(e=>G(xh(e)?.callee)??``).join(` `))}function Nh(e){let t=e.split(`
4
+ `)}function kp(e){let t=j(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function Ap(e){if(kf(e))return e.expression.literal.value;if(zf(e)&&N(e)?.toLowerCase()===`none`)return _o}function jp(e){if(e){if(E(e)){let t=M(e);if(t!==void 0)return{value:t,type:`string`}}if(Mf(e))return{type:`number`,value:Dp(e)};if(zf(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof ym&&e.value)return{value:e.value.value,type:`expression`};if(Bf(e)){let t=ip(e)?.at(-1),n=t?N(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function Mp(e,t){let r=``,i=null;if(t instanceof Cm){if(i=(t.argumentList?.elementList??[]).map(e=>Mf(e)?Ep(e):E(e)?M(e):N(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof Cm||t instanceof km;)if(t instanceof Cm){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Mf(e)?Ep(e):E(e)?M(e):N(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof km){if(r=`${`[${(t.indexer?.elementList??[]).map(e=>e?.name?.expression?.literal?.value??``).join(`,`)}]`}${r}`,!t.array)break;t=t.array}let{name:a,schemaName:o}=kp(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new w(C.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}function Np(e,t){let n=new Set(t.map(e=>e.toLowerCase())),r={};for(let[t,i]of Object.entries(e)){if(n.has(t.toLowerCase()))continue;let e=i[0],a=Pp(e.value);a!==void 0&&(r[t]=a)}return r}function Pp(e){if(!e)return;let t=M(e);if(t!==void 0)return t;let n=Ap(e);if(n!==void 0)return n}var F=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.StickyNote=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewTopLevelWildcard=`DiagramView top-level wildcard`,e.DiagramViewTable=`DiagramView table`,e.DiagramViewTableGroup=`DiagramView tablegroup`,e.DiagramViewNote=`DiagramView note`,e.DiagramViewSchema=`DiagramView schema`,e.Metadata=`Metadata`,e.Element=`Element`,e.Program=`Program`,e}({}),Fp={Table:`Table`,Enum:`Enum`,TableGroup:`TableGroup`,TablePartial:`TablePartial`,Note:`Note`,Schema:`Schema`},Ip=function(e){return e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.Note=`Note`,e}({}),Lp=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Rp=class{constructor({kind:e,declaration:t,name:n},r,i){this.id=r,this.kind=e,this.declaration=t,this.filepath=i,this.name=n}get originalFilepath(){return this.originalSymbol.filepath}intern(){return`symbol@${this.filepath.intern()}:${this.id}`}isKind(...e){return e.includes(this.kind)}canonicalName(e,t){return e.canonicalName(t,this).getValue()}interpretedName(e,t){if(!t)return{schema:null,name:this.name??``};let n=this.canonicalName(e,t);return n?{schema:n.schema===`public`?null:n.schema,name:n.name}:{schema:null,name:this.name??``}}settings(e){if(this.declaration)return e.nodeSettings(this.declaration).getFiltered(t)}get token(){if(this.declaration)return P(this.declaration)}references(e){return e.symbolReferences(this)}metadata(e){return e.symbolMetadata(this)}members(e){let n=e.symbolMembers(this);return n.hasValue(t)?[]:n.getValue()}},zp=class e extends Rp{constructor({name:e,parent:t},n,r){super({kind:`Schema`},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===y}inNestedSchema(t,n){let r=this.members(t);if(r.some(e=>e.originalSymbol===n.originalSymbol))return!0;for(let i of r)if(i instanceof e&&i.inNestedSchema(t,n))return!0;return!1}},Bp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Enum`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Vp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Enum field`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Op(M(i));if(a)return{value:a,token:P(r)}}},Hp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Table`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}schema(e){let t=this.canonicalName(e,this.filepath);return t?t.schema===`public`?null:t.schema:null}columns(e){return this.mergedColumns(e).filter(e=>!(e instanceof am))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(`Column`))}partialInjections(e){return this.members(e).filter(e=>e.isKind(`PartialInjection`))}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Op(M(i));if(a)return{value:a,token:P(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?Ap(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===Sh.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===Sh.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===Sh.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===Sh.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof H)||!Ef(n.declaration.callee))return[];let r=n.declaration.callee.expression;if(!r)return[];let i=e.nodeReferee(r).getFiltered(t);return i?[i]:[]})}mergedIndexes(e){let t=this.indexes(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===Sh.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===Sh.TableChecks));return[...t,...n]}mergedHeadercolor(e){let n=this.headercolor(e);for(let r of this.resolvedPartials(e)){if(!r.declaration)continue;let a=e.nodeSettings(r.declaration).getFiltered(t);a?.[i.HeaderColor]?.length&&(n=Ap(a[i.HeaderColor].at(0)?.value))}return n}mergedNote(e){let n=n=>{if(!n.declaration)return;let r=e.nodeSettings(n.declaration).getFiltered(t);if(!r?.note?.length)return;let i=r.note[0],a=i?.value;if(!a)return;let o=Op(M(a));if(o)return{value:o,token:P(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Up=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Column`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}qualifiedName(e){let n=this.name??``,r=(this instanceof am?this.injectionDeclaration:this.declaration)?.parentOfKind(R);if(!r)return[n];let i=e.nodeSymbol(r).getFiltered(t);if(!i)return[n];let{schema:a,name:o}=i.interpretedName(e,this.filepath);return a?[a,o,n]:[o,n]}pk(e){if(!this.declaration)return!1;let n=e.nodeSettings(this.declaration).getFiltered(t);return!!(n?.[i.PK]?.length||n?.[i.PrimaryKey]?.length)}isUniqueSet(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Unique]?.length:!1}unique(e){return this.isUniqueSet(e)||this.pk(e)||this.increment(e)}nullable(e){return this.declaration?!(this.pk(e)||this.increment(e)||this.isInPkIndex(e)||e.nodeSettings(this.declaration).getFiltered(t)?.[i.NotNull]?.length):!0}isInPkIndex(e){if(!this.declaration||!this.name)return!1;let n=(this instanceof am?this.injectionDeclaration:this.declaration).parentOfKind(R);if(!n)return!1;let r=e.nodeSymbol(n).getFiltered(t);if(!(r instanceof Hp))return!1;for(let t of r.mergedIndexes(e)){let n=e.interpretMetadata(t,this.filepath).getValue();if(!(!n||!Array.isArray(n))){for(let e of n)if(e.pk&&e.columns.some(e=>e.value===this.name))return!0}}return!1}isNotNullSet(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(n?.[i.NotNull]?.length)return!0;if(n?.[i.Null]?.length)return!1}isIncrementSet(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Increment]?.length:!1}increment(e){return this.isIncrementSet(e)||Io(this.type(e)?.name??``)}default(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t)?.[i.Default]?.at(0)?.value;if(n)return jp(n)}type(e){if(!(this.declaration instanceof H))return;let n=Mp(e,this.declaration.args[0]).getValue();if(!n)return;let r=n.args?n.args.split(`,`).map(e=>{let t=Number(e);return Number.isNaN(t)?e:t}):void 0,i=[],a=/\[([^\]]*)\]/g,o,s=n.type_name;for(;(o=a.exec(s))!==null;){let e=o[1];if(e===``)i.push(void 0);else{let t=Number(e);i.push(Number.isNaN(t)?e:t)}}let c=s.replace(/\[[^\]]*\]/g,``),l=e.nodeReferee(this.declaration.args[0]).getFiltered(t);return{name:c,enumSymbol:l instanceof Bp?l:void 0,args:r?.length?r:void 0,schema:n.schemaName??void 0,array:i.length?i:void 0}}checks(e){return this.metadata(e).filter(e=>e.kind===Sh.TableChecks)}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Op(M(i));if(a)return{value:a,token:P(r)}}},Wp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`TableGroup`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}fields(e){return this.members(e).filter(e=>e.isKind(`TableGroup field`))}color(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.color?.length?Ap(n.color.at(0)?.value):void 0}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Op(M(i));if(a)return{value:a,token:P(r)}}},Gp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`TableGroup field`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Kp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Element`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},qp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Note`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Jp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`TablePartial`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Yp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`PartialInjection`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Xp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Zp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView top-level wildcard`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Qp=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView table`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},$p=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView tablegroup`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},em=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView note`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},tm=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView schema`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},nm=class extends Rp{constructor({declaration:e,name:t},n,r){super({kind:`Program`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}inNestedSchema(e,t){let n=this.members(e);if(n.some(e=>e.originalSymbol===t.originalSymbol))return!0;for(let r of n)if(r instanceof zp&&r.inNestedSchema(e,t))return!0;return!1}},rm=class extends Rp{constructor({kind:e,declaration:t,aliasedSymbol:n,name:r},i,a){super({kind:e,declaration:t,name:r},i,a),this.aliasedSymbol=n}get canBeImported(){return this.aliasedSymbol.canBeImported}get originalSymbol(){return this.aliasedSymbol.originalSymbol}},im=class extends Rp{constructor({kind:e,declaration:t,useSpecifierDeclaration:n,usedSymbol:r,name:i},a,o){super({kind:e,declaration:t,name:i},a,o),this.useSpecifierDeclaration=n,this.usedSymbol=r}get canBeImported(){let e=this.useSpecifierDeclaration?.parentOfKind(mm);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},am=class extends Up{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}};function om(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`as`}function sm(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`use`}function cm(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`metadata`}function lm(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`from`}function um(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function dm(e){return!!e?.isInvalid}var fm=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},I=class{constructor(e,t,n,r){this.id=e,this.kind=t,this.filepath=n;let i=r.find(e=>e!==void 0&&!Number.isNaN(e.start));i?(this.startPos=i.startPos,this.fullStart=i instanceof Va?Ka(i):i.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let a=[...r].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));a?(this.endPos=a.endPos,this.fullEnd=a instanceof Va?Ga(a):a.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}intern(){return`node@${this.filepath.intern()}:${this.id}`}get parent(){let e=this.parentNode;for(;e;){if(e instanceof R||e instanceof L)return e;e=e.parentNode}}parentOfKind(e){let t=this;for(;t;){if(t instanceof e)return t;t=t.parentNode}}strictlyContains(e){if(typeof e==`number`)return this.start<e&&this.end>e;let{start:t,end:n}=e,r=this.start<t,i=r||this.start===t,a=this.end>n,o=a||this.end===n;return r&&o||i&&a}containsEq(e){if(typeof e==`number`)return this.start<=e&&this.end>=e;let{start:t,end:n}=e;return this.start<=t&&this.end>=n}},pm=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.USE_DECLARATION=`<use-declaration>`,e.USE_SPECIFIER=`<use-specifier>`,e.USE_SPECIFIER_LIST=`<use-specifier-list>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifier-stream>`,e.LITERAL=`<literal>`,e.VARIABLE=`<variable>`,e.PREFIX_EXPRESSION=`<prefix-expression>`,e.INFIX_EXPRESSION=`<infix-expression>`,e.POSTFIX_EXPRESSION=`<postfix-expression>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.FUNCTION_APPLICATION=`<function-application>`,e.BLOCK_EXPRESSION=`<block-expression>`,e.LIST_EXPRESSION=`<list-expression>`,e.TUPLE_EXPRESSION=`<tuple-expression>`,e.CALL_EXPRESSION=`<call-expression>`,e.PRIMARY_EXPRESSION=`<primary-expression>`,e.GROUP_EXPRESSION=`<group-expression>`,e.COMMA_EXPRESSION=`<comma-expression>`,e.EMPTY=`<dummy>`,e.ARRAY=`<array>`,e.WILDCARD=`<wildcard>`,e}({}),L=class extends I{constructor({body:e=[],eof:t,source:n},r,i){super(r,`<program>`,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===`<element-declaration>`)}get uses(){return this.body.filter(e=>e.kind===`<use-declaration>`)}},mm=class extends I{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,`<use-declaration>`,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return um(this.useKeyword)}},hm=class extends I{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,`<use-specifier>`,a,[e,t,n,r]),this.importKind=e,this.name=t,this.asKeyword=n,this.alias=r}isKind(...e){return this.importKind?.value!==void 0&&e.map(e=>e.toLowerCase()).includes(this.importKind.value.toLowerCase())}getSymbolKind(){let e=this.importKind?.value?.toLowerCase();if(e!==void 0)return this.archImport?e===`kind`?void 0:Object.values(Fp).find(t=>t.toLowerCase()===e)??F.Element:Object.values(F).find(t=>t.toLowerCase()===e)}},gm=class extends I{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,`<use-specifier-list>`,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},R=class e extends I{constructor({type:t,targetKind:n,name:r,as:i,alias:a,attributeList:o,bodyColon:s,body:c},l,u){if(super(l,`<element-declaration>`,u,[t,n,r,i,a,o,s,c]),c&&s&&!(c instanceof H||c instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.targetKind=n,this.name=r,this.as=i,this.alias=a,this.attributeList=o,this.bodyColon=s,this.body=c}isKind(...e){return e.some(e=>this.type?.value.toLowerCase()===e)}getElementKind(){return Object.values(r).find(e=>this.isKind(e))}},_m=class extends I{constructor({identifiers:e=[]},t,n){super(t,`<identifier-stream>`,n,e||[]),this.identifiers=e}},z=class extends I{constructor({name:e,colon:t,value:n},r,i){super(r,`<attribute>`,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},B=class extends I{constructor({op:e,expression:t},n,r){super(n,`<prefix-expression>`,r,[e,t]),this.op=e,this.expression=t}},V=class extends I{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,`<infix-expression>`,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},vm=class extends I{constructor({op:e,expression:t},n,r){super(n,`<postfix-expression>`,r,[t,e]),this.op=e,this.expression=t}},ym=class extends I{constructor({value:e},t,n){super(t,`<function-expression>`,n,[e]),this.value=e}},H=class extends I{constructor({callee:e,args:t=[]},n,r){super(n,`<function-application>`,r,[e,...t]),this.callee=e,this.args=t}},U=class extends I{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,`<block-expression>`,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},W=class extends I{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,`<list-expression>`,a,[e,...Am(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},bm=class extends I{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,`<tuple-expression>`,a,[e,...Am(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},xm=class extends I{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,`<comma-expression>`,r,[...Am(e,t)]),this.elementList=e,this.commaList=t}},Sm=class extends bm{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=`<group-expression>`}},Cm=class extends I{constructor({callee:e,argumentList:t},n,r){super(n,`<call-expression>`,r,[e,t]),this.callee=e,this.argumentList=t}},wm=class extends I{constructor({literal:e},t,n){super(t,`<literal>`,n,[e]),this.literal=e}},Tm=class extends I{constructor({token:e},t,n){super(t,`<wildcard>`,n,[e]),this.token=e}},Em=class extends I{constructor({variable:e},t,n){super(t,`<variable>`,n,[e]),this.variable=e}},Dm=class extends I{constructor({expression:e},t,n){super(t,`<primary-expression>`,n,[e]),this.expression=e}},Om=class extends I{constructor({prevToken:e},t,n){let r=Va.create(v.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,`<dummy>`,n,[r])}},km=class extends I{constructor({expression:e,indexer:t},n,r){super(n,`<array>`,r,[e,t]),this.array=e,this.indexer=t}};function Am(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?br(La(e,t)):br(La(t,e))).filter(e=>e!==null)}var jm=function(e){return e.Table=`table`,e}({});function Mm(e,t,n){let r=t,i=e;if(i instanceof Cm&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!zf(i)||r.length===0)return;let a=[...r],o=$f(i),s=a.pop();if(!(s instanceof U))return;let c=g(a)instanceof W?a.pop():void 0;if(a.length===3){let e=$f(a[1]);return!e||!om(e)?void 0:n.create(R,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(R,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(R,{type:o,attributeList:c,body:s})}function G(e){e&&(e instanceof Va?Nm(e):Pm(e))}function Nm(e){e.kind!==v.EOF&&(e.isInvalid=!0)}function Pm(e){if(e instanceof R)G(e.type),G(e.targetKind),G(e.name),G(e.as),G(e.alias),G(e.bodyColon),G(e.attributeList),G(e.body);else if(e instanceof _m)e.identifiers.forEach(G);else if(e instanceof z)G(e.name),G(e.colon),G(e.value);else if(e instanceof B)G(e.op),G(e.expression);else if(e instanceof V)G(e.leftExpression),G(e.op),G(e.rightExpression);else if(e instanceof vm)G(e.op),G(e.expression);else if(e instanceof U)G(e.blockOpenBrace),e.body.forEach(G),G(e.blockCloseBrace);else if(e instanceof W)G(e.listOpenBracket),e.commaList.forEach(G),e.elementList.forEach(G),G(e.listCloseBracket);else if(e instanceof bm)G(e.tupleOpenParen),e.commaList.forEach(G),e.elementList.forEach(G),G(e.tupleCloseParen);else if(e instanceof xm)e.commaList.forEach(G),e.elementList.forEach(G);else if(e instanceof Cm)G(e.callee),G(e.argumentList);else if(e instanceof H)G(e.callee),e.args.forEach(G);else if(e instanceof Dm)G(e.expression);else if(e instanceof ym)G(e.value);else if(e instanceof Em)G(e.variable);else if(e instanceof wm)G(e.literal);else if(e instanceof Sm)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof km)G(e.array),G(e.indexer);else if(e instanceof L)e.body.forEach(G),G(e.eof);else if(!(e instanceof Om))if(e instanceof mm)G(e.useKeyword),G(e.specifiers),G(e.fromKeyword),G(e.importPath);else if(e instanceof gm)G(e.openBrace),e.specifiers.forEach(G),G(e.closeBrace);else if(e instanceof hm)G(e.importKind),G(e.name),G(e.asKeyword),G(e.alias);else if(e instanceof Tm)G(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Fm(...e){return e.filter(e=>e!==void 0)}function Im(e){if(e instanceof L)return Fm(...e.body,e.eof);if(e instanceof R)return Fm(e.type,e.targetKind,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof z)return Fm(e.name,e.colon,e.value);if(e instanceof _m)return e.identifiers;if(e instanceof wm)return e.literal?[e.literal]:[];if(e instanceof Em)return Fm(e.variable);if(e instanceof B)return Fm(e.op,e.expression);if(e instanceof V)return Fm(e.leftExpression,e.op,e.rightExpression);if(e instanceof vm)return Fm(e.expression,e.op);if(e instanceof ym)return Fm(e.value);if(e instanceof H)return Fm(e.callee,...e.args);if(e instanceof U)return Fm(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof W)return Fm(e.listOpenBracket,...Lm(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof bm)return Fm(e.tupleOpenParen,...Lm(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof xm)return Fm(...Lm(e.elementList,e.commaList));if(e instanceof Cm)return Fm(e.callee,e.argumentList);if(e instanceof Dm)return Fm(e.expression);if(e instanceof km)return Fm(e.array,e.indexer);if(e instanceof Om)return[];if(e instanceof mm)return Fm(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof gm)return Fm(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof hm)return Fm(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof Tm)return Fm(e.token);throw e instanceof Sm?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Lm(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 Rm(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function zm(e){if(!e)return[];if(D(e))return[{variables:[e],tupleElements:[]}];if(e instanceof V){let t=ap(e);return t?[t]:[...zm(e.leftExpression),...zm(e.rightExpression)]}if(e instanceof B||e instanceof vm)return zm(e.expression);if(e instanceof bm){let t=ap(e);return t?[t]:e.elementList.flatMap(zm)}return[]}function Bm(e,n){let r=n.parentNode;if(!r||!O(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;O(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Vm(e,t,r,i){if(!D(r))return new n(void 0);let a=lp(r)??``;if(O(r.parentNode)&&r.parentNode.rightExpression===r&&Qf(r)){let t=Bm(e,r);if(!t)return new n(void 0);if(i===F.Column){if(t.isKind(F.Table)){let i=e.lookupMembers(t,F.Column,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${t.name}'`,r)])}return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist`,r)])}else{if(t.isKind(F.Schema)){let i=e.lookupMembers(t,F.Table,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist`,r)])}}let o=Bm(e,r);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,r)])}if(i===F.Column&&o.isKind(F.Table)){let t=e.lookupMembers(o,F.Column,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${o.name}'`,r)])}return new n(void 0)}let s=r.parentNode;if(s.leftExpression===r){if(O(s.parentNode)&&s.parentNode.leftExpression===s||i===F.Table){let i=e.lookupMembers(t,F.Schema,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist in Schema 'public'`,r)])}let o=e.lookupMembers(t,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Hm(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof zp&&e.isPublicSchema())}function Um(e,n){let r=e.parseFile(n).getValue().ast;return e.nodeSymbol(r).getFiltered(t)}var Wm={group:`group`,kind:`kind`,link:`link`,ref:`link`,metadata:`metadata`,project:`project`},Gm=e=>e.type?.value;function Km(e){return e instanceof R&&e.parentNode instanceof L&&!!e.type}function qm(e){if(!Km(e))return;let t=e.type.value.toLowerCase();if(t!==`note`)return Wm[t]??`node`}var Jm=e=>Km(e)&&e.type.value.toLowerCase()===`note`;function Ym(e){let t=e;for(;t;){if(Km(t))return t;t=t.parentNode}}function Xm(e){if(e){if(e instanceof Dm){if(e.expression instanceof Em)return e.expression.variable?.value;if(e.expression instanceof wm)return String(e.expression.literal?.value)}if(e instanceof _m)return e.identifiers?.map(e=>e.value).join(` `)}}var Zm=e=>Xm(e.alias)??Xm(e.name);function Qm(e){if(!(e instanceof Dm)||!(e.expression instanceof wm))return null;let t=e.expression.literal;if(t?.kind!==v.NUMERIC_LITERAL)return null;let n=Number(t.value);return Number.isFinite(n)?n:null}function $m(e){let t=Qm(e);if(t!==null)return t;let n=Xm(e);if(n!==void 0)return n===`true`?!0:n===`false`?!1:n}var eh=new Set([`link`,`ref`]),th=e=>eh.has(e.toLowerCase());function nh(e){let t={};for(let n of e?.elementList??[]){if(!(n instanceof z))continue;let e=Xm(n.name)?.toLowerCase();!e||eh.has(e)||(t[e]=n.value===void 0?!0:$m(n.value)??!0)}return t}function rh(e){return e.body?e.body instanceof U?[...e.body.body]:[e.body]:[]}function ih(e){if(!(e instanceof H))return;let t=[...e.args??[]],n=t[t.length-1]instanceof W?t.pop():void 0;return{callee:e.callee,args:t,settings:n}}function ah(e){if(!(e instanceof V))return;let t=e.op?.value;if(!(!t||!e.leftExpression||!e.rightExpression))return{left:e.leftExpression,op:t,right:e.rightExpression}}function oh(e){let t=ah(e);return t&&t.op===`.`?t.left:e}var sh=new Set([`>`,`<`,`<>`,`-`]);function ch(e){let[t]=rh(e);if(!t)return;let n=ih(t),r=ah(n?.callee??t);if(!(!r||!sh.has(r.op)))return{row:n,infix:r}}function lh(e){return eh.has(Xm(e.name)?.toLowerCase()??``)}function uh(e){return(e.attributeList?.elementList??[]).filter(e=>e instanceof z&&lh(e))}function dh(e){let{value:t}=e;if(!(t instanceof B)||!t.expression)return;let n=t.op?.value;if(!(!n||!sh.has(n)))return{op:n,target:oh(t.expression)}}function fh(e){if(e instanceof R){let t=Gm(e);if(!t)return;let[n]=rh(e);if(!n)return{key:t,value:void 0};let r=ih(n);return{key:t,value:$m(r?r.callee??n:n)}}let t=ih(e),n=Xm(t?.callee);if(!n)return;let[r]=t?.args??[];return{key:n,value:r===void 0?void 0:$m(r)}}var ph=e=>e instanceof R&&e.type?.value.toLowerCase()===`note`;function mh(e){return rh(e).find(ph)}function hh(e){return gh(rh(e).map(e=>Xm(ih(e)?.callee)??``).join(` `))}function gh(e){let t=e.split(`
5
5
  `),n=t.filter(e=>e.trim()).map(e=>e.length-e.trimStart().length),r=n.length?Math.min(...n):0;return t.map(e=>e.slice(r)).join(`
6
- `).trim()}var Ph=/^(https:\/\/|data:image\/)/i,Fh=`A picture must be an https: URL or a data:image/ URI.`;function Ih(e,t,n){let r={settings:t,problems:[]},i=new Set;for(let a of bh(e)){if(!(a instanceof R)){if(!n)continue;let e=xh(a);if(!e)continue;for(let n of[e.callee,...e.args]){let e=G(n);if(e){if(i.has(e)){r.problems.push({code:`duplicate`,message:`${e} is set twice`,node:a});continue}i.add(e),t[e]=!0}}continue}let e=lh(a);if(!e||e.toLowerCase()===`note`)continue;let o=kh(a);if(!o||o.value===void 0){r.problems.push({code:`bad`,message:`A property reads ${e}: 'value'`,node:a});continue}if(i.has(o.key)){r.problems.push({code:`duplicate`,message:`${o.key} is set twice`,node:a});continue}i.add(o.key),t[o.key]=o.value}return r}function Lh(e,t,n,r){let i=Gm(e,t);if(!i)return;let a=Wm(e,i);return(a&&e.lookupMembers(a,n,r))??e.lookupMembers(i,n,r)}function Rh(e,n){let r=new Map,i=Gm(e,n);if(!i)return r;let a=Wm(e,i);if(!a)return r;let o=(e.symbolMembers(a).getFiltered(t)??[]).filter(e=>e.isKind(F.Kind)&&e.name!==void 0&&!oh(e.name));for(let e of[...o.filter(e=>e instanceof am),...o.filter(e=>!(e instanceof am))])r.set(e.name.toLowerCase(),e);return r}function zh(e,t,n){let r=Rh(e,t).get(n.toLowerCase());return r?r.originalSymbol.name:th(n)}function Bh(e,t,n){let r=t.originalSymbol;if(r.isKind(F.StickyNote))return r.interpretedName(e,n).name;let i=r.declaration;return i instanceof R?mh(i):void 0}var Vh=function(e){return e.Ref=`ref`,e.Dep=`dep`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e.MetadataElement=`metadata element`,e.Link=`link`,e}({}),Hh=class e{static{this.id=0}constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}resolveOwnerPrograms(e,t){let n=this.declaration.filepath;return e.reachableFiles().flatMap(t=>Gm(e,t)||[]).filter(r=>e.reachableFiles(r.filepath).some(e=>e.equals(n))&&t.every(t=>r.inNestedSchema(e,t)))}},Uh=class extends Hh{constructor(e){super(e),this.kind=`ref`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof R){let t=rp(this.declaration)[0];if(!(t instanceof V))return[];let n=t.callee;return n instanceof ym?$h(e,n.leftExpression):[]}if(this.declaration instanceof z){let n=this.declaration.parentOfKind(V);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof R){let t=rp(this.declaration)[0];if(!(t instanceof V))return[];let n=t.callee;return n instanceof ym?$h(e,n.rightExpression):[]}if(this.declaration instanceof z){let t=this.declaration.value;return t instanceof B?$h(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof R){let t=rp(this.declaration)[0];if(!(t instanceof V))return;let n=t.callee;return n instanceof ym?eg(e,n.leftExpression):void 0}if(this.declaration instanceof z)return this.container(e)}rightTable(e){if(this.declaration instanceof R){let t=rp(this.declaration)[0];if(!(t instanceof V))return;let n=t.callee;return n instanceof ym?eg(e,n.rightExpression):void 0}if(this.declaration instanceof z){let t=this.declaration.value;return t instanceof B?eg(e,t.expression)??this.container(e):void 0}}op(e){return this.opToken()?.value}opToken(){if(this.declaration instanceof R){let e=rp(this.declaration)[0];if(!(e instanceof V))return;let t=e.callee;return t instanceof ym?t.op:void 0}if(this.declaration instanceof z){let e=this.declaration.value;return e instanceof B?e.op:void 0}}cardinalities(e){let t=this.op(e);return t?af(t):void 0}leftCardinality(e){let t=this.cardinalities(e);return t?Zd(t[0]):void 0}rightCardinality(e){let t=this.cardinalities(e);return t?Zd(t[1]):void 0}active(e){if(!(this.declaration instanceof R))return!0;let n=rp(this.declaration)[0];return n?!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length:!0}leftToken(){if(this.declaration instanceof R){let e=rp(this.declaration)[0];if(e instanceof V){let t=e.callee;if(t instanceof ym&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof z){let e=this.declaration.parentOfKind(V);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof R){let e=rp(this.declaration)[0];if(e instanceof V){let t=e.callee;if(t instanceof ym&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof z,this.declaration}owners(e){let t=this.leftTable(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Wh=class extends Hh{constructor(e){super(e),this.kind=`dep`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}edgeExpressions(){return this.declaration instanceof R?rp(this.declaration).filter(e=>e instanceof V).map(e=>e.callee).filter(e=>e instanceof ym):[]}upstreamColumns(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>$h(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=this.hostColumn(e),i=$h(e,t.expression);if(n===`->`)return[r?[r]:[]];if(n===`<-`)return[i]}return[]}downstreamColumns(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>$h(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=this.hostColumn(e),i=$h(e,t.expression);if(n===`->`)return[i];if(n===`<-`)return[r?[r]:[]]}return[]}upstreamTables(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>tg(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=tg(e,t.expression);if(n===`->`)return[this.container(e)];if(n===`<-`)return[r]}return[]}downstreamTables(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>tg(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=tg(e,t.expression);if(n===`->`)return[r];if(n===`<-`)return[this.container(e)]}return[]}hostColumn(e){if(!(this.declaration instanceof z))return;let n=this.declaration.parentOfKind(V);if(n)return e.nodeSymbol(n).getFiltered(t)}owners(e){let n=this.upstreamTables(e),r=this.downstreamTables(e),i=[...n,...r].filter(e=>!!e);if(i.length===0)return[];let a=this.declaration.filepath;return e.reachableFiles().flatMap(n=>e.nodeSymbol(e.parseFile(n).getValue().ast).getFiltered(t)||[]).filter(t=>e.reachableFiles(t.filepath).some(e=>e.equals(a))&&i.every(n=>t.inNestedSchema(e,n)))}},Gh=class extends Hh{constructor(e){super(e),this.kind=`partial ref`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof z))return[];let n=this.declaration.parentOfKind(V);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof z))return[];let t=this.declaration.value;return t instanceof B?$h(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof z)return this.container(e)}rightTable(e){if(!(this.declaration instanceof z))return;let t=this.declaration.value;if(t instanceof B)return eg(e,t.expression)??this.container(e)}op(e){return this.opToken()?.value}opToken(){if(!(this.declaration instanceof z))return;let e=this.declaration.value;if(e instanceof B)return e.op}cardinalities(e){let t=this.op(e);return t?af(t):void 0}leftToken(){if(this.declaration instanceof z){let e=this.declaration.parentOfKind(V);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof z,this.declaration}owners(e){let t=this.leftTablePartial(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Kh=class extends Hh{constructor(e){super(e),this.kind=`table checks`,this.ownerTable=e.parentNode?.parentOfKind(R)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},qh=class extends Hh{constructor(e){super(e),this.kind=`indexes`,this.ownerTable=e.parentNode?.parentOfKind(R)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Jh=class extends Hh{constructor(e){super(e),this.kind=`records`}table(e){let n=this.declaration,i=n.parent;if(i instanceof R&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof Tm))return;let o=cp(a);if(!o)return;let s=o.variables.at(-1);if(s)return e.nodeReferee(s).getFiltered(t)?.originalSymbol}example(e){return!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Example]?.length}owners(e){let t=this.table(e);return t?this.resolveOwnerPrograms(e,[t]):[]}},Yh=class extends Hh{constructor(e){super(e),this.kind=`metadata element`}target(e){let n=this.declaration.name;if(!n)return;let r=Zf(n)??n;return e.nodeReferee(r).getFiltered(t)?.originalSymbol}owners(e){let n=this.target(e);if(!n)return[];if(n.kind===F.Column){let r=n.declaration?.parentOfKind(R),i=r?e.nodeSymbol(r).getFiltered(t)?.originalSymbol:void 0;if(!i)return[];n=i}return this.resolveOwnerPrograms(e,[n])}},Xh=class extends Hh{constructor(e){super(e),this.kind=`link`}op(){return this.declaration instanceof z?Oh(this.declaration)?.op:Th(this.declaration)?.infix.op}endpoints(e){let n=n=>{let r=Ch(n);return D(r)?e.nodeReferee(r).getFiltered(t)?.originalSymbol:void 0};if(this.declaration instanceof z){let r=Oh(this.declaration),i=this.declaration.parentOfKind(R);return!r||!i?[void 0,void 0]:[e.nodeSymbol(i).getFiltered(t)?.originalSymbol,n(r.target)]}let r=Th(this.declaration);return r?[n(r.infix.left),n(r.infix.right)]:[void 0,void 0]}owners(e){let[t,n]=this.endpoints(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Zh=class extends Yh{target(e){if(this.declaration.name)return super.target(e);let t=this.declaration.targetKind?.value;if(t)return Lh(e,this.declaration.filepath,F.Element,t)?.originalSymbol}},Qh=class extends Hh{constructor(e){super(e),this.kind=`project`}owners(e){let n=this.declaration.filepath,r=e.parseFile(n).getValue().ast,i=e.nodeSymbol(r).getFiltered(t);return i?[i]:[]}};function $h(e,n){if(!n)return[];let r=ap(n);return r?(r.tupleElements.length>0?r.tupleElements:r.variables.at(-1)?[r.variables.at(-1)]:[]).flatMap(n=>{let r=e.nodeReferee(n).getFiltered(t);return r?.isKind(F.Column)?[r]:[]}):[]}function eg(e,n){if(!n)return;let r=ap(n);if(!r)return;let i=r.tupleElements.length>0?r.variables.at(-1):r.variables.at(-2);if(i)return e.nodeReferee(i).getFiltered(t)}function tg(e,n){if(!n)return;let r=ap(n);if(!r)return;if(r.tupleElements.length>0){let n=r.variables.at(-1);return n?e.nodeReferee(n).getFiltered(t):void 0}let i=r.variables.at(-1);if(i){let n=e.nodeReferee(i).getFiltered(t);if(n?.isKind(F.Table))return n}let a=r.variables.at(-2);if(a)return e.nodeReferee(a).getFiltered(t)}var ng=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},rg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof H?new n(e.body.flatMap(e=>{if(!(e instanceof V))return[];let t=P(e),n=e.callee instanceof xm?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof U);return a&&(r=M(T(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}},ig={nodeMetadata(t,i){if(k(i,r.Checks)){let t=i.parent;return!t||!k(t,r.Table)&&!k(t,r.TablePartial)?n.create(e):n.create(new Kh(i))}return n.create(e)},bindNode(t,i){return k(i,r.Checks)?n.create(void 0,new ng(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Vh.TableChecks?r.declaration instanceof R?new rg(t,r.declaration).interpret():n.create(void 0):n.create(e)}},ag=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[e.callee,...e.args].flatMap(Vm).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors())),n=this.checkColumnSelfLoop(e.callee);return t.concat(n)})}checkColumnSelfLoop(e){if(!(e instanceof ym)||this.endpointLevel(e.leftExpression)!==`column`||this.endpointLevel(e.rightExpression)!==`column`)return[];let t=this.endpointSymbol(e.leftExpression),n=this.endpointSymbol(e.rightExpression);return t&&n&&t===n?[new w(C.DEP_SELF_LOOP,`A column cannot depend on itself`,e)]:[]}endpointSymbol(e){if(!e)return;let n=ap(e);if(!n)return;let r=n.variables.at(-1);if(r)return this.compiler.nodeReferee(r).getFiltered(t)}endpointLevel(e){if(!e)return;let n=ap(e);if(!n)return;if(n.tupleElements.length>0)return`column`;let r=n.variables.at(-1);if(!r)return;let i=this.compiler.nodeReferee(r).getFiltered(t);if(i?.isKind(F.Column))return`column`;if(i?.isKind(F.Table))return`table`}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},og=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.dep={}}interpret(){this.dep.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretEdges(),...this.interpretSettings()];return n.create(this.dep,e)}interpretName(){if(!(this.declarationNode instanceof R))return this.dep.name=null,this.dep.schemaName=null,[];let e=[],t=this.declarationNode.name?j(this.declarationNode.name)??[]:[];return this.dep.name=t.pop()||null,t.length>1&&e.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.dep.schemaName=t.join(`.`)||null,e}interpretEdges(){let e=this.metadata.upstreamColumns(this.compiler),t=this.metadata.downstreamColumns(this.compiler),n=this.metadata.upstreamTables(this.compiler),r=this.metadata.downstreamTables(this.compiler),i=[],a=[],o=Math.max(n.length,r.length);for(let a=0;a<o;a++){let o=n[a],s=r[a],c=e[a]??[],l=t[a]??[],u=o?.interpretedName(this.compiler,this.filepath),d=s?.interpretedName(this.compiler,this.filepath);u?.schema,d?.schema,i.push({upstream:{schemaName:u?.schema??null,tableName:u?.name??``,fieldNames:c.map(e=>e.name??``),token:this.dep.token},downstream:{schemaName:d?.schema??null,tableName:d?.name??``,fieldNames:l.map(e=>e.name??``),token:this.dep.token},token:this.dep.token})}return this.dep.edges=i,a}interpretSettings(){let e={};if(this.declarationNode instanceof R){this.declarationNode.attributeList&&this.consumeSettings(this.declarationNode.attributeList,e);let t=this.declarationNode.body;if(t){let n=t instanceof V?[t]:t.body.filter(e=>e instanceof V);for(let t of n){let n=t.args.find(e=>e instanceof U);n&&this.consumeSettings(n,e)}if(!(t instanceof V)){let n=t.body.filter(e=>e instanceof R);for(let t of n){let n=t.type?.value?.toLowerCase();if(!n)continue;let a=t.body;if(t.isKind(r.Note)&&a instanceof H){let e=a.body[0];if(e instanceof V&&e.callee){let n=this.extractAttrValue(e.callee);n!==void 0&&(this.dep.note={value:Op(String(n)),token:P(t)})}continue}if(!(a instanceof V))continue;if(n===i.Color){let e=Ap(a.callee);e!==void 0&&(this.dep.color=e);continue}let o=this.extractAttrValue(a.callee);o!==void 0&&(t.isKind(r.Note)?this.dep.note={value:Op(String(o)),token:P(t)}:e[n]=o)}}}}return Object.keys(e).length>0&&(this.dep.metadata=e),[]}consumeSettings(e,t){let n=T(e).getValue();for(let[e,r]of Object.entries(n)){let n=r[0];if(!n)continue;if(e===i.Color){let e=Ap(n.value);e!==void 0&&(this.dep.color=e);continue}let a=this.extractAttrValue(n.value);a!==void 0&&(e===i.Note?this.dep.note={value:Op(String(a)),token:P(n)}:t[e]=a)}}extractAttrValue(e){if(e instanceof vm)return ep(e);let t=sp(e);if(t!==null)return t;let n=M(e);return n===void 0?N(e):n}};function sg(e){let t=e.parent;for(;t;){if(t instanceof R&&t.isKind(r.Dep))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var cg={nodeReferee(r,i){if(!D(i)&&!O(i)||!sg(i)||i.parentOfKind(z))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):lg(r,o,i)},nodeMetadata(t,a){if(k(a,r.Dep)){let t=rp(a);return t.length===0||!t.some(e=>e instanceof V&&e.callee instanceof ym)?n.create(e):n.create(new Wh(a))}return a instanceof z?!(a.name instanceof vm)||ep(a.name)?.toLowerCase()!==i.Dep?n.create(e):n.create(new Wh(a)):n.create(e)},bindNode(t,i){return k(i,r.Dep)?n.create(void 0,new ag(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Wh?new og(t,r,i).interpret():n.create(e)}};function lg(e,r,i){if(!D(i))return new n(void 0);let a=lp(i)??``;if(!O(i.parentNode)){let t=Wm(e,r);if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=i.parentNode;if(o.rightExpression===i){let r=Hm(e,i);if(r?.isKind(F.Schema)){let t=e.lookupMembers(r,F.Table,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema '${r.name}'`,i)])}if(r?.isKind(F.Table)){let o=e.lookupMembers(r,F.Column,a);if(o)return n.create(o);let s=r.declaration?e.nodeFullname(r.declaration).getFiltered(t)?.join(`.`)??r.name:r.name;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${s}'`,i)])}return new n(void 0)}if(o.leftExpression===i){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let t=e.lookupMembers(r,F.Schema,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=e.lookupMembers(r,F.Schema,a);if(t)return n.create(t);let s=Wm(e,r);if(s){let t=e.lookupMembers(s,F.Table,a);if(t)return n.create(t)}let c=e.lookupMembers(r,F.Table,a);return c?n.create(c):new n(void 0,[new w(C.BINDING_ERROR,`Schema or Table '${a}' does not exist`,i)])}return new n(void 0)}var ug=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=_(e.body,e=>e instanceof V);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof H)?[]:e.isKind(r.DiagramViewTables)?this.bindTableReferences(e.body):e.isKind(r.DiagramViewNotes)?this.bindNoteReferences(e.body):e.isKind(r.DiagramViewTableGroups)?this.bindTableGroupReferences(e.body):e.isKind(r.DiagramViewSchemas)?this.bindSchemaReferences(e.body):[])}bindTableReferences(e){let[t]=_(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||Rf(e.callee)?[]:[e.callee,...e.args].flatMap(Vm).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables.pop();return[...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}))}bindNoteReferences(e){let[t]=_(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||Rf(e.callee)?[]:Vm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=_(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||Rf(e.callee)?[]:Vm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=_(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||Rf(e.callee)?[]:Vm(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},dg=class{constructor(e,t,n,r){this.diagramViewWildcards=new Set,this.diagramViewExplicitlySet=new Set,this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r??t.filepath,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null}}}interpret(){let e=[];this.diagramView.token=this.symbol.token;let{name:t,schema:r}=this.symbol.interpretedName(this.compiler,this.filepath);return this.diagramView.name=t,this.diagramView.schemaName=r,this.declarationNode.body instanceof H&&e.push(...this.interpretBody(this.declarationNode.body)),this.expandDiagramViewWildcards(),new n(this.diagramView,e)}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof V&&Rf(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramViewWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramViewExplicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=_(e.body,e=>e instanceof R),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof H&&this.interpretSubBlock(e.body,t)}let i=this.diagramView.visibleEntities;return(n.has(`tables`)&&i.tables!==null||n.has(`tablegroups`)&&i.tableGroups!==null||n.has(`schemas`)&&i.schemas!==null)&&(n.has(`tables`)||(i.tables=[]),n.has(`tablegroups`)||(i.tableGroups=[]),n.has(`schemas`)||(i.schemas=[])),n.has(r.DiagramViewTables)&&this.diagramViewExplicitlySet.add(`tables`),n.has(r.DiagramViewTableGroups)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(r.DiagramViewSchemas)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(r.DiagramViewNotes)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,n){if(!n)return;if(e.body.some(e=>e instanceof V&&Rf(e.callee))){let e=this.diagramViewWildcards;switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=[],e.add(`tables`);break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=[],e.add(`stickyNotes`);break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=[],e.add(`tableGroups`);break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=[],e.add(`schemas`);break}return}if(e.body.length===0)return;let i=[];for(let n of e.body){if(!(n instanceof V))continue;let e=n.callee&&Zf(n.callee),r=e&&this.compiler.nodeReferee(e).getFiltered(t);if(r?.declaration instanceof R){let e=j(r.declaration.name)??[];if(e.length>0){let t=e[e.length-1],n=e.length>1?e.slice(0,-1).join(`.`):y;i.push({name:t,schemaName:n});continue}}let a=j(n.callee)??[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[0]:y;i.push({name:o,schemaName:s})}switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=i.length>0?i:null;break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=i.length>0?i.map(e=>({name:e.name})):null;break}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;if(!(!t||!e)){if(t.has(`tables`)||t.has(`schemas`)){e.tables=[],e.tableGroups=[],e.schemas=[];return}t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames())}}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n)return[];let r=this.compiler.symbolMembers(n).getFiltered(t);return r?Pa(r.filter(e=>e.isKind(F.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function fg(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var pg={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new w(C.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},mg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.DiagramView)?new n(i.symbolFactory.create(Zp,{declaration:a,name:o},a.filepath)):A(a,r.DiagramView)&&a instanceof Dm?new n(i.symbolFactory.create(Qp,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(tm,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewTables)?new n(i.symbolFactory.create($p,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(em,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(nm,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&Kf(a))return n.create(e);let o=hg(a);if(!o)return n.create(e);let s=i.parseFile(a.filepath).getValue().ast,c=i.nodeSymbol(s).getFiltered(t);return c?o.isKind(r.DiagramViewTables)?gg(i,c,a):o.isKind(r.DiagramViewNotes)?_g(i,c,a,F.StickyNote):o.isKind(r.DiagramViewTableGroups)?_g(i,c,a,F.TableGroup):o.isKind(r.DiagramViewSchemas)?vg(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(F.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!k(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of rp(o))if(e instanceof V){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof R&&c.push(...rp(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(F.DiagramViewSchema,F.DiagramViewTableGroup,F.DiagramViewTable,F.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(Jv).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(pg.getFieldDuplicateError(n,e.kind,i)),s.push(pg.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!k(a,r.DiagramView))return n.create(e);let o=new ug(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Zp?r.declaration instanceof R?new dg(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function hg(e){let t=e.parentOfKind(V);if(!t)return;let n=t.parentNode;if(!(n instanceof H))return;let i=n.parentNode;if(!(i instanceof R)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof H))return;let o=a.parentNode;if(!(!(o instanceof R)||!o.isKind(r.DiagramView)))return i}function gg(e,r,i){let a=lp(i);if(a===void 0)return n.create(void 0);if(O(i.parentNode)){let t=Hm(e,i);if(t){if(t.isKind(F.Schema)){let r=Qf(i),o=e.lookupMembers(t,r?F.Table:F.Schema,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,F.Schema,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find schema '${a}'`,i)])}let o=e.symbolMembers(r).getFiltered(t)||[];for(let e of o){let t=e.name;if(e.isKind(F.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,F.Table,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Could not find table '${a}'`,i)])}function _g(e,t,r,i){let a=lp(r);if(a===void 0)return n.create(void 0);let o=e.lookupMembers(t,i,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${i===F.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function vg(e,t,r){let i=lp(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var yg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof V)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},bg=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.enum={values:[]}}interpret(){this.enum.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody(this.declarationNode.body)];return n.create(this.enum,e)}interpretName(){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);return this.enum.name=e,this.enum.schemaName=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=P(t),n.name=N(t.callee);let r=T(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Op(M(r.value)),token:P(r)},this.enum.values.push(n),[]})}},xg={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new w(C.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},Sg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.Enum)?new n(i.symbolFactory.create(Bp,{declaration:a,name:o},a.filepath)):A(a,r.Enum)?new n(i.symbolFactory.create(Vp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof R))return new n([]);let o=rp(a),s=[],c=[];for(let e of o){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(s.push(i),c.push(...n.getErrors()))}let l=new Map;for(let e of s){if(!e.isKind(F.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push(xg.getFieldDuplicateError(t,r)),c.push(xg.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!k(a,r.Enum))return n.create(e);let o=new yg(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Bp?new bg(t,r,i).interpret():n.create(e)}},Cg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof R)||!this.declarationNode.parent.isKind(r.Table)&&!this.declarationNode.parent.isKind(r.TablePartial)||!(this.declarationNode.body instanceof H)?[]:this.bindBody(this.declarationNode.body)}get ownerContainerKind(){return this.declarationNode.parent.isKind(r.TablePartial)?`TablePartial`:`Table`}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=j(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(Vm).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=lp(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new w(C.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},wg=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof H?new n(e.body.flatMap(e=>{if(!(e instanceof V)||!e.callee)return[];let n=[],r=P(e),a=[e.callee,...e.args],o,s,c,l,u;g(a)instanceof U&&a.pop();let d=this.compiler.nodeSettings(e).getFiltered(t);if(d){o=!!d[i.PK]?.length||void 0,s=!!d[i.Unique]?.length||void 0,c=M(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=M(e.value);t!==void 0&&(l={value:t,token:P(e)})}u=N(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof Tm))return e;let t=[],n=e;for(;n instanceof Tm&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=op(e);if(!t)continue;let r=[];for(let e of t.functional)r.push({value:e.value?.value??``,type:`expression`,token:P(e)});for(let e of t.nonFunctional)r.push({value:lp(e)??``,type:`column`,token:P(e)});r.sort((e,t)=>e.token.start.offset-t.token.start.offset),n.push(...r)}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}},Tg={nodeMetadata(t,i){if(!k(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!k(a,r.Table)&&!k(a,r.TablePartial)?n.create(e):n.create(new qh(i))},nodeReferee(i,a){if(!D(a)||Kf(a))return n.create(e);let o=a;for(;o&&!k(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!k(s,r.Table)&&!k(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=D(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,F.Column,l);if(u)return n.create(u);let d=k(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return k(i,r.Indexes)?n.create(void 0,new Cg(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Vh.Indexes?r.declaration instanceof R?new wg(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function Eg(e,n){let r=ip(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof Sm){let n=[];for(let r of i.elementList){let i=e.nodeReferee(r).getFiltered(t);if(!i)return;n.push(i.originalSymbol)}return n}let a=r[r.length-1];if(!a||a instanceof Sm)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function Dg(e,t,n,r){let i=e.map(e=>e.intern()).sort().join(`,`),a=t.map(e=>e.intern()).sort().join(`,`);if(i===a)return[new w(C.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new w(C.CIRCULAR_REF,`References with same endpoints exist`,n),new w(C.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var Og=class{constructor(e,t){this.compiler=t,this.ast=e}resolve(){let e=[],i=this.compiler.reachableFiles(this.ast.filepath);for(let n of i){let{ast:i}=this.compiler.parseFile(n).getFiltered(t)||{ast:void 0};if(!i)continue;let a=i.body.filter(e=>e instanceof R&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new w(C.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof R&&t.type){let n=t;e.push(...this.compiler.bindNode(n).getErrors())}else e.push(...this.compiler.bindNode(t).getErrors())}let a=this.compiler.nodeSymbol(this.ast).getFiltered(t);return a&&e.push(...kg(this.compiler,a)),e.push(...this.checkDuplicateRefs()),e.push(...this.checkTableGroups()),new n(void 0,e)}isArchFile(e){return!this.compiler.explicitModules&&this.compiler.parsedFileKind(e)===`arch`}checkDuplicateRefs(){let e=[],n=new Map,i=this.compiler.reachableFiles(this.ast.filepath);for(let a of i){if(this.isArchFile(a))continue;let i=this.compiler.parseFile(a).getFiltered(t);if(!i)continue;let{ast:o}=i;for(let t of o.body){if(!(t instanceof R)||!t.type)continue;let i=t;k(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),k(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),k(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of rp(e)){if(!(r instanceof V)||!r.callee||!Jf(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=Eg(this.compiler,i.leftExpression),o=Eg(this.compiler,i.rightExpression);!a||!o||n.push(...Dg(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of rp(e)){if(!(a instanceof V)||!a.callee)continue;let e=this.compiler.nodeSymbol(a).getFiltered(t);if(!e)continue;let o=this.compiler.nodeSettings(a).getFiltered(t);if(!o)continue;let s=o[i.Ref];if(!(!s||s.length===0))for(let t of s){let i=t.value;if(!(i instanceof B)||!i.op||!Df(i.op.value)||!i.expression)continue;let a=Eg(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...Dg(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of rp(e)){if(!(r instanceof V)||!r.callee)continue;let e=N(r.callee);if(!e)continue;let a=this.compiler.nodeSettings(r).getFiltered(t);if(!a)continue;let o=a[i.Ref];if(!(!o||o.length===0))for(let t of o){let r=t.value;r instanceof B&&(!r.op||!Df(r.op.value)||r.expression&&D(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new w(C.SAME_ENDPOINT,`Two endpoints are the same`,t)))}}return n}checkTableGroups(){let e=[],n=new Map,i=this.compiler.reachableFiles(this.ast.filepath);for(let a of i){if(this.isArchFile(a))continue;let i=this.compiler.parseFile(a).getFiltered(t);if(!i)continue;let{ast:o}=i;for(let i of o.body){if(!(i instanceof R)||!i.type)continue;let a=i;if(!k(a,r.TableGroup))continue;let o=a.name?j(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=rp(a);for(let r of c){if(!(r instanceof V)||!r.callee)continue;let i=ip(r.callee);if(!i||i.length===0)continue;let a=i[i.length-1],o=this.compiler.nodeReferee(a).getFiltered(t)?.originalSymbol;if(!o)continue;let c=n.get(o.id);if(c){let t=j(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new w(C.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${n}" already appears in group "${c.groupName}"`,r))}else n.set(o.id,{groupName:s,node:r})}}}return e}};function kg(e,n,r=new Set){if(r.has(n.id))return[];r.add(n.id);let i=e.symbolMembers(n),a=[...i.getErrors()],o=i.getFiltered(t);if(!o)return a;for(let t of o)t instanceof zp&&a.push(...kg(e,t,r));return a}function Ag(e,t,n){t.isKind(F.Table)?e.externals.tables.push(n):t.isKind(F.Enum)?e.externals.enums.push(n):t.isKind(F.TableGroup)?e.externals.tableGroups.push(n):t.isKind(F.TablePartial)?e.externals.tablePartials.push(n):t.isKind(F.StickyNote)?e.externals.notes.push(n):t.isKind(F.Kind)?(e.externals.kinds??=[]).push(n):t.isKind(F.Element)&&(dh(t.originalSymbol.declaration)===`group`?(e.externals.groups??=[]).push(n):(e.externals.nodes??=[]).push(n))}function jg(e,t){return e>=t.start&&e<t.end}function Mg(e,t){let n=t.bodyColon?.start??t.body?.start;return n===void 0?e>=t.start&&e<=t.end:e>=t.start&&e<n}function Ng(e,t){let n=e.getSource(t.filepath);if(n)return n.slice(t.start,t.end).trim()}function Pg(e,t){return t.map(t=>t.qualifiedName(e).join(`.`)).join(`, `)}function Fg(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Pg(e,i),c=i.length>1?`Columns (\`${s}\`) are all nullable but operator \`${r}\` requires at least one to be NOT NULL`:`Column \`${s}\` is nullable but operator \`${r}\` requires it to be NOT NULL`,l=Ng(e,a),u=i[0]?.declaration,d=u&&Ng(e,u),f=[`- In ref definition \`${l??r}\`, the operator \`${r}\` requires \`${s}\` to reference an existing row.`,d?`- In column definition \`${d}\`, the column is nullable, which allows rows with no parent.`:`- A nullable column allows rows with no parent.`].join(`
7
- `);return new _f(C.INVALID_REF_RELATIONSHIP,c,t,{category:hf.RefColumnMismatch,explanation:f,quickFixes:o})}function Ig(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Pg(e,i),c=i.length>1?`Columns (\`${s}\`) are NOT NULL but operator \`${r}\` allows them to be optional`:`Column \`${s}\` is NOT NULL but operator \`${r}\` allows it to be optional`,l=Ng(e,a),u=i[0]?.declaration,d=u&&Ng(e,u),f=[`- In ref definition \`${l??r}\`, the operator \`${r}\` marks \`${s}\` as optional.`,d?`- In column definition \`${d}\`, the column is NOT NULL.`:`- The column is NOT NULL.`].join(`
8
- `);return new _f(C.INVALID_REF_RELATIONSHIP,c,t,{category:hf.RefColumnMismatch,explanation:f,quickFixes:o})}function Lg(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Pg(e,i),c=i.length>1?`Columns (\`${s}\`) have a unique index but operator \`${r}\` allows many`:`Column \`${s}\` is unique but operator \`${r}\` allows many`,l=[`- In ref definition \`${Ng(e,a)??r}\`, the operator \`${r}\` allows many.`,`- \`${s}\` has a unique constraint, so each value can appear at most once.`].join(`
9
- `);return new _f(C.INVALID_REF_RELATIONSHIP,c,t,{category:hf.RefColumnMismatch,explanation:l,quickFixes:o})}function Rg(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Pg(e,i),c=i.length>1?`Columns (\`${s}\`) should have a composite unique index for operator \`${r}\``:`Column \`${s}\` should be unique or primary key for operator \`${r}\``,l=[`- In ref definition \`${Ng(e,a)??r}\`, the operator \`${r}\` implies \`${s}\` has at most one row.`,`- \`${s}\` has no unique or primary key constraint.`].join(`
10
- `);return new _f(C.INVALID_REF_RELATIONSHIP,c,t,{category:hf.RefColumnMismatch,explanation:l,quickFixes:o})}function zg(e,t,n,r){let{schema:i,name:a}=r?t.interpretedName(e,r):{schema:t.schema(e),name:t.name??``},o=n.map(e=>{let t=e.name??``;return i?`${i}.${a}.${t}`:`${a}.${t}`});return o.length===1?o[0]:`(${o.join(`, `)})`}function Bg(e,t){return e.length>1?`Composite ${t}`:t}function Vg(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`NULL not allowed for NOT NULL column \`${n}\` without a default value or auto-increment`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is marked NOT NULL and has no default value or auto-increment.`})}function Hg(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid enum value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` uses an enum type. The value must match one of the defined enum members.`})}function Ug(e,t){let{colName:n,typeName:r}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid numeric value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` has type \`${r}\` which expects a numeric value. Provide a valid integer or decimal.`})}function Wg(e,t){let{colName:n,value:r}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid integer value \`${r}\` for column \`${n}\`: expected integer, got decimal`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is an integer column and cannot store decimal values.`})}function Gg(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,totalDigits:s}=t;return new _f(C.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds precision: expected at most ${a} total digits, got ${s}`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${a} total digits. The value \`${i}\` has ${s}.`})}function Kg(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,decimalDigits:s}=t;return new _f(C.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds scale: expected at most ${o} decimal digits, got ${s}`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${o} decimal places. The value \`${i}\` has ${s}.`})}function qg(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid boolean value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is a boolean column. Use \`true\`/\`false\`, \`1\`/\`0\`, or \`'yes'\`/\`'no'\`.`})}function Jg(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid datetime value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` expects a date or time value. Supported formats include \`'YYYY-MM-DD'\`, \`'HH:MM:SS'\`, \`'YYYY-MM-DD HH:MM:SS'\`, \`'MM/DD/YYYY'\`, \`'D MMM YYYY'\`, or \`'MMM D, YYYY'\`.`})}function Yg(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid string value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is a string column. Values must be wrapped in quotes.`})}function Xg(e,t){let{colName:n,typeName:r,typeArg:i,maxLength:a,actualLength:o}=t;return new _f(C.INVALID_RECORDS_FIELD,`String value for column \`${n}\` exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${i})\`, limiting values to ${a} bytes in UTF-8 encoding. The provided value uses ${o} bytes.`})}function Zg(e,t,n){let{table:r,columns:i}=n,a=zg(e,r,i),o=Bg(i,`PK`);return new _f(C.INVALID_RECORDS_FIELD,`NULL in ${o}: \`${a}\` cannot be NULL`,t,{category:hf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key and cannot be NULL.`})}function Qg(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=zg(e,r,i),s=Bg(i,`PK`);return new _f(C.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:hf.RecordConstraintViolation,explanation:`\`${o}\` is a primary key and must be unique across all rows.`})}function $g(e,t,n){let{table:r,columns:i}=n,a=zg(e,r,i),o=Bg(i,`PK`);return new _f(C.INVALID_RECORDS_FIELD,`${o}: Column \`${a}\` is missing from record and has no default value`,t,{category:hf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key with no default or auto-increment, so it must be specified in the records block.`})}function e_(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=zg(e,r,i,s),u=zg(e,a,o,s);return new _f(C.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` must not be NULL`,t,{category:hf.RecordConstraintViolation,explanation:`\`${l}\` references \`${u}\`, so every row must have a non-null value.`})}function t_(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=zg(e,r,i,s),u=zg(e,a,o,s);return new _f(C.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` does not exist in \`${u}\``,t,{category:hf.RecordConstraintViolation,explanation:`\`${l}\` is a foreign key referencing \`${u}\`. Every non-null value in an FK must match an existing row in the referenced column.`})}function n_(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=zg(e,r,i),s=Bg(i,`UNIQUE`);return new _f(C.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:hf.RecordConstraintViolation,explanation:`\`${o}\` has a unique constraint, so no two rows can have the same value.`})}function r_(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function i_(e,t){return e?`${e}.${t}`:`${y}.${t}`}function a_(e,t,n){return n.map(n=>{let r=t[n.name??``]?.value;if(r==null){let t=n.default(e);if(t)return JSON.stringify(t.value)}return JSON.stringify(r)}).join(`|`)}function o_(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function s_(e,t,n){let r=n.map(n=>{let r=n.name??``,i=t[r]===void 0?n.default(e)?.value:t[r].value;return JSON.stringify(i)}).join(`, `);return n.length===1?r:`(${r})`}function c_(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function l_(e,t){let{token:n}=t;return e.nodeAtPosition(n.filepath,n.start.offset)??e.parse.ast(n.filepath)}function u_(e,t,n,r){return Oa(r.values)?[]:xa(h_(t,e),i=>d_(e,t,n,i,r))}function d_(e,t,n,r,i){let a=r_(i),o=m_(e,t,n,r,i);if(!Oa(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=_(a,t=>o_(e,t,s)),u=f_(e,t,s,c),d=r.some(t=>t.increment(e))?[]:p_(e,t,r,l);return[...u,...d]}function f_(e,t,n,r){if(Oa(r))return[];let i=n.map(e=>e.name??``);return xa(r,r=>c_(r,i).map(r=>Zg(e,l_(e,r),{table:t,columns:n})))}function p_(e,t,n,r){let i=n.map(e=>e.name??``);return xa(ma(wa(r,t=>a_(e,t,n)),e=>e.length>1),r=>xa(r,r=>{let a=s_(e,r,n);return c_(r,i).map(r=>Qg(e,l_(e,r),{table:t,columns:n,valueStr:a}))}))}function m_(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=da(a,Array.from(o));if(Oa(s))return[];let c=new Set(s),l=r.filter(e=>c.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e));return Oa(l)?[]:i.values.map(()=>$g(e,n,{table:t,columns:l}))}function h_(e,t){let n=e.mergedColumns(t),r=ka(n,e=>e.name??``);return[...n.filter(e=>e.pk(t)).map(e=>[e]),...e.mergedIndexes(t).flatMap(e=>{let n=t.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.pk).map(e=>Qr(e.columns.map(e=>r[e.value]))):[]})]}function g_(e,t,n){if(Oa(n.values))return[];let r=r_(n);return xa(__(e,t),n=>v_(e,t,n,r))}function __(e,t){let n=t.mergedColumns(e),r=ka(n,e=>e.name??``);return[...n.filter(t=>t.isUniqueSet(e)).map(e=>[e]),...t.mergedIndexes(e).flatMap(t=>{let n=e.interpretMetadata(t,t.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.unique).map(e=>Qr(e.columns.map(e=>r[e.value]))):[]})]}function v_(e,t,n,r){let i=n.map(e=>e.name??``);return xa(ma(wa(r.filter(t=>!o_(e,t,n)),t=>a_(e,t,n)),e=>e.length>1),r=>xa(r,r=>{let a=s_(e,r,n);return c_(r,i).map(r=>n_(e,l_(e,r),{table:t,columns:n,valueStr:a}))}))}function y_(e,t,n){let r=new Map;for(let i of e.values()){let{name:e,schema:a}=i.tableSymbol.interpretedName(t,n);r.set(i_(a,e),i)}return r}function b_(e,t,n,r){let i=y_(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!Oa(t.record.values)&&a.add(e);return xa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(i_(e.schemaName,e.tableName))):!1),t=>x_(e,t,i,r))}function x_(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(i_(i.schemaName,i.tableName)),s=n.get(i_(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=Qr(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=Qr(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=Zd(i.relation),{min:m,max:h}=Zd(a.relation),ee=p===1&&m===0||p!==`*`&&h!==`*`,te=h===1&&f===0;return[...ee?[]:S_(e,o,u,s,d,i.relation,a.relation,r),...te?[]:S_(e,s,d,o,u,a.relation,i.relation,r)]}function S_(e,t,n,r,i,a,o,s){if(!t.record||Oa(t.record.values))return[];let{min:c,max:l}=Zd(a),{min:u,max:d}=Zd(o),f=Qr(n.map(e=>e.name));Qr(i.map(e=>e.name));let p=u===0,m=r_(t.record),h=r.record?r_(r.record):[],ee=new Set(h.map(t=>a_(e,t,i))),te={leftTable:t.tableSymbol,leftColumns:n,rightTable:r.tableSymbol,rightColumns:i,filepath:s};return xa(m,t=>{if(o_(e,t,n)){if(p)return[];let r=s_(e,t,n);return c_(t,f).map(t=>e_(e,l_(e,t),{...te,valueStr:r}))}if(d===`*`&&c===0&&l===`*`)return[];let r=a_(e,t,n);if(ee.has(r))return[];let i=s_(e,t,n);return c_(t,f).map(t=>t_(e,l_(e,t),{...te,valueStr:i}))})}function C_(e){return e instanceof Wh&&e.declaration instanceof R&&e.declaration.body instanceof H}function w_(e,t){let n=e.edges??[];if(n.length===0||!C_(t))return[];let r=[],i=i_(n[0].downstream.schemaName,n[0].downstream.tableName);for(let e=1;e<n.length;e++){let a=i_(n[e].downstream.schemaName,n[e].downstream.tableName);if(a!==i){r.push(new w(C.DEP_MIXED_DOWNSTREAM_TABLES,`All edges in a Dep block must target the same downstream table, but found '${i}' and '${a}'`,t.declaration));break}}let a=e=>e.upstream.fieldNames.length>0||e.downstream.fieldNames.length>0,o=a(n[0]);for(let e=1;e<n.length;e++)if(a(n[e])!==o){r.push(new w(C.DEP_MIXED_LEVEL,`All edges in a Dep block must be at the same level (all table-level or all column-level)`,t.declaration));break}return r}function T_(e){let t=e.targetKind?.value?.toLowerCase();return Object.values(Ip).find(e=>e.toLowerCase()===t)}function E_(e,t,n){let r=[];return t.length>1&&r.push(...t.map(t=>new w(n.duplicate,`'${e}' can only appear once`,t))),t.forEach(t=>{Lf(t.value)||r.push(new w(n.invalidValue,`Custom setting '${e}' must be a string or a color literal`,t.value||t.name||t))}),r}function D_(e,t,n){if(!n.length)return;let{name:r,symbolKind:i}=n[0],a=e.lookupMembers(t,i,r);return n.length>1&&a?D_(e,a,n.slice(1)):a}function O_(e,t){if(e.length===0)return[];let n;switch(t){case Ip.Table:n=[...Array(e.length-1).fill(F.Schema),F.Table];break;case Ip.Column:n=e.length===1?[F.Column]:[...Array(e.length-2).fill(F.Schema),F.Table,F.Column];break;case Ip.TableGroup:n=[...Array(e.length-1).fill(F.Schema),F.TableGroup];break;case Ip.Note:n=[...Array(e.length-1).fill(F.Schema),F.StickyNote];break;default:break}return e.map((e,t)=>({name:e,symbolKind:n[t]}))}function k_(e,t){let n=Gm(e,t.filepath);if(!n)return;let r=T_(t),i=j(t.name);if(!i?.length||!r)return;let a=O_(i,r),{name:o,symbolKind:s}=a[0];if(o===`public`&&s===F.Schema){let t=Wm(e,n);if(t)return D_(e,t,a.slice(1))}return D_(e,n,a)}function A_(e,t){let n=[],r=new Set,i=t=>{let a=t.intern();if(!r.has(a)){r.add(a);for(let n of e.fileDependencies(t))i(n);n.push(t)}};i(t);let a=new Map;return n.forEach((e,t)=>a.set(e.intern(),t)),a}function j_(e,n,r,i,a){let o=Gm(e,a);if(!o)return;let s=e.symbolMetadata(r).filter(t=>t.owners(e).includes(o));if(!s.length)return;let c=A_(e,a),l=[...s].sort((e,t)=>{let n=c.get(e.declaration.filepath.intern())??-1,r=c.get(t.declaration.filepath.intern())??-1;return n===r?e.declaration.start-t.declaration.start:n-r}).map(n=>e.interpretMetadata(n,a).getFiltered(t)).filter(e=>!!e);if(!l.length)return;let u={};for(let e of l)for(let[t,{value:n,token:r}]of Object.entries(e))u[t.toLowerCase()]={originalKey:t,value:n,token:r};let d=n.metadata?Object.fromEntries(Object.entries(n.metadata).map(([e,t])=>[e.toLowerCase(),{originalKey:e,value:t}])):{};Object.entries(u).forEach(([e,t])=>{let{originalKey:r,value:a,token:o}=t;i[e]?i[e].assignBuiltinField(n,a,o):d[e]={originalKey:r,value:a}}),n.metadata=Object.fromEntries(Object.values(d).map(e=>[e.originalKey,e.value]))}function M_(e,t,n,r,i){let a=[],o=Gm(e,n);if(!o)return a;let s=A_(e,n),c=e.symbolMetadata(t).filter(t=>t instanceof Zh&&t.owners(e).includes(o)).sort((e,t)=>{let n=s.get(e.declaration.filepath.intern())??-1,r=s.get(t.declaration.filepath.intern())??-1;return n===r?e.declaration.start-t.declaration.start:n-r});for(let e of c){Object.assign(r,B_(e).getValue());let t=e.declaration.name?e.declaration.targetKind?.value:void 0;i&&t&&i.toLowerCase()!==t.toLowerCase()&&a.push(new gf(C.METADATA_KIND_MISMATCH,`${G(e.declaration.name)} is a ${i}, not a ${t}`,e.declaration))}return a}function N_(e){let t=jh(e);if(!t)return null;let n=Mh(t);return n?{value:n,token:P(t)}:null}function P_(e,r,i){let a=r.declaration;if(!(a instanceof R))return new n(void 0);let o=dh(a),s=G(a.name)??``,c=P(a),l=G(a.alias)??null,u=yh(a.attributeList);if(Ih(a,u,o===`node`),o===`group`){let o=[];for(let n of bh(a))if(n instanceof V)for(let r of[n.callee,...n.args]){if(!D(r))continue;let n=e.nodeReferee(r).getFiltered(t),a=n&&Bh(e,n,i);a!==void 0&&!o.includes(a)&&o.push(a)}let d=M_(e,r,i,u);return new n({name:s,alias:l,children:o,settings:u,note:N_(a),token:c},[],d)}let{type:d,image:f}=F_(u.type),p=I_(u.type,a),m=lh(a),h=zh(e,a.filepath,m)??m;return p.push(...M_(e,r,i,u,h)),new n({name:s,alias:l,kind:h,type:d,image:f,settings:u,note:N_(a),token:c},[],p)}function F_(e){let t=typeof e==`string`?e.trim():``;return t?Ph.test(t)?{type:null,image:t}:{type:Qm(t)?Xm(t):null,image:null}:{type:null,image:null}}function I_(e,t){let n=typeof e==`string`?e.trim():``;return!n||Ph.test(n)||Qm(n)?[]:/^[a-z]+:/i.test(n)?[new gf(C.BAD_IMAGE,`${Fh} Got: ${n}`,t)]:[new gf(C.UNKNOWN_TYPE,`There is no type called ${n}. ${sh(n)}`,t)]}function L_(e){let t=e.declaration;if(!(t instanceof R))return new n(void 0);let r=yh(t.attributeList),i=typeof r.icon==`string`?r.icon:`box`,a=Ph.test(i)?i:null,o=typeof r.glyph==`string`?r.glyph.split(`;`).map(e=>e.trim()).filter(Boolean):null,s=[];if(typeof r.icon==`string`&&!a&&!Qm(i)){let e=/^[a-z][a-z0-9+.-]*:/i.test(i);s.push(new gf(e?C.BAD_IMAGE:C.UNKNOWN_ICON,e?`${Fh} Got: ${i}`:`There is no icon called ${i}. ${sh(i)}`,t))}return new n({name:G(t.name)??``,icon:!a&&Qm(i)?Xm(i):`box`,glyph:o?.length?o:null,image:a,category:`custom`,color:typeof r.color==`string`?r.color:null,builtin:!1,token:P(t)},[],s)}function R_(){return Object.entries($m).map(([e,t])=>({name:e,icon:t.icon,glyph:null,image:null,category:t.category,color:null,builtin:!0,token:null}))}function z_(e,t,r){let{declaration:i}=t,a=t.op(),[o,s]=t.endpoints(e),c=o&&Bh(e,o,r),l=s&&Bh(e,s,r);return!a||c===void 0||l===void 0?new n(void 0):new n({from:c,to:l,op:a,settings:i instanceof R?yh(Th(i)?.row?.settings??i.attributeList):{},token:P(i)})}function B_(e){let t={},r=new Set;for(let n of bh(e.declaration)){let e=n instanceof R?kh(n):void 0;!e||e.value===void 0||r.has(e.key)||(r.add(e.key),t[e.key]=e.value)}return new n(t)}function V_(e,t){let n=G_(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof z?up(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof R){let n=K_(e,t);if(n)return{kind:`body`,declaration:n}}}function H_(e,t){let n=G_(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof R){let n=e.body;if(n&&!(n instanceof V))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function U_(e,t,n,r){if(n===null)return W_(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=V_(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return H_(e,i)}function W_(e,t,n){let r=V_(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function G_(e){if(e instanceof V)return e.args.find(e=>e instanceof U);if(e instanceof R){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof V)return t.args.find(e=>e instanceof U)}}function K_(e,t){let n=e.body;if(!(!n||Tf(e)||n instanceof V)){for(let e of n.body)if(e instanceof R&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function q_(e,t,n,r){let{allowOtherColFix:i=!0,allowOwnColFix:a=!0}=r??{},o=t.op(e),s=t.opToken(),c=t.cardinalities(e);if(!o||!s||!c)return[];let l=n===`left`?c[0]:c[1],u=Zd(l),d=n===`left`?c[1]:c[0],f=Zd(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),h=n===`left`?t.leftToken():t.rightToken(),ee=n===`left`?t.rightToken():t.leftToken(),te=[];function ne(e,t,n){te.push(n(e));for(let r of t)r.declaration&&r.declaration!==e&&te.push(n(r.declaration))}let re=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&re&&m.length>0&&m.every(t=>t.nullable(e))){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Y_(s,ff(l),d,n,`Make '${r}' optional in the ref`),...i?m.map(t=>X_(t,e)).filter(e=>!!e):[]].filter(e=>!!e);ne(ee,m,n=>Fg(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.min===0&&re&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Y_(s,pf(l),d,n,`Make '${r}' required in the ref`),...i?m.map(t=>Z_(t,e)).filter(e=>!!e):[]].filter(e=>!!e);ne(ee,m,n=>Ig(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.max===`*`&&Q_(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Y_(s,`1`,d,n,`Make '${r}' one in the ref`)].filter(e=>!!e);ne(h,p,n=>Lg(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}if(u.max===1&&!Q_(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Y_(s,mf(l),d,n,`Make '${r}' many in the ref`),a&&p.length===1&&$_(p[0],e)].filter(e=>!!e);ne(h,p,n=>Rg(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}return te}function J_(e,t){return[...q_(e,t,`right`,{allowOtherColFix:!1}),...q_(e,t,`left`,{allowOwnColFix:!1})]}function Y_(e,t,n,r,i){let a=df(r===`left`?t:n,r===`right`?t:n);return{title:`${i} (change operator to '${a}')`,shortTitle:`Change to ${a}`,filepath:e.filepath,edits:[{start:e.start,end:e.end,newText:a}],isPreferred:!0}}function X_(e,t){if(!e.declaration||e.pk(t)||e.increment(t)||e.isNotNullSet(t))return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=e.qualifiedName(t).join(`.`),i=W_(e.declaration,`null`,n);if(i)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[i]};let a=H_(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[a]}}function Z_(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=W_(e.declaration,`not null`,n);if(r)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as NULL`,shortTitle:`Make nullable`,filepath:e.declaration.filepath,edits:[r]}}function Q_(e,n){if(n.length===0)return!1;if(n.length===1&&n[0].unique(e))return!0;let r=n[0],i=(r instanceof om?r.injectionDeclaration:r.declaration)?.parentOfKind(R);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof Hp))return!1;let o=a.mergedIndexes(e),s=new Set(n.map(e=>e.name));for(let t of o){let r=e.interpretMetadata(t,n[0].filepath).getValue();if(!(!r||!Array.isArray(r))){for(let e of r)if(!(!e.unique&&!e.pk)&&e.columns.length===s.size&&e.columns.every(e=>s.has(e.value)))return!0}}return!1}function $_(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=H_(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,shortTitle:`Add unique`,filepath:e.declaration.filepath,edits:[n]}}var ev=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],this.arch={nodes:[],groups:[],links:[],kinds:[],importedKinds:[]},this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],deps:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:P(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.infos.push(...this.validateRecords()),this.finishArch(),new n(this.db,this.errors,this.warnings,this.infos)}finishArch(){let e=this.compiler.parsedFileKind(this.filepath)===`arch`,t=new Map;for(let e of this.arch.kinds)t.set(e.name.toLowerCase(),e);for(let e of this.arch.importedKinds)t.has(e.name.toLowerCase())||t.set(e.name.toLowerCase(),e);if(e||this.arch.nodes.length)for(let e of R_())t.has(e.name.toLowerCase())||t.set(e.name.toLowerCase(),e);let n=new Set([...[...this.arch.nodes,...this.arch.groups].map(e=>e.alias??e.name),...this.db.notes.map(e=>e.name)]),r=new Map;for(let e of this.arch.groups){let t=e.alias??e.name;for(let i of e.children)n.has(i)&&!r.has(i)&&r.set(i,t)}for(let e of this.arch.groups){let t=e.alias??e.name;e.children=e.children.filter(e=>r.get(e)===t)}let i=new Set;for(let{link:e,declaration:t}of this.arch.links){let n=[e.from,e.to].sort().join(`\0`);i.has(n)&&this.warnings.push(new gf(C.DUPLICATE_LINK,`${e.from} and ${e.to} are already connected`,t)),i.add(n),(r.get(e.from)===e.to||r.get(e.to)===e.from)&&this.warnings.push(new gf(C.NESTED_ENDPOINTS,`${e.from} is already inside ${e.to}`,t))}let a={nodes:this.arch.nodes,groups:this.arch.groups,links:this.arch.links.map(({link:e})=>e),kinds:[...t.values()]};for(let[t,n]of Object.entries(a))(e||n.length)&&(this.db[t]=n);let o={...this.compiler.scanFile(this.filepath).frontMatter,...e?tv(this.programNode):{}};Object.keys(o).length&&(this.db.frontMatter=o),e&&(this.db.diagramType=`arch`)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof am)continue;let r=this.compiler.interpretSymbol(n,this.filepath);if(r.hasValue(t))continue;this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let i=r.getValue();i&&this.pushElement(n,i)}let e=new Set,n=(this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[]).filter(e=>e instanceof zp);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof zp){n.push(t);continue}if(!(t instanceof am))continue;let r=t.originalSymbol.intern();e.has(r)||(e.add(r),this.interpretUseSymbol(t))}}}interpretUseSymbol(e){let n=e.originalSymbol,r=this.compiler.interpretSymbol(n,this.filepath);if(!r.hasValue(t)){this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let t=r.getValue();t&&this.pushElement(e,t)}let i=n instanceof Hp?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Hp?n.interpretedName(this.compiler,this.filepath):{name:e.name??n.name??``,schema:null},o={name:i.name,schemaName:i.schema,filepath:n.filepath,visibleNames:[{schemaName:a.schema,name:a.name}]};Ag(this.db,e,o)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],n=new Set,r=new Set,i=new Map;for(let t of e){if(!(t instanceof Jh))continue;let e=t.table(this.compiler);if(!e)continue;let n=e.originalSymbol.intern(),r=i.get(n);r?r.count++:i.set(n,{count:1,tableName:e.name??``})}for(let a of e){let e=this.compiler.interpretMetadata(a,this.filepath);if(e.hasValue(t))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings()),this.infos.push(...e.getInfos());let o=e.getValue();if(o!==void 0)switch(a.kind){case Vh.Ref:{let e=o,[t,r]=e.endpoints??[];if(t&&r){let e=[t.schemaName,t.tableName,t.fieldNames.join(`,`),r.schemaName,r.tableName,r.fieldNames.join(`,`)].join(`|`),i=[r.schemaName,r.tableName,r.fieldNames.join(`,`),t.schemaName,t.tableName,t.fieldNames.join(`,`)].join(`|`);if(n.has(e)||n.has(i)){this.errors.push(new w(C.SAME_ENDPOINT,`Ref with same endpoints already exists`,a.declaration));break}n.add(e)}this.db.refs.push(e);break}case Vh.Dep:{let e=o,t=a instanceof Wh?a.edgeExpressions():[],n=-1;if((e.edges??[]).some((e,t)=>{let{upstream:i,downstream:a}=e,o=[i.schemaName,i.tableName,i.fieldNames.join(`,`),a.schemaName,a.tableName,a.fieldNames.join(`,`)].join(`|`);return r.has(o)?(n=t,!0):(r.add(o),!1)}),n>=0){let e=t[n]??a.declaration;this.errors.push(new w(C.SAME_ENDPOINT,`Dep with same endpoints already exists`,e));break}let i=w_(e,a);if(i.length>0){this.errors.push(...i);break}this.db.deps.push(e);break}case Vh.Records:if(a instanceof Jh){let e=a.table(this.compiler)?.originalSymbol.intern()??``,t=e?i.get(e):void 0;if(t&&t.count>1){this.errors.push(new w(C.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,a.declaration));break}}this.db.records.push(o);break;case Vh.Project:this.db.project=o;break;case Vh.Link:this.arch.links.push({link:o,declaration:a.declaration});break;case Vh.MetadataElement:default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof im)||!t.isKind(F.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:Nm.Table,value:{tableName:e,schemaName:n}};this.db.aliases.push(r)}}validateRecords(){let e=[],n=new Map,r=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let e of r){if(!(e instanceof zp))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(F.Table))continue;let t=e.originalSymbol;if(!(t instanceof Hp))continue;let r=t.intern();n.has(r)||n.set(r,{tableSymbol:t,record:void 0,recordBlock:t.declaration})}}let i=this.compiler.symbolMetadata(this.programSymbol);for(let r of i){if(!(r instanceof Jh))continue;let i=r.table(this.compiler);if(!(i instanceof Hp))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...u_(this.compiler,i,r.declaration,o)),e.push(...g_(this.compiler,i,o));let s=i.originalSymbol.intern(),c=n.get(s);c?c.record=o:n.set(s,{tableSymbol:i,record:o,recordBlock:r.declaration})}let a=this.collectPartialRefs(n);return e.push(...b_(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Gh);for(let t of e)this.infos.push(...J_(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Gh),n=[];for(let{tableSymbol:r}of e.values())for(let e of r.resolvedPartials(this.compiler))for(let i of t){if(i.leftTablePartial(this.compiler)?.originalSymbol!==e.originalSymbol)continue;let t=i.leftColumns(this.compiler),a=i.rightTable(this.compiler),o=i.rightColumns(this.compiler),s=i.op(this.compiler);if(!a||!s||t.length===0||o.length===0)continue;let c=r.mergedColumns(this.compiler);if(!t.some(e=>c.some(t=>t instanceof om&&t.declaration===e.declaration)))continue;let l=af(s);if(!l)continue;let u=a instanceof Yp&&a.originalSymbol===e.originalSymbol?r:a,d=r.interpretedName(this.compiler,this.filepath),f=u.interpretedName(this.compiler,this.filepath),p={schemaName:d.schema,tableName:d.name,fieldNames:t.map(e=>e.name??``),relation:l[0],token:P(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:P(i.rightToken())};n.push({token:P(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case F.Element:dh(e.originalSymbol.declaration)===`group`?this.arch.groups.push(t):this.arch.nodes.push(t);break;case F.Kind:e instanceof am?this.arch.importedKinds.push(t):this.arch.kinds.push(t);break;case F.Table:this.db.tables.push(t);break;case F.Enum:this.db.enums.push(t);break;case F.TableGroup:this.db.tableGroups.push(t);break;case F.TablePartial:this.db.tablePartials.push(t);break;case F.StickyNote:this.db.notes.push(t);break;case F.DiagramView:this.db.diagramViews.push(t);break;default:break}}};function tv(e){let t={};for(let n of e.body)if(!(!uh(n)||dh(n)!==`project`))for(let e of bh(n)){let n,r;if(e instanceof R)n=lh(e)?.toLowerCase(),r=G(xh(bh(e)[0])?.callee);else{let t=xh(e);n=G(t?.callee)?.toLowerCase(),r=G(t?.args[0])}!n||n===`diagram_type`||r===void 0||(t[n]=r)}return t}var nv={nodeSymbol(t,r){return Uf(r)?n.create(t.symbolFactory.create(rm,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Program))return n.create(e);if(!(i.declaration instanceof L))return n.create([]);let a=new Map;for(let e of r.reachableFiles(i.filepath)){let{schemaMembers:t}=r.usableMembers(e).getValue();for(let e of t)a.has(e.name)||a.set(e.name,e)}let o=a.get(y);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(F.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Uf(r)?new Og(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof rm))return n.create(e);if(!(r.declaration instanceof L))return n.create(void 0);if(!Bm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new ev(t,r,i).interpret()}},rv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof V)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},iv=class{constructor(e,t,n){this.declarationNode=t,this.compiler=e,this.filepath=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){this.project.token=P(this.declarationNode);let e=[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)];return new n(this.project,e)}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=kp(e);return this.project.name=t,[]}interpretSubElement(e){let r=this.compiler.nodeSymbol(e).getFiltered(t);if(r){let e=this.compiler.interpretSymbol(r,this.filepath);if(!e.hasValue(t))return e}return n.create(void 0)}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.getElementKind()){case r.Table:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tables?.push(e.getValue()),e.getErrors()}case r.TableGroup:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tableGroups?.push(e.getValue()),e.getErrors()}case r.Enum:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.enums?.push(e.getValue()),e.getErrors()}case r.Note:{let e=t.body instanceof H?t.body.body[0]?.callee:t.body?.callee,n=e?M(e):void 0;return n&&(this.project.note={value:Op(n),token:P(t)}),[]}case r.TablePartial:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tablePartials?.push(e.getValue()),e.getErrors()}default:return this.project[t.type.value.toLowerCase()]=M(t.body.callee),[]}})}},av={nodeMetadata(t,i){return k(i,r.Project)?n.create(new Qh(i)):n.create(e)},bindNode(t,i){return k(i,r.Project)?n.create(void 0,new rv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Qh)||!(r.declaration instanceof R)?n.create(e):new iv(t,r.declaration,i).interpret()}},ov=class{constructor(e,t){this.compiler=e,this.declarationNode=t,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof H&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof L?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=cp(e);if(!n)return[];let r=n.variables.pop(),i=n.variables;if(!r)return[];let a=this.compiler.nodeReferee(r).getErrors();if(a.length>0)return a;let o=this.compiler.nodeReferee(r).getFiltered(t);if(!o)return[];let s=tp(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=lp(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new w(C.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new w(C.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new w(C.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,e))),this.boundColumns.set(r,e)}return c}bindInsideTableName(e){let n=this.declarationNode.parent;if(!(n instanceof R)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Ff(e))return[];let i=tp(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=lp(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new w(C.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n));continue}}return a}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof V),n=e.body.filter(e=>e instanceof R);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof Cm?e.callee.elementList:[e.callee]).flatMap(Vm).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();return!t||!n?[]:[...e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors()),...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}):[]}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},sv=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=cv(this.element,this.compiler,this.filepath);if(!r||r.columns.length===0)return new n(void 0,e);let i=[];for(let n of this.element.body.body){let a=lv(n,r.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getInfos());let o=a.getValue();o.row&&i.push(o.row)}let a=P(this.element),o=this.metadata.example(this.compiler)||void 0;return new n({schemaName:r.schemaName,tableName:r.tableName,columns:r.columns.map(e=>e.name??``),values:i,example:o,token:a},e,[],t)}};function cv(e,n,i){let a=e.name,o=e.parent;if(o instanceof R&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Hp))return;let r=e.mergedColumns(n),s=e.interpretedName(n,i),c=s.schema,l=s.name;return a?{schemaName:c,tableName:l,columns:a.elementList.flatMap(e=>r.find(t=>t.name===N(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=cp(a);if(!s)return;let c=s.variables.map(e=>e.expression.variable?.value??``),l=c.at(-1)??``,u=c.length>1?c.slice(0,-1).join(`.`):void 0,d=n.parseFile(e.filepath).getValue().ast,f=n.nodeSymbol(d).getFiltered(t);if(!f)return;let p;if(u){let e=n.lookupMembers(f,F.Schema,u);e&&(p=n.lookupMembers(e,F.Table,l))}if(p||=n.lookupMembers(f,F.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Hp))return;let h=m.mergedColumns(n),ee=s.args.map(e=>h.find(t=>t.name===N(e))).filter(Boolean),te=m.interpretedName(n,i);return{schemaName:te.schema,tableName:te.name,columns:ee}}function lv(e,t,r){let i=[],a=[],o={},s=e.callee instanceof Cm?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new w(C.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new n({row:null,columnNodes:{}},i,[],a);let c=[];for(let e=0;e<t.length;e++){let n=s[e],l=t[e];o[l.name??``]=n;let u=dv(n,l,r);i.push(...u.getErrors()),a.push(...u.getInfos());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:P(n)})}return new n({row:c,columnNodes:o},i,[],a)}function uv(e){return e instanceof xm&&e.value?.value||``}function dv(e,t,r){let i=P(e),a=t.type(r),o=(a?.name??``).split(`(`)[0],s=!!a?.enumSymbol,c=t.increment(r),l=t.isNotNullSet(r)===!0,u=t.default(r),d=t.name??``,f=Lo(o,s),p=xp(e),m=p===null?uv(e):p,h=p===null?`expression`:f;if(e instanceof xm)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(dp(e)||fp(e)&&!No(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Io(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[],[Vg(e,{colName:d})]):new n({value:null,type:f,token:i},[],[])}if(s){let a=t.type(r)?.enumSymbol,o=a?a.members(r).filter(e=>e.isKind(F.EnumField)).map(e=>e.name).filter(Boolean):[],s=M(e);return s===void 0&&(s=D(e)?e.expression.variable.value:void 0),o.includes(s)?new n({value:s,type:f,token:i},[],[]):new n({value:s,type:f,token:i},[],[],[Hg(e,{colName:d})])}if(ko(o)||Ao(o)||Io(o)){let t=mp(e);if(t===null)return new n({value:m,type:h,token:i},[],[],[Ug(e,{colName:d,typeName:o})]);if(ko(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[],[Wg(e,{colName:d,value:t})]);let r=Ao(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Ao(o)&&r){let{precision:a,scale:s}=r,c=t.toString().split(`.`),l=c[0].replace(/^-/,``),u=c[1]||``,p=l.length+u.length,m=u.length;if(p>a)return new n({value:t,type:f,token:i},[],[],[Gg(e,{colName:d,typeName:o,value:t,precision:a,scale:s,totalDigits:p})]);if(m>s)return new n({value:t,type:f,token:i},[],[],[Kg(e,{colName:d,typeName:o,value:t,precision:a,scale:s,decimalDigits:m})])}return new n({value:t,type:f,token:i},[],[])}if(Mo(o)){let t=yp(e);return t===null?new n({value:m,type:h,token:i},[],[],[qg(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Fo(o)){let t=Tp(e);return t===null?new n({value:m,type:h,token:i},[],[],[Jg(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(No(o)){let t=xp(e);if(t===null)return new n({value:m,type:h,token:i},[],[],[Yg(e,{colName:d})]);let r=a?.args?.length?Number(a.args[0]):void 0;if(r&&!Number.isNaN(r)){let s=r,c=new TextEncoder().encode(t).length;if(c>s)return new n({value:t,type:f,token:i},[],[],[Xg(e,{colName:d,typeName:o,typeArg:String(a.args[0]),maxLength:s,actualLength:c})])}return new n({value:t,type:`string`,token:i},[],[])}return new n({value:m,type:h,token:i},[],[])}var fv={nodeMetadata(t,i){if(!k(i,r.Records))return n.create(e);let a=i.parent;if(a&&k(a,r.Table))return n.create(new Jh(i));let o=i.name;return o instanceof Tm&&o.callee?n.create(new Jh(i)):n.create(e)},nodeReferee(i,a){if(!D(a))return n.create(e);let o=a.parentOfKind(R);if(!o?.isKind(r.Records))return n.create(e);let s=i.parseFile(a.filepath).getValue().ast,c=i.nodeSymbol(s).getFiltered(t);if(!c)return n.create(void 0);let l=a.parentOfKind(Sm);if(l?.parentNode===o)return pv(i,o,a);let u=a.parentOfKind(Tm);return u?.parentNode===o&&l?.parentNode===u?mv(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?hv(i,c,a):_v(i,c,a)},bindNode(t,i){return k(i,r.Records)?n.create(void 0,new ov(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Jh?r.declaration instanceof R?new sv(t,r,i).interpret():n.create(void 0):n.create(e)}};function pv(e,i,a){let o=i.parent;if(o instanceof R&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return gv(e,n,a)}return new n(void 0)}function mv(e,r,i){if(r.callee){let n;if(D(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=ip(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return gv(e,n,i)}return new n(void 0)}function hv(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode)){let a=e.lookupMembers(t,[F.Table,F.Schema],i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Hm(e,r);if(!a){let a=e.lookupMembers(t,[F.Table,F.Schema],i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Table,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function gv(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``,a=e.lookupMembers(t,F.Column,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function _v(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return new n(void 0);let a=Hm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var vv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Vm).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();return!t||!n?[]:(Array.isArray(t)||(t=[t]),[...e.variables,n,...t].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},yv=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()],{infos:t}=this.validateRefConstraints();return n.create(this.ref,e,void 0,t)}interpretName(){if(!(this.declarationNode instanceof R))return[];let e=[],t=j(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if(La(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new w(C.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=af(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=P(this.metadata.leftToken()),l=P(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof R?[{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c},{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l}]:[{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l},{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c}],!(this.declarationNode instanceof R))return[];let u=rp(this.declarationNode)[0];if(u.args[0]){let e=T(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof vm?ep(t):N(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof vm?ep(n):N(n),this.ref.color=e.color?.length?Ap(e.color?.at(0)?.value):void 0,this.ref.inactive=e.inactive?.length?!0:void 0}return[]}validateRefConstraints(){return this.metadata.cardinalities(this.compiler)?{infos:[...q_(this.compiler,this.metadata,`right`),...q_(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function bv(e){let t=e.parent;for(;t;){if(t instanceof R&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var xv={nodeReferee(r,i){if(!D(i)&&!O(i)||!bv(i)||i.parentOfKind(z))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):Sv(r,o,i)},nodeMetadata(t,a){if(k(a,r.Ref)){let t=rp(a)[0];if(!(t instanceof V)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof ym)||!r.op?n.create(e):n.create(new Uh(a))}if(a instanceof z){if(!(a.name instanceof vm)||ep(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof R&&t.isKind(r.TablePartial)?n.create(new Gh(a)):n.create(new Uh(a))}return n.create(e)},bindNode(t,i){return k(i,r.Ref)?n.create(void 0,new vv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Uh?new yv(t,r,i).interpret():n.create(e)}};function Sv(e,r,i){if(!D(i))return new n(void 0);let a=lp(i)??``;if(!O(i.parentNode)){let r=i.parentNode;if(r&&O(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=O(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(F.Table)){let r=e.lookupMembers(c,F.Column,a);if(r)return n.create(r);let o=c.declaration?e.nodeFullname(c.declaration).getFiltered(t)?.join(`.`)??c.name:c.name;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Hm(e,i);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(F.Table)){let r=e.lookupMembers(o,F.Column,a);return r?n.create(r):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${o.declaration?e.nodeFullname(o.declaration).getFiltered(t)?.join(`.`)??o.name:o.name}'`,i)])}return new n(void 0)}let s=i.parentNode;if(s.leftExpression===i){if(O(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,F.Schema,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Wm(e,r);if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var Cv={visibleName(e,n){let r=n instanceof I?n:n.useSpecifierDeclaration instanceof gm?n.useSpecifierDeclaration:n.declaration;if(r instanceof gm&&n instanceof Rp&&r.getSymbolKind()!==n.kind&&(r=n.declaration),!r)return;let i=e.nodeAlias(r).getFiltered(t);return i===void 0?e.nodeFullname(r).getFiltered(t):[i]}},wv={nodeSymbol(r,i){if(!Hf(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===F.Schema)return n.create(e);let o=r.nodeReferee(i.name).getFiltered(t);return o&&!o.canBeImported?n.create(e):n.create(r.symbolFactory.create(am,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:Cv.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new w(C.BINDING_ERROR,`Failed to resolve the import of ${a} '${(j(i.name)||[]).map(Jv).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof am))return n.create(e);if(i.originalSymbol===i)return n.create([]);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!D(i)&&!Bf(i))return n.create(e);let a=i.parentOfKind(gm);if(!a)return n.create(e);let o=a.name===i||O(a.name)&&a.name.rightExpression===i?a.getSymbolKind():F.Schema;if(o===void 0)return n.create(void 0);let s=j(i.parentOfKind(ym)),c=N(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(hm);if(l?.importPath?.value===void 0)return n.create(void 0);let u=r.layout.resolveFileSpecifier(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new w(C.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new w(C.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toKey()}. Does the file exist?`,i)]);let d=i.parentOfKind(ym)?.leftExpression;if(d&&d!==i){let e=r.nodeReferee(d).getFiltered(t);if(!e)return n.create(void 0);let a=r.lookupMembers(e,o,c);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=Tv(r,u,c,o);return f?n.create(f):n.create(void 0,[new w(C.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toKey()}`,i)])},bindNode(t,r){if(Vf(r)){let e=[];if(r.importPath?.value){let n=t.layout.resolveFileSpecifier(r.filepath,r.importPath.value);(!n||!t.layout.exists(n))&&e.push(new w(C.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath))}if(r.specifiers){let n=t.bindNode(r.specifiers);e.push(...n.getErrors())}return new n(void 0,e)}return r instanceof _m?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):Hf(r)?r.name?new n(void 0,t.nodeReferee(r.name).getErrors()):new n(void 0):n.create(e)},interpretSymbol(r,i,a){if(!(i instanceof am))return n.create(e);if(!i.usedSymbol)return n.create(void 0);let o=r.interpretSymbol(i.usedSymbol,a);if(o.hasValue(t))return n.create(void 0);let s=o.getValue();if(!s||Array.isArray(s))return o;let c=i.name;return c&&`name`in s?n.create({...s,name:c}):n.create(s)}};function Tv(e,n,r,i,a=new Set){if(!n||a.has(n.intern()))return;a.add(n.intern());let o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.nonSchemaMembers.find(e=>e.name===r&&e.isKind(i));if(s)return s;let c=o.schemaMembers.find(e=>e.name===r);if(c?.isKind(F.Schema))return c;for(let t of o.reuses.selective)if(j(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(hm);if(o?.importPath?.value){let s=Tv(e,e.layout.resolveFileSpecifier(n,o.importPath.value),j(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=Tv(e,t,r,i,a);if(n)return n}}function Ev(e){if(e instanceof mo){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=Ov(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof rm?kv(this,e,i):Av(this,e,i);return new n({nonSchemaMembers:a,schemaMembers:o,reuses:{selective:i.selectiveReuses,wildcard:i.wildcardReuses},uses:{selective:i.selectiveUses,wildcard:i.wildcardUses}},i.parseResult.getErrors(),i.parseResult.getWarnings())}function Dv(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof gm?Cv.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof gm&&r.getSymbolKind()===F.Schema?a:a.length<=1?[y]:a.slice(0,-1);return o.length<i.length||!i.every((e,t)=>e===o[t])?{kind:`none`}:o.length===i.length?{kind:`direct`}:{kind:`child`,schemaName:o[i.length]}}function Ov(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let n of r.body){if(!(n instanceof hm)||!n.specifiers||!n.importPath)continue;let r=e.layout.resolveFileSpecifier(t,n.importPath.value);r&&(n.isReuse?n.specifiers instanceof Dm?i.push({importPath:r,node:n.specifiers}):a.push(...n.specifiers.specifiers):n.specifiers instanceof Dm?o.push({importPath:r,node:n.specifiers}):s.push(...n.specifiers.specifiers))}return{ast:r,parseResult:n,selectiveReuses:a,wildcardReuses:i,selectiveUses:s,wildcardUses:o}}function kv(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[y,e.symbolFactory.create(zp,{name:y},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?y:r[0];c.has(i)||c.set(i,e.symbolFactory.create(zp,{name:i},s))}jv(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of Nv(e,t))c.has(n)||c.set(n,e.symbolFactory.create(zp,{name:n},s));let l=[...c.values()],u=[],d=l.find(e=>e.isPublicSchema());if(d){let n=e.usableMembers(d).getFiltered(t);n&&u.push(...n.nonSchemaMembers)}return{nonSchemaMembers:u,schemaMembers:l}}function Av(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof R))continue;let i=Dv(e,n,r),a=e.nodeAlias(r).getFiltered(t),o=e.nodeSymbol(r).getFiltered(t);if(a!==void 0&&n.isPublicSchema()&&o&&s.push(e.symbolFactory.create(im,{kind:o.kind,declaration:r,aliasedSymbol:o,name:a},n.filepath)),i.kind!==`none`)if(i.kind===`direct`){let n=e.nodeSymbol(r).getFiltered(t);if(!n)continue;s.push(n)}else c.has(i.schemaName)||c.set(i.schemaName,e.symbolFactory.create(zp,{name:i.schemaName,parent:n},n.filepath))}Mv(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of Pv(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(zp,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function jv(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==F.Schema)continue;let t=Cv.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(zp,{name:t},r))}}function Mv(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==F.Schema)continue;let t=Cv.visibleName(e,a);if(!t||t.length<=i.length||!i.every((e,n)=>e===t[n]))continue;let o=t[i.length];o&&!r.has(o)&&r.set(o,e.symbolFactory.create(zp,{name:o,parent:n},n.filepath))}}function Nv(e,n){let{ast:r}=e.parseFile(n).getValue(),i=[];for(let n of r.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],a=r.length<=1?y:r[0];i.push(a)}let a=Ov(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==F.Schema)continue;let n=Cv.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function Pv(e,n,r){let{ast:i}=e.parseFile(n).getValue(),a=[];for(let n of i.declarations){let i=e.nodeFullname(n).getFiltered(t)||[],o=i.length<=1?[y]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=Ov(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==F.Schema)continue;let n=Cv.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var Fv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){let e=[];return this.declarationNode.attributeList&&e.push(...this.bindHeaderSettings(this.declarationNode.attributeList)),this.declarationNode.body instanceof H&&e.push(...this.bindBody(this.declarationNode.body)),e}bindHeaderSettings(e){return T(e).getValue().dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])??[]}bindInlineDepValue(e){return Vm(e).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);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(g(n)instanceof U){let e=T(g(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.dep?.flatMap(e=>e.value?this.bindInlineDepValue(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=>!Ef(e.callee)))}tryToBindColumnType(e){let t=ap(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(E(e))return[];if(D(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&go.includes(t))return[]}let t=ap(e);if(!t){if(O(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return Vm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Iv=class{constructor(e,t,n,r){this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=this.symbol?.token??P(this.declarationNode);let e=[];if(this.symbol){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);this.table.name=e,this.table.schemaName=t}else e.push(...this.interpretName(this.declarationNode.name));let t=[...e,...this.interpretAlias(this.declarationNode.alias),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.table.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),this.attachTableAndColumnMetadata(),n.create(this.table,t)}attachTableAndColumnMetadata(){if(!this.symbol)return;j_(this.compiler,this.table,this.symbol,Rv,this.filepath);let e=this.compiler.symbolMembers(this.symbol).getFiltered(t)??[];for(let t of e){if(!t.isKind(F.Column))continue;let e=this.table.fields.find(e=>e.name===t.name);e&&j_(this.compiler,e,t,zv,this.filepath)}}interpretName(e){let{name:t,schemaName:n}=kp(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new w(C.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=lp(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=T(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Ap(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Op(M(n?.value)),token:P(n)},this.table.metadata=Np(t,Object.keys(Rv)),[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:Op(M(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:P(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);case r.Records:return[];default:return[]}})}interpretInjection(e,n){let r=[],i={order:n,token:P(e)};i.name=N(e.expression)||``;let a=e.expression?this.compiler.nodeReferee(e.expression).getFiltered(t):void 0,o=this.compiler.parseFile(this.filepath).getValue().ast,s=this.compiler.nodeSymbol(o).getFiltered(t);if(a&&!s.inNestedSchema(this.compiler,a)){let n=this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),o=n?(this.compiler.symbolUses(n).getFiltered(t)??[]).find(e=>e.filepath.equals(this.filepath)):void 0;r.push(new w(C.UNSUPPORTED,`TablePartial ${i.name} from '${a.filepath}' should be imported. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,o?.useSpecifierDeclaration??e))}return this.table.partials.push(i),r}interpretFields(e){let n=this.symbol??this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),r=(n?this.compiler.symbolMembers(n).getFiltered(t)??[]:[]).filter(e=>e.isKind(F.Column)).length?[]:[new w(C.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Ef(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...r,...i]}interpretColumn(e){let n=[],r={},a=this.compiler.nodeSymbol(e).getFiltered(t);r.name=lp(e.callee),r.token=P(e);let o=Mp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||!1,r.unique=a?.isUniqueSet(this.compiler)||!1,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{};r.metadata=Np(s,Lv);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.endpoints?.[0])return[];let s=o.endpoints[0],c=r.op(this.compiler);return c?{schemaName:s.schemaName,tableName:s.tableName,fieldNames:s.fieldNames,relation:c,token:s.token}:[]}),r.inline_deps=(s[i.Dep]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.edges?.[0])return[];let s=e.value;if(!(s instanceof B))return[];let c=s.op?.value;if(c!==`->`&&c!==`<-`)return[];let u=o.edges[0],d=c===`->`?u.downstream:u.upstream;return{schemaName:d.schemaName,tableName:d.tableName,fieldNames:d.fieldNames,direction:c,token:d.token}}),r.checks=(s[i.Check]||[]).map(e=>({token:P(e),expression:e.value.value.value})),this.table.fields.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.indexes.push(...i):i&&this.table.indexes.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.checks.push(...i):i&&this.table.checks.push(i),r.getErrors()}},Lv=[i.Note,i.Ref,i.PrimaryKey,i.PK,i.NotNull,i.Null,i.Unique,i.Increment,i.Default,i.Check],Rv={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.HeaderColor]:{isValidBuiltinFieldValue:kf,message:`'headercolor' must be a color literal`,assignBuiltinField(e,t){e.headerColor=t}}},zv={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a quoted string`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}}},Bv={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new w(C.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new w(C.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},Vv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.Table)?new n(i.symbolFactory.create(Hp,{declaration:a,name:o},a.filepath)):A(a,r.Table)?Ef(a.callee)?new n(i.symbolFactory.create(Xp,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Up,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Table))return n.create(e);let a=i.declaration;if(!(a instanceof R))return new n([]);let o=rp(a),s=[],c=[];for(let e of o){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(s.push(i),c.push(...n.getErrors()))}let l=new Map;for(let e of s){if(!e.isKind(F.Column,F.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(F.Column)?(c.push(Bv.getColumnDuplicateError(e.name,r)),c.push(Bv.getColumnDuplicateError(e.name,n))):(c.push(Bv.getPartialInjectionDuplicateError(e.name,r)),c.push(Bv.getPartialInjectionDuplicateError(e.name,n))):l.set(t,n)}}let u=[];for(let e=0;e<s.length;e++){let n=s[e];if(!(n.declaration instanceof V)||!Ef(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=N(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new w(C.BINDING_ERROR,`TablePartial '${o}' does not exist in Schema 'public'`,i||a));continue}let d=r.symbolMembers(l).getFiltered(t);if(d){let t=d.flatMap(e=>{if(!e.declaration)return[];let t=e.name;return t===void 0?e:r.symbolFactory.create(om,{kind:F.Column,injectionDeclaration:n.declaration,declaration:e.declaration,name:t},a.filepath)});u.push({index:e,partialMembers:t})}}for(let e=u.length-1;e>=0;e--){let{index:t,partialMembers:n}=u[e];s.splice(t,0,...n)}let d=new Set(s.filter(e=>e.isKind(F.Column)&&!(e instanceof om)).map(e=>e.name));return new n(Pa([...s.filter(e=>!(e instanceof om&&d.has(e.name)))].reverse(),e=>e.isKind(F.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(qf(o,i.Dep)&&o.parent instanceof R&&o.parent.isKind(r.Table)&&!Wf(o,r.Table)){let e=a.parseFile(o.filepath).getValue().ast,r=a.nodeSymbol(e).getValue();return r===t?n.create(void 0):Gv(a,r,o)}if(!Wf(o,r.Table))return n.create(e);let s=a.parseFile(o.filepath).getValue().ast,c=a.nodeSymbol(s).getValue();return c===t?n.create(void 0):D(o)&&o.parentNode instanceof B&&o.parentNode.op?.value===`~`?Hv(a,c,o):Gf(o,1)?Uv(a,c,o):qf(o,i.Ref)?Wv(a,c,o):qf(o,i.Dep)?Gv(a,c,o):Gf(o,0)?n.create(e):Kv(a,c,o)},bindNode(i,a){if(!k(a,r.Table))return n.create(e);let o=new Fv(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Hp?r.declaration instanceof R?new Iv(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function Hv(e,r,i){let a=N(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof zp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,F.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,F.TablePartial,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function Uv(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return n.create(e.lookupMembers(t,F.Enum,i));let a=Hm(e,r);if(a){if(a.isKind(F.Schema)){let t=Qf(r),o=e.lookupMembers(a,t?F.Enum:F.Schema,i);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,t?`Enum '${i}' does not exist in Schema 'public'`:`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Wv(e,i,a){if(!D(a))return new n(void 0);let o=lp(a)??``;if(!O(a.parentNode)){let s=a.parent,c=s instanceof R&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,F.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,F.Column,o);return l?n.create(l):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}return Um(e,i,a,F.Column)}function Gv(e,i,a){if(!D(a))return new n(void 0);let o=Wf(a,r.Table),s=lp(a)??``;if(!O(a.parentNode))if(o){let o=a.parent,c=o instanceof R&&o.isKind(r.Table)?e.nodeSymbol(o).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,F.Column,s);if(t)return n.create(t)}let l=e.lookupMembers(i,F.Column,s);return l?n.create(l):new n(void 0,[new w(C.BINDING_ERROR,`Column '${s}' does not exist in Table 'public.${c?.name??``}'`,a)])}else{let t=e.lookupMembers(i,F.Table,s);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${s}' does not exist in Schema 'public'`,a)])}return Um(e,i,a,o?F.Column:F.Table)}function Kv(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return go.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,F.Enum,i));let a=Hm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function qv(e){return e?e.split(``).every(e=>vf(e)||yf(e))&&!yf(e[0]):!1}function Jv(e){return qv(e)?e:`"${Zv(e)}"`}function Yv(...e){return e.map(Jv).join(`.`)}function Xv(e){let t=``,n=0,r={n:`
11
- `,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function Zv(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
12
- `:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function Qv(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return`'${Zv(e)}'`;let{value:t,type:n}=e;if(t==null||Mo(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(Mo(n)){let e=yp(t);return e===null?`\`${t}\``:e?`true`:`false`}if(jo(n)){let e=hp(t);return e===null?`\`${t}\``:String(e)}if(Fo(n)){let e=Tp(t);return e===null?`\`${t}\``:`'${Zv(e)}'`}let r=xp(t);return r===null?`\`${t}\``:`'${Zv(r)}'`}function $v(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?Xv(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function ey(e,t){let n=new Set,r=[];for(let i of t)for(let t of e.reachableFiles(i))n.has(t.intern())||(n.add(t.intern()),r.push(t));return r}function ty(e){let r=[],i=[],a=[];e.bindProject();for(let n of e.parseProject().values()){i.push(...n.getErrors()),a.push(...n.getWarnings());let o=e.nodeSymbol(n.getValue().ast).getFiltered(t);if(!o)continue;let s=e.symbolMembers(o);i.push(...s.getErrors()),a.push(...s.getWarnings());for(let n of s.getFiltered(t)??[])if(r.push(n),n instanceof zp&&n.isKind(F.Schema)){let o=e.symbolMembers(n);i.push(...o.getErrors()),a.push(...o.getWarnings()),r.push(...o.getFiltered(t)??[])}}return new n(r,i,a)}function ny(e){return e.includes(`
13
- `)?`'''\n${e}\n'''`:`'${Zv(e)}'`}var ry=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Vm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof am?[...r.getErrors(),new w(C.BINDING_ERROR,`TableGroup cannot reference imported table '${i.name}'`,n)]:r.getErrors()}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},iy={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.Color]:{isValidBuiltinFieldValue:kf,message:`'color' must be a color literal`,assignBuiltinField(e,t){e.color=t}}},ay=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=P(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),j_(this.compiler,this.tableGroup,this.symbol,iy,this.filepath),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=kp(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new w(C.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]=_(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:Op(M(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:P(e)};break;default:break}return[]})}interpretFields(e){let n=[];return this.tableGroup.tables=e.map(e=>{let r=e.callee?this.compiler.nodeReferee(e.callee).getFiltered(t):void 0;if(r?.isKind(F.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=j(e.callee);return i.length>2&&n.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=T(e).getValue();this.tableGroup.color=t.color?.length?Ap(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Op(M(n?.value)),token:P(n)},this.tableGroup.metadata=Np(t,Object.keys(iy)),[]}},oy={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new w(C.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},sy={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return k(a,r.TableGroup)?new n(i.symbolFactory.create(Wp,{declaration:a,name:s},a.filepath)):A(a,r.TableGroup)?new n(i.symbolFactory.create(Gp,{declaration:a,name:o?.map(Jv).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(F.TableGroup)){let e=i.declaration;if(!(e instanceof R))return new n([]);let a=rp(e),o=[],s=[];for(let e of a){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(o.push(i),s.push(...n.getErrors()))}let c=new Map;for(let e of o){if(!e.isKind(F.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(oy.getFieldDuplicateError(e.name,r)),s.push(oy.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(F.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!D(a)||!Wf(a,r.TableGroup)||a.parent&&Kf(a))return n.create(e);let o=i.parseFile(a.filepath).getValue().ast,s=i.nodeSymbol(o).getValue();return s===t?n.create(void 0):cy(i,s,a)},bindNode(i,a){if(!k(a,r.TableGroup))return n.create(e);let o=new ry(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,i,a){let o=i.declaration;return!k(o,r.TableGroup)||!(i instanceof Wp)?n.create(e):Bm(t,o)?new ay(t,i,a).interpret():n.create(void 0)}};function cy(e,r,i){let a=lp(i)??``;if(!O(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof zp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,F.Table,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Hm(e,i);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,F.Schema,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var ly=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);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(g(n)instanceof U){let e=T(g(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=ap(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return Vm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];if(n){let r=[],i=e.variables;for(let e of i)r.push(...this.compiler.nodeReferee(e).getErrors());let a=this.compiler.nodeReferee(n);return r.push(...a.getErrors()),a.getValue()&&r.push(...this.compiler.nodeReferee(t).getErrors()),r}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},uy=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=this.symbol?.token??P(this.declarationNode),this.symbol?this.tablePartial.name=this.symbol.interpretedName(this.compiler,this.filepath).name:this.interpretName(this.declarationNode.name);let e=[...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.tablePartial.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),pk:!0,token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath}}),this.pkColumns.forEach(e=>{e.pk=!1})),new n(this.tablePartial,e)}interpretName(e){let{name:t}=kp(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=T(e).getValue(),n=va(t[i.HeaderColor]);this.tablePartial.headerColor=n?Ap(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Op(M(r?.value)),token:P(r)},[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:Op(M(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:P(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let n=[],r={},a=this.compiler.nodeSymbol(e).getFiltered(t);r.name=lp(e.callee)??``,r.token=P(e);let o=Mp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||void 0,r.unique=a?.isUniqueSet(this.compiler)||void 0,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{};r.metadata=Np(s,Lv);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!(n instanceof Gh))return[];let r=n.owners(this.compiler);if(l&&r.length>0&&!r.some(e=>e===l))return[];let i=n.op(this.compiler);if(!i)return[];let a=n.rightTable(this.compiler),o=n.rightColumns(this.compiler);if(!a||o.length===0)return[];let s=a.interpretedName(this.compiler,this.filepath);return{schemaName:s.schema,tableName:s.name,fieldNames:o.map(e=>e.name??``),relation:i,token:P(n.rightToken())}}),r.inline_deps=[],r.checks=(s[i.Check]||[]).map(e=>({token:P(e),expression:e.value.value.value})),this.tablePartial.fields?.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.indexes?.push(...i):i&&this.tablePartial.indexes?.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.checks?.push(...i):i&&this.tablePartial.checks?.push(i),r.getErrors()}},dy={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},fy={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.TablePartial)?new n(i.symbolFactory.create(Yp,{declaration:a,name:o},a.filepath)):A(a,r.TablePartial)?new n(i.symbolFactory.create(Up,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(F.TablePartial)){let e=a.declaration;if(!(e instanceof R))return new n([]);let r=rp(e),o=[],s=[];for(let e of r){let n=i.nodeSymbol(e),r=n.getFiltered(t);r&&(o.push(r),s.push(...n.getErrors()))}let c=new Map;for(let e of o){if(!e.isKind(F.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Bv.getColumnDuplicateError(t,r)),s.push(Bv.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(F.Column)&&k(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!D(o)&&!O(o)||!Wf(o,r.TablePartial))return n.create(e);let s=a.parseFile(o.filepath).getValue().ast,c=a.nodeSymbol(s).getValue();return c===t?n.create(void 0):Gf(o,1)?py(a,c,o):qf(o,i.Ref)?my(a,c,o):hy(a,c,o)},bindNode(i,a){if(!k(a,r.TablePartial))return n.create(e);let o=new ly(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Yp?r.declaration instanceof R?new uy(t,r,i).interpret():n.create(void 0):n.create(e)}};function py(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return n.create(e.lookupMembers(t,F.Enum,i));let a=Hm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function my(e,i,a){if(!D(a))return new n(void 0);let o=lp(a)??``;if(!O(a.parentNode)){let s=a.parent;if(s instanceof R&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,F.Column,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,F.Column,o);return c?n.create(c):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Hm(e,a);if(s){if(s.isKind(F.Schema)){let t=e.lookupMembers(s,[F.Table,F.Schema],o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(F.Table)){let t=e.lookupMembers(s,F.Column,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${s.name}'`,a)])}return new n(void 0)}let c=a.parentNode;if(c.leftExpression===a){if(O(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,F.Schema,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,F.Table,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function hy(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return go.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,F.Enum,i));let a=Hm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var gy={symbolMembers(r,i){if(!i.isKind(F.Schema)||!(i instanceof zp))return n.create(e);let a=i.qualifiedName,o=r.usableMembers(i).getFiltered(t);if(!o)return n.create([]);let s=[...o.nonSchemaMembers],c=new Map(o.schemaMembers.map(e=>[e.name,e])),l=[];for(let e of o.reuses.selective){let n=vy(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...yy(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...xy(r,i,e,t,c));for(let e of o.uses.selective){let n=vy(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...yy(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...xy(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(F.TableGroup));if(!i.isPublicSchema()){let n=r.usableMembers(i.filepath).getFiltered(t)?.schemaMembers.find(e=>e.isPublicSchema());if(n){let i=r.symbolMembers(n).getFiltered(t);i&&e.push(...i.filter(e=>e.isKind(F.TableGroup)))}}for(let t of e)u.push(...Cy(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof am&&e.isKind(F.Schema))return!1;let t=`${e.originalSymbol.intern()}:${e.name??``}`;return d.has(t)?!1:(d.add(t),!0)}),p=r.parsedFileKind(i.filepath)===`arch`,m=e=>p&&e.isKind(F.StickyNote)?F.Element:e.kind,h=new Map;for(let e of f){let t=`${m(e)}:${e.name}`;if(h.get(t)){if(e.isKind(F.Schema)||e.isKind(F.Kind))continue;let t=m(e),n=e instanceof am?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof R&&e.declaration.name&&t!==F.Element?e.declaration.name:e.declaration;n&&e.name!==void 0&&l.push(_y(t,e.name,a.join(`.`),n))}else h.set(t,e)}return new n(f,l)}};function _y(e,t,n,r){switch(e){case F.Table:return Bv.getDuplicateError(t,n,r);case F.Enum:return xg.getDuplicateError(t,n,r);case F.TablePartial:return dy.getDuplicateError(t,n,r);case F.TableGroup:return oy.getDuplicateError(t,n,r);case F.DiagramView:return pg.getDuplicateError(t,n,r);case F.Element:return new w(C.DUPLICATE_NAME,`${t} is already declared`,r);default:return new w(C.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function vy(e,r,i,a){let o=Dv(e,r,i);if(o.kind===`none`)return n.create(void 0);if(o.kind===`direct`){let r=e.nodeSymbol(i);return r.hasValue(t)?n.create(void 0):r}return a.has(o.schemaName)||a.set(o.schemaName,e.symbolFactory.create(zp,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function yy(e,n,r,i=new Set){if(r.getSymbolKind()!==F.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(F.Schema))return[];let o=Cv.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:by(e,n,r,a,i)}function by(e,n,r,i,a){let o=i.intern();if(a.has(o))return[];a.add(o);let s=e.usableMembers(i).getFiltered(t);if(!s)return[];let c=s.nonSchemaMembers.filter(e=>e.canBeImported).map(t=>e.symbolFactory.create(am,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(F.TableGroup)&&c.push(...Cy(e,n,t));for(let i of s.reuses.selective)if(c.push(...yy(e,n,i,a)),Dv(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(am,{kind:a.kind,declaration:a.originalSymbol.declaration,usedSymbol:a.originalSymbol,useSpecifierDeclaration:r,name:a.name},n.filepath))}for(let{importPath:t}of s.reuses.wildcard){let i=Sy(e,t,n.qualifiedName);i&&c.push(...by(e,n,r,i,a))}return c}function xy(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=Sy(e,r,n.qualifiedName);if(!s)return[];let c=e.usableMembers(s).getFiltered(t);if(!c)return[];let l=c.nonSchemaMembers.filter(e=>e.canBeImported).map(t=>e.symbolFactory.create(am,{kind:t.kind,declaration:t.declaration,usedSymbol:t,useSpecifierDeclaration:i,name:t.name},n.filepath));for(let t of c.schemaMembers)a.has(t.name)||a.set(t.name,e.symbolFactory.create(zp,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=vy(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...yy(e,n,r))}for(let{importPath:t}of d)l.push(...xy(e,n,t,i,a,o));return l}function Sy(e,n,r){if(r.length===0)return;let i=e.usableMembers(n).getFiltered(t);if(!i)return;let{schemaMembers:a}=i,o,s=[...r];for(;s.length>0;){let t=s.shift();if(o=a.find(e=>e.name===t),!o)return;let n=e.usableMembers(o).getValue();({schemaMembers:a}=n)}return o}function Cy(e,n,r){if(!r.isKind(F.TableGroup)||!(r instanceof am))return[];let i=r.originalSymbol,a=e.symbolMembers(i).getFiltered(t);if(!a)return[];let o=n.qualifiedName,s=[];for(let t of a){if(!t.isKind(F.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=j(n);if(!i||i.length===0)continue;let a=i.length<=1?[y]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=wy(e,c,i);l&&s.push(e.symbolFactory.create(am,{kind:F.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function wy(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(F.Table)&&e.name===r[0]):void 0}let i=r[0],a=r[r.length-1],o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.schemaMembers.find(e=>e.name===i);if(!s)return;let c=e.usableMembers(s).getFiltered(t);if(c)return c.nonSchemaMembers.find(e=>e.isKind(F.Table)&&e.name===a)}var Ty=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof V)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Ey={[i.Color]:{isValidBuiltinFieldValue:Af,message:`'color' must be a color literal or 'none'`,assignBuiltinField(e,t){e.color=t}}},Dy=[`link`,`ref`],Oy=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){this.note.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return j_(this.compiler,this.note,this.symbol,Ey,this.filepath),n.create(this.note,e)}interpretName(){let{name:e}=this.symbol.interpretedName(this.compiler,this.filepath);return this.note.name=e,[]}interpretSettingList(e){let t=T(e).getValue();t.color?.length&&(this.note.color=Ap(t.color.at(0)?.value));let n=this.compiler.parsedFileKind(this.declarationNode.filepath)===`arch`,r=[...Object.keys(Ey),...n?Dy:[]];return this.note.metadata=Np(t,r),[]}interpretBody(e){if(!e)return this.note.content=``,[];let[t,n]=_(e.body,e=>e instanceof V);return t.length!==1||n.length>0?[new w(C.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=M(e.callee)??``;return this.note.content=Op(t),[]}},ky={nodeSymbol(i,a){return!k(a,r.Note)||!(a.parentNode instanceof L)?n.create(e):new n(i.symbolFactory.create(Jp,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(F.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return k(i,r.Note)?n.create(void 0,new Ty(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Jp?r.declaration instanceof R?new Oy(t,r,i).interpret():n.create(void 0):n.create(e)}},Ay=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[...this.bindTargetElement(this.declarationNode.name),...this.bindBody(this.declarationNode.body)]}bindTargetElement(e){let t=T_(this.declarationNode);return!j(e)?.length||!t||k_(this.compiler,this.declarationNode)?[]:[new w(C.BINDING_ERROR,`cannot find metadata target element`,e??this.declarationNode)]}bindBody(e){return e instanceof H?e.body.filter(e=>e instanceof R).flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[]):[]}},jy=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.filepath=n,this.values={}}interpret(){let e=this.interpretValues(this.declarationNode.body);return new n(this.values,e)}interpretValues(e){if(!(e instanceof H))return[];for(let t of e.body){if(!(t instanceof R))continue;let e=t.type?.value;if(!e)continue;let n=Pp(t.body instanceof V?t.body.callee:void 0);n&&(this.values[e]={value:e===`note`?Op(n):n,token:P(t)})}return[]}},My={nodeMetadata(t,i){return k(i,r.Metadata)?new n(new Yh(i)):new n(e)},nodeReferee(t,i){if(!D(i))return new n(e);let a=i.parentOfKind(R);return!a||!k(a,r.Metadata)||!a.name?.containsEq(i)?new n(e):!j(a.name)||!T_(a)?new n(void 0):new n(k_(t,a))},bindNode(t,i){return k(i,r.Metadata)?new n(void 0,new Ay(t,i).bind()):new n(e)},interpretMetadata(t,i,a){return i instanceof Yh?k(i.declaration,r.Metadata)?new jy(t,i,a).interpret():new n(void 0):new n(e)}};function Ny(e,t){let n=e.parentNode;return!(n instanceof V)||!(t.body instanceof H)||n.parentNode!==t.body?!1:n.callee===e||n.args.includes(e)}function Py(e,t){let n=Th(t);return!!n&&(Ch(n.infix.left)===e||Ch(n.infix.right)===e)}var Fy=e=>[`node`,`group`].includes(dh(e)??``)||fh(e),Iy=(e,t,n)=>Lh(e,t.filepath,F.Element,n)??Lh(e,t.filepath,F.StickyNote,n);function Ly(e,t){return Dh(t).some(t=>Oh(t)?.target===e)}var Ry=(e,t,n)=>new w(e,`${t} is not declared anywhere`,n);function zy(e,t,n,r){if(Lh(e,t.filepath,F.Table,n))return new w(C.BINDING_ERROR,`${n} is a table; ${r}`,t)}function By(e,t,r,i){let a=Iy(e,t,r);return a?new n(a):new n(void 0,[zy(e,t,r,`a link joins elements`)??Ry(C.UNKNOWN_ENDPOINT,r,i)])}function Vy(e,t,r){let i=G(t);if(i===void 0)return new n(void 0);if(Fy(r)&&Ly(t,r))return By(e,t,i,t);switch(dh(r)){case`group`:{if(!Ny(t,r))return new n(void 0);let a=Iy(e,t,i),o=a?void 0:zy(e,t,i,`a group lists elements and groups`);return new n(a,o?[o]:[])}case`link`:return Py(t,r)?By(e,t,i,r):new n(void 0);case`metadata`:{if(!r.name?.containsEq(t))return new n(void 0);let a=Lh(e,t.filepath,F.Element,i);return a?new n(a):new n(void 0,[Ry(C.UNKNOWN_METADATA_TARGET,i,r)])}default:return new n(void 0)}}function Hy(e,t){let r=[],i=lh(t);if(Fy(t))for(let n of Dh(t)){let t=Oh(n)?.target;t&&D(t)&&r.push(...e.nodeReferee(t).getErrors())}switch(dh(t)){case`node`:G(t.name)!==void 0&&!zh(e,t.filepath,i)&&r.push(new w(C.UNKNOWN_KIND,`${i} is not a kind. ${nh(i)}`,t));break;case`group`:for(let n of bh(t))if(n instanceof V)for(let t of[n.callee,...n.args])D(t)&&r.push(...e.nodeReferee(t).getErrors());break;case`link`:{let n=Th(t);if(!n)break;for(let t of[n.infix.left,n.infix.right]){let n=Ch(t);D(n)&&r.push(...e.nodeReferee(n).getErrors())}break}case`metadata`:if(D(t.name)&&r.push(...e.nodeReferee(t.name).getErrors()),!new Zh(t).target(e)&&!r.length){let e=G(t.name)??t.targetKind?.value??`that`;r.push(Ry(C.UNKNOWN_METADATA_TARGET,e,t))}break;default:break}return new n(void 0,r)}function Uy(e,r){if(!r.name)return new n(void 0);let i=e.nodeReferee(r.name),a=[...i.getErrors()],o=i.getFiltered(t)?.originalSymbol,s=r.importKind?.value,c=o?.declaration;if(s&&o?.isKind(F.Element)&&c instanceof R){let t=lh(c),n=dh(c)===`node`?zh(e,c.filepath,t)??t:t;n.toLowerCase()!==s.toLowerCase()&&a.push(new w(C.BINDING_ERROR,`${mh(c)} is a ${n}, not a ${s}`,r.importKind))}return new n(void 0,a)}var Wy={nodeSymbol(t,r){if(!uh(r))return n.create(e);switch(dh(r)){case`node`:case`group`:return new n(t.symbolFactory.create(Kp,{declaration:r,name:mh(r)},r.filepath));case`kind`:return new n(t.symbolFactory.create(qp,{declaration:r,name:G(r.name)},r.filepath));default:return n.create(e)}},symbolMembers(t,r){return r instanceof Kp||r instanceof qp?new n([]):n.create(e)},nodeReferee(t,r){if(!D(r)||r.parentOfKind(gm))return n.create(e);let i=ph(r);return i?Vy(t,r,i):n.create(e)},bindNode(t,r){return r instanceof gm&&r.archImport?Uy(t,r):uh(r)?Hy(t,r):n.create(e)},nodeMetadata(t,r){if(r instanceof z){let t=r.parentOfKind(R);return!t||!uh(t)||!Fy(t)||!Eh(r)?n.create(e):new n(new Xh(r))}if(!uh(r))return n.create(e);switch(dh(r)){case`link`:return new n(new Xh(r));case`metadata`:return new n(new Zh(r));default:return n.create(e)}},interpretSymbol(t,r,i){return r instanceof Kp?P_(t,r,i):r instanceof qp?L_(r):n.create(e)},interpretMetadata(t,r,i){return r instanceof Xh?z_(t,r,i):r instanceof Zh?B_(r):n.create(e)}},Gy=[wv,Vv,Sg,fv,Tg,ig,xv,cg,av,sy,fy,ky,My,gy,mg,nv],Ky=[Wy,wv,ky,gy,nv];function qy(e,t){if(e.explicitModules)return e.explicitModules;let n=t.filepath??t.declaration?.filepath;return n&&e.parsedFileKind(n)===`arch`?Ky:Gy}function Jy(t,r,...i){for(let a of qy(t,i[1])){let t=a[r];if(t){let r=t(...i);if(r instanceof n&&!r.hasValue(e))return r}}return n.create(e)}function Yy(r){let i=Jy(this,`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Xy(r){let i=Jy(this,`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Zy(r){let i=Jy(this,`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Qy(r){let i=Jy(this,`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function $y(r){let i=Jy(this,`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function eb(r,i){let a=Jy(this,`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function tb(r,i){let a=Jy(this,`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var nb=class{constructor(e,t,n={}){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t,this.options=n}scanFrontMatter(){if(!this.options.allowFrontMatter||!this.text.startsWith(`---`))return;let e=this.text[3];if(e!==`
6
+ `).trim()}var _h=/^(https:\/\/|data:image\/)/i,vh=`A picture must be an https: URL or a data:image/ URI.`;function yh(e,t,n){let r={settings:t,problems:[]},i=new Set;for(let a of rh(e)){if(!(a instanceof R)){if(!n)continue;let e=ih(a);if(!e)continue;for(let n of[e.callee,...e.args]){let e=Xm(n);if(e){if(i.has(e)){r.problems.push({code:`duplicate`,message:`${e} is set twice`,node:a});continue}i.add(e),t[e]=!0}}continue}let e=Gm(a);if(!e||e.toLowerCase()===`note`)continue;let o=fh(a);if(!o||o.value===void 0){r.problems.push({code:`bad`,message:`A property reads ${e}: 'value'`,node:a});continue}if(i.has(o.key)){r.problems.push({code:`duplicate`,message:`${o.key} is set twice`,node:a});continue}i.add(o.key),t[o.key]=o.value}return r}function bh(e,t,n,r){let i=Um(e,t);if(!i)return;let a=Hm(e,i);return(a&&e.lookupMembers(a,n,r))??e.lookupMembers(i,n,r)}function xh(e,t,n){let r=t.originalSymbol;if(r.isKind(F.StickyNote))return r.interpretedName(e,n).name;let i=r.declaration;return i instanceof R?Zm(i):void 0}var Sh=function(e){return e.Ref=`ref`,e.Dep=`dep`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e.MetadataElement=`metadata element`,e.Link=`link`,e}({}),Ch=class e{static{this.id=0}constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}resolveOwnerPrograms(e,t){let n=this.declaration.filepath;return e.reachableFiles().flatMap(t=>Um(e,t)||[]).filter(r=>e.reachableFiles(r.filepath).some(e=>e.equals(n))&&t.every(t=>r.inNestedSchema(e,t)))}},wh=class extends Ch{constructor(e){super(e),this.kind=`ref`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof R){let t=rp(this.declaration)[0];if(!(t instanceof H))return[];let n=t.callee;return n instanceof V?Ph(e,n.leftExpression):[]}if(this.declaration instanceof z){let n=this.declaration.parentOfKind(H);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof R){let t=rp(this.declaration)[0];if(!(t instanceof H))return[];let n=t.callee;return n instanceof V?Ph(e,n.rightExpression):[]}if(this.declaration instanceof z){let t=this.declaration.value;return t instanceof B?Ph(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof R){let t=rp(this.declaration)[0];if(!(t instanceof H))return;let n=t.callee;return n instanceof V?Fh(e,n.leftExpression):void 0}if(this.declaration instanceof z)return this.container(e)}rightTable(e){if(this.declaration instanceof R){let t=rp(this.declaration)[0];if(!(t instanceof H))return;let n=t.callee;return n instanceof V?Fh(e,n.rightExpression):void 0}if(this.declaration instanceof z){let t=this.declaration.value;return t instanceof B?Fh(e,t.expression)??this.container(e):void 0}}op(e){return this.opToken()?.value}opToken(){if(this.declaration instanceof R){let e=rp(this.declaration)[0];if(!(e instanceof H))return;let t=e.callee;return t instanceof V?t.op:void 0}if(this.declaration instanceof z){let e=this.declaration.value;return e instanceof B?e.op:void 0}}cardinalities(e){let t=this.op(e);return t?af(t):void 0}leftCardinality(e){let t=this.cardinalities(e);return t?Zd(t[0]):void 0}rightCardinality(e){let t=this.cardinalities(e);return t?Zd(t[1]):void 0}active(e){if(!(this.declaration instanceof R))return!0;let n=rp(this.declaration)[0];return n?!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length:!0}leftToken(){if(this.declaration instanceof R){let e=rp(this.declaration)[0];if(e instanceof H){let t=e.callee;if(t instanceof V&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof z){let e=this.declaration.parentOfKind(H);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof R){let e=rp(this.declaration)[0];if(e instanceof H){let t=e.callee;if(t instanceof V&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof z,this.declaration}owners(e){let t=this.leftTable(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Th=class extends Ch{constructor(e){super(e),this.kind=`dep`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}edgeExpressions(){return this.declaration instanceof R?rp(this.declaration).filter(e=>e instanceof H).map(e=>e.callee).filter(e=>e instanceof V):[]}upstreamColumns(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>Ph(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=this.hostColumn(e),i=Ph(e,t.expression);if(n===`->`)return[r?[r]:[]];if(n===`<-`)return[i]}return[]}downstreamColumns(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>Ph(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=this.hostColumn(e),i=Ph(e,t.expression);if(n===`->`)return[i];if(n===`<-`)return[r?[r]:[]]}return[]}upstreamTables(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>Ih(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=Ih(e,t.expression);if(n===`->`)return[this.container(e)];if(n===`<-`)return[r]}return[]}downstreamTables(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>Ih(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=Ih(e,t.expression);if(n===`->`)return[r];if(n===`<-`)return[this.container(e)]}return[]}hostColumn(e){if(!(this.declaration instanceof z))return;let n=this.declaration.parentOfKind(H);if(n)return e.nodeSymbol(n).getFiltered(t)}owners(e){let n=this.upstreamTables(e),r=this.downstreamTables(e),i=[...n,...r].filter(e=>!!e);if(i.length===0)return[];let a=this.declaration.filepath;return e.reachableFiles().flatMap(n=>e.nodeSymbol(e.parseFile(n).getValue().ast).getFiltered(t)||[]).filter(t=>e.reachableFiles(t.filepath).some(e=>e.equals(a))&&i.every(n=>t.inNestedSchema(e,n)))}},Eh=class extends Ch{constructor(e){super(e),this.kind=`partial ref`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof z))return[];let n=this.declaration.parentOfKind(H);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof z))return[];let t=this.declaration.value;return t instanceof B?Ph(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof z)return this.container(e)}rightTable(e){if(!(this.declaration instanceof z))return;let t=this.declaration.value;if(t instanceof B)return Fh(e,t.expression)??this.container(e)}op(e){return this.opToken()?.value}opToken(){if(!(this.declaration instanceof z))return;let e=this.declaration.value;if(e instanceof B)return e.op}cardinalities(e){let t=this.op(e);return t?af(t):void 0}leftToken(){if(this.declaration instanceof z){let e=this.declaration.parentOfKind(H);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof z,this.declaration}owners(e){let t=this.leftTablePartial(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Dh=class extends Ch{constructor(e){super(e),this.kind=`table checks`,this.ownerTable=e.parentNode?.parentOfKind(R)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Oh=class extends Ch{constructor(e){super(e),this.kind=`indexes`,this.ownerTable=e.parentNode?.parentOfKind(R)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},kh=class extends Ch{constructor(e){super(e),this.kind=`records`}table(e){let n=this.declaration,i=n.parent;if(i instanceof R&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof Cm))return;let o=cp(a);if(!o)return;let s=o.variables.at(-1);if(s)return e.nodeReferee(s).getFiltered(t)?.originalSymbol}example(e){return!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Example]?.length}owners(e){let t=this.table(e);return t?this.resolveOwnerPrograms(e,[t]):[]}},Ah=class extends Ch{constructor(e){super(e),this.kind=`metadata element`}target(e){let n=this.declaration.name;if(!n)return;let r=Zf(n)??n;return e.nodeReferee(r).getFiltered(t)?.originalSymbol}owners(e){let n=this.target(e);if(!n)return[];if(n.kind===F.Column){let r=n.declaration?.parentOfKind(R),i=r?e.nodeSymbol(r).getFiltered(t)?.originalSymbol:void 0;if(!i)return[];n=i}return this.resolveOwnerPrograms(e,[n])}},jh=class extends Ch{constructor(e){super(e),this.kind=`link`}op(){return this.declaration instanceof z?dh(this.declaration)?.op:ch(this.declaration)?.infix.op}endpoints(e){let n=n=>{let r=oh(n);return D(r)?e.nodeReferee(r).getFiltered(t)?.originalSymbol:void 0};if(this.declaration instanceof z){let r=dh(this.declaration),i=this.declaration.parentOfKind(R);return!r||!i?[void 0,void 0]:[e.nodeSymbol(i).getFiltered(t)?.originalSymbol,n(r.target)]}let r=ch(this.declaration);return r?[n(r.infix.left),n(r.infix.right)]:[void 0,void 0]}owners(e){let[t,n]=this.endpoints(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Mh=class extends Ah{target(e){if(this.declaration.name)return super.target(e);let t=this.declaration.targetKind?.value;if(t)return bh(e,this.declaration.filepath,F.Element,t)?.originalSymbol}},Nh=class extends Ch{constructor(e){super(e),this.kind=`project`}owners(e){let n=this.declaration.filepath,r=e.parseFile(n).getValue().ast,i=e.nodeSymbol(r).getFiltered(t);return i?[i]:[]}};function Ph(e,n){if(!n)return[];let r=ap(n);return r?(r.tupleElements.length>0?r.tupleElements:r.variables.at(-1)?[r.variables.at(-1)]:[]).flatMap(n=>{let r=e.nodeReferee(n).getFiltered(t);return r?.isKind(F.Column)?[r]:[]}):[]}function Fh(e,n){if(!n)return;let r=ap(n);if(!r)return;let i=r.tupleElements.length>0?r.variables.at(-1):r.variables.at(-2);if(i)return e.nodeReferee(i).getFiltered(t)}function Ih(e,n){if(!n)return;let r=ap(n);if(!r)return;if(r.tupleElements.length>0){let n=r.variables.at(-1);return n?e.nodeReferee(n).getFiltered(t):void 0}let i=r.variables.at(-1);if(i){let n=e.nodeReferee(i).getFiltered(t);if(n?.isKind(F.Table))return n}let a=r.variables.at(-2);if(a)return e.nodeReferee(a).getFiltered(t)}var Lh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},Rh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof U?new n(e.body.flatMap(e=>{if(!(e instanceof H))return[];let t=P(e),n=e.callee instanceof ym?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof W);return a&&(r=M(T(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}},zh={nodeMetadata(t,i){if(k(i,r.Checks)){let t=i.parent;return!t||!k(t,r.Table)&&!k(t,r.TablePartial)?n.create(e):n.create(new Dh(i))}return n.create(e)},bindNode(t,i){return k(i,r.Checks)?n.create(void 0,new Lh(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Sh.TableChecks?r.declaration instanceof R?new Rh(t,r.declaration).interpret():n.create(void 0):n.create(e)}},Bh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[e.callee,...e.args].flatMap(zm).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors())),n=this.checkColumnSelfLoop(e.callee);return t.concat(n)})}checkColumnSelfLoop(e){if(!(e instanceof V)||this.endpointLevel(e.leftExpression)!==`column`||this.endpointLevel(e.rightExpression)!==`column`)return[];let t=this.endpointSymbol(e.leftExpression),n=this.endpointSymbol(e.rightExpression);return t&&n&&t===n?[new w(C.DEP_SELF_LOOP,`A column cannot depend on itself`,e)]:[]}endpointSymbol(e){if(!e)return;let n=ap(e);if(!n)return;let r=n.variables.at(-1);if(r)return this.compiler.nodeReferee(r).getFiltered(t)}endpointLevel(e){if(!e)return;let n=ap(e);if(!n)return;if(n.tupleElements.length>0)return`column`;let r=n.variables.at(-1);if(!r)return;let i=this.compiler.nodeReferee(r).getFiltered(t);if(i?.isKind(F.Column))return`column`;if(i?.isKind(F.Table))return`table`}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Vh=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.dep={}}interpret(){this.dep.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretEdges(),...this.interpretSettings()];return n.create(this.dep,e)}interpretName(){if(!(this.declarationNode instanceof R))return this.dep.name=null,this.dep.schemaName=null,[];let e=[],t=this.declarationNode.name?j(this.declarationNode.name)??[]:[];return this.dep.name=t.pop()||null,t.length>1&&e.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.dep.schemaName=t.join(`.`)||null,e}interpretEdges(){let e=this.metadata.upstreamColumns(this.compiler),t=this.metadata.downstreamColumns(this.compiler),n=this.metadata.upstreamTables(this.compiler),r=this.metadata.downstreamTables(this.compiler),i=[],a=[],o=Math.max(n.length,r.length);for(let a=0;a<o;a++){let o=n[a],s=r[a],c=e[a]??[],l=t[a]??[],u=o?.interpretedName(this.compiler,this.filepath),d=s?.interpretedName(this.compiler,this.filepath);u?.schema,d?.schema,i.push({upstream:{schemaName:u?.schema??null,tableName:u?.name??``,fieldNames:c.map(e=>e.name??``),token:this.dep.token},downstream:{schemaName:d?.schema??null,tableName:d?.name??``,fieldNames:l.map(e=>e.name??``),token:this.dep.token},token:this.dep.token})}return this.dep.edges=i,a}interpretSettings(){let e={};if(this.declarationNode instanceof R){this.declarationNode.attributeList&&this.consumeSettings(this.declarationNode.attributeList,e);let t=this.declarationNode.body;if(t){let n=t instanceof H?[t]:t.body.filter(e=>e instanceof H);for(let t of n){let n=t.args.find(e=>e instanceof W);n&&this.consumeSettings(n,e)}if(!(t instanceof H)){let n=t.body.filter(e=>e instanceof R);for(let t of n){let n=t.type?.value?.toLowerCase();if(!n)continue;let a=t.body;if(t.isKind(r.Note)&&a instanceof U){let e=a.body[0];if(e instanceof H&&e.callee){let n=this.extractAttrValue(e.callee);n!==void 0&&(this.dep.note={value:Op(String(n)),token:P(t)})}continue}if(!(a instanceof H))continue;if(n===i.Color){let e=Ap(a.callee);e!==void 0&&(this.dep.color=e);continue}let o=this.extractAttrValue(a.callee);o!==void 0&&(t.isKind(r.Note)?this.dep.note={value:Op(String(o)),token:P(t)}:e[n]=o)}}}}return Object.keys(e).length>0&&(this.dep.metadata=e),[]}consumeSettings(e,t){let n=T(e).getValue();for(let[e,r]of Object.entries(n)){let n=r[0];if(!n)continue;if(e===i.Color){let e=Ap(n.value);e!==void 0&&(this.dep.color=e);continue}let a=this.extractAttrValue(n.value);a!==void 0&&(e===i.Note?this.dep.note={value:Op(String(a)),token:P(n)}:t[e]=a)}}extractAttrValue(e){if(e instanceof _m)return ep(e);let t=sp(e);if(t!==null)return t;let n=M(e);return n===void 0?N(e):n}};function Hh(e){let t=e.parent;for(;t;){if(t instanceof R&&t.isKind(r.Dep))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var Uh={nodeReferee(r,i){if(!D(i)&&!O(i)||!Hh(i)||i.parentOfKind(z))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):Wh(r,o,i)},nodeMetadata(t,a){if(k(a,r.Dep)){let t=rp(a);return t.length===0||!t.some(e=>e instanceof H&&e.callee instanceof V)?n.create(e):n.create(new Th(a))}return a instanceof z?!(a.name instanceof _m)||ep(a.name)?.toLowerCase()!==i.Dep?n.create(e):n.create(new Th(a)):n.create(e)},bindNode(t,i){return k(i,r.Dep)?n.create(void 0,new Bh(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Th?new Vh(t,r,i).interpret():n.create(e)}};function Wh(e,r,i){if(!D(i))return new n(void 0);let a=lp(i)??``;if(!O(i.parentNode)){let t=Hm(e,r);if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=i.parentNode;if(o.rightExpression===i){let r=Bm(e,i);if(r?.isKind(F.Schema)){let t=e.lookupMembers(r,F.Table,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema '${r.name}'`,i)])}if(r?.isKind(F.Table)){let o=e.lookupMembers(r,F.Column,a);if(o)return n.create(o);let s=r.declaration?e.nodeFullname(r.declaration).getFiltered(t)?.join(`.`)??r.name:r.name;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${s}'`,i)])}return new n(void 0)}if(o.leftExpression===i){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let t=e.lookupMembers(r,F.Schema,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=e.lookupMembers(r,F.Schema,a);if(t)return n.create(t);let s=Hm(e,r);if(s){let t=e.lookupMembers(s,F.Table,a);if(t)return n.create(t)}let c=e.lookupMembers(r,F.Table,a);return c?n.create(c):new n(void 0,[new w(C.BINDING_ERROR,`Schema or Table '${a}' does not exist`,i)])}return new n(void 0)}var Gh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=_(e.body,e=>e instanceof H);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof U)?[]:e.isKind(r.DiagramViewTables)?this.bindTableReferences(e.body):e.isKind(r.DiagramViewNotes)?this.bindNoteReferences(e.body):e.isKind(r.DiagramViewTableGroups)?this.bindTableGroupReferences(e.body):e.isKind(r.DiagramViewSchemas)?this.bindSchemaReferences(e.body):[])}bindTableReferences(e){let[t]=_(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Rf(e.callee)?[]:[e.callee,...e.args].flatMap(zm).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables.pop();return[...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}))}bindNoteReferences(e){let[t]=_(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Rf(e.callee)?[]:zm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=_(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Rf(e.callee)?[]:zm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=_(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Rf(e.callee)?[]:zm(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},Kh=class{constructor(e,t,n,r){this.diagramViewWildcards=new Set,this.diagramViewExplicitlySet=new Set,this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r??t.filepath,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null}}}interpret(){let e=[];this.diagramView.token=this.symbol.token;let{name:t,schema:r}=this.symbol.interpretedName(this.compiler,this.filepath);return this.diagramView.name=t,this.diagramView.schemaName=r,this.declarationNode.body instanceof U&&e.push(...this.interpretBody(this.declarationNode.body)),this.expandDiagramViewWildcards(),new n(this.diagramView,e)}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof H&&Rf(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramViewWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramViewExplicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=_(e.body,e=>e instanceof R),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof U&&this.interpretSubBlock(e.body,t)}let i=this.diagramView.visibleEntities;return(n.has(`tables`)&&i.tables!==null||n.has(`tablegroups`)&&i.tableGroups!==null||n.has(`schemas`)&&i.schemas!==null)&&(n.has(`tables`)||(i.tables=[]),n.has(`tablegroups`)||(i.tableGroups=[]),n.has(`schemas`)||(i.schemas=[])),n.has(r.DiagramViewTables)&&this.diagramViewExplicitlySet.add(`tables`),n.has(r.DiagramViewTableGroups)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(r.DiagramViewSchemas)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(r.DiagramViewNotes)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,n){if(!n)return;if(e.body.some(e=>e instanceof H&&Rf(e.callee))){let e=this.diagramViewWildcards;switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=[],e.add(`tables`);break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=[],e.add(`stickyNotes`);break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=[],e.add(`tableGroups`);break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=[],e.add(`schemas`);break}return}if(e.body.length===0)return;let i=[];for(let n of e.body){if(!(n instanceof H))continue;let e=n.callee&&Zf(n.callee),r=e&&this.compiler.nodeReferee(e).getFiltered(t);if(r?.declaration instanceof R){let e=j(r.declaration.name)??[];if(e.length>0){let t=e[e.length-1],n=e.length>1?e.slice(0,-1).join(`.`):y;i.push({name:t,schemaName:n});continue}}let a=j(n.callee)??[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[0]:y;i.push({name:o,schemaName:s})}switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=i.length>0?i:null;break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=i.length>0?i.map(e=>({name:e.name})):null;break}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;if(!(!t||!e)){if(t.has(`tables`)||t.has(`schemas`)){e.tables=[],e.tableGroups=[],e.schemas=[];return}t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames())}}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n)return[];let r=this.compiler.symbolMembers(n).getFiltered(t);return r?Pa(r.filter(e=>e.isKind(F.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function qh(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var Jh={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new w(C.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},Yh={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.DiagramView)?new n(i.symbolFactory.create(Xp,{declaration:a,name:o},a.filepath)):A(a,r.DiagramView)&&a instanceof Tm?new n(i.symbolFactory.create(Zp,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(em,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewTables)?new n(i.symbolFactory.create(Qp,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create($p,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(tm,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&Kf(a))return n.create(e);let o=Xh(a);if(!o)return n.create(e);let s=i.parseFile(a.filepath).getValue().ast,c=i.nodeSymbol(s).getFiltered(t);return c?o.isKind(r.DiagramViewTables)?Zh(i,c,a):o.isKind(r.DiagramViewNotes)?Qh(i,c,a,F.StickyNote):o.isKind(r.DiagramViewTableGroups)?Qh(i,c,a,F.TableGroup):o.isKind(r.DiagramViewSchemas)?$h(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(F.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!k(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of rp(o))if(e instanceof H){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof R&&c.push(...rp(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(F.DiagramViewSchema,F.DiagramViewTableGroup,F.DiagramViewTable,F.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(bv).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(Jh.getFieldDuplicateError(n,e.kind,i)),s.push(Jh.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!k(a,r.DiagramView))return n.create(e);let o=new Gh(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Xp?r.declaration instanceof R?new Kh(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function Xh(e){let t=e.parentOfKind(H);if(!t)return;let n=t.parentNode;if(!(n instanceof U))return;let i=n.parentNode;if(!(i instanceof R)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof U))return;let o=a.parentNode;if(!(!(o instanceof R)||!o.isKind(r.DiagramView)))return i}function Zh(e,r,i){let a=lp(i);if(a===void 0)return n.create(void 0);if(O(i.parentNode)){let t=Bm(e,i);if(t){if(t.isKind(F.Schema)){let r=Qf(i),o=e.lookupMembers(t,r?F.Table:F.Schema,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,F.Schema,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find schema '${a}'`,i)])}let o=e.symbolMembers(r).getFiltered(t)||[];for(let e of o){let t=e.name;if(e.isKind(F.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,F.Table,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Could not find table '${a}'`,i)])}function Qh(e,t,r,i){let a=lp(r);if(a===void 0)return n.create(void 0);let o=e.lookupMembers(t,i,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${i===F.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function $h(e,t,r){let i=lp(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var eg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof H)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},tg=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.enum={values:[]}}interpret(){this.enum.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody(this.declarationNode.body)];return n.create(this.enum,e)}interpretName(){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);return this.enum.name=e,this.enum.schemaName=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=P(t),n.name=N(t.callee);let r=T(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Op(M(r.value)),token:P(r)},this.enum.values.push(n),[]})}},ng={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new w(C.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},rg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.Enum)?new n(i.symbolFactory.create(Bp,{declaration:a,name:o},a.filepath)):A(a,r.Enum)?new n(i.symbolFactory.create(Vp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof R))return new n([]);let o=rp(a),s=[],c=[];for(let e of o){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(s.push(i),c.push(...n.getErrors()))}let l=new Map;for(let e of s){if(!e.isKind(F.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push(ng.getFieldDuplicateError(t,r)),c.push(ng.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!k(a,r.Enum))return n.create(e);let o=new eg(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Bp?new tg(t,r,i).interpret():n.create(e)}},ig=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof R)||!this.declarationNode.parent.isKind(r.Table)&&!this.declarationNode.parent.isKind(r.TablePartial)||!(this.declarationNode.body instanceof U)?[]:this.bindBody(this.declarationNode.body)}get ownerContainerKind(){return this.declarationNode.parent.isKind(r.TablePartial)?`TablePartial`:`Table`}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=j(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(zm).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=lp(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new w(C.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},ag=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof U?new n(e.body.flatMap(e=>{if(!(e instanceof H)||!e.callee)return[];let n=[],r=P(e),a=[e.callee,...e.args],o,s,c,l,u;g(a)instanceof W&&a.pop();let d=this.compiler.nodeSettings(e).getFiltered(t);if(d){o=!!d[i.PK]?.length||void 0,s=!!d[i.Unique]?.length||void 0,c=M(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=M(e.value);t!==void 0&&(l={value:t,token:P(e)})}u=N(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof Cm))return e;let t=[],n=e;for(;n instanceof Cm&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=op(e);if(!t)continue;let r=[];for(let e of t.functional)r.push({value:e.value?.value??``,type:`expression`,token:P(e)});for(let e of t.nonFunctional)r.push({value:lp(e)??``,type:`column`,token:P(e)});r.sort((e,t)=>e.token.start.offset-t.token.start.offset),n.push(...r)}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}},og={nodeMetadata(t,i){if(!k(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!k(a,r.Table)&&!k(a,r.TablePartial)?n.create(e):n.create(new Oh(i))},nodeReferee(i,a){if(!D(a)||Kf(a))return n.create(e);let o=a;for(;o&&!k(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!k(s,r.Table)&&!k(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=D(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,F.Column,l);if(u)return n.create(u);let d=k(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return k(i,r.Indexes)?n.create(void 0,new ig(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Sh.Indexes?r.declaration instanceof R?new ag(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function sg(e,n){let r=ip(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof bm){let n=[];for(let r of i.elementList){let i=e.nodeReferee(r).getFiltered(t);if(!i)return;n.push(i.originalSymbol)}return n}let a=r[r.length-1];if(!a||a instanceof bm)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function cg(e,t,n,r){let i=e.map(e=>e.intern()).sort().join(`,`),a=t.map(e=>e.intern()).sort().join(`,`);if(i===a)return[new w(C.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new w(C.CIRCULAR_REF,`References with same endpoints exist`,n),new w(C.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var lg=class{constructor(e,t){this.compiler=t,this.ast=e}resolve(){let e=[],i=this.compiler.reachableFiles(this.ast.filepath);for(let n of i){let{ast:i}=this.compiler.parseFile(n).getFiltered(t)||{ast:void 0};if(!i)continue;let a=i.body.filter(e=>e instanceof R&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new w(C.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof R&&t.type){let n=t;e.push(...this.compiler.bindNode(n).getErrors())}else e.push(...this.compiler.bindNode(t).getErrors())}let a=this.compiler.nodeSymbol(this.ast).getFiltered(t);return a&&e.push(...ug(this.compiler,a)),e.push(...this.checkDuplicateRefs()),e.push(...this.checkTableGroups()),new n(void 0,e)}isArchFile(e){return!this.compiler.explicitModules&&this.compiler.parsedFileKind(e)===`arch`}checkDuplicateRefs(){let e=[],n=new Map,i=this.compiler.reachableFiles(this.ast.filepath);for(let a of i){if(this.isArchFile(a))continue;let i=this.compiler.parseFile(a).getFiltered(t);if(!i)continue;let{ast:o}=i;for(let t of o.body){if(!(t instanceof R)||!t.type)continue;let i=t;k(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),k(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),k(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of rp(e)){if(!(r instanceof H)||!r.callee||!Jf(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=sg(this.compiler,i.leftExpression),o=sg(this.compiler,i.rightExpression);!a||!o||n.push(...cg(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of rp(e)){if(!(a instanceof H)||!a.callee)continue;let e=this.compiler.nodeSymbol(a).getFiltered(t);if(!e)continue;let o=this.compiler.nodeSettings(a).getFiltered(t);if(!o)continue;let s=o[i.Ref];if(!(!s||s.length===0))for(let t of s){let i=t.value;if(!(i instanceof B)||!i.op||!Df(i.op.value)||!i.expression)continue;let a=sg(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...cg(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of rp(e)){if(!(r instanceof H)||!r.callee)continue;let e=N(r.callee);if(!e)continue;let a=this.compiler.nodeSettings(r).getFiltered(t);if(!a)continue;let o=a[i.Ref];if(!(!o||o.length===0))for(let t of o){let r=t.value;r instanceof B&&(!r.op||!Df(r.op.value)||r.expression&&D(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new w(C.SAME_ENDPOINT,`Two endpoints are the same`,t)))}}return n}checkTableGroups(){let e=[],n=new Map,i=this.compiler.reachableFiles(this.ast.filepath);for(let a of i){if(this.isArchFile(a))continue;let i=this.compiler.parseFile(a).getFiltered(t);if(!i)continue;let{ast:o}=i;for(let i of o.body){if(!(i instanceof R)||!i.type)continue;let a=i;if(!k(a,r.TableGroup))continue;let o=a.name?j(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=rp(a);for(let r of c){if(!(r instanceof H)||!r.callee)continue;let i=ip(r.callee);if(!i||i.length===0)continue;let a=i[i.length-1],o=this.compiler.nodeReferee(a).getFiltered(t)?.originalSymbol;if(!o)continue;let c=n.get(o.id);if(c){let t=j(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new w(C.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${n}" already appears in group "${c.groupName}"`,r))}else n.set(o.id,{groupName:s,node:r})}}}return e}};function ug(e,n,r=new Set){if(r.has(n.id))return[];r.add(n.id);let i=e.symbolMembers(n),a=[...i.getErrors()],o=i.getFiltered(t);if(!o)return a;for(let t of o)t instanceof zp&&a.push(...ug(e,t,r));return a}function dg(e,t,n){t.isKind(F.Table)?e.externals.tables.push(n):t.isKind(F.Enum)?e.externals.enums.push(n):t.isKind(F.TableGroup)?e.externals.tableGroups.push(n):t.isKind(F.TablePartial)?e.externals.tablePartials.push(n):t.isKind(F.StickyNote)?e.externals.notes.push(n):t.isKind(F.Element)&&(qm(t.originalSymbol.declaration)===`group`?(e.externals.groups??=[]).push(n):(e.externals.nodes??=[]).push(n))}function fg(e,t){return e>=t.start&&e<t.end}function pg(e,t){let n=t.bodyColon?.start??t.body?.start;return n===void 0?e>=t.start&&e<=t.end:e>=t.start&&e<n}function mg(e,t){let n=e.getSource(t.filepath);if(n)return n.slice(t.start,t.end).trim()}function hg(e,t){return t.map(t=>t.qualifiedName(e).join(`.`)).join(`, `)}function gg(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=hg(e,i),c=i.length>1?`Columns (\`${s}\`) are all nullable but operator \`${r}\` requires at least one to be NOT NULL`:`Column \`${s}\` is nullable but operator \`${r}\` requires it to be NOT NULL`,l=mg(e,a),u=i[0]?.declaration,d=u&&mg(e,u),f=[`- In ref definition \`${l??r}\`, the operator \`${r}\` requires \`${s}\` to reference an existing row.`,d?`- In column definition \`${d}\`, the column is nullable, which allows rows with no parent.`:`- A nullable column allows rows with no parent.`].join(`
7
+ `);return new _f(C.INVALID_REF_RELATIONSHIP,c,t,{category:hf.RefColumnMismatch,explanation:f,quickFixes:o})}function _g(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=hg(e,i),c=i.length>1?`Columns (\`${s}\`) are NOT NULL but operator \`${r}\` allows them to be optional`:`Column \`${s}\` is NOT NULL but operator \`${r}\` allows it to be optional`,l=mg(e,a),u=i[0]?.declaration,d=u&&mg(e,u),f=[`- In ref definition \`${l??r}\`, the operator \`${r}\` marks \`${s}\` as optional.`,d?`- In column definition \`${d}\`, the column is NOT NULL.`:`- The column is NOT NULL.`].join(`
8
+ `);return new _f(C.INVALID_REF_RELATIONSHIP,c,t,{category:hf.RefColumnMismatch,explanation:f,quickFixes:o})}function vg(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=hg(e,i),c=i.length>1?`Columns (\`${s}\`) have a unique index but operator \`${r}\` allows many`:`Column \`${s}\` is unique but operator \`${r}\` allows many`,l=[`- In ref definition \`${mg(e,a)??r}\`, the operator \`${r}\` allows many.`,`- \`${s}\` has a unique constraint, so each value can appear at most once.`].join(`
9
+ `);return new _f(C.INVALID_REF_RELATIONSHIP,c,t,{category:hf.RefColumnMismatch,explanation:l,quickFixes:o})}function yg(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=hg(e,i),c=i.length>1?`Columns (\`${s}\`) should have a composite unique index for operator \`${r}\``:`Column \`${s}\` should be unique or primary key for operator \`${r}\``,l=[`- In ref definition \`${mg(e,a)??r}\`, the operator \`${r}\` implies \`${s}\` has at most one row.`,`- \`${s}\` has no unique or primary key constraint.`].join(`
10
+ `);return new _f(C.INVALID_REF_RELATIONSHIP,c,t,{category:hf.RefColumnMismatch,explanation:l,quickFixes:o})}function bg(e,t,n,r){let{schema:i,name:a}=r?t.interpretedName(e,r):{schema:t.schema(e),name:t.name??``},o=n.map(e=>{let t=e.name??``;return i?`${i}.${a}.${t}`:`${a}.${t}`});return o.length===1?o[0]:`(${o.join(`, `)})`}function xg(e,t){return e.length>1?`Composite ${t}`:t}function Sg(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`NULL not allowed for NOT NULL column \`${n}\` without a default value or auto-increment`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is marked NOT NULL and has no default value or auto-increment.`})}function Cg(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid enum value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` uses an enum type. The value must match one of the defined enum members.`})}function wg(e,t){let{colName:n,typeName:r}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid numeric value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` has type \`${r}\` which expects a numeric value. Provide a valid integer or decimal.`})}function Tg(e,t){let{colName:n,value:r}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid integer value \`${r}\` for column \`${n}\`: expected integer, got decimal`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is an integer column and cannot store decimal values.`})}function Eg(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,totalDigits:s}=t;return new _f(C.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds precision: expected at most ${a} total digits, got ${s}`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${a} total digits. The value \`${i}\` has ${s}.`})}function Dg(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,decimalDigits:s}=t;return new _f(C.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds scale: expected at most ${o} decimal digits, got ${s}`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${o} decimal places. The value \`${i}\` has ${s}.`})}function Og(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid boolean value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is a boolean column. Use \`true\`/\`false\`, \`1\`/\`0\`, or \`'yes'\`/\`'no'\`.`})}function kg(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid datetime value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` expects a date or time value. Supported formats include \`'YYYY-MM-DD'\`, \`'HH:MM:SS'\`, \`'YYYY-MM-DD HH:MM:SS'\`, \`'MM/DD/YYYY'\`, \`'D MMM YYYY'\`, or \`'MMM D, YYYY'\`.`})}function Ag(e,t){let{colName:n}=t;return new _f(C.INVALID_RECORDS_FIELD,`Invalid string value for column \`${n}\``,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is a string column. Values must be wrapped in quotes.`})}function jg(e,t){let{colName:n,typeName:r,typeArg:i,maxLength:a,actualLength:o}=t;return new _f(C.INVALID_RECORDS_FIELD,`String value for column \`${n}\` exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e,{category:hf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${i})\`, limiting values to ${a} bytes in UTF-8 encoding. The provided value uses ${o} bytes.`})}function Mg(e,t,n){let{table:r,columns:i}=n,a=bg(e,r,i),o=xg(i,`PK`);return new _f(C.INVALID_RECORDS_FIELD,`NULL in ${o}: \`${a}\` cannot be NULL`,t,{category:hf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key and cannot be NULL.`})}function Ng(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=bg(e,r,i),s=xg(i,`PK`);return new _f(C.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:hf.RecordConstraintViolation,explanation:`\`${o}\` is a primary key and must be unique across all rows.`})}function Pg(e,t,n){let{table:r,columns:i}=n,a=bg(e,r,i),o=xg(i,`PK`);return new _f(C.INVALID_RECORDS_FIELD,`${o}: Column \`${a}\` is missing from record and has no default value`,t,{category:hf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key with no default or auto-increment, so it must be specified in the records block.`})}function Fg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=bg(e,r,i,s),u=bg(e,a,o,s);return new _f(C.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` must not be NULL`,t,{category:hf.RecordConstraintViolation,explanation:`\`${l}\` references \`${u}\`, so every row must have a non-null value.`})}function Ig(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=bg(e,r,i,s),u=bg(e,a,o,s);return new _f(C.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` does not exist in \`${u}\``,t,{category:hf.RecordConstraintViolation,explanation:`\`${l}\` is a foreign key referencing \`${u}\`. Every non-null value in an FK must match an existing row in the referenced column.`})}function Lg(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=bg(e,r,i),s=xg(i,`UNIQUE`);return new _f(C.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:hf.RecordConstraintViolation,explanation:`\`${o}\` has a unique constraint, so no two rows can have the same value.`})}function Rg(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function zg(e,t){return e?`${e}.${t}`:`${y}.${t}`}function Bg(e,t,n){return n.map(n=>{let r=t[n.name??``]?.value;if(r==null){let t=n.default(e);if(t)return JSON.stringify(t.value)}return JSON.stringify(r)}).join(`|`)}function Vg(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function Hg(e,t,n){let r=n.map(n=>{let r=n.name??``,i=t[r]===void 0?n.default(e)?.value:t[r].value;return JSON.stringify(i)}).join(`, `);return n.length===1?r:`(${r})`}function Ug(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function Wg(e,t){let{token:n}=t;return e.nodeAtPosition(n.filepath,n.start.offset)??e.parse.ast(n.filepath)}function Gg(e,t,n,r){return Oa(r.values)?[]:xa(Xg(t,e),i=>Kg(e,t,n,i,r))}function Kg(e,t,n,r,i){let a=Rg(i),o=Yg(e,t,n,r,i);if(!Oa(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=_(a,t=>Vg(e,t,s)),u=qg(e,t,s,c),d=r.some(t=>t.increment(e))?[]:Jg(e,t,r,l);return[...u,...d]}function qg(e,t,n,r){if(Oa(r))return[];let i=n.map(e=>e.name??``);return xa(r,r=>Ug(r,i).map(r=>Mg(e,Wg(e,r),{table:t,columns:n})))}function Jg(e,t,n,r){let i=n.map(e=>e.name??``);return xa(ma(wa(r,t=>Bg(e,t,n)),e=>e.length>1),r=>xa(r,r=>{let a=Hg(e,r,n);return Ug(r,i).map(r=>Ng(e,Wg(e,r),{table:t,columns:n,valueStr:a}))}))}function Yg(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=da(a,Array.from(o));if(Oa(s))return[];let c=new Set(s),l=r.filter(e=>c.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e));return Oa(l)?[]:i.values.map(()=>Pg(e,n,{table:t,columns:l}))}function Xg(e,t){let n=e.mergedColumns(t),r=ka(n,e=>e.name??``);return[...n.filter(e=>e.pk(t)).map(e=>[e]),...e.mergedIndexes(t).flatMap(e=>{let n=t.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.pk).map(e=>Qr(e.columns.map(e=>r[e.value]))):[]})]}function Zg(e,t,n){if(Oa(n.values))return[];let r=Rg(n);return xa(Qg(e,t),n=>$g(e,t,n,r))}function Qg(e,t){let n=t.mergedColumns(e),r=ka(n,e=>e.name??``);return[...n.filter(t=>t.isUniqueSet(e)).map(e=>[e]),...t.mergedIndexes(e).flatMap(t=>{let n=e.interpretMetadata(t,t.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.unique).map(e=>Qr(e.columns.map(e=>r[e.value]))):[]})]}function $g(e,t,n,r){let i=n.map(e=>e.name??``);return xa(ma(wa(r.filter(t=>!Vg(e,t,n)),t=>Bg(e,t,n)),e=>e.length>1),r=>xa(r,r=>{let a=Hg(e,r,n);return Ug(r,i).map(r=>Lg(e,Wg(e,r),{table:t,columns:n,valueStr:a}))}))}function e_(e,t,n){let r=new Map;for(let i of e.values()){let{name:e,schema:a}=i.tableSymbol.interpretedName(t,n);r.set(zg(a,e),i)}return r}function t_(e,t,n,r){let i=e_(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!Oa(t.record.values)&&a.add(e);return xa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(zg(e.schemaName,e.tableName))):!1),t=>n_(e,t,i,r))}function n_(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(zg(i.schemaName,i.tableName)),s=n.get(zg(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=Qr(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=Qr(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=Zd(i.relation),{min:m,max:h}=Zd(a.relation),ee=p===1&&m===0||p!==`*`&&h!==`*`,te=h===1&&f===0;return[...ee?[]:r_(e,o,u,s,d,i.relation,a.relation,r),...te?[]:r_(e,s,d,o,u,a.relation,i.relation,r)]}function r_(e,t,n,r,i,a,o,s){if(!t.record||Oa(t.record.values))return[];let{min:c,max:l}=Zd(a),{min:u,max:d}=Zd(o),f=Qr(n.map(e=>e.name));Qr(i.map(e=>e.name));let p=u===0,m=Rg(t.record),h=r.record?Rg(r.record):[],ee=new Set(h.map(t=>Bg(e,t,i))),te={leftTable:t.tableSymbol,leftColumns:n,rightTable:r.tableSymbol,rightColumns:i,filepath:s};return xa(m,t=>{if(Vg(e,t,n)){if(p)return[];let r=Hg(e,t,n);return Ug(t,f).map(t=>Fg(e,Wg(e,t),{...te,valueStr:r}))}if(d===`*`&&c===0&&l===`*`)return[];let r=Bg(e,t,n);if(ee.has(r))return[];let i=Hg(e,t,n);return Ug(t,f).map(t=>Ig(e,Wg(e,t),{...te,valueStr:i}))})}function i_(e){return e instanceof Th&&e.declaration instanceof R&&e.declaration.body instanceof U}function a_(e,t){let n=e.edges??[];if(n.length===0||!i_(t))return[];let r=[],i=zg(n[0].downstream.schemaName,n[0].downstream.tableName);for(let e=1;e<n.length;e++){let a=zg(n[e].downstream.schemaName,n[e].downstream.tableName);if(a!==i){r.push(new w(C.DEP_MIXED_DOWNSTREAM_TABLES,`All edges in a Dep block must target the same downstream table, but found '${i}' and '${a}'`,t.declaration));break}}let a=e=>e.upstream.fieldNames.length>0||e.downstream.fieldNames.length>0,o=a(n[0]);for(let e=1;e<n.length;e++)if(a(n[e])!==o){r.push(new w(C.DEP_MIXED_LEVEL,`All edges in a Dep block must be at the same level (all table-level or all column-level)`,t.declaration));break}return r}function o_(e,t){let n=u_(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof z?up(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof R){let n=d_(e,t);if(n)return{kind:`body`,declaration:n}}}function s_(e,t){let n=u_(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof R){let n=e.body;if(n&&!(n instanceof H))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function c_(e,t,n,r){if(n===null)return l_(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=o_(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return s_(e,i)}function l_(e,t,n){let r=o_(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function u_(e){if(e instanceof H)return e.args.find(e=>e instanceof W);if(e instanceof R){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof H)return t.args.find(e=>e instanceof W)}}function d_(e,t){let n=e.body;if(!(!n||Tf(e)||n instanceof H)){for(let e of n.body)if(e instanceof R&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function f_(e,t,n,r){let{allowOtherColFix:i=!0,allowOwnColFix:a=!0}=r??{},o=t.op(e),s=t.opToken(),c=t.cardinalities(e);if(!o||!s||!c)return[];let l=n===`left`?c[0]:c[1],u=Zd(l),d=n===`left`?c[1]:c[0],f=Zd(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),h=n===`left`?t.leftToken():t.rightToken(),ee=n===`left`?t.rightToken():t.leftToken(),te=[];function ne(e,t,n){te.push(n(e));for(let r of t)r.declaration&&r.declaration!==e&&te.push(n(r.declaration))}let re=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&re&&m.length>0&&m.every(t=>t.nullable(e))){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&m_(s,ff(l),d,n,`Make '${r}' optional in the ref`),...i?m.map(t=>h_(t,e)).filter(e=>!!e):[]].filter(e=>!!e);ne(ee,m,n=>gg(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.min===0&&re&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&m_(s,pf(l),d,n,`Make '${r}' required in the ref`),...i?m.map(t=>g_(t,e)).filter(e=>!!e):[]].filter(e=>!!e);ne(ee,m,n=>_g(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.max===`*`&&__(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&m_(s,`1`,d,n,`Make '${r}' one in the ref`)].filter(e=>!!e);ne(h,p,n=>vg(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}if(u.max===1&&!__(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&m_(s,mf(l),d,n,`Make '${r}' many in the ref`),a&&p.length===1&&v_(p[0],e)].filter(e=>!!e);ne(h,p,n=>yg(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}return te}function p_(e,t){return[...f_(e,t,`right`,{allowOtherColFix:!1}),...f_(e,t,`left`,{allowOwnColFix:!1})]}function m_(e,t,n,r,i){let a=df(r===`left`?t:n,r===`right`?t:n);return{title:`${i} (change operator to '${a}')`,shortTitle:`Change to ${a}`,filepath:e.filepath,edits:[{start:e.start,end:e.end,newText:a}],isPreferred:!0}}function h_(e,t){if(!e.declaration||e.pk(t)||e.increment(t)||e.isNotNullSet(t))return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=e.qualifiedName(t).join(`.`),i=l_(e.declaration,`null`,n);if(i)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[i]};let a=s_(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[a]}}function g_(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=l_(e.declaration,`not null`,n);if(r)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as NULL`,shortTitle:`Make nullable`,filepath:e.declaration.filepath,edits:[r]}}function __(e,n){if(n.length===0)return!1;if(n.length===1&&n[0].unique(e))return!0;let r=n[0],i=(r instanceof am?r.injectionDeclaration:r.declaration)?.parentOfKind(R);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof Hp))return!1;let o=a.mergedIndexes(e),s=new Set(n.map(e=>e.name));for(let t of o){let r=e.interpretMetadata(t,n[0].filepath).getValue();if(!(!r||!Array.isArray(r))){for(let e of r)if(!(!e.unique&&!e.pk)&&e.columns.length===s.size&&e.columns.every(e=>s.has(e.value)))return!0}}return!1}function v_(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=s_(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,shortTitle:`Add unique`,filepath:e.declaration.filepath,edits:[n]}}var y_=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],this.arch={nodes:[],groups:[],links:[]},this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],deps:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:P(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.infos.push(...this.validateRecords()),this.finishArch(),new n(this.db,this.errors,this.warnings,this.infos)}finishArch(){let e=this.compiler.parsedFileKind(this.filepath)===`arch`,t=new Set([...[...this.arch.nodes,...this.arch.groups].map(e=>e.alias??e.name),...this.db.notes.map(e=>e.name)]),n=new Map;for(let e of this.arch.groups){let r=e.alias??e.name;for(let i of e.children)t.has(i)&&!n.has(i)&&n.set(i,r)}for(let e of this.arch.groups){let t=e.alias??e.name;e.children=e.children.filter(e=>n.get(e)===t)}let r=new Set;for(let{link:e,declaration:t}of this.arch.links){let i=[e.from,e.to].sort().join(`\0`);r.has(i)&&this.warnings.push(new gf(C.DUPLICATE_LINK,`${e.from} and ${e.to} are already connected`,t)),r.add(i),(n.get(e.from)===e.to||n.get(e.to)===e.from)&&this.warnings.push(new gf(C.NESTED_ENDPOINTS,`${e.from} is already inside ${e.to}`,t))}let i={nodes:this.arch.nodes,groups:this.arch.groups,links:this.arch.links.map(({link:e})=>e)};for(let[t,n]of Object.entries(i))(e||n.length)&&(this.db[t]=n);let a={...this.compiler.scanFile(this.filepath).frontMatter,...e?b_(this.programNode):{}};Object.keys(a).length&&(this.db.frontMatter=a),e&&(this.db.diagramType=`arch`)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof im)continue;let r=this.compiler.interpretSymbol(n,this.filepath);if(r.hasValue(t))continue;this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let i=r.getValue();i&&this.pushElement(n,i)}let e=new Set,n=(this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[]).filter(e=>e instanceof zp);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof zp){n.push(t);continue}if(!(t instanceof im))continue;let r=t.originalSymbol.intern();e.has(r)||(e.add(r),this.interpretUseSymbol(t))}}}interpretUseSymbol(e){let n=e.originalSymbol,r=this.compiler.interpretSymbol(n,this.filepath);if(!r.hasValue(t)){this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let t=r.getValue();t&&this.pushElement(e,t)}let i=n instanceof Hp?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Hp?n.interpretedName(this.compiler,this.filepath):{name:e.name??n.name??``,schema:null},o={name:i.name,schemaName:i.schema,filepath:n.filepath,visibleNames:[{schemaName:a.schema,name:a.name}]};dg(this.db,e,o)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],n=new Set,r=new Set,i=new Map;for(let t of e){if(!(t instanceof kh))continue;let e=t.table(this.compiler);if(!e)continue;let n=e.originalSymbol.intern(),r=i.get(n);r?r.count++:i.set(n,{count:1,tableName:e.name??``})}for(let a of e){let e=this.compiler.interpretMetadata(a,this.filepath);if(e.hasValue(t))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings()),this.infos.push(...e.getInfos());let o=e.getValue();if(o!==void 0)switch(a.kind){case Sh.Ref:{let e=o,[t,r]=e.endpoints??[];if(t&&r){let e=[t.schemaName,t.tableName,t.fieldNames.join(`,`),r.schemaName,r.tableName,r.fieldNames.join(`,`)].join(`|`),i=[r.schemaName,r.tableName,r.fieldNames.join(`,`),t.schemaName,t.tableName,t.fieldNames.join(`,`)].join(`|`);if(n.has(e)||n.has(i)){this.errors.push(new w(C.SAME_ENDPOINT,`Ref with same endpoints already exists`,a.declaration));break}n.add(e)}this.db.refs.push(e);break}case Sh.Dep:{let e=o,t=a instanceof Th?a.edgeExpressions():[],n=-1;if((e.edges??[]).some((e,t)=>{let{upstream:i,downstream:a}=e,o=[i.schemaName,i.tableName,i.fieldNames.join(`,`),a.schemaName,a.tableName,a.fieldNames.join(`,`)].join(`|`);return r.has(o)?(n=t,!0):(r.add(o),!1)}),n>=0){let e=t[n]??a.declaration;this.errors.push(new w(C.SAME_ENDPOINT,`Dep with same endpoints already exists`,e));break}let i=a_(e,a);if(i.length>0){this.errors.push(...i);break}this.db.deps.push(e);break}case Sh.Records:if(a instanceof kh){let e=a.table(this.compiler)?.originalSymbol.intern()??``,t=e?i.get(e):void 0;if(t&&t.count>1){this.errors.push(new w(C.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,a.declaration));break}}this.db.records.push(o);break;case Sh.Project:this.db.project=o;break;case Sh.Link:this.arch.links.push({link:o,declaration:a.declaration});break;case Sh.MetadataElement:default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof rm)||!t.isKind(F.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:jm.Table,value:{tableName:e,schemaName:n}};this.db.aliases.push(r)}}validateRecords(){let e=[],n=new Map,r=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let e of r){if(!(e instanceof zp))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(F.Table))continue;let t=e.originalSymbol;if(!(t instanceof Hp))continue;let r=t.intern();n.has(r)||n.set(r,{tableSymbol:t,record:void 0,recordBlock:t.declaration})}}let i=this.compiler.symbolMetadata(this.programSymbol);for(let r of i){if(!(r instanceof kh))continue;let i=r.table(this.compiler);if(!(i instanceof Hp))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...Gg(this.compiler,i,r.declaration,o)),e.push(...Zg(this.compiler,i,o));let s=i.originalSymbol.intern(),c=n.get(s);c?c.record=o:n.set(s,{tableSymbol:i,record:o,recordBlock:r.declaration})}let a=this.collectPartialRefs(n);return e.push(...t_(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Eh);for(let t of e)this.infos.push(...p_(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Eh),n=[];for(let{tableSymbol:r}of e.values())for(let e of r.resolvedPartials(this.compiler))for(let i of t){if(i.leftTablePartial(this.compiler)?.originalSymbol!==e.originalSymbol)continue;let t=i.leftColumns(this.compiler),a=i.rightTable(this.compiler),o=i.rightColumns(this.compiler),s=i.op(this.compiler);if(!a||!s||t.length===0||o.length===0)continue;let c=r.mergedColumns(this.compiler);if(!t.some(e=>c.some(t=>t instanceof am&&t.declaration===e.declaration)))continue;let l=af(s);if(!l)continue;let u=a instanceof Jp&&a.originalSymbol===e.originalSymbol?r:a,d=r.interpretedName(this.compiler,this.filepath),f=u.interpretedName(this.compiler,this.filepath),p={schemaName:d.schema,tableName:d.name,fieldNames:t.map(e=>e.name??``),relation:l[0],token:P(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:P(i.rightToken())};n.push({token:P(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case F.Element:qm(e.originalSymbol.declaration)===`group`?this.arch.groups.push(t):this.arch.nodes.push(t);break;case F.Table:this.db.tables.push(t);break;case F.Enum:this.db.enums.push(t);break;case F.TableGroup:this.db.tableGroups.push(t);break;case F.TablePartial:this.db.tablePartials.push(t);break;case F.StickyNote:this.db.notes.push(t);break;case F.DiagramView:this.db.diagramViews.push(t);break;default:break}}};function b_(e){let t={};for(let n of e.body)if(!(!Km(n)||qm(n)!==`project`))for(let e of rh(n)){let n,r;if(e instanceof R)n=Gm(e)?.toLowerCase(),r=Xm(ih(rh(e)[0])?.callee);else{let t=ih(e);n=Xm(t?.callee)?.toLowerCase(),r=Xm(t?.args[0])}!n||n===`diagram_type`||r===void 0||(t[n]=r)}return t}var x_={nodeSymbol(t,r){return Uf(r)?n.create(t.symbolFactory.create(nm,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Program))return n.create(e);if(!(i.declaration instanceof L))return n.create([]);let a=new Map;for(let e of r.reachableFiles(i.filepath)){let{schemaMembers:t}=r.usableMembers(e).getValue();for(let e of t)a.has(e.name)||a.set(e.name,e)}let o=a.get(y);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(F.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Uf(r)?new lg(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof nm))return n.create(e);if(!(r.declaration instanceof L))return n.create(void 0);if(!Rm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new y_(t,r,i).interpret()}},S_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof H)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},C_=class{constructor(e,t,n){this.declarationNode=t,this.compiler=e,this.filepath=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){this.project.token=P(this.declarationNode);let e=[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)];return new n(this.project,e)}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=kp(e);return this.project.name=t,[]}interpretSubElement(e){let r=this.compiler.nodeSymbol(e).getFiltered(t);if(r){let e=this.compiler.interpretSymbol(r,this.filepath);if(!e.hasValue(t))return e}return n.create(void 0)}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.getElementKind()){case r.Table:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tables?.push(e.getValue()),e.getErrors()}case r.TableGroup:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tableGroups?.push(e.getValue()),e.getErrors()}case r.Enum:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.enums?.push(e.getValue()),e.getErrors()}case r.Note:{let e=t.body instanceof U?t.body.body[0]?.callee:t.body?.callee,n=e?M(e):void 0;return n&&(this.project.note={value:Op(n),token:P(t)}),[]}case r.TablePartial:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tablePartials?.push(e.getValue()),e.getErrors()}default:return this.project[t.type.value.toLowerCase()]=M(t.body.callee),[]}})}},w_={nodeMetadata(t,i){return k(i,r.Project)?n.create(new Nh(i)):n.create(e)},bindNode(t,i){return k(i,r.Project)?n.create(void 0,new S_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Nh)||!(r.declaration instanceof R)?n.create(e):new C_(t,r.declaration,i).interpret()}},T_=class{constructor(e,t){this.compiler=e,this.declarationNode=t,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof U&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof L?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=cp(e);if(!n)return[];let r=n.variables.pop(),i=n.variables;if(!r)return[];let a=this.compiler.nodeReferee(r).getErrors();if(a.length>0)return a;let o=this.compiler.nodeReferee(r).getFiltered(t);if(!o)return[];let s=tp(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=lp(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new w(C.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new w(C.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new w(C.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,e))),this.boundColumns.set(r,e)}return c}bindInsideTableName(e){let n=this.declarationNode.parent;if(!(n instanceof R)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Ff(e))return[];let i=tp(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=lp(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new w(C.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n));continue}}return a}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof H),n=e.body.filter(e=>e instanceof R);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof xm?e.callee.elementList:[e.callee]).flatMap(zm).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();return!t||!n?[]:[...e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors()),...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}):[]}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},E_=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=D_(this.element,this.compiler,this.filepath);if(!r||r.columns.length===0)return new n(void 0,e);let i=[];for(let n of this.element.body.body){let a=O_(n,r.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getInfos());let o=a.getValue();o.row&&i.push(o.row)}let a=P(this.element),o=this.metadata.example(this.compiler)||void 0;return new n({schemaName:r.schemaName,tableName:r.tableName,columns:r.columns.map(e=>e.name??``),values:i,example:o,token:a},e,[],t)}};function D_(e,n,i){let a=e.name,o=e.parent;if(o instanceof R&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Hp))return;let r=e.mergedColumns(n),s=e.interpretedName(n,i),c=s.schema,l=s.name;return a?{schemaName:c,tableName:l,columns:a.elementList.flatMap(e=>r.find(t=>t.name===N(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=cp(a);if(!s)return;let c=s.variables.map(e=>e.expression.variable?.value??``),l=c.at(-1)??``,u=c.length>1?c.slice(0,-1).join(`.`):void 0,d=n.parseFile(e.filepath).getValue().ast,f=n.nodeSymbol(d).getFiltered(t);if(!f)return;let p;if(u){let e=n.lookupMembers(f,F.Schema,u);e&&(p=n.lookupMembers(e,F.Table,l))}if(p||=n.lookupMembers(f,F.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Hp))return;let h=m.mergedColumns(n),ee=s.args.map(e=>h.find(t=>t.name===N(e))).filter(Boolean),te=m.interpretedName(n,i);return{schemaName:te.schema,tableName:te.name,columns:ee}}function O_(e,t,r){let i=[],a=[],o={},s=e.callee instanceof xm?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new w(C.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new n({row:null,columnNodes:{}},i,[],a);let c=[];for(let e=0;e<t.length;e++){let n=s[e],l=t[e];o[l.name??``]=n;let u=A_(n,l,r);i.push(...u.getErrors()),a.push(...u.getInfos());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:P(n)})}return new n({row:c,columnNodes:o},i,[],a)}function k_(e){return e instanceof ym&&e.value?.value||``}function A_(e,t,r){let i=P(e),a=t.type(r),o=(a?.name??``).split(`(`)[0],s=!!a?.enumSymbol,c=t.increment(r),l=t.isNotNullSet(r)===!0,u=t.default(r),d=t.name??``,f=Lo(o,s),p=xp(e),m=p===null?k_(e):p,h=p===null?`expression`:f;if(e instanceof ym)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(dp(e)||fp(e)&&!No(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Io(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[],[Sg(e,{colName:d})]):new n({value:null,type:f,token:i},[],[])}if(s){let a=t.type(r)?.enumSymbol,o=a?a.members(r).filter(e=>e.isKind(F.EnumField)).map(e=>e.name).filter(Boolean):[],s=M(e);return s===void 0&&(s=D(e)?e.expression.variable.value:void 0),o.includes(s)?new n({value:s,type:f,token:i},[],[]):new n({value:s,type:f,token:i},[],[],[Cg(e,{colName:d})])}if(ko(o)||Ao(o)||Io(o)){let t=mp(e);if(t===null)return new n({value:m,type:h,token:i},[],[],[wg(e,{colName:d,typeName:o})]);if(ko(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[],[Tg(e,{colName:d,value:t})]);let r=Ao(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Ao(o)&&r){let{precision:a,scale:s}=r,c=t.toString().split(`.`),l=c[0].replace(/^-/,``),u=c[1]||``,p=l.length+u.length,m=u.length;if(p>a)return new n({value:t,type:f,token:i},[],[],[Eg(e,{colName:d,typeName:o,value:t,precision:a,scale:s,totalDigits:p})]);if(m>s)return new n({value:t,type:f,token:i},[],[],[Dg(e,{colName:d,typeName:o,value:t,precision:a,scale:s,decimalDigits:m})])}return new n({value:t,type:f,token:i},[],[])}if(Mo(o)){let t=yp(e);return t===null?new n({value:m,type:h,token:i},[],[],[Og(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Fo(o)){let t=Tp(e);return t===null?new n({value:m,type:h,token:i},[],[],[kg(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(No(o)){let t=xp(e);if(t===null)return new n({value:m,type:h,token:i},[],[],[Ag(e,{colName:d})]);let r=a?.args?.length?Number(a.args[0]):void 0;if(r&&!Number.isNaN(r)){let s=r,c=new TextEncoder().encode(t).length;if(c>s)return new n({value:t,type:f,token:i},[],[],[jg(e,{colName:d,typeName:o,typeArg:String(a.args[0]),maxLength:s,actualLength:c})])}return new n({value:t,type:`string`,token:i},[],[])}return new n({value:m,type:h,token:i},[],[])}var j_={nodeMetadata(t,i){if(!k(i,r.Records))return n.create(e);let a=i.parent;if(a&&k(a,r.Table))return n.create(new kh(i));let o=i.name;return o instanceof Cm&&o.callee?n.create(new kh(i)):n.create(e)},nodeReferee(i,a){if(!D(a))return n.create(e);let o=a.parentOfKind(R);if(!o?.isKind(r.Records))return n.create(e);let s=i.parseFile(a.filepath).getValue().ast,c=i.nodeSymbol(s).getFiltered(t);if(!c)return n.create(void 0);let l=a.parentOfKind(bm);if(l?.parentNode===o)return M_(i,o,a);let u=a.parentOfKind(Cm);return u?.parentNode===o&&l?.parentNode===u?N_(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?P_(i,c,a):I_(i,c,a)},bindNode(t,i){return k(i,r.Records)?n.create(void 0,new T_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof kh?r.declaration instanceof R?new E_(t,r,i).interpret():n.create(void 0):n.create(e)}};function M_(e,i,a){let o=i.parent;if(o instanceof R&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return F_(e,n,a)}return new n(void 0)}function N_(e,r,i){if(r.callee){let n;if(D(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=ip(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return F_(e,n,i)}return new n(void 0)}function P_(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode)){let a=e.lookupMembers(t,[F.Table,F.Schema],i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Bm(e,r);if(!a){let a=e.lookupMembers(t,[F.Table,F.Schema],i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Table,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function F_(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``,a=e.lookupMembers(t,F.Column,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function I_(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return new n(void 0);let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var L_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(zm).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();return!t||!n?[]:(Array.isArray(t)||(t=[t]),[...e.variables,n,...t].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},R_=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()],{infos:t}=this.validateRefConstraints();return n.create(this.ref,e,void 0,t)}interpretName(){if(!(this.declarationNode instanceof R))return[];let e=[],t=j(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if(La(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new w(C.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=af(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=P(this.metadata.leftToken()),l=P(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof R?[{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c},{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l}]:[{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l},{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c}],!(this.declarationNode instanceof R))return[];let u=rp(this.declarationNode)[0];if(u.args[0]){let e=T(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof _m?ep(t):N(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof _m?ep(n):N(n),this.ref.color=e.color?.length?Ap(e.color?.at(0)?.value):void 0,this.ref.inactive=e.inactive?.length?!0:void 0}return[]}validateRefConstraints(){return this.metadata.cardinalities(this.compiler)?{infos:[...f_(this.compiler,this.metadata,`right`),...f_(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function z_(e){let t=e.parent;for(;t;){if(t instanceof R&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var B_={nodeReferee(r,i){if(!D(i)&&!O(i)||!z_(i)||i.parentOfKind(z))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):V_(r,o,i)},nodeMetadata(t,a){if(k(a,r.Ref)){let t=rp(a)[0];if(!(t instanceof H)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof V)||!r.op?n.create(e):n.create(new wh(a))}if(a instanceof z){if(!(a.name instanceof _m)||ep(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof R&&t.isKind(r.TablePartial)?n.create(new Eh(a)):n.create(new wh(a))}return n.create(e)},bindNode(t,i){return k(i,r.Ref)?n.create(void 0,new L_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof wh?new R_(t,r,i).interpret():n.create(e)}};function V_(e,r,i){if(!D(i))return new n(void 0);let a=lp(i)??``;if(!O(i.parentNode)){let r=i.parentNode;if(r&&O(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=O(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(F.Table)){let r=e.lookupMembers(c,F.Column,a);if(r)return n.create(r);let o=c.declaration?e.nodeFullname(c.declaration).getFiltered(t)?.join(`.`)??c.name:c.name;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Bm(e,i);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(F.Table)){let r=e.lookupMembers(o,F.Column,a);return r?n.create(r):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${o.declaration?e.nodeFullname(o.declaration).getFiltered(t)?.join(`.`)??o.name:o.name}'`,i)])}return new n(void 0)}let s=i.parentNode;if(s.leftExpression===i){if(O(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,F.Schema,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Hm(e,r);if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var H_={visibleName(e,n){let r=n instanceof I?n:n.useSpecifierDeclaration instanceof hm?n.useSpecifierDeclaration:n.declaration;if(r instanceof hm&&n instanceof Rp&&r.getSymbolKind()!==n.kind&&(r=n.declaration),!r)return;let i=e.nodeAlias(r).getFiltered(t);return i===void 0?e.nodeFullname(r).getFiltered(t):[i]}},U_={nodeSymbol(r,i){if(!Hf(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===F.Schema)return n.create(e);let o=r.nodeReferee(i.name).getFiltered(t);return o&&!o.canBeImported?n.create(e):n.create(r.symbolFactory.create(im,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:H_.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new w(C.BINDING_ERROR,`Failed to resolve the import of ${a} '${(j(i.name)||[]).map(bv).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof im))return n.create(e);if(i.originalSymbol===i)return n.create([]);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!D(i)&&!Bf(i))return n.create(e);let a=i.parentOfKind(hm);if(!a)return n.create(e);let o=a.name===i||O(a.name)&&a.name.rightExpression===i?a.getSymbolKind():F.Schema;if(o===void 0)return n.create(void 0);let s=j(i.parentOfKind(V)),c=N(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(mm);if(l?.importPath?.value===void 0)return n.create(void 0);let u=r.layout.resolveFileSpecifier(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new w(C.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new w(C.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toKey()}. Does the file exist?`,i)]);let d=i.parentOfKind(V)?.leftExpression;if(d&&d!==i){let e=r.nodeReferee(d).getFiltered(t);if(!e)return n.create(void 0);let a=r.lookupMembers(e,o,c);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=W_(r,u,c,o);return f?n.create(f):n.create(void 0,[new w(C.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toKey()}`,i)])},bindNode(t,r){if(Vf(r)){let e=[];if(r.importPath?.value){let n=t.layout.resolveFileSpecifier(r.filepath,r.importPath.value);(!n||!t.layout.exists(n))&&e.push(new w(C.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath))}if(r.specifiers){let n=t.bindNode(r.specifiers);e.push(...n.getErrors())}return new n(void 0,e)}return r instanceof gm?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):Hf(r)?r.name?new n(void 0,t.nodeReferee(r.name).getErrors()):new n(void 0):n.create(e)},interpretSymbol(r,i,a){if(!(i instanceof im))return n.create(e);if(!i.usedSymbol)return n.create(void 0);let o=r.interpretSymbol(i.usedSymbol,a);if(o.hasValue(t))return n.create(void 0);let s=o.getValue();if(!s||Array.isArray(s))return o;let c=i.name;return c&&`name`in s?n.create({...s,name:c}):n.create(s)}};function W_(e,n,r,i,a=new Set){if(!n||a.has(n.intern()))return;a.add(n.intern());let o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.nonSchemaMembers.find(e=>e.name===r&&e.isKind(i));if(s)return s;let c=o.schemaMembers.find(e=>e.name===r);if(c?.isKind(F.Schema))return c;for(let t of o.reuses.selective)if(j(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(mm);if(o?.importPath?.value){let s=W_(e,e.layout.resolveFileSpecifier(n,o.importPath.value),j(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=W_(e,t,r,i,a);if(n)return n}}function G_(e){if(e instanceof mo){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=q_(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof nm?J_(this,e,i):Y_(this,e,i);return new n({nonSchemaMembers:a,schemaMembers:o,reuses:{selective:i.selectiveReuses,wildcard:i.wildcardReuses},uses:{selective:i.selectiveUses,wildcard:i.wildcardUses}},i.parseResult.getErrors(),i.parseResult.getWarnings())}function K_(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof hm?H_.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof hm&&r.getSymbolKind()===F.Schema?a:a.length<=1?[y]:a.slice(0,-1);return o.length<i.length||!i.every((e,t)=>e===o[t])?{kind:`none`}:o.length===i.length?{kind:`direct`}:{kind:`child`,schemaName:o[i.length]}}function q_(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let n of r.body){if(!(n instanceof mm)||!n.specifiers||!n.importPath)continue;let r=e.layout.resolveFileSpecifier(t,n.importPath.value);r&&(n.isReuse?n.specifiers instanceof Tm?i.push({importPath:r,node:n.specifiers}):a.push(...n.specifiers.specifiers):n.specifiers instanceof Tm?o.push({importPath:r,node:n.specifiers}):s.push(...n.specifiers.specifiers))}return{ast:r,parseResult:n,selectiveReuses:a,wildcardReuses:i,selectiveUses:s,wildcardUses:o}}function J_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[y,e.symbolFactory.create(zp,{name:y},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?y:r[0];c.has(i)||c.set(i,e.symbolFactory.create(zp,{name:i},s))}X_(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of Q_(e,t))c.has(n)||c.set(n,e.symbolFactory.create(zp,{name:n},s));let l=[...c.values()],u=[],d=l.find(e=>e.isPublicSchema());if(d){let n=e.usableMembers(d).getFiltered(t);n&&u.push(...n.nonSchemaMembers)}return{nonSchemaMembers:u,schemaMembers:l}}function Y_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof R))continue;let i=K_(e,n,r),a=e.nodeAlias(r).getFiltered(t),o=e.nodeSymbol(r).getFiltered(t);if(a!==void 0&&n.isPublicSchema()&&o&&s.push(e.symbolFactory.create(rm,{kind:o.kind,declaration:r,aliasedSymbol:o,name:a},n.filepath)),i.kind!==`none`)if(i.kind===`direct`){let n=e.nodeSymbol(r).getFiltered(t);if(!n)continue;s.push(n)}else c.has(i.schemaName)||c.set(i.schemaName,e.symbolFactory.create(zp,{name:i.schemaName,parent:n},n.filepath))}Z_(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of $_(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(zp,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function X_(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==F.Schema)continue;let t=H_.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(zp,{name:t},r))}}function Z_(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==F.Schema)continue;let t=H_.visibleName(e,a);if(!t||t.length<=i.length||!i.every((e,n)=>e===t[n]))continue;let o=t[i.length];o&&!r.has(o)&&r.set(o,e.symbolFactory.create(zp,{name:o,parent:n},n.filepath))}}function Q_(e,n){let{ast:r}=e.parseFile(n).getValue(),i=[];for(let n of r.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],a=r.length<=1?y:r[0];i.push(a)}let a=q_(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==F.Schema)continue;let n=H_.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function $_(e,n,r){let{ast:i}=e.parseFile(n).getValue(),a=[];for(let n of i.declarations){let i=e.nodeFullname(n).getFiltered(t)||[],o=i.length<=1?[y]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=q_(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==F.Schema)continue;let n=H_.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var ev=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){let e=[];return this.declarationNode.attributeList&&e.push(...this.bindHeaderSettings(this.declarationNode.attributeList)),this.declarationNode.body instanceof U&&e.push(...this.bindBody(this.declarationNode.body)),e}bindHeaderSettings(e){return T(e).getValue().dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])??[]}bindInlineDepValue(e){return zm(e).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof H);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(g(n)instanceof W){let e=T(g(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.dep?.flatMap(e=>e.value?this.bindInlineDepValue(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=>!Ef(e.callee)))}tryToBindColumnType(e){let t=ap(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(E(e))return[];if(D(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&go.includes(t))return[]}let t=ap(e);if(!t){if(O(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return zm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}};function tv(e){let t=e.targetKind?.value?.toLowerCase();return Object.values(Ip).find(e=>e.toLowerCase()===t)}function nv(e,t,n){let r=[];return t.length>1&&r.push(...t.map(t=>new w(n.duplicate,`'${e}' can only appear once`,t))),t.forEach(t=>{Lf(t.value)||r.push(new w(n.invalidValue,`Custom setting '${e}' must be a string or a color literal`,t.value||t.name||t))}),r}function rv(e,t,n){if(!n.length)return;let{name:r,symbolKind:i}=n[0],a=e.lookupMembers(t,i,r);return n.length>1&&a?rv(e,a,n.slice(1)):a}function iv(e,t){if(e.length===0)return[];let n;switch(t){case Ip.Table:n=[...Array(e.length-1).fill(F.Schema),F.Table];break;case Ip.Column:n=e.length===1?[F.Column]:[...Array(e.length-2).fill(F.Schema),F.Table,F.Column];break;case Ip.TableGroup:n=[...Array(e.length-1).fill(F.Schema),F.TableGroup];break;case Ip.Note:n=[...Array(e.length-1).fill(F.Schema),F.StickyNote];break;default:break}return e.map((e,t)=>({name:e,symbolKind:n[t]}))}function av(e,t){let n=Um(e,t.filepath);if(!n)return;let r=tv(t),i=j(t.name);if(!i?.length||!r)return;let a=iv(i,r),{name:o,symbolKind:s}=a[0];if(o===`public`&&s===F.Schema){let t=Hm(e,n);if(t)return rv(e,t,a.slice(1))}return rv(e,n,a)}function ov(e,t){let n=[],r=new Set,i=t=>{let a=t.intern();if(!r.has(a)){r.add(a);for(let n of e.fileDependencies(t))i(n);n.push(t)}};i(t);let a=new Map;return n.forEach((e,t)=>a.set(e.intern(),t)),a}function sv(e,n,r,i,a){let o=Um(e,a);if(!o)return;let s=e.symbolMetadata(r).filter(t=>t.owners(e).includes(o));if(!s.length)return;let c=ov(e,a),l=[...s].sort((e,t)=>{let n=c.get(e.declaration.filepath.intern())??-1,r=c.get(t.declaration.filepath.intern())??-1;return n===r?e.declaration.start-t.declaration.start:n-r}).map(n=>e.interpretMetadata(n,a).getFiltered(t)).filter(e=>!!e);if(!l.length)return;let u={};for(let e of l)for(let[t,{value:n,token:r}]of Object.entries(e))u[t.toLowerCase()]={originalKey:t,value:n,token:r};let d=n.metadata?Object.fromEntries(Object.entries(n.metadata).map(([e,t])=>[e.toLowerCase(),{originalKey:e,value:t}])):{};Object.entries(u).forEach(([e,t])=>{let{originalKey:r,value:a,token:o}=t;i[e]?i[e].assignBuiltinField(n,a,o):d[e]={originalKey:r,value:a}}),n.metadata=Object.fromEntries(Object.values(d).map(e=>[e.originalKey,e.value]))}var cv=class{constructor(e,t,n,r){this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=this.symbol?.token??P(this.declarationNode);let e=[];if(this.symbol){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);this.table.name=e,this.table.schemaName=t}else e.push(...this.interpretName(this.declarationNode.name));let t=[...e,...this.interpretAlias(this.declarationNode.alias),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.table.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),this.attachTableAndColumnMetadata(),n.create(this.table,t)}attachTableAndColumnMetadata(){if(!this.symbol)return;sv(this.compiler,this.table,this.symbol,uv,this.filepath);let e=this.compiler.symbolMembers(this.symbol).getFiltered(t)??[];for(let t of e){if(!t.isKind(F.Column))continue;let e=this.table.fields.find(e=>e.name===t.name);e&&sv(this.compiler,e,t,dv,this.filepath)}}interpretName(e){let{name:t,schemaName:n}=kp(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new w(C.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=lp(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=T(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Ap(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Op(M(n?.value)),token:P(n)},this.table.metadata=Np(t,Object.keys(uv)),[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof H);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:Op(M(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:P(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);case r.Records:return[];default:return[]}})}interpretInjection(e,n){let r=[],i={order:n,token:P(e)};i.name=N(e.expression)||``;let a=e.expression?this.compiler.nodeReferee(e.expression).getFiltered(t):void 0,o=this.compiler.parseFile(this.filepath).getValue().ast,s=this.compiler.nodeSymbol(o).getFiltered(t);if(a&&!s.inNestedSchema(this.compiler,a)){let n=this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),o=n?(this.compiler.symbolUses(n).getFiltered(t)??[]).find(e=>e.filepath.equals(this.filepath)):void 0;r.push(new w(C.UNSUPPORTED,`TablePartial ${i.name} from '${a.filepath}' should be imported. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,o?.useSpecifierDeclaration??e))}return this.table.partials.push(i),r}interpretFields(e){let n=this.symbol??this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),r=(n?this.compiler.symbolMembers(n).getFiltered(t)??[]:[]).filter(e=>e.isKind(F.Column)).length?[]:[new w(C.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Ef(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...r,...i]}interpretColumn(e){let n=[],r={},a=this.compiler.nodeSymbol(e).getFiltered(t);r.name=lp(e.callee),r.token=P(e);let o=Mp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||!1,r.unique=a?.isUniqueSet(this.compiler)||!1,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{};r.metadata=Np(s,lv);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.endpoints?.[0])return[];let s=o.endpoints[0],c=r.op(this.compiler);return c?{schemaName:s.schemaName,tableName:s.tableName,fieldNames:s.fieldNames,relation:c,token:s.token}:[]}),r.inline_deps=(s[i.Dep]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.edges?.[0])return[];let s=e.value;if(!(s instanceof B))return[];let c=s.op?.value;if(c!==`->`&&c!==`<-`)return[];let u=o.edges[0],d=c===`->`?u.downstream:u.upstream;return{schemaName:d.schemaName,tableName:d.tableName,fieldNames:d.fieldNames,direction:c,token:d.token}}),r.checks=(s[i.Check]||[]).map(e=>({token:P(e),expression:e.value.value.value})),this.table.fields.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.indexes.push(...i):i&&this.table.indexes.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.checks.push(...i):i&&this.table.checks.push(i),r.getErrors()}},lv=[i.Note,i.Ref,i.PrimaryKey,i.PK,i.NotNull,i.Null,i.Unique,i.Increment,i.Default,i.Check],uv={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.HeaderColor]:{isValidBuiltinFieldValue:kf,message:`'headercolor' must be a color literal`,assignBuiltinField(e,t){e.headerColor=t}}},dv={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a quoted string`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}}},fv={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new w(C.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new w(C.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},pv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.Table)?new n(i.symbolFactory.create(Hp,{declaration:a,name:o},a.filepath)):A(a,r.Table)?Ef(a.callee)?new n(i.symbolFactory.create(Yp,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Up,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Table))return n.create(e);let a=i.declaration;if(!(a instanceof R))return new n([]);let o=rp(a),s=[],c=[];for(let e of o){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(s.push(i),c.push(...n.getErrors()))}let l=new Map;for(let e of s){if(!e.isKind(F.Column,F.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(F.Column)?(c.push(fv.getColumnDuplicateError(e.name,r)),c.push(fv.getColumnDuplicateError(e.name,n))):(c.push(fv.getPartialInjectionDuplicateError(e.name,r)),c.push(fv.getPartialInjectionDuplicateError(e.name,n))):l.set(t,n)}}let u=[];for(let e=0;e<s.length;e++){let n=s[e];if(!(n.declaration instanceof H)||!Ef(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=N(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new w(C.BINDING_ERROR,`TablePartial '${o}' does not exist in Schema 'public'`,i||a));continue}let d=r.symbolMembers(l).getFiltered(t);if(d){let t=d.flatMap(e=>{if(!e.declaration)return[];let t=e.name;return t===void 0?e:r.symbolFactory.create(am,{kind:F.Column,injectionDeclaration:n.declaration,declaration:e.declaration,name:t},a.filepath)});u.push({index:e,partialMembers:t})}}for(let e=u.length-1;e>=0;e--){let{index:t,partialMembers:n}=u[e];s.splice(t,0,...n)}let d=new Set(s.filter(e=>e.isKind(F.Column)&&!(e instanceof am)).map(e=>e.name));return new n(Pa([...s.filter(e=>!(e instanceof am&&d.has(e.name)))].reverse(),e=>e.isKind(F.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(qf(o,i.Dep)&&o.parent instanceof R&&o.parent.isKind(r.Table)&&!Wf(o,r.Table)){let e=a.parseFile(o.filepath).getValue().ast,r=a.nodeSymbol(e).getValue();return r===t?n.create(void 0):_v(a,r,o)}if(!Wf(o,r.Table))return n.create(e);let s=a.parseFile(o.filepath).getValue().ast,c=a.nodeSymbol(s).getValue();return c===t?n.create(void 0):D(o)&&o.parentNode instanceof B&&o.parentNode.op?.value===`~`?mv(a,c,o):Gf(o,1)?hv(a,c,o):qf(o,i.Ref)?gv(a,c,o):qf(o,i.Dep)?_v(a,c,o):Gf(o,0)?n.create(e):vv(a,c,o)},bindNode(i,a){if(!k(a,r.Table))return n.create(e);let o=new ev(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Hp?r.declaration instanceof R?new cv(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function mv(e,r,i){let a=N(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof zp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,F.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,F.TablePartial,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function hv(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return n.create(e.lookupMembers(t,F.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=Qf(r),o=e.lookupMembers(a,t?F.Enum:F.Schema,i);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,t?`Enum '${i}' does not exist in Schema 'public'`:`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function gv(e,i,a){if(!D(a))return new n(void 0);let o=lp(a)??``;if(!O(a.parentNode)){let s=a.parent,c=s instanceof R&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,F.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,F.Column,o);return l?n.create(l):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}return Vm(e,i,a,F.Column)}function _v(e,i,a){if(!D(a))return new n(void 0);let o=Wf(a,r.Table),s=lp(a)??``;if(!O(a.parentNode))if(o){let o=a.parent,c=o instanceof R&&o.isKind(r.Table)?e.nodeSymbol(o).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,F.Column,s);if(t)return n.create(t)}let l=e.lookupMembers(i,F.Column,s);return l?n.create(l):new n(void 0,[new w(C.BINDING_ERROR,`Column '${s}' does not exist in Table 'public.${c?.name??``}'`,a)])}else{let t=e.lookupMembers(i,F.Table,s);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${s}' does not exist in Schema 'public'`,a)])}return Vm(e,i,a,o?F.Column:F.Table)}function vv(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return go.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,F.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function yv(e){return e?e.split(``).every(e=>vf(e)||yf(e))&&!yf(e[0]):!1}function bv(e){return yv(e)?e:`"${Cv(e)}"`}function xv(...e){return e.map(bv).join(`.`)}function Sv(e){let t=``,n=0,r={n:`
11
+ `,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function Cv(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
12
+ `:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function wv(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return`'${Cv(e)}'`;let{value:t,type:n}=e;if(t==null||Mo(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(Mo(n)){let e=yp(t);return e===null?`\`${t}\``:e?`true`:`false`}if(jo(n)){let e=hp(t);return e===null?`\`${t}\``:String(e)}if(Fo(n)){let e=Tp(t);return e===null?`\`${t}\``:`'${Cv(e)}'`}let r=xp(t);return r===null?`\`${t}\``:`'${Cv(r)}'`}function Tv(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?Sv(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function Ev(e,t){let n=new Set,r=[];for(let i of t)for(let t of e.reachableFiles(i))n.has(t.intern())||(n.add(t.intern()),r.push(t));return r}function Dv(e){let r=[],i=[],a=[];e.bindProject();for(let n of e.parseProject().values()){i.push(...n.getErrors()),a.push(...n.getWarnings());let o=e.nodeSymbol(n.getValue().ast).getFiltered(t);if(!o)continue;let s=e.symbolMembers(o);i.push(...s.getErrors()),a.push(...s.getWarnings());for(let n of s.getFiltered(t)??[])if(r.push(n),n instanceof zp&&n.isKind(F.Schema)){let o=e.symbolMembers(n);i.push(...o.getErrors()),a.push(...o.getWarnings()),r.push(...o.getFiltered(t)??[])}}return new n(r,i,a)}function Ov(e){return e.includes(`
13
+ `)?`'''\n${e}\n'''`:`'${Cv(e)}'`}var kv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(zm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof im?[...r.getErrors(),new w(C.BINDING_ERROR,`TableGroup cannot reference imported table '${i.name}'`,n)]:r.getErrors()}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Av={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.Color]:{isValidBuiltinFieldValue:kf,message:`'color' must be a color literal`,assignBuiltinField(e,t){e.color=t}}},jv=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=P(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),sv(this.compiler,this.tableGroup,this.symbol,Av,this.filepath),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=kp(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new w(C.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]=_(e.body,e=>e instanceof H);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:Op(M(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:P(e)};break;default:break}return[]})}interpretFields(e){let n=[];return this.tableGroup.tables=e.map(e=>{let r=e.callee?this.compiler.nodeReferee(e.callee).getFiltered(t):void 0;if(r?.isKind(F.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=j(e.callee);return i.length>2&&n.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=T(e).getValue();this.tableGroup.color=t.color?.length?Ap(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Op(M(n?.value)),token:P(n)},this.tableGroup.metadata=Np(t,Object.keys(Av)),[]}},Mv={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new w(C.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Nv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return k(a,r.TableGroup)?new n(i.symbolFactory.create(Wp,{declaration:a,name:s},a.filepath)):A(a,r.TableGroup)?new n(i.symbolFactory.create(Gp,{declaration:a,name:o?.map(bv).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(F.TableGroup)){let e=i.declaration;if(!(e instanceof R))return new n([]);let a=rp(e),o=[],s=[];for(let e of a){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(o.push(i),s.push(...n.getErrors()))}let c=new Map;for(let e of o){if(!e.isKind(F.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Mv.getFieldDuplicateError(e.name,r)),s.push(Mv.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(F.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!D(a)||!Wf(a,r.TableGroup)||a.parent&&Kf(a))return n.create(e);let o=i.parseFile(a.filepath).getValue().ast,s=i.nodeSymbol(o).getValue();return s===t?n.create(void 0):Pv(i,s,a)},bindNode(i,a){if(!k(a,r.TableGroup))return n.create(e);let o=new kv(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,i,a){let o=i.declaration;return!k(o,r.TableGroup)||!(i instanceof Wp)?n.create(e):Rm(t,o)?new jv(t,i,a).interpret():n.create(void 0)}};function Pv(e,r,i){let a=lp(i)??``;if(!O(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof zp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,F.Table,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Bm(e,i);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,F.Schema,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var Fv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof H);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(g(n)instanceof W){let e=T(g(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=ap(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return zm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];if(n){let r=[],i=e.variables;for(let e of i)r.push(...this.compiler.nodeReferee(e).getErrors());let a=this.compiler.nodeReferee(n);return r.push(...a.getErrors()),a.getValue()&&r.push(...this.compiler.nodeReferee(t).getErrors()),r}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Iv=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=this.symbol?.token??P(this.declarationNode),this.symbol?this.tablePartial.name=this.symbol.interpretedName(this.compiler,this.filepath).name:this.interpretName(this.declarationNode.name);let e=[...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.tablePartial.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),pk:!0,token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath}}),this.pkColumns.forEach(e=>{e.pk=!1})),new n(this.tablePartial,e)}interpretName(e){let{name:t}=kp(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=T(e).getValue(),n=va(t[i.HeaderColor]);this.tablePartial.headerColor=n?Ap(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Op(M(r?.value)),token:P(r)},[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof H);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:Op(M(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:P(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let n=[],r={},a=this.compiler.nodeSymbol(e).getFiltered(t);r.name=lp(e.callee)??``,r.token=P(e);let o=Mp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||void 0,r.unique=a?.isUniqueSet(this.compiler)||void 0,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{};r.metadata=Np(s,lv);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!(n instanceof Eh))return[];let r=n.owners(this.compiler);if(l&&r.length>0&&!r.some(e=>e===l))return[];let i=n.op(this.compiler);if(!i)return[];let a=n.rightTable(this.compiler),o=n.rightColumns(this.compiler);if(!a||o.length===0)return[];let s=a.interpretedName(this.compiler,this.filepath);return{schemaName:s.schema,tableName:s.name,fieldNames:o.map(e=>e.name??``),relation:i,token:P(n.rightToken())}}),r.inline_deps=[],r.checks=(s[i.Check]||[]).map(e=>({token:P(e),expression:e.value.value.value})),this.tablePartial.fields?.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.indexes?.push(...i):i&&this.tablePartial.indexes?.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.checks?.push(...i):i&&this.tablePartial.checks?.push(i),r.getErrors()}},Lv={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},Rv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.TablePartial)?new n(i.symbolFactory.create(Jp,{declaration:a,name:o},a.filepath)):A(a,r.TablePartial)?new n(i.symbolFactory.create(Up,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(F.TablePartial)){let e=a.declaration;if(!(e instanceof R))return new n([]);let r=rp(e),o=[],s=[];for(let e of r){let n=i.nodeSymbol(e),r=n.getFiltered(t);r&&(o.push(r),s.push(...n.getErrors()))}let c=new Map;for(let e of o){if(!e.isKind(F.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(fv.getColumnDuplicateError(t,r)),s.push(fv.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(F.Column)&&k(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!D(o)&&!O(o)||!Wf(o,r.TablePartial))return n.create(e);let s=a.parseFile(o.filepath).getValue().ast,c=a.nodeSymbol(s).getValue();return c===t?n.create(void 0):Gf(o,1)?zv(a,c,o):qf(o,i.Ref)?Bv(a,c,o):Vv(a,c,o)},bindNode(i,a){if(!k(a,r.TablePartial))return n.create(e);let o=new Fv(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Jp?r.declaration instanceof R?new Iv(t,r,i).interpret():n.create(void 0):n.create(e)}};function zv(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return n.create(e.lookupMembers(t,F.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Bv(e,i,a){if(!D(a))return new n(void 0);let o=lp(a)??``;if(!O(a.parentNode)){let s=a.parent;if(s instanceof R&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,F.Column,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,F.Column,o);return c?n.create(c):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Bm(e,a);if(s){if(s.isKind(F.Schema)){let t=e.lookupMembers(s,[F.Table,F.Schema],o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(F.Table)){let t=e.lookupMembers(s,F.Column,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${s.name}'`,a)])}return new n(void 0)}let c=a.parentNode;if(c.leftExpression===a){if(O(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,F.Schema,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,F.Table,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function Vv(e,t,r){if(!D(r))return new n(void 0);let i=lp(r)??``;if(!O(r.parentNode))return go.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,F.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var Hv={symbolMembers(r,i){if(!i.isKind(F.Schema)||!(i instanceof zp))return n.create(e);let a=i.qualifiedName,o=r.usableMembers(i).getFiltered(t);if(!o)return n.create([]);let s=[...o.nonSchemaMembers],c=new Map(o.schemaMembers.map(e=>[e.name,e])),l=[];for(let e of o.reuses.selective){let n=Wv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...Gv(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...qv(r,i,e,t,c));for(let e of o.uses.selective){let n=Wv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...Gv(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...qv(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(F.TableGroup));if(!i.isPublicSchema()){let n=r.usableMembers(i.filepath).getFiltered(t)?.schemaMembers.find(e=>e.isPublicSchema());if(n){let i=r.symbolMembers(n).getFiltered(t);i&&e.push(...i.filter(e=>e.isKind(F.TableGroup)))}}for(let t of e)u.push(...Yv(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof im&&e.isKind(F.Schema))return!1;let t=`${e.originalSymbol.intern()}:${e.name??``}`;return d.has(t)?!1:(d.add(t),!0)}),p=r.parsedFileKind(i.filepath)===`arch`,m=e=>p&&e.isKind(F.StickyNote)?F.Element:e.kind,h=new Map;for(let e of f){let t=`${m(e)}:${e.name}`;if(h.get(t)){if(e.isKind(F.Schema))continue;let t=m(e),n=e instanceof im?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof R&&e.declaration.name&&t!==F.Element?e.declaration.name:e.declaration;n&&e.name!==void 0&&l.push(Uv(t,e.name,a.join(`.`),n))}else h.set(t,e)}return new n(f,l)}};function Uv(e,t,n,r){switch(e){case F.Table:return fv.getDuplicateError(t,n,r);case F.Enum:return ng.getDuplicateError(t,n,r);case F.TablePartial:return Lv.getDuplicateError(t,n,r);case F.TableGroup:return Mv.getDuplicateError(t,n,r);case F.DiagramView:return Jh.getDuplicateError(t,n,r);case F.Element:return new w(C.DUPLICATE_NAME,`${t} is already declared`,r);default:return new w(C.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function Wv(e,r,i,a){let o=K_(e,r,i);if(o.kind===`none`)return n.create(void 0);if(o.kind===`direct`){let r=e.nodeSymbol(i);return r.hasValue(t)?n.create(void 0):r}return a.has(o.schemaName)||a.set(o.schemaName,e.symbolFactory.create(zp,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function Gv(e,n,r,i=new Set){if(r.getSymbolKind()!==F.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(F.Schema))return[];let o=H_.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:Kv(e,n,r,a,i)}function Kv(e,n,r,i,a){let o=i.intern();if(a.has(o))return[];a.add(o);let s=e.usableMembers(i).getFiltered(t);if(!s)return[];let c=s.nonSchemaMembers.filter(e=>e.canBeImported).map(t=>e.symbolFactory.create(im,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(F.TableGroup)&&c.push(...Yv(e,n,t));for(let i of s.reuses.selective)if(c.push(...Gv(e,n,i,a)),K_(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(im,{kind:a.kind,declaration:a.originalSymbol.declaration,usedSymbol:a.originalSymbol,useSpecifierDeclaration:r,name:a.name},n.filepath))}for(let{importPath:t}of s.reuses.wildcard){let i=Jv(e,t,n.qualifiedName);i&&c.push(...Kv(e,n,r,i,a))}return c}function qv(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=Jv(e,r,n.qualifiedName);if(!s)return[];let c=e.usableMembers(s).getFiltered(t);if(!c)return[];let l=c.nonSchemaMembers.filter(e=>e.canBeImported).map(t=>e.symbolFactory.create(im,{kind:t.kind,declaration:t.declaration,usedSymbol:t,useSpecifierDeclaration:i,name:t.name},n.filepath));for(let t of c.schemaMembers)a.has(t.name)||a.set(t.name,e.symbolFactory.create(zp,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=Wv(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...Gv(e,n,r))}for(let{importPath:t}of d)l.push(...qv(e,n,t,i,a,o));return l}function Jv(e,n,r){if(r.length===0)return;let i=e.usableMembers(n).getFiltered(t);if(!i)return;let{schemaMembers:a}=i,o,s=[...r];for(;s.length>0;){let t=s.shift();if(o=a.find(e=>e.name===t),!o)return;let n=e.usableMembers(o).getValue();({schemaMembers:a}=n)}return o}function Yv(e,n,r){if(!r.isKind(F.TableGroup)||!(r instanceof im))return[];let i=r.originalSymbol,a=e.symbolMembers(i).getFiltered(t);if(!a)return[];let o=n.qualifiedName,s=[];for(let t of a){if(!t.isKind(F.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=j(n);if(!i||i.length===0)continue;let a=i.length<=1?[y]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=Xv(e,c,i);l&&s.push(e.symbolFactory.create(im,{kind:F.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function Xv(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(F.Table)&&e.name===r[0]):void 0}let i=r[0],a=r[r.length-1],o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.schemaMembers.find(e=>e.name===i);if(!s)return;let c=e.usableMembers(s).getFiltered(t);if(c)return c.nonSchemaMembers.find(e=>e.isKind(F.Table)&&e.name===a)}var Zv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof H)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Qv={[i.Color]:{isValidBuiltinFieldValue:Af,message:`'color' must be a color literal or 'none'`,assignBuiltinField(e,t){e.color=t}}},$v=[`link`,`ref`],ey=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){this.note.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return sv(this.compiler,this.note,this.symbol,Qv,this.filepath),n.create(this.note,e)}interpretName(){let{name:e}=this.symbol.interpretedName(this.compiler,this.filepath);return this.note.name=e,[]}interpretSettingList(e){let t=T(e).getValue();t.color?.length&&(this.note.color=Ap(t.color.at(0)?.value));let n=this.compiler.parsedFileKind(this.declarationNode.filepath)===`arch`,r=[...Object.keys(Qv),...n?$v:[]];return this.note.metadata=Np(t,r),[]}interpretBody(e){if(!e)return this.note.content=``,[];let[t,n]=_(e.body,e=>e instanceof H);return t.length!==1||n.length>0?[new w(C.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=M(e.callee)??``;return this.note.content=Op(t),[]}},ty={nodeSymbol(i,a){return!k(a,r.Note)||!(a.parentNode instanceof L)?n.create(e):new n(i.symbolFactory.create(qp,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(F.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return k(i,r.Note)?n.create(void 0,new Zv(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof qp?r.declaration instanceof R?new ey(t,r,i).interpret():n.create(void 0):n.create(e)}},ny=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[...this.bindTargetElement(this.declarationNode.name),...this.bindBody(this.declarationNode.body)]}bindTargetElement(e){let t=tv(this.declarationNode);return!j(e)?.length||!t||av(this.compiler,this.declarationNode)?[]:[new w(C.BINDING_ERROR,`cannot find metadata target element`,e??this.declarationNode)]}bindBody(e){return e instanceof U?e.body.filter(e=>e instanceof R).flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[]):[]}},ry=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.filepath=n,this.values={}}interpret(){let e=this.interpretValues(this.declarationNode.body);return new n(this.values,e)}interpretValues(e){if(!(e instanceof U))return[];for(let t of e.body){if(!(t instanceof R))continue;let e=t.type?.value;if(!e)continue;let n=Pp(t.body instanceof H?t.body.callee:void 0);n&&(this.values[e]={value:e===`note`?Op(n):n,token:P(t)})}return[]}},iy={nodeMetadata(t,i){return k(i,r.Metadata)?new n(new Ah(i)):new n(e)},nodeReferee(t,i){if(!D(i))return new n(e);let a=i.parentOfKind(R);return!a||!k(a,r.Metadata)||!a.name?.containsEq(i)?new n(e):!j(a.name)||!tv(a)?new n(void 0):new n(av(t,a))},bindNode(t,i){return k(i,r.Metadata)?new n(void 0,new ny(t,i).bind()):new n(e)},interpretMetadata(t,i,a){return i instanceof Ah?k(i.declaration,r.Metadata)?new ry(t,i,a).interpret():new n(void 0):new n(e)}},ay=`server.function.container.database.cache.queue.disk.bucket.balancer.proxy.lock.key.gateway.globe.cloud.firewall.shield.router.switch.pipeline.chip.box.person.users.browser.mobile.laptop.desktop.terminal.mail.pulse.chart.clock.bell.search.settings.file.folder.tag.warning.check.rocket.webhook.stream.graph.robot.azure.windows.haproxy`.split(`.`),oy=`aws.gcp.digitalocean.hetzner.vultr.alibabacloud.oracle.heroku.railway.fly.render.postgres.mysql.mariadb.mongodb.sqlite.cockroachdb.cassandra.dynamodb.neo4j.influxdb.clickhouse.couchbase.planetscale.supabase.firebase.duckdb.rds.spanner.redis.kafka.rabbitmq.nats.sqs.celery.pubsub.elastic.opensearch.algolia.meilisearch.solr.snowflake.bigquery.redshift.databricks.hive.s3.minio.gcs.ceph.nginx.envoy.traefik.caddy.cloudflare.kong.fastly.akamai.docker.podman.kubernetes.openshift.containerd.nomad.consul.istio.lambda.workers.vercel.netlify.linux.ubuntu.debian.redhat.alpine.apple.apache.jfrog.harbor.grafana.prometheus.datadog.newrelic.sentry.opentelemetry.splunk.fluentd.logstash.pagerduty.opsgenie.slack.discord.jenkins.githubactions.gitlab.github.circleci.argo.airflow.dbt.airbyte.travisci.teamcity.buildkite.temporal.prefect.terraform.vault.onepassword.hashicorp.tailscale.wireguard.openvpn.zerotier.pfsense.chrome.firefox.safari.brave.android.ios.flutter.nodejs.python.golang.java.rust.ruby.php.dotnet.elixir.deno.bun.springboot.stripe`.split(`.`),sy=[...ay,...oy],cy={k8s:`kubernetes`,k9s:`kubernetes`,k8sio:`kubernetes`,postgresql:`postgres`,pg:`postgres`,psql:`postgres`,mongo:`mongodb`,node:`nodejs`,go:`golang`,elasticsearch:`elastic`,es:`elastic`,mq:`rabbitmq`,amqp:`rabbitmq`,tf:`terraform`,otel:`opentelemetry`,gha:`githubactions`,"1password":`onepassword`,do:`digitalocean`,google:`gcp`,gcloud:`gcp`,amazon:`aws`,ec2:`aws`,cdn:`globe`,internet:`cloud`,user:`person`,team:`users`,vpn:`lock`,monitor:`pulse`,metrics:`chart`,log:`file`,ci:`pipeline`,cron:`clock`,ai:`chip`,ml:`chip`},ly=e=>cy[e]??e,uy=new Set(sy),dy=e=>uy.has(ly(e)),fy={Server:{icon:`server`,category:`compute`},Function:{icon:`function`,category:`compute`},Container:{icon:`container`,category:`compute`},Service:{icon:`chip`,category:`compute`},Registry:{icon:`container`,category:`compute`},Database:{icon:`database`,category:`data`},Cache:{icon:`cache`,category:`data`},Queue:{icon:`queue`,category:`data`},Topic:{icon:`stream`,category:`data`},Storage:{icon:`disk`,category:`data`},Bucket:{icon:`bucket`,category:`data`},Warehouse:{icon:`graph`,category:`data`},Search:{icon:`search`,category:`data`},LoadBalancer:{icon:`balancer`,category:`net`},Proxy:{icon:`proxy`,category:`net`},VPN:{icon:`lock`,category:`net`},Gateway:{icon:`gateway`,category:`net`},Firewall:{icon:`firewall`,category:`net`},Router:{icon:`router`,category:`net`},Secret:{icon:`key`,category:`net`},CDN:{icon:`globe`,category:`edge`},Internet:{icon:`cloud`,category:`edge`},Client:{icon:`person`,category:`people`},Browser:{icon:`browser`,category:`people`},Mobile:{icon:`mobile`,category:`people`},Team:{icon:`users`,category:`people`},Monitoring:{icon:`pulse`,category:`ops`},Logging:{icon:`file`,category:`ops`},Alerting:{icon:`bell`,category:`ops`},Scheduler:{icon:`clock`,category:`ops`},Pipeline:{icon:`pipeline`,category:`ops`}},py=new Map(Object.keys(fy).map(e=>[e.toLowerCase(),e])),my=e=>py.get(e.toLowerCase()),hy="Custom roles are not supported. Use a built-in role; `type` sets the mark (a mark name or an image URL) and `color` the colour.";function gy(e){let t=e.toLowerCase();if(dy(t))return`${e} is a brand, and a brand is a setting: Database name [type: '${t}']`;let n=Object.keys(fy).filter(e=>{let n=e.toLowerCase();return n.startsWith(t)||t.startsWith(n)||n.includes(t)?!0:_y(n,t,2)}).slice(0,6);return n.length?`Did you mean: ${n.join(`, `)}?`:`The roles are: ${Object.keys(fy).join(`, `)}.`}function _y(e,t,n){if(Math.abs(e.length-t.length)>n)return!1;let r=Array.from({length:t.length+1},(e,t)=>t);for(let i=1;i<=e.length;i+=1){let a=[i],o=i;for(let n=1;n<=t.length;n+=1)a[n]=e[i-1]===t[n-1]?r[n-1]:1+Math.min(r[n-1],r[n],a[n-1]),o=Math.min(o,a[n]);if(o>n)return!1;r=a}return r[t.length]<=n}function vy(e){let t=e.toLowerCase(),n=[...sy,...Object.keys(cy)].filter(e=>e.startsWith(t)||t.startsWith(e)||e.includes(t)).slice(0,6);return n.length?`Did you mean: ${n.join(`, `)}?`:`The pack has ${sy.length} marks; any other picture can be given as an image URL.`}function yy(e,t,n,r,i){let a=[],o=Um(e,n);if(!o)return a;let s=ov(e,n),c=e.symbolMetadata(t).filter(t=>t instanceof Mh&&t.owners(e).includes(o)).sort((e,t)=>{let n=s.get(e.declaration.filepath.intern())??-1,r=s.get(t.declaration.filepath.intern())??-1;return n===r?e.declaration.start-t.declaration.start:n-r});for(let e of c){Object.assign(r,Ty(e).getValue());let t=e.declaration.name?e.declaration.targetKind?.value:void 0;i&&t&&i.toLowerCase()!==t.toLowerCase()&&a.push(new gf(C.METADATA_ROLE_MISMATCH,`${Xm(e.declaration.name)} is a ${i}, not a ${t}`,e.declaration))}return a}function by(e){let t=mh(e);if(!t)return null;let n=hh(t);return n?{value:n,token:P(t)}:null}function xy(e,r,i){let a=r.declaration;if(!(a instanceof R))return new n(void 0);let o=qm(a),s=Xm(a.name)??``,c=P(a),l=Xm(a.alias)??null,u=nh(a.attributeList);if(yh(a,u,o===`node`),o===`group`){let o=[];for(let n of rh(a))if(n instanceof H)for(let r of[n.callee,...n.args]){if(!D(r))continue;let n=e.nodeReferee(r).getFiltered(t),a=n&&xh(e,n,i);a!==void 0&&!o.includes(a)&&o.push(a)}let d=yy(e,r,i,u);return new n({name:s,alias:l,children:o,settings:u,note:by(a),token:c},[],d)}let{type:d,image:f}=Sy(u.type),p=Cy(u.type,a),m=Gm(a),h=my(m)??m;return p.push(...yy(e,r,i,u,h)),new n({name:s,alias:l,role:h,type:d,image:f,settings:u,note:by(a),token:c},[],p)}function Sy(e){let t=typeof e==`string`?e.trim():``;return t?_h.test(t)?{type:null,image:t}:{type:dy(t)?ly(t):null,image:null}:{type:null,image:null}}function Cy(e,t){let n=typeof e==`string`?e.trim():``;return!n||_h.test(n)||dy(n)?[]:/^[a-z]+:/i.test(n)?[new gf(C.BAD_IMAGE,`${vh} Got: ${n}`,t)]:[new gf(C.UNKNOWN_TYPE,`There is no type called ${n}. ${vy(n)}`,t)]}function wy(e,t,r){let{declaration:i}=t,a=t.op(),[o,s]=t.endpoints(e),c=o&&xh(e,o,r),l=s&&xh(e,s,r);return!a||c===void 0||l===void 0?new n(void 0):new n({from:c,to:l,op:a,settings:i instanceof R?nh(ch(i)?.row?.settings??i.attributeList):{},token:P(i)})}function Ty(e){let t={},r=new Set;for(let n of rh(e.declaration)){let e=n instanceof R?fh(n):void 0;!e||e.value===void 0||r.has(e.key)||(r.add(e.key),t[e.key]=e.value)}return new n(t)}function Ey(e,t){let n=e.parentNode;return!(n instanceof H)||!(t.body instanceof U)||n.parentNode!==t.body?!1:n.callee===e||n.args.includes(e)}function Dy(e,t){let n=ch(t);return!!n&&(oh(n.infix.left)===e||oh(n.infix.right)===e)}var Oy=e=>[`node`,`group`].includes(qm(e)??``)||Jm(e),ky=(e,t,n)=>bh(e,t.filepath,F.Element,n)??bh(e,t.filepath,F.StickyNote,n);function Ay(e,t){return uh(t).some(t=>dh(t)?.target===e)}var jy=(e,t,n)=>new w(e,`${t} is not declared anywhere`,n);function My(e,t,n,r){if(bh(e,t.filepath,F.Table,n))return new w(C.BINDING_ERROR,`${n} is a table; ${r}`,t)}function Ny(e,t,r,i){let a=ky(e,t,r);return a?new n(a):new n(void 0,[My(e,t,r,`a link joins elements`)??jy(C.UNKNOWN_ENDPOINT,r,i)])}function Py(e,t,r){let i=Xm(t);if(i===void 0)return new n(void 0);if(Oy(r)&&Ay(t,r))return Ny(e,t,i,t);switch(qm(r)){case`group`:{if(!Ey(t,r))return new n(void 0);let a=ky(e,t,i),o=a?void 0:My(e,t,i,`a group lists elements and groups`);return new n(a,o?[o]:[])}case`link`:return Dy(t,r)?Ny(e,t,i,r):new n(void 0);case`metadata`:{if(!r.name?.containsEq(t))return new n(void 0);let a=bh(e,t.filepath,F.Element,i);return a?new n(a):new n(void 0,[jy(C.UNKNOWN_METADATA_TARGET,i,r)])}default:return new n(void 0)}}function Fy(e,t){let r=[],i=Gm(t);if(Oy(t))for(let n of uh(t)){let t=dh(n)?.target;t&&D(t)&&r.push(...e.nodeReferee(t).getErrors())}switch(qm(t)){case`node`:Xm(t.name)!==void 0&&!my(i)&&r.push(new w(C.UNKNOWN_ROLE,`${i} is not a role. ${gy(i)}`,t));break;case`group`:for(let n of rh(t))if(n instanceof H)for(let t of[n.callee,...n.args])D(t)&&r.push(...e.nodeReferee(t).getErrors());break;case`link`:{let n=ch(t);if(!n)break;for(let t of[n.infix.left,n.infix.right]){let n=oh(t);D(n)&&r.push(...e.nodeReferee(n).getErrors())}break}case`metadata`:if(D(t.name)&&r.push(...e.nodeReferee(t.name).getErrors()),!new Mh(t).target(e)&&!r.length){let e=Xm(t.name)??t.targetKind?.value??`that`;r.push(jy(C.UNKNOWN_METADATA_TARGET,e,t))}break;default:break}return new n(void 0,r)}function Iy(e,r){if(!r.name)return new n(void 0);let i=e.nodeReferee(r.name),a=[...i.getErrors()],o=i.getFiltered(t)?.originalSymbol,s=r.importKind?.value,c=o?.declaration;if(s&&o?.isKind(F.Element)&&c instanceof R){let e=Gm(c),t=qm(c)===`node`?my(e)??e:e;t.toLowerCase()!==s.toLowerCase()&&a.push(new w(C.BINDING_ERROR,`${Zm(c)} is a ${t}, not a ${s}`,r.importKind))}return new n(void 0,a)}var Ly={nodeSymbol(t,r){if(!Km(r))return n.create(e);switch(qm(r)){case`node`:case`group`:return new n(t.symbolFactory.create(Kp,{declaration:r,name:Zm(r)},r.filepath));default:return n.create(e)}},symbolMembers(t,r){return r instanceof Kp?new n([]):n.create(e)},nodeReferee(t,r){if(!D(r)||r.parentOfKind(hm))return n.create(e);let i=Ym(r);return i?Py(t,r,i):n.create(e)},bindNode(t,r){return r instanceof hm&&r.archImport?Iy(t,r):Km(r)?Fy(t,r):n.create(e)},nodeMetadata(t,r){if(r instanceof z){let t=r.parentOfKind(R);return!t||!Km(t)||!Oy(t)||!lh(r)?n.create(e):new n(new jh(r))}if(!Km(r))return n.create(e);switch(qm(r)){case`link`:return new n(new jh(r));case`metadata`:return new n(new Mh(r));default:return n.create(e)}},interpretSymbol(t,r,i){return r instanceof Kp?xy(t,r,i):n.create(e)},interpretMetadata(t,r,i){return r instanceof jh?wy(t,r,i):r instanceof Mh?Ty(r):n.create(e)}},Ry=[U_,pv,rg,j_,og,zh,B_,Uh,w_,Nv,Rv,ty,iy,Hv,Yh,x_],zy=[Ly,U_,ty,Hv,x_];function By(e,t){if(e.explicitModules)return e.explicitModules;let n=t.filepath??t.declaration?.filepath;return n&&e.parsedFileKind(n)===`arch`?zy:Ry}function Vy(t,r,...i){for(let a of By(t,i[1])){let t=a[r];if(t){let r=t(...i);if(r instanceof n&&!r.hasValue(e))return r}}return n.create(e)}function Hy(r){let i=Vy(this,`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Uy(r){let i=Vy(this,`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Wy(r){let i=Vy(this,`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Gy(r){let i=Vy(this,`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function Ky(r){let i=Vy(this,`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function qy(r,i){let a=Vy(this,`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function Jy(r,i){let a=Vy(this,`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var Yy=class{constructor(e,t,n={}){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t,this.options=n}scanFrontMatter(){if(!this.options.allowFrontMatter||!this.text.startsWith(`---`))return;let e=this.text[3];if(e!==`
14
14
  `&&e!==`\r`)return;let t=this.text.indexOf(`
15
15
  ---`,3);if(t===-1)return;let n=this.text.indexOf(`
16
16
  `,t+1);for(n===-1&&(n=this.text.length);this.current.offset<n;)this.advance();this.addToken(v.FRONT_MATTER)}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
17
17
  `?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,e}peek(e=0){if(!(this.current.offset+e>=this.text.length))return this.text[this.current.offset+e]}check(e){for(let t=0;t<e.length;t+=1)if(e[t]!==this.peek(t))return!1;return!0}match(e){return this.check(e)?(e.split(``).forEach(()=>this.advance()),!0):!1}addToken(e,t=!1){this.tokens.push(this.createToken(e,t))}createToken(e,t=!1){return Va.create(e,this.filepath,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),t)}lex(){return this.scanTokens(),this.tokens.push(Va.create(v.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new n(this.tokens,this.errors)}scanTokens(){for(this.scanFrontMatter();!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(v.SPACE);break;case`\r`:break;case`
18
- `:this.addToken(v.NEWLINE);break;case` `:this.addToken(v.TAB);break;case`,`:this.addToken(v.COMMA);break;case`(`:this.addToken(v.LPAREN);break;case`)`:this.addToken(v.RPAREN);break;case`[`:this.addToken(v.LBRACKET);break;case`]`:this.addToken(v.RBRACKET);break;case`{`:this.addToken(v.LBRACE);break;case`}`:this.addToken(v.RBRACE);break;case`;`:this.addToken(v.SEMICOLON);break;case`:`:this.addToken(v.COLON);break;case`'`:this.match(`''`)?this.multilineStringLiteral():this.singleLineStringLiteral();break;case`"`:this.quotedVariable();break;case"`":this.functionExpression();break;case`#`:this.colorLiteral();break;case`/`:this.match(`/`)?this.singleLineComment():this.match(`*`)?this.multilineComment():this.operator(e);break;case`*`:this.addToken(v.WILDCARD);break;default:if(za(e)){this.operator(e);break}if(vf(e)){this.identifier();break}if(yf(e)){this.numericLiteralOrIdentifier();break}this.addToken(v.OP,!0),this.errors.push(new w(C.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(v.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)Ra(i)?(t.push(i),i.kind===v.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&&fm(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];fm(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(`
18
+ `:this.addToken(v.NEWLINE);break;case` `:this.addToken(v.TAB);break;case`,`:this.addToken(v.COMMA);break;case`(`:this.addToken(v.LPAREN);break;case`)`:this.addToken(v.RPAREN);break;case`[`:this.addToken(v.LBRACKET);break;case`]`:this.addToken(v.RBRACKET);break;case`{`:this.addToken(v.LBRACE);break;case`}`:this.addToken(v.RBRACE);break;case`;`:this.addToken(v.SEMICOLON);break;case`:`:this.addToken(v.COLON);break;case`'`:this.match(`''`)?this.multilineStringLiteral():this.singleLineStringLiteral();break;case`"`:this.quotedVariable();break;case"`":this.functionExpression();break;case`#`:this.colorLiteral();break;case`/`:this.match(`/`)?this.singleLineComment():this.match(`*`)?this.multilineComment():this.operator(e);break;case`*`:this.addToken(v.WILDCARD);break;default:if(za(e)){this.operator(e);break}if(vf(e)){this.identifier();break}if(yf(e)){this.numericLiteralOrIdentifier();break}this.addToken(v.OP,!0),this.errors.push(new w(C.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(v.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)Ra(i)?(t.push(i),i.kind===v.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&&dm(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];dm(n)?r.trailingInvalid.push(n):(r=n,t.push(n))}this.tokens=t}consumeUntil(e,t,{allowNewline:n,allowEof:r,raw:i,consumeStopSequence:a=!0}){let o=``;for(;!this.isAtEnd()&&(n||!this.check(`
19
19
  `))&&!this.check(t);)this.peek()===`\\`&&!i?(this.advance(),o+=this.escapedString()):o+=this.advance();if(this.isAtEnd()&&!r){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new w(C.UNEXPECTED_EOF,`EOF reached while parsing`,t));return}if(this.check(`
20
20
  `)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new w(C.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(Va.create(e,this.filepath,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(v.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(v.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(v.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(v.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(v.SINGLE_LINE_COMMENT,`
21
21
  `,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(v.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&xf(this.peek());)this.advance();this.addToken(v.IDENTIFIER)}operator(e){switch(e){case`<`:this.peek()===`=`?this.advance():this.peek()===`>`?(this.advance(),this.peek()===`?`&&this.advance()):(this.peek()===`?`||this.peek()===`-`)&&this.advance();break;case`>`:(this.peek()===`=`||this.peek()===`?`)&&this.advance();break;case`-`:(this.peek()===`>`||this.peek()===`?`)&&this.advance();break;case`?`:this.peek()===`-`?(this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`<`?(this.advance(),this.peek()===`>`&&this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`>`&&(this.advance(),this.peek()===`?`&&this.advance());break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(v.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(v.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=+!!t,e>1)break;if(this.check(`e`)||this.check(`E`)){let e=this.peek(1),t=e===`+`||e===`-`,n=t?this.peek(2):e;if(n&&yf(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&yf(this.peek());)this.advance();if(this.isAtEnd()||!xf(this.peek()))return this.addToken(v.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1&&yf(this.peek()))return this.advance(),this.addToken(v.NUMERIC_LITERAL);if(!t&&!xf(this.peek()))return this.addToken(v.NUMERIC_LITERAL);if(!t&&!yf(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||xf(this.peek()));)this.advance();let e=this.createToken(v.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new w(C.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&xf(this.peek());)this.advance();let e=this.createToken(v.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&xf(this.peek());)this.advance();this.addToken(v.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(`
22
22
  `)&&this.advance(),``;case`
23
23
  `:return``;case`t`:return` `;case`n`:return`
24
- `;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()||!xf(this.peek()))return this.errors.push(new w(C.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`,Va.create(v.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},rb=new Set([`arch`,`architecture`]),ib=e=>!!e&&rb.has(e.toLowerCase());function ab(e){let t={};for(let n of e.split(`
25
- `)){let e=n.trim();if(!e||e===`---`)continue;let r=e.indexOf(`:`);if(r<=0)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim().replace(/^['"]|['"]$/g,``);i&&(t[i]=a)}return t}function ob(e){return e[0]?.leadingTrivia.find(e=>e.kind===v.FRONT_MATTER)}var sb=new Set([v.LBRACE,v.LBRACKET,v.LPAREN]),cb=new Set([v.RBRACE,v.RBRACKET,v.RPAREN]);function lb(e){let t=ob(e),n={frontMatter:t?ab(t.value):{},topWords:[],kindNames:[],usePaths:[]},r=0,i=-1;for(let t=0;t<e.length;t+=1){let a=e[t];if(a.kind===v.EOF)break;let o=a.startPos.line>i;if(i=a.endPos.line,sb.has(a.kind)?r+=1:cb.has(a.kind)&&(r=Math.max(0,r-1)),r!==0||!o||a.kind!==v.IDENTIFIER)continue;let s=a.value.toLowerCase();if(n.topWords.push(s),s===`kind`){let r=e[t+1];(r?.kind===v.IDENTIFIER||r?.kind===v.QUOTED_STRING)&&n.kindNames.push(r.value.toLowerCase())}if(s===`use`||s===`reuse`){let r=0;for(let i=t+1;i<e.length;i+=1){let t=e[i];if(t.kind===v.EOF)break;if(sb.has(t.kind))r+=1;else if(cb.has(t.kind))--r;else if(r===0&&t.kind===v.IDENTIFIER&&t.value===`from`){let t=e[i+1];t?.kind===v.STRING_LITERAL&&n.usePaths.push(t.value);break}}}}return n}function ub(e,t){if(e.frontMatter.diagram_type!==void 0)return{kind:ib(e.frontMatter.diagram_type)?`arch`:`dbml`,dependsOnImports:!1};if(e.topWords.some(e=>e===`group`||e===`kind`||th(e)!==void 0))return{kind:`arch`,dependsOnImports:!1};if(e.usePaths.length===0)return{kind:`dbml`,dependsOnImports:!1};let n=new Set(t().flatMap(e=>e.kindNames));return{kind:e.topWords.some(e=>n.has(e))?`arch`:`dbml`,dependsOnImports:!0}}var db=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new w(C.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=_(e.body,e=>e instanceof V);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 g(n)instanceof U&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof xm))&&t.push(new w(C.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`name`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||n.push(new w(C.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},fb={validateNode(t,i){if(!k(i,r.Checks))return n.create(e);let a=new db(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return k(i,r.Checks)?i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Checks)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Checks)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},pb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Project,r.Dep)?[]:[new w(C.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project or a Dep`,this.declarationNode)]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return!(this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Dep))&&!E(e.callee)&&t.push(new w(C.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 w(C.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function mb(e){return e instanceof R&&!!e.type?.value}var hb={validateNode(t,r){if(!mb(r))return n.create(e);let i=new pb(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return mb(r)?r.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return mb(r)?r.alias?new n(void 0,[new w(C.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return mb(r)?r.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},gb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettings(),...this.validateBody(this.declarationNode.body)]}validateSettings(){let e=[];this.declarationNode.attributeList&&e.push(..._b(this.declarationNode.attributeList).getErrors());let t=this.declarationNode.body;if(t instanceof V){let n=t.args.find(e=>e instanceof U);n&&e.push(..._b(n).getErrors())}return e}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_DEP_CONTEXT,`A Dep must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Dm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Dep name`,e)]:wf(e)?[]:[new w(C.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.forEach(e=>{if(!e.callee){t.push(new w(C.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e));return}if(!(e.callee instanceof ym)){t.push(new w(C.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e.callee));return}let n=e.callee;n.op?.value!==`->`&&n.op?.value!==`<-`&&t.push(new w(C.INVALID_DEP_FIELD,`Dep edges must use the '->' or '<-' operator`,e.callee));let r=ap(n.leftExpression)??{variables:[],tupleElements:[]},i=ap(n.rightExpression)??{variables:[],tupleElements:[]};r.variables.length===0&&r.tupleElements.length===0&&t.push(new w(C.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.leftExpression||e.callee)),i.variables.length===0&&i.tupleElements.length===0&&t.push(new w(C.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.rightExpression||e.callee));let a=[...e.args];g(a)instanceof U?a.pop():a[0]instanceof U&&a.shift(),a.length>0&&t.push(...a.map(e=>new w(C.INVALID_DEP_FIELD,`A Dep field should only have a single binary relationship`,e)))}),t}validateSubElements(e){return e.flatMap(e=>{if(!e.type)return[];let t=e.type.value?.toLowerCase(),n=e.body;if(!t)return[];switch(t){case i.Color:return e.name||!(n instanceof V)||!n.callee||!kf(n.callee)?[new w(C.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,e)]:[];case i.Note:{let t;return n instanceof V?t=n.callee:n instanceof H&&n.body[0]instanceof V&&(t=n.body[0].callee),!t||!E(t)?[new w(C.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,e)]:[]}default:return e.name||n instanceof H?[new w(C.INVALID_SETTINGS,`'${t}' must be a simple field (e.g. ${t}: value). Block syntax is not allowed`,e)]:!(n instanceof V)||!n.callee?[]:!E(n.callee)&&!kf(n.callee)&&!Mf(n.callee)&&!wf(n.callee)?[new w(C.INVALID_SETTINGS,`Invalid value for '${t}'. Expected a string, number, color, or identifier`,e)]:[]}})}};function _b(e){let t=T(e),r=[...t.getErrors()],a=t.getValue();for(let[e,t]of Object.entries(a))for(let n of t)switch(e){case i.Color:kf(n.value)||r.push(new w(C.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,n));break;case i.Note:E(n.value)||r.push(new w(C.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,n));break;default:n.value&&!E(n.value)&&!kf(n.value)&&!Mf(n.value)&&!wf(n.value)&&r.push(new w(C.INVALID_SETTINGS,`Invalid value for setting '${e}'. Expected a string, number, color, or identifier`,n));break}return new n(a,r)}var vb={validateNode(t,i){return k(i,r.Dep)?n.create(void 0,new gb(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Dep)?i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,i.name)]):new n(void 0):A(i,r.Dep)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Dep)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Dep)?new n(void 0):n.create(e)},nodeSettings(t,i){if(k(i,r.Dep))return i.attributeList?_b(i.attributeList):new n({});if(A(i,r.Dep)){let e=[...i.args],t;return g(e)instanceof U?t=g(e):e[0]instanceof U&&(t=e[0]),t?_b(t):new n({})}return n.create(e)}},yb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList)],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?wf(e)?[]:[new w(C.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new w(C.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof V)return{errors:[new w(C.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=_(e.body,e=>e instanceof V),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Rf(e.callee)?e.args.length>0?e.args.map(e=>new w(C.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new w(C.INVALID_DIAGRAMVIEW_FIELD,`Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.`,e)])}validateSubElements(e){let t=[],n=[],r=[`tables`,`notes`,`tablegroups`,`schemas`];for(let i of e){if(!i.type)continue;let e=i.type.value.toLowerCase();if(!r.includes(e)){t.push(new w(C.INVALID_DIAGRAMVIEW_FIELD,`Unknown block type "${i.type.value}" in DiagramView. Allowed: Tables, Notes, TableGroups, Schemas`,i));continue}let a=this.validateSubBlock(i);t.push(...a.errors),n.push(...a.warnings)}return{errors:t,warnings:n}}validateSubBlock(e){let t=[],n=[];if(Tf(e))return t.push(new w(C.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof H))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof V&&Rf(e.callee)),a=r.body.some(e=>e instanceof V&&!Rf(e.callee));return i&&a&&n.push(new gf(C.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t.push(...this.validateSubBlockFields(e)),{errors:t,warnings:n}}validateSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof H))return t;let n=e.body.body.filter(e=>e instanceof V);for(let e of n)Rf(e.callee)||(e.args.length>0||!j(e.callee))&&t.push(...e.args.map(e=>new w(C.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},bb={validateNode(t,i){if(!k(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new yb(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(k(i,r.DiagramView)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=j(i.name);return e?new n(e):new n(void 0)}else if(A(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=j(i.callee);return e?(e.length===1&&A(i,r.DiagramViewTables)&&e.unshift(y),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return k(i,r.DiagramView)?new n(void 0):n.create(e)}},xb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Dm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Sf(e)?[]:[new w(C.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new w(C.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new w(C.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!D(n.callee)&&t.push(new w(C.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];g(e)instanceof U?(t.push(...this.validateFieldSettings(g(e))),e.pop()):e[0]instanceof U&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new w(C.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];if(t)switch(e){case i.Note:t.length>1&&t.forEach(e=>n.push(new w(C.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{E(e.value)||n.push(new w(C.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Sb={validateNode(t,i){return k(i,r.Enum)?n.create(void 0,new xb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.Enum)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Sf(i.name))return new n(void 0,[new w(C.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=j(i.name);return e?.length===1&&e.unshift(y),new n(e)}if(A(i,r.Enum)){let e=N(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return k(i,r.Enum)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(k(a,r.Enum))return a.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(A(a,r.Enum)){let e=[...a.args],t;if(g(e)instanceof U?t=g(e):e[0]instanceof U&&(t=e[0]),!t)return new n({});let r=T(t),o=r.getErrors(),s=r.getValue(),c={};for(let[e,t]of Object.entries(s))switch(e){case i.Note:t.length>1&&t.forEach(e=>o.push(new w(C.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{E(e.value)||o.push(new w(C.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new w(C.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Cb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new w(C.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return[new w(C.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=_(e.body,e=>e instanceof V);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 g(n)instanceof U&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof Tm;)e.argumentList&&op(e.argumentList)===void 0&&t.push(new w(C.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;op(e)===void 0&&t.push(new w(C.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=T(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`note`:case`name`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{D(e.value)||n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},wb={validateNode(t,i){return k(i,r.Indexes)?n.create(void 0,new Cb(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Indexes)?i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):A(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Indexes)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(k(a,r.Indexes))return a.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(A(a,r.Indexes)){let e=[a.callee,...a.args],t;if(g(e)instanceof U&&(t=g(e)),!t)return new n({});let r=T(t),o=r.getErrors(),s=r.getValue(),c={};for(let[e,t]of Object.entries(s))switch(e){case i.Note:case i.Name:t.length>1&&t.forEach(t=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))}),c[e]=t;break;case i.Unique:case i.PK:t.length>1&&t.forEach(t=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))}),c[e]=t;break;case i.Type:t.length>1&&t.forEach(e=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{D(e.value)||o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new w(C.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Tb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return!(e instanceof L)&&!(e instanceof R&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project,r.Dep))?[new w(C.INVALID_NOTE_CONTEXT,`A Note can only appear inside a Table, a TableGroup, a TablePartial or a Project. Sticky note can only appear at the global scope.`,this.declarationNode)]:[]}validateName(e){return this.compiler.nodeFullname(this.declarationNode).getErrors()}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof L}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new w(C.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=T(e),n=t.getErrors(),r=t.getValue(),a=this.compiler.parsedFileKind(this.declarationNode.filepath)===`arch`;return Sa(r,(e,t)=>{if(!(a&&vh(t)))switch(t){case i.Color:{let t=Ey[i.Color];e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{t.isValidBuiltinFieldValue(e.value)||n.push(new w(C.INVALID_NOTE_SETTING_VALUE,t.message,e.value||e.name))});break}default:n.push(...E_(t,e,{duplicate:C.DUPLICATE_NOTE_SETTING,invalidValue:C.INVALID_NOTE_SETTING_VALUE}))}}),n}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new w(C.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new w(C.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),E(e[0].callee)||t.push(new w(C.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 w(C.INVALID_NOTE,`A Note can only contain one quoted string`,e))),t)}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Eb={validateNode(t,i){return k(i,r.Note)?n.create(void 0,new Tb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!k(i,r.Note))return n.create(e);if(!(i.parent instanceof L))return i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new w(C.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof Dm)return new n(void 0,[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=j(i.name);return a===void 0?new n(void 0,[new w(C.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return k(i,r.Note)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Note)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},Db={[Ip.Table]:Rv,[Ip.Column]:zv,[Ip.TableGroup]:iy,[Ip.Note]:Ey},Ob=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateTargetKind(),...this.validateTargetName(this.declarationNode.name),...this.validateBody(this.declarationNode.body)]}validateTargetKind(){return T_(this.declarationNode)?[]:[new w(C.INVALID_METADATA_TARGET_KIND,`A Metadata target kind must be one of: ${Object.values(Ip).join(`, `)}`,this.declarationNode.targetKind??this.declarationNode)]}validateTargetName(e){return e?e instanceof Dm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Metadata target's name`,e)]:Sf(e)?[]:[new w(C.INVALID_NAME,`A Metadata target's name must be of the form <schema>.<table>, <table>.<column>, <schema>.<table>.<column> or a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A Metadata target must have a name`,this.declarationNode)]}validateBody(e){if(!e)return[];if(e instanceof V)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Metadata's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.map(e=>new w(C.INVALID_METADATA_FIELD,`A Metadata field must use the 'key: value' syntax`,e))}validateSubElements(e){let t={},n=T_(this.declarationNode),r=e.flatMap(e=>{if(!e.type)return[];if(e.body instanceof H)return[new w(C.UNEXPECTED_COMPLEX_BODY,`A Metadata field can only have an inline value`,e.body)];let r=e.type.value.toLowerCase();t[r]||(t[r]=[]),t[r].push(e);let i=n?Db[n][r]:void 0;return i?i.isValidBuiltinFieldValue(e.body?.callee)?[]:[new w(C.INVALID_METADATA_FIELD,i.message,e)]:Lf(e.body?.callee)?[]:[new w(C.INVALID_METADATA_FIELD,`A Metadata field value must be a string or a color literal`,e.body??e)]});return r.push(...Object.values(t).flatMap(e=>e.length<=1?[]:e.map(e=>new w(C.DUPLICATE_METADATA_FIELD,`Duplicate Metadata fields are defined`,e)))),r}},kb={validateNode(t,i){return k(i,r.Metadata)?new n(void 0,new Ob(t,i).validate()):new n(e)},nodeFullname(t,i){return k(i,r.Metadata)?new n(void 0):new n(e)},nodeAlias(t,i){return k(i,r.Metadata)?new n(void 0):new n(e)},nodeSettings(t,i){return k(i,r.Metadata)?new n({}):new n(e)}},Ab=class{constructor(e,t){this.ast=t,this.compiler=e}validate(){let e=[],t=[];for(let n of this.ast.body){let r=this.compiler.validateNode(n);e.push(...r.getErrors()),t.push(...r.getWarnings())}return new n(this.ast,e,t)}},jb={validateNode(t,r){return Uf(r)?n.create(void 0,new Ab(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Uf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Uf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Uf(r)?new n({}):n.create(e)}},Mb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name).getErrors(),...this.validateAlias(this.declarationNode.alias).getErrors(),...this.validateSettingList(this.declarationNode.attributeList).getErrors(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?wf(e)?new n(j(e)):new n(void 0,[new w(C.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]):new n(void 0)}validateAlias(e){return e?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof V)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...t.map(e=>new w(C.INVALID_PROJECT_FIELD,`A Project can not have inline fields`,e)),...this.validateSubElements(n)]}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Nb={validateNode(t,i){return k(i,r.Project)?n.create(void 0,new Mb(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Project)?i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):A(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Project)&&i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):A(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Project)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):A(i,r.Project)?new n({}):n.create(e)}},Pb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return e instanceof L||e instanceof R&&e.isKind(r.Table)?[]:[new w(C.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof Dm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof L?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof Tm))return[new w(C.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,e||this.declarationNode.type||this.declarationNode)];let t=[];return(!e.callee||!Sf(e.callee))&&t.push(new w(C.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Ff(e.argumentList))&&t.push(new w(C.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Ff(e)?[new w(C.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return Fb(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateDataRow(e);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateDataRows(t),...this.validateSubElements(n)]}validateDataRows(e){return e.flatMap(e=>this.validateDataRow(e))}validateDataRow(e){let t=[];if(!e.callee||e.args.length>0)return t.push(new w(C.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof Cm)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new w(C.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,n));else this.isValidRecordValue(e.callee)||t.push(new w(C.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,e.callee));return t}isValidRecordValue(e){if(e instanceof Am||Mf(e)||E(e)||e instanceof xm)return!0;if(D(e)){let t=e.expression.variable.value.toLowerCase();return go.includes(t)}if(O(e)){let t=j(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function Fb(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.Example:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_RECORDS_SETTING,`'example' can only appear once`,e))),e.forEach(e=>{e.value&&r.push(new w(C.INVALID_RECORDS_SETTING_VALUE,`'example' cannot have a value`,e))});break;default:r.push(...e.map(e=>new w(C.UNKNOWN_RECORDS_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}var Ib={validateNode(t,i){return k(i,r.Records)?n.create(void 0,new Pb(t,i).validate()):n.create(e)},nodeFullname(i,a){if(k(a,r.Records)){if(a.name instanceof Dm)return new n(void 0,[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof L){if(!(a.name instanceof Tm))return new n(void 0,[new w(C.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,a.name||a.type||a)]);let e=[];(!a.name.callee||!Sf(a.name.callee))&&e.push(new w(C.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Ff(a.name.argumentList))&&e.push(new w(C.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=j(a.name.callee);return t?.length===1&&t.unshift(y),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Ff(a.name)?new n(e,[new w(C.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return A(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Records)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):A(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Records)?i.attributeList?Fb(i.attributeList):new n({}):A(i,r.Records)?new n({}):n.create(e)}},Lb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Dm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:wf(e)?[]:[new w(C.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new w(C.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 w(C.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Jf(e.callee)&&t.push(new w(C.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Jf(e.callee)){let n=ap(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=ap(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new w(C.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new w(C.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Yf(e.callee)&&t.push(new w(C.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(g(n)instanceof U){let e=this.validateFieldSettings(g(n));t.push(...e),n.pop()}else n[0]instanceof U&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new w(C.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return zb(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function Rb(e){if(!(D(e)&&e.expression.variable.kind!==v.QUOTED_STRING)&&!(e instanceof vm))return!1;let t;if(t=e instanceof vm?ep(e)||``:e.expression.variable.value,t)switch(t.toLowerCase()){case`cascade`:case`no action`:case`set null`:case`set default`:case`restrict`:return!0;default:return!1}return!1}function zb(e){let t=T(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Delete:case i.Update:t.length>1&&t.forEach(t=>r.push(new w(C.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Rb(t.value)||r.push(new w(C.INVALID_REF_SETTING_VALUE,`'${e}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,t))}),o[e]=t;break;case i.Color:t.length>1&&r.push(...t.map(e=>new w(C.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{kf(e.value)||r.push(new w(C.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),o[e]=t;break;case i.Inactive:t.length>1&&r.push(...t.map(e=>new w(C.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new w(C.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new w(C.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var Bb={validateNode(t,i){return k(i,r.Ref)?n.create(void 0,new Lb(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Ref)?i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):A(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Ref)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(k(i,r.Ref))return i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(A(i,r.Ref)){let e=[...i.args],t;return g(e)instanceof U?t=g(e):e[0]instanceof U&&(t=e[0]),t?zb(t):new n({})}return n.create(e)}},Vb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof jm?[new w(C.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof Dm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Sf(e)?[]:[new w(C.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new w(C.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Cf(e)?[]:[new w(C.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){return Hb(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);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 w(C.INVALID_COLUMN,`A column must have a type`,e.callee)),D(e.callee)||t.push(new w(C.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!If(e.args[0])&&t.push(new w(C.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t},n=e=>{let t=[];return e.callee?(Ef(e.callee)||t.push(new w(C.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee)),e.args.length&&t.push(...e.args.map(e=>new w(C.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof B&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){return Ub(e).getErrors()}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Hb(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{let t=Rv[i.HeaderColor];t.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{let t=Rv[i.Note];t.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Pf(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,"'dep' must be `-> target` or `<- source`",e.value||e.name))});break;default:r.push(...E_(t,e,{duplicate:C.DUPLICATE_TABLE_SETTING,invalidValue:C.INVALID_TABLE_SETTING_VALUE}))}}),new n(a,r)}function Ub(e){if(!e.slice(0,-1).every(zf)||!e.slice(-1).every(e=>zf(e)||e instanceof U))return new n({},e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let t;g(e)instanceof U&&(t=e.pop());let r=T(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}o[t]===void 0?o[t]=[e]:o[t].push(e)});let s=o[i.PK]||[],c=o[i.PrimaryKey]||[];return s.length>=1&&c.length>=1&&a.push(...[...s,...c].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{let t=zv[i.Note];t.isValidBuiltinFieldValue(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=o[i.Null]||[];e.length>=1&&t.length>=1&&a.push(...[...e,...t].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{jf(e.value)||a.push(new w(C.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 i.Check:e.forEach(e=>{e.value instanceof xm||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Pf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'dep' must be a valid unary relationship`,e.value||e.name))});break;default:a.push(...E_(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),new n(o,a)}var Wb={validateNode(t,i){return k(i,r.Table)?n.create(void 0,new Vb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.Table)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof jm)return new n(void 0,[new w(C.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,i.name)]);let e=j(i.name);return e?.length===1&&e.unshift(y),new n(e)}if(A(i,r.Table)){if(Ef(i.callee)){let e=N(i.callee.expression);return new n(e?[e]:void 0)}let e=N(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return k(i,r.Table)?i.alias?Cf(i.alias)?new n(N(i.alias)):new n(void 0,[new w(C.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):A(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Table)?i.attributeList?Hb(i.attributeList):new n({}):A(i,r.Table)?Ub(i.args.slice(1)):n.create(e)}},Gb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Dm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:wf(e)?[]:[new w(C.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){return Kb(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&j(e.callee)===void 0&&t.push(new w(C.INVALID_TABLEGROUP_FIELD,`A TableGroup field must be of the form <table> or <schema>.<table>`,e.callee)),e.args.length>0&&t.push(...e.args.map(e=>new w(C.INVALID_TABLEGROUP_FIELD,`A TableGroup field should only have a single Table name`,e))),t})}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Kb(e){let t=T(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Color:case i.Note:{let n=iy[e];t.length>1&&r.push(...t.map(t=>new w(C.DUPLICATE_TABLE_SETTING,`'${e}' can only appear once`,t))),t.forEach(e=>{n.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,n.message,e.value||e.name))}),o[e]=t;break}default:r.push(...E_(e,t,{duplicate:C.DUPLICATE_TABLE_SETTING,invalidValue:C.INVALID_TABLE_SETTING_VALUE})),o[e]=t;break}return new n(o,r)}var qb={validateNode(t,i){return k(i,r.TableGroup)?n.create(void 0,new Gb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.TableGroup))return i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new w(C.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(A(i,r.TableGroup)){let e=j(i.callee);return e?.length===1&&e.unshift(y),new n(e)}return n.create(e)},nodeAlias(t,i){return k(i,r.TableGroup)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.TableGroup)?Kb(i.attributeList):A(i,r.TableGroup)?new n({}):n.create(e)}},Jb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Dm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:wf(e)?[]:[new w(C.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new w(C.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=T(e),n=t.getErrors();return Sa(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{kf(e.value)||n.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||n.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new w(C.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof V)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);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 w(C.INVALID_COLUMN,`A column must have a type`,e.callee)),D(e.callee)||t.push(new w(C.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!If(e.args[0])&&t.push(new w(C.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t})}validateFieldSetting(e){let t=g(e);if(!e.slice(0,-1).every(zf)||!(zf(t)||t instanceof U))return e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;g(e)instanceof U&&(n=e.pop());let r=T(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}o[t]===void 0?o[t]=[e]:o[t].push(e)});let s=o[i.PK]||[],c=o[i.PrimaryKey]||[];return s.length>=1&&c.length>=1&&a.push(...[...s,...c].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=o[i.Null]||[];e.length>=1&&n.length>=1&&a.push(...[...e,...n].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{jf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof xm||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...E_(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),a}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Yb(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{kf(e.value)||r.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||r.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new w(C.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Xb(e){let t=g(e);if(e.length>0&&(!e.slice(0,-1).every(zf)||!(zf(t)||t instanceof U)))return new n({},e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let r;g(e)instanceof U&&(r=e.pop());let a=T(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}s[t]===void 0?s[t]=[e]:s[t].push(e)});let c=s[i.PK]||[],l=s[i.PrimaryKey]||[];return c.length>=1&&l.length>=1&&o.push(...[...c,...l].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=s[i.Null]||[];e.length>=1&&n.length>=1&&o.push(...[...e,...n].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{jf(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof xm||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:o.push(...E_(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),new n(s,o)}var Zb={validateNode(t,i){return k(i,r.TablePartial)?n.create(void 0,new Jb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.TablePartial))return i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new w(C.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(A(i,r.TablePartial)){let e=N(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return k(i,r.TablePartial)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(N(i.alias)):A(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.TablePartial)?Yb(i.attributeList):A(i,r.TablePartial)?Xb(i.args.slice(1)):n.create(e)}},Qb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.specifiers instanceof Dm)return[];for(let t of this.declarationNode.specifiers?.specifiers||[])e.push(...this.validateSpecifier(t));return e}validateSpecifier(e){let t=[];return e.importKind===void 0?t.push(new w(C.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):!e.archImport&&!e.isKind(...Object.values(Fp))&&t.push(new w(C.INVALID_USE_SPECIFIER_KIND,`'${e.importKind.value}' is not a valid specifier type`,e.importKind)),[...t,...this.compiler.nodeFullname(e).getErrors(),...this.compiler.nodeAlias(e).getErrors()]}},$b={validateNode(t,r){return r instanceof hm?n.create(void 0,new Qb(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!Hf(r))return n.create(e);let i=j(r.name);return!i||i.length===0?n.create(void 0,[new w(C.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Fp.TableGroup)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Fp.TablePartial)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Fp.Note)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Fp.Schema)&&i.unshift(y),new n(i))},nodeAlias(t,r){return Hf(r)?r.alias?Cf(r.alias)?new n(N(r.alias)):new n(void 0,[new w(C.INVALID_ALIAS,`Use aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return r instanceof hm?n.create({}):n.create(e)}};function ex(e){let t=[];for(let n of Dh(e)){if(n.value===void 0){t.push(new w(C.EMPTY_LINK,`An inline link needs an endpoint: [link: > b]`,n));continue}G(Oh(n)?.target)||t.push(new w(C.BAD_LINK,`An inline link reads [link: > b], [link: < b], [link: <> b] or [link: - b]`,n))}return t}function tx(e){let t=[],r=lh(e),i=dh(e);switch(i){case`node`:case`group`:if(!G(e.name)){t.push(new w(C.MISSING_NAME,`A ${r} needs a name`,e));break}t.push(...ex(e));for(let n of Ih(e,yh(e.attributeList),i===`node`).problems)t.push(new w(n.code===`bad`?C.BAD_PROPERTY:C.DUPLICATE_PROPERTY,n.message,n.node));break;case`kind`:{let n=G(e.name);n&&oh(n)&&t.push(new w(C.RESERVED_KIND,`${n} opens a declaration, so it cannot also be the name of a kind`,e));break}case`link`:{if(!bh(e)[0]){t.push(new w(C.EMPTY_LINK,`A Link needs two endpoints: Link: a > b`,e));break}let n=Th(e);(!n||!G(Ch(n.infix.left))||!G(Ch(n.infix.right)))&&t.push(new w(C.BAD_LINK,`A Link reads a > b, a < b, a <> b or a - b`,e));break}case`metadata`:{let n=new Set;for(let r of bh(e)){let e=r instanceof R?kh(r):void 0;if(!e||e.value===void 0){t.push(new w(C.BAD_PROPERTY,`A Metadata field must use the 'key: value' syntax`,r));continue}if(n.has(e.key)){t.push(new w(C.DUPLICATE_PROPERTY,`Duplicate Metadata fields are defined`,r));continue}n.add(e.key)}break}case`project`:for(let n of bh(e))(n instanceof R?lh(n):G(xh(n)?.callee))?.toLowerCase()===`diagram_type`&&t.push(new w(C.DIAGRAM_TYPE_NOT_HERE,`diagram_type has no effect inside Project. It says what the DOCUMENT is, and a host reads it before parsing, so it has to be in front matter:
24
+ `;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()||!xf(this.peek()))return this.errors.push(new w(C.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`,Va.create(v.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},Xy=new Set([`arch`,`architecture`]),Zy=e=>!!e&&Xy.has(e.toLowerCase());function Qy(e){let t={};for(let n of e.split(`
25
+ `)){let e=n.trim();if(!e||e===`---`)continue;let r=e.indexOf(`:`);if(r<=0)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim().replace(/^['"]|['"]$/g,``);i&&(t[i]=a)}return t}function $y(e){return e[0]?.leadingTrivia.find(e=>e.kind===v.FRONT_MATTER)}var eb=new Set([v.LBRACE,v.LBRACKET,v.LPAREN]),tb=new Set([v.RBRACE,v.RBRACKET,v.RPAREN]);function nb(e){let t=$y(e),n={frontMatter:t?Qy(t.value):{},topWords:[]},r=0,i=-1;for(let t of e){if(t.kind===v.EOF)break;let e=t.startPos.line>i;i=t.endPos.line,eb.has(t.kind)?r+=1:tb.has(t.kind)&&(r=Math.max(0,r-1)),!(r!==0||!e||t.kind!==v.IDENTIFIER)&&n.topWords.push(t.value.toLowerCase())}return n}var rb=e=>e===`group`||e===`kind`||my(e)!==void 0;function ib(e){return e.frontMatter.diagram_type===void 0?e.topWords.some(rb)?`arch`:`dbml`:Zy(e.frontMatter.diagram_type)?`arch`:`dbml`}var ab=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new w(C.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=_(e.body,e=>e instanceof H);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 g(n)instanceof W&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof ym))&&t.push(new w(C.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`name`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||n.push(new w(C.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},ob={validateNode(t,i){if(!k(i,r.Checks))return n.create(e);let a=new ab(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return k(i,r.Checks)?i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Checks)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Checks)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},sb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Project,r.Dep)?[]:[new w(C.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project or a Dep`,this.declarationNode)]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return[new w(C.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return!(this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Dep))&&!E(e.callee)&&t.push(new w(C.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 w(C.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function cb(e){return e instanceof R&&!!e.type?.value}var lb={validateNode(t,r){if(!cb(r))return n.create(e);let i=new sb(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return cb(r)?r.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return cb(r)?r.alias?new n(void 0,[new w(C.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return cb(r)?r.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},ub=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettings(),...this.validateBody(this.declarationNode.body)]}validateSettings(){let e=[];this.declarationNode.attributeList&&e.push(...db(this.declarationNode.attributeList).getErrors());let t=this.declarationNode.body;if(t instanceof H){let n=t.args.find(e=>e instanceof W);n&&e.push(...db(n).getErrors())}return e}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_DEP_CONTEXT,`A Dep must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Dep name`,e)]:wf(e)?[]:[new w(C.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.forEach(e=>{if(!e.callee){t.push(new w(C.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e));return}if(!(e.callee instanceof V)){t.push(new w(C.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e.callee));return}let n=e.callee;n.op?.value!==`->`&&n.op?.value!==`<-`&&t.push(new w(C.INVALID_DEP_FIELD,`Dep edges must use the '->' or '<-' operator`,e.callee));let r=ap(n.leftExpression)??{variables:[],tupleElements:[]},i=ap(n.rightExpression)??{variables:[],tupleElements:[]};r.variables.length===0&&r.tupleElements.length===0&&t.push(new w(C.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.leftExpression||e.callee)),i.variables.length===0&&i.tupleElements.length===0&&t.push(new w(C.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.rightExpression||e.callee));let a=[...e.args];g(a)instanceof W?a.pop():a[0]instanceof W&&a.shift(),a.length>0&&t.push(...a.map(e=>new w(C.INVALID_DEP_FIELD,`A Dep field should only have a single binary relationship`,e)))}),t}validateSubElements(e){return e.flatMap(e=>{if(!e.type)return[];let t=e.type.value?.toLowerCase(),n=e.body;if(!t)return[];switch(t){case i.Color:return e.name||!(n instanceof H)||!n.callee||!kf(n.callee)?[new w(C.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,e)]:[];case i.Note:{let t;return n instanceof H?t=n.callee:n instanceof U&&n.body[0]instanceof H&&(t=n.body[0].callee),!t||!E(t)?[new w(C.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,e)]:[]}default:return e.name||n instanceof U?[new w(C.INVALID_SETTINGS,`'${t}' must be a simple field (e.g. ${t}: value). Block syntax is not allowed`,e)]:!(n instanceof H)||!n.callee?[]:!E(n.callee)&&!kf(n.callee)&&!Mf(n.callee)&&!wf(n.callee)?[new w(C.INVALID_SETTINGS,`Invalid value for '${t}'. Expected a string, number, color, or identifier`,e)]:[]}})}};function db(e){let t=T(e),r=[...t.getErrors()],a=t.getValue();for(let[e,t]of Object.entries(a))for(let n of t)switch(e){case i.Color:kf(n.value)||r.push(new w(C.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,n));break;case i.Note:E(n.value)||r.push(new w(C.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,n));break;default:n.value&&!E(n.value)&&!kf(n.value)&&!Mf(n.value)&&!wf(n.value)&&r.push(new w(C.INVALID_SETTINGS,`Invalid value for setting '${e}'. Expected a string, number, color, or identifier`,n));break}return new n(a,r)}var fb={validateNode(t,i){return k(i,r.Dep)?n.create(void 0,new ub(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Dep)?i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,i.name)]):new n(void 0):A(i,r.Dep)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Dep)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Dep)?new n(void 0):n.create(e)},nodeSettings(t,i){if(k(i,r.Dep))return i.attributeList?db(i.attributeList):new n({});if(A(i,r.Dep)){let e=[...i.args],t;return g(e)instanceof W?t=g(e):e[0]instanceof W&&(t=e[0]),t?db(t):new n({})}return n.create(e)}},pb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList)],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?wf(e)?[]:[new w(C.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new w(C.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof H)return{errors:[new w(C.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=_(e.body,e=>e instanceof H),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Rf(e.callee)?e.args.length>0?e.args.map(e=>new w(C.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new w(C.INVALID_DIAGRAMVIEW_FIELD,`Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.`,e)])}validateSubElements(e){let t=[],n=[],r=[`tables`,`notes`,`tablegroups`,`schemas`];for(let i of e){if(!i.type)continue;let e=i.type.value.toLowerCase();if(!r.includes(e)){t.push(new w(C.INVALID_DIAGRAMVIEW_FIELD,`Unknown block type "${i.type.value}" in DiagramView. Allowed: Tables, Notes, TableGroups, Schemas`,i));continue}let a=this.validateSubBlock(i);t.push(...a.errors),n.push(...a.warnings)}return{errors:t,warnings:n}}validateSubBlock(e){let t=[],n=[];if(Tf(e))return t.push(new w(C.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof U))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof H&&Rf(e.callee)),a=r.body.some(e=>e instanceof H&&!Rf(e.callee));return i&&a&&n.push(new gf(C.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t.push(...this.validateSubBlockFields(e)),{errors:t,warnings:n}}validateSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof U))return t;let n=e.body.body.filter(e=>e instanceof H);for(let e of n)Rf(e.callee)||(e.args.length>0||!j(e.callee))&&t.push(...e.args.map(e=>new w(C.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},mb={validateNode(t,i){if(!k(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new pb(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(k(i,r.DiagramView)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=j(i.name);return e?new n(e):new n(void 0)}else if(A(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=j(i.callee);return e?(e.length===1&&A(i,r.DiagramViewTables)&&e.unshift(y),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return k(i,r.DiagramView)?new n(void 0):n.create(e)}},hb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Sf(e)?[]:[new w(C.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new w(C.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new w(C.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!D(n.callee)&&t.push(new w(C.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];g(e)instanceof W?(t.push(...this.validateFieldSettings(g(e))),e.pop()):e[0]instanceof W&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new w(C.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];if(t)switch(e){case i.Note:t.length>1&&t.forEach(e=>n.push(new w(C.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{E(e.value)||n.push(new w(C.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},gb={validateNode(t,i){return k(i,r.Enum)?n.create(void 0,new hb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.Enum)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Sf(i.name))return new n(void 0,[new w(C.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=j(i.name);return e?.length===1&&e.unshift(y),new n(e)}if(A(i,r.Enum)){let e=N(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return k(i,r.Enum)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(k(a,r.Enum))return a.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(A(a,r.Enum)){let e=[...a.args],t;if(g(e)instanceof W?t=g(e):e[0]instanceof W&&(t=e[0]),!t)return new n({});let r=T(t),o=r.getErrors(),s=r.getValue(),c={};for(let[e,t]of Object.entries(s))switch(e){case i.Note:t.length>1&&t.forEach(e=>o.push(new w(C.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{E(e.value)||o.push(new w(C.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new w(C.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},_b=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new w(C.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=_(e.body,e=>e instanceof H);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 g(n)instanceof W&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof Cm;)e.argumentList&&op(e.argumentList)===void 0&&t.push(new w(C.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;op(e)===void 0&&t.push(new w(C.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=T(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`note`:case`name`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{D(e.value)||n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},vb={validateNode(t,i){return k(i,r.Indexes)?n.create(void 0,new _b(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Indexes)?i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):A(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Indexes)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(k(a,r.Indexes))return a.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(A(a,r.Indexes)){let e=[a.callee,...a.args],t;if(g(e)instanceof W&&(t=g(e)),!t)return new n({});let r=T(t),o=r.getErrors(),s=r.getValue(),c={};for(let[e,t]of Object.entries(s))switch(e){case i.Note:case i.Name:t.length>1&&t.forEach(t=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))}),c[e]=t;break;case i.Unique:case i.PK:t.length>1&&t.forEach(t=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))}),c[e]=t;break;case i.Type:t.length>1&&t.forEach(e=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{D(e.value)||o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new w(C.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},yb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return!(e instanceof L)&&!(e instanceof R&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project,r.Dep))?[new w(C.INVALID_NOTE_CONTEXT,`A Note can only appear inside a Table, a TableGroup, a TablePartial or a Project. Sticky note can only appear at the global scope.`,this.declarationNode)]:[]}validateName(e){return this.compiler.nodeFullname(this.declarationNode).getErrors()}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof L}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new w(C.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=T(e),n=t.getErrors(),r=t.getValue(),a=this.compiler.parsedFileKind(this.declarationNode.filepath)===`arch`;return Sa(r,(e,t)=>{if(!(a&&th(t)))switch(t){case i.Color:{let t=Qv[i.Color];e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{t.isValidBuiltinFieldValue(e.value)||n.push(new w(C.INVALID_NOTE_SETTING_VALUE,t.message,e.value||e.name))});break}default:n.push(...nv(t,e,{duplicate:C.DUPLICATE_NOTE_SETTING,invalidValue:C.INVALID_NOTE_SETTING_VALUE}))}}),n}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new w(C.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new w(C.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),E(e[0].callee)||t.push(new w(C.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 w(C.INVALID_NOTE,`A Note can only contain one quoted string`,e))),t)}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},bb={validateNode(t,i){return k(i,r.Note)?n.create(void 0,new yb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!k(i,r.Note))return n.create(e);if(!(i.parent instanceof L))return i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new w(C.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof Tm)return new n(void 0,[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=j(i.name);return a===void 0?new n(void 0,[new w(C.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return k(i,r.Note)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Note)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},xb={[Ip.Table]:uv,[Ip.Column]:dv,[Ip.TableGroup]:Av,[Ip.Note]:Qv},Sb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateTargetKind(),...this.validateTargetName(this.declarationNode.name),...this.validateBody(this.declarationNode.body)]}validateTargetKind(){return tv(this.declarationNode)?[]:[new w(C.INVALID_METADATA_TARGET_KIND,`A Metadata target kind must be one of: ${Object.values(Ip).join(`, `)}`,this.declarationNode.targetKind??this.declarationNode)]}validateTargetName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Metadata target's name`,e)]:Sf(e)?[]:[new w(C.INVALID_NAME,`A Metadata target's name must be of the form <schema>.<table>, <table>.<column>, <schema>.<table>.<column> or a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A Metadata target must have a name`,this.declarationNode)]}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Metadata's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.map(e=>new w(C.INVALID_METADATA_FIELD,`A Metadata field must use the 'key: value' syntax`,e))}validateSubElements(e){let t={},n=tv(this.declarationNode),r=e.flatMap(e=>{if(!e.type)return[];if(e.body instanceof U)return[new w(C.UNEXPECTED_COMPLEX_BODY,`A Metadata field can only have an inline value`,e.body)];let r=e.type.value.toLowerCase();t[r]||(t[r]=[]),t[r].push(e);let i=n?xb[n][r]:void 0;return i?i.isValidBuiltinFieldValue(e.body?.callee)?[]:[new w(C.INVALID_METADATA_FIELD,i.message,e)]:Lf(e.body?.callee)?[]:[new w(C.INVALID_METADATA_FIELD,`A Metadata field value must be a string or a color literal`,e.body??e)]});return r.push(...Object.values(t).flatMap(e=>e.length<=1?[]:e.map(e=>new w(C.DUPLICATE_METADATA_FIELD,`Duplicate Metadata fields are defined`,e)))),r}},Cb={validateNode(t,i){return k(i,r.Metadata)?new n(void 0,new Sb(t,i).validate()):new n(e)},nodeFullname(t,i){return k(i,r.Metadata)?new n(void 0):new n(e)},nodeAlias(t,i){return k(i,r.Metadata)?new n(void 0):new n(e)},nodeSettings(t,i){return k(i,r.Metadata)?new n({}):new n(e)}},wb=class{constructor(e,t){this.ast=t,this.compiler=e}validate(){let e=[],t=[];for(let n of this.ast.body){let r=this.compiler.validateNode(n);e.push(...r.getErrors()),t.push(...r.getWarnings())}return new n(this.ast,e,t)}},Tb={validateNode(t,r){return Uf(r)?n.create(void 0,new wb(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Uf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Uf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Uf(r)?new n({}):n.create(e)}},Eb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name).getErrors(),...this.validateAlias(this.declarationNode.alias).getErrors(),...this.validateSettingList(this.declarationNode.attributeList).getErrors(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?wf(e)?new n(j(e)):new n(void 0,[new w(C.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]):new n(void 0)}validateAlias(e){return e?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof H);return[...t.map(e=>new w(C.INVALID_PROJECT_FIELD,`A Project can not have inline fields`,e)),...this.validateSubElements(n)]}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Db={validateNode(t,i){return k(i,r.Project)?n.create(void 0,new Eb(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Project)?i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):A(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Project)&&i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):A(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Project)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):A(i,r.Project)?new n({}):n.create(e)}},Ob=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return e instanceof L||e instanceof R&&e.isKind(r.Table)?[]:[new w(C.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof L?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof Cm))return[new w(C.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,e||this.declarationNode.type||this.declarationNode)];let t=[];return(!e.callee||!Sf(e.callee))&&t.push(new w(C.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Ff(e.argumentList))&&t.push(new w(C.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Ff(e)?[new w(C.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return kb(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateDataRow(e);let[t,n]=_(e.body,e=>e instanceof H);return[...this.validateDataRows(t),...this.validateSubElements(n)]}validateDataRows(e){return e.flatMap(e=>this.validateDataRow(e))}validateDataRow(e){let t=[];if(!e.callee||e.args.length>0)return t.push(new w(C.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof xm)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new w(C.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,n));else this.isValidRecordValue(e.callee)||t.push(new w(C.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,e.callee));return t}isValidRecordValue(e){if(e instanceof Om||Mf(e)||E(e)||e instanceof ym)return!0;if(D(e)){let t=e.expression.variable.value.toLowerCase();return go.includes(t)}if(O(e)){let t=j(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function kb(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.Example:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_RECORDS_SETTING,`'example' can only appear once`,e))),e.forEach(e=>{e.value&&r.push(new w(C.INVALID_RECORDS_SETTING_VALUE,`'example' cannot have a value`,e))});break;default:r.push(...e.map(e=>new w(C.UNKNOWN_RECORDS_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}var Ab={validateNode(t,i){return k(i,r.Records)?n.create(void 0,new Ob(t,i).validate()):n.create(e)},nodeFullname(i,a){if(k(a,r.Records)){if(a.name instanceof Tm)return new n(void 0,[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof L){if(!(a.name instanceof Cm))return new n(void 0,[new w(C.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,a.name||a.type||a)]);let e=[];(!a.name.callee||!Sf(a.name.callee))&&e.push(new w(C.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Ff(a.name.argumentList))&&e.push(new w(C.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=j(a.name.callee);return t?.length===1&&t.unshift(y),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Ff(a.name)?new n(e,[new w(C.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return A(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Records)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):A(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Records)?i.attributeList?kb(i.attributeList):new n({}):A(i,r.Records)?new n({}):n.create(e)}},jb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:wf(e)?[]:[new w(C.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new w(C.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 w(C.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Jf(e.callee)&&t.push(new w(C.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Jf(e.callee)){let n=ap(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=ap(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new w(C.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new w(C.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Yf(e.callee)&&t.push(new w(C.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(g(n)instanceof W){let e=this.validateFieldSettings(g(n));t.push(...e),n.pop()}else n[0]instanceof W&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new w(C.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return Nb(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function Mb(e){if(!(D(e)&&e.expression.variable.kind!==v.QUOTED_STRING)&&!(e instanceof _m))return!1;let t;if(t=e instanceof _m?ep(e)||``:e.expression.variable.value,t)switch(t.toLowerCase()){case`cascade`:case`no action`:case`set null`:case`set default`:case`restrict`:return!0;default:return!1}return!1}function Nb(e){let t=T(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Delete:case i.Update:t.length>1&&t.forEach(t=>r.push(new w(C.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Mb(t.value)||r.push(new w(C.INVALID_REF_SETTING_VALUE,`'${e}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,t))}),o[e]=t;break;case i.Color:t.length>1&&r.push(...t.map(e=>new w(C.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{kf(e.value)||r.push(new w(C.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),o[e]=t;break;case i.Inactive:t.length>1&&r.push(...t.map(e=>new w(C.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new w(C.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new w(C.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var Pb={validateNode(t,i){return k(i,r.Ref)?n.create(void 0,new jb(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Ref)?i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):A(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Ref)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(k(i,r.Ref))return i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(A(i,r.Ref)){let e=[...i.args],t;return g(e)instanceof W?t=g(e):e[0]instanceof W&&(t=e[0]),t?Nb(t):new n({})}return n.create(e)}},Fb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof km?[new w(C.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Sf(e)?[]:[new w(C.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new w(C.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Cf(e)?[]:[new w(C.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){return Ib(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof H);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 w(C.INVALID_COLUMN,`A column must have a type`,e.callee)),D(e.callee)||t.push(new w(C.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!If(e.args[0])&&t.push(new w(C.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t},n=e=>{let t=[];return e.callee?(Ef(e.callee)||t.push(new w(C.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee)),e.args.length&&t.push(...e.args.map(e=>new w(C.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof B&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){return Lb(e).getErrors()}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Ib(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{let t=uv[i.HeaderColor];t.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{let t=uv[i.Note];t.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Pf(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,"'dep' must be `-> target` or `<- source`",e.value||e.name))});break;default:r.push(...nv(t,e,{duplicate:C.DUPLICATE_TABLE_SETTING,invalidValue:C.INVALID_TABLE_SETTING_VALUE}))}}),new n(a,r)}function Lb(e){if(!e.slice(0,-1).every(zf)||!e.slice(-1).every(e=>zf(e)||e instanceof W))return new n({},e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let t;g(e)instanceof W&&(t=e.pop());let r=T(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}o[t]===void 0?o[t]=[e]:o[t].push(e)});let s=o[i.PK]||[],c=o[i.PrimaryKey]||[];return s.length>=1&&c.length>=1&&a.push(...[...s,...c].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{let t=dv[i.Note];t.isValidBuiltinFieldValue(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=o[i.Null]||[];e.length>=1&&t.length>=1&&a.push(...[...e,...t].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{jf(e.value)||a.push(new w(C.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 i.Check:e.forEach(e=>{e.value instanceof ym||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Pf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'dep' must be a valid unary relationship`,e.value||e.name))});break;default:a.push(...nv(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),new n(o,a)}var Rb={validateNode(t,i){return k(i,r.Table)?n.create(void 0,new Fb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.Table)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof km)return new n(void 0,[new w(C.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,i.name)]);let e=j(i.name);return e?.length===1&&e.unshift(y),new n(e)}if(A(i,r.Table)){if(Ef(i.callee)){let e=N(i.callee.expression);return new n(e?[e]:void 0)}let e=N(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return k(i,r.Table)?i.alias?Cf(i.alias)?new n(N(i.alias)):new n(void 0,[new w(C.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):A(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Table)?i.attributeList?Ib(i.attributeList):new n({}):A(i,r.Table)?Lb(i.args.slice(1)):n.create(e)}},zb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:wf(e)?[]:[new w(C.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){return Bb(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&j(e.callee)===void 0&&t.push(new w(C.INVALID_TABLEGROUP_FIELD,`A TableGroup field must be of the form <table> or <schema>.<table>`,e.callee)),e.args.length>0&&t.push(...e.args.map(e=>new w(C.INVALID_TABLEGROUP_FIELD,`A TableGroup field should only have a single Table name`,e))),t})}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Bb(e){let t=T(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Color:case i.Note:{let n=Av[e];t.length>1&&r.push(...t.map(t=>new w(C.DUPLICATE_TABLE_SETTING,`'${e}' can only appear once`,t))),t.forEach(e=>{n.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,n.message,e.value||e.name))}),o[e]=t;break}default:r.push(...nv(e,t,{duplicate:C.DUPLICATE_TABLE_SETTING,invalidValue:C.INVALID_TABLE_SETTING_VALUE})),o[e]=t;break}return new n(o,r)}var Vb={validateNode(t,i){return k(i,r.TableGroup)?n.create(void 0,new zb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.TableGroup))return i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new w(C.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(A(i,r.TableGroup)){let e=j(i.callee);return e?.length===1&&e.unshift(y),new n(e)}return n.create(e)},nodeAlias(t,i){return k(i,r.TableGroup)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.TableGroup)?Bb(i.attributeList):A(i,r.TableGroup)?new n({}):n.create(e)}},Hb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:wf(e)?[]:[new w(C.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new w(C.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=T(e),n=t.getErrors();return Sa(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{kf(e.value)||n.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||n.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new w(C.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof H);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 w(C.INVALID_COLUMN,`A column must have a type`,e.callee)),D(e.callee)||t.push(new w(C.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!If(e.args[0])&&t.push(new w(C.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t})}validateFieldSetting(e){let t=g(e);if(!e.slice(0,-1).every(zf)||!(zf(t)||t instanceof W))return e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;g(e)instanceof W&&(n=e.pop());let r=T(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}o[t]===void 0?o[t]=[e]:o[t].push(e)});let s=o[i.PK]||[],c=o[i.PrimaryKey]||[];return s.length>=1&&c.length>=1&&a.push(...[...s,...c].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=o[i.Null]||[];e.length>=1&&n.length>=1&&a.push(...[...e,...n].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{jf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof ym||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...nv(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),a}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Ub(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{kf(e.value)||r.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||r.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new w(C.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Wb(e){let t=g(e);if(e.length>0&&(!e.slice(0,-1).every(zf)||!(zf(t)||t instanceof W)))return new n({},e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let r;g(e)instanceof W&&(r=e.pop());let a=T(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}s[t]===void 0?s[t]=[e]:s[t].push(e)});let c=s[i.PK]||[],l=s[i.PrimaryKey]||[];return c.length>=1&&l.length>=1&&o.push(...[...c,...l].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=s[i.Null]||[];e.length>=1&&n.length>=1&&o.push(...[...e,...n].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{jf(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof ym||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:o.push(...nv(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),new n(s,o)}var Gb={validateNode(t,i){return k(i,r.TablePartial)?n.create(void 0,new Hb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.TablePartial))return i.name?wf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new w(C.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(A(i,r.TablePartial)){let e=N(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return k(i,r.TablePartial)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(N(i.alias)):A(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.TablePartial)?Ub(i.attributeList):A(i,r.TablePartial)?Wb(i.args.slice(1)):n.create(e)}},Kb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.specifiers instanceof Tm)return[];for(let t of this.declarationNode.specifiers?.specifiers||[])e.push(...this.validateSpecifier(t));return e}validateSpecifier(e){let t=[];return e.importKind===void 0?t.push(new w(C.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):!e.archImport&&!e.isKind(...Object.values(Fp))?t.push(new w(C.INVALID_USE_SPECIFIER_KIND,`'${e.importKind.value}' is not a valid specifier type`,e.importKind)):e.archImport&&e.importKind.value.toLowerCase()===`kind`&&t.push(new w(C.NO_CUSTOM_ROLE,hy,e.importKind)),[...t,...this.compiler.nodeFullname(e).getErrors(),...this.compiler.nodeAlias(e).getErrors()]}},qb={validateNode(t,r){return r instanceof mm?n.create(void 0,new Kb(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!Hf(r))return n.create(e);let i=j(r.name);return!i||i.length===0?n.create(void 0,[new w(C.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Fp.TableGroup)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Fp.TablePartial)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Fp.Note)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Fp.Schema)&&i.unshift(y),new n(i))},nodeAlias(t,r){return Hf(r)?r.alias?Cf(r.alias)?new n(N(r.alias)):new n(void 0,[new w(C.INVALID_ALIAS,`Use aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return r instanceof mm?n.create({}):n.create(e)}};function Jb(e){let t=[];for(let n of uh(e)){if(n.value===void 0){t.push(new w(C.EMPTY_LINK,`An inline link needs an endpoint: [link: > b]`,n));continue}Xm(dh(n)?.target)||t.push(new w(C.BAD_LINK,`An inline link reads [link: > b], [link: < b], [link: <> b] or [link: - b]`,n))}return t}function Yb(e){let t=[],r=Gm(e),i=qm(e);switch(i){case`node`:case`group`:if(!Xm(e.name)){t.push(new w(C.MISSING_NAME,`A ${r} needs a name`,e));break}t.push(...Jb(e));for(let n of yh(e,nh(e.attributeList),i===`node`).problems)t.push(new w(n.code===`bad`?C.BAD_PROPERTY:C.DUPLICATE_PROPERTY,n.message,n.node));break;case`kind`:t.push(new w(C.NO_CUSTOM_ROLE,hy,e));break;case`link`:{if(!rh(e)[0]){t.push(new w(C.EMPTY_LINK,`A Link needs two endpoints: Link: a > b`,e));break}let n=ch(e);(!n||!Xm(oh(n.infix.left))||!Xm(oh(n.infix.right)))&&t.push(new w(C.BAD_LINK,`A Link reads a > b, a < b, a <> b or a - b`,e));break}case`metadata`:{let n=new Set;for(let r of rh(e)){let e=r instanceof R?fh(r):void 0;if(!e||e.value===void 0){t.push(new w(C.BAD_PROPERTY,`A Metadata field must use the 'key: value' syntax`,r));continue}if(n.has(e.key)){t.push(new w(C.DUPLICATE_PROPERTY,`Duplicate Metadata fields are defined`,r));continue}n.add(e.key)}break}case`project`:for(let n of rh(e))(n instanceof R?Gm(n):Xm(ih(n)?.callee))?.toLowerCase()===`diagram_type`&&t.push(new w(C.DIAGRAM_TYPE_NOT_HERE,`diagram_type has no effect inside Project. It says what the DOCUMENT is, and a host reads it before parsing, so it has to be in front matter:
26
26
 
27
27
  ---
28
28
  diagram_type: arch
29
- ---`,n));break;default:break}return new n(void 0,t)}var nx={validateNode(t,r){if(fh(r)){let e=r;return new n(void 0,[...ex(e),...new Tb(t,e).validate()])}return uh(r)?tx(r):n.create(e)},nodeFullname(t,r){if(!uh(r)||fh(r))return n.create(e);let i=dh(r),a=i===`kind`?G(r.name):i===`node`||i===`group`?mh(r):void 0;return new n(a===void 0?void 0:[a])},nodeAlias(t,r){return!uh(r)||fh(r)?n.create(e):new n(void 0)},nodeSettings(t,r){return!uh(r)||fh(r)?n.create(e):new n({})}},rx=[Wb,Sb,Ib,wb,fb,Bb,vb,Nb,qb,Zb,Eb,kb,bb,jb,$b,hb],ix=[nx,Eb,jb,$b];function ax(t,...r){let[i,a]=r,o=!i.explicitModules&&i.parsedFileKind(a.filepath)===`arch`?ix:rx;for(let n of o){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function ox(r){let i=ax(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function sx(r){let i=ax(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function cx(r){let i=ax(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function lx(r){let i=ax(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var ux=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function dx(e,t){let n;return n=t.length===0?e:e.replace(/\{(\d+)\}/g,(e,n)=>{let r=t[n[0]],i=e;return typeof r==`string`?i=r:(typeof r==`number`||typeof r==`boolean`||r==null)&&(i=String(r)),i}),ux&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function fx(e,t,...n){return dx(t,n)}var px=!1,mx=!1,hx=!1,gx=!1,_x=void 0,vx=typeof self==`object`?self:typeof global==`object`?global:{},yx=void 0;vx.vscode!==void 0&&vx.vscode.process!==void 0?yx=vx.vscode.process:typeof process<`u`&&(yx=process);var bx=typeof yx?.versions?.electron==`string`&&yx?.type===`renderer`;if(typeof navigator==`object`&&!bx)_x=navigator.userAgent,px=_x.indexOf(`Windows`)>=0,mx=_x.indexOf(`Macintosh`)>=0,(_x.indexOf(`Macintosh`)>=0||_x.indexOf(`iPad`)>=0||_x.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,hx=_x.indexOf(`Linux`)>=0,_x?.indexOf(`Mobi`),gx=!0,fx({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof yx==`object`){px=yx.platform===`win32`,mx=yx.platform===`darwin`,hx=yx.platform===`linux`,hx&&yx.env.SNAP&&yx.env.SNAP_REVISION,yx.env.CI||yx.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=yx.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.availableLanguages[`*`],t.locale,t.osLocale,t._translationsConfigFile}catch{}}else console.error(`Unable to resolve platform.`);var xx=px,Sx=mx;gx&&vx.importScripts;var Cx=_x,wx=typeof vx.postMessage==`function`&&!vx.importScripts;(()=>{if(wx){let e=[];vx.addEventListener(`message`,t=>{if(t.data&&t.data.vscodeScheduleAsyncWork)for(let n=0,r=e.length;n<r;n++){let r=e[n];if(r.id===t.data.vscodeScheduleAsyncWork){e.splice(n,1),r.callback();return}}});let t=0;return n=>{let r=++t;e.push({id:r,callback:n}),vx.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var Tx=!!(Cx&&Cx.indexOf(`Chrome`)>=0);Cx&&Cx.indexOf(`Firefox`),!Tx&&Cx&&Cx.indexOf(`Safari`),Cx&&Cx.indexOf(`Edg/`),Cx&&Cx.indexOf(`Android`);var Ex;if(vx.vscode!==void 0&&vx.vscode.process!==void 0){let e=vx.vscode.process;Ex={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else Ex=typeof process<`u`?{get platform(){return process.platform},get arch(){return process.arch},get env(){return process.env},cwd(){return process.env.VSCODE_CWD||process.cwd()}}:{get platform(){return xx?`win32`:Sx?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var Dx=Ex.cwd,Ox=Ex.env,kx=Ex.platform,Ax=65,jx=97,Mx=90,Nx=122,Px=46,Fx=47,Ix=92,Lx=58,Rx=63,zx=class extends Error{constructor(e,t,n){let r;typeof t==`string`&&t.indexOf(`not `)===0?(r=`must not be`,t=t.replace(/^not /,``)):r=`must be`;let i=`The "${e}" ${e.indexOf(`.`)===-1?`argument`:`property`} ${r} of type ${t}`;i+=`. Received type ${typeof n}`,super(i),this.code=`ERR_INVALID_ARG_TYPE`}};function Bx(e,t){if(typeof e!=`object`||!e)throw new zx(t,`Object`,e)}function Vx(e,t){if(typeof e!=`string`)throw new zx(t,`string`,e)}var Hx=kx===`win32`;function K(e){return e===Fx||e===Ix}function Ux(e){return e===Fx}function Wx(e){return e>=Ax&&e<=Mx||e>=jx&&e<=Nx}function Gx(e,t,n,r){let i=``,a=0,o=-1,s=0,c=0;for(let l=0;l<=e.length;++l){if(l<e.length)c=e.charCodeAt(l);else if(r(c))break;else c=Fx;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==Px||i.charCodeAt(i.length-2)!==Px){if(i.length>2){let e=i.lastIndexOf(n);e===-1?(i=``,a=0):(i=i.slice(0,e),a=i.length-1-i.lastIndexOf(n)),o=l,s=0;continue}else if(i.length!==0){i=``,a=0,o=l,s=0;continue}}t&&(i+=i.length>0?`${n}..`:`..`,a=2)}else i.length>0?i+=`${n}${e.slice(o+1,l)}`:i=e.slice(o+1,l),a=l-o-1;o=l,s=0}else c===Px&&s!==-1?++s:s=-1}return i}function Kx(e,t){Bx(t,`pathObject`);let n=t.dir||t.root,r=t.base||`${t.name||``}${t.ext||``}`;return n?n===t.root?`${n}${r}`:`${n}${e}${r}`:r}var qx={resolve(...e){let t=``,n=``,r=!1;for(let i=e.length-1;i>=-1;i--){let a;if(i>=0){if(a=e[i],Vx(a,`path`),a.length===0)continue}else t.length===0?a=Dx():(a=Ox[`=${t}`]||Dx(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Ix)&&(a=`${t}\\`));let o=a.length,s=0,c=``,l=!1,u=a.charCodeAt(0);if(o===1)K(u)&&(s=1,l=!0);else if(K(u))if(l=!0,K(a.charCodeAt(1))){let e=2,t=e;for(;e<o&&!K(a.charCodeAt(e));)e++;if(e<o&&e!==t){let n=a.slice(t,e);for(t=e;e<o&&K(a.charCodeAt(e));)e++;if(e<o&&e!==t){for(t=e;e<o&&!K(a.charCodeAt(e));)e++;(e===o||e!==t)&&(c=`\\\\${n}\\${a.slice(t,e)}`,s=e)}}}else s=1;else Wx(u)&&a.charCodeAt(1)===Lx&&(c=a.slice(0,2),s=2,o>2&&K(a.charCodeAt(2))&&(l=!0,s=3));if(c.length>0)if(t.length>0){if(c.toLowerCase()!==t.toLowerCase())continue}else t=c;if(r){if(t.length>0)break}else if(n=`${a.slice(s)}\\${n}`,r=l,l&&t.length>0)break}return n=Gx(n,!r,`\\`,K),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){Vx(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return Ux(a)?`\\`:e;if(K(a))if(i=!0,K(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!K(e.charCodeAt(i));)i++;if(i<t&&i!==a){let o=e.slice(a,i);for(a=i;i<t&&K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!K(e.charCodeAt(i));)i++;if(i===t)return`\\\\${o}\\${e.slice(a)}\\`;i!==a&&(r=`\\\\${o}\\${e.slice(a,i)}`,n=i)}}}else n=1;else Wx(a)&&e.charCodeAt(1)===Lx&&(r=e.slice(0,2),n=2,t>2&&K(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?Gx(e.slice(n),!i,`\\`,K):``;return o.length===0&&!i&&(o=`.`),o.length>0&&K(e.charCodeAt(t-1))&&(o+=`\\`),r===void 0?i?`\\${o}`:o:i?`${r}\\${o}`:`${r}${o}`},isAbsolute(e){Vx(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return K(n)||t>2&&Wx(n)&&e.charCodeAt(1)===Lx&&K(e.charCodeAt(2))},join(...e){if(e.length===0)return`.`;let t,n;for(let r=0;r<e.length;++r){let i=e[r];Vx(i,`path`),i.length>0&&(t===void 0?t=n=i:t+=`\\${i}`)}if(t===void 0)return`.`;let r=!0,i=0;if(typeof n==`string`&&K(n.charCodeAt(0))){++i;let e=n.length;e>1&&K(n.charCodeAt(1))&&(++i,e>2&&(K(n.charCodeAt(2))?++i:r=!1))}if(r){for(;i<t.length&&K(t.charCodeAt(i));)i++;i>=2&&(t=`\\${t.slice(i)}`)}return qx.normalize(t)},relative(e,t){if(Vx(e,`from`),Vx(t,`to`),e===t)return``;let n=qx.resolve(e),r=qx.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Ix;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Ix;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Ix;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Ix;)c--;let l=c-s,u=o<l?o:l,d=-1,f=0;for(;f<u;f++){let n=e.charCodeAt(i+f);if(n!==t.charCodeAt(s+f))break;n===Ix&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Ix)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Ix?d=f:f===2&&(d=3)),d===-1&&(d=0)}let p=``;for(f=i+d+1;f<=a;++f)(f===a||e.charCodeAt(f)===Ix)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Ix&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=qx.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Ix){if(t.charCodeAt(1)===Ix){let e=t.charCodeAt(2);if(e!==Rx&&e!==Px)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(Wx(t.charCodeAt(0))&&t.charCodeAt(1)===Lx&&t.charCodeAt(2)===Ix)return`\\\\?\\${t}`;return e},dirname(e){Vx(e,`path`);let t=e.length;if(t===0)return`.`;let n=-1,r=0,i=e.charCodeAt(0);if(t===1)return K(i)?e:`.`;if(K(i)){if(n=r=1,K(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!K(e.charCodeAt(i));)i++;if(i===t)return e;i!==a&&(n=r=i+1)}}}}else Wx(i)&&e.charCodeAt(1)===Lx&&(n=t>2&&K(e.charCodeAt(2))?3:2,r=n);let a=-1,o=!0;for(let n=t-1;n>=r;--n)if(K(e.charCodeAt(n))){if(!o){a=n;break}}else o=!1;if(a===-1){if(n===-1)return`.`;a=n}return e.slice(0,a)},basename(e,t){t!==void 0&&Vx(t,`ext`),Vx(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&Wx(e.charCodeAt(0))&&e.charCodeAt(1)===Lx&&(n=2),t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=n;--a){let c=e.charCodeAt(a);if(K(c)){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=n;--a)if(K(e.charCodeAt(a))){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Vx(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Lx&&Wx(e.charCodeAt(0))&&(t=r=2);for(let s=e.length-1;s>=t;--s){let t=e.charCodeAt(s);if(K(t)){if(!a){r=s+1;break}continue}i===-1&&(a=!1,i=s+1),t===Px?n===-1?n=s:o!==1&&(o=1):n!==-1&&(o=-1)}return n===-1||i===-1||o===0||o===1&&n===i-1&&n===r+1?``:e.slice(n,i)},format:Kx.bind(null,`\\`),parse(e){Vx(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.length,r=0,i=e.charCodeAt(0);if(n===1)return K(i)?(t.root=t.dir=e,t):(t.base=t.name=e,t);if(K(i)){if(r=1,K(e.charCodeAt(1))){let t=2,i=t;for(;t<n&&!K(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&K(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&!K(e.charCodeAt(t));)t++;t===n?r=t:t!==i&&(r=t+1)}}}}else if(Wx(i)&&e.charCodeAt(1)===Lx){if(n<=2)return t.root=t.dir=e,t;if(r=2,K(e.charCodeAt(2))){if(n===3)return t.root=t.dir=e,t;r=3}}r>0&&(t.root=e.slice(0,r));let a=-1,o=r,s=-1,c=!0,l=e.length-1,u=0;for(;l>=r;--l){if(i=e.charCodeAt(l),K(i)){if(!c){o=l+1;break}continue}s===-1&&(c=!1,s=l+1),i===Px?a===-1?a=l:u!==1&&(u=1):a!==-1&&(u=-1)}return s!==-1&&(a===-1||u===0||u===1&&a===s-1&&a===o+1?t.base=t.name=e.slice(o,s):(t.name=e.slice(o,a),t.base=e.slice(o,s),t.ext=e.slice(a,s))),o>0&&o!==r?t.dir=e.slice(0,o-1):t.dir=t.root,t},sep:`\\`,delimiter:`;`,win32:null,posix:null},Jx=(()=>{if(Hx){let e=/\\/g;return()=>{let t=Dx().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Dx()})(),Yx={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:Jx();Vx(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Fx)}return t=Gx(t,!n,`/`,Ux),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(Vx(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Fx,n=e.charCodeAt(e.length-1)===Fx;return e=Gx(e,!t,`/`,Ux),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return Vx(e,`path`),e.length>0&&e.charCodeAt(0)===Fx},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];Vx(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:Yx.normalize(t)},relative(e,t){if(Vx(e,`from`),Vx(t,`to`),e===t||(e=Yx.resolve(e),t=Yx.resolve(t),e===t))return``;let n=e.length,r=n-1,i=t.length-1,a=r<i?r:i,o=-1,s=0;for(;s<a;s++){let n=e.charCodeAt(1+s);if(n!==t.charCodeAt(1+s))break;n===Fx&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===Fx)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Fx?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Fx)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(Vx(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Fx,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Fx){if(!r){n=t;break}}else r=!1;return n===-1?t?`/`:`.`:t&&n===1?`//`:e.slice(0,n)},basename(e,t){t!==void 0&&Vx(t,`ext`),Vx(e,`path`);let n=0,r=-1,i=!0,a;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=0;--a){let c=e.charCodeAt(a);if(c===Fx){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=0;--a)if(e.charCodeAt(a)===Fx){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Vx(e,`path`);let t=-1,n=0,r=-1,i=!0,a=0;for(let o=e.length-1;o>=0;--o){let s=e.charCodeAt(o);if(s===Fx){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===Px?t===-1?t=o:a!==1&&(a=1):t!==-1&&(a=-1)}return t===-1||r===-1||a===0||a===1&&t===r-1&&t===n+1?``:e.slice(t,r)},format:Kx.bind(null,`/`),parse(e){Vx(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Fx,r;n?(t.root=`/`,r=1):r=0;let i=-1,a=0,o=-1,s=!0,c=e.length-1,l=0;for(;c>=r;--c){let t=e.charCodeAt(c);if(t===Fx){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===Px?i===-1?i=c:l!==1&&(l=1):i!==-1&&(l=-1)}if(o!==-1){let r=a===0&&n?1:a;i===-1||l===0||l===1&&i===o-1&&i===a+1?t.base=t.name=e.slice(r,o):(t.name=e.slice(r,i),t.base=e.slice(r,o),t.ext=e.slice(i,o))}return a>0?t.dir=e.slice(0,a-1):n&&(t.dir=`/`),t},sep:`/`,delimiter:`:`,win32:null,posix:null};Yx.win32=qx.win32=qx,Yx.posix=qx.posix=Yx,Hx?qx.normalize:Yx.normalize,Hx?qx.resolve:Yx.resolve,Hx?qx.relative:Yx.relative,Hx?qx.dirname:Yx.dirname,Hx?qx.basename:Yx.basename,Hx?qx.extname:Yx.extname,Hx?qx.sep:Yx.sep;var Xx=/^\w[\w\d+.-]*$/,Zx=/^\//,Qx=/^\/\//;function $x(e,t){if(!e.scheme&&t)throw Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${e.authority}", path: "${e.path}", query: "${e.query}", fragment: "${e.fragment}"}`);if(e.scheme&&!Xx.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!Zx.test(e.path))throw Error(`[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character`)}else if(Qx.test(e.path))throw Error(`[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")`)}}function eS(e,t){return!e&&!t?`file`:e}function tS(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==nS&&(t=nS+t):t=nS;break}return t}var q=``,nS=`/`,rS=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,iS=class e{static isUri(t){return t instanceof e?!0:t?typeof t.authority==`string`&&typeof t.fragment==`string`&&typeof t.path==`string`&&typeof t.query==`string`&&typeof t.scheme==`string`&&typeof t.fsPath==`string`&&typeof t.with==`function`&&typeof t.toString==`function`:!1}constructor(e,t,n,r,i,a=!1){typeof e==`object`?(this.scheme=e.scheme||q,this.authority=e.authority||q,this.path=e.path||q,this.query=e.query||q,this.fragment=e.fragment||q):(this.scheme=eS(e,a),this.authority=t||q,this.path=tS(this.scheme,n||q),this.query=r||q,this.fragment=i||q,$x(this,a))}get fsPath(){return uS(this,!1)}with(e){if(!e)return this;let{scheme:t,authority:n,path:r,query:i,fragment:a}=e;return t===void 0?t=this.scheme:t===null&&(t=q),n===void 0?n=this.authority:n===null&&(n=q),r===void 0?r=this.path:r===null&&(r=q),i===void 0?i=this.query:i===null&&(i=q),a===void 0?a=this.fragment:a===null&&(a=q),t===this.scheme&&n===this.authority&&r===this.path&&i===this.query&&a===this.fragment?this:new oS(t,n,r,i,a)}static parse(e,t=!1){let n=rS.exec(e);return n?new oS(n[2]||q,mS(n[4]||q),mS(n[5]||q),mS(n[7]||q),mS(n[9]||q),t):new oS(q,q,q,q,q)}static file(e){let t=q;if(xx&&(e=e.replace(/\\/g,nS)),e[0]===nS&&e[1]===nS){let n=e.indexOf(nS,2);n===-1?(t=e.substring(2),e=nS):(t=e.substring(2,n),e=e.substring(n)||nS)}return new oS(`file`,t,e,q,q)}static from(e,t){return new oS(e.scheme,e.authority,e.path,e.query,e.fragment,t)}static joinPath(t,...n){if(!t.path)throw Error(`[UriError]: cannot call joinPath on URI without path`);let r;return r=xx&&t.scheme===`file`?e.file(qx.join(uS(t,!0),...n)).path:Yx.join(t.path,...n),t.with({path:r})}toString(e=!1){return dS(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new oS(t);return e._formatted=t.external??null,e._fsPath=t._sep===aS?t.fsPath??null:null,e}}},aS=xx?1:void 0,oS=class extends iS{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=uS(this,!1),this._fsPath}toString(e=!1){return e?dS(this,!0):(this._formatted||=dS(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=aS),this._formatted&&(e.external=this._formatted),this.path&&(e.path=this.path),this.scheme&&(e.scheme=this.scheme),this.authority&&(e.authority=this.authority),this.query&&(e.query=this.query),this.fragment&&(e.fragment=this.fragment),e}},sS={58:`%3A`,47:`%2F`,63:`%3F`,35:`%23`,91:`%5B`,93:`%5D`,64:`%40`,33:`%21`,36:`%24`,38:`%26`,39:`%27`,40:`%28`,41:`%29`,42:`%2A`,43:`%2B`,44:`%2C`,59:`%3B`,61:`%3D`,32:`%20`};function cS(e,t,n){let r,i=-1;for(let a=0;a<e.length;a++){let o=e.charCodeAt(a);if(o>=97&&o<=122||o>=65&&o<=90||o>=48&&o<=57||o===45||o===46||o===95||o===126||t&&o===47||n&&o===91||n&&o===93||n&&o===58)i!==-1&&(r+=encodeURIComponent(e.substring(i,a)),i=-1),r!==void 0&&(r+=e.charAt(a));else{r===void 0&&(r=e.substr(0,a));let t=sS[o];t===void 0?i===-1&&(i=a):(i!==-1&&(r+=encodeURIComponent(e.substring(i,a)),i=-1),r+=t)}}return i!==-1&&(r+=encodeURIComponent(e.substring(i))),r===void 0?e:r}function lS(e){let t;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r===35||r===63?(t===void 0&&(t=e.substr(0,n)),t+=sS[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function uS(e,t){let n;return n=e.authority&&e.path.length>1&&e.scheme===`file`?`//${e.authority}${e.path}`:e.path.charCodeAt(0)===47&&(e.path.charCodeAt(1)>=65&&e.path.charCodeAt(1)<=90||e.path.charCodeAt(1)>=97&&e.path.charCodeAt(1)<=122)&&e.path.charCodeAt(2)===58?t?e.path.substr(1):e.path[1].toLowerCase()+e.path.substr(2):e.path,xx&&(n=n.replace(/\//g,`\\`)),n}function dS(e,t){let n=t?lS:cS,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=nS,r+=nS),a){let e=a.indexOf(`@`);if(e!==-1){let t=a.substr(0,e);a=a.substr(e+1),e=t.lastIndexOf(`:`),e===-1?r+=n(t,!1,!1):(r+=n(t.substr(0,e),!1,!1),r+=`:`,r+=n(t.substr(e+1),!1,!0)),r+=`@`}a=a.toLowerCase(),e=a.lastIndexOf(`:`),e===-1?r+=n(a,!1,!0):(r+=n(a.substr(0,e),!1,!0),r+=a.substr(e))}if(o){if(o.length>=3&&o.charCodeAt(0)===47&&o.charCodeAt(2)===58){let e=o.charCodeAt(1);e>=65&&e<=90&&(o=`/${String.fromCharCode(e+32)}:${o.substr(3)}`)}else if(o.length>=2&&o.charCodeAt(1)===58){let e=o.charCodeAt(0);e>=65&&e<=90&&(o=`${String.fromCharCode(e+32)}:${o.substr(2)}`)}r+=n(o,!0,!1)}return s&&(r+=`?`,r+=n(s,!1,!1)),c&&(r+=`#`,r+=t?c:cS(c,!1,!1)),r}function fS(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+fS(e.substr(3)):e}}var pS=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function mS(e){return e.match(pS)?e.replace(pS,e=>fS(e)):e}var J=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}({}),Y=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),hS=function(e){return e[e.Hint=1]=`Hint`,e[e.Info=2]=`Info`,e[e.Warning=4]=`Warning`,e[e.Error=8]=`Error`,e}({});function gS(e,t){return e.getOffsetAt(t)}function _S(e,t){let{startPos:n,endPos:r}=t;return{startLineNumber:n.line+1,startColumn:n.column+1,endLineNumber:r.line+1,endColumn:r.column+1}}var vS=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=mo.fromUri(String(e.uri)),a=this.compiler.interpretProject().getInfos().filter(e=>e.quickFixes?.length&&e.filepath.equals(i));if(!a.length)return;let o=[];for(let t of n.markers)for(let n of a){let r=_S(e,n.nodeOrToken);if(!(r.startLineNumber!==t.startLineNumber||r.startColumn!==t.startColumn||r.endLineNumber!==t.endLineNumber||r.endColumn!==t.endColumn))for(let r of n.quickFixes??[]){let n=this.quickFixToCodeAction(r,e,t);n&&o.push(n)}}let s=Pa(o,e=>{let t=e.diagnostics?.[0];return`${e.title}@${t?.startLineNumber}:${t?.startColumn}`});if(s.length)return{actions:s,dispose(){}}}quickFixToCodeAction(e,t,n){let r=mo.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=iS.parse(e.filepath.toUri({protocol:t.uri.scheme})),a={edits:e.edits.map(e=>{let n=t.getPositionAt(e.start),r=t.getPositionAt(e.end);return{resource:i,textEdit:{range:{startLineNumber:n.lineNumber,startColumn:n.column,endLineNumber:r.lineNumber,endColumn:r.column},text:e.newText},versionId:t.getVersionId()}})};return{title:e.title,kind:`quickfix`,edit:a,diagnostics:[n]}}},yS=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=mo.fromUri(String(e.uri)),a=gS(e,n),o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(!e)continue;let n=this.compiler.nodeReferee(e).getFiltered(t);if(!n)continue;let i;if(n.declaration&&[mm.PRIMARY_EXPRESSION,mm.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=iS.parse(i.filepath.toUri({protocol:r.scheme}))),[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}]}}return[]}},bS=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e),...this.provideInfos(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideInfos(e){return e?this.compiler.interpretFile(e).getInfos().map(e=>this.createDiagnostic(e,`info`)):this.compiler.interpretProject().getInfos().map(e=>this.createDiagnostic(e,`info`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos,a=e.details,o=a?.quickFixes?.filter(e=>e.edits.length>0).map(e=>({title:e.title,shortTitle:e.shortTitle,edits:e.edits.map(e=>({start:e.start,end:e.end,newText:e.newText})),isPreferred:e.isPreferred}));return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code,category:a?.category,explanation:a?.explanation,filepath:e.filepath,quickFixes:o}}getSeverityValue(e){return e===`error`?hS.Error:e===`warning`?hS.Warning:hS.Info}},xS=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=mo.fromUri(String(r)),a=gS(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[mm.ELEMENT_DECLARATION,mm.FUNCTION_APPLICATION,mm.PRIMARY_EXPRESSION].includes(e?.kind)){let n=this.compiler.nodeSymbol(e).getFiltered(t)??this.compiler.nodeReferee(e).getFiltered(t),i=n?this.compiler.symbolReferences(n):void 0;if(i&&i.length>0)return i.map(e=>{let t=r;return r&&e.filepath&&(t=iS.parse(e.filepath.toUri({protocol:r.scheme}))),{range:{startColumn:e.startPos.column+1,startLineNumber:e.startPos.line+1,endColumn:e.endPos.column+1,endLineNumber:e.endPos.line+1},uri:t}})}}return[]}};function SS(e,t){let n=[],r=e.parseFile(t).getValue()?.ast;if(!r)return n;for(let e of r.uses){let t=e.importPath?.value??``,r=[];if(e.specifiers instanceof _m)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=N(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?N(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof Dm&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof Dm)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function CS(e,t,n,r,i,a){let o=SS(e,i),s=r.relativeTo(i.dirname).replace(/\.dbml$/,``),c=o.findIndex(e=>e.sourceFile===s),l=`${n} ${t}`;if(c!==-1){let e=o[c];return e.specifiers.some(e=>e.name===t)?{topInsert:``}:{topInsert:wS(Na([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
30
- `),removeRange:TS(a,e.startOffset,e.endOffset)}}return{topInsert:wS([l],s,`
31
- `)}}function wS(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function TS(e,t,n){let r=e.lastIndexOf(`
29
+ ---`,n));break;default:break}return new n(void 0,t)}var Xb={validateNode(t,r){if(Jm(r)){let e=r;return new n(void 0,[...Jb(e),...new yb(t,e).validate()])}return Km(r)?Yb(r):n.create(e)},nodeFullname(t,r){if(!Km(r)||Jm(r))return n.create(e);let i=qm(r),a=i===`node`||i===`group`?Zm(r):void 0;return new n(a===void 0?void 0:[a])},nodeAlias(t,r){return!Km(r)||Jm(r)?n.create(e):new n(void 0)},nodeSettings(t,r){return!Km(r)||Jm(r)?n.create(e):new n({})}},Zb=[Rb,gb,Ab,vb,ob,Pb,fb,Db,Vb,Gb,bb,Cb,mb,Tb,qb,lb],Qb=[Xb,bb,Tb,qb];function $b(t,...r){let[i,a]=r,o=!i.explicitModules&&i.parsedFileKind(a.filepath)===`arch`?Qb:Zb;for(let n of o){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function ex(r){let i=$b(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function tx(r){let i=$b(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function nx(r){let i=$b(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function rx(r){let i=$b(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var ix=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function ax(e,t){let n;return n=t.length===0?e:e.replace(/\{(\d+)\}/g,(e,n)=>{let r=t[n[0]],i=e;return typeof r==`string`?i=r:(typeof r==`number`||typeof r==`boolean`||r==null)&&(i=String(r)),i}),ix&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function ox(e,t,...n){return ax(t,n)}var sx=!1,cx=!1,lx=!1,ux=!1,dx=void 0,fx=typeof self==`object`?self:typeof global==`object`?global:{},px=void 0;fx.vscode!==void 0&&fx.vscode.process!==void 0?px=fx.vscode.process:typeof process<`u`&&(px=process);var mx=typeof px?.versions?.electron==`string`&&px?.type===`renderer`;if(typeof navigator==`object`&&!mx)dx=navigator.userAgent,sx=dx.indexOf(`Windows`)>=0,cx=dx.indexOf(`Macintosh`)>=0,(dx.indexOf(`Macintosh`)>=0||dx.indexOf(`iPad`)>=0||dx.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,lx=dx.indexOf(`Linux`)>=0,dx?.indexOf(`Mobi`),ux=!0,ox({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof px==`object`){sx=px.platform===`win32`,cx=px.platform===`darwin`,lx=px.platform===`linux`,lx&&px.env.SNAP&&px.env.SNAP_REVISION,px.env.CI||px.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=px.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.availableLanguages[`*`],t.locale,t.osLocale,t._translationsConfigFile}catch{}}else console.error(`Unable to resolve platform.`);var hx=sx,gx=cx;ux&&fx.importScripts;var _x=dx,vx=typeof fx.postMessage==`function`&&!fx.importScripts;(()=>{if(vx){let e=[];fx.addEventListener(`message`,t=>{if(t.data&&t.data.vscodeScheduleAsyncWork)for(let n=0,r=e.length;n<r;n++){let r=e[n];if(r.id===t.data.vscodeScheduleAsyncWork){e.splice(n,1),r.callback();return}}});let t=0;return n=>{let r=++t;e.push({id:r,callback:n}),fx.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var yx=!!(_x&&_x.indexOf(`Chrome`)>=0);_x&&_x.indexOf(`Firefox`),!yx&&_x&&_x.indexOf(`Safari`),_x&&_x.indexOf(`Edg/`),_x&&_x.indexOf(`Android`);var bx;if(fx.vscode!==void 0&&fx.vscode.process!==void 0){let e=fx.vscode.process;bx={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else bx=typeof process<`u`?{get platform(){return process.platform},get arch(){return process.arch},get env(){return process.env},cwd(){return process.env.VSCODE_CWD||process.cwd()}}:{get platform(){return hx?`win32`:gx?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var xx=bx.cwd,Sx=bx.env,Cx=bx.platform,wx=65,Tx=97,Ex=90,Dx=122,Ox=46,kx=47,Ax=92,jx=58,Mx=63,Nx=class extends Error{constructor(e,t,n){let r;typeof t==`string`&&t.indexOf(`not `)===0?(r=`must not be`,t=t.replace(/^not /,``)):r=`must be`;let i=`The "${e}" ${e.indexOf(`.`)===-1?`argument`:`property`} ${r} of type ${t}`;i+=`. Received type ${typeof n}`,super(i),this.code=`ERR_INVALID_ARG_TYPE`}};function Px(e,t){if(typeof e!=`object`||!e)throw new Nx(t,`Object`,e)}function Fx(e,t){if(typeof e!=`string`)throw new Nx(t,`string`,e)}var Ix=Cx===`win32`;function K(e){return e===kx||e===Ax}function Lx(e){return e===kx}function Rx(e){return e>=wx&&e<=Ex||e>=Tx&&e<=Dx}function zx(e,t,n,r){let i=``,a=0,o=-1,s=0,c=0;for(let l=0;l<=e.length;++l){if(l<e.length)c=e.charCodeAt(l);else if(r(c))break;else c=kx;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==Ox||i.charCodeAt(i.length-2)!==Ox){if(i.length>2){let e=i.lastIndexOf(n);e===-1?(i=``,a=0):(i=i.slice(0,e),a=i.length-1-i.lastIndexOf(n)),o=l,s=0;continue}else if(i.length!==0){i=``,a=0,o=l,s=0;continue}}t&&(i+=i.length>0?`${n}..`:`..`,a=2)}else i.length>0?i+=`${n}${e.slice(o+1,l)}`:i=e.slice(o+1,l),a=l-o-1;o=l,s=0}else c===Ox&&s!==-1?++s:s=-1}return i}function Bx(e,t){Px(t,`pathObject`);let n=t.dir||t.root,r=t.base||`${t.name||``}${t.ext||``}`;return n?n===t.root?`${n}${r}`:`${n}${e}${r}`:r}var Vx={resolve(...e){let t=``,n=``,r=!1;for(let i=e.length-1;i>=-1;i--){let a;if(i>=0){if(a=e[i],Fx(a,`path`),a.length===0)continue}else t.length===0?a=xx():(a=Sx[`=${t}`]||xx(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Ax)&&(a=`${t}\\`));let o=a.length,s=0,c=``,l=!1,u=a.charCodeAt(0);if(o===1)K(u)&&(s=1,l=!0);else if(K(u))if(l=!0,K(a.charCodeAt(1))){let e=2,t=e;for(;e<o&&!K(a.charCodeAt(e));)e++;if(e<o&&e!==t){let n=a.slice(t,e);for(t=e;e<o&&K(a.charCodeAt(e));)e++;if(e<o&&e!==t){for(t=e;e<o&&!K(a.charCodeAt(e));)e++;(e===o||e!==t)&&(c=`\\\\${n}\\${a.slice(t,e)}`,s=e)}}}else s=1;else Rx(u)&&a.charCodeAt(1)===jx&&(c=a.slice(0,2),s=2,o>2&&K(a.charCodeAt(2))&&(l=!0,s=3));if(c.length>0)if(t.length>0){if(c.toLowerCase()!==t.toLowerCase())continue}else t=c;if(r){if(t.length>0)break}else if(n=`${a.slice(s)}\\${n}`,r=l,l&&t.length>0)break}return n=zx(n,!r,`\\`,K),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){Fx(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return Lx(a)?`\\`:e;if(K(a))if(i=!0,K(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!K(e.charCodeAt(i));)i++;if(i<t&&i!==a){let o=e.slice(a,i);for(a=i;i<t&&K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!K(e.charCodeAt(i));)i++;if(i===t)return`\\\\${o}\\${e.slice(a)}\\`;i!==a&&(r=`\\\\${o}\\${e.slice(a,i)}`,n=i)}}}else n=1;else Rx(a)&&e.charCodeAt(1)===jx&&(r=e.slice(0,2),n=2,t>2&&K(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?zx(e.slice(n),!i,`\\`,K):``;return o.length===0&&!i&&(o=`.`),o.length>0&&K(e.charCodeAt(t-1))&&(o+=`\\`),r===void 0?i?`\\${o}`:o:i?`${r}\\${o}`:`${r}${o}`},isAbsolute(e){Fx(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return K(n)||t>2&&Rx(n)&&e.charCodeAt(1)===jx&&K(e.charCodeAt(2))},join(...e){if(e.length===0)return`.`;let t,n;for(let r=0;r<e.length;++r){let i=e[r];Fx(i,`path`),i.length>0&&(t===void 0?t=n=i:t+=`\\${i}`)}if(t===void 0)return`.`;let r=!0,i=0;if(typeof n==`string`&&K(n.charCodeAt(0))){++i;let e=n.length;e>1&&K(n.charCodeAt(1))&&(++i,e>2&&(K(n.charCodeAt(2))?++i:r=!1))}if(r){for(;i<t.length&&K(t.charCodeAt(i));)i++;i>=2&&(t=`\\${t.slice(i)}`)}return Vx.normalize(t)},relative(e,t){if(Fx(e,`from`),Fx(t,`to`),e===t)return``;let n=Vx.resolve(e),r=Vx.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Ax;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Ax;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Ax;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Ax;)c--;let l=c-s,u=o<l?o:l,d=-1,f=0;for(;f<u;f++){let n=e.charCodeAt(i+f);if(n!==t.charCodeAt(s+f))break;n===Ax&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Ax)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Ax?d=f:f===2&&(d=3)),d===-1&&(d=0)}let p=``;for(f=i+d+1;f<=a;++f)(f===a||e.charCodeAt(f)===Ax)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Ax&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=Vx.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Ax){if(t.charCodeAt(1)===Ax){let e=t.charCodeAt(2);if(e!==Mx&&e!==Ox)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(Rx(t.charCodeAt(0))&&t.charCodeAt(1)===jx&&t.charCodeAt(2)===Ax)return`\\\\?\\${t}`;return e},dirname(e){Fx(e,`path`);let t=e.length;if(t===0)return`.`;let n=-1,r=0,i=e.charCodeAt(0);if(t===1)return K(i)?e:`.`;if(K(i)){if(n=r=1,K(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!K(e.charCodeAt(i));)i++;if(i===t)return e;i!==a&&(n=r=i+1)}}}}else Rx(i)&&e.charCodeAt(1)===jx&&(n=t>2&&K(e.charCodeAt(2))?3:2,r=n);let a=-1,o=!0;for(let n=t-1;n>=r;--n)if(K(e.charCodeAt(n))){if(!o){a=n;break}}else o=!1;if(a===-1){if(n===-1)return`.`;a=n}return e.slice(0,a)},basename(e,t){t!==void 0&&Fx(t,`ext`),Fx(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&Rx(e.charCodeAt(0))&&e.charCodeAt(1)===jx&&(n=2),t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=n;--a){let c=e.charCodeAt(a);if(K(c)){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=n;--a)if(K(e.charCodeAt(a))){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Fx(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===jx&&Rx(e.charCodeAt(0))&&(t=r=2);for(let s=e.length-1;s>=t;--s){let t=e.charCodeAt(s);if(K(t)){if(!a){r=s+1;break}continue}i===-1&&(a=!1,i=s+1),t===Ox?n===-1?n=s:o!==1&&(o=1):n!==-1&&(o=-1)}return n===-1||i===-1||o===0||o===1&&n===i-1&&n===r+1?``:e.slice(n,i)},format:Bx.bind(null,`\\`),parse(e){Fx(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.length,r=0,i=e.charCodeAt(0);if(n===1)return K(i)?(t.root=t.dir=e,t):(t.base=t.name=e,t);if(K(i)){if(r=1,K(e.charCodeAt(1))){let t=2,i=t;for(;t<n&&!K(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&K(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&!K(e.charCodeAt(t));)t++;t===n?r=t:t!==i&&(r=t+1)}}}}else if(Rx(i)&&e.charCodeAt(1)===jx){if(n<=2)return t.root=t.dir=e,t;if(r=2,K(e.charCodeAt(2))){if(n===3)return t.root=t.dir=e,t;r=3}}r>0&&(t.root=e.slice(0,r));let a=-1,o=r,s=-1,c=!0,l=e.length-1,u=0;for(;l>=r;--l){if(i=e.charCodeAt(l),K(i)){if(!c){o=l+1;break}continue}s===-1&&(c=!1,s=l+1),i===Ox?a===-1?a=l:u!==1&&(u=1):a!==-1&&(u=-1)}return s!==-1&&(a===-1||u===0||u===1&&a===s-1&&a===o+1?t.base=t.name=e.slice(o,s):(t.name=e.slice(o,a),t.base=e.slice(o,s),t.ext=e.slice(a,s))),o>0&&o!==r?t.dir=e.slice(0,o-1):t.dir=t.root,t},sep:`\\`,delimiter:`;`,win32:null,posix:null},Hx=(()=>{if(Ix){let e=/\\/g;return()=>{let t=xx().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>xx()})(),Ux={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:Hx();Fx(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===kx)}return t=zx(t,!n,`/`,Lx),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(Fx(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===kx,n=e.charCodeAt(e.length-1)===kx;return e=zx(e,!t,`/`,Lx),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return Fx(e,`path`),e.length>0&&e.charCodeAt(0)===kx},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];Fx(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:Ux.normalize(t)},relative(e,t){if(Fx(e,`from`),Fx(t,`to`),e===t||(e=Ux.resolve(e),t=Ux.resolve(t),e===t))return``;let n=e.length,r=n-1,i=t.length-1,a=r<i?r:i,o=-1,s=0;for(;s<a;s++){let n=e.charCodeAt(1+s);if(n!==t.charCodeAt(1+s))break;n===kx&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===kx)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===kx?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===kx)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(Fx(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===kx,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===kx){if(!r){n=t;break}}else r=!1;return n===-1?t?`/`:`.`:t&&n===1?`//`:e.slice(0,n)},basename(e,t){t!==void 0&&Fx(t,`ext`),Fx(e,`path`);let n=0,r=-1,i=!0,a;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=0;--a){let c=e.charCodeAt(a);if(c===kx){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=0;--a)if(e.charCodeAt(a)===kx){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Fx(e,`path`);let t=-1,n=0,r=-1,i=!0,a=0;for(let o=e.length-1;o>=0;--o){let s=e.charCodeAt(o);if(s===kx){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===Ox?t===-1?t=o:a!==1&&(a=1):t!==-1&&(a=-1)}return t===-1||r===-1||a===0||a===1&&t===r-1&&t===n+1?``:e.slice(t,r)},format:Bx.bind(null,`/`),parse(e){Fx(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===kx,r;n?(t.root=`/`,r=1):r=0;let i=-1,a=0,o=-1,s=!0,c=e.length-1,l=0;for(;c>=r;--c){let t=e.charCodeAt(c);if(t===kx){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===Ox?i===-1?i=c:l!==1&&(l=1):i!==-1&&(l=-1)}if(o!==-1){let r=a===0&&n?1:a;i===-1||l===0||l===1&&i===o-1&&i===a+1?t.base=t.name=e.slice(r,o):(t.name=e.slice(r,i),t.base=e.slice(r,o),t.ext=e.slice(i,o))}return a>0?t.dir=e.slice(0,a-1):n&&(t.dir=`/`),t},sep:`/`,delimiter:`:`,win32:null,posix:null};Ux.win32=Vx.win32=Vx,Ux.posix=Vx.posix=Ux,Ix?Vx.normalize:Ux.normalize,Ix?Vx.resolve:Ux.resolve,Ix?Vx.relative:Ux.relative,Ix?Vx.dirname:Ux.dirname,Ix?Vx.basename:Ux.basename,Ix?Vx.extname:Ux.extname,Ix?Vx.sep:Ux.sep;var Wx=/^\w[\w\d+.-]*$/,Gx=/^\//,Kx=/^\/\//;function qx(e,t){if(!e.scheme&&t)throw Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${e.authority}", path: "${e.path}", query: "${e.query}", fragment: "${e.fragment}"}`);if(e.scheme&&!Wx.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!Gx.test(e.path))throw Error(`[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character`)}else if(Kx.test(e.path))throw Error(`[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")`)}}function Jx(e,t){return!e&&!t?`file`:e}function Yx(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==Xx&&(t=Xx+t):t=Xx;break}return t}var q=``,Xx=`/`,Zx=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,Qx=class e{static isUri(t){return t instanceof e?!0:t?typeof t.authority==`string`&&typeof t.fragment==`string`&&typeof t.path==`string`&&typeof t.query==`string`&&typeof t.scheme==`string`&&typeof t.fsPath==`string`&&typeof t.with==`function`&&typeof t.toString==`function`:!1}constructor(e,t,n,r,i,a=!1){typeof e==`object`?(this.scheme=e.scheme||q,this.authority=e.authority||q,this.path=e.path||q,this.query=e.query||q,this.fragment=e.fragment||q):(this.scheme=Jx(e,a),this.authority=t||q,this.path=Yx(this.scheme,n||q),this.query=r||q,this.fragment=i||q,qx(this,a))}get fsPath(){return iS(this,!1)}with(e){if(!e)return this;let{scheme:t,authority:n,path:r,query:i,fragment:a}=e;return t===void 0?t=this.scheme:t===null&&(t=q),n===void 0?n=this.authority:n===null&&(n=q),r===void 0?r=this.path:r===null&&(r=q),i===void 0?i=this.query:i===null&&(i=q),a===void 0?a=this.fragment:a===null&&(a=q),t===this.scheme&&n===this.authority&&r===this.path&&i===this.query&&a===this.fragment?this:new eS(t,n,r,i,a)}static parse(e,t=!1){let n=Zx.exec(e);return n?new eS(n[2]||q,cS(n[4]||q),cS(n[5]||q),cS(n[7]||q),cS(n[9]||q),t):new eS(q,q,q,q,q)}static file(e){let t=q;if(hx&&(e=e.replace(/\\/g,Xx)),e[0]===Xx&&e[1]===Xx){let n=e.indexOf(Xx,2);n===-1?(t=e.substring(2),e=Xx):(t=e.substring(2,n),e=e.substring(n)||Xx)}return new eS(`file`,t,e,q,q)}static from(e,t){return new eS(e.scheme,e.authority,e.path,e.query,e.fragment,t)}static joinPath(t,...n){if(!t.path)throw Error(`[UriError]: cannot call joinPath on URI without path`);let r;return r=hx&&t.scheme===`file`?e.file(Vx.join(iS(t,!0),...n)).path:Ux.join(t.path,...n),t.with({path:r})}toString(e=!1){return aS(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new eS(t);return e._formatted=t.external??null,e._fsPath=t._sep===$x?t.fsPath??null:null,e}}},$x=hx?1:void 0,eS=class extends Qx{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=iS(this,!1),this._fsPath}toString(e=!1){return e?aS(this,!0):(this._formatted||=aS(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=$x),this._formatted&&(e.external=this._formatted),this.path&&(e.path=this.path),this.scheme&&(e.scheme=this.scheme),this.authority&&(e.authority=this.authority),this.query&&(e.query=this.query),this.fragment&&(e.fragment=this.fragment),e}},tS={58:`%3A`,47:`%2F`,63:`%3F`,35:`%23`,91:`%5B`,93:`%5D`,64:`%40`,33:`%21`,36:`%24`,38:`%26`,39:`%27`,40:`%28`,41:`%29`,42:`%2A`,43:`%2B`,44:`%2C`,59:`%3B`,61:`%3D`,32:`%20`};function nS(e,t,n){let r,i=-1;for(let a=0;a<e.length;a++){let o=e.charCodeAt(a);if(o>=97&&o<=122||o>=65&&o<=90||o>=48&&o<=57||o===45||o===46||o===95||o===126||t&&o===47||n&&o===91||n&&o===93||n&&o===58)i!==-1&&(r+=encodeURIComponent(e.substring(i,a)),i=-1),r!==void 0&&(r+=e.charAt(a));else{r===void 0&&(r=e.substr(0,a));let t=tS[o];t===void 0?i===-1&&(i=a):(i!==-1&&(r+=encodeURIComponent(e.substring(i,a)),i=-1),r+=t)}}return i!==-1&&(r+=encodeURIComponent(e.substring(i))),r===void 0?e:r}function rS(e){let t;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r===35||r===63?(t===void 0&&(t=e.substr(0,n)),t+=tS[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function iS(e,t){let n;return n=e.authority&&e.path.length>1&&e.scheme===`file`?`//${e.authority}${e.path}`:e.path.charCodeAt(0)===47&&(e.path.charCodeAt(1)>=65&&e.path.charCodeAt(1)<=90||e.path.charCodeAt(1)>=97&&e.path.charCodeAt(1)<=122)&&e.path.charCodeAt(2)===58?t?e.path.substr(1):e.path[1].toLowerCase()+e.path.substr(2):e.path,hx&&(n=n.replace(/\//g,`\\`)),n}function aS(e,t){let n=t?rS:nS,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=Xx,r+=Xx),a){let e=a.indexOf(`@`);if(e!==-1){let t=a.substr(0,e);a=a.substr(e+1),e=t.lastIndexOf(`:`),e===-1?r+=n(t,!1,!1):(r+=n(t.substr(0,e),!1,!1),r+=`:`,r+=n(t.substr(e+1),!1,!0)),r+=`@`}a=a.toLowerCase(),e=a.lastIndexOf(`:`),e===-1?r+=n(a,!1,!0):(r+=n(a.substr(0,e),!1,!0),r+=a.substr(e))}if(o){if(o.length>=3&&o.charCodeAt(0)===47&&o.charCodeAt(2)===58){let e=o.charCodeAt(1);e>=65&&e<=90&&(o=`/${String.fromCharCode(e+32)}:${o.substr(3)}`)}else if(o.length>=2&&o.charCodeAt(1)===58){let e=o.charCodeAt(0);e>=65&&e<=90&&(o=`${String.fromCharCode(e+32)}:${o.substr(2)}`)}r+=n(o,!0,!1)}return s&&(r+=`?`,r+=n(s,!1,!1)),c&&(r+=`#`,r+=t?c:nS(c,!1,!1)),r}function oS(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+oS(e.substr(3)):e}}var sS=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function cS(e){return e.match(sS)?e.replace(sS,e=>oS(e)):e}var J=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}({}),Y=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),lS=function(e){return e[e.Hint=1]=`Hint`,e[e.Info=2]=`Info`,e[e.Warning=4]=`Warning`,e[e.Error=8]=`Error`,e}({});function uS(e,t){return e.getOffsetAt(t)}function dS(e,t){let{startPos:n,endPos:r}=t;return{startLineNumber:n.line+1,startColumn:n.column+1,endLineNumber:r.line+1,endColumn:r.column+1}}var fS=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=mo.fromUri(String(e.uri)),a=this.compiler.interpretProject().getInfos().filter(e=>e.quickFixes?.length&&e.filepath.equals(i));if(!a.length)return;let o=[];for(let t of n.markers)for(let n of a){let r=dS(e,n.nodeOrToken);if(!(r.startLineNumber!==t.startLineNumber||r.startColumn!==t.startColumn||r.endLineNumber!==t.endLineNumber||r.endColumn!==t.endColumn))for(let r of n.quickFixes??[]){let n=this.quickFixToCodeAction(r,e,t);n&&o.push(n)}}let s=Pa(o,e=>{let t=e.diagnostics?.[0];return`${e.title}@${t?.startLineNumber}:${t?.startColumn}`});if(s.length)return{actions:s,dispose(){}}}quickFixToCodeAction(e,t,n){let r=mo.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=Qx.parse(e.filepath.toUri({protocol:t.uri.scheme})),a={edits:e.edits.map(e=>{let n=t.getPositionAt(e.start),r=t.getPositionAt(e.end);return{resource:i,textEdit:{range:{startLineNumber:n.lineNumber,startColumn:n.column,endLineNumber:r.lineNumber,endColumn:r.column},text:e.newText},versionId:t.getVersionId()}})};return{title:e.title,kind:`quickfix`,edit:a,diagnostics:[n]}}},pS=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=mo.fromUri(String(e.uri)),a=uS(e,n),o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(!e)continue;let n=this.compiler.nodeReferee(e).getFiltered(t);if(!n)continue;let i;if(n.declaration&&[pm.PRIMARY_EXPRESSION,pm.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=Qx.parse(i.filepath.toUri({protocol:r.scheme}))),[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}]}}return[]}},mS=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e),...this.provideInfos(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideInfos(e){return e?this.compiler.interpretFile(e).getInfos().map(e=>this.createDiagnostic(e,`info`)):this.compiler.interpretProject().getInfos().map(e=>this.createDiagnostic(e,`info`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos,a=e.details,o=a?.quickFixes?.filter(e=>e.edits.length>0).map(e=>({title:e.title,shortTitle:e.shortTitle,edits:e.edits.map(e=>({start:e.start,end:e.end,newText:e.newText})),isPreferred:e.isPreferred}));return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code,category:a?.category,explanation:a?.explanation,filepath:e.filepath,quickFixes:o}}getSeverityValue(e){return e===`error`?lS.Error:e===`warning`?lS.Warning:lS.Info}},hS=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=mo.fromUri(String(r)),a=uS(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[pm.ELEMENT_DECLARATION,pm.FUNCTION_APPLICATION,pm.PRIMARY_EXPRESSION].includes(e?.kind)){let n=this.compiler.nodeSymbol(e).getFiltered(t)??this.compiler.nodeReferee(e).getFiltered(t),i=n?this.compiler.symbolReferences(n):void 0;if(i&&i.length>0)return i.map(e=>{let t=r;return r&&e.filepath&&(t=Qx.parse(e.filepath.toUri({protocol:r.scheme}))),{range:{startColumn:e.startPos.column+1,startLineNumber:e.startPos.line+1,endColumn:e.endPos.column+1,endLineNumber:e.endPos.line+1},uri:t}})}}return[]}};function gS(e,t){let n=[],r=e.parseFile(t).getValue()?.ast;if(!r)return n;for(let e of r.uses){let t=e.importPath?.value??``,r=[];if(e.specifiers instanceof gm)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=N(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?N(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof Tm&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof Tm)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function _S(e,t,n,r,i,a){let o=gS(e,i),s=r.relativeTo(i.dirname).replace(/\.dbml$/,``),c=o.findIndex(e=>e.sourceFile===s),l=`${n} ${t}`;if(c!==-1){let e=o[c];return e.specifiers.some(e=>e.name===t)?{topInsert:``}:{topInsert:vS(Na([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
30
+ `),removeRange:yS(a,e.startOffset,e.endOffset)}}return{topInsert:vS([l],s,`
31
+ `)}}function vS(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function yS(e,t,n){let r=e.lastIndexOf(`
32
32
  `,t-1)+1,i=n;for(;i<e.length&&(e[i]===` `||e[i]===` `);)i++;return i<e.length&&e[i]===`\r`&&i++,i<e.length&&e[i]===`
33
- `&&i++,{startOffset:r,endOffset:i}}function ES(e){switch(e){case F.Schema:return J.Module;case F.Table:case F.TablePartial:case F.Metadata:return J.Class;case F.Column:case F.TableGroupField:return J.Field;case F.Enum:return J.Enum;case F.EnumField:return J.EnumMember;case F.TableGroup:return J.Struct;default:return J.Text}}function DS(e,t){if(!e||Wa(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===v.NEWLINE&&n.end<=t)return!1}return!0}function X(){return{suggestions:[]}}function OS(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function kS(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:Jv(e.insertText??``),quoted:!0}))}}function AS(e,t=`, `){let n=e.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label).join(t);return n?{...e,suggestions:[{label:`* (all)`,insertText:n,insertTextRules:Y.KeepWhitespace,kind:J.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function jS(e,n,r){let i=[],a=new Set,o=e.layout.getSource(r)??``;for(let s of e.layout.getEntrypoints()){if(s.equals(r))continue;let c=e.usableMembers(s).getFiltered(t);if(c)for(let t of[...c.nonSchemaMembers,...c.schemaMembers]){if(!n.includes(t.kind))continue;let c=t.name;!c||a.has(c)||(a.add(c),i.push(MS(e,c,t.kind,s,r,o)))}}return i}function MS(e,t,n,r,i,a){let o=CS(e,t,n,r,i,a),s=[];if(o.topInsert&&s.push({range:{startLineNumber:1,startColumn:1,endLineNumber:1,endColumn:1},text:o.topInsert}),o.removeRange){let e=NS(a,o.removeRange.startOffset),t=NS(a,o.removeRange.endOffset);s.push({range:{startLineNumber:e.line,startColumn:e.column,endLineNumber:t.line,endColumn:t.column},text:``})}return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:ES(n),detail:`from ${r.basename}`,sortText:`zzz_${ES(n).toString().padStart(2,`0`)}_${t}`,range:void 0,additionalTextEdits:s}}function NS(e,t){let n=1,r=1;for(let i=0;i<t&&i<e.length;i++)e[i]===`
34
- `?(n++,r=1):r++;return{line:n,column:r}}function PS(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof R)||!o.isKind(r.Records)||!(o.body instanceof H)||!o.body||!jg(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof L?FS(e,o):IS(e,o)}function FS(e,n){if(!(n.name instanceof Tm))return X();let r=n.name.argumentList?.elementList||[],i=r.map(n=>e.nodeReferee(n).getFiltered(t));if(!i||i.length===0)return X();let a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Up||r instanceof om))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}});return a.length===0?X():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function IS(e,n){let r=n.parent;if(!(r instanceof R))return X();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof Hp))return X();let a;if(n.name instanceof Sm){let r=n.name.elementList,i=r.map(n=>e.nodeReferee(n).getFiltered(t)).filter(e=>e!==void 0);a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Up||r instanceof om))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}})}else{let t=i.mergedColumns(e).flatMap(t=>{let{name:n}=t.canonicalName(e,t.filepath),{name:r}=t.type(e);return{name:n,type:r}});if(!t)return X();a=t}return a.length===0?X():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function LS(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof hm&&n>=o.start&&n<=o.fullEnd)return RS(e,t,n,o,i,r);return null}function RS(e,t,n,r,i,a){if(r.importPath&&jg(n,r.importPath))return US(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return X();if(r.fromKeyword&&n>r.fromKeyword.end)return US(e,t,void 0,i,r);if(r.specifiers instanceof _m){if(!r.specifiers.openBrace){let e=HS();return DS(r.useKeyword,n)?OS(e):e}return zS(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof Dm)return X();let o=HS();return DS(r.useKeyword,n)?OS(o):o}function zS(e,t,n,r,i,a){for(let o of r.specifiers){let r=!Number.isNaN(o.start)&&n>=o.start&&n<=o.end,s=a===o.importKind||a===o.asKeyword;if(r||s){if(o.importKind&&n>o.importKind.end){let n=o.getSymbolKind();if(n!==void 0&&n!==F.Schema)return VS(e,t,i,n)}return BS()}}return BS()}function BS(){return{suggestions:Object.keys(Fp).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function VS(e,n,r,i){if(!r)return X();let a=e.layout.resolveFileSpecifier(n,r.value);if(!a)return X();let o=e.usableMembers(a).getFiltered(t);if(!o)return X();let s=new Set;for(let n of o.schemaMembers){let r=e.symbolMembers(n).getFiltered(t)??[];for(let e of r){if(e.kind!==i||e instanceof am&&!e.canBeImported)continue;let t=e.name;t&&(n.isPublicSchema()?s.add(t):s.add(`${n.name}.${t}`))}}return{suggestions:[...s].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:ES(i),range:void 0}))}}function HS(){return{suggestions:[{label:`* from`,detail:`import all`,insertText:"* from '${1:./path}'",insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0},{label:`{ } from`,detail:`import named`,insertText:"{ ${1:type} ${2:name} } from '${3:./path}'",insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function US(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=_S(r,n);c={startLineNumber:e.startLineNumber,startColumn:e.startColumn+1,endLineNumber:e.endLineNumber,endColumn:e.endColumn-1}}let l=new Map,u=new Map,d=Pa(e.layout.getEntrypoints().flatMap(t=>[...e.reachableFiles(t)]),e=>e.intern());for(let n of d){if(n.equals(t))continue;let r=n.relativeTo(a);if(r.endsWith(`.dbml`)&&(r=r.slice(0,-vo.length)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=mo.resolve(a,d),p=e.layout.isDirectory(f);if(GS(e,n,WS(i))&&u.set(d,!0),l.has(d))continue;let m=s?`'${d}'`:d;l.set(d,{label:d,insertText:m,insertTextRules:Y.KeepWhitespace,kind:p?J.Folder:J.File,sortText:`${p?`2`:`3`}${d}`,range:c})}for(let[e,t]of l)u.get(e)&&(t.sortText=`${t.kind===J.File?`0`:`1`}${e}`,t.detail=`best match`);return{suggestions:[...l.values()]}}function WS(e){let t=e.specifiers;return t instanceof _m?t.specifiers.flatMap(e=>{let t=N(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function GS(e,n,r){if(r.length===0)return!1;let i=e.usableMembers(n).getFiltered(t);return i?r.every(({name:e,kind:t})=>i.nonSchemaMembers.some(n=>n.kind===t&&n.name===e)):!1}var Z={Table:`Table`,TableGroup:`TableGroup`,Enum:`Enum`,Project:`Project`,Ref:`Ref`,Dep:`Dep`,TablePartial:`TablePartial`,Records:`Records`,DiagramView:`DiagramView`,Note:`Note`,Metadata:`Metadata`,Indexes:`indexes`,Checks:`checks`,Tables:`Tables`,TableGroups:`TableGroups`,Notes:`Notes`,Schemas:`Schemas`,Column:`Column`},KS=`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(`.`),qS=[i.HeaderColor,i.Note];qS.map(e=>`${e}: `);var JS=[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique],YS=[i.Ref,i.Dep,i.Default,i.Note,i.Check],XS=[...JS,...YS],ZS=[...JS,...YS.map(e=>`${e}: `)],QS=[i.Unique,i.PK],$S=[i.Note,i.Name,i.Type],eC=[...QS,...$S],tC=[...QS,...$S.map(e=>`${e}: `)],nC=[i.Inactive],rC=[i.Update,i.Delete,i.Color],iC=[...nC,...rC],aC=[...nC,...rC.map(e=>`${e}: `)],oC=[i.Note],sC=oC.map(e=>`${e}: `),cC=[i.Name],lC=cC.map(e=>`${e}: `),uC=[`cascade`,`set default`,`set null`,`restrict`],dC=[`btree`,`hash`],fC=[Z.Note,Z.Indexes,Z.Checks,Z.Records],pC=[Z.Table,Z.TableGroup,Z.Enum,Z.Note,Z.Ref,Z.Dep,Z.TablePartial],mC=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=mo.fromUri(String(e.uri)),i=gS(e,t),a=PS(this.compiler,e,t,n,i);if(a!==null)return a;let o=this.compiler.token.flatStream(n),{token:s,index:c}=this.compiler.container.token(n,i),l=c===void 0?o[0]:o[c+1];if([...s?.trailingTrivia||[],...s?.leadingTrivia||[],...l?.leadingTrivia||[]].find(e=>qa(e)&&jg(i,e)))return X();if(c===void 0)return kC();let u=LS(this.compiler,n,i,s,e);if(u!==null)return u;if([v.STRING_LITERAL,v.QUOTED_STRING].includes(s.kind)&&jg(i,s))return X();let d=this.compiler.container.element(n,i);if(this.compiler.container.scopeKind(n,i)===Q.TOPLEVEL||d instanceof R&&d.type&&d.type.start<=i&&d.type.end>=i)return kC();let f=[...this.compiler.container.stack(n,i)].reverse();for(let e of f)if(e instanceof B)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return gC(this.compiler,n,i,e);case`~`:return hC(this.compiler,n,i);default:}else if(e instanceof ym)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return gC(this.compiler,n,i,e);case`.`:return EC(this.compiler,n,i,e);default:}else if(e instanceof z)return xC(this.compiler,n,i,e);else if(e instanceof U)return xC(this.compiler,n,i,e);else if(e instanceof Sm)return yC(this.compiler,n,i,e);else if(e instanceof Cm)return bC(this.compiler,n,i);else if(e instanceof Tm)return zC(this.compiler,n,i,e);else if(e instanceof V)return DC(this.compiler,n,i,e);else if(e instanceof R){if(Mg(i,e))return k(e,r.Metadata)?LC(this.compiler,n,i,e):RC(this.compiler,n,i,e);if(e.bodyColon&&i>=e.bodyColon.end||e.body&&jg(i,e.body))return DC(this.compiler,n,i,void 0)}return X()}};function hC(e,t,n){return vC(e,t,n,e.parse.ast(t),[F.TablePartial])}function gC(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.DEP,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=vC(e,t,n,e.container.element(t,n),[F.Table,F.Schema,F.Column]);return DS(r.op,n)?OS(i):i}return X()}function _C(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?kS({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof zp&&e.isPublicSchema())).flatMap(e=>{let t=e.name;if(t===void 0)return[];let r=e.originalFilepath,i=r&&!r.equals(n.filepath)?`from ${r.basename}`:`this file`;return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:ES(e.kind),sortText:ES(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):X()}function vC(e,n,r,i,a){if(i===void 0)return X();let o=i,s={suggestions:[]},c;for(;o;){o instanceof L&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=_C(e,n,a).suggestions,r=e=>{switch(e){case J.Field:return 0;case J.Module:return 1;case J.Class:return 2;default:return 3}};t.sort((e,t)=>r(e.kind)-r(t.kind)),s.suggestions.push(...t)}o=o instanceof R?o.parent:void 0}if(c?.filepath){let t=c.filepath,n=new Set(s.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label));for(let r of jS(e,a,t)){let e=typeof r.label==`string`?r.label:r.label.label;n.has(e)||(n.add(e),s.suggestions.push(r))}}return kS(s)}function yC(e,n,i,a){let o=e.container.scopeKind(n,i),s=e.container.element(n,i),c=[...e.container.stack(n,i)];for(let t of c)if(t instanceof Tm&&t.argumentList===a)return zC(e,n,i,t);if(s instanceof R&&s.isKind(r.Records)&&!(s.name instanceof Tm)&&Mg(i,s)){let n=s.parent?e.nodeSymbol(s.parent).getFiltered(t):void 0,r=s.name?e.nodeReferee(s.name).getFiltered(t):void 0,i=n||r;if(i){let t=_C(e,i,[F.Column]);return np(a)?AS(t):t}}switch(o){case Q.INDEXES:return UC(e,n,i);case Q.REF:case Q.DEP:for(;c.length>0;){let t=c.pop();if(t instanceof ym&&t.op?.value===`.`)return EC(e,n,i,t)}return NC(e,n,i);default:break}return X()}function bC(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?vC(e,t,n,e.container.element(t,n),[F.Schema,F.Enum,F.EnumField]):X()}function xC(e,t,n,r){let{token:i}=e.container.token(t,n);if([v.COMMA,v.LBRACKET].includes(i?.kind)){let r=SC(e,t,n);return i?.kind===v.COMMA&&DS(i,n)?OS(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return SC(e,t,n);if(r.name instanceof vm){let a=wC(e,t,n,ep(r.name)??``);return i?.kind===v.COLON&&DS(i,n)?OS(a):a}return X()}function SC(e,t,n){let r=e.container.element(t,n);if(r instanceof L)return X();let a=e.container.scopeKind(t,n);if(r.body&&!jg(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=qS;break;case Q.TABLEGROUP:e=[i.Color,i.Note];break;case Q.RECORDS:return{suggestions:[{label:i.Example,insertText:i.Example,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}]};case Q.NOTE:e=[i.Color];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}))}}switch(a){case Q.TABLE:case Q.TABLEPARTIAL:return{suggestions:CC(XS,ZS)};case Q.ENUM:return{suggestions:CC(oC,sC)};case Q.INDEXES:return{suggestions:CC(eC,tC)};case Q.REF:return{suggestions:CC(iC,aC)};case Q.DEP:return{suggestions:[i.Note,i.Color].map(e=>({label:e,insertText:`${e}: `,kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))};case Q.CHECKS:return{suggestions:CC(cC,lC)};default:break}return X()}function CC(e,t){return e.map((e,n)=>({label:e,insertText:t[n],kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))}function wC(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:uC.map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:dC.map(e=>({label:e,insertText:`${e}`,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`color`:if(e.container.scopeKind(t,n)===Q.NOTE)return{suggestions:[_o].map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};break;case`default`:return vC(e,t,n,e.container.element(t,n),[F.Schema,F.Enum]);default:break}return X()}function TC(e,n,r){if(!r)return[];let i=[],a=r;for(;a;){let n=e.nodeSymbol(a).getFiltered(t);if(n){let r=e.symbolMembers(n).getFiltered(t);i.push(...r||[])}a=a instanceof R?a.parent:void 0}for(let e of n){let t=i.filter(t=>t.name===e);if(t.length===0)return[];i=t}return i}function EC(e,n,r,i){let a=ip(i)??[];return a.pop(),a.some(e=>!D(e))?X():kS({suggestions:TC(e,a.map(e=>N(e)),e.container.element(n,r)).flatMap(n=>e.symbolMembers(n).getFiltered(t)||[]).flatMap(e=>{let t=e.name;return t===void 0?[]:{label:t,insertText:t,kind:ES(e.kind),range:void 0}})})}function DC(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return jC(e,t,n,i);case Q.PROJECT:return MC(e,t,n,i);case Q.INDEXES:return VC(e,t,n);case Q.ENUM:return AC(e,t,n,i);case Q.REF:case Q.DEP:{let r=NC(e,t,n);return e.container.token(t,n).token?.kind===v.COLON&&DS(e.container.token(t,n).token,n)?OS(r):r}case Q.TABLEGROUP:return BC(e,t);case Q.DIAGRAMVIEW:return KC();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof R){let a=i.parentNode,o=a instanceof H?a.parentNode:void 0;if(o instanceof R&&o.isKind(r.DiagramView))return qC(e,t,n,i)}return X()}default:return X()}}var OC=[Z.Table,Z.TableGroup,Z.Enum,Z.Project,Z.Ref,Z.Dep,Z.TablePartial,Z.Records,Z.DiagramView,Z.Note,Z.Metadata];function kC(){return{suggestions:OC.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function AC(e,t,n,r){return r?.callee&&WC(n,r)===1?vC(e,t,n,e.container.element(t,n),[F.Schema,F.Table,F.Column]):X()}function jC(e,t,n,r){let i=fC;if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))};let a=WC(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:a===1?HC(e,t,n):X()}function MC(e,t,n,r){let i=pC;return!r?.callee||WC(n,r)===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:X()}function NC(e,t,n){return vC(e,t,n,e.container.element(t,n),[F.Schema,F.Table,F.Column])}var PC={[Ip.Table]:[F.Schema,F.Table],[Ip.Column]:[F.Schema,F.Table,F.Column],[Ip.TableGroup]:[F.TableGroup],[Ip.Note]:[F.StickyNote]},FC={[Ip.Table]:Z.Table,[Ip.Column]:Z.Column,[Ip.TableGroup]:Z.TableGroup,[Ip.Note]:Z.Note};function IC(){return{suggestions:Object.values(Ip).map(e=>{let t=FC[e];return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}})}}function LC(e,t,n,r){let i=T_(r);if(!i||n<=r.targetKind.end&&n>=r.targetKind.start)return IC();let a=PC[i];return a?vC(e,t,n,r.parent,a):X()}function RC(e,t,n,i){return i.isKind(r.Records)?vC(e,t,n,i.parent,[F.Schema,F.Table]):X()}function zC(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&jg(i,a.callee),c=a.argumentList&&jg(i,a.argumentList);if(o instanceof R&&o.isKind(r.Records)&&Mg(i,o)){if(s)return vC(e,n,i,o.parent,[F.Schema,F.Table]);if(!c)return X();let r=a.callee;if(!r)return X();let l=ip(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return X();let f=_C(e,d,[F.Column]),{argumentList:p}=a;return!p||!np(p)?f:AS(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof V)||o.callee!==a||(N(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return X();let l=_C(e,s,[F.Column]),{argumentList:u}=a;return!u||!np(u)?l:AS(l)}return X()}function BC(e,t){return{suggestions:[...kS({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==F.Table&&e.kind!==F.Schema)return[];let t=e.name;return t===void 0||e instanceof zp&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:ES(e.kind),range:void 0}})}).suggestions,...[Z.Note].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))]}}function VC(e,t,n){return UC(e,t,n)}function HC(e,t,n){return{suggestions:[...KS.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.TypeParameter,sortText:J.TypeParameter.toString().padStart(2,`0`),range:void 0})),...vC(e,t,n,e.container.element(t,n),[F.Enum,F.Schema]).suggestions]}}function UC(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(F.Table))return X();let o=e.symbolMembers(a).getFiltered(t);return o?kS({suggestions:o.flatMap(n=>{let r=n.declaration?e.nodeFullname(n.declaration):void 0,i=r&&!r.hasValue(t)?r.getValue()?.at(-1):void 0;return i?{label:i,insertText:i,insertTextRules:Y.KeepWhitespace,kind:ES(F.Column),range:void 0}:[]})}):X()}function WC(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 GC={label:`*`,insertText:`*`,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0};function KC(){return{suggestions:[...[Z.Tables,Z.TableGroups,Z.Notes,Z.Schemas].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0})),GC]}}function qC(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[GC,...vC(e,t,n,e.parse.ast(t),[F.Table,F.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[GC,...vC(e,t,n,e.parse.ast(t),[F.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[GC,{label:y,insertText:y,insertTextRules:Y.KeepWhitespace,kind:J.Module,range:void 0},...vC(e,t,n,e.parse.ast(t),[F.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[GC,...vC(e,t,n,e.parse.ast(t),[F.StickyNote]).suggestions]};default:return X()}}var JC={comments:{lineComment:`//`,blockComment:[`/*`,`*/`]},brackets:[[`{`,`}`],[`[`,`]`],[`(`,`)`]],autoClosingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:"`",close:"`"}],surroundingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:"`",close:"`"}],indentationRules:{increaseIndentPattern:/^(.*\{[^}]*|\s*[{[].*)$/,decreaseIndentPattern:/^(.*\}.*|\s*[}\]].*)$/}},YC={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`dep`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`,`metadata`],metadataTarget:[`table`,`tablegroup`,`schema`,`column`,`note`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`dep`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`none`,`check`,`tables`,`tablegroups`,`notes`,`schemas`,`inactive`,`example`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>~-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":{cases:{"$3@metadataTarget":[`keyword`,``,`keyword`,``,`identifier`],"@default":[`keyword`,``,`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`identifier`,``,`identifier`]}}],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@metadataTarget":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}};function XC(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:_a(n,e=>!e.isInvalid,r);if(a===-1)return[this.parse.ast(e)];let o=n[a].start,s=this.parse.ast(e),c=[s];for(;;){let e=Rm(s).find(e=>jg(o,e));if(e===void 0||e instanceof Va)break;c.push(e),s=e}if(i?.kind===v.COLON)return c;for(;c.length>0;){let n=!1,r=g(c);if(r instanceof V){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
35
- `&&(c.pop(),n=!0)}else r instanceof B||r instanceof ym?this.container.token(e,t).token!==r.op&&(c.pop(),n=!0):r instanceof U?r.listCloseBracket&&r.end<=t&&(c.pop(),n=!0):r instanceof Sm?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof Cm?r.end<=t&&(c.pop(),n=!0):r instanceof H?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof vm||r.end<t&&(c.pop(),n=!0);if(n){let e=g(c);e instanceof R&&e.end<=t&&c.pop()}if(!n)break}return c}function ZC(e,t){let n=this.token.flatStream(e).findIndex(e=>e.start>=t);return n===void 0||n<=0?{token:void 0,index:void 0}:{token:this.token.flatStream(e)[n-1],index:n-1}}function QC(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof R)return n[e];return this.parse.ast(e)}function $C(e,n){let r=this.container.element(e,n);if(!r)return;let i=this.nodeSymbol(r);if(i.hasValue(t))return;let a=this.symbolMembers(i.getValue());if(!a.hasValue(t))return a.getValue()}var Q=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.DEP=6]=`DEP`,e[e.PROJECT=7]=`PROJECT`,e[e.CUSTOM=8]=`CUSTOM`,e[e.TOPLEVEL=9]=`TOPLEVEL`,e[e.TABLEPARTIAL=10]=`TABLEPARTIAL`,e[e.CHECKS=11]=`CHECKS`,e[e.RECORDS=12]=`RECORDS`,e[e.DIAGRAMVIEW=13]=`DIAGRAMVIEW`,e[e.METADATA=14]=`METADATA`,e}({});function ew(e,t){let n=this.container.element(e,t);if(n instanceof L)return Q.TOPLEVEL;switch(n.type?.value.toLowerCase()){case`table`:return Q.TABLE;case`enum`:return Q.ENUM;case`ref`:return Q.REF;case`dep`:return Q.DEP;case`tablegroup`:return Q.TABLEGROUP;case`indexes`:return Q.INDEXES;case`note`:return Q.NOTE;case`project`:return Q.PROJECT;case`tablepartial`:return Q.TABLEPARTIAL;case`checks`:return Q.CHECKS;case`records`:return Q.RECORDS;case`diagramview`:return Q.DIAGRAMVIEW;case`metadata`:return Q.METADATA;default:return Q.CUSTOM}}function tw(e,t){let r=t.originalSymbol;if(r.filepath.equals(e))return n.create(rw(this,r));let i=[...this.symbolUses(r).getValue(),...this.symbolAliases(r).getValue()].filter(t=>t.filepath.equals(e));for(let e of i){let t=e.name;if(!t)continue;if(t!==r.name)return n.create({schema:``,name:t});let i=nw(this,e);if(i.length>0)return n.create({schema:i.join(`.`),name:t});let a=rw(this,r);return a?n.create({...a,name:t}):n.create({schema:y,name:t})}return n.create(rw(this,r))}function nw(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof zp&&e.isKind(F.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function rw(e,n){if(!n.declaration)return n.name?{schema:y,name:n.name}:void 0;let r=e.nodeFullname(n.declaration).getFiltered(t);if(!r||r.length===0)return n.name?{schema:y,name:n.name}:void 0;let i=r[r.length-1];return{schema:r.length>1?r.slice(0,-1).join(`.`):y,name:i}}function iw(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof hm)||!i.importPath)continue;let t=this.layout.resolveFileSpecifier(e,i.importPath.value);!t||r.has(t.absolute)||(r.add(t.absolute),n.push(t))}return n}function aw(e,t){let n=new Set,r=[],i=[...t],a=0;for(;a<i.length;){let t=i[a++],o=t.intern();if(!n.has(o)){n.add(o),r.push(t);for(let n of e.fileDependencies(t))i.push(n)}}return r}function ow(e){return aw(this,e?[e]:this.layout.getEntrypoints())}function sw(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function cw(e){return this.interpretFile(e).getErrors()}function lw(e){return this.interpretFile(e).getWarnings()}function uw(e){return this.parseFile(e).getValue().tokens}function dw(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.interpretSymbol(r,e).getFiltered(t)}function fw(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.symbolMembers(r).getFiltered(t)}function pw(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function mw(e){return this.parseFile(e).getValue().tokens.filter(fm)}function hw(e,t){let n=this.parse.ast(e);for(;;){let e=Rm(n).find(e=>jg(t,e));if(e===void 0)return n;if(e instanceof Va)return e;n=e}}function gw(e){let t=this.validateFile(e),r=this.parseFile(e).getValue().ast,i=this.bindNode(r).map(()=>void 0);return new n(void 0,[...t.getErrors(),...i.getErrors()],[...t.getWarnings(),...i.getWarnings()])}function _w(){let e=ey(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.bindFile(n);t.set(n.absolute,e)}return t}function vw(e){let{ast:r}=this.parseFile(e).getValue(),i=this.nodeSymbol(r).getFiltered(t);return i?this.interpretSymbol(i,e).map(e=>e===t||!e?void 0:e):n.create(void 0)}function yw(){let e=[],r=[],i=[],a=new Set,o=[];for(let e of this.layout.getEntrypoints())for(let t of this.reachableFiles(e)){let e=t.intern();a.has(e)||(a.add(e),o.push(t))}let s=new Map;for(let a of o){let o=this.parseFile(a);e.push(...o.getErrors()),r.push(...o.getWarnings()),i.push(...o.getInfos());let c=this.bindFile(a);e.push(...c.getErrors()),r.push(...c.getWarnings()),i.push(...c.getInfos());let{ast:l}=o.getValue(),u=this.nodeSymbol(l).getFiltered(t),d=u?this.interpretSymbol(u,a):n.create(t),f=d.getFiltered(t);f&&s.set(a.absolute,f),e.push(...d.getErrors()),r.push(...d.getWarnings()),i.push(...d.getInfos())}let c={};for(let[e,t]of s)c[e]=t;return new n({files:c},e,r,i)}function bw(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var xw=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),Sw=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return g(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 v.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case v.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case v.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case v.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},Cw=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},ww=class{constructor(e,t,n,r,i={}){this.current=0,this.errors=[],this.contextStack=new Sw,this.useSpecifierList=this.contextStack.withContextDo(xw.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(_m,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof gm&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(v.IDENTIFIER)&&um(this.peek()))break;!Ha(this.previous())&&!this.check(v.RBRACE)&&this.logError(this.peek(),C.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(v.RBRACE))for(W(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||this.check(v.STRING_LITERAL)||this.check(v.IDENTIFIER)&&um(e)||Ua(this.previous(),e))break;W(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===v.EOF?this.logError(e,C.UNEXPECTED_EOF,`Unexpected EOF`):W(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(sm(e)||this.check(v.COLON,v.LBRACE,v.LBRACKET))break;W(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COLON,v.LBRACE,v.LBRACKET))break;W(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(xw.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(H,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(v.RBRACE))for(W(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||Ua(this.previous(),e))break;W(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(xw.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(wm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(Sm,e);try{this.consume(`Expect an opening parenthesis '('`,v.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(v.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(v.RPAREN);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof I&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,v.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(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(v.RPAREN,v.COMMA))break;W(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(xw.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(U,e);try{this.consume(`Expect an opening bracket '['`,v.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(v.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(v.RBRACKET);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof I&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,v.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;W(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET,v.COLON))break;W(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;W(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Cw(n,r),this.filepath=r,this.options=i}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===v.EOF}advance(){return this.isAtEnd()?g(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?g(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(),C.UNEXPECTED_TOKEN,e),new $(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(),C.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(),r=this.nodeFactory.create(L,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Rm(e).forEach(t=>{t instanceof I&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(cm(this.peek())||dm(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof hm&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(hm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===v.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(Dm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof _m&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof Dm?`'*'`:`specifier list`;return um(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(v.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(gm,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,v.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(v.IDENTIFIER,v.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof I&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an element name`);if(sm(this.peek())){e.asKeyword=this.advance();try{if(!this.check(v.IDENTIFIER,v.QUOTED_STRING))throw this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(lm(e.type))try{this.consume(`Expect a metadata target kind`,v.IDENTIFIER),e.targetKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(v.COLON,v.LBRACE,v.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(sm(this.peek()))if(e.as=this.advance(),this.check(v.COLON,v.LBRACE,v.LBRACKET))this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(v.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.options.allowBodylessElement&&!this.check(v.LBRACE,v.COLON)||!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,v.LBRACE,v.COLON))return t();try{if(this.match(v.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof R?(W(t),this.logError(t,C.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 $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,v.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof R?this.errors.push(new w(C.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}expression(){let e={args:[]},t=()=>Pm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(V,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Wa(this.previous())||this.logError(n,C.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.RBRACKET,v.RPAREN,v.COMMA,v.COLON].includes(e)}commaExpression(){let e=this.check(v.COMMA)?this.nodeFactory.create(Am,{prevToken:this.previous()}):this.normalExpression();if(!this.check(v.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(Am,{prevToken:this.previous()}));break}if(this.check(v.COMMA)){t.elementList.push(this.nodeFactory.create(Am,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(Cm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(v.COMMA));return this.nodeFactory.create(Cm,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.LBRACE,v.RBRACKET,v.LBRACKET,v.RPAREN,v.LPAREN,v.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===v.LPAREN){let{left:r}=Pw(n);if(r<e||Ua(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(Tm,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Tm,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===v.LBRACKET){if(Wa(this.previous()))break;try{t=this.nodeFactory.create(jm,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(jm,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Ba(n)){let r=n,i=Pw(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(bm,{expression:t,op:r})}else{let n=Aw(r);if(n.left===null||n.left<=e||Mw(r).right!==null&&Ua(this.previous(),r)&&this.contextStack.top()===xw.BlockExpression)break;this.advance();try{t=this.nodeFactory.create(ym,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(ym,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Ba(this.peek())){let t={};t.op=this.peek();let n=Mw(t.op);if(n.right===null)throw this.logError(t.op,C.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Am,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(B,t),e.handlerContext)):e}e=this.nodeFactory.create(B,t)}else if(e=this.extractOperand(),e instanceof Am)throw new $(this.peek(),this.nodeFactory.create(Am,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(v.WILDCARD)?this.wildcardExpression():this.check(v.NUMERIC_LITERAL,v.STRING_LITERAL,v.COLOR_LITERAL,v.QUOTED_STRING,v.IDENTIFIER)?this.primaryExpression():this.check(v.FUNCTION_EXPRESSION)?this.functionExpression():this.check(v.LBRACKET)?this.listExpression():this.check(v.LBRACE)?this.blockExpression():this.check(v.LPAREN)?this.tupleExpression():(this.peek().kind===v.EOF?this.logError(this.peek(),C.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),C.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Am,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,v.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(xm,e),t.handlerContext):t}return this.nodeFactory.create(xm,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(Dm,{token:this.previous()})}canBeField(){return this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.COLON}primaryExpression(){if(this.match(v.COLOR_LITERAL,v.STRING_LITERAL,v.NUMERIC_LITERAL))return this.nodeFactory.create(km,{expression:this.nodeFactory.create(Em,{literal:this.previous()})});if(this.match(v.QUOTED_STRING,v.IDENTIFIER))return this.nodeFactory.create(km,{expression:this.nodeFactory.create(Om,{variable:this.previous()})});throw this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(v.COLON,v.RBRACKET,v.COMMA)){let t=this.peek();this.logError(t,C.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(vm,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(z,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(v.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(z,e)}attributeValue(){let e;try{e=this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==v.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(v.COLON,v.COMMA,v.RBRACKET);)try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(vm,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(vm,{identifiers:e})}logError(e,t,n){this.errors.push(new w(t,n,e))}},Tw=e=>({left:e,right:e+1}),Ew=e=>({left:null,right:e}),Dw=e=>({left:e,right:null}),Ow={left:null,right:null},kw={".":Tw(16),"/":Tw(11),"%":Tw(11),"+":Tw(9),"=":Tw(2),"==":Tw(4),"!=":Tw(4),"-":Tw(9),"-?":Tw(9),"?-":Tw(9),"?-?":Tw(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`].map(e=>[e,Tw(7)]))};function Aw(e){return kw[e.value]??Ow}var jw=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`,`!`,`~`].map(e=>[e,Ew(15)]));function Mw(e){return jw[e.value]??Ow}var Nw={"(":Dw(14)};function Pw(e){return Nw[e.value]??Ow}function Fw(e){let t=this.getSource(e)??``,n=this.lexerOptions();return new nb(t,e,n).lex().chain(r=>{let i=this.fileKindForParse(e,n.allowFrontMatter?r:void 0);return new ww(t,r,this.nodeIdGenerator,e,this.parserOptions(i)).parse().map(e=>(i===`arch`&&!this.explicitModules&&Iw(e.ast),e))}).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function Iw(e){for(let t of e.body)if(!(!(t instanceof hm)||!(t.specifiers instanceof _m)))for(let e of t.specifiers.specifiers)e.archImport=!0}function Lw(){let e=ey(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function Rw(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof am?Cv.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function zw(e,n,r){let i;if(e instanceof Rp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Rp))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function Bw(e){let t=e.originalSymbol;return ty(this).map(n=>n.filter(n=>n instanceof im&&n.originalSymbol===t&&n!==e))}function Vw(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{if(e instanceof Yh){let t=e.target(this);if(!t)return;let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e);return}for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(D(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof Sm&&O(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=Zf(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Rm(e))t instanceof I&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof zp&&t.isKind(F.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function Hw(e){return this.resolutionIndex().parents.get(e.intern())??[]}function Uw(e){return this.resolutionIndex().references.get(e.intern())??[]}function Ww(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function Gw(e){let t=e.originalSymbol;return ty(this).map(n=>n.filter(n=>n instanceof am&&n.originalSymbol===t&&n!==e))}function Kw(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function qw(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=e.getSource(n)??``;for(let t of e.symbolMetadata(o))if(t instanceof Uh&&Yw(e,t,r)){if(t.declaration instanceof z){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(V);if(!r)continue;let a=W_(r,i.Ref,s);if(!a)continue;return{kind:`inline`,op:n,fullStart:a.start,fullEnd:a.end}}if(t.declaration instanceof R){let e=rp(t.declaration)[0];if(e instanceof V)return{kind:`standalone`,node:e}}}}function Jw(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0?!0:t.length===r.length?t.every((e,t)=>e.name===r[t]):!1}function Yw(e,t,n){let r=t.leftTable(e),i=t.leftColumns(e),a=t.rightTable(e),o=t.rightColumns(e),[s,c]=n.endpoints;return Jw(r,i,s)&&Jw(a,o,c)||Jw(r,i,c)&&Jw(a,o,s)}function Xw(e,t,n){let r=nT(e,t,eT(n.schemaName),n.tableName,F.Table);return{table:r,columns:(n.fieldNames??[]).map(t=>r?e.lookupMembers(r,F.Column,t):void 0)}}function Zw(e,t){let n=e?.originalSymbol.declaration;return!!n&&n===t?.originalSymbol.declaration}function Qw(e,t,n){return!Zw(e,n.table)||t.length!==n.columns.length?!1:t.every((e,t)=>Zw(e,n.columns[t]))}function $w(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=Xw(e,n,r.upstream),c=Xw(e,n,r.downstream);if(!s.table||!c.table)return;let l=e.getSource(n)??``;for(let t of e.symbolMetadata(o)){if(!(t instanceof Wh))continue;let n=t.upstreamTables(e),r=t.upstreamColumns(e),a=t.downstreamTables(e),o=t.downstreamColumns(e);if(!n.some((e,t)=>Qw(n[t],r[t]??[],s)&&Qw(a[t],o[t]??[],c)))continue;if(t.declaration instanceof R)return{kind:`block`,declaration:t.declaration};let u=t.declaration.parentOfKind(V);if(!u)continue;let d=W_(u,i.Dep,l);if(!d)continue;let f=t.declaration.value;if(!(f instanceof B))continue;let p=f.op?.value;if(p)return{kind:`inline`,op:p,fullStart:d.start,fullEnd:d.end}}}function eT(e){return e&&e.length>0?e:y}function tT(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=$v(e);if(t.length===0)return{schema:y,table:``};if(t.length===1)return{schema:y,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function nT(e,n,r,i,a=F.Table){let o=e.parseFile(n).getValue().ast,s=e.nodeSymbol(o).getFiltered(t);if(!s)return;if(r===`public`)return e.lookupMembers(s,a,i)??void 0;let c=e.lookupMembers(s,F.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function rT(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function iT(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(Jv(e.schemaName)),t.push(Jv(e.tableName));for(let n of e.fieldNames??[])t.push(Jv(n));return t.join(`.`)}function aT(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function oT(e,t){if(!e||!(e instanceof R))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function sT(e,t,n){let r=!qv(t),i=!qv(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 cT(e,t,n,r,i,a){return n===i&&r===a?!1:nT(e,t,i,a)!==void 0}function lT(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 rT(n.substring(i,a))===t?{start:i,end:e.end}:null}function uT(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function dT(e,t,n,r,i){let a=[],o=new Set,s=uT(r);for(let r of e){if(rT(i.substring(r.start,r.end))!==n)continue;let e=lT(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function fT(e,n,r){let i=tT(n),a=tT(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=nT(this,e,o,s);if(!u||u instanceof im||cT(this,e,o,s,c,l))return new Map;if(u instanceof am&&u.useSpecifierDeclaration instanceof gm&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return pT(this,e,n,u,c,l)}return mT(this,u,o,s,c,l)}function pT(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=sT(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,Kw(o,c)]])}function mT(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof R))return new Map;let c=s.filepath;if(!c)return new Map;let l=sT(i,a,oT(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:uT(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of dT([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,Kw(r,n))}return m}function hT(e,t){let n=e.parseFile(t).getValue().ast;return e.parsedFileKind(t)===`arch`?n.body.filter(uh):[]}var gT=e=>{let t=dh(e);return t===`node`||t===`group`||fh(e)};function _T(e,t,n){return hT(e,t).find(e=>gT(e)&&mh(e)===n)}var vT=(e,t,n,r)=>e===n&&t===r||e===r&&t===n;function yT(e,t,n,r){for(let i of hT(e,t)){if(dh(i)===`link`){let e=Th(i);if(e&&vT(G(Ch(e.infix.left)),G(Ch(e.infix.right)),n,r))return{kind:`standalone`,declaration:i};continue}if(gT(i))for(let e of Dh(i)){let t=Oh(e);if(t&&vT(mh(i),G(t.target),n,r))return{kind:`inline`,element:i,attribute:e,op:t.op}}}}function bT(e,t,n){let r=e.elementList??[],i=r.indexOf(t);if(r.length===1){let t=e.start;for(;t>0&&n[t-1]===` `;)--t;return{start:t,end:e.end,newText:``}}return i===0?{start:t.start,end:r[1].start,newText:``}:{start:r[i-1].end,end:t.end,newText:``}}function xT(e,t,n){let r=_T(this,e,t);if(!r?.name)return new Map;let i=!r.alias,a=Lh(this,e,F.Element,n)??Lh(this,e,F.StickyNote,n);if(i&&n!==t&&a)return new Map;let o=this.getSource(e)??``,s=o.substring(r.name.start,r.name.end).includes(`"`)||!qv(n)?`"${n}"`:n,c=[{start:r.name.start,end:r.name.end,newText:s}];if(i){let i=qv(n)?n:`${lh(r)} ${s}`;for(let n of ST(hT(this,e),t))c.push({start:n.start,end:n.end,newText:n instanceof Va?i:s})}return new Map([[e.absolute,Kw(o,c)]])}function ST(e,t){let n=e=>D(e)&&G(e)===t,r=[];for(let i of e)switch(r.push(...Dh(i).map(e=>Oh(e)?.target).filter(n)),dh(i)){case`link`:{let e=Th(i);if(!e)break;r.push(...[Ch(e.infix.left),Ch(e.infix.right)].filter(n));break}case`group`:for(let e of bh(i))e instanceof V&&r.push(...[e.callee,...e.args].filter(n));break;case`metadata`:i.name?n(i.name)&&r.push(i.name):i.targetKind?.value===t&&r.push(i.targetKind);break;default:break}return r}function CT(e,t,n,r){if(t.kind===`dep`)return ET(this,e,t,n,r);if(t.kind===`ref`)return DT(this,e,t,n,r);if(t.kind===F.Element)return OT(this,e,t,n,r);if(t.kind===`Link`)return kT(this,e,t,n,r);let i=TT(this,e,t);if(!i)return[];let a=U_(i,n,r,this.getSource(e)??``);return a?[a]:[]}function wT(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:Kw(i,a)}function TT(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case F.Column:{let i=nT(e,t,r,n.table,F.Table);return i?e.lookupMembers(i,F.Column,n.column)?.declaration:void 0}case F.Table:return nT(e,t,r,n.table)?.declaration;case F.Enum:case F.StickyNote:case F.TableGroup:return nT(e,t,r,n.name,n.kind)?.declaration;case F.Schema:return nT(e,t,n.schema,``,F.Schema)?.declaration;default:return}}function ET(e,t,n,r,i){let a=e.getSource(t)??``,o=$w(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=iT(n.upstream),t=iT(n.downstream),s=aT(r,i),c=s?`Dep [${s}] {\n ${e} -> ${t}\n}`:`Dep {\n ${e} -> ${t}\n}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
33
+ `&&i++,{startOffset:r,endOffset:i}}function bS(e){switch(e){case F.Schema:return J.Module;case F.Table:case F.TablePartial:case F.Metadata:return J.Class;case F.Column:case F.TableGroupField:return J.Field;case F.Enum:return J.Enum;case F.EnumField:return J.EnumMember;case F.TableGroup:return J.Struct;default:return J.Text}}function xS(e,t){if(!e||Wa(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===v.NEWLINE&&n.end<=t)return!1}return!0}function X(){return{suggestions:[]}}function SS(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function CS(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:bv(e.insertText??``),quoted:!0}))}}function wS(e,t=`, `){let n=e.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label).join(t);return n?{...e,suggestions:[{label:`* (all)`,insertText:n,insertTextRules:Y.KeepWhitespace,kind:J.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function TS(e,n,r){let i=[],a=new Set,o=e.layout.getSource(r)??``;for(let s of e.layout.getEntrypoints()){if(s.equals(r))continue;let c=e.usableMembers(s).getFiltered(t);if(c)for(let t of[...c.nonSchemaMembers,...c.schemaMembers]){if(!n.includes(t.kind))continue;let c=t.name;!c||a.has(c)||(a.add(c),i.push(ES(e,c,t.kind,s,r,o)))}}return i}function ES(e,t,n,r,i,a){let o=_S(e,t,n,r,i,a),s=[];if(o.topInsert&&s.push({range:{startLineNumber:1,startColumn:1,endLineNumber:1,endColumn:1},text:o.topInsert}),o.removeRange){let e=DS(a,o.removeRange.startOffset),t=DS(a,o.removeRange.endOffset);s.push({range:{startLineNumber:e.line,startColumn:e.column,endLineNumber:t.line,endColumn:t.column},text:``})}return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:bS(n),detail:`from ${r.basename}`,sortText:`zzz_${bS(n).toString().padStart(2,`0`)}_${t}`,range:void 0,additionalTextEdits:s}}function DS(e,t){let n=1,r=1;for(let i=0;i<t&&i<e.length;i++)e[i]===`
34
+ `?(n++,r=1):r++;return{line:n,column:r}}function OS(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof R)||!o.isKind(r.Records)||!(o.body instanceof U)||!o.body||!fg(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof L?kS(e,o):AS(e,o)}function kS(e,n){if(!(n.name instanceof Cm))return X();let r=n.name.argumentList?.elementList||[],i=r.map(n=>e.nodeReferee(n).getFiltered(t));if(!i||i.length===0)return X();let a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Up||r instanceof am))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}});return a.length===0?X():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function AS(e,n){let r=n.parent;if(!(r instanceof R))return X();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof Hp))return X();let a;if(n.name instanceof bm){let r=n.name.elementList,i=r.map(n=>e.nodeReferee(n).getFiltered(t)).filter(e=>e!==void 0);a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Up||r instanceof am))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}})}else{let t=i.mergedColumns(e).flatMap(t=>{let{name:n}=t.canonicalName(e,t.filepath),{name:r}=t.type(e);return{name:n,type:r}});if(!t)return X();a=t}return a.length===0?X():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function jS(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof mm&&n>=o.start&&n<=o.fullEnd)return MS(e,t,n,o,i,r);return null}function MS(e,t,n,r,i,a){if(r.importPath&&fg(n,r.importPath))return LS(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return X();if(r.fromKeyword&&n>r.fromKeyword.end)return LS(e,t,void 0,i,r);if(r.specifiers instanceof gm){if(!r.specifiers.openBrace){let e=IS();return xS(r.useKeyword,n)?SS(e):e}return NS(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof Tm)return X();let o=IS();return xS(r.useKeyword,n)?SS(o):o}function NS(e,t,n,r,i,a){for(let o of r.specifiers){let r=!Number.isNaN(o.start)&&n>=o.start&&n<=o.end,s=a===o.importKind||a===o.asKeyword;if(r||s){if(o.importKind&&n>o.importKind.end){let n=o.getSymbolKind();if(n!==void 0&&n!==F.Schema)return FS(e,t,i,n)}return PS()}}return PS()}function PS(){return{suggestions:Object.keys(Fp).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function FS(e,n,r,i){if(!r)return X();let a=e.layout.resolveFileSpecifier(n,r.value);if(!a)return X();let o=e.usableMembers(a).getFiltered(t);if(!o)return X();let s=new Set;for(let n of o.schemaMembers){let r=e.symbolMembers(n).getFiltered(t)??[];for(let e of r){if(e.kind!==i||e instanceof im&&!e.canBeImported)continue;let t=e.name;t&&(n.isPublicSchema()?s.add(t):s.add(`${n.name}.${t}`))}}return{suggestions:[...s].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:bS(i),range:void 0}))}}function IS(){return{suggestions:[{label:`* from`,detail:`import all`,insertText:"* from '${1:./path}'",insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0},{label:`{ } from`,detail:`import named`,insertText:"{ ${1:type} ${2:name} } from '${3:./path}'",insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function LS(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=dS(r,n);c={startLineNumber:e.startLineNumber,startColumn:e.startColumn+1,endLineNumber:e.endLineNumber,endColumn:e.endColumn-1}}let l=new Map,u=new Map,d=Pa(e.layout.getEntrypoints().flatMap(t=>[...e.reachableFiles(t)]),e=>e.intern());for(let n of d){if(n.equals(t))continue;let r=n.relativeTo(a);if(r.endsWith(`.dbml`)&&(r=r.slice(0,-vo.length)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=mo.resolve(a,d),p=e.layout.isDirectory(f);if(zS(e,n,RS(i))&&u.set(d,!0),l.has(d))continue;let m=s?`'${d}'`:d;l.set(d,{label:d,insertText:m,insertTextRules:Y.KeepWhitespace,kind:p?J.Folder:J.File,sortText:`${p?`2`:`3`}${d}`,range:c})}for(let[e,t]of l)u.get(e)&&(t.sortText=`${t.kind===J.File?`0`:`1`}${e}`,t.detail=`best match`);return{suggestions:[...l.values()]}}function RS(e){let t=e.specifiers;return t instanceof gm?t.specifiers.flatMap(e=>{let t=N(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function zS(e,n,r){if(r.length===0)return!1;let i=e.usableMembers(n).getFiltered(t);return i?r.every(({name:e,kind:t})=>i.nonSchemaMembers.some(n=>n.kind===t&&n.name===e)):!1}var Z={Table:`Table`,TableGroup:`TableGroup`,Enum:`Enum`,Project:`Project`,Ref:`Ref`,Dep:`Dep`,TablePartial:`TablePartial`,Records:`Records`,DiagramView:`DiagramView`,Note:`Note`,Metadata:`Metadata`,Indexes:`indexes`,Checks:`checks`,Tables:`Tables`,TableGroups:`TableGroups`,Notes:`Notes`,Schemas:`Schemas`,Column:`Column`},BS=`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(`.`),VS=[i.HeaderColor,i.Note];VS.map(e=>`${e}: `);var HS=[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique],US=[i.Ref,i.Dep,i.Default,i.Note,i.Check],WS=[...HS,...US],GS=[...HS,...US.map(e=>`${e}: `)],KS=[i.Unique,i.PK],qS=[i.Note,i.Name,i.Type],JS=[...KS,...qS],YS=[...KS,...qS.map(e=>`${e}: `)],XS=[i.Inactive],ZS=[i.Update,i.Delete,i.Color],QS=[...XS,...ZS],$S=[...XS,...ZS.map(e=>`${e}: `)],eC=[i.Note],tC=eC.map(e=>`${e}: `),nC=[i.Name],rC=nC.map(e=>`${e}: `),iC=[`cascade`,`set default`,`set null`,`restrict`],aC=[`btree`,`hash`],oC=[Z.Note,Z.Indexes,Z.Checks,Z.Records],sC=[Z.Table,Z.TableGroup,Z.Enum,Z.Note,Z.Ref,Z.Dep,Z.TablePartial],cC=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=mo.fromUri(String(e.uri)),i=uS(e,t),a=OS(this.compiler,e,t,n,i);if(a!==null)return a;let o=this.compiler.token.flatStream(n),{token:s,index:c}=this.compiler.container.token(n,i),l=c===void 0?o[0]:o[c+1];if([...s?.trailingTrivia||[],...s?.leadingTrivia||[],...l?.leadingTrivia||[]].find(e=>qa(e)&&fg(i,e)))return X();if(c===void 0)return CC();let u=jS(this.compiler,n,i,s,e);if(u!==null)return u;if([v.STRING_LITERAL,v.QUOTED_STRING].includes(s.kind)&&fg(i,s))return X();let d=this.compiler.container.element(n,i);if(this.compiler.container.scopeKind(n,i)===Q.TOPLEVEL||d instanceof R&&d.type&&d.type.start<=i&&d.type.end>=i)return CC();let f=[...this.compiler.container.stack(n,i)].reverse();for(let e of f)if(e instanceof B)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return uC(this.compiler,n,i,e);case`~`:return lC(this.compiler,n,i);default:}else if(e instanceof V)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return uC(this.compiler,n,i,e);case`.`:return bC(this.compiler,n,i,e);default:}else if(e instanceof z)return hC(this.compiler,n,i,e);else if(e instanceof W)return hC(this.compiler,n,i,e);else if(e instanceof bm)return pC(this.compiler,n,i,e);else if(e instanceof xm)return mC(this.compiler,n,i);else if(e instanceof Cm)return NC(this.compiler,n,i,e);else if(e instanceof H)return xC(this.compiler,n,i,e);else if(e instanceof R){if(pg(i,e))return k(e,r.Metadata)?jC(this.compiler,n,i,e):MC(this.compiler,n,i,e);if(e.bodyColon&&i>=e.bodyColon.end||e.body&&fg(i,e.body))return xC(this.compiler,n,i,void 0)}return X()}};function lC(e,t,n){return fC(e,t,n,e.parse.ast(t),[F.TablePartial])}function uC(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.DEP,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=fC(e,t,n,e.container.element(t,n),[F.Table,F.Schema,F.Column]);return xS(r.op,n)?SS(i):i}return X()}function dC(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?CS({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof zp&&e.isPublicSchema())).flatMap(e=>{let t=e.name;if(t===void 0)return[];let r=e.originalFilepath,i=r&&!r.equals(n.filepath)?`from ${r.basename}`:`this file`;return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:bS(e.kind),sortText:bS(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):X()}function fC(e,n,r,i,a){if(i===void 0)return X();let o=i,s={suggestions:[]},c;for(;o;){o instanceof L&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=dC(e,n,a).suggestions,r=e=>{switch(e){case J.Field:return 0;case J.Module:return 1;case J.Class:return 2;default:return 3}};t.sort((e,t)=>r(e.kind)-r(t.kind)),s.suggestions.push(...t)}o=o instanceof R?o.parent:void 0}if(c?.filepath){let t=c.filepath,n=new Set(s.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label));for(let r of TS(e,a,t)){let e=typeof r.label==`string`?r.label:r.label.label;n.has(e)||(n.add(e),s.suggestions.push(r))}}return CS(s)}function pC(e,n,i,a){let o=e.container.scopeKind(n,i),s=e.container.element(n,i),c=[...e.container.stack(n,i)];for(let t of c)if(t instanceof Cm&&t.argumentList===a)return NC(e,n,i,t);if(s instanceof R&&s.isKind(r.Records)&&!(s.name instanceof Cm)&&pg(i,s)){let n=s.parent?e.nodeSymbol(s.parent).getFiltered(t):void 0,r=s.name?e.nodeReferee(s.name).getFiltered(t):void 0,i=n||r;if(i){let t=dC(e,i,[F.Column]);return np(a)?wS(t):t}}switch(o){case Q.INDEXES:return LC(e,n,i);case Q.REF:case Q.DEP:for(;c.length>0;){let t=c.pop();if(t instanceof V&&t.op?.value===`.`)return bC(e,n,i,t)}return DC(e,n,i);default:break}return X()}function mC(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?fC(e,t,n,e.container.element(t,n),[F.Schema,F.Enum,F.EnumField]):X()}function hC(e,t,n,r){let{token:i}=e.container.token(t,n);if([v.COMMA,v.LBRACKET].includes(i?.kind)){let r=gC(e,t,n);return i?.kind===v.COMMA&&xS(i,n)?SS(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return gC(e,t,n);if(r.name instanceof _m){let a=vC(e,t,n,ep(r.name)??``);return i?.kind===v.COLON&&xS(i,n)?SS(a):a}return X()}function gC(e,t,n){let r=e.container.element(t,n);if(r instanceof L)return X();let a=e.container.scopeKind(t,n);if(r.body&&!fg(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=VS;break;case Q.TABLEGROUP:e=[i.Color,i.Note];break;case Q.RECORDS:return{suggestions:[{label:i.Example,insertText:i.Example,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}]};case Q.NOTE:e=[i.Color];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}))}}switch(a){case Q.TABLE:case Q.TABLEPARTIAL:return{suggestions:_C(WS,GS)};case Q.ENUM:return{suggestions:_C(eC,tC)};case Q.INDEXES:return{suggestions:_C(JS,YS)};case Q.REF:return{suggestions:_C(QS,$S)};case Q.DEP:return{suggestions:[i.Note,i.Color].map(e=>({label:e,insertText:`${e}: `,kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))};case Q.CHECKS:return{suggestions:_C(nC,rC)};default:break}return X()}function _C(e,t){return e.map((e,n)=>({label:e,insertText:t[n],kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))}function vC(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:iC.map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:aC.map(e=>({label:e,insertText:`${e}`,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`color`:if(e.container.scopeKind(t,n)===Q.NOTE)return{suggestions:[_o].map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};break;case`default`:return fC(e,t,n,e.container.element(t,n),[F.Schema,F.Enum]);default:break}return X()}function yC(e,n,r){if(!r)return[];let i=[],a=r;for(;a;){let n=e.nodeSymbol(a).getFiltered(t);if(n){let r=e.symbolMembers(n).getFiltered(t);i.push(...r||[])}a=a instanceof R?a.parent:void 0}for(let e of n){let t=i.filter(t=>t.name===e);if(t.length===0)return[];i=t}return i}function bC(e,n,r,i){let a=ip(i)??[];return a.pop(),a.some(e=>!D(e))?X():CS({suggestions:yC(e,a.map(e=>N(e)),e.container.element(n,r)).flatMap(n=>e.symbolMembers(n).getFiltered(t)||[]).flatMap(e=>{let t=e.name;return t===void 0?[]:{label:t,insertText:t,kind:bS(e.kind),range:void 0}})})}function xC(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return TC(e,t,n,i);case Q.PROJECT:return EC(e,t,n,i);case Q.INDEXES:return FC(e,t,n);case Q.ENUM:return wC(e,t,n,i);case Q.REF:case Q.DEP:{let r=DC(e,t,n);return e.container.token(t,n).token?.kind===v.COLON&&xS(e.container.token(t,n).token,n)?SS(r):r}case Q.TABLEGROUP:return PC(e,t);case Q.DIAGRAMVIEW:return BC();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof R){let a=i.parentNode,o=a instanceof U?a.parentNode:void 0;if(o instanceof R&&o.isKind(r.DiagramView))return VC(e,t,n,i)}return X()}default:return X()}}var SC=[Z.Table,Z.TableGroup,Z.Enum,Z.Project,Z.Ref,Z.Dep,Z.TablePartial,Z.Records,Z.DiagramView,Z.Note,Z.Metadata];function CC(){return{suggestions:SC.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function wC(e,t,n,r){return r?.callee&&RC(n,r)===1?fC(e,t,n,e.container.element(t,n),[F.Schema,F.Table,F.Column]):X()}function TC(e,t,n,r){let i=oC;if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))};let a=RC(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:a===1?IC(e,t,n):X()}function EC(e,t,n,r){let i=sC;return!r?.callee||RC(n,r)===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:X()}function DC(e,t,n){return fC(e,t,n,e.container.element(t,n),[F.Schema,F.Table,F.Column])}var OC={[Ip.Table]:[F.Schema,F.Table],[Ip.Column]:[F.Schema,F.Table,F.Column],[Ip.TableGroup]:[F.TableGroup],[Ip.Note]:[F.StickyNote]},kC={[Ip.Table]:Z.Table,[Ip.Column]:Z.Column,[Ip.TableGroup]:Z.TableGroup,[Ip.Note]:Z.Note};function AC(){return{suggestions:Object.values(Ip).map(e=>{let t=kC[e];return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}})}}function jC(e,t,n,r){let i=tv(r);if(!i||n<=r.targetKind.end&&n>=r.targetKind.start)return AC();let a=OC[i];return a?fC(e,t,n,r.parent,a):X()}function MC(e,t,n,i){return i.isKind(r.Records)?fC(e,t,n,i.parent,[F.Schema,F.Table]):X()}function NC(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&fg(i,a.callee),c=a.argumentList&&fg(i,a.argumentList);if(o instanceof R&&o.isKind(r.Records)&&pg(i,o)){if(s)return fC(e,n,i,o.parent,[F.Schema,F.Table]);if(!c)return X();let r=a.callee;if(!r)return X();let l=ip(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return X();let f=dC(e,d,[F.Column]),{argumentList:p}=a;return!p||!np(p)?f:wS(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof H)||o.callee!==a||(N(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return X();let l=dC(e,s,[F.Column]),{argumentList:u}=a;return!u||!np(u)?l:wS(l)}return X()}function PC(e,t){return{suggestions:[...CS({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==F.Table&&e.kind!==F.Schema)return[];let t=e.name;return t===void 0||e instanceof zp&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:bS(e.kind),range:void 0}})}).suggestions,...[Z.Note].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))]}}function FC(e,t,n){return LC(e,t,n)}function IC(e,t,n){return{suggestions:[...BS.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.TypeParameter,sortText:J.TypeParameter.toString().padStart(2,`0`),range:void 0})),...fC(e,t,n,e.container.element(t,n),[F.Enum,F.Schema]).suggestions]}}function LC(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(F.Table))return X();let o=e.symbolMembers(a).getFiltered(t);return o?CS({suggestions:o.flatMap(n=>{let r=n.declaration?e.nodeFullname(n.declaration):void 0,i=r&&!r.hasValue(t)?r.getValue()?.at(-1):void 0;return i?{label:i,insertText:i,insertTextRules:Y.KeepWhitespace,kind:bS(F.Column),range:void 0}:[]})}):X()}function RC(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 zC={label:`*`,insertText:`*`,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0};function BC(){return{suggestions:[...[Z.Tables,Z.TableGroups,Z.Notes,Z.Schemas].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0})),zC]}}function VC(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[zC,...fC(e,t,n,e.parse.ast(t),[F.Table,F.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[zC,...fC(e,t,n,e.parse.ast(t),[F.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[zC,{label:y,insertText:y,insertTextRules:Y.KeepWhitespace,kind:J.Module,range:void 0},...fC(e,t,n,e.parse.ast(t),[F.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[zC,...fC(e,t,n,e.parse.ast(t),[F.StickyNote]).suggestions]};default:return X()}}var HC={comments:{lineComment:`//`,blockComment:[`/*`,`*/`]},brackets:[[`{`,`}`],[`[`,`]`],[`(`,`)`]],autoClosingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:"`",close:"`"}],surroundingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:"`",close:"`"}],indentationRules:{increaseIndentPattern:/^(.*\{[^}]*|\s*[{[].*)$/,decreaseIndentPattern:/^(.*\}.*|\s*[}\]].*)$/}},UC={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`dep`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`,`metadata`],metadataTarget:[`table`,`tablegroup`,`schema`,`column`,`note`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`dep`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`none`,`check`,`tables`,`tablegroups`,`notes`,`schemas`,`inactive`,`example`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>~-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":{cases:{"$3@metadataTarget":[`keyword`,``,`keyword`,``,`identifier`],"@default":[`keyword`,``,`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`identifier`,``,`identifier`]}}],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@metadataTarget":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}};function WC(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:_a(n,e=>!e.isInvalid,r);if(a===-1)return[this.parse.ast(e)];let o=n[a].start,s=this.parse.ast(e),c=[s];for(;;){let e=Im(s).find(e=>fg(o,e));if(e===void 0||e instanceof Va)break;c.push(e),s=e}if(i?.kind===v.COLON)return c;for(;c.length>0;){let n=!1,r=g(c);if(r instanceof H){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
35
+ `&&(c.pop(),n=!0)}else r instanceof B||r instanceof V?this.container.token(e,t).token!==r.op&&(c.pop(),n=!0):r instanceof W?r.listCloseBracket&&r.end<=t&&(c.pop(),n=!0):r instanceof bm?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof xm?r.end<=t&&(c.pop(),n=!0):r instanceof U?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof _m||r.end<t&&(c.pop(),n=!0);if(n){let e=g(c);e instanceof R&&e.end<=t&&c.pop()}if(!n)break}return c}function GC(e,t){let n=this.token.flatStream(e).findIndex(e=>e.start>=t);return n===void 0||n<=0?{token:void 0,index:void 0}:{token:this.token.flatStream(e)[n-1],index:n-1}}function KC(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof R)return n[e];return this.parse.ast(e)}function qC(e,n){let r=this.container.element(e,n);if(!r)return;let i=this.nodeSymbol(r);if(i.hasValue(t))return;let a=this.symbolMembers(i.getValue());if(!a.hasValue(t))return a.getValue()}var Q=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.DEP=6]=`DEP`,e[e.PROJECT=7]=`PROJECT`,e[e.CUSTOM=8]=`CUSTOM`,e[e.TOPLEVEL=9]=`TOPLEVEL`,e[e.TABLEPARTIAL=10]=`TABLEPARTIAL`,e[e.CHECKS=11]=`CHECKS`,e[e.RECORDS=12]=`RECORDS`,e[e.DIAGRAMVIEW=13]=`DIAGRAMVIEW`,e[e.METADATA=14]=`METADATA`,e}({});function JC(e,t){let n=this.container.element(e,t);if(n instanceof L)return Q.TOPLEVEL;switch(n.type?.value.toLowerCase()){case`table`:return Q.TABLE;case`enum`:return Q.ENUM;case`ref`:return Q.REF;case`dep`:return Q.DEP;case`tablegroup`:return Q.TABLEGROUP;case`indexes`:return Q.INDEXES;case`note`:return Q.NOTE;case`project`:return Q.PROJECT;case`tablepartial`:return Q.TABLEPARTIAL;case`checks`:return Q.CHECKS;case`records`:return Q.RECORDS;case`diagramview`:return Q.DIAGRAMVIEW;case`metadata`:return Q.METADATA;default:return Q.CUSTOM}}function YC(e,t){let r=t.originalSymbol;if(r.filepath.equals(e))return n.create(ZC(this,r));let i=[...this.symbolUses(r).getValue(),...this.symbolAliases(r).getValue()].filter(t=>t.filepath.equals(e));for(let e of i){let t=e.name;if(!t)continue;if(t!==r.name)return n.create({schema:``,name:t});let i=XC(this,e);if(i.length>0)return n.create({schema:i.join(`.`),name:t});let a=ZC(this,r);return a?n.create({...a,name:t}):n.create({schema:y,name:t})}return n.create(ZC(this,r))}function XC(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof zp&&e.isKind(F.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function ZC(e,n){if(!n.declaration)return n.name?{schema:y,name:n.name}:void 0;let r=e.nodeFullname(n.declaration).getFiltered(t);if(!r||r.length===0)return n.name?{schema:y,name:n.name}:void 0;let i=r[r.length-1];return{schema:r.length>1?r.slice(0,-1).join(`.`):y,name:i}}function QC(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof mm)||!i.importPath)continue;let t=this.layout.resolveFileSpecifier(e,i.importPath.value);!t||r.has(t.absolute)||(r.add(t.absolute),n.push(t))}return n}function $C(e,t){let n=new Set,r=[],i=[...t],a=0;for(;a<i.length;){let t=i[a++],o=t.intern();if(!n.has(o)){n.add(o),r.push(t);for(let n of e.fileDependencies(t))i.push(n)}}return r}function ew(e){return $C(this,e?[e]:this.layout.getEntrypoints())}function tw(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function nw(e){return this.interpretFile(e).getErrors()}function rw(e){return this.interpretFile(e).getWarnings()}function iw(e){return this.parseFile(e).getValue().tokens}function aw(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.interpretSymbol(r,e).getFiltered(t)}function ow(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.symbolMembers(r).getFiltered(t)}function sw(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function cw(e){return this.parseFile(e).getValue().tokens.filter(dm)}function lw(e,t){let n=this.parse.ast(e);for(;;){let e=Im(n).find(e=>fg(t,e));if(e===void 0)return n;if(e instanceof Va)return e;n=e}}function uw(e){let t=this.validateFile(e),r=this.parseFile(e).getValue().ast,i=this.bindNode(r).map(()=>void 0);return new n(void 0,[...t.getErrors(),...i.getErrors()],[...t.getWarnings(),...i.getWarnings()])}function dw(){let e=Ev(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.bindFile(n);t.set(n.absolute,e)}return t}function fw(e){let{ast:r}=this.parseFile(e).getValue(),i=this.nodeSymbol(r).getFiltered(t);return i?this.interpretSymbol(i,e).map(e=>e===t||!e?void 0:e):n.create(void 0)}function pw(){let e=[],r=[],i=[],a=new Set,o=[];for(let e of this.layout.getEntrypoints())for(let t of this.reachableFiles(e)){let e=t.intern();a.has(e)||(a.add(e),o.push(t))}let s=new Map;for(let a of o){let o=this.parseFile(a);e.push(...o.getErrors()),r.push(...o.getWarnings()),i.push(...o.getInfos());let c=this.bindFile(a);e.push(...c.getErrors()),r.push(...c.getWarnings()),i.push(...c.getInfos());let{ast:l}=o.getValue(),u=this.nodeSymbol(l).getFiltered(t),d=u?this.interpretSymbol(u,a):n.create(t),f=d.getFiltered(t);f&&s.set(a.absolute,f),e.push(...d.getErrors()),r.push(...d.getWarnings()),i.push(...d.getInfos())}let c={};for(let[e,t]of s)c[e]=t;return new n({files:c},e,r,i)}function mw(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var hw=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),gw=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return g(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 v.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case v.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case v.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case v.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},_w=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},vw=class{constructor(e,t,n,r,i={}){this.current=0,this.errors=[],this.contextStack=new gw,this.useSpecifierList=this.contextStack.withContextDo(hw.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(gm,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof hm&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(v.IDENTIFIER)&&lm(this.peek()))break;!Ha(this.previous())&&!this.check(v.RBRACE)&&this.logError(this.peek(),C.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(v.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||this.check(v.STRING_LITERAL)||this.check(v.IDENTIFIER)&&lm(e)||Ua(this.previous(),e))break;G(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===v.EOF?this.logError(e,C.UNEXPECTED_EOF,`Unexpected EOF`):G(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(om(e)||this.check(v.COLON,v.LBRACE,v.LBRACKET))break;G(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COLON,v.LBRACE,v.LBRACKET))break;G(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(hw.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(U,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(v.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||Ua(this.previous(),e))break;G(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(hw.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(Sm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(bm,e);try{this.consume(`Expect an opening parenthesis '('`,v.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(v.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(v.RPAREN);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof I&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,v.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(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(v.RPAREN,v.COMMA))break;G(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(hw.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(W,e);try{this.consume(`Expect an opening bracket '['`,v.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(v.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(v.RBRACKET);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof I&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,v.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;G(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET,v.COLON))break;G(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;G(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new _w(n,r),this.filepath=r,this.options=i}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===v.EOF}advance(){return this.isAtEnd()?g(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?g(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(),C.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(G(this.peek()),this.logError(this.advance(),C.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)G(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(),r=this.nodeFactory.create(L,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Im(e).forEach(t=>{t instanceof I&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(sm(this.peek())||um(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof mm&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(mm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===v.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(Tm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof gm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof Tm?`'*'`:`specifier list`;return lm(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(v.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(hm,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,v.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(v.IDENTIFIER,v.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof I&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an element name`);if(om(this.peek())){e.asKeyword=this.advance();try{if(!this.check(v.IDENTIFIER,v.QUOTED_STRING))throw this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(cm(e.type))try{this.consume(`Expect a metadata target kind`,v.IDENTIFIER),e.targetKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(v.COLON,v.LBRACE,v.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(om(this.peek()))if(e.as=this.advance(),this.check(v.COLON,v.LBRACE,v.LBRACKET))this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(v.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.options.allowBodylessElement&&!this.check(v.LBRACE,v.COLON)||!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,v.LBRACE,v.COLON))return t();try{if(this.match(v.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof R?(G(t),this.logError(t,C.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 $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,v.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof R?this.errors.push(new w(C.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}expression(){let e={args:[]},t=()=>Mm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(H,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Wa(this.previous())||this.logError(n,C.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.RBRACKET,v.RPAREN,v.COMMA,v.COLON].includes(e)}commaExpression(){let e=this.check(v.COMMA)?this.nodeFactory.create(Om,{prevToken:this.previous()}):this.normalExpression();if(!this.check(v.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(Om,{prevToken:this.previous()}));break}if(this.check(v.COMMA)){t.elementList.push(this.nodeFactory.create(Om,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(xm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(v.COMMA));return this.nodeFactory.create(xm,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.LBRACE,v.RBRACKET,v.LBRACKET,v.RPAREN,v.LPAREN,v.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===v.LPAREN){let{left:r}=Ow(n);if(r<e||Ua(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(Cm,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Cm,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===v.LBRACKET){if(Wa(this.previous()))break;try{t=this.nodeFactory.create(km,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(km,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Ba(n)){let r=n,i=Ow(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(vm,{expression:t,op:r})}else{let n=ww(r);if(n.left===null||n.left<=e||Ew(r).right!==null&&Ua(this.previous(),r)&&this.contextStack.top()===hw.BlockExpression)break;this.advance();try{t=this.nodeFactory.create(V,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(V,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Ba(this.peek())){let t={};t.op=this.peek();let n=Ew(t.op);if(n.right===null)throw this.logError(t.op,C.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Om,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(B,t),e.handlerContext)):e}e=this.nodeFactory.create(B,t)}else if(e=this.extractOperand(),e instanceof Om)throw new $(this.peek(),this.nodeFactory.create(Om,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(v.WILDCARD)?this.wildcardExpression():this.check(v.NUMERIC_LITERAL,v.STRING_LITERAL,v.COLOR_LITERAL,v.QUOTED_STRING,v.IDENTIFIER)?this.primaryExpression():this.check(v.FUNCTION_EXPRESSION)?this.functionExpression():this.check(v.LBRACKET)?this.listExpression():this.check(v.LBRACE)?this.blockExpression():this.check(v.LPAREN)?this.tupleExpression():(this.peek().kind===v.EOF?this.logError(this.peek(),C.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),C.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Om,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,v.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(ym,e),t.handlerContext):t}return this.nodeFactory.create(ym,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(Tm,{token:this.previous()})}canBeField(){return this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.COLON}primaryExpression(){if(this.match(v.COLOR_LITERAL,v.STRING_LITERAL,v.NUMERIC_LITERAL))return this.nodeFactory.create(Dm,{expression:this.nodeFactory.create(wm,{literal:this.previous()})});if(this.match(v.QUOTED_STRING,v.IDENTIFIER))return this.nodeFactory.create(Dm,{expression:this.nodeFactory.create(Em,{variable:this.previous()})});throw this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(v.COLON,v.RBRACKET,v.COMMA)){let t=this.peek();this.logError(t,C.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(_m,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(z,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(v.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(z,e)}attributeValue(){let e;try{e=this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==v.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(v.COLON,v.COMMA,v.RBRACKET);)try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(_m,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(_m,{identifiers:e})}logError(e,t,n){this.errors.push(new w(t,n,e))}},yw=e=>({left:e,right:e+1}),bw=e=>({left:null,right:e}),xw=e=>({left:e,right:null}),Sw={left:null,right:null},Cw={".":yw(16),"/":yw(11),"%":yw(11),"+":yw(9),"=":yw(2),"==":yw(4),"!=":yw(4),"-":yw(9),"-?":yw(9),"?-":yw(9),"?-?":yw(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`].map(e=>[e,yw(7)]))};function ww(e){return Cw[e.value]??Sw}var Tw=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`,`!`,`~`].map(e=>[e,bw(15)]));function Ew(e){return Tw[e.value]??Sw}var Dw={"(":xw(14)};function Ow(e){return Dw[e.value]??Sw}function kw(e){let t=this.getSource(e)??``,n=this.lexerOptions();return new Yy(t,e,n).lex().chain(r=>{let i=this.fileKindForParse(e,n.allowFrontMatter?r:void 0);return new vw(t,r,this.nodeIdGenerator,e,this.parserOptions(i)).parse().map(e=>(i===`arch`&&!this.explicitModules&&Aw(e.ast),e))}).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function Aw(e){for(let t of e.body)if(!(!(t instanceof mm)||!(t.specifiers instanceof gm)))for(let e of t.specifiers.specifiers)e.archImport=!0}function jw(){let e=Ev(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function Mw(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof im?H_.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function Nw(e,n,r){let i;if(e instanceof Rp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Rp))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function Pw(e){let t=e.originalSymbol;return Dv(this).map(n=>n.filter(n=>n instanceof rm&&n.originalSymbol===t&&n!==e))}function Fw(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{if(e instanceof Ah){let t=e.target(this);if(!t)return;let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e);return}for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(D(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof bm&&O(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=Zf(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Im(e))t instanceof I&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof zp&&t.isKind(F.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function Iw(e){return this.resolutionIndex().parents.get(e.intern())??[]}function Lw(e){return this.resolutionIndex().references.get(e.intern())??[]}function Rw(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function zw(e){let t=e.originalSymbol;return Dv(this).map(n=>n.filter(n=>n instanceof im&&n.originalSymbol===t&&n!==e))}function Bw(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function Vw(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=e.getSource(n)??``;for(let t of e.symbolMetadata(o))if(t instanceof wh&&Uw(e,t,r)){if(t.declaration instanceof z){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(H);if(!r)continue;let a=l_(r,i.Ref,s);if(!a)continue;return{kind:`inline`,op:n,fullStart:a.start,fullEnd:a.end}}if(t.declaration instanceof R){let e=rp(t.declaration)[0];if(e instanceof H)return{kind:`standalone`,node:e}}}}function Hw(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0?!0:t.length===r.length?t.every((e,t)=>e.name===r[t]):!1}function Uw(e,t,n){let r=t.leftTable(e),i=t.leftColumns(e),a=t.rightTable(e),o=t.rightColumns(e),[s,c]=n.endpoints;return Hw(r,i,s)&&Hw(a,o,c)||Hw(r,i,c)&&Hw(a,o,s)}function Ww(e,t,n){let r=Xw(e,t,Jw(n.schemaName),n.tableName,F.Table);return{table:r,columns:(n.fieldNames??[]).map(t=>r?e.lookupMembers(r,F.Column,t):void 0)}}function Gw(e,t){let n=e?.originalSymbol.declaration;return!!n&&n===t?.originalSymbol.declaration}function Kw(e,t,n){return!Gw(e,n.table)||t.length!==n.columns.length?!1:t.every((e,t)=>Gw(e,n.columns[t]))}function qw(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=Ww(e,n,r.upstream),c=Ww(e,n,r.downstream);if(!s.table||!c.table)return;let l=e.getSource(n)??``;for(let t of e.symbolMetadata(o)){if(!(t instanceof Th))continue;let n=t.upstreamTables(e),r=t.upstreamColumns(e),a=t.downstreamTables(e),o=t.downstreamColumns(e);if(!n.some((e,t)=>Kw(n[t],r[t]??[],s)&&Kw(a[t],o[t]??[],c)))continue;if(t.declaration instanceof R)return{kind:`block`,declaration:t.declaration};let u=t.declaration.parentOfKind(H);if(!u)continue;let d=l_(u,i.Dep,l);if(!d)continue;let f=t.declaration.value;if(!(f instanceof B))continue;let p=f.op?.value;if(p)return{kind:`inline`,op:p,fullStart:d.start,fullEnd:d.end}}}function Jw(e){return e&&e.length>0?e:y}function Yw(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=Tv(e);if(t.length===0)return{schema:y,table:``};if(t.length===1)return{schema:y,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function Xw(e,n,r,i,a=F.Table){let o=e.parseFile(n).getValue().ast,s=e.nodeSymbol(o).getFiltered(t);if(!s)return;if(r===`public`)return e.lookupMembers(s,a,i)??void 0;let c=e.lookupMembers(s,F.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function Zw(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function Qw(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(bv(e.schemaName)),t.push(bv(e.tableName));for(let n of e.fieldNames??[])t.push(bv(n));return t.join(`.`)}function $w(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function eT(e,t){if(!e||!(e instanceof R))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function tT(e,t,n){let r=!yv(t),i=!yv(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 nT(e,t,n,r,i,a){return n===i&&r===a?!1:Xw(e,t,i,a)!==void 0}function rT(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 Zw(n.substring(i,a))===t?{start:i,end:e.end}:null}function iT(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function aT(e,t,n,r,i){let a=[],o=new Set,s=iT(r);for(let r of e){if(Zw(i.substring(r.start,r.end))!==n)continue;let e=rT(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function oT(e,n,r){let i=Yw(n),a=Yw(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=Xw(this,e,o,s);if(!u||u instanceof rm||nT(this,e,o,s,c,l))return new Map;if(u instanceof im&&u.useSpecifierDeclaration instanceof hm&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return sT(this,e,n,u,c,l)}return cT(this,u,o,s,c,l)}function sT(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=tT(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,Bw(o,c)]])}function cT(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof R))return new Map;let c=s.filepath;if(!c)return new Map;let l=tT(i,a,eT(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:iT(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of aT([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,Bw(r,n))}return m}function lT(e,t){let n=e.parseFile(t).getValue().ast;return e.parsedFileKind(t)===`arch`?n.body.filter(Km):[]}var uT=e=>{let t=qm(e);return t===`node`||t===`group`||Jm(e)};function dT(e,t,n){return lT(e,t).find(e=>uT(e)&&Zm(e)===n)}var fT=(e,t,n,r)=>e===n&&t===r||e===r&&t===n;function pT(e,t,n,r){for(let i of lT(e,t)){if(qm(i)===`link`){let e=ch(i);if(e&&fT(Xm(oh(e.infix.left)),Xm(oh(e.infix.right)),n,r))return{kind:`standalone`,declaration:i};continue}if(uT(i))for(let e of uh(i)){let t=dh(e);if(t&&fT(Zm(i),Xm(t.target),n,r))return{kind:`inline`,element:i,attribute:e,op:t.op}}}}function mT(e,t,n){let r=e.elementList??[],i=r.indexOf(t);if(r.length===1){let t=e.start;for(;t>0&&n[t-1]===` `;)--t;return{start:t,end:e.end,newText:``}}return i===0?{start:t.start,end:r[1].start,newText:``}:{start:r[i-1].end,end:t.end,newText:``}}function hT(e,t,n){let r=dT(this,e,t);if(!r?.name)return new Map;let i=!r.alias,a=bh(this,e,F.Element,n)??bh(this,e,F.StickyNote,n);if(i&&n!==t&&a)return new Map;let o=this.getSource(e)??``,s=o.substring(r.name.start,r.name.end).includes(`"`)||!yv(n)?`"${n}"`:n,c=[{start:r.name.start,end:r.name.end,newText:s}];if(i){let i=yv(n)?n:`${Gm(r)} ${s}`;for(let n of gT(lT(this,e),t))c.push({start:n.start,end:n.end,newText:n instanceof Va?i:s})}return new Map([[e.absolute,Bw(o,c)]])}function gT(e,t){let n=e=>D(e)&&Xm(e)===t,r=[];for(let i of e)switch(r.push(...uh(i).map(e=>dh(e)?.target).filter(n)),qm(i)){case`link`:{let e=ch(i);if(!e)break;r.push(...[oh(e.infix.left),oh(e.infix.right)].filter(n));break}case`group`:for(let e of rh(i))e instanceof H&&r.push(...[e.callee,...e.args].filter(n));break;case`metadata`:i.name?n(i.name)&&r.push(i.name):i.targetKind?.value===t&&r.push(i.targetKind);break;default:break}return r}function _T(e,t,n,r){if(t.kind===`dep`)return bT(this,e,t,n,r);if(t.kind===`ref`)return xT(this,e,t,n,r);if(t.kind===F.Element)return ST(this,e,t,n,r);if(t.kind===`Link`)return CT(this,e,t,n,r);let i=yT(this,e,t);if(!i)return[];let a=c_(i,n,r,this.getSource(e)??``);return a?[a]:[]}function vT(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:Bw(i,a)}function yT(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case F.Column:{let i=Xw(e,t,r,n.table,F.Table);return i?e.lookupMembers(i,F.Column,n.column)?.declaration:void 0}case F.Table:return Xw(e,t,r,n.table)?.declaration;case F.Enum:case F.StickyNote:case F.TableGroup:return Xw(e,t,r,n.name,n.kind)?.declaration;case F.Schema:return Xw(e,t,n.schema,``,F.Schema)?.declaration;default:return}}function bT(e,t,n,r,i){let a=e.getSource(t)??``,o=qw(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=Qw(n.upstream),t=Qw(n.downstream),s=$w(r,i),c=s?`Dep [${s}] {\n ${e} -> ${t}\n}`:`Dep {\n ${e} -> ${t}\n}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
36
36
 
37
37
  `+c+`
38
- `}]}let{declaration:s}=o,{body:c}=s;if(c instanceof V){let e=U_(s,r,i,a);if(e)return[e];let t=U_(c,r,i,a);return t?[t]:[]}let l=U_(s,r,i,a);return l?[l]:[]}function DT(e,t,n,r,i){let a=e.getSource(t)??``,o=qw(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=iT(n.endpoints[0]),t=iT(n.endpoints[1]),s=aT(r,i),c=s?`Ref: ${e} ${o.op} ${t} [${s}]`:`Ref: ${e} ${o.op} ${t}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
38
+ `}]}let{declaration:s}=o,{body:c}=s;if(c instanceof H){let e=c_(s,r,i,a);if(e)return[e];let t=c_(c,r,i,a);return t?[t]:[]}let l=c_(s,r,i,a);return l?[l]:[]}function xT(e,t,n,r,i){let a=e.getSource(t)??``,o=Vw(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=Qw(n.endpoints[0]),t=Qw(n.endpoints[1]),s=$w(r,i),c=s?`Ref: ${e} ${o.op} ${t} [${s}]`:`Ref: ${e} ${o.op} ${t}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
39
39
 
40
40
  `+c+`
41
- `}]}let s=U_(o.node,r,i,a);return s?[s]:[]}function OT(e,t,n,r,i){let a=_T(e,t,n.name);if(!a)return[];let o=U_(a,r,i,e.getSource(t)??``);return o?[o]:[]}function kT(e,t,n,r,i){let a=e.getSource(t)??``,o=yT(e,t,n.from,n.to);if(!o)return[];if(o.kind===`inline`){let e=o.attribute.value?.expression;if(i===null||!o.element.attributeList||!e)return[];let t=aT(r,i),n=`Link: ${Jv(mh(o.element)??``)} ${o.op} ${a.substring(e.start,e.end)}`;return[bT(o.element.attributeList,o.attribute,a),{start:a.length,end:a.length,newText:`\n\n${t?`${n} [${t}]`:n}\n`}]}let{declaration:s}=o,c=U_(!Th(s)?.row?.settings&&s.attributeList?s:bh(s)[0],r,i,e.getSource(t)??``);return c?[c]:[]}function AT(e){let t=[],n=new nb(e,bo).lex();if(n.getErrors().length>0)return t;let i=new ww(e,n.getValue(),new pm,bo).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?j(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function jT(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function MT(e,t){e.push(` ${t} { * }`)}function NT(e){return e==null?`null`:e.length===0?`empty`:`items`}function PT(e,t){let n=`DiagramView ${Jv(e)} {`,r=e=>Jv(e.name),i=t?.tables?.map(e=>{let t=Jv(e.name);return e.schemaName===`public`?t:`${Jv(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:NT(t.tables),tableGroups:NT(t.tableGroups),schemas:NT(t.schemas),stickyNotes:NT(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&jT(d,`Tables`,i),c.tableGroups===`items`&&jT(d,`TableGroups`,a),c.schemas===`items`&&jT(d,`Schemas`,o)):u&&MT(d,`Tables`),c.stickyNotes===`items`?jT(d,`Notes`,s):c.stickyNotes===`empty`&&MT(d,`Notes`),d.push(`}`),d.join(`
42
- `)}function FT(e,t,n){let r=this.getSource(e)??``,i=n??AT(r),a=[];for(let e of t){let t=IT(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:Kw(r,a,!0),edits:a}}function IT(e,t,n){switch(t.operation){case`create`:return LT(e,t,n);case`update`:return RT(e,t,n);case`delete`:return zT(e,t,n);default:return[]}}function LT(e,t,n){if(n.find(e=>e.name===t.name))return RT(e,t,n);let r=`
41
+ `}]}let s=c_(o.node,r,i,a);return s?[s]:[]}function ST(e,t,n,r,i){let a=dT(e,t,n.name);if(!a)return[];let o=c_(a,r,i,e.getSource(t)??``);return o?[o]:[]}function CT(e,t,n,r,i){let a=e.getSource(t)??``,o=pT(e,t,n.from,n.to);if(!o)return[];if(o.kind===`inline`){let e=o.attribute.value?.expression;if(i===null||!o.element.attributeList||!e)return[];let t=$w(r,i),n=`Link: ${bv(Zm(o.element)??``)} ${o.op} ${a.substring(e.start,e.end)}`;return[mT(o.element.attributeList,o.attribute,a),{start:a.length,end:a.length,newText:`\n\n${t?`${n} [${t}]`:n}\n`}]}let{declaration:s}=o,c=c_(!ch(s)?.row?.settings&&s.attributeList?s:rh(s)[0],r,i,e.getSource(t)??``);return c?[c]:[]}function wT(e){let t=[],n=new Yy(e,bo).lex();if(n.getErrors().length>0)return t;let i=new vw(e,n.getValue(),new fm,bo).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?j(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function TT(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function ET(e,t){e.push(` ${t} { * }`)}function DT(e){return e==null?`null`:e.length===0?`empty`:`items`}function OT(e,t){let n=`DiagramView ${bv(e)} {`,r=e=>bv(e.name),i=t?.tables?.map(e=>{let t=bv(e.name);return e.schemaName===`public`?t:`${bv(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:DT(t.tables),tableGroups:DT(t.tableGroups),schemas:DT(t.schemas),stickyNotes:DT(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&TT(d,`Tables`,i),c.tableGroups===`items`&&TT(d,`TableGroups`,a),c.schemas===`items`&&TT(d,`Schemas`,o)):u&&ET(d,`Tables`),c.stickyNotes===`items`?TT(d,`Notes`,s):c.stickyNotes===`empty`&&ET(d,`Notes`),d.push(`}`),d.join(`
42
+ `)}function kT(e,t,n){let r=this.getSource(e)??``,i=n??wT(r),a=[];for(let e of t){let t=AT(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:Bw(r,a,!0),edits:a}}function AT(e,t,n){switch(t.operation){case`create`:return jT(e,t,n);case`update`:return MT(e,t,n);case`delete`:return NT(e,t,n);default:return[]}}function jT(e,t,n){if(n.find(e=>e.name===t.name))return MT(e,t,n);let r=`
43
43
 
44
- `+PT(t.name,t.visibleEntities)+`
45
- `;return[{start:e.length,end:e.length,newText:r}]}function RT(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=PT(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function zT(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
44
+ `+OT(t.name,t.visibleEntities)+`
45
+ `;return[{start:e.length,end:e.length,newText:r}]}function MT(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=OT(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function NT(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
46
46
  `;){i--,i>0&&e[i-1]===`\r`&&i--;let t=e.lastIndexOf(`
47
47
  `,i-1)+1;if(e.substring(t,i).trim()!==``){i=r.startIndex,i>0&&e[i-1]===`
48
48
  `&&(i--,i>0&&e[i-1]===`\r`&&i--);break}}return a<e.length&&e[a]===`\r`&&a++,a<e.length&&e[a]===`
49
- `&&a++,[{start:i,end:a,newText:``}]}function BT(e,t){let n=UT(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:ny(t)}}function VT(e){let t=UT(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function HT(e,t){if(UT(e)||!(e instanceof R))return;let n=WT(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${ny(t)}\n`};let r=e.body;if(r instanceof V){let n=r.args.find(e=>e instanceof U);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${ny(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${ny(t)}]`}}}function UT(e){if(!(e instanceof R))return;let t=e.body;if(t&&!(t instanceof V))for(let e of t.body){if(!(e instanceof R)||!e.isKind(r.Note))continue;let t=GT(e);if(t)return{kind:mm.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof V?t.args.find(e=>e instanceof U):void 0);if(n)return KT(n)}function WT(e){let t=e.body;if(!(!t||t instanceof V)&&t.blockCloseBrace)return t.blockCloseBrace.start}function GT(e){let t=e.body;if(t instanceof V)return t.callee??void 0;if(t instanceof H&&t.body[0]instanceof V)return t.body[0].callee??void 0}function KT(e){let t=T(e).getValue()[i.Note];if(!t?.length)return;let n=t[0];if(!n.value)return;let r=e.elementList,a=r.indexOf(n),o=n.start,s=n.end;return r.length===1?(o=e.start,s=e.end):a<r.length-1?s=r[a+1].start:o=r[a-1].end,{kind:mm.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function qT(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...YT(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:Kw(n,r,!0),edits:r}}function JT(e,t){return`Dep [color: ${t}] {\n ${iT(e.upstream)} -> ${iT(e.downstream)}\n}`}function YT(e,t,n,r){let i=$w(e,t,r.edge);switch(r.operation){case`create`:return ZT(n,r,i);case`update`:return i?.kind===`block`?XT(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?XT({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function XT(e,t,n){let r=[];if(e.color!==void 0){let a=U_(t,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=VT(t);e&&r.push(e)}else if(e.note!==void 0){let n=BT(t,e.note)??HT(t,e.note);n&&r.push(n)}return r}function ZT(e,t,n){if(n?.kind===`block`)return XT(t,n.declaration,e);let r=JT(t.edge,t.color??``),i={start:e.length,end:e.length,newText:`
49
+ `&&a++,[{start:i,end:a,newText:``}]}function PT(e,t){let n=LT(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:Ov(t)}}function FT(e){let t=LT(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function IT(e,t){if(LT(e)||!(e instanceof R))return;let n=RT(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${Ov(t)}\n`};let r=e.body;if(r instanceof H){let n=r.args.find(e=>e instanceof W);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${Ov(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${Ov(t)}]`}}}function LT(e){if(!(e instanceof R))return;let t=e.body;if(t&&!(t instanceof H))for(let e of t.body){if(!(e instanceof R)||!e.isKind(r.Note))continue;let t=zT(e);if(t)return{kind:pm.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof H?t.args.find(e=>e instanceof W):void 0);if(n)return BT(n)}function RT(e){let t=e.body;if(!(!t||t instanceof H)&&t.blockCloseBrace)return t.blockCloseBrace.start}function zT(e){let t=e.body;if(t instanceof H)return t.callee??void 0;if(t instanceof U&&t.body[0]instanceof H)return t.body[0].callee??void 0}function BT(e){let t=T(e).getValue()[i.Note];if(!t?.length)return;let n=t[0];if(!n.value)return;let r=e.elementList,a=r.indexOf(n),o=n.start,s=n.end;return r.length===1?(o=e.start,s=e.end):a<r.length-1?s=r[a+1].start:o=r[a-1].end,{kind:pm.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function VT(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...UT(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:Bw(n,r,!0),edits:r}}function HT(e,t){return`Dep [color: ${t}] {\n ${Qw(e.upstream)} -> ${Qw(e.downstream)}\n}`}function UT(e,t,n,r){let i=qw(e,t,r.edge);switch(r.operation){case`create`:return GT(n,r,i);case`update`:return i?.kind===`block`?WT(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?WT({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function WT(e,t,n){let r=[];if(e.color!==void 0){let a=c_(t,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=FT(t);e&&r.push(e)}else if(e.note!==void 0){let n=PT(t,e.note)??IT(t,e.note);n&&r.push(n)}return r}function GT(e,t,n){if(n?.kind===`block`)return WT(t,n.declaration,e);let r=HT(t.edge,t.color??``),i={start:e.length,end:e.length,newText:`
50
50
 
51
51
  `+r+`
52
- `};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var QT={allowFrontMatter:!0},$T=Symbol(`COMPUTING`),eE=class{constructor(e,t,n){this.layout=e,this.nodeIdGenerator=new pm,this.symbolIdGenerator=new Lp,this.symbolFactory=new Ja(this.symbolIdGenerator),this.fileScans=new Map,this.fileKinds=new Map,this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(Fw),this.parseProject=this.globalQuery(Lw),this.validateNode=this.localQuery(ox),this.validateFile=this.localQuery(bw),this.nodeFullname=this.localQuery(cx),this.nodeAlias=this.localQuery(lx),this.nodeSettings=this.localQuery(sx),this.canonicalName=this.globalQuery(tw),this.bindNode=this.globalQuery(Qy),this.bindFile=this.globalQuery(gw),this.bindProject=this.globalQuery(_w),this.interpretSymbol=this.globalQuery(eb),this.interpretMetadata=this.globalQuery(tb),this.interpretFile=this.globalQuery(vw),this.interpretProject=this.globalQuery(yw),this.nodeSymbol=this.globalQuery(Yy),this.nodeMetadata=this.globalQuery($y),this.symbolMembers=this.globalQuery(Xy),this.symbolMembersLookupMap=this.globalQuery(Rw),this.lookupMembers=this.globalQuery(zw),this.nodeReferee=this.globalQuery(Zy),this.resolutionIndex=this.globalQuery(Vw),this.symbolReferences=this.globalQuery(Uw),this.symbolParent=this.globalQuery(Hw),this.symbolMetadata=this.globalQuery(Ww),this.symbolAliases=this.globalQuery(Bw),this.symbolUses=this.globalQuery(Gw),this.fileDependencies=this.localQuery(iw),this.reachableFiles=this.globalQuery(ow),this.usableMembers=this.globalQuery(Ev),this.nodeAtPosition=this.localQuery(hw),this.renameTable=fT.bind(this),this.renameElement=xT.bind(this),this.updateElementSetting=wT.bind(this),this.updateElementSettingEdit=CT.bind(this),this.syncDiagramView=FT.bind(this),this.syncDep=qT.bind(this),this.token={invalidStream:this.localQuery(mw),flatStream:this.localQuery(pw)},this.parse={source:e=>this.getSource(e)||``,ast:(e=bo)=>sw.call(this,e),errors:(e=bo)=>cw.call(this,e),warnings:(e=bo)=>lw.call(this,e),tokens:(e=bo)=>uw.call(this,e),rawDb:(e=bo)=>dw.call(this,e),publicSymbolTable:(e=bo)=>fw.call(this,e)},this.container={stack:this.localQuery(XC),token:this.localQuery(ZC),element:this.localQuery(QC),scope:this.localQuery($C),scopeKind:this.localQuery(ew)},this.explicitModules=t,this.explicitDialect=n,this.dialect=n??{}}getSource(e){return this.layout.getSource(e)}lexerOptions(){return this.explicitDialect?this.explicitDialect.lexer??{}:QT}parserOptions(e){return this.explicitDialect?this.explicitDialect.parser??{}:{allowBodylessElement:e===`arch`}}scanFile(e,t){let n=this.layout.getSource(e)??``,r=e.intern(),i=this.fileScans.get(r);if(i&&i.source===n)return i.scan;let a=lb(t??new nb(n,e,QT).lex().getValue());return this.fileScans.set(r,{source:n,scan:a}),a}fileKind(e){return this.decideKind(e).kind}fileKindForParse(e,t){let n=this.decideKind(e,t);return this.fileKinds.set(e.intern(),{filepath:e,...n}),n.kind}parsedFileKind(e){return this.fileKinds.get(e.intern())?.kind??this.fileKind(e)}decideKind(e,t){let n=this.scanFile(e,t);return ub(n,()=>n.usePaths.flatMap(t=>{let n=this.layout.resolveFileSpecifier(e,t);return n?[this.scanFile(n)]:[]}))}refreshFileKind(e){let t=e.intern(),n=this.fileKinds.get(t);if(!n)return;let r=this.decideKind(e);r.kind!==n.kind&&(this.localCache.delete(t),this.globalCache.clear(),this.fileKinds.set(t,{filepath:e,...r}))}cleanStaleLocalCache(e){let t=this.layout.getSource(e),n=e.absolute,r=this.sourceSnapshot.get(n);if(r!==void 0)if(r!==t){this.localCache.delete(e.intern()),this.globalCache.clear(),this.sourceSnapshot.set(n,t);for(let{filepath:e}of[...this.fileKinds.values()])this.refreshFileKind(e)}else this.fileKinds.get(e.intern())?.dependsOnImports&&this.refreshFileKind(e);else this.sourceSnapshot.set(n,t)}cleanStaleGlobalCache(){let e=this.layout.getEntrypoints(),t=!1;this.entrypointsSnapshot!==void 0&&(this.entrypointsSnapshot.length!==e.length||this.entrypointsSnapshot.some((t,n)=>t.absolute!==e[n].absolute))&&(t=!0),this.entrypointsSnapshot=e;for(let t of aw(this,e))this.cleanStaleLocalCache(t);t&&this.globalCache.clear()}globalQuery(e){let t=Symbol();return((...n)=>{let r=!this.globallyQuerying;r&&(this.globallyQuerying=!0,this.cleanStaleGlobalCache());try{let r=this.globalCache.get(t);r||(r=new Map,this.globalCache.set(t,r));let i=n.length===0?``:n.length===1?fg(n[0]):n.map(e=>fg(e)).join(`\0`),a=r.get(i);if(a){if(a===$T)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,$T);try{let t=e.apply(this,n);return r.set(i,t),t}catch(e){throw r.delete(i),e}}finally{r&&(this.globallyQuerying=!1)}})}localQuery(e){let t=Symbol();return((...n)=>{let[r]=n,i=r instanceof I?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?fg(n[0]):n.map(e=>fg(e)).join(`\0`),s=this.localCache.get(a);s||(s=new Map,this.localCache.set(a,s));let c=s.get(t);if(c||(c=new Map,s.set(t,c)),c.has(o)){let t=c.get(o);if(t===$T)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,$T);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}initMonacoServices(e){let t=e?.autocompletion?.triggerCharacters??[];return{definitionProvider:new yS(this),referenceProvider:new xS(this),autocompletionProvider:new mC(this,{triggerCharacters:t}),diagnosticsProvider:new bS(this),codeActionProvider:new vS(this)}}},tE=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}resolveFileSpecifier(e,t){if(!mo.isRelative(t))return;let n=mo.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:mo.from(n.absolute+`.dbml`)}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(mo.from)}getEntrypoints(){return[...this.files.keys()].map(mo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ARCH_DIAGRAM_TYPES=rb,exports.ArrayNode=jm,exports.AttributeNode=z,exports.BUILTIN_KINDS=$m,exports.BlockExpressionNode=H,exports.CARDINALITY_MANY=tf,exports.CARDINALITY_MAYBE=$d,exports.CARDINALITY_ONE=Qd,exports.CARDINALITY_SOME=ef,exports.CallExpressionNode=Tm,exports.CommaExpressionNode=Cm,exports.CompileError=w,exports.CompileErrorCode=C,exports.Compiler=eE,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=vS,exports.DBMLCompletionItemProvider=mC,exports.DBMLDefinitionProvider=yS,exports.DBMLDiagnosticsProvider=bS,exports.DBMLReferencesProvider=xS,exports.DEFAULT_ENTRY=bo,exports.ElementDeclarationNode=R,exports.ElementKind=r,exports.EmptyNode=Am,exports.FALSY_VALUES=vp,exports.Filepath=mo,exports.FunctionApplicationNode=V,exports.FunctionExpressionNode=xm,exports.GroupExpressionNode=wm,exports.ICON_ALIAS=Ym,exports.ICON_NAMES=Jm,exports.IdentifierStreamNode=vm,exports.InfixExpressionNode=ym,exports.ListExpressionNode=U,exports.LiteralNode=Em,exports.MarkerSeverity=hS,exports.MemoryProjectLayout=tE,exports.MetadataKind=Vh,exports.PostfixExpressionNode=bm,exports.PrefixExpressionNode=B,exports.PrimaryExpressionNode=km,exports.ProgramNode=L,exports.RESERVED=ih,exports.ScopeKind=Q,exports.SymbolKind=F,exports.SyntaxNode=I,exports.SyntaxNodeIdGenerator=pm,exports.SyntaxNodeKind=mm,exports.SyntaxToken=Va,exports.SyntaxTokenKind=v,exports.TRUTHY_VALUES=_p,exports.TupleExpressionNode=Sm,exports.UNHANDLED=t,exports.Uri=iS,exports.UseDeclarationNode=hm,exports.UseSpecifierListNode=_m,exports.UseSpecifierNode=gm,exports.VariableNode=Om,exports.WildcardNode=Dm,exports.addDoubleQuoteIfNeeded=Jv,exports.dbmlLanguageConfig=JC,exports.dbmlModules=Gy,exports.dbmlMonarchTokensProvider=YC,exports.escapeString=Zv,exports.extractNumericLiteral=sp,exports.extractSignedNumber=mp,exports.findDiagramViewBlocks=AT,exports.formatRecordValue=Qv,exports.getMultiplicities=af,exports.getRecordValueType=Lo,exports.getRelationshipOp=df,exports.isArchDiagramType=ib,exports.isBinaryType=Po,exports.isBooleanType=Mo,exports.isDateTimeType=Fo,exports.isEmptyStringLiteral=fp,exports.isEndpointManySide=sf,exports.isEndpointOneSide=of,exports.isEndpointOptional=cf,exports.isEndpointRequired=lf,exports.isFloatType=Ao,exports.isFunctionExpression=pp,exports.isIconName=Qm,exports.isIntegerType=ko,exports.isNullish=dp,exports.isNumericType=jo,exports.isOp=za,exports.isOpToken=Ba,exports.isReserved=oh,exports.isSerialType=Io,exports.isStringType=No,exports.isTriviaToken=Ra,exports.isValidIdentifier=qv,exports.makeCardinalityOptional=ff,exports.makeCardinalityRequired=pf,exports.makeRelationshipRequired=uf,exports.normalizeQualifiedName=Yv,exports.normalizeTypeName=Oo,exports.parseCardinality=Zd,exports.resolveIcon=Xm,exports.splitQualifiedIdentifier=$v,exports.suggestIcon=sh,exports.suggestKind=nh,exports.tryExtractBoolean=yp,exports.tryExtractDateTime=Tp,exports.tryExtractEnum=bp,exports.tryExtractInteger=gp,exports.tryExtractNumeric=hp,exports.tryExtractString=xp,exports.unescapeString=Xv,exports.validateForeignKeys=b_,exports.validatePrimaryKey=u_,exports.validateUnique=g_;
52
+ `};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var KT={allowFrontMatter:!0},qT=Symbol(`COMPUTING`),JT=class{constructor(e,t,n){this.layout=e,this.nodeIdGenerator=new fm,this.symbolIdGenerator=new Lp,this.symbolFactory=new Ja(this.symbolIdGenerator),this.fileScans=new Map,this.fileKinds=new Map,this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(kw),this.parseProject=this.globalQuery(jw),this.validateNode=this.localQuery(ex),this.validateFile=this.localQuery(mw),this.nodeFullname=this.localQuery(nx),this.nodeAlias=this.localQuery(rx),this.nodeSettings=this.localQuery(tx),this.canonicalName=this.globalQuery(YC),this.bindNode=this.globalQuery(Gy),this.bindFile=this.globalQuery(uw),this.bindProject=this.globalQuery(dw),this.interpretSymbol=this.globalQuery(qy),this.interpretMetadata=this.globalQuery(Jy),this.interpretFile=this.globalQuery(fw),this.interpretProject=this.globalQuery(pw),this.nodeSymbol=this.globalQuery(Hy),this.nodeMetadata=this.globalQuery(Ky),this.symbolMembers=this.globalQuery(Uy),this.symbolMembersLookupMap=this.globalQuery(Mw),this.lookupMembers=this.globalQuery(Nw),this.nodeReferee=this.globalQuery(Wy),this.resolutionIndex=this.globalQuery(Fw),this.symbolReferences=this.globalQuery(Lw),this.symbolParent=this.globalQuery(Iw),this.symbolMetadata=this.globalQuery(Rw),this.symbolAliases=this.globalQuery(Pw),this.symbolUses=this.globalQuery(zw),this.fileDependencies=this.localQuery(QC),this.reachableFiles=this.globalQuery(ew),this.usableMembers=this.globalQuery(G_),this.nodeAtPosition=this.localQuery(lw),this.renameTable=oT.bind(this),this.renameElement=hT.bind(this),this.updateElementSetting=vT.bind(this),this.updateElementSettingEdit=_T.bind(this),this.syncDiagramView=kT.bind(this),this.syncDep=VT.bind(this),this.token={invalidStream:this.localQuery(cw),flatStream:this.localQuery(sw)},this.parse={source:e=>this.getSource(e)||``,ast:(e=bo)=>tw.call(this,e),errors:(e=bo)=>nw.call(this,e),warnings:(e=bo)=>rw.call(this,e),tokens:(e=bo)=>iw.call(this,e),rawDb:(e=bo)=>aw.call(this,e),publicSymbolTable:(e=bo)=>ow.call(this,e)},this.container={stack:this.localQuery(WC),token:this.localQuery(GC),element:this.localQuery(KC),scope:this.localQuery(qC),scopeKind:this.localQuery(JC)},this.explicitModules=t,this.explicitDialect=n,this.dialect=n??{}}getSource(e){return this.layout.getSource(e)}lexerOptions(){return this.explicitDialect?this.explicitDialect.lexer??{}:KT}parserOptions(e){return this.explicitDialect?this.explicitDialect.parser??{}:{allowBodylessElement:e===`arch`}}scanFile(e,t){let n=this.layout.getSource(e)??``,r=e.intern(),i=this.fileScans.get(r);if(i&&i.source===n)return i.scan;let a=nb(t??new Yy(n,e,KT).lex().getValue());return this.fileScans.set(r,{source:n,scan:a}),a}fileKind(e){return ib(this.scanFile(e))}fileKindForParse(e,t){let n=ib(this.scanFile(e,t));return this.fileKinds.set(e.intern(),n),n}parsedFileKind(e){return this.fileKinds.get(e.intern())??this.fileKind(e)}cleanStaleLocalCache(e){let t=this.layout.getSource(e),n=e.absolute,r=this.sourceSnapshot.get(n);r===void 0?this.sourceSnapshot.set(n,t):r!==t&&(this.localCache.delete(e.intern()),this.globalCache.clear(),this.sourceSnapshot.set(n,t))}cleanStaleGlobalCache(){let e=this.layout.getEntrypoints(),t=!1;this.entrypointsSnapshot!==void 0&&(this.entrypointsSnapshot.length!==e.length||this.entrypointsSnapshot.some((t,n)=>t.absolute!==e[n].absolute))&&(t=!0),this.entrypointsSnapshot=e;for(let t of $C(this,e))this.cleanStaleLocalCache(t);t&&this.globalCache.clear()}globalQuery(e){let t=Symbol();return((...n)=>{let r=!this.globallyQuerying;r&&(this.globallyQuerying=!0,this.cleanStaleGlobalCache());try{let r=this.globalCache.get(t);r||(r=new Map,this.globalCache.set(t,r));let i=n.length===0?``:n.length===1?qh(n[0]):n.map(e=>qh(e)).join(`\0`),a=r.get(i);if(a){if(a===qT)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,qT);try{let t=e.apply(this,n);return r.set(i,t),t}catch(e){throw r.delete(i),e}}finally{r&&(this.globallyQuerying=!1)}})}localQuery(e){let t=Symbol();return((...n)=>{let[r]=n,i=r instanceof I?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?qh(n[0]):n.map(e=>qh(e)).join(`\0`),s=this.localCache.get(a);s||(s=new Map,this.localCache.set(a,s));let c=s.get(t);if(c||(c=new Map,s.set(t,c)),c.has(o)){let t=c.get(o);if(t===qT)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,qT);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}initMonacoServices(e){let t=e?.autocompletion?.triggerCharacters??[];return{definitionProvider:new pS(this),referenceProvider:new hS(this),autocompletionProvider:new cC(this,{triggerCharacters:t}),diagnosticsProvider:new mS(this),codeActionProvider:new fS(this)}}},YT=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}resolveFileSpecifier(e,t){if(!mo.isRelative(t))return;let n=mo.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:mo.from(n.absolute+`.dbml`)}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(mo.from)}getEntrypoints(){return[...this.files.keys()].map(mo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ARCH_DIAGRAM_TYPES=Xy,exports.ArrayNode=km,exports.AttributeNode=z,exports.BUILTIN_ROLES=fy,exports.BlockExpressionNode=U,exports.CARDINALITY_MANY=tf,exports.CARDINALITY_MAYBE=$d,exports.CARDINALITY_ONE=Qd,exports.CARDINALITY_SOME=ef,exports.CallExpressionNode=Cm,exports.CommaExpressionNode=xm,exports.CompileError=w,exports.CompileErrorCode=C,exports.Compiler=JT,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=fS,exports.DBMLCompletionItemProvider=cC,exports.DBMLDefinitionProvider=pS,exports.DBMLDiagnosticsProvider=mS,exports.DBMLReferencesProvider=hS,exports.DEFAULT_ENTRY=bo,exports.ElementDeclarationNode=R,exports.ElementKind=r,exports.EmptyNode=Om,exports.FALSY_VALUES=vp,exports.Filepath=mo,exports.FunctionApplicationNode=H,exports.FunctionExpressionNode=ym,exports.GroupExpressionNode=Sm,exports.ICON_ALIAS=cy,exports.ICON_NAMES=sy,exports.IdentifierStreamNode=_m,exports.InfixExpressionNode=V,exports.ListExpressionNode=W,exports.LiteralNode=wm,exports.MarkerSeverity=lS,exports.MemoryProjectLayout=YT,exports.MetadataKind=Sh,exports.PostfixExpressionNode=vm,exports.PrefixExpressionNode=B,exports.PrimaryExpressionNode=Dm,exports.ProgramNode=L,exports.ScopeKind=Q,exports.SymbolKind=F,exports.SyntaxNode=I,exports.SyntaxNodeIdGenerator=fm,exports.SyntaxNodeKind=pm,exports.SyntaxToken=Va,exports.SyntaxTokenKind=v,exports.TRUTHY_VALUES=_p,exports.TupleExpressionNode=bm,exports.UNHANDLED=t,exports.Uri=Qx,exports.UseDeclarationNode=mm,exports.UseSpecifierListNode=gm,exports.UseSpecifierNode=hm,exports.VariableNode=Em,exports.WildcardNode=Tm,exports.addDoubleQuoteIfNeeded=bv,exports.dbmlLanguageConfig=HC,exports.dbmlModules=Ry,exports.dbmlMonarchTokensProvider=UC,exports.escapeString=Cv,exports.extractNumericLiteral=sp,exports.extractSignedNumber=mp,exports.findDiagramViewBlocks=wT,exports.formatRecordValue=wv,exports.getMultiplicities=af,exports.getRecordValueType=Lo,exports.getRelationshipOp=df,exports.isArchDiagramType=Zy,exports.isBinaryType=Po,exports.isBooleanType=Mo,exports.isDateTimeType=Fo,exports.isEmptyStringLiteral=fp,exports.isEndpointManySide=sf,exports.isEndpointOneSide=of,exports.isEndpointOptional=cf,exports.isEndpointRequired=lf,exports.isFloatType=Ao,exports.isFunctionExpression=pp,exports.isIconName=dy,exports.isIntegerType=ko,exports.isNullish=dp,exports.isNumericType=jo,exports.isOp=za,exports.isOpToken=Ba,exports.isSerialType=Io,exports.isStringType=No,exports.isTriviaToken=Ra,exports.isValidIdentifier=yv,exports.makeCardinalityOptional=ff,exports.makeCardinalityRequired=pf,exports.makeRelationshipRequired=uf,exports.normalizeQualifiedName=xv,exports.normalizeTypeName=Oo,exports.parseCardinality=Zd,exports.resolveIcon=ly,exports.splitQualifiedIdentifier=Tv,exports.suggestIcon=vy,exports.suggestRole=gy,exports.tryExtractBoolean=yp,exports.tryExtractDateTime=Tp,exports.tryExtractEnum=bp,exports.tryExtractInteger=gp,exports.tryExtractNumeric=hp,exports.tryExtractString=xp,exports.unescapeString=Sv,exports.validateForeignKeys=t_,exports.validatePrimaryKey=Gg,exports.validateUnique=Zg;