@dbml/parse 8.3.0-alpha.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__benchmarks__/compiler.benchmark.d.ts +1 -0
- package/dist/__benchmarks__/compiler.profile.d.ts +1 -0
- package/dist/dbml-parse.js +19 -19
- package/dist/dbml-parse.mjs +10466 -10117
- package/dist/src/compiler/index.d.ts +2 -0
- package/dist/src/compiler/queries/symbol/lookupMembers.d.ts +1 -0
- package/dist/src/core/types/report.d.ts +3 -3
- package/package.json +8 -4
package/dist/dbml-parse.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=Symbol(`PASS_THROUGH`),t=Symbol(`UNHANDLED`);var n=class e{static create(t,n,r){return new e(t,n,r)}constructor(e,t,n){this.value=e,this.errors=t===void 0?[]:t,n?.length&&(this.warnings=n)}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings):this}hasValue(e){return this.value===e}getFiltered(...e){return e.includes(this.value)?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings||[]}chainFiltered(t,...n){if(n.includes(this.value))return new e(void 0,this.errors,this.warnings);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()];return new e(r.value,i,a)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()];return new e(n.value,r,i)}mapFiltered(t,...n){return n.includes(this.value)?new e(void 0,this.errors,this.warnings):new e(t(this.value),this.errors,this.warnings)}map(t){return new e(t(this.value),this.errors,this.warnings)}};let r=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e}({}),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.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}({});var a=typeof global==`object`&&global&&global.Object===Object&&global,o=a,s=typeof self==`object`&&self&&self.Object===Object&&self,c=o||s||Function(`return this`)(),l=c,u=l.Symbol,d=u,f=Object.prototype,p=f.hasOwnProperty,m=f.toString,ee=d?d.toStringTag:void 0;function te(e){var t=p.call(e,ee),n=e[ee];try{e[ee]=void 0;var r=!0}catch{}var i=m.call(e);return r&&(t?e[ee]=n:delete e[ee]),i}var ne=te,re=Object.prototype.toString;function ie(e){return re.call(e)}var ae=ie,oe=`[object Null]`,se=`[object Undefined]`,ce=d?d.toStringTag:void 0;function le(e){return e==null?e===void 0?se:oe:ce&&ce in Object(e)?ne(e):ae(e)}var ue=le;function de(e){return typeof e==`object`&&!!e}var fe=de,pe=`[object Symbol]`;function me(e){return typeof e==`symbol`||fe(e)&&ue(e)==pe}var he=me;function ge(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 _e=ge,ve=Array.isArray,ye=ve,be=1/0,xe=d?d.prototype:void 0,Se=xe?xe.toString:void 0;function Ce(e){if(typeof e==`string`)return e;if(ye(e))return _e(e,Ce)+``;if(he(e))return Se?Se.call(e):``;var t=e+``;return t==`0`&&1/e==-be?`-0`:t}var we=Ce,Te=/\s/;function Ee(e){for(var t=e.length;t--&&Te.test(e.charAt(t)););return t}var De=Ee,Oe=/^\s+/;function ke(e){return e&&e.slice(0,De(e)+1).replace(Oe,``)}var Ae=ke;function je(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var Me=je,Ne=NaN,Pe=/^[-+]0x[0-9a-f]+$/i,Fe=/^0b[01]+$/i,Ie=/^0o[0-7]+$/i,Le=parseInt;function Re(e){if(typeof e==`number`)return e;if(he(e))return Ne;if(Me(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=Me(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Ae(e);var n=Fe.test(e);return n||Ie.test(e)?Le(e.slice(2),n?2:8):Pe.test(e)?Ne:+e}var ze=Re,Be=1/0,Ve=17976931348623157e292;function He(e){return e?(e=ze(e),e===Be||e===-Be?(e<0?-1:1)*Ve:e===e?e:0):e===0?e:0}var Ue=He;function We(e){var t=Ue(e),n=t%1;return t===t?n?t-n:t:0}var Ge=We;function Ke(e){return e}var qe=Ke,Je=`[object AsyncFunction]`,Ye=`[object Function]`,Xe=`[object GeneratorFunction]`,Ze=`[object Proxy]`;function Qe(e){if(!Me(e))return!1;var t=ue(e);return t==Ye||t==Xe||t==Je||t==Ze}var $e=Qe,et=l[`__core-js_shared__`],tt=et,nt=function(){var e=/[^.]+$/.exec(tt&&tt.keys&&tt.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function rt(e){return!!nt&&nt in e}var it=rt,at=Function.prototype.toString;function ot(e){if(e!=null){try{return at.call(e)}catch{}try{return e+``}catch{}}return``}var st=ot,ct=/[\\^$.*+?()[\]{}|]/g,lt=/^\[object .+?Constructor\]$/,ut=Function.prototype,dt=Object.prototype,ft=ut.toString,pt=dt.hasOwnProperty,mt=RegExp(`^`+ft.call(pt).replace(ct,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function ht(e){return!Me(e)||it(e)?!1:($e(e)?mt:lt).test(st(e))}var gt=ht;function _t(e,t){return e?.[t]}var vt=_t;function yt(e,t){var n=vt(e,t);return gt(n)?n:void 0}var bt=yt,xt=bt(l,`WeakMap`),St=xt;function Ct(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var wt=Ct;function Tt(){}var Et=Tt,Dt=800,Ot=16,kt=Date.now;function At(e){var t=0,n=0;return function(){var r=kt(),i=Ot-(r-n);if(n=r,i>0){if(++t>=Dt)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var jt=At;function Mt(e){return function(){return e}}var Nt=Mt,Pt=function(){try{var e=bt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Ft=Pt,It=Ft?function(e,t){return Ft(e,`toString`,{configurable:!0,enumerable:!1,value:Nt(t),writable:!0})}:qe,Lt=It,Rt=jt(Lt),zt=Rt;function Bt(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1}var Vt=Bt;function Ht(e){return e!==e}var Ut=Ht;function Wt(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}var Gt=Wt;function Kt(e,t,n){return t===t?Gt(e,t,n):Vt(e,Ut,n)}var qt=Kt;function Jt(e,t){return!!(e!=null&&e.length)&&qt(e,t,0)>-1}var Yt=Jt,Xt=9007199254740991,Zt=/^(?:0|[1-9]\d*)$/;function Qt(e,t){var n=typeof e;return t??=Xt,!!t&&(n==`number`||n!=`symbol`&&Zt.test(e))&&e>-1&&e%1==0&&e<t}var $t=Qt;function en(e,t,n){t==`__proto__`&&Ft?Ft(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var tn=en;function nn(e,t){return e===t||e!==e&&t!==t}var rn=nn,an=Math.max;function on(e,t,n){return t=an(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=an(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),wt(e,this,s)}}var sn=on;function cn(e,t){return zt(sn(e,t,qe),e+``)}var ln=cn,un=9007199254740991;function dn(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=un}var fn=dn;function pn(e){return e!=null&&fn(e.length)&&!$e(e)}var mn=pn,hn=Object.prototype;function gn(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||hn)}var _n=gn;function vn(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var yn=vn,bn=`[object Arguments]`;function xn(e){return fe(e)&&ue(e)==bn}var Sn=xn,Cn=Object.prototype,wn=Cn.hasOwnProperty,Tn=Cn.propertyIsEnumerable,En=Sn(function(){return arguments}())?Sn:function(e){return fe(e)&&wn.call(e,`callee`)&&!Tn.call(e,`callee`)},Dn=En;function On(){return!1}var kn=On,An=typeof exports==`object`&&exports&&!exports.nodeType&&exports,jn=An&&typeof module==`object`&&module&&!module.nodeType&&module,Mn=jn&&jn.exports===An?l.Buffer:void 0,Nn=(Mn?Mn.isBuffer:void 0)||kn,Pn=Nn,Fn=`[object Arguments]`,In=`[object Array]`,Ln=`[object Boolean]`,Rn=`[object Date]`,zn=`[object Error]`,Bn=`[object Function]`,Vn=`[object Map]`,Hn=`[object Number]`,Un=`[object Object]`,Wn=`[object RegExp]`,Gn=`[object Set]`,Kn=`[object String]`,qn=`[object WeakMap]`,Jn=`[object ArrayBuffer]`,Yn=`[object DataView]`,Xn=`[object Float32Array]`,Zn=`[object Float64Array]`,Qn=`[object Int8Array]`,$n=`[object Int16Array]`,er=`[object Int32Array]`,tr=`[object Uint8Array]`,nr=`[object Uint8ClampedArray]`,rr=`[object Uint16Array]`,ir=`[object Uint32Array]`,ar={};ar[Xn]=ar[Zn]=ar[Qn]=ar[$n]=ar[er]=ar[tr]=ar[nr]=ar[rr]=ar[ir]=!0,ar[Fn]=ar[In]=ar[Jn]=ar[Ln]=ar[Yn]=ar[Rn]=ar[zn]=ar[Bn]=ar[Vn]=ar[Hn]=ar[Un]=ar[Wn]=ar[Gn]=ar[Kn]=ar[qn]=!1;function or(e){return fe(e)&&fn(e.length)&&!!ar[ue(e)]}var sr=or;function cr(e){return function(t){return e(t)}}var lr=cr,ur=typeof exports==`object`&&exports&&!exports.nodeType&&exports,dr=ur&&typeof module==`object`&&module&&!module.nodeType&&module,fr=dr&&dr.exports===ur&&o.process,pr=function(){try{return dr&&dr.require&&dr.require(`util`).types||fr&&fr.binding&&fr.binding(`util`)}catch{}}(),mr=pr,hr=mr&&mr.isTypedArray,gr=hr?lr(hr):sr,_r=gr,vr=Object.prototype.hasOwnProperty;function yr(e,t){var n=ye(e),r=!n&&Dn(e),i=!n&&!r&&Pn(e),a=!n&&!r&&!i&&_r(e),o=n||r||i||a,s=o?yn(e.length,String):[],c=s.length;for(var l in e)(t||vr.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||$t(l,c)))&&s.push(l);return s}var br=yr;function xr(e,t){return function(n){return e(t(n))}}var Sr=xr,Cr=Sr(Object.keys,Object),wr=Cr,Tr=Object.prototype.hasOwnProperty;function Er(e){if(!_n(e))return wr(e);var t=[];for(var n in Object(e))Tr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var Dr=Er;function Or(e){return mn(e)?br(e):Dr(e)}var kr=Or;function Ar(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var jr=Ar,Mr=Object.prototype.hasOwnProperty;function Nr(e){if(!Me(e))return jr(e);var t=_n(e),n=[];for(var r in e)r==`constructor`&&(t||!Mr.call(e,r))||n.push(r);return n}var Pr=Nr;function Fr(e){return mn(e)?br(e,!0):Pr(e)}var Ir=Fr,Lr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Rr=/^\w*$/;function zr(e,t){if(ye(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||he(e)?!0:Rr.test(e)||!Lr.test(e)||t!=null&&e in Object(t)}var Br=zr,Vr=bt(Object,`create`),Hr=Vr;function Ur(){this.__data__=Hr?Hr(null):{},this.size=0}var Wr=Ur;function Gr(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Kr=Gr,qr=`__lodash_hash_undefined__`,Jr=Object.prototype.hasOwnProperty;function Yr(e){var t=this.__data__;if(Hr){var n=t[e];return n===qr?void 0:n}return Jr.call(t,e)?t[e]:void 0}var Xr=Yr,Zr=Object.prototype.hasOwnProperty;function Qr(e){var t=this.__data__;return Hr?t[e]!==void 0:Zr.call(t,e)}var $r=Qr,ei=`__lodash_hash_undefined__`;function ti(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Hr&&t===void 0?ei:t,this}var ni=ti;function ri(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ri.prototype.clear=Wr,ri.prototype.delete=Kr,ri.prototype.get=Xr,ri.prototype.has=$r,ri.prototype.set=ni;var ii=ri;function ai(){this.__data__=[],this.size=0}var oi=ai;function si(e,t){for(var n=e.length;n--;)if(rn(e[n][0],t))return n;return-1}var ci=si,li=Array.prototype.splice;function ui(e){var t=this.__data__,n=ci(t,e);return n<0?!1:(n==t.length-1?t.pop():li.call(t,n,1),--this.size,!0)}var di=ui;function fi(e){var t=this.__data__,n=ci(t,e);return n<0?void 0:t[n][1]}var pi=fi;function mi(e){return ci(this.__data__,e)>-1}var hi=mi;function gi(e,t){var n=this.__data__,r=ci(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var _i=gi;function vi(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])}}vi.prototype.clear=oi,vi.prototype.delete=di,vi.prototype.get=pi,vi.prototype.has=hi,vi.prototype.set=_i;var yi=vi,bi=bt(l,`Map`),xi=bi;function Si(){this.size=0,this.__data__={hash:new ii,map:new(xi||yi),string:new ii}}var Ci=Si;function wi(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var Ti=wi;function Ei(e,t){var n=e.__data__;return Ti(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var Di=Ei;function Oi(e){var t=Di(this,e).delete(e);return this.size-=t?1:0,t}var ki=Oi;function Ai(e){return Di(this,e).get(e)}var ji=Ai;function Mi(e){return Di(this,e).has(e)}var Ni=Mi;function Pi(e,t){var n=Di(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var Fi=Pi;function Ii(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Ii.prototype.clear=Ci,Ii.prototype.delete=ki,Ii.prototype.get=ji,Ii.prototype.has=Ni,Ii.prototype.set=Fi;var Li=Ii,Ri=`Expected a function`;function zi(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(Ri);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(zi.Cache||Li),n}zi.Cache=Li;var Bi=zi,Vi=500;function Hi(e){var t=Bi(e,function(e){return n.size===Vi&&n.clear(),e}),n=t.cache;return t}var Ui=Hi,Wi=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Gi=/\\(\\)?/g,Ki=Ui(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(Wi,function(e,n,r,i){t.push(r?i.replace(Gi,`$1`):n||e)}),t}),qi=Ki;function Ji(e){return e==null?``:we(e)}var Yi=Ji;function Xi(e,t){return ye(e)?e:Br(e,t)?[e]:qi(Yi(e))}var Zi=Xi,Qi=1/0;function $i(e){if(typeof e==`string`||he(e))return e;var t=e+``;return t==`0`&&1/e==-Qi?`-0`:t}var ea=$i;function ta(e,t){t=Zi(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[ea(t[n++])];return n&&n==r?e:void 0}var na=ta;function ra(e,t,n){var r=e==null?void 0:na(e,t);return r===void 0?n:r}var ia=ra;function aa(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var oa=aa,sa=d?d.isConcatSpreadable:void 0;function ca(e){return ye(e)||Dn(e)||!!(sa&&e&&e[sa])}var la=ca;function ua(e,t,n,r,i){var a=-1,o=e.length;for(n||=la,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?ua(s,t-1,n,r,i):oa(i,s):r||(i[i.length]=s)}return i}var da=ua;function fa(e){return e!=null&&e.length?da(e,1):[]}var pa=fa;function ma(){this.__data__=new yi,this.size=0}var ha=ma;function ga(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var _a=ga;function va(e){return this.__data__.get(e)}var ya=va;function ba(e){return this.__data__.has(e)}var xa=ba,Sa=200;function Ca(e,t){var n=this.__data__;if(n instanceof yi){var r=n.__data__;if(!xi||r.length<Sa-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Li(r)}return n.set(e,t),this.size=n.size,this}var wa=Ca;function Ta(e){this.size=(this.__data__=new yi(e)).size}Ta.prototype.clear=ha,Ta.prototype.delete=_a,Ta.prototype.get=ya,Ta.prototype.has=xa,Ta.prototype.set=wa;var Ea=Ta;function Da(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}var Oa=Da;function ka(){return[]}var Aa=ka,ja=Object.prototype.propertyIsEnumerable,Ma=Object.getOwnPropertySymbols,Na=Ma?function(e){return e==null?[]:(e=Object(e),Oa(Ma(e),function(t){return ja.call(e,t)}))}:Aa,Pa=Na;function Fa(e,t,n){var r=t(e);return ye(e)?r:oa(r,n(e))}var Ia=Fa;function La(e){return Ia(e,kr,Pa)}var Ra=La,za=bt(l,`DataView`),Ba=za,Va=bt(l,`Promise`),Ha=Va,Ua=bt(l,`Set`),Wa=Ua,Ga=`[object Map]`,Ka=`[object Object]`,qa=`[object Promise]`,Ja=`[object Set]`,Ya=`[object WeakMap]`,Xa=`[object DataView]`,Za=st(Ba),Qa=st(xi),$a=st(Ha),eo=st(Wa),to=st(St),no=ue;(Ba&&no(new Ba(new ArrayBuffer(1)))!=Xa||xi&&no(new xi)!=Ga||Ha&&no(Ha.resolve())!=qa||Wa&&no(new Wa)!=Ja||St&&no(new St)!=Ya)&&(no=function(e){var t=ue(e),n=t==Ka?e.constructor:void 0,r=n?st(n):``;if(r)switch(r){case Za:return Xa;case Qa:return Ga;case $a:return qa;case eo:return Ja;case to:return Ya}return t});var ro=no,io=l.Uint8Array,ao=io;function oo(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 so=oo,co=`__lodash_hash_undefined__`;function lo(e){return this.__data__.set(e,co),this}var uo=lo;function fo(e){return this.__data__.has(e)}var po=fo;function mo(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Li;++t<n;)this.add(e[t])}mo.prototype.add=mo.prototype.push=uo,mo.prototype.has=po;var ho=mo;function go(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}var _o=go;function vo(e,t){return e.has(t)}var yo=vo,bo=1,xo=2;function So(e,t,n,r,i,a){var o=n&bo,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,p=n&xo?new ho: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(!_o(t,function(e,t){if(!yo(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===ee||i(m,ee,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var Co=So;function wo(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var To=wo;function Eo(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var Do=Eo,Oo=1,ko=2,Ao=`[object Boolean]`,jo=`[object Date]`,Mo=`[object Error]`,No=`[object Map]`,Po=`[object Number]`,Fo=`[object RegExp]`,Io=`[object Set]`,Lo=`[object String]`,Ro=`[object Symbol]`,zo=`[object ArrayBuffer]`,Bo=`[object DataView]`,Vo=d?d.prototype:void 0,Ho=Vo?Vo.valueOf:void 0;function Uo(e,t,n,r,i,a,o){switch(n){case Bo:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case zo:return!(e.byteLength!=t.byteLength||!a(new ao(e),new ao(t)));case Ao:case jo:case Po:return rn(+e,+t);case Mo:return e.name==t.name&&e.message==t.message;case Fo:case Lo:return e==t+``;case No:var s=To;case Io:var c=r&Oo;if(s||=Do,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=ko,o.set(e,t);var u=Co(s(e),s(t),r,i,a,o);return o.delete(e),u;case Ro:if(Ho)return Ho.call(e)==Ho.call(t)}return!1}var Wo=Uo,Go=1,Ko=Object.prototype.hasOwnProperty;function qo(e,t,n,r,i,a){var o=n&Go,s=Ra(e),c=s.length;if(c!=Ra(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Ko.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 Jo=qo,Yo=1,Xo=`[object Arguments]`,Zo=`[object Array]`,Qo=`[object Object]`,$o=Object.prototype.hasOwnProperty;function es(e,t,n,r,i,a){var o=ye(e),s=ye(t),c=o?Zo:ro(e),l=s?Zo:ro(t);c=c==Xo?Qo:c,l=l==Xo?Qo:l;var u=c==Qo,d=l==Qo,f=c==l;if(f&&Pn(e)){if(!Pn(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Ea,o||_r(e)?Co(e,t,n,r,i,a):Wo(e,t,c,n,r,i,a);if(!(n&Yo)){var p=u&&$o.call(e,`__wrapped__`),m=d&&$o.call(t,`__wrapped__`);if(p||m){var ee=p?e.value():e,te=m?t.value():t;return a||=new Ea,i(ee,te,n,r,a)}}return f?(a||=new Ea,Jo(e,t,n,r,i,a)):!1}var ts=es;function ns(e,t,n,r,i){return e===t?!0:e==null||t==null||!fe(e)&&!fe(t)?e!==e&&t!==t:ts(e,t,n,r,ns,i)}var rs=ns,is=1,as=2;function os(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 Ea;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?rs(u,l,is|as,r,d):f))return!1}}return!0}var ss=os;function cs(e){return e===e&&!Me(e)}var ls=cs;function us(e){for(var t=kr(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,ls(i)]}return t}var ds=us;function fs(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var ps=fs;function ms(e){var t=ds(e);return t.length==1&&t[0][2]?ps(t[0][0],t[0][1]):function(n){return n===e||ss(n,e,t)}}var hs=ms;function gs(e,t){return e!=null&&t in Object(e)}var _s=gs;function vs(e,t,n){t=Zi(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=ea(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&&fn(i)&&$t(o,i)&&(ye(e)||Dn(e)))}var ys=vs;function bs(e,t){return e!=null&&ys(e,t,_s)}var xs=bs,Ss=1,Cs=2;function ws(e,t){return Br(e)&&ls(t)?ps(ea(e),t):function(n){var r=ia(n,e);return r===void 0&&r===t?xs(n,e):rs(t,r,Ss|Cs)}}var Ts=ws;function Es(e){return function(t){return t?.[e]}}var Ds=Es;function Os(e){return function(t){return na(t,e)}}var ks=Os;function As(e){return Br(e)?Ds(ea(e)):ks(e)}var js=As;function Ms(e){return typeof e==`function`?e:e==null?qe:typeof e==`object`?ye(e)?Ts(e[0],e[1]):hs(e):js(e)}var Ns=Ms;function Ps(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}var Fs=Ps;function Is(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 Ls=Is,Rs=Ls(),zs=Rs;function Bs(e,t){return e&&zs(e,t,kr)}var Vs=Bs;function Hs(e,t){return function(n,r){if(n==null)return n;if(!mn(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 Us=Hs,Ws=Us(Vs),Gs=Ws;function Ks(e,t,n,r){return Gs(e,function(e,i,a){t(r,e,n(e),a)}),r}var qs=Ks;function Js(e,t){return function(n,r){var i=ye(n)?Fs:qs,a=t?t():{};return i(n,e,Ns(r,2),a)}}var Ys=Js;function Xs(e){return fe(e)&&mn(e)}var Zs=Xs;function Qs(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 $s=Qs,ec=200;function tc(e,t,n,r){var i=-1,a=Yt,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=_e(t,lr(n))),r?(a=$s,o=!1):t.length>=ec&&(a=yo,o=!1,t=new ho(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 nc=tc,rc=ln(function(e,t){return Zs(e)?nc(e,da(t,1,Zs,!0)):[]}),ic=rc;function ac(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var h=ac;function oc(e){return typeof e==`function`?e:qe}var sc=oc;function cc(e,t){var n=[];return Gs(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}var lc=cc;function uc(e,t){return(ye(e)?Oa:lc)(e,Ns(t,3))}var dc=uc,fc=Math.max,pc=Math.min;function mc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Ge(n),i=n<0?fc(r+i,0):pc(i,r-1)),Vt(e,Ns(t,3),i,!0)}var hc=mc;function gc(e){return e&&e.length?e[0]:void 0}var _c=gc;function vc(e,t){var n=-1,r=mn(e)?Array(e.length):[];return Gs(e,function(e,i,a){r[++n]=t(e,i,a)}),r}var yc=vc;function bc(e,t){return(ye(e)?_e:yc)(e,Ns(t,3))}var xc=bc;function Sc(e,t){return da(xc(e,t),1)}var Cc=Sc;function wc(e,t){return e==null?e:zs(e,sc(t),Ir)}var Tc=wc,Ec=Object.prototype.hasOwnProperty,Dc=Ys(function(e,t,n){Ec.call(e,n)?e[n].push(t):tn(e,n,[t])}),Oc=Dc,kc=`[object Map]`,Ac=`[object Set]`,jc=Object.prototype.hasOwnProperty;function Mc(e){if(e==null)return!0;if(mn(e)&&(ye(e)||typeof e==`string`||typeof e.splice==`function`||Pn(e)||_r(e)||Dn(e)))return!e.length;var t=ro(e);if(t==kc||t==Ac)return!e.size;if(_n(e))return!Dr(e).length;for(var n in e)if(jc.call(e,n))return!1;return!0}var Nc=Mc,Pc=Ys(function(e,t,n){tn(e,n,t)}),Fc=Pc,Ic=Ys(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),g=Ic,Lc=Wa&&1/Do(new Wa([,-0]))[1]==1/0?function(e){return new Wa(e)}:Et,Rc=Lc,zc=200;function Bc(e,t,n){var r=-1,i=Yt,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=$s;else if(a>=zc){var l=t?null:Rc(e);if(l)return Do(l);o=!1,i=yo,c=new ho}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}var Vc=Bc;function Hc(e){return e&&e.length?Vc(e):[]}var Uc=Hc;function Wc(e,t){return e&&e.length?Vc(e,Ns(t,2)):[]}var Gc=Wc,Kc=Math.max;function qc(e){if(!(e&&e.length))return[];var t=0;return e=Oa(e,function(e){if(Zs(e))return t=Kc(e.length,t),!0}),yn(t,function(t){return _e(e,Ds(t))})}var Jc=qc,Yc=ln(Jc),Xc=Yc;let _=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 Zc(e){switch(e.kind){case _.NEWLINE:case _.SPACE:case _.TAB:case _.SINGLE_LINE_COMMENT:case _.MULTILINE_COMMENT:return!0;default:return!1}}function Qc(e){if(!e)return!1;switch(e){case`+`:case`-`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function $c(e){return e!==void 0&&e.kind===_.OP}var el=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 tl(e){return e.trailingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0}function nl(e,t){return t.leadingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0||tl(e)}function rl(e){return e.trailingTrivia.find(({kind:e})=>[_.SPACE,_.TAB].includes(e))!==void 0}function il(e){return e.trailingTrivia.length===0?e.end:il(h(e.trailingTrivia))}function al(e){return e.leadingTrivia.length===0?e.start:al(e.leadingTrivia[0])}function ol(e){return[_.SINGLE_LINE_COMMENT,_.MULTILINE_COMMENT].includes(e.kind)}function sl(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`as`}function cl(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`use`}function ll(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`from`}function ul(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function dl(e){return!!e?.isInvalid}var fl=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},pl=/^[A-Za-z]:\//;function ml(e=``){return e&&e.replace(/\\/g,`/`).replace(pl,e=>e.toUpperCase())}var hl=/^[/\\]{2}/,gl=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,_l=/^[A-Za-z]:$/,vl=/^\/([A-Za-z]:)?$/,yl=/.(\.[^./]+|\.)$/,bl=function(e){if(e.length===0)return`.`;e=ml(e);let t=e.match(hl),n=Tl(e),r=e[e.length-1]===`/`;return e=wl(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),_l.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!Tl(e)?`/${e}`:e)},xl=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 bl(t)};function Sl(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var Cl=function(...e){e=e.map(e=>ml(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:Sl();!i||i.length===0||(t=`${i}/${t}`,n=Tl(i))}return t=wl(t,!n),n&&!Tl(t)?`/${t}`:t.length>0?t:`.`};function wl(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 Tl=function(e){return gl.test(e)},El=function(e){if(e===`..`)return``;let t=yl.exec(ml(e));return t&&t[1]||``},Dl=function(e,t){let n=Cl(e).replace(vl,`$1`).split(`/`),r=Cl(t).replace(vl,`$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(`/`)},Ol=function(e){let t=ml(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&_l.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(Tl(e)?`/`:`.`)},kl=function(e,t){let n=ml(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},Al=/^[a-zA-Z]:\//,jl=class e{constructor(e,t={}){let n=bl(e);if(!Tl(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(Cl(t,n))}static fromUri(t){try{let n=new URL(t);return new e(bl(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(bl(t))}}get absolute(){return this.path}get dirname(){return Ol(this.path)}get basename(){return kl(this.path)}get extname(){return El(this.path)}resolve(t){return new e(Cl(this.dirname,t))}join(...t){return new e(xl(this.path,...t))}relativeTo(e){let t=Dl(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=Al.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!Tl(bl(e))}};function Ml(e,t){if(!jl.isRelative(t))return;let n=jl.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:jl.from(n.absolute+`.dbml`)}const Nl=[`null`,`true`,`false`],Pl=`none`,Fl=`.dbml`,Il=[`-`,`+`],v=`public`,Ll=jl.from(`/main.dbml`);let y=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.UNKNOWN_NOTE_SETTING=3047]=`UNKNOWN_NOTE_SETTING`,e[e.DUPLICATE_NOTE_SETTING=3048]=`DUPLICATE_NOTE_SETTING`,e[e.INVALID_NOTE_SETTING_VALUE=3049]=`INVALID_NOTE_SETTING_VALUE`,e[e.INVALID_INDEXES_CONTEXT=3050]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3051]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3052]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3053]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3054]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3055]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3056]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3057]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3058]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3059]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3060]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3061]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3062]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3063]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3064]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3065]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3066]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3067]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3068]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3069]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3070]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3071]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3072]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3073]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3074]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3075]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3076]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3077]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3078]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3079]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3080]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3081]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3082]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3083]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3084]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.INVALID_USE_CONTEXT=3085]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3086]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3087]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3088]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3089]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3090]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3091]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.UNEQUAL_FIELDS_BINARY_REF=5003]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5004]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e}({});var b=class e extends Error{constructor(t,n,r){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new Rl(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},Rl=class extends Error{constructor(e,t,n){super(t),this.code=e,this.diagnostic=t,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,b.prototype)}get filepath(){return this.nodeOrToken.filepath}};function zl(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Bl(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Vl(e){let[t]=e;return Bl(t)||zl(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Hl(e){return zl(e)||Bl(e)}function Ul(e){let t=D(e);return t!==void 0&&t.length>0}function Wl(e){return Gl(e)}function Gl(e){return e instanceof _d&&e.expression instanceof gd}function Kl(e){return!!e.bodyColon}function ql(e){return e instanceof L&&e.op?.value===`~`&&C(e.expression)}function Jl(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function Yl(e){if(!(e instanceof _d)||!(e.expression instanceof md)||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(!Vl(t[e]))return!1;return!0}function Xl(e){if(S(e)||Zl(e)||nu(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof L&&Il.includes(e.op?.value)&&Zl(e.expression)||e instanceof ud)return!0;if(!e||!ru(e))return!1;let t=xu(e);return t.length===2||t.length===3}function Zl(e){return e instanceof L?Il.includes(e.op.value)?Zl(e.expression):!1:e instanceof _d&&e.expression instanceof md&&e.expression.literal?.kind===_.NUMERIC_LITERAL}function Ql(e){if(!(e instanceof L)||!Jl(e.op?.value))return!1;let t=D(e.expression);return t!==void 0&&t.length>0}function $l(e){return e instanceof dd&&e.elementList.every(C)}function eu(e){if(!(e instanceof V||w(e)||e instanceof _d||e instanceof yd))return!1;for(;e instanceof V||e instanceof yd;)if(e instanceof V){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Zl(e)||S(e)||nu(e)))return!1;e=e.callee}else if(e instanceof yd){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Zl(e.name)))return!1;e=e.array}let t=D(e);return t!==void 0&&t.length>0}function x(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof _d){r.push(new b(y.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=_u(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 S(e){return e instanceof _d&&(e.expression instanceof gd&&e.expression.variable instanceof el&&e.expression.variable.kind===_.QUOTED_STRING||e.expression instanceof md&&e.expression.literal?.kind===_.STRING_LITERAL)}function C(e){return e instanceof _d&&e.expression instanceof gd&&e.expression.variable instanceof el}function tu(e){return e?e instanceof hd:!1}function nu(e){return e instanceof _d&&e.expression instanceof gd&&e.expression.variable?.kind===_.IDENTIFIER}function w(e){return e instanceof cd&&e.leftExpression instanceof M&&e.rightExpression instanceof M&&e.op?.value===`.`}function ru(e){return C(e)?!0:w(e)&&C(e.rightExpression)&&ru(e.leftExpression)}function T(e,t){return e instanceof F&&e.isKind(t)}function iu(e){return e instanceof id}function au(e,t){return e instanceof ad&&(t===void 0||e.isKind(t))}function ou(e){return e instanceof P}function E(e,...t){return e instanceof R&&e.parent instanceof F&&e.parent.isKind(...t)}function su(e,t){let n=e.parent;return n instanceof F&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function cu(e,t){let n=e.parentOfKind(R);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 lu(e){return!!e.parentOfKind(B)}function uu(e,t){let n=e.parentOfKind(I);return!n||(n.name instanceof _d?k(n.name):_u(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function du(e){return!(e instanceof cd)||!Jl(e.op?.value)?!1:Su(e.leftExpression)!==void 0&&Su(e.rightExpression)!==void 0}function fu(e){let t=Su(e.leftExpression),n=Su(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function pu(e){return e instanceof _d&&e.expression instanceof gd||e instanceof ud}function mu(e){if(C(e))return e;if(w(e)){let t=e.rightExpression;if(t&&C(t))return t}}function hu(e){let t=e.parentNode;return!w(t)||t.rightExpression!==e?!1:!(w(t.parentNode)&&t.parentNode.leftExpression===t)}function gu(e){if(C(e))return e.expression.variable}function _u(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function vu(e){if(!(e instanceof F))return;let t=D(e?.name);return t===void 0?void 0:t.join(`.`)}function yu(e){return e.elementList.length===0}function bu(e){return e?.body?e.body instanceof z?e.body.body:[e.body]:[]}function xu(e){if(!e)return;if(!w(e))return[e];let t=xu(e.leftExpression);if(t)return t.push(e.rightExpression),t}function D(e){if(e===void 0)return;let t=xu(e);if(!t)return;let n=[];for(let e of t){let t=k(e);if(typeof t!=`string`)return;n.push(t)}return n}function Su(e){if(e===void 0)return;let t=xu(e);if(!t||t.length===0)return;let n=[];if(!C(h(t))){let e=t.pop();if($l(e))n=e.elementList;else return}let r=t;if(r.every(C))return{variables:r,tupleElements:n}}function Cu(e){if(pu(e))return e instanceof ud?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof dd&&e.elementList.every(pu))return{functional:e.elementList.filter(e=>e instanceof ud),nonFunctional:e.elementList.filter(C)}}function O(e){if(S(e))return e.expression instanceof gd?e?.expression?.variable?.value:e.expression.literal.value}function wu(e){return e instanceof _d&&e.expression instanceof md&&e.expression.literal?.kind===_.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function Tu(e){if(!(e instanceof V)||!e.callee)return;let t=xu(e.callee);if(!t||t.length===0||!t.every(C))return;let n=[];return $l(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function k(e){if(C(e))return e.expression.variable.value}function Eu(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function Du(e){return e instanceof L?`${e.op?.value}${Du(e.expression)}`:e.expression.literal.value}function Ou(e){return e instanceof L?e.op?.value===`-`?-Ou(e.expression):Ou(e.expression):Number.parseFloat(e.expression.literal.value)}function A(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 ku(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){return new e(t,n,r)}constructor(e,t,n){this.value=e,this.errors=t===void 0?[]:t,n?.length&&(this.warnings=n)}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings):this}hasValue(e){return this.value===e}getFiltered(e){return this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings||[]}chainFiltered(t,n){if(this.value===n)return new e(void 0,this.errors,this.warnings);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()];return new e(r.value,i,a)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()];return new e(n.value,r,i)}mapFiltered(t,n){return this.value===n?new e(void 0,this.errors,this.warnings):new e(t(this.value),this.errors,this.warnings)}map(t){return new e(t(this.value),this.errors,this.warnings)}},r=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e}({}),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.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}({}),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)&<(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]`,h={};h[Zt]=h[Qt]=h[$t]=h[en]=h[tn]=h[nn]=h[rn]=h[an]=h[on]=!0,h[It]=h[Lt]=h[Yt]=h[Rt]=h[Xt]=h[zt]=h[Bt]=h[Vt]=h[Ht]=h[Ut]=h[Wt]=h[Gt]=h[Kt]=h[qt]=h[Jt]=!1;function sn(e){return ae(e)&&bt(e.length)&&!!h[ie(e)]}function cn(e){return function(t){return e(t)}}var ln=typeof exports==`object`&&exports&&!exports.nodeType&&exports,un=ln&&typeof module==`object`&&module&&!module.nodeType&&module,dn=un&&un.exports===ln&&a.process,fn=function(){try{return un&&un.require&&un.require(`util`).types||dn&&dn.binding&&dn.binding(`util`)}catch{}}(),pn=fn&&fn.isTypedArray,mn=pn?cn(pn):sn,hn=Object.prototype.hasOwnProperty;function gn(e,t){var n=le(e),r=!n&&At(e),i=!n&&!r&&Ft(e),a=!n&&!r&&!i&&mn(e),o=n||r||i||a,s=o?wt(e.length,String):[],c=s.length;for(var l in e)(t||hn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||pt(l,c)))&&s.push(l);return s}function _n(e,t){return function(n){return e(t(n))}}var vn=_n(Object.keys,Object),yn=Object.prototype.hasOwnProperty;function bn(e){if(!Ct(e))return vn(e);var t=[];for(var n in Object(e))yn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function xn(e){return xt(e)?gn(e):bn(e)}function Sn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Cn=Object.prototype.hasOwnProperty;function wn(e){if(!ve(e))return Sn(e);var t=Ct(e),n=[];for(var r in e)r==`constructor`&&(t||!Cn.call(e,r))||n.push(r);return n}function Tn(e){return xt(e)?gn(e,!0):wn(e)}var En=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Dn=/^\w*$/;function On(e,t){if(le(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||se(e)?!0:Dn.test(e)||!En.test(e)||t!=null&&e in Object(t)}var kn=Ye(Object,`create`);function An(){this.__data__=kn?kn(null):{},this.size=0}function jn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Mn=`__lodash_hash_undefined__`,Nn=Object.prototype.hasOwnProperty;function Pn(e){var t=this.__data__;if(kn){var n=t[e];return n===Mn?void 0:n}return Nn.call(t,e)?t[e]:void 0}var Fn=Object.prototype.hasOwnProperty;function In(e){var t=this.__data__;return kn?t[e]!==void 0:Fn.call(t,e)}var Ln=`__lodash_hash_undefined__`;function Rn(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=kn&&t===void 0?Ln:t,this}function zn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}zn.prototype.clear=An,zn.prototype.delete=jn,zn.prototype.get=Pn,zn.prototype.has=In,zn.prototype.set=Rn;function Bn(){this.__data__=[],this.size=0}function Vn(e,t){for(var n=e.length;n--;)if(ht(e[n][0],t))return n;return-1}var Hn=Array.prototype.splice;function Un(e){var t=this.__data__,n=Vn(t,e);return n<0?!1:(n==t.length-1?t.pop():Hn.call(t,n,1),--this.size,!0)}function Wn(e){var t=this.__data__,n=Vn(t,e);return n<0?void 0:t[n][1]}function Gn(e){return Vn(this.__data__,e)>-1}function Kn(e,t){var n=this.__data__,r=Vn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function qn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}qn.prototype.clear=Bn,qn.prototype.delete=Un,qn.prototype.get=Wn,qn.prototype.has=Gn,qn.prototype.set=Kn;var Jn=Ye(s,`Map`);function Yn(){this.size=0,this.__data__={hash:new zn,map:new(Jn||qn),string:new zn}}function Xn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Zn(e,t){var n=e.__data__;return Xn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function Qn(e){var t=Zn(this,e).delete(e);return this.size-=+!!t,t}function $n(e){return Zn(this,e).get(e)}function er(e){return Zn(this,e).has(e)}function tr(e,t){var n=Zn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function nr(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}nr.prototype.clear=Yn,nr.prototype.delete=Qn,nr.prototype.get=$n,nr.prototype.has=er,nr.prototype.set=tr;var rr=`Expected a function`;function ir(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(rr);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],a=n.cache;if(a.has(i))return a.get(i);var o=e.apply(this,r);return n.cache=a.set(i,o)||a,o};return n.cache=new(ir.Cache||nr),n}ir.Cache=nr;var ar=500;function or(e){var t=ir(e,function(e){return n.size===ar&&n.clear(),e}),n=t.cache;return t}var sr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,cr=/\\(\\)?/g,lr=or(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(sr,function(e,n,r,i){t.push(r?i.replace(cr,`$1`):n||e)}),t});function ur(e){return e==null?``:pe(e)}function dr(e,t){return le(e)?e:On(e,t)?[e]:lr(ur(e))}var fr=1/0;function pr(e){if(typeof e==`string`||se(e))return e;var t=e+``;return t==`0`&&1/e==-fr?`-0`:t}function mr(e,t){t=dr(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[pr(t[n++])];return n&&n==r?e:void 0}function hr(e,t,n){var r=e==null?void 0:mr(e,t);return r===void 0?n:r}function gr(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var _r=c?c.isConcatSpreadable:void 0;function vr(e){return le(e)||At(e)||!!(_r&&e&&e[_r])}function yr(e,t,n,r,i){var a=-1,o=e.length;for(n||=vr,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?yr(s,t-1,n,r,i):gr(i,s):r||(i[i.length]=s)}return i}function br(e){return e!=null&&e.length?yr(e,1):[]}function xr(){this.__data__=new qn,this.size=0}function Sr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Cr(e){return this.__data__.get(e)}function wr(e){return this.__data__.has(e)}var Tr=200;function Er(e,t){var n=this.__data__;if(n instanceof qn){var r=n.__data__;if(!Jn||r.length<Tr-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new nr(r)}return n.set(e,t),this.size=n.size,this}function Dr(e){var t=this.__data__=new qn(e);this.size=t.size}Dr.prototype.clear=xr,Dr.prototype.delete=Sr,Dr.prototype.get=Cr,Dr.prototype.has=wr,Dr.prototype.set=Er;function Or(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}function kr(){return[]}var Ar=Object.prototype.propertyIsEnumerable,jr=Object.getOwnPropertySymbols,Mr=jr?function(e){return e==null?[]:(e=Object(e),Or(jr(e),function(t){return Ar.call(e,t)}))}:kr;function Nr(e,t,n){var r=t(e);return le(e)?r:gr(r,n(e))}function Pr(e){return Nr(e,xn,Mr)}var Fr=Ye(s,`DataView`),Ir=Ye(s,`Promise`),Lr=Ye(s,`Set`),Rr=`[object Map]`,zr=`[object Object]`,Br=`[object Promise]`,Vr=`[object Set]`,Hr=`[object WeakMap]`,Ur=`[object DataView]`,Wr=ze(Fr),Gr=ze(Jn),Kr=ze(Ir),qr=ze(Lr),Jr=ze(Xe),Yr=ie;(Fr&&Yr(new Fr(new ArrayBuffer(1)))!=Ur||Jn&&Yr(new Jn)!=Rr||Ir&&Yr(Ir.resolve())!=Br||Lr&&Yr(new Lr)!=Vr||Xe&&Yr(new Xe)!=Hr)&&(Yr=function(e){var t=ie(e),n=t==zr?e.constructor:void 0,r=n?ze(n):``;if(r)switch(r){case Wr:return Ur;case Gr:return Rr;case Kr:return Br;case qr:return Vr;case Jr:return Hr}return t});var Xr=Yr,Zr=s.Uint8Array;function Qr(e){for(var t=-1,n=e==null?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i}var $r=`__lodash_hash_undefined__`;function ei(e){return this.__data__.set(e,$r),this}function ti(e){return this.__data__.has(e)}function ni(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new nr;++t<n;)this.add(e[t])}ni.prototype.add=ni.prototype.push=ei,ni.prototype.has=ti;function ri(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function ii(e,t){return e.has(t)}var ai=1,oi=2;function si(e,t,n,r,i,a){var o=n&ai,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,p=n&oi?new ni:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],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(!ri(t,function(e,t){if(!ii(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===ee||i(m,ee,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}function ci(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function li(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var ui=1,di=2,fi=`[object Boolean]`,pi=`[object Date]`,mi=`[object Error]`,hi=`[object Map]`,gi=`[object Number]`,_i=`[object RegExp]`,vi=`[object Set]`,yi=`[object String]`,bi=`[object Symbol]`,xi=`[object ArrayBuffer]`,Si=`[object DataView]`,Ci=c?c.prototype:void 0,wi=Ci?Ci.valueOf:void 0;function Ti(e,t,n,r,i,a,o){switch(n){case Si:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case xi:return!(e.byteLength!=t.byteLength||!a(new Zr(e),new Zr(t)));case fi:case pi:case gi:return ht(+e,+t);case mi:return e.name==t.name&&e.message==t.message;case _i:case yi:return e==t+``;case hi:var s=ci;case vi:var c=r&ui;if(s||=li,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=di,o.set(e,t);var u=si(s(e),s(t),r,i,a,o);return o.delete(e),u;case bi:if(wi)return wi.call(e)==wi.call(t)}return!1}var Ei=1,Di=Object.prototype.hasOwnProperty;function Oi(e,t,n,r,i,a){var o=n&Ei,s=Pr(e),c=s.length;if(c!=Pr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Di.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var 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 ki=1,Ai=`[object Arguments]`,ji=`[object Array]`,Mi=`[object Object]`,Ni=Object.prototype.hasOwnProperty;function Pi(e,t,n,r,i,a){var o=le(e),s=le(t),c=o?ji:Xr(e),l=s?ji:Xr(t);c=c==Ai?Mi:c,l=l==Ai?Mi:l;var u=c==Mi,d=l==Mi,f=c==l;if(f&&Ft(e)){if(!Ft(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Dr,o||mn(e)?si(e,t,n,r,i,a):Ti(e,t,c,n,r,i,a);if(!(n&ki)){var p=u&&Ni.call(e,`__wrapped__`),m=d&&Ni.call(t,`__wrapped__`);if(p||m){var ee=p?e.value():e,te=m?t.value():t;return a||=new Dr,i(ee,te,n,r,a)}}return f?(a||=new Dr,Oi(e,t,n,r,i,a)):!1}function Fi(e,t,n,r,i){return e===t?!0:e==null||t==null||!ae(e)&&!ae(t)?e!==e&&t!==t:Pi(e,t,n,r,Fi,i)}var Ii=1,Li=2;function Ri(e,t,n,r){var i=n.length,a=i,o=!r;if(e==null)return!a;for(e=Object(e);i--;){var s=n[i];if(o&&s[2]?s[1]!==e[s[0]]:!(s[0]in e))return!1}for(;++i<a;){s=n[i];var c=s[0],l=e[c],u=s[1];if(o&&s[2]){if(l===void 0&&!(c in e))return!1}else{var d=new Dr;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Fi(u,l,Ii|Li,r,d):f))return!1}}return!0}function zi(e){return e===e&&!ve(e)}function Bi(e){for(var t=xn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,zi(i)]}return t}function Vi(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function Hi(e){var t=Bi(e);return t.length==1&&t[0][2]?Vi(t[0][0],t[0][1]):function(n){return n===e||Ri(n,e,t)}}function Ui(e,t){return e!=null&&t in Object(e)}function Wi(e,t,n){t=dr(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=pr(t[r]);if(!(a=e!=null&&n(e,o)))break;e=e[o]}return a||++r!=i?a:(i=e==null?0:e.length,!!i&&bt(i)&&pt(o,i)&&(le(e)||At(e)))}function Gi(e,t){return e!=null&&Wi(e,t,Ui)}var Ki=1,qi=2;function Ji(e,t){return On(e)&&zi(t)?Vi(pr(e),t):function(n){var r=hr(n,e);return r===void 0&&r===t?Gi(n,e):Fi(t,r,Ki|qi)}}function Yi(e){return function(t){return t?.[e]}}function Xi(e){return function(t){return mr(t,e)}}function Zi(e){return On(e)?Yi(pr(e)):Xi(e)}function Qi(e){return typeof e==`function`?e:e==null?ke:typeof e==`object`?le(e)?Ji(e[0],e[1]):Hi(e):Zi(e)}function $i(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}function ea(e){return function(t,n,r){for(var i=-1,a=Object(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}var ta=ea();function na(e,t){return e&&ta(e,t,xn)}function ra(e,t){return function(n,r){if(n==null)return n;if(!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 ia=ra(na);function aa(e,t,n,r){return ia(e,function(e,i,a){t(r,e,n(e),a)}),r}function oa(e,t){return function(n,r){var i=le(n)?$i:aa,a=t?t():{};return i(n,e,Qi(r,2),a)}}function sa(e){return ae(e)&&xt(e)}function ca(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}var la=200;function ua(e,t,n,r){var i=-1,a=ut,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ce(t,cn(n))),r?(a=ca,o=!1):t.length>=la&&(a=ii,o=!1,t=new ni(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var da=vt(function(e,t){return sa(e)?ua(e,yr(t,1,sa,!0)):[]});function g(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function fa(e){return typeof e==`function`?e:ke}function pa(e,t){var n=[];return ia(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ma(e,t){return(le(e)?Or:pa)(e,Qi(t,3))}var ha=Math.max,ga=Math.min;function _a(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Oe(n),i=n<0?ha(r+i,0):ga(i,r-1)),ot(e,Qi(t,3),i,!0)}function va(e){return e&&e.length?e[0]:void 0}function ya(e,t){var n=-1,r=xt(e)?Array(e.length):[];return ia(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function ba(e,t){return(le(e)?ce:ya)(e,Qi(t,3))}function xa(e,t){return yr(ba(e,t),1)}function Sa(e,t){return e==null?e:ta(e,fa(t),Tn)}var Ca=Object.prototype.hasOwnProperty,wa=oa(function(e,t,n){Ca.call(e,n)?e[n].push(t):mt(e,n,[t])}),Ta=`[object Map]`,Ea=`[object Set]`,Da=Object.prototype.hasOwnProperty;function Oa(e){if(e==null)return!0;if(xt(e)&&(le(e)||typeof e==`string`||typeof e.splice==`function`||Ft(e)||mn(e)||At(e)))return!e.length;var t=Xr(e);if(t==Ta||t==Ea)return!e.size;if(Ct(e))return!bn(e).length;for(var n in e)if(Da.call(e,n))return!1;return!0}var ka=oa(function(e,t,n){mt(e,n,t)}),_=oa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),Aa=Lr&&1/li(new Lr([,-0]))[1]==1/0?function(e){return new Lr(e)}:Qe,ja=200;function Ma(e,t,n){var r=-1,i=ut,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=ca;else if(a>=ja){var l=t?null:Aa(e);if(l)return li(l);o=!1,i=ii,c=new ni}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}function Na(e){return e&&e.length?Ma(e):[]}function Pa(e,t){return e&&e.length?Ma(e,Qi(t,2)):[]}var Fa=Math.max;function Ia(e){if(!(e&&e.length))return[];var t=0;return e=Or(e,function(e){if(sa(e))return t=Fa(e.length,t),!0}),wt(t,function(t){return ce(e,Yi(t))})}var La=vt(Ia),v=function(e){return e.SPACE=`<space>`,e.TAB=`<tab>`,e.NEWLINE=`<newline>`,e.COMMA=`<comma>`,e.LPAREN=`<lparen>`,e.RPAREN=`<rparen>`,e.LBRACE=`<lbrace>`,e.RBRACE=`<rbrace>`,e.LBRACKET=`<lbracket>`,e.RBRACKET=`<rbracket>`,e.LANGLE=`<langle>`,e.RANGLE=`<rangle>`,e.OP=`<op>`,e.EOF=`<eof>`,e.NUMERIC_LITERAL=`<number>`,e.STRING_LITERAL=`<string>`,e.COLOR_LITERAL=`<color>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.QUOTED_STRING=`<variable>`,e.IDENTIFIER=`<identifier>`,e.SEMICOLON=`<semicolon>`,e.COLON=`<colon>`,e.SINGLE_LINE_COMMENT=`<single-line-comment>`,e.MULTILINE_COMMENT=`<multiline-comment>`,e.WILDCARD=`<wildcard>`,e}({});function Ra(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:return!0;default:return!1}}function za(e){if(!e)return!1;switch(e){case`+`:case`-`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function Ba(e){return e!==void 0&&e.kind===`<op>`}var Va=class e{constructor(e,t,n,r,i,a){this.kind=e,this.filepath=t,this.startPos=n,this.endPos=r,this.value=i,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=a,this.start=n.offset,this.end=r.offset}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}};function Ha(e){return e.trailingTrivia.find(({kind:e})=>e===v.NEWLINE)!==void 0}function Ua(e,t){return t.leadingTrivia.find(({kind:e})=>e===v.NEWLINE)!==void 0||Ha(e)}function Wa(e){return e.trailingTrivia.find(({kind:e})=>[v.SPACE,v.TAB].includes(e))!==void 0}function Ga(e){return e.trailingTrivia.length===0?e.end:Ga(g(e.trailingTrivia))}function Ka(e){return e.leadingTrivia.length===0?e.start:Ka(e.leadingTrivia[0])}function qa(e){return[v.SINGLE_LINE_COMMENT,v.MULTILINE_COMMENT].includes(e.kind)}function Ja(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`as`}function Ya(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`use`}function Xa(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`from`}function Za(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function Qa(e){return!!e?.isInvalid}var $a=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},eo=/^[A-Za-z]:\//;function to(e=``){return e&&e.replace(/\\/g,`/`).replace(eo,e=>e.toUpperCase())}var no=/^[/\\]{2}/,ro=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,io=/^[A-Za-z]:$/,ao=/^\/([A-Za-z]:)?$/,oo=/.(\.[^./]+|\.)$/,so=function(e){if(e.length===0)return`.`;e=to(e);let t=e.match(no),n=po(e),r=e[e.length-1]===`/`;return e=fo(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),io.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!po(e)?`/${e}`:e)},co=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 so(t)};function lo(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var uo=function(...e){e=e.map(e=>to(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:lo();!i||i.length===0||(t=`${i}/${t}`,n=po(i))}return t=fo(t,!n),n&&!po(t)?`/${t}`:t.length>0?t:`.`};function fo(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 po=function(e){return ro.test(e)},mo=function(e){if(e===`..`)return``;let t=oo.exec(to(e));return t&&t[1]||``},ho=function(e,t){let n=uo(e).replace(ao,`$1`).split(`/`),r=uo(t).replace(ao,`$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(`/`)},go=function(e){let t=to(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&io.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(po(e)?`/`:`.`)},_o=function(e,t){let n=to(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},vo=/^[a-zA-Z]:\//,yo=class e{constructor(e,t={}){let n=so(e);if(!po(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(uo(t,n))}static fromUri(t){try{let n=new URL(t);return new e(so(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(so(t))}}get absolute(){return this.path}get dirname(){return go(this.path)}get basename(){return _o(this.path)}get extname(){return mo(this.path)}resolve(t){return new e(uo(this.dirname,t))}join(...t){return new e(co(this.path,...t))}relativeTo(e){let t=ho(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=vo.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!po(so(e))}};function bo(e,t){if(!yo.isRelative(t))return;let n=yo.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:yo.from(n.absolute+`.dbml`)}var xo=[`null`,`true`,`false`],So=`none`,Co=`.dbml`,wo=[`-`,`+`],y=`public`,To=yo.from(`/main.dbml`),b=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.UNKNOWN_NOTE_SETTING=3047]=`UNKNOWN_NOTE_SETTING`,e[e.DUPLICATE_NOTE_SETTING=3048]=`DUPLICATE_NOTE_SETTING`,e[e.INVALID_NOTE_SETTING_VALUE=3049]=`INVALID_NOTE_SETTING_VALUE`,e[e.INVALID_INDEXES_CONTEXT=3050]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3051]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3052]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3053]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3054]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3055]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3056]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3057]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3058]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3059]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3060]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3061]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3062]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3063]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3064]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3065]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3066]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3067]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3068]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3069]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3070]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3071]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3072]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3073]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3074]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3075]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3076]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3077]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3078]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3079]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3080]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3081]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3082]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3083]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3084]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.INVALID_USE_CONTEXT=3085]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3086]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3087]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3088]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3089]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3090]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3091]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.UNEQUAL_FIELDS_BINARY_REF=5003]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5004]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e}({}),x=class e extends Error{constructor(t,n,r){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new Eo(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},Eo=class extends Error{constructor(e,t,n){super(t),this.code=e,this.diagnostic=t,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,x.prototype)}get filepath(){return this.nodeOrToken.filepath}};function Do(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Oo(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function ko(e){let[t]=e;return Oo(t)||Do(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Ao(e){return Do(e)||Oo(e)}function jo(e){let t=O(e);return t!==void 0&&t.length>0}function Mo(e){return No(e)}function No(e){return e instanceof sc&&e.expression instanceof oc}function Po(e){return!!e.bodyColon}function Fo(e){return e instanceof I&&e.op?.value===`~`&&w(e.expression)}function Io(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function Lo(e){if(!(e instanceof sc)||!(e.expression instanceof ic)||e.expression.literal?.kind!==v.COLOR_LITERAL)return!1;let t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!==`#`)return!1;for(let e=1;e<t.length;e+=1)if(!ko(t[e]))return!1;return!0}function Ro(e){if(C(e)||zo(e)||Wo(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof I&&wo.includes(e.op?.value)&&zo(e.expression)||e instanceof ec)return!0;if(!e||!Go(e))return!1;let t=ls(e);return t.length===2||t.length===3}function zo(e){return e instanceof I?wo.includes(e.op.value)?zo(e.expression):!1:e instanceof sc&&e.expression instanceof ic&&e.expression.literal?.kind===v.NUMERIC_LITERAL}function Bo(e){if(!(e instanceof I)||!Io(e.op?.value))return!1;let t=O(e.expression);return t!==void 0&&t.length>0}function Vo(e){return e instanceof tc&&e.elementList.every(w)}function Ho(e){if(!(e instanceof B||T(e)||e instanceof sc||e instanceof lc))return!1;for(;e instanceof B||e instanceof lc;)if(e instanceof B){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>zo(e)||C(e)||Wo(e)))return!1;e=e.callee}else if(e instanceof lc){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&zo(e.name)))return!1;e=e.array}let t=O(e);return t!==void 0&&t.length>0}function S(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof sc){r.push(new x(b.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=as(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 C(e){return e instanceof sc&&(e.expression instanceof oc&&e.expression.variable instanceof Va&&e.expression.variable.kind===v.QUOTED_STRING||e.expression instanceof ic&&e.expression.literal?.kind===v.STRING_LITERAL)}function w(e){return e instanceof sc&&e.expression instanceof oc&&e.expression.variable instanceof Va}function Uo(e){return e?e instanceof ac:!1}function Wo(e){return e instanceof sc&&e.expression instanceof oc&&e.expression.variable?.kind===v.IDENTIFIER}function T(e){return e instanceof Qs&&e.leftExpression instanceof N&&e.rightExpression instanceof N&&e.op?.value===`.`}function Go(e){return w(e)?!0:T(e)&&w(e.rightExpression)&&Go(e.leftExpression)}function E(e,t){return e instanceof P&&e.isKind(t)}function Ko(e){return e instanceof Js}function qo(e,t){return e instanceof Ys&&(t===void 0||e.isKind(t))}function Jo(e){return e instanceof qs}function D(e,...t){return e instanceof L&&e.parent instanceof P&&e.parent.isKind(...t)}function Yo(e,t){let n=e.parent;return n instanceof P&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Xo(e,t){let n=e.parentOfKind(L);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 Zo(e){return!!e.parentOfKind(z)}function Qo(e,t){let n=e.parentOfKind(F);return!n||(n.name instanceof sc?A(n.name):as(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function $o(e){return!(e instanceof Qs)||!Io(e.op?.value)?!1:us(e.leftExpression)!==void 0&&us(e.rightExpression)!==void 0}function es(e){let t=us(e.leftExpression),n=us(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function ts(e){return e instanceof sc&&e.expression instanceof oc||e instanceof ec}function ns(e){if(w(e))return e;if(T(e)){let t=e.rightExpression;if(t&&w(t))return t}}function rs(e){let t=e.parentNode;return!T(t)||t.rightExpression!==e?!1:!(T(t.parentNode)&&t.parentNode.leftExpression===t)}function is(e){if(w(e))return e.expression.variable}function as(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function os(e){if(!(e instanceof P))return;let t=O(e?.name);return t===void 0?void 0:t.join(`.`)}function ss(e){return e.elementList.length===0}function cs(e){return e?.body?e.body instanceof R?e.body.body:[e.body]:[]}function ls(e){if(!e)return;if(!T(e))return[e];let t=ls(e.leftExpression);if(t)return t.push(e.rightExpression),t}function O(e){if(e===void 0)return;let t=ls(e);if(!t)return;let n=[];for(let e of t){let t=A(e);if(typeof t!=`string`)return;n.push(t)}return n}function us(e){if(e===void 0)return;let t=ls(e);if(!t||t.length===0)return;let n=[];if(!w(g(t))){let e=t.pop();if(Vo(e))n=e.elementList;else return}let r=t;if(r.every(w))return{variables:r,tupleElements:n}}function ds(e){if(ts(e))return e instanceof ec?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof tc&&e.elementList.every(ts))return{functional:e.elementList.filter(e=>e instanceof ec),nonFunctional:e.elementList.filter(w)}}function k(e){if(C(e))return e.expression instanceof oc?e?.expression?.variable?.value:e.expression.literal.value}function fs(e){return e instanceof sc&&e.expression instanceof ic&&e.expression.literal?.kind===v.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function ps(e){if(!(e instanceof B)||!e.callee)return;let t=ls(e.callee);if(!t||t.length===0||!t.every(w))return;let n=[];return Vo(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function A(e){if(w(e))return e.expression.variable.value}function ms(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function hs(e){return e instanceof I?`${e.op?.value}${hs(e.expression)}`:e.expression.literal.value}function gs(e){return e instanceof I?e.op?.value===`-`?-gs(e.expression):gs(e.expression):Number.parseFloat(e.expression.literal.value)}function j(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 _s(e){let t=e.split(`
|
|
2
2
|
`),n=t.slice(t.findIndex(e=>e.trimStart()!==``)),r=n.filter(e=>e.trimStart());if(r.length===0)return n.join(`
|
|
3
3
|
`);let i=Math.min(...r.map(e=>e.length-e.trimStart().length));return n.map(e=>e.slice(i)).join(`
|
|
4
|
-
`)}function Au(e){let t=D(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function ju(e){if(e instanceof _d&&e.expression instanceof md&&e.expression.literal?.kind===_.COLOR_LITERAL)return e.expression.literal.value;if(nu(e)&&k(e)?.toLowerCase()===`none`)return Pl}function Mu(e){if(e){if(S(e)){let t=O(e);if(t!==void 0)return{value:t,type:`string`}}if(Zl(e))return{type:`number`,value:Ou(e)};if(nu(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof ud&&e.value)return{value:e.value.value,type:`expression`};if(ru(e)){let t=xu(e)?.at(-1),n=t?k(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function Nu(e,t){let r=``,i=null;if(t instanceof V){if(i=(t.argumentList?.elementList??[]).map(e=>Zl(e)?Du(e):S(e)?O(e):k(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof V||t instanceof yd;)if(t instanceof V){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Zl(e)?Du(e):S(e)?O(e):k(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof yd){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}=Au(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new b(y.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}let j=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.StickyNote=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewTopLevelWildcard=`DiagramView top-level wildcard`,e.DiagramViewTable=`DiagramView table`,e.DiagramViewTableGroup=`DiagramView tablegroup`,e.DiagramViewNote=`DiagramView note`,e.DiagramViewSchema=`DiagramView schema`,e.Program=`Program`,e}({});const Pu={Table:j.Table,Enum:j.Enum,TableGroup:j.TableGroup,TablePartial:j.TablePartial,Note:j.StickyNote,Schema:j.Schema};var Fu=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Iu=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 A(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()}},Lu=class e extends Iu{constructor({name:e,parent:t},n,r){super({kind:j.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}},Ru=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.Enum,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},zu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.EnumField,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=ku(O(i));if(a)return{value:a,token:A(r)}}},Bu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.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 nd))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(j.Column))}partialInjections(e){return this.members(e).filter(e=>e.isKind(j.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=ku(O(i));if(a)return{value:a,token:A(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?ju(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===xd.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===xd.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===xd.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===xd.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof R)||!ql(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===xd.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===xd.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=ju(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=ku(O(a));if(o)return{value:o,token:A(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Vu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.Column,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}pk(e){if(!this.declaration)return!1;let n=e.nodeSettings(this.declaration).getFiltered(t);return!!(n?.[i.PK]?.length||n?.[i.PrimaryKey]?.length)}unique(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Unique]?.length:!1}nullable(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(n?.[i.NotNull]?.length)return!1;if(n?.[i.Null]?.length)return!0}increment(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Increment]?.length:!1}default(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t)?.[i.Default]?.at(0)?.value;if(n)return Mu(n)}type(e){if(!(this.declaration instanceof R))return;let n=Nu(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 Ru?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===xd.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=ku(O(i));if(a)return{value:a,token:A(r)}}},Hu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.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(j.TableGroupField))}color(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.color?.length?ju(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=ku(O(i));if(a)return{value:a,token:A(r)}}},Uu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.TableGroupField,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Wu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.StickyNote,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Gu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.TablePartial,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Ku=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.PartialInjection,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},qu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.DiagramView,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Ju=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.DiagramViewTopLevelWildcard,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Yu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.DiagramViewTable,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Xu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.DiagramViewTableGroup,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Zu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.DiagramViewNote,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Qu=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.DiagramViewSchema,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},$u=class extends Iu{constructor({declaration:e,name:t},n,r){super({kind:j.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 Lu&&r.inNestedSchema(e,t))return!0;return!1}},ed=class extends Iu{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}},td=class extends Iu{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(id);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},nd=class extends Vu{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},rd=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},M=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 el?al(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 el?il(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 F||e instanceof P)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}};let N=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}({});var P=class extends M{constructor({body:e=[],eof:t,source:n},r,i){super(r,N.PROGRAM,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===N.ELEMENT_DECLARATION)}get uses(){return this.body.filter(e=>e.kind===N.USE_DECLARATION)}},id=class extends M{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,N.USE_DECLARATION,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return ul(this.useKeyword)}},ad=class extends M{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,N.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(j).find(t=>t.toLowerCase()===e)}},od=class extends M{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,N.USE_SPECIFIER_LIST,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},F=class e extends M{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,N.ELEMENT_DECLARATION,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof R||s instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.name=n,this.as=r,this.alias=i,this.attributeList=a,this.bodyColon=o,this.body=s}isKind(...e){return e.some(e=>this.type?.value.toLowerCase()===e)}getElementKind(){return Object.values(r).find(e=>this.isKind(e))}},sd=class extends M{constructor({identifiers:e=[]},t,n){super(t,N.IDENTIFIER_STREAM,n,e||[]),this.identifiers=e}},I=class extends M{constructor({name:e,colon:t,value:n},r,i){super(r,N.ATTRIBUTE,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},L=class extends M{constructor({op:e,expression:t},n,r){super(n,N.PREFIX_EXPRESSION,r,[e,t]),this.op=e,this.expression=t}},cd=class extends M{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,N.INFIX_EXPRESSION,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},ld=class extends M{constructor({op:e,expression:t},n,r){super(n,N.POSTFIX_EXPRESSION,r,[t,e]),this.op=e,this.expression=t}},ud=class extends M{constructor({value:e},t,n){super(t,N.FUNCTION_EXPRESSION,n,[e]),this.value=e}},R=class extends M{constructor({callee:e,args:t=[]},n,r){super(n,N.FUNCTION_APPLICATION,r,[e,...t]),this.callee=e,this.args=t}},z=class extends M{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,N.BLOCK_EXPRESSION,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},B=class extends M{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,N.LIST_EXPRESSION,a,[e,...bd(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},dd=class extends M{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,N.TUPLE_EXPRESSION,a,[e,...bd(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},fd=class extends M{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,N.COMMA_EXPRESSION,r,[...bd(e,t)]),this.elementList=e,this.commaList=t}},pd=class extends dd{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=N.GROUP_EXPRESSION}},V=class extends M{constructor({callee:e,argumentList:t},n,r){super(n,N.CALL_EXPRESSION,r,[e,t]),this.callee=e,this.argumentList=t}},md=class extends M{constructor({literal:e},t,n){super(t,N.LITERAL,n,[e]),this.literal=e}},hd=class extends M{constructor({token:e},t,n){super(t,N.WILDCARD,n,[e]),this.token=e}},gd=class extends M{constructor({variable:e},t,n){super(t,N.VARIABLE,n,[e]),this.variable=e}},_d=class extends M{constructor({expression:e},t,n){super(t,N.PRIMARY_EXPRESSION,n,[e]),this.expression=e}},vd=class extends M{constructor({prevToken:e},t,n){let r=el.create(_.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,N.EMPTY,n,[r])}},yd=class extends M{constructor({expression:e,indexer:t},n,r){super(n,N.ARRAY,r,[e,t]),this.array=e,this.indexer=t}};function bd(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?pa(Xc(e,t)):pa(Xc(t,e))).filter(e=>e!==null)}let xd=function(e){return e.Ref=`ref`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e}({});var Sd=class e{static#e=this.id=0;constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}},Cd=class extends Sd{constructor(e){super(e),this.kind=xd.Ref}container(e){let n=this.declaration.parentOfKind(F);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof F){let t=bu(this.declaration)[0];if(!(t instanceof R))return[];let n=t.callee;return n instanceof cd?kd(e,n.leftExpression):[]}if(this.declaration instanceof I){let n=this.declaration.parentOfKind(R);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof F){let t=bu(this.declaration)[0];if(!(t instanceof R))return[];let n=t.callee;return n instanceof cd?kd(e,n.rightExpression):[]}if(this.declaration instanceof I){let t=this.declaration.value;return t instanceof L?kd(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof F){let t=bu(this.declaration)[0];if(!(t instanceof R))return;let n=t.callee;return n instanceof cd?Ad(e,n.leftExpression):void 0}if(this.declaration instanceof I)return this.container(e)}rightTable(e){if(this.declaration instanceof F){let t=bu(this.declaration)[0];if(!(t instanceof R))return;let n=t.callee;return n instanceof cd?Ad(e,n.rightExpression):void 0}if(this.declaration instanceof I){let t=this.declaration.value;return t instanceof L?Ad(e,t.expression)??this.container(e):void 0}}op(e){if(this.declaration instanceof F){let e=bu(this.declaration)[0];if(!(e instanceof R))return;let t=e.callee;return t instanceof cd?t.op?.value:void 0}if(this.declaration instanceof I){let e=this.declaration.value;return e instanceof L?e.op?.value:void 0}}active(e){if(!(this.declaration instanceof F))return!0;let n=bu(this.declaration)[0];return n?!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length:!0}leftToken(){if(this.declaration instanceof F){let e=bu(this.declaration)[0];if(e instanceof R){let t=e.callee;if(t instanceof cd&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof I){let e=this.declaration.parentOfKind(R);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof F){let e=bu(this.declaration)[0];if(e instanceof R){let t=e.callee;if(t instanceof cd&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof I,this.declaration}owners(e){let n=this.leftTable(e),r=this.rightTable(e);if(!n||!r)return[];let i=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(i))&&t.inNestedSchema(e,n)&&t.inNestedSchema(e,r))}},wd=class extends Sd{constructor(e){super(e),this.kind=xd.PartialRef}container(e){let n=this.declaration.parentOfKind(F);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof I))return[];let n=this.declaration.parentOfKind(R);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof I))return[];let t=this.declaration.value;return t instanceof L?kd(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof I)return this.container(e)}rightTable(e){if(!(this.declaration instanceof I))return;let t=this.declaration.value;if(t instanceof L)return Ad(e,t.expression)??this.container(e)}op(e){if(!(this.declaration instanceof I))return;let t=this.declaration.value;if(t instanceof L)return t.op?.value}leftToken(){if(this.declaration instanceof I){let e=this.declaration.parentOfKind(R);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof I,this.declaration}owners(e){let n=this.leftTablePartial(e),r=this.rightTable(e);return!n||!r?[]:e.reachableFiles().flatMap(n=>e.nodeSymbol(e.parseFile(n).getValue().ast).getFiltered(t)||[]).filter(t=>t.inNestedSchema(e,n)&&t.inNestedSchema(e,r))}},Td=class extends Sd{constructor(e){super(e),this.kind=xd.TableChecks,this.ownerTable=e.parentNode?.parentOfKind(F)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Ed=class extends Sd{constructor(e){super(e),this.kind=xd.Indexes,this.ownerTable=e.parentNode?.parentOfKind(F)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Dd=class extends Sd{constructor(e){super(e),this.kind=xd.Records}table(e){let n=this.declaration,i=n.parent;if(i instanceof F&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof V))return;let o=Tu(a);if(!o)return;let s=o.variables.at(-1);if(s)return e.nodeReferee(s).getFiltered(t)?.originalSymbol}owners(e){let n=this.table(e);return n?e.reachableFiles().flatMap(n=>e.nodeSymbol(e.parseFile(n).getValue().ast).getFiltered(t)||[]).filter(t=>t.inNestedSchema(e,n)):[]}},Od=class extends Sd{constructor(e){super(e),this.kind=xd.Project}owners(e){let n=this.declaration.filepath,r=e.parseFile(n).getValue().ast,i=e.nodeSymbol(r).getFiltered(t);return i?[i]:[]}};function kd(e,n){if(!n)return[];let r=Su(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?[r]:[]}):[]}function Ad(e,n){if(!n)return;let r=Su(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)}var jd=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},Md=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof z?new n(e.body.flatMap(e=>{if(!(e instanceof R))return[];let t=A(e),n=e.callee instanceof ud?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof B);return a&&(r=O(x(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}};const Nd={nodeMetadata(t,i){if(T(i,r.Checks)){let t=i.parent;return!t||!T(t,r.Table)&&!T(t,r.TablePartial)?n.create(e):n.create(new Td(i))}return n.create(e)},bindNode(t,i){return T(i,r.Checks)?n.create(void 0,new jd(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===xd.TableChecks?r.declaration instanceof F?new Md(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function Pd(e,t,n){let r=t,i=e;if(i instanceof V&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!nu(i)||r.length===0)return;let a=[...r],o=gu(i),s=a.pop();if(!(s instanceof z))return;let c=h(a)instanceof B?a.pop():void 0;if(a.length===3){let e=gu(a[1]);return!e||!sl(e)?void 0:n.create(F,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(F,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(F,{type:o,attributeList:c,body:s})}function H(e){e&&(e instanceof el?Fd(e):Id(e))}function Fd(e){e.kind!==_.EOF&&(e.isInvalid=!0)}function Id(e){if(e instanceof F)H(e.type),H(e.name),H(e.as),H(e.alias),H(e.bodyColon),H(e.attributeList),H(e.body);else if(e instanceof sd)e.identifiers.forEach(H);else if(e instanceof I)H(e.name),H(e.colon),H(e.value);else if(e instanceof L)H(e.op),H(e.expression);else if(e instanceof cd)H(e.leftExpression),H(e.op),H(e.rightExpression);else if(e instanceof ld)H(e.op),H(e.expression);else if(e instanceof z)H(e.blockOpenBrace),e.body.forEach(H),H(e.blockCloseBrace);else if(e instanceof B)H(e.listOpenBracket),e.commaList.forEach(H),e.elementList.forEach(H),H(e.listCloseBracket);else if(e instanceof dd)H(e.tupleOpenParen),e.commaList.forEach(H),e.elementList.forEach(H),H(e.tupleCloseParen);else if(e instanceof fd)e.commaList.forEach(H),e.elementList.forEach(H);else if(e instanceof V)H(e.callee),H(e.argumentList);else if(e instanceof R)H(e.callee),e.args.forEach(H);else if(e instanceof _d)H(e.expression);else if(e instanceof ud)H(e.value);else if(e instanceof gd)H(e.variable);else if(e instanceof md)H(e.literal);else if(e instanceof pd)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof yd)H(e.array),H(e.indexer);else if(e instanceof P)e.body.forEach(H),H(e.eof);else if(!(e instanceof vd))if(e instanceof id)H(e.useKeyword),H(e.specifiers),H(e.fromKeyword),H(e.importPath);else if(e instanceof od)H(e.openBrace),e.specifiers.forEach(H),H(e.closeBrace);else if(e instanceof ad)H(e.importKind),H(e.name),H(e.asKeyword),H(e.alias);else if(e instanceof hd)H(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Ld(...e){return e.filter(e=>e!==void 0)}function Rd(e){if(e instanceof P)return Ld(...e.body,e.eof);if(e instanceof F)return Ld(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof I)return Ld(e.name,e.colon,e.value);if(e instanceof sd)return e.identifiers;if(e instanceof md)return e.literal?[e.literal]:[];if(e instanceof gd)return Ld(e.variable);if(e instanceof L)return Ld(e.op,e.expression);if(e instanceof cd)return Ld(e.leftExpression,e.op,e.rightExpression);if(e instanceof ld)return Ld(e.expression,e.op);if(e instanceof ud)return Ld(e.value);if(e instanceof R)return Ld(e.callee,...e.args);if(e instanceof z)return Ld(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof B)return Ld(e.listOpenBracket,...zd(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof dd)return Ld(e.tupleOpenParen,...zd(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof fd)return Ld(...zd(e.elementList,e.commaList));if(e instanceof V)return Ld(e.callee,e.argumentList);if(e instanceof _d)return Ld(e.expression);if(e instanceof yd)return Ld(e.array,e.indexer);if(e instanceof vd)return[];if(e instanceof id)return Ld(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof od)return Ld(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof ad)return Ld(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof hd)return Ld(e.token);throw e instanceof pd?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function zd(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 Bd(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function Vd(e){if(!e)return[];if(C(e))return[{variables:[e],tupleElements:[]}];if(e instanceof cd){let t=Su(e);return t?[t]:[...Vd(e.leftExpression),...Vd(e.rightExpression)]}if(e instanceof L||e instanceof ld)return Vd(e.expression);if(e instanceof dd){let t=Su(e);return t?[t]:e.elementList.flatMap(Vd)}return[]}function Hd(e,n){let r=n.parentNode;if(!r||!w(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;w(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Ud(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:return}}var Wd=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof z?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=g(e.body,e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof z)?[]: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 R);return t.flatMap(e=>!e.callee||tu(e.callee)?[]:[e.callee,...e.args].flatMap(Vd).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 R);return t.flatMap(e=>!e.callee||tu(e.callee)?[]:Vd(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 R);return t.flatMap(e=>!e.callee||tu(e.callee)?[]:Vd(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 R);return t.flatMap(e=>!e.callee||tu(e.callee)?[]:Vd(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},Gd=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 z&&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 R&&tu(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 F),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof z&&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 R&&tu(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 R))continue;let e=n.callee&&mu(n.callee),r=e&&this.compiler.nodeReferee(e).getFiltered(t);if(r?.declaration instanceof F){let e=D(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=D(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?Gc(r.filter(e=>e.isKind(j.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function Kd(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}let qd=function(e){return e.Table=`table`,e}({});const Jd={getDuplicateError(e,t,n){return new b(y.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new b(y.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},Yd={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return T(a,r.DiagramView)?new n(i.symbolFactory.create(qu,{declaration:a,name:o},a.filepath)):E(a,r.DiagramView)&&a instanceof hd?new n(i.symbolFactory.create(Ju,{declaration:a,name:o},a.filepath)):E(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(Zu,{declaration:a,name:o},a.filepath)):E(a,r.DiagramViewTables)?new n(i.symbolFactory.create(Yu,{declaration:a,name:o},a.filepath)):E(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(Xu,{declaration:a,name:o},a.filepath)):E(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(Qu,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&lu(a))return n.create(e);let o=Xd(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)?Zd(i,c,a):o.isKind(r.DiagramViewNotes)?Qd(i,c,a,j.StickyNote):o.isKind(r.DiagramViewTableGroups)?Qd(i,c,a,j.TableGroup):o.isKind(r.DiagramViewSchemas)?$d(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(j.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!T(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of bu(o))if(e instanceof R){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof F&&c.push(...bu(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(j.DiagramViewSchema,j.DiagramViewTableGroup,j.DiagramViewTable,j.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(vy).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(Jd.getFieldDuplicateError(n,e.kind,i)),s.push(Jd.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!T(a,r.DiagramView))return n.create(e);let o=new Wd(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 qu?r.declaration instanceof F?new Gd(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function Xd(e){let t=e.parentOfKind(R);if(!t)return;let n=t.parentNode;if(!(n instanceof z))return;let i=n.parentNode;if(!(i instanceof F)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof z))return;let o=a.parentNode;if(!(!(o instanceof F)||!o.isKind(r.DiagramView)))return i}function Zd(e,r,i){let a=Eu(i);if(a===void 0)return n.create(void 0);if(w(i.parentNode)){let t=Hd(e,i);if(t){if(t.isKind(j.Schema)){let r=hu(i),o=e.lookupMembers(t,r?j.Table:j.Schema,a);return o?n.create(o):new n(void 0,[new b(y.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,j.Schema,a);return o?n.create(o):new n(void 0,[new b(y.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(j.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,j.Table,a);return s?n.create(s):new n(void 0,[new b(y.BINDING_ERROR,`Could not find table '${a}'`,i)])}function Qd(e,t,r,i){let a=Eu(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 b(y.BINDING_ERROR,`Could not find ${i===j.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function $d(e,t,r){let i=Eu(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,j.Schema,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var ef=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof z?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof R)return[];let t=e.body.filter(e=>e instanceof F);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},tf=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=A(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=A(t),n.name=k(t.callee);let r=x(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:ku(O(r.value)),token:A(r)},this.enum.values.push(n),[]})}};const nf={getDuplicateError(e,t,n){return new b(y.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new b(y.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},rf={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return T(a,r.Enum)?new n(i.symbolFactory.create(Ru,{declaration:a,name:o},a.filepath)):E(a,r.Enum)?new n(i.symbolFactory.create(zu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(j.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof F))return new n([]);let o=bu(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(j.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push(nf.getFieldDuplicateError(t,r)),c.push(nf.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!T(a,r.Enum))return n.create(e);let o=new ef(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 Ru?new tf(t,r,i).interpret():n.create(e)}};var af=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof F)||!this.declarationNode.parent.isKind(r.Table)&&!this.declarationNode.parent.isKind(r.TablePartial)||!(this.declarationNode.body instanceof z)?[]:this.bindBody(this.declarationNode.body)}get ownerContainerKind(){return this.declarationNode.parent.isKind(r.TablePartial)?`TablePartial`:`Table`}bindBody(e){if(!e)return[];if(e instanceof R)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof R);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=D(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(Vd).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=Eu(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new b(y.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},of=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof z?new n(e.body.flatMap(e=>{if(!(e instanceof R)||!e.callee)return[];let n=[],r=A(e),a=[e.callee,...e.args],o,s,c,l,u;h(a)instanceof B&&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=O(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=O(e.value);t!==void 0&&(l={value:t,token:A(e)})}u=k(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof V))return e;let t=[],n=e;for(;n instanceof V&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=Cu(e);if(t){for(let e of t.functional)n.push({value:e.value?.value??``,type:`expression`,token:A(e)});for(let e of t.nonFunctional)n.push({value:Eu(e)??``,type:`column`,token:A(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}};const sf={nodeMetadata(t,i){if(!T(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!T(a,r.Table)&&!T(a,r.TablePartial)?n.create(e):n.create(new Ed(i))},nodeReferee(i,a){if(!C(a)||lu(a))return n.create(e);let o=a;for(;o&&!T(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!T(s,r.Table)&&!T(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=C(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,j.Column,l);if(u)return n.create(u);let d=T(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new b(y.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return T(i,r.Indexes)?n.create(void 0,new af(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===xd.Indexes?r.declaration instanceof F?new of(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function cf(e,n){let r=xu(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof dd){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 dd)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function lf(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 b(y.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new b(y.CIRCULAR_REF,`References with same endpoints exist`,n),new b(y.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var uf=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 F&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new b(y.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof F&&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(...df(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 F)||!t.type)continue;let i=t;T(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),T(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),T(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of bu(e)){if(!(r instanceof R)||!r.callee||!du(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=cf(this.compiler,i.leftExpression),o=cf(this.compiler,i.rightExpression);!a||!o||n.push(...lf(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of bu(e)){if(!(a instanceof R)||!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 L)||!i.op||!Jl(i.op.value)||!i.expression)continue;let a=cf(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...lf(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of bu(e)){if(!(r instanceof R)||!r.callee)continue;let e=k(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 L&&(!r.op||!Jl(r.op.value)||r.expression&&C(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new b(y.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 F)||!i.type)continue;let a=i;if(!T(a,r.TableGroup))continue;let o=a.name?D(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=bu(a);for(let r of c){if(!(r instanceof R)||!r.callee)continue;let i=xu(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=D(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new b(y.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 df(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 Lu&&a.push(...df(e,t,r));return a}function ff(e,t,n){t.isKind(j.Table)?e.externals.tables.push(n):t.isKind(j.Enum)?e.externals.enums.push(n):t.isKind(j.TableGroup)?e.externals.tableGroups.push(n):t.isKind(j.TablePartial)?e.externals.tablePartials.push(n):t.isKind(j.StickyNote)&&e.externals.notes.push(n)}var pf={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`])},mf={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`])},hf={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},gf={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`])},_f={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`])},vf={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`])},yf={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function bf(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function xf(e,t){let n=bf(e);return t?pf[t].has(n):Object.values(pf).some(e=>e.has(n))}function Sf(e,t){let n=bf(e);return t?mf[t].has(n):Object.values(mf).some(e=>e.has(n))}function Cf(e,t){return xf(e,t)||Sf(e,t)}function wf(e,t){let n=bf(e);return t?hf[t].has(n):Object.values(hf).some(e=>e.has(n))}function Tf(e,t){let n=bf(e);return t?gf[t].has(n):Object.values(gf).some(e=>e.has(n))}function Ef(e,t){let n=bf(e);return t?_f[t].has(n):Object.values(_f).some(e=>e.has(n))}function Df(e,t){let n=bf(e);return t?vf[t].has(n):Object.values(vf).some(e=>e.has(n))}function Of(e,t){let n=bf(e);return t?yf[t].has(n):Object.values(yf).some(e=>e.has(n))}function kf(e,t){if(t)return`string`;if(xf(e))return`integer`;if(Sf(e))return`real`;if(wf(e))return`bool`;if(Tf(e))return`string`;let n=bf(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:Df(e)?`datetime`:e}var Af=class extends Error{},jf=class extends Af{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Mf=class extends Af{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Nf=class extends Af{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Pf=class extends Af{},Ff=class extends Af{constructor(e){super(`Invalid unit ${e}`)}},If=class extends Af{},Lf=class extends Af{constructor(){super(`Zone is an abstract class`)}},U=`numeric`,Rf=`short`,zf=`long`,Bf={year:U,month:U,day:U},Vf={year:U,month:Rf,day:U},Hf={year:U,month:Rf,day:U,weekday:Rf},Uf={year:U,month:zf,day:U},Wf={year:U,month:zf,day:U,weekday:zf},Gf={hour:U,minute:U},Kf={hour:U,minute:U,second:U},qf={hour:U,minute:U,second:U,timeZoneName:Rf},Jf={hour:U,minute:U,second:U,timeZoneName:zf},Yf={hour:U,minute:U,hourCycle:`h23`},Xf={hour:U,minute:U,second:U,hourCycle:`h23`},Zf={hour:U,minute:U,second:U,hourCycle:`h23`,timeZoneName:Rf},Qf={hour:U,minute:U,second:U,hourCycle:`h23`,timeZoneName:zf},$f={year:U,month:U,day:U,hour:U,minute:U},ep={year:U,month:U,day:U,hour:U,minute:U,second:U},tp={year:U,month:Rf,day:U,hour:U,minute:U},np={year:U,month:Rf,day:U,hour:U,minute:U,second:U},rp={year:U,month:Rf,day:U,weekday:Rf,hour:U,minute:U},ip={year:U,month:zf,day:U,hour:U,minute:U,timeZoneName:Rf},ap={year:U,month:zf,day:U,hour:U,minute:U,second:U,timeZoneName:Rf},op={year:U,month:zf,day:U,weekday:zf,hour:U,minute:U,timeZoneName:zf},sp={year:U,month:zf,day:U,weekday:zf,hour:U,minute:U,second:U,timeZoneName:zf},cp=class{get type(){throw new Lf}get name(){throw new Lf}get ianaName(){return this.name}get isUniversal(){throw new Lf}offsetName(e,t){throw new Lf}formatOffset(e,t){throw new Lf}offset(e){throw new Lf}equals(e){throw new Lf}get isValid(){throw new Lf}},lp=null,up=class e extends cp{static get instance(){return lp===null&&(lp=new e),lp}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Xm(e,t,n)}formatOffset(e,t){return eh(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},dp=new Map;function fp(e){let t=dp.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(`en-US`,{hour12:!1,timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,era:`short`}),dp.set(e,t)),t}var pp={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function mp(e,t){let n=e.format(t).replace(/\u200E/g,``),[,r,i,a,o,s,c,l]=/(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(n);return[a,r,i,o,s,c,l]}function hp(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=pp[t];t===`era`?r[a]=i:G(a)||(r[a]=parseInt(i,10))}return r}var gp=new Map,_p=class e extends cp{static create(t){let n=gp.get(t);return n===void 0&&gp.set(t,n=new e(t)),n}static resetCache(){gp.clear(),dp.clear()}static isValidSpecifier(e){return this.isValidZone(e)}static isValidZone(e){if(!e)return!1;try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).format(),!0}catch{return!1}}constructor(t){super(),this.zoneName=t,this.valid=e.isValidZone(t)}get type(){return`iana`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Xm(e,t,n,this.name)}formatOffset(e,t){return eh(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=fp(this.name),[r,i,a,o,s,c,l]=n.formatToParts?hp(n,t):mp(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=Km({year:r,month:i,day:a,hour:s===24?0:s,minute:c,second:l,millisecond:0}),d=+t,f=d%1e3;return d-=f>=0?f:1e3+f,(u-d)/(60*1e3)}equals(e){return e.type===`iana`&&e.name===this.name}get isValid(){return this.valid}},vp={};function yp(e,t={}){let n=JSON.stringify([e,t]),r=vp[n];return r||(r=new Intl.ListFormat(e,t),vp[n]=r),r}var bp=new Map;function xp(e,t={}){let n=JSON.stringify([e,t]),r=bp.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),bp.set(n,r)),r}var Sp=new Map;function Cp(e,t={}){let n=JSON.stringify([e,t]),r=Sp.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Sp.set(n,r)),r}var wp=new Map;function Tp(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=wp.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),wp.set(i,a)),a}var Ep=null;function Dp(){return Ep||(Ep=new Intl.DateTimeFormat().resolvedOptions().locale,Ep)}var Op=new Map;function kp(e){let t=Op.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Op.set(e,t)),t}var Ap=new Map;function jp(e){let t=Ap.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Vp,...t}),Ap.set(e,t)}return t}function Mp(e){let t=e.indexOf(`-x-`);t!==-1&&(e=e.substring(0,t));let n=e.indexOf(`-u-`);if(n===-1)return[e];{let t,r;try{t=xp(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=xp(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Np(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Pp(e){let t=[];for(let n=1;n<=12;n++){let r=B_.utc(2009,n,1);t.push(e(r))}return t}function Fp(e){let t=[];for(let n=1;n<=7;n++){let r=B_.utc(2016,11,13+n);t.push(e(r))}return t}function Ip(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Lp(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||kp(e.locale).numberingSystem===`latn`}var Rp=class{constructor(e,t,n){this.padTo=n.padTo||0,this.floor=n.floor||!1;let{padTo:r,floor:i,...a}=n;if(!t||Object.keys(a).length>0){let t={useGrouping:!1,...n};n.padTo>0&&(t.minimumIntegerDigits=n.padTo),this.inf=Cp(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return Rm(this.floor?Math.floor(e):Hm(e,3),this.padTo)}},zp=class{constructor(e,t,n){this.opts=n,this.originalZone=void 0;let r;if(this.opts.timeZone)this.dt=e;else if(e.zone.type===`fixed`){let t=-1*(e.offset/60),n=t>=0?`Etc/GMT+${t}`:`Etc/GMT${t}`;e.offset!==0&&_p.create(n).valid?(r=n,this.dt=e):(r=`UTC`,this.dt=e.offset===0?e:e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone)}else e.zone.type===`system`?this.dt=e:e.zone.type===`iana`?(this.dt=e,r=e.zone.name):(r=`UTC`,this.dt=e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone);let i={...this.opts};i.timeZone=i.timeZone||r,this.dtf=xp(t,i)}format(){return this.originalZone?this.formatToParts().map(({value:e})=>e).join(``):this.dtf.format(this.dt.toJSDate())}formatToParts(){let e=this.dtf.formatToParts(this.dt.toJSDate());return this.originalZone?e.map(e=>{if(e.type===`timeZoneName`){let t=this.originalZone.offsetName(this.dt.ts,{locale:this.dt.locale,format:this.opts.timeZoneName});return{...e,value:t}}else return e}):e}resolvedOptions(){return this.dtf.resolvedOptions()}},Bp=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&km()&&(this.rtf=Tp(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):yh(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Vp={firstDay:1,minimalDays:4,weekend:[6,7]},W=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||sm.defaultLocale;return new e(o||(a?`en-US`:Dp()),n||sm.defaultNumberingSystem,r||sm.defaultOutputCalendar,Fm(i)||sm.defaultWeekSettings,o)}static resetCache(){Ep=null,bp.clear(),Sp.clear(),wp.clear(),Op.clear(),Ap.clear()}static fromObject({locale:t,numberingSystem:n,outputCalendar:r,weekSettings:i}={}){return e.create(t,n,r,i)}constructor(e,t,n,r,i){let[a,o,s]=Mp(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Np(this.locale,this.numberingSystem,this.outputCalendar),this.weekdaysCache={format:{},standalone:{}},this.monthsCache={format:{},standalone:{}},this.meridiemCache=null,this.eraCache={},this.specifiedLocale=i,this.fastNumbersCached=null}get fastNumbers(){return this.fastNumbersCached??=Lp(this),this.fastNumbersCached}listingMode(){let e=this.isEnglish(),t=(this.numberingSystem===null||this.numberingSystem===`latn`)&&(this.outputCalendar===null||this.outputCalendar===`gregory`);return e&&t?`en`:`intl`}clone(t){return!t||Object.getOwnPropertyNames(t).length===0?this:e.create(t.locale||this.specifiedLocale,t.numberingSystem||this.numberingSystem,t.outputCalendar||this.outputCalendar,Fm(t.weekSettings)||this.weekSettings,t.defaultToEN||!1)}redefaultToEN(e={}){return this.clone({...e,defaultToEN:!0})}redefaultToSystem(e={}){return this.clone({...e,defaultToEN:!1})}months(e,t=!1){return Ip(this,e,ah,()=>{let n=this.intl===`ja`||this.intl.startsWith(`ja-`);t&=!n;let r=t?{month:e,day:`numeric`}:{month:e},i=t?`format`:`standalone`;if(!this.monthsCache[i][e]){let t=n?e=>this.dtFormatter(e,r).format():e=>this.extract(e,r,`month`);this.monthsCache[i][e]=Pp(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Ip(this,e,lh,()=>{let n=t?{weekday:e,year:`numeric`,month:`long`,day:`numeric`}:{weekday:e},r=t?`format`:`standalone`;return this.weekdaysCache[r][e]||(this.weekdaysCache[r][e]=Fp(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Ip(this,void 0,()=>uh,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[B_.utc(2016,11,13,9),B_.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Ip(this,e,mh,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[B_.utc(-40,1,1),B_.utc(2017,1,1)].map(e=>this.extract(e,t,`era`))),this.eraCache[e]})}extract(e,t,n){let r=this.dtFormatter(e,t).formatToParts().find(e=>e.type.toLowerCase()===n);return r?r.value:null}numberFormatter(e={}){return new Rp(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new zp(e,this.intl,t)}relFormatter(e={}){return new Bp(this.intl,this.isEnglish(),e)}listFormatter(e={}){return yp(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||kp(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Am()?jp(this.locale):Vp}getStartOfWeek(){return this.getWeekSettings().firstDay}getMinDaysInFirstWeek(){return this.getWeekSettings().minimalDays}getWeekendDays(){return this.getWeekSettings().weekend}equals(e){return this.locale===e.locale&&this.numberingSystem===e.numberingSystem&&this.outputCalendar===e.outputCalendar}toString(){return`Locale(${this.locale}, ${this.numberingSystem}, ${this.outputCalendar})`}},Hp=null,Up=class e extends cp{static get utcInstance(){return Hp===null&&(Hp=new e(0)),Hp}static instance(t){return t===0?e.utcInstance:new e(t)}static parseSpecifier(t){if(t){let n=t.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);if(n)return new e(Zm(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${eh(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${eh(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return eh(this.fixed,t)}get isUniversal(){return!0}offset(){return this.fixed}equals(e){return e.type===`fixed`&&e.fixed===this.fixed}get isValid(){return!0}},Wp=class extends cp{constructor(e){super(),this.zoneName=e}get type(){return`invalid`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(){return null}formatOffset(){return``}offset(){return NaN}equals(){return!1}get isValid(){return!1}};function Gp(e,t){if(G(e)||e===null)return t;if(e instanceof cp)return e;if(Dm(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?up.instance:n===`utc`||n===`gmt`?Up.utcInstance:Up.parseSpecifier(n)||_p.create(e)}else if(Tm(e))return Up.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new Wp(e)}var Kp={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},qp={arab:[1632,1641],arabext:[1776,1785],bali:[6992,7001],beng:[2534,2543],deva:[2406,2415],fullwide:[65296,65303],gujr:[2790,2799],khmr:[6112,6121],knda:[3302,3311],laoo:[3792,3801],limb:[6470,6479],mlym:[3430,3439],mong:[6160,6169],mymr:[4160,4169],orya:[2918,2927],tamldec:[3046,3055],telu:[3174,3183],thai:[3664,3673],tibt:[3872,3881]},Jp=Kp.hanidec.replace(/[\[|\]]/g,``).split(``);function Yp(e){let t=parseInt(e,10);if(isNaN(t)){t=``;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(e[n].search(Kp.hanidec)!==-1)t+=Jp.indexOf(e[n]);else for(let e in qp){let[n,i]=qp[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Xp=new Map;function Zp(){Xp.clear()}function Qp({numberingSystem:e},t=``){let n=e||`latn`,r=Xp.get(n);r===void 0&&(r=new Map,Xp.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Kp[n]}${t}`),r.set(t,i)),i}var $p=()=>Date.now(),em=`system`,tm=null,nm=null,rm=null,im=60,am,om=null,sm=class{static get now(){return $p}static set now(e){$p=e}static set defaultZone(e){em=e}static get defaultZone(){return Gp(em,up.instance)}static get defaultLocale(){return tm}static set defaultLocale(e){tm=e}static get defaultNumberingSystem(){return nm}static set defaultNumberingSystem(e){nm=e}static get defaultOutputCalendar(){return rm}static set defaultOutputCalendar(e){rm=e}static get defaultWeekSettings(){return om}static set defaultWeekSettings(e){om=Fm(e)}static get twoDigitCutoffYear(){return im}static set twoDigitCutoffYear(e){im=e%100}static get throwOnInvalid(){return am}static set throwOnInvalid(e){am=e}static resetCaches(){W.resetCache(),_p.resetCache(),B_.resetCache(),Zp()}},cm=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},lm=[0,31,59,90,120,151,181,212,243,273,304,334],um=[0,31,60,91,121,152,182,213,244,274,305,335];function dm(e,t){return new cm(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function fm(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 pm(e,t,n){return n+(Um(e)?um:lm)[t-1]}function mm(e,t){let n=Um(e)?um:lm,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function hm(e,t){return(e-t+7)%7+1}function gm(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=pm(r,i,a),s=hm(fm(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=Jm(l,t,n)):c>Jm(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...th(e)}}function _m(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=hm(fm(r,1,t),n),s=Wm(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=Wm(l)):c>s?(l=r+1,c-=Wm(r)):l=r;let{month:u,day:d}=mm(l,c);return{year:l,month:u,day:d,...th(e)}}function vm(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:pm(t,n,r),...th(e)}}function ym(e){let{year:t,ordinal:n}=e,{month:r,day:i}=mm(t,n);return{year:t,month:r,day:i,...th(e)}}function bm(e,t){if(!G(e.localWeekday)||!G(e.localWeekNumber)||!G(e.localWeekYear)){if(!G(e.weekday)||!G(e.weekNumber)||!G(e.weekYear))throw new Pf(`Cannot mix locale-based week fields with ISO-based week fields`);return G(e.localWeekday)||(e.weekday=e.localWeekday),G(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),G(e.localWeekYear)||(e.weekYear=e.localWeekYear),delete e.localWeekday,delete e.localWeekNumber,delete e.localWeekYear,{minDaysInFirstWeek:t.getMinDaysInFirstWeek(),startOfWeek:t.getStartOfWeek()}}else return{minDaysInFirstWeek:4,startOfWeek:1}}function xm(e,t=4,n=1){let r=Em(e.weekYear),i=Im(e.weekNumber,1,Jm(e.weekYear,t,n)),a=Im(e.weekday,1,7);return r?i?a?!1:dm(`weekday`,e.weekday):dm(`week`,e.weekNumber):dm(`weekYear`,e.weekYear)}function Sm(e){let t=Em(e.year),n=Im(e.ordinal,1,Wm(e.year));return t?n?!1:dm(`ordinal`,e.ordinal):dm(`year`,e.year)}function Cm(e){let t=Em(e.year),n=Im(e.month,1,12),r=Im(e.day,1,Gm(e.year,e.month));return t?n?r?!1:dm(`day`,e.day):dm(`month`,e.month):dm(`year`,e.year)}function wm(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Im(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Im(n,0,59),s=Im(r,0,59),c=Im(i,0,999);return a?o?s?c?!1:dm(`millisecond`,i):dm(`second`,r):dm(`minute`,n):dm(`hour`,t)}function G(e){return e===void 0}function Tm(e){return typeof e==`number`}function Em(e){return typeof e==`number`&&e%1==0}function Dm(e){return typeof e==`string`}function Om(e){return Object.prototype.toString.call(e)===`[object Date]`}function km(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Am(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function jm(e){return Array.isArray(e)?e:[e]}function Mm(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 Nm(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Pm(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Fm(e){if(e==null)return null;if(typeof e!=`object`)throw new If(`Week settings must be an object`);if(!Im(e.firstDay,1,7)||!Im(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Im(e,1,7)))throw new If(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Im(e,t,n){return Em(e)&&e>=t&&e<=n}function Lm(e,t){return e-t*Math.floor(e/t)}function Rm(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function zm(e){if(!(G(e)||e===null||e===``))return parseInt(e,10)}function Bm(e){if(!(G(e)||e===null||e===``))return parseFloat(e)}function Vm(e){if(!(G(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Hm(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 Um(e){return e%4==0&&(e%100!=0||e%400==0)}function Wm(e){return Um(e)?366:365}function Gm(e,t){let n=Lm(t-1,12)+1,r=e+(t-n)/12;return n===2?Um(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function Km(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 qm(e,t,n){return-hm(fm(e,1,t),n)+t-1}function Jm(e,t=4,n=1){let r=qm(e,t,n),i=qm(e+1,t,n);return(Wm(e)-r+i)/7}function Ym(e){return e>99?e:e>sm.twoDigitCutoffYear?1900+e:2e3+e}function Xm(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 Zm(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 Qm(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new If(`Invalid unit value ${e}`);return t}function $m(e,t){let n={};for(let r in e)if(Pm(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=Qm(i)}return n}function eh(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}${Rm(n,2)}:${Rm(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${Rm(n,2)}${Rm(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function th(e){return Nm(e,[`hour`,`minute`,`second`,`millisecond`])}var nh=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],rh=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ih=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function ah(e){switch(e){case`narrow`:return[...ih];case`short`:return[...rh];case`long`:return[...nh];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 oh=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],sh=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],ch=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function lh(e){switch(e){case`narrow`:return[...ch];case`short`:return[...sh];case`long`:return[...oh];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var uh=[`AM`,`PM`],dh=[`Before Christ`,`Anno Domini`],fh=[`BC`,`AD`],ph=[`B`,`A`];function mh(e){switch(e){case`narrow`:return[...ph];case`short`:return[...fh];case`long`:return[...dh];default:return null}}function hh(e){return uh[e.hour<12?0:1]}function gh(e,t){return lh(t)[e.weekday-1]}function _h(e,t){return ah(t)[e.month-1]}function vh(e,t){return mh(t)[e.year<0?0:1]}function yh(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 bh(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var xh={D:Bf,DD:Vf,DDD:Uf,DDDD:Wf,t:Gf,tt:Kf,ttt:qf,tttt:Jf,T:Yf,TT:Xf,TTT:Zf,TTTT:Qf,f:$f,ff:tp,fff:ip,ffff:op,F:ep,FF:np,FFF:ap,FFFF:sp},Sh=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 xh[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 Rm(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?hh(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?_h(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?gh(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?vh(t,e):a({era:e},`era`);return bh(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 bh(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Ch=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function wh(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Th(...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 Eh(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 Dh(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=zm(t[n+i]);return[r,null,n+i]}}var Oh=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,kh=`(?:${Oh.source}?(?:\\[(${Ch.source})\\])?)?`,Ah=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,jh=RegExp(`${Ah.source}${kh}`),Mh=RegExp(`(?:[Tt]${jh.source})?`),Nh=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Ph=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Fh=/(\d{4})-?(\d{3})/,Ih=Dh(`weekYear`,`weekNumber`,`weekDay`),Lh=Dh(`year`,`ordinal`),Rh=/(\d{4})-(\d\d)-(\d\d)/,zh=RegExp(`${Ah.source} ?(?:${Oh.source}|(${Ch.source}))?`),Bh=RegExp(`(?: ${zh.source})?`);function Vh(e,t,n){let r=e[t];return G(r)?n:zm(r)}function Hh(e,t){return[{year:Vh(e,t),month:Vh(e,t+1,1),day:Vh(e,t+2,1)},null,t+3]}function Uh(e,t){return[{hours:Vh(e,t,0),minutes:Vh(e,t+1,0),seconds:Vh(e,t+2,0),milliseconds:Vm(e[t+3])},null,t+4]}function Wh(e,t){let n=!e[t]&&!e[t+1],r=Zm(e[t+1],e[t+2]);return[{},n?null:Up.instance(r),t+3]}function Gh(e,t){return[{},e[t]?_p.create(e[t]):null,t+1]}var Kh=RegExp(`^T?${Ah.source}$`),qh=/^-?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 Jh(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(Bm(n)),months:f(Bm(r)),weeks:f(Bm(i)),days:f(Bm(a)),hours:f(Bm(o)),minutes:f(Bm(s)),seconds:f(Bm(c),c===`-0`),milliseconds:f(Vm(l),d)}]}var Yh={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Xh(e,t,n,r,i,a,o){let s={year:t.length===2?Ym(zm(t)):zm(t),month:rh.indexOf(n)+1,day:zm(r),hour:zm(i),minute:zm(a)};return o&&(s.second=zm(o)),e&&(s.weekday=e.length>3?oh.indexOf(e)+1:sh.indexOf(e)+1),s}var Zh=/^(?:(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 Qh(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=Xh(t,i,r,n,a,o,s),p;return p=c?Yh[c]:l?0:Zm(u,d),[f,new Up(p)]}function $h(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var eg=/^(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$/,tg=/^(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$/,ng=/^(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 rg(e){let[,t,n,r,i,a,o,s]=e;return[Xh(t,i,r,n,a,o,s),Up.utcInstance]}function ig(e){let[,t,n,r,i,a,o,s]=e;return[Xh(t,s,n,r,i,a,o),Up.utcInstance]}var ag=wh(Nh,Mh),og=wh(Ph,Mh),sg=wh(Fh,Mh),cg=wh(jh),lg=Th(Hh,Uh,Wh,Gh),ug=Th(Ih,Uh,Wh,Gh),dg=Th(Lh,Uh,Wh,Gh),fg=Th(Uh,Wh,Gh);function pg(e){return Eh(e,[ag,lg],[og,ug],[sg,dg],[cg,fg])}function mg(e){return Eh($h(e),[Zh,Qh])}function hg(e){return Eh(e,[eg,rg],[tg,rg],[ng,ig])}function gg(e){return Eh(e,[qh,Jh])}var _g=Th(Uh);function vg(e){return Eh(e,[Kh,_g])}var yg=wh(Rh,Bh),bg=wh(zh),xg=Th(Uh,Wh,Gh);function Sg(e){return Eh(e,[yg,lg],[bg,xg])}var Cg=`Invalid Duration`,wg={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}},Tg={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},...wg},Eg=146097/400,Dg=146097/4800,Og={years:{quarters:4,months:12,weeks:Eg/7,days:Eg,hours:Eg*24,minutes:Eg*24*60,seconds:Eg*24*60*60,milliseconds:Eg*24*60*60*1e3},quarters:{months:3,weeks:Eg/28,days:Eg/4,hours:Eg*24/4,minutes:Eg*24*60/4,seconds:Eg*24*60*60/4,milliseconds:Eg*24*60*60*1e3/4},months:{weeks:Dg/7,days:Dg,hours:Dg*24,minutes:Dg*24*60,seconds:Dg*24*60*60,milliseconds:Dg*24*60*60*1e3},...wg},kg=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Ag=kg.slice(0).reverse();function jg(e,t,n=!1){return new Fg({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 Mg(e,t){let n=t.milliseconds??0;for(let r of Ag.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Ng(e,t){let n=Mg(e,t)<0?-1:1;kg.reduceRight((r,i)=>{if(G(t[i]))return r;if(r){let a=t[r]*n,o=e[i][r],s=Math.floor(a/o);t[i]+=s*n,t[r]-=s*o*n}return i},null),kg.reduce((n,r)=>{if(G(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Pg(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Fg=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Og:Tg;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||W.create(),this.conversionAccuracy=t?`longterm`:`casual`,this.invalid=e.invalid||null,this.matrix=n,this.isLuxonDuration=!0}static fromMillis(t,n){return e.fromObject({milliseconds:t},n)}static fromObject(t,n={}){if(typeof t!=`object`||!t)throw new If(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:$m(t,e.normalizeUnit),loc:W.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Tm(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new If(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=gg(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]=vg(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static invalid(t,n=null){if(!t)throw new If(`need to specify a reason the Duration is invalid`);let r=t instanceof cm?t:new cm(t,n);if(sm.throwOnInvalid)throw new Nf(r);return new e({invalid:r})}static normalizeUnit(e){let t={year:`years`,years:`years`,quarter:`quarters`,quarters:`quarters`,month:`months`,months:`months`,week:`weeks`,weeks:`weeks`,day:`days`,days:`days`,hour:`hours`,hours:`hours`,minute:`minutes`,minutes:`minutes`,second:`seconds`,seconds:`seconds`,millisecond:`milliseconds`,milliseconds:`milliseconds`}[e&&e.toLowerCase()];if(!t)throw new Ff(e);return t}static isDuration(e){return e&&e.isLuxonDuration||!1}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}toFormat(e,t={}){let n={...t,floor:t.round!==!1&&t.floor!==!1};return this.isValid?Sh.create(this.loc,n).formatDurationFromString(this,e):Cg}toHuman(e={}){if(!this.isValid)return Cg;let t=e.showZeros!==!1,n=kg.map(n=>{let r=this.values[n];return G(r)||r===0&&!t?null:this.loc.numberFormatter({style:`unit`,unitDisplay:`long`,...e,unit:n.slice(0,-1)}).format(r)}).filter(e=>e);return this.loc.listFormatter({type:`conjunction`,style:e.listStyle||`narrow`,...e}).format(n)}toObject(){return this.isValid?{...this.values}:{}}toISO(){if(!this.isValid)return null;let e=`P`;return this.years!==0&&(e+=this.years+`Y`),(this.months!==0||this.quarters!==0)&&(e+=this.months+this.quarters*3+`M`),this.weeks!==0&&(e+=this.weeks+`W`),this.days!==0&&(e+=this.days+`D`),(this.hours!==0||this.minutes!==0||this.seconds!==0||this.milliseconds!==0)&&(e+=`T`),this.hours!==0&&(e+=this.hours+`H`),this.minutes!==0&&(e+=this.minutes+`M`),(this.seconds!==0||this.milliseconds!==0)&&(e+=Hm(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},B_.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?Mg(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 kg)(Pm(n.values,e)||Pm(this.values,e))&&(r[e]=n.get(e)+this.get(e));return jg(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]=Qm(e(this.values[n],n));return jg(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...$m(t,e.normalizeUnit)};return jg(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 jg(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Ng(this.matrix,e),jg(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Pg(this.normalize().shiftToAll().toObject());return jg(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 kg)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;Tm(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Tm(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 Ng(this.matrix,n),jg(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 jg(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Pg(this.values);return jg(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 kg)if(!t(this.values[n],e.values[n]))return!1;return!0}},Ig=`Invalid Interval`;function Lg(e,t){return!e||!e.isValid?Rg.invalid(`missing or invalid start`):!t||!t.isValid?Rg.invalid(`missing or invalid end`):t<e?Rg.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 Rg=class e{constructor(e){this.s=e.start,this.e=e.end,this.invalid=e.invalid||null,this.isLuxonInterval=!0}static invalid(t,n=null){if(!t)throw new If(`need to specify a reason the Interval is invalid`);let r=t instanceof cm?t:new cm(t,n);if(sm.throwOnInvalid)throw new Mf(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=V_(t),i=V_(n);return Lg(r,i)??new e({start:r,end:i})}static after(t,n){let r=Fg.fromDurationLike(n),i=V_(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Fg.fromDurationLike(n),i=V_(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=B_.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=B_.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Fg.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Fg.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(V_).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=Fg.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()})`:Ig}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`:`Interval { Invalid, reason: ${this.invalidReason} }`}toLocaleString(e=Bf,t={}){return this.isValid?Sh.create(this.s.loc.clone(t),e).formatInterval(this):Ig}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Ig}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Ig}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Ig}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Ig}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Fg.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},zg=class{static hasDST(e=sm.defaultZone){let t=B_.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return _p.isValidZone(e)}static normalizeZone(e){return Gp(e,sm.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||W.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||W.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||W.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||W.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return W.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return W.create(t,null,`gregory`).eras(e)}static features(){return{relative:km(),localeWeek:Am()}}};function Bg(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Fg.fromMillis(r).as(`days`))}function Vg(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=Bg(e,t);return(n-n%7)/7}],[`days`,Bg]],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 Hg(e,t,n,r){let[i,a,o,s]=Vg(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=Fg.fromObject(a,r);return l.length>0?Fg.fromMillis(c,r).shiftTo(...l).plus(u):u}var Ug=`missing Intl.DateTimeFormat.formatToParts support`;function K(e,t=e=>e){return{regex:e,deser:([e])=>t(Yp(e))}}var Wg=`[ \xA0]`,Gg=new RegExp(Wg,`g`);function Kg(e){return e.replace(/\./g,`\\.?`).replace(Gg,Wg)}function qg(e){return e.replace(/\./g,``).replace(Gg,` `).toLowerCase()}function Jg(e,t){return e===null?null:{regex:RegExp(e.map(Kg).join(`|`)),deser:([n])=>e.findIndex(e=>qg(n)===qg(e))+t}}function Yg(e,t){return{regex:e,deser:([,e,t])=>Zm(e,t),groups:t}}function Xg(e){return{regex:e,deser:([e])=>e}}function Zg(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function Qg(e,t){let n=Qp(t),r=Qp(t,`{2}`),i=Qp(t,`{3}`),a=Qp(t,`{4}`),o=Qp(t,`{6}`),s=Qp(t,`{1,2}`),c=Qp(t,`{1,3}`),l=Qp(t,`{1,6}`),u=Qp(t,`{1,9}`),d=Qp(t,`{2,4}`),f=Qp(t,`{4,6}`),p=e=>({regex:RegExp(Zg(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return Jg(t.eras(`short`),0);case`GG`:return Jg(t.eras(`long`),0);case`y`:return K(l);case`yy`:return K(d,Ym);case`yyyy`:return K(a);case`yyyyy`:return K(f);case`yyyyyy`:return K(o);case`M`:return K(s);case`MM`:return K(r);case`MMM`:return Jg(t.months(`short`,!0),1);case`MMMM`:return Jg(t.months(`long`,!0),1);case`L`:return K(s);case`LL`:return K(r);case`LLL`:return Jg(t.months(`short`,!1),1);case`LLLL`:return Jg(t.months(`long`,!1),1);case`d`:return K(s);case`dd`:return K(r);case`o`:return K(c);case`ooo`:return K(i);case`HH`:return K(r);case`H`:return K(s);case`hh`:return K(r);case`h`:return K(s);case`mm`:return K(r);case`m`:return K(s);case`q`:return K(s);case`qq`:return K(r);case`s`:return K(s);case`ss`:return K(r);case`S`:return K(c);case`SSS`:return K(i);case`u`:return Xg(u);case`uu`:return Xg(s);case`uuu`:return K(n);case`a`:return Jg(t.meridiems(),0);case`kkkk`:return K(a);case`kk`:return K(d,Ym);case`W`:return K(s);case`WW`:return K(r);case`E`:case`c`:return K(n);case`EEE`:return Jg(t.weekdays(`short`,!1),1);case`EEEE`:return Jg(t.weekdays(`long`,!1),1);case`ccc`:return Jg(t.weekdays(`short`,!0),1);case`cccc`:return Jg(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return Yg(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return Yg(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return Xg(/[a-z_+-/]{1,256}?/i);case` `:return Xg(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:Ug};return m.token=e,m}var $g={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 e_(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=$g[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function t_(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function n_(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Pm(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 r_(e){let t=e=>{switch(e){case`S`:return`millisecond`;case`s`:return`second`;case`m`:return`minute`;case`h`:case`H`:return`hour`;case`d`:return`day`;case`o`:return`ordinal`;case`L`:case`M`:return`month`;case`y`:return`year`;case`E`:case`c`:return`weekday`;case`W`:return`weekNumber`;case`k`:return`weekYear`;case`q`:return`quarter`;default:return null}},n=null,r;return G(e.z)||(n=_p.create(e.z)),G(e.Z)||(n||=new Up(e.Z),r=e.Z),G(e.q)||(e.M=(e.q-1)*3+1),G(e.h)||(e.h<12&&e.a===1?e.h+=12:e.h===12&&e.a===0&&(e.h=0)),e.G===0&&e.y&&(e.y=-e.y),G(e.u)||(e.S=Vm(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var i_=null;function a_(){return i_||=B_.fromMillis(1555555555555),i_}function o_(e,t){if(e.literal)return e;let n=d_(Sh.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function s_(e,t){return Array.prototype.concat(...e.map(e=>o_(e,t)))}var c_=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=s_(Sh.parseFormat(t),e),this.units=this.tokens.map(t=>Qg(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=t_(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=n_(e,this.regex,this.handlers),[r,i,a]=n?r_(n):[null,null,void 0];if(Pm(n,`a`)&&Pm(n,`H`))throw new Pf(`Can't include meridiem when specifying 24-hour format`);return{input:e,tokens:this.tokens,regex:this.regex,rawMatches:t,matches:n,result:r,zone:i,specificOffset:a}}else return{input:e,tokens:this.tokens,invalidReason:this.invalidReason}}get isValid(){return!this.disqualifyingUnit}get invalidReason(){return this.disqualifyingUnit?this.disqualifyingUnit.invalidReason:null}};function l_(e,t,n){return new c_(e,n).explainFromTokens(t)}function u_(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=l_(e,t,n);return[r,i,a,o]}function d_(e,t){if(!e)return null;let n=Sh.create(t,e).dtFormatter(a_()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>e_(t,e,i))}var f_=`Invalid DateTime`,p_=864e13;function m_(e){return new cm(`unsupported zone`,`the zone "${e.name}" is not supported`)}function h_(e){return e.weekData===null&&(e.weekData=gm(e.c)),e.weekData}function g_(e){return e.localWeekData===null&&(e.localWeekData=gm(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function __(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new B_({...n,...t,old:n})}function v_(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 y_(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 b_(e,t,n){return v_(Km(e),t,n)}function x_(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,Gm(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Fg.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]=v_(Km(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function S_(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=B_.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return B_.invalid(new cm(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function C_(e,t,n=!0){return e.isValid?Sh.create(W.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function w_(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=Rm(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=Rm(e.c.month),n===`month`)return i;i+=`-`}else if(i+=Rm(e.c.month),n===`month`)return i;return i+=Rm(e.c.day),i}function T_(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+=Rm(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=Rm(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=Rm(e.c.second))}else{if(c+=Rm(e.c.minute),o===`minute`)break;s&&(c+=Rm(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=Rm(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=Rm(Math.trunc(-e.o/60)),c+=`:`,c+=Rm(Math.trunc(-e.o%60))):(c+=`+`,c+=Rm(Math.trunc(e.o/60)),c+=`:`,c+=Rm(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var E_={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},D_={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},O_={ordinal:1,hour:0,minute:0,second:0,millisecond:0},k_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],A_=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],j_=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function M_(e){let t={year:`year`,years:`year`,month:`month`,months:`month`,day:`day`,days:`day`,hour:`hour`,hours:`hour`,minute:`minute`,minutes:`minute`,quarter:`quarter`,quarters:`quarter`,second:`second`,seconds:`second`,millisecond:`millisecond`,milliseconds:`millisecond`,weekday:`weekday`,weekdays:`weekday`,weeknumber:`weekNumber`,weeksnumber:`weekNumber`,weeknumbers:`weekNumber`,weekyear:`weekYear`,weekyears:`weekYear`,ordinal:`ordinal`}[e.toLowerCase()];if(!t)throw new Ff(e);return t}function N_(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return M_(e)}}function P_(e){if(R_===void 0&&(R_=sm.now()),e.type!==`iana`)return e.offset(R_);let t=e.name,n=z_.get(t);return n===void 0&&(n=e.offset(R_),z_.set(t,n)),n}function F_(e,t){let n=Gp(t.zone,sm.defaultZone);if(!n.isValid)return B_.invalid(m_(n));let r=W.fromObject(t),i,a;if(G(e.year))i=sm.now();else{for(let t of k_)G(e[t])&&(e[t]=E_[t]);let t=Cm(e)||wm(e);if(t)return B_.invalid(t);let r=P_(n);[i,a]=b_(e,r,n)}return new B_({ts:i,zone:n,loc:r,o:a})}function I_(e,t,n){let r=G(n.round)?!0:n.round,i=G(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Hm(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 L_(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 R_,z_=new Map,B_=class e{constructor(e){let t=e.zone||sm.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new cm(`invalid input`):null)||(t.isValid?null:m_(t));this.ts=G(e.ts)?sm.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=Tm(e.o)&&!e.old?e.o:t.offset(this.ts);r=y_(this.ts,a),n=Number.isNaN(r.year)?new cm(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||W.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]=L_(arguments),[n,r,i,a,o,s,c]=t;return F_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=L_(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Up.utcInstance,F_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Om(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Gp(n.zone,sm.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:W.fromObject(n)}):e.invalid(m_(i))}static fromMillis(t,n={}){if(Tm(t))return t<-p_||t>p_?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Gp(n.zone,sm.defaultZone),loc:W.fromObject(n)});throw new If(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(Tm(t))return new e({ts:t*1e3,zone:Gp(n.zone,sm.defaultZone),loc:W.fromObject(n)});throw new If(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Gp(n.zone,sm.defaultZone);if(!r.isValid)return e.invalid(m_(r));let i=W.fromObject(n),a=$m(t,N_),{minDaysInFirstWeek:o,startOfWeek:s}=bm(a,i),c=sm.now(),l=G(n.specificOffset)?r.offset(c):n.specificOffset,u=!G(a.ordinal),d=!G(a.year),f=!G(a.month)||!G(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new Pf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Pf(`Can't mix ordinal dates with month/day`);let ee=m||a.weekday&&!p,te,ne,re=y_(c,l);ee?(te=A_,ne=D_,re=gm(re,o,s)):u?(te=j_,ne=O_,re=vm(re)):(te=k_,ne=E_);let ie=!1;for(let e of te){let t=a[e];G(t)?ie?a[e]=ne[e]:a[e]=re[e]:ie=!0}let ae=(ee?xm(a,o,s):u?Sm(a):Cm(a))||wm(a);if(ae)return e.invalid(ae);let[oe,se]=b_(ee?_m(a,o,s):u?ym(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]=pg(e);return S_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=mg(e);return S_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=hg(e);return S_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(G(t)||G(n))throw new If(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=u_(W.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):S_(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]=Sg(e);return S_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new If(`need to specify a reason the DateTime is invalid`);let r=t instanceof cm?t:new cm(t,n);if(sm.throwOnInvalid)throw new jf(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=d_(e,W.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return s_(Sh.parseFormat(e),W.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){R_=void 0,z_.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?h_(this).weekYear:NaN}get weekNumber(){return this.isValid?h_(this).weekNumber:NaN}get weekday(){return this.isValid?h_(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?g_(this).weekday:NaN}get localWeekNumber(){return this.isValid?g_(this).weekNumber:NaN}get localWeekYear(){return this.isValid?g_(this).weekYear:NaN}get ordinal(){return this.isValid?vm(this.c).ordinal:NaN}get monthShort(){return this.isValid?zg.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?zg.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?zg.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?zg.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=Km(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=y_(s,a),u=y_(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[__(this,{ts:s}),__(this,{ts:c})]:[this]}get isInLeapYear(){return Um(this.year)}get daysInMonth(){return Gm(this.year,this.month)}get daysInYear(){return this.isValid?Wm(this.year):NaN}get weeksInWeekYear(){return this.isValid?Jm(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?Jm(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=Sh.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Up.instance(e),t)}toLocal(){return this.setZone(sm.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Gp(t,sm.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]=b_(r,n,t)}return __(this,{ts:e,zone:t})}else return e.invalid(m_(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return __(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=$m(e,N_),{minDaysInFirstWeek:n,startOfWeek:r}=bm(t,this.loc),i=!G(t.weekYear)||!G(t.weekNumber)||!G(t.weekday),a=!G(t.ordinal),o=!G(t.year),s=!G(t.month)||!G(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new Pf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Pf(`Can't mix ordinal dates with month/day`);let u;i?u=_m({...gm(this.c,n,r),...t},n,r):G(t.ordinal)?(u={...this.toObject(),...t},G(t.day)&&(u.day=Math.min(Gm(u.year,u.month),u.day))):u=ym({...vm(this.c),...t});let[d,f]=b_(u,this.o,this.zone);return __(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Fg.fromDurationLike(e);return __(this,x_(this,t))}minus(e){if(!this.isValid)return this;let t=Fg.fromDurationLike(e).negate();return __(this,x_(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Fg.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?Sh.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):f_}toLocaleString(e=Bf,t={}){return this.isValid?Sh.create(this.loc.clone(t),e).formatDateTime(this):f_}toLocaleParts(e={}){return this.isValid?Sh.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=M_(a);let o=e===`extended`,s=w_(this,o,a);return k_.indexOf(a)>=3&&(s+=`T`),s+=T_(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?w_(this,e===`extended`,M_(t)):null}toISOWeekDate(){return C_(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=M_(o),(r&&k_.indexOf(o)>=3?`T`:``)+T_(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return C_(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return C_(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?w_(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`)),C_(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():f_}[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 Fg.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=jm(t).map(Fg.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Hg(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?Rg.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),I_(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?I_(t.base||e.fromObject({},{zone:this.zone}),this,{...t,numeric:`auto`,units:[`years`,`months`,`days`],calendary:!0}):null}static min(...t){if(!t.every(e.isDateTime))throw new If(`min requires all arguments be DateTimes`);return Mm(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new If(`max requires all arguments be DateTimes`);return Mm(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return l_(W.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 c_(W.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(G(t)||G(n))throw new If(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=W.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new If(`fromFormatParser called with a locale of ${o}, but the format parser was created for ${n.locale}`);let{result:s,zone:c,specificOffset:l,invalidReason:u}=n.explainFromTokens(t);return u?e.invalid(u):S_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Bf}static get DATE_MED(){return Vf}static get DATE_MED_WITH_WEEKDAY(){return Hf}static get DATE_FULL(){return Uf}static get DATE_HUGE(){return Wf}static get TIME_SIMPLE(){return Gf}static get TIME_WITH_SECONDS(){return Kf}static get TIME_WITH_SHORT_OFFSET(){return qf}static get TIME_WITH_LONG_OFFSET(){return Jf}static get TIME_24_SIMPLE(){return Yf}static get TIME_24_WITH_SECONDS(){return Xf}static get TIME_24_WITH_SHORT_OFFSET(){return Zf}static get TIME_24_WITH_LONG_OFFSET(){return Qf}static get DATETIME_SHORT(){return $f}static get DATETIME_SHORT_WITH_SECONDS(){return ep}static get DATETIME_MED(){return tp}static get DATETIME_MED_WITH_SECONDS(){return np}static get DATETIME_MED_WITH_WEEKDAY(){return rp}static get DATETIME_FULL(){return ip}static get DATETIME_FULL_WITH_SECONDS(){return ap}static get DATETIME_HUGE(){return op}static get DATETIME_HUGE_WITH_SECONDS(){return sp}};function V_(e){if(B_.isDateTime(e))return e;if(e&&e.valueOf&&Tm(e.valueOf()))return B_.fromJSDate(e);if(e&&typeof e==`object`)return B_.fromObject(e);throw new If(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function H_(e){return nu(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof vd}function U_(e){return O(e)===``}function W_(e){return e instanceof ud}function G_(e){let t=wu(e);if(t!==null)return t;if(Zl(e)&&e instanceof L&&e.expression){let t=e.op?.value,n=wu(e.expression);if(n!==null)return t===`-`?-n:n}return null}function K_(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=G_(e);if(t!==null)return t;let n=O(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function q_(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=G_(e);if(t!==null)return Number.isInteger(t)?t:null;let n=O(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}const J_=[`true`,`yes`,`y`,`t`,`1`],Y_=[`false`,`no`,`n`,`f`,`0`];function X_(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 J_.includes(t)?!0:Y_.includes(t)?!1:null}if(nu(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=wu(e);if(t===0)return!1;if(t===1)return!0;let n=O(e)?.toLowerCase();if(n){if(J_.includes(n))return!0;if(Y_.includes(n))return!1}return null}function Z_(e){if(e==null)return null;if(typeof e==`string`)return e;let t=D(e);return t?h(t):O(e)??null}function Q_(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=O(e)??null??K_(e)??X_(e);return t===null?null:t.toString()}var $_=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],ev=[`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`],tv=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function nv(e){if(e==null)return null;let t=typeof e==`string`?e:O(e)??null;if(t===null)return null;for(let e of tv){let n=B_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of $_){let n=B_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of ev){let n=B_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=B_.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 rv(e,t){let n=e.type(t),r=e.default(t);return{name:e.name??``,pk:e.pk(t),unique:e.unique(t),increment:e.increment(t),notNull:e.nullable(t)===!1,dbdefault:r,typeName:n?.name??``}}function iv(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function av(e,t,n){return t.map((t,r)=>{let i=e[t]?.value;if(i==null&&n&&n[r]){let e=n[r];if(e?.dbdefault)return JSON.stringify(e.dbdefault.value)}return JSON.stringify(i)}).join(`|`)}function ov(e,t,n){return t.some((t,r)=>{let i=e[t]?.value;return i==null&&n&&n[r]&&n[r]?.dbdefault?!1:i==null})}function sv(e){return e.increment||Of(e.typeName)}function cv(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function lv(e,t,n){return n.length===1?cv(e,t,n[0]):`(${n.map(n=>cv(e,t,n)).join(`, `)})`}function uv(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function dv(e,t,n){let{token:r}=t,i=e.nodeAtPosition(r.filepath,r.start.offset)??e.parse.ast(r.filepath);return new Rl(y.INVALID_RECORDS_FIELD,n,i)}var fv=e=>e>1?`Composite PK`:`PK`;function pv(e,t,n,r){if(Nc(r.values))return[];let i=t.mergedColumns(e).map(t=>rv(t,e)),a=Fc(i,`name`),o=iv(r),s=vv(t,i,e),c=new Set(r.columns);return Cc(s,i=>mv(e,t,n,i,o,c,a,r))}function mv(e,t,n,r,i,a,o,s){let c=t.schema(e),l=t.name??``,u=_v(n,r,a,o,c,l,s);if(!Nc(u))return u;let d=so(r.map(e=>o[e])),f=d.every(e=>e&&sv(e)),[p,m]=g(i,e=>ov(e,r,d)),ee=f?[]:hv(e,p,r,c,l),te=gv(e,m,r,d,c,l);return[...ee,...te]}function hv(e,t,n,r,i){if(Nc(t))return[];let a=`NULL in ${fv(n.length)}: ${lv(r,i,n)} cannot be NULL`;return Cc(t,t=>n.map(n=>dv(e,t[n],a)))}function gv(e,t,n,r,i,a){return Cc(dc(Oc(t,e=>av(e,n,r)),e=>e.length>1),t=>{let r=fv(n.length),o=lv(i,a,n);return Cc(t,t=>{let i=`Duplicate ${r}: ${o} = ${uv(t,n)}`;return n.map(n=>dv(e,t[n],i))})})}function _v(e,t,n,r,i,a,o){let s=ic(t,Array.from(n));if(Nc(s))return[];let c=s.filter(e=>{let t=r[e];return!!(t&&!sv(t)&&!t.dbdefault)});if(Nc(c))return[];let l=`${fv(c.length)}: Column ${lv(i,a,c)} is missing from record and has no default value`;return o.values.map(()=>new Rl(y.INVALID_RECORDS_FIELD,l,e))}function vv(e,t,n){return[...t.filter(e=>e.pk).map(e=>[e.name]),...e.mergedIndexes(n).flatMap(e=>{let t=n.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(t)?t.filter(e=>e.pk).map(e=>e.columns.map(e=>e.value)):[]})]}var yv=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function bv(e,t,n){if(Nc(n.values))return[];let r=t.mergedColumns(e).map(t=>rv(t,e)),i=Fc(r,`name`),a=iv(n),o=t.schema(e),s=t.name??``;return Cc(xv(t,r,e),t=>Sv(e,a,t,so(t.map(e=>i[e])),o,s))}function xv(e,t,n){return[...t.filter(e=>e.unique).map(e=>[e.name]),...e.mergedIndexes(n).flatMap(e=>{let t=n.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(t)?t.filter(e=>e.unique).map(e=>e.columns.map(e=>e.value)):[]})]}function Sv(e,t,n,r,i,a){return Cc(dc(Oc(t.filter(e=>!ov(e,n,r)),e=>av(e,n,r)),e=>e.length>1),t=>{let r=yv(n.length),o=lv(i,a,n);return Cc(t,t=>{let i=`Duplicate ${r}: ${o} = ${uv(t,n)}`;return n.map(n=>dv(e,t[n],i))})})}function Cv(e,t,n,r){return Cc(t,t=>Ev(e,t,n,r))}function wv(e,t,n,r,i,a){if(!t.record||Nc(t.record.values))return[];let o=iv(t.record),s=n.record?iv(n.record):[],c=new Set(s.map(e=>av(e,i.fieldNames))),l=o.filter(e=>!ov(e,r.fieldNames)).filter(e=>{let t=av(e,r.fieldNames);return!c.has(t)}),u=t.tableSymbol.interpretedName(e,a),d=n.tableSymbol.interpretedName(e,a);return Cc(l,t=>{let n=lv(u.schema,u.name,r.fieldNames),a=lv(d.schema,d.name,i.fieldNames),o=`FK violation: ${n} = ${uv(t,r.fieldNames)} does not exist in ${a}`;return r.fieldNames.map(n=>dv(e,t[n],o))})}function Tv(e,t,n,r){let i=t.schemaName===`public`?null:t.schemaName;for(let a of e.values()){let{name:e,schema:o}=a.tableSymbol.interpretedName(n,r);if(e===t.tableName&&o===i)return a}}function Ev(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=Tv(n,i,e,r),s=Tv(n,a,e,r);return!o||!s?[]:Dv(e,o,s,i,a,r)}function Dv(e,t,n,r,i,a){let o=r.relation,s=i.relation;return o===`1`&&s===`1`||o===`*`&&s===`*`?[...wv(e,t,n,r,i,a),...wv(e,n,t,i,r,a)]:o===`*`&&s===`1`?wv(e,t,n,r,i,a):o===`1`&&s===`*`?wv(e,n,t,i,r,a):[]}var Ov=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:A(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.warnings.push(...this.validateRecords()),new n(this.db,this.errors,this.warnings)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof td)continue;let r=this.compiler.interpretSymbol(n,this.filepath);if(r.hasValue(t))continue;this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings());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 Lu);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Lu){n.push(t);continue}if(!(t instanceof td))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());let t=r.getValue();t&&this.pushElement(e,t)}let i=n instanceof Bu?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Bu?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}]};ff(this.db,e,o)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],n=new Set,r=new Map;for(let t of e){if(!(t instanceof Dd))continue;let e=t.table(this.compiler);if(!e)continue;let n=e.originalSymbol.intern(),i=r.get(n);i?i.count++:r.set(n,{count:1,tableName:e.name??``})}for(let i of e){let e=this.compiler.interpretMetadata(i,this.filepath);if(e.hasValue(t))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings());let a=e.getValue();if(a!==void 0)switch(i.kind){case xd.Ref:{let e=a,[t,r]=e.endpoints??[];if(t&&r){let e=[t.schemaName,t.tableName,t.fieldNames.join(`,`),r.schemaName,r.tableName,r.fieldNames.join(`,`)].join(`|`),a=[r.schemaName,r.tableName,r.fieldNames.join(`,`),t.schemaName,t.tableName,t.fieldNames.join(`,`)].join(`|`);if(n.has(e)||n.has(a)){this.errors.push(new b(y.SAME_ENDPOINT,`Ref with same endpoints already exists`,i.declaration));break}n.add(e)}this.db.refs.push(e);break}case xd.Records:if(i instanceof Dd){let e=i.table(this.compiler)?.originalSymbol.intern()??``,t=e?r.get(e):void 0;if(t&&t.count>1){this.errors.push(new b(y.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,i.declaration));break}}this.db.records.push(a);break;case xd.Project:this.db.project=a;break;default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof ed)||!t.isKind(j.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:qd.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 Lu))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(j.Table))continue;let t=e.originalSymbol;if(!(t instanceof Bu))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 Dd))continue;let i=r.table(this.compiler);if(!(i instanceof Bu))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...pv(this.compiler,i,r.declaration,o)),e.push(...bv(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(...Cv(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof wd),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 nd&&t.declaration===e.declaration)))continue;let l=Ud(s);if(!l)continue;let u=a instanceof Gu&&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:A(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:A(i.rightToken())};n.push({token:A(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case j.Table:this.db.tables.push(t);break;case j.Enum:this.db.enums.push(t);break;case j.TableGroup:this.db.tableGroups.push(t);break;case j.TablePartial:this.db.tablePartials.push(t);break;case j.StickyNote:this.db.notes.push(t);break;case j.DiagramView:this.db.diagramViews.push(t);break;default:break}}};const kv={nodeSymbol(t,r){return ou(r)?n.create(t.symbolFactory.create($u,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(j.Program))return n.create(e);if(!(i.declaration instanceof P))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(j.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return ou(r)?new uf(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof $u))return n.create(e);if(!(r.declaration instanceof P))return n.create(void 0);if(!Bd(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new Ov(t,r,i).interpret()}};var Av=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof z?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof R)return[];let t=e.body.filter(e=>e instanceof F);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},jv=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=A(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}=Au(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 z?t.body.body[0]?.callee:t.body?.callee,n=e?O(e):void 0;return n&&(this.project.note={value:ku(n),token:A(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()]=O(t.body.callee),[]}})}};const Mv={nodeMetadata(t,i){return T(i,r.Project)?n.create(new Od(i)):n.create(e)},bindNode(t,i){return T(i,r.Project)?n.create(void 0,new Av(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Od)||!(r.declaration instanceof F)?n.create(e):new jv(t,r.declaration,i).interpret()}};var Nv=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 z&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof P?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=Tu(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=vu(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=Eu(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new b(y.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new b(y.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new b(y.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 F)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!$l(e))return[];let i=vu(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=Eu(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new b(y.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n));continue}}return a}bindBody(e){if(!e)return[];if(e instanceof R)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof R),n=e.body.filter(e=>e instanceof F);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof fd?e.callee.elementList:[e.callee]).flatMap(Vd).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():[])}},Pv=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Fv(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=Iv(n,r.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getWarnings());let o=a.getValue();o.row&&i.push(o.row)}let a=A(this.element);return new n({schemaName:r.schemaName,tableName:r.tableName,columns:r.columns.map(e=>e.name??``),values:i,token:a},e,t)}};function Fv(e,n,i){let a=e.name,o=e.parent;if(o instanceof F&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Bu))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===k(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=Tu(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,j.Schema,u);e&&(p=n.lookupMembers(e,j.Table,l))}if(p||=n.lookupMembers(f,j.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Bu))return;let ee=m.mergedColumns(n),te=s.args.map(e=>ee.find(t=>t.name===k(e))).filter(Boolean),ne=m.interpretedName(n,i);return{schemaName:ne.schema,tableName:ne.name,columns:te}}function Iv(e,t,r){let i=[],a=[],o={},s=e.callee instanceof fd?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new b(y.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=Rv(n,l,r);i.push(...u.getErrors()),a.push(...u.getWarnings());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:A(n)})}return new n({row:c,columnNodes:o},i,a)}function Lv(e){return e instanceof ud&&e.value?.value||``}function Rv(e,t,r){let i=A(e),a=t.type(r),o=(a?.name??``).split(`(`)[0],s=!!a?.enumSymbol,c=t.increment(r),l=t.nullable(r)===!1,u=t.default(r),d=t.name??``,f=kf(o,s),p=Q_(e),m=p===null?Lv(e):p,ee=p===null?`expression`:f;if(e instanceof ud)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(H_(e)||U_(e)&&!Tf(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Of(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`NULL not allowed for non-nullable column '${d}' without default and increment`,e)]):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(j.EnumField)).map(e=>e.name).filter(Boolean):[],s=O(e);return s===void 0&&(s=C(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},[],[new Rl(y.INVALID_RECORDS_FIELD,`Invalid enum value for column '${d}'`,e)])}if(xf(o)||Sf(o)||Of(o)){let t=G_(e);if(t===null)return new n({value:m,type:ee,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${d}'`,e)]);if(xf(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`Invalid integer value ${t} for column '${d}': expected integer, got decimal`,e)]);let r=Sf(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Sf(o)&&r){let{precision:a,scale:o}=r,s=t.toString().split(`.`),c=s[0].replace(/^-/,``),l=s[1]||``,u=c.length+l.length,p=l.length;if(u>a)return new n({value:t,type:f,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`Numeric value ${t} for column '${d}' exceeds precision: expected at most ${a} total digits, got ${u}`,e)]);if(p>o)return new n({value:t,type:f,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`Numeric value ${t} for column '${d}' exceeds scale: expected at most ${o} decimal digits, got ${p}`,e)])}return new n({value:t,type:f,token:i},[],[])}if(wf(o)){let t=X_(e);return t===null?new n({value:m,type:ee,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${d}'`,e)]):new n({value:t,type:f,token:i},[],[])}if(Df(o)){let t=nv(e);return t===null?new n({value:m,type:ee,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`Invalid datetime value for column '${d}', expected valid datetime format (e.g., 'YYYY-MM-DD', 'HH:MM:SS', 'YYYY-MM-DD HH:MM:SS', 'MM/DD/YYYY', 'D MMM YYYY', or 'MMM D, YYYY')`,e)]):new n({value:t,type:f,token:i},[],[])}if(Tf(o)){let t=Q_(e);if(t===null)return new n({value:m,type:ee,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`Invalid string value for column '${d}'`,e)]);let r=a?.args?.length?Number(a.args[0]):void 0;if(r&&!Number.isNaN(r)){let a=r,o=new TextEncoder().encode(t).length;if(o>a)return new n({value:t,type:f,token:i},[],[new Rl(y.INVALID_RECORDS_FIELD,`String value for column '${d}' exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e)])}return new n({value:t,type:`string`,token:i},[],[])}return new n({value:m,type:ee,token:i},[],[])}const zv={nodeMetadata(t,i){if(!T(i,r.Records))return n.create(e);let a=i.parent;if(a&&T(a,r.Table))return n.create(new Dd(i));let o=i.name;return o instanceof V&&o.callee?n.create(new Dd(i)):n.create(e)},nodeReferee(i,a){if(!C(a))return n.create(e);let o=a.parentOfKind(F);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(dd);if(l?.parentNode===o)return Bv(i,o,a);let u=a.parentOfKind(V);return u?.parentNode===o&&l?.parentNode===u?Vv(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?Hv(i,c,a):Wv(i,c,a)},bindNode(t,i){return T(i,r.Records)?n.create(void 0,new Nv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Dd?r.declaration instanceof F?new Pv(t,r,i).interpret():n.create(void 0):n.create(e)}};function Bv(e,i,a){let o=i.parent;if(o instanceof F&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return Uv(e,n,a)}return new n(void 0)}function Vv(e,r,i){if(r.callee){let n;if(C(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=xu(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return Uv(e,n,i)}return new n(void 0)}function Hv(e,t,r){if(!C(r))return new n(void 0);let i=Eu(r)??``;if(!w(r.parentNode)){let a=e.lookupMembers(t,[j.Table,j.Schema],i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Hd(e,r);if(!a){let a=e.lookupMembers(t,[j.Table,j.Schema],i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(j.Schema)){let t=e.lookupMembers(a,[j.Table,j.Schema],i);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function Uv(e,t,r){if(!C(r))return new n(void 0);let i=Eu(r)??``,a=e.lookupMembers(t,j.Column,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function Wv(e,t,r){if(!C(r))return new n(void 0);let i=Eu(r)??``;if(!w(r.parentNode))return new n(void 0);let a=Hd(e,r);if(a){if(a.isKind(j.Schema)){let t=e.lookupMembers(a,[j.Enum,j.Schema],i);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(j.Enum)){let t=e.lookupMembers(a,j.EnumField,i);return t?n.create(t):new n(void 0,[new b(y.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(w(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,j.Schema,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,j.Enum,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var Gv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof P)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof R)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof R);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Vd).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():[])}},Kv=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=A(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()];return n.create(this.ref,e)}interpretName(){if(!(this.declarationNode instanceof F))return[];let e=[],t=D(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new b(y.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(Xc(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new b(y.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=Ud(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=A(this.metadata.leftToken()),l=A(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof F?[{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 F))return[];let u=bu(this.declarationNode)[0];if(u.args[0]){let e=x(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof sd?_u(t):k(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof sd?_u(n):k(n),this.ref.color=e.color?.length?ju(e.color?.at(0)?.value):void 0,this.ref.inactive=e.inactive?.length?!0:void 0}return[]}};function qv(e){let t=e.parent;for(;t;){if(t instanceof F&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}const Jv={nodeReferee(r,i){if(!C(i)&&!w(i)||!qv(i)||i.parentOfKind(I))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):Xv(r,o,i)},nodeMetadata(t,a){if(T(a,r.Ref)){let t=bu(a)[0];if(!(t instanceof R)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof cd)||!r.op?n.create(e):n.create(new Cd(a))}if(a instanceof I){if(!(a.name instanceof sd)||_u(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof F&&t.isKind(r.TablePartial)?n.create(new wd(a)):n.create(new Cd(a))}return n.create(e)},bindNode(t,i){return T(i,r.Ref)?n.create(void 0,new Gv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Cd?new Kv(t,r,i).interpret():n.create(e)}};function Yv(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Lu&&e.isPublicSchema())}function Xv(e,r,i){if(!C(i))return new n(void 0);let a=Eu(i)??``;if(!w(i.parentNode)){let r=i.parentNode;if(r&&w(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=w(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(j.Table)){let r=e.lookupMembers(c,j.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 b(y.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Hd(e,i);if(o){if(o.isKind(j.Schema)){let t=e.lookupMembers(o,[j.Table,j.Schema],a);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(j.Table)){let r=e.lookupMembers(o,j.Column,a);return r?n.create(r):new n(void 0,[new b(y.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(w(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,j.Schema,a);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Yv(e,r);if(t){let r=e.lookupMembers(t,j.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,j.Table,a);return o?n.create(o):new n(void 0,[new b(y.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}const Zv={visibleName(e,n){let r=n instanceof M?n:n.useSpecifierDeclaration instanceof ad?n.useSpecifierDeclaration:n.declaration;if(r instanceof ad&&n instanceof Iu&&r.getSymbolKind()!==n.kind&&(r=n.declaration),r)return e.nodeAlias(r).mapFiltered(e=>[e],t,void 0).getFiltered(t)||e.nodeFullname(r).getFiltered(t)}},Qv={nodeSymbol(r,i){if(!au(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===j.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(td,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:Zv.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new b(y.BINDING_ERROR,`Failed to resolve the import of ${a} '${(D(i.name)||[]).map(vy).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof td))return n.create(e);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!C(i)&&!ru(i))return n.create(e);let a=i.parentOfKind(ad);if(!a)return n.create(e);let o=a.name===i||w(a.name)&&a.name.rightExpression===i?a.getSymbolKind():j.Schema;if(o===void 0)return n.create(void 0);let s=D(i.parentOfKind(cd)),c=k(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(id);if(l?.importPath?.value===void 0)return n.create(void 0);let u=Ml(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new b(y.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new b(y.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toString()}. Does the file exist?`,i)]);let d=i.parentOfKind(cd)?.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 b(y.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=$v(r,u,c,o);return f?n.create(f):n.create(void 0,[new b(y.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toString()}`,i)])},bindNode(t,r){if(iu(r)){let e=[];if(r.importPath?.value){let n=Ml(r.filepath,r.importPath.value);n?t.layout.exists(n)||e.push(new b(y.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath)):e.push(new b(y.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 od?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):au(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 td))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 $v(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(j.Schema))return c;for(let t of o.reuses.selective)if(D(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(id);if(o?.importPath?.value){let s=$v(e,Ml(n,o.importPath.value),D(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=$v(e,t,r,i,a);if(n)return n}}function ey(e){if(e instanceof jl){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=ny(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof $u?ry(this,e,i):iy(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 ty(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof ad?Zv.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof ad&&r.getSymbolKind()===j.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 ny(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof id)||!e.specifiers||!e.importPath)continue;let n=Ml(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof hd?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof hd?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 ry(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[v,e.symbolFactory.create(Lu,{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(Lu,{name:i},s))}ay(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of sy(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Lu,{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 iy(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof F))continue;let i=ty(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(ed,{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(Lu,{name:i.schemaName,parent:n},n.filepath))}oy(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of cy(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Lu,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function ay(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==j.Schema)continue;let t=Zv.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Lu,{name:t},r))}}function oy(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==j.Schema)continue;let t=Zv.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(Lu,{name:o,parent:n},n.filepath))}}function sy(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=ny(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==j.Schema)continue;let n=Zv.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function cy(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=ny(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==j.Schema)continue;let n=Zv.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var ly=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof z?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof R)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof R);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 B){let e=x(h(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!ql(e.callee)))}tryToBindColumnType(e){let t=Su(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(S(e))return[];if(C(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&Nl.includes(t))return[]}let t=Su(e);if(!t){if(w(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 Vd(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():[])}},uy=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??A(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})),n.create(this.table,t)}interpretName(e){let{name:t,schemaName:n}=Au(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new b(y.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=Eu(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=x(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?ju(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:ku(O(n?.value)),token:A(n)},[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof R);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:ku(O(e.body instanceof z?e.body.body[0].callee:e.body.callee)),token:A(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:A(e)};i.name=k(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 b(y.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(j.Column)).length?[]:[new b(y.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>ql(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=Eu(e.callee),r.token=A(e);let o=Nu(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||!1,r.unique=a?.unique(this.compiler)||!1,r.increment=a?.increment(this.compiler)||void 0;let s=a?.nullable(this.compiler);r.not_null=s===void 0?void 0:!s,r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let c=this.compiler.nodeSettings(e).getFiltered(t)??{},l=this.compiler.parseFile(this.filepath).getValue().ast,u=this.compiler.nodeSymbol(l).getFiltered(t);return r.inline_refs=(c[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(u&&i.length>0&&!i.some(e=>e===u))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.checks=(c[i.Check]||[]).map(e=>({token:A(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()}};const dy={getDuplicateError(e,t,n){return new b(y.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new b(y.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new b(y.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},fy={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return T(a,r.Table)?new n(i.symbolFactory.create(Bu,{declaration:a,name:o},a.filepath)):E(a,r.Table)?ql(a.callee)?new n(i.symbolFactory.create(Ku,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Vu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(j.Table))return n.create(e);let a=i.declaration;if(!(a instanceof F))return new n([]);let o=bu(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(j.Column,j.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof F&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(j.Column)?(c.push(dy.getColumnDuplicateError(e.name,r)),c.push(dy.getColumnDuplicateError(e.name,n))):(c.push(dy.getPartialInjectionDuplicateError(e.name,r)),c.push(dy.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 R)||!ql(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=k(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new b(y.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(nd,{kind:j.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(j.Column)&&!(e instanceof nd)).map(e=>e.name));return new n(Gc([...s.filter(e=>!(e instanceof nd&&d.has(e.name)))].reverse(),e=>e.isKind(j.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(!su(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):C(o)&&o.parentNode instanceof L&&o.parentNode.op?.value===`~`?py(a,c,o):cu(o,1)?my(a,c,o):uu(o,i.Ref)?hy(a,c,o):cu(o,0)?n.create(e):gy(a,c,o)},bindNode(i,a){if(!T(a,r.Table))return n.create(e);let o=new ly(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Bu?r.declaration instanceof F?new uy(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function py(e,r,i){let a=k(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Lu&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,j.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,j.TablePartial,a);return s?n.create(s):new n(void 0,[new b(y.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function my(e,t,r){if(!C(r))return new n(void 0);let i=Eu(r)??``;if(!w(r.parentNode))return n.create(e.lookupMembers(t,j.Enum,i));let a=Hd(e,r);if(a){if(a.isKind(j.Schema)){let t=hu(r),o=e.lookupMembers(a,t?j.Enum:j.Schema,i);return o?n.create(o):new n(void 0,[new b(y.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,j.Schema,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function hy(e,i,a){if(!C(a))return new n(void 0);let o=Eu(a)??``;if(!w(a.parentNode)){let s=a.parent,c=s instanceof F&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,j.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,j.Column,o);return l?n.create(l):new n(void 0,[new b(y.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}let s=Hd(e,a);if(s){if(s.isKind(j.Schema)){let t=e.lookupMembers(s,[j.Table,j.Schema],o);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(j.Table)){let t=e.lookupMembers(s,j.Column,o);return t?n.create(t):new n(void 0,[new b(y.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(w(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,j.Schema,o);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,j.Table,o);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function gy(e,t,r){if(!C(r))return new n(void 0);let i=Eu(r)??``;if(!w(r.parentNode))return Nl.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,j.Enum,i));let a=Hd(e,r);if(a){if(a.isKind(j.Schema)){let t=e.lookupMembers(a,[j.Enum,j.Schema],i);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(j.Enum)){let t=e.lookupMembers(a,j.EnumField,i);return t?n.create(t):new n(void 0,[new b(y.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(w(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,j.Schema,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,j.Enum,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function _y(e){return e?e.split(``).every(e=>zl(e)||Bl(e))&&!Bl(e[0]):!1}function vy(e){return _y(e)?e:`"${by(e)}"`}function yy(e){let t=``,n=0,r={n:`
|
|
5
|
-
`,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function
|
|
6
|
-
`:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function xy(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`'${by(e)}'`;let{value:t,type:n}=e;if(t==null||wf(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(wf(n)){let e=X_(t);return e===null?`\`${t}\``:e?`true`:`false`}if(Cf(n)){let e=K_(t);return e===null?`\`${t}\``:String(e)}if(Df(n)){let e=nv(t);return e===null?`\`${t}\``:`'${by(e)}'`}let r=Q_(t);return r===null?`\`${t}\``:`'${by(r)}'`}function Sy(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?yy(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function Cy(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 wy(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 Lu&&n.isKind(j.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)}var Ty=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof z?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof R)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof R);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Vd).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof td?[...r.getErrors(),new b(y.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():[])}},Ey=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=A(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=Au(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new b(y.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 R);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:ku(O(e.body instanceof z?e.body.body[0].callee:e.body.callee)),token:A(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(j.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=D(e.callee);return i.length>2&&n.push(new b(y.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=x(e).getValue();this.tableGroup.color=t.color?.length?ju(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:ku(O(n?.value)),token:A(n)},[]}};const Dy={getDuplicateError(e,t,n){return new b(y.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new b(y.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Oy={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return T(a,r.TableGroup)?new n(i.symbolFactory.create(Hu,{declaration:a,name:s},a.filepath)):E(a,r.TableGroup)?new n(i.symbolFactory.create(Uu,{declaration:a,name:o?.map(vy).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(j.TableGroup)){let e=i.declaration;if(!(e instanceof F))return new n([]);let a=bu(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(j.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof F&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Dy.getFieldDuplicateError(e.name,r)),s.push(Dy.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(j.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!C(a)||!su(a,r.TableGroup)||a.parent&&lu(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):ky(i,s,a)},bindNode(i,a){if(!T(a,r.TableGroup))return n.create(e);let o=new Ty(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!T(o,r.TableGroup)||!(i instanceof Hu)?n.create(e):Bd(t,o)?new Ey(t,i,a).interpret():n.create(void 0)}};function ky(e,r,i){let a=Eu(i)??``;if(!w(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Lu&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,j.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,j.Table,a);return s?n.create(s):new n(void 0,[new b(y.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Hd(e,i);if(o){if(o.isKind(j.Schema)){let t=e.lookupMembers(o,[j.Table,j.Schema],a);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,j.Schema,a);return s?n.create(s):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var Ay=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof z?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof R)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof R);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 B){let e=x(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=Su(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return Vd(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():[])}},jy=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??A(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}=Au(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=x(e).getValue(),n=_c(t[i.HeaderColor]);this.tablePartial.headerColor=n?ju(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:ku(O(r?.value)),token:A(r)},[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof R);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:ku(O(e.body instanceof z?e.body.body[0].callee:e.body.callee)),token:A(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=Eu(e.callee)??``,r.token=A(e);let o=Nu(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||void 0,r.unique=a?.unique(this.compiler)||void 0,r.increment=a?.increment(this.compiler)||void 0;let s=a?.nullable(this.compiler);r.not_null=s===void 0?void 0:!s,r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let c=this.compiler.nodeSettings(e).getFiltered(t)??{},l=this.compiler.parseFile(this.filepath).getValue().ast,u=this.compiler.nodeSymbol(l).getFiltered(t);return r.inline_refs=(c[i.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!(n instanceof wd))return[];let r=n.owners(this.compiler);if(u&&r.length>0&&!r.some(e=>e===u))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:A(n.rightToken())}}),r.checks=(c[i.Check]||[]).map(e=>({token:A(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()}};const My={getDuplicateError(e,t,n){return new b(y.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},Ny={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return T(a,r.TablePartial)?new n(i.symbolFactory.create(Gu,{declaration:a,name:o},a.filepath)):E(a,r.TablePartial)?new n(i.symbolFactory.create(Vu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(j.TablePartial)){let e=a.declaration;if(!(e instanceof F))return new n([]);let r=bu(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(j.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof F&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(dy.getColumnDuplicateError(t,r)),s.push(dy.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(j.Column)&&T(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!C(o)&&!w(o)||!su(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):cu(o,1)?Py(a,c,o):uu(o,i.Ref)?Fy(a,c,o):Iy(a,c,o)},bindNode(i,a){if(!T(a,r.TablePartial))return n.create(e);let o=new Ay(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 Gu?r.declaration instanceof F?new jy(t,r,i).interpret():n.create(void 0):n.create(e)}};function Py(e,t,r){if(!C(r))return new n(void 0);let i=Eu(r)??``;if(!w(r.parentNode))return n.create(e.lookupMembers(t,j.Enum,i));let a=Hd(e,r);if(a){if(a.isKind(j.Schema)){let t=e.lookupMembers(a,[j.Enum,j.Schema],i);return t?n.create(t):new n(void 0,[new b(y.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,j.Schema,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Fy(e,i,a){if(!C(a))return new n(void 0);let o=Eu(a)??``;if(!w(a.parentNode)){let s=a.parent;if(s instanceof F&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,j.Column,o);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,j.Column,o);return c?n.create(c):new n(void 0,[new b(y.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Hd(e,a);if(s){if(s.isKind(j.Schema)){let t=e.lookupMembers(s,[j.Table,j.Schema],o);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(j.Table)){let t=e.lookupMembers(s,j.Column,o);return t?n.create(t):new n(void 0,[new b(y.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(w(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,j.Schema,o);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,j.Table,o);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function Iy(e,t,r){if(!C(r))return new n(void 0);let i=Eu(r)??``;if(!w(r.parentNode))return Nl.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,j.Enum,i));let a=Hd(e,r);if(a){if(a.isKind(j.Schema)){let t=e.lookupMembers(a,[j.Enum,j.Schema],i);return t?n.create(t):new n(void 0,[new b(y.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(j.Enum)){let t=e.lookupMembers(a,j.EnumField,i);return t?n.create(t):new n(void 0,[new b(y.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(w(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,j.Schema,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,j.Enum,i);return a?n.create(a):new n(void 0,[new b(y.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}const Ly={symbolMembers(r,i){if(!i.isKind(j.Schema)||!(i instanceof Lu))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=zy(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...By(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...Hy(r,i,e,t,c));for(let e of o.uses.selective){let n=zy(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...By(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...Hy(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(j.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(j.TableGroup)))}}for(let t of e)u.push(...Wy(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof td&&e.isKind(j.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(j.Schema))continue;let t=e instanceof td?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof F&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(Ry(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function Ry(e,t,n,r){switch(e){case j.Table:return dy.getDuplicateError(t,n,r);case j.Enum:return nf.getDuplicateError(t,n,r);case j.TablePartial:return My.getDuplicateError(t,n,r);case j.TableGroup:return Dy.getDuplicateError(t,n,r);case j.DiagramView:return Jd.getDuplicateError(t,n,r);default:return new b(y.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function zy(e,r,i,a){let o=ty(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(Lu,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function By(e,n,r,i=new Set){if(r.getSymbolKind()!==j.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(j.Schema))return[];let o=Zv.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:Vy(e,n,r,a,i)}function Vy(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(td,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(j.TableGroup)&&c.push(...Wy(e,n,t));for(let i of s.reuses.selective)if(c.push(...By(e,n,i,a)),ty(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(td,{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=Uy(e,t,n.qualifiedName);i&&c.push(...Vy(e,n,r,i,a))}return c}function Hy(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=Uy(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(td,{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(Lu,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=zy(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...By(e,n,r))}for(let{importPath:t}of d)l.push(...Hy(e,n,t,i,a,o));return l}function Uy(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 Wy(e,n,r){if(!r.isKind(j.TableGroup)||!(r instanceof td))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(j.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=D(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=Gy(e,c,i);l&&s.push(e.symbolFactory.create(td,{kind:j.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function Gy(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(j.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(j.Table)&&e.name===a)}var Ky=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof R)return[];let t=e.body.filter(e=>e instanceof F);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},qy=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=A(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return 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=x(e).getValue();return t.color?.length&&(this.note.color=ju(t.color.at(0)?.value)),[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof R);return t.length!==1||n.length>0?[new b(y.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=O(e.callee)??``;return this.note.content=ku(t),[]}};const Jy={nodeSymbol(i,a){return!T(a,r.Note)||!(a.parentNode instanceof P)?n.create(e):new n(i.symbolFactory.create(Wu,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(j.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return T(i,r.Note)?n.create(void 0,new Ky(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Wu?r.declaration instanceof F?new qy(t,r,i).interpret():n.create(void 0):n.create(e)}},Yy=[fy,rf,zv,sf,Nd,Jv,Mv,Oy,Ny,Jy,Qv,Ly,Yd,kv];function Xy(t,...r){for(let i of Yy){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function Zy(r){let i=Xy(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Qy(r){let i=Xy(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function $y(r){let i=Xy(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function eb(r){let i=Xy(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function tb(r){let i=Xy(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function nb(r,i){let a=Xy(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function rb(r,i){let a=Xy(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var ib=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 b(y.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof P?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new b(y.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new b(y.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new b(y.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof R)return[new b(y.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=g(e.body,e=>e instanceof R);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 B&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof ud))&&t.push(new b(y.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=x(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 b(y.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{S(t.value)||n.push(new b(y.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new b(y.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const ab={validateNode(t,i){if(!T(i,r.Checks))return n.create(e);let a=new ib(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return T(i,r.Checks)?i.name?new n(void 0,[new b(y.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return T(i,r.Checks)?i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return T(i,r.Checks)?i.attributeList?new n({},[new b(y.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}};var ob=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof F&&this.declarationNode.parent.isKind(r.Project)?[]:[new b(y.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e?[new b(y.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new b(y.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new b(y.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return[new b(y.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return S(e.callee)||t.push(new b(y.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 b(y.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function sb(e){return e instanceof F&&!!e.type?.value}const cb={validateNode(t,r){if(!sb(r))return n.create(e);let i=new ob(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return sb(r)?r.name?new n(void 0,[new b(y.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return sb(r)?r.alias?new n(void 0,[new b(y.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return sb(r)?r.attributeList?new n({},[new b(y.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}};var lb=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 F?[new b(y.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Gl(e)?[]:[new b(y.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new b(y.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new b(y.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=x(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new b(y.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof R)return{errors:[new b(y.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=g(e.body,e=>e instanceof R),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>tu(e.callee)?e.args.length>0?e.args.map(e=>new b(y.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new b(y.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 b(y.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(Kl(e))return t.push(new b(y.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof z))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof R&&tu(e.callee)),a=r.body.some(e=>e instanceof R&&!tu(e.callee));return i&&a&&n.push(new Rl(y.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 z))return t;let n=e.body.body.filter(e=>e instanceof R);for(let e of n)tu(e.callee)||(e.args.length>0||!D(e.callee))&&t.push(...e.args.map(e=>new b(y.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}};const ub={validateNode(t,i){if(!T(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new lb(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(T(i,r.DiagramView)){if(!i.name)return new n(void 0,[new b(y.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=D(i.name);return e?new n(e):new n(void 0)}else if(E(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=D(i.callee);return e?(e.length===1&&E(i,r.DiagramViewTables)&&e.unshift(v),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return T(i,r.DiagramView)?new n(void 0):n.create(e)}};var db=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof F?[new b(y.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof hd?[new b(y.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Ul(e)?[]:[new b(y.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new b(y.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new b(y.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new b(y.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof R)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof R);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new b(y.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!C(n.callee)&&t.push(new b(y.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];h(e)instanceof B?(t.push(...this.validateFieldSettings(h(e))),e.pop()):e[0]instanceof B&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new b(y.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=x(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 b(y.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{S(e.value)||n.push(new b(y.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new b(y.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():[])}};const fb={validateNode(t,i){return T(i,r.Enum)?n.create(void 0,new db(t,i).validate()):n.create(e)},nodeFullname(t,i){if(T(i,r.Enum)){if(!i.name)return new n(void 0,[new b(y.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Ul(i.name))return new n(void 0,[new b(y.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=D(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(E(i,r.Enum)){let e=k(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return T(i,r.Enum)?i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):E(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(T(a,r.Enum))return a.attributeList?new n({},[new b(y.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(E(a,r.Enum)){let e=[...a.args],t;if(h(e)instanceof B?t=h(e):e[0]instanceof B&&(t=e[0]),!t)return new n({});let r=x(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 b(y.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{S(e.value)||o.push(new b(y.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new b(y.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}};var pb=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 b(y.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof P?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new b(y.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new b(y.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new b(y.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof R)return[new b(y.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=g(e.body,e=>e instanceof R);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 B&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof V;)e.argumentList&&Cu(e.argumentList)===void 0&&t.push(new b(y.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;Cu(e)===void 0&&t.push(new b(y.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=x(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 b(y.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{S(t.value)||n.push(new b(y.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new b(y.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new b(y.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new b(y.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{C(e.value)||n.push(new b(y.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new b(y.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const mb={validateNode(t,i){return T(i,r.Indexes)?n.create(void 0,new pb(t,i).validate()):n.create(e)},nodeFullname(t,i){return T(i,r.Indexes)?i.name?new n(void 0,[new b(y.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):E(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return T(i,r.Indexes)?i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):E(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(T(a,r.Indexes))return a.attributeList?new n({},[new b(y.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(E(a,r.Indexes)){let e=[a.callee,...a.args],t;if(h(e)instanceof B&&(t=h(e)),!t)return new n({});let r=x(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 b(y.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{S(t.value)||o.push(new b(y.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 b(y.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new b(y.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 b(y.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{C(e.value)||o.push(new b(y.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new b(y.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}};var hb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return!(e instanceof P)&&!(e instanceof F&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project))?[new b(y.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 b(y.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof P}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new b(y.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=x(e),n=t.getErrors();return Tc(t.getValue(),(e,t)=>{switch(t){case i.Color:e.length>1&&n.push(...e.map(e=>new b(y.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{let t=nu(e.value)&&e.value.expression.variable.value.toLowerCase()===`none`;!Yl(e.value)&&!t&&n.push(new b(y.INVALID_NOTE_SETTING_VALUE,`'color' must be a color literal or 'none'`,e.value||e.name))});break;default:n.push(...e.map(e=>new b(y.UNKNOWN_NOTE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof R)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof R);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new b(y.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new b(y.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),S(e[0].callee)||t.push(new b(y.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 b(y.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():[])}};const gb={validateNode(t,i){return T(i,r.Note)?n.create(void 0,new hb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!T(i,r.Note))return n.create(e);if(!(i.parent instanceof P))return i.name?new n(void 0,[new b(y.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new b(y.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof hd)return new n(void 0,[new b(y.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=D(i.name);return a===void 0?new n(void 0,[new b(y.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return T(i,r.Note)?i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return T(i,r.Note)?i.attributeList?new n({},[new b(y.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}};var _b=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)}};const vb={validateNode(t,r){return ou(r)?n.create(void 0,new _b(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return ou(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return ou(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return ou(r)?new n({}):n.create(e)}};var yb=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 F?[new b(y.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Gl(e)?new n(D(e)):new n(void 0,[new b(y.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 b(y.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new b(y.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof R)return[new b(y.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof R);return[...t.map(e=>new b(y.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():[])}};const bb={validateNode(t,i){return T(i,r.Project)?n.create(void 0,new yb(t,i).validate()):n.create(e)},nodeFullname(t,i){return T(i,r.Project)?i.name?Gl(i.name)?new n(D(i.name)):new n(void 0,[new b(y.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):E(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return T(i,r.Project)&&i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):E(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return T(i,r.Project)?i.attributeList?new n({},[new b(y.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):E(i,r.Project)?new n({}):n.create(e)}};var xb=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 P||e instanceof F&&e.isKind(r.Table)?[]:[new b(y.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof hd?[new b(y.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof P?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof V))return[new b(y.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||!Ul(e.callee))&&t.push(new b(y.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!$l(e.argumentList))&&t.push(new b(y.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!$l(e)?[new b(y.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new b(y.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new b(y.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof R)return this.validateDataRow(e);let[t,n]=g(e.body,e=>e instanceof R);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 b(y.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof fd)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new b(y.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 b(y.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 vd||Zl(e)||S(e)||e instanceof ud)return!0;if(C(e)){let t=e.expression.variable.value.toLowerCase();return Nl.includes(t)}if(w(e)){let t=D(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const Sb={validateNode(t,i){return T(i,r.Records)?n.create(void 0,new xb(t,i).validate()):n.create(e)},nodeFullname(i,a){if(T(a,r.Records)){if(a.name instanceof hd)return new n(void 0,[new b(y.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof P){if(!(a.name instanceof V))return new n(void 0,[new b(y.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||!Ul(a.name.callee))&&e.push(new b(y.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!$l(a.name.argumentList))&&e.push(new b(y.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=D(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&&!$l(a.name)?new n(e,[new b(y.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return E(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return T(i,r.Records)?i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):E(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return T(i,r.Records)?i.attributeList?new n({},[new b(y.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,i.attributeList)]):new n({}):E(i,r.Records)?new n({}):n.create(e)}};var Cb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[]:[new b(y.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof hd?[new b(y.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:Gl(e)?[]:[new b(y.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new b(y.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new b(y.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof R)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof R);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new b(y.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 b(y.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!du(e.callee)&&t.push(new b(y.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&du(e.callee)){let n=Su(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=Su(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new b(y.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new b(y.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!fu(e.callee)&&t.push(new b(y.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(h(n)instanceof B){let e=this.validateFieldSettings(h(n));t.push(...e),n.pop()}else n[0]instanceof B&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new b(y.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return Tb(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function wb(e){if(!(C(e)&&e.expression.variable.kind!==_.QUOTED_STRING)&&!(e instanceof sd))return!1;let t;if(t=e instanceof sd?_u(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 Tb(e){let t=x(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 b(y.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{wb(t.value)||r.push(new b(y.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 b(y.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Yl(e.value)||r.push(new b(y.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 b(y.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new b(y.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new b(y.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}const Eb={validateNode(t,i){return T(i,r.Ref)?n.create(void 0,new Cb(t,i).validate()):n.create(e)},nodeFullname(t,i){return T(i,r.Ref)?i.name?Gl(i.name)?new n(D(i.name)):new n(void 0,[new b(y.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):E(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return T(i,r.Ref)?i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):E(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(T(i,r.Ref))return i.attributeList?new n({},[new b(y.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(E(i,r.Ref)){let e=[...i.args],t;return h(e)instanceof B?t=h(e):e[0]instanceof B&&(t=e[0]),t?Tb(t):new n({})}return n.create(e)}};var Db=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 F?[new b(y.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof yd?[new b(y.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof hd?[new b(y.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Ul(e)?[]:[new b(y.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new b(y.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Wl(e)?[]:[new b(y.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=x(e),n=t.getErrors();return Tc(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new b(y.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Yl(e.value)||n.push(new b(y.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&n.push(...e.map(e=>new b(y.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{S(e.value)||n.push(new b(y.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new b(y.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof R)return[new b(y.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof R);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 b(y.INVALID_COLUMN,`A column must have a type`,e.callee)),C(e.callee)||t.push(new b(y.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!eu(e.args[0])&&t.push(new b(y.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?(ql(e.callee)||t.push(new b(y.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 b(y.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof L&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){if(!e.slice(0,-1).every(nu)||!e.slice(-1).every(e=>nu(e)||e instanceof B))return e.map(e=>new b(y.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let t;h(e)instanceof B&&(t=e.pop());let n=x(t),r=n.getErrors(),a=n.getValue();e.forEach(e=>{let t=(k(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){r.push(new b(y.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}a[t]===void 0?a[t]=[e]:a[t].push(e)});let o=a[i.PK]||[],s=a[i.PrimaryKey]||[];return o.length>=1&&s.length>=1&&r.push(...[...o,...s].map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Tc(a,(e,t)=>{switch(t){case i.Note:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{S(e.value)||r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Ql(e.value)||r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=a[i.Null]||[];e.length>=1&&t.length>=1&&r.push(...[...e,...t].map(e=>new b(y.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Xl(e.value)||r.push(new b(y.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 ud||r.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new b(y.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),r}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new b(y.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Ob(e){let t=x(e),r=t.getErrors(),a=t.getValue();return Tc(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Yl(e.value)||r.push(new b(y.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{S(e.value)||r.push(new b(y.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new b(y.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function kb(e){if(!e.slice(0,-1).every(nu)||!e.slice(-1).every(e=>nu(e)||e instanceof B))return new n({},e.map(e=>new b(y.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 B&&(t=e.pop());let r=x(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(k(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Tc(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{S(e.value)||a.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Ql(e.value)||a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&a.push(new b(y.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 b(y.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 b(y.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 b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Xl(e.value)||a.push(new b(y.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 ud||a.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new b(y.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(o,a)}const Ab={validateNode(t,i){return T(i,r.Table)?n.create(void 0,new Db(t,i).validate()):n.create(e)},nodeFullname(t,i){if(T(i,r.Table)){if(!i.name)return new n(void 0,[new b(y.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof yd)return new n(void 0,[new b(y.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=D(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(E(i,r.Table)){if(ql(i.callee)){let e=k(i.callee.expression);return new n(e?[e]:void 0)}let e=k(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return T(i,r.Table)?i.alias?Wl(i.alias)?new n(k(i.alias)):new n(void 0,[new b(y.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):E(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return T(i,r.Table)?i.attributeList?Ob(i.attributeList):new n({}):E(i,r.Table)?kb(i.args.slice(1)):n.create(e)}};var jb=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 F?[new b(y.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof hd?[new b(y.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:Gl(e)?[]:[new b(y.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new b(y.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new b(y.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=x(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`color`:t.length>1&&n.push(...t.map(e=>new b(y.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Yl(e.value)||n.push(new b(y.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))});break;case`note`:t.length>1&&n.push(...t.map(e=>new b(y.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!S(e.value)).forEach(e=>{n.push(new b(y.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...t.map(t=>new b(y.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return n}validateBody(e){if(!e)return[];if(e instanceof R)return[new b(y.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof R);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&D(e.callee)===void 0&&t.push(new b(y.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 b(y.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 b(y.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Mb(e){let t=x(e),r=t.getErrors(),i=t.getValue(),a={};for(let[e,t]of Object.entries(i))switch(e){case`color`:t.length>1&&r.push(...t.map(e=>new b(y.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Yl(e.value)||r.push(new b(y.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))}),a[e]=t;break;case`note`:t.length>1&&r.push(...t.map(e=>new b(y.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!S(e.value)).forEach(e=>{r.push(new b(y.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))}),a[e]=t;break;default:r.push(...t.map(t=>new b(y.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return new n(a,r)}const Nb={validateNode(t,i){return T(i,r.TableGroup)?n.create(void 0,new jb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(T(i,r.TableGroup))return i.name?Gl(i.name)?new n(D(i.name)):new n(void 0,[new b(y.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new b(y.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(E(i,r.TableGroup)){let e=D(i.callee);return e?.length===1&&e.unshift(v),new n(e)}return n.create(e)},nodeAlias(t,i){return T(i,r.TableGroup)?i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):E(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return T(i,r.TableGroup)?Mb(i.attributeList):E(i,r.TableGroup)?new n({}):n.create(e)}};var Pb=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 F?[new b(y.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof hd?[new b(y.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:Gl(e)?[]:[new b(y.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new b(y.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new b(y.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=x(e),n=t.getErrors();return Tc(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new b(y.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Yl(e.value)||n.push(new b(y.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 b(y.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{S(e.value)||n.push(new b(y.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new b(y.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof R)return[new b(y.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof R);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 b(y.INVALID_COLUMN,`A column must have a type`,e.callee)),C(e.callee)||t.push(new b(y.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!eu(e.args[0])&&t.push(new b(y.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(nu)||!(nu(t)||t instanceof B))return e.map(e=>new b(y.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 B&&(n=e.pop());let r=x(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(k(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Tc(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{S(e.value)||a.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Ql(e.value)||a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&a.push(new b(y.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 b(y.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 b(y.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 b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&a.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Xl(e.value)||a.push(new b(y.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 ud||a.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new b(y.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),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 b(y.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Fb(e){let t=x(e),r=t.getErrors(),a=t.getValue();return Tc(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new b(y.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Yl(e.value)||r.push(new b(y.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 b(y.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{S(e.value)||r.push(new b(y.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new b(y.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Ib(e){let t=h(e);if(e.length>0&&(!e.slice(0,-1).every(nu)||!(nu(t)||t instanceof B)))return new n({},e.map(e=>new b(y.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 B&&(r=e.pop());let a=x(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(k(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Tc(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{S(e.value)||o.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Ql(e.value)||o.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&o.push(new b(y.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 b(y.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 b(y.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 b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&o.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof I&&e.value!==void 0&&o.push(new b(y.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 b(y.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Xl(e.value)||o.push(new b(y.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 ud||o.push(new b(y.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>o.push(new b(y.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(s,o)}const Lb={validateNode(t,i){return T(i,r.TablePartial)?n.create(void 0,new Pb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(T(i,r.TablePartial))return i.name?Gl(i.name)?new n(D(i.name)):new n(void 0,[new b(y.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new b(y.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(E(i,r.TablePartial)){let e=k(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return T(i,r.TablePartial)?i.alias?new n(void 0,[new b(y.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(k(i.alias)):E(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return T(i,r.TablePartial)?Fb(i.attributeList):E(i,r.TablePartial)?Ib(i.args.slice(1)):n.create(e)}};var Rb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof P?[]:[new b(y.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.importPath&&!jl.isRelative(this.declarationNode.importPath.value)&&e.push(new b(y.INVALID_USE_SPECIFIER_NAME,`Import path must be a relative path (starting with './' or '../')`,this.declarationNode.importPath)),this.declarationNode.specifiers instanceof hd)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 b(y.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Pu))||t.push(new b(y.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()]}};const zb={validateNode(t,r){return r instanceof id?n.create(void 0,new Rb(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!au(r))return n.create(e);let i=D(r.name);return!i||i.length===0?n.create(void 0,[new b(y.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Pu.TableGroup)&&i.length>1?n.create(i,[new b(y.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Pu.TablePartial)&&i.length>1?n.create(i,[new b(y.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Pu.Note)&&i.length>1?n.create(i,[new b(y.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Pu.Schema)&&i.unshift(v),new n(i))},nodeAlias(t,r){return au(r)?r.alias?Wl(r.alias)?new n(k(r.alias)):new n(void 0,[new b(y.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 id?n.create({}):n.create(e)}},Bb=[Ab,fb,Sb,mb,ab,Eb,bb,Nb,Lb,gb,ub,vb,zb,cb];function Vb(t,...r){for(let n of Bb){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function Hb(r){let i=Vb(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function Ub(r){let i=Vb(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function Wb(r){let i=Vb(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function Gb(r){let i=Vb(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var Kb=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},qb=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Jb(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}),qb&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function Yb(e,t,...n){return Jb(t,n)}function Xb(e){}var Zb;const Qb=`en`;var $b=!1,ex=!1,tx=!1,nx=!1,rx=!1,ix=!1,ax=!1,ox=void 0,sx=`en`,cx=void 0;const lx=typeof self==`object`?self:typeof global==`object`?global:{};var ux=void 0;lx.vscode!==void 0&&lx.vscode.process!==void 0?ux=lx.vscode.process:typeof process<`u`&&(ux=process);var dx=typeof(Zb=ux?.versions)?.electron==`string`&&ux?.type===`renderer`;if(typeof navigator==`object`&&!dx)cx=navigator.userAgent,$b=cx.indexOf(`Windows`)>=0,ex=cx.indexOf(`Macintosh`)>=0,(cx.indexOf(`Macintosh`)>=0||cx.indexOf(`iPad`)>=0||cx.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,tx=cx.indexOf(`Linux`)>=0,cx?.indexOf(`Mobi`),rx=!0,ox=(Yb({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),`en`),navigator.language;else if(typeof ux==`object`){$b=ux.platform===`win32`,ex=ux.platform===`darwin`,tx=ux.platform===`linux`,tx&&ux.env.SNAP&&ux.env.SNAP_REVISION,ux.env.CI||ux.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=ux.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.`);const fx=$b,px=ex,mx=rx&&typeof lx.importScripts==`function`,hx=cx,gx=typeof lx.postMessage==`function`&&!lx.importScripts,_x=(()=>{if(gx){let e=[];lx.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}),lx.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})(),vx=!!(hx&&hx.indexOf(`Chrome`)>=0),yx=!!(hx&&hx.indexOf(`Firefox`)>=0),bx=!!(!vx&&hx&&hx.indexOf(`Safari`)>=0),xx=!!(hx&&hx.indexOf(`Edg/`)>=0),Sx=!!(hx&&hx.indexOf(`Android`)>=0);var Cx;if(lx.vscode!==void 0&&lx.vscode.process!==void 0){let e=lx.vscode.process;Cx={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else Cx=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 fx?`win32`:px?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};const wx=Cx.cwd,Tx=Cx.env,Ex=Cx.platform;var Dx=65,Ox=97,kx=90,Ax=122,jx=46,Mx=47,Nx=92,Px=58,Fx=63,Ix=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 Lx(e,t){if(typeof e!=`object`||!e)throw new Ix(t,`Object`,e)}function Rx(e,t){if(typeof e!=`string`)throw new Ix(t,`string`,e)}var zx=Ex===`win32`;function q(e){return e===Mx||e===Nx}function Bx(e){return e===Mx}function Vx(e){return e>=Dx&&e<=kx||e>=Ox&&e<=Ax}function Hx(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=Mx;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==jx||i.charCodeAt(i.length-2)!==jx){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===jx&&s!==-1?++s:s=-1}return i}function Ux(e,t){Lx(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}const Wx={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],Rx(a,`path`),a.length===0)continue}else t.length===0?a=wx():(a=Tx[`=${t}`]||wx(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Nx)&&(a=`${t}\\`));let o=a.length,s=0,c=``,l=!1,u=a.charCodeAt(0);if(o===1)q(u)&&(s=1,l=!0);else if(q(u))if(l=!0,q(a.charCodeAt(1))){let e=2,t=e;for(;e<o&&!q(a.charCodeAt(e));)e++;if(e<o&&e!==t){let n=a.slice(t,e);for(t=e;e<o&&q(a.charCodeAt(e));)e++;if(e<o&&e!==t){for(t=e;e<o&&!q(a.charCodeAt(e));)e++;(e===o||e!==t)&&(c=`\\\\${n}\\${a.slice(t,e)}`,s=e)}}}else s=1;else Vx(u)&&a.charCodeAt(1)===Px&&(c=a.slice(0,2),s=2,o>2&&q(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=Hx(n,!r,`\\`,q),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){Rx(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return Bx(a)?`\\`:e;if(q(a))if(i=!0,q(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!q(e.charCodeAt(i));)i++;if(i<t&&i!==a){let o=e.slice(a,i);for(a=i;i<t&&q(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!q(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 Vx(a)&&e.charCodeAt(1)===Px&&(r=e.slice(0,2),n=2,t>2&&q(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?Hx(e.slice(n),!i,`\\`,q):``;return o.length===0&&!i&&(o=`.`),o.length>0&&q(e.charCodeAt(t-1))&&(o+=`\\`),r===void 0?i?`\\${o}`:o:i?`${r}\\${o}`:`${r}${o}`},isAbsolute(e){Rx(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return q(n)||t>2&&Vx(n)&&e.charCodeAt(1)===Px&&q(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];Rx(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`&&q(n.charCodeAt(0))){++i;let e=n.length;e>1&&q(n.charCodeAt(1))&&(++i,e>2&&(q(n.charCodeAt(2))?++i:r=!1))}if(r){for(;i<t.length&&q(t.charCodeAt(i));)i++;i>=2&&(t=`\\${t.slice(i)}`)}return Wx.normalize(t)},relative(e,t){if(Rx(e,`from`),Rx(t,`to`),e===t)return``;let n=Wx.resolve(e),r=Wx.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Nx;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Nx;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Nx;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Nx;)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===Nx&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Nx)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Nx?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)===Nx)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Nx&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=Wx.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Nx){if(t.charCodeAt(1)===Nx){let e=t.charCodeAt(2);if(e!==Fx&&e!==jx)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(Vx(t.charCodeAt(0))&&t.charCodeAt(1)===Px&&t.charCodeAt(2)===Nx)return`\\\\?\\${t}`;return e},dirname(e){Rx(e,`path`);let t=e.length;if(t===0)return`.`;let n=-1,r=0,i=e.charCodeAt(0);if(t===1)return q(i)?e:`.`;if(q(i)){if(n=r=1,q(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!q(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&q(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!q(e.charCodeAt(i));)i++;if(i===t)return e;i!==a&&(n=r=i+1)}}}}else Vx(i)&&e.charCodeAt(1)===Px&&(n=t>2&&q(e.charCodeAt(2))?3:2,r=n);let a=-1,o=!0;for(let n=t-1;n>=r;--n)if(q(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&&Rx(t,`ext`),Rx(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&Vx(e.charCodeAt(0))&&e.charCodeAt(1)===Px&&(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(q(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(q(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){Rx(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Px&&Vx(e.charCodeAt(0))&&(t=r=2);for(let s=e.length-1;s>=t;--s){let t=e.charCodeAt(s);if(q(t)){if(!a){r=s+1;break}continue}i===-1&&(a=!1,i=s+1),t===jx?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:Ux.bind(null,`\\`),parse(e){Rx(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 q(i)?(t.root=t.dir=e,t):(t.base=t.name=e,t);if(q(i)){if(r=1,q(e.charCodeAt(1))){let t=2,i=t;for(;t<n&&!q(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&q(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&!q(e.charCodeAt(t));)t++;t===n?r=t:t!==i&&(r=t+1)}}}}else if(Vx(i)&&e.charCodeAt(1)===Px){if(n<=2)return t.root=t.dir=e,t;if(r=2,q(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),q(i)){if(!c){o=l+1;break}continue}s===-1&&(c=!1,s=l+1),i===jx?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};var Gx=(()=>{if(zx){let e=/\\/g;return()=>{let t=wx().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>wx()})();const Kx={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:Gx();Rx(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Mx)}return t=Hx(t,!n,`/`,Bx),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(Rx(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Mx,n=e.charCodeAt(e.length-1)===Mx;return e=Hx(e,!t,`/`,Bx),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return Rx(e,`path`),e.length>0&&e.charCodeAt(0)===Mx},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];Rx(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:Kx.normalize(t)},relative(e,t){if(Rx(e,`from`),Rx(t,`to`),e===t||(e=Kx.resolve(e),t=Kx.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===Mx&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===Mx)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Mx?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Mx)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(Rx(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Mx,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Mx){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&&Rx(t,`ext`),Rx(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===Mx){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)===Mx){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Rx(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===Mx){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===jx?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:Ux.bind(null,`/`),parse(e){Rx(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Mx,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===Mx){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===jx?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};Kx.win32=Wx.win32=Wx,Kx.posix=Wx.posix=Kx;const qx=zx?Wx.normalize:Kx.normalize,Jx=zx?Wx.resolve:Kx.resolve,Yx=zx?Wx.relative:Kx.relative,Xx=zx?Wx.dirname:Kx.dirname,Zx=zx?Wx.basename:Kx.basename,Qx=zx?Wx.extname:Kx.extname,$x=zx?Wx.sep:Kx.sep;var eS=/^\w[\w\d+.-]*$/,tS=/^\//,nS=/^\/\//;function rS(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&&!eS.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!tS.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(nS.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 iS(e,t){return!e&&!t?`file`:e}function aS(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==oS&&(t=oS+t):t=oS;break}return t}var J=``,oS=`/`,sS=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,cS=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||J,this.authority=e.authority||J,this.path=e.path||J,this.query=e.query||J,this.fragment=e.fragment||J):(this.scheme=iS(e,a),this.authority=t||J,this.path=aS(this.scheme,n||J),this.query=r||J,this.fragment=i||J,rS(this,a))}get fsPath(){return mS(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=J),n===void 0?n=this.authority:n===null&&(n=J),r===void 0?r=this.path:r===null&&(r=J),i===void 0?i=this.query:i===null&&(i=J),a===void 0?a=this.fragment:a===null&&(a=J),t===this.scheme&&n===this.authority&&r===this.path&&i===this.query&&a===this.fragment?this:new uS(t,n,r,i,a)}static parse(e,t=!1){let n=sS.exec(e);return n?new uS(n[2]||J,vS(n[4]||J),vS(n[5]||J),vS(n[7]||J),vS(n[9]||J),t):new uS(J,J,J,J,J)}static file(e){let t=J;if(fx&&(e=e.replace(/\\/g,oS)),e[0]===oS&&e[1]===oS){let n=e.indexOf(oS,2);n===-1?(t=e.substring(2),e=oS):(t=e.substring(2,n),e=e.substring(n)||oS)}return new uS(`file`,t,e,J,J)}static from(e,t){return new uS(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=fx&&t.scheme===`file`?e.file(Wx.join(mS(t,!0),...n)).path:Kx.join(t.path,...n),t.with({path:r})}toString(e=!1){return hS(this,e)}toJSON(){return this}static revive(t){if(t){if(t instanceof e)return t;{let e=new uS(t);return e._formatted=t.external??null,e._fsPath=t._sep===lS?t.fsPath??null:null,e}}else return t}},lS=fx?1:void 0,uS=class extends cS{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=mS(this,!1),this._fsPath}toString(e=!1){return e?hS(this,!0):(this._formatted||=hS(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=lS),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}},dS={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 fS(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=dS[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 pS(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+=dS[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function mS(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,fx&&(n=n.replace(/\//g,`\\`)),n}function hS(e,t){let n=t?pS:fS,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=oS,r+=oS),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:fS(c,!1,!1)),r}function gS(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+gS(e.substr(3)):e}}var _S=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function vS(e){return e.match(_S)?e.replace(_S,e=>gS(e)):e}let Y=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}({}),X=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),yS=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 bS(e,t){return e.getOffsetAt(t)}function xS(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 SS=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=jl.fromUri(String(e.uri)),a=bS(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&&[N.PRIMARY_EXPRESSION,N.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=cS.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[]}},CS=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos;return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code,filepath:e.filepath}}getSeverityValue(e){return e===`error`?yS.Error:yS.Warning}},wS=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=jl.fromUri(String(r)),a=bS(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[N.ELEMENT_DECLARATION,N.FUNCTION_APPLICATION,N.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=cS.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 TS(e,t){return e>=t.start&&e<t.end}function ES(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 DS(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 od)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=k(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?k(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof hd&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof hd)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function OS(e,t,n,r,i,a){let o=DS(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:kS(Uc([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
|
|
7
|
-
`),removeRange:
|
|
8
|
-
`)}}function
|
|
4
|
+
`)}function vs(e){let t=O(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function ys(e){if(e instanceof sc&&e.expression instanceof ic&&e.expression.literal?.kind===v.COLOR_LITERAL)return e.expression.literal.value;if(Wo(e)&&A(e)?.toLowerCase()===`none`)return So}function bs(e){if(e){if(C(e)){let t=k(e);if(t!==void 0)return{value:t,type:`string`}}if(zo(e))return{type:`number`,value:gs(e)};if(Wo(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof ec&&e.value)return{value:e.value.value,type:`expression`};if(Go(e)){let t=ls(e)?.at(-1),n=t?A(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function xs(e,t){let r=``,i=null;if(t instanceof B){if(i=(t.argumentList?.elementList??[]).map(e=>zo(e)?hs(e):C(e)?k(e):A(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof B||t instanceof lc;)if(t instanceof B){if(r=`(${(t.argumentList?.elementList??[]).map(e=>zo(e)?hs(e):C(e)?k(e):A(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof lc){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}=vs(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new x(b.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}var M=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.StickyNote=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewTopLevelWildcard=`DiagramView top-level wildcard`,e.DiagramViewTable=`DiagramView table`,e.DiagramViewTableGroup=`DiagramView tablegroup`,e.DiagramViewNote=`DiagramView note`,e.DiagramViewSchema=`DiagramView schema`,e.Program=`Program`,e}({}),Ss={Table:`Table`,Enum:`Enum`,TableGroup:`TableGroup`,TablePartial:`TablePartial`,Note:`Note`,Schema:`Schema`},Cs=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},ws=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 j(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()}},Ts=class e extends ws{constructor({name:e,parent:t},n,r){super({kind:`Schema`},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===y}inNestedSchema(t,n){let r=this.members(t);if(r.some(e=>e.originalSymbol===n.originalSymbol))return!0;for(let i of r)if(i instanceof e&&i.inNestedSchema(t,n))return!0;return!1}},Es=class extends ws{constructor({declaration:e,name:t},n,r){super({kind:`Enum`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Ds=class extends ws{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=_s(k(i));if(a)return{value:a,token:j(r)}}},Os=class extends ws{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 Ws))}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=_s(k(i));if(a)return{value:a,token:j(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?ys(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===dc.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===dc.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===dc.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===dc.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof L)||!Fo(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===dc.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===dc.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=ys(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=_s(k(a));if(o)return{value:o,token:j(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},ks=class extends ws{constructor({declaration:e,name:t},n,r){super({kind:`Column`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}pk(e){if(!this.declaration)return!1;let n=e.nodeSettings(this.declaration).getFiltered(t);return!!(n?.[i.PK]?.length||n?.[i.PrimaryKey]?.length)}unique(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Unique]?.length:!1}nullable(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(n?.[i.NotNull]?.length)return!1;if(n?.[i.Null]?.length)return!0}increment(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Increment]?.length:!1}default(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t)?.[i.Default]?.at(0)?.value;if(n)return bs(n)}type(e){if(!(this.declaration instanceof L))return;let n=xs(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 Es?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===dc.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=_s(k(i));if(a)return{value:a,token:j(r)}}},As=class extends ws{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?ys(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=_s(k(i));if(a)return{value:a,token:j(r)}}},js=class extends ws{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}},Ms=class extends ws{constructor({declaration:e,name:t},n,r){super({kind:`Note`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Ns=class extends ws{constructor({declaration:e,name:t},n,r){super({kind:`TablePartial`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Ps=class extends ws{constructor({declaration:e,name:t},n,r){super({kind:`PartialInjection`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Fs=class extends ws{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Is=class extends ws{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}},Ls=class extends ws{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}},Rs=class extends ws{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}},zs=class extends ws{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}},Bs=class extends ws{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}},Vs=class extends ws{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 Ts&&r.inNestedSchema(e,t))return!0;return!1}},Hs=class extends ws{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}},Us=class extends ws{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(Js);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},Ws=class extends ks{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},Gs=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},N=class{constructor(e,t,n,r){this.id=e,this.kind=t,this.filepath=n;let i=r.find(e=>e!==void 0&&!Number.isNaN(e.start));i?(this.startPos=i.startPos,this.fullStart=i instanceof Va?Ka(i):i.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let a=[...r].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));a?(this.endPos=a.endPos,this.fullEnd=a instanceof Va?Ga(a):a.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}intern(){return`node@${this.filepath.intern()}:${this.id}`}get parent(){let e=this.parentNode;for(;e;){if(e instanceof P||e instanceof qs)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}},Ks=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}({}),qs=class extends N{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>`)}},Js=class extends N{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 Za(this.useKeyword)}},Ys=class extends N{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(M).find(t=>t.toLowerCase()===e)}},Xs=class extends N{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}},P=class e extends N{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,`<element-declaration>`,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof L||s instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.name=n,this.as=r,this.alias=i,this.attributeList=a,this.bodyColon=o,this.body=s}isKind(...e){return e.some(e=>this.type?.value.toLowerCase()===e)}getElementKind(){return Object.values(r).find(e=>this.isKind(e))}},Zs=class extends N{constructor({identifiers:e=[]},t,n){super(t,`<identifier-stream>`,n,e||[]),this.identifiers=e}},F=class extends N{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}},I=class extends N{constructor({op:e,expression:t},n,r){super(n,`<prefix-expression>`,r,[e,t]),this.op=e,this.expression=t}},Qs=class extends N{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}},$s=class extends N{constructor({op:e,expression:t},n,r){super(n,`<postfix-expression>`,r,[t,e]),this.op=e,this.expression=t}},ec=class extends N{constructor({value:e},t,n){super(t,`<function-expression>`,n,[e]),this.value=e}},L=class extends N{constructor({callee:e,args:t=[]},n,r){super(n,`<function-application>`,r,[e,...t]),this.callee=e,this.args=t}},R=class extends N{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}},z=class extends N{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,`<list-expression>`,a,[e,...uc(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},tc=class extends N{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,`<tuple-expression>`,a,[e,...uc(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},nc=class extends N{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,`<comma-expression>`,r,[...uc(e,t)]),this.elementList=e,this.commaList=t}},rc=class extends tc{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=`<group-expression>`}},B=class extends N{constructor({callee:e,argumentList:t},n,r){super(n,`<call-expression>`,r,[e,t]),this.callee=e,this.argumentList=t}},ic=class extends N{constructor({literal:e},t,n){super(t,`<literal>`,n,[e]),this.literal=e}},ac=class extends N{constructor({token:e},t,n){super(t,`<wildcard>`,n,[e]),this.token=e}},oc=class extends N{constructor({variable:e},t,n){super(t,`<variable>`,n,[e]),this.variable=e}},sc=class extends N{constructor({expression:e},t,n){super(t,`<primary-expression>`,n,[e]),this.expression=e}},cc=class extends N{constructor({prevToken:e},t,n){let r=Va.create(v.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,`<dummy>`,n,[r])}},lc=class extends N{constructor({expression:e,indexer:t},n,r){super(n,`<array>`,r,[e,t]),this.array=e,this.indexer=t}};function uc(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];let[n]=e,[r]=t;return(n.start<r.start?br(La(e,t)):br(La(t,e))).filter(e=>e!==null)}var dc=function(e){return e.Ref=`ref`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e}({}),fc=class e{static{this.id=0}constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}},pc=class extends fc{constructor(e){super(e),this.kind=`ref`}container(e){let n=this.declaration.parentOfKind(P);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof P){let t=cs(this.declaration)[0];if(!(t instanceof L))return[];let n=t.callee;return n instanceof Qs?yc(e,n.leftExpression):[]}if(this.declaration instanceof F){let n=this.declaration.parentOfKind(L);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof P){let t=cs(this.declaration)[0];if(!(t instanceof L))return[];let n=t.callee;return n instanceof Qs?yc(e,n.rightExpression):[]}if(this.declaration instanceof F){let t=this.declaration.value;return t instanceof I?yc(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof P){let t=cs(this.declaration)[0];if(!(t instanceof L))return;let n=t.callee;return n instanceof Qs?bc(e,n.leftExpression):void 0}if(this.declaration instanceof F)return this.container(e)}rightTable(e){if(this.declaration instanceof P){let t=cs(this.declaration)[0];if(!(t instanceof L))return;let n=t.callee;return n instanceof Qs?bc(e,n.rightExpression):void 0}if(this.declaration instanceof F){let t=this.declaration.value;return t instanceof I?bc(e,t.expression)??this.container(e):void 0}}op(e){if(this.declaration instanceof P){let e=cs(this.declaration)[0];if(!(e instanceof L))return;let t=e.callee;return t instanceof Qs?t.op?.value:void 0}if(this.declaration instanceof F){let e=this.declaration.value;return e instanceof I?e.op?.value:void 0}}active(e){if(!(this.declaration instanceof P))return!0;let n=cs(this.declaration)[0];return n?!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length:!0}leftToken(){if(this.declaration instanceof P){let e=cs(this.declaration)[0];if(e instanceof L){let t=e.callee;if(t instanceof Qs&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof F){let e=this.declaration.parentOfKind(L);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof P){let e=cs(this.declaration)[0];if(e instanceof L){let t=e.callee;if(t instanceof Qs&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof F,this.declaration}owners(e){let n=this.leftTable(e),r=this.rightTable(e);if(!n||!r)return[];let i=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(i))&&t.inNestedSchema(e,n)&&t.inNestedSchema(e,r))}},mc=class extends fc{constructor(e){super(e),this.kind=`partial ref`}container(e){let n=this.declaration.parentOfKind(P);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof F))return[];let n=this.declaration.parentOfKind(L);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof F))return[];let t=this.declaration.value;return t instanceof I?yc(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof F)return this.container(e)}rightTable(e){if(!(this.declaration instanceof F))return;let t=this.declaration.value;if(t instanceof I)return bc(e,t.expression)??this.container(e)}op(e){if(!(this.declaration instanceof F))return;let t=this.declaration.value;if(t instanceof I)return t.op?.value}leftToken(){if(this.declaration instanceof F){let e=this.declaration.parentOfKind(L);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof F,this.declaration}owners(e){let n=this.leftTablePartial(e),r=this.rightTable(e);return!n||!r?[]:e.reachableFiles().flatMap(n=>e.nodeSymbol(e.parseFile(n).getValue().ast).getFiltered(t)||[]).filter(t=>t.inNestedSchema(e,n)&&t.inNestedSchema(e,r))}},hc=class extends fc{constructor(e){super(e),this.kind=`table checks`,this.ownerTable=e.parentNode?.parentOfKind(P)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},gc=class extends fc{constructor(e){super(e),this.kind=`indexes`,this.ownerTable=e.parentNode?.parentOfKind(P)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},_c=class extends fc{constructor(e){super(e),this.kind=`records`}table(e){let n=this.declaration,i=n.parent;if(i instanceof P&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof B))return;let o=ps(a);if(!o)return;let s=o.variables.at(-1);if(s)return e.nodeReferee(s).getFiltered(t)?.originalSymbol}owners(e){let n=this.table(e);return n?e.reachableFiles().flatMap(n=>e.nodeSymbol(e.parseFile(n).getValue().ast).getFiltered(t)||[]).filter(t=>t.inNestedSchema(e,n)):[]}},vc=class extends fc{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 yc(e,n){if(!n)return[];let r=us(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?[r]:[]}):[]}function bc(e,n){if(!n)return;let r=us(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)}var xc=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},Sc=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof R?new n(e.body.flatMap(e=>{if(!(e instanceof L))return[];let t=j(e),n=e.callee instanceof ec?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof z);return a&&(r=k(S(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}},Cc={nodeMetadata(t,i){if(E(i,r.Checks)){let t=i.parent;return!t||!E(t,r.Table)&&!E(t,r.TablePartial)?n.create(e):n.create(new hc(i))}return n.create(e)},bindNode(t,i){return E(i,r.Checks)?n.create(void 0,new xc(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===dc.TableChecks?r.declaration instanceof P?new Sc(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function wc(e,t,n){let r=t,i=e;if(i instanceof B&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Wo(i)||r.length===0)return;let a=[...r],o=is(i),s=a.pop();if(!(s instanceof R))return;let c=g(a)instanceof z?a.pop():void 0;if(a.length===3){let e=is(a[1]);return!e||!Ja(e)?void 0:n.create(P,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(P,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(P,{type:o,attributeList:c,body:s})}function V(e){e&&(e instanceof Va?Tc(e):Ec(e))}function Tc(e){e.kind!==v.EOF&&(e.isInvalid=!0)}function Ec(e){if(e instanceof P)V(e.type),V(e.name),V(e.as),V(e.alias),V(e.bodyColon),V(e.attributeList),V(e.body);else if(e instanceof Zs)e.identifiers.forEach(V);else if(e instanceof F)V(e.name),V(e.colon),V(e.value);else if(e instanceof I)V(e.op),V(e.expression);else if(e instanceof Qs)V(e.leftExpression),V(e.op),V(e.rightExpression);else if(e instanceof $s)V(e.op),V(e.expression);else if(e instanceof R)V(e.blockOpenBrace),e.body.forEach(V),V(e.blockCloseBrace);else if(e instanceof z)V(e.listOpenBracket),e.commaList.forEach(V),e.elementList.forEach(V),V(e.listCloseBracket);else if(e instanceof tc)V(e.tupleOpenParen),e.commaList.forEach(V),e.elementList.forEach(V),V(e.tupleCloseParen);else if(e instanceof nc)e.commaList.forEach(V),e.elementList.forEach(V);else if(e instanceof B)V(e.callee),V(e.argumentList);else if(e instanceof L)V(e.callee),e.args.forEach(V);else if(e instanceof sc)V(e.expression);else if(e instanceof ec)V(e.value);else if(e instanceof oc)V(e.variable);else if(e instanceof ic)V(e.literal);else if(e instanceof rc)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof lc)V(e.array),V(e.indexer);else if(e instanceof qs)e.body.forEach(V),V(e.eof);else if(!(e instanceof cc))if(e instanceof Js)V(e.useKeyword),V(e.specifiers),V(e.fromKeyword),V(e.importPath);else if(e instanceof Xs)V(e.openBrace),e.specifiers.forEach(V),V(e.closeBrace);else if(e instanceof Ys)V(e.importKind),V(e.name),V(e.asKeyword),V(e.alias);else if(e instanceof ac)V(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Dc(...e){return e.filter(e=>e!==void 0)}function Oc(e){if(e instanceof qs)return Dc(...e.body,e.eof);if(e instanceof P)return Dc(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof F)return Dc(e.name,e.colon,e.value);if(e instanceof Zs)return e.identifiers;if(e instanceof ic)return e.literal?[e.literal]:[];if(e instanceof oc)return Dc(e.variable);if(e instanceof I)return Dc(e.op,e.expression);if(e instanceof Qs)return Dc(e.leftExpression,e.op,e.rightExpression);if(e instanceof $s)return Dc(e.expression,e.op);if(e instanceof ec)return Dc(e.value);if(e instanceof L)return Dc(e.callee,...e.args);if(e instanceof R)return Dc(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof z)return Dc(e.listOpenBracket,...kc(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof tc)return Dc(e.tupleOpenParen,...kc(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof nc)return Dc(...kc(e.elementList,e.commaList));if(e instanceof B)return Dc(e.callee,e.argumentList);if(e instanceof sc)return Dc(e.expression);if(e instanceof lc)return Dc(e.array,e.indexer);if(e instanceof cc)return[];if(e instanceof Js)return Dc(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof Xs)return Dc(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof Ys)return Dc(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof ac)return Dc(e.token);throw e instanceof rc?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function kc(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 Ac(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function jc(e){if(!e)return[];if(w(e))return[{variables:[e],tupleElements:[]}];if(e instanceof Qs){let t=us(e);return t?[t]:[...jc(e.leftExpression),...jc(e.rightExpression)]}if(e instanceof I||e instanceof $s)return jc(e.expression);if(e instanceof tc){let t=us(e);return t?[t]:e.elementList.flatMap(jc)}return[]}function Mc(e,n){let r=n.parentNode;if(!r||!T(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;T(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Nc(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:return}}var Pc=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof R?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=_(e.body,e=>e instanceof L);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof R)?[]:e.isKind(r.DiagramViewTables)?this.bindTableReferences(e.body):e.isKind(r.DiagramViewNotes)?this.bindNoteReferences(e.body):e.isKind(r.DiagramViewTableGroups)?this.bindTableGroupReferences(e.body):e.isKind(r.DiagramViewSchemas)?this.bindSchemaReferences(e.body):[])}bindTableReferences(e){let[t]=_(e.body,e=>e instanceof L);return t.flatMap(e=>!e.callee||Uo(e.callee)?[]:[e.callee,...e.args].flatMap(jc).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables.pop();return[...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}))}bindNoteReferences(e){let[t]=_(e.body,e=>e instanceof L);return t.flatMap(e=>!e.callee||Uo(e.callee)?[]:jc(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=_(e.body,e=>e instanceof L);return t.flatMap(e=>!e.callee||Uo(e.callee)?[]:jc(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=_(e.body,e=>e instanceof L);return t.flatMap(e=>!e.callee||Uo(e.callee)?[]:jc(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},Fc=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 R&&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 L&&Uo(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramViewWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramViewExplicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=_(e.body,e=>e instanceof P),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof R&&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 L&&Uo(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 L))continue;let e=n.callee&&ns(n.callee),r=e&&this.compiler.nodeReferee(e).getFiltered(t);if(r?.declaration instanceof P){let e=O(r.declaration.name)??[];if(e.length>0){let t=e[e.length-1],n=e.length>1?e.slice(0,-1).join(`.`):y;i.push({name:t,schemaName:n});continue}}let a=O(n.callee)??[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[0]:y;i.push({name:o,schemaName:s})}switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=i.length>0?i:null;break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=i.length>0?i.map(e=>({name:e.name})):null;break}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;if(!(!t||!e)){if(t.has(`tables`)||t.has(`schemas`)){e.tables=[],e.tableGroups=[],e.schemas=[];return}t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames())}}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n)return[];let r=this.compiler.symbolMembers(n).getFiltered(t);return r?Pa(r.filter(e=>e.isKind(M.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function Ic(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var Lc=function(e){return e.Table=`table`,e}({}),Rc={getDuplicateError(e,t,n){return new x(b.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new x(b.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},zc={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return E(a,r.DiagramView)?new n(i.symbolFactory.create(Fs,{declaration:a,name:o},a.filepath)):D(a,r.DiagramView)&&a instanceof ac?new n(i.symbolFactory.create(Is,{declaration:a,name:o},a.filepath)):D(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(zs,{declaration:a,name:o},a.filepath)):D(a,r.DiagramViewTables)?new n(i.symbolFactory.create(Ls,{declaration:a,name:o},a.filepath)):D(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(Rs,{declaration:a,name:o},a.filepath)):D(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(Bs,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&Zo(a))return n.create(e);let o=Bc(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)?Vc(i,c,a):o.isKind(r.DiagramViewNotes)?Hc(i,c,a,M.StickyNote):o.isKind(r.DiagramViewTableGroups)?Hc(i,c,a,M.TableGroup):o.isKind(r.DiagramViewSchemas)?Uc(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(M.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!E(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of cs(o))if(e instanceof L){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof P&&c.push(...cs(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(M.DiagramViewSchema,M.DiagramViewTableGroup,M.DiagramViewTable,M.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(cg).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(Rc.getFieldDuplicateError(n,e.kind,i)),s.push(Rc.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!E(a,r.DiagramView))return n.create(e);let o=new Pc(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 Fs?r.declaration instanceof P?new Fc(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function Bc(e){let t=e.parentOfKind(L);if(!t)return;let n=t.parentNode;if(!(n instanceof R))return;let i=n.parentNode;if(!(i instanceof P)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof R))return;let o=a.parentNode;if(!(!(o instanceof P)||!o.isKind(r.DiagramView)))return i}function Vc(e,r,i){let a=ms(i);if(a===void 0)return n.create(void 0);if(T(i.parentNode)){let t=Mc(e,i);if(t){if(t.isKind(M.Schema)){let r=rs(i),o=e.lookupMembers(t,r?M.Table:M.Schema,a);return o?n.create(o):new n(void 0,[new x(b.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,M.Schema,a);return o?n.create(o):new n(void 0,[new x(b.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(M.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,M.Table,a);return s?n.create(s):new n(void 0,[new x(b.BINDING_ERROR,`Could not find table '${a}'`,i)])}function Hc(e,t,r,i){let a=ms(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 x(b.BINDING_ERROR,`Could not find ${i===M.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function Uc(e,t,r){let i=ms(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,M.Schema,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var Wc=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof R?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof L)return[];let t=e.body.filter(e=>e instanceof P);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Gc=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=j(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=j(t),n.name=A(t.callee);let r=S(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:_s(k(r.value)),token:j(r)},this.enum.values.push(n),[]})}},Kc={getDuplicateError(e,t,n){return new x(b.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new x(b.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},qc={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return E(a,r.Enum)?new n(i.symbolFactory.create(Es,{declaration:a,name:o},a.filepath)):D(a,r.Enum)?new n(i.symbolFactory.create(Ds,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(M.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof P))return new n([]);let o=cs(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(M.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push(Kc.getFieldDuplicateError(t,r)),c.push(Kc.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!E(a,r.Enum))return n.create(e);let o=new Wc(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 Es?new Gc(t,r,i).interpret():n.create(e)}},Jc=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof P)||!this.declarationNode.parent.isKind(r.Table)&&!this.declarationNode.parent.isKind(r.TablePartial)||!(this.declarationNode.body instanceof R)?[]:this.bindBody(this.declarationNode.body)}get ownerContainerKind(){return this.declarationNode.parent.isKind(r.TablePartial)?`TablePartial`:`Table`}bindBody(e){if(!e)return[];if(e instanceof L)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof L);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=O(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(jc).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=ms(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new x(b.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Yc=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof R?new n(e.body.flatMap(e=>{if(!(e instanceof L)||!e.callee)return[];let n=[],r=j(e),a=[e.callee,...e.args],o,s,c,l,u;g(a)instanceof z&&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=k(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=k(e.value);t!==void 0&&(l={value:t,token:j(e)})}u=A(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof B))return e;let t=[],n=e;for(;n instanceof B&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=ds(e);if(t){for(let e of t.functional)n.push({value:e.value?.value??``,type:`expression`,token:j(e)});for(let e of t.nonFunctional)n.push({value:ms(e)??``,type:`column`,token:j(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}},Xc={nodeMetadata(t,i){if(!E(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!E(a,r.Table)&&!E(a,r.TablePartial)?n.create(e):n.create(new gc(i))},nodeReferee(i,a){if(!w(a)||Zo(a))return n.create(e);let o=a;for(;o&&!E(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!E(s,r.Table)&&!E(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=w(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,M.Column,l);if(u)return n.create(u);let d=E(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new x(b.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return E(i,r.Indexes)?n.create(void 0,new Jc(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===dc.Indexes?r.declaration instanceof P?new Yc(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function Zc(e,n){let r=ls(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof tc){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 tc)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function Qc(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 x(b.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new x(b.CIRCULAR_REF,`References with same endpoints exist`,n),new x(b.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var $c=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 P&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new x(b.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof P&&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(...el(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 P)||!t.type)continue;let i=t;E(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),E(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),E(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of cs(e)){if(!(r instanceof L)||!r.callee||!$o(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=Zc(this.compiler,i.leftExpression),o=Zc(this.compiler,i.rightExpression);!a||!o||n.push(...Qc(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of cs(e)){if(!(a instanceof L)||!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 I)||!i.op||!Io(i.op.value)||!i.expression)continue;let a=Zc(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...Qc(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of cs(e)){if(!(r instanceof L)||!r.callee)continue;let e=A(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 I&&(!r.op||!Io(r.op.value)||r.expression&&w(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new x(b.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 P)||!i.type)continue;let a=i;if(!E(a,r.TableGroup))continue;let o=a.name?O(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=cs(a);for(let r of c){if(!(r instanceof L)||!r.callee)continue;let i=ls(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=O(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new x(b.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 el(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 Ts&&a.push(...el(e,t,r));return a}function tl(e,t,n){t.isKind(M.Table)?e.externals.tables.push(n):t.isKind(M.Enum)?e.externals.enums.push(n):t.isKind(M.TableGroup)?e.externals.tableGroups.push(n):t.isKind(M.TablePartial)?e.externals.tablePartials.push(n):t.isKind(M.StickyNote)&&e.externals.notes.push(n)}var nl={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`])},rl={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`])},il={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},al={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`])},ol={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`])},sl={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`])},cl={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function ll(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function ul(e,t){let n=ll(e);return t?nl[t].has(n):Object.values(nl).some(e=>e.has(n))}function dl(e,t){let n=ll(e);return t?rl[t].has(n):Object.values(rl).some(e=>e.has(n))}function fl(e,t){return ul(e,t)||dl(e,t)}function pl(e,t){let n=ll(e);return t?il[t].has(n):Object.values(il).some(e=>e.has(n))}function ml(e,t){let n=ll(e);return t?al[t].has(n):Object.values(al).some(e=>e.has(n))}function hl(e,t){let n=ll(e);return t?ol[t].has(n):Object.values(ol).some(e=>e.has(n))}function gl(e,t){let n=ll(e);return t?sl[t].has(n):Object.values(sl).some(e=>e.has(n))}function _l(e,t){let n=ll(e);return t?cl[t].has(n):Object.values(cl).some(e=>e.has(n))}function vl(e,t){if(t)return`string`;if(ul(e))return`integer`;if(dl(e))return`real`;if(pl(e))return`bool`;if(ml(e))return`string`;let n=ll(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:gl(e)?`datetime`:e}var yl=class extends Error{},bl=class extends yl{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},xl=class extends yl{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Sl=class extends yl{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Cl=class extends yl{},wl=class extends yl{constructor(e){super(`Invalid unit ${e}`)}},Tl=class extends yl{},El=class extends yl{constructor(){super(`Zone is an abstract class`)}},H=`numeric`,Dl=`short`,Ol=`long`,kl={year:H,month:H,day:H},Al={year:H,month:Dl,day:H},jl={year:H,month:Dl,day:H,weekday:Dl},Ml={year:H,month:Ol,day:H},Nl={year:H,month:Ol,day:H,weekday:Ol},Pl={hour:H,minute:H},Fl={hour:H,minute:H,second:H},Il={hour:H,minute:H,second:H,timeZoneName:Dl},Ll={hour:H,minute:H,second:H,timeZoneName:Ol},Rl={hour:H,minute:H,hourCycle:`h23`},zl={hour:H,minute:H,second:H,hourCycle:`h23`},Bl={hour:H,minute:H,second:H,hourCycle:`h23`,timeZoneName:Dl},Vl={hour:H,minute:H,second:H,hourCycle:`h23`,timeZoneName:Ol},Hl={year:H,month:H,day:H,hour:H,minute:H},Ul={year:H,month:H,day:H,hour:H,minute:H,second:H},Wl={year:H,month:Dl,day:H,hour:H,minute:H},Gl={year:H,month:Dl,day:H,hour:H,minute:H,second:H},Kl={year:H,month:Dl,day:H,weekday:Dl,hour:H,minute:H},ql={year:H,month:Ol,day:H,hour:H,minute:H,timeZoneName:Dl},Jl={year:H,month:Ol,day:H,hour:H,minute:H,second:H,timeZoneName:Dl},Yl={year:H,month:Ol,day:H,weekday:Ol,hour:H,minute:H,timeZoneName:Ol},Xl={year:H,month:Ol,day:H,weekday:Ol,hour:H,minute:H,second:H,timeZoneName:Ol},Zl=class{get type(){throw new El}get name(){throw new El}get ianaName(){return this.name}get isUniversal(){throw new El}offsetName(e,t){throw new El}formatOffset(e,t){throw new El}offset(e){throw new El}equals(e){throw new El}get isValid(){throw new El}},Ql=null,$l=class e extends Zl{static get instance(){return Ql===null&&(Ql=new e),Ql}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return zd(e,t,n)}formatOffset(e,t){return Ud(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},eu=new Map;function tu(e){let t=eu.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`}),eu.set(e,t)),t}var nu={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function ru(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 iu(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=nu[t];t===`era`?r[a]=i:W(a)||(r[a]=parseInt(i,10))}return r}var au=new Map,ou=class e extends Zl{static create(t){let n=au.get(t);return n===void 0&&au.set(t,n=new e(t)),n}static resetCache(){au.clear(),eu.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 zd(e,t,n,this.name)}formatOffset(e,t){return Ud(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=tu(this.name),[r,i,a,o,s,c,l]=n.formatToParts?iu(n,t):ru(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=Fd({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}},su={};function cu(e,t={}){let n=JSON.stringify([e,t]),r=su[n];return r||(r=new Intl.ListFormat(e,t),su[n]=r),r}var lu=new Map;function uu(e,t={}){let n=JSON.stringify([e,t]),r=lu.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),lu.set(n,r)),r}var du=new Map;function fu(e,t={}){let n=JSON.stringify([e,t]),r=du.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),du.set(n,r)),r}var pu=new Map;function mu(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=pu.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),pu.set(i,a)),a}var hu=null;function gu(){return hu||(hu=new Intl.DateTimeFormat().resolvedOptions().locale,hu)}var _u=new Map;function vu(e){let t=_u.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),_u.set(e,t)),t}var yu=new Map;function bu(e){let t=yu.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Au,...t}),yu.set(e,t)}return t}function xu(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=uu(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=uu(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Su(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Cu(e){let t=[];for(let n=1;n<=12;n++){let r=K.utc(2009,n,1);t.push(e(r))}return t}function wu(e){let t=[];for(let n=1;n<=7;n++){let r=K.utc(2016,11,13+n);t.push(e(r))}return t}function Tu(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Eu(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||vu(e.locale).numberingSystem===`latn`}var Du=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=fu(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return Dd(this.floor?Math.floor(e):jd(e,3),this.padTo)}},Ou=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&&ou.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=uu(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()}},ku=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&vd()&&(this.rtf=mu(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):lf(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Au={firstDay:1,minimalDays:4,weekend:[6,7]},U=class e{static fromOpts(t){return e.create(t.locale,t.numberingSystem,t.outputCalendar,t.weekSettings,t.defaultToEN)}static create(t,n,r,i,a=!1){let o=t||Xu.defaultLocale;return new e(o||(a?`en-US`:gu()),n||Xu.defaultNumberingSystem,r||Xu.defaultOutputCalendar,wd(i)||Xu.defaultWeekSettings,o)}static resetCache(){hu=null,lu.clear(),du.clear(),pu.clear(),_u.clear(),yu.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]=xu(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Su(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??=Eu(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,wd(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 Tu(this,e,Jd,()=>{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]=Cu(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Tu(this,e,Qd,()=>{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]=wu(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Tu(this,void 0,()=>$d,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[K.utc(2016,11,13,9),K.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Tu(this,e,rf,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[K.utc(-40,1,1),K.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 Du(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new Ou(e,this.intl,t)}relFormatter(e={}){return new ku(this.intl,this.isEnglish(),e)}listFormatter(e={}){return cu(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||vu(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:yd()?bu(this.locale):Au}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})`}},ju=null,Mu=class e extends Zl{static get utcInstance(){return ju===null&&(ju=new e(0)),ju}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(Bd(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${Ud(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${Ud(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return Ud(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}},Nu=class extends Zl{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 Pu(e,t){if(W(e)||e===null)return t;if(e instanceof Zl)return e;if(gd(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?$l.instance:n===`utc`||n===`gmt`?Mu.utcInstance:Mu.parseSpecifier(n)||ou.create(e)}else if(md(e))return Mu.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new Nu(e)}var Fu={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},Iu={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]},Lu=Fu.hanidec.replace(/[\[|\]]/g,``).split(``);function Ru(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(Fu.hanidec)!==-1)t+=Lu.indexOf(e[n]);else for(let e in Iu){let[n,i]=Iu[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var zu=new Map;function Bu(){zu.clear()}function Vu({numberingSystem:e},t=``){let n=e||`latn`,r=zu.get(n);r===void 0&&(r=new Map,zu.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Fu[n]}${t}`),r.set(t,i)),i}var Hu=()=>Date.now(),Uu=`system`,Wu=null,Gu=null,Ku=null,qu=60,Ju,Yu=null,Xu=class{static get now(){return Hu}static set now(e){Hu=e}static set defaultZone(e){Uu=e}static get defaultZone(){return Pu(Uu,$l.instance)}static get defaultLocale(){return Wu}static set defaultLocale(e){Wu=e}static get defaultNumberingSystem(){return Gu}static set defaultNumberingSystem(e){Gu=e}static get defaultOutputCalendar(){return Ku}static set defaultOutputCalendar(e){Ku=e}static get defaultWeekSettings(){return Yu}static set defaultWeekSettings(e){Yu=wd(e)}static get twoDigitCutoffYear(){return qu}static set twoDigitCutoffYear(e){qu=e%100}static get throwOnInvalid(){return Ju}static set throwOnInvalid(e){Ju=e}static resetCaches(){U.resetCache(),ou.resetCache(),K.resetCache(),Bu()}},Zu=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},Qu=[0,31,59,90,120,151,181,212,243,273,304,334],$u=[0,31,60,91,121,152,182,213,244,274,305,335];function ed(e,t){return new Zu(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function td(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 nd(e,t,n){return n+(Md(e)?$u:Qu)[t-1]}function rd(e,t){let n=Md(e)?$u:Qu,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function id(e,t){return(e-t+7)%7+1}function ad(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=nd(r,i,a),s=id(td(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=Ld(l,t,n)):c>Ld(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...Wd(e)}}function od(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=id(td(r,1,t),n),s=Nd(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=Nd(l)):c>s?(l=r+1,c-=Nd(r)):l=r;let{month:u,day:d}=rd(l,c);return{year:l,month:u,day:d,...Wd(e)}}function sd(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:nd(t,n,r),...Wd(e)}}function cd(e){let{year:t,ordinal:n}=e,{month:r,day:i}=rd(t,n);return{year:t,month:r,day:i,...Wd(e)}}function ld(e,t){if(!W(e.localWeekday)||!W(e.localWeekNumber)||!W(e.localWeekYear)){if(!W(e.weekday)||!W(e.weekNumber)||!W(e.weekYear))throw new Cl(`Cannot mix locale-based week fields with ISO-based week fields`);return W(e.localWeekday)||(e.weekday=e.localWeekday),W(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),W(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 ud(e,t=4,n=1){let r=hd(e.weekYear),i=Td(e.weekNumber,1,Ld(e.weekYear,t,n)),a=Td(e.weekday,1,7);return r?i?a?!1:ed(`weekday`,e.weekday):ed(`week`,e.weekNumber):ed(`weekYear`,e.weekYear)}function dd(e){let t=hd(e.year),n=Td(e.ordinal,1,Nd(e.year));return t?n?!1:ed(`ordinal`,e.ordinal):ed(`year`,e.year)}function fd(e){let t=hd(e.year),n=Td(e.month,1,12),r=Td(e.day,1,Pd(e.year,e.month));return t?n?r?!1:ed(`day`,e.day):ed(`month`,e.month):ed(`year`,e.year)}function pd(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Td(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Td(n,0,59),s=Td(r,0,59),c=Td(i,0,999);return a?o?s?c?!1:ed(`millisecond`,i):ed(`second`,r):ed(`minute`,n):ed(`hour`,t)}function W(e){return e===void 0}function md(e){return typeof e==`number`}function hd(e){return typeof e==`number`&&e%1==0}function gd(e){return typeof e==`string`}function _d(e){return Object.prototype.toString.call(e)===`[object Date]`}function vd(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function yd(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function bd(e){return Array.isArray(e)?e:[e]}function xd(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 Sd(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Cd(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function wd(e){if(e==null)return null;if(typeof e!=`object`)throw new Tl(`Week settings must be an object`);if(!Td(e.firstDay,1,7)||!Td(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Td(e,1,7)))throw new Tl(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Td(e,t,n){return hd(e)&&e>=t&&e<=n}function Ed(e,t){return e-t*Math.floor(e/t)}function Dd(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Od(e){if(!(W(e)||e===null||e===``))return parseInt(e,10)}function kd(e){if(!(W(e)||e===null||e===``))return parseFloat(e)}function Ad(e){if(!(W(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function jd(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 Md(e){return e%4==0&&(e%100!=0||e%400==0)}function Nd(e){return Md(e)?366:365}function Pd(e,t){let n=Ed(t-1,12)+1,r=e+(t-n)/12;return n===2?Md(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function Fd(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 Id(e,t,n){return-id(td(e,1,t),n)+t-1}function Ld(e,t=4,n=1){let r=Id(e,t,n),i=Id(e+1,t,n);return(Nd(e)-r+i)/7}function Rd(e){return e>99?e:e>Xu.twoDigitCutoffYear?1900+e:2e3+e}function zd(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 Bd(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 Vd(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Tl(`Invalid unit value ${e}`);return t}function Hd(e,t){let n={};for(let r in e)if(Cd(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=Vd(i)}return n}function Ud(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}${Dd(n,2)}:${Dd(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${Dd(n,2)}${Dd(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function Wd(e){return Sd(e,[`hour`,`minute`,`second`,`millisecond`])}var Gd=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Kd=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],qd=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function Jd(e){switch(e){case`narrow`:return[...qd];case`short`:return[...Kd];case`long`:return[...Gd];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 Yd=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],Xd=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Zd=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function Qd(e){switch(e){case`narrow`:return[...Zd];case`short`:return[...Xd];case`long`:return[...Yd];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var $d=[`AM`,`PM`],ef=[`Before Christ`,`Anno Domini`],tf=[`BC`,`AD`],nf=[`B`,`A`];function rf(e){switch(e){case`narrow`:return[...nf];case`short`:return[...tf];case`long`:return[...ef];default:return null}}function af(e){return $d[e.hour<12?0:1]}function of(e,t){return Qd(t)[e.weekday-1]}function sf(e,t){return Jd(t)[e.month-1]}function cf(e,t){return rf(t)[e.year<0?0:1]}function lf(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 uf(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var df={D:kl,DD:Al,DDD:Ml,DDDD:Nl,t:Pl,tt:Fl,ttt:Il,tttt:Ll,T:Rl,TT:zl,TTT:Bl,TTTT:Vl,f:Hl,ff:Wl,fff:ql,ffff:Yl,F:Ul,FF:Gl,FFF:Jl,FFFF:Xl},ff=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 df[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 Dd(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?af(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?sf(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?of(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?cf(t,e):a({era:e},`era`);return uf(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 uf(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},pf=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function mf(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function hf(...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 gf(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 _f(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Od(t[n+i]);return[r,null,n+i]}}var vf=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,yf=`(?:${vf.source}?(?:\\[(${pf.source})\\])?)?`,bf=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,xf=RegExp(`${bf.source}${yf}`),Sf=RegExp(`(?:[Tt]${xf.source})?`),Cf=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,wf=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Tf=/(\d{4})-?(\d{3})/,Ef=_f(`weekYear`,`weekNumber`,`weekDay`),Df=_f(`year`,`ordinal`),Of=/(\d{4})-(\d\d)-(\d\d)/,kf=RegExp(`${bf.source} ?(?:${vf.source}|(${pf.source}))?`),Af=RegExp(`(?: ${kf.source})?`);function jf(e,t,n){let r=e[t];return W(r)?n:Od(r)}function Mf(e,t){return[{year:jf(e,t),month:jf(e,t+1,1),day:jf(e,t+2,1)},null,t+3]}function Nf(e,t){return[{hours:jf(e,t,0),minutes:jf(e,t+1,0),seconds:jf(e,t+2,0),milliseconds:Ad(e[t+3])},null,t+4]}function Pf(e,t){let n=!e[t]&&!e[t+1],r=Bd(e[t+1],e[t+2]);return[{},n?null:Mu.instance(r),t+3]}function Ff(e,t){return[{},e[t]?ou.create(e[t]):null,t+1]}var If=RegExp(`^T?${bf.source}$`),Lf=/^-?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 Rf(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(kd(n)),months:f(kd(r)),weeks:f(kd(i)),days:f(kd(a)),hours:f(kd(o)),minutes:f(kd(s)),seconds:f(kd(c),c===`-0`),milliseconds:f(Ad(l),d)}]}var zf={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Bf(e,t,n,r,i,a,o){let s={year:t.length===2?Rd(Od(t)):Od(t),month:Kd.indexOf(n)+1,day:Od(r),hour:Od(i),minute:Od(a)};return o&&(s.second=Od(o)),e&&(s.weekday=e.length>3?Yd.indexOf(e)+1:Xd.indexOf(e)+1),s}var Vf=/^(?:(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 Hf(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=Bf(t,i,r,n,a,o,s),p;return p=c?zf[c]:l?0:Bd(u,d),[f,new Mu(p)]}function Uf(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var Wf=/^(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$/,Gf=/^(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$/,Kf=/^(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 qf(e){let[,t,n,r,i,a,o,s]=e;return[Bf(t,i,r,n,a,o,s),Mu.utcInstance]}function Jf(e){let[,t,n,r,i,a,o,s]=e;return[Bf(t,s,n,r,i,a,o),Mu.utcInstance]}var Yf=mf(Cf,Sf),Xf=mf(wf,Sf),Zf=mf(Tf,Sf),Qf=mf(xf),$f=hf(Mf,Nf,Pf,Ff),ep=hf(Ef,Nf,Pf,Ff),tp=hf(Df,Nf,Pf,Ff),np=hf(Nf,Pf,Ff);function rp(e){return gf(e,[Yf,$f],[Xf,ep],[Zf,tp],[Qf,np])}function ip(e){return gf(Uf(e),[Vf,Hf])}function ap(e){return gf(e,[Wf,qf],[Gf,qf],[Kf,Jf])}function op(e){return gf(e,[Lf,Rf])}var sp=hf(Nf);function cp(e){return gf(e,[If,sp])}var lp=mf(Of,Af),up=mf(kf),dp=hf(Nf,Pf,Ff);function fp(e){return gf(e,[lp,$f],[up,dp])}var pp=`Invalid Duration`,mp={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}},hp={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},...mp},gp=146097/400,_p=146097/4800,vp={years:{quarters:4,months:12,weeks:gp/7,days:gp,hours:gp*24,minutes:gp*24*60,seconds:gp*24*60*60,milliseconds:gp*24*60*60*1e3},quarters:{months:3,weeks:gp/28,days:gp/4,hours:gp*24/4,minutes:gp*24*60/4,seconds:gp*24*60*60/4,milliseconds:gp*24*60*60*1e3/4},months:{weeks:_p/7,days:_p,hours:_p*24,minutes:_p*24*60,seconds:_p*24*60*60,milliseconds:_p*24*60*60*1e3},...mp},yp=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],bp=yp.slice(0).reverse();function xp(e,t,n=!1){return new Tp({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 Sp(e,t){let n=t.milliseconds??0;for(let r of bp.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Cp(e,t){let n=Sp(e,t)<0?-1:1;yp.reduceRight((r,i)=>{if(W(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),yp.reduce((n,r)=>{if(W(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function wp(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Tp=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?vp:hp;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||U.create(),this.conversionAccuracy=t?`longterm`:`casual`,this.invalid=e.invalid||null,this.matrix=n,this.isLuxonDuration=!0}static fromMillis(t,n){return e.fromObject({milliseconds:t},n)}static fromObject(t,n={}){if(typeof t!=`object`||!t)throw new Tl(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:Hd(t,e.normalizeUnit),loc:U.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(md(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Tl(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=op(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]=cp(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 Tl(`need to specify a reason the Duration is invalid`);let r=t instanceof Zu?t:new Zu(t,n);if(Xu.throwOnInvalid)throw new Sl(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 wl(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?ff.create(this.loc,n).formatDurationFromString(this,e):pp}toHuman(e={}){if(!this.isValid)return pp;let t=e.showZeros!==!1,n=yp.map(n=>{let r=this.values[n];return W(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+=jd(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},K.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?Sp(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 yp)(Cd(n.values,e)||Cd(this.values,e))&&(r[e]=n.get(e)+this.get(e));return xp(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]=Vd(e(this.values[n],n));return xp(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...Hd(t,e.normalizeUnit)};return xp(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 xp(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Cp(this.matrix,e),xp(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=wp(this.normalize().shiftToAll().toObject());return xp(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 yp)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;md(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else md(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 Cp(this.matrix,n),xp(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 xp(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=wp(this.values);return xp(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 yp)if(!t(this.values[n],e.values[n]))return!1;return!0}},Ep=`Invalid Interval`;function Dp(e,t){return!e||!e.isValid?Op.invalid(`missing or invalid start`):!t||!t.isValid?Op.invalid(`missing or invalid end`):t<e?Op.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 Op=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 Tl(`need to specify a reason the Interval is invalid`);let r=t instanceof Zu?t:new Zu(t,n);if(Xu.throwOnInvalid)throw new xl(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=Am(t),i=Am(n);return Dp(r,i)??new e({start:r,end:i})}static after(t,n){let r=Tp.fromDurationLike(n),i=Am(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Tp.fromDurationLike(n),i=Am(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=K.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=K.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Tp.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Tp.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(Am).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=Tp.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()})`:Ep}[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=kl,t={}){return this.isValid?ff.create(this.s.loc.clone(t),e).formatInterval(this):Ep}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Ep}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Ep}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Ep}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Ep}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Tp.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},kp=class{static hasDST(e=Xu.defaultZone){let t=K.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return ou.isValidZone(e)}static normalizeZone(e){return Pu(e,Xu.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||U.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||U.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||U.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||U.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return U.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return U.create(t,null,`gregory`).eras(e)}static features(){return{relative:vd(),localeWeek:yd()}}};function Ap(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Tp.fromMillis(r).as(`days`))}function jp(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=Ap(e,t);return(n-n%7)/7}],[`days`,Ap]],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 Mp(e,t,n,r){let[i,a,o,s]=jp(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=Tp.fromObject(a,r);return l.length>0?Tp.fromMillis(c,r).shiftTo(...l).plus(u):u}var Np=`missing Intl.DateTimeFormat.formatToParts support`;function G(e,t=e=>e){return{regex:e,deser:([e])=>t(Ru(e))}}var Pp=`[ \xA0]`,Fp=new RegExp(Pp,`g`);function Ip(e){return e.replace(/\./g,`\\.?`).replace(Fp,Pp)}function Lp(e){return e.replace(/\./g,``).replace(Fp,` `).toLowerCase()}function Rp(e,t){return e===null?null:{regex:RegExp(e.map(Ip).join(`|`)),deser:([n])=>e.findIndex(e=>Lp(n)===Lp(e))+t}}function zp(e,t){return{regex:e,deser:([,e,t])=>Bd(e,t),groups:t}}function Bp(e){return{regex:e,deser:([e])=>e}}function Vp(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function Hp(e,t){let n=Vu(t),r=Vu(t,`{2}`),i=Vu(t,`{3}`),a=Vu(t,`{4}`),o=Vu(t,`{6}`),s=Vu(t,`{1,2}`),c=Vu(t,`{1,3}`),l=Vu(t,`{1,6}`),u=Vu(t,`{1,9}`),d=Vu(t,`{2,4}`),f=Vu(t,`{4,6}`),p=e=>({regex:RegExp(Vp(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return Rp(t.eras(`short`),0);case`GG`:return Rp(t.eras(`long`),0);case`y`:return G(l);case`yy`:return G(d,Rd);case`yyyy`:return G(a);case`yyyyy`:return G(f);case`yyyyyy`:return G(o);case`M`:return G(s);case`MM`:return G(r);case`MMM`:return Rp(t.months(`short`,!0),1);case`MMMM`:return Rp(t.months(`long`,!0),1);case`L`:return G(s);case`LL`:return G(r);case`LLL`:return Rp(t.months(`short`,!1),1);case`LLLL`:return Rp(t.months(`long`,!1),1);case`d`:return G(s);case`dd`:return G(r);case`o`:return G(c);case`ooo`:return G(i);case`HH`:return G(r);case`H`:return G(s);case`hh`:return G(r);case`h`:return G(s);case`mm`:return G(r);case`m`:return G(s);case`q`:return G(s);case`qq`:return G(r);case`s`:return G(s);case`ss`:return G(r);case`S`:return G(c);case`SSS`:return G(i);case`u`:return Bp(u);case`uu`:return Bp(s);case`uuu`:return G(n);case`a`:return Rp(t.meridiems(),0);case`kkkk`:return G(a);case`kk`:return G(d,Rd);case`W`:return G(s);case`WW`:return G(r);case`E`:case`c`:return G(n);case`EEE`:return Rp(t.weekdays(`short`,!1),1);case`EEEE`:return Rp(t.weekdays(`long`,!1),1);case`ccc`:return Rp(t.weekdays(`short`,!0),1);case`cccc`:return Rp(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return zp(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return zp(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return Bp(/[a-z_+-/]{1,256}?/i);case` `:return Bp(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:Np};return m.token=e,m}var Up={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 Wp(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=Up[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function Gp(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function Kp(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Cd(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 qp(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 W(e.z)||(n=ou.create(e.z)),W(e.Z)||(n||=new Mu(e.Z),r=e.Z),W(e.q)||(e.M=(e.q-1)*3+1),W(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),W(e.u)||(e.S=Ad(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var Jp=null;function Yp(){return Jp||=K.fromMillis(1555555555555),Jp}function Xp(e,t){if(e.literal)return e;let n=tm(ff.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function Zp(e,t){return Array.prototype.concat(...e.map(e=>Xp(e,t)))}var Qp=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=Zp(ff.parseFormat(t),e),this.units=this.tokens.map(t=>Hp(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=Gp(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=Kp(e,this.regex,this.handlers),[r,i,a]=n?qp(n):[null,null,void 0];if(Cd(n,`a`)&&Cd(n,`H`))throw new Cl(`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 $p(e,t,n){return new Qp(e,n).explainFromTokens(t)}function em(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=$p(e,t,n);return[r,i,a,o]}function tm(e,t){if(!e)return null;let n=ff.create(t,e).dtFormatter(Yp()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>Wp(t,e,i))}var nm=`Invalid DateTime`,rm=864e13;function im(e){return new Zu(`unsupported zone`,`the zone "${e.name}" is not supported`)}function am(e){return e.weekData===null&&(e.weekData=ad(e.c)),e.weekData}function om(e){return e.localWeekData===null&&(e.localWeekData=ad(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function sm(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new K({...n,...t,old:n})}function cm(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 lm(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 um(e,t,n){return cm(Fd(e),t,n)}function dm(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,Pd(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Tp.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]=cm(Fd(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function fm(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=K.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return K.invalid(new Zu(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function pm(e,t,n=!0){return e.isValid?ff.create(U.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function mm(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=Dd(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=Dd(e.c.month),n===`month`)return i;i+=`-`}else if(i+=Dd(e.c.month),n===`month`)return i;return i+=Dd(e.c.day),i}function hm(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+=Dd(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=Dd(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=Dd(e.c.second))}else{if(c+=Dd(e.c.minute),o===`minute`)break;s&&(c+=Dd(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=Dd(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=Dd(Math.trunc(-e.o/60)),c+=`:`,c+=Dd(Math.trunc(-e.o%60))):(c+=`+`,c+=Dd(Math.trunc(e.o/60)),c+=`:`,c+=Dd(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var gm={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},_m={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},vm={ordinal:1,hour:0,minute:0,second:0,millisecond:0},ym=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],bm=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],xm=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function Sm(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 wl(e);return t}function Cm(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return Sm(e)}}function wm(e){if(Om===void 0&&(Om=Xu.now()),e.type!==`iana`)return e.offset(Om);let t=e.name,n=km.get(t);return n===void 0&&(n=e.offset(Om),km.set(t,n)),n}function Tm(e,t){let n=Pu(t.zone,Xu.defaultZone);if(!n.isValid)return K.invalid(im(n));let r=U.fromObject(t),i,a;if(W(e.year))i=Xu.now();else{for(let t of ym)W(e[t])&&(e[t]=gm[t]);let t=fd(e)||pd(e);if(t)return K.invalid(t);let r=wm(n);[i,a]=um(e,r,n)}return new K({ts:i,zone:n,loc:r,o:a})}function Em(e,t,n){let r=W(n.round)?!0:n.round,i=W(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=jd(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 Dm(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 Om,km=new Map,K=class e{constructor(e){let t=e.zone||Xu.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new Zu(`invalid input`):null)||(t.isValid?null:im(t));this.ts=W(e.ts)?Xu.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=md(e.o)&&!e.old?e.o:t.offset(this.ts);r=lm(this.ts,a),n=Number.isNaN(r.year)?new Zu(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||U.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=Dm(arguments),[n,r,i,a,o,s,c]=t;return Tm({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=Dm(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Mu.utcInstance,Tm({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=_d(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Pu(n.zone,Xu.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:U.fromObject(n)}):e.invalid(im(i))}static fromMillis(t,n={}){if(!md(t))throw new Tl(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>rm?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Pu(n.zone,Xu.defaultZone),loc:U.fromObject(n)})}static fromSeconds(t,n={}){if(md(t))return new e({ts:t*1e3,zone:Pu(n.zone,Xu.defaultZone),loc:U.fromObject(n)});throw new Tl(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Pu(n.zone,Xu.defaultZone);if(!r.isValid)return e.invalid(im(r));let i=U.fromObject(n),a=Hd(t,Cm),{minDaysInFirstWeek:o,startOfWeek:s}=ld(a,i),c=Xu.now(),l=W(n.specificOffset)?r.offset(c):n.specificOffset,u=!W(a.ordinal),d=!W(a.year),f=!W(a.month)||!W(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new Cl(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Cl(`Can't mix ordinal dates with month/day`);let ee=m||a.weekday&&!p,te,ne,re=lm(c,l);ee?(te=bm,ne=_m,re=ad(re,o,s)):u?(te=xm,ne=vm,re=sd(re)):(te=ym,ne=gm);let ie=!1;for(let e of te){let t=a[e];W(t)?ie?a[e]=ne[e]:a[e]=re[e]:ie=!0}let ae=(ee?ud(a,o,s):u?dd(a):fd(a))||pd(a);if(ae)return e.invalid(ae);let[oe,se]=um(ee?od(a,o,s):u?cd(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]=rp(e);return fm(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=ip(e);return fm(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=ap(e);return fm(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(W(t)||W(n))throw new Tl(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=em(U.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):fm(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]=fp(e);return fm(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Tl(`need to specify a reason the DateTime is invalid`);let r=t instanceof Zu?t:new Zu(t,n);if(Xu.throwOnInvalid)throw new bl(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=tm(e,U.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return Zp(ff.parseFormat(e),U.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){Om=void 0,km.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?am(this).weekYear:NaN}get weekNumber(){return this.isValid?am(this).weekNumber:NaN}get weekday(){return this.isValid?am(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?om(this).weekday:NaN}get localWeekNumber(){return this.isValid?om(this).weekNumber:NaN}get localWeekYear(){return this.isValid?om(this).weekYear:NaN}get ordinal(){return this.isValid?sd(this.c).ordinal:NaN}get monthShort(){return this.isValid?kp.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?kp.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?kp.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?kp.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=Fd(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=lm(s,a),u=lm(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[sm(this,{ts:s}),sm(this,{ts:c})]:[this]}get isInLeapYear(){return Md(this.year)}get daysInMonth(){return Pd(this.year,this.month)}get daysInYear(){return this.isValid?Nd(this.year):NaN}get weeksInWeekYear(){return this.isValid?Ld(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?Ld(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=ff.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Mu.instance(e),t)}toLocal(){return this.setZone(Xu.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Pu(t,Xu.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]=um(r,n,t)}return sm(this,{ts:e,zone:t})}else return e.invalid(im(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return sm(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=Hd(e,Cm),{minDaysInFirstWeek:n,startOfWeek:r}=ld(t,this.loc),i=!W(t.weekYear)||!W(t.weekNumber)||!W(t.weekday),a=!W(t.ordinal),o=!W(t.year),s=!W(t.month)||!W(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new Cl(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Cl(`Can't mix ordinal dates with month/day`);let u;i?u=od({...ad(this.c,n,r),...t},n,r):W(t.ordinal)?(u={...this.toObject(),...t},W(t.day)&&(u.day=Math.min(Pd(u.year,u.month),u.day))):u=cd({...sd(this.c),...t});let[d,f]=um(u,this.o,this.zone);return sm(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Tp.fromDurationLike(e);return sm(this,dm(this,t))}minus(e){if(!this.isValid)return this;let t=Tp.fromDurationLike(e).negate();return sm(this,dm(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Tp.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?ff.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):nm}toLocaleString(e=kl,t={}){return this.isValid?ff.create(this.loc.clone(t),e).formatDateTime(this):nm}toLocaleParts(e={}){return this.isValid?ff.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=Sm(a);let o=e===`extended`,s=mm(this,o,a);return ym.indexOf(a)>=3&&(s+=`T`),s+=hm(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?mm(this,e===`extended`,Sm(t)):null}toISOWeekDate(){return pm(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=Sm(o),(r&&ym.indexOf(o)>=3?`T`:``)+hm(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return pm(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return pm(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?mm(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`)),pm(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():nm}[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 Tp.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=bd(t).map(Tp.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Mp(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?Op.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),Em(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?Em(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 Tl(`min requires all arguments be DateTimes`);return xd(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Tl(`max requires all arguments be DateTimes`);return xd(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return $p(U.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new Qp(U.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(W(t)||W(n))throw new Tl(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=U.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Tl(`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):fm(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return kl}static get DATE_MED(){return Al}static get DATE_MED_WITH_WEEKDAY(){return jl}static get DATE_FULL(){return Ml}static get DATE_HUGE(){return Nl}static get TIME_SIMPLE(){return Pl}static get TIME_WITH_SECONDS(){return Fl}static get TIME_WITH_SHORT_OFFSET(){return Il}static get TIME_WITH_LONG_OFFSET(){return Ll}static get TIME_24_SIMPLE(){return Rl}static get TIME_24_WITH_SECONDS(){return zl}static get TIME_24_WITH_SHORT_OFFSET(){return Bl}static get TIME_24_WITH_LONG_OFFSET(){return Vl}static get DATETIME_SHORT(){return Hl}static get DATETIME_SHORT_WITH_SECONDS(){return Ul}static get DATETIME_MED(){return Wl}static get DATETIME_MED_WITH_SECONDS(){return Gl}static get DATETIME_MED_WITH_WEEKDAY(){return Kl}static get DATETIME_FULL(){return ql}static get DATETIME_FULL_WITH_SECONDS(){return Jl}static get DATETIME_HUGE(){return Yl}static get DATETIME_HUGE_WITH_SECONDS(){return Xl}};function Am(e){if(K.isDateTime(e))return e;if(e&&e.valueOf&&md(e.valueOf()))return K.fromJSDate(e);if(e&&typeof e==`object`)return K.fromObject(e);throw new Tl(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function jm(e){return Wo(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof cc}function Mm(e){return k(e)===``}function Nm(e){return e instanceof ec}function Pm(e){let t=fs(e);if(t!==null)return t;if(zo(e)&&e instanceof I&&e.expression){let t=e.op?.value,n=fs(e.expression);if(n!==null)return t===`-`?-n:n}return null}function Fm(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=Pm(e);if(t!==null)return t;let n=k(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function Im(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=Pm(e);if(t!==null)return Number.isInteger(t)?t:null;let n=k(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var Lm=[`true`,`yes`,`y`,`t`,`1`],Rm=[`false`,`no`,`n`,`f`,`0`];function zm(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 Lm.includes(t)?!0:Rm.includes(t)?!1:null}if(Wo(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=fs(e);if(t===0)return!1;if(t===1)return!0;let n=k(e)?.toLowerCase();if(n){if(Lm.includes(n))return!0;if(Rm.includes(n))return!1}return null}function Bm(e){if(e==null)return null;if(typeof e==`string`)return e;let t=O(e);return t?g(t):k(e)??null}function Vm(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=k(e)??null??Fm(e)??zm(e);return t===null?null:t.toString()}var Hm=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Um=[`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`],Wm=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Gm(e){if(e==null)return null;let t=typeof e==`string`?e:k(e)??null;if(t===null)return null;for(let e of Wm){let n=K.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of Hm){let n=K.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Um){let n=K.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=K.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 Km(e,t){let n=e.type(t),r=e.default(t);return{name:e.name??``,pk:e.pk(t),unique:e.unique(t),increment:e.increment(t),notNull:e.nullable(t)===!1,dbdefault:r,typeName:n?.name??``}}function qm(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function Jm(e,t){return e?`${e}.${t}`:`${y}.${t}`}function Ym(e,t,n){return t.map((t,r)=>{let i=e[t]?.value;if(i==null&&n&&n[r]){let e=n[r];if(e?.dbdefault)return JSON.stringify(e.dbdefault.value)}return JSON.stringify(i)}).join(`|`)}function Xm(e,t,n){return t.some((t,r)=>{let i=e[t]?.value;return i==null&&n&&n[r]&&n[r]?.dbdefault?!1:i==null})}function Zm(e){return e.increment||_l(e.typeName)}function Qm(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function $m(e,t,n){return n.length===1?Qm(e,t,n[0]):`(${n.map(n=>Qm(e,t,n)).join(`, `)})`}function eh(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function th(e,t,n){let{token:r}=t,i=e.nodeAtPosition(r.filepath,r.start.offset)??e.parse.ast(r.filepath);return new Eo(b.INVALID_RECORDS_FIELD,n,i)}var nh=e=>e>1?`Composite PK`:`PK`;function rh(e,t,n,r){if(Oa(r.values))return[];let i=t.mergedColumns(e).map(t=>Km(t,e)),a=ka(i,`name`),o=qm(r),s=ch(t,i,e),c=new Set(r.columns);return xa(s,i=>ih(e,t,n,i,o,c,a,r))}function ih(e,t,n,r,i,a,o,s){let c=t.schema(e),l=t.name??``,u=sh(n,r,a,o,c,l,s);if(!Oa(u))return u;let d=Qr(r.map(e=>o[e])),f=d.every(e=>e&&Zm(e)),[p,m]=_(i,e=>Xm(e,r,d)),ee=f?[]:ah(e,p,r,c,l),te=oh(e,m,r,d,c,l);return[...ee,...te]}function ah(e,t,n,r,i){if(Oa(t))return[];let a=`NULL in ${nh(n.length)}: ${$m(r,i,n)} cannot be NULL`;return xa(t,t=>n.map(n=>th(e,t[n],a)))}function oh(e,t,n,r,i,a){return xa(ma(wa(t,e=>Ym(e,n,r)),e=>e.length>1),t=>{let r=nh(n.length),o=$m(i,a,n);return xa(t,t=>{let i=`Duplicate ${r}: ${o} = ${eh(t,n)}`;return n.map(n=>th(e,t[n],i))})})}function sh(e,t,n,r,i,a,o){let s=da(t,Array.from(n));if(Oa(s))return[];let c=s.filter(e=>{let t=r[e];return!!(t&&!Zm(t)&&!t.dbdefault)});if(Oa(c))return[];let l=`${nh(c.length)}: Column ${$m(i,a,c)} is missing from record and has no default value`;return o.values.map(()=>new Eo(b.INVALID_RECORDS_FIELD,l,e))}function ch(e,t,n){return[...t.filter(e=>e.pk).map(e=>[e.name]),...e.mergedIndexes(n).flatMap(e=>{let t=n.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(t)?t.filter(e=>e.pk).map(e=>e.columns.map(e=>e.value)):[]})]}var lh=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function uh(e,t,n){if(Oa(n.values))return[];let r=t.mergedColumns(e).map(t=>Km(t,e)),i=ka(r,`name`),a=qm(n),o=t.schema(e),s=t.name??``;return xa(dh(t,r,e),t=>fh(e,a,t,Qr(t.map(e=>i[e])),o,s))}function dh(e,t,n){return[...t.filter(e=>e.unique).map(e=>[e.name]),...e.mergedIndexes(n).flatMap(e=>{let t=n.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(t)?t.filter(e=>e.unique).map(e=>e.columns.map(e=>e.value)):[]})]}function fh(e,t,n,r,i,a){return xa(ma(wa(t.filter(e=>!Xm(e,n,r)),e=>Ym(e,n,r)),e=>e.length>1),t=>{let r=lh(n.length),o=$m(i,a,n);return xa(t,t=>{let i=`Duplicate ${r}: ${o} = ${eh(t,n)}`;return n.map(n=>th(e,t[n],i))})})}function ph(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(Jm(a,e),i)}return r}function mh(e,t,n,r){let i=ph(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!Oa(t.record.values)&&a.add(e);return xa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(Jm(e.schemaName,e.tableName))):!1),t=>gh(e,t,i,r))}function hh(e,t,n,r,i,a){if(!t.record||Oa(t.record.values))return[];let o=qm(t.record),s=n.record?qm(n.record):[],c=new Set(s.map(e=>Ym(e,i.fieldNames))),l=o.filter(e=>!Xm(e,r.fieldNames)).filter(e=>{let t=Ym(e,r.fieldNames);return!c.has(t)}),u=t.tableSymbol.interpretedName(e,a),d=n.tableSymbol.interpretedName(e,a);return xa(l,t=>{let n=$m(u.schema,u.name,r.fieldNames),a=$m(d.schema,d.name,i.fieldNames),o=`FK violation: ${n} = ${eh(t,r.fieldNames)} does not exist in ${a}`;return r.fieldNames.map(n=>th(e,t[n],o))})}function gh(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(Jm(i.schemaName,i.tableName)),s=n.get(Jm(a.schemaName,a.tableName));return!o||!s?[]:_h(e,o,s,i,a,r)}function _h(e,t,n,r,i,a){let o=r.relation,s=i.relation;return o===`1`&&s===`1`||o===`*`&&s===`*`?[...hh(e,t,n,r,i,a),...hh(e,n,t,i,r,a)]:o===`*`&&s===`1`?hh(e,t,n,r,i,a):o===`1`&&s===`*`?hh(e,n,t,i,r,a):[]}var vh=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:j(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.warnings.push(...this.validateRecords()),new n(this.db,this.errors,this.warnings)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof Us)continue;let r=this.compiler.interpretSymbol(n,this.filepath);if(r.hasValue(t))continue;this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings());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 Ts);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Ts){n.push(t);continue}if(!(t instanceof Us))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());let t=r.getValue();t&&this.pushElement(e,t)}let i=n instanceof Os?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Os?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}]};tl(this.db,e,o)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],n=new Set,r=new Map;for(let t of e){if(!(t instanceof _c))continue;let e=t.table(this.compiler);if(!e)continue;let n=e.originalSymbol.intern(),i=r.get(n);i?i.count++:r.set(n,{count:1,tableName:e.name??``})}for(let i of e){let e=this.compiler.interpretMetadata(i,this.filepath);if(e.hasValue(t))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings());let a=e.getValue();if(a!==void 0)switch(i.kind){case dc.Ref:{let e=a,[t,r]=e.endpoints??[];if(t&&r){let e=[t.schemaName,t.tableName,t.fieldNames.join(`,`),r.schemaName,r.tableName,r.fieldNames.join(`,`)].join(`|`),a=[r.schemaName,r.tableName,r.fieldNames.join(`,`),t.schemaName,t.tableName,t.fieldNames.join(`,`)].join(`|`);if(n.has(e)||n.has(a)){this.errors.push(new x(b.SAME_ENDPOINT,`Ref with same endpoints already exists`,i.declaration));break}n.add(e)}this.db.refs.push(e);break}case dc.Records:if(i instanceof _c){let e=i.table(this.compiler)?.originalSymbol.intern()??``,t=e?r.get(e):void 0;if(t&&t.count>1){this.errors.push(new x(b.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,i.declaration));break}}this.db.records.push(a);break;case dc.Project:this.db.project=a;break;default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof Hs)||!t.isKind(M.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:Lc.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 Ts))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(M.Table))continue;let t=e.originalSymbol;if(!(t instanceof Os))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 _c))continue;let i=r.table(this.compiler);if(!(i instanceof Os))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...rh(this.compiler,i,r.declaration,o)),e.push(...uh(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(...mh(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof mc),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 Ws&&t.declaration===e.declaration)))continue;let l=Nc(s);if(!l)continue;let u=a instanceof Ns&&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:j(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:j(i.rightToken())};n.push({token:j(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case M.Table:this.db.tables.push(t);break;case M.Enum:this.db.enums.push(t);break;case M.TableGroup:this.db.tableGroups.push(t);break;case M.TablePartial:this.db.tablePartials.push(t);break;case M.StickyNote:this.db.notes.push(t);break;case M.DiagramView:this.db.diagramViews.push(t);break;default:break}}},yh={nodeSymbol(t,r){return Jo(r)?n.create(t.symbolFactory.create(Vs,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(M.Program))return n.create(e);if(!(i.declaration instanceof qs))return n.create([]);let a=new Map;for(let e of r.reachableFiles(i.filepath)){let{schemaMembers:t}=r.usableMembers(e).getValue();for(let e of t)a.has(e.name)||a.set(e.name,e)}let o=a.get(y);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(M.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Jo(r)?new $c(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof Vs))return n.create(e);if(!(r.declaration instanceof qs))return n.create(void 0);if(!Ac(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new vh(t,r,i).interpret()}},bh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof R?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof L)return[];let t=e.body.filter(e=>e instanceof P);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},xh=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=j(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}=vs(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 R?t.body.body[0]?.callee:t.body?.callee,n=e?k(e):void 0;return n&&(this.project.note={value:_s(n),token:j(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()]=k(t.body.callee),[]}})}},Sh={nodeMetadata(t,i){return E(i,r.Project)?n.create(new vc(i)):n.create(e)},bindNode(t,i){return E(i,r.Project)?n.create(void 0,new bh(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof vc)||!(r.declaration instanceof P)?n.create(e):new xh(t,r.declaration,i).interpret()}},Ch=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 R&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof qs?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=ps(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=os(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=ms(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new x(b.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new x(b.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new x(b.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 P)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Vo(e))return[];let i=os(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=ms(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new x(b.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n));continue}}return a}bindBody(e){if(!e)return[];if(e instanceof L)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof L),n=e.body.filter(e=>e instanceof P);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof nc?e.callee.elementList:[e.callee]).flatMap(jc).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():[])}},wh=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Th(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=Eh(n,r.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getWarnings());let o=a.getValue();o.row&&i.push(o.row)}let a=j(this.element);return new n({schemaName:r.schemaName,tableName:r.tableName,columns:r.columns.map(e=>e.name??``),values:i,token:a},e,t)}};function Th(e,n,i){let a=e.name,o=e.parent;if(o instanceof P&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Os))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===A(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=ps(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,M.Schema,u);e&&(p=n.lookupMembers(e,M.Table,l))}if(p||=n.lookupMembers(f,M.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Os))return;let ee=m.mergedColumns(n),te=s.args.map(e=>ee.find(t=>t.name===A(e))).filter(Boolean),ne=m.interpretedName(n,i);return{schemaName:ne.schema,tableName:ne.name,columns:te}}function Eh(e,t,r){let i=[],a=[],o={},s=e.callee instanceof nc?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new x(b.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=Oh(n,l,r);i.push(...u.getErrors()),a.push(...u.getWarnings());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:j(n)})}return new n({row:c,columnNodes:o},i,a)}function Dh(e){return e instanceof ec&&e.value?.value||``}function Oh(e,t,r){let i=j(e),a=t.type(r),o=(a?.name??``).split(`(`)[0],s=!!a?.enumSymbol,c=t.increment(r),l=t.nullable(r)===!1,u=t.default(r),d=t.name??``,f=vl(o,s),p=Vm(e),m=p===null?Dh(e):p,ee=p===null?`expression`:f;if(e instanceof ec)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(jm(e)||Mm(e)&&!ml(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=_l(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`NULL not allowed for non-nullable column '${d}' without default and increment`,e)]):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(M.EnumField)).map(e=>e.name).filter(Boolean):[],s=k(e);return s===void 0&&(s=w(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},[],[new Eo(b.INVALID_RECORDS_FIELD,`Invalid enum value for column '${d}'`,e)])}if(ul(o)||dl(o)||_l(o)){let t=Pm(e);if(t===null)return new n({value:m,type:ee,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${d}'`,e)]);if(ul(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`Invalid integer value ${t} for column '${d}': expected integer, got decimal`,e)]);let r=dl(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(dl(o)&&r){let{precision:a,scale:o}=r,s=t.toString().split(`.`),c=s[0].replace(/^-/,``),l=s[1]||``,u=c.length+l.length,p=l.length;if(u>a)return new n({value:t,type:f,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`Numeric value ${t} for column '${d}' exceeds precision: expected at most ${a} total digits, got ${u}`,e)]);if(p>o)return new n({value:t,type:f,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`Numeric value ${t} for column '${d}' exceeds scale: expected at most ${o} decimal digits, got ${p}`,e)])}return new n({value:t,type:f,token:i},[],[])}if(pl(o)){let t=zm(e);return t===null?new n({value:m,type:ee,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${d}'`,e)]):new n({value:t,type:f,token:i},[],[])}if(gl(o)){let t=Gm(e);return t===null?new n({value:m,type:ee,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`Invalid datetime value for column '${d}', expected valid datetime format (e.g., 'YYYY-MM-DD', 'HH:MM:SS', 'YYYY-MM-DD HH:MM:SS', 'MM/DD/YYYY', 'D MMM YYYY', or 'MMM D, YYYY')`,e)]):new n({value:t,type:f,token:i},[],[])}if(ml(o)){let t=Vm(e);if(t===null)return new n({value:m,type:ee,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`Invalid string value for column '${d}'`,e)]);let r=a?.args?.length?Number(a.args[0]):void 0;if(r&&!Number.isNaN(r)){let a=r,o=new TextEncoder().encode(t).length;if(o>a)return new n({value:t,type:f,token:i},[],[new Eo(b.INVALID_RECORDS_FIELD,`String value for column '${d}' exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e)])}return new n({value:t,type:`string`,token:i},[],[])}return new n({value:m,type:ee,token:i},[],[])}var kh={nodeMetadata(t,i){if(!E(i,r.Records))return n.create(e);let a=i.parent;if(a&&E(a,r.Table))return n.create(new _c(i));let o=i.name;return o instanceof B&&o.callee?n.create(new _c(i)):n.create(e)},nodeReferee(i,a){if(!w(a))return n.create(e);let o=a.parentOfKind(P);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(tc);if(l?.parentNode===o)return Ah(i,o,a);let u=a.parentOfKind(B);return u?.parentNode===o&&l?.parentNode===u?jh(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?Mh(i,c,a):Ph(i,c,a)},bindNode(t,i){return E(i,r.Records)?n.create(void 0,new Ch(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof _c?r.declaration instanceof P?new wh(t,r,i).interpret():n.create(void 0):n.create(e)}};function Ah(e,i,a){let o=i.parent;if(o instanceof P&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return Nh(e,n,a)}return new n(void 0)}function jh(e,r,i){if(r.callee){let n;if(w(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=ls(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return Nh(e,n,i)}return new n(void 0)}function Mh(e,t,r){if(!w(r))return new n(void 0);let i=ms(r)??``;if(!T(r.parentNode)){let a=e.lookupMembers(t,[M.Table,M.Schema],i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Mc(e,r);if(!a){let a=e.lookupMembers(t,[M.Table,M.Schema],i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(M.Schema)){let t=e.lookupMembers(a,[M.Table,M.Schema],i);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function Nh(e,t,r){if(!w(r))return new n(void 0);let i=ms(r)??``,a=e.lookupMembers(t,M.Column,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function Ph(e,t,r){if(!w(r))return new n(void 0);let i=ms(r)??``;if(!T(r.parentNode))return new n(void 0);let a=Mc(e,r);if(a){if(a.isKind(M.Schema)){let t=e.lookupMembers(a,[M.Enum,M.Schema],i);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(M.Enum)){let t=e.lookupMembers(a,M.EnumField,i);return t?n.create(t):new n(void 0,[new x(b.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(T(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,M.Schema,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,M.Enum,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var Fh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof qs)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof L)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof L);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(jc).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():[])}},Ih=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=j(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()];return n.create(this.ref,e)}interpretName(){if(!(this.declarationNode instanceof P))return[];let e=[],t=O(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new x(b.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if(La(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new x(b.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=Nc(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=j(this.metadata.leftToken()),l=j(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof P?[{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 P))return[];let u=cs(this.declarationNode)[0];if(u.args[0]){let e=S(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof Zs?as(t):A(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof Zs?as(n):A(n),this.ref.color=e.color?.length?ys(e.color?.at(0)?.value):void 0,this.ref.inactive=e.inactive?.length?!0:void 0}return[]}};function Lh(e){let t=e.parent;for(;t;){if(t instanceof P&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var Rh={nodeReferee(r,i){if(!w(i)&&!T(i)||!Lh(i)||i.parentOfKind(F))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):Bh(r,o,i)},nodeMetadata(t,a){if(E(a,r.Ref)){let t=cs(a)[0];if(!(t instanceof L)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof Qs)||!r.op?n.create(e):n.create(new pc(a))}if(a instanceof F){if(!(a.name instanceof Zs)||as(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof P&&t.isKind(r.TablePartial)?n.create(new mc(a)):n.create(new pc(a))}return n.create(e)},bindNode(t,i){return E(i,r.Ref)?n.create(void 0,new Fh(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof pc?new Ih(t,r,i).interpret():n.create(e)}};function zh(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Ts&&e.isPublicSchema())}function Bh(e,r,i){if(!w(i))return new n(void 0);let a=ms(i)??``;if(!T(i.parentNode)){let r=i.parentNode;if(r&&T(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=T(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(M.Table)){let r=e.lookupMembers(c,M.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 x(b.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Mc(e,i);if(o){if(o.isKind(M.Schema)){let t=e.lookupMembers(o,[M.Table,M.Schema],a);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(M.Table)){let r=e.lookupMembers(o,M.Column,a);return r?n.create(r):new n(void 0,[new x(b.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(T(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,M.Schema,a);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=zh(e,r);if(t){let r=e.lookupMembers(t,M.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,M.Table,a);return o?n.create(o):new n(void 0,[new x(b.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var Vh={visibleName(e,n){let r=n instanceof N?n:n.useSpecifierDeclaration instanceof Ys?n.useSpecifierDeclaration:n.declaration;if(r instanceof Ys&&n instanceof ws&&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]}},Hh={nodeSymbol(r,i){if(!qo(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===M.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(Us,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:Vh.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new x(b.BINDING_ERROR,`Failed to resolve the import of ${a} '${(O(i.name)||[]).map(cg).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof Us))return n.create(e);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!w(i)&&!Go(i))return n.create(e);let a=i.parentOfKind(Ys);if(!a)return n.create(e);let o=a.name===i||T(a.name)&&a.name.rightExpression===i?a.getSymbolKind():M.Schema;if(o===void 0)return n.create(void 0);let s=O(i.parentOfKind(Qs)),c=A(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(Js);if(l?.importPath?.value===void 0)return n.create(void 0);let u=bo(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new x(b.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new x(b.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toString()}. Does the file exist?`,i)]);let d=i.parentOfKind(Qs)?.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 x(b.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=Uh(r,u,c,o);return f?n.create(f):n.create(void 0,[new x(b.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toString()}`,i)])},bindNode(t,r){if(Ko(r)){let e=[];if(r.importPath?.value){let n=bo(r.filepath,r.importPath.value);n?t.layout.exists(n)||e.push(new x(b.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath)):e.push(new x(b.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 Xs?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):qo(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 Us))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 Uh(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(M.Schema))return c;for(let t of o.reuses.selective)if(O(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(Js);if(o?.importPath?.value){let s=Uh(e,bo(n,o.importPath.value),O(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=Uh(e,t,r,i,a);if(n)return n}}function Wh(e){if(e instanceof yo){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=Kh(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof Vs?qh(this,e,i):Jh(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 Gh(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof Ys?Vh.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof Ys&&r.getSymbolKind()===M.Schema?a:a.length<=1?[y]:a.slice(0,-1);return o.length<i.length||!i.every((e,t)=>e===o[t])?{kind:`none`}:o.length===i.length?{kind:`direct`}:{kind:`child`,schemaName:o[i.length]}}function Kh(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof Js)||!e.specifiers||!e.importPath)continue;let n=bo(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof ac?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof ac?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 qh(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[y,e.symbolFactory.create(Ts,{name:y},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?y:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Ts,{name:i},s))}Yh(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of Zh(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Ts,{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 Jh(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof P))continue;let i=Gh(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(Hs,{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(Ts,{name:i.schemaName,parent:n},n.filepath))}Xh(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of Qh(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Ts,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function Yh(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==M.Schema)continue;let t=Vh.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Ts,{name:t},r))}}function Xh(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==M.Schema)continue;let t=Vh.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(Ts,{name:o,parent:n},n.filepath))}}function Zh(e,n){let{ast:r}=e.parseFile(n).getValue(),i=[];for(let n of r.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],a=r.length<=1?y:r[0];i.push(a)}let a=Kh(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==M.Schema)continue;let n=Vh.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function Qh(e,n,r){let{ast:i}=e.parseFile(n).getValue(),a=[];for(let n of i.declarations){let i=e.nodeFullname(n).getFiltered(t)||[],o=i.length<=1?[y]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=Kh(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==M.Schema)continue;let n=Vh.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var $h=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof R?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof L)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof L);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return(e=>e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(g(n)instanceof z){let e=S(g(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!Fo(e.callee)))}tryToBindColumnType(e){let t=us(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(C(e))return[];if(w(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&xo.includes(t))return[]}let t=us(e);if(!t){if(T(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 jc(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():[])}},eg=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??j(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})),n.create(this.table,t)}interpretName(e){let{name:t,schemaName:n}=vs(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new x(b.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=ms(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=S(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?ys(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:_s(k(n?.value)),token:j(n)},[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof L);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:_s(k(e.body instanceof R?e.body.body[0].callee:e.body.callee)),token:j(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:j(e)};i.name=A(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 x(b.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(M.Column)).length?[]:[new x(b.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Fo(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=ms(e.callee),r.token=j(e);let o=xs(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||!1,r.unique=a?.unique(this.compiler)||!1,r.increment=a?.increment(this.compiler)||void 0;let s=a?.nullable(this.compiler);r.not_null=s===void 0?void 0:!s,r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let c=this.compiler.nodeSettings(e).getFiltered(t)??{},l=this.compiler.parseFile(this.filepath).getValue().ast,u=this.compiler.nodeSymbol(l).getFiltered(t);return r.inline_refs=(c[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(u&&i.length>0&&!i.some(e=>e===u))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.checks=(c[i.Check]||[]).map(e=>({token:j(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()}},tg={getDuplicateError(e,t,n){return new x(b.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new x(b.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new x(b.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},ng={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return E(a,r.Table)?new n(i.symbolFactory.create(Os,{declaration:a,name:o},a.filepath)):D(a,r.Table)?Fo(a.callee)?new n(i.symbolFactory.create(Ps,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(ks,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(M.Table))return n.create(e);let a=i.declaration;if(!(a instanceof P))return new n([]);let o=cs(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(M.Column,M.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof P&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(M.Column)?(c.push(tg.getColumnDuplicateError(e.name,r)),c.push(tg.getColumnDuplicateError(e.name,n))):(c.push(tg.getPartialInjectionDuplicateError(e.name,r)),c.push(tg.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 L)||!Fo(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=A(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new x(b.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(Ws,{kind:M.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(M.Column)&&!(e instanceof Ws)).map(e=>e.name));return new n(Pa([...s.filter(e=>!(e instanceof Ws&&d.has(e.name)))].reverse(),e=>e.isKind(M.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(!Yo(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):w(o)&&o.parentNode instanceof I&&o.parentNode.op?.value===`~`?rg(a,c,o):Xo(o,1)?ig(a,c,o):Qo(o,i.Ref)?ag(a,c,o):Xo(o,0)?n.create(e):og(a,c,o)},bindNode(i,a){if(!E(a,r.Table))return n.create(e);let o=new $h(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 Os?r.declaration instanceof P?new eg(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function rg(e,r,i){let a=A(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Ts&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,M.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,M.TablePartial,a);return s?n.create(s):new n(void 0,[new x(b.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function ig(e,t,r){if(!w(r))return new n(void 0);let i=ms(r)??``;if(!T(r.parentNode))return n.create(e.lookupMembers(t,M.Enum,i));let a=Mc(e,r);if(a){if(a.isKind(M.Schema)){let t=rs(r),o=e.lookupMembers(a,t?M.Enum:M.Schema,i);return o?n.create(o):new n(void 0,[new x(b.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,M.Schema,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function ag(e,i,a){if(!w(a))return new n(void 0);let o=ms(a)??``;if(!T(a.parentNode)){let s=a.parent,c=s instanceof P&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,M.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,M.Column,o);return l?n.create(l):new n(void 0,[new x(b.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}let s=Mc(e,a);if(s){if(s.isKind(M.Schema)){let t=e.lookupMembers(s,[M.Table,M.Schema],o);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(M.Table)){let t=e.lookupMembers(s,M.Column,o);return t?n.create(t):new n(void 0,[new x(b.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(T(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,M.Schema,o);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,M.Table,o);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function og(e,t,r){if(!w(r))return new n(void 0);let i=ms(r)??``;if(!T(r.parentNode))return xo.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,M.Enum,i));let a=Mc(e,r);if(a){if(a.isKind(M.Schema)){let t=e.lookupMembers(a,[M.Enum,M.Schema],i);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(M.Enum)){let t=e.lookupMembers(a,M.EnumField,i);return t?n.create(t):new n(void 0,[new x(b.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(T(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,M.Schema,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,M.Enum,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function sg(e){return e?e.split(``).every(e=>Do(e)||Oo(e))&&!Oo(e[0]):!1}function cg(e){return sg(e)?e:`"${ug(e)}"`}function lg(e){let t=``,n=0,r={n:`
|
|
5
|
+
`,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function ug(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
|
|
6
|
+
`: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 dg(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`'${ug(e)}'`;let{value:t,type:n}=e;if(t==null||pl(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(pl(n)){let e=zm(t);return e===null?`\`${t}\``:e?`true`:`false`}if(fl(n)){let e=Fm(t);return e===null?`\`${t}\``:String(e)}if(gl(n)){let e=Gm(t);return e===null?`\`${t}\``:`'${ug(e)}'`}let r=Vm(t);return r===null?`\`${t}\``:`'${ug(r)}'`}function fg(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?lg(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function pg(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 mg(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 Ts&&n.isKind(M.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)}var hg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof R?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof L)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof L);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(jc).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof Us?[...r.getErrors(),new x(b.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():[])}},gg=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=j(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=vs(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new x(b.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name))),this.tableGroup.name=n,this.tableGroup.schemaName=r[0]||null,t}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof L);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:_s(k(e.body instanceof R?e.body.body[0].callee:e.body.callee)),token:j(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(M.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=O(e.callee);return i.length>2&&n.push(new x(b.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=S(e).getValue();this.tableGroup.color=t.color?.length?ys(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:_s(k(n?.value)),token:j(n)},[]}},_g={getDuplicateError(e,t,n){return new x(b.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new x(b.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},vg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return E(a,r.TableGroup)?new n(i.symbolFactory.create(As,{declaration:a,name:s},a.filepath)):D(a,r.TableGroup)?new n(i.symbolFactory.create(js,{declaration:a,name:o?.map(cg).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(M.TableGroup)){let e=i.declaration;if(!(e instanceof P))return new n([]);let a=cs(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(M.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof P&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(_g.getFieldDuplicateError(e.name,r)),s.push(_g.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(M.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!w(a)||!Yo(a,r.TableGroup)||a.parent&&Zo(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):yg(i,s,a)},bindNode(i,a){if(!E(a,r.TableGroup))return n.create(e);let o=new hg(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!E(o,r.TableGroup)||!(i instanceof As)?n.create(e):Ac(t,o)?new gg(t,i,a).interpret():n.create(void 0)}};function yg(e,r,i){let a=ms(i)??``;if(!T(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Ts&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,M.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,M.Table,a);return s?n.create(s):new n(void 0,[new x(b.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Mc(e,i);if(o){if(o.isKind(M.Schema)){let t=e.lookupMembers(o,[M.Table,M.Schema],a);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,M.Schema,a);return s?n.create(s):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var bg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof R?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof L)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof L);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(g(n)instanceof z){let e=S(g(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t})}tryToBindColumnType(e){let t=us(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return jc(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():[])}},xg=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??j(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}=vs(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=S(e).getValue(),n=va(t[i.HeaderColor]);this.tablePartial.headerColor=n?ys(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:_s(k(r?.value)),token:j(r)},[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof L);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:_s(k(e.body instanceof R?e.body.body[0].callee:e.body.callee)),token:j(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=ms(e.callee)??``,r.token=j(e);let o=xs(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||void 0,r.unique=a?.unique(this.compiler)||void 0,r.increment=a?.increment(this.compiler)||void 0;let s=a?.nullable(this.compiler);r.not_null=s===void 0?void 0:!s,r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let c=this.compiler.nodeSettings(e).getFiltered(t)??{},l=this.compiler.parseFile(this.filepath).getValue().ast,u=this.compiler.nodeSymbol(l).getFiltered(t);return r.inline_refs=(c[i.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!(n instanceof mc))return[];let r=n.owners(this.compiler);if(u&&r.length>0&&!r.some(e=>e===u))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:j(n.rightToken())}}),r.checks=(c[i.Check]||[]).map(e=>({token:j(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()}},Sg={getDuplicateError(e,t,n){return new x(b.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},Cg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return E(a,r.TablePartial)?new n(i.symbolFactory.create(Ns,{declaration:a,name:o},a.filepath)):D(a,r.TablePartial)?new n(i.symbolFactory.create(ks,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(M.TablePartial)){let e=a.declaration;if(!(e instanceof P))return new n([]);let r=cs(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(M.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof P&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(tg.getColumnDuplicateError(t,r)),s.push(tg.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(M.Column)&&E(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!w(o)&&!T(o)||!Yo(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):Xo(o,1)?wg(a,c,o):Qo(o,i.Ref)?Tg(a,c,o):Eg(a,c,o)},bindNode(i,a){if(!E(a,r.TablePartial))return n.create(e);let o=new bg(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 Ns?r.declaration instanceof P?new xg(t,r,i).interpret():n.create(void 0):n.create(e)}};function wg(e,t,r){if(!w(r))return new n(void 0);let i=ms(r)??``;if(!T(r.parentNode))return n.create(e.lookupMembers(t,M.Enum,i));let a=Mc(e,r);if(a){if(a.isKind(M.Schema)){let t=e.lookupMembers(a,[M.Enum,M.Schema],i);return t?n.create(t):new n(void 0,[new x(b.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,M.Schema,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Tg(e,i,a){if(!w(a))return new n(void 0);let o=ms(a)??``;if(!T(a.parentNode)){let s=a.parent;if(s instanceof P&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,M.Column,o);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,M.Column,o);return c?n.create(c):new n(void 0,[new x(b.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Mc(e,a);if(s){if(s.isKind(M.Schema)){let t=e.lookupMembers(s,[M.Table,M.Schema],o);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(M.Table)){let t=e.lookupMembers(s,M.Column,o);return t?n.create(t):new n(void 0,[new x(b.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(T(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,M.Schema,o);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,M.Table,o);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function Eg(e,t,r){if(!w(r))return new n(void 0);let i=ms(r)??``;if(!T(r.parentNode))return xo.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,M.Enum,i));let a=Mc(e,r);if(a){if(a.isKind(M.Schema)){let t=e.lookupMembers(a,[M.Enum,M.Schema],i);return t?n.create(t):new n(void 0,[new x(b.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(M.Enum)){let t=e.lookupMembers(a,M.EnumField,i);return t?n.create(t):new n(void 0,[new x(b.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(T(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,M.Schema,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,M.Enum,i);return a?n.create(a):new n(void 0,[new x(b.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var Dg={symbolMembers(r,i){if(!i.isKind(M.Schema)||!(i instanceof Ts))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=kg(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...Ag(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...Mg(r,i,e,t,c));for(let e of o.uses.selective){let n=kg(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...Ag(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...Mg(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(M.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(M.TableGroup)))}}for(let t of e)u.push(...Pg(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof Us&&e.isKind(M.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(M.Schema))continue;let t=e instanceof Us?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof P&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(Og(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function Og(e,t,n,r){switch(e){case M.Table:return tg.getDuplicateError(t,n,r);case M.Enum:return Kc.getDuplicateError(t,n,r);case M.TablePartial:return Sg.getDuplicateError(t,n,r);case M.TableGroup:return _g.getDuplicateError(t,n,r);case M.DiagramView:return Rc.getDuplicateError(t,n,r);default:return new x(b.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function kg(e,r,i,a){let o=Gh(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(Ts,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function Ag(e,n,r,i=new Set){if(r.getSymbolKind()!==M.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(M.Schema))return[];let o=Vh.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:jg(e,n,r,a,i)}function jg(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(Us,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(M.TableGroup)&&c.push(...Pg(e,n,t));for(let i of s.reuses.selective)if(c.push(...Ag(e,n,i,a)),Gh(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(Us,{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=Ng(e,t,n.qualifiedName);i&&c.push(...jg(e,n,r,i,a))}return c}function Mg(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=Ng(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(Us,{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(Ts,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=kg(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...Ag(e,n,r))}for(let{importPath:t}of d)l.push(...Mg(e,n,t,i,a,o));return l}function Ng(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 Pg(e,n,r){if(!r.isKind(M.TableGroup)||!(r instanceof Us))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(M.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=O(n);if(!i||i.length===0)continue;let a=i.length<=1?[y]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=Fg(e,c,i);l&&s.push(e.symbolFactory.create(Us,{kind:M.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function Fg(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(M.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(M.Table)&&e.name===a)}var Ig=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof L)return[];let t=e.body.filter(e=>e instanceof P);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Lg=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=j(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return 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=S(e).getValue();return t.color?.length&&(this.note.color=ys(t.color.at(0)?.value)),[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof L);return t.length!==1||n.length>0?[new x(b.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=k(e.callee)??``;return this.note.content=_s(t),[]}},Rg=[ng,qc,kh,Xc,Cc,Rh,Sh,vg,Cg,{nodeSymbol(i,a){return!E(a,r.Note)||!(a.parentNode instanceof qs)?n.create(e):new n(i.symbolFactory.create(Ms,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(M.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return E(i,r.Note)?n.create(void 0,new Ig(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Ms?r.declaration instanceof P?new Lg(t,r,i).interpret():n.create(void 0):n.create(e)}},Hh,Dg,zc,yh];function zg(t,...r){for(let i of Rg){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function Bg(r){let i=zg(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Vg(r){let i=zg(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Hg(r){let i=zg(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Ug(r){let i=zg(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function Wg(r){let i=zg(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function Gg(r,i){let a=zg(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function Kg(r,i){let a=zg(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var qg=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 x(b.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof qs?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new x(b.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new x(b.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new x(b.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof L)return[new x(b.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=_(e.body,e=>e instanceof L);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return g(n)instanceof z&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof ec))&&t.push(new x(b.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=S(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 x(b.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{C(t.value)||n.push(new x(b.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new x(b.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Jg={validateNode(t,i){if(!E(i,r.Checks))return n.create(e);let a=new qg(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return E(i,r.Checks)?i.name?new n(void 0,[new x(b.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return E(i,r.Checks)?i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return E(i,r.Checks)?i.attributeList?new n({},[new x(b.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},Yg=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 P&&this.declarationNode.parent.isKind(r.Project)?[]:[new x(b.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e?[new x(b.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new x(b.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new x(b.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof R)return[new x(b.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return C(e.callee)||t.push(new x(b.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 x(b.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function Xg(e){return e instanceof P&&!!e.type?.value}var Zg={validateNode(t,r){if(!Xg(r))return n.create(e);let i=new Yg(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return Xg(r)?r.name?new n(void 0,[new x(b.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return Xg(r)?r.alias?new n(void 0,[new x(b.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return Xg(r)?r.attributeList?new n({},[new x(b.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},Qg=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 P?[new x(b.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?No(e)?[]:[new x(b.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new x(b.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new x(b.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=S(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new x(b.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof L)return{errors:[new x(b.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=_(e.body,e=>e instanceof L),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Uo(e.callee)?e.args.length>0?e.args.map(e=>new x(b.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new x(b.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 x(b.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(Po(e))return t.push(new x(b.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof R))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof L&&Uo(e.callee)),a=r.body.some(e=>e instanceof L&&!Uo(e.callee));return i&&a&&n.push(new Eo(b.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 R))return t;let n=e.body.body.filter(e=>e instanceof L);for(let e of n)Uo(e.callee)||(e.args.length>0||!O(e.callee))&&t.push(...e.args.map(e=>new x(b.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},$g={validateNode(t,i){if(!E(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new Qg(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(E(i,r.DiagramView)){if(!i.name)return new n(void 0,[new x(b.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=O(i.name);return e?new n(e):new n(void 0)}else if(D(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=O(i.callee);return e?(e.length===1&&D(i,r.DiagramViewTables)&&e.unshift(y),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return E(i,r.DiagramView)?new n(void 0):n.create(e)}},e_=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 P?[new x(b.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof ac?[new x(b.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:jo(e)?[]:[new x(b.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new x(b.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new x(b.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new x(b.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof L)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof L);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new x(b.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!w(n.callee)&&t.push(new x(b.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];g(e)instanceof z?(t.push(...this.validateFieldSettings(g(e))),e.pop()):e[0]instanceof z&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new x(b.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=S(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 x(b.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{C(e.value)||n.push(new x(b.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new x(b.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():[])}},t_={validateNode(t,i){return E(i,r.Enum)?n.create(void 0,new e_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(E(i,r.Enum)){if(!i.name)return new n(void 0,[new x(b.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!jo(i.name))return new n(void 0,[new x(b.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=O(i.name);return e?.length===1&&e.unshift(y),new n(e)}if(D(i,r.Enum)){let e=A(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return E(i,r.Enum)?i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):D(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(E(a,r.Enum))return a.attributeList?new n({},[new x(b.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(D(a,r.Enum)){let e=[...a.args],t;if(g(e)instanceof z?t=g(e):e[0]instanceof z&&(t=e[0]),!t)return new n({});let r=S(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 x(b.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{C(e.value)||o.push(new x(b.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new x(b.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},n_=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 x(b.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof qs?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new x(b.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new x(b.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new x(b.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof L)return[new x(b.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=_(e.body,e=>e instanceof L);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return g(n)instanceof z&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof B;)e.argumentList&&ds(e.argumentList)===void 0&&t.push(new x(b.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;ds(e)===void 0&&t.push(new x(b.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=S(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 x(b.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{C(t.value)||n.push(new x(b.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new x(b.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new x(b.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new x(b.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{w(e.value)||n.push(new x(b.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new x(b.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},r_={validateNode(t,i){return E(i,r.Indexes)?n.create(void 0,new n_(t,i).validate()):n.create(e)},nodeFullname(t,i){return E(i,r.Indexes)?i.name?new n(void 0,[new x(b.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):D(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return E(i,r.Indexes)?i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):D(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(E(a,r.Indexes))return a.attributeList?new n({},[new x(b.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(D(a,r.Indexes)){let e=[a.callee,...a.args],t;if(g(e)instanceof z&&(t=g(e)),!t)return new n({});let r=S(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 x(b.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{C(t.value)||o.push(new x(b.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 x(b.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new x(b.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 x(b.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{w(e.value)||o.push(new x(b.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new x(b.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},i_=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 qs)&&!(e instanceof P&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project))?[new x(b.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 x(b.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof qs}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new x(b.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=S(e),n=t.getErrors();return Sa(t.getValue(),(e,t)=>{switch(t){case i.Color:e.length>1&&n.push(...e.map(e=>new x(b.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{let t=Wo(e.value)&&e.value.expression.variable.value.toLowerCase()===`none`;!Lo(e.value)&&!t&&n.push(new x(b.INVALID_NOTE_SETTING_VALUE,`'color' must be a color literal or 'none'`,e.value||e.name))});break;default:n.push(...e.map(e=>new x(b.UNKNOWN_NOTE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof L)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof L);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new x(b.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new x(b.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),C(e[0].callee)||t.push(new x(b.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 x(b.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():[])}},a_={validateNode(t,i){return E(i,r.Note)?n.create(void 0,new i_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!E(i,r.Note))return n.create(e);if(!(i.parent instanceof qs))return i.name?new n(void 0,[new x(b.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new x(b.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof ac)return new n(void 0,[new x(b.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=O(i.name);return a===void 0?new n(void 0,[new x(b.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return E(i,r.Note)?i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return E(i,r.Note)?i.attributeList?new n({},[new x(b.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},o_=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)}},s_={validateNode(t,r){return Jo(r)?n.create(void 0,new o_(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Jo(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Jo(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Jo(r)?new n({}):n.create(e)}},c_=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 P?[new x(b.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?No(e)?new n(O(e)):new n(void 0,[new x(b.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 x(b.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new x(b.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof L)return[new x(b.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof L);return[...t.map(e=>new x(b.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():[])}},l_={validateNode(t,i){return E(i,r.Project)?n.create(void 0,new c_(t,i).validate()):n.create(e)},nodeFullname(t,i){return E(i,r.Project)?i.name?No(i.name)?new n(O(i.name)):new n(void 0,[new x(b.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):D(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return E(i,r.Project)&&i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):D(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return E(i,r.Project)?i.attributeList?new n({},[new x(b.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):D(i,r.Project)?new n({}):n.create(e)}},u_=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 qs||e instanceof P&&e.isKind(r.Table)?[]:[new x(b.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof ac?[new x(b.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof qs?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof B))return[new x(b.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||!jo(e.callee))&&t.push(new x(b.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Vo(e.argumentList))&&t.push(new x(b.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Vo(e)?[new x(b.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new x(b.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new x(b.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof L)return this.validateDataRow(e);let[t,n]=_(e.body,e=>e instanceof L);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 x(b.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof nc)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new x(b.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 x(b.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 cc||zo(e)||C(e)||e instanceof ec)return!0;if(w(e)){let t=e.expression.variable.value.toLowerCase();return xo.includes(t)}if(T(e)){let t=O(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},d_={validateNode(t,i){return E(i,r.Records)?n.create(void 0,new u_(t,i).validate()):n.create(e)},nodeFullname(i,a){if(E(a,r.Records)){if(a.name instanceof ac)return new n(void 0,[new x(b.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof qs){if(!(a.name instanceof B))return new n(void 0,[new x(b.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||!jo(a.name.callee))&&e.push(new x(b.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Vo(a.name.argumentList))&&e.push(new x(b.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=O(a.name.callee);return t?.length===1&&t.unshift(y),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Vo(a.name)?new n(e,[new x(b.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return D(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return E(i,r.Records)?i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):D(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return E(i,r.Records)?i.attributeList?new n({},[new x(b.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,i.attributeList)]):new n({}):D(i,r.Records)?new n({}):n.create(e)}},f_=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 qs?[]:[new x(b.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof ac?[new x(b.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:No(e)?[]:[new x(b.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new x(b.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new x(b.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof L)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof L);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new x(b.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 x(b.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!$o(e.callee)&&t.push(new x(b.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&$o(e.callee)){let n=us(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=us(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new x(b.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new x(b.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!es(e.callee)&&t.push(new x(b.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(g(n)instanceof z){let e=this.validateFieldSettings(g(n));t.push(...e),n.pop()}else n[0]instanceof z&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new x(b.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return m_(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function p_(e){if(!(w(e)&&e.expression.variable.kind!==v.QUOTED_STRING)&&!(e instanceof Zs))return!1;let t;if(t=e instanceof Zs?as(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 m_(e){let t=S(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 x(b.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{p_(t.value)||r.push(new x(b.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 x(b.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Lo(e.value)||r.push(new x(b.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 x(b.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new x(b.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new x(b.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var h_={validateNode(t,i){return E(i,r.Ref)?n.create(void 0,new f_(t,i).validate()):n.create(e)},nodeFullname(t,i){return E(i,r.Ref)?i.name?No(i.name)?new n(O(i.name)):new n(void 0,[new x(b.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):D(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return E(i,r.Ref)?i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):D(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(E(i,r.Ref))return i.attributeList?new n({},[new x(b.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(D(i,r.Ref)){let e=[...i.args],t;return g(e)instanceof z?t=g(e):e[0]instanceof z&&(t=e[0]),t?m_(t):new n({})}return n.create(e)}},g_=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 P?[new x(b.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof lc?[new x(b.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof ac?[new x(b.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:jo(e)?[]:[new x(b.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new x(b.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Mo(e)?[]:[new x(b.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=S(e),n=t.getErrors();return Sa(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new x(b.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Lo(e.value)||n.push(new x(b.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&n.push(...e.map(e=>new x(b.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{C(e.value)||n.push(new x(b.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new x(b.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof L)return[new x(b.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof L);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 x(b.INVALID_COLUMN,`A column must have a type`,e.callee)),w(e.callee)||t.push(new x(b.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Ho(e.args[0])&&t.push(new x(b.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?(Fo(e.callee)||t.push(new x(b.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 x(b.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof I&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){if(!e.slice(0,-1).every(Wo)||!e.slice(-1).every(e=>Wo(e)||e instanceof z))return e.map(e=>new x(b.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let t;g(e)instanceof z&&(t=e.pop());let n=S(t),r=n.getErrors(),a=n.getValue();e.forEach(e=>{let t=(A(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){r.push(new x(b.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}a[t]===void 0?a[t]=[e]:a[t].push(e)});let o=a[i.PK]||[],s=a[i.PrimaryKey]||[];return o.length>=1&&s.length>=1&&r.push(...[...o,...s].map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(a,(e,t)=>{switch(t){case i.Note:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{C(e.value)||r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Bo(e.value)||r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=a[i.Null]||[];e.length>=1&&t.length>=1&&r.push(...[...e,...t].map(e=>new x(b.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Ro(e.value)||r.push(new x(b.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 ec||r.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new x(b.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),r}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new x(b.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function __(e){let t=S(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Lo(e.value)||r.push(new x(b.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{C(e.value)||r.push(new x(b.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new x(b.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function v_(e){if(!e.slice(0,-1).every(Wo)||!e.slice(-1).every(e=>Wo(e)||e instanceof z))return new n({},e.map(e=>new x(b.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let t;g(e)instanceof z&&(t=e.pop());let r=S(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(A(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{C(e.value)||a.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Bo(e.value)||a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&a.push(new x(b.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 x(b.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 x(b.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 x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Ro(e.value)||a.push(new x(b.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 ec||a.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new x(b.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(o,a)}var y_={validateNode(t,i){return E(i,r.Table)?n.create(void 0,new g_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(E(i,r.Table)){if(!i.name)return new n(void 0,[new x(b.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof lc)return new n(void 0,[new x(b.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=O(i.name);return e?.length===1&&e.unshift(y),new n(e)}if(D(i,r.Table)){if(Fo(i.callee)){let e=A(i.callee.expression);return new n(e?[e]:void 0)}let e=A(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return E(i,r.Table)?i.alias?Mo(i.alias)?new n(A(i.alias)):new n(void 0,[new x(b.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):D(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return E(i,r.Table)?i.attributeList?__(i.attributeList):new n({}):D(i,r.Table)?v_(i.args.slice(1)):n.create(e)}},b_=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 P?[new x(b.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof ac?[new x(b.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:No(e)?[]:[new x(b.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new x(b.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new x(b.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=S(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`color`:t.length>1&&n.push(...t.map(e=>new x(b.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Lo(e.value)||n.push(new x(b.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))});break;case`note`:t.length>1&&n.push(...t.map(e=>new x(b.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!C(e.value)).forEach(e=>{n.push(new x(b.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...t.map(t=>new x(b.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return n}validateBody(e){if(!e)return[];if(e instanceof L)return[new x(b.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof L);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&O(e.callee)===void 0&&t.push(new x(b.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 x(b.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 x(b.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function x_(e){let t=S(e),r=t.getErrors(),i=t.getValue(),a={};for(let[e,t]of Object.entries(i))switch(e){case`color`:t.length>1&&r.push(...t.map(e=>new x(b.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Lo(e.value)||r.push(new x(b.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))}),a[e]=t;break;case`note`:t.length>1&&r.push(...t.map(e=>new x(b.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!C(e.value)).forEach(e=>{r.push(new x(b.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))}),a[e]=t;break;default:r.push(...t.map(t=>new x(b.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return new n(a,r)}var S_={validateNode(t,i){return E(i,r.TableGroup)?n.create(void 0,new b_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(E(i,r.TableGroup))return i.name?No(i.name)?new n(O(i.name)):new n(void 0,[new x(b.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new x(b.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(D(i,r.TableGroup)){let e=O(i.callee);return e?.length===1&&e.unshift(y),new n(e)}return n.create(e)},nodeAlias(t,i){return E(i,r.TableGroup)?i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):D(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return E(i,r.TableGroup)?x_(i.attributeList):D(i,r.TableGroup)?new n({}):n.create(e)}},C_=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 P?[new x(b.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof ac?[new x(b.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:No(e)?[]:[new x(b.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new x(b.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new x(b.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=S(e),n=t.getErrors();return Sa(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new x(b.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Lo(e.value)||n.push(new x(b.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 x(b.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{C(e.value)||n.push(new x(b.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new x(b.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof L)return[new x(b.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof L);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 x(b.INVALID_COLUMN,`A column must have a type`,e.callee)),w(e.callee)||t.push(new x(b.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Ho(e.args[0])&&t.push(new x(b.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t})}validateFieldSetting(e){let t=g(e);if(!e.slice(0,-1).every(Wo)||!(Wo(t)||t instanceof z))return e.map(e=>new x(b.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;g(e)instanceof z&&(n=e.pop());let r=S(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(A(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{C(e.value)||a.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Bo(e.value)||a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&a.push(new x(b.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 x(b.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 x(b.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 x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&a.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Ro(e.value)||a.push(new x(b.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 ec||a.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new x(b.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),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 x(b.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function w_(e){let t=S(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new x(b.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Lo(e.value)||r.push(new x(b.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 x(b.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{C(e.value)||r.push(new x(b.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new x(b.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function T_(e){let t=g(e);if(e.length>0&&(!e.slice(0,-1).every(Wo)||!(Wo(t)||t instanceof z)))return new n({},e.map(e=>new x(b.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let r;g(e)instanceof z&&(r=e.pop());let a=S(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(A(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{C(e.value)||o.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Bo(e.value)||o.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&o.push(new x(b.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 x(b.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 x(b.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 x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&o.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof F&&e.value!==void 0&&o.push(new x(b.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 x(b.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Ro(e.value)||o.push(new x(b.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 ec||o.push(new x(b.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>o.push(new x(b.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(s,o)}var E_={validateNode(t,i){return E(i,r.TablePartial)?n.create(void 0,new C_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(E(i,r.TablePartial))return i.name?No(i.name)?new n(O(i.name)):new n(void 0,[new x(b.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new x(b.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(D(i,r.TablePartial)){let e=A(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return E(i,r.TablePartial)?i.alias?new n(void 0,[new x(b.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(A(i.alias)):D(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return E(i,r.TablePartial)?w_(i.attributeList):D(i,r.TablePartial)?T_(i.args.slice(1)):n.create(e)}},D_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof qs?[]:[new x(b.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.importPath&&!yo.isRelative(this.declarationNode.importPath.value)&&e.push(new x(b.INVALID_USE_SPECIFIER_NAME,`Import path must be a relative path (starting with './' or '../')`,this.declarationNode.importPath)),this.declarationNode.specifiers instanceof ac)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 x(b.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Ss))||t.push(new x(b.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()]}},O_=[y_,t_,d_,r_,Jg,h_,l_,S_,E_,a_,$g,s_,{validateNode(t,r){return r instanceof Js?n.create(void 0,new D_(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!qo(r))return n.create(e);let i=O(r.name);return!i||i.length===0?n.create(void 0,[new x(b.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Ss.TableGroup)&&i.length>1?n.create(i,[new x(b.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Ss.TablePartial)&&i.length>1?n.create(i,[new x(b.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Ss.Note)&&i.length>1?n.create(i,[new x(b.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Ss.Schema)&&i.unshift(y),new n(i))},nodeAlias(t,r){return qo(r)?r.alias?Mo(r.alias)?new n(A(r.alias)):new n(void 0,[new x(b.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 Js?n.create({}):n.create(e)}},Zg];function k_(t,...r){for(let n of O_){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function A_(r){let i=k_(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function j_(r){let i=k_(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function M_(r){let i=k_(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function N_(r){let i=k_(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var P_=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function F_(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}),P_&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function I_(e,t,...n){return F_(t,n)}var L_=!1,R_=!1,z_=!1,B_=!1,V_=void 0,H_=typeof self==`object`?self:typeof global==`object`?global:{},U_=void 0;H_.vscode!==void 0&&H_.vscode.process!==void 0?U_=H_.vscode.process:typeof process<`u`&&(U_=process);var W_=typeof U_?.versions?.electron==`string`&&U_?.type===`renderer`;if(typeof navigator==`object`&&!W_)V_=navigator.userAgent,L_=V_.indexOf(`Windows`)>=0,R_=V_.indexOf(`Macintosh`)>=0,(V_.indexOf(`Macintosh`)>=0||V_.indexOf(`iPad`)>=0||V_.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,z_=V_.indexOf(`Linux`)>=0,V_?.indexOf(`Mobi`),B_=!0,I_({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof U_==`object`){L_=U_.platform===`win32`,R_=U_.platform===`darwin`,z_=U_.platform===`linux`,z_&&U_.env.SNAP&&U_.env.SNAP_REVISION,U_.env.CI||U_.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=U_.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 G_=L_,K_=R_;B_&&H_.importScripts;var q_=V_,J_=typeof H_.postMessage==`function`&&!H_.importScripts;(()=>{if(J_){let e=[];H_.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}),H_.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var Y_=!!(q_&&q_.indexOf(`Chrome`)>=0);q_&&q_.indexOf(`Firefox`),!Y_&&q_&&q_.indexOf(`Safari`),q_&&q_.indexOf(`Edg/`),q_&&q_.indexOf(`Android`);var X_;if(H_.vscode!==void 0&&H_.vscode.process!==void 0){let e=H_.vscode.process;X_={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else X_=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 G_?`win32`:K_?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var Z_=X_.cwd,Q_=X_.env,$_=X_.platform,ev=65,tv=97,nv=90,rv=122,iv=46,av=47,ov=92,sv=58,cv=63,lv=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 uv(e,t){if(typeof e!=`object`||!e)throw new lv(t,`Object`,e)}function dv(e,t){if(typeof e!=`string`)throw new lv(t,`string`,e)}var fv=$_===`win32`;function q(e){return e===av||e===ov}function pv(e){return e===av}function mv(e){return e>=ev&&e<=nv||e>=tv&&e<=rv}function hv(e,t,n,r){let i=``,a=0,o=-1,s=0,c=0;for(let l=0;l<=e.length;++l){if(l<e.length)c=e.charCodeAt(l);else if(r(c))break;else c=av;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==iv||i.charCodeAt(i.length-2)!==iv){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===iv&&s!==-1?++s:s=-1}return i}function gv(e,t){uv(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 _v={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],dv(a,`path`),a.length===0)continue}else t.length===0?a=Z_():(a=Q_[`=${t}`]||Z_(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===ov)&&(a=`${t}\\`));let o=a.length,s=0,c=``,l=!1,u=a.charCodeAt(0);if(o===1)q(u)&&(s=1,l=!0);else if(q(u))if(l=!0,q(a.charCodeAt(1))){let e=2,t=e;for(;e<o&&!q(a.charCodeAt(e));)e++;if(e<o&&e!==t){let n=a.slice(t,e);for(t=e;e<o&&q(a.charCodeAt(e));)e++;if(e<o&&e!==t){for(t=e;e<o&&!q(a.charCodeAt(e));)e++;(e===o||e!==t)&&(c=`\\\\${n}\\${a.slice(t,e)}`,s=e)}}}else s=1;else mv(u)&&a.charCodeAt(1)===sv&&(c=a.slice(0,2),s=2,o>2&&q(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=hv(n,!r,`\\`,q),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){dv(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return pv(a)?`\\`:e;if(q(a))if(i=!0,q(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!q(e.charCodeAt(i));)i++;if(i<t&&i!==a){let o=e.slice(a,i);for(a=i;i<t&&q(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!q(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 mv(a)&&e.charCodeAt(1)===sv&&(r=e.slice(0,2),n=2,t>2&&q(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?hv(e.slice(n),!i,`\\`,q):``;return o.length===0&&!i&&(o=`.`),o.length>0&&q(e.charCodeAt(t-1))&&(o+=`\\`),r===void 0?i?`\\${o}`:o:i?`${r}\\${o}`:`${r}${o}`},isAbsolute(e){dv(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return q(n)||t>2&&mv(n)&&e.charCodeAt(1)===sv&&q(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];dv(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`&&q(n.charCodeAt(0))){++i;let e=n.length;e>1&&q(n.charCodeAt(1))&&(++i,e>2&&(q(n.charCodeAt(2))?++i:r=!1))}if(r){for(;i<t.length&&q(t.charCodeAt(i));)i++;i>=2&&(t=`\\${t.slice(i)}`)}return _v.normalize(t)},relative(e,t){if(dv(e,`from`),dv(t,`to`),e===t)return``;let n=_v.resolve(e),r=_v.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===ov;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===ov;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===ov;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===ov;)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===ov&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===ov)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===ov?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)===ov)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===ov&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=_v.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===ov){if(t.charCodeAt(1)===ov){let e=t.charCodeAt(2);if(e!==cv&&e!==iv)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(mv(t.charCodeAt(0))&&t.charCodeAt(1)===sv&&t.charCodeAt(2)===ov)return`\\\\?\\${t}`;return e},dirname(e){dv(e,`path`);let t=e.length;if(t===0)return`.`;let n=-1,r=0,i=e.charCodeAt(0);if(t===1)return q(i)?e:`.`;if(q(i)){if(n=r=1,q(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!q(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&q(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!q(e.charCodeAt(i));)i++;if(i===t)return e;i!==a&&(n=r=i+1)}}}}else mv(i)&&e.charCodeAt(1)===sv&&(n=t>2&&q(e.charCodeAt(2))?3:2,r=n);let a=-1,o=!0;for(let n=t-1;n>=r;--n)if(q(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&&dv(t,`ext`),dv(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&mv(e.charCodeAt(0))&&e.charCodeAt(1)===sv&&(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(q(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(q(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){dv(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===sv&&mv(e.charCodeAt(0))&&(t=r=2);for(let s=e.length-1;s>=t;--s){let t=e.charCodeAt(s);if(q(t)){if(!a){r=s+1;break}continue}i===-1&&(a=!1,i=s+1),t===iv?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:gv.bind(null,`\\`),parse(e){dv(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 q(i)?(t.root=t.dir=e,t):(t.base=t.name=e,t);if(q(i)){if(r=1,q(e.charCodeAt(1))){let t=2,i=t;for(;t<n&&!q(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&q(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&!q(e.charCodeAt(t));)t++;t===n?r=t:t!==i&&(r=t+1)}}}}else if(mv(i)&&e.charCodeAt(1)===sv){if(n<=2)return t.root=t.dir=e,t;if(r=2,q(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),q(i)){if(!c){o=l+1;break}continue}s===-1&&(c=!1,s=l+1),i===iv?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},vv=(()=>{if(fv){let e=/\\/g;return()=>{let t=Z_().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Z_()})(),yv={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:vv();dv(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===av)}return t=hv(t,!n,`/`,pv),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(dv(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===av,n=e.charCodeAt(e.length-1)===av;return e=hv(e,!t,`/`,pv),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return dv(e,`path`),e.length>0&&e.charCodeAt(0)===av},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];dv(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:yv.normalize(t)},relative(e,t){if(dv(e,`from`),dv(t,`to`),e===t||(e=yv.resolve(e),t=yv.resolve(t),e===t))return``;let n=e.length,r=n-1,i=t.length-1,a=r<i?r:i,o=-1,s=0;for(;s<a;s++){let n=e.charCodeAt(1+s);if(n!==t.charCodeAt(1+s))break;n===av&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===av)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===av?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===av)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(dv(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===av,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===av){if(!r){n=t;break}}else r=!1;return n===-1?t?`/`:`.`:t&&n===1?`//`:e.slice(0,n)},basename(e,t){t!==void 0&&dv(t,`ext`),dv(e,`path`);let n=0,r=-1,i=!0,a;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=0;--a){let c=e.charCodeAt(a);if(c===av){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=0;--a)if(e.charCodeAt(a)===av){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){dv(e,`path`);let t=-1,n=0,r=-1,i=!0,a=0;for(let o=e.length-1;o>=0;--o){let s=e.charCodeAt(o);if(s===av){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===iv?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:gv.bind(null,`/`),parse(e){dv(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===av,r;n?(t.root=`/`,r=1):r=0;let i=-1,a=0,o=-1,s=!0,c=e.length-1,l=0;for(;c>=r;--c){let t=e.charCodeAt(c);if(t===av){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===iv?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};yv.win32=_v.win32=_v,yv.posix=_v.posix=yv,fv?_v.normalize:yv.normalize,fv?_v.resolve:yv.resolve,fv?_v.relative:yv.relative,fv?_v.dirname:yv.dirname,fv?_v.basename:yv.basename,fv?_v.extname:yv.extname,fv?_v.sep:yv.sep;var bv=/^\w[\w\d+.-]*$/,xv=/^\//,Sv=/^\/\//;function Cv(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&&!bv.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!xv.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(Sv.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 wv(e,t){return!e&&!t?`file`:e}function Tv(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==Ev&&(t=Ev+t):t=Ev;break}return t}var J=``,Ev=`/`,Dv=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,Ov=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||J,this.authority=e.authority||J,this.path=e.path||J,this.query=e.query||J,this.fragment=e.fragment||J):(this.scheme=wv(e,a),this.authority=t||J,this.path=Tv(this.scheme,n||J),this.query=r||J,this.fragment=i||J,Cv(this,a))}get fsPath(){return Pv(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=J),n===void 0?n=this.authority:n===null&&(n=J),r===void 0?r=this.path:r===null&&(r=J),i===void 0?i=this.query:i===null&&(i=J),a===void 0?a=this.fragment:a===null&&(a=J),t===this.scheme&&n===this.authority&&r===this.path&&i===this.query&&a===this.fragment?this:new Av(t,n,r,i,a)}static parse(e,t=!1){let n=Dv.exec(e);return n?new Av(n[2]||J,Rv(n[4]||J),Rv(n[5]||J),Rv(n[7]||J),Rv(n[9]||J),t):new Av(J,J,J,J,J)}static file(e){let t=J;if(G_&&(e=e.replace(/\\/g,Ev)),e[0]===Ev&&e[1]===Ev){let n=e.indexOf(Ev,2);n===-1?(t=e.substring(2),e=Ev):(t=e.substring(2,n),e=e.substring(n)||Ev)}return new Av(`file`,t,e,J,J)}static from(e,t){return new Av(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=G_&&t.scheme===`file`?e.file(_v.join(Pv(t,!0),...n)).path:yv.join(t.path,...n),t.with({path:r})}toString(e=!1){return Fv(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new Av(t);return e._formatted=t.external??null,e._fsPath=t._sep===kv?t.fsPath??null:null,e}}},kv=G_?1:void 0,Av=class extends Ov{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=Pv(this,!1),this._fsPath}toString(e=!1){return e?Fv(this,!0):(this._formatted||=Fv(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=kv),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}},jv={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 Mv(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=jv[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 Nv(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+=jv[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function Pv(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,G_&&(n=n.replace(/\//g,`\\`)),n}function Fv(e,t){let n=t?Nv:Mv,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=Ev,r+=Ev),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:Mv(c,!1,!1)),r}function Iv(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+Iv(e.substr(3)):e}}var Lv=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function Rv(e){return e.match(Lv)?e.replace(Lv,e=>Iv(e)):e}var Y=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}({}),X=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),zv=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 Bv(e,t){return e.getOffsetAt(t)}function Vv(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 Hv=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=yo.fromUri(String(e.uri)),a=Bv(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&&[Ks.PRIMARY_EXPRESSION,Ks.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=Ov.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[]}},Uv=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos;return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code,filepath:e.filepath}}getSeverityValue(e){return e===`error`?zv.Error:zv.Warning}},Wv=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=yo.fromUri(String(r)),a=Bv(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[Ks.ELEMENT_DECLARATION,Ks.FUNCTION_APPLICATION,Ks.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=Ov.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 Gv(e,t){return e>=t.start&&e<t.end}function Kv(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 qv(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 Xs)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=A(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?A(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof ac&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof ac)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function Jv(e,t,n,r,i,a){let o=qv(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:Yv(Na([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
|
|
7
|
+
`),removeRange:Xv(a,e.startOffset,e.endOffset)}}return{topInsert:Yv([l],s,`
|
|
8
|
+
`)}}function Yv(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function Xv(e,t,n){let r=e.lastIndexOf(`
|
|
9
9
|
`,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]===`
|
|
10
|
-
`&&i++,{startOffset:r,endOffset:i}}function
|
|
11
|
-
`?(n++,r=1):r++;return{line:n,column:r}}function zS(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof F)||!o.isKind(r.Records)||!(o.body instanceof z)||!o.body||!TS(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof P?BS(e,o):VS(e,o)}function BS(e,n){if(!(n.name instanceof V))return Z();let r=n.name.argumentList?.elementList||[],i=r.map(n=>e.nodeReferee(n).getFiltered(t));if(!i||i.length===0)return Z();let a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Vu||r instanceof nd))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}});return a.length===0?Z():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function VS(e,n){let r=n.parent;if(!(r instanceof F))return Z();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof Bu))return Z();let a;if(n.name instanceof dd){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 Vu||r instanceof nd))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 Z();a=t}return a.length===0?Z():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function HS(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof id&&n>=o.start&&n<=o.fullEnd)return US(e,t,n,o,i,r);return null}function US(e,t,n,r,i,a){if(r.importPath&&TS(n,r.importPath))return JS(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return Z();if(r.fromKeyword&&n>r.fromKeyword.end)return JS(e,t,void 0,i,r);if(r.specifiers instanceof od){if(!r.specifiers.openBrace){let e=qS();return MS(r.useKeyword,n)?NS(e):e}return WS(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof hd)return Z();let o=qS();return MS(r.useKeyword,n)?NS(o):o}function WS(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!==j.Schema)return KS(e,t,i,n)}return GS()}}return GS()}function GS(){return{suggestions:Object.keys(Pu).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}}function KS(e,n,r,i){if(!r)return Z();let a=Ml(n,r.value);if(!a)return Z();let o=e.usableMembers(a).getFiltered(t);if(!o)return Z();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 td&&!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:X.KeepWhitespace,kind:jS(i),range:void 0}))}}function qS(){return{suggestions:[{label:`* from`,detail:`import all`,insertText:"* from '${1:./path}'",insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0},{label:`{ } from`,detail:`import named`,insertText:"{ ${1:type} ${2:name} } from '${3:./path}'",insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function JS(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=xS(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=Gc(e.layout.getEntrypoints().flatMap(t=>[...e.reachableFiles(t)]),e=>e.intern());for(let n of d){if(n.equals(t))continue;let r=n.relativeTo(a);if(r.endsWith(`.dbml`)&&(r=r.slice(0,-5)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=jl.resolve(a,d),p=e.layout.isDirectory(f);if(XS(e,n,YS(i))&&u.set(d,!0),l.has(d))continue;let m=s?`'${d}'`:d;l.set(d,{label:d,insertText:m,insertTextRules:X.KeepWhitespace,kind:p?Y.Folder:Y.File,sortText:`${p?`2`:`3`}${d}`,range:c})}for(let[e,t]of l)u.get(e)&&(t.sortText=`${t.kind===Y.File?`0`:`1`}${e}`,t.detail=`best match`);return{suggestions:[...l.values()]}}function YS(e){let t=e.specifiers;return t instanceof od?t.specifiers.flatMap(e=>{let t=k(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function XS(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 ZS=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=jl.fromUri(String(e.uri)),r=bS(e,t),i=zS(this.compiler,e,t,n,r);if(i!==null)return i;let a=this.compiler.token.flatStream(n),{token:o,index:s}=this.compiler.container.token(n,r),c=s===void 0?a[0]:a[s+1];if([...o?.trailingTrivia||[],...o?.leadingTrivia||[],...c?.leadingTrivia||[]].find(e=>ol(e)&&TS(r,e)))return Z();if(s===void 0)return uC();let l=HS(this.compiler,n,r,o,e);if(l!==null)return l;if([_.STRING_LITERAL,_.QUOTED_STRING].includes(o.kind)&&TS(r,o))return Z();let u=this.compiler.container.element(n,r);if(this.compiler.container.scopeKind(n,r)===Q.TOPLEVEL||u instanceof F&&u.type&&u.type.start<=r&&u.type.end>=r)return uC();let d=[...this.compiler.container.stack(n,r)].reverse();for(let e of d)if(e instanceof L)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return $S(this.compiler,n,r,e);case`~`:return QS(this.compiler,n,r);default:}else if(e instanceof cd)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return $S(this.compiler,n,r,e);case`.`:return cC(this.compiler,n,r,e);default:}else if(e instanceof I)return iC(this.compiler,n,r,e);else if(e instanceof B)return iC(this.compiler,n,r,e);else if(e instanceof dd)return nC(this.compiler,n,r,e);else if(e instanceof fd)return rC(this.compiler,n,r);else if(e instanceof V)return gC(this.compiler,n,r,e);else if(e instanceof R)return lC(this.compiler,n,r,e);else if(e instanceof F){if(ES(r,e))return hC(this.compiler,n,r,e);if(e.bodyColon&&r>=e.bodyColon.end||e.body&&TS(r,e.body))return lC(this.compiler,n,r,void 0)}return Z()}};function QS(e,t,n){return tC(e,t,n,e.parse.ast(t),[j.TablePartial])}function $S(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=tC(e,t,n,e.container.element(t,n),[j.Table,j.Schema,j.Column]);return MS(r.op,n)?NS(i):i}return Z()}function eC(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?PS({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof Lu&&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:X.KeepWhitespace,kind:jS(e.kind),sortText:jS(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):Z()}function tC(e,n,r,i,a){if(i===void 0)return Z();let o=i,s={suggestions:[]},c;for(;o;){o instanceof P&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=eC(e,n,a).suggestions,r=e=>{switch(e){case Y.Field:return 0;case Y.Module:return 1;case Y.Class:return 2;default:return 3}};t.sort((e,t)=>r(e.kind)-r(t.kind)),s.suggestions.push(...t)}o=o instanceof F?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 IS(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 PS(s)}function nC(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 V&&t.argumentList===a)return gC(e,n,i,t);if(s instanceof F&&s.isKind(r.Records)&&!(s.name instanceof V)&&ES(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=eC(e,i,[j.Column]);return yu(a)?FS(t):t}}switch(o){case Q.INDEXES:return bC(e,n,i);case Q.REF:for(;c.length>0;){let t=c.pop();if(t instanceof cd&&t.op?.value===`.`)return cC(e,n,i,t)}return mC(e,n,i);default:break}return Z()}function rC(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?tC(e,t,n,e.container.element(t,n),[j.Schema,j.Enum,j.EnumField]):Z()}function iC(e,t,n,r){let{token:i}=e.container.token(t,n);if([_.COMMA,_.LBRACKET].includes(i?.kind)){let r=aC(e,t,n);return i?.kind===_.COMMA&&MS(i,n)?NS(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return aC(e,t,n);if(r.name instanceof sd){let a=oC(e,t,n,_u(r.name)??``);return i?.kind===_.COLON&&MS(i,n)?NS(a):a}return Z()}function aC(e,t,n){let r=e.container.element(t,n);if(r instanceof P)return Z();let a=e.container.scopeKind(t,n);if(r.body&&!TS(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=[i.HeaderColor,i.Note];break;case Q.TABLEGROUP:e=[i.Color,i.Note];break;case Q.NOTE:e=[i.Color];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:Y.Field,insertTextRules:X.KeepWhitespace,range:void 0}))}}switch(a){case Q.TABLE:case Q.TABLEPARTIAL:return{suggestions:[...[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique].map(e=>({label:e,insertText:e,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0})),...[i.Ref,i.Default,i.Note,i.Check].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.ENUM:return{suggestions:[...[i.Note].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.INDEXES:return{suggestions:[...[i.Unique,i.PK].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Property,range:void 0})),...[i.Note,i.Name,i.Type].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.REF:return{suggestions:[{label:i.Inactive,insertText:i.Inactive,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0},...[i.Update,i.Delete,i.Color].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.CHECKS:return{suggestions:[i.Name].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))};default:break}return Z()}function oC(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};case`color`:if(e.container.scopeKind(t,n)===Q.NOTE)return{suggestions:[Pl].map(e=>({label:e,insertText:e,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};break;case`default`:return tC(e,t,n,e.container.element(t,n),[j.Schema,j.Enum]);default:break}return Z()}function sC(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 F?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 cC(e,n,r,i){let a=xu(i)??[];return a.pop(),a.some(e=>!C(e))?Z():PS({suggestions:sC(e,a.map(e=>k(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:jS(e.kind),range:void 0}})})}function lC(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return fC(e,t,n,i);case Q.PROJECT:return pC(e,t,n,i);case Q.INDEXES:return vC(e,t,n);case Q.ENUM:return dC(e,t,n,i);case Q.REF:{let r=mC(e,t,n);return e.container.token(t,n).token?.kind===_.COLON&&MS(e.container.token(t,n).token,n)?NS(r):r}case Q.TABLEGROUP:return _C(e,t);case Q.DIAGRAMVIEW:return CC();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof F){let a=i.parentNode,o=a instanceof z?a.parentNode:void 0;if(o instanceof F&&o.isKind(r.DiagramView))return wC(e,t,n,i)}return Z()}default:return Z()}}function uC(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`,`DiagramView`,`Note`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}}function dC(e,t,n,r){return r?.callee&&xC(n,r)===1?tC(e,t,n,e.container.element(t,n),[j.Schema,j.Table,j.Column]):Z()}function fC(e,t,n,r){let i=[`Note`,`indexes`,`checks`,`Records`];if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))};let a=xC(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}:a===1?yC(e,t,n):Z()}function pC(e,t,n,r){return!r?.callee||xC(n,r)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}:Z()}function mC(e,t,n){return tC(e,t,n,e.container.element(t,n),[j.Schema,j.Table,j.Column])}function hC(e,t,n,i){return i.isKind(r.Records)?tC(e,t,n,i.parent,[j.Schema,j.Table]):Z()}function gC(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&TS(i,a.callee),c=a.argumentList&&TS(i,a.argumentList);if(o instanceof F&&o.isKind(r.Records)&&ES(i,o)){if(s)return tC(e,n,i,o.parent,[j.Schema,j.Table]);if(!c)return Z();let r=a.callee;if(!r)return Z();let l=xu(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return Z();let f=eC(e,d,[j.Column]),{argumentList:p}=a;return!p||!yu(p)?f:FS(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof R)||o.callee!==a||(k(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return Z();let l=eC(e,s,[j.Column]),{argumentList:u}=a;return!u||!yu(u)?l:FS(l)}return Z()}function _C(e,t){return{suggestions:[...PS({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==j.Table&&e.kind!==j.Schema)return[];let t=e.name;return t===void 0||e instanceof Lu&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:X.KeepWhitespace,kind:jS(e.kind),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))]}}function vC(e,t,n){return bC(e,t,n)}function yC(e,t,n){return{suggestions:[...`integer.int.tinyint.smallint.mediumint.bigint.bit.bool.binary.varbinary.logical.char.nchar.varchar.varchar2.nvarchar.nvarchar2.binary_float.binary_double.float.double.decimal.dec.real.money.smallmoney.enum.tinyblob.tinytext.blob.text.mediumblob.mediumtext.longblob.longtext.ntext.set.inet6.uuid.image.date.time.datetime.datetime2.timestamp.year.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`).map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.TypeParameter,sortText:Y.TypeParameter.toString().padStart(2,`0`),range:void 0})),...tC(e,t,n,e.container.element(t,n),[j.Enum,j.Schema]).suggestions]}}function bC(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(j.Table))return Z();let o=e.symbolMembers(a).getFiltered(t);return o?PS({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:X.KeepWhitespace,kind:jS(j.Column),range:void 0}:[]})}):Z()}function xC(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 SC={label:`*`,insertText:`*`,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0};function CC(){return{suggestions:[...[`Tables`,`TableGroups`,`Notes`,`Schemas`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0})),SC]}}function wC(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[SC,...tC(e,t,n,e.parse.ast(t),[j.Table,j.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[SC,...tC(e,t,n,e.parse.ast(t),[j.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[SC,{label:v,insertText:v,insertTextRules:X.KeepWhitespace,kind:Y.Module,range:void 0},...tC(e,t,n,e.parse.ast(t),[j.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[SC,...tC(e,t,n,e.parse.ast(t),[j.StickyNote]).suggestions]};default:return Z()}}const TC={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*[}\]].*)$/}};var EC={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`none`,`check`,`tables`,`tablegroups`,`notes`,`schemas`,`inactive`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>~-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}};function DC(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:hc(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=Rd(s).find(e=>TS(o,e));if(e===void 0||e instanceof el)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 R){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
|
|
12
|
-
`&&(c.pop(),n=!0)}else r instanceof
|
|
13
|
-
`?(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
|
|
14
|
-
`:this.addToken(
|
|
15
|
-
`))&&!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 b
|
|
16
|
-
`)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new b
|
|
17
|
-
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(
|
|
10
|
+
`&&i++,{startOffset:r,endOffset:i}}function Zv(e){switch(e){case M.Schema:return Y.Module;case M.Table:case M.TablePartial:return Y.Class;case M.Column:case M.TableGroupField:return Y.Field;case M.Enum:return Y.Enum;case M.EnumField:return Y.EnumMember;case M.TableGroup:return Y.Struct;default:return Y.Text}}function Qv(e,t){if(!e||Wa(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===v.NEWLINE&&n.end<=t)return!1}return!0}function Z(){return{suggestions:[]}}function $v(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function ey(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:cg(e.insertText??``),quoted:!0}))}}function ty(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:X.KeepWhitespace,kind:Y.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function ny(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(ry(e,c,t.kind,s,r,o)))}}return i}function ry(e,t,n,r,i,a){let o=Jv(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=iy(a,o.removeRange.startOffset),t=iy(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:X.KeepWhitespace,kind:Zv(n),detail:`from ${r.basename}`,sortText:`zzz_${Zv(n).toString().padStart(2,`0`)}_${t}`,range:void 0,additionalTextEdits:s}}function iy(e,t){let n=1,r=1;for(let i=0;i<t&&i<e.length;i++)e[i]===`
|
|
11
|
+
`?(n++,r=1):r++;return{line:n,column:r}}function ay(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof P)||!o.isKind(r.Records)||!(o.body instanceof R)||!o.body||!Gv(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof qs?oy(e,o):sy(e,o)}function oy(e,n){if(!(n.name instanceof B))return Z();let r=n.name.argumentList?.elementList||[],i=r.map(n=>e.nodeReferee(n).getFiltered(t));if(!i||i.length===0)return Z();let a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof ks||r instanceof Ws))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}});return a.length===0?Z():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function sy(e,n){let r=n.parent;if(!(r instanceof P))return Z();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof Os))return Z();let a;if(n.name instanceof tc){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 ks||r instanceof Ws))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 Z();a=t}return a.length===0?Z():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function cy(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof Js&&n>=o.start&&n<=o.fullEnd)return ly(e,t,n,o,i,r);return null}function ly(e,t,n,r,i,a){if(r.importPath&&Gv(n,r.importPath))return my(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return Z();if(r.fromKeyword&&n>r.fromKeyword.end)return my(e,t,void 0,i,r);if(r.specifiers instanceof Xs){if(!r.specifiers.openBrace){let e=py();return Qv(r.useKeyword,n)?$v(e):e}return uy(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof ac)return Z();let o=py();return Qv(r.useKeyword,n)?$v(o):o}function uy(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!==M.Schema)return fy(e,t,i,n)}return dy()}}return dy()}function dy(){return{suggestions:Object.keys(Ss).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}}function fy(e,n,r,i){if(!r)return Z();let a=bo(n,r.value);if(!a)return Z();let o=e.usableMembers(a).getFiltered(t);if(!o)return Z();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 Us&&!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:X.KeepWhitespace,kind:Zv(i),range:void 0}))}}function py(){return{suggestions:[{label:`* from`,detail:`import all`,insertText:"* from '${1:./path}'",insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0},{label:`{ } from`,detail:`import named`,insertText:"{ ${1:type} ${2:name} } from '${3:./path}'",insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function my(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=Vv(r,n);c={startLineNumber:e.startLineNumber,startColumn:e.startColumn+1,endLineNumber:e.endLineNumber,endColumn:e.endColumn-1}}let l=new Map,u=new Map,d=Pa(e.layout.getEntrypoints().flatMap(t=>[...e.reachableFiles(t)]),e=>e.intern());for(let n of d){if(n.equals(t))continue;let r=n.relativeTo(a);if(r.endsWith(`.dbml`)&&(r=r.slice(0,-Co.length)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=yo.resolve(a,d),p=e.layout.isDirectory(f);if(gy(e,n,hy(i))&&u.set(d,!0),l.has(d))continue;let m=s?`'${d}'`:d;l.set(d,{label:d,insertText:m,insertTextRules:X.KeepWhitespace,kind:p?Y.Folder:Y.File,sortText:`${p?`2`:`3`}${d}`,range:c})}for(let[e,t]of l)u.get(e)&&(t.sortText=`${t.kind===Y.File?`0`:`1`}${e}`,t.detail=`best match`);return{suggestions:[...l.values()]}}function hy(e){let t=e.specifiers;return t instanceof Xs?t.specifiers.flatMap(e=>{let t=A(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function gy(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 _y=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=yo.fromUri(String(e.uri)),r=Bv(e,t),i=ay(this.compiler,e,t,n,r);if(i!==null)return i;let a=this.compiler.token.flatStream(n),{token:o,index:s}=this.compiler.container.token(n,r),c=s===void 0?a[0]:a[s+1];if([...o?.trailingTrivia||[],...o?.leadingTrivia||[],...c?.leadingTrivia||[]].find(e=>qa(e)&&Gv(r,e)))return Z();if(s===void 0)return Ay();let l=cy(this.compiler,n,r,o,e);if(l!==null)return l;if([v.STRING_LITERAL,v.QUOTED_STRING].includes(o.kind)&&Gv(r,o))return Z();let u=this.compiler.container.element(n,r);if(this.compiler.container.scopeKind(n,r)===Q.TOPLEVEL||u instanceof P&&u.type&&u.type.start<=r&&u.type.end>=r)return Ay();let d=[...this.compiler.container.stack(n,r)].reverse();for(let e of d)if(e instanceof I)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return yy(this.compiler,n,r,e);case`~`:return vy(this.compiler,n,r);default:}else if(e instanceof Qs)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return yy(this.compiler,n,r,e);case`.`:return Oy(this.compiler,n,r,e);default:}else if(e instanceof F)return wy(this.compiler,n,r,e);else if(e instanceof z)return wy(this.compiler,n,r,e);else if(e instanceof tc)return Sy(this.compiler,n,r,e);else if(e instanceof nc)return Cy(this.compiler,n,r);else if(e instanceof B)return Iy(this.compiler,n,r,e);else if(e instanceof L)return ky(this.compiler,n,r,e);else if(e instanceof P){if(Kv(r,e))return Fy(this.compiler,n,r,e);if(e.bodyColon&&r>=e.bodyColon.end||e.body&&Gv(r,e.body))return ky(this.compiler,n,r,void 0)}return Z()}};function vy(e,t,n){return xy(e,t,n,e.parse.ast(t),[M.TablePartial])}function yy(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=xy(e,t,n,e.container.element(t,n),[M.Table,M.Schema,M.Column]);return Qv(r.op,n)?$v(i):i}return Z()}function by(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?ey({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof Ts&&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:X.KeepWhitespace,kind:Zv(e.kind),sortText:Zv(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):Z()}function xy(e,n,r,i,a){if(i===void 0)return Z();let o=i,s={suggestions:[]},c;for(;o;){o instanceof qs&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=by(e,n,a).suggestions,r=e=>{switch(e){case Y.Field:return 0;case Y.Module:return 1;case Y.Class:return 2;default:return 3}};t.sort((e,t)=>r(e.kind)-r(t.kind)),s.suggestions.push(...t)}o=o instanceof P?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 ny(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 ey(s)}function Sy(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 B&&t.argumentList===a)return Iy(e,n,i,t);if(s instanceof P&&s.isKind(r.Records)&&!(s.name instanceof B)&&Kv(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=by(e,i,[M.Column]);return ss(a)?ty(t):t}}switch(o){case Q.INDEXES:return By(e,n,i);case Q.REF:for(;c.length>0;){let t=c.pop();if(t instanceof Qs&&t.op?.value===`.`)return Oy(e,n,i,t)}return Py(e,n,i);default:break}return Z()}function Cy(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?xy(e,t,n,e.container.element(t,n),[M.Schema,M.Enum,M.EnumField]):Z()}function wy(e,t,n,r){let{token:i}=e.container.token(t,n);if([v.COMMA,v.LBRACKET].includes(i?.kind)){let r=Ty(e,t,n);return i?.kind===v.COMMA&&Qv(i,n)?$v(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return Ty(e,t,n);if(r.name instanceof Zs){let a=Ey(e,t,n,as(r.name)??``);return i?.kind===v.COLON&&Qv(i,n)?$v(a):a}return Z()}function Ty(e,t,n){let r=e.container.element(t,n);if(r instanceof qs)return Z();let a=e.container.scopeKind(t,n);if(r.body&&!Gv(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=[i.HeaderColor,i.Note];break;case Q.TABLEGROUP:e=[i.Color,i.Note];break;case Q.NOTE:e=[i.Color];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:Y.Field,insertTextRules:X.KeepWhitespace,range:void 0}))}}switch(a){case Q.TABLE:case Q.TABLEPARTIAL:return{suggestions:[...[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique].map(e=>({label:e,insertText:e,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0})),...[i.Ref,i.Default,i.Note,i.Check].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.ENUM:return{suggestions:[...[i.Note].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.INDEXES:return{suggestions:[...[i.Unique,i.PK].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Property,range:void 0})),...[i.Note,i.Name,i.Type].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.REF:return{suggestions:[{label:i.Inactive,insertText:i.Inactive,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0},...[i.Update,i.Delete,i.Color].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.CHECKS:return{suggestions:[i.Name].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))};default:break}return Z()}function Ey(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};case`color`:if(e.container.scopeKind(t,n)===Q.NOTE)return{suggestions:[So].map(e=>({label:e,insertText:e,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};break;case`default`:return xy(e,t,n,e.container.element(t,n),[M.Schema,M.Enum]);default:break}return Z()}function Dy(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 P?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 Oy(e,n,r,i){let a=ls(i)??[];return a.pop(),a.some(e=>!w(e))?Z():ey({suggestions:Dy(e,a.map(e=>A(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:Zv(e.kind),range:void 0}})})}function ky(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return My(e,t,n,i);case Q.PROJECT:return Ny(e,t,n,i);case Q.INDEXES:return Ry(e,t,n);case Q.ENUM:return jy(e,t,n,i);case Q.REF:{let r=Py(e,t,n);return e.container.token(t,n).token?.kind===v.COLON&&Qv(e.container.token(t,n).token,n)?$v(r):r}case Q.TABLEGROUP:return Ly(e,t);case Q.DIAGRAMVIEW:return Uy();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof P){let a=i.parentNode,o=a instanceof R?a.parentNode:void 0;if(o instanceof P&&o.isKind(r.DiagramView))return Wy(e,t,n,i)}return Z()}default:return Z()}}function Ay(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`,`DiagramView`,`Note`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}}function jy(e,t,n,r){return r?.callee&&Vy(n,r)===1?xy(e,t,n,e.container.element(t,n),[M.Schema,M.Table,M.Column]):Z()}function My(e,t,n,r){let i=[`Note`,`indexes`,`checks`,`Records`];if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))};let a=Vy(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}:a===1?zy(e,t,n):Z()}function Ny(e,t,n,r){return!r?.callee||Vy(n,r)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}:Z()}function Py(e,t,n){return xy(e,t,n,e.container.element(t,n),[M.Schema,M.Table,M.Column])}function Fy(e,t,n,i){return i.isKind(r.Records)?xy(e,t,n,i.parent,[M.Schema,M.Table]):Z()}function Iy(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&Gv(i,a.callee),c=a.argumentList&&Gv(i,a.argumentList);if(o instanceof P&&o.isKind(r.Records)&&Kv(i,o)){if(s)return xy(e,n,i,o.parent,[M.Schema,M.Table]);if(!c)return Z();let r=a.callee;if(!r)return Z();let l=ls(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return Z();let f=by(e,d,[M.Column]),{argumentList:p}=a;return!p||!ss(p)?f:ty(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof L)||o.callee!==a||(A(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return Z();let l=by(e,s,[M.Column]),{argumentList:u}=a;return!u||!ss(u)?l:ty(l)}return Z()}function Ly(e,t){return{suggestions:[...ey({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==M.Table&&e.kind!==M.Schema)return[];let t=e.name;return t===void 0||e instanceof Ts&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:X.KeepWhitespace,kind:Zv(e.kind),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))]}}function Ry(e,t,n){return By(e,t,n)}function zy(e,t,n){return{suggestions:[...`integer.int.tinyint.smallint.mediumint.bigint.bit.bool.binary.varbinary.logical.char.nchar.varchar.varchar2.nvarchar.nvarchar2.binary_float.binary_double.float.double.decimal.dec.real.money.smallmoney.enum.tinyblob.tinytext.blob.text.mediumblob.mediumtext.longblob.longtext.ntext.set.inet6.uuid.image.date.time.datetime.datetime2.timestamp.year.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`).map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.TypeParameter,sortText:Y.TypeParameter.toString().padStart(2,`0`),range:void 0})),...xy(e,t,n,e.container.element(t,n),[M.Enum,M.Schema]).suggestions]}}function By(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(M.Table))return Z();let o=e.symbolMembers(a).getFiltered(t);return o?ey({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:X.KeepWhitespace,kind:Zv(M.Column),range:void 0}:[]})}):Z()}function Vy(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 Hy={label:`*`,insertText:`*`,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0};function Uy(){return{suggestions:[...[`Tables`,`TableGroups`,`Notes`,`Schemas`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0})),Hy]}}function Wy(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[Hy,...xy(e,t,n,e.parse.ast(t),[M.Table,M.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[Hy,...xy(e,t,n,e.parse.ast(t),[M.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[Hy,{label:y,insertText:y,insertTextRules:X.KeepWhitespace,kind:Y.Module,range:void 0},...xy(e,t,n,e.parse.ast(t),[M.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[Hy,...xy(e,t,n,e.parse.ast(t),[M.StickyNote]).suggestions]};default:return Z()}}var Gy={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*[}\]].*)$/}},Ky={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`none`,`check`,`tables`,`tablegroups`,`notes`,`schemas`,`inactive`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>~-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}};function qy(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:_a(n,e=>!e.isInvalid,r);if(a===-1)return[this.parse.ast(e)];let o=n[a].start,s=this.parse.ast(e),c=[s];for(;;){let e=Oc(s).find(e=>Gv(o,e));if(e===void 0||e instanceof Va)break;c.push(e),s=e}if(i?.kind===v.COLON)return c;for(;c.length>0;){let n=!1,r=g(c);if(r instanceof L){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
|
|
12
|
+
`&&(c.pop(),n=!0)}else r instanceof I||r instanceof Qs?this.container.token(e,t).token!==r.op&&(c.pop(),n=!0):r instanceof z?r.listCloseBracket&&r.end<=t&&(c.pop(),n=!0):r instanceof tc?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof nc?r.end<=t&&(c.pop(),n=!0):r instanceof R?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof Zs||r.end<t&&(c.pop(),n=!0);if(n){let e=g(c);e instanceof P&&e.end<=t&&c.pop()}if(!n)break}return c}function Jy(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 Yy(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof P)return n[e];return this.parse.ast(e)}function Xy(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.PROJECT=6]=`PROJECT`,e[e.CUSTOM=7]=`CUSTOM`,e[e.TOPLEVEL=8]=`TOPLEVEL`,e[e.TABLEPARTIAL=9]=`TABLEPARTIAL`,e[e.CHECKS=10]=`CHECKS`,e[e.RECORDS=11]=`RECORDS`,e[e.DIAGRAMVIEW=12]=`DIAGRAMVIEW`,e}({});function Zy(e,t){let n=this.container.element(e,t);if(n instanceof qs)return Q.TOPLEVEL;switch(n.type?.value.toLowerCase()){case`table`:return Q.TABLE;case`enum`:return Q.ENUM;case`ref`:return Q.REF;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;default:return Q.CUSTOM}}function Qy(e,t){let r=t.originalSymbol;if(r.filepath.equals(e))return n.create(eb(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=$y(this,e);if(i.length>0)return n.create({schema:i.join(`.`),name:t});let a=eb(this,r);return a?n.create({...a,name:t}):n.create({schema:y,name:t})}return n.create(eb(this,r))}function $y(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof Ts&&e.isKind(M.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function eb(e,n){if(!n.declaration)return n.name?{schema:y,name:n.name}:void 0;let r=e.nodeFullname(n.declaration).getFiltered(t);if(!r||r.length===0)return n.name?{schema:y,name:n.name}:void 0;let i=r[r.length-1];return{schema:r.length>1?r.slice(0,-1).join(`.`):y,name:i}}function tb(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof Js)||!i.importPath)continue;let t=bo(e,i.importPath.value);!t||r.has(t.absolute)||(r.add(t.absolute),n.push(t))}return n}function nb(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 rb(e){return nb(this,e?[e]:this.layout.getEntrypoints())}function ib(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function ab(e){return this.interpretFile(e).getErrors()}function ob(e){return this.interpretFile(e).getWarnings()}function sb(e){return this.parseFile(e).getValue().tokens}function cb(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.interpretSymbol(r,e).getFiltered(t)}function lb(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.symbolMembers(r).getFiltered(t)}function ub(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function db(e){return this.parseFile(e).getValue().tokens.filter(Qa)}function fb(e,t){let n=this.parse.ast(e);for(;;){let e=Oc(n).find(e=>Gv(t,e));if(e===void 0)return n;if(e instanceof Va)return e;n=e}}function pb(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 mb(){let e=pg(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 hb(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 gb(){let e=[],r=[],i=new Set,a=[];for(let e of this.layout.getEntrypoints())for(let t of this.reachableFiles(e)){let e=t.intern();i.has(e)||(i.add(e),a.push(t))}let o=new Map;for(let i of a){let a=this.parseFile(i);e.push(...a.getErrors()),r.push(...a.getWarnings());let s=this.bindFile(i);e.push(...s.getErrors()),r.push(...s.getWarnings());let{ast:c}=a.getValue(),l=this.nodeSymbol(c).getFiltered(t),u=l?this.interpretSymbol(l,i):n.create(t),d=u.getFiltered(t);d&&o.set(i.absolute,d),e.push(...u.getErrors()),r.push(...u.getWarnings())}let s={};for(let[e,t]of o)s[e]=t;return new n({files:s},e,r)}function _b(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var vb=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===`
|
|
13
|
+
`?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,e}peek(e=0){if(!(this.current.offset+e>=this.text.length))return this.text[this.current.offset+e]}check(e){for(let t=0;t<e.length;t+=1)if(e[t]!==this.peek(t))return!1;return!0}match(e){return this.check(e)?(e.split(``).forEach(()=>this.advance()),!0):!1}addToken(e,t=!1){this.tokens.push(this.createToken(e,t))}createToken(e,t=!1){return Va.create(e,this.filepath,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),t)}lex(){return this.scanTokens(),this.tokens.push(Va.create(v.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new n(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(v.SPACE);break;case`\r`:break;case`
|
|
14
|
+
`:this.addToken(v.NEWLINE);break;case` `:this.addToken(v.TAB);break;case`,`:this.addToken(v.COMMA);break;case`(`:this.addToken(v.LPAREN);break;case`)`:this.addToken(v.RPAREN);break;case`[`:this.addToken(v.LBRACKET);break;case`]`:this.addToken(v.RBRACKET);break;case`{`:this.addToken(v.LBRACE);break;case`}`:this.addToken(v.RBRACE);break;case`;`:this.addToken(v.SEMICOLON);break;case`:`:this.addToken(v.COLON);break;case`'`:this.match(`''`)?this.multilineStringLiteral():this.singleLineStringLiteral();break;case`"`:this.quotedVariable();break;case"`":this.functionExpression();break;case`#`:this.colorLiteral();break;case`/`:this.match(`/`)?this.singleLineComment():this.match(`*`)?this.multilineComment():this.operator(e);break;case`*`:this.addToken(v.WILDCARD);break;default:if(za(e)){this.operator(e);break}if(Do(e)){this.identifier();break}if(Oo(e)){this.numericLiteralOrIdentifier();break}this.addToken(v.OP,!0),this.errors.push(new x(b.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(v.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)Ra(i)?(t.push(i),i.kind===v.NEWLINE&&n&&(n.trailingTrivia=t,e=!0,n=void 0,t=[])):(e?i.leadingTrivia=t:n.trailingTrivia=t,r.push(i),t=[],n=i,e=!1);this.tokens=r}gatherInvalid(){let e,t=[],n=[];for(e=0;e<this.tokens.length&&Qa(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];Qa(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(`
|
|
15
|
+
`))&&!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 x(b.UNEXPECTED_EOF,`EOF reached while parsing`,t));return}if(this.check(`
|
|
16
|
+
`)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new x(b.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(Va.create(e,this.filepath,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(v.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(v.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(v.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(v.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(v.SINGLE_LINE_COMMENT,`
|
|
17
|
+
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(v.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();this.addToken(v.IDENTIFIER)}operator(e){switch(e){case`<`:[`>`,`=`].includes(this.peek())&&this.advance();break;case`>`:this.peek()===`=`&&this.advance();break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(v.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(v.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=+!!t,e>1)break;if(this.check(`e`)||this.check(`E`)){let e=this.peek(1),t=e===`+`||e===`-`,n=t?this.peek(2):e;if(n&&Oo(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Oo(this.peek());)this.advance();if(this.isAtEnd()||!Ao(this.peek()))return this.addToken(v.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(v.NUMERIC_LITERAL);if(!t&&!Ao(this.peek()))return this.addToken(v.NUMERIC_LITERAL);if(!t&&!Oo(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||Ao(this.peek()));)this.advance();let e=this.createToken(v.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new x(b.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();let e=this.createToken(v.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();this.addToken(v.COLOR_LITERAL)}escapedString(){let e={column:this.current.column-1,offset:this.current.offset-1,line:this.current.line};if(this.isAtEnd())return`\\`;switch(this.advance()){case`\r`:return this.check(`
|
|
18
18
|
`)&&this.advance(),``;case`
|
|
19
19
|
`:return``;case`t`:return` `;case`n`:return`
|
|
20
|
-
`;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!Hl(this.peek()))return this.errors.push(new b(y.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,el.create(_.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}};let $C=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({});var ew=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===$C.ListExpression&&(this.numberOfNestedLBrackets+=1),e===$C.GroupExpression&&(this.numberOfNestedLParens+=1),e===$C.BlockExpression&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===$C.ListExpression&&--this.numberOfNestedLBrackets,e===$C.GroupExpression&&--this.numberOfNestedLParens,e===$C.BlockExpression&&--this.numberOfNestedLBraces,e}top(){return h(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case _.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[$C.GroupExpression,$C.ListExpression].includes(e));break;case _.RPAREN:if(this.isWithinGroupExpressionContext())return $C.GroupExpression;break;case _.RBRACE:if(this.isWithinBlockExpressionContext())return $C.BlockExpression;break;case _.RBRACKET:if(this.isWithinListExpressionContext())return $C.ListExpression;break;default:break}}},tw=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},nw=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new ew,this.useSpecifierList=this.contextStack.withContextDo($C.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(od,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof ad&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(_.IDENTIFIER)&&ll(this.peek()))break;!tl(this.previous())&&!this.check(_.RBRACE)&&this.logError(this.peek(),y.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(_.RBRACE))for(H(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||this.check(_.STRING_LITERAL)||this.check(_.IDENTIFIER)&&ll(e)||nl(this.previous(),e))break;H(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===_.EOF?this.logError(e,y.UNEXPECTED_EOF,`Unexpected EOF`):H(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(sl(e)||this.check(_.COLON,_.LBRACE,_.LBRACKET))break;H(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COLON,_.LBRACE,_.LBRACKET))break;H(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo($C.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(z,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(_.RBRACE))for(H(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||nl(this.previous(),e))break;H(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo($C.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(pd,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(dd,e);try{this.consume(`Expect an opening parenthesis '('`,_.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(_.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(_.RPAREN);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof M&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,_.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.RPAREN,_.COMMA))break;H(e),this.advance()}},this.listExpression=this.contextStack.withContextDo($C.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(B,e);try{this.consume(`Expect an opening bracket '['`,_.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(_.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(_.RBRACKET);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof M&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,_.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;H(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET,_.COLON))break;H(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;H(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new tw(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===_.EOF}advance(){return this.isAtEnd()?h(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?h(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),y.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(H(this.peek()),this.logError(this.advance(),y.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)H(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(P,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Rd(e).forEach(t=>{t instanceof M&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(cl(this.peek())||ul(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof id&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(id,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===_.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(hd,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof od&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof hd?`'*'`:`specifier list`;return ll(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),y.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(_.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),y.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(ad,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,_.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(_.IDENTIFIER,_.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof M&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),y.UNEXPECTED_TOKEN,`Expect an element name`);if(sl(this.peek())){e.asKeyword=this.advance();try{if(!this.check(_.IDENTIFIER,_.QUOTED_STRING))throw this.logError(this.peek(),y.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(F,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(_.COLON,_.LBRACE,_.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(sl(this.peek()))if(e.as=this.advance(),this.check(_.COLON,_.LBRACE,_.LBRACKET))this.logError(this.peek(),y.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(_.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,_.LBRACE,_.COLON))return t();try{if(this.match(_.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof F?(H(t),this.logError(t,y.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(F,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(F,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,_.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof F?this.errors.push(new b(y.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(F,e)}expression(){let e={args:[]},t=()=>Pd(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(R,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){rl(this.previous())||this.logError(n,y.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||tl(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.RBRACKET,_.RPAREN,_.COMMA,_.COLON].includes(e)}commaExpression(){let e=this.check(_.COMMA)?this.nodeFactory.create(vd,{prevToken:this.previous()}):this.normalExpression();if(!this.check(_.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(vd,{prevToken:this.previous()}));break}if(this.check(_.COMMA)){t.elementList.push(this.nodeFactory.create(vd,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(fd,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(_.COMMA));return this.nodeFactory.create(fd,t)}shouldStopCommaExpression(){if(this.isAtEnd()||tl(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.LBRACE,_.RBRACKET,_.LBRACKET,_.RPAREN,_.LPAREN,_.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===_.LPAREN){let{left:r}=cw(n);if(r<e||nl(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(V,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(V,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===_.LBRACKET){if(rl(this.previous()))break;try{t=this.nodeFactory.create(yd,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(yd,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if($c(n)){let r=n,i=cw(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(ld,{expression:t,op:r})}else{let n=iw(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(cd,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(cd,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if($c(this.peek())){let t={};t.op=this.peek();let n=ow(t.op);if(n.right===null)throw this.logError(t.op,y.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(vd,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(L,t),e.handlerContext)):e}e=this.nodeFactory.create(L,t)}else if(e=this.extractOperand(),e instanceof vd)throw new $(this.peek(),this.nodeFactory.create(vd,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(_.WILDCARD)?this.wildcardExpression():this.check(_.NUMERIC_LITERAL,_.STRING_LITERAL,_.COLOR_LITERAL,_.QUOTED_STRING,_.IDENTIFIER)?this.primaryExpression():this.check(_.FUNCTION_EXPRESSION)?this.functionExpression():this.check(_.LBRACKET)?this.listExpression():this.check(_.LBRACE)?this.blockExpression():this.check(_.LPAREN)?this.tupleExpression():(this.peek().kind===_.EOF?this.logError(this.peek(),y.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),y.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(vd,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,_.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(ud,e),t.handlerContext):t}return this.nodeFactory.create(ud,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(hd,{token:this.previous()})}canBeField(){return this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.COLON}primaryExpression(){if(this.match(_.COLOR_LITERAL,_.STRING_LITERAL,_.NUMERIC_LITERAL))return this.nodeFactory.create(_d,{expression:this.nodeFactory.create(md,{literal:this.previous()})});if(this.match(_.QUOTED_STRING,_.IDENTIFIER))return this.nodeFactory.create(_d,{expression:this.nodeFactory.create(gd,{variable:this.previous()})});throw this.logError(this.peek(),y.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(_.COLON,_.RBRACKET,_.COMMA)){let t=this.peek();this.logError(t,y.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(sd,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(I,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(_.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(I,e)}attributeValue(){let e;try{e=this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==_.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(_.COLON,_.COMMA,_.RBRACKET);)try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(sd,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(sd,{identifiers:e})}logError(e,t,n){this.errors.push(new b(t,n,e))}},rw={"+":{left:9,right:10},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function iw(e){return rw[e.value]||{left:null,right:null}}var aw={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function ow(e){return aw[e.value]||{left:null,right:null}}var sw={"(":{left:14,right:null}};function cw(e){return sw[e.value]||{left:null,right:null}}function lw(e){let t=this.getSource(e);return new QC(t??``,e).lex().chain(n=>new nw(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function uw(){let e=Cy(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function dw(e,n,r){let i;if(e instanceof Iu)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Iu))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembers(i).getFiltered(t);if(o)return o.find(e=>a.length&&!e.isKind(...a)?!1:e instanceof td?Zv.visibleName(this,e)?.at(-1)===r:e.name===r)}function fw(e){let t=e.originalSymbol;return wy(this).map(n=>n.filter(n=>n instanceof ed&&n.originalSymbol===t&&n!==e))}function pw(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(C(e)){let n=$y.call(this,e).getFiltered(t);n&&a(n,e);return}if(e instanceof dd&&w(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=mu(n);if(e){let n=$y.call(this,e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Rd(e))t instanceof M&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Lu&&t.isKind(j.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function mw(e){return this.resolutionIndex().parents.get(e.intern())??[]}function hw(e){return this.resolutionIndex().references.get(e.intern())??[]}function gw(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function _w(e){let t=e.originalSymbol;return wy(this).map(n=>n.filter(n=>n instanceof td&&n.originalSymbol===t&&n!==e))}function vw(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function yw(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=Sy(e);if(t.length===0)return{schema:v,table:``};if(t.length===1)return{schema:v,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function bw(e,n,r,i){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return null;if(r===`public`)return e.lookupMembers(o,j.Table,i)??null;let s=e.lookupMembers(o,j.Schema,r);return s?e.lookupMembers(s,j.Table,i)??null:null}function xw(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function Sw(e,t){if(!e||!(e instanceof F))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function Cw(e,t,n){let r=!_y(t),i=!_y(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function ww(e,t,n,r,i,a){return n===i&&r===a?!1:bw(e,t,i,a)!==null}function Tw(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return xw(n.substring(i,a))===t?{start:i,end:e.end}:null}function Ew(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function Dw(e,t,n,r,i){let a=[],o=new Set,s=Ew(r);for(let r of e){if(xw(i.substring(r.start,r.end))!==n)continue;let e=Tw(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function Ow(e,n,r){let i=yw(n),a=yw(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=bw(this,e,o,s);if(!u||u instanceof ed||ww(this,e,o,s,c,l))return new Map;if(u instanceof td&&u.useSpecifierDeclaration instanceof ad&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return kw(this,e,n,u,c,l)}return Aw(this,u,o,s,c,l)}function kw(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=Cw(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,vw(o,c)]])}function Aw(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof F))return new Map;let c=s.filepath;if(!c)return new Map;let l=Cw(i,a,Sw(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:Ew(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of Dw([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,vw(r,n))}return m}function jw(e){let t=[],n=new QC(e,Ll).lex();if(n.getErrors().length>0)return t;let i=new nw(e,n.getValue(),new rd,Ll).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?D(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function Mw(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function Nw(e,t){e.push(` ${t} { * }`)}function Pw(e){return e==null?`null`:e.length===0?`empty`:`items`}function Fw(e,t){let n=`DiagramView ${vy(e)} {`,r=e=>vy(e.name),i=t?.tables?.map(e=>{let t=vy(e.name);return e.schemaName===`public`?t:`${vy(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:Pw(t.tables),tableGroups:Pw(t.tableGroups),schemas:Pw(t.schemas),stickyNotes:Pw(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&Mw(d,`Tables`,i),c.tableGroups===`items`&&Mw(d,`TableGroups`,a),c.schemas===`items`&&Mw(d,`Schemas`,o)):u&&Nw(d,`Tables`),c.stickyNotes===`items`?Mw(d,`Notes`,s):c.stickyNotes===`empty`&&Nw(d,`Notes`),d.push(`}`),d.join(`
|
|
21
|
-
`)}function
|
|
20
|
+
`;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!Ao(this.peek()))return this.errors.push(new x(b.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Va.create(v.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},yb=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),bb=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return g(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case v.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case v.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case v.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case v.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},xb=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},Sb=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new bb,this.useSpecifierList=this.contextStack.withContextDo(yb.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(Xs,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof Ys&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(v.IDENTIFIER)&&Xa(this.peek()))break;!Ha(this.previous())&&!this.check(v.RBRACE)&&this.logError(this.peek(),b.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(v.RBRACE))for(V(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||this.check(v.STRING_LITERAL)||this.check(v.IDENTIFIER)&&Xa(e)||Ua(this.previous(),e))break;V(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===v.EOF?this.logError(e,b.UNEXPECTED_EOF,`Unexpected EOF`):V(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ja(e)||this.check(v.COLON,v.LBRACE,v.LBRACKET))break;V(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COLON,v.LBRACE,v.LBRACKET))break;V(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(yb.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(v.RBRACE))for(V(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||Ua(this.previous(),e))break;V(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(yb.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(rc,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(tc,e);try{this.consume(`Expect an opening parenthesis '('`,v.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(v.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(v.RPAREN);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof N&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,v.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.RPAREN,v.COMMA))break;V(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(yb.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(z,e);try{this.consume(`Expect an opening bracket '['`,v.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(v.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(v.RBRACKET);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof N&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,v.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;V(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET,v.COLON))break;V(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;V(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new xb(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===v.EOF}advance(){return this.isAtEnd()?g(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?g(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(V(this.peek()),this.logError(this.advance(),b.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)V(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(qs,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Oc(e).forEach(t=>{t instanceof N&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Ya(this.peek())||Za(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Js&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(Js,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===v.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(ac,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Xs&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof ac?`'*'`:`specifier list`;return Xa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(v.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(Ys,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,v.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(v.IDENTIFIER,v.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof N&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an element name`);if(Ja(this.peek())){e.asKeyword=this.advance();try{if(!this.check(v.IDENTIFIER,v.QUOTED_STRING))throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(P,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(v.COLON,v.LBRACE,v.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ja(this.peek()))if(e.as=this.advance(),this.check(v.COLON,v.LBRACE,v.LBRACKET))this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(v.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,v.LBRACE,v.COLON))return t();try{if(this.match(v.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof P?(V(t),this.logError(t,b.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(P,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(P,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,v.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof P?this.errors.push(new x(b.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(P,e)}expression(){let e={args:[]},t=()=>wc(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(L,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Wa(this.previous())||this.logError(n,b.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.RBRACKET,v.RPAREN,v.COMMA,v.COLON].includes(e)}commaExpression(){let e=this.check(v.COMMA)?this.nodeFactory.create(cc,{prevToken:this.previous()}):this.normalExpression();if(!this.check(v.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(cc,{prevToken:this.previous()}));break}if(this.check(v.COMMA)){t.elementList.push(this.nodeFactory.create(cc,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(nc,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(v.COMMA));return this.nodeFactory.create(nc,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.LBRACE,v.RBRACKET,v.LBRACKET,v.RPAREN,v.LPAREN,v.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===v.LPAREN){let{left:r}=Ob(n);if(r<e||Ua(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(B,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(B,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===v.LBRACKET){if(Wa(this.previous()))break;try{t=this.nodeFactory.create(lc,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(lc,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Ba(n)){let r=n,i=Ob(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create($s,{expression:t,op:r})}else{let n=wb(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(Qs,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Qs,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Ba(this.peek())){let t={};t.op=this.peek();let n=Eb(t.op);if(n.right===null)throw this.logError(t.op,b.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(cc,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(I,t),e.handlerContext)):e}e=this.nodeFactory.create(I,t)}else if(e=this.extractOperand(),e instanceof cc)throw new $(this.peek(),this.nodeFactory.create(cc,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(v.WILDCARD)?this.wildcardExpression():this.check(v.NUMERIC_LITERAL,v.STRING_LITERAL,v.COLOR_LITERAL,v.QUOTED_STRING,v.IDENTIFIER)?this.primaryExpression():this.check(v.FUNCTION_EXPRESSION)?this.functionExpression():this.check(v.LBRACKET)?this.listExpression():this.check(v.LBRACE)?this.blockExpression():this.check(v.LPAREN)?this.tupleExpression():(this.peek().kind===v.EOF?this.logError(this.peek(),b.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),b.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(cc,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,v.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(ec,e),t.handlerContext):t}return this.nodeFactory.create(ec,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(ac,{token:this.previous()})}canBeField(){return this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.COLON}primaryExpression(){if(this.match(v.COLOR_LITERAL,v.STRING_LITERAL,v.NUMERIC_LITERAL))return this.nodeFactory.create(sc,{expression:this.nodeFactory.create(ic,{literal:this.previous()})});if(this.match(v.QUOTED_STRING,v.IDENTIFIER))return this.nodeFactory.create(sc,{expression:this.nodeFactory.create(oc,{variable:this.previous()})});throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(v.COLON,v.RBRACKET,v.COMMA)){let t=this.peek();this.logError(t,b.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(Zs,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(F,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(v.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(F,e)}attributeValue(){let e;try{e=this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==v.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(v.COLON,v.COMMA,v.RBRACKET);)try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(Zs,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(Zs,{identifiers:e})}logError(e,t,n){this.errors.push(new x(t,n,e))}},Cb={"+":{left:9,right:10},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function wb(e){return Cb[e.value]||{left:null,right:null}}var Tb={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function Eb(e){return Tb[e.value]||{left:null,right:null}}var Db={"(":{left:14,right:null}};function Ob(e){return Db[e.value]||{left:null,right:null}}function kb(e){let t=this.getSource(e);return new vb(t??``,e).lex().chain(n=>new Sb(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function Ab(){let e=pg(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function jb(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof Us?Vh.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function Mb(e,n,r){let i;if(e instanceof ws)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof ws))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function Nb(e){let t=e.originalSymbol;return mg(this).map(n=>n.filter(n=>n instanceof Hs&&n.originalSymbol===t&&n!==e))}function Pb(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(w(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof tc&&T(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ns(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Oc(e))t instanceof N&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Ts&&t.isKind(M.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function Fb(e){return this.resolutionIndex().parents.get(e.intern())??[]}function Ib(e){return this.resolutionIndex().references.get(e.intern())??[]}function Lb(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function Rb(e){let t=e.originalSymbol;return mg(this).map(n=>n.filter(n=>n instanceof Us&&n.originalSymbol===t&&n!==e))}function zb(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function Bb(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=fg(e);if(t.length===0)return{schema:y,table:``};if(t.length===1)return{schema:y,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function Vb(e,n,r,i){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return null;if(r===`public`)return e.lookupMembers(o,M.Table,i)??null;let s=e.lookupMembers(o,M.Schema,r);return s?e.lookupMembers(s,M.Table,i)??null:null}function Hb(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function Ub(e,t){if(!e||!(e instanceof P))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function Wb(e,t,n){let r=!sg(t),i=!sg(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function Gb(e,t,n,r,i,a){return n===i&&r===a?!1:Vb(e,t,i,a)!==null}function Kb(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return Hb(n.substring(i,a))===t?{start:i,end:e.end}:null}function qb(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function Jb(e,t,n,r,i){let a=[],o=new Set,s=qb(r);for(let r of e){if(Hb(i.substring(r.start,r.end))!==n)continue;let e=Kb(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function Yb(e,n,r){let i=Bb(n),a=Bb(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=Vb(this,e,o,s);if(!u||u instanceof Hs||Gb(this,e,o,s,c,l))return new Map;if(u instanceof Us&&u.useSpecifierDeclaration instanceof Ys&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return Xb(this,e,n,u,c,l)}return Zb(this,u,o,s,c,l)}function Xb(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=Wb(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,zb(o,c)]])}function Zb(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof P))return new Map;let c=s.filepath;if(!c)return new Map;let l=Wb(i,a,Ub(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:qb(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of Jb([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,zb(r,n))}return m}function Qb(e){let t=[],n=new vb(e,To).lex();if(n.getErrors().length>0)return t;let i=new Sb(e,n.getValue(),new Gs,To).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?O(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function $b(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function ex(e,t){e.push(` ${t} { * }`)}function tx(e){return e==null?`null`:e.length===0?`empty`:`items`}function nx(e,t){let n=`DiagramView ${cg(e)} {`,r=e=>cg(e.name),i=t?.tables?.map(e=>{let t=cg(e.name);return e.schemaName===`public`?t:`${cg(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:tx(t.tables),tableGroups:tx(t.tableGroups),schemas:tx(t.schemas),stickyNotes:tx(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&$b(d,`Tables`,i),c.tableGroups===`items`&&$b(d,`TableGroups`,a),c.schemas===`items`&&$b(d,`Schemas`,o)):u&&ex(d,`Tables`),c.stickyNotes===`items`?$b(d,`Notes`,s):c.stickyNotes===`empty`&&ex(d,`Notes`),d.push(`}`),d.join(`
|
|
21
|
+
`)}function rx(e,t,n){let r=this.getSource(e)??``,i=n??Qb(r),a=[];for(let e of t){let t=ix(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:zb(r,a,!0),edits:a}}function ix(e,t,n){switch(t.operation){case`create`:return ax(e,t,n);case`update`:return ox(e,t,n);case`delete`:return sx(e,t,n);default:return[]}}function ax(e,t,n){if(n.find(e=>e.name===t.name))return ox(e,t,n);let r=`
|
|
22
22
|
|
|
23
|
-
`+
|
|
24
|
-
`;return[{start:e.length,end:e.length,newText:r}]}function
|
|
23
|
+
`+nx(t.name,t.visibleEntities)+`
|
|
24
|
+
`;return[{start:e.length,end:e.length,newText:r}]}function ox(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=nx(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function sx(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
|
|
25
25
|
`;){i--,i>0&&e[i-1]===`\r`&&i--;let t=e.lastIndexOf(`
|
|
26
26
|
`,i-1)+1;if(e.substring(t,i).trim()!==``){i=r.startIndex,i>0&&e[i-1]===`
|
|
27
27
|
`&&(i--,i>0&&e[i-1]===`\r`&&i--);break}}return a<e.length&&e[a]===`\r`&&a++,a<e.length&&e[a]===`
|
|
28
|
-
`&&a++,[{start:i,end:a,newText:``}]}var
|
|
28
|
+
`&&a++,[{start:i,end:a,newText:``}]}var cx=Symbol(`COMPUTING`),lx=class{constructor(e){this.layout=e,this.nodeIdGenerator=new Gs,this.symbolIdGenerator=new Cs,this.symbolFactory=new $a(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(kb),this.parseProject=this.globalQuery(Ab),this.validateNode=this.localQuery(A_),this.validateFile=this.localQuery(_b),this.nodeFullname=this.localQuery(M_),this.nodeAlias=this.localQuery(N_),this.nodeSettings=this.localQuery(j_),this.canonicalName=this.globalQuery(Qy),this.bindNode=this.globalQuery(Ug),this.bindFile=this.globalQuery(pb),this.bindProject=this.globalQuery(mb),this.interpretSymbol=this.globalQuery(Gg),this.interpretMetadata=this.globalQuery(Kg),this.interpretFile=this.globalQuery(hb),this.interpretProject=this.globalQuery(gb),this.nodeSymbol=this.globalQuery(Bg),this.nodeMetadata=this.globalQuery(Wg),this.symbolMembers=this.globalQuery(Vg),this.symbolMembersLookupMap=this.globalQuery(jb),this.lookupMembers=this.globalQuery(Mb),this.nodeReferee=this.globalQuery(Hg),this.resolutionIndex=this.globalQuery(Pb),this.symbolReferences=this.globalQuery(Ib),this.symbolParent=this.globalQuery(Fb),this.symbolMetadata=this.globalQuery(Lb),this.symbolAliases=this.globalQuery(Nb),this.symbolUses=this.globalQuery(Rb),this.fileDependencies=this.localQuery(tb),this.reachableFiles=this.globalQuery(rb),this.usableMembers=this.globalQuery(Wh),this.nodeAtPosition=this.localQuery(fb),this.renameTable=Yb.bind(this),this.syncDiagramView=rx.bind(this),this.token={invalidStream:this.localQuery(db),flatStream:this.localQuery(ub)},this.parse={source:e=>this.getSource(e)||``,ast:(e=To)=>ib.call(this,e),errors:(e=To)=>ab.call(this,e),warnings:(e=To)=>ob.call(this,e),tokens:(e=To)=>sb.call(this,e),rawDb:(e=To)=>cb.call(this,e),publicSymbolTable:(e=To)=>lb.call(this,e)},this.container={stack:this.localQuery(qy),token:this.localQuery(Jy),element:this.localQuery(Yy),scope:this.localQuery(Xy),scopeKind:this.localQuery(Zy)}}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 nb(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?Ic(n[0]):n.map(e=>Ic(e)).join(`\0`),a=r.get(i);if(a){if(a===cx)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,cx);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 N?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?Ic(n[0]):n.map(e=>Ic(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===cx)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,cx);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}findDiagramViewBlocks(e){return Qb(this.getSource(e)??``)}initMonacoServices(e){let t=e?.autocompletion?.triggerCharacters??[];return{definitionProvider:new Hv(this),referenceProvider:new Wv(this),autocompletionProvider:new _y(this,{triggerCharacters:t}),diagnosticsProvider:new Uv(this)}}},ux=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(yo.from)}getEntrypoints(){return[...this.files.keys()].map(yo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=lc,exports.AttributeNode=F,exports.BlockExpressionNode=R,exports.CallExpressionNode=B,exports.CommaExpressionNode=nc,exports.CompileError=x,exports.CompileErrorCode=b,exports.Compiler=lx,exports.CompletionItemInsertTextRule=X,exports.CompletionItemKind=Y,exports.DBMLCompletionItemProvider=_y,exports.DBMLDefinitionProvider=Hv,exports.DBMLDiagnosticsProvider=Uv,exports.DBMLReferencesProvider=Wv,exports.DEFAULT_ENTRY=To,exports.ElementDeclarationNode=P,exports.ElementKind=r,exports.EmptyNode=cc,exports.FALSY_VALUES=Rm,exports.Filepath=yo,exports.FunctionApplicationNode=L,exports.FunctionExpressionNode=ec,exports.GroupExpressionNode=rc,exports.IdentifierStreamNode=Zs,exports.InfixExpressionNode=Qs,exports.ListExpressionNode=z,exports.LiteralNode=ic,exports.MarkerSeverity=zv,exports.MemoryProjectLayout=ux,exports.PostfixExpressionNode=$s,exports.PrefixExpressionNode=I,exports.PrimaryExpressionNode=sc,exports.ProgramNode=qs,exports.ScopeKind=Q,exports.SymbolKind=M,exports.SyntaxNode=N,exports.SyntaxNodeIdGenerator=Gs,exports.SyntaxNodeKind=Ks,exports.SyntaxToken=Va,exports.SyntaxTokenKind=v,exports.TRUTHY_VALUES=Lm,exports.TupleExpressionNode=tc,exports.UNHANDLED=t,exports.Uri=Ov,exports.UseDeclarationNode=Js,exports.UseSpecifierListNode=Xs,exports.UseSpecifierNode=Ys,exports.VariableNode=oc,exports.WildcardNode=ac,exports.addDoubleQuoteIfNeeded=cg,exports.dbmlLanguageConfig=Gy,exports.dbmlMonarchTokensProvider=Ky,exports.escapeString=ug,exports.extractNumericLiteral=fs,exports.extractSignedNumber=Pm,exports.formatRecordValue=dg,exports.getRecordValueType=vl,exports.isBinaryType=hl,exports.isBooleanType=pl,exports.isDateTimeType=gl,exports.isEmptyStringLiteral=Mm,exports.isFloatType=dl,exports.isFunctionExpression=Nm,exports.isIntegerType=ul,exports.isNullish=jm,exports.isNumericType=fl,exports.isOp=za,exports.isOpToken=Ba,exports.isSerialType=_l,exports.isStringType=ml,exports.isTriviaToken=Ra,exports.isValidIdentifier=sg,exports.normalizeTypeName=ll,exports.splitQualifiedIdentifier=fg,exports.tryExtractBoolean=zm,exports.tryExtractDateTime=Gm,exports.tryExtractEnum=Bm,exports.tryExtractInteger=Im,exports.tryExtractNumeric=Fm,exports.tryExtractString=Vm,exports.unescapeString=lg,exports.validateForeignKeys=mh,exports.validatePrimaryKey=rh,exports.validateUnique=uh;
|