@dbml/parse 10.3.0-alpha.0 → 10.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
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 ee(e){return m.call(e)}var te=`[object Null]`,ne=`[object Undefined]`,re=c?c.toStringTag:void 0;function ie(e){return e==null?e===void 0?ne:te:re&&re in Object(e)?p(e):ee(e)}function ae(e){return typeof e==`object`&&!!e}var oe=`[object Symbol]`;function se(e){return typeof e==`symbol`||ae(e)&&ie(e)==oe}function ce(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var le=Array.isArray,ue=1/0,de=c?c.prototype:void 0,fe=de?de.toString:void 0;function pe(e){if(typeof e==`string`)return e;if(le(e))return ce(e,pe)+``;if(se(e))return fe?fe.call(e):``;var t=e+``;return t==`0`&&1/e==-ue?`-0`:t}var me=/\s/;function he(e){for(var t=e.length;t--&&me.test(e.charAt(t)););return t}var ge=/^\s+/;function _e(e){return e&&e.slice(0,he(e)+1).replace(ge,``)}function ve(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var ye=NaN,be=/^[-+]0x[0-9a-f]+$/i,xe=/^0b[01]+$/i,Se=/^0o[0-7]+$/i,Ce=parseInt;function we(e){if(typeof e==`number`)return e;if(se(e))return ye;if(ve(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=ve(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=_e(e);var n=xe.test(e);return n||Se.test(e)?Ce(e.slice(2),n?2:8):be.test(e)?ye:+e}var Te=1/0,Ee=17976931348623157e292;function De(e){return e?(e=we(e),e===Te||e===-Te?(e<0?-1:1)*Ee:e===e?e:0):e===0?e:0}function Oe(e){var t=De(e),n=t%1;return t===t?n?t-n:t:0}function ke(e){return e}var Ae=`[object AsyncFunction]`,je=`[object Function]`,Me=`[object GeneratorFunction]`,Ne=`[object Proxy]`;function Pe(e){if(!ve(e))return!1;var t=ie(e);return t==je||t==Me||t==Ae||t==Ne}var Fe=s[`__core-js_shared__`],Ie=function(){var e=/[^.]+$/.exec(Fe&&Fe.keys&&Fe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Le(e){return!!Ie&&Ie in e}var Re=Function.prototype.toString;function ze(e){if(e!=null){try{return Re.call(e)}catch{}try{return e+``}catch{}}return``}var Be=/[\\^$.*+?()[\]{}|]/g,Ve=/^\[object .+?Constructor\]$/,He=Function.prototype,Ue=Object.prototype,We=He.toString,Ge=Ue.hasOwnProperty,Ke=RegExp(`^`+We.call(Ge).replace(Be,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function qe(e){return!ve(e)||Le(e)?!1:(Pe(e)?Ke:Ve).test(ze(e))}function Je(e,t){return e?.[t]}function Ye(e,t){var n=Je(e,t);return qe(n)?n:void 0}var Xe=Ye(s,`WeakMap`);function Ze(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 Qe(){}var $e=800,et=16,tt=Date.now;function nt(e){var t=0,n=0;return function(){var r=tt(),i=et-(r-n);if(n=r,i>0){if(++t>=$e)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function rt(e){return function(){return e}}var it=function(){try{var e=Ye(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),at=nt(it?function(e,t){return it(e,`toString`,{configurable:!0,enumerable:!1,value:rt(t),writable:!0})}:ke);function ot(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 st(e){return e!==e}function ct(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function lt(e,t,n){return t===t?ct(e,t,n):ot(e,st,n)}function ut(e,t){return!!(e!=null&&e.length)&&lt(e,t,0)>-1}var dt=9007199254740991,ft=/^(?:0|[1-9]\d*)$/;function pt(e,t){var n=typeof e;return t??=dt,!!t&&(n==`number`||n!=`symbol`&&ft.test(e))&&e>-1&&e%1==0&&e<t}function mt(e,t,n){t==`__proto__`&&it?it(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function ht(e,t){return e===t||e!==e&&t!==t}var gt=Math.max;function _t(e,t,n){return t=gt(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=gt(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Ze(e,this,s)}}function vt(e,t){return at(_t(e,t,ke),e+``)}var yt=9007199254740991;function bt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=yt}function xt(e){return e!=null&&bt(e.length)&&!Pe(e)}var St=Object.prototype;function Ct(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||St)}function wt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var Tt=`[object Arguments]`;function Et(e){return ae(e)&&ie(e)==Tt}var Dt=Object.prototype,Ot=Dt.hasOwnProperty,kt=Dt.propertyIsEnumerable,At=Et(function(){return arguments}())?Et:function(e){return ae(e)&&Ot.call(e,`callee`)&&!kt.call(e,`callee`)};function jt(){return!1}var Mt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Nt=Mt&&typeof module==`object`&&module&&!module.nodeType&&module,Pt=Nt&&Nt.exports===Mt?s.Buffer:void 0,Ft=(Pt?Pt.isBuffer:void 0)||jt,It=`[object Arguments]`,Lt=`[object Array]`,Rt=`[object Boolean]`,zt=`[object Date]`,Bt=`[object Error]`,Vt=`[object Function]`,Ht=`[object Map]`,Ut=`[object Number]`,Wt=`[object Object]`,Gt=`[object RegExp]`,Kt=`[object Set]`,qt=`[object String]`,Jt=`[object WeakMap]`,Yt=`[object ArrayBuffer]`,Xt=`[object DataView]`,Zt=`[object Float32Array]`,Qt=`[object Float64Array]`,$t=`[object Int8Array]`,en=`[object Int16Array]`,tn=`[object Int32Array]`,nn=`[object Uint8Array]`,rn=`[object Uint8ClampedArray]`,an=`[object Uint16Array]`,on=`[object Uint32Array]`,sn={};sn[Zt]=sn[Qt]=sn[$t]=sn[en]=sn[tn]=sn[nn]=sn[rn]=sn[an]=sn[on]=!0,sn[It]=sn[Lt]=sn[Yt]=sn[Rt]=sn[Xt]=sn[zt]=sn[Bt]=sn[Vt]=sn[Ht]=sn[Ut]=sn[Wt]=sn[Gt]=sn[Kt]=sn[qt]=sn[Jt]=!1;function cn(e){return ae(e)&&bt(e.length)&&!!sn[ie(e)]}function ln(e){return function(t){return e(t)}}var un=typeof exports==`object`&&exports&&!exports.nodeType&&exports,dn=un&&typeof module==`object`&&module&&!module.nodeType&&module,fn=dn&&dn.exports===un&&a.process,pn=function(){try{return dn&&dn.require&&dn.require(`util`).types||fn&&fn.binding&&fn.binding(`util`)}catch{}}(),mn=pn&&pn.isTypedArray,hn=mn?ln(mn):cn,gn=Object.prototype.hasOwnProperty;function _n(e,t){var n=le(e),r=!n&&At(e),i=!n&&!r&&Ft(e),a=!n&&!r&&!i&&hn(e),o=n||r||i||a,s=o?wt(e.length,String):[],c=s.length;for(var l in e)(t||gn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||pt(l,c)))&&s.push(l);return s}function vn(e,t){return function(n){return e(t(n))}}var yn=vn(Object.keys,Object),bn=Object.prototype.hasOwnProperty;function xn(e){if(!Ct(e))return yn(e);var t=[];for(var n in Object(e))bn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function Sn(e){return xt(e)?_n(e):xn(e)}function Cn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var wn=Object.prototype.hasOwnProperty;function Tn(e){if(!ve(e))return Cn(e);var t=Ct(e),n=[];for(var r in e)r==`constructor`&&(t||!wn.call(e,r))||n.push(r);return n}function En(e){return xt(e)?_n(e,!0):Tn(e)}var Dn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,On=/^\w*$/;function kn(e,t){if(le(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||se(e)?!0:On.test(e)||!Dn.test(e)||t!=null&&e in Object(t)}var An=Ye(Object,`create`);function jn(){this.__data__=An?An(null):{},this.size=0}function Mn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Nn=`__lodash_hash_undefined__`,Pn=Object.prototype.hasOwnProperty;function Fn(e){var t=this.__data__;if(An){var n=t[e];return n===Nn?void 0:n}return Pn.call(t,e)?t[e]:void 0}var In=Object.prototype.hasOwnProperty;function Ln(e){var t=this.__data__;return An?t[e]!==void 0:In.call(t,e)}var Rn=`__lodash_hash_undefined__`;function zn(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=An&&t===void 0?Rn:t,this}function Bn(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])}}Bn.prototype.clear=jn,Bn.prototype.delete=Mn,Bn.prototype.get=Fn,Bn.prototype.has=Ln,Bn.prototype.set=zn;function Vn(){this.__data__=[],this.size=0}function Hn(e,t){for(var n=e.length;n--;)if(ht(e[n][0],t))return n;return-1}var Un=Array.prototype.splice;function Wn(e){var t=this.__data__,n=Hn(t,e);return n<0?!1:(n==t.length-1?t.pop():Un.call(t,n,1),--this.size,!0)}function Gn(e){var t=this.__data__,n=Hn(t,e);return n<0?void 0:t[n][1]}function Kn(e){return Hn(this.__data__,e)>-1}function qn(e,t){var n=this.__data__,r=Hn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function Jn(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])}}Jn.prototype.clear=Vn,Jn.prototype.delete=Wn,Jn.prototype.get=Gn,Jn.prototype.has=Kn,Jn.prototype.set=qn;var Yn=Ye(s,`Map`);function Xn(){this.size=0,this.__data__={hash:new Bn,map:new(Yn||Jn),string:new Bn}}function Zn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Qn(e,t){var n=e.__data__;return Zn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function $n(e){var t=Qn(this,e).delete(e);return this.size-=+!!t,t}function er(e){return Qn(this,e).get(e)}function tr(e){return Qn(this,e).has(e)}function nr(e,t){var n=Qn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function rr(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])}}rr.prototype.clear=Xn,rr.prototype.delete=$n,rr.prototype.get=er,rr.prototype.has=tr,rr.prototype.set=nr;var ir=`Expected a function`;function ar(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(ir);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(ar.Cache||rr),n}ar.Cache=rr;var or=500;function sr(e){var t=ar(e,function(e){return n.size===or&&n.clear(),e}),n=t.cache;return t}var cr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,lr=/\\(\\)?/g,ur=sr(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(cr,function(e,n,r,i){t.push(r?i.replace(lr,`$1`):n||e)}),t});function dr(e){return e==null?``:pe(e)}function fr(e,t){return le(e)?e:kn(e,t)?[e]:ur(dr(e))}var pr=1/0;function mr(e){if(typeof e==`string`||se(e))return e;var t=e+``;return t==`0`&&1/e==-pr?`-0`:t}function hr(e,t){t=fr(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[mr(t[n++])];return n&&n==r?e:void 0}function gr(e,t,n){var r=e==null?void 0:hr(e,t);return r===void 0?n:r}function _r(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var vr=c?c.isConcatSpreadable:void 0;function yr(e){return le(e)||At(e)||!!(vr&&e&&e[vr])}function br(e,t,n,r,i){var a=-1,o=e.length;for(n||=yr,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?br(s,t-1,n,r,i):_r(i,s):r||(i[i.length]=s)}return i}function xr(e){return e!=null&&e.length?br(e,1):[]}function Sr(){this.__data__=new Jn,this.size=0}function Cr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function wr(e){return this.__data__.get(e)}function Tr(e){return this.__data__.has(e)}var Er=200;function Dr(e,t){var n=this.__data__;if(n instanceof Jn){var r=n.__data__;if(!Yn||r.length<Er-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new rr(r)}return n.set(e,t),this.size=n.size,this}function Or(e){var t=this.__data__=new Jn(e);this.size=t.size}Or.prototype.clear=Sr,Or.prototype.delete=Cr,Or.prototype.get=wr,Or.prototype.has=Tr,Or.prototype.set=Dr;function kr(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 Ar(){return[]}var jr=Object.prototype.propertyIsEnumerable,Mr=Object.getOwnPropertySymbols,Nr=Mr?function(e){return e==null?[]:(e=Object(e),kr(Mr(e),function(t){return jr.call(e,t)}))}:Ar;function Pr(e,t,n){var r=t(e);return le(e)?r:_r(r,n(e))}function Fr(e){return Pr(e,Sn,Nr)}var Ir=Ye(s,`DataView`),Lr=Ye(s,`Promise`),Rr=Ye(s,`Set`),zr=`[object Map]`,Br=`[object Object]`,Vr=`[object Promise]`,Hr=`[object Set]`,Ur=`[object WeakMap]`,Wr=`[object DataView]`,Gr=ze(Ir),Kr=ze(Yn),qr=ze(Lr),Jr=ze(Rr),Yr=ze(Xe),Xr=ie;(Ir&&Xr(new Ir(new ArrayBuffer(1)))!=Wr||Yn&&Xr(new Yn)!=zr||Lr&&Xr(Lr.resolve())!=Vr||Rr&&Xr(new Rr)!=Hr||Xe&&Xr(new Xe)!=Ur)&&(Xr=function(e){var t=ie(e),n=t==Br?e.constructor:void 0,r=n?ze(n):``;if(r)switch(r){case Gr:return Wr;case Kr:return zr;case qr:return Vr;case Jr:return Hr;case Yr:return Ur}return t});var Zr=Xr,Qr=s.Uint8Array;function $r(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 ei=`__lodash_hash_undefined__`;function ti(e){return this.__data__.set(e,ei),this}function ni(e){return this.__data__.has(e)}function ri(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new rr;++t<n;)this.add(e[t])}ri.prototype.add=ri.prototype.push=ti,ri.prototype.has=ni;function ii(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 ai(e,t){return e.has(t)}var oi=1,si=2;function ci(e,t,n,r,i,a){var o=n&oi,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&si?new ri:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],ee=t[d];if(r)var te=o?r(ee,m,d,t,e,a):r(m,ee,d,e,t,a);if(te!==void 0){if(te)continue;f=!1;break}if(p){if(!ii(t,function(e,t){if(!ai(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===ee||i(m,ee,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}function li(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function ui(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var di=1,fi=2,pi=`[object Boolean]`,mi=`[object Date]`,hi=`[object Error]`,gi=`[object Map]`,_i=`[object Number]`,vi=`[object RegExp]`,yi=`[object Set]`,bi=`[object String]`,xi=`[object Symbol]`,Si=`[object ArrayBuffer]`,Ci=`[object DataView]`,wi=c?c.prototype:void 0,Ti=wi?wi.valueOf:void 0;function Ei(e,t,n,r,i,a,o){switch(n){case Ci:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Si:return!(e.byteLength!=t.byteLength||!a(new Qr(e),new Qr(t)));case pi:case mi:case _i:return ht(+e,+t);case hi:return e.name==t.name&&e.message==t.message;case vi:case bi:return e==t+``;case gi:var s=li;case yi:var c=r&di;if(s||=ui,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=fi,o.set(e,t);var u=ci(s(e),s(t),r,i,a,o);return o.delete(e),u;case xi:if(Ti)return Ti.call(e)==Ti.call(t)}return!1}var Di=1,Oi=Object.prototype.hasOwnProperty;function ki(e,t,n,r,i,a){var o=n&Di,s=Fr(e),c=s.length;if(c!=Fr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Oi.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var ee=e[u],te=t[u];if(r)var ne=o?r(te,ee,u,t,e,a):r(ee,te,u,e,t,a);if(!(ne===void 0?ee===te||i(ee,te,n,r,a):ne)){p=!1;break}m||=u==`constructor`}if(p&&!m){var re=e.constructor,ie=t.constructor;re!=ie&&`constructor`in e&&`constructor`in t&&!(typeof re==`function`&&re instanceof re&&typeof ie==`function`&&ie instanceof ie)&&(p=!1)}return a.delete(e),a.delete(t),p}var Ai=1,ji=`[object Arguments]`,Mi=`[object Array]`,Ni=`[object Object]`,Pi=Object.prototype.hasOwnProperty;function Fi(e,t,n,r,i,a){var o=le(e),s=le(t),c=o?Mi:Zr(e),l=s?Mi:Zr(t);c=c==ji?Ni:c,l=l==ji?Ni:l;var u=c==Ni,d=l==Ni,f=c==l;if(f&&Ft(e)){if(!Ft(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Or,o||hn(e)?ci(e,t,n,r,i,a):Ei(e,t,c,n,r,i,a);if(!(n&Ai)){var p=u&&Pi.call(e,`__wrapped__`),m=d&&Pi.call(t,`__wrapped__`);if(p||m){var ee=p?e.value():e,te=m?t.value():t;return a||=new Or,i(ee,te,n,r,a)}}return f?(a||=new Or,ki(e,t,n,r,i,a)):!1}function Ii(e,t,n,r,i){return e===t?!0:e==null||t==null||!ae(e)&&!ae(t)?e!==e&&t!==t:Fi(e,t,n,r,Ii,i)}var Li=1,Ri=2;function zi(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 Or;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Ii(u,l,Li|Ri,r,d):f))return!1}}return!0}function Bi(e){return e===e&&!ve(e)}function Vi(e){for(var t=Sn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Bi(i)]}return t}function Hi(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function Ui(e){var t=Vi(e);return t.length==1&&t[0][2]?Hi(t[0][0],t[0][1]):function(n){return n===e||zi(n,e,t)}}function Wi(e,t){return e!=null&&t in Object(e)}function Gi(e,t,n){t=fr(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=mr(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&&bt(i)&&pt(o,i)&&(le(e)||At(e)))}function Ki(e,t){return e!=null&&Gi(e,t,Wi)}var qi=1,Ji=2;function Yi(e,t){return kn(e)&&Bi(t)?Hi(mr(e),t):function(n){var r=gr(n,e);return r===void 0&&r===t?Ki(n,e):Ii(t,r,qi|Ji)}}function Xi(e){return function(t){return t?.[e]}}function Zi(e){return function(t){return hr(t,e)}}function Qi(e){return kn(e)?Xi(mr(e)):Zi(e)}function $i(e){return typeof e==`function`?e:e==null?ke:typeof e==`object`?le(e)?Yi(e[0],e[1]):Ui(e):Qi(e)}function ea(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 ta(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 na=ta();function ra(e,t){return e&&na(e,t,Sn)}function ia(e,t){return function(n,r){if(n==null)return n;if(!xt(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 aa=ia(ra);function oa(e,t,n,r){return aa(e,function(e,i,a){t(r,e,n(e),a)}),r}function sa(e,t){return function(n,r){var i=le(n)?ea:oa,a=t?t():{};return i(n,e,$i(r,2),a)}}function ca(e){return ae(e)&&xt(e)}function la(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 ua=200;function da(e,t,n,r){var i=-1,a=ut,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ce(t,ln(n))),r?(a=la,o=!1):t.length>=ua&&(a=ai,o=!1,t=new ri(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 fa=vt(function(e,t){return ca(e)?da(e,br(t,1,ca,!0)):[]});function h(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function pa(e){return typeof e==`function`?e:ke}function ma(e,t){var n=[];return aa(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ha(e,t){return(le(e)?kr:ma)(e,$i(t,3))}var ga=Math.max,_a=Math.min;function va(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Oe(n),i=n<0?ga(r+i,0):_a(i,r-1)),ot(e,$i(t,3),i,!0)}function ya(e){return e&&e.length?e[0]:void 0}function ba(e,t){var n=-1,r=xt(e)?Array(e.length):[];return aa(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function xa(e,t){return(le(e)?ce:ba)(e,$i(t,3))}function Sa(e,t){return br(xa(e,t),1)}function Ca(e,t){return e==null?e:na(e,pa(t),En)}var wa=Object.prototype.hasOwnProperty,Ta=sa(function(e,t,n){wa.call(e,n)?e[n].push(t):mt(e,n,[t])}),Ea=`[object Map]`,Da=`[object Set]`,Oa=Object.prototype.hasOwnProperty;function ka(e){if(e==null)return!0;if(xt(e)&&(le(e)||typeof e==`string`||typeof e.splice==`function`||Ft(e)||hn(e)||At(e)))return!e.length;var t=Zr(e);if(t==Ea||t==Da)return!e.size;if(Ct(e))return!xn(e).length;for(var n in e)if(Oa.call(e,n))return!1;return!0}var Aa=sa(function(e,t,n){mt(e,n,t)}),g=sa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),ja=Rr&&1/ui(new Rr([,-0]))[1]==1/0?function(e){return new Rr(e)}:Qe,Ma=200;function Na(e,t,n){var r=-1,i=ut,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=la;else if(a>=Ma){var l=t?null:ja(e);if(l)return ui(l);o=!1,i=ai,c=new ri}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 Pa(e){return e&&e.length?Na(e):[]}function Fa(e,t){return e&&e.length?Na(e,$i(t,2)):[]}var Ia=Math.max;function La(e){if(!(e&&e.length))return[];var t=0;return e=kr(e,function(e){if(ca(e))return t=Ia(e.length,t),!0}),wt(t,function(t){return ce(e,Xi(t))})}var Ra=vt(La),_=function(e){return e.SPACE=`<space>`,e.TAB=`<tab>`,e.NEWLINE=`<newline>`,e.COMMA=`<comma>`,e.LPAREN=`<lparen>`,e.RPAREN=`<rparen>`,e.LBRACE=`<lbrace>`,e.RBRACE=`<rbrace>`,e.LBRACKET=`<lbracket>`,e.RBRACKET=`<rbracket>`,e.LANGLE=`<langle>`,e.RANGLE=`<rangle>`,e.OP=`<op>`,e.EOF=`<eof>`,e.NUMERIC_LITERAL=`<number>`,e.STRING_LITERAL=`<string>`,e.COLOR_LITERAL=`<color>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.QUOTED_STRING=`<variable>`,e.IDENTIFIER=`<identifier>`,e.SEMICOLON=`<semicolon>`,e.COLON=`<colon>`,e.SINGLE_LINE_COMMENT=`<single-line-comment>`,e.MULTILINE_COMMENT=`<multiline-comment>`,e.WILDCARD=`<wildcard>`,e}({});function za(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:return!0;default:return!1}}function Ba(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 Va(e){return e!==void 0&&e.kind===`<op>`}var Ha=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 Ua(e){return e.trailingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0}function Wa(e,t){return t.leadingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0||Ua(e)}function Ga(e){return e.trailingTrivia.find(({kind:e})=>[_.SPACE,_.TAB].includes(e))!==void 0}function Ka(e){return e.trailingTrivia.length===0?e.end:Ka(h(e.trailingTrivia))}function qa(e){return e.leadingTrivia.length===0?e.start:qa(e.leadingTrivia[0])}function Ja(e){return[_.SINGLE_LINE_COMMENT,_.MULTILINE_COMMENT].includes(e.kind)}function Ya(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`as`}function Xa(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`use`}function Za(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`metadata`}function Qa(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`from`}function $a(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function eo(e){return!!e?.isInvalid}var to=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},no=/^[A-Za-z]:\//;function ro(e=``){return e&&e.replace(/\\/g,`/`).replace(no,e=>e.toUpperCase())}var io=/^[/\\]{2}/,ao=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,oo=/^[A-Za-z]:$/,so=/^\/([A-Za-z]:)?$/,co=/.(\.[^./]+|\.)$/,lo=function(e){if(e.length===0)return`.`;e=ro(e);let t=e.match(io),n=ho(e),r=e[e.length-1]===`/`;return e=mo(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),oo.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!ho(e)?`/${e}`:e)},uo=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 lo(t)};function fo(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var po=function(...e){e=e.map(e=>ro(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:fo();!i||i.length===0||(t=`${i}/${t}`,n=ho(i))}return t=mo(t,!n),n&&!ho(t)?`/${t}`:t.length>0?t:`.`};function mo(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 ho=function(e){return ao.test(e)},go=function(e){if(e===`..`)return``;let t=co.exec(ro(e));return t&&t[1]||``},_o=function(e,t){let n=po(e).replace(so,`$1`).split(`/`),r=po(t).replace(so,`$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(`/`)},vo=function(e){let t=ro(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&oo.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(ho(e)?`/`:`.`)},yo=function(e,t){let n=ro(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},bo=/^[a-zA-Z]:\//,xo=class e{constructor(e,t={}){let n=lo(e);if(!ho(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(po(t,n))}static fromUri(t){try{let n=new URL(t);return new e(lo(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(lo(t))}}get absolute(){return this.path}get dirname(){return vo(this.path)}get basename(){return yo(this.path)}get extname(){return go(this.path)}resolve(t){return new e(po(this.dirname,t))}join(...t){return new e(uo(this.path,...t))}relativeTo(e){let t=_o(e,this.path);return!t.startsWith(`./`)&&!t.startsWith(`../`)&&![`.`,`..`].includes(t)?`./${t}`:t}toString(){return this.path}equals(e){return this.path===e.path}isParentOf(e){if(this.path===e.path)return!1;let t=this.path.endsWith(`/`)?this.path:`${this.path}/`;return e.path.startsWith(t)}toUri(e={}){let t=e.protocol||this.protocol;if(!t)return this.path;let n=bo.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!ho(lo(e))}};function So(e,t){if(!xo.isRelative(t))return;let n=xo.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:xo.from(n.absolute+`.dbml`)}var Co=[`null`,`true`,`false`],wo=`none`,To=`.dbml`,Eo=[`-`,`+`],v=`public`,Do=xo.from(`/main.dbml`),Oo={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`])},ko={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`])},Ao={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},jo={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`])},Mo={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`])},No={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`])},Po={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function Fo(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function Io(e,t){let n=Fo(e);return t?Oo[t].has(n):Object.values(Oo).some(e=>e.has(n))}function Lo(e,t){let n=Fo(e);return t?ko[t].has(n):Object.values(ko).some(e=>e.has(n))}function Ro(e,t){return Io(e,t)||Lo(e,t)}function zo(e,t){let n=Fo(e);return t?Ao[t].has(n):Object.values(Ao).some(e=>e.has(n))}function Bo(e,t){let n=Fo(e);return t?jo[t].has(n):Object.values(jo).some(e=>e.has(n))}function Vo(e,t){let n=Fo(e);return t?Mo[t].has(n):Object.values(Mo).some(e=>e.has(n))}function Ho(e,t){let n=Fo(e);return t?No[t].has(n):Object.values(No).some(e=>e.has(n))}function Uo(e,t){let n=Fo(e);return t?Po[t].has(n):Object.values(Po).some(e=>e.has(n))}function Wo(e,t){if(t)return`string`;if(Io(e))return`integer`;if(Lo(e))return`real`;if(zo(e))return`bool`;if(Bo(e))return`string`;let n=Fo(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:Ho(e)?`datetime`:e}var Go=class extends Error{},Ko=class extends Go{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},qo=class extends Go{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Jo=class extends Go{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Yo=class extends Go{},Xo=class extends Go{constructor(e){super(`Invalid unit ${e}`)}},Zo=class extends Go{},Qo=class extends Go{constructor(){super(`Zone is an abstract class`)}},y=`numeric`,$o=`short`,es=`long`,ts={year:y,month:y,day:y},ns={year:y,month:$o,day:y},rs={year:y,month:$o,day:y,weekday:$o},is={year:y,month:es,day:y},as={year:y,month:es,day:y,weekday:es},os={hour:y,minute:y},ss={hour:y,minute:y,second:y},cs={hour:y,minute:y,second:y,timeZoneName:$o},ls={hour:y,minute:y,second:y,timeZoneName:es},us={hour:y,minute:y,hourCycle:`h23`},ds={hour:y,minute:y,second:y,hourCycle:`h23`},fs={hour:y,minute:y,second:y,hourCycle:`h23`,timeZoneName:$o},ps={hour:y,minute:y,second:y,hourCycle:`h23`,timeZoneName:es},ms={year:y,month:y,day:y,hour:y,minute:y},hs={year:y,month:y,day:y,hour:y,minute:y,second:y},gs={year:y,month:$o,day:y,hour:y,minute:y},_s={year:y,month:$o,day:y,hour:y,minute:y,second:y},vs={year:y,month:$o,day:y,weekday:$o,hour:y,minute:y},ys={year:y,month:es,day:y,hour:y,minute:y,timeZoneName:$o},bs={year:y,month:es,day:y,hour:y,minute:y,second:y,timeZoneName:$o},xs={year:y,month:es,day:y,weekday:es,hour:y,minute:y,timeZoneName:es},Ss={year:y,month:es,day:y,weekday:es,hour:y,minute:y,second:y,timeZoneName:es},Cs=class{get type(){throw new Qo}get name(){throw new Qo}get ianaName(){return this.name}get isUniversal(){throw new Qo}offsetName(e,t){throw new Qo}formatOffset(e,t){throw new Qo}offset(e){throw new Qo}equals(e){throw new Qo}get isValid(){throw new Qo}},ws=null,Ts=class e extends Cs{static get instance(){return ws===null&&(ws=new e),ws}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return dl(e,t,n)}formatOffset(e,t){return hl(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},Es=new Map;function Ds(e){let t=Es.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`}),Es.set(e,t)),t}var Os={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function ks(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 As(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=Os[t];t===`era`?r[a]=i:x(a)||(r[a]=parseInt(i,10))}return r}var js=new Map,Ms=class e extends Cs{static create(t){let n=js.get(t);return n===void 0&&js.set(t,n=new e(t)),n}static resetCache(){js.clear(),Es.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 dl(e,t,n,this.name)}formatOffset(e,t){return hl(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=Ds(this.name),[r,i,a,o,s,c,l]=n.formatToParts?As(n,t):ks(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=sl({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}},Ns={};function Ps(e,t={}){let n=JSON.stringify([e,t]),r=Ns[n];return r||(r=new Intl.ListFormat(e,t),Ns[n]=r),r}var Fs=new Map;function Is(e,t={}){let n=JSON.stringify([e,t]),r=Fs.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),Fs.set(n,r)),r}var Ls=new Map;function Rs(e,t={}){let n=JSON.stringify([e,t]),r=Ls.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Ls.set(n,r)),r}var zs=new Map;function Bs(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=zs.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),zs.set(i,a)),a}var Vs=null;function Hs(){return Vs||(Vs=new Intl.DateTimeFormat().resolvedOptions().locale,Vs)}var Us=new Map;function Ws(e){let t=Us.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Us.set(e,t)),t}var Gs=new Map;function Ks(e){let t=Gs.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...nc,...t}),Gs.set(e,t)}return t}function qs(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=Is(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=Is(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Js(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Ys(e){let t=[];for(let n=1;n<=12;n++){let r=C.utc(2009,n,1);t.push(e(r))}return t}function Xs(e){let t=[];for(let n=1;n<=7;n++){let r=C.utc(2016,11,13+n);t.push(e(r))}return t}function Zs(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Qs(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Ws(e.locale).numberingSystem===`latn`}var $s=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=Rs(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return $c(this.floor?Math.floor(e):rl(e,3),this.padTo)}},ec=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&&Ms.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=Is(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()}},tc=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Wc()&&(this.rtf=Bs(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):Pl(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},nc={firstDay:1,minimalDays:4,weekend:[6,7]},b=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||Sc.defaultLocale;return new e(o||(a?`en-US`:Hs()),n||Sc.defaultNumberingSystem,r||Sc.defaultOutputCalendar,Xc(i)||Sc.defaultWeekSettings,o)}static resetCache(){Vs=null,Fs.clear(),Ls.clear(),zs.clear(),Us.clear(),Gs.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]=qs(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Js(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??=Qs(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,Xc(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 Zs(this,e,bl,()=>{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]=Ys(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Zs(this,e,wl,()=>{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]=Xs(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Zs(this,void 0,()=>Tl,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[C.utc(2016,11,13,9),C.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Zs(this,e,kl,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[C.utc(-40,1,1),C.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 $s(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new ec(e,this.intl,t)}relFormatter(e={}){return new tc(this.intl,this.isEnglish(),e)}listFormatter(e={}){return Ps(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Ws(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Gc()?Ks(this.locale):nc}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})`}},rc=null,ic=class e extends Cs{static get utcInstance(){return rc===null&&(rc=new e(0)),rc}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(fl(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${hl(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${hl(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return hl(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}},ac=class extends Cs{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 oc(e,t){if(x(e)||e===null)return t;if(e instanceof Cs)return e;if(Hc(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?Ts.instance:n===`utc`||n===`gmt`?ic.utcInstance:ic.parseSpecifier(n)||Ms.create(e)}else if(Bc(e))return ic.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new ac(e)}var sc={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},cc={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]},lc=sc.hanidec.replace(/[\[|\]]/g,``).split(``);function uc(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(sc.hanidec)!==-1)t+=lc.indexOf(e[n]);else for(let e in cc){let[n,i]=cc[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var dc=new Map;function fc(){dc.clear()}function pc({numberingSystem:e},t=``){let n=e||`latn`,r=dc.get(n);r===void 0&&(r=new Map,dc.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${sc[n]}${t}`),r.set(t,i)),i}var mc=()=>Date.now(),hc=`system`,gc=null,_c=null,vc=null,yc=60,bc,xc=null,Sc=class{static get now(){return mc}static set now(e){mc=e}static set defaultZone(e){hc=e}static get defaultZone(){return oc(hc,Ts.instance)}static get defaultLocale(){return gc}static set defaultLocale(e){gc=e}static get defaultNumberingSystem(){return _c}static set defaultNumberingSystem(e){_c=e}static get defaultOutputCalendar(){return vc}static set defaultOutputCalendar(e){vc=e}static get defaultWeekSettings(){return xc}static set defaultWeekSettings(e){xc=Xc(e)}static get twoDigitCutoffYear(){return yc}static set twoDigitCutoffYear(e){yc=e%100}static get throwOnInvalid(){return bc}static set throwOnInvalid(e){bc=e}static resetCaches(){b.resetCache(),Ms.resetCache(),C.resetCache(),fc()}},Cc=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},wc=[0,31,59,90,120,151,181,212,243,273,304,334],Tc=[0,31,60,91,121,152,182,213,244,274,305,335];function Ec(e,t){return new Cc(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function Dc(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 Oc(e,t,n){return n+(il(e)?Tc:wc)[t-1]}function kc(e,t){let n=il(e)?Tc:wc,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function Ac(e,t){return(e-t+7)%7+1}function jc(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Oc(r,i,a),s=Ac(Dc(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=ll(l,t,n)):c>ll(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...gl(e)}}function Mc(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=Ac(Dc(r,1,t),n),s=al(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=al(l)):c>s?(l=r+1,c-=al(r)):l=r;let{month:u,day:d}=kc(l,c);return{year:l,month:u,day:d,...gl(e)}}function Nc(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Oc(t,n,r),...gl(e)}}function Pc(e){let{year:t,ordinal:n}=e,{month:r,day:i}=kc(t,n);return{year:t,month:r,day:i,...gl(e)}}function Fc(e,t){if(!x(e.localWeekday)||!x(e.localWeekNumber)||!x(e.localWeekYear)){if(!x(e.weekday)||!x(e.weekNumber)||!x(e.weekYear))throw new Yo(`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 Ic(e,t=4,n=1){let r=Vc(e.weekYear),i=Zc(e.weekNumber,1,ll(e.weekYear,t,n)),a=Zc(e.weekday,1,7);return r?i?a?!1:Ec(`weekday`,e.weekday):Ec(`week`,e.weekNumber):Ec(`weekYear`,e.weekYear)}function Lc(e){let t=Vc(e.year),n=Zc(e.ordinal,1,al(e.year));return t?n?!1:Ec(`ordinal`,e.ordinal):Ec(`year`,e.year)}function Rc(e){let t=Vc(e.year),n=Zc(e.month,1,12),r=Zc(e.day,1,ol(e.year,e.month));return t?n?r?!1:Ec(`day`,e.day):Ec(`month`,e.month):Ec(`year`,e.year)}function zc(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Zc(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Zc(n,0,59),s=Zc(r,0,59),c=Zc(i,0,999);return a?o?s?c?!1:Ec(`millisecond`,i):Ec(`second`,r):Ec(`minute`,n):Ec(`hour`,t)}function x(e){return e===void 0}function Bc(e){return typeof e==`number`}function Vc(e){return typeof e==`number`&&e%1==0}function Hc(e){return typeof e==`string`}function Uc(e){return Object.prototype.toString.call(e)===`[object Date]`}function Wc(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Gc(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Kc(e){return Array.isArray(e)?e:[e]}function qc(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 Jc(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Yc(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Xc(e){if(e==null)return null;if(typeof e!=`object`)throw new Zo(`Week settings must be an object`);if(!Zc(e.firstDay,1,7)||!Zc(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Zc(e,1,7)))throw new Zo(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Zc(e,t,n){return Vc(e)&&e>=t&&e<=n}function Qc(e,t){return e-t*Math.floor(e/t)}function $c(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function el(e){if(!(x(e)||e===null||e===``))return parseInt(e,10)}function tl(e){if(!(x(e)||e===null||e===``))return parseFloat(e)}function nl(e){if(!(x(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function rl(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 il(e){return e%4==0&&(e%100!=0||e%400==0)}function al(e){return il(e)?366:365}function ol(e,t){let n=Qc(t-1,12)+1,r=e+(t-n)/12;return n===2?il(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function sl(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 cl(e,t,n){return-Ac(Dc(e,1,t),n)+t-1}function ll(e,t=4,n=1){let r=cl(e,t,n),i=cl(e+1,t,n);return(al(e)-r+i)/7}function ul(e){return e>99?e:e>Sc.twoDigitCutoffYear?1900+e:2e3+e}function dl(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 fl(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 pl(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Zo(`Invalid unit value ${e}`);return t}function ml(e,t){let n={};for(let r in e)if(Yc(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=pl(i)}return n}function hl(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}${$c(n,2)}:${$c(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${$c(n,2)}${$c(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function gl(e){return Jc(e,[`hour`,`minute`,`second`,`millisecond`])}var _l=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],vl=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],yl=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function bl(e){switch(e){case`narrow`:return[...yl];case`short`:return[...vl];case`long`:return[..._l];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 xl=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],Sl=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Cl=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function wl(e){switch(e){case`narrow`:return[...Cl];case`short`:return[...Sl];case`long`:return[...xl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var Tl=[`AM`,`PM`],El=[`Before Christ`,`Anno Domini`],Dl=[`BC`,`AD`],Ol=[`B`,`A`];function kl(e){switch(e){case`narrow`:return[...Ol];case`short`:return[...Dl];case`long`:return[...El];default:return null}}function Al(e){return Tl[e.hour<12?0:1]}function jl(e,t){return wl(t)[e.weekday-1]}function Ml(e,t){return bl(t)[e.month-1]}function Nl(e,t){return kl(t)[e.year<0?0:1]}function Pl(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 Fl(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var Il={D:ts,DD:ns,DDD:is,DDDD:as,t:os,tt:ss,ttt:cs,tttt:ls,T:us,TT:ds,TTT:fs,TTTT:ps,f:ms,ff:gs,fff:ys,ffff:xs,F:hs,FF:_s,FFF:bs,FFFF:Ss},Ll=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 Il[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 $c(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?Al(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?Ml(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?jl(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?Nl(t,e):a({era:e},`era`);return Fl(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 Fl(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Rl=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function zl(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Bl(...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 Vl(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 Hl(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=el(t[n+i]);return[r,null,n+i]}}var Ul=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Wl=`(?:${Ul.source}?(?:\\[(${Rl.source})\\])?)?`,Gl=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Kl=RegExp(`${Gl.source}${Wl}`),ql=RegExp(`(?:[Tt]${Kl.source})?`),Jl=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Yl=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Xl=/(\d{4})-?(\d{3})/,Zl=Hl(`weekYear`,`weekNumber`,`weekDay`),Ql=Hl(`year`,`ordinal`),$l=/(\d{4})-(\d\d)-(\d\d)/,eu=RegExp(`${Gl.source} ?(?:${Ul.source}|(${Rl.source}))?`),tu=RegExp(`(?: ${eu.source})?`);function nu(e,t,n){let r=e[t];return x(r)?n:el(r)}function ru(e,t){return[{year:nu(e,t),month:nu(e,t+1,1),day:nu(e,t+2,1)},null,t+3]}function iu(e,t){return[{hours:nu(e,t,0),minutes:nu(e,t+1,0),seconds:nu(e,t+2,0),milliseconds:nl(e[t+3])},null,t+4]}function au(e,t){let n=!e[t]&&!e[t+1],r=fl(e[t+1],e[t+2]);return[{},n?null:ic.instance(r),t+3]}function ou(e,t){return[{},e[t]?Ms.create(e[t]):null,t+1]}var su=RegExp(`^T?${Gl.source}$`),cu=/^-?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 lu(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(tl(n)),months:f(tl(r)),weeks:f(tl(i)),days:f(tl(a)),hours:f(tl(o)),minutes:f(tl(s)),seconds:f(tl(c),c===`-0`),milliseconds:f(nl(l),d)}]}var uu={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function du(e,t,n,r,i,a,o){let s={year:t.length===2?ul(el(t)):el(t),month:vl.indexOf(n)+1,day:el(r),hour:el(i),minute:el(a)};return o&&(s.second=el(o)),e&&(s.weekday=e.length>3?xl.indexOf(e)+1:Sl.indexOf(e)+1),s}var fu=/^(?:(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 pu(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=du(t,i,r,n,a,o,s),p;return p=c?uu[c]:l?0:fl(u,d),[f,new ic(p)]}function mu(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var hu=/^(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$/,gu=/^(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$/,_u=/^(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 vu(e){let[,t,n,r,i,a,o,s]=e;return[du(t,i,r,n,a,o,s),ic.utcInstance]}function yu(e){let[,t,n,r,i,a,o,s]=e;return[du(t,s,n,r,i,a,o),ic.utcInstance]}var bu=zl(Jl,ql),xu=zl(Yl,ql),Su=zl(Xl,ql),Cu=zl(Kl),wu=Bl(ru,iu,au,ou),Tu=Bl(Zl,iu,au,ou),Eu=Bl(Ql,iu,au,ou),Du=Bl(iu,au,ou);function Ou(e){return Vl(e,[bu,wu],[xu,Tu],[Su,Eu],[Cu,Du])}function ku(e){return Vl(mu(e),[fu,pu])}function Au(e){return Vl(e,[hu,vu],[gu,vu],[_u,yu])}function ju(e){return Vl(e,[cu,lu])}var Mu=Bl(iu);function Nu(e){return Vl(e,[su,Mu])}var Pu=zl($l,tu),Fu=zl(eu),Iu=Bl(iu,au,ou);function Lu(e){return Vl(e,[Pu,wu],[Fu,Iu])}var Ru=`Invalid Duration`,zu={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}},Bu={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},...zu},Vu=146097/400,Hu=146097/4800,Uu={years:{quarters:4,months:12,weeks:Vu/7,days:Vu,hours:Vu*24,minutes:Vu*24*60,seconds:Vu*24*60*60,milliseconds:Vu*24*60*60*1e3},quarters:{months:3,weeks:Vu/28,days:Vu/4,hours:Vu*24/4,minutes:Vu*24*60/4,seconds:Vu*24*60*60/4,milliseconds:Vu*24*60*60*1e3/4},months:{weeks:Hu/7,days:Hu,hours:Hu*24,minutes:Hu*24*60,seconds:Hu*24*60*60,milliseconds:Hu*24*60*60*1e3},...zu},Wu=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Gu=Wu.slice(0).reverse();function Ku(e,t,n=!1){return new Xu({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 qu(e,t){let n=t.milliseconds??0;for(let r of Gu.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Ju(e,t){let n=qu(e,t)<0?-1:1;Wu.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),Wu.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 Yu(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Xu=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Uu:Bu;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||b.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 Zo(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:ml(t,e.normalizeUnit),loc:b.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Bc(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Zo(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=ju(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]=Nu(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 Zo(`need to specify a reason the Duration is invalid`);let r=t instanceof Cc?t:new Cc(t,n);if(Sc.throwOnInvalid)throw new Jo(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 Xo(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?Ll.create(this.loc,n).formatDurationFromString(this,e):Ru}toHuman(e={}){if(!this.isValid)return Ru;let t=e.showZeros!==!1,n=Wu.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+=rl(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},C.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?qu(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 Wu)(Yc(n.values,e)||Yc(this.values,e))&&(r[e]=n.get(e)+this.get(e));return Ku(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]=pl(e(this.values[n],n));return Ku(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...ml(t,e.normalizeUnit)};return Ku(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 Ku(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Ju(this.matrix,e),Ku(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Yu(this.normalize().shiftToAll().toObject());return Ku(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 Wu)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;Bc(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Bc(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 Ju(this.matrix,n),Ku(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 Ku(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Yu(this.values);return Ku(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 Wu)if(!t(this.values[n],e.values[n]))return!1;return!0}},Zu=`Invalid Interval`;function Qu(e,t){return!e||!e.isValid?$u.invalid(`missing or invalid start`):!t||!t.isValid?$u.invalid(`missing or invalid end`):t<e?$u.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 $u=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 Zo(`need to specify a reason the Interval is invalid`);let r=t instanceof Cc?t:new Cc(t,n);if(Sc.throwOnInvalid)throw new qo(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=tf(t),i=tf(n);return Qu(r,i)??new e({start:r,end:i})}static after(t,n){let r=Xu.fromDurationLike(n),i=tf(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Xu.fromDurationLike(n),i=tf(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=C.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=C.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Xu.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Xu.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(tf).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=Xu.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()})`:Zu}[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=ts,t={}){return this.isValid?Ll.create(this.s.loc.clone(t),e).formatInterval(this):Zu}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Zu}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Zu}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Zu}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Zu}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Xu.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},ed=class{static hasDST(e=Sc.defaultZone){let t=C.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return Ms.isValidZone(e)}static normalizeZone(e){return oc(e,Sc.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||b.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||b.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||b.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||b.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||b.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||b.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||b.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return b.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return b.create(t,null,`gregory`).eras(e)}static features(){return{relative:Wc(),localeWeek:Gc()}}};function td(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Xu.fromMillis(r).as(`days`))}function nd(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=td(e,t);return(n-n%7)/7}],[`days`,td]],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 rd(e,t,n,r){let[i,a,o,s]=nd(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=Xu.fromObject(a,r);return l.length>0?Xu.fromMillis(c,r).shiftTo(...l).plus(u):u}var id=`missing Intl.DateTimeFormat.formatToParts support`;function S(e,t=e=>e){return{regex:e,deser:([e])=>t(uc(e))}}var ad=`[ \xA0]`,od=new RegExp(ad,`g`);function sd(e){return e.replace(/\./g,`\\.?`).replace(od,ad)}function cd(e){return e.replace(/\./g,``).replace(od,` `).toLowerCase()}function ld(e,t){return e===null?null:{regex:RegExp(e.map(sd).join(`|`)),deser:([n])=>e.findIndex(e=>cd(n)===cd(e))+t}}function ud(e,t){return{regex:e,deser:([,e,t])=>fl(e,t),groups:t}}function dd(e){return{regex:e,deser:([e])=>e}}function fd(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function pd(e,t){let n=pc(t),r=pc(t,`{2}`),i=pc(t,`{3}`),a=pc(t,`{4}`),o=pc(t,`{6}`),s=pc(t,`{1,2}`),c=pc(t,`{1,3}`),l=pc(t,`{1,6}`),u=pc(t,`{1,9}`),d=pc(t,`{2,4}`),f=pc(t,`{4,6}`),p=e=>({regex:RegExp(fd(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return ld(t.eras(`short`),0);case`GG`:return ld(t.eras(`long`),0);case`y`:return S(l);case`yy`:return S(d,ul);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 ld(t.months(`short`,!0),1);case`MMMM`:return ld(t.months(`long`,!0),1);case`L`:return S(s);case`LL`:return S(r);case`LLL`:return ld(t.months(`short`,!1),1);case`LLLL`:return ld(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 dd(u);case`uu`:return dd(s);case`uuu`:return S(n);case`a`:return ld(t.meridiems(),0);case`kkkk`:return S(a);case`kk`:return S(d,ul);case`W`:return S(s);case`WW`:return S(r);case`E`:case`c`:return S(n);case`EEE`:return ld(t.weekdays(`short`,!1),1);case`EEEE`:return ld(t.weekdays(`long`,!1),1);case`ccc`:return ld(t.weekdays(`short`,!0),1);case`cccc`:return ld(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return ud(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return ud(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return dd(/[a-z_+-/]{1,256}?/i);case` `:return dd(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:id};return m.token=e,m}var md={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 hd(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=md[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function gd(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function _d(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Yc(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 vd(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=Ms.create(e.z)),x(e.Z)||(n||=new ic(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=nl(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var yd=null;function bd(){return yd||=C.fromMillis(1555555555555),yd}function xd(e,t){if(e.literal)return e;let n=Ed(Ll.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function Sd(e,t){return Array.prototype.concat(...e.map(e=>xd(e,t)))}var Cd=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=Sd(Ll.parseFormat(t),e),this.units=this.tokens.map(t=>pd(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=gd(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=_d(e,this.regex,this.handlers),[r,i,a]=n?vd(n):[null,null,void 0];if(Yc(n,`a`)&&Yc(n,`H`))throw new Yo(`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 wd(e,t,n){return new Cd(e,n).explainFromTokens(t)}function Td(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=wd(e,t,n);return[r,i,a,o]}function Ed(e,t){if(!e)return null;let n=Ll.create(t,e).dtFormatter(bd()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>hd(t,e,i))}var Dd=`Invalid DateTime`,Od=864e13;function kd(e){return new Cc(`unsupported zone`,`the zone "${e.name}" is not supported`)}function Ad(e){return e.weekData===null&&(e.weekData=jc(e.c)),e.weekData}function jd(e){return e.localWeekData===null&&(e.localWeekData=jc(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function Md(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new C({...n,...t,old:n})}function Nd(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 Pd(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 Fd(e,t,n){return Nd(sl(e),t,n)}function Id(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,ol(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Xu.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]=Nd(sl(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function Ld(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=C.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return C.invalid(new Cc(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function Rd(e,t,n=!0){return e.isValid?Ll.create(b.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function zd(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=$c(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=$c(e.c.month),n===`month`)return i;i+=`-`}else if(i+=$c(e.c.month),n===`month`)return i;return i+=$c(e.c.day),i}function Bd(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+=$c(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=$c(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=$c(e.c.second))}else{if(c+=$c(e.c.minute),o===`minute`)break;s&&(c+=$c(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=$c(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=$c(Math.trunc(-e.o/60)),c+=`:`,c+=$c(Math.trunc(-e.o%60))):(c+=`+`,c+=$c(Math.trunc(e.o/60)),c+=`:`,c+=$c(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Vd={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Hd={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Ud={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Wd=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],Gd=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],Kd=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function qd(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 Xo(e);return t}function Jd(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return qd(e)}}function Yd(e){if($d===void 0&&($d=Sc.now()),e.type!==`iana`)return e.offset($d);let t=e.name,n=ef.get(t);return n===void 0&&(n=e.offset($d),ef.set(t,n)),n}function Xd(e,t){let n=oc(t.zone,Sc.defaultZone);if(!n.isValid)return C.invalid(kd(n));let r=b.fromObject(t),i,a;if(x(e.year))i=Sc.now();else{for(let t of Wd)x(e[t])&&(e[t]=Vd[t]);let t=Rc(e)||zc(e);if(t)return C.invalid(t);let r=Yd(n);[i,a]=Fd(e,r,n)}return new C({ts:i,zone:n,loc:r,o:a})}function Zd(e,t,n){let r=x(n.round)?!0:n.round,i=x(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=rl(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 Qd(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 $d,ef=new Map,C=class e{constructor(e){let t=e.zone||Sc.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new Cc(`invalid input`):null)||(t.isValid?null:kd(t));this.ts=x(e.ts)?Sc.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=Bc(e.o)&&!e.old?e.o:t.offset(this.ts);r=Pd(this.ts,a),n=Number.isNaN(r.year)?new Cc(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||b.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]=Qd(arguments),[n,r,i,a,o,s,c]=t;return Xd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=Qd(arguments),[n,r,i,a,o,s,c]=t;return e.zone=ic.utcInstance,Xd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Uc(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=oc(n.zone,Sc.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:b.fromObject(n)}):e.invalid(kd(i))}static fromMillis(t,n={}){if(!Bc(t))throw new Zo(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>Od?e.invalid(`Timestamp out of range`):new e({ts:t,zone:oc(n.zone,Sc.defaultZone),loc:b.fromObject(n)})}static fromSeconds(t,n={}){if(Bc(t))return new e({ts:t*1e3,zone:oc(n.zone,Sc.defaultZone),loc:b.fromObject(n)});throw new Zo(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=oc(n.zone,Sc.defaultZone);if(!r.isValid)return e.invalid(kd(r));let i=b.fromObject(n),a=ml(t,Jd),{minDaysInFirstWeek:o,startOfWeek:s}=Fc(a,i),c=Sc.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 Yo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Yo(`Can't mix ordinal dates with month/day`);let ee=m||a.weekday&&!p,te,ne,re=Pd(c,l);ee?(te=Gd,ne=Hd,re=jc(re,o,s)):u?(te=Kd,ne=Ud,re=Nc(re)):(te=Wd,ne=Vd);let ie=!1;for(let e of te){let t=a[e];x(t)?ie?a[e]=ne[e]:a[e]=re[e]:ie=!0}let ae=(ee?Ic(a,o,s):u?Lc(a):Rc(a))||zc(a);if(ae)return e.invalid(ae);let[oe,se]=Fd(ee?Mc(a,o,s):u?Pc(a):a,l,r),ce=new e({ts:oe,zone:r,o:se,loc:i});return a.weekday&&p&&t.weekday!==ce.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${ce.toISO()}`):ce.isValid?ce:e.invalid(ce.invalid)}static fromISO(e,t={}){let[n,r]=Ou(e);return Ld(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=ku(e);return Ld(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=Au(e);return Ld(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(x(t)||x(n))throw new Zo(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=Td(b.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):Ld(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]=Lu(e);return Ld(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Zo(`need to specify a reason the DateTime is invalid`);let r=t instanceof Cc?t:new Cc(t,n);if(Sc.throwOnInvalid)throw new Ko(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=Ed(e,b.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return Sd(Ll.parseFormat(e),b.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){$d=void 0,ef.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?Ad(this).weekYear:NaN}get weekNumber(){return this.isValid?Ad(this).weekNumber:NaN}get weekday(){return this.isValid?Ad(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?jd(this).weekday:NaN}get localWeekNumber(){return this.isValid?jd(this).weekNumber:NaN}get localWeekYear(){return this.isValid?jd(this).weekYear:NaN}get ordinal(){return this.isValid?Nc(this.c).ordinal:NaN}get monthShort(){return this.isValid?ed.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?ed.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?ed.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?ed.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=sl(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=Pd(s,a),u=Pd(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[Md(this,{ts:s}),Md(this,{ts:c})]:[this]}get isInLeapYear(){return il(this.year)}get daysInMonth(){return ol(this.year,this.month)}get daysInYear(){return this.isValid?al(this.year):NaN}get weeksInWeekYear(){return this.isValid?ll(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?ll(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=Ll.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(ic.instance(e),t)}toLocal(){return this.setZone(Sc.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=oc(t,Sc.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]=Fd(r,n,t)}return Md(this,{ts:e,zone:t})}else return e.invalid(kd(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return Md(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=ml(e,Jd),{minDaysInFirstWeek:n,startOfWeek:r}=Fc(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 Yo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Yo(`Can't mix ordinal dates with month/day`);let u;i?u=Mc({...jc(this.c,n,r),...t},n,r):x(t.ordinal)?(u={...this.toObject(),...t},x(t.day)&&(u.day=Math.min(ol(u.year,u.month),u.day))):u=Pc({...Nc(this.c),...t});let[d,f]=Fd(u,this.o,this.zone);return Md(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Xu.fromDurationLike(e);return Md(this,Id(this,t))}minus(e){if(!this.isValid)return this;let t=Xu.fromDurationLike(e).negate();return Md(this,Id(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Xu.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?Ll.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):Dd}toLocaleString(e=ts,t={}){return this.isValid?Ll.create(this.loc.clone(t),e).formatDateTime(this):Dd}toLocaleParts(e={}){return this.isValid?Ll.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=qd(a);let o=e===`extended`,s=zd(this,o,a);return Wd.indexOf(a)>=3&&(s+=`T`),s+=Bd(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?zd(this,e===`extended`,qd(t)):null}toISOWeekDate(){return Rd(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=qd(o),(r&&Wd.indexOf(o)>=3?`T`:``)+Bd(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return Rd(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return Rd(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?zd(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`)),Rd(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():Dd}[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 Xu.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Kc(t).map(Xu.normalizeUnit),a=e.valueOf()>this.valueOf(),o=rd(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?$u.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),Zd(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?Zd(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 Zo(`min requires all arguments be DateTimes`);return qc(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Zo(`max requires all arguments be DateTimes`);return qc(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return wd(b.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 Cd(b.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(x(t)||x(n))throw new Zo(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=b.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Zo(`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):Ld(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return ts}static get DATE_MED(){return ns}static get DATE_MED_WITH_WEEKDAY(){return rs}static get DATE_FULL(){return is}static get DATE_HUGE(){return as}static get TIME_SIMPLE(){return os}static get TIME_WITH_SECONDS(){return ss}static get TIME_WITH_SHORT_OFFSET(){return cs}static get TIME_WITH_LONG_OFFSET(){return ls}static get TIME_24_SIMPLE(){return us}static get TIME_24_WITH_SECONDS(){return ds}static get TIME_24_WITH_SHORT_OFFSET(){return fs}static get TIME_24_WITH_LONG_OFFSET(){return ps}static get DATETIME_SHORT(){return ms}static get DATETIME_SHORT_WITH_SECONDS(){return hs}static get DATETIME_MED(){return gs}static get DATETIME_MED_WITH_SECONDS(){return _s}static get DATETIME_MED_WITH_WEEKDAY(){return vs}static get DATETIME_FULL(){return ys}static get DATETIME_FULL_WITH_SECONDS(){return bs}static get DATETIME_HUGE(){return xs}static get DATETIME_HUGE_WITH_SECONDS(){return Ss}};function tf(e){if(C.isDateTime(e))return e;if(e&&e.valueOf&&Bc(e.valueOf()))return C.fromJSDate(e);if(e&&typeof e==`object`)return C.fromObject(e);throw new Zo(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function nf(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 rf=`1`,af=`0..1`,of=`*`,sf=`0..*`,cf=new Map([[`-`,[`1`,`1`]],[`<>`,[`*`,`*`]],[`>`,[`*`,`1`]],[`<`,[`1`,`*`]],[`-?`,[`1`,af]],[`?-`,[af,`1`]],[`?-?`,[af,af]],[`?>`,[sf,`1`]],[`>?`,[`*`,af]],[`?>?`,[sf,af]],[`?<`,[af,`*`]],[`<?`,[`1`,sf]],[`?<?`,[af,sf]],[`?<>`,[sf,`*`]],[`<>?`,[`*`,sf]],[`?<>?`,[sf,sf]]]),lf=new Map([...cf.entries()].map(([e,[t,n]])=>[`${t}-${n}`,e]));function uf(e){return cf.get(e)}function df(e){return nf(e).max===1}function ff(e){return nf(e).max===`*`}function pf(e){return nf(e).min===0}function mf(e){return nf(e).min>=1}function hf(e){return e.replace(/\?/g,``)}function gf(e,t){return lf.get(`${e}-${t}`)??`<>`}function _f(e){let{min:t,max:n}=nf(e);return t===0?e:n===`*`?sf:af}function vf(e){let{min:t,max:n}=nf(e);return t>=1?e:n===`*`?`*`:`1`}function yf(e){let{min:t,max:n}=nf(e);return n===`*`?e:t===0?sf:`*`}var w=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}({}),bf=function(e){return e.RefColumnMismatch=`Mismatched optional ref constraints`,e.RecordValueTypeMismatch=`Record type errors`,e.RecordConstraintViolation=`Record constraint violations`,e.Other=`Other`,e}({}),T=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 xf(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},xf=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,T.prototype)}get filepath(){return this.nodeOrToken.filepath}},Sf=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 Cf(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function wf(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Tf(e){let[t]=e;return wf(t)||Cf(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Ef(e){return Cf(e)||wf(e)}function Df(e){let t=M(e);return t!==void 0&&t.length>0}function Of(e){return kf(e)}function kf(e){return e instanceof Em&&e.expression instanceof Tm}function Af(e){return!!e.bodyColon}function jf(e){return e instanceof V&&e.op?.value===`~`&&O(e.expression)}function Mf(e){return e!==void 0&&cf.has(e)}function Nf(e){return e===`<-`||e===`->`}function Pf(e){if(!(e instanceof Em)||!(e.expression instanceof Cm)||e.expression.literal?.kind!==_.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(!Tf(t[e]))return!1;return!0}function Ff(e){return Pf(e)?!0:Wf(e)&&e.expression.variable.value.toLowerCase()===`none`}function If(e){if(D(e)||Lf(e)||Wf(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof V&&Eo.includes(e.op?.value)&&Lf(e.expression)||e instanceof vm)return!0;if(!e||!Gf(e))return!1;let t=lp(e);return t.length===2||t.length===3}function Lf(e){return e instanceof V?Eo.includes(e.op.value)?Lf(e.expression):!1:e instanceof Em&&e.expression instanceof Cm&&e.expression.literal?.kind===_.NUMERIC_LITERAL}function Rf(e){if(!(e instanceof V)||!Mf(e.op?.value))return!1;let t=M(e.expression);return t!==void 0&&t.length>0}function zf(e){if(!(e instanceof V)||!Nf(e.op?.value))return!1;let t=M(e.expression);return t!==void 0&&t.length>0}function Bf(e){return e instanceof ym&&e.elementList.every(O)}function Vf(e){if(!(e instanceof Sm||k(e)||e instanceof Em||e instanceof Om))return!1;for(;e instanceof Sm||e instanceof Om;)if(e instanceof Sm){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Lf(e)||D(e)||Wf(e)))return!1;e=e.callee}else if(e instanceof Om){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Lf(e.name)))return!1;e=e.array}let t=M(e);return t!==void 0&&t.length>0}function Hf(e){return D(e)||Pf(e)}function E(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof Em){r.push(new T(w.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=ap(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 D(e){return e instanceof Em&&(e.expression instanceof Tm&&e.expression.variable instanceof Ha&&e.expression.variable.kind===_.QUOTED_STRING||e.expression instanceof Cm&&e.expression.literal?.kind===_.STRING_LITERAL)}function O(e){return e instanceof Em&&e.expression instanceof Tm&&e.expression.variable instanceof Ha}function Uf(e){return e?e instanceof wm:!1}function Wf(e){return e instanceof Em&&e.expression instanceof Tm&&e.expression.variable?.kind===_.IDENTIFIER}function k(e){return e instanceof gm&&e.leftExpression instanceof L&&e.rightExpression instanceof L&&e.op?.value===`.`}function Gf(e){return O(e)?!0:k(e)&&O(e.rightExpression)&&Gf(e.leftExpression)}function A(e,t){return e instanceof z&&e.isKind(t)}function Kf(e){return e instanceof fm}function qf(e,t){return e instanceof pm&&(t===void 0||e.isKind(t))}function Jf(e){return e instanceof R}function j(e,...t){return e instanceof H&&e.parent instanceof z&&e.parent.isKind(...t)}function Yf(e,t){let n=e.parent;return n instanceof z&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Xf(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 Zf(e){return!!e.parentOfKind(W)}function Qf(e,t){let n=e.parentOfKind(B);return!n||(n.name instanceof Em?P(n.name):ap(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function $f(e){return!(e instanceof gm)||!Mf(e.op?.value)?!1:up(e.leftExpression)!==void 0&&up(e.rightExpression)!==void 0}function ep(e){let t=up(e.leftExpression),n=up(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function tp(e){return e instanceof Em&&e.expression instanceof Tm||e instanceof vm}function np(e){if(O(e))return e;if(k(e)){let t=e.rightExpression;if(t&&O(t))return t}}function rp(e){let t=e.parentNode;return!k(t)||t.rightExpression!==e?!1:!(k(t.parentNode)&&t.parentNode.leftExpression===t)}function ip(e){if(O(e))return e.expression.variable}function ap(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function op(e){if(!(e instanceof z))return;let t=M(e?.name);return t===void 0?void 0:t.join(`.`)}function sp(e){return e.elementList.length===0}function cp(e){return e?.body?e.body instanceof U?e.body.body:[e.body]:[]}function lp(e){if(!e)return;if(!k(e))return[e];let t=lp(e.leftExpression);if(t)return t.push(e.rightExpression),t}function M(e){if(e===void 0)return;let t=lp(e);if(!t)return;let n=[];for(let e of t){let t=P(e);if(typeof t!=`string`)return;n.push(t)}return n}function up(e){if(e===void 0)return;let t=lp(e);if(!t||t.length===0)return;let n=[];if(!O(h(t))){let e=t.pop();if(Bf(e))n=e.elementList;else return}let r=t;if(r.every(O))return{variables:r,tupleElements:n}}function dp(e){if(tp(e))return e instanceof vm?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof ym&&e.elementList.every(tp))return{functional:e.elementList.filter(e=>e instanceof vm),nonFunctional:e.elementList.filter(O)}}function N(e){if(D(e))return e.expression instanceof Tm?e?.expression?.variable?.value:e.expression.literal.value}function fp(e){return e instanceof Em&&e.expression instanceof Cm&&e.expression.literal?.kind===_.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function pp(e){if(!(e instanceof Sm)||!e.callee)return;let t=lp(e.callee);if(!t||t.length===0||!t.every(O))return;let n=[];return Bf(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function P(e){if(O(e))return e.expression.variable.value}function mp(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function hp(e){if(e.name instanceof hm)return ap(e.name)?.toLowerCase();if(e.name instanceof Em)return P(e.name)}function gp(e){return Wf(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Dm}function _p(e){return N(e)===``}function vp(e){return e instanceof vm}function yp(e){let t=fp(e);if(t!==null)return t;if(Lf(e)&&e instanceof V&&e.expression){let t=e.op?.value,n=fp(e.expression);if(n!==null)return t===`-`?-n:n}return null}function bp(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=yp(e);if(t!==null)return t;let n=N(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function xp(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=yp(e);if(t!==null)return Number.isInteger(t)?t:null;let n=N(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var Sp=[`true`,`yes`,`y`,`t`,`1`],Cp=[`false`,`no`,`n`,`f`,`0`];function wp(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 Sp.includes(t)?!0:Cp.includes(t)?!1:null}if(Wf(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=fp(e);if(t===0)return!1;if(t===1)return!0;let n=N(e)?.toLowerCase();if(n){if(Sp.includes(n))return!0;if(Cp.includes(n))return!1}return null}function Tp(e){if(e==null)return null;if(typeof e==`string`)return e;let t=M(e);return t?h(t):N(e)??null}function Ep(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=N(e)??null??bp(e)??wp(e);return t===null?null:t.toString()}var Dp=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Op=[`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`],kp=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Ap(e){if(e==null)return null;let t=typeof e==`string`?e:N(e)??null;if(t===null)return null;for(let e of kp){let n=C.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of Dp){let n=C.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Op){let n=C.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=C.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 jp(e){return e instanceof V?`${e.op?.value}${jp(e.expression)}`:e.expression.literal.value}function Mp(e){return e instanceof V?e.op?.value===`-`?-Mp(e.expression):Mp(e.expression):Number.parseFloat(e.expression.literal.value)}function F(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 Np(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 ee(e){return m.call(e)}var te=`[object Null]`,ne=`[object Undefined]`,re=c?c.toStringTag:void 0;function ie(e){return e==null?e===void 0?ne:te:re&&re in Object(e)?p(e):ee(e)}function ae(e){return typeof e==`object`&&!!e}var oe=`[object Symbol]`;function se(e){return typeof e==`symbol`||ae(e)&&ie(e)==oe}function ce(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var le=Array.isArray,ue=1/0,de=c?c.prototype:void 0,fe=de?de.toString:void 0;function pe(e){if(typeof e==`string`)return e;if(le(e))return ce(e,pe)+``;if(se(e))return fe?fe.call(e):``;var t=e+``;return t==`0`&&1/e==-ue?`-0`:t}var me=/\s/;function he(e){for(var t=e.length;t--&&me.test(e.charAt(t)););return t}var ge=/^\s+/;function _e(e){return e&&e.slice(0,he(e)+1).replace(ge,``)}function ve(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var ye=NaN,be=/^[-+]0x[0-9a-f]+$/i,xe=/^0b[01]+$/i,Se=/^0o[0-7]+$/i,Ce=parseInt;function we(e){if(typeof e==`number`)return e;if(se(e))return ye;if(ve(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=ve(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=_e(e);var n=xe.test(e);return n||Se.test(e)?Ce(e.slice(2),n?2:8):be.test(e)?ye:+e}var Te=1/0,Ee=17976931348623157e292;function De(e){return e?(e=we(e),e===Te||e===-Te?(e<0?-1:1)*Ee:e===e?e:0):e===0?e:0}function Oe(e){var t=De(e),n=t%1;return t===t?n?t-n:t:0}function ke(e){return e}var Ae=`[object AsyncFunction]`,je=`[object Function]`,Me=`[object GeneratorFunction]`,Ne=`[object Proxy]`;function Pe(e){if(!ve(e))return!1;var t=ie(e);return t==je||t==Me||t==Ae||t==Ne}var Fe=s[`__core-js_shared__`],Ie=function(){var e=/[^.]+$/.exec(Fe&&Fe.keys&&Fe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Le(e){return!!Ie&&Ie in e}var Re=Function.prototype.toString;function ze(e){if(e!=null){try{return Re.call(e)}catch{}try{return e+``}catch{}}return``}var Be=/[\\^$.*+?()[\]{}|]/g,Ve=/^\[object .+?Constructor\]$/,He=Function.prototype,Ue=Object.prototype,We=He.toString,Ge=Ue.hasOwnProperty,Ke=RegExp(`^`+We.call(Ge).replace(Be,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function qe(e){return!ve(e)||Le(e)?!1:(Pe(e)?Ke:Ve).test(ze(e))}function Je(e,t){return e?.[t]}function Ye(e,t){var n=Je(e,t);return qe(n)?n:void 0}var Xe=Ye(s,`WeakMap`);function Ze(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 Qe(){}var $e=800,et=16,tt=Date.now;function nt(e){var t=0,n=0;return function(){var r=tt(),i=et-(r-n);if(n=r,i>0){if(++t>=$e)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function rt(e){return function(){return e}}var it=function(){try{var e=Ye(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),at=nt(it?function(e,t){return it(e,`toString`,{configurable:!0,enumerable:!1,value:rt(t),writable:!0})}:ke);function ot(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 st(e){return e!==e}function ct(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function lt(e,t,n){return t===t?ct(e,t,n):ot(e,st,n)}function ut(e,t){return!!(e!=null&&e.length)&&lt(e,t,0)>-1}var dt=9007199254740991,ft=/^(?:0|[1-9]\d*)$/;function pt(e,t){var n=typeof e;return t??=dt,!!t&&(n==`number`||n!=`symbol`&&ft.test(e))&&e>-1&&e%1==0&&e<t}function mt(e,t,n){t==`__proto__`&&it?it(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function ht(e,t){return e===t||e!==e&&t!==t}var gt=Math.max;function _t(e,t,n){return t=gt(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=gt(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Ze(e,this,s)}}function vt(e,t){return at(_t(e,t,ke),e+``)}var yt=9007199254740991;function bt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=yt}function xt(e){return e!=null&&bt(e.length)&&!Pe(e)}var St=Object.prototype;function Ct(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||St)}function wt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var Tt=`[object Arguments]`;function Et(e){return ae(e)&&ie(e)==Tt}var Dt=Object.prototype,Ot=Dt.hasOwnProperty,kt=Dt.propertyIsEnumerable,At=Et(function(){return arguments}())?Et:function(e){return ae(e)&&Ot.call(e,`callee`)&&!kt.call(e,`callee`)};function jt(){return!1}var Mt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Nt=Mt&&typeof module==`object`&&module&&!module.nodeType&&module,Pt=Nt&&Nt.exports===Mt?s.Buffer:void 0,Ft=(Pt?Pt.isBuffer:void 0)||jt,It=`[object Arguments]`,Lt=`[object Array]`,Rt=`[object Boolean]`,zt=`[object Date]`,Bt=`[object Error]`,Vt=`[object Function]`,Ht=`[object Map]`,Ut=`[object Number]`,Wt=`[object Object]`,Gt=`[object RegExp]`,Kt=`[object Set]`,qt=`[object String]`,Jt=`[object WeakMap]`,Yt=`[object ArrayBuffer]`,Xt=`[object DataView]`,Zt=`[object Float32Array]`,Qt=`[object Float64Array]`,$t=`[object Int8Array]`,en=`[object Int16Array]`,tn=`[object Int32Array]`,nn=`[object Uint8Array]`,rn=`[object Uint8ClampedArray]`,an=`[object Uint16Array]`,on=`[object Uint32Array]`,sn={};sn[Zt]=sn[Qt]=sn[$t]=sn[en]=sn[tn]=sn[nn]=sn[rn]=sn[an]=sn[on]=!0,sn[It]=sn[Lt]=sn[Yt]=sn[Rt]=sn[Xt]=sn[zt]=sn[Bt]=sn[Vt]=sn[Ht]=sn[Ut]=sn[Wt]=sn[Gt]=sn[Kt]=sn[qt]=sn[Jt]=!1;function cn(e){return ae(e)&&bt(e.length)&&!!sn[ie(e)]}function ln(e){return function(t){return e(t)}}var un=typeof exports==`object`&&exports&&!exports.nodeType&&exports,dn=un&&typeof module==`object`&&module&&!module.nodeType&&module,fn=dn&&dn.exports===un&&a.process,pn=function(){try{return dn&&dn.require&&dn.require(`util`).types||fn&&fn.binding&&fn.binding(`util`)}catch{}}(),mn=pn&&pn.isTypedArray,hn=mn?ln(mn):cn,gn=Object.prototype.hasOwnProperty;function _n(e,t){var n=le(e),r=!n&&At(e),i=!n&&!r&&Ft(e),a=!n&&!r&&!i&&hn(e),o=n||r||i||a,s=o?wt(e.length,String):[],c=s.length;for(var l in e)(t||gn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||pt(l,c)))&&s.push(l);return s}function vn(e,t){return function(n){return e(t(n))}}var yn=vn(Object.keys,Object),bn=Object.prototype.hasOwnProperty;function xn(e){if(!Ct(e))return yn(e);var t=[];for(var n in Object(e))bn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function Sn(e){return xt(e)?_n(e):xn(e)}function Cn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var wn=Object.prototype.hasOwnProperty;function Tn(e){if(!ve(e))return Cn(e);var t=Ct(e),n=[];for(var r in e)r==`constructor`&&(t||!wn.call(e,r))||n.push(r);return n}function En(e){return xt(e)?_n(e,!0):Tn(e)}var Dn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,On=/^\w*$/;function kn(e,t){if(le(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||se(e)?!0:On.test(e)||!Dn.test(e)||t!=null&&e in Object(t)}var An=Ye(Object,`create`);function jn(){this.__data__=An?An(null):{},this.size=0}function Mn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Nn=`__lodash_hash_undefined__`,Pn=Object.prototype.hasOwnProperty;function Fn(e){var t=this.__data__;if(An){var n=t[e];return n===Nn?void 0:n}return Pn.call(t,e)?t[e]:void 0}var In=Object.prototype.hasOwnProperty;function Ln(e){var t=this.__data__;return An?t[e]!==void 0:In.call(t,e)}var Rn=`__lodash_hash_undefined__`;function zn(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=An&&t===void 0?Rn:t,this}function Bn(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])}}Bn.prototype.clear=jn,Bn.prototype.delete=Mn,Bn.prototype.get=Fn,Bn.prototype.has=Ln,Bn.prototype.set=zn;function Vn(){this.__data__=[],this.size=0}function Hn(e,t){for(var n=e.length;n--;)if(ht(e[n][0],t))return n;return-1}var Un=Array.prototype.splice;function Wn(e){var t=this.__data__,n=Hn(t,e);return n<0?!1:(n==t.length-1?t.pop():Un.call(t,n,1),--this.size,!0)}function Gn(e){var t=this.__data__,n=Hn(t,e);return n<0?void 0:t[n][1]}function Kn(e){return Hn(this.__data__,e)>-1}function qn(e,t){var n=this.__data__,r=Hn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function Jn(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])}}Jn.prototype.clear=Vn,Jn.prototype.delete=Wn,Jn.prototype.get=Gn,Jn.prototype.has=Kn,Jn.prototype.set=qn;var Yn=Ye(s,`Map`);function Xn(){this.size=0,this.__data__={hash:new Bn,map:new(Yn||Jn),string:new Bn}}function Zn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Qn(e,t){var n=e.__data__;return Zn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function $n(e){var t=Qn(this,e).delete(e);return this.size-=+!!t,t}function er(e){return Qn(this,e).get(e)}function tr(e){return Qn(this,e).has(e)}function nr(e,t){var n=Qn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function rr(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])}}rr.prototype.clear=Xn,rr.prototype.delete=$n,rr.prototype.get=er,rr.prototype.has=tr,rr.prototype.set=nr;var ir=`Expected a function`;function ar(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(ir);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(ar.Cache||rr),n}ar.Cache=rr;var or=500;function sr(e){var t=ar(e,function(e){return n.size===or&&n.clear(),e}),n=t.cache;return t}var cr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,lr=/\\(\\)?/g,ur=sr(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(cr,function(e,n,r,i){t.push(r?i.replace(lr,`$1`):n||e)}),t});function dr(e){return e==null?``:pe(e)}function fr(e,t){return le(e)?e:kn(e,t)?[e]:ur(dr(e))}var pr=1/0;function mr(e){if(typeof e==`string`||se(e))return e;var t=e+``;return t==`0`&&1/e==-pr?`-0`:t}function hr(e,t){t=fr(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[mr(t[n++])];return n&&n==r?e:void 0}function gr(e,t,n){var r=e==null?void 0:hr(e,t);return r===void 0?n:r}function _r(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var vr=c?c.isConcatSpreadable:void 0;function yr(e){return le(e)||At(e)||!!(vr&&e&&e[vr])}function br(e,t,n,r,i){var a=-1,o=e.length;for(n||=yr,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?br(s,t-1,n,r,i):_r(i,s):r||(i[i.length]=s)}return i}function xr(e){return e!=null&&e.length?br(e,1):[]}function Sr(){this.__data__=new Jn,this.size=0}function Cr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function wr(e){return this.__data__.get(e)}function Tr(e){return this.__data__.has(e)}var Er=200;function Dr(e,t){var n=this.__data__;if(n instanceof Jn){var r=n.__data__;if(!Yn||r.length<Er-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new rr(r)}return n.set(e,t),this.size=n.size,this}function Or(e){var t=this.__data__=new Jn(e);this.size=t.size}Or.prototype.clear=Sr,Or.prototype.delete=Cr,Or.prototype.get=wr,Or.prototype.has=Tr,Or.prototype.set=Dr;function kr(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 Ar(){return[]}var jr=Object.prototype.propertyIsEnumerable,Mr=Object.getOwnPropertySymbols,Nr=Mr?function(e){return e==null?[]:(e=Object(e),kr(Mr(e),function(t){return jr.call(e,t)}))}:Ar;function Pr(e,t,n){var r=t(e);return le(e)?r:_r(r,n(e))}function Fr(e){return Pr(e,Sn,Nr)}var Ir=Ye(s,`DataView`),Lr=Ye(s,`Promise`),Rr=Ye(s,`Set`),zr=`[object Map]`,Br=`[object Object]`,Vr=`[object Promise]`,Hr=`[object Set]`,Ur=`[object WeakMap]`,Wr=`[object DataView]`,Gr=ze(Ir),Kr=ze(Yn),qr=ze(Lr),Jr=ze(Rr),Yr=ze(Xe),Xr=ie;(Ir&&Xr(new Ir(new ArrayBuffer(1)))!=Wr||Yn&&Xr(new Yn)!=zr||Lr&&Xr(Lr.resolve())!=Vr||Rr&&Xr(new Rr)!=Hr||Xe&&Xr(new Xe)!=Ur)&&(Xr=function(e){var t=ie(e),n=t==Br?e.constructor:void 0,r=n?ze(n):``;if(r)switch(r){case Gr:return Wr;case Kr:return zr;case qr:return Vr;case Jr:return Hr;case Yr:return Ur}return t});var Zr=Xr,Qr=s.Uint8Array;function $r(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 ei=`__lodash_hash_undefined__`;function ti(e){return this.__data__.set(e,ei),this}function ni(e){return this.__data__.has(e)}function ri(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new rr;++t<n;)this.add(e[t])}ri.prototype.add=ri.prototype.push=ti,ri.prototype.has=ni;function ii(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 ai(e,t){return e.has(t)}var oi=1,si=2;function ci(e,t,n,r,i,a){var o=n&oi,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&si?new ri:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],ee=t[d];if(r)var te=o?r(ee,m,d,t,e,a):r(m,ee,d,e,t,a);if(te!==void 0){if(te)continue;f=!1;break}if(p){if(!ii(t,function(e,t){if(!ai(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===ee||i(m,ee,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}function li(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function ui(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var di=1,fi=2,pi=`[object Boolean]`,mi=`[object Date]`,hi=`[object Error]`,gi=`[object Map]`,_i=`[object Number]`,vi=`[object RegExp]`,yi=`[object Set]`,bi=`[object String]`,xi=`[object Symbol]`,Si=`[object ArrayBuffer]`,Ci=`[object DataView]`,wi=c?c.prototype:void 0,Ti=wi?wi.valueOf:void 0;function Ei(e,t,n,r,i,a,o){switch(n){case Ci:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Si:return!(e.byteLength!=t.byteLength||!a(new Qr(e),new Qr(t)));case pi:case mi:case _i:return ht(+e,+t);case hi:return e.name==t.name&&e.message==t.message;case vi:case bi:return e==t+``;case gi:var s=li;case yi:var c=r&di;if(s||=ui,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=fi,o.set(e,t);var u=ci(s(e),s(t),r,i,a,o);return o.delete(e),u;case xi:if(Ti)return Ti.call(e)==Ti.call(t)}return!1}var Di=1,Oi=Object.prototype.hasOwnProperty;function ki(e,t,n,r,i,a){var o=n&Di,s=Fr(e),c=s.length;if(c!=Fr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Oi.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var ee=e[u],te=t[u];if(r)var ne=o?r(te,ee,u,t,e,a):r(ee,te,u,e,t,a);if(!(ne===void 0?ee===te||i(ee,te,n,r,a):ne)){p=!1;break}m||=u==`constructor`}if(p&&!m){var re=e.constructor,ie=t.constructor;re!=ie&&`constructor`in e&&`constructor`in t&&!(typeof re==`function`&&re instanceof re&&typeof ie==`function`&&ie instanceof ie)&&(p=!1)}return a.delete(e),a.delete(t),p}var Ai=1,ji=`[object Arguments]`,Mi=`[object Array]`,Ni=`[object Object]`,Pi=Object.prototype.hasOwnProperty;function Fi(e,t,n,r,i,a){var o=le(e),s=le(t),c=o?Mi:Zr(e),l=s?Mi:Zr(t);c=c==ji?Ni:c,l=l==ji?Ni:l;var u=c==Ni,d=l==Ni,f=c==l;if(f&&Ft(e)){if(!Ft(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Or,o||hn(e)?ci(e,t,n,r,i,a):Ei(e,t,c,n,r,i,a);if(!(n&Ai)){var p=u&&Pi.call(e,`__wrapped__`),m=d&&Pi.call(t,`__wrapped__`);if(p||m){var ee=p?e.value():e,te=m?t.value():t;return a||=new Or,i(ee,te,n,r,a)}}return f?(a||=new Or,ki(e,t,n,r,i,a)):!1}function Ii(e,t,n,r,i){return e===t?!0:e==null||t==null||!ae(e)&&!ae(t)?e!==e&&t!==t:Fi(e,t,n,r,Ii,i)}var Li=1,Ri=2;function zi(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 Or;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Ii(u,l,Li|Ri,r,d):f))return!1}}return!0}function Bi(e){return e===e&&!ve(e)}function Vi(e){for(var t=Sn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Bi(i)]}return t}function Hi(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function Ui(e){var t=Vi(e);return t.length==1&&t[0][2]?Hi(t[0][0],t[0][1]):function(n){return n===e||zi(n,e,t)}}function Wi(e,t){return e!=null&&t in Object(e)}function Gi(e,t,n){t=fr(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=mr(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&&bt(i)&&pt(o,i)&&(le(e)||At(e)))}function Ki(e,t){return e!=null&&Gi(e,t,Wi)}var qi=1,Ji=2;function Yi(e,t){return kn(e)&&Bi(t)?Hi(mr(e),t):function(n){var r=gr(n,e);return r===void 0&&r===t?Ki(n,e):Ii(t,r,qi|Ji)}}function Xi(e){return function(t){return t?.[e]}}function Zi(e){return function(t){return hr(t,e)}}function Qi(e){return kn(e)?Xi(mr(e)):Zi(e)}function $i(e){return typeof e==`function`?e:e==null?ke:typeof e==`object`?le(e)?Yi(e[0],e[1]):Ui(e):Qi(e)}function ea(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 ta(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 na=ta();function ra(e,t){return e&&na(e,t,Sn)}function ia(e,t){return function(n,r){if(n==null)return n;if(!xt(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 aa=ia(ra);function oa(e,t,n,r){return aa(e,function(e,i,a){t(r,e,n(e),a)}),r}function sa(e,t){return function(n,r){var i=le(n)?ea:oa,a=t?t():{};return i(n,e,$i(r,2),a)}}function ca(e){return ae(e)&&xt(e)}function la(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 ua=200;function da(e,t,n,r){var i=-1,a=ut,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ce(t,ln(n))),r?(a=la,o=!1):t.length>=ua&&(a=ai,o=!1,t=new ri(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 fa=vt(function(e,t){return ca(e)?da(e,br(t,1,ca,!0)):[]});function h(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function pa(e){return typeof e==`function`?e:ke}function ma(e,t){var n=[];return aa(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ha(e,t){return(le(e)?kr:ma)(e,$i(t,3))}var ga=Math.max,_a=Math.min;function va(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Oe(n),i=n<0?ga(r+i,0):_a(i,r-1)),ot(e,$i(t,3),i,!0)}function ya(e){return e&&e.length?e[0]:void 0}function ba(e,t){var n=-1,r=xt(e)?Array(e.length):[];return aa(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function xa(e,t){return(le(e)?ce:ba)(e,$i(t,3))}function Sa(e,t){return br(xa(e,t),1)}function Ca(e,t){return e==null?e:na(e,pa(t),En)}var wa=Object.prototype.hasOwnProperty,Ta=sa(function(e,t,n){wa.call(e,n)?e[n].push(t):mt(e,n,[t])}),Ea=`[object Map]`,Da=`[object Set]`,Oa=Object.prototype.hasOwnProperty;function ka(e){if(e==null)return!0;if(xt(e)&&(le(e)||typeof e==`string`||typeof e.splice==`function`||Ft(e)||hn(e)||At(e)))return!e.length;var t=Zr(e);if(t==Ea||t==Da)return!e.size;if(Ct(e))return!xn(e).length;for(var n in e)if(Oa.call(e,n))return!1;return!0}var Aa=sa(function(e,t,n){mt(e,n,t)}),g=sa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),ja=Rr&&1/ui(new Rr([,-0]))[1]==1/0?function(e){return new Rr(e)}:Qe,Ma=200;function Na(e,t,n){var r=-1,i=ut,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=la;else if(a>=Ma){var l=t?null:ja(e);if(l)return ui(l);o=!1,i=ai,c=new ri}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 Pa(e){return e&&e.length?Na(e):[]}function Fa(e,t){return e&&e.length?Na(e,$i(t,2)):[]}var Ia=Math.max;function La(e){if(!(e&&e.length))return[];var t=0;return e=kr(e,function(e){if(ca(e))return t=Ia(e.length,t),!0}),wt(t,function(t){return ce(e,Xi(t))})}var Ra=vt(La),_=function(e){return e.SPACE=`<space>`,e.TAB=`<tab>`,e.NEWLINE=`<newline>`,e.COMMA=`<comma>`,e.LPAREN=`<lparen>`,e.RPAREN=`<rparen>`,e.LBRACE=`<lbrace>`,e.RBRACE=`<rbrace>`,e.LBRACKET=`<lbracket>`,e.RBRACKET=`<rbracket>`,e.LANGLE=`<langle>`,e.RANGLE=`<rangle>`,e.OP=`<op>`,e.EOF=`<eof>`,e.NUMERIC_LITERAL=`<number>`,e.STRING_LITERAL=`<string>`,e.COLOR_LITERAL=`<color>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.QUOTED_STRING=`<variable>`,e.IDENTIFIER=`<identifier>`,e.SEMICOLON=`<semicolon>`,e.COLON=`<colon>`,e.SINGLE_LINE_COMMENT=`<single-line-comment>`,e.MULTILINE_COMMENT=`<multiline-comment>`,e.WILDCARD=`<wildcard>`,e}({});function za(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:return!0;default:return!1}}function Ba(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 Va(e){return e!==void 0&&e.kind===`<op>`}var Ha=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 Ua(e){return e.trailingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0}function Wa(e,t){return t.leadingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0||Ua(e)}function Ga(e){return e.trailingTrivia.find(({kind:e})=>[_.SPACE,_.TAB].includes(e))!==void 0}function Ka(e){return e.trailingTrivia.length===0?e.end:Ka(h(e.trailingTrivia))}function qa(e){return e.leadingTrivia.length===0?e.start:qa(e.leadingTrivia[0])}function Ja(e){return[_.SINGLE_LINE_COMMENT,_.MULTILINE_COMMENT].includes(e.kind)}function Ya(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`as`}function Xa(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`use`}function Za(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`metadata`}function Qa(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`from`}function $a(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function eo(e){return!!e?.isInvalid}var to=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},no=/^[A-Za-z]:\//;function ro(e=``){return e&&e.replace(/\\/g,`/`).replace(no,e=>e.toUpperCase())}var io=/^[/\\]{2}/,ao=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,oo=/^[A-Za-z]:$/,so=/^\/([A-Za-z]:)?$/,co=/.(\.[^./]+|\.)$/,lo=function(e){if(e.length===0)return`.`;e=ro(e);let t=e.match(io),n=ho(e),r=e[e.length-1]===`/`;return e=mo(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),oo.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!ho(e)?`/${e}`:e)},uo=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 lo(t)};function fo(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var po=function(...e){e=e.map(e=>ro(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:fo();!i||i.length===0||(t=`${i}/${t}`,n=ho(i))}return t=mo(t,!n),n&&!ho(t)?`/${t}`:t.length>0?t:`.`};function mo(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 ho=function(e){return ao.test(e)},go=function(e){if(e===`..`)return``;let t=co.exec(ro(e));return t&&t[1]||``},_o=function(e,t){let n=po(e).replace(so,`$1`).split(`/`),r=po(t).replace(so,`$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(`/`)},vo=function(e){let t=ro(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&oo.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(ho(e)?`/`:`.`)},yo=function(e,t){let n=ro(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},bo=/^[a-zA-Z]:\//,xo=class e{constructor(e,t={}){e=e.split(`/`).map(So).join(`/`);let n=lo(e);if(!ho(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(po(t,n))}static fromUri(t){try{let n=new URL(t);return new e(lo(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(lo(t))}}get absolute(){return this.path}get fsPath(){return this.path.split(`/`).map(decodeURIComponent).join(`/`)}get dirname(){return vo(this.fsPath)}get basename(){return yo(this.fsPath)}get extname(){return go(this.fsPath)}resolve(t){return new e(po(this.dirname,t))}join(...t){return new e(uo(this.path,...t))}relativeTo(e){let t=_o(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=bo.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!ho(lo(e))}};function So(e){try{return encodeURIComponent(decodeURIComponent(e))}catch{return encodeURIComponent(e)}}var Co=[`null`,`true`,`false`],wo=`none`,To=`.dbml`,Eo=[`-`,`+`],v=`public`,Do=xo.from(`/main.dbml`),Oo={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`])},ko={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`])},Ao={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},jo={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`])},Mo={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`])},No={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`])},Po={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function Fo(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function Io(e,t){let n=Fo(e);return t?Oo[t].has(n):Object.values(Oo).some(e=>e.has(n))}function Lo(e,t){let n=Fo(e);return t?ko[t].has(n):Object.values(ko).some(e=>e.has(n))}function Ro(e,t){return Io(e,t)||Lo(e,t)}function zo(e,t){let n=Fo(e);return t?Ao[t].has(n):Object.values(Ao).some(e=>e.has(n))}function Bo(e,t){let n=Fo(e);return t?jo[t].has(n):Object.values(jo).some(e=>e.has(n))}function Vo(e,t){let n=Fo(e);return t?Mo[t].has(n):Object.values(Mo).some(e=>e.has(n))}function Ho(e,t){let n=Fo(e);return t?No[t].has(n):Object.values(No).some(e=>e.has(n))}function Uo(e,t){let n=Fo(e);return t?Po[t].has(n):Object.values(Po).some(e=>e.has(n))}function Wo(e,t){if(t)return`string`;if(Io(e))return`integer`;if(Lo(e))return`real`;if(zo(e))return`bool`;if(Bo(e))return`string`;let n=Fo(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:Ho(e)?`datetime`:e}var Go=class extends Error{},Ko=class extends Go{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},qo=class extends Go{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Jo=class extends Go{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Yo=class extends Go{},Xo=class extends Go{constructor(e){super(`Invalid unit ${e}`)}},Zo=class extends Go{},Qo=class extends Go{constructor(){super(`Zone is an abstract class`)}},y=`numeric`,$o=`short`,es=`long`,ts={year:y,month:y,day:y},ns={year:y,month:$o,day:y},rs={year:y,month:$o,day:y,weekday:$o},is={year:y,month:es,day:y},as={year:y,month:es,day:y,weekday:es},os={hour:y,minute:y},ss={hour:y,minute:y,second:y},cs={hour:y,minute:y,second:y,timeZoneName:$o},ls={hour:y,minute:y,second:y,timeZoneName:es},us={hour:y,minute:y,hourCycle:`h23`},ds={hour:y,minute:y,second:y,hourCycle:`h23`},fs={hour:y,minute:y,second:y,hourCycle:`h23`,timeZoneName:$o},ps={hour:y,minute:y,second:y,hourCycle:`h23`,timeZoneName:es},ms={year:y,month:y,day:y,hour:y,minute:y},hs={year:y,month:y,day:y,hour:y,minute:y,second:y},gs={year:y,month:$o,day:y,hour:y,minute:y},_s={year:y,month:$o,day:y,hour:y,minute:y,second:y},vs={year:y,month:$o,day:y,weekday:$o,hour:y,minute:y},ys={year:y,month:es,day:y,hour:y,minute:y,timeZoneName:$o},bs={year:y,month:es,day:y,hour:y,minute:y,second:y,timeZoneName:$o},xs={year:y,month:es,day:y,weekday:es,hour:y,minute:y,timeZoneName:es},Ss={year:y,month:es,day:y,weekday:es,hour:y,minute:y,second:y,timeZoneName:es},Cs=class{get type(){throw new Qo}get name(){throw new Qo}get ianaName(){return this.name}get isUniversal(){throw new Qo}offsetName(e,t){throw new Qo}formatOffset(e,t){throw new Qo}offset(e){throw new Qo}equals(e){throw new Qo}get isValid(){throw new Qo}},ws=null,Ts=class e extends Cs{static get instance(){return ws===null&&(ws=new e),ws}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return dl(e,t,n)}formatOffset(e,t){return hl(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},Es=new Map;function Ds(e){let t=Es.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`}),Es.set(e,t)),t}var Os={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function ks(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 As(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=Os[t];t===`era`?r[a]=i:x(a)||(r[a]=parseInt(i,10))}return r}var js=new Map,Ms=class e extends Cs{static create(t){let n=js.get(t);return n===void 0&&js.set(t,n=new e(t)),n}static resetCache(){js.clear(),Es.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 dl(e,t,n,this.name)}formatOffset(e,t){return hl(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=Ds(this.name),[r,i,a,o,s,c,l]=n.formatToParts?As(n,t):ks(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=sl({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}},Ns={};function Ps(e,t={}){let n=JSON.stringify([e,t]),r=Ns[n];return r||(r=new Intl.ListFormat(e,t),Ns[n]=r),r}var Fs=new Map;function Is(e,t={}){let n=JSON.stringify([e,t]),r=Fs.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),Fs.set(n,r)),r}var Ls=new Map;function Rs(e,t={}){let n=JSON.stringify([e,t]),r=Ls.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Ls.set(n,r)),r}var zs=new Map;function Bs(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=zs.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),zs.set(i,a)),a}var Vs=null;function Hs(){return Vs||(Vs=new Intl.DateTimeFormat().resolvedOptions().locale,Vs)}var Us=new Map;function Ws(e){let t=Us.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Us.set(e,t)),t}var Gs=new Map;function Ks(e){let t=Gs.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...nc,...t}),Gs.set(e,t)}return t}function qs(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=Is(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=Is(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Js(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Ys(e){let t=[];for(let n=1;n<=12;n++){let r=C.utc(2009,n,1);t.push(e(r))}return t}function Xs(e){let t=[];for(let n=1;n<=7;n++){let r=C.utc(2016,11,13+n);t.push(e(r))}return t}function Zs(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Qs(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Ws(e.locale).numberingSystem===`latn`}var $s=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=Rs(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return $c(this.floor?Math.floor(e):rl(e,3),this.padTo)}},ec=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&&Ms.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=Is(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()}},tc=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Wc()&&(this.rtf=Bs(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):Pl(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},nc={firstDay:1,minimalDays:4,weekend:[6,7]},b=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||Sc.defaultLocale;return new e(o||(a?`en-US`:Hs()),n||Sc.defaultNumberingSystem,r||Sc.defaultOutputCalendar,Xc(i)||Sc.defaultWeekSettings,o)}static resetCache(){Vs=null,Fs.clear(),Ls.clear(),zs.clear(),Us.clear(),Gs.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]=qs(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Js(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??=Qs(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,Xc(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 Zs(this,e,bl,()=>{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]=Ys(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Zs(this,e,wl,()=>{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]=Xs(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Zs(this,void 0,()=>Tl,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[C.utc(2016,11,13,9),C.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Zs(this,e,kl,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[C.utc(-40,1,1),C.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 $s(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new ec(e,this.intl,t)}relFormatter(e={}){return new tc(this.intl,this.isEnglish(),e)}listFormatter(e={}){return Ps(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Ws(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Gc()?Ks(this.locale):nc}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})`}},rc=null,ic=class e extends Cs{static get utcInstance(){return rc===null&&(rc=new e(0)),rc}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(fl(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${hl(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${hl(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return hl(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}},ac=class extends Cs{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 oc(e,t){if(x(e)||e===null)return t;if(e instanceof Cs)return e;if(Hc(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?Ts.instance:n===`utc`||n===`gmt`?ic.utcInstance:ic.parseSpecifier(n)||Ms.create(e)}else if(Bc(e))return ic.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new ac(e)}var sc={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},cc={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]},lc=sc.hanidec.replace(/[\[|\]]/g,``).split(``);function uc(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(sc.hanidec)!==-1)t+=lc.indexOf(e[n]);else for(let e in cc){let[n,i]=cc[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var dc=new Map;function fc(){dc.clear()}function pc({numberingSystem:e},t=``){let n=e||`latn`,r=dc.get(n);r===void 0&&(r=new Map,dc.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${sc[n]}${t}`),r.set(t,i)),i}var mc=()=>Date.now(),hc=`system`,gc=null,_c=null,vc=null,yc=60,bc,xc=null,Sc=class{static get now(){return mc}static set now(e){mc=e}static set defaultZone(e){hc=e}static get defaultZone(){return oc(hc,Ts.instance)}static get defaultLocale(){return gc}static set defaultLocale(e){gc=e}static get defaultNumberingSystem(){return _c}static set defaultNumberingSystem(e){_c=e}static get defaultOutputCalendar(){return vc}static set defaultOutputCalendar(e){vc=e}static get defaultWeekSettings(){return xc}static set defaultWeekSettings(e){xc=Xc(e)}static get twoDigitCutoffYear(){return yc}static set twoDigitCutoffYear(e){yc=e%100}static get throwOnInvalid(){return bc}static set throwOnInvalid(e){bc=e}static resetCaches(){b.resetCache(),Ms.resetCache(),C.resetCache(),fc()}},Cc=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},wc=[0,31,59,90,120,151,181,212,243,273,304,334],Tc=[0,31,60,91,121,152,182,213,244,274,305,335];function Ec(e,t){return new Cc(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function Dc(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 Oc(e,t,n){return n+(il(e)?Tc:wc)[t-1]}function kc(e,t){let n=il(e)?Tc:wc,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function Ac(e,t){return(e-t+7)%7+1}function jc(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Oc(r,i,a),s=Ac(Dc(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=ll(l,t,n)):c>ll(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...gl(e)}}function Mc(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=Ac(Dc(r,1,t),n),s=al(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=al(l)):c>s?(l=r+1,c-=al(r)):l=r;let{month:u,day:d}=kc(l,c);return{year:l,month:u,day:d,...gl(e)}}function Nc(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Oc(t,n,r),...gl(e)}}function Pc(e){let{year:t,ordinal:n}=e,{month:r,day:i}=kc(t,n);return{year:t,month:r,day:i,...gl(e)}}function Fc(e,t){if(!x(e.localWeekday)||!x(e.localWeekNumber)||!x(e.localWeekYear)){if(!x(e.weekday)||!x(e.weekNumber)||!x(e.weekYear))throw new Yo(`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 Ic(e,t=4,n=1){let r=Vc(e.weekYear),i=Zc(e.weekNumber,1,ll(e.weekYear,t,n)),a=Zc(e.weekday,1,7);return r?i?a?!1:Ec(`weekday`,e.weekday):Ec(`week`,e.weekNumber):Ec(`weekYear`,e.weekYear)}function Lc(e){let t=Vc(e.year),n=Zc(e.ordinal,1,al(e.year));return t?n?!1:Ec(`ordinal`,e.ordinal):Ec(`year`,e.year)}function Rc(e){let t=Vc(e.year),n=Zc(e.month,1,12),r=Zc(e.day,1,ol(e.year,e.month));return t?n?r?!1:Ec(`day`,e.day):Ec(`month`,e.month):Ec(`year`,e.year)}function zc(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Zc(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Zc(n,0,59),s=Zc(r,0,59),c=Zc(i,0,999);return a?o?s?c?!1:Ec(`millisecond`,i):Ec(`second`,r):Ec(`minute`,n):Ec(`hour`,t)}function x(e){return e===void 0}function Bc(e){return typeof e==`number`}function Vc(e){return typeof e==`number`&&e%1==0}function Hc(e){return typeof e==`string`}function Uc(e){return Object.prototype.toString.call(e)===`[object Date]`}function Wc(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Gc(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Kc(e){return Array.isArray(e)?e:[e]}function qc(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 Jc(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Yc(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Xc(e){if(e==null)return null;if(typeof e!=`object`)throw new Zo(`Week settings must be an object`);if(!Zc(e.firstDay,1,7)||!Zc(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Zc(e,1,7)))throw new Zo(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Zc(e,t,n){return Vc(e)&&e>=t&&e<=n}function Qc(e,t){return e-t*Math.floor(e/t)}function $c(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function el(e){if(!(x(e)||e===null||e===``))return parseInt(e,10)}function tl(e){if(!(x(e)||e===null||e===``))return parseFloat(e)}function nl(e){if(!(x(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function rl(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 il(e){return e%4==0&&(e%100!=0||e%400==0)}function al(e){return il(e)?366:365}function ol(e,t){let n=Qc(t-1,12)+1,r=e+(t-n)/12;return n===2?il(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function sl(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 cl(e,t,n){return-Ac(Dc(e,1,t),n)+t-1}function ll(e,t=4,n=1){let r=cl(e,t,n),i=cl(e+1,t,n);return(al(e)-r+i)/7}function ul(e){return e>99?e:e>Sc.twoDigitCutoffYear?1900+e:2e3+e}function dl(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 fl(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 pl(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Zo(`Invalid unit value ${e}`);return t}function ml(e,t){let n={};for(let r in e)if(Yc(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=pl(i)}return n}function hl(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}${$c(n,2)}:${$c(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${$c(n,2)}${$c(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function gl(e){return Jc(e,[`hour`,`minute`,`second`,`millisecond`])}var _l=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],vl=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],yl=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function bl(e){switch(e){case`narrow`:return[...yl];case`short`:return[...vl];case`long`:return[..._l];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 xl=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],Sl=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Cl=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function wl(e){switch(e){case`narrow`:return[...Cl];case`short`:return[...Sl];case`long`:return[...xl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var Tl=[`AM`,`PM`],El=[`Before Christ`,`Anno Domini`],Dl=[`BC`,`AD`],Ol=[`B`,`A`];function kl(e){switch(e){case`narrow`:return[...Ol];case`short`:return[...Dl];case`long`:return[...El];default:return null}}function Al(e){return Tl[e.hour<12?0:1]}function jl(e,t){return wl(t)[e.weekday-1]}function Ml(e,t){return bl(t)[e.month-1]}function Nl(e,t){return kl(t)[e.year<0?0:1]}function Pl(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 Fl(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var Il={D:ts,DD:ns,DDD:is,DDDD:as,t:os,tt:ss,ttt:cs,tttt:ls,T:us,TT:ds,TTT:fs,TTTT:ps,f:ms,ff:gs,fff:ys,ffff:xs,F:hs,FF:_s,FFF:bs,FFFF:Ss},Ll=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 Il[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 $c(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?Al(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?Ml(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?jl(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?Nl(t,e):a({era:e},`era`);return Fl(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 Fl(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Rl=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function zl(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Bl(...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 Vl(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 Hl(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=el(t[n+i]);return[r,null,n+i]}}var Ul=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Wl=`(?:${Ul.source}?(?:\\[(${Rl.source})\\])?)?`,Gl=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Kl=RegExp(`${Gl.source}${Wl}`),ql=RegExp(`(?:[Tt]${Kl.source})?`),Jl=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Yl=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Xl=/(\d{4})-?(\d{3})/,Zl=Hl(`weekYear`,`weekNumber`,`weekDay`),Ql=Hl(`year`,`ordinal`),$l=/(\d{4})-(\d\d)-(\d\d)/,eu=RegExp(`${Gl.source} ?(?:${Ul.source}|(${Rl.source}))?`),tu=RegExp(`(?: ${eu.source})?`);function nu(e,t,n){let r=e[t];return x(r)?n:el(r)}function ru(e,t){return[{year:nu(e,t),month:nu(e,t+1,1),day:nu(e,t+2,1)},null,t+3]}function iu(e,t){return[{hours:nu(e,t,0),minutes:nu(e,t+1,0),seconds:nu(e,t+2,0),milliseconds:nl(e[t+3])},null,t+4]}function au(e,t){let n=!e[t]&&!e[t+1],r=fl(e[t+1],e[t+2]);return[{},n?null:ic.instance(r),t+3]}function ou(e,t){return[{},e[t]?Ms.create(e[t]):null,t+1]}var su=RegExp(`^T?${Gl.source}$`),cu=/^-?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 lu(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(tl(n)),months:f(tl(r)),weeks:f(tl(i)),days:f(tl(a)),hours:f(tl(o)),minutes:f(tl(s)),seconds:f(tl(c),c===`-0`),milliseconds:f(nl(l),d)}]}var uu={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function du(e,t,n,r,i,a,o){let s={year:t.length===2?ul(el(t)):el(t),month:vl.indexOf(n)+1,day:el(r),hour:el(i),minute:el(a)};return o&&(s.second=el(o)),e&&(s.weekday=e.length>3?xl.indexOf(e)+1:Sl.indexOf(e)+1),s}var fu=/^(?:(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 pu(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=du(t,i,r,n,a,o,s),p;return p=c?uu[c]:l?0:fl(u,d),[f,new ic(p)]}function mu(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var hu=/^(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$/,gu=/^(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$/,_u=/^(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 vu(e){let[,t,n,r,i,a,o,s]=e;return[du(t,i,r,n,a,o,s),ic.utcInstance]}function yu(e){let[,t,n,r,i,a,o,s]=e;return[du(t,s,n,r,i,a,o),ic.utcInstance]}var bu=zl(Jl,ql),xu=zl(Yl,ql),Su=zl(Xl,ql),Cu=zl(Kl),wu=Bl(ru,iu,au,ou),Tu=Bl(Zl,iu,au,ou),Eu=Bl(Ql,iu,au,ou),Du=Bl(iu,au,ou);function Ou(e){return Vl(e,[bu,wu],[xu,Tu],[Su,Eu],[Cu,Du])}function ku(e){return Vl(mu(e),[fu,pu])}function Au(e){return Vl(e,[hu,vu],[gu,vu],[_u,yu])}function ju(e){return Vl(e,[cu,lu])}var Mu=Bl(iu);function Nu(e){return Vl(e,[su,Mu])}var Pu=zl($l,tu),Fu=zl(eu),Iu=Bl(iu,au,ou);function Lu(e){return Vl(e,[Pu,wu],[Fu,Iu])}var Ru=`Invalid Duration`,zu={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}},Bu={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},...zu},Vu=146097/400,Hu=146097/4800,Uu={years:{quarters:4,months:12,weeks:Vu/7,days:Vu,hours:Vu*24,minutes:Vu*24*60,seconds:Vu*24*60*60,milliseconds:Vu*24*60*60*1e3},quarters:{months:3,weeks:Vu/28,days:Vu/4,hours:Vu*24/4,minutes:Vu*24*60/4,seconds:Vu*24*60*60/4,milliseconds:Vu*24*60*60*1e3/4},months:{weeks:Hu/7,days:Hu,hours:Hu*24,minutes:Hu*24*60,seconds:Hu*24*60*60,milliseconds:Hu*24*60*60*1e3},...zu},Wu=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Gu=Wu.slice(0).reverse();function Ku(e,t,n=!1){return new Xu({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 qu(e,t){let n=t.milliseconds??0;for(let r of Gu.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Ju(e,t){let n=qu(e,t)<0?-1:1;Wu.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),Wu.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 Yu(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Xu=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Uu:Bu;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||b.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 Zo(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:ml(t,e.normalizeUnit),loc:b.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Bc(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Zo(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=ju(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]=Nu(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 Zo(`need to specify a reason the Duration is invalid`);let r=t instanceof Cc?t:new Cc(t,n);if(Sc.throwOnInvalid)throw new Jo(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 Xo(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?Ll.create(this.loc,n).formatDurationFromString(this,e):Ru}toHuman(e={}){if(!this.isValid)return Ru;let t=e.showZeros!==!1,n=Wu.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+=rl(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},C.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?qu(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 Wu)(Yc(n.values,e)||Yc(this.values,e))&&(r[e]=n.get(e)+this.get(e));return Ku(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]=pl(e(this.values[n],n));return Ku(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...ml(t,e.normalizeUnit)};return Ku(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 Ku(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Ju(this.matrix,e),Ku(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Yu(this.normalize().shiftToAll().toObject());return Ku(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 Wu)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;Bc(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Bc(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 Ju(this.matrix,n),Ku(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 Ku(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Yu(this.values);return Ku(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 Wu)if(!t(this.values[n],e.values[n]))return!1;return!0}},Zu=`Invalid Interval`;function Qu(e,t){return!e||!e.isValid?$u.invalid(`missing or invalid start`):!t||!t.isValid?$u.invalid(`missing or invalid end`):t<e?$u.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 $u=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 Zo(`need to specify a reason the Interval is invalid`);let r=t instanceof Cc?t:new Cc(t,n);if(Sc.throwOnInvalid)throw new qo(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=tf(t),i=tf(n);return Qu(r,i)??new e({start:r,end:i})}static after(t,n){let r=Xu.fromDurationLike(n),i=tf(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Xu.fromDurationLike(n),i=tf(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=C.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=C.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Xu.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Xu.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(tf).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=Xu.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()})`:Zu}[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=ts,t={}){return this.isValid?Ll.create(this.s.loc.clone(t),e).formatInterval(this):Zu}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Zu}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Zu}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Zu}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Zu}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Xu.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},ed=class{static hasDST(e=Sc.defaultZone){let t=C.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return Ms.isValidZone(e)}static normalizeZone(e){return oc(e,Sc.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||b.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||b.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||b.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||b.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||b.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||b.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||b.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return b.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return b.create(t,null,`gregory`).eras(e)}static features(){return{relative:Wc(),localeWeek:Gc()}}};function td(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Xu.fromMillis(r).as(`days`))}function nd(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=td(e,t);return(n-n%7)/7}],[`days`,td]],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 rd(e,t,n,r){let[i,a,o,s]=nd(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=Xu.fromObject(a,r);return l.length>0?Xu.fromMillis(c,r).shiftTo(...l).plus(u):u}var id=`missing Intl.DateTimeFormat.formatToParts support`;function S(e,t=e=>e){return{regex:e,deser:([e])=>t(uc(e))}}var ad=`[ \xA0]`,od=new RegExp(ad,`g`);function sd(e){return e.replace(/\./g,`\\.?`).replace(od,ad)}function cd(e){return e.replace(/\./g,``).replace(od,` `).toLowerCase()}function ld(e,t){return e===null?null:{regex:RegExp(e.map(sd).join(`|`)),deser:([n])=>e.findIndex(e=>cd(n)===cd(e))+t}}function ud(e,t){return{regex:e,deser:([,e,t])=>fl(e,t),groups:t}}function dd(e){return{regex:e,deser:([e])=>e}}function fd(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function pd(e,t){let n=pc(t),r=pc(t,`{2}`),i=pc(t,`{3}`),a=pc(t,`{4}`),o=pc(t,`{6}`),s=pc(t,`{1,2}`),c=pc(t,`{1,3}`),l=pc(t,`{1,6}`),u=pc(t,`{1,9}`),d=pc(t,`{2,4}`),f=pc(t,`{4,6}`),p=e=>({regex:RegExp(fd(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return ld(t.eras(`short`),0);case`GG`:return ld(t.eras(`long`),0);case`y`:return S(l);case`yy`:return S(d,ul);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 ld(t.months(`short`,!0),1);case`MMMM`:return ld(t.months(`long`,!0),1);case`L`:return S(s);case`LL`:return S(r);case`LLL`:return ld(t.months(`short`,!1),1);case`LLLL`:return ld(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 dd(u);case`uu`:return dd(s);case`uuu`:return S(n);case`a`:return ld(t.meridiems(),0);case`kkkk`:return S(a);case`kk`:return S(d,ul);case`W`:return S(s);case`WW`:return S(r);case`E`:case`c`:return S(n);case`EEE`:return ld(t.weekdays(`short`,!1),1);case`EEEE`:return ld(t.weekdays(`long`,!1),1);case`ccc`:return ld(t.weekdays(`short`,!0),1);case`cccc`:return ld(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return ud(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return ud(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return dd(/[a-z_+-/]{1,256}?/i);case` `:return dd(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:id};return m.token=e,m}var md={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 hd(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=md[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function gd(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function _d(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Yc(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 vd(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=Ms.create(e.z)),x(e.Z)||(n||=new ic(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=nl(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var yd=null;function bd(){return yd||=C.fromMillis(1555555555555),yd}function xd(e,t){if(e.literal)return e;let n=Ed(Ll.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function Sd(e,t){return Array.prototype.concat(...e.map(e=>xd(e,t)))}var Cd=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=Sd(Ll.parseFormat(t),e),this.units=this.tokens.map(t=>pd(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=gd(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=_d(e,this.regex,this.handlers),[r,i,a]=n?vd(n):[null,null,void 0];if(Yc(n,`a`)&&Yc(n,`H`))throw new Yo(`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 wd(e,t,n){return new Cd(e,n).explainFromTokens(t)}function Td(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=wd(e,t,n);return[r,i,a,o]}function Ed(e,t){if(!e)return null;let n=Ll.create(t,e).dtFormatter(bd()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>hd(t,e,i))}var Dd=`Invalid DateTime`,Od=864e13;function kd(e){return new Cc(`unsupported zone`,`the zone "${e.name}" is not supported`)}function Ad(e){return e.weekData===null&&(e.weekData=jc(e.c)),e.weekData}function jd(e){return e.localWeekData===null&&(e.localWeekData=jc(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function Md(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new C({...n,...t,old:n})}function Nd(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 Pd(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 Fd(e,t,n){return Nd(sl(e),t,n)}function Id(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,ol(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Xu.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]=Nd(sl(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function Ld(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=C.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return C.invalid(new Cc(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function Rd(e,t,n=!0){return e.isValid?Ll.create(b.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function zd(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=$c(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=$c(e.c.month),n===`month`)return i;i+=`-`}else if(i+=$c(e.c.month),n===`month`)return i;return i+=$c(e.c.day),i}function Bd(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+=$c(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=$c(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=$c(e.c.second))}else{if(c+=$c(e.c.minute),o===`minute`)break;s&&(c+=$c(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=$c(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=$c(Math.trunc(-e.o/60)),c+=`:`,c+=$c(Math.trunc(-e.o%60))):(c+=`+`,c+=$c(Math.trunc(e.o/60)),c+=`:`,c+=$c(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Vd={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Hd={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Ud={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Wd=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],Gd=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],Kd=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function qd(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 Xo(e);return t}function Jd(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return qd(e)}}function Yd(e){if($d===void 0&&($d=Sc.now()),e.type!==`iana`)return e.offset($d);let t=e.name,n=ef.get(t);return n===void 0&&(n=e.offset($d),ef.set(t,n)),n}function Xd(e,t){let n=oc(t.zone,Sc.defaultZone);if(!n.isValid)return C.invalid(kd(n));let r=b.fromObject(t),i,a;if(x(e.year))i=Sc.now();else{for(let t of Wd)x(e[t])&&(e[t]=Vd[t]);let t=Rc(e)||zc(e);if(t)return C.invalid(t);let r=Yd(n);[i,a]=Fd(e,r,n)}return new C({ts:i,zone:n,loc:r,o:a})}function Zd(e,t,n){let r=x(n.round)?!0:n.round,i=x(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=rl(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 Qd(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 $d,ef=new Map,C=class e{constructor(e){let t=e.zone||Sc.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new Cc(`invalid input`):null)||(t.isValid?null:kd(t));this.ts=x(e.ts)?Sc.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=Bc(e.o)&&!e.old?e.o:t.offset(this.ts);r=Pd(this.ts,a),n=Number.isNaN(r.year)?new Cc(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||b.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]=Qd(arguments),[n,r,i,a,o,s,c]=t;return Xd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=Qd(arguments),[n,r,i,a,o,s,c]=t;return e.zone=ic.utcInstance,Xd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Uc(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=oc(n.zone,Sc.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:b.fromObject(n)}):e.invalid(kd(i))}static fromMillis(t,n={}){if(!Bc(t))throw new Zo(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>Od?e.invalid(`Timestamp out of range`):new e({ts:t,zone:oc(n.zone,Sc.defaultZone),loc:b.fromObject(n)})}static fromSeconds(t,n={}){if(Bc(t))return new e({ts:t*1e3,zone:oc(n.zone,Sc.defaultZone),loc:b.fromObject(n)});throw new Zo(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=oc(n.zone,Sc.defaultZone);if(!r.isValid)return e.invalid(kd(r));let i=b.fromObject(n),a=ml(t,Jd),{minDaysInFirstWeek:o,startOfWeek:s}=Fc(a,i),c=Sc.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 Yo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Yo(`Can't mix ordinal dates with month/day`);let ee=m||a.weekday&&!p,te,ne,re=Pd(c,l);ee?(te=Gd,ne=Hd,re=jc(re,o,s)):u?(te=Kd,ne=Ud,re=Nc(re)):(te=Wd,ne=Vd);let ie=!1;for(let e of te){let t=a[e];x(t)?ie?a[e]=ne[e]:a[e]=re[e]:ie=!0}let ae=(ee?Ic(a,o,s):u?Lc(a):Rc(a))||zc(a);if(ae)return e.invalid(ae);let[oe,se]=Fd(ee?Mc(a,o,s):u?Pc(a):a,l,r),ce=new e({ts:oe,zone:r,o:se,loc:i});return a.weekday&&p&&t.weekday!==ce.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${ce.toISO()}`):ce.isValid?ce:e.invalid(ce.invalid)}static fromISO(e,t={}){let[n,r]=Ou(e);return Ld(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=ku(e);return Ld(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=Au(e);return Ld(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(x(t)||x(n))throw new Zo(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=Td(b.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):Ld(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]=Lu(e);return Ld(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Zo(`need to specify a reason the DateTime is invalid`);let r=t instanceof Cc?t:new Cc(t,n);if(Sc.throwOnInvalid)throw new Ko(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=Ed(e,b.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return Sd(Ll.parseFormat(e),b.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){$d=void 0,ef.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?Ad(this).weekYear:NaN}get weekNumber(){return this.isValid?Ad(this).weekNumber:NaN}get weekday(){return this.isValid?Ad(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?jd(this).weekday:NaN}get localWeekNumber(){return this.isValid?jd(this).weekNumber:NaN}get localWeekYear(){return this.isValid?jd(this).weekYear:NaN}get ordinal(){return this.isValid?Nc(this.c).ordinal:NaN}get monthShort(){return this.isValid?ed.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?ed.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?ed.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?ed.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=sl(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=Pd(s,a),u=Pd(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[Md(this,{ts:s}),Md(this,{ts:c})]:[this]}get isInLeapYear(){return il(this.year)}get daysInMonth(){return ol(this.year,this.month)}get daysInYear(){return this.isValid?al(this.year):NaN}get weeksInWeekYear(){return this.isValid?ll(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?ll(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=Ll.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(ic.instance(e),t)}toLocal(){return this.setZone(Sc.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=oc(t,Sc.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]=Fd(r,n,t)}return Md(this,{ts:e,zone:t})}else return e.invalid(kd(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return Md(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=ml(e,Jd),{minDaysInFirstWeek:n,startOfWeek:r}=Fc(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 Yo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Yo(`Can't mix ordinal dates with month/day`);let u;i?u=Mc({...jc(this.c,n,r),...t},n,r):x(t.ordinal)?(u={...this.toObject(),...t},x(t.day)&&(u.day=Math.min(ol(u.year,u.month),u.day))):u=Pc({...Nc(this.c),...t});let[d,f]=Fd(u,this.o,this.zone);return Md(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Xu.fromDurationLike(e);return Md(this,Id(this,t))}minus(e){if(!this.isValid)return this;let t=Xu.fromDurationLike(e).negate();return Md(this,Id(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Xu.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?Ll.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):Dd}toLocaleString(e=ts,t={}){return this.isValid?Ll.create(this.loc.clone(t),e).formatDateTime(this):Dd}toLocaleParts(e={}){return this.isValid?Ll.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=qd(a);let o=e===`extended`,s=zd(this,o,a);return Wd.indexOf(a)>=3&&(s+=`T`),s+=Bd(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?zd(this,e===`extended`,qd(t)):null}toISOWeekDate(){return Rd(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=qd(o),(r&&Wd.indexOf(o)>=3?`T`:``)+Bd(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return Rd(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return Rd(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?zd(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`)),Rd(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():Dd}[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 Xu.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Kc(t).map(Xu.normalizeUnit),a=e.valueOf()>this.valueOf(),o=rd(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?$u.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),Zd(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?Zd(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 Zo(`min requires all arguments be DateTimes`);return qc(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Zo(`max requires all arguments be DateTimes`);return qc(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return wd(b.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 Cd(b.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(x(t)||x(n))throw new Zo(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=b.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Zo(`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):Ld(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return ts}static get DATE_MED(){return ns}static get DATE_MED_WITH_WEEKDAY(){return rs}static get DATE_FULL(){return is}static get DATE_HUGE(){return as}static get TIME_SIMPLE(){return os}static get TIME_WITH_SECONDS(){return ss}static get TIME_WITH_SHORT_OFFSET(){return cs}static get TIME_WITH_LONG_OFFSET(){return ls}static get TIME_24_SIMPLE(){return us}static get TIME_24_WITH_SECONDS(){return ds}static get TIME_24_WITH_SHORT_OFFSET(){return fs}static get TIME_24_WITH_LONG_OFFSET(){return ps}static get DATETIME_SHORT(){return ms}static get DATETIME_SHORT_WITH_SECONDS(){return hs}static get DATETIME_MED(){return gs}static get DATETIME_MED_WITH_SECONDS(){return _s}static get DATETIME_MED_WITH_WEEKDAY(){return vs}static get DATETIME_FULL(){return ys}static get DATETIME_FULL_WITH_SECONDS(){return bs}static get DATETIME_HUGE(){return xs}static get DATETIME_HUGE_WITH_SECONDS(){return Ss}};function tf(e){if(C.isDateTime(e))return e;if(e&&e.valueOf&&Bc(e.valueOf()))return C.fromJSDate(e);if(e&&typeof e==`object`)return C.fromObject(e);throw new Zo(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function nf(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 rf=`1`,af=`0..1`,of=`*`,sf=`0..*`,cf=new Map([[`-`,[`1`,`1`]],[`<>`,[`*`,`*`]],[`>`,[`*`,`1`]],[`<`,[`1`,`*`]],[`-?`,[`1`,af]],[`?-`,[af,`1`]],[`?-?`,[af,af]],[`?>`,[sf,`1`]],[`>?`,[`*`,af]],[`?>?`,[sf,af]],[`?<`,[af,`*`]],[`<?`,[`1`,sf]],[`?<?`,[af,sf]],[`?<>`,[sf,`*`]],[`<>?`,[`*`,sf]],[`?<>?`,[sf,sf]]]),lf=new Map([...cf.entries()].map(([e,[t,n]])=>[`${t}-${n}`,e]));function uf(e){return cf.get(e)}function df(e){return nf(e).max===1}function ff(e){return nf(e).max===`*`}function pf(e){return nf(e).min===0}function mf(e){return nf(e).min>=1}function hf(e){return e.replace(/\?/g,``)}function gf(e,t){return lf.get(`${e}-${t}`)??`<>`}function _f(e){let{min:t,max:n}=nf(e);return t===0?e:n===`*`?sf:af}function vf(e){let{min:t,max:n}=nf(e);return t>=1?e:n===`*`?`*`:`1`}function yf(e){let{min:t,max:n}=nf(e);return n===`*`?e:t===0?sf:`*`}var w=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}({}),bf=function(e){return e.RefColumnMismatch=`Mismatched optional ref constraints`,e.RecordValueTypeMismatch=`Record type errors`,e.RecordConstraintViolation=`Record constraint violations`,e.Other=`Other`,e}({}),T=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 xf(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},xf=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,T.prototype)}get filepath(){return this.nodeOrToken.filepath}},Sf=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 Cf(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function wf(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Tf(e){let[t]=e;return wf(t)||Cf(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Ef(e){return Cf(e)||wf(e)}function Df(e){let t=M(e);return t!==void 0&&t.length>0}function Of(e){return kf(e)}function kf(e){return e instanceof Em&&e.expression instanceof Tm}function Af(e){return!!e.bodyColon}function jf(e){return e instanceof V&&e.op?.value===`~`&&O(e.expression)}function Mf(e){return e!==void 0&&cf.has(e)}function Nf(e){return e===`<-`||e===`->`}function Pf(e){if(!(e instanceof Em)||!(e.expression instanceof Cm)||e.expression.literal?.kind!==_.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(!Tf(t[e]))return!1;return!0}function Ff(e){return Pf(e)?!0:Wf(e)&&e.expression.variable.value.toLowerCase()===`none`}function If(e){if(D(e)||Lf(e)||Wf(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof V&&Eo.includes(e.op?.value)&&Lf(e.expression)||e instanceof vm)return!0;if(!e||!Gf(e))return!1;let t=lp(e);return t.length===2||t.length===3}function Lf(e){return e instanceof V?Eo.includes(e.op.value)?Lf(e.expression):!1:e instanceof Em&&e.expression instanceof Cm&&e.expression.literal?.kind===_.NUMERIC_LITERAL}function Rf(e){if(!(e instanceof V)||!Mf(e.op?.value))return!1;let t=M(e.expression);return t!==void 0&&t.length>0}function zf(e){if(!(e instanceof V)||!Nf(e.op?.value))return!1;let t=M(e.expression);return t!==void 0&&t.length>0}function Bf(e){return e instanceof ym&&e.elementList.every(O)}function Vf(e){if(!(e instanceof Sm||k(e)||e instanceof Em||e instanceof Om))return!1;for(;e instanceof Sm||e instanceof Om;)if(e instanceof Sm){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Lf(e)||D(e)||Wf(e)))return!1;e=e.callee}else if(e instanceof Om){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Lf(e.name)))return!1;e=e.array}let t=M(e);return t!==void 0&&t.length>0}function Hf(e){return D(e)||Pf(e)}function E(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof Em){r.push(new T(w.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=ap(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 D(e){return e instanceof Em&&(e.expression instanceof Tm&&e.expression.variable instanceof Ha&&e.expression.variable.kind===_.QUOTED_STRING||e.expression instanceof Cm&&e.expression.literal?.kind===_.STRING_LITERAL)}function O(e){return e instanceof Em&&e.expression instanceof Tm&&e.expression.variable instanceof Ha}function Uf(e){return e?e instanceof wm:!1}function Wf(e){return e instanceof Em&&e.expression instanceof Tm&&e.expression.variable?.kind===_.IDENTIFIER}function k(e){return e instanceof gm&&e.leftExpression instanceof L&&e.rightExpression instanceof L&&e.op?.value===`.`}function Gf(e){return O(e)?!0:k(e)&&O(e.rightExpression)&&Gf(e.leftExpression)}function A(e,t){return e instanceof z&&e.isKind(t)}function Kf(e){return e instanceof fm}function qf(e,t){return e instanceof pm&&(t===void 0||e.isKind(t))}function Jf(e){return e instanceof R}function j(e,...t){return e instanceof H&&e.parent instanceof z&&e.parent.isKind(...t)}function Yf(e,t){let n=e.parent;return n instanceof z&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Xf(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 Zf(e){return!!e.parentOfKind(W)}function Qf(e,t){let n=e.parentOfKind(B);return!n||(n.name instanceof Em?P(n.name):ap(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function $f(e){return!(e instanceof gm)||!Mf(e.op?.value)?!1:up(e.leftExpression)!==void 0&&up(e.rightExpression)!==void 0}function ep(e){let t=up(e.leftExpression),n=up(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function tp(e){return e instanceof Em&&e.expression instanceof Tm||e instanceof vm}function np(e){if(O(e))return e;if(k(e)){let t=e.rightExpression;if(t&&O(t))return t}}function rp(e){let t=e.parentNode;return!k(t)||t.rightExpression!==e?!1:!(k(t.parentNode)&&t.parentNode.leftExpression===t)}function ip(e){if(O(e))return e.expression.variable}function ap(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function op(e){if(!(e instanceof z))return;let t=M(e?.name);return t===void 0?void 0:t.join(`.`)}function sp(e){return e.elementList.length===0}function cp(e){return e?.body?e.body instanceof U?e.body.body:[e.body]:[]}function lp(e){if(!e)return;if(!k(e))return[e];let t=lp(e.leftExpression);if(t)return t.push(e.rightExpression),t}function M(e){if(e===void 0)return;let t=lp(e);if(!t)return;let n=[];for(let e of t){let t=P(e);if(typeof t!=`string`)return;n.push(t)}return n}function up(e){if(e===void 0)return;let t=lp(e);if(!t||t.length===0)return;let n=[];if(!O(h(t))){let e=t.pop();if(Bf(e))n=e.elementList;else return}let r=t;if(r.every(O))return{variables:r,tupleElements:n}}function dp(e){if(tp(e))return e instanceof vm?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof ym&&e.elementList.every(tp))return{functional:e.elementList.filter(e=>e instanceof vm),nonFunctional:e.elementList.filter(O)}}function N(e){if(D(e))return e.expression instanceof Tm?e?.expression?.variable?.value:e.expression.literal.value}function fp(e){return e instanceof Em&&e.expression instanceof Cm&&e.expression.literal?.kind===_.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function pp(e){if(!(e instanceof Sm)||!e.callee)return;let t=lp(e.callee);if(!t||t.length===0||!t.every(O))return;let n=[];return Bf(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function P(e){if(O(e))return e.expression.variable.value}function mp(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function hp(e){if(e.name instanceof hm)return ap(e.name)?.toLowerCase();if(e.name instanceof Em)return P(e.name)}function gp(e){return Wf(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Dm}function _p(e){return N(e)===``}function vp(e){return e instanceof vm}function yp(e){let t=fp(e);if(t!==null)return t;if(Lf(e)&&e instanceof V&&e.expression){let t=e.op?.value,n=fp(e.expression);if(n!==null)return t===`-`?-n:n}return null}function bp(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=yp(e);if(t!==null)return t;let n=N(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function xp(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=yp(e);if(t!==null)return Number.isInteger(t)?t:null;let n=N(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var Sp=[`true`,`yes`,`y`,`t`,`1`],Cp=[`false`,`no`,`n`,`f`,`0`];function wp(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 Sp.includes(t)?!0:Cp.includes(t)?!1:null}if(Wf(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=fp(e);if(t===0)return!1;if(t===1)return!0;let n=N(e)?.toLowerCase();if(n){if(Sp.includes(n))return!0;if(Cp.includes(n))return!1}return null}function Tp(e){if(e==null)return null;if(typeof e==`string`)return e;let t=M(e);return t?h(t):N(e)??null}function Ep(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=N(e)??null??bp(e)??wp(e);return t===null?null:t.toString()}var Dp=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Op=[`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`],kp=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Ap(e){if(e==null)return null;let t=typeof e==`string`?e:N(e)??null;if(t===null)return null;for(let e of kp){let n=C.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of Dp){let n=C.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Op){let n=C.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=C.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 jp(e){return e instanceof V?`${e.op?.value}${jp(e.expression)}`:e.expression.literal.value}function Mp(e){return e instanceof V?e.op?.value===`-`?-Mp(e.expression):Mp(e.expression):Number.parseFloat(e.expression.literal.value)}function F(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 Np(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
4
  `)}function Pp(e){let t=M(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function Fp(e){if(Pf(e))return e.expression.literal.value;if(Wf(e)&&P(e)?.toLowerCase()===`none`)return wo}function Ip(e){if(e){if(D(e)){let t=N(e);if(t!==void 0)return{value:t,type:`string`}}if(Lf(e))return{type:`number`,value:Mp(e)};if(Wf(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof vm&&e.value)return{value:e.value.value,type:`expression`};if(Gf(e)){let t=lp(e)?.at(-1),n=t?P(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function Lp(e,t){let r=``,i=null;if(t instanceof Sm){if(i=(t.argumentList?.elementList??[]).map(e=>Lf(e)?jp(e):D(e)?N(e):P(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof Sm||t instanceof Om;)if(t instanceof Sm){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Lf(e)?jp(e):D(e)?N(e):P(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof Om){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}=Pp(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new T(w.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}function Rp(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=zp(e.value);a!==void 0&&(r[t]=a)}return r}function zp(e){if(!e)return;let t=N(e);if(t!==void 0)return t;let n=Fp(e);if(n!==void 0)return n}var I=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.Program=`Program`,e}({}),Bp={Table:`Table`,Enum:`Enum`,TableGroup:`TableGroup`,TablePartial:`TablePartial`,Note:`Note`,Schema:`Schema`},Vp=function(e){return e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.Note=`Note`,e}({}),Hp=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Up=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 F(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()}},Wp=class e extends Up{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(`.`)===v}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}},Gp=class extends Up{constructor({declaration:e,name:t},n,r){super({kind:`Enum`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Kp=class extends Up{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=Np(N(i));if(a)return{value:a,token:F(r)}}},qp=class extends Up{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 lm))}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=Np(N(i));if(a)return{value:a,token:F(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?Fp(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===Um.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===Um.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===Um.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===Um.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof H)||!jf(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===Um.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===Um.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=Fp(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=Np(N(a));if(o)return{value:o,token:F(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Jp=class extends Up{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 lm?this.injectionDeclaration:this.declaration)?.parentOfKind(z);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 lm?this.injectionDeclaration:this.declaration).parentOfKind(z);if(!n)return!1;let r=e.nodeSymbol(n).getFiltered(t);if(!(r instanceof qp))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)||Uo(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 Ip(n)}type(e){if(!(this.declaration instanceof H))return;let n=Lp(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 Gp?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===Um.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=Np(N(i));if(a)return{value:a,token:F(r)}}},Yp=class extends Up{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?Fp(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=Np(N(i));if(a)return{value:a,token:F(r)}}},Xp=class extends Up{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}},Zp=class extends Up{constructor({declaration:e,name:t},n,r){super({kind:`Note`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Qp=class extends Up{constructor({declaration:e,name:t},n,r){super({kind:`TablePartial`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},$p=class extends Up{constructor({declaration:e,name:t},n,r){super({kind:`PartialInjection`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},em=class extends Up{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},tm=class extends Up{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}},nm=class extends Up{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}},rm=class extends Up{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}},im=class extends Up{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}},am=class extends Up{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}},om=class extends Up{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 Wp&&r.inNestedSchema(e,t))return!0;return!1}},sm=class extends Up{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}},cm=class extends Up{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(fm);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},lm=class extends Jp{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},um=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},L=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 Ha?qa(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 Ha?Ka(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 z||e instanceof R)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}},dm=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}({}),R=class extends L{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>`)}},fm=class extends L{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 $a(this.useKeyword)}},pm=class extends L{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 Object.values(I).find(t=>t.toLowerCase()===e)}},mm=class extends L{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}},z=class e extends L{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))}},hm=class extends L{constructor({identifiers:e=[]},t,n){super(t,`<identifier-stream>`,n,e||[]),this.identifiers=e}},B=class extends L{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}},V=class extends L{constructor({op:e,expression:t},n,r){super(n,`<prefix-expression>`,r,[e,t]),this.op=e,this.expression=t}},gm=class extends L{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}},_m=class extends L{constructor({op:e,expression:t},n,r){super(n,`<postfix-expression>`,r,[t,e]),this.op=e,this.expression=t}},vm=class extends L{constructor({value:e},t,n){super(t,`<function-expression>`,n,[e]),this.value=e}},H=class extends L{constructor({callee:e,args:t=[]},n,r){super(n,`<function-application>`,r,[e,...t]),this.callee=e,this.args=t}},U=class extends L{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 L{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,`<list-expression>`,a,[e,...km(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},ym=class extends L{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,`<tuple-expression>`,a,[e,...km(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},bm=class extends L{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,`<comma-expression>`,r,[...km(e,t)]),this.elementList=e,this.commaList=t}},xm=class extends ym{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=`<group-expression>`}},Sm=class extends L{constructor({callee:e,argumentList:t},n,r){super(n,`<call-expression>`,r,[e,t]),this.callee=e,this.argumentList=t}},Cm=class extends L{constructor({literal:e},t,n){super(t,`<literal>`,n,[e]),this.literal=e}},wm=class extends L{constructor({token:e},t,n){super(t,`<wildcard>`,n,[e]),this.token=e}},Tm=class extends L{constructor({variable:e},t,n){super(t,`<variable>`,n,[e]),this.variable=e}},Em=class extends L{constructor({expression:e},t,n){super(t,`<primary-expression>`,n,[e]),this.expression=e}},Dm=class extends L{constructor({prevToken:e},t,n){let r=Ha.create(_.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,`<dummy>`,n,[r])}},Om=class extends L{constructor({expression:e,indexer:t},n,r){super(n,`<array>`,r,[e,t]),this.array=e,this.indexer=t}};function km(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?xr(Ra(e,t)):xr(Ra(t,e))).filter(e=>e!==null)}var Am=function(e){return e.Table=`table`,e}({});function jm(e,t,n){let r=t,i=e;if(i instanceof Sm&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Wf(i)||r.length===0)return;let a=[...r],o=ip(i),s=a.pop();if(!(s instanceof U))return;let c=h(a)instanceof W?a.pop():void 0;if(a.length===3){let e=ip(a[1]);return!e||!Ya(e)?void 0:n.create(z,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(z,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(z,{type:o,attributeList:c,body:s})}function G(e){e&&(e instanceof Ha?Mm(e):Nm(e))}function Mm(e){e.kind!==_.EOF&&(e.isInvalid=!0)}function Nm(e){if(e instanceof z)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 hm)e.identifiers.forEach(G);else if(e instanceof B)G(e.name),G(e.colon),G(e.value);else if(e instanceof V)G(e.op),G(e.expression);else if(e instanceof gm)G(e.leftExpression),G(e.op),G(e.rightExpression);else if(e instanceof _m)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 ym)G(e.tupleOpenParen),e.commaList.forEach(G),e.elementList.forEach(G),G(e.tupleCloseParen);else if(e instanceof bm)e.commaList.forEach(G),e.elementList.forEach(G);else if(e instanceof Sm)G(e.callee),G(e.argumentList);else if(e instanceof H)G(e.callee),e.args.forEach(G);else if(e instanceof Em)G(e.expression);else if(e instanceof vm)G(e.value);else if(e instanceof Tm)G(e.variable);else if(e instanceof Cm)G(e.literal);else if(e instanceof xm)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof Om)G(e.array),G(e.indexer);else if(e instanceof R)e.body.forEach(G),G(e.eof);else if(!(e instanceof Dm))if(e instanceof fm)G(e.useKeyword),G(e.specifiers),G(e.fromKeyword),G(e.importPath);else if(e instanceof mm)G(e.openBrace),e.specifiers.forEach(G),G(e.closeBrace);else if(e instanceof pm)G(e.importKind),G(e.name),G(e.asKeyword),G(e.alias);else if(e instanceof wm)G(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Pm(...e){return e.filter(e=>e!==void 0)}function Fm(e){if(e instanceof R)return Pm(...e.body,e.eof);if(e instanceof z)return Pm(e.type,e.targetKind,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof B)return Pm(e.name,e.colon,e.value);if(e instanceof hm)return e.identifiers;if(e instanceof Cm)return e.literal?[e.literal]:[];if(e instanceof Tm)return Pm(e.variable);if(e instanceof V)return Pm(e.op,e.expression);if(e instanceof gm)return Pm(e.leftExpression,e.op,e.rightExpression);if(e instanceof _m)return Pm(e.expression,e.op);if(e instanceof vm)return Pm(e.value);if(e instanceof H)return Pm(e.callee,...e.args);if(e instanceof U)return Pm(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof W)return Pm(e.listOpenBracket,...Im(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof ym)return Pm(e.tupleOpenParen,...Im(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof bm)return Pm(...Im(e.elementList,e.commaList));if(e instanceof Sm)return Pm(e.callee,e.argumentList);if(e instanceof Em)return Pm(e.expression);if(e instanceof Om)return Pm(e.array,e.indexer);if(e instanceof Dm)return[];if(e instanceof fm)return Pm(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof mm)return Pm(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof pm)return Pm(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof wm)return Pm(e.token);throw e instanceof xm?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Im(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 Lm(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function Rm(e){if(!e)return[];if(O(e))return[{variables:[e],tupleElements:[]}];if(e instanceof gm){let t=up(e);return t?[t]:[...Rm(e.leftExpression),...Rm(e.rightExpression)]}if(e instanceof V||e instanceof _m)return Rm(e.expression);if(e instanceof ym){let t=up(e);return t?[t]:e.elementList.flatMap(Rm)}return[]}function zm(e,n){let r=n.parentNode;if(!r||!k(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;k(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Bm(e,t,r,i){if(!O(r))return new n(void 0);let a=mp(r)??``;if(k(r.parentNode)&&r.parentNode.rightExpression===r&&rp(r)){let t=zm(e,r);if(!t)return new n(void 0);if(i===I.Column){if(t.isKind(I.Table)){let i=e.lookupMembers(t,I.Column,a);return i?n.create(i):new n(void 0,[new T(w.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${t.name}'`,r)])}return new n(void 0,[new T(w.BINDING_ERROR,`Column '${a}' does not exist`,r)])}else{if(t.isKind(I.Schema)){let i=e.lookupMembers(t,I.Table,a);return i?n.create(i):new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist`,r)])}}let o=zm(e,r);if(o){if(o.isKind(I.Schema)){let t=e.lookupMembers(o,[I.Table,I.Schema],a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${a}' does not exist`,r)])}if(i===I.Column&&o.isKind(I.Table)){let t=e.lookupMembers(o,I.Column,a);return t?n.create(t):new n(void 0,[new T(w.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(k(s.parentNode)&&s.parentNode.leftExpression===s||i===I.Table){let i=e.lookupMembers(t,I.Schema,a);return i?n.create(i):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${a}' does not exist in Schema 'public'`,r)])}let o=e.lookupMembers(t,I.Table,a);return o?n.create(o):new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Vm(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Wp&&e.isPublicSchema())}function Hm(e,n){let r=e.parseFile(n).getValue().ast;return e.nodeSymbol(r).getFiltered(t)}var Um=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}({}),Wm=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=>Hm(e,t)||[]).filter(r=>e.reachableFiles(r.filepath).some(e=>e.equals(n))&&t.every(t=>r.inNestedSchema(e,t)))}},Gm=class extends Wm{constructor(e){super(e),this.kind=`ref`}container(e){let n=this.declaration.parentOfKind(z);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof z){let t=cp(this.declaration)[0];if(!(t instanceof H))return[];let n=t.callee;return n instanceof gm?$m(e,n.leftExpression):[]}if(this.declaration instanceof B){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 z){let t=cp(this.declaration)[0];if(!(t instanceof H))return[];let n=t.callee;return n instanceof gm?$m(e,n.rightExpression):[]}if(this.declaration instanceof B){let t=this.declaration.value;return t instanceof V?$m(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof z){let t=cp(this.declaration)[0];if(!(t instanceof H))return;let n=t.callee;return n instanceof gm?eh(e,n.leftExpression):void 0}if(this.declaration instanceof B)return this.container(e)}rightTable(e){if(this.declaration instanceof z){let t=cp(this.declaration)[0];if(!(t instanceof H))return;let n=t.callee;return n instanceof gm?eh(e,n.rightExpression):void 0}if(this.declaration instanceof B){let t=this.declaration.value;return t instanceof V?eh(e,t.expression)??this.container(e):void 0}}op(e){return this.opToken()?.value}opToken(){if(this.declaration instanceof z){let e=cp(this.declaration)[0];if(!(e instanceof H))return;let t=e.callee;return t instanceof gm?t.op:void 0}if(this.declaration instanceof B){let e=this.declaration.value;return e instanceof V?e.op:void 0}}cardinalities(e){let t=this.op(e);return t?uf(t):void 0}leftCardinality(e){let t=this.cardinalities(e);return t?nf(t[0]):void 0}rightCardinality(e){let t=this.cardinalities(e);return t?nf(t[1]):void 0}active(e){if(!(this.declaration instanceof z))return!0;let n=cp(this.declaration)[0];return n?!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length:!0}leftToken(){if(this.declaration instanceof z){let e=cp(this.declaration)[0];if(e instanceof H){let t=e.callee;if(t instanceof gm&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof B){let e=this.declaration.parentOfKind(H);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof z){let e=cp(this.declaration)[0];if(e instanceof H){let t=e.callee;if(t instanceof gm&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof B,this.declaration}owners(e){let t=this.leftTable(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Km=class extends Wm{constructor(e){super(e),this.kind=`dep`}container(e){let n=this.declaration.parentOfKind(z);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}edgeExpressions(){return this.declaration instanceof z?cp(this.declaration).filter(e=>e instanceof H).map(e=>e.callee).filter(e=>e instanceof gm):[]}upstreamColumns(e){if(this.declaration instanceof z)return this.edgeExpressions().map(t=>$m(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof B){let t=this.declaration.value;if(!(t instanceof V))return[];let n=t.op?.value,r=this.hostColumn(e),i=$m(e,t.expression);if(n===`->`)return[r?[r]:[]];if(n===`<-`)return[i]}return[]}downstreamColumns(e){if(this.declaration instanceof z)return this.edgeExpressions().map(t=>$m(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof B){let t=this.declaration.value;if(!(t instanceof V))return[];let n=t.op?.value,r=this.hostColumn(e),i=$m(e,t.expression);if(n===`->`)return[i];if(n===`<-`)return[r?[r]:[]]}return[]}upstreamTables(e){if(this.declaration instanceof z)return this.edgeExpressions().map(t=>th(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof B){let t=this.declaration.value;if(!(t instanceof V))return[];let n=t.op?.value,r=th(e,t.expression);if(n===`->`)return[this.container(e)];if(n===`<-`)return[r]}return[]}downstreamTables(e){if(this.declaration instanceof z)return this.edgeExpressions().map(t=>th(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof B){let t=this.declaration.value;if(!(t instanceof V))return[];let n=t.op?.value,r=th(e,t.expression);if(n===`->`)return[r];if(n===`<-`)return[this.container(e)]}return[]}hostColumn(e){if(!(this.declaration instanceof B))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)))}},qm=class extends Wm{constructor(e){super(e),this.kind=`partial ref`}container(e){let n=this.declaration.parentOfKind(z);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof B))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 B))return[];let t=this.declaration.value;return t instanceof V?$m(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof B)return this.container(e)}rightTable(e){if(!(this.declaration instanceof B))return;let t=this.declaration.value;if(t instanceof V)return eh(e,t.expression)??this.container(e)}op(e){return this.opToken()?.value}opToken(){if(!(this.declaration instanceof B))return;let e=this.declaration.value;if(e instanceof V)return e.op}cardinalities(e){let t=this.op(e);return t?uf(t):void 0}leftToken(){if(this.declaration instanceof B){let e=this.declaration.parentOfKind(H);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof B,this.declaration}owners(e){let t=this.leftTablePartial(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Jm=class extends Wm{constructor(e){super(e),this.kind=`table checks`,this.ownerTable=e.parentNode?.parentOfKind(z)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Ym=class extends Wm{constructor(e){super(e),this.kind=`indexes`,this.ownerTable=e.parentNode?.parentOfKind(z)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Xm=class extends Wm{constructor(e){super(e),this.kind=`records`}table(e){let n=this.declaration,i=n.parent;if(i instanceof z&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof Sm))return;let o=pp(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]):[]}},Zm=class extends Wm{constructor(e){super(e),this.kind=`metadata element`}target(e){let n=this.declaration.name;if(!n)return;let r=np(n)??n;return e.nodeReferee(r).getFiltered(t)?.originalSymbol}owners(e){let n=this.target(e);if(!n)return[];if(n.kind===I.Column){let r=n.declaration?.parentOfKind(z),i=r?e.nodeSymbol(r).getFiltered(t)?.originalSymbol:void 0;if(!i)return[];n=i}return this.resolveOwnerPrograms(e,[n])}},Qm=class extends Wm{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 $m(e,n){if(!n)return[];let r=up(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(I.Column)?[r]:[]}):[]}function eh(e,n){if(!n)return;let r=up(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 th(e,n){if(!n)return;let r=up(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(I.Table))return n}let a=r.variables.at(-2);if(a)return e.nodeReferee(a).getFiltered(t)}var nh=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=F(e),n=e.callee instanceof vm?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof W);return a&&(r=N(E(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}},ih={nodeMetadata(t,i){if(A(i,r.Checks)){let t=i.parent;return!t||!A(t,r.Table)&&!A(t,r.TablePartial)?n.create(e):n.create(new Jm(i))}return n.create(e)},bindNode(t,i){return A(i,r.Checks)?n.create(void 0,new nh(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Um.TableChecks?r.declaration instanceof z?new rh(t,r.declaration).interpret():n.create(void 0):n.create(e)}},ah=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof R)&&!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]=g(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(Rm).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 gm)||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 T(w.DEP_SELF_LOOP,`A column cannot depend on itself`,e)]:[]}endpointSymbol(e){if(!e)return;let n=up(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=up(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(I.Column))return`column`;if(i?.isKind(I.Table))return`table`}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},oh=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.dep={}}interpret(){this.dep.token=F(this.declarationNode);let e=[...this.interpretName(),...this.interpretEdges(),...this.interpretSettings()];return n.create(this.dep,e)}interpretName(){if(!(this.declarationNode instanceof z))return this.dep.name=null,this.dep.schemaName=null,[];let e=[],t=this.declarationNode.name?M(this.declarationNode.name)??[]:[];return this.dep.name=t.pop()||null,t.length>1&&e.push(new T(w.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 z){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 z);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:Np(String(n)),token:F(t)})}continue}if(!(a instanceof H))continue;if(n===i.Color){let e=Fp(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:Np(String(o)),token:F(t)}:e[n]=o)}}}}return Object.keys(e).length>0&&(this.dep.metadata=e),[]}consumeSettings(e,t){let n=E(e).getValue();for(let[e,r]of Object.entries(n)){let n=r[0];if(!n)continue;if(e===i.Color){let e=Fp(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:Np(String(a)),token:F(n)}:t[e]=a)}}extractAttrValue(e){if(e instanceof hm)return ap(e);let t=fp(e);if(t!==null)return t;let n=N(e);return n===void 0?P(e):n}};function sh(e){let t=e.parent;for(;t;){if(t instanceof z&&t.isKind(r.Dep))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var ch={nodeReferee(r,i){if(!O(i)&&!k(i)||!sh(i)||i.parentOfKind(B))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):lh(r,o,i)},nodeMetadata(t,a){if(A(a,r.Dep)){let t=cp(a);return t.length===0||!t.some(e=>e instanceof H&&e.callee instanceof gm)?n.create(e):n.create(new Km(a))}return a instanceof B?!(a.name instanceof hm)||ap(a.name)?.toLowerCase()!==i.Dep?n.create(e):n.create(new Km(a)):n.create(e)},bindNode(t,i){return A(i,r.Dep)?n.create(void 0,new ah(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Km?new oh(t,r,i).interpret():n.create(e)}};function lh(e,r,i){if(!O(i))return new n(void 0);let a=mp(i)??``;if(!k(i.parentNode)){let t=Vm(e,r);if(t){let r=e.lookupMembers(t,I.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,I.Table,a);return o?n.create(o):new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=i.parentNode;if(o.rightExpression===i){let r=zm(e,i);if(r?.isKind(I.Schema)){let t=e.lookupMembers(r,I.Table,a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist in Schema '${r.name}'`,i)])}if(r?.isKind(I.Table)){let o=e.lookupMembers(r,I.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 T(w.BINDING_ERROR,`Column '${a}' does not exist in Table '${s}'`,i)])}return new n(void 0)}if(o.leftExpression===i){if(k(o.parentNode)&&o.parentNode.leftExpression===o){let t=e.lookupMembers(r,I.Schema,a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=e.lookupMembers(r,I.Schema,a);if(t)return n.create(t);let s=Vm(e,r);if(s){let t=e.lookupMembers(s,I.Table,a);if(t)return n.create(t)}let c=e.lookupMembers(r,I.Table,a);return c?n.create(c):new n(void 0,[new T(w.BINDING_ERROR,`Schema or Table '${a}' does not exist`,i)])}return new n(void 0)}var uh=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]=g(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]=g(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Uf(e.callee)?[]:[e.callee,...e.args].flatMap(Rm).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]=g(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Uf(e.callee)?[]:Rm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=g(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Uf(e.callee)?[]:Rm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=g(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Uf(e.callee)?[]:Rm(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},dh=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&&Uf(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]=g(e.body,e=>e instanceof z),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&&Uf(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&&np(n.callee),r=e&&this.compiler.nodeReferee(e).getFiltered(t);if(r?.declaration instanceof z){let e=M(r.declaration.name)??[];if(e.length>0){let t=e[e.length-1],n=e.length>1?e.slice(0,-1).join(`.`):v;i.push({name:t,schemaName:n});continue}}let a=M(n.callee)??[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[0]:v;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?Fa(r.filter(e=>e.isKind(I.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function fh(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var ph={getDuplicateError(e,t,n){return new T(w.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new T(w.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},mh={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return A(a,r.DiagramView)?new n(i.symbolFactory.create(em,{declaration:a,name:o},a.filepath)):j(a,r.DiagramView)&&a instanceof wm?new n(i.symbolFactory.create(tm,{declaration:a,name:o},a.filepath)):j(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(im,{declaration:a,name:o},a.filepath)):j(a,r.DiagramViewTables)?new n(i.symbolFactory.create(nm,{declaration:a,name:o},a.filepath)):j(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(rm,{declaration:a,name:o},a.filepath)):j(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(am,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&Zf(a))return n.create(e);let o=hh(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)?gh(i,c,a):o.isKind(r.DiagramViewNotes)?_h(i,c,a,I.StickyNote):o.isKind(r.DiagramViewTableGroups)?_h(i,c,a,I.TableGroup):o.isKind(r.DiagramViewSchemas)?vh(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(I.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!A(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of cp(o))if(e instanceof H){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof z&&c.push(...cp(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(I.DiagramViewSchema,I.DiagramViewTableGroup,I.DiagramViewTable,I.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(R_).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(ph.getFieldDuplicateError(n,e.kind,i)),s.push(ph.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!A(a,r.DiagramView))return n.create(e);let o=new uh(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 em?r.declaration instanceof z?new dh(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function hh(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 z)||!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 z)||!o.isKind(r.DiagramView)))return i}function gh(e,r,i){let a=mp(i);if(a===void 0)return n.create(void 0);if(k(i.parentNode)){let t=zm(e,i);if(t){if(t.isKind(I.Schema)){let r=rp(i),o=e.lookupMembers(t,r?I.Table:I.Schema,a);return o?n.create(o):new n(void 0,[new T(w.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,I.Schema,a);return o?n.create(o):new n(void 0,[new T(w.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(I.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,I.Table,a);return s?n.create(s):new n(void 0,[new T(w.BINDING_ERROR,`Could not find table '${a}'`,i)])}function _h(e,t,r,i){let a=mp(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 T(w.BINDING_ERROR,`Could not find ${i===I.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function vh(e,t,r){let i=mp(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var yh=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 z);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},bh=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=F(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=F(t),n.name=P(t.callee);let r=E(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Np(N(r.value)),token:F(r)},this.enum.values.push(n),[]})}},xh={getDuplicateError(e,t,n){return new T(w.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new T(w.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},Sh={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return A(a,r.Enum)?new n(i.symbolFactory.create(Gp,{declaration:a,name:o},a.filepath)):j(a,r.Enum)?new n(i.symbolFactory.create(Kp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(I.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof z))return new n([]);let o=cp(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(I.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push(xh.getFieldDuplicateError(t,r)),c.push(xh.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!A(a,r.Enum))return n.create(e);let o=new yh(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 Gp?new bh(t,r,i).interpret():n.create(e)}},Ch=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof z)||!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]=g(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=M(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(Rm).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=mp(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new T(w.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},wh=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=F(e),a=[e.callee,...e.args],o,s,c,l,u;h(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=N(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=N(e.value);t!==void 0&&(l={value:t,token:F(e)})}u=P(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof Sm))return e;let t=[],n=e;for(;n instanceof Sm&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=dp(e);if(t){for(let e of t.functional)n.push({value:e.value?.value??``,type:`expression`,token:F(e)});for(let e of t.nonFunctional)n.push({value:mp(e)??``,type:`column`,token:F(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}},Th={nodeMetadata(t,i){if(!A(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!A(a,r.Table)&&!A(a,r.TablePartial)?n.create(e):n.create(new Ym(i))},nodeReferee(i,a){if(!O(a)||Zf(a))return n.create(e);let o=a;for(;o&&!A(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!A(s,r.Table)&&!A(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=O(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,I.Column,l);if(u)return n.create(u);let d=A(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new T(w.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return A(i,r.Indexes)?n.create(void 0,new Ch(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Um.Indexes?r.declaration instanceof z?new wh(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function Eh(e,n){let r=lp(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof ym){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 ym)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function Dh(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 T(w.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new T(w.CIRCULAR_REF,`References with same endpoints exist`,n),new T(w.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var Oh=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 z&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new T(w.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof z&&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(...kh(this.compiler,a)),e.push(...this.checkDuplicateRefs()),e.push(...this.checkTableGroups()),new n(void 0,e)}checkDuplicateRefs(){let e=[],n=new Map,i=this.compiler.reachableFiles(this.ast.filepath);for(let a of i){let i=this.compiler.parseFile(a).getFiltered(t);if(!i)continue;let{ast:o}=i;for(let t of o.body){if(!(t instanceof z)||!t.type)continue;let i=t;A(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),A(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),A(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of cp(e)){if(!(r instanceof H)||!r.callee||!$f(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=Eh(this.compiler,i.leftExpression),o=Eh(this.compiler,i.rightExpression);!a||!o||n.push(...Dh(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of cp(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 V)||!i.op||!Mf(i.op.value)||!i.expression)continue;let a=Eh(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...Dh(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of cp(e)){if(!(r instanceof H)||!r.callee)continue;let e=P(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 V&&(!r.op||!Mf(r.op.value)||r.expression&&O(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new T(w.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){let i=this.compiler.parseFile(a).getFiltered(t);if(!i)continue;let{ast:o}=i;for(let i of o.body){if(!(i instanceof z)||!i.type)continue;let a=i;if(!A(a,r.TableGroup))continue;let o=a.name?M(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=cp(a);for(let r of c){if(!(r instanceof H)||!r.callee)continue;let i=lp(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=M(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new T(w.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 kh(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 Wp&&a.push(...kh(e,t,r));return a}function Ah(e,t,n){t.isKind(I.Table)?e.externals.tables.push(n):t.isKind(I.Enum)?e.externals.enums.push(n):t.isKind(I.TableGroup)?e.externals.tableGroups.push(n):t.isKind(I.TablePartial)?e.externals.tablePartials.push(n):t.isKind(I.StickyNote)&&e.externals.notes.push(n)}function jh(e,t){return e>=t.start&&e<t.end}function Mh(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 Nh(e,t){let n=e.getSource(t.filepath);if(n)return n.slice(t.start,t.end).trim()}function Ph(e,t){return t.map(t=>t.qualifiedName(e).join(`.`)).join(`, `)}function Fh(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Ph(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=Nh(e,a),u=i[0]?.declaration,d=u&&Nh(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(`
5
5
  `);return new Sf(w.INVALID_REF_RELATIONSHIP,c,t,{category:bf.RefColumnMismatch,explanation:f,quickFixes:o})}function Ih(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Ph(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=Nh(e,a),u=i[0]?.declaration,d=u&&Nh(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(`
6
6
  `);return new Sf(w.INVALID_REF_RELATIONSHIP,c,t,{category:bf.RefColumnMismatch,explanation:f,quickFixes:o})}function Lh(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Ph(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 \`${Nh(e,a)??r}\`, the operator \`${r}\` allows many.`,`- \`${s}\` has a unique constraint, so each value can appear at most once.`].join(`
7
7
  `);return new Sf(w.INVALID_REF_RELATIONSHIP,c,t,{category:bf.RefColumnMismatch,explanation:l,quickFixes:o})}function Rh(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Ph(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 \`${Nh(e,a)??r}\`, the operator \`${r}\` implies \`${s}\` has at most one row.`,`- \`${s}\` has no unique or primary key constraint.`].join(`
8
- `);return new Sf(w.INVALID_REF_RELATIONSHIP,c,t,{category:bf.RefColumnMismatch,explanation:l,quickFixes:o})}function zh(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 Bh(e,t){return e.length>1?`Composite ${t}`:t}function Vh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`NULL not allowed for NOT NULL column \`${n}\` without a default value or auto-increment`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is marked NOT NULL and has no default value or auto-increment.`})}function Hh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid enum value for column \`${n}\``,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` uses an enum type. The value must match one of the defined enum members.`})}function Uh(e,t){let{colName:n,typeName:r}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid numeric value for column \`${n}\``,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` has type \`${r}\` which expects a numeric value. Provide a valid integer or decimal.`})}function Wh(e,t){let{colName:n,value:r}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid integer value \`${r}\` for column \`${n}\`: expected integer, got decimal`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is an integer column and cannot store decimal values.`})}function Gh(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,totalDigits:s}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds precision: expected at most ${a} total digits, got ${s}`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${a} total digits. The value \`${i}\` has ${s}.`})}function Kh(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,decimalDigits:s}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds scale: expected at most ${o} decimal digits, got ${s}`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${o} decimal places. The value \`${i}\` has ${s}.`})}function qh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid boolean value for column \`${n}\``,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is a boolean column. Use \`true\`/\`false\`, \`1\`/\`0\`, or \`'yes'\`/\`'no'\`.`})}function Jh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid datetime value for column \`${n}\``,e,{category:bf.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 Yh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid string value for column \`${n}\``,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is a string column. Values must be wrapped in quotes.`})}function Xh(e,t){let{colName:n,typeName:r,typeArg:i,maxLength:a,actualLength:o}=t;return new Sf(w.INVALID_RECORDS_FIELD,`String value for column \`${n}\` exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${i})\`, limiting values to ${a} bytes in UTF-8 encoding. The provided value uses ${o} bytes.`})}function Zh(e,t,n){let{table:r,columns:i}=n,a=zh(e,r,i),o=Bh(i,`PK`);return new Sf(w.INVALID_RECORDS_FIELD,`NULL in ${o}: \`${a}\` cannot be NULL`,t,{category:bf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key and cannot be NULL.`})}function Qh(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=zh(e,r,i),s=Bh(i,`PK`);return new Sf(w.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:bf.RecordConstraintViolation,explanation:`\`${o}\` is a primary key and must be unique across all rows.`})}function $h(e,t,n){let{table:r,columns:i}=n,a=zh(e,r,i),o=Bh(i,`PK`);return new Sf(w.INVALID_RECORDS_FIELD,`${o}: Column \`${a}\` is missing from record and has no default value`,t,{category:bf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key with no default or auto-increment, so it must be specified in the records block.`})}function eg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=zh(e,r,i,s),u=zh(e,a,o,s);return new Sf(w.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` must not be NULL`,t,{category:bf.RecordConstraintViolation,explanation:`\`${l}\` references \`${u}\`, so every row must have a non-null value.`})}function tg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=zh(e,r,i,s),u=zh(e,a,o,s);return new Sf(w.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` does not exist in \`${u}\``,t,{category:bf.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 ng(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=zh(e,r,i),s=Bh(i,`UNIQUE`);return new Sf(w.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:bf.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 ig(e,t){return e?`${e}.${t}`:`${v}.${t}`}function ag(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 og(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function sg(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 cg(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function lg(e,t){let{token:n}=t;return e.nodeAtPosition(n.filepath,n.start.offset)??e.parse.ast(n.filepath)}function ug(e,t,n,r){return ka(r.values)?[]:Sa(hg(t,e),i=>dg(e,t,n,i,r))}function dg(e,t,n,r,i){let a=rg(i),o=mg(e,t,n,r,i);if(!ka(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=g(a,t=>og(e,t,s)),u=fg(e,t,s,c),d=r.some(t=>t.increment(e))?[]:pg(e,t,r,l);return[...u,...d]}function fg(e,t,n,r){if(ka(r))return[];let i=n.map(e=>e.name??``);return Sa(r,r=>cg(r,i).map(r=>Zh(e,lg(e,r),{table:t,columns:n})))}function pg(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r,t=>ag(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=sg(e,r,n);return cg(r,i).map(r=>Qh(e,lg(e,r),{table:t,columns:n,valueStr:a}))}))}function mg(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=fa(a,Array.from(o));if(ka(s))return[];let c=new Set(s),l=r.filter(e=>c.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e));return ka(l)?[]:i.values.map(()=>$h(e,n,{table:t,columns:l}))}function hg(e,t){let n=e.mergedColumns(t),r=Aa(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=>$r(e.columns.map(e=>r[e.value]))):[]})]}function gg(e,t,n){if(ka(n.values))return[];let r=rg(n);return Sa(_g(e,t),n=>vg(e,t,n,r))}function _g(e,t){let n=t.mergedColumns(e),r=Aa(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=>$r(e.columns.map(e=>r[e.value]))):[]})]}function vg(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r.filter(t=>!og(e,t,n)),t=>ag(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=sg(e,r,n);return cg(r,i).map(r=>ng(e,lg(e,r),{table:t,columns:n,valueStr:a}))}))}function yg(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(ig(a,e),i)}return r}function bg(e,t,n,r){let i=yg(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!ka(t.record.values)&&a.add(e);return Sa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(ig(e.schemaName,e.tableName))):!1),t=>xg(e,t,i,r))}function xg(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(ig(i.schemaName,i.tableName)),s=n.get(ig(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=$r(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=$r(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=nf(i.relation),{min:m,max:ee}=nf(a.relation),te=p===1&&m===0||p!==`*`&&ee!==`*`,ne=ee===1&&f===0;return[...te?[]:Sg(e,o,u,s,d,i.relation,a.relation,r),...ne?[]:Sg(e,s,d,o,u,a.relation,i.relation,r)]}function Sg(e,t,n,r,i,a,o,s){if(!t.record||ka(t.record.values))return[];let{min:c,max:l}=nf(a),{min:u,max:d}=nf(o),f=$r(n.map(e=>e.name));$r(i.map(e=>e.name));let p=u===0,m=rg(t.record),ee=r.record?rg(r.record):[],te=new Set(ee.map(t=>ag(e,t,i))),ne={leftTable:t.tableSymbol,leftColumns:n,rightTable:r.tableSymbol,rightColumns:i,filepath:s};return Sa(m,t=>{if(og(e,t,n)){if(p)return[];let r=sg(e,t,n);return cg(t,f).map(t=>eg(e,lg(e,t),{...ne,valueStr:r}))}if(d===`*`&&c===0&&l===`*`)return[];let r=ag(e,t,n);if(te.has(r))return[];let i=sg(e,t,n);return cg(t,f).map(t=>tg(e,lg(e,t),{...ne,valueStr:i}))})}function Cg(e){return e instanceof Km&&e.declaration instanceof z&&e.declaration.body instanceof U}function wg(e,t){let n=e.edges??[];if(n.length===0||!Cg(t))return[];let r=[],i=ig(n[0].downstream.schemaName,n[0].downstream.tableName);for(let e=1;e<n.length;e++){let a=ig(n[e].downstream.schemaName,n[e].downstream.tableName);if(a!==i){r.push(new T(w.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 T(w.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 Tg(e,t){let n=kg(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof B?hp(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof z){let n=Ag(e,t);if(n)return{kind:`body`,declaration:n}}}function Eg(e,t){let n=kg(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof z){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 Dg(e,t,n,r){if(n===null)return Og(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=Tg(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return Eg(e,i)}function Og(e,t,n){let r=Tg(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 kg(e){if(e instanceof H)return e.args.find(e=>e instanceof W);if(e instanceof z){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof H)return t.args.find(e=>e instanceof W)}}function Ag(e,t){let n=e.body;if(!(!n||Af(e)||n instanceof H)){for(let e of n.body)if(e instanceof z&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function jg(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=nf(l),d=n===`left`?c[1]:c[0],f=nf(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),ee=n===`left`?t.leftToken():t.rightToken(),te=n===`left`?t.rightToken():t.leftToken(),ne=[];function re(e,t,n){ne.push(n(e));for(let r of t)r.declaration&&r.declaration!==e&&ne.push(n(r.declaration))}let ie=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&ie&&m.length>0&&m.every(t=>t.nullable(e))){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Ng(s,_f(l),d,n,`Make '${r}' optional in the ref`),...i?m.map(t=>Pg(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Fh(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.min===0&&ie&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Ng(s,vf(l),d,n,`Make '${r}' required in the ref`),...i?m.map(t=>Fg(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Ih(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.max===`*`&&Ig(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Ng(s,`1`,d,n,`Make '${r}' one in the ref`)].filter(e=>!!e);re(ee,p,n=>Lh(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}if(u.max===1&&!Ig(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Ng(s,yf(l),d,n,`Make '${r}' many in the ref`),a&&p.length===1&&Lg(p[0],e)].filter(e=>!!e);re(ee,p,n=>Rh(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}return ne}function Mg(e,t){return[...jg(e,t,`right`,{allowOtherColFix:!1}),...jg(e,t,`left`,{allowOwnColFix:!1})]}function Ng(e,t,n,r,i){let a=gf(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 Pg(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=Og(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=Eg(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[a]}}function Fg(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=Og(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 Ig(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 lm?r.injectionDeclaration:r.declaration)?.parentOfKind(z);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof qp))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 Lg(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=Eg(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,shortTitle:`Add unique`,filepath:e.declaration.filepath,edits:[n]}}var Rg=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],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:F(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.infos.push(...this.validateRecords()),new n(this.db,this.errors,this.warnings,this.infos)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof cm)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 Wp);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Wp){n.push(t);continue}if(!(t instanceof cm))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 qp?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof qp?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}]};Ah(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 Xm))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 Um.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 T(w.SAME_ENDPOINT,`Ref with same endpoints already exists`,a.declaration));break}n.add(e)}this.db.refs.push(e);break}case Um.Dep:{let e=o,t=a instanceof Km?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 T(w.SAME_ENDPOINT,`Dep with same endpoints already exists`,e));break}let i=wg(e,a);if(i.length>0){this.errors.push(...i);break}this.db.deps.push(e);break}case Um.Records:if(a instanceof Xm){let e=a.table(this.compiler)?.originalSymbol.intern()??``,t=e?i.get(e):void 0;if(t&&t.count>1){this.errors.push(new T(w.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 Um.Project:this.db.project=o;break;case Um.MetadataElement:default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof sm)||!t.isKind(I.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:Am.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 Wp))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(I.Table))continue;let t=e.originalSymbol;if(!(t instanceof qp))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 Xm))continue;let i=r.table(this.compiler);if(!(i instanceof qp))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...ug(this.compiler,i,r.declaration,o)),e.push(...gg(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(...bg(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof qm);for(let t of e)this.infos.push(...Mg(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof qm),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 lm&&t.declaration===e.declaration)))continue;let l=uf(s);if(!l)continue;let u=a instanceof Qp&&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:F(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:F(i.rightToken())};n.push({token:F(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case I.Table:this.db.tables.push(t);break;case I.Enum:this.db.enums.push(t);break;case I.TableGroup:this.db.tableGroups.push(t);break;case I.TablePartial:this.db.tablePartials.push(t);break;case I.StickyNote:this.db.notes.push(t);break;case I.DiagramView:this.db.diagramViews.push(t);break;default:break}}},zg={nodeSymbol(t,r){return Jf(r)?n.create(t.symbolFactory.create(om,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(I.Program))return n.create(e);if(!(i.declaration instanceof R))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(v);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(I.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Jf(r)?new Oh(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof om))return n.create(e);if(!(r.declaration instanceof R))return n.create(void 0);if(!Lm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new Rg(t,r,i).interpret()}},Bg=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 z);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Vg=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=F(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}=Pp(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?N(e):void 0;return n&&(this.project.note={value:Np(n),token:F(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()]=N(t.body.callee),[]}})}},Hg={nodeMetadata(t,i){return A(i,r.Project)?n.create(new Qm(i)):n.create(e)},bindNode(t,i){return A(i,r.Project)?n.create(void 0,new Bg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Qm)||!(r.declaration instanceof z)?n.create(e):new Vg(t,r.declaration,i).interpret()}},Ug=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 R?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=pp(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=op(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=mp(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new T(w.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new T(w.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new T(w.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 z)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Bf(e))return[];let i=op(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=mp(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new T(w.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 z);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof bm?e.callee.elementList:[e.callee]).flatMap(Rm).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():[])}},Wg=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Gg(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=Kg(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=F(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 Gg(e,n,i){let a=e.name,o=e.parent;if(o instanceof z&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof qp))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===P(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=pp(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,I.Schema,u);e&&(p=n.lookupMembers(e,I.Table,l))}if(p||=n.lookupMembers(f,I.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof qp))return;let ee=m.mergedColumns(n),te=s.args.map(e=>ee.find(t=>t.name===P(e))).filter(Boolean),ne=m.interpretedName(n,i);return{schemaName:ne.schema,tableName:ne.name,columns:te}}function Kg(e,t,r){let i=[],a=[],o={},s=e.callee instanceof bm?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new T(w.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=Jg(n,l,r);i.push(...u.getErrors()),a.push(...u.getInfos());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:F(n)})}return new n({row:c,columnNodes:o},i,[],a)}function qg(e){return e instanceof vm&&e.value?.value||``}function Jg(e,t,r){let i=F(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=Wo(o,s),p=Ep(e),m=p===null?qg(e):p,ee=p===null?`expression`:f;if(e instanceof vm)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(gp(e)||_p(e)&&!Bo(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Uo(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[],[Vh(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(I.EnumField)).map(e=>e.name).filter(Boolean):[],s=N(e);return s===void 0&&(s=O(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},[],[],[Hh(e,{colName:d})])}if(Io(o)||Lo(o)||Uo(o)){let t=yp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Uh(e,{colName:d,typeName:o})]);if(Io(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[],[Wh(e,{colName:d,value:t})]);let r=Lo(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Lo(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},[],[],[Gh(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},[],[],[Kh(e,{colName:d,typeName:o,value:t,precision:a,scale:s,decimalDigits:m})])}return new n({value:t,type:f,token:i},[],[])}if(zo(o)){let t=wp(e);return t===null?new n({value:m,type:ee,token:i},[],[],[qh(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Ho(o)){let t=Ap(e);return t===null?new n({value:m,type:ee,token:i},[],[],[Jh(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Bo(o)){let t=Ep(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Yh(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},[],[],[Xh(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:ee,token:i},[],[])}var Yg={nodeMetadata(t,i){if(!A(i,r.Records))return n.create(e);let a=i.parent;if(a&&A(a,r.Table))return n.create(new Xm(i));let o=i.name;return o instanceof Sm&&o.callee?n.create(new Xm(i)):n.create(e)},nodeReferee(i,a){if(!O(a))return n.create(e);let o=a.parentOfKind(z);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(ym);if(l?.parentNode===o)return Xg(i,o,a);let u=a.parentOfKind(Sm);return u?.parentNode===o&&l?.parentNode===u?Zg(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?Qg(i,c,a):e_(i,c,a)},bindNode(t,i){return A(i,r.Records)?n.create(void 0,new Ug(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Xm?r.declaration instanceof z?new Wg(t,r,i).interpret():n.create(void 0):n.create(e)}};function Xg(e,i,a){let o=i.parent;if(o instanceof z&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return $g(e,n,a)}return new n(void 0)}function Zg(e,r,i){if(r.callee){let n;if(O(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=lp(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return $g(e,n,i)}return new n(void 0)}function Qg(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode)){let a=e.lookupMembers(t,[I.Table,I.Schema],i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=zm(e,r);if(!a){let a=e.lookupMembers(t,[I.Table,I.Schema],i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Table,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function $g(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``,a=e.lookupMembers(t,I.Column,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function e_(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return new n(void 0);let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Enum,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(I.Enum)){let t=e.lookupMembers(a,I.EnumField,i);return t?n.create(t):new n(void 0,[new T(w.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(k(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,I.Enum,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var t_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof R)&&!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]=g(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(Rm).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():[])}},n_=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=F(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 z))return[];let e=[],t=M(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new T(w.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(Ra(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new T(w.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=uf(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=F(this.metadata.leftToken()),l=F(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof z?[{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 z))return[];let u=cp(this.declarationNode)[0];if(u.args[0]){let e=E(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof hm?ap(t):P(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof hm?ap(n):P(n),this.ref.color=e.color?.length?Fp(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:[...jg(this.compiler,this.metadata,`right`),...jg(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function r_(e){let t=e.parent;for(;t;){if(t instanceof z&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var i_={nodeReferee(r,i){if(!O(i)&&!k(i)||!r_(i)||i.parentOfKind(B))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):a_(r,o,i)},nodeMetadata(t,a){if(A(a,r.Ref)){let t=cp(a)[0];if(!(t instanceof H)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof gm)||!r.op?n.create(e):n.create(new Gm(a))}if(a instanceof B){if(!(a.name instanceof hm)||ap(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof z&&t.isKind(r.TablePartial)?n.create(new qm(a)):n.create(new Gm(a))}return n.create(e)},bindNode(t,i){return A(i,r.Ref)?n.create(void 0,new t_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Gm?new n_(t,r,i).interpret():n.create(e)}};function a_(e,r,i){if(!O(i))return new n(void 0);let a=mp(i)??``;if(!k(i.parentNode)){let r=i.parentNode;if(r&&k(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=k(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(I.Table)){let r=e.lookupMembers(c,I.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 T(w.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=zm(e,i);if(o){if(o.isKind(I.Schema)){let t=e.lookupMembers(o,[I.Table,I.Schema],a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(I.Table)){let r=e.lookupMembers(o,I.Column,a);return r?n.create(r):new n(void 0,[new T(w.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(k(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,I.Schema,a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Vm(e,r);if(t){let r=e.lookupMembers(t,I.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,I.Table,a);return o?n.create(o):new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var o_={visibleName(e,n){let r=n instanceof L?n:n.useSpecifierDeclaration instanceof pm?n.useSpecifierDeclaration:n.declaration;if(r instanceof pm&&n instanceof Up&&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]}},s_={nodeSymbol(r,i){if(!qf(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===I.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(cm,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:o_.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new T(w.BINDING_ERROR,`Failed to resolve the import of ${a} '${(M(i.name)||[]).map(R_).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof cm))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(!O(i)&&!Gf(i))return n.create(e);let a=i.parentOfKind(pm);if(!a)return n.create(e);let o=a.name===i||k(a.name)&&a.name.rightExpression===i?a.getSymbolKind():I.Schema;if(o===void 0)return n.create(void 0);let s=M(i.parentOfKind(gm)),c=P(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(fm);if(l?.importPath?.value===void 0)return n.create(void 0);let u=So(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new T(w.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new T(w.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toString()}. Does the file exist?`,i)]);let d=i.parentOfKind(gm)?.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 T(w.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=c_(r,u,c,o);return f?n.create(f):n.create(void 0,[new T(w.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toString()}`,i)])},bindNode(t,r){if(Kf(r)){let e=[];if(r.importPath?.value){let n=So(r.filepath,r.importPath.value);n?t.layout.exists(n)||e.push(new T(w.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath)):e.push(new T(w.BINDING_ERROR,`Import path must be relative, got '${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 mm?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):qf(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 cm))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 c_(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(I.Schema))return c;for(let t of o.reuses.selective)if(M(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(fm);if(o?.importPath?.value){let s=c_(e,So(n,o.importPath.value),M(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=c_(e,t,r,i,a);if(n)return n}}function l_(e){if(e instanceof xo){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=d_(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof om?f_(this,e,i):p_(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 u_(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof pm?o_.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof pm&&r.getSymbolKind()===I.Schema?a:a.length<=1?[v]: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 d_(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof fm)||!e.specifiers||!e.importPath)continue;let n=So(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof wm?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof wm?o.push({importPath:n,node:e.specifiers}):s.push(...e.specifiers.specifiers))}return{ast:r,parseResult:n,selectiveReuses:a,wildcardReuses:i,selectiveUses:s,wildcardUses:o}}function f_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[v,e.symbolFactory.create(Wp,{name:v},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?v:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Wp,{name:i},s))}m_(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of g_(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Wp,{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 p_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof z))continue;let i=u_(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(sm,{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(Wp,{name:i.schemaName,parent:n},n.filepath))}h_(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(Wp,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function m_(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==I.Schema)continue;let t=o_.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Wp,{name:t},r))}}function h_(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==I.Schema)continue;let t=o_.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(Wp,{name:o,parent:n},n.filepath))}}function g_(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?v:r[0];i.push(a)}let a=d_(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==I.Schema)continue;let n=o_.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?[v]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=d_(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==I.Schema)continue;let n=o_.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var v_=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 E(e).getValue().dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])??[]}bindInlineDepValue(e){return Rm(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]=g(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(h(n)instanceof W){let e=E(h(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=>!jf(e.callee)))}tryToBindColumnType(e){let t=up(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(D(e))return[];if(O(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&Co.includes(t))return[]}let t=up(e);if(!t){if(k(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 Rm(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 y_(e){let t=e.targetKind?.value?.toLowerCase();return Object.values(Vp).find(e=>e.toLowerCase()===t)}function b_(e,t,n){let r=[];return t.length>1&&r.push(...t.map(t=>new T(n.duplicate,`'${e}' can only appear once`,t))),t.forEach(t=>{Hf(t.value)||r.push(new T(n.invalidValue,`Custom setting '${e}' must be a string or a color literal`,t.value||t.name||t))}),r}function x_(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?x_(e,a,n.slice(1)):a}function S_(e,t){if(e.length===0)return[];let n;switch(t){case Vp.Table:n=[...Array(e.length-1).fill(I.Schema),I.Table];break;case Vp.Column:n=e.length===1?[I.Column]:[...Array(e.length-2).fill(I.Schema),I.Table,I.Column];break;case Vp.TableGroup:n=[...Array(e.length-1).fill(I.Schema),I.TableGroup];break;case Vp.Note:n=[...Array(e.length-1).fill(I.Schema),I.StickyNote];break;default:break}return e.map((e,t)=>({name:e,symbolKind:n[t]}))}function C_(e,t){let n=Hm(e,t.filepath);if(!n)return;let r=y_(t),i=M(t.name);if(!i?.length||!r)return;let a=S_(i,r),{name:o,symbolKind:s}=a[0];if(o===`public`&&s===I.Schema){let t=Vm(e,n);if(t)return x_(e,t,a.slice(1))}return x_(e,n,a)}function w_(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 T_(e,n,r,i,a){let o=Hm(e,a);if(!o)return;let s=e.symbolMetadata(r).filter(t=>t.owners(e).includes(o));if(!s.length)return;let c=w_(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 E_=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??F(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;T_(this.compiler,this.table,this.symbol,O_,this.filepath);let e=this.compiler.symbolMembers(this.symbol).getFiltered(t)??[];for(let t of e){if(!t.isKind(I.Column))continue;let e=this.table.fields.find(e=>e.name===t.name);e&&T_(this.compiler,e,t,k_,this.filepath)}}interpretName(e){let{name:t,schemaName:n}=Pp(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new T(w.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=mp(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=E(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Fp(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Np(N(n?.value)),token:F(n)},this.table.metadata=Rp(t,Object.keys(O_)),[]}interpretBody(e){let[t,n]=g(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:Np(N(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:F(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:F(e)};i.name=P(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 T(w.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(I.Column)).length?[]:[new T(w.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>jf(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=mp(e.callee),r.token=F(e);let o=Lp(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=Rp(s,D_);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 V))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:F(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()}},D_=[i.Note,i.Ref,i.PrimaryKey,i.PK,i.NotNull,i.Null,i.Unique,i.Increment,i.Default,i.Check],O_={[i.Note]:{isValidBuiltinFieldValue:D,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.HeaderColor]:{isValidBuiltinFieldValue:Pf,message:`'headercolor' must be a color literal`,assignBuiltinField(e,t){e.headerColor=t}}},k_={[i.Note]:{isValidBuiltinFieldValue:D,message:`'note' must be a quoted string`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}}},A_={getDuplicateError(e,t,n){return new T(w.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new T(w.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new T(w.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},j_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return A(a,r.Table)?new n(i.symbolFactory.create(qp,{declaration:a,name:o},a.filepath)):j(a,r.Table)?jf(a.callee)?new n(i.symbolFactory.create($p,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Jp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(I.Table))return n.create(e);let a=i.declaration;if(!(a instanceof z))return new n([]);let o=cp(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(I.Column,I.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof z&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(I.Column)?(c.push(A_.getColumnDuplicateError(e.name,r)),c.push(A_.getColumnDuplicateError(e.name,n))):(c.push(A_.getPartialInjectionDuplicateError(e.name,r)),c.push(A_.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)||!jf(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=P(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new T(w.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(lm,{kind:I.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(I.Column)&&!(e instanceof lm)).map(e=>e.name));return new n(Fa([...s.filter(e=>!(e instanceof lm&&d.has(e.name)))].reverse(),e=>e.isKind(I.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(Qf(o,i.Dep)&&o.parent instanceof z&&o.parent.isKind(r.Table)&&!Yf(o,r.Table)){let e=a.parseFile(o.filepath).getValue().ast,r=a.nodeSymbol(e).getValue();return r===t?n.create(void 0):F_(a,r,o)}if(!Yf(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):O(o)&&o.parentNode instanceof V&&o.parentNode.op?.value===`~`?M_(a,c,o):Xf(o,1)?N_(a,c,o):Qf(o,i.Ref)?P_(a,c,o):Qf(o,i.Dep)?F_(a,c,o):Xf(o,0)?n.create(e):I_(a,c,o)},bindNode(i,a){if(!A(a,r.Table))return n.create(e);let o=new v_(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 qp?r.declaration instanceof z?new E_(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function M_(e,r,i){let a=P(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Wp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,I.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,I.TablePartial,a);return s?n.create(s):new n(void 0,[new T(w.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function N_(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return n.create(e.lookupMembers(t,I.Enum,i));let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=rp(r),o=e.lookupMembers(a,t?I.Enum:I.Schema,i);return o?n.create(o):new n(void 0,[new T(w.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,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function P_(e,i,a){if(!O(a))return new n(void 0);let o=mp(a)??``;if(!k(a.parentNode)){let s=a.parent,c=s instanceof z&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,I.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,I.Column,o);return l?n.create(l):new n(void 0,[new T(w.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}return Bm(e,i,a,I.Column)}function F_(e,i,a){if(!O(a))return new n(void 0);let o=Yf(a,r.Table),s=mp(a)??``;if(!k(a.parentNode))if(o){let o=a.parent,c=o instanceof z&&o.isKind(r.Table)?e.nodeSymbol(o).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,I.Column,s);if(t)return n.create(t)}let l=e.lookupMembers(i,I.Column,s);return l?n.create(l):new n(void 0,[new T(w.BINDING_ERROR,`Column '${s}' does not exist in Table 'public.${c?.name??``}'`,a)])}else{let t=e.lookupMembers(i,I.Table,s);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table '${s}' does not exist in Schema 'public'`,a)])}return Bm(e,i,a,o?I.Column:I.Table)}function I_(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return Co.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,I.Enum,i));let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Enum,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(I.Enum)){let t=e.lookupMembers(a,I.EnumField,i);return t?n.create(t):new n(void 0,[new T(w.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(k(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,I.Enum,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function L_(e){return e?e.split(``).every(e=>Cf(e)||wf(e))&&!wf(e[0]):!1}function R_(e){return L_(e)?e:`"${V_(e)}"`}function z_(...e){return e.map(R_).join(`.`)}function B_(e){let t=``,n=0,r={n:`
8
+ `);return new Sf(w.INVALID_REF_RELATIONSHIP,c,t,{category:bf.RefColumnMismatch,explanation:l,quickFixes:o})}function zh(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 Bh(e,t){return e.length>1?`Composite ${t}`:t}function Vh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`NULL not allowed for NOT NULL column \`${n}\` without a default value or auto-increment`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is marked NOT NULL and has no default value or auto-increment.`})}function Hh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid enum value for column \`${n}\``,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` uses an enum type. The value must match one of the defined enum members.`})}function Uh(e,t){let{colName:n,typeName:r}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid numeric value for column \`${n}\``,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` has type \`${r}\` which expects a numeric value. Provide a valid integer or decimal.`})}function Wh(e,t){let{colName:n,value:r}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid integer value \`${r}\` for column \`${n}\`: expected integer, got decimal`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is an integer column and cannot store decimal values.`})}function Gh(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,totalDigits:s}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds precision: expected at most ${a} total digits, got ${s}`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${a} total digits. The value \`${i}\` has ${s}.`})}function Kh(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,decimalDigits:s}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds scale: expected at most ${o} decimal digits, got ${s}`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${o} decimal places. The value \`${i}\` has ${s}.`})}function qh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid boolean value for column \`${n}\``,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is a boolean column. Use \`true\`/\`false\`, \`1\`/\`0\`, or \`'yes'\`/\`'no'\`.`})}function Jh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid datetime value for column \`${n}\``,e,{category:bf.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 Yh(e,t){let{colName:n}=t;return new Sf(w.INVALID_RECORDS_FIELD,`Invalid string value for column \`${n}\``,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is a string column. Values must be wrapped in quotes.`})}function Xh(e,t){let{colName:n,typeName:r,typeArg:i,maxLength:a,actualLength:o}=t;return new Sf(w.INVALID_RECORDS_FIELD,`String value for column \`${n}\` exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e,{category:bf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${i})\`, limiting values to ${a} bytes in UTF-8 encoding. The provided value uses ${o} bytes.`})}function Zh(e,t,n){let{table:r,columns:i}=n,a=zh(e,r,i),o=Bh(i,`PK`);return new Sf(w.INVALID_RECORDS_FIELD,`NULL in ${o}: \`${a}\` cannot be NULL`,t,{category:bf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key and cannot be NULL.`})}function Qh(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=zh(e,r,i),s=Bh(i,`PK`);return new Sf(w.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:bf.RecordConstraintViolation,explanation:`\`${o}\` is a primary key and must be unique across all rows.`})}function $h(e,t,n){let{table:r,columns:i}=n,a=zh(e,r,i),o=Bh(i,`PK`);return new Sf(w.INVALID_RECORDS_FIELD,`${o}: Column \`${a}\` is missing from record and has no default value`,t,{category:bf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key with no default or auto-increment, so it must be specified in the records block.`})}function eg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=zh(e,r,i,s),u=zh(e,a,o,s);return new Sf(w.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` must not be NULL`,t,{category:bf.RecordConstraintViolation,explanation:`\`${l}\` references \`${u}\`, so every row must have a non-null value.`})}function tg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=zh(e,r,i,s),u=zh(e,a,o,s);return new Sf(w.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` does not exist in \`${u}\``,t,{category:bf.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 ng(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=zh(e,r,i),s=Bh(i,`UNIQUE`);return new Sf(w.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:bf.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 ig(e,t){return e?`${e}.${t}`:`${v}.${t}`}function ag(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 og(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function sg(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 cg(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function lg(e,t){let{token:n}=t;return e.nodeAtPosition(n.filepath,n.start.offset)??e.parse.ast(n.filepath)}function ug(e,t,n,r){return ka(r.values)?[]:Sa(hg(t,e),i=>dg(e,t,n,i,r))}function dg(e,t,n,r,i){let a=rg(i),o=mg(e,t,n,r,i);if(!ka(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=g(a,t=>og(e,t,s)),u=fg(e,t,s,c),d=r.some(t=>t.increment(e))?[]:pg(e,t,r,l);return[...u,...d]}function fg(e,t,n,r){if(ka(r))return[];let i=n.map(e=>e.name??``);return Sa(r,r=>cg(r,i).map(r=>Zh(e,lg(e,r),{table:t,columns:n})))}function pg(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r,t=>ag(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=sg(e,r,n);return cg(r,i).map(r=>Qh(e,lg(e,r),{table:t,columns:n,valueStr:a}))}))}function mg(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=fa(a,Array.from(o));if(ka(s))return[];let c=new Set(s),l=r.filter(e=>c.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e));return ka(l)?[]:i.values.map(()=>$h(e,n,{table:t,columns:l}))}function hg(e,t){let n=e.mergedColumns(t),r=Aa(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=>$r(e.columns.map(e=>r[e.value]))):[]})]}function gg(e,t,n){if(ka(n.values))return[];let r=rg(n);return Sa(_g(e,t),n=>vg(e,t,n,r))}function _g(e,t){let n=t.mergedColumns(e),r=Aa(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=>$r(e.columns.map(e=>r[e.value]))):[]})]}function vg(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r.filter(t=>!og(e,t,n)),t=>ag(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=sg(e,r,n);return cg(r,i).map(r=>ng(e,lg(e,r),{table:t,columns:n,valueStr:a}))}))}function yg(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(ig(a,e),i)}return r}function bg(e,t,n,r){let i=yg(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!ka(t.record.values)&&a.add(e);return Sa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(ig(e.schemaName,e.tableName))):!1),t=>xg(e,t,i,r))}function xg(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(ig(i.schemaName,i.tableName)),s=n.get(ig(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=$r(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=$r(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=nf(i.relation),{min:m,max:ee}=nf(a.relation),te=p===1&&m===0||p!==`*`&&ee!==`*`,ne=ee===1&&f===0;return[...te?[]:Sg(e,o,u,s,d,i.relation,a.relation,r),...ne?[]:Sg(e,s,d,o,u,a.relation,i.relation,r)]}function Sg(e,t,n,r,i,a,o,s){if(!t.record||ka(t.record.values))return[];let{min:c,max:l}=nf(a),{min:u,max:d}=nf(o),f=$r(n.map(e=>e.name));$r(i.map(e=>e.name));let p=u===0,m=rg(t.record),ee=r.record?rg(r.record):[],te=new Set(ee.map(t=>ag(e,t,i))),ne={leftTable:t.tableSymbol,leftColumns:n,rightTable:r.tableSymbol,rightColumns:i,filepath:s};return Sa(m,t=>{if(og(e,t,n)){if(p)return[];let r=sg(e,t,n);return cg(t,f).map(t=>eg(e,lg(e,t),{...ne,valueStr:r}))}if(d===`*`&&c===0&&l===`*`)return[];let r=ag(e,t,n);if(te.has(r))return[];let i=sg(e,t,n);return cg(t,f).map(t=>tg(e,lg(e,t),{...ne,valueStr:i}))})}function Cg(e){return e instanceof Km&&e.declaration instanceof z&&e.declaration.body instanceof U}function wg(e,t){let n=e.edges??[];if(n.length===0||!Cg(t))return[];let r=[],i=ig(n[0].downstream.schemaName,n[0].downstream.tableName);for(let e=1;e<n.length;e++){let a=ig(n[e].downstream.schemaName,n[e].downstream.tableName);if(a!==i){r.push(new T(w.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 T(w.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 Tg(e,t){let n=kg(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof B?hp(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof z){let n=Ag(e,t);if(n)return{kind:`body`,declaration:n}}}function Eg(e,t){let n=kg(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof z){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 Dg(e,t,n,r){if(n===null)return Og(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=Tg(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return Eg(e,i)}function Og(e,t,n){let r=Tg(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 kg(e){if(e instanceof H)return e.args.find(e=>e instanceof W);if(e instanceof z){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof H)return t.args.find(e=>e instanceof W)}}function Ag(e,t){let n=e.body;if(!(!n||Af(e)||n instanceof H)){for(let e of n.body)if(e instanceof z&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function jg(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=nf(l),d=n===`left`?c[1]:c[0],f=nf(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),ee=n===`left`?t.leftToken():t.rightToken(),te=n===`left`?t.rightToken():t.leftToken(),ne=[];function re(e,t,n){ne.push(n(e));for(let r of t)r.declaration&&r.declaration!==e&&ne.push(n(r.declaration))}let ie=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&ie&&m.length>0&&m.every(t=>t.nullable(e))){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Ng(s,_f(l),d,n,`Make '${r}' optional in the ref`),...i?m.map(t=>Pg(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Fh(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.min===0&&ie&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Ng(s,vf(l),d,n,`Make '${r}' required in the ref`),...i?m.map(t=>Fg(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Ih(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.max===`*`&&Ig(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Ng(s,`1`,d,n,`Make '${r}' one in the ref`)].filter(e=>!!e);re(ee,p,n=>Lh(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}if(u.max===1&&!Ig(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Ng(s,yf(l),d,n,`Make '${r}' many in the ref`),a&&p.length===1&&Lg(p[0],e)].filter(e=>!!e);re(ee,p,n=>Rh(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}return ne}function Mg(e,t){return[...jg(e,t,`right`,{allowOtherColFix:!1}),...jg(e,t,`left`,{allowOwnColFix:!1})]}function Ng(e,t,n,r,i){let a=gf(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 Pg(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=Og(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=Eg(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[a]}}function Fg(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=Og(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 Ig(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 lm?r.injectionDeclaration:r.declaration)?.parentOfKind(z);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof qp))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 Lg(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=Eg(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,shortTitle:`Add unique`,filepath:e.declaration.filepath,edits:[n]}}var Rg=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],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:F(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.infos.push(...this.validateRecords()),new n(this.db,this.errors,this.warnings,this.infos)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof cm)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 Wp);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Wp){n.push(t);continue}if(!(t instanceof cm))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 qp?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof qp?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}]};Ah(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 Xm))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 Um.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 T(w.SAME_ENDPOINT,`Ref with same endpoints already exists`,a.declaration));break}n.add(e)}this.db.refs.push(e);break}case Um.Dep:{let e=o,t=a instanceof Km?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 T(w.SAME_ENDPOINT,`Dep with same endpoints already exists`,e));break}let i=wg(e,a);if(i.length>0){this.errors.push(...i);break}this.db.deps.push(e);break}case Um.Records:if(a instanceof Xm){let e=a.table(this.compiler)?.originalSymbol.intern()??``,t=e?i.get(e):void 0;if(t&&t.count>1){this.errors.push(new T(w.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 Um.Project:this.db.project=o;break;case Um.MetadataElement:default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof sm)||!t.isKind(I.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:Am.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 Wp))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(I.Table))continue;let t=e.originalSymbol;if(!(t instanceof qp))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 Xm))continue;let i=r.table(this.compiler);if(!(i instanceof qp))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...ug(this.compiler,i,r.declaration,o)),e.push(...gg(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(...bg(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof qm);for(let t of e)this.infos.push(...Mg(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof qm),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 lm&&t.declaration===e.declaration)))continue;let l=uf(s);if(!l)continue;let u=a instanceof Qp&&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:F(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:F(i.rightToken())};n.push({token:F(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case I.Table:this.db.tables.push(t);break;case I.Enum:this.db.enums.push(t);break;case I.TableGroup:this.db.tableGroups.push(t);break;case I.TablePartial:this.db.tablePartials.push(t);break;case I.StickyNote:this.db.notes.push(t);break;case I.DiagramView:this.db.diagramViews.push(t);break;default:break}}},zg={nodeSymbol(t,r){return Jf(r)?n.create(t.symbolFactory.create(om,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(I.Program))return n.create(e);if(!(i.declaration instanceof R))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(v);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(I.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Jf(r)?new Oh(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof om))return n.create(e);if(!(r.declaration instanceof R))return n.create(void 0);if(!Lm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new Rg(t,r,i).interpret()}},Bg=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 z);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Vg=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=F(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}=Pp(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?N(e):void 0;return n&&(this.project.note={value:Np(n),token:F(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()]=N(t.body.callee),[]}})}},Hg={nodeMetadata(t,i){return A(i,r.Project)?n.create(new Qm(i)):n.create(e)},bindNode(t,i){return A(i,r.Project)?n.create(void 0,new Bg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Qm)||!(r.declaration instanceof z)?n.create(e):new Vg(t,r.declaration,i).interpret()}},Ug=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 R?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=pp(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=op(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=mp(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new T(w.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new T(w.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new T(w.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 z)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Bf(e))return[];let i=op(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=mp(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new T(w.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 z);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof bm?e.callee.elementList:[e.callee]).flatMap(Rm).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():[])}},Wg=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Gg(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=Kg(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=F(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 Gg(e,n,i){let a=e.name,o=e.parent;if(o instanceof z&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof qp))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===P(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=pp(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,I.Schema,u);e&&(p=n.lookupMembers(e,I.Table,l))}if(p||=n.lookupMembers(f,I.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof qp))return;let ee=m.mergedColumns(n),te=s.args.map(e=>ee.find(t=>t.name===P(e))).filter(Boolean),ne=m.interpretedName(n,i);return{schemaName:ne.schema,tableName:ne.name,columns:te}}function Kg(e,t,r){let i=[],a=[],o={},s=e.callee instanceof bm?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new T(w.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=Jg(n,l,r);i.push(...u.getErrors()),a.push(...u.getInfos());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:F(n)})}return new n({row:c,columnNodes:o},i,[],a)}function qg(e){return e instanceof vm&&e.value?.value||``}function Jg(e,t,r){let i=F(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=Wo(o,s),p=Ep(e),m=p===null?qg(e):p,ee=p===null?`expression`:f;if(e instanceof vm)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(gp(e)||_p(e)&&!Bo(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Uo(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[],[Vh(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(I.EnumField)).map(e=>e.name).filter(Boolean):[],s=N(e);return s===void 0&&(s=O(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},[],[],[Hh(e,{colName:d})])}if(Io(o)||Lo(o)||Uo(o)){let t=yp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Uh(e,{colName:d,typeName:o})]);if(Io(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[],[Wh(e,{colName:d,value:t})]);let r=Lo(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Lo(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},[],[],[Gh(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},[],[],[Kh(e,{colName:d,typeName:o,value:t,precision:a,scale:s,decimalDigits:m})])}return new n({value:t,type:f,token:i},[],[])}if(zo(o)){let t=wp(e);return t===null?new n({value:m,type:ee,token:i},[],[],[qh(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Ho(o)){let t=Ap(e);return t===null?new n({value:m,type:ee,token:i},[],[],[Jh(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Bo(o)){let t=Ep(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Yh(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},[],[],[Xh(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:ee,token:i},[],[])}var Yg={nodeMetadata(t,i){if(!A(i,r.Records))return n.create(e);let a=i.parent;if(a&&A(a,r.Table))return n.create(new Xm(i));let o=i.name;return o instanceof Sm&&o.callee?n.create(new Xm(i)):n.create(e)},nodeReferee(i,a){if(!O(a))return n.create(e);let o=a.parentOfKind(z);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(ym);if(l?.parentNode===o)return Xg(i,o,a);let u=a.parentOfKind(Sm);return u?.parentNode===o&&l?.parentNode===u?Zg(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?Qg(i,c,a):e_(i,c,a)},bindNode(t,i){return A(i,r.Records)?n.create(void 0,new Ug(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Xm?r.declaration instanceof z?new Wg(t,r,i).interpret():n.create(void 0):n.create(e)}};function Xg(e,i,a){let o=i.parent;if(o instanceof z&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return $g(e,n,a)}return new n(void 0)}function Zg(e,r,i){if(r.callee){let n;if(O(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=lp(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return $g(e,n,i)}return new n(void 0)}function Qg(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode)){let a=e.lookupMembers(t,[I.Table,I.Schema],i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=zm(e,r);if(!a){let a=e.lookupMembers(t,[I.Table,I.Schema],i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Table,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function $g(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``,a=e.lookupMembers(t,I.Column,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function e_(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return new n(void 0);let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Enum,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(I.Enum)){let t=e.lookupMembers(a,I.EnumField,i);return t?n.create(t):new n(void 0,[new T(w.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(k(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,I.Enum,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var t_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof R)&&!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]=g(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(Rm).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():[])}},n_=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=F(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 z))return[];let e=[],t=M(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new T(w.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(Ra(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new T(w.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=uf(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=F(this.metadata.leftToken()),l=F(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof z?[{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 z))return[];let u=cp(this.declarationNode)[0];if(u.args[0]){let e=E(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof hm?ap(t):P(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof hm?ap(n):P(n),this.ref.color=e.color?.length?Fp(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:[...jg(this.compiler,this.metadata,`right`),...jg(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function r_(e){let t=e.parent;for(;t;){if(t instanceof z&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var i_={nodeReferee(r,i){if(!O(i)&&!k(i)||!r_(i)||i.parentOfKind(B))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):a_(r,o,i)},nodeMetadata(t,a){if(A(a,r.Ref)){let t=cp(a)[0];if(!(t instanceof H)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof gm)||!r.op?n.create(e):n.create(new Gm(a))}if(a instanceof B){if(!(a.name instanceof hm)||ap(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof z&&t.isKind(r.TablePartial)?n.create(new qm(a)):n.create(new Gm(a))}return n.create(e)},bindNode(t,i){return A(i,r.Ref)?n.create(void 0,new t_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Gm?new n_(t,r,i).interpret():n.create(e)}};function a_(e,r,i){if(!O(i))return new n(void 0);let a=mp(i)??``;if(!k(i.parentNode)){let r=i.parentNode;if(r&&k(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=k(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(I.Table)){let r=e.lookupMembers(c,I.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 T(w.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=zm(e,i);if(o){if(o.isKind(I.Schema)){let t=e.lookupMembers(o,[I.Table,I.Schema],a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(I.Table)){let r=e.lookupMembers(o,I.Column,a);return r?n.create(r):new n(void 0,[new T(w.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(k(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,I.Schema,a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Vm(e,r);if(t){let r=e.lookupMembers(t,I.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,I.Table,a);return o?n.create(o):new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var o_={visibleName(e,n){let r=n instanceof L?n:n.useSpecifierDeclaration instanceof pm?n.useSpecifierDeclaration:n.declaration;if(r instanceof pm&&n instanceof Up&&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]}},s_={nodeSymbol(r,i){if(!qf(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===I.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(cm,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:o_.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new T(w.BINDING_ERROR,`Failed to resolve the import of ${a} '${(M(i.name)||[]).map(R_).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof cm))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(!O(i)&&!Gf(i))return n.create(e);let a=i.parentOfKind(pm);if(!a)return n.create(e);let o=a.name===i||k(a.name)&&a.name.rightExpression===i?a.getSymbolKind():I.Schema;if(o===void 0)return n.create(void 0);let s=M(i.parentOfKind(gm)),c=P(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(fm);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 T(w.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new T(w.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toKey()}. Does the file exist?`,i)]);let d=i.parentOfKind(gm)?.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 T(w.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=c_(r,u,c,o);return f?n.create(f):n.create(void 0,[new T(w.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toKey()}`,i)])},bindNode(t,r){if(Kf(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 T(w.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 mm?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):qf(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 cm))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 c_(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(I.Schema))return c;for(let t of o.reuses.selective)if(M(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(fm);if(o?.importPath?.value){let s=c_(e,e.layout.resolveFileSpecifier(n,o.importPath.value),M(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=c_(e,t,r,i,a);if(n)return n}}function l_(e){if(e instanceof xo){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=d_(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof om?f_(this,e,i):p_(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 u_(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof pm?o_.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof pm&&r.getSymbolKind()===I.Schema?a:a.length<=1?[v]: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 d_(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let n of r.body){if(!(n instanceof fm)||!n.specifiers||!n.importPath)continue;let r=e.layout.resolveFileSpecifier(t,n.importPath.value);r&&(n.isReuse?n.specifiers instanceof wm?i.push({importPath:r,node:n.specifiers}):a.push(...n.specifiers.specifiers):n.specifiers instanceof wm?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 f_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[v,e.symbolFactory.create(Wp,{name:v},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?v:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Wp,{name:i},s))}m_(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of g_(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Wp,{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 p_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof z))continue;let i=u_(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(sm,{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(Wp,{name:i.schemaName,parent:n},n.filepath))}h_(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(Wp,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function m_(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==I.Schema)continue;let t=o_.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Wp,{name:t},r))}}function h_(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==I.Schema)continue;let t=o_.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(Wp,{name:o,parent:n},n.filepath))}}function g_(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?v:r[0];i.push(a)}let a=d_(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==I.Schema)continue;let n=o_.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?[v]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=d_(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==I.Schema)continue;let n=o_.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var v_=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 E(e).getValue().dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])??[]}bindInlineDepValue(e){return Rm(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]=g(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(h(n)instanceof W){let e=E(h(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=>!jf(e.callee)))}tryToBindColumnType(e){let t=up(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(D(e))return[];if(O(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&Co.includes(t))return[]}let t=up(e);if(!t){if(k(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 Rm(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 y_(e){let t=e.targetKind?.value?.toLowerCase();return Object.values(Vp).find(e=>e.toLowerCase()===t)}function b_(e,t,n){let r=[];return t.length>1&&r.push(...t.map(t=>new T(n.duplicate,`'${e}' can only appear once`,t))),t.forEach(t=>{Hf(t.value)||r.push(new T(n.invalidValue,`Custom setting '${e}' must be a string or a color literal`,t.value||t.name||t))}),r}function x_(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?x_(e,a,n.slice(1)):a}function S_(e,t){if(e.length===0)return[];let n;switch(t){case Vp.Table:n=[...Array(e.length-1).fill(I.Schema),I.Table];break;case Vp.Column:n=e.length===1?[I.Column]:[...Array(e.length-2).fill(I.Schema),I.Table,I.Column];break;case Vp.TableGroup:n=[...Array(e.length-1).fill(I.Schema),I.TableGroup];break;case Vp.Note:n=[...Array(e.length-1).fill(I.Schema),I.StickyNote];break;default:break}return e.map((e,t)=>({name:e,symbolKind:n[t]}))}function C_(e,t){let n=Hm(e,t.filepath);if(!n)return;let r=y_(t),i=M(t.name);if(!i?.length||!r)return;let a=S_(i,r),{name:o,symbolKind:s}=a[0];if(o===`public`&&s===I.Schema){let t=Vm(e,n);if(t)return x_(e,t,a.slice(1))}return x_(e,n,a)}function w_(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 T_(e,n,r,i,a){let o=Hm(e,a);if(!o)return;let s=e.symbolMetadata(r).filter(t=>t.owners(e).includes(o));if(!s.length)return;let c=w_(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 E_=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??F(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;T_(this.compiler,this.table,this.symbol,O_,this.filepath);let e=this.compiler.symbolMembers(this.symbol).getFiltered(t)??[];for(let t of e){if(!t.isKind(I.Column))continue;let e=this.table.fields.find(e=>e.name===t.name);e&&T_(this.compiler,e,t,k_,this.filepath)}}interpretName(e){let{name:t,schemaName:n}=Pp(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new T(w.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=mp(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=E(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Fp(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Np(N(n?.value)),token:F(n)},this.table.metadata=Rp(t,Object.keys(O_)),[]}interpretBody(e){let[t,n]=g(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:Np(N(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:F(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:F(e)};i.name=P(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 T(w.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(I.Column)).length?[]:[new T(w.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>jf(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=mp(e.callee),r.token=F(e);let o=Lp(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=Rp(s,D_);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 V))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:F(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()}},D_=[i.Note,i.Ref,i.PrimaryKey,i.PK,i.NotNull,i.Null,i.Unique,i.Increment,i.Default,i.Check],O_={[i.Note]:{isValidBuiltinFieldValue:D,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.HeaderColor]:{isValidBuiltinFieldValue:Pf,message:`'headercolor' must be a color literal`,assignBuiltinField(e,t){e.headerColor=t}}},k_={[i.Note]:{isValidBuiltinFieldValue:D,message:`'note' must be a quoted string`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}}},A_={getDuplicateError(e,t,n){return new T(w.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new T(w.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new T(w.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},j_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return A(a,r.Table)?new n(i.symbolFactory.create(qp,{declaration:a,name:o},a.filepath)):j(a,r.Table)?jf(a.callee)?new n(i.symbolFactory.create($p,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Jp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(I.Table))return n.create(e);let a=i.declaration;if(!(a instanceof z))return new n([]);let o=cp(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(I.Column,I.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof z&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(I.Column)?(c.push(A_.getColumnDuplicateError(e.name,r)),c.push(A_.getColumnDuplicateError(e.name,n))):(c.push(A_.getPartialInjectionDuplicateError(e.name,r)),c.push(A_.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)||!jf(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=P(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new T(w.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(lm,{kind:I.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(I.Column)&&!(e instanceof lm)).map(e=>e.name));return new n(Fa([...s.filter(e=>!(e instanceof lm&&d.has(e.name)))].reverse(),e=>e.isKind(I.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(Qf(o,i.Dep)&&o.parent instanceof z&&o.parent.isKind(r.Table)&&!Yf(o,r.Table)){let e=a.parseFile(o.filepath).getValue().ast,r=a.nodeSymbol(e).getValue();return r===t?n.create(void 0):F_(a,r,o)}if(!Yf(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):O(o)&&o.parentNode instanceof V&&o.parentNode.op?.value===`~`?M_(a,c,o):Xf(o,1)?N_(a,c,o):Qf(o,i.Ref)?P_(a,c,o):Qf(o,i.Dep)?F_(a,c,o):Xf(o,0)?n.create(e):I_(a,c,o)},bindNode(i,a){if(!A(a,r.Table))return n.create(e);let o=new v_(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 qp?r.declaration instanceof z?new E_(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function M_(e,r,i){let a=P(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Wp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,I.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,I.TablePartial,a);return s?n.create(s):new n(void 0,[new T(w.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function N_(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return n.create(e.lookupMembers(t,I.Enum,i));let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=rp(r),o=e.lookupMembers(a,t?I.Enum:I.Schema,i);return o?n.create(o):new n(void 0,[new T(w.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,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function P_(e,i,a){if(!O(a))return new n(void 0);let o=mp(a)??``;if(!k(a.parentNode)){let s=a.parent,c=s instanceof z&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,I.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,I.Column,o);return l?n.create(l):new n(void 0,[new T(w.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}return Bm(e,i,a,I.Column)}function F_(e,i,a){if(!O(a))return new n(void 0);let o=Yf(a,r.Table),s=mp(a)??``;if(!k(a.parentNode))if(o){let o=a.parent,c=o instanceof z&&o.isKind(r.Table)?e.nodeSymbol(o).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,I.Column,s);if(t)return n.create(t)}let l=e.lookupMembers(i,I.Column,s);return l?n.create(l):new n(void 0,[new T(w.BINDING_ERROR,`Column '${s}' does not exist in Table 'public.${c?.name??``}'`,a)])}else{let t=e.lookupMembers(i,I.Table,s);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table '${s}' does not exist in Schema 'public'`,a)])}return Bm(e,i,a,o?I.Column:I.Table)}function I_(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return Co.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,I.Enum,i));let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Enum,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(I.Enum)){let t=e.lookupMembers(a,I.EnumField,i);return t?n.create(t):new n(void 0,[new T(w.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(k(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,I.Enum,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function L_(e){return e?e.split(``).every(e=>Cf(e)||wf(e))&&!wf(e[0]):!1}function R_(e){return L_(e)?e:`"${V_(e)}"`}function z_(...e){return e.map(R_).join(`.`)}function B_(e){let t=``,n=0,r={n:`
9
9
  `,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function V_(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
10
10
  `: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 H_(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return`'${V_(e)}'`;let{value:t,type:n}=e;if(t==null||zo(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(zo(n)){let e=wp(t);return e===null?`\`${t}\``:e?`true`:`false`}if(Ro(n)){let e=bp(t);return e===null?`\`${t}\``:String(e)}if(Ho(n)){let e=Ap(t);return e===null?`\`${t}\``:`'${V_(e)}'`}let r=Ep(t);return r===null?`\`${t}\``:`'${V_(r)}'`}function U_(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?B_(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function W_(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 G_(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 Wp&&n.isKind(I.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 K_(e){return e.includes(`
11
- `)?`'''\n${e}\n'''`:`'${V_(e)}'`}var q_=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]=g(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(Rm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof cm?[...r.getErrors(),new T(w.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():[])}},J_={[i.Note]:{isValidBuiltinFieldValue:D,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.Color]:{isValidBuiltinFieldValue:Pf,message:`'color' must be a color literal`,assignBuiltinField(e,t){e.color=t}}},Y_=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=F(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),T_(this.compiler,this.tableGroup,this.symbol,J_,this.filepath),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=Pp(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new T(w.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]=g(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:Np(N(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:F(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(I.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=M(e.callee);return i.length>2&&n.push(new T(w.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=E(e).getValue();this.tableGroup.color=t.color?.length?Fp(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Np(N(n?.value)),token:F(n)},this.tableGroup.metadata=Rp(t,Object.keys(J_)),[]}},X_={getDuplicateError(e,t,n){return new T(w.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new T(w.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Z_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return A(a,r.TableGroup)?new n(i.symbolFactory.create(Yp,{declaration:a,name:s},a.filepath)):j(a,r.TableGroup)?new n(i.symbolFactory.create(Xp,{declaration:a,name:o?.map(R_).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(I.TableGroup)){let e=i.declaration;if(!(e instanceof z))return new n([]);let a=cp(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(I.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof z&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(X_.getFieldDuplicateError(e.name,r)),s.push(X_.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(I.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!O(a)||!Yf(a,r.TableGroup)||a.parent&&Zf(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):Q_(i,s,a)},bindNode(i,a){if(!A(a,r.TableGroup))return n.create(e);let o=new q_(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!A(o,r.TableGroup)||!(i instanceof Yp)?n.create(e):Lm(t,o)?new Y_(t,i,a).interpret():n.create(void 0)}};function Q_(e,r,i){let a=mp(i)??``;if(!k(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Wp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,I.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,I.Table,a);return s?n.create(s):new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=zm(e,i);if(o){if(o.isKind(I.Schema)){let t=e.lookupMembers(o,[I.Table,I.Schema],a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,I.Schema,a);return s?n.create(s):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var $_=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]=g(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(h(n)instanceof W){let e=E(h(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=up(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return Rm(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():[])}},ev=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??F(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}=Pp(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=E(e).getValue(),n=ya(t[i.HeaderColor]);this.tablePartial.headerColor=n?Fp(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Np(N(r?.value)),token:F(r)},[]}interpretBody(e){let[t,n]=g(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:Np(N(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:F(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=mp(e.callee)??``,r.token=F(e);let o=Lp(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=Rp(s,D_);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 qm))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:F(n.rightToken())}}),r.inline_deps=[],r.checks=(s[i.Check]||[]).map(e=>({token:F(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()}},tv={getDuplicateError(e,t,n){return new T(w.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},nv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return A(a,r.TablePartial)?new n(i.symbolFactory.create(Qp,{declaration:a,name:o},a.filepath)):j(a,r.TablePartial)?new n(i.symbolFactory.create(Jp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(I.TablePartial)){let e=a.declaration;if(!(e instanceof z))return new n([]);let r=cp(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(I.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof z&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(A_.getColumnDuplicateError(t,r)),s.push(A_.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(I.Column)&&A(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!O(o)&&!k(o)||!Yf(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):Xf(o,1)?rv(a,c,o):Qf(o,i.Ref)?iv(a,c,o):av(a,c,o)},bindNode(i,a){if(!A(a,r.TablePartial))return n.create(e);let o=new $_(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 Qp?r.declaration instanceof z?new ev(t,r,i).interpret():n.create(void 0):n.create(e)}};function rv(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return n.create(e.lookupMembers(t,I.Enum,i));let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Enum,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.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,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function iv(e,i,a){if(!O(a))return new n(void 0);let o=mp(a)??``;if(!k(a.parentNode)){let s=a.parent;if(s instanceof z&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,I.Column,o);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,I.Column,o);return c?n.create(c):new n(void 0,[new T(w.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=zm(e,a);if(s){if(s.isKind(I.Schema)){let t=e.lookupMembers(s,[I.Table,I.Schema],o);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(I.Table)){let t=e.lookupMembers(s,I.Column,o);return t?n.create(t):new n(void 0,[new T(w.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(k(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,I.Schema,o);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,I.Table,o);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function av(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return Co.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,I.Enum,i));let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Enum,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(I.Enum)){let t=e.lookupMembers(a,I.EnumField,i);return t?n.create(t):new n(void 0,[new T(w.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(k(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,I.Enum,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var ov={symbolMembers(r,i){if(!i.isKind(I.Schema)||!(i instanceof Wp))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=cv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...lv(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...dv(r,i,e,t,c));for(let e of o.uses.selective){let n=cv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...lv(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...dv(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(I.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(I.TableGroup)))}}for(let t of e)u.push(...pv(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof cm&&e.isKind(I.Schema))return!1;let t=`${e.originalSymbol.intern()}:${e.name??``}`;return d.has(t)?!1:(d.add(t),!0)}),p=new Map;for(let e of f){let t=`${e.kind}:${e.name}`;if(p.get(t)){if(e.isKind(I.Schema))continue;let t=e instanceof cm?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof z&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(sv(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function sv(e,t,n,r){switch(e){case I.Table:return A_.getDuplicateError(t,n,r);case I.Enum:return xh.getDuplicateError(t,n,r);case I.TablePartial:return tv.getDuplicateError(t,n,r);case I.TableGroup:return X_.getDuplicateError(t,n,r);case I.DiagramView:return ph.getDuplicateError(t,n,r);default:return new T(w.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function cv(e,r,i,a){let o=u_(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(Wp,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function lv(e,n,r,i=new Set){if(r.getSymbolKind()!==I.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(I.Schema))return[];let o=o_.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:uv(e,n,r,a,i)}function uv(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(cm,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(I.TableGroup)&&c.push(...pv(e,n,t));for(let i of s.reuses.selective)if(c.push(...lv(e,n,i,a)),u_(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(cm,{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=fv(e,t,n.qualifiedName);i&&c.push(...uv(e,n,r,i,a))}return c}function dv(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=fv(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(cm,{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(Wp,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=cv(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...lv(e,n,r))}for(let{importPath:t}of d)l.push(...dv(e,n,t,i,a,o));return l}function fv(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 pv(e,n,r){if(!r.isKind(I.TableGroup)||!(r instanceof cm))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(I.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=M(n);if(!i||i.length===0)continue;let a=i.length<=1?[v]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=mv(e,c,i);l&&s.push(e.symbolFactory.create(cm,{kind:I.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function mv(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(I.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(I.Table)&&e.name===a)}var hv=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 z);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},gv={[i.Color]:{isValidBuiltinFieldValue:Ff,message:`'color' must be a color literal or 'none'`,assignBuiltinField(e,t){e.color=t}}},_v=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=F(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return T_(this.compiler,this.note,this.symbol,gv,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=E(e).getValue();return t.color?.length&&(this.note.color=Fp(t.color.at(0)?.value)),this.note.metadata=Rp(t,Object.keys(gv)),[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof H);return t.length!==1||n.length>0?[new T(w.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=N(e.callee)??``;return this.note.content=Np(t),[]}},vv={nodeSymbol(i,a){return!A(a,r.Note)||!(a.parentNode instanceof R)?n.create(e):new n(i.symbolFactory.create(Zp,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(I.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return A(i,r.Note)?n.create(void 0,new hv(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Zp?r.declaration instanceof z?new _v(t,r,i).interpret():n.create(void 0):n.create(e)}},yv=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=y_(this.declarationNode);return!M(e)?.length||!t||C_(this.compiler,this.declarationNode)?[]:[new T(w.BINDING_ERROR,`cannot find metadata target element`,e??this.declarationNode)]}bindBody(e){return e instanceof U?e.body.filter(e=>e instanceof z).flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[]):[]}},bv=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 z))continue;let e=t.type?.value;if(!e)continue;let n=zp(t.body instanceof H?t.body.callee:void 0);n&&(this.values[e]={value:e===`note`?Np(n):n,token:F(t)})}return[]}},xv=[s_,j_,Sh,Yg,Th,ih,i_,ch,Hg,Z_,nv,vv,{nodeMetadata(t,i){return A(i,r.Metadata)?new n(new Zm(i)):new n(e)},nodeReferee(t,i){if(!O(i))return new n(e);let a=i.parentOfKind(z);return!a||!A(a,r.Metadata)||!a.name?.containsEq(i)?new n(e):!M(a.name)||!y_(a)?new n(void 0):new n(C_(t,a))},bindNode(t,i){return A(i,r.Metadata)?new n(void 0,new yv(t,i).bind()):new n(e)},interpretMetadata(t,i,a){return i instanceof Zm?A(i.declaration,r.Metadata)?new bv(t,i,a).interpret():new n(void 0):new n(e)}},ov,mh,zg];function Sv(t,...r){for(let i of xv){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function Cv(r){let i=Sv(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function wv(r){let i=Sv(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Tv(r){let i=Sv(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Ev(r){let i=Sv(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function Dv(r){let i=Sv(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function Ov(r,i){let a=Sv(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function kv(r,i){let a=Sv(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var Av=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 T(w.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof R?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new T(w.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=g(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 h(n)instanceof W&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof vm))&&t.push(new T(w.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=E(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 T(w.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{D(t.value)||n.push(new T(w.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new T(w.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},jv={validateNode(t,i){if(!A(i,r.Checks))return n.create(e);let a=new Av(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return A(i,r.Checks)?i.name?new n(void 0,[new T(w.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Checks)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Checks)?i.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},Mv=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 z&&this.declarationNode.parent.isKind(r.Project,r.Dep)?[]:[new T(w.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project or a Dep`,this.declarationNode)]}validateName(e){return e?[new T(w.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return[new T(w.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return!(this.declarationNode.parent instanceof z&&this.declarationNode.parent.isKind(r.Dep))&&!D(e.callee)&&t.push(new T(w.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 T(w.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function Nv(e){return e instanceof z&&!!e.type?.value}var Pv={validateNode(t,r){if(!Nv(r))return n.create(e);let i=new Mv(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return Nv(r)?r.name?new n(void 0,[new T(w.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return Nv(r)?r.alias?new n(void 0,[new T(w.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return Nv(r)?r.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},Fv=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(...Iv(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(...Iv(n).getErrors())}return e}validateContext(){return this.declarationNode.parent instanceof R?[]:[new T(w.INVALID_DEP_CONTEXT,`A Dep must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Dep name`,e)]:kf(e)?[]:[new T(w.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,e)]:[]}validateAlias(e){return e?[new T(w.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]=g(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 T(w.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e));return}if(!(e.callee instanceof gm)){t.push(new T(w.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 T(w.INVALID_DEP_FIELD,`Dep edges must use the '->' or '<-' operator`,e.callee));let r=up(n.leftExpression)??{variables:[],tupleElements:[]},i=up(n.rightExpression)??{variables:[],tupleElements:[]};r.variables.length===0&&r.tupleElements.length===0&&t.push(new T(w.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.leftExpression||e.callee)),i.variables.length===0&&i.tupleElements.length===0&&t.push(new T(w.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.rightExpression||e.callee));let a=[...e.args];h(a)instanceof W?a.pop():a[0]instanceof W&&a.shift(),a.length>0&&t.push(...a.map(e=>new T(w.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||!Pf(n.callee)?[new T(w.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||!D(t)?[new T(w.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,e)]:[]}default:return e.name||n instanceof U?[new T(w.INVALID_SETTINGS,`'${t}' must be a simple field (e.g. ${t}: value). Block syntax is not allowed`,e)]:!(n instanceof H)||!n.callee?[]:!D(n.callee)&&!Pf(n.callee)&&!Lf(n.callee)&&!kf(n.callee)?[new T(w.INVALID_SETTINGS,`Invalid value for '${t}'. Expected a string, number, color, or identifier`,e)]:[]}})}};function Iv(e){let t=E(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:Pf(n.value)||r.push(new T(w.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,n));break;case i.Note:D(n.value)||r.push(new T(w.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,n));break;default:n.value&&!D(n.value)&&!Pf(n.value)&&!Lf(n.value)&&!kf(n.value)&&r.push(new T(w.INVALID_SETTINGS,`Invalid value for setting '${e}'. Expected a string, number, color, or identifier`,n));break}return new n(a,r)}var Lv={validateNode(t,i){return A(i,r.Dep)?n.create(void 0,new Fv(t,i).validate()):n.create(e)},nodeFullname(t,i){return A(i,r.Dep)?i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,i.name)]):new n(void 0):j(i,r.Dep)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Dep)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.Dep)?new n(void 0):n.create(e)},nodeSettings(t,i){if(A(i,r.Dep))return i.attributeList?Iv(i.attributeList):new n({});if(j(i,r.Dep)){let e=[...i.args],t;return h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),t?Iv(t):new n({})}return n.create(e)}},Rv=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 z?[new T(w.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?kf(e)?[]:[new T(w.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new T(w.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=E(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new T(w.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof H)return{errors:[new T(w.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=g(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=>Uf(e.callee)?e.args.length>0?e.args.map(e=>new T(w.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new T(w.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 T(w.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(Af(e))return t.push(new T(w.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&&Uf(e.callee)),a=r.body.some(e=>e instanceof H&&!Uf(e.callee));return i&&a&&n.push(new xf(w.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)Uf(e.callee)||(e.args.length>0||!M(e.callee))&&t.push(...e.args.map(e=>new T(w.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},zv={validateNode(t,i){if(!A(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new Rv(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(A(i,r.DiagramView)){if(!i.name)return new n(void 0,[new T(w.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=M(i.name);return e?new n(e):new n(void 0)}else if(j(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=M(i.callee);return e?(e.length===1&&j(i,r.DiagramViewTables)&&e.unshift(v),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return A(i,r.DiagramView)?new n(void 0):n.create(e)}},Bv=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 z?[new T(w.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Df(e)?[]:[new T(w.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new T(w.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.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]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new T(w.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!O(n.callee)&&t.push(new T(w.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];h(e)instanceof W?(t.push(...this.validateFieldSettings(h(e))),e.pop()):e[0]instanceof W&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new T(w.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=E(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 T(w.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{D(e.value)||n.push(new T(w.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new T(w.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():[])}},Vv={validateNode(t,i){return A(i,r.Enum)?n.create(void 0,new Bv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(A(i,r.Enum)){if(!i.name)return new n(void 0,[new T(w.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Df(i.name))return new n(void 0,[new T(w.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=M(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(j(i,r.Enum)){let e=P(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return A(i,r.Enum)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(A(a,r.Enum))return a.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(j(a,r.Enum)){let e=[...a.args],t;if(h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),!t)return new n({});let r=E(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 T(w.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{D(e.value)||o.push(new T(w.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new T(w.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Hv=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 T(w.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof R?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new T(w.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=g(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 h(n)instanceof W&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof Sm;)e.argumentList&&dp(e.argumentList)===void 0&&t.push(new T(w.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;dp(e)===void 0&&t.push(new T(w.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=E(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 T(w.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{D(t.value)||n.push(new T(w.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new T(w.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new T(w.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new T(w.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{O(e.value)||n.push(new T(w.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new T(w.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Uv={validateNode(t,i){return A(i,r.Indexes)?n.create(void 0,new Hv(t,i).validate()):n.create(e)},nodeFullname(t,i){return A(i,r.Indexes)?i.name?new n(void 0,[new T(w.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):j(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Indexes)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(A(a,r.Indexes))return a.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(j(a,r.Indexes)){let e=[a.callee,...a.args],t;if(h(e)instanceof W&&(t=h(e)),!t)return new n({});let r=E(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 T(w.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{D(t.value)||o.push(new T(w.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 T(w.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{O(e.value)||o.push(new T(w.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new T(w.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Wv=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 R)&&!(e instanceof z&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project,r.Dep))?[new T(w.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 T(w.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof R}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new T(w.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=E(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.Color:{let t=gv[i.Color];e.length>1&&n.push(...e.map(e=>new T(w.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{t.isValidBuiltinFieldValue(e.value)||n.push(new T(w.INVALID_NOTE_SETTING_VALUE,t.message,e.value||e.name))});break}default:n.push(...b_(t,e,{duplicate:w.DUPLICATE_NOTE_SETTING,invalidValue:w.INVALID_NOTE_SETTING_VALUE}))}}),n}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new T(w.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new T(w.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),D(e[0].callee)||t.push(new T(w.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 T(w.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():[])}},Gv={validateNode(t,i){return A(i,r.Note)?n.create(void 0,new Wv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!A(i,r.Note))return n.create(e);if(!(i.parent instanceof R))return i.name?new n(void 0,[new T(w.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new T(w.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof wm)return new n(void 0,[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=M(i.name);return a===void 0?new n(void 0,[new T(w.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return A(i,r.Note)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Note)?i.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},Kv={[Vp.Table]:O_,[Vp.Column]:k_,[Vp.TableGroup]:J_,[Vp.Note]:gv},qv=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 y_(this.declarationNode)?[]:[new T(w.INVALID_METADATA_TARGET_KIND,`A Metadata target kind must be one of: ${Object.values(Vp).join(`, `)}`,this.declarationNode.targetKind??this.declarationNode)]}validateTargetName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Metadata target's name`,e)]:Df(e)?[]:[new T(w.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 T(w.NAME_NOT_FOUND,`A Metadata target must have a name`,this.declarationNode)]}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A Metadata's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.map(e=>new T(w.INVALID_METADATA_FIELD,`A Metadata field must use the 'key: value' syntax`,e))}validateSubElements(e){let t={},n=y_(this.declarationNode),r=e.flatMap(e=>{if(!e.type)return[];if(e.body instanceof U)return[new T(w.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?Kv[n][r]:void 0;return i?i.isValidBuiltinFieldValue(e.body?.callee)?[]:[new T(w.INVALID_METADATA_FIELD,i.message,e)]:Hf(e.body?.callee)?[]:[new T(w.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 T(w.DUPLICATE_METADATA_FIELD,`Duplicate Metadata fields are defined`,e)))),r}},Jv={validateNode(t,i){return A(i,r.Metadata)?new n(void 0,new qv(t,i).validate()):new n(e)},nodeFullname(t,i){return A(i,r.Metadata)?new n(void 0):new n(e)},nodeAlias(t,i){return A(i,r.Metadata)?new n(void 0):new n(e)},nodeSettings(t,i){return A(i,r.Metadata)?new n({}):new n(e)}},Yv=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)}},Xv={validateNode(t,r){return Jf(r)?n.create(void 0,new Yv(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Jf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Jf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Jf(r)?new n({}):n.create(e)}},Zv=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 z?[new T(w.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?kf(e)?new n(M(e)):new n(void 0,[new T(w.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 T(w.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...t.map(e=>new T(w.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():[])}},Qv={validateNode(t,i){return A(i,r.Project)?n.create(void 0,new Zv(t,i).validate()):n.create(e)},nodeFullname(t,i){return A(i,r.Project)?i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):j(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Project)&&i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):j(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Project)?i.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):j(i,r.Project)?new n({}):n.create(e)}},$v=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 R||e instanceof z&&e.isKind(r.Table)?[]:[new T(w.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof R?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof Sm))return[new T(w.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||!Df(e.callee))&&t.push(new T(w.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Bf(e.argumentList))&&t.push(new T(w.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Bf(e)?[new T(w.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return ey(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateDataRow(e);let[t,n]=g(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 T(w.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof bm)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new T(w.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 T(w.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 Dm||Lf(e)||D(e)||e instanceof vm)return!0;if(O(e)){let t=e.expression.variable.value.toLowerCase();return Co.includes(t)}if(k(e)){let t=M(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function ey(e){let t=E(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.Example:e.length>1&&r.push(...e.map(e=>new T(w.DUPLICATE_RECORDS_SETTING,`'example' can only appear once`,e))),e.forEach(e=>{e.value&&r.push(new T(w.INVALID_RECORDS_SETTING_VALUE,`'example' cannot have a value`,e))});break;default:r.push(...e.map(e=>new T(w.UNKNOWN_RECORDS_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}var ty={validateNode(t,i){return A(i,r.Records)?n.create(void 0,new $v(t,i).validate()):n.create(e)},nodeFullname(i,a){if(A(a,r.Records)){if(a.name instanceof wm)return new n(void 0,[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof R){if(!(a.name instanceof Sm))return new n(void 0,[new T(w.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||!Df(a.name.callee))&&e.push(new T(w.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Bf(a.name.argumentList))&&e.push(new T(w.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=M(a.name.callee);return t?.length===1&&t.unshift(v),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Bf(a.name)?new n(e,[new T(w.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return j(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Records)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):j(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Records)?i.attributeList?ey(i.attributeList):new n({}):j(i,r.Records)?new n({}):n.create(e)}},ny=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 T(w.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:kf(e)?[]:[new T(w.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.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]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new T(w.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 T(w.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!$f(e.callee)&&t.push(new T(w.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&$f(e.callee)){let n=up(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=up(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new T(w.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new T(w.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!ep(e.callee)&&t.push(new T(w.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(h(n)instanceof W){let e=this.validateFieldSettings(h(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 T(w.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return iy(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function ry(e){if(!(O(e)&&e.expression.variable.kind!==_.QUOTED_STRING)&&!(e instanceof hm))return!1;let t;if(t=e instanceof hm?ap(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 iy(e){let t=E(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 T(w.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{ry(t.value)||r.push(new T(w.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 T(w.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Pf(e.value)||r.push(new T(w.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 T(w.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new T(w.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new T(w.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var ay={validateNode(t,i){return A(i,r.Ref)?n.create(void 0,new ny(t,i).validate()):n.create(e)},nodeFullname(t,i){return A(i,r.Ref)?i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):j(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Ref)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(A(i,r.Ref))return i.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(j(i,r.Ref)){let e=[...i.args],t;return h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),t?iy(t):new n({})}return n.create(e)}},oy=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 z?[new T(w.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Om?[new T(w.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Df(e)?[]:[new T(w.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new T(w.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Of(e)?[]:[new T(w.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){return sy(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=g(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 T(w.INVALID_COLUMN,`A column must have a type`,e.callee)),O(e.callee)||t.push(new T(w.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Vf(e.args[0])&&t.push(new T(w.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?(jf(e.callee)||t.push(new T(w.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 T(w.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof V&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){return cy(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 T(w.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function sy(e){let t=E(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new T(w.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{let t=O_[i.HeaderColor];t.isValidBuiltinFieldValue(e.value)||r.push(new T(w.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new T(w.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{let t=O_[i.Note];t.isValidBuiltinFieldValue(e.value)||r.push(new T(w.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Dep:e.forEach(e=>{zf(e.value)||r.push(new T(w.INVALID_TABLE_SETTING_VALUE,"'dep' must be `-> target` or `<- source`",e.value||e.name))});break;default:r.push(...b_(t,e,{duplicate:w.DUPLICATE_TABLE_SETTING,invalidValue:w.INVALID_TABLE_SETTING_VALUE}))}}),new n(a,r)}function cy(e){if(!e.slice(0,-1).every(Wf)||!e.slice(-1).every(e=>Wf(e)||e instanceof W))return new n({},e.map(e=>new T(w.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;h(e)instanceof W&&(t=e.pop());let r=E(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(P(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new T(w.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{let t=k_[i.Note];t.isValidBuiltinFieldValue(e.value)||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Rf(e.value)||a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.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 T(w.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 T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{If(e.value)||a.push(new T(w.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 vm||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;case i.Dep:e.forEach(e=>{zf(e.value)||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'dep' must be a valid unary relationship`,e.value||e.name))});break;default:a.push(...b_(t,e,{duplicate:w.DUPLICATE_COLUMN_SETTING,invalidValue:w.INVALID_COLUMN_SETTING_VALUE}))}}),new n(o,a)}var ly={validateNode(t,i){return A(i,r.Table)?n.create(void 0,new oy(t,i).validate()):n.create(e)},nodeFullname(t,i){if(A(i,r.Table)){if(!i.name)return new n(void 0,[new T(w.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof Om)return new n(void 0,[new T(w.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=M(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(j(i,r.Table)){if(jf(i.callee)){let e=P(i.callee.expression);return new n(e?[e]:void 0)}let e=P(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return A(i,r.Table)?i.alias?Of(i.alias)?new n(P(i.alias)):new n(void 0,[new T(w.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):j(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Table)?i.attributeList?sy(i.attributeList):new n({}):j(i,r.Table)?cy(i.args.slice(1)):n.create(e)}},uy=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 z?[new T(w.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:kf(e)?[]:[new T(w.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new T(w.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){return dy(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&M(e.callee)===void 0&&t.push(new T(w.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 T(w.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 T(w.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function dy(e){let t=E(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=J_[e];t.length>1&&r.push(...t.map(t=>new T(w.DUPLICATE_TABLE_SETTING,`'${e}' can only appear once`,t))),t.forEach(e=>{n.isValidBuiltinFieldValue(e.value)||r.push(new T(w.INVALID_TABLE_SETTING_VALUE,n.message,e.value||e.name))}),o[e]=t;break}default:r.push(...b_(e,t,{duplicate:w.DUPLICATE_TABLE_SETTING,invalidValue:w.INVALID_TABLE_SETTING_VALUE})),o[e]=t;break}return new n(o,r)}var fy={validateNode(t,i){return A(i,r.TableGroup)?n.create(void 0,new uy(t,i).validate()):n.create(e)},nodeFullname(t,i){if(A(i,r.TableGroup))return i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new T(w.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(j(i,r.TableGroup)){let e=M(i.callee);return e?.length===1&&e.unshift(v),new n(e)}return n.create(e)},nodeAlias(t,i){return A(i,r.TableGroup)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.TableGroup)?dy(i.attributeList):j(i,r.TableGroup)?new n({}):n.create(e)}},py=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 z?[new T(w.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:kf(e)?[]:[new T(w.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new T(w.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=E(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new T(w.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Pf(e.value)||n.push(new T(w.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 T(w.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{D(e.value)||n.push(new T(w.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new T(w.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=g(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 T(w.INVALID_COLUMN,`A column must have a type`,e.callee)),O(e.callee)||t.push(new T(w.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Vf(e.args[0])&&t.push(new T(w.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=h(e);if(!e.slice(0,-1).every(Wf)||!(Wf(t)||t instanceof W))return e.map(e=>new T(w.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;h(e)instanceof W&&(n=e.pop());let r=E(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(P(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{D(e.value)||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Rf(e.value)||a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.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 T(w.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 T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{If(e.value)||a.push(new T(w.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 vm||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...b_(t,e,{duplicate:w.DUPLICATE_COLUMN_SETTING,invalidValue:w.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 T(w.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function my(e){let t=E(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new T(w.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Pf(e.value)||r.push(new T(w.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 T(w.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{D(e.value)||r.push(new T(w.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new T(w.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function hy(e){let t=h(e);if(e.length>0&&(!e.slice(0,-1).every(Wf)||!(Wf(t)||t instanceof W)))return new n({},e.map(e=>new T(w.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;h(e)instanceof W&&(r=e.pop());let a=E(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(P(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{D(e.value)||o.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Rf(e.value)||o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&o.push(new T(w.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 T(w.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 T(w.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 T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{If(e.value)||o.push(new T(w.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 vm||o.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:o.push(...b_(t,e,{duplicate:w.DUPLICATE_COLUMN_SETTING,invalidValue:w.INVALID_COLUMN_SETTING_VALUE}))}}),new n(s,o)}var gy={validateNode(t,i){return A(i,r.TablePartial)?n.create(void 0,new py(t,i).validate()):n.create(e)},nodeFullname(t,i){if(A(i,r.TablePartial))return i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new T(w.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(j(i,r.TablePartial)){let e=P(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return A(i,r.TablePartial)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(P(i.alias)):j(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.TablePartial)?my(i.attributeList):j(i,r.TablePartial)?hy(i.args.slice(1)):n.create(e)}},_y=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof R?[]:[new T(w.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.importPath&&!xo.isRelative(this.declarationNode.importPath.value)&&e.push(new T(w.INVALID_USE_SPECIFIER_NAME,`Import path must be a relative path (starting with './' or '../')`,this.declarationNode.importPath)),this.declarationNode.specifiers instanceof wm)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 T(w.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Bp))||t.push(new T(w.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()]}},vy=[ly,Vv,ty,Uv,jv,ay,Lv,Qv,fy,gy,Gv,Jv,zv,Xv,{validateNode(t,r){return r instanceof fm?n.create(void 0,new _y(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!qf(r))return n.create(e);let i=M(r.name);return!i||i.length===0?n.create(void 0,[new T(w.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Bp.TableGroup)&&i.length>1?n.create(i,[new T(w.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Bp.TablePartial)&&i.length>1?n.create(i,[new T(w.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Bp.Note)&&i.length>1?n.create(i,[new T(w.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Bp.Schema)&&i.unshift(v),new n(i))},nodeAlias(t,r){return qf(r)?r.alias?Of(r.alias)?new n(P(r.alias)):new n(void 0,[new T(w.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 fm?n.create({}):n.create(e)}},Pv];function yy(t,...r){for(let n of vy){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function by(r){let i=yy(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function xy(r){let i=yy(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function Sy(r){let i=yy(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function Cy(r){let i=yy(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var wy=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Ty(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}),wy&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function Ey(e,t,...n){return Ty(t,n)}var Dy=!1,Oy=!1,ky=!1,Ay=!1,jy=void 0,My=typeof self==`object`?self:typeof global==`object`?global:{},Ny=void 0;My.vscode!==void 0&&My.vscode.process!==void 0?Ny=My.vscode.process:typeof process<`u`&&(Ny=process);var Py=typeof Ny?.versions?.electron==`string`&&Ny?.type===`renderer`;if(typeof navigator==`object`&&!Py)jy=navigator.userAgent,Dy=jy.indexOf(`Windows`)>=0,Oy=jy.indexOf(`Macintosh`)>=0,(jy.indexOf(`Macintosh`)>=0||jy.indexOf(`iPad`)>=0||jy.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,ky=jy.indexOf(`Linux`)>=0,jy?.indexOf(`Mobi`),Ay=!0,Ey({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof Ny==`object`){Dy=Ny.platform===`win32`,Oy=Ny.platform===`darwin`,ky=Ny.platform===`linux`,ky&&Ny.env.SNAP&&Ny.env.SNAP_REVISION,Ny.env.CI||Ny.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=Ny.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 Fy=Dy,Iy=Oy;Ay&&My.importScripts;var Ly=jy,Ry=typeof My.postMessage==`function`&&!My.importScripts;(()=>{if(Ry){let e=[];My.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}),My.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var zy=!!(Ly&&Ly.indexOf(`Chrome`)>=0);Ly&&Ly.indexOf(`Firefox`),!zy&&Ly&&Ly.indexOf(`Safari`),Ly&&Ly.indexOf(`Edg/`),Ly&&Ly.indexOf(`Android`);var By;if(My.vscode!==void 0&&My.vscode.process!==void 0){let e=My.vscode.process;By={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else By=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 Fy?`win32`:Iy?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var Vy=By.cwd,Hy=By.env,Uy=By.platform,Wy=65,Gy=97,Ky=90,qy=122,Jy=46,Yy=47,Xy=92,Zy=58,Qy=63,$y=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 eb(e,t){if(typeof e!=`object`||!e)throw new $y(t,`Object`,e)}function tb(e,t){if(typeof e!=`string`)throw new $y(t,`string`,e)}var nb=Uy===`win32`;function K(e){return e===Yy||e===Xy}function rb(e){return e===Yy}function ib(e){return e>=Wy&&e<=Ky||e>=Gy&&e<=qy}function ab(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=Yy;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==Jy||i.charCodeAt(i.length-2)!==Jy){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===Jy&&s!==-1?++s:s=-1}return i}function ob(e,t){eb(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 sb={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],tb(a,`path`),a.length===0)continue}else t.length===0?a=Vy():(a=Hy[`=${t}`]||Vy(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Xy)&&(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 ib(u)&&a.charCodeAt(1)===Zy&&(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=ab(n,!r,`\\`,K),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){tb(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return rb(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 ib(a)&&e.charCodeAt(1)===Zy&&(r=e.slice(0,2),n=2,t>2&&K(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?ab(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){tb(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return K(n)||t>2&&ib(n)&&e.charCodeAt(1)===Zy&&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];tb(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 sb.normalize(t)},relative(e,t){if(tb(e,`from`),tb(t,`to`),e===t)return``;let n=sb.resolve(e),r=sb.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Xy;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Xy;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Xy;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Xy;)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===Xy&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Xy)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Xy?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)===Xy)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Xy&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=sb.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Xy){if(t.charCodeAt(1)===Xy){let e=t.charCodeAt(2);if(e!==Qy&&e!==Jy)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(ib(t.charCodeAt(0))&&t.charCodeAt(1)===Zy&&t.charCodeAt(2)===Xy)return`\\\\?\\${t}`;return e},dirname(e){tb(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 ib(i)&&e.charCodeAt(1)===Zy&&(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&&tb(t,`ext`),tb(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&ib(e.charCodeAt(0))&&e.charCodeAt(1)===Zy&&(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){tb(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Zy&&ib(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===Jy?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:ob.bind(null,`\\`),parse(e){tb(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(ib(i)&&e.charCodeAt(1)===Zy){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===Jy?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},cb=(()=>{if(nb){let e=/\\/g;return()=>{let t=Vy().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Vy()})(),lb={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:cb();tb(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Yy)}return t=ab(t,!n,`/`,rb),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(tb(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Yy,n=e.charCodeAt(e.length-1)===Yy;return e=ab(e,!t,`/`,rb),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return tb(e,`path`),e.length>0&&e.charCodeAt(0)===Yy},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];tb(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:lb.normalize(t)},relative(e,t){if(tb(e,`from`),tb(t,`to`),e===t||(e=lb.resolve(e),t=lb.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===Yy&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===Yy)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Yy?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Yy)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(tb(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Yy,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Yy){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&&tb(t,`ext`),tb(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===Yy){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)===Yy){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){tb(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===Yy){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===Jy?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:ob.bind(null,`/`),parse(e){tb(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Yy,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===Yy){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===Jy?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};lb.win32=sb.win32=sb,lb.posix=sb.posix=lb,nb?sb.normalize:lb.normalize,nb?sb.resolve:lb.resolve,nb?sb.relative:lb.relative,nb?sb.dirname:lb.dirname,nb?sb.basename:lb.basename,nb?sb.extname:lb.extname,nb?sb.sep:lb.sep;var ub=/^\w[\w\d+.-]*$/,db=/^\//,fb=/^\/\//;function pb(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&&!ub.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!db.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(fb.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 mb(e,t){return!e&&!t?`file`:e}function hb(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==gb&&(t=gb+t):t=gb;break}return t}var q=``,gb=`/`,_b=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,vb=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=mb(e,a),this.authority=t||q,this.path=hb(this.scheme,n||q),this.query=r||q,this.fragment=i||q,pb(this,a))}get fsPath(){return wb(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 bb(t,n,r,i,a)}static parse(e,t=!1){let n=_b.exec(e);return n?new bb(n[2]||q,Ob(n[4]||q),Ob(n[5]||q),Ob(n[7]||q),Ob(n[9]||q),t):new bb(q,q,q,q,q)}static file(e){let t=q;if(Fy&&(e=e.replace(/\\/g,gb)),e[0]===gb&&e[1]===gb){let n=e.indexOf(gb,2);n===-1?(t=e.substring(2),e=gb):(t=e.substring(2,n),e=e.substring(n)||gb)}return new bb(`file`,t,e,q,q)}static from(e,t){return new bb(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=Fy&&t.scheme===`file`?e.file(sb.join(wb(t,!0),...n)).path:lb.join(t.path,...n),t.with({path:r})}toString(e=!1){return Tb(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new bb(t);return e._formatted=t.external??null,e._fsPath=t._sep===yb?t.fsPath??null:null,e}}},yb=Fy?1:void 0,bb=class extends vb{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=wb(this,!1),this._fsPath}toString(e=!1){return e?Tb(this,!0):(this._formatted||=Tb(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=yb),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}},xb={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 Sb(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=xb[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 Cb(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+=xb[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function wb(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,Fy&&(n=n.replace(/\//g,`\\`)),n}function Tb(e,t){let n=t?Cb:Sb,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=gb,r+=gb),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:Sb(c,!1,!1)),r}function Eb(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+Eb(e.substr(3)):e}}var Db=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function Ob(e){return e.match(Db)?e.replace(Db,e=>Eb(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}({}),kb=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 Ab(e,t){return e.getOffsetAt(t)}function jb(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 Mb=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=xo.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=jb(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=Fa(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=xo.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=vb.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]}}},Nb=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=xo.fromUri(String(e.uri)),a=Ab(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&&[dm.PRIMARY_EXPRESSION,dm.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=vb.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[]}},Pb=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`?kb.Error:e===`warning`?kb.Warning:kb.Info}},Fb=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=xo.fromUri(String(r)),a=Ab(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[dm.ELEMENT_DECLARATION,dm.FUNCTION_APPLICATION,dm.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=vb.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 Ib(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 mm)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=P(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?P(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof wm&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof wm)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function Lb(e,t,n,r,i,a){let o=Ib(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:Rb(Pa([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
11
+ `)?`'''\n${e}\n'''`:`'${V_(e)}'`}var q_=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]=g(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(Rm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof cm?[...r.getErrors(),new T(w.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():[])}},J_={[i.Note]:{isValidBuiltinFieldValue:D,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.Color]:{isValidBuiltinFieldValue:Pf,message:`'color' must be a color literal`,assignBuiltinField(e,t){e.color=t}}},Y_=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=F(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),T_(this.compiler,this.tableGroup,this.symbol,J_,this.filepath),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=Pp(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new T(w.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]=g(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:Np(N(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:F(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(I.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=M(e.callee);return i.length>2&&n.push(new T(w.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=E(e).getValue();this.tableGroup.color=t.color?.length?Fp(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Np(N(n?.value)),token:F(n)},this.tableGroup.metadata=Rp(t,Object.keys(J_)),[]}},X_={getDuplicateError(e,t,n){return new T(w.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new T(w.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Z_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return A(a,r.TableGroup)?new n(i.symbolFactory.create(Yp,{declaration:a,name:s},a.filepath)):j(a,r.TableGroup)?new n(i.symbolFactory.create(Xp,{declaration:a,name:o?.map(R_).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(I.TableGroup)){let e=i.declaration;if(!(e instanceof z))return new n([]);let a=cp(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(I.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof z&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(X_.getFieldDuplicateError(e.name,r)),s.push(X_.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(I.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!O(a)||!Yf(a,r.TableGroup)||a.parent&&Zf(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):Q_(i,s,a)},bindNode(i,a){if(!A(a,r.TableGroup))return n.create(e);let o=new q_(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!A(o,r.TableGroup)||!(i instanceof Yp)?n.create(e):Lm(t,o)?new Y_(t,i,a).interpret():n.create(void 0)}};function Q_(e,r,i){let a=mp(i)??``;if(!k(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Wp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,I.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,I.Table,a);return s?n.create(s):new n(void 0,[new T(w.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=zm(e,i);if(o){if(o.isKind(I.Schema)){let t=e.lookupMembers(o,[I.Table,I.Schema],a);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,I.Schema,a);return s?n.create(s):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var $_=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]=g(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(h(n)instanceof W){let e=E(h(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=up(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return Rm(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():[])}},ev=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??F(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}=Pp(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=E(e).getValue(),n=ya(t[i.HeaderColor]);this.tablePartial.headerColor=n?Fp(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Np(N(r?.value)),token:F(r)},[]}interpretBody(e){let[t,n]=g(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:Np(N(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:F(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=mp(e.callee)??``,r.token=F(e);let o=Lp(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=Rp(s,D_);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 qm))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:F(n.rightToken())}}),r.inline_deps=[],r.checks=(s[i.Check]||[]).map(e=>({token:F(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()}},tv={getDuplicateError(e,t,n){return new T(w.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},nv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return A(a,r.TablePartial)?new n(i.symbolFactory.create(Qp,{declaration:a,name:o},a.filepath)):j(a,r.TablePartial)?new n(i.symbolFactory.create(Jp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(I.TablePartial)){let e=a.declaration;if(!(e instanceof z))return new n([]);let r=cp(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(I.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof z&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(A_.getColumnDuplicateError(t,r)),s.push(A_.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(I.Column)&&A(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!O(o)&&!k(o)||!Yf(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):Xf(o,1)?rv(a,c,o):Qf(o,i.Ref)?iv(a,c,o):av(a,c,o)},bindNode(i,a){if(!A(a,r.TablePartial))return n.create(e);let o=new $_(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 Qp?r.declaration instanceof z?new ev(t,r,i).interpret():n.create(void 0):n.create(e)}};function rv(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return n.create(e.lookupMembers(t,I.Enum,i));let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Enum,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.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,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function iv(e,i,a){if(!O(a))return new n(void 0);let o=mp(a)??``;if(!k(a.parentNode)){let s=a.parent;if(s instanceof z&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,I.Column,o);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,I.Column,o);return c?n.create(c):new n(void 0,[new T(w.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=zm(e,a);if(s){if(s.isKind(I.Schema)){let t=e.lookupMembers(s,[I.Table,I.Schema],o);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(I.Table)){let t=e.lookupMembers(s,I.Column,o);return t?n.create(t):new n(void 0,[new T(w.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(k(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,I.Schema,o);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,I.Table,o);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function av(e,t,r){if(!O(r))return new n(void 0);let i=mp(r)??``;if(!k(r.parentNode))return Co.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,I.Enum,i));let a=zm(e,r);if(a){if(a.isKind(I.Schema)){let t=e.lookupMembers(a,[I.Enum,I.Schema],i);return t?n.create(t):new n(void 0,[new T(w.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(I.Enum)){let t=e.lookupMembers(a,I.EnumField,i);return t?n.create(t):new n(void 0,[new T(w.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(k(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,I.Schema,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,I.Enum,i);return a?n.create(a):new n(void 0,[new T(w.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var ov={symbolMembers(r,i){if(!i.isKind(I.Schema)||!(i instanceof Wp))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=cv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...lv(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...dv(r,i,e,t,c));for(let e of o.uses.selective){let n=cv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...lv(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...dv(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(I.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(I.TableGroup)))}}for(let t of e)u.push(...pv(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof cm&&e.isKind(I.Schema))return!1;let t=`${e.originalSymbol.intern()}:${e.name??``}`;return d.has(t)?!1:(d.add(t),!0)}),p=new Map;for(let e of f){let t=`${e.kind}:${e.name}`;if(p.get(t)){if(e.isKind(I.Schema))continue;let t=e instanceof cm?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof z&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(sv(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function sv(e,t,n,r){switch(e){case I.Table:return A_.getDuplicateError(t,n,r);case I.Enum:return xh.getDuplicateError(t,n,r);case I.TablePartial:return tv.getDuplicateError(t,n,r);case I.TableGroup:return X_.getDuplicateError(t,n,r);case I.DiagramView:return ph.getDuplicateError(t,n,r);default:return new T(w.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function cv(e,r,i,a){let o=u_(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(Wp,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function lv(e,n,r,i=new Set){if(r.getSymbolKind()!==I.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(I.Schema))return[];let o=o_.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:uv(e,n,r,a,i)}function uv(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(cm,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(I.TableGroup)&&c.push(...pv(e,n,t));for(let i of s.reuses.selective)if(c.push(...lv(e,n,i,a)),u_(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(cm,{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=fv(e,t,n.qualifiedName);i&&c.push(...uv(e,n,r,i,a))}return c}function dv(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=fv(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(cm,{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(Wp,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=cv(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...lv(e,n,r))}for(let{importPath:t}of d)l.push(...dv(e,n,t,i,a,o));return l}function fv(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 pv(e,n,r){if(!r.isKind(I.TableGroup)||!(r instanceof cm))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(I.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=M(n);if(!i||i.length===0)continue;let a=i.length<=1?[v]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=mv(e,c,i);l&&s.push(e.symbolFactory.create(cm,{kind:I.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function mv(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(I.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(I.Table)&&e.name===a)}var hv=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 z);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},gv={[i.Color]:{isValidBuiltinFieldValue:Ff,message:`'color' must be a color literal or 'none'`,assignBuiltinField(e,t){e.color=t}}},_v=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=F(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return T_(this.compiler,this.note,this.symbol,gv,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=E(e).getValue();return t.color?.length&&(this.note.color=Fp(t.color.at(0)?.value)),this.note.metadata=Rp(t,Object.keys(gv)),[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof H);return t.length!==1||n.length>0?[new T(w.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=N(e.callee)??``;return this.note.content=Np(t),[]}},vv={nodeSymbol(i,a){return!A(a,r.Note)||!(a.parentNode instanceof R)?n.create(e):new n(i.symbolFactory.create(Zp,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(I.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return A(i,r.Note)?n.create(void 0,new hv(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Zp?r.declaration instanceof z?new _v(t,r,i).interpret():n.create(void 0):n.create(e)}},yv=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=y_(this.declarationNode);return!M(e)?.length||!t||C_(this.compiler,this.declarationNode)?[]:[new T(w.BINDING_ERROR,`cannot find metadata target element`,e??this.declarationNode)]}bindBody(e){return e instanceof U?e.body.filter(e=>e instanceof z).flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[]):[]}},bv=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 z))continue;let e=t.type?.value;if(!e)continue;let n=zp(t.body instanceof H?t.body.callee:void 0);n&&(this.values[e]={value:e===`note`?Np(n):n,token:F(t)})}return[]}},xv=[s_,j_,Sh,Yg,Th,ih,i_,ch,Hg,Z_,nv,vv,{nodeMetadata(t,i){return A(i,r.Metadata)?new n(new Zm(i)):new n(e)},nodeReferee(t,i){if(!O(i))return new n(e);let a=i.parentOfKind(z);return!a||!A(a,r.Metadata)||!a.name?.containsEq(i)?new n(e):!M(a.name)||!y_(a)?new n(void 0):new n(C_(t,a))},bindNode(t,i){return A(i,r.Metadata)?new n(void 0,new yv(t,i).bind()):new n(e)},interpretMetadata(t,i,a){return i instanceof Zm?A(i.declaration,r.Metadata)?new bv(t,i,a).interpret():new n(void 0):new n(e)}},ov,mh,zg];function Sv(t,...r){for(let i of xv){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function Cv(r){let i=Sv(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function wv(r){let i=Sv(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Tv(r){let i=Sv(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Ev(r){let i=Sv(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function Dv(r){let i=Sv(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function Ov(r,i){let a=Sv(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function kv(r,i){let a=Sv(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var Av=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 T(w.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof R?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new T(w.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=g(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 h(n)instanceof W&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof vm))&&t.push(new T(w.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=E(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 T(w.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{D(t.value)||n.push(new T(w.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new T(w.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},jv={validateNode(t,i){if(!A(i,r.Checks))return n.create(e);let a=new Av(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return A(i,r.Checks)?i.name?new n(void 0,[new T(w.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Checks)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Checks)?i.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},Mv=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 z&&this.declarationNode.parent.isKind(r.Project,r.Dep)?[]:[new T(w.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project or a Dep`,this.declarationNode)]}validateName(e){return e?[new T(w.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return[new T(w.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return!(this.declarationNode.parent instanceof z&&this.declarationNode.parent.isKind(r.Dep))&&!D(e.callee)&&t.push(new T(w.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 T(w.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function Nv(e){return e instanceof z&&!!e.type?.value}var Pv={validateNode(t,r){if(!Nv(r))return n.create(e);let i=new Mv(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return Nv(r)?r.name?new n(void 0,[new T(w.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return Nv(r)?r.alias?new n(void 0,[new T(w.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return Nv(r)?r.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},Fv=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(...Iv(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(...Iv(n).getErrors())}return e}validateContext(){return this.declarationNode.parent instanceof R?[]:[new T(w.INVALID_DEP_CONTEXT,`A Dep must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Dep name`,e)]:kf(e)?[]:[new T(w.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,e)]:[]}validateAlias(e){return e?[new T(w.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]=g(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 T(w.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e));return}if(!(e.callee instanceof gm)){t.push(new T(w.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 T(w.INVALID_DEP_FIELD,`Dep edges must use the '->' or '<-' operator`,e.callee));let r=up(n.leftExpression)??{variables:[],tupleElements:[]},i=up(n.rightExpression)??{variables:[],tupleElements:[]};r.variables.length===0&&r.tupleElements.length===0&&t.push(new T(w.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.leftExpression||e.callee)),i.variables.length===0&&i.tupleElements.length===0&&t.push(new T(w.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.rightExpression||e.callee));let a=[...e.args];h(a)instanceof W?a.pop():a[0]instanceof W&&a.shift(),a.length>0&&t.push(...a.map(e=>new T(w.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||!Pf(n.callee)?[new T(w.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||!D(t)?[new T(w.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,e)]:[]}default:return e.name||n instanceof U?[new T(w.INVALID_SETTINGS,`'${t}' must be a simple field (e.g. ${t}: value). Block syntax is not allowed`,e)]:!(n instanceof H)||!n.callee?[]:!D(n.callee)&&!Pf(n.callee)&&!Lf(n.callee)&&!kf(n.callee)?[new T(w.INVALID_SETTINGS,`Invalid value for '${t}'. Expected a string, number, color, or identifier`,e)]:[]}})}};function Iv(e){let t=E(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:Pf(n.value)||r.push(new T(w.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,n));break;case i.Note:D(n.value)||r.push(new T(w.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,n));break;default:n.value&&!D(n.value)&&!Pf(n.value)&&!Lf(n.value)&&!kf(n.value)&&r.push(new T(w.INVALID_SETTINGS,`Invalid value for setting '${e}'. Expected a string, number, color, or identifier`,n));break}return new n(a,r)}var Lv={validateNode(t,i){return A(i,r.Dep)?n.create(void 0,new Fv(t,i).validate()):n.create(e)},nodeFullname(t,i){return A(i,r.Dep)?i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,i.name)]):new n(void 0):j(i,r.Dep)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Dep)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.Dep)?new n(void 0):n.create(e)},nodeSettings(t,i){if(A(i,r.Dep))return i.attributeList?Iv(i.attributeList):new n({});if(j(i,r.Dep)){let e=[...i.args],t;return h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),t?Iv(t):new n({})}return n.create(e)}},Rv=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 z?[new T(w.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?kf(e)?[]:[new T(w.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new T(w.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=E(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new T(w.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof H)return{errors:[new T(w.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=g(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=>Uf(e.callee)?e.args.length>0?e.args.map(e=>new T(w.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new T(w.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 T(w.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(Af(e))return t.push(new T(w.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&&Uf(e.callee)),a=r.body.some(e=>e instanceof H&&!Uf(e.callee));return i&&a&&n.push(new xf(w.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)Uf(e.callee)||(e.args.length>0||!M(e.callee))&&t.push(...e.args.map(e=>new T(w.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},zv={validateNode(t,i){if(!A(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new Rv(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(A(i,r.DiagramView)){if(!i.name)return new n(void 0,[new T(w.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=M(i.name);return e?new n(e):new n(void 0)}else if(j(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=M(i.callee);return e?(e.length===1&&j(i,r.DiagramViewTables)&&e.unshift(v),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return A(i,r.DiagramView)?new n(void 0):n.create(e)}},Bv=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 z?[new T(w.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Df(e)?[]:[new T(w.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new T(w.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.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]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new T(w.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!O(n.callee)&&t.push(new T(w.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];h(e)instanceof W?(t.push(...this.validateFieldSettings(h(e))),e.pop()):e[0]instanceof W&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new T(w.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=E(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 T(w.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{D(e.value)||n.push(new T(w.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new T(w.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():[])}},Vv={validateNode(t,i){return A(i,r.Enum)?n.create(void 0,new Bv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(A(i,r.Enum)){if(!i.name)return new n(void 0,[new T(w.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Df(i.name))return new n(void 0,[new T(w.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=M(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(j(i,r.Enum)){let e=P(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return A(i,r.Enum)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(A(a,r.Enum))return a.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(j(a,r.Enum)){let e=[...a.args],t;if(h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),!t)return new n({});let r=E(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 T(w.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{D(e.value)||o.push(new T(w.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new T(w.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Hv=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 T(w.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof R?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new T(w.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=g(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 h(n)instanceof W&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof Sm;)e.argumentList&&dp(e.argumentList)===void 0&&t.push(new T(w.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;dp(e)===void 0&&t.push(new T(w.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=E(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 T(w.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{D(t.value)||n.push(new T(w.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new T(w.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new T(w.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new T(w.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{O(e.value)||n.push(new T(w.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new T(w.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Uv={validateNode(t,i){return A(i,r.Indexes)?n.create(void 0,new Hv(t,i).validate()):n.create(e)},nodeFullname(t,i){return A(i,r.Indexes)?i.name?new n(void 0,[new T(w.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):j(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Indexes)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(A(a,r.Indexes))return a.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(j(a,r.Indexes)){let e=[a.callee,...a.args],t;if(h(e)instanceof W&&(t=h(e)),!t)return new n({});let r=E(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 T(w.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{D(t.value)||o.push(new T(w.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 T(w.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{O(e.value)||o.push(new T(w.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new T(w.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Wv=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 R)&&!(e instanceof z&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project,r.Dep))?[new T(w.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 T(w.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof R}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new T(w.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=E(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.Color:{let t=gv[i.Color];e.length>1&&n.push(...e.map(e=>new T(w.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{t.isValidBuiltinFieldValue(e.value)||n.push(new T(w.INVALID_NOTE_SETTING_VALUE,t.message,e.value||e.name))});break}default:n.push(...b_(t,e,{duplicate:w.DUPLICATE_NOTE_SETTING,invalidValue:w.INVALID_NOTE_SETTING_VALUE}))}}),n}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new T(w.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new T(w.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),D(e[0].callee)||t.push(new T(w.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 T(w.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():[])}},Gv={validateNode(t,i){return A(i,r.Note)?n.create(void 0,new Wv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!A(i,r.Note))return n.create(e);if(!(i.parent instanceof R))return i.name?new n(void 0,[new T(w.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new T(w.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof wm)return new n(void 0,[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=M(i.name);return a===void 0?new n(void 0,[new T(w.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return A(i,r.Note)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Note)?i.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},Kv={[Vp.Table]:O_,[Vp.Column]:k_,[Vp.TableGroup]:J_,[Vp.Note]:gv},qv=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 y_(this.declarationNode)?[]:[new T(w.INVALID_METADATA_TARGET_KIND,`A Metadata target kind must be one of: ${Object.values(Vp).join(`, `)}`,this.declarationNode.targetKind??this.declarationNode)]}validateTargetName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Metadata target's name`,e)]:Df(e)?[]:[new T(w.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 T(w.NAME_NOT_FOUND,`A Metadata target must have a name`,this.declarationNode)]}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A Metadata's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.map(e=>new T(w.INVALID_METADATA_FIELD,`A Metadata field must use the 'key: value' syntax`,e))}validateSubElements(e){let t={},n=y_(this.declarationNode),r=e.flatMap(e=>{if(!e.type)return[];if(e.body instanceof U)return[new T(w.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?Kv[n][r]:void 0;return i?i.isValidBuiltinFieldValue(e.body?.callee)?[]:[new T(w.INVALID_METADATA_FIELD,i.message,e)]:Hf(e.body?.callee)?[]:[new T(w.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 T(w.DUPLICATE_METADATA_FIELD,`Duplicate Metadata fields are defined`,e)))),r}},Jv={validateNode(t,i){return A(i,r.Metadata)?new n(void 0,new qv(t,i).validate()):new n(e)},nodeFullname(t,i){return A(i,r.Metadata)?new n(void 0):new n(e)},nodeAlias(t,i){return A(i,r.Metadata)?new n(void 0):new n(e)},nodeSettings(t,i){return A(i,r.Metadata)?new n({}):new n(e)}},Yv=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)}},Xv={validateNode(t,r){return Jf(r)?n.create(void 0,new Yv(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Jf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Jf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Jf(r)?new n({}):n.create(e)}},Zv=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 z?[new T(w.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?kf(e)?new n(M(e)):new n(void 0,[new T(w.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 T(w.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...t.map(e=>new T(w.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():[])}},Qv={validateNode(t,i){return A(i,r.Project)?n.create(void 0,new Zv(t,i).validate()):n.create(e)},nodeFullname(t,i){return A(i,r.Project)?i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):j(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Project)&&i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):j(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Project)?i.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):j(i,r.Project)?new n({}):n.create(e)}},$v=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 R||e instanceof z&&e.isKind(r.Table)?[]:[new T(w.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof R?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof Sm))return[new T(w.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||!Df(e.callee))&&t.push(new T(w.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Bf(e.argumentList))&&t.push(new T(w.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Bf(e)?[new T(w.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return ey(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateDataRow(e);let[t,n]=g(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 T(w.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof bm)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new T(w.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 T(w.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 Dm||Lf(e)||D(e)||e instanceof vm)return!0;if(O(e)){let t=e.expression.variable.value.toLowerCase();return Co.includes(t)}if(k(e)){let t=M(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function ey(e){let t=E(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.Example:e.length>1&&r.push(...e.map(e=>new T(w.DUPLICATE_RECORDS_SETTING,`'example' can only appear once`,e))),e.forEach(e=>{e.value&&r.push(new T(w.INVALID_RECORDS_SETTING_VALUE,`'example' cannot have a value`,e))});break;default:r.push(...e.map(e=>new T(w.UNKNOWN_RECORDS_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}var ty={validateNode(t,i){return A(i,r.Records)?n.create(void 0,new $v(t,i).validate()):n.create(e)},nodeFullname(i,a){if(A(a,r.Records)){if(a.name instanceof wm)return new n(void 0,[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof R){if(!(a.name instanceof Sm))return new n(void 0,[new T(w.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||!Df(a.name.callee))&&e.push(new T(w.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Bf(a.name.argumentList))&&e.push(new T(w.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=M(a.name.callee);return t?.length===1&&t.unshift(v),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Bf(a.name)?new n(e,[new T(w.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return j(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Records)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):j(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Records)?i.attributeList?ey(i.attributeList):new n({}):j(i,r.Records)?new n({}):n.create(e)}},ny=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 T(w.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:kf(e)?[]:[new T(w.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new T(w.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]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new T(w.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 T(w.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!$f(e.callee)&&t.push(new T(w.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&$f(e.callee)){let n=up(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=up(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new T(w.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new T(w.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!ep(e.callee)&&t.push(new T(w.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(h(n)instanceof W){let e=this.validateFieldSettings(h(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 T(w.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return iy(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function ry(e){if(!(O(e)&&e.expression.variable.kind!==_.QUOTED_STRING)&&!(e instanceof hm))return!1;let t;if(t=e instanceof hm?ap(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 iy(e){let t=E(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 T(w.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{ry(t.value)||r.push(new T(w.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 T(w.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Pf(e.value)||r.push(new T(w.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 T(w.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new T(w.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new T(w.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var ay={validateNode(t,i){return A(i,r.Ref)?n.create(void 0,new ny(t,i).validate()):n.create(e)},nodeFullname(t,i){return A(i,r.Ref)?i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):j(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return A(i,r.Ref)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(A(i,r.Ref))return i.attributeList?new n({},[new T(w.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(j(i,r.Ref)){let e=[...i.args],t;return h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),t?iy(t):new n({})}return n.create(e)}},oy=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 z?[new T(w.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Om?[new T(w.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Df(e)?[]:[new T(w.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new T(w.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Of(e)?[]:[new T(w.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){return sy(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=g(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 T(w.INVALID_COLUMN,`A column must have a type`,e.callee)),O(e.callee)||t.push(new T(w.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Vf(e.args[0])&&t.push(new T(w.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?(jf(e.callee)||t.push(new T(w.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 T(w.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof V&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){return cy(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 T(w.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function sy(e){let t=E(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new T(w.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{let t=O_[i.HeaderColor];t.isValidBuiltinFieldValue(e.value)||r.push(new T(w.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new T(w.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{let t=O_[i.Note];t.isValidBuiltinFieldValue(e.value)||r.push(new T(w.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Dep:e.forEach(e=>{zf(e.value)||r.push(new T(w.INVALID_TABLE_SETTING_VALUE,"'dep' must be `-> target` or `<- source`",e.value||e.name))});break;default:r.push(...b_(t,e,{duplicate:w.DUPLICATE_TABLE_SETTING,invalidValue:w.INVALID_TABLE_SETTING_VALUE}))}}),new n(a,r)}function cy(e){if(!e.slice(0,-1).every(Wf)||!e.slice(-1).every(e=>Wf(e)||e instanceof W))return new n({},e.map(e=>new T(w.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;h(e)instanceof W&&(t=e.pop());let r=E(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(P(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new T(w.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{let t=k_[i.Note];t.isValidBuiltinFieldValue(e.value)||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Rf(e.value)||a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.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 T(w.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 T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{If(e.value)||a.push(new T(w.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 vm||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;case i.Dep:e.forEach(e=>{zf(e.value)||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'dep' must be a valid unary relationship`,e.value||e.name))});break;default:a.push(...b_(t,e,{duplicate:w.DUPLICATE_COLUMN_SETTING,invalidValue:w.INVALID_COLUMN_SETTING_VALUE}))}}),new n(o,a)}var ly={validateNode(t,i){return A(i,r.Table)?n.create(void 0,new oy(t,i).validate()):n.create(e)},nodeFullname(t,i){if(A(i,r.Table)){if(!i.name)return new n(void 0,[new T(w.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof Om)return new n(void 0,[new T(w.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=M(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(j(i,r.Table)){if(jf(i.callee)){let e=P(i.callee.expression);return new n(e?[e]:void 0)}let e=P(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return A(i,r.Table)?i.alias?Of(i.alias)?new n(P(i.alias)):new n(void 0,[new T(w.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):j(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.Table)?i.attributeList?sy(i.attributeList):new n({}):j(i,r.Table)?cy(i.args.slice(1)):n.create(e)}},uy=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 z?[new T(w.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:kf(e)?[]:[new T(w.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new T(w.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){return dy(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&M(e.callee)===void 0&&t.push(new T(w.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 T(w.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 T(w.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function dy(e){let t=E(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=J_[e];t.length>1&&r.push(...t.map(t=>new T(w.DUPLICATE_TABLE_SETTING,`'${e}' can only appear once`,t))),t.forEach(e=>{n.isValidBuiltinFieldValue(e.value)||r.push(new T(w.INVALID_TABLE_SETTING_VALUE,n.message,e.value||e.name))}),o[e]=t;break}default:r.push(...b_(e,t,{duplicate:w.DUPLICATE_TABLE_SETTING,invalidValue:w.INVALID_TABLE_SETTING_VALUE})),o[e]=t;break}return new n(o,r)}var fy={validateNode(t,i){return A(i,r.TableGroup)?n.create(void 0,new uy(t,i).validate()):n.create(e)},nodeFullname(t,i){if(A(i,r.TableGroup))return i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new T(w.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(j(i,r.TableGroup)){let e=M(i.callee);return e?.length===1&&e.unshift(v),new n(e)}return n.create(e)},nodeAlias(t,i){return A(i,r.TableGroup)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):j(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.TableGroup)?dy(i.attributeList):j(i,r.TableGroup)?new n({}):n.create(e)}},py=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 z?[new T(w.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof wm?[new T(w.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:kf(e)?[]:[new T(w.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new T(w.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new T(w.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=E(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new T(w.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Pf(e.value)||n.push(new T(w.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 T(w.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{D(e.value)||n.push(new T(w.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new T(w.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof H)return[new T(w.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=g(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 T(w.INVALID_COLUMN,`A column must have a type`,e.callee)),O(e.callee)||t.push(new T(w.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Vf(e.args[0])&&t.push(new T(w.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=h(e);if(!e.slice(0,-1).every(Wf)||!(Wf(t)||t instanceof W))return e.map(e=>new T(w.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;h(e)instanceof W&&(n=e.pop());let r=E(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(P(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{D(e.value)||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Rf(e.value)||a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.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 T(w.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 T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&a.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{If(e.value)||a.push(new T(w.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 vm||a.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...b_(t,e,{duplicate:w.DUPLICATE_COLUMN_SETTING,invalidValue:w.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 T(w.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function my(e){let t=E(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new T(w.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Pf(e.value)||r.push(new T(w.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 T(w.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{D(e.value)||r.push(new T(w.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new T(w.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function hy(e){let t=h(e);if(e.length>0&&(!e.slice(0,-1).every(Wf)||!(Wf(t)||t instanceof W)))return new n({},e.map(e=>new T(w.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;h(e)instanceof W&&(r=e.pop());let a=E(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(P(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{D(e.value)||o.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Rf(e.value)||o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&o.push(new T(w.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 T(w.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 T(w.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 T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof B&&e.value!==void 0&&o.push(new T(w.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 T(w.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{If(e.value)||o.push(new T(w.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 vm||o.push(new T(w.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:o.push(...b_(t,e,{duplicate:w.DUPLICATE_COLUMN_SETTING,invalidValue:w.INVALID_COLUMN_SETTING_VALUE}))}}),new n(s,o)}var gy={validateNode(t,i){return A(i,r.TablePartial)?n.create(void 0,new py(t,i).validate()):n.create(e)},nodeFullname(t,i){if(A(i,r.TablePartial))return i.name?kf(i.name)?new n(M(i.name)):new n(void 0,[new T(w.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new T(w.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(j(i,r.TablePartial)){let e=P(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return A(i,r.TablePartial)?i.alias?new n(void 0,[new T(w.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(P(i.alias)):j(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return A(i,r.TablePartial)?my(i.attributeList):j(i,r.TablePartial)?hy(i.args.slice(1)):n.create(e)}},_y=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof R?[]:[new T(w.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.specifiers instanceof wm)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 T(w.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Bp))||t.push(new T(w.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()]}},vy=[ly,Vv,ty,Uv,jv,ay,Lv,Qv,fy,gy,Gv,Jv,zv,Xv,{validateNode(t,r){return r instanceof fm?n.create(void 0,new _y(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!qf(r))return n.create(e);let i=M(r.name);return!i||i.length===0?n.create(void 0,[new T(w.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Bp.TableGroup)&&i.length>1?n.create(i,[new T(w.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Bp.TablePartial)&&i.length>1?n.create(i,[new T(w.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Bp.Note)&&i.length>1?n.create(i,[new T(w.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Bp.Schema)&&i.unshift(v),new n(i))},nodeAlias(t,r){return qf(r)?r.alias?Of(r.alias)?new n(P(r.alias)):new n(void 0,[new T(w.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 fm?n.create({}):n.create(e)}},Pv];function yy(t,...r){for(let n of vy){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function by(r){let i=yy(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function xy(r){let i=yy(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function Sy(r){let i=yy(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function Cy(r){let i=yy(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var wy=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Ty(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}),wy&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function Ey(e,t,...n){return Ty(t,n)}var Dy=!1,Oy=!1,ky=!1,Ay=!1,jy=void 0,My=typeof self==`object`?self:typeof global==`object`?global:{},Ny=void 0;My.vscode!==void 0&&My.vscode.process!==void 0?Ny=My.vscode.process:typeof process<`u`&&(Ny=process);var Py=typeof Ny?.versions?.electron==`string`&&Ny?.type===`renderer`;if(typeof navigator==`object`&&!Py)jy=navigator.userAgent,Dy=jy.indexOf(`Windows`)>=0,Oy=jy.indexOf(`Macintosh`)>=0,(jy.indexOf(`Macintosh`)>=0||jy.indexOf(`iPad`)>=0||jy.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,ky=jy.indexOf(`Linux`)>=0,jy?.indexOf(`Mobi`),Ay=!0,Ey({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof Ny==`object`){Dy=Ny.platform===`win32`,Oy=Ny.platform===`darwin`,ky=Ny.platform===`linux`,ky&&Ny.env.SNAP&&Ny.env.SNAP_REVISION,Ny.env.CI||Ny.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=Ny.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 Fy=Dy,Iy=Oy;Ay&&My.importScripts;var Ly=jy,Ry=typeof My.postMessage==`function`&&!My.importScripts;(()=>{if(Ry){let e=[];My.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}),My.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var zy=!!(Ly&&Ly.indexOf(`Chrome`)>=0);Ly&&Ly.indexOf(`Firefox`),!zy&&Ly&&Ly.indexOf(`Safari`),Ly&&Ly.indexOf(`Edg/`),Ly&&Ly.indexOf(`Android`);var By;if(My.vscode!==void 0&&My.vscode.process!==void 0){let e=My.vscode.process;By={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else By=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 Fy?`win32`:Iy?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var Vy=By.cwd,Hy=By.env,Uy=By.platform,Wy=65,Gy=97,Ky=90,qy=122,Jy=46,Yy=47,Xy=92,Zy=58,Qy=63,$y=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 eb(e,t){if(typeof e!=`object`||!e)throw new $y(t,`Object`,e)}function tb(e,t){if(typeof e!=`string`)throw new $y(t,`string`,e)}var nb=Uy===`win32`;function K(e){return e===Yy||e===Xy}function rb(e){return e===Yy}function ib(e){return e>=Wy&&e<=Ky||e>=Gy&&e<=qy}function ab(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=Yy;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==Jy||i.charCodeAt(i.length-2)!==Jy){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===Jy&&s!==-1?++s:s=-1}return i}function ob(e,t){eb(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 sb={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],tb(a,`path`),a.length===0)continue}else t.length===0?a=Vy():(a=Hy[`=${t}`]||Vy(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Xy)&&(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 ib(u)&&a.charCodeAt(1)===Zy&&(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=ab(n,!r,`\\`,K),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){tb(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return rb(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 ib(a)&&e.charCodeAt(1)===Zy&&(r=e.slice(0,2),n=2,t>2&&K(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?ab(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){tb(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return K(n)||t>2&&ib(n)&&e.charCodeAt(1)===Zy&&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];tb(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 sb.normalize(t)},relative(e,t){if(tb(e,`from`),tb(t,`to`),e===t)return``;let n=sb.resolve(e),r=sb.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Xy;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Xy;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Xy;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Xy;)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===Xy&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Xy)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Xy?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)===Xy)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Xy&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=sb.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Xy){if(t.charCodeAt(1)===Xy){let e=t.charCodeAt(2);if(e!==Qy&&e!==Jy)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(ib(t.charCodeAt(0))&&t.charCodeAt(1)===Zy&&t.charCodeAt(2)===Xy)return`\\\\?\\${t}`;return e},dirname(e){tb(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 ib(i)&&e.charCodeAt(1)===Zy&&(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&&tb(t,`ext`),tb(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&ib(e.charCodeAt(0))&&e.charCodeAt(1)===Zy&&(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){tb(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Zy&&ib(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===Jy?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:ob.bind(null,`\\`),parse(e){tb(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(ib(i)&&e.charCodeAt(1)===Zy){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===Jy?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},cb=(()=>{if(nb){let e=/\\/g;return()=>{let t=Vy().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Vy()})(),lb={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:cb();tb(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Yy)}return t=ab(t,!n,`/`,rb),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(tb(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Yy,n=e.charCodeAt(e.length-1)===Yy;return e=ab(e,!t,`/`,rb),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return tb(e,`path`),e.length>0&&e.charCodeAt(0)===Yy},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];tb(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:lb.normalize(t)},relative(e,t){if(tb(e,`from`),tb(t,`to`),e===t||(e=lb.resolve(e),t=lb.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===Yy&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===Yy)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Yy?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Yy)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(tb(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Yy,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Yy){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&&tb(t,`ext`),tb(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===Yy){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)===Yy){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){tb(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===Yy){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===Jy?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:ob.bind(null,`/`),parse(e){tb(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Yy,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===Yy){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===Jy?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};lb.win32=sb.win32=sb,lb.posix=sb.posix=lb,nb?sb.normalize:lb.normalize,nb?sb.resolve:lb.resolve,nb?sb.relative:lb.relative,nb?sb.dirname:lb.dirname,nb?sb.basename:lb.basename,nb?sb.extname:lb.extname,nb?sb.sep:lb.sep;var ub=/^\w[\w\d+.-]*$/,db=/^\//,fb=/^\/\//;function pb(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&&!ub.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!db.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(fb.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 mb(e,t){return!e&&!t?`file`:e}function hb(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==gb&&(t=gb+t):t=gb;break}return t}var q=``,gb=`/`,_b=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,vb=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=mb(e,a),this.authority=t||q,this.path=hb(this.scheme,n||q),this.query=r||q,this.fragment=i||q,pb(this,a))}get fsPath(){return wb(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 bb(t,n,r,i,a)}static parse(e,t=!1){let n=_b.exec(e);return n?new bb(n[2]||q,Ob(n[4]||q),Ob(n[5]||q),Ob(n[7]||q),Ob(n[9]||q),t):new bb(q,q,q,q,q)}static file(e){let t=q;if(Fy&&(e=e.replace(/\\/g,gb)),e[0]===gb&&e[1]===gb){let n=e.indexOf(gb,2);n===-1?(t=e.substring(2),e=gb):(t=e.substring(2,n),e=e.substring(n)||gb)}return new bb(`file`,t,e,q,q)}static from(e,t){return new bb(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=Fy&&t.scheme===`file`?e.file(sb.join(wb(t,!0),...n)).path:lb.join(t.path,...n),t.with({path:r})}toString(e=!1){return Tb(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new bb(t);return e._formatted=t.external??null,e._fsPath=t._sep===yb?t.fsPath??null:null,e}}},yb=Fy?1:void 0,bb=class extends vb{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=wb(this,!1),this._fsPath}toString(e=!1){return e?Tb(this,!0):(this._formatted||=Tb(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=yb),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}},xb={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 Sb(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=xb[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 Cb(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+=xb[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function wb(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,Fy&&(n=n.replace(/\//g,`\\`)),n}function Tb(e,t){let n=t?Cb:Sb,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=gb,r+=gb),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:Sb(c,!1,!1)),r}function Eb(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+Eb(e.substr(3)):e}}var Db=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function Ob(e){return e.match(Db)?e.replace(Db,e=>Eb(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}({}),kb=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 Ab(e,t){return e.getOffsetAt(t)}function jb(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 Mb=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=xo.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=jb(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=Fa(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=xo.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=vb.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]}}},Nb=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=xo.fromUri(String(e.uri)),a=Ab(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&&[dm.PRIMARY_EXPRESSION,dm.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=vb.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[]}},Pb=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`?kb.Error:e===`warning`?kb.Warning:kb.Info}},Fb=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=xo.fromUri(String(r)),a=Ab(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[dm.ELEMENT_DECLARATION,dm.FUNCTION_APPLICATION,dm.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=vb.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 Ib(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 mm)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=P(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?P(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof wm&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof wm)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function Lb(e,t,n,r,i,a){let o=Ib(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:Rb(Pa([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
12
12
  `),removeRange:zb(a,e.startOffset,e.endOffset)}}return{topInsert:Rb([l],s,`
13
13
  `)}}function Rb(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function zb(e,t,n){let r=e.lastIndexOf(`
14
14
  `,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]===`
15
15
  `&&i++,{startOffset:r,endOffset:i}}function Bb(e){switch(e){case I.Schema:return J.Module;case I.Table:case I.TablePartial:case I.Metadata:return J.Class;case I.Column:case I.TableGroupField:return J.Field;case I.Enum:return J.Enum;case I.EnumField:return J.EnumMember;case I.TableGroup:return J.Struct;default:return J.Text}}function Vb(e,t){if(!e||Ga(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===_.NEWLINE&&n.end<=t)return!1}return!0}function X(){return{suggestions:[]}}function Hb(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function Ub(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:R_(e.insertText??``),quoted:!0}))}}function Wb(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 Gb(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(Kb(e,c,t.kind,s,r,o)))}}return i}function Kb(e,t,n,r,i,a){let o=Lb(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=qb(a,o.removeRange.startOffset),t=qb(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:Bb(n),detail:`from ${r.basename}`,sortText:`zzz_${Bb(n).toString().padStart(2,`0`)}_${t}`,range:void 0,additionalTextEdits:s}}function qb(e,t){let n=1,r=1;for(let i=0;i<t&&i<e.length;i++)e[i]===`
16
- `?(n++,r=1):r++;return{line:n,column:r}}function Jb(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof z)||!o.isKind(r.Records)||!(o.body instanceof U)||!o.body||!jh(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof R?Yb(e,o):Xb(e,o)}function Yb(e,n){if(!(n.name instanceof Sm))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 Jp||r instanceof lm))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 Xb(e,n){let r=n.parent;if(!(r instanceof z))return X();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof qp))return X();let a;if(n.name instanceof ym){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 Jp||r instanceof lm))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 Zb(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof fm&&n>=o.start&&n<=o.fullEnd)return Qb(e,t,n,o,i,r);return null}function Qb(e,t,n,r,i,a){if(r.importPath&&jh(n,r.importPath))return rx(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return X();if(r.fromKeyword&&n>r.fromKeyword.end)return rx(e,t,void 0,i,r);if(r.specifiers instanceof mm){if(!r.specifiers.openBrace){let e=nx();return Vb(r.useKeyword,n)?Hb(e):e}return $b(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof wm)return X();let o=nx();return Vb(r.useKeyword,n)?Hb(o):o}function $b(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!==I.Schema)return tx(e,t,i,n)}return ex()}}return ex()}function ex(){return{suggestions:Object.keys(Bp).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function tx(e,n,r,i){if(!r)return X();let a=So(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 cm&&!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:Bb(i),range:void 0}))}}function nx(){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 rx(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=jb(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=Fa(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,-To.length)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=xo.resolve(a,d),p=e.layout.isDirectory(f);if(ax(e,n,ix(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 ix(e){let t=e.specifiers;return t instanceof mm?t.specifiers.flatMap(e=>{let t=P(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function ax(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`},ox=`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(`.`),sx=[i.HeaderColor,i.Note];sx.map(e=>`${e}: `);var cx=[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique],lx=[i.Ref,i.Dep,i.Default,i.Note,i.Check],ux=[...cx,...lx],dx=[...cx,...lx.map(e=>`${e}: `)],fx=[i.Unique,i.PK],px=[i.Note,i.Name,i.Type],mx=[...fx,...px],hx=[...fx,...px.map(e=>`${e}: `)],gx=[i.Inactive],_x=[i.Update,i.Delete,i.Color],vx=[...gx,..._x],yx=[...gx,..._x.map(e=>`${e}: `)],bx=[i.Note],xx=bx.map(e=>`${e}: `),Sx=[i.Name],Cx=Sx.map(e=>`${e}: `),wx=[`cascade`,`set default`,`set null`,`restrict`],Tx=[`btree`,`hash`],Ex=[Z.Note,Z.Indexes,Z.Checks,Z.Records],Dx=[Z.Table,Z.TableGroup,Z.Enum,Z.Note,Z.Ref,Z.Dep,Z.TablePartial],Ox=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=xo.fromUri(String(e.uri)),i=Ab(e,t),a=Jb(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=>Ja(e)&&jh(i,e)))return X();if(c===void 0)return Ux();let u=Zb(this.compiler,n,i,s,e);if(u!==null)return u;if([_.STRING_LITERAL,_.QUOTED_STRING].includes(s.kind)&&jh(i,s))return X();let d=this.compiler.container.element(n,i);if(this.compiler.container.scopeKind(n,i)===Q.TOPLEVEL||d instanceof z&&d.type&&d.type.start<=i&&d.type.end>=i)return Ux();let f=[...this.compiler.container.stack(n,i)].reverse();for(let e of f)if(e instanceof V)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return Ax(this.compiler,n,i,e);case`~`:return kx(this.compiler,n,i);default:}else if(e instanceof gm)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return Ax(this.compiler,n,i,e);case`.`:return Bx(this.compiler,n,i,e);default:}else if(e instanceof B)return Fx(this.compiler,n,i,e);else if(e instanceof W)return Fx(this.compiler,n,i,e);else if(e instanceof ym)return Nx(this.compiler,n,i,e);else if(e instanceof bm)return Px(this.compiler,n,i);else if(e instanceof Sm)return $x(this.compiler,n,i,e);else if(e instanceof H)return Vx(this.compiler,n,i,e);else if(e instanceof z){if(Mh(i,e))return A(e,r.Metadata)?Zx(this.compiler,n,i,e):Qx(this.compiler,n,i,e);if(e.bodyColon&&i>=e.bodyColon.end||e.body&&jh(i,e.body))return Vx(this.compiler,n,i,void 0)}return X()}};function kx(e,t,n){return Mx(e,t,n,e.parse.ast(t),[I.TablePartial])}function Ax(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.DEP,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=Mx(e,t,n,e.container.element(t,n),[I.Table,I.Schema,I.Column]);return Vb(r.op,n)?Hb(i):i}return X()}function jx(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?Ub({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof Wp&&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:Bb(e.kind),sortText:Bb(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):X()}function Mx(e,n,r,i,a){if(i===void 0)return X();let o=i,s={suggestions:[]},c;for(;o;){o instanceof R&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=jx(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 z?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 Gb(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 Ub(s)}function Nx(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 Sm&&t.argumentList===a)return $x(e,n,i,t);if(s instanceof z&&s.isKind(r.Records)&&!(s.name instanceof Sm)&&Mh(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=jx(e,i,[I.Column]);return sp(a)?Wb(t):t}}switch(o){case Q.INDEXES:return rS(e,n,i);case Q.REF:case Q.DEP:for(;c.length>0;){let t=c.pop();if(t instanceof gm&&t.op?.value===`.`)return Bx(e,n,i,t)}return qx(e,n,i);default:break}return X()}function Px(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?Mx(e,t,n,e.container.element(t,n),[I.Schema,I.Enum,I.EnumField]):X()}function Fx(e,t,n,r){let{token:i}=e.container.token(t,n);if([_.COMMA,_.LBRACKET].includes(i?.kind)){let r=Ix(e,t,n);return i?.kind===_.COMMA&&Vb(i,n)?Hb(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return Ix(e,t,n);if(r.name instanceof hm){let a=Rx(e,t,n,ap(r.name)??``);return i?.kind===_.COLON&&Vb(i,n)?Hb(a):a}return X()}function Ix(e,t,n){let r=e.container.element(t,n);if(r instanceof R)return X();let a=e.container.scopeKind(t,n);if(r.body&&!jh(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=sx;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:Lx(ux,dx)};case Q.ENUM:return{suggestions:Lx(bx,xx)};case Q.INDEXES:return{suggestions:Lx(mx,hx)};case Q.REF:return{suggestions:Lx(vx,yx)};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:Lx(Sx,Cx)};default:break}return X()}function Lx(e,t){return e.map((e,n)=>({label:e,insertText:t[n],kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))}function Rx(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:wx.map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:Tx.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:[wo].map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};break;case`default`:return Mx(e,t,n,e.container.element(t,n),[I.Schema,I.Enum]);default:break}return X()}function zx(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 z?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 Bx(e,n,r,i){let a=lp(i)??[];return a.pop(),a.some(e=>!O(e))?X():Ub({suggestions:zx(e,a.map(e=>P(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:Bb(e.kind),range:void 0}})})}function Vx(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return Gx(e,t,n,i);case Q.PROJECT:return Kx(e,t,n,i);case Q.INDEXES:return tS(e,t,n);case Q.ENUM:return Wx(e,t,n,i);case Q.REF:case Q.DEP:{let r=qx(e,t,n);return e.container.token(t,n).token?.kind===_.COLON&&Vb(e.container.token(t,n).token,n)?Hb(r):r}case Q.TABLEGROUP:return eS(e,t);case Q.DIAGRAMVIEW:return oS();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof z){let a=i.parentNode,o=a instanceof U?a.parentNode:void 0;if(o instanceof z&&o.isKind(r.DiagramView))return sS(e,t,n,i)}return X()}default:return X()}}var Hx=[Z.Table,Z.TableGroup,Z.Enum,Z.Project,Z.Ref,Z.Dep,Z.TablePartial,Z.Records,Z.DiagramView,Z.Note,Z.Metadata];function Ux(){return{suggestions:Hx.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function Wx(e,t,n,r){return r?.callee&&iS(n,r)===1?Mx(e,t,n,e.container.element(t,n),[I.Schema,I.Table,I.Column]):X()}function Gx(e,t,n,r){let i=Ex;if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))};let a=iS(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:a===1?nS(e,t,n):X()}function Kx(e,t,n,r){let i=Dx;return!r?.callee||iS(n,r)===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:X()}function qx(e,t,n){return Mx(e,t,n,e.container.element(t,n),[I.Schema,I.Table,I.Column])}var Jx={[Vp.Table]:[I.Schema,I.Table],[Vp.Column]:[I.Schema,I.Table,I.Column],[Vp.TableGroup]:[I.TableGroup],[Vp.Note]:[I.StickyNote]},Yx={[Vp.Table]:Z.Table,[Vp.Column]:Z.Column,[Vp.TableGroup]:Z.TableGroup,[Vp.Note]:Z.Note};function Xx(){return{suggestions:Object.values(Vp).map(e=>{let t=Yx[e];return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}})}}function Zx(e,t,n,r){let i=y_(r);if(!i||n<=r.targetKind.end&&n>=r.targetKind.start)return Xx();let a=Jx[i];return a?Mx(e,t,n,r.parent,a):X()}function Qx(e,t,n,i){return i.isKind(r.Records)?Mx(e,t,n,i.parent,[I.Schema,I.Table]):X()}function $x(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&jh(i,a.callee),c=a.argumentList&&jh(i,a.argumentList);if(o instanceof z&&o.isKind(r.Records)&&Mh(i,o)){if(s)return Mx(e,n,i,o.parent,[I.Schema,I.Table]);if(!c)return X();let r=a.callee;if(!r)return X();let l=lp(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return X();let f=jx(e,d,[I.Column]),{argumentList:p}=a;return!p||!sp(p)?f:Wb(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof H)||o.callee!==a||(P(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return X();let l=jx(e,s,[I.Column]),{argumentList:u}=a;return!u||!sp(u)?l:Wb(l)}return X()}function eS(e,t){return{suggestions:[...Ub({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==I.Table&&e.kind!==I.Schema)return[];let t=e.name;return t===void 0||e instanceof Wp&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:Bb(e.kind),range:void 0}})}).suggestions,...[Z.Note].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))]}}function tS(e,t,n){return rS(e,t,n)}function nS(e,t,n){return{suggestions:[...ox.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.TypeParameter,sortText:J.TypeParameter.toString().padStart(2,`0`),range:void 0})),...Mx(e,t,n,e.container.element(t,n),[I.Enum,I.Schema]).suggestions]}}function rS(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(I.Table))return X();let o=e.symbolMembers(a).getFiltered(t);return o?Ub({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:Bb(I.Column),range:void 0}:[]})}):X()}function iS(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 aS={label:`*`,insertText:`*`,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0};function oS(){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})),aS]}}function sS(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[aS,...Mx(e,t,n,e.parse.ast(t),[I.Table,I.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[aS,...Mx(e,t,n,e.parse.ast(t),[I.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[aS,{label:v,insertText:v,insertTextRules:Y.KeepWhitespace,kind:J.Module,range:void 0},...Mx(e,t,n,e.parse.ast(t),[I.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[aS,...Mx(e,t,n,e.parse.ast(t),[I.StickyNote]).suggestions]};default:return X()}}var cS={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*[}\]].*)$/}},lS={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 uS(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:va(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=Fm(s).find(e=>jh(o,e));if(e===void 0||e instanceof Ha)break;c.push(e),s=e}if(i?.kind===_.COLON)return c;for(;c.length>0;){let n=!1,r=h(c);if(r instanceof H){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
17
- `&&(c.pop(),n=!0)}else r instanceof V||r instanceof gm?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 ym?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof bm?r.end<=t&&(c.pop(),n=!0):r instanceof U?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof hm||r.end<t&&(c.pop(),n=!0);if(n){let e=h(c);e instanceof z&&e.end<=t&&c.pop()}if(!n)break}return c}function dS(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 fS(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof z)return n[e];return this.parse.ast(e)}function pS(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 mS(e,t){let n=this.container.element(e,t);if(n instanceof R)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 hS(e,t){let r=t.originalSymbol;if(r.filepath.equals(e))return n.create(_S(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=gS(this,e);if(i.length>0)return n.create({schema:i.join(`.`),name:t});let a=_S(this,r);return a?n.create({...a,name:t}):n.create({schema:v,name:t})}return n.create(_S(this,r))}function gS(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof Wp&&e.isKind(I.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function _S(e,n){if(!n.declaration)return n.name?{schema:v,name:n.name}:void 0;let r=e.nodeFullname(n.declaration).getFiltered(t);if(!r||r.length===0)return n.name?{schema:v,name:n.name}:void 0;let i=r[r.length-1];return{schema:r.length>1?r.slice(0,-1).join(`.`):v,name:i}}function vS(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof fm)||!i.importPath)continue;let t=So(e,i.importPath.value);!t||r.has(t.absolute)||(r.add(t.absolute),n.push(t))}return n}function yS(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 bS(e){return yS(this,e?[e]:this.layout.getEntrypoints())}function xS(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function SS(e){return this.interpretFile(e).getErrors()}function CS(e){return this.interpretFile(e).getWarnings()}function wS(e){return this.parseFile(e).getValue().tokens}function TS(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.interpretSymbol(r,e).getFiltered(t)}function ES(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.symbolMembers(r).getFiltered(t)}function DS(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function OS(e){return this.parseFile(e).getValue().tokens.filter(eo)}function kS(e,t){let n=this.parse.ast(e);for(;;){let e=Fm(n).find(e=>jh(t,e));if(e===void 0)return n;if(e instanceof Ha)return e;n=e}}function AS(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 jS(){let e=W_(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 MS(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 NS(){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 PS(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var FS=class{constructor(e,t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
16
+ `?(n++,r=1):r++;return{line:n,column:r}}function Jb(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof z)||!o.isKind(r.Records)||!(o.body instanceof U)||!o.body||!jh(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof R?Yb(e,o):Xb(e,o)}function Yb(e,n){if(!(n.name instanceof Sm))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 Jp||r instanceof lm))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 Xb(e,n){let r=n.parent;if(!(r instanceof z))return X();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof qp))return X();let a;if(n.name instanceof ym){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 Jp||r instanceof lm))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 Zb(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof fm&&n>=o.start&&n<=o.fullEnd)return Qb(e,t,n,o,i,r);return null}function Qb(e,t,n,r,i,a){if(r.importPath&&jh(n,r.importPath))return rx(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return X();if(r.fromKeyword&&n>r.fromKeyword.end)return rx(e,t,void 0,i,r);if(r.specifiers instanceof mm){if(!r.specifiers.openBrace){let e=nx();return Vb(r.useKeyword,n)?Hb(e):e}return $b(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof wm)return X();let o=nx();return Vb(r.useKeyword,n)?Hb(o):o}function $b(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!==I.Schema)return tx(e,t,i,n)}return ex()}}return ex()}function ex(){return{suggestions:Object.keys(Bp).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function tx(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 cm&&!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:Bb(i),range:void 0}))}}function nx(){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 rx(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=jb(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=Fa(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,-To.length)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=xo.resolve(a,d),p=e.layout.isDirectory(f);if(ax(e,n,ix(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 ix(e){let t=e.specifiers;return t instanceof mm?t.specifiers.flatMap(e=>{let t=P(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function ax(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`},ox=`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(`.`),sx=[i.HeaderColor,i.Note];sx.map(e=>`${e}: `);var cx=[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique],lx=[i.Ref,i.Dep,i.Default,i.Note,i.Check],ux=[...cx,...lx],dx=[...cx,...lx.map(e=>`${e}: `)],fx=[i.Unique,i.PK],px=[i.Note,i.Name,i.Type],mx=[...fx,...px],hx=[...fx,...px.map(e=>`${e}: `)],gx=[i.Inactive],_x=[i.Update,i.Delete,i.Color],vx=[...gx,..._x],yx=[...gx,..._x.map(e=>`${e}: `)],bx=[i.Note],xx=bx.map(e=>`${e}: `),Sx=[i.Name],Cx=Sx.map(e=>`${e}: `),wx=[`cascade`,`set default`,`set null`,`restrict`],Tx=[`btree`,`hash`],Ex=[Z.Note,Z.Indexes,Z.Checks,Z.Records],Dx=[Z.Table,Z.TableGroup,Z.Enum,Z.Note,Z.Ref,Z.Dep,Z.TablePartial],Ox=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=xo.fromUri(String(e.uri)),i=Ab(e,t),a=Jb(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=>Ja(e)&&jh(i,e)))return X();if(c===void 0)return Ux();let u=Zb(this.compiler,n,i,s,e);if(u!==null)return u;if([_.STRING_LITERAL,_.QUOTED_STRING].includes(s.kind)&&jh(i,s))return X();let d=this.compiler.container.element(n,i);if(this.compiler.container.scopeKind(n,i)===Q.TOPLEVEL||d instanceof z&&d.type&&d.type.start<=i&&d.type.end>=i)return Ux();let f=[...this.compiler.container.stack(n,i)].reverse();for(let e of f)if(e instanceof V)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return Ax(this.compiler,n,i,e);case`~`:return kx(this.compiler,n,i);default:}else if(e instanceof gm)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return Ax(this.compiler,n,i,e);case`.`:return Bx(this.compiler,n,i,e);default:}else if(e instanceof B)return Fx(this.compiler,n,i,e);else if(e instanceof W)return Fx(this.compiler,n,i,e);else if(e instanceof ym)return Nx(this.compiler,n,i,e);else if(e instanceof bm)return Px(this.compiler,n,i);else if(e instanceof Sm)return $x(this.compiler,n,i,e);else if(e instanceof H)return Vx(this.compiler,n,i,e);else if(e instanceof z){if(Mh(i,e))return A(e,r.Metadata)?Zx(this.compiler,n,i,e):Qx(this.compiler,n,i,e);if(e.bodyColon&&i>=e.bodyColon.end||e.body&&jh(i,e.body))return Vx(this.compiler,n,i,void 0)}return X()}};function kx(e,t,n){return Mx(e,t,n,e.parse.ast(t),[I.TablePartial])}function Ax(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.DEP,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=Mx(e,t,n,e.container.element(t,n),[I.Table,I.Schema,I.Column]);return Vb(r.op,n)?Hb(i):i}return X()}function jx(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?Ub({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof Wp&&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:Bb(e.kind),sortText:Bb(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):X()}function Mx(e,n,r,i,a){if(i===void 0)return X();let o=i,s={suggestions:[]},c;for(;o;){o instanceof R&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=jx(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 z?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 Gb(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 Ub(s)}function Nx(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 Sm&&t.argumentList===a)return $x(e,n,i,t);if(s instanceof z&&s.isKind(r.Records)&&!(s.name instanceof Sm)&&Mh(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=jx(e,i,[I.Column]);return sp(a)?Wb(t):t}}switch(o){case Q.INDEXES:return rS(e,n,i);case Q.REF:case Q.DEP:for(;c.length>0;){let t=c.pop();if(t instanceof gm&&t.op?.value===`.`)return Bx(e,n,i,t)}return qx(e,n,i);default:break}return X()}function Px(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?Mx(e,t,n,e.container.element(t,n),[I.Schema,I.Enum,I.EnumField]):X()}function Fx(e,t,n,r){let{token:i}=e.container.token(t,n);if([_.COMMA,_.LBRACKET].includes(i?.kind)){let r=Ix(e,t,n);return i?.kind===_.COMMA&&Vb(i,n)?Hb(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return Ix(e,t,n);if(r.name instanceof hm){let a=Rx(e,t,n,ap(r.name)??``);return i?.kind===_.COLON&&Vb(i,n)?Hb(a):a}return X()}function Ix(e,t,n){let r=e.container.element(t,n);if(r instanceof R)return X();let a=e.container.scopeKind(t,n);if(r.body&&!jh(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=sx;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:Lx(ux,dx)};case Q.ENUM:return{suggestions:Lx(bx,xx)};case Q.INDEXES:return{suggestions:Lx(mx,hx)};case Q.REF:return{suggestions:Lx(vx,yx)};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:Lx(Sx,Cx)};default:break}return X()}function Lx(e,t){return e.map((e,n)=>({label:e,insertText:t[n],kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))}function Rx(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:wx.map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:Tx.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:[wo].map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};break;case`default`:return Mx(e,t,n,e.container.element(t,n),[I.Schema,I.Enum]);default:break}return X()}function zx(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 z?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 Bx(e,n,r,i){let a=lp(i)??[];return a.pop(),a.some(e=>!O(e))?X():Ub({suggestions:zx(e,a.map(e=>P(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:Bb(e.kind),range:void 0}})})}function Vx(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return Gx(e,t,n,i);case Q.PROJECT:return Kx(e,t,n,i);case Q.INDEXES:return tS(e,t,n);case Q.ENUM:return Wx(e,t,n,i);case Q.REF:case Q.DEP:{let r=qx(e,t,n);return e.container.token(t,n).token?.kind===_.COLON&&Vb(e.container.token(t,n).token,n)?Hb(r):r}case Q.TABLEGROUP:return eS(e,t);case Q.DIAGRAMVIEW:return oS();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof z){let a=i.parentNode,o=a instanceof U?a.parentNode:void 0;if(o instanceof z&&o.isKind(r.DiagramView))return sS(e,t,n,i)}return X()}default:return X()}}var Hx=[Z.Table,Z.TableGroup,Z.Enum,Z.Project,Z.Ref,Z.Dep,Z.TablePartial,Z.Records,Z.DiagramView,Z.Note,Z.Metadata];function Ux(){return{suggestions:Hx.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function Wx(e,t,n,r){return r?.callee&&iS(n,r)===1?Mx(e,t,n,e.container.element(t,n),[I.Schema,I.Table,I.Column]):X()}function Gx(e,t,n,r){let i=Ex;if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))};let a=iS(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:a===1?nS(e,t,n):X()}function Kx(e,t,n,r){let i=Dx;return!r?.callee||iS(n,r)===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:X()}function qx(e,t,n){return Mx(e,t,n,e.container.element(t,n),[I.Schema,I.Table,I.Column])}var Jx={[Vp.Table]:[I.Schema,I.Table],[Vp.Column]:[I.Schema,I.Table,I.Column],[Vp.TableGroup]:[I.TableGroup],[Vp.Note]:[I.StickyNote]},Yx={[Vp.Table]:Z.Table,[Vp.Column]:Z.Column,[Vp.TableGroup]:Z.TableGroup,[Vp.Note]:Z.Note};function Xx(){return{suggestions:Object.values(Vp).map(e=>{let t=Yx[e];return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}})}}function Zx(e,t,n,r){let i=y_(r);if(!i||n<=r.targetKind.end&&n>=r.targetKind.start)return Xx();let a=Jx[i];return a?Mx(e,t,n,r.parent,a):X()}function Qx(e,t,n,i){return i.isKind(r.Records)?Mx(e,t,n,i.parent,[I.Schema,I.Table]):X()}function $x(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&jh(i,a.callee),c=a.argumentList&&jh(i,a.argumentList);if(o instanceof z&&o.isKind(r.Records)&&Mh(i,o)){if(s)return Mx(e,n,i,o.parent,[I.Schema,I.Table]);if(!c)return X();let r=a.callee;if(!r)return X();let l=lp(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return X();let f=jx(e,d,[I.Column]),{argumentList:p}=a;return!p||!sp(p)?f:Wb(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof H)||o.callee!==a||(P(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return X();let l=jx(e,s,[I.Column]),{argumentList:u}=a;return!u||!sp(u)?l:Wb(l)}return X()}function eS(e,t){return{suggestions:[...Ub({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==I.Table&&e.kind!==I.Schema)return[];let t=e.name;return t===void 0||e instanceof Wp&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:Bb(e.kind),range:void 0}})}).suggestions,...[Z.Note].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))]}}function tS(e,t,n){return rS(e,t,n)}function nS(e,t,n){return{suggestions:[...ox.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.TypeParameter,sortText:J.TypeParameter.toString().padStart(2,`0`),range:void 0})),...Mx(e,t,n,e.container.element(t,n),[I.Enum,I.Schema]).suggestions]}}function rS(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(I.Table))return X();let o=e.symbolMembers(a).getFiltered(t);return o?Ub({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:Bb(I.Column),range:void 0}:[]})}):X()}function iS(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 aS={label:`*`,insertText:`*`,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0};function oS(){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})),aS]}}function sS(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[aS,...Mx(e,t,n,e.parse.ast(t),[I.Table,I.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[aS,...Mx(e,t,n,e.parse.ast(t),[I.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[aS,{label:v,insertText:v,insertTextRules:Y.KeepWhitespace,kind:J.Module,range:void 0},...Mx(e,t,n,e.parse.ast(t),[I.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[aS,...Mx(e,t,n,e.parse.ast(t),[I.StickyNote]).suggestions]};default:return X()}}var cS={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*[}\]].*)$/}},lS={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 uS(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:va(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=Fm(s).find(e=>jh(o,e));if(e===void 0||e instanceof Ha)break;c.push(e),s=e}if(i?.kind===_.COLON)return c;for(;c.length>0;){let n=!1,r=h(c);if(r instanceof H){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
17
+ `&&(c.pop(),n=!0)}else r instanceof V||r instanceof gm?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 ym?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof bm?r.end<=t&&(c.pop(),n=!0):r instanceof U?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof hm||r.end<t&&(c.pop(),n=!0);if(n){let e=h(c);e instanceof z&&e.end<=t&&c.pop()}if(!n)break}return c}function dS(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 fS(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof z)return n[e];return this.parse.ast(e)}function pS(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 mS(e,t){let n=this.container.element(e,t);if(n instanceof R)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 hS(e,t){let r=t.originalSymbol;if(r.filepath.equals(e))return n.create(_S(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=gS(this,e);if(i.length>0)return n.create({schema:i.join(`.`),name:t});let a=_S(this,r);return a?n.create({...a,name:t}):n.create({schema:v,name:t})}return n.create(_S(this,r))}function gS(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof Wp&&e.isKind(I.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function _S(e,n){if(!n.declaration)return n.name?{schema:v,name:n.name}:void 0;let r=e.nodeFullname(n.declaration).getFiltered(t);if(!r||r.length===0)return n.name?{schema:v,name:n.name}:void 0;let i=r[r.length-1];return{schema:r.length>1?r.slice(0,-1).join(`.`):v,name:i}}function vS(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof fm)||!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 yS(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 bS(e){return yS(this,e?[e]:this.layout.getEntrypoints())}function xS(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function SS(e){return this.interpretFile(e).getErrors()}function CS(e){return this.interpretFile(e).getWarnings()}function wS(e){return this.parseFile(e).getValue().tokens}function TS(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.interpretSymbol(r,e).getFiltered(t)}function ES(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.symbolMembers(r).getFiltered(t)}function DS(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function OS(e){return this.parseFile(e).getValue().tokens.filter(eo)}function kS(e,t){let n=this.parse.ast(e);for(;;){let e=Fm(n).find(e=>jh(t,e));if(e===void 0)return n;if(e instanceof Ha)return e;n=e}}function AS(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 jS(){let e=W_(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 MS(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 NS(){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 PS(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var FS=class{constructor(e,t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
18
18
  `?(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 Ha.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(Ha.create(_.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new n(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(_.SPACE);break;case`\r`:break;case`
19
19
  `:this.addToken(_.NEWLINE);break;case` `:this.addToken(_.TAB);break;case`,`:this.addToken(_.COMMA);break;case`(`:this.addToken(_.LPAREN);break;case`)`:this.addToken(_.RPAREN);break;case`[`:this.addToken(_.LBRACKET);break;case`]`:this.addToken(_.RBRACKET);break;case`{`:this.addToken(_.LBRACE);break;case`}`:this.addToken(_.RBRACE);break;case`;`:this.addToken(_.SEMICOLON);break;case`:`:this.addToken(_.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(_.WILDCARD);break;default:if(Ba(e)){this.operator(e);break}if(Cf(e)){this.identifier();break}if(wf(e)){this.numericLiteralOrIdentifier();break}this.addToken(_.OP,!0),this.errors.push(new T(w.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(_.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)za(i)?(t.push(i),i.kind===_.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&&eo(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];eo(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(`
20
20
  `))&&!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 T(w.UNEXPECTED_EOF,`EOF reached while parsing`,t));return}if(this.check(`
@@ -39,4 +39,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(
39
39
  `&&a++,[{start:i,end:a,newText:``}]}function WC(e,t){let n=qC(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:K_(t)}}function GC(e){let t=qC(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function KC(e,t){if(qC(e)||!(e instanceof z))return;let n=JC(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${K_(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: ${K_(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${K_(t)}]`}}}function qC(e){if(!(e instanceof z))return;let t=e.body;if(t&&!(t instanceof H))for(let e of t.body){if(!(e instanceof z)||!e.isKind(r.Note))continue;let t=YC(e);if(t)return{kind:dm.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 XC(n)}function JC(e){let t=e.body;if(!(!t||t instanceof H)&&t.blockCloseBrace)return t.blockCloseBrace.start}function YC(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 XC(e){let t=E(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:dm.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function ZC(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...$C(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:oC(n,r,!0),edits:r}}function QC(e,t){return`Dep [color: ${t}] {\n ${vC(e.upstream)} -> ${vC(e.downstream)}\n}`}function $C(e,t,n,r){let i=pC(e,t,r.edge);switch(r.operation){case`create`:return tw(n,r,i);case`update`:return i?.kind===`block`?ew(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?ew({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function ew(e,t,n){let r=[];if(e.color!==void 0){let a=Dg(t,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=GC(t);e&&r.push(e)}else if(e.note!==void 0){let n=WC(t,e.note)??KC(t,e.note);n&&r.push(n)}return r}function tw(e,t,n){if(n?.kind===`block`)return ew(t,n.declaration,e);let r=QC(t.edge,t.color??``),i={start:e.length,end:e.length,newText:`
40
40
 
41
41
  `+r+`
42
- `};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var nw=Symbol(`COMPUTING`),rw=class{constructor(e){this.layout=e,this.nodeIdGenerator=new um,this.symbolIdGenerator=new Hp,this.symbolFactory=new to(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(XS),this.parseProject=this.globalQuery(ZS),this.validateNode=this.localQuery(by),this.validateFile=this.localQuery(PS),this.nodeFullname=this.localQuery(Sy),this.nodeAlias=this.localQuery(Cy),this.nodeSettings=this.localQuery(xy),this.canonicalName=this.globalQuery(hS),this.bindNode=this.globalQuery(Ev),this.bindFile=this.globalQuery(AS),this.bindProject=this.globalQuery(jS),this.interpretSymbol=this.globalQuery(Ov),this.interpretMetadata=this.globalQuery(kv),this.interpretFile=this.globalQuery(MS),this.interpretProject=this.globalQuery(NS),this.nodeSymbol=this.globalQuery(Cv),this.nodeMetadata=this.globalQuery(Dv),this.symbolMembers=this.globalQuery(wv),this.symbolMembersLookupMap=this.globalQuery(QS),this.lookupMembers=this.globalQuery($S),this.nodeReferee=this.globalQuery(Tv),this.resolutionIndex=this.globalQuery(tC),this.symbolReferences=this.globalQuery(rC),this.symbolParent=this.globalQuery(nC),this.symbolMetadata=this.globalQuery(iC),this.symbolAliases=this.globalQuery(eC),this.symbolUses=this.globalQuery(aC),this.fileDependencies=this.localQuery(vS),this.reachableFiles=this.globalQuery(bS),this.usableMembers=this.globalQuery(l_),this.nodeAtPosition=this.localQuery(kS),this.renameTable=EC.bind(this),this.updateElementSetting=AC.bind(this),this.updateElementSettingEdit=kC.bind(this),this.syncDiagramView=zC.bind(this),this.syncDep=ZC.bind(this),this.token={invalidStream:this.localQuery(OS),flatStream:this.localQuery(DS)},this.parse={source:e=>this.getSource(e)||``,ast:(e=Do)=>xS.call(this,e),errors:(e=Do)=>SS.call(this,e),warnings:(e=Do)=>CS.call(this,e),tokens:(e=Do)=>wS.call(this,e),rawDb:(e=Do)=>TS.call(this,e),publicSymbolTable:(e=Do)=>ES.call(this,e)},this.container={stack:this.localQuery(uS),token:this.localQuery(dS),element:this.localQuery(fS),scope:this.localQuery(pS),scopeKind:this.localQuery(mS)}}getSource(e){return this.layout.getSource(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 yS(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?fh(n[0]):n.map(e=>fh(e)).join(`\0`),a=r.get(i);if(a){if(a===nw)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,nw);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 L?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?fh(n[0]):n.map(e=>fh(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===nw)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,nw);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 Nb(this),referenceProvider:new Fb(this),autocompletionProvider:new Ox(this,{triggerCharacters:t}),diagnosticsProvider:new Pb(this),codeActionProvider:new Mb(this)}}},iw=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(xo.from)}getEntrypoints(){return[...this.files.keys()].map(xo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=Om,exports.AttributeNode=B,exports.BlockExpressionNode=U,exports.CARDINALITY_MANY=sf,exports.CARDINALITY_MAYBE=af,exports.CARDINALITY_ONE=rf,exports.CARDINALITY_SOME=of,exports.CallExpressionNode=Sm,exports.CommaExpressionNode=bm,exports.CompileError=T,exports.CompileErrorCode=w,exports.Compiler=rw,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=Mb,exports.DBMLCompletionItemProvider=Ox,exports.DBMLDefinitionProvider=Nb,exports.DBMLDiagnosticsProvider=Pb,exports.DBMLReferencesProvider=Fb,exports.DEFAULT_ENTRY=Do,exports.ElementDeclarationNode=z,exports.ElementKind=r,exports.EmptyNode=Dm,exports.FALSY_VALUES=Cp,exports.Filepath=xo,exports.FunctionApplicationNode=H,exports.FunctionExpressionNode=vm,exports.GroupExpressionNode=xm,exports.IdentifierStreamNode=hm,exports.InfixExpressionNode=gm,exports.ListExpressionNode=W,exports.LiteralNode=Cm,exports.MarkerSeverity=kb,exports.MemoryProjectLayout=iw,exports.MetadataKind=Um,exports.PostfixExpressionNode=_m,exports.PrefixExpressionNode=V,exports.PrimaryExpressionNode=Em,exports.ProgramNode=R,exports.ScopeKind=Q,exports.SymbolKind=I,exports.SyntaxNode=L,exports.SyntaxNodeIdGenerator=um,exports.SyntaxNodeKind=dm,exports.SyntaxToken=Ha,exports.SyntaxTokenKind=_,exports.TRUTHY_VALUES=Sp,exports.TupleExpressionNode=ym,exports.UNHANDLED=t,exports.Uri=vb,exports.UseDeclarationNode=fm,exports.UseSpecifierListNode=mm,exports.UseSpecifierNode=pm,exports.VariableNode=Tm,exports.WildcardNode=wm,exports.addDoubleQuoteIfNeeded=R_,exports.dbmlLanguageConfig=cS,exports.dbmlMonarchTokensProvider=lS,exports.escapeString=V_,exports.extractNumericLiteral=fp,exports.extractSignedNumber=yp,exports.findDiagramViewBlocks=PC,exports.formatRecordValue=H_,exports.getMultiplicities=uf,exports.getRecordValueType=Wo,exports.getRelationshipOp=gf,exports.isBinaryType=Vo,exports.isBooleanType=zo,exports.isDateTimeType=Ho,exports.isEmptyStringLiteral=_p,exports.isEndpointManySide=ff,exports.isEndpointOneSide=df,exports.isEndpointOptional=pf,exports.isEndpointRequired=mf,exports.isFloatType=Lo,exports.isFunctionExpression=vp,exports.isIntegerType=Io,exports.isNullish=gp,exports.isNumericType=Ro,exports.isOp=Ba,exports.isOpToken=Va,exports.isSerialType=Uo,exports.isStringType=Bo,exports.isTriviaToken=za,exports.isValidIdentifier=L_,exports.makeCardinalityOptional=_f,exports.makeCardinalityRequired=vf,exports.makeRelationshipRequired=hf,exports.normalizeQualifiedName=z_,exports.normalizeTypeName=Fo,exports.parseCardinality=nf,exports.splitQualifiedIdentifier=U_,exports.tryExtractBoolean=wp,exports.tryExtractDateTime=Ap,exports.tryExtractEnum=Tp,exports.tryExtractInteger=xp,exports.tryExtractNumeric=bp,exports.tryExtractString=Ep,exports.unescapeString=B_,exports.validateForeignKeys=bg,exports.validatePrimaryKey=ug,exports.validateUnique=gg;
42
+ `};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var nw=Symbol(`COMPUTING`),rw=class{constructor(e){this.layout=e,this.nodeIdGenerator=new um,this.symbolIdGenerator=new Hp,this.symbolFactory=new to(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(XS),this.parseProject=this.globalQuery(ZS),this.validateNode=this.localQuery(by),this.validateFile=this.localQuery(PS),this.nodeFullname=this.localQuery(Sy),this.nodeAlias=this.localQuery(Cy),this.nodeSettings=this.localQuery(xy),this.canonicalName=this.globalQuery(hS),this.bindNode=this.globalQuery(Ev),this.bindFile=this.globalQuery(AS),this.bindProject=this.globalQuery(jS),this.interpretSymbol=this.globalQuery(Ov),this.interpretMetadata=this.globalQuery(kv),this.interpretFile=this.globalQuery(MS),this.interpretProject=this.globalQuery(NS),this.nodeSymbol=this.globalQuery(Cv),this.nodeMetadata=this.globalQuery(Dv),this.symbolMembers=this.globalQuery(wv),this.symbolMembersLookupMap=this.globalQuery(QS),this.lookupMembers=this.globalQuery($S),this.nodeReferee=this.globalQuery(Tv),this.resolutionIndex=this.globalQuery(tC),this.symbolReferences=this.globalQuery(rC),this.symbolParent=this.globalQuery(nC),this.symbolMetadata=this.globalQuery(iC),this.symbolAliases=this.globalQuery(eC),this.symbolUses=this.globalQuery(aC),this.fileDependencies=this.localQuery(vS),this.reachableFiles=this.globalQuery(bS),this.usableMembers=this.globalQuery(l_),this.nodeAtPosition=this.localQuery(kS),this.renameTable=EC.bind(this),this.updateElementSetting=AC.bind(this),this.updateElementSettingEdit=kC.bind(this),this.syncDiagramView=zC.bind(this),this.syncDep=ZC.bind(this),this.token={invalidStream:this.localQuery(OS),flatStream:this.localQuery(DS)},this.parse={source:e=>this.getSource(e)||``,ast:(e=Do)=>xS.call(this,e),errors:(e=Do)=>SS.call(this,e),warnings:(e=Do)=>CS.call(this,e),tokens:(e=Do)=>wS.call(this,e),rawDb:(e=Do)=>TS.call(this,e),publicSymbolTable:(e=Do)=>ES.call(this,e)},this.container={stack:this.localQuery(uS),token:this.localQuery(dS),element:this.localQuery(fS),scope:this.localQuery(pS),scopeKind:this.localQuery(mS)}}getSource(e){return this.layout.getSource(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 yS(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?fh(n[0]):n.map(e=>fh(e)).join(`\0`),a=r.get(i);if(a){if(a===nw)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,nw);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 L?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?fh(n[0]):n.map(e=>fh(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===nw)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,nw);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 Nb(this),referenceProvider:new Fb(this),autocompletionProvider:new Ox(this,{triggerCharacters:t}),diagnosticsProvider:new Pb(this),codeActionProvider:new Mb(this)}}},iw=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}resolveFileSpecifier(e,t){if(!xo.isRelative(t))return;let n=xo.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:xo.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(xo.from)}getEntrypoints(){return[...this.files.keys()].map(xo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=Om,exports.AttributeNode=B,exports.BlockExpressionNode=U,exports.CARDINALITY_MANY=sf,exports.CARDINALITY_MAYBE=af,exports.CARDINALITY_ONE=rf,exports.CARDINALITY_SOME=of,exports.CallExpressionNode=Sm,exports.CommaExpressionNode=bm,exports.CompileError=T,exports.CompileErrorCode=w,exports.Compiler=rw,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=Mb,exports.DBMLCompletionItemProvider=Ox,exports.DBMLDefinitionProvider=Nb,exports.DBMLDiagnosticsProvider=Pb,exports.DBMLReferencesProvider=Fb,exports.DEFAULT_ENTRY=Do,exports.ElementDeclarationNode=z,exports.ElementKind=r,exports.EmptyNode=Dm,exports.FALSY_VALUES=Cp,exports.Filepath=xo,exports.FunctionApplicationNode=H,exports.FunctionExpressionNode=vm,exports.GroupExpressionNode=xm,exports.IdentifierStreamNode=hm,exports.InfixExpressionNode=gm,exports.ListExpressionNode=W,exports.LiteralNode=Cm,exports.MarkerSeverity=kb,exports.MemoryProjectLayout=iw,exports.MetadataKind=Um,exports.PostfixExpressionNode=_m,exports.PrefixExpressionNode=V,exports.PrimaryExpressionNode=Em,exports.ProgramNode=R,exports.ScopeKind=Q,exports.SymbolKind=I,exports.SyntaxNode=L,exports.SyntaxNodeIdGenerator=um,exports.SyntaxNodeKind=dm,exports.SyntaxToken=Ha,exports.SyntaxTokenKind=_,exports.TRUTHY_VALUES=Sp,exports.TupleExpressionNode=ym,exports.UNHANDLED=t,exports.Uri=vb,exports.UseDeclarationNode=fm,exports.UseSpecifierListNode=mm,exports.UseSpecifierNode=pm,exports.VariableNode=Tm,exports.WildcardNode=wm,exports.addDoubleQuoteIfNeeded=R_,exports.dbmlLanguageConfig=cS,exports.dbmlMonarchTokensProvider=lS,exports.escapeString=V_,exports.extractNumericLiteral=fp,exports.extractSignedNumber=yp,exports.findDiagramViewBlocks=PC,exports.formatRecordValue=H_,exports.getMultiplicities=uf,exports.getRecordValueType=Wo,exports.getRelationshipOp=gf,exports.isBinaryType=Vo,exports.isBooleanType=zo,exports.isDateTimeType=Ho,exports.isEmptyStringLiteral=_p,exports.isEndpointManySide=ff,exports.isEndpointOneSide=df,exports.isEndpointOptional=pf,exports.isEndpointRequired=mf,exports.isFloatType=Lo,exports.isFunctionExpression=vp,exports.isIntegerType=Io,exports.isNullish=gp,exports.isNumericType=Ro,exports.isOp=Ba,exports.isOpToken=Va,exports.isSerialType=Uo,exports.isStringType=Bo,exports.isTriviaToken=za,exports.isValidIdentifier=L_,exports.makeCardinalityOptional=_f,exports.makeCardinalityRequired=vf,exports.makeRelationshipRequired=hf,exports.normalizeQualifiedName=z_,exports.normalizeTypeName=Fo,exports.parseCardinality=nf,exports.splitQualifiedIdentifier=U_,exports.tryExtractBoolean=wp,exports.tryExtractDateTime=Ap,exports.tryExtractEnum=Tp,exports.tryExtractInteger=xp,exports.tryExtractNumeric=bp,exports.tryExtractString=Ep,exports.unescapeString=B_,exports.validateForeignKeys=bg,exports.validatePrimaryKey=ug,exports.validateUnique=gg;