@dbml/parse 8.0.0-alpha.11 → 8.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dbml-parse.js +3 -3
- package/dist/dbml-parse.mjs +8 -8
- package/package.json +2 -2
package/dist/dbml-parse.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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}({});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,h=d?d.toStringTag:void 0;function ee(e){var t=p.call(e,h),n=e[h];try{e[h]=void 0;var r=!0}catch{}var i=m.call(e);return r&&(t?e[h]=n:delete e[h]),i}var te=ee,ne=Object.prototype.toString;function re(e){return ne.call(e)}var ie=re,ae=`[object Null]`,oe=`[object Undefined]`,se=d?d.toStringTag:void 0;function ce(e){return e==null?e===void 0?oe:ae:se&&se in Object(e)?te(e):ie(e)}var le=ce;function ue(e){return typeof e==`object`&&!!e}var de=ue,fe=`[object Symbol]`;function pe(e){return typeof e==`symbol`||de(e)&&le(e)==fe}var me=pe;function he(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var ge=he,_e=Array.isArray,ve=_e,ye=1/0,be=d?d.prototype:void 0,xe=be?be.toString:void 0;function Se(e){if(typeof e==`string`)return e;if(ve(e))return ge(e,Se)+``;if(me(e))return xe?xe.call(e):``;var t=e+``;return t==`0`&&1/e==-ye?`-0`:t}var Ce=Se,we=/\s/;function Te(e){for(var t=e.length;t--&&we.test(e.charAt(t)););return t}var Ee=Te,De=/^\s+/;function Oe(e){return e&&e.slice(0,Ee(e)+1).replace(De,``)}var ke=Oe;function Ae(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var je=Ae,Me=NaN,Ne=/^[-+]0x[0-9a-f]+$/i,Pe=/^0b[01]+$/i,Fe=/^0o[0-7]+$/i,Ie=parseInt;function Le(e){if(typeof e==`number`)return e;if(me(e))return Me;if(je(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=je(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=ke(e);var n=Pe.test(e);return n||Fe.test(e)?Ie(e.slice(2),n?2:8):Ne.test(e)?Me:+e}var Re=Le,ze=1/0,Be=17976931348623157e292;function Ve(e){return e?(e=Re(e),e===ze||e===-ze?(e<0?-1:1)*Be:e===e?e:0):e===0?e:0}var He=Ve;function Ue(e){var t=He(e),n=t%1;return t===t?n?t-n:t:0}var We=Ue;function Ge(e){return e}var Ke=Ge,qe=`[object AsyncFunction]`,Je=`[object Function]`,Ye=`[object GeneratorFunction]`,Xe=`[object Proxy]`;function Ze(e){if(!je(e))return!1;var t=le(e);return t==Je||t==Ye||t==qe||t==Xe}var Qe=Ze,$e=l[`__core-js_shared__`],et=$e,tt=function(){var e=/[^.]+$/.exec(et&&et.keys&&et.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function nt(e){return!!tt&&tt in e}var rt=nt,it=Function.prototype.toString;function at(e){if(e!=null){try{return it.call(e)}catch{}try{return e+``}catch{}}return``}var ot=at,st=/[\\^$.*+?()[\]{}|]/g,ct=/^\[object .+?Constructor\]$/,lt=Function.prototype,ut=Object.prototype,dt=lt.toString,ft=ut.hasOwnProperty,pt=RegExp(`^`+dt.call(ft).replace(st,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function mt(e){return!je(e)||rt(e)?!1:(Qe(e)?pt:ct).test(ot(e))}var ht=mt;function gt(e,t){return e?.[t]}var _t=gt;function vt(e,t){var n=_t(e,t);return ht(n)?n:void 0}var yt=vt,bt=yt(l,`WeakMap`),xt=bt;function St(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var Ct=St;function wt(){}var Tt=wt,Et=800,Dt=16,Ot=Date.now;function kt(e){var t=0,n=0;return function(){var r=Ot(),i=Dt-(r-n);if(n=r,i>0){if(++t>=Et)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var At=kt;function jt(e){return function(){return e}}var Mt=jt,Nt=function(){try{var e=yt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Pt=Nt,Ft=Pt?function(e,t){return Pt(e,`toString`,{configurable:!0,enumerable:!1,value:Mt(t),writable:!0})}:Ke,It=Ft,Lt=At(It),Rt=Lt;function zt(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 Bt=zt;function Vt(e){return e!==e}var Ht=Vt;function Ut(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}var Wt=Ut;function Gt(e,t,n){return t===t?Wt(e,t,n):Bt(e,Ht,n)}var Kt=Gt;function qt(e,t){return!!(e!=null&&e.length)&&Kt(e,t,0)>-1}var Jt=qt,Yt=9007199254740991,Xt=/^(?:0|[1-9]\d*)$/;function Zt(e,t){var n=typeof e;return t??=Yt,!!t&&(n==`number`||n!=`symbol`&&Xt.test(e))&&e>-1&&e%1==0&&e<t}var Qt=Zt;function $t(e,t,n){t==`__proto__`&&Pt?Pt(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var en=$t;function tn(e,t){return e===t||e!==e&&t!==t}var nn=tn,rn=Math.max;function an(e,t,n){return t=rn(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=rn(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Ct(e,this,s)}}var on=an;function sn(e,t){return Rt(on(e,t,Ke),e+``)}var cn=sn,ln=9007199254740991;function un(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=ln}var dn=un;function fn(e){return e!=null&&dn(e.length)&&!Qe(e)}var pn=fn,mn=Object.prototype;function hn(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||mn)}var gn=hn;function _n(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var vn=_n,yn=`[object Arguments]`;function bn(e){return de(e)&&le(e)==yn}var xn=bn,Sn=Object.prototype,Cn=Sn.hasOwnProperty,wn=Sn.propertyIsEnumerable,Tn=xn(function(){return arguments}())?xn:function(e){return de(e)&&Cn.call(e,`callee`)&&!wn.call(e,`callee`)},En=Tn;function Dn(){return!1}var On=Dn,kn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,An=kn&&typeof module==`object`&&module&&!module.nodeType&&module,jn=An&&An.exports===kn?l.Buffer:void 0,Mn=(jn?jn.isBuffer:void 0)||On,Nn=Mn,Pn=`[object Arguments]`,Fn=`[object Array]`,In=`[object Boolean]`,Ln=`[object Date]`,Rn=`[object Error]`,zn=`[object Function]`,Bn=`[object Map]`,Vn=`[object Number]`,Hn=`[object Object]`,Un=`[object RegExp]`,Wn=`[object Set]`,Gn=`[object String]`,Kn=`[object WeakMap]`,qn=`[object ArrayBuffer]`,Jn=`[object DataView]`,Yn=`[object Float32Array]`,Xn=`[object Float64Array]`,Zn=`[object Int8Array]`,Qn=`[object Int16Array]`,$n=`[object Int32Array]`,er=`[object Uint8Array]`,tr=`[object Uint8ClampedArray]`,nr=`[object Uint16Array]`,rr=`[object Uint32Array]`,g={};g[Yn]=g[Xn]=g[Zn]=g[Qn]=g[$n]=g[er]=g[tr]=g[nr]=g[rr]=!0,g[Pn]=g[Fn]=g[qn]=g[In]=g[Jn]=g[Ln]=g[Rn]=g[zn]=g[Bn]=g[Vn]=g[Hn]=g[Un]=g[Wn]=g[Gn]=g[Kn]=!1;function ir(e){return de(e)&&dn(e.length)&&!!g[le(e)]}var ar=ir;function or(e){return function(t){return e(t)}}var sr=or,cr=typeof exports==`object`&&exports&&!exports.nodeType&&exports,lr=cr&&typeof module==`object`&&module&&!module.nodeType&&module,ur=lr&&lr.exports===cr&&o.process,dr=function(){try{return lr&&lr.require&&lr.require(`util`).types||ur&&ur.binding&&ur.binding(`util`)}catch{}}(),fr=dr,pr=fr&&fr.isTypedArray,mr=pr?sr(pr):ar,hr=mr,gr=Object.prototype.hasOwnProperty;function _r(e,t){var n=ve(e),r=!n&&En(e),i=!n&&!r&&Nn(e),a=!n&&!r&&!i&&hr(e),o=n||r||i||a,s=o?vn(e.length,String):[],c=s.length;for(var l in e)(t||gr.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||Qt(l,c)))&&s.push(l);return s}var vr=_r;function yr(e,t){return function(n){return e(t(n))}}var br=yr,xr=br(Object.keys,Object),Sr=xr,Cr=Object.prototype.hasOwnProperty;function wr(e){if(!gn(e))return Sr(e);var t=[];for(var n in Object(e))Cr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var Tr=wr;function Er(e){return pn(e)?vr(e):Tr(e)}var Dr=Er;function Or(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var kr=Or,Ar=Object.prototype.hasOwnProperty;function jr(e){if(!je(e))return kr(e);var t=gn(e),n=[];for(var r in e)r==`constructor`&&(t||!Ar.call(e,r))||n.push(r);return n}var Mr=jr;function Nr(e){return pn(e)?vr(e,!0):Mr(e)}var Pr=Nr,Fr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ir=/^\w*$/;function Lr(e,t){if(ve(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||me(e)?!0:Ir.test(e)||!Fr.test(e)||t!=null&&e in Object(t)}var Rr=Lr,zr=yt(Object,`create`),Br=zr;function Vr(){this.__data__=Br?Br(null):{},this.size=0}var Hr=Vr;function Ur(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Wr=Ur,Gr=`__lodash_hash_undefined__`,Kr=Object.prototype.hasOwnProperty;function qr(e){var t=this.__data__;if(Br){var n=t[e];return n===Gr?void 0:n}return Kr.call(t,e)?t[e]:void 0}var Jr=qr,Yr=Object.prototype.hasOwnProperty;function Xr(e){var t=this.__data__;return Br?t[e]!==void 0:Yr.call(t,e)}var Zr=Xr,Qr=`__lodash_hash_undefined__`;function $r(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Br&&t===void 0?Qr:t,this}var ei=$r;function ti(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])}}ti.prototype.clear=Hr,ti.prototype.delete=Wr,ti.prototype.get=Jr,ti.prototype.has=Zr,ti.prototype.set=ei;var ni=ti;function ri(){this.__data__=[],this.size=0}var ii=ri;function ai(e,t){for(var n=e.length;n--;)if(nn(e[n][0],t))return n;return-1}var oi=ai,si=Array.prototype.splice;function ci(e){var t=this.__data__,n=oi(t,e);return n<0?!1:(n==t.length-1?t.pop():si.call(t,n,1),--this.size,!0)}var li=ci;function ui(e){var t=this.__data__,n=oi(t,e);return n<0?void 0:t[n][1]}var di=ui;function fi(e){return oi(this.__data__,e)>-1}var pi=fi;function mi(e,t){var n=this.__data__,r=oi(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var hi=mi;function gi(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])}}gi.prototype.clear=ii,gi.prototype.delete=li,gi.prototype.get=di,gi.prototype.has=pi,gi.prototype.set=hi;var _i=gi,vi=yt(l,`Map`),yi=vi;function bi(){this.size=0,this.__data__={hash:new ni,map:new(yi||_i),string:new ni}}var xi=bi;function Si(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var Ci=Si;function wi(e,t){var n=e.__data__;return Ci(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var Ti=wi;function Ei(e){var t=Ti(this,e).delete(e);return this.size-=t?1:0,t}var Di=Ei;function Oi(e){return Ti(this,e).get(e)}var ki=Oi;function Ai(e){return Ti(this,e).has(e)}var ji=Ai;function Mi(e,t){var n=Ti(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var Ni=Mi;function Pi(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])}}Pi.prototype.clear=xi,Pi.prototype.delete=Di,Pi.prototype.get=ki,Pi.prototype.has=ji,Pi.prototype.set=Ni;var Fi=Pi,Ii=`Expected a function`;function Li(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(Ii);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(Li.Cache||Fi),n}Li.Cache=Fi;var Ri=Li,zi=500;function Bi(e){var t=Ri(e,function(e){return n.size===zi&&n.clear(),e}),n=t.cache;return t}var Vi=Bi,Hi=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ui=/\\(\\)?/g,Wi=Vi(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(Hi,function(e,n,r,i){t.push(r?i.replace(Ui,`$1`):n||e)}),t}),Gi=Wi;function Ki(e){return e==null?``:Ce(e)}var qi=Ki;function Ji(e,t){return ve(e)?e:Rr(e,t)?[e]:Gi(qi(e))}var Yi=Ji,Xi=1/0;function Zi(e){if(typeof e==`string`||me(e))return e;var t=e+``;return t==`0`&&1/e==-Xi?`-0`:t}var Qi=Zi;function $i(e,t){t=Yi(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[Qi(t[n++])];return n&&n==r?e:void 0}var ea=$i;function ta(e,t,n){var r=e==null?void 0:ea(e,t);return r===void 0?n:r}var na=ta;function ra(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var ia=ra,aa=d?d.isConcatSpreadable:void 0;function oa(e){return ve(e)||En(e)||!!(aa&&e&&e[aa])}var sa=oa;function ca(e,t,n,r,i){var a=-1,o=e.length;for(n||=sa,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?ca(s,t-1,n,r,i):ia(i,s):r||(i[i.length]=s)}return i}var la=ca;function ua(e){return e!=null&&e.length?la(e,1):[]}var da=ua;function fa(){this.__data__=new _i,this.size=0}var pa=fa;function ma(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var ha=ma;function ga(e){return this.__data__.get(e)}var _a=ga;function va(e){return this.__data__.has(e)}var ya=va,ba=200;function xa(e,t){var n=this.__data__;if(n instanceof _i){var r=n.__data__;if(!yi||r.length<ba-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Fi(r)}return n.set(e,t),this.size=n.size,this}var Sa=xa;function Ca(e){this.size=(this.__data__=new _i(e)).size}Ca.prototype.clear=pa,Ca.prototype.delete=ha,Ca.prototype.get=_a,Ca.prototype.has=ya,Ca.prototype.set=Sa;var wa=Ca;function Ta(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}var Ea=Ta;function Da(){return[]}var Oa=Da,ka=Object.prototype.propertyIsEnumerable,Aa=Object.getOwnPropertySymbols,ja=Aa?function(e){return e==null?[]:(e=Object(e),Ea(Aa(e),function(t){return ka.call(e,t)}))}:Oa,Ma=ja;function Na(e,t,n){var r=t(e);return ve(e)?r:ia(r,n(e))}var Pa=Na;function Fa(e){return Pa(e,Dr,Ma)}var Ia=Fa,La=yt(l,`DataView`),Ra=La,za=yt(l,`Promise`),Ba=za,Va=yt(l,`Set`),Ha=Va,Ua=`[object Map]`,Wa=`[object Object]`,Ga=`[object Promise]`,Ka=`[object Set]`,qa=`[object WeakMap]`,Ja=`[object DataView]`,Ya=ot(Ra),Xa=ot(yi),Za=ot(Ba),Qa=ot(Ha),$a=ot(xt),eo=le;(Ra&&eo(new Ra(new ArrayBuffer(1)))!=Ja||yi&&eo(new yi)!=Ua||Ba&&eo(Ba.resolve())!=Ga||Ha&&eo(new Ha)!=Ka||xt&&eo(new xt)!=qa)&&(eo=function(e){var t=le(e),n=t==Wa?e.constructor:void 0,r=n?ot(n):``;if(r)switch(r){case Ya:return Ja;case Xa:return Ua;case Za:return Ga;case Qa:return Ka;case $a:return qa}return t});var to=eo,no=l.Uint8Array,ro=no;function io(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 ao=io,oo=`__lodash_hash_undefined__`;function so(e){return this.__data__.set(e,oo),this}var co=so;function lo(e){return this.__data__.has(e)}var uo=lo;function fo(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Fi;++t<n;)this.add(e[t])}fo.prototype.add=fo.prototype.push=co,fo.prototype.has=uo;var po=fo;function mo(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 ho=mo;function go(e,t){return e.has(t)}var _o=go,vo=1,yo=2;function bo(e,t,n,r,i,a){var o=n&vo,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&yo?new po:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var ee=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(ee!==void 0){if(ee)continue;f=!1;break}if(p){if(!ho(t,function(e,t){if(!_o(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===h||i(m,h,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var xo=bo;function So(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var Co=So;function wo(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var To=wo,Eo=1,Do=2,Oo=`[object Boolean]`,ko=`[object Date]`,Ao=`[object Error]`,jo=`[object Map]`,Mo=`[object Number]`,No=`[object RegExp]`,Po=`[object Set]`,Fo=`[object String]`,Io=`[object Symbol]`,Lo=`[object ArrayBuffer]`,Ro=`[object DataView]`,zo=d?d.prototype:void 0,Bo=zo?zo.valueOf:void 0;function Vo(e,t,n,r,i,a,o){switch(n){case Ro:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Lo:return!(e.byteLength!=t.byteLength||!a(new ro(e),new ro(t)));case Oo:case ko:case Mo:return nn(+e,+t);case Ao:return e.name==t.name&&e.message==t.message;case No:case Fo:return e==t+``;case jo:var s=Co;case Po:var c=r&Eo;if(s||=To,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Do,o.set(e,t);var u=xo(s(e),s(t),r,i,a,o);return o.delete(e),u;case Io:if(Bo)return Bo.call(e)==Bo.call(t)}return!1}var Ho=Vo,Uo=1,Wo=Object.prototype.hasOwnProperty;function Go(e,t,n,r,i,a){var o=n&Uo,s=Ia(e),c=s.length;if(c!=Ia(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Wo.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var h=e[u],ee=t[u];if(r)var te=o?r(ee,h,u,t,e,a):r(h,ee,u,e,t,a);if(!(te===void 0?h===ee||i(h,ee,n,r,a):te)){p=!1;break}m||=u==`constructor`}if(p&&!m){var ne=e.constructor,re=t.constructor;ne!=re&&`constructor`in e&&`constructor`in t&&!(typeof ne==`function`&&ne instanceof ne&&typeof re==`function`&&re instanceof re)&&(p=!1)}return a.delete(e),a.delete(t),p}var Ko=Go,qo=1,Jo=`[object Arguments]`,Yo=`[object Array]`,Xo=`[object Object]`,Zo=Object.prototype.hasOwnProperty;function Qo(e,t,n,r,i,a){var o=ve(e),s=ve(t),c=o?Yo:to(e),l=s?Yo:to(t);c=c==Jo?Xo:c,l=l==Jo?Xo:l;var u=c==Xo,d=l==Xo,f=c==l;if(f&&Nn(e)){if(!Nn(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new wa,o||hr(e)?xo(e,t,n,r,i,a):Ho(e,t,c,n,r,i,a);if(!(n&qo)){var p=u&&Zo.call(e,`__wrapped__`),m=d&&Zo.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,ee=m?t.value():t;return a||=new wa,i(h,ee,n,r,a)}}return f?(a||=new wa,Ko(e,t,n,r,i,a)):!1}var $o=Qo;function es(e,t,n,r,i){return e===t?!0:e==null||t==null||!de(e)&&!de(t)?e!==e&&t!==t:$o(e,t,n,r,es,i)}var ts=es,ns=1,rs=2;function is(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 wa;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?ts(u,l,ns|rs,r,d):f))return!1}}return!0}var as=is;function os(e){return e===e&&!je(e)}var ss=os;function cs(e){for(var t=Dr(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,ss(i)]}return t}var ls=cs;function us(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var ds=us;function fs(e){var t=ls(e);return t.length==1&&t[0][2]?ds(t[0][0],t[0][1]):function(n){return n===e||as(n,e,t)}}var ps=fs;function ms(e,t){return e!=null&&t in Object(e)}var hs=ms;function gs(e,t,n){t=Yi(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=Qi(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&&dn(i)&&Qt(o,i)&&(ve(e)||En(e)))}var _s=gs;function vs(e,t){return e!=null&&_s(e,t,hs)}var ys=vs,bs=1,xs=2;function Ss(e,t){return Rr(e)&&ss(t)?ds(Qi(e),t):function(n){var r=na(n,e);return r===void 0&&r===t?ys(n,e):ts(t,r,bs|xs)}}var Cs=Ss;function ws(e){return function(t){return t?.[e]}}var Ts=ws;function Es(e){return function(t){return ea(t,e)}}var Ds=Es;function Os(e){return Rr(e)?Ts(Qi(e)):Ds(e)}var ks=Os;function As(e){return typeof e==`function`?e:e==null?Ke:typeof e==`object`?ve(e)?Cs(e[0],e[1]):ps(e):ks(e)}var js=As;function Ms(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 Ns=Ms;function Ps(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 Fs=Ps,Is=Fs(),Ls=Is;function Rs(e,t){return e&&Ls(e,t,Dr)}var zs=Rs;function Bs(e,t){return function(n,r){if(n==null)return n;if(!pn(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var Vs=Bs,Hs=Vs(zs),Us=Hs;function Ws(e,t,n,r){return Us(e,function(e,i,a){t(r,e,n(e),a)}),r}var Gs=Ws;function Ks(e,t){return function(n,r){var i=ve(n)?Ns:Gs,a=t?t():{};return i(n,e,js(r,2),a)}}var qs=Ks;function Js(e){return de(e)&&pn(e)}var Ys=Js;function Xs(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 Zs=Xs,Qs=200;function $s(e,t,n,r){var i=-1,a=Jt,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ge(t,sr(n))),r?(a=Zs,o=!1):t.length>=Qs&&(a=_o,o=!1,t=new po(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var ec=$s,tc=cn(function(e,t){return Ys(e)?ec(e,la(t,1,Ys,!0)):[]}),nc=tc;function rc(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var _=rc;function ic(e){return typeof e==`function`?e:Ke}var ac=ic;function oc(e,t){var n=[];return Us(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}var sc=oc;function cc(e,t){return(ve(e)?Ea:sc)(e,js(t,3))}var lc=cc,uc=Math.max,dc=Math.min;function fc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=We(n),i=n<0?uc(r+i,0):dc(i,r-1)),Bt(e,js(t,3),i,!0)}var pc=fc;function mc(e){return e&&e.length?e[0]:void 0}var hc=mc;function gc(e,t){var n=-1,r=pn(e)?Array(e.length):[];return Us(e,function(e,i,a){r[++n]=t(e,i,a)}),r}var _c=gc;function vc(e,t){return(ve(e)?ge:_c)(e,js(t,3))}var yc=vc;function bc(e,t){return la(yc(e,t),1)}var xc=bc;function Sc(e,t){return e==null?e:Ls(e,ac(t),Pr)}var Cc=Sc,wc=Object.prototype.hasOwnProperty,Tc=qs(function(e,t,n){wc.call(e,n)?e[n].push(t):en(e,n,[t])}),Ec=Tc,Dc=`[object Map]`,Oc=`[object Set]`,kc=Object.prototype.hasOwnProperty;function Ac(e){if(e==null)return!0;if(pn(e)&&(ve(e)||typeof e==`string`||typeof e.splice==`function`||Nn(e)||hr(e)||En(e)))return!e.length;var t=to(e);if(t==Dc||t==Oc)return!e.size;if(gn(e))return!Tr(e).length;for(var n in e)if(kc.call(e,n))return!1;return!0}var jc=Ac,Mc=qs(function(e,t,n){en(e,n,t)}),Nc=Mc,Pc=qs(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),v=Pc,Fc=Ha&&1/To(new Ha([,-0]))[1]==1/0?function(e){return new Ha(e)}:Tt,Ic=Fc,Lc=200;function Rc(e,t,n){var r=-1,i=Jt,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=Zs;else if(a>=Lc){var l=t?null:Ic(e);if(l)return To(l);o=!1,i=_o,c=new po}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}var zc=Rc;function Bc(e){return e&&e.length?zc(e):[]}var Vc=Bc;function Hc(e,t){return e&&e.length?zc(e,js(t,2)):[]}var Uc=Hc,Wc=Math.max;function Gc(e){if(!(e&&e.length))return[];var t=0;return e=Ea(e,function(e){if(Ys(e))return t=Wc(e.length,t),!0}),vn(t,function(t){return ge(e,Ts(t))})}var Kc=Gc,qc=cn(Kc),Jc=qc;let y=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 Yc(e){switch(e.kind){case y.NEWLINE:case y.SPACE:case y.TAB:case y.SINGLE_LINE_COMMENT:case y.MULTILINE_COMMENT:return!0;default:return!1}}function Xc(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 Zc(e){return e!==void 0&&e.kind===y.OP}var Qc=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 $c(e){return e.trailingTrivia.find(({kind:e})=>e===y.NEWLINE)!==void 0}function el(e,t){return t.leadingTrivia.find(({kind:e})=>e===y.NEWLINE)!==void 0||$c(e)}function tl(e){return e.trailingTrivia.find(({kind:e})=>[y.SPACE,y.TAB].includes(e))!==void 0}function nl(e){return e.trailingTrivia.length===0?e.end:nl(_(e.trailingTrivia))}function rl(e){return e.leadingTrivia.length===0?e.start:rl(e.leadingTrivia[0])}function il(e){return[y.SINGLE_LINE_COMMENT,y.MULTILINE_COMMENT].includes(e.kind)}function al(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`as`}function ol(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`use`}function sl(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`from`}function cl(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function ll(e){return!!e?.isInvalid}var ul=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},dl=/^[A-Za-z]:\//;function fl(e=``){return e&&e.replace(/\\/g,`/`).replace(dl,e=>e.toUpperCase())}var pl=/^[/\\]{2}/,ml=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,hl=/^[A-Za-z]:$/,gl=/^\/([A-Za-z]:)?$/,_l=/.(\.[^./]+|\.)$/,vl=function(e){if(e.length===0)return`.`;e=fl(e);let t=e.match(pl),n=Cl(e),r=e[e.length-1]===`/`;return e=Sl(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),hl.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!Cl(e)?`/${e}`:e)},yl=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 vl(t)};function bl(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var xl=function(...e){e=e.map(e=>fl(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:bl();!i||i.length===0||(t=`${i}/${t}`,n=Cl(i))}return t=Sl(t,!n),n&&!Cl(t)?`/${t}`:t.length>0?t:`.`};function Sl(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 Cl=function(e){return ml.test(e)},wl=function(e){if(e===`..`)return``;let t=_l.exec(fl(e));return t&&t[1]||``},Tl=function(e,t){let n=xl(e).replace(gl,`$1`).split(`/`),r=xl(t).replace(gl,`$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(`/`)},El=function(e){let t=fl(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&hl.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(Cl(e)?`/`:`.`)},Dl=function(e,t){let n=fl(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},Ol=/^[a-zA-Z]:\//,kl=class e{constructor(e,t={}){let n=vl(e);if(!Cl(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(xl(t,n))}static fromUri(t){try{let n=new URL(t);return new e(vl(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(vl(t))}}get absolute(){return this.path}get dirname(){return El(this.path)}get basename(){return Dl(this.path)}get extname(){return wl(this.path)}resolve(t){return new e(xl(this.dirname,t))}join(...t){return new e(yl(this.path,...t))}relativeTo(e){let t=Tl(e,this.path);return t.startsWith(`.`)?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===void 0)return this.path;let n=Ol.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!Cl(vl(e))}};function Al(e,t){if(!kl.isRelative(t))return;let n=kl.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:kl.from(n.absolute+`.dbml`)}const jl=[`null`,`true`,`false`],Ml=`.dbml`,Nl=[`-`,`+`],b=`public`,Pl=kl.from(`/main.dbml`);let x=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.INVALID_INDEXES_CONTEXT=3047]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3048]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3049]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3050]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3051]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3052]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3053]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3054]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3055]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3056]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3057]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3058]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3059]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3060]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3061]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3062]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3063]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3064]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3065]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3066]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3067]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3069]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3070]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3071]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3072]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3073]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3074]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3075]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3076]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3077]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3078]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3079]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3080]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3081]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.INVALID_USE_CONTEXT=3082]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3083]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3084]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3085]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3086]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3087]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3088]=`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 S=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 Fl(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},Fl=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,S.prototype)}get filepath(){return this.nodeOrToken.filepath}};function Il(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Ll(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Rl(e){let[t]=e;return Ll(t)||Il(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function zl(e){return Il(e)||Ll(e)}function Bl(e){let t=k(e);return t!==void 0&&t.length>0}function Vl(e){return Hl(e)}function Hl(e){return e instanceof md&&e.expression instanceof pd}function Ul(e){return!!e.bodyColon}function Wl(e){return e instanceof R&&e.op?.value===`~`&&T(e.expression)}function Gl(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function Kl(e){if(!(e instanceof md)||!(e.expression instanceof dd)||e.expression.literal?.kind!==y.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(!Rl(t[e]))return!1;return!0}function ql(e){if(w(e)||Jl(e)||$l(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof R&&Nl.includes(e.op?.value)&&Jl(e.expression)||e instanceof sd)return!0;if(!e||!eu(e))return!1;let t=_u(e);return t.length===2||t.length===3}function Jl(e){return e instanceof R?Nl.includes(e.op.value)?Jl(e.expression):!1:e instanceof md&&e.expression instanceof dd&&e.expression.literal?.kind===y.NUMERIC_LITERAL}function Yl(e){if(!(e instanceof R)||!Gl(e.op?.value))return!1;let t=k(e.expression);return t!==void 0&&t.length>0}function Xl(e){return e instanceof cd&&e.elementList.every(T)}function Zl(e){if(!(e instanceof H||E(e)||e instanceof md||e instanceof gd))return!1;for(;e instanceof H||e instanceof gd;)if(e instanceof H){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Jl(e)||w(e)||$l(e)))return!1;e=e.callee}else if(e instanceof gd){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Jl(e.name)))return!1;e=e.array}let t=k(e);return t!==void 0&&t.length>0}function C(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof md){r.push(new S(x.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=pu(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 w(e){return e instanceof md&&(e.expression instanceof pd&&e.expression.variable instanceof Qc&&e.expression.variable.kind===y.QUOTED_STRING||e.expression instanceof dd&&e.expression.literal?.kind===y.STRING_LITERAL)}function T(e){return e instanceof md&&e.expression instanceof pd&&e.expression.variable instanceof Qc}function Ql(e){return e?e instanceof fd:!1}function $l(e){return e instanceof md&&e.expression instanceof pd&&e.expression.variable?.kind===y.IDENTIFIER}function E(e){return e instanceof ad&&e.leftExpression instanceof P&&e.rightExpression instanceof P&&e.op?.value===`.`}function eu(e){return T(e)?!0:E(e)&&T(e.rightExpression)&&eu(e.leftExpression)}function D(e,t){return e instanceof I&&e.isKind(t)}function tu(e){return e instanceof td}function nu(e,t){return e instanceof nd&&(t===void 0||e.isKind(t))}function ru(e){return e instanceof ed}function O(e,...t){return e instanceof z&&e.parent instanceof I&&e.parent.isKind(...t)}function iu(e,t){let n=e.parent;return n instanceof I&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function au(e,t){let n=e.parentOfKind(z);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 ou(e){return!!e.parentOfKind(V)}function su(e,t){let n=e.parentOfKind(L);return!n||(n.name instanceof md?j(n.name):pu(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function cu(e){return!(e instanceof ad)||!Gl(e.op?.value)?!1:vu(e.leftExpression)!==void 0&&vu(e.rightExpression)!==void 0}function lu(e){let t=vu(e.leftExpression),n=vu(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function uu(e){return e instanceof md&&e.expression instanceof pd||e instanceof sd}function du(e){let t=e.parentNode;return!E(t)||t.rightExpression!==e?!1:!(E(t.parentNode)&&t.parentNode.leftExpression===t)}function fu(e){if(T(e))return e.expression.variable}function pu(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function mu(e){if(!(e instanceof I))return;let t=k(e?.name);return t===void 0?void 0:t.join(`.`)}function hu(e){return e.elementList.length===0}function gu(e){return e?.body?e.body instanceof B?e.body.body:[e.body]:[]}function _u(e){if(!e)return;if(!E(e))return[e];let t=_u(e.leftExpression);if(t)return t.push(e.rightExpression),t}function k(e){if(e===void 0)return;let t=_u(e);if(!t)return;let n=[];for(let e of t){let t=j(e);if(typeof t!=`string`)return;n.push(t)}return n}function vu(e){if(e===void 0)return;let t=_u(e);if(!t||t.length===0)return;let n=[];if(!T(_(t))){let e=t.pop();if(Xl(e))n=e.elementList;else return}let r=t;if(r.every(T))return{variables:r,tupleElements:n}}function yu(e){if(uu(e))return e instanceof sd?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof cd&&e.elementList.every(uu))return{functional:e.elementList.filter(e=>e instanceof sd),nonFunctional:e.elementList.filter(T)}}function A(e){if(w(e))return e.expression instanceof pd?e?.expression?.variable?.value:e.expression.literal.value}function bu(e){return e instanceof md&&e.expression instanceof dd&&e.expression.literal?.kind===y.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function xu(e){if(!(e instanceof H)||!e.callee)return;let t=_u(e.callee);if(!t||t.length===0||!t.every(T))return;let n=[];return Xl(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function j(e){if(T(e))return e.expression.variable.value}function Su(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function Cu(e){return e instanceof R?`${e.op?.value}${Cu(e.expression)}`:e.expression.literal.value}function wu(e){return e instanceof R?e.op?.value===`-`?-wu(e.expression):wu(e.expression):Number.parseFloat(e.expression.literal.value)}function M(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 Tu(e){let t=e.split(`
|
|
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}({});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,h=d?d.toStringTag:void 0;function ee(e){var t=p.call(e,h),n=e[h];try{e[h]=void 0;var r=!0}catch{}var i=m.call(e);return r&&(t?e[h]=n:delete e[h]),i}var te=ee,ne=Object.prototype.toString;function re(e){return ne.call(e)}var ie=re,ae=`[object Null]`,oe=`[object Undefined]`,se=d?d.toStringTag:void 0;function ce(e){return e==null?e===void 0?oe:ae:se&&se in Object(e)?te(e):ie(e)}var le=ce;function ue(e){return typeof e==`object`&&!!e}var de=ue,fe=`[object Symbol]`;function pe(e){return typeof e==`symbol`||de(e)&&le(e)==fe}var me=pe;function he(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var ge=he,_e=Array.isArray,ve=_e,ye=1/0,be=d?d.prototype:void 0,xe=be?be.toString:void 0;function Se(e){if(typeof e==`string`)return e;if(ve(e))return ge(e,Se)+``;if(me(e))return xe?xe.call(e):``;var t=e+``;return t==`0`&&1/e==-ye?`-0`:t}var Ce=Se,we=/\s/;function Te(e){for(var t=e.length;t--&&we.test(e.charAt(t)););return t}var Ee=Te,De=/^\s+/;function Oe(e){return e&&e.slice(0,Ee(e)+1).replace(De,``)}var ke=Oe;function Ae(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var je=Ae,Me=NaN,Ne=/^[-+]0x[0-9a-f]+$/i,Pe=/^0b[01]+$/i,Fe=/^0o[0-7]+$/i,Ie=parseInt;function Le(e){if(typeof e==`number`)return e;if(me(e))return Me;if(je(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=je(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=ke(e);var n=Pe.test(e);return n||Fe.test(e)?Ie(e.slice(2),n?2:8):Ne.test(e)?Me:+e}var Re=Le,ze=1/0,Be=17976931348623157e292;function Ve(e){return e?(e=Re(e),e===ze||e===-ze?(e<0?-1:1)*Be:e===e?e:0):e===0?e:0}var He=Ve;function Ue(e){var t=He(e),n=t%1;return t===t?n?t-n:t:0}var We=Ue;function Ge(e){return e}var Ke=Ge,qe=`[object AsyncFunction]`,Je=`[object Function]`,Ye=`[object GeneratorFunction]`,Xe=`[object Proxy]`;function Ze(e){if(!je(e))return!1;var t=le(e);return t==Je||t==Ye||t==qe||t==Xe}var Qe=Ze,$e=l[`__core-js_shared__`],et=$e,tt=function(){var e=/[^.]+$/.exec(et&&et.keys&&et.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function nt(e){return!!tt&&tt in e}var rt=nt,it=Function.prototype.toString;function at(e){if(e!=null){try{return it.call(e)}catch{}try{return e+``}catch{}}return``}var ot=at,st=/[\\^$.*+?()[\]{}|]/g,ct=/^\[object .+?Constructor\]$/,lt=Function.prototype,ut=Object.prototype,dt=lt.toString,ft=ut.hasOwnProperty,pt=RegExp(`^`+dt.call(ft).replace(st,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function mt(e){return!je(e)||rt(e)?!1:(Qe(e)?pt:ct).test(ot(e))}var ht=mt;function gt(e,t){return e?.[t]}var _t=gt;function vt(e,t){var n=_t(e,t);return ht(n)?n:void 0}var yt=vt,bt=yt(l,`WeakMap`),xt=bt;function St(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var Ct=St;function wt(){}var Tt=wt,Et=800,Dt=16,Ot=Date.now;function kt(e){var t=0,n=0;return function(){var r=Ot(),i=Dt-(r-n);if(n=r,i>0){if(++t>=Et)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var At=kt;function jt(e){return function(){return e}}var Mt=jt,Nt=function(){try{var e=yt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Pt=Nt,Ft=Pt?function(e,t){return Pt(e,`toString`,{configurable:!0,enumerable:!1,value:Mt(t),writable:!0})}:Ke,It=Ft,Lt=At(It),Rt=Lt;function zt(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 Bt=zt;function Vt(e){return e!==e}var Ht=Vt;function Ut(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}var Wt=Ut;function Gt(e,t,n){return t===t?Wt(e,t,n):Bt(e,Ht,n)}var Kt=Gt;function qt(e,t){return!!(e!=null&&e.length)&&Kt(e,t,0)>-1}var Jt=qt,Yt=9007199254740991,Xt=/^(?:0|[1-9]\d*)$/;function Zt(e,t){var n=typeof e;return t??=Yt,!!t&&(n==`number`||n!=`symbol`&&Xt.test(e))&&e>-1&&e%1==0&&e<t}var Qt=Zt;function $t(e,t,n){t==`__proto__`&&Pt?Pt(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var en=$t;function tn(e,t){return e===t||e!==e&&t!==t}var nn=tn,rn=Math.max;function an(e,t,n){return t=rn(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=rn(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Ct(e,this,s)}}var on=an;function sn(e,t){return Rt(on(e,t,Ke),e+``)}var cn=sn,ln=9007199254740991;function un(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=ln}var dn=un;function fn(e){return e!=null&&dn(e.length)&&!Qe(e)}var pn=fn,mn=Object.prototype;function hn(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||mn)}var gn=hn;function _n(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var vn=_n,yn=`[object Arguments]`;function bn(e){return de(e)&&le(e)==yn}var xn=bn,Sn=Object.prototype,Cn=Sn.hasOwnProperty,wn=Sn.propertyIsEnumerable,Tn=xn(function(){return arguments}())?xn:function(e){return de(e)&&Cn.call(e,`callee`)&&!wn.call(e,`callee`)},En=Tn;function Dn(){return!1}var On=Dn,kn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,An=kn&&typeof module==`object`&&module&&!module.nodeType&&module,jn=An&&An.exports===kn?l.Buffer:void 0,Mn=(jn?jn.isBuffer:void 0)||On,Nn=Mn,Pn=`[object Arguments]`,Fn=`[object Array]`,In=`[object Boolean]`,Ln=`[object Date]`,Rn=`[object Error]`,zn=`[object Function]`,Bn=`[object Map]`,Vn=`[object Number]`,Hn=`[object Object]`,Un=`[object RegExp]`,Wn=`[object Set]`,Gn=`[object String]`,Kn=`[object WeakMap]`,qn=`[object ArrayBuffer]`,Jn=`[object DataView]`,Yn=`[object Float32Array]`,Xn=`[object Float64Array]`,Zn=`[object Int8Array]`,Qn=`[object Int16Array]`,$n=`[object Int32Array]`,er=`[object Uint8Array]`,tr=`[object Uint8ClampedArray]`,nr=`[object Uint16Array]`,rr=`[object Uint32Array]`,g={};g[Yn]=g[Xn]=g[Zn]=g[Qn]=g[$n]=g[er]=g[tr]=g[nr]=g[rr]=!0,g[Pn]=g[Fn]=g[qn]=g[In]=g[Jn]=g[Ln]=g[Rn]=g[zn]=g[Bn]=g[Vn]=g[Hn]=g[Un]=g[Wn]=g[Gn]=g[Kn]=!1;function ir(e){return de(e)&&dn(e.length)&&!!g[le(e)]}var ar=ir;function or(e){return function(t){return e(t)}}var sr=or,cr=typeof exports==`object`&&exports&&!exports.nodeType&&exports,lr=cr&&typeof module==`object`&&module&&!module.nodeType&&module,ur=lr&&lr.exports===cr&&o.process,dr=function(){try{return lr&&lr.require&&lr.require(`util`).types||ur&&ur.binding&&ur.binding(`util`)}catch{}}(),fr=dr,pr=fr&&fr.isTypedArray,mr=pr?sr(pr):ar,hr=mr,gr=Object.prototype.hasOwnProperty;function _r(e,t){var n=ve(e),r=!n&&En(e),i=!n&&!r&&Nn(e),a=!n&&!r&&!i&&hr(e),o=n||r||i||a,s=o?vn(e.length,String):[],c=s.length;for(var l in e)(t||gr.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||Qt(l,c)))&&s.push(l);return s}var vr=_r;function yr(e,t){return function(n){return e(t(n))}}var br=yr,xr=br(Object.keys,Object),Sr=xr,Cr=Object.prototype.hasOwnProperty;function wr(e){if(!gn(e))return Sr(e);var t=[];for(var n in Object(e))Cr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var Tr=wr;function Er(e){return pn(e)?vr(e):Tr(e)}var Dr=Er;function Or(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var kr=Or,Ar=Object.prototype.hasOwnProperty;function jr(e){if(!je(e))return kr(e);var t=gn(e),n=[];for(var r in e)r==`constructor`&&(t||!Ar.call(e,r))||n.push(r);return n}var Mr=jr;function Nr(e){return pn(e)?vr(e,!0):Mr(e)}var Pr=Nr,Fr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ir=/^\w*$/;function Lr(e,t){if(ve(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||me(e)?!0:Ir.test(e)||!Fr.test(e)||t!=null&&e in Object(t)}var Rr=Lr,zr=yt(Object,`create`),Br=zr;function Vr(){this.__data__=Br?Br(null):{},this.size=0}var Hr=Vr;function Ur(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Wr=Ur,Gr=`__lodash_hash_undefined__`,Kr=Object.prototype.hasOwnProperty;function qr(e){var t=this.__data__;if(Br){var n=t[e];return n===Gr?void 0:n}return Kr.call(t,e)?t[e]:void 0}var Jr=qr,Yr=Object.prototype.hasOwnProperty;function Xr(e){var t=this.__data__;return Br?t[e]!==void 0:Yr.call(t,e)}var Zr=Xr,Qr=`__lodash_hash_undefined__`;function $r(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Br&&t===void 0?Qr:t,this}var ei=$r;function ti(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])}}ti.prototype.clear=Hr,ti.prototype.delete=Wr,ti.prototype.get=Jr,ti.prototype.has=Zr,ti.prototype.set=ei;var ni=ti;function ri(){this.__data__=[],this.size=0}var ii=ri;function ai(e,t){for(var n=e.length;n--;)if(nn(e[n][0],t))return n;return-1}var oi=ai,si=Array.prototype.splice;function ci(e){var t=this.__data__,n=oi(t,e);return n<0?!1:(n==t.length-1?t.pop():si.call(t,n,1),--this.size,!0)}var li=ci;function ui(e){var t=this.__data__,n=oi(t,e);return n<0?void 0:t[n][1]}var di=ui;function fi(e){return oi(this.__data__,e)>-1}var pi=fi;function mi(e,t){var n=this.__data__,r=oi(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var hi=mi;function gi(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])}}gi.prototype.clear=ii,gi.prototype.delete=li,gi.prototype.get=di,gi.prototype.has=pi,gi.prototype.set=hi;var _i=gi,vi=yt(l,`Map`),yi=vi;function bi(){this.size=0,this.__data__={hash:new ni,map:new(yi||_i),string:new ni}}var xi=bi;function Si(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var Ci=Si;function wi(e,t){var n=e.__data__;return Ci(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var Ti=wi;function Ei(e){var t=Ti(this,e).delete(e);return this.size-=t?1:0,t}var Di=Ei;function Oi(e){return Ti(this,e).get(e)}var ki=Oi;function Ai(e){return Ti(this,e).has(e)}var ji=Ai;function Mi(e,t){var n=Ti(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var Ni=Mi;function Pi(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])}}Pi.prototype.clear=xi,Pi.prototype.delete=Di,Pi.prototype.get=ki,Pi.prototype.has=ji,Pi.prototype.set=Ni;var Fi=Pi,Ii=`Expected a function`;function Li(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(Ii);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(Li.Cache||Fi),n}Li.Cache=Fi;var Ri=Li,zi=500;function Bi(e){var t=Ri(e,function(e){return n.size===zi&&n.clear(),e}),n=t.cache;return t}var Vi=Bi,Hi=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ui=/\\(\\)?/g,Wi=Vi(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(Hi,function(e,n,r,i){t.push(r?i.replace(Ui,`$1`):n||e)}),t}),Gi=Wi;function Ki(e){return e==null?``:Ce(e)}var qi=Ki;function Ji(e,t){return ve(e)?e:Rr(e,t)?[e]:Gi(qi(e))}var Yi=Ji,Xi=1/0;function Zi(e){if(typeof e==`string`||me(e))return e;var t=e+``;return t==`0`&&1/e==-Xi?`-0`:t}var Qi=Zi;function $i(e,t){t=Yi(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[Qi(t[n++])];return n&&n==r?e:void 0}var ea=$i;function ta(e,t,n){var r=e==null?void 0:ea(e,t);return r===void 0?n:r}var na=ta;function ra(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var ia=ra,aa=d?d.isConcatSpreadable:void 0;function oa(e){return ve(e)||En(e)||!!(aa&&e&&e[aa])}var sa=oa;function ca(e,t,n,r,i){var a=-1,o=e.length;for(n||=sa,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?ca(s,t-1,n,r,i):ia(i,s):r||(i[i.length]=s)}return i}var la=ca;function ua(e){return e!=null&&e.length?la(e,1):[]}var da=ua;function fa(){this.__data__=new _i,this.size=0}var pa=fa;function ma(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var ha=ma;function ga(e){return this.__data__.get(e)}var _a=ga;function va(e){return this.__data__.has(e)}var ya=va,ba=200;function xa(e,t){var n=this.__data__;if(n instanceof _i){var r=n.__data__;if(!yi||r.length<ba-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Fi(r)}return n.set(e,t),this.size=n.size,this}var Sa=xa;function Ca(e){this.size=(this.__data__=new _i(e)).size}Ca.prototype.clear=pa,Ca.prototype.delete=ha,Ca.prototype.get=_a,Ca.prototype.has=ya,Ca.prototype.set=Sa;var wa=Ca;function Ta(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}var Ea=Ta;function Da(){return[]}var Oa=Da,ka=Object.prototype.propertyIsEnumerable,Aa=Object.getOwnPropertySymbols,ja=Aa?function(e){return e==null?[]:(e=Object(e),Ea(Aa(e),function(t){return ka.call(e,t)}))}:Oa,Ma=ja;function Na(e,t,n){var r=t(e);return ve(e)?r:ia(r,n(e))}var Pa=Na;function Fa(e){return Pa(e,Dr,Ma)}var Ia=Fa,La=yt(l,`DataView`),Ra=La,za=yt(l,`Promise`),Ba=za,Va=yt(l,`Set`),Ha=Va,Ua=`[object Map]`,Wa=`[object Object]`,Ga=`[object Promise]`,Ka=`[object Set]`,qa=`[object WeakMap]`,Ja=`[object DataView]`,Ya=ot(Ra),Xa=ot(yi),Za=ot(Ba),Qa=ot(Ha),$a=ot(xt),eo=le;(Ra&&eo(new Ra(new ArrayBuffer(1)))!=Ja||yi&&eo(new yi)!=Ua||Ba&&eo(Ba.resolve())!=Ga||Ha&&eo(new Ha)!=Ka||xt&&eo(new xt)!=qa)&&(eo=function(e){var t=le(e),n=t==Wa?e.constructor:void 0,r=n?ot(n):``;if(r)switch(r){case Ya:return Ja;case Xa:return Ua;case Za:return Ga;case Qa:return Ka;case $a:return qa}return t});var to=eo,no=l.Uint8Array,ro=no;function io(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 ao=io,oo=`__lodash_hash_undefined__`;function so(e){return this.__data__.set(e,oo),this}var co=so;function lo(e){return this.__data__.has(e)}var uo=lo;function fo(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Fi;++t<n;)this.add(e[t])}fo.prototype.add=fo.prototype.push=co,fo.prototype.has=uo;var po=fo;function mo(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 ho=mo;function go(e,t){return e.has(t)}var _o=go,vo=1,yo=2;function bo(e,t,n,r,i,a){var o=n&vo,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&yo?new po:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var ee=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(ee!==void 0){if(ee)continue;f=!1;break}if(p){if(!ho(t,function(e,t){if(!_o(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===h||i(m,h,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var xo=bo;function So(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var Co=So;function wo(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var To=wo,Eo=1,Do=2,Oo=`[object Boolean]`,ko=`[object Date]`,Ao=`[object Error]`,jo=`[object Map]`,Mo=`[object Number]`,No=`[object RegExp]`,Po=`[object Set]`,Fo=`[object String]`,Io=`[object Symbol]`,Lo=`[object ArrayBuffer]`,Ro=`[object DataView]`,zo=d?d.prototype:void 0,Bo=zo?zo.valueOf:void 0;function Vo(e,t,n,r,i,a,o){switch(n){case Ro:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Lo:return!(e.byteLength!=t.byteLength||!a(new ro(e),new ro(t)));case Oo:case ko:case Mo:return nn(+e,+t);case Ao:return e.name==t.name&&e.message==t.message;case No:case Fo:return e==t+``;case jo:var s=Co;case Po:var c=r&Eo;if(s||=To,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Do,o.set(e,t);var u=xo(s(e),s(t),r,i,a,o);return o.delete(e),u;case Io:if(Bo)return Bo.call(e)==Bo.call(t)}return!1}var Ho=Vo,Uo=1,Wo=Object.prototype.hasOwnProperty;function Go(e,t,n,r,i,a){var o=n&Uo,s=Ia(e),c=s.length;if(c!=Ia(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Wo.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var h=e[u],ee=t[u];if(r)var te=o?r(ee,h,u,t,e,a):r(h,ee,u,e,t,a);if(!(te===void 0?h===ee||i(h,ee,n,r,a):te)){p=!1;break}m||=u==`constructor`}if(p&&!m){var ne=e.constructor,re=t.constructor;ne!=re&&`constructor`in e&&`constructor`in t&&!(typeof ne==`function`&&ne instanceof ne&&typeof re==`function`&&re instanceof re)&&(p=!1)}return a.delete(e),a.delete(t),p}var Ko=Go,qo=1,Jo=`[object Arguments]`,Yo=`[object Array]`,Xo=`[object Object]`,Zo=Object.prototype.hasOwnProperty;function Qo(e,t,n,r,i,a){var o=ve(e),s=ve(t),c=o?Yo:to(e),l=s?Yo:to(t);c=c==Jo?Xo:c,l=l==Jo?Xo:l;var u=c==Xo,d=l==Xo,f=c==l;if(f&&Nn(e)){if(!Nn(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new wa,o||hr(e)?xo(e,t,n,r,i,a):Ho(e,t,c,n,r,i,a);if(!(n&qo)){var p=u&&Zo.call(e,`__wrapped__`),m=d&&Zo.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,ee=m?t.value():t;return a||=new wa,i(h,ee,n,r,a)}}return f?(a||=new wa,Ko(e,t,n,r,i,a)):!1}var $o=Qo;function es(e,t,n,r,i){return e===t?!0:e==null||t==null||!de(e)&&!de(t)?e!==e&&t!==t:$o(e,t,n,r,es,i)}var ts=es,ns=1,rs=2;function is(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 wa;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?ts(u,l,ns|rs,r,d):f))return!1}}return!0}var as=is;function os(e){return e===e&&!je(e)}var ss=os;function cs(e){for(var t=Dr(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,ss(i)]}return t}var ls=cs;function us(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var ds=us;function fs(e){var t=ls(e);return t.length==1&&t[0][2]?ds(t[0][0],t[0][1]):function(n){return n===e||as(n,e,t)}}var ps=fs;function ms(e,t){return e!=null&&t in Object(e)}var hs=ms;function gs(e,t,n){t=Yi(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=Qi(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&&dn(i)&&Qt(o,i)&&(ve(e)||En(e)))}var _s=gs;function vs(e,t){return e!=null&&_s(e,t,hs)}var ys=vs,bs=1,xs=2;function Ss(e,t){return Rr(e)&&ss(t)?ds(Qi(e),t):function(n){var r=na(n,e);return r===void 0&&r===t?ys(n,e):ts(t,r,bs|xs)}}var Cs=Ss;function ws(e){return function(t){return t?.[e]}}var Ts=ws;function Es(e){return function(t){return ea(t,e)}}var Ds=Es;function Os(e){return Rr(e)?Ts(Qi(e)):Ds(e)}var ks=Os;function As(e){return typeof e==`function`?e:e==null?Ke:typeof e==`object`?ve(e)?Cs(e[0],e[1]):ps(e):ks(e)}var js=As;function Ms(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 Ns=Ms;function Ps(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 Fs=Ps,Is=Fs(),Ls=Is;function Rs(e,t){return e&&Ls(e,t,Dr)}var zs=Rs;function Bs(e,t){return function(n,r){if(n==null)return n;if(!pn(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var Vs=Bs,Hs=Vs(zs),Us=Hs;function Ws(e,t,n,r){return Us(e,function(e,i,a){t(r,e,n(e),a)}),r}var Gs=Ws;function Ks(e,t){return function(n,r){var i=ve(n)?Ns:Gs,a=t?t():{};return i(n,e,js(r,2),a)}}var qs=Ks;function Js(e){return de(e)&&pn(e)}var Ys=Js;function Xs(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 Zs=Xs,Qs=200;function $s(e,t,n,r){var i=-1,a=Jt,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ge(t,sr(n))),r?(a=Zs,o=!1):t.length>=Qs&&(a=_o,o=!1,t=new po(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var ec=$s,tc=cn(function(e,t){return Ys(e)?ec(e,la(t,1,Ys,!0)):[]}),nc=tc;function rc(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var _=rc;function ic(e){return typeof e==`function`?e:Ke}var ac=ic;function oc(e,t){var n=[];return Us(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}var sc=oc;function cc(e,t){return(ve(e)?Ea:sc)(e,js(t,3))}var lc=cc,uc=Math.max,dc=Math.min;function fc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=We(n),i=n<0?uc(r+i,0):dc(i,r-1)),Bt(e,js(t,3),i,!0)}var pc=fc;function mc(e){return e&&e.length?e[0]:void 0}var hc=mc;function gc(e,t){var n=-1,r=pn(e)?Array(e.length):[];return Us(e,function(e,i,a){r[++n]=t(e,i,a)}),r}var _c=gc;function vc(e,t){return(ve(e)?ge:_c)(e,js(t,3))}var yc=vc;function bc(e,t){return la(yc(e,t),1)}var xc=bc;function Sc(e,t){return e==null?e:Ls(e,ac(t),Pr)}var Cc=Sc,wc=Object.prototype.hasOwnProperty,Tc=qs(function(e,t,n){wc.call(e,n)?e[n].push(t):en(e,n,[t])}),Ec=Tc,Dc=`[object Map]`,Oc=`[object Set]`,kc=Object.prototype.hasOwnProperty;function Ac(e){if(e==null)return!0;if(pn(e)&&(ve(e)||typeof e==`string`||typeof e.splice==`function`||Nn(e)||hr(e)||En(e)))return!e.length;var t=to(e);if(t==Dc||t==Oc)return!e.size;if(gn(e))return!Tr(e).length;for(var n in e)if(kc.call(e,n))return!1;return!0}var jc=Ac,Mc=qs(function(e,t,n){en(e,n,t)}),Nc=Mc,Pc=qs(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),v=Pc,Fc=Ha&&1/To(new Ha([,-0]))[1]==1/0?function(e){return new Ha(e)}:Tt,Ic=Fc,Lc=200;function Rc(e,t,n){var r=-1,i=Jt,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=Zs;else if(a>=Lc){var l=t?null:Ic(e);if(l)return To(l);o=!1,i=_o,c=new po}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}var zc=Rc;function Bc(e){return e&&e.length?zc(e):[]}var Vc=Bc;function Hc(e,t){return e&&e.length?zc(e,js(t,2)):[]}var Uc=Hc,Wc=Math.max;function Gc(e){if(!(e&&e.length))return[];var t=0;return e=Ea(e,function(e){if(Ys(e))return t=Wc(e.length,t),!0}),vn(t,function(t){return ge(e,Ts(t))})}var Kc=Gc,qc=cn(Kc),Jc=qc;let y=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 Yc(e){switch(e.kind){case y.NEWLINE:case y.SPACE:case y.TAB:case y.SINGLE_LINE_COMMENT:case y.MULTILINE_COMMENT:return!0;default:return!1}}function Xc(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 Zc(e){return e!==void 0&&e.kind===y.OP}var Qc=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 $c(e){return e.trailingTrivia.find(({kind:e})=>e===y.NEWLINE)!==void 0}function el(e,t){return t.leadingTrivia.find(({kind:e})=>e===y.NEWLINE)!==void 0||$c(e)}function tl(e){return e.trailingTrivia.find(({kind:e})=>[y.SPACE,y.TAB].includes(e))!==void 0}function nl(e){return e.trailingTrivia.length===0?e.end:nl(_(e.trailingTrivia))}function rl(e){return e.leadingTrivia.length===0?e.start:rl(e.leadingTrivia[0])}function il(e){return[y.SINGLE_LINE_COMMENT,y.MULTILINE_COMMENT].includes(e.kind)}function al(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`as`}function ol(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`use`}function sl(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`from`}function cl(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function ll(e){return!!e?.isInvalid}var ul=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},dl=/^[A-Za-z]:\//;function fl(e=``){return e&&e.replace(/\\/g,`/`).replace(dl,e=>e.toUpperCase())}var pl=/^[/\\]{2}/,ml=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,hl=/^[A-Za-z]:$/,gl=/^\/([A-Za-z]:)?$/,_l=/.(\.[^./]+|\.)$/,vl=function(e){if(e.length===0)return`.`;e=fl(e);let t=e.match(pl),n=Cl(e),r=e[e.length-1]===`/`;return e=Sl(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),hl.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!Cl(e)?`/${e}`:e)},yl=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 vl(t)};function bl(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var xl=function(...e){e=e.map(e=>fl(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:bl();!i||i.length===0||(t=`${i}/${t}`,n=Cl(i))}return t=Sl(t,!n),n&&!Cl(t)?`/${t}`:t.length>0?t:`.`};function Sl(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 Cl=function(e){return ml.test(e)},wl=function(e){if(e===`..`)return``;let t=_l.exec(fl(e));return t&&t[1]||``},Tl=function(e,t){let n=xl(e).replace(gl,`$1`).split(`/`),r=xl(t).replace(gl,`$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(`/`)},El=function(e){let t=fl(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&hl.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(Cl(e)?`/`:`.`)},Dl=function(e,t){let n=fl(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},Ol=/^[a-zA-Z]:\//,kl=class e{constructor(e,t={}){let n=vl(e);if(!Cl(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(xl(t,n))}static fromUri(t){try{let n=new URL(t);return new e(vl(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(vl(t))}}get absolute(){return this.path}get dirname(){return El(this.path)}get basename(){return Dl(this.path)}get extname(){return wl(this.path)}resolve(t){return new e(xl(this.dirname,t))}join(...t){return new e(yl(this.path,...t))}relativeTo(e){let t=Tl(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===void 0)return this.path;let n=Ol.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!Cl(vl(e))}};function Al(e,t){if(!kl.isRelative(t))return;let n=kl.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:kl.from(n.absolute+`.dbml`)}const jl=[`null`,`true`,`false`],Ml=`.dbml`,Nl=[`-`,`+`],b=`public`,Pl=kl.from(`/main.dbml`);let x=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.INVALID_INDEXES_CONTEXT=3047]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3048]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3049]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3050]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3051]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3052]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3053]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3054]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3055]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3056]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3057]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3058]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3059]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3060]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3061]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3062]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3063]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3064]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3065]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3066]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3067]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3069]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3070]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3071]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3072]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3073]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3074]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3075]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3076]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3077]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3078]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3079]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3080]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3081]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.INVALID_USE_CONTEXT=3082]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3083]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3084]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3085]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3086]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3087]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3088]=`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 S=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 Fl(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},Fl=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,S.prototype)}get filepath(){return this.nodeOrToken.filepath}};function Il(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Ll(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Rl(e){let[t]=e;return Ll(t)||Il(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function zl(e){return Il(e)||Ll(e)}function Bl(e){let t=k(e);return t!==void 0&&t.length>0}function Vl(e){return Hl(e)}function Hl(e){return e instanceof md&&e.expression instanceof pd}function Ul(e){return!!e.bodyColon}function Wl(e){return e instanceof R&&e.op?.value===`~`&&T(e.expression)}function Gl(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function Kl(e){if(!(e instanceof md)||!(e.expression instanceof dd)||e.expression.literal?.kind!==y.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(!Rl(t[e]))return!1;return!0}function ql(e){if(w(e)||Jl(e)||$l(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof R&&Nl.includes(e.op?.value)&&Jl(e.expression)||e instanceof sd)return!0;if(!e||!eu(e))return!1;let t=_u(e);return t.length===2||t.length===3}function Jl(e){return e instanceof R?Nl.includes(e.op.value)?Jl(e.expression):!1:e instanceof md&&e.expression instanceof dd&&e.expression.literal?.kind===y.NUMERIC_LITERAL}function Yl(e){if(!(e instanceof R)||!Gl(e.op?.value))return!1;let t=k(e.expression);return t!==void 0&&t.length>0}function Xl(e){return e instanceof cd&&e.elementList.every(T)}function Zl(e){if(!(e instanceof H||E(e)||e instanceof md||e instanceof gd))return!1;for(;e instanceof H||e instanceof gd;)if(e instanceof H){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Jl(e)||w(e)||$l(e)))return!1;e=e.callee}else if(e instanceof gd){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Jl(e.name)))return!1;e=e.array}let t=k(e);return t!==void 0&&t.length>0}function C(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof md){r.push(new S(x.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=pu(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 w(e){return e instanceof md&&(e.expression instanceof pd&&e.expression.variable instanceof Qc&&e.expression.variable.kind===y.QUOTED_STRING||e.expression instanceof dd&&e.expression.literal?.kind===y.STRING_LITERAL)}function T(e){return e instanceof md&&e.expression instanceof pd&&e.expression.variable instanceof Qc}function Ql(e){return e?e instanceof fd:!1}function $l(e){return e instanceof md&&e.expression instanceof pd&&e.expression.variable?.kind===y.IDENTIFIER}function E(e){return e instanceof ad&&e.leftExpression instanceof P&&e.rightExpression instanceof P&&e.op?.value===`.`}function eu(e){return T(e)?!0:E(e)&&T(e.rightExpression)&&eu(e.leftExpression)}function D(e,t){return e instanceof I&&e.isKind(t)}function tu(e){return e instanceof td}function nu(e,t){return e instanceof nd&&(t===void 0||e.isKind(t))}function ru(e){return e instanceof ed}function O(e,...t){return e instanceof z&&e.parent instanceof I&&e.parent.isKind(...t)}function iu(e,t){let n=e.parent;return n instanceof I&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function au(e,t){let n=e.parentOfKind(z);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 ou(e){return!!e.parentOfKind(V)}function su(e,t){let n=e.parentOfKind(L);return!n||(n.name instanceof md?j(n.name):pu(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function cu(e){return!(e instanceof ad)||!Gl(e.op?.value)?!1:vu(e.leftExpression)!==void 0&&vu(e.rightExpression)!==void 0}function lu(e){let t=vu(e.leftExpression),n=vu(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function uu(e){return e instanceof md&&e.expression instanceof pd||e instanceof sd}function du(e){let t=e.parentNode;return!E(t)||t.rightExpression!==e?!1:!(E(t.parentNode)&&t.parentNode.leftExpression===t)}function fu(e){if(T(e))return e.expression.variable}function pu(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function mu(e){if(!(e instanceof I))return;let t=k(e?.name);return t===void 0?void 0:t.join(`.`)}function hu(e){return e.elementList.length===0}function gu(e){return e?.body?e.body instanceof B?e.body.body:[e.body]:[]}function _u(e){if(!e)return;if(!E(e))return[e];let t=_u(e.leftExpression);if(t)return t.push(e.rightExpression),t}function k(e){if(e===void 0)return;let t=_u(e);if(!t)return;let n=[];for(let e of t){let t=j(e);if(typeof t!=`string`)return;n.push(t)}return n}function vu(e){if(e===void 0)return;let t=_u(e);if(!t||t.length===0)return;let n=[];if(!T(_(t))){let e=t.pop();if(Xl(e))n=e.elementList;else return}let r=t;if(r.every(T))return{variables:r,tupleElements:n}}function yu(e){if(uu(e))return e instanceof sd?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof cd&&e.elementList.every(uu))return{functional:e.elementList.filter(e=>e instanceof sd),nonFunctional:e.elementList.filter(T)}}function A(e){if(w(e))return e.expression instanceof pd?e?.expression?.variable?.value:e.expression.literal.value}function bu(e){return e instanceof md&&e.expression instanceof dd&&e.expression.literal?.kind===y.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function xu(e){if(!(e instanceof H)||!e.callee)return;let t=_u(e.callee);if(!t||t.length===0||!t.every(T))return;let n=[];return Xl(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function j(e){if(T(e))return e.expression.variable.value}function Su(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function Cu(e){return e instanceof R?`${e.op?.value}${Cu(e.expression)}`:e.expression.literal.value}function wu(e){return e instanceof R?e.op?.value===`-`?-wu(e.expression):wu(e.expression):Number.parseFloat(e.expression.literal.value)}function M(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 Tu(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 Eu(e){let t=k(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function Du(e){if(e instanceof md&&e.expression instanceof dd&&e.expression.literal?.kind===y.COLOR_LITERAL)return e.expression.literal.value}function Ou(e){if(e){if(w(e)){let t=A(e);if(t!==void 0)return{value:t,type:`string`}}if(Jl(e))return{type:`number`,value:wu(e)};if($l(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof sd&&e.value)return{value:e.value.value,type:`expression`};if(eu(e)){let t=_u(e)?.at(-1),n=t?j(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function ku(e,t){let r=``,i=null;if(t instanceof H){if(i=(t.argumentList?.elementList??[]).map(e=>Jl(e)?Cu(e):w(e)?A(e):j(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof H||t instanceof gd;)if(t instanceof H){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Jl(e)?Cu(e):w(e)?A(e):j(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof gd){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}=Eu(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new S(x.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}let N=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 Au={Table:N.Table,Enum:N.Enum,TableGroup:N.TableGroup,TablePartial:N.TablePartial,Note:N.StickyNote,Schema:N.Schema};var ju=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Mu=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 M(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()}},Nu=class e extends Mu{constructor({name:e,parent:t},n,r){super({kind:N.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(`.`)===b}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}},Pu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.Enum,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Fu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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=Tu(A(i));if(a)return{value:a,token:M(r)}}},Iu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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 Qu))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(N.Column))}partialInjections(e){return this.members(e).filter(e=>e.isKind(N.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=Tu(A(i));if(a)return{value:a,token:M(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?Du(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===vd.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===vd.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===vd.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===vd.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof z)||!Wl(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===vd.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===vd.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=Du(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=Tu(A(a));if(o)return{value:o,token:M(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Lu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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 Ou(n)}type(e){if(!(this.declaration instanceof z))return;let n=ku(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 Pu?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===vd.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=Tu(A(i));if(a)return{value:a,token:M(r)}}},Ru=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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(N.TableGroupField))}color(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.color?.length?Du(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=Tu(A(i));if(a)return{value:a,token:M(r)}}},zu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.TableGroupField,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Bu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.StickyNote,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Vu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.TablePartial,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Hu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.PartialInjection,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Uu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramView,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Wu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewTopLevelWildcard,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Gu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewTable,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Ku=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewTableGroup,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},qu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewNote,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Ju=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewSchema,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Yu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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 Nu&&r.inNestedSchema(e,t))return!0;return!1}},Xu=class extends Mu{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}},Zu=class extends Mu{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(td);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},Qu=class extends Lu{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},$u=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},P=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 Qc?rl(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 Qc?nl(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 I||e instanceof ed)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 F=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 ed=class extends P{constructor({body:e=[],eof:t,source:n},r,i){super(r,F.PROGRAM,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===F.ELEMENT_DECLARATION)}get uses(){return this.body.filter(e=>e.kind===F.USE_DECLARATION)}},td=class extends P{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,F.USE_DECLARATION,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return cl(this.useKeyword)}},nd=class extends P{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,F.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(N).find(t=>t.toLowerCase()===e)}},rd=class extends P{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,F.USE_SPECIFIER_LIST,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},I=class e extends P{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,F.ELEMENT_DECLARATION,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof z||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))}},id=class extends P{constructor({identifiers:e=[]},t,n){super(t,F.IDENTIFIER_STREAM,n,e||[]),this.identifiers=e}},L=class extends P{constructor({name:e,colon:t,value:n},r,i){super(r,F.ATTRIBUTE,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},R=class extends P{constructor({op:e,expression:t},n,r){super(n,F.PREFIX_EXPRESSION,r,[e,t]),this.op=e,this.expression=t}},ad=class extends P{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,F.INFIX_EXPRESSION,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},od=class extends P{constructor({op:e,expression:t},n,r){super(n,F.POSTFIX_EXPRESSION,r,[t,e]),this.op=e,this.expression=t}},sd=class extends P{constructor({value:e},t,n){super(t,F.FUNCTION_EXPRESSION,n,[e]),this.value=e}},z=class extends P{constructor({callee:e,args:t=[]},n,r){super(n,F.FUNCTION_APPLICATION,r,[e,...t]),this.callee=e,this.args=t}},B=class extends P{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,F.BLOCK_EXPRESSION,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},V=class extends P{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,F.LIST_EXPRESSION,a,[e,..._d(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},cd=class extends P{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,F.TUPLE_EXPRESSION,a,[e,..._d(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},ld=class extends P{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,F.COMMA_EXPRESSION,r,[..._d(e,t)]),this.elementList=e,this.commaList=t}},ud=class extends cd{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=F.GROUP_EXPRESSION}},H=class extends P{constructor({callee:e,argumentList:t},n,r){super(n,F.CALL_EXPRESSION,r,[e,t]),this.callee=e,this.argumentList=t}},dd=class extends P{constructor({literal:e},t,n){super(t,F.LITERAL,n,[e]),this.literal=e}},fd=class extends P{constructor({token:e},t,n){super(t,F.WILDCARD,n,[e]),this.token=e}},pd=class extends P{constructor({variable:e},t,n){super(t,F.VARIABLE,n,[e]),this.variable=e}},md=class extends P{constructor({expression:e},t,n){super(t,F.PRIMARY_EXPRESSION,n,[e]),this.expression=e}},hd=class extends P{constructor({prevToken:e},t,n){let r=Qc.create(y.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,F.EMPTY,n,[r])}},gd=class extends P{constructor({expression:e,indexer:t},n,r){super(n,F.ARRAY,r,[e,t]),this.array=e,this.indexer=t}};function _d(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?da(Jc(e,t)):da(Jc(t,e))).filter(e=>e!==null)}let vd=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 yd=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}`}},bd=class extends yd{constructor(e){super(e),this.kind=vd.Ref}container(e){let n=this.declaration.parentOfKind(I);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof I){let t=gu(this.declaration)[0];if(!(t instanceof z))return[];let n=t.callee;return n instanceof ad?Ed(e,n.leftExpression):[]}if(this.declaration instanceof L){let n=this.declaration.parentOfKind(z);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof I){let t=gu(this.declaration)[0];if(!(t instanceof z))return[];let n=t.callee;return n instanceof ad?Ed(e,n.rightExpression):[]}if(this.declaration instanceof L){let t=this.declaration.value;return t instanceof R?Ed(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof I){let t=gu(this.declaration)[0];if(!(t instanceof z))return;let n=t.callee;return n instanceof ad?Dd(e,n.leftExpression):void 0}if(this.declaration instanceof L)return this.container(e)}rightTable(e){if(this.declaration instanceof I){let t=gu(this.declaration)[0];if(!(t instanceof z))return;let n=t.callee;return n instanceof ad?Dd(e,n.rightExpression):void 0}if(this.declaration instanceof L){let t=this.declaration.value;return t instanceof R?Dd(e,t.expression)??this.container(e):void 0}}op(e){if(this.declaration instanceof I){let e=gu(this.declaration)[0];if(!(e instanceof z))return;let t=e.callee;return t instanceof ad?t.op?.value:void 0}if(this.declaration instanceof L){let e=this.declaration.value;return e instanceof R?e.op?.value:void 0}}leftToken(){if(this.declaration instanceof I){let e=gu(this.declaration)[0];if(e instanceof z){let t=e.callee;if(t instanceof ad&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof L){let e=this.declaration.parentOfKind(z);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof I){let e=gu(this.declaration)[0];if(e instanceof z){let t=e.callee;if(t instanceof ad&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof L,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))}},xd=class extends yd{constructor(e){super(e),this.kind=vd.PartialRef}container(e){let n=this.declaration.parentOfKind(I);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof L))return[];let n=this.declaration.parentOfKind(z);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof L))return[];let t=this.declaration.value;return t instanceof R?Ed(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof L)return this.container(e)}rightTable(e){if(!(this.declaration instanceof L))return;let t=this.declaration.value;if(t instanceof R)return Dd(e,t.expression)??this.container(e)}op(e){if(!(this.declaration instanceof L))return;let t=this.declaration.value;if(t instanceof R)return t.op?.value}leftToken(){if(this.declaration instanceof L){let e=this.declaration.parentOfKind(z);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof L,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))}},Sd=class extends yd{constructor(e){super(e),this.kind=vd.TableChecks,this.ownerTable=e.parentNode?.parentOfKind(I)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Cd=class extends yd{constructor(e){super(e),this.kind=vd.Indexes,this.ownerTable=e.parentNode?.parentOfKind(I)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},wd=class extends yd{constructor(e){super(e),this.kind=vd.Records}table(e){let n=this.declaration,i=n.parent;if(i instanceof I&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof H))return;let o=xu(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)):[]}},Td=class extends yd{constructor(e){super(e),this.kind=vd.Project}owners(e){let n=this.declaration.filepath,r=e.parseFile(n).getValue().ast,i=e.nodeSymbol(r).getFiltered(t);return i?[i]:[]}};function Ed(e,n){if(!n)return[];let r=vu(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 Dd(e,n){if(!n)return;let r=vu(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 Od=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},kd=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof B?new n(e.body.flatMap(e=>{if(!(e instanceof z))return[];let t=M(e),n=e.callee instanceof sd?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof V);return a&&(r=A(C(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}};const Ad={nodeMetadata(t,i){if(D(i,r.Checks)){let t=i.parent;return!t||!D(t,r.Table)&&!D(t,r.TablePartial)?n.create(e):n.create(new Sd(i))}return n.create(e)},bindNode(t,i){return D(i,r.Checks)?n.create(void 0,new Od(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===vd.TableChecks?r.declaration instanceof I?new kd(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function jd(e,t,n){let r=t,i=e;if(i instanceof H&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!$l(i)||r.length===0)return;let a=[...r],o=fu(i),s=a.pop();if(!(s instanceof B))return;let c=_(a)instanceof V?a.pop():void 0;if(a.length===3){let e=fu(a[1]);return!e||!al(e)?void 0:n.create(I,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(I,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(I,{type:o,attributeList:c,body:s})}function U(e){e&&(e instanceof Qc?Md(e):Nd(e))}function Md(e){e.kind!==y.EOF&&(e.isInvalid=!0)}function Nd(e){if(e instanceof I)U(e.type),U(e.name),U(e.as),U(e.alias),U(e.bodyColon),U(e.attributeList),U(e.body);else if(e instanceof id)e.identifiers.forEach(U);else if(e instanceof L)U(e.name),U(e.colon),U(e.value);else if(e instanceof R)U(e.op),U(e.expression);else if(e instanceof ad)U(e.leftExpression),U(e.op),U(e.rightExpression);else if(e instanceof od)U(e.op),U(e.expression);else if(e instanceof B)U(e.blockOpenBrace),e.body.forEach(U),U(e.blockCloseBrace);else if(e instanceof V)U(e.listOpenBracket),e.commaList.forEach(U),e.elementList.forEach(U),U(e.listCloseBracket);else if(e instanceof cd)U(e.tupleOpenParen),e.commaList.forEach(U),e.elementList.forEach(U),U(e.tupleCloseParen);else if(e instanceof ld)e.commaList.forEach(U),e.elementList.forEach(U);else if(e instanceof H)U(e.callee),U(e.argumentList);else if(e instanceof z)U(e.callee),e.args.forEach(U);else if(e instanceof md)U(e.expression);else if(e instanceof sd)U(e.value);else if(e instanceof pd)U(e.variable);else if(e instanceof dd)U(e.literal);else if(e instanceof ud)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof gd)U(e.array),U(e.indexer);else if(e instanceof ed)e.body.forEach(U),U(e.eof);else if(!(e instanceof hd))if(e instanceof td)U(e.useKeyword),U(e.specifiers),U(e.fromKeyword),U(e.importPath);else if(e instanceof rd)U(e.openBrace),e.specifiers.forEach(U),U(e.closeBrace);else if(e instanceof nd)U(e.importKind),U(e.name);else if(e instanceof fd)U(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Pd(...e){return e.filter(e=>e!==void 0)}function Fd(e){if(e instanceof ed)return Pd(...e.body,e.eof);if(e instanceof I)return Pd(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof L)return Pd(e.name,e.colon,e.value);if(e instanceof id)return e.identifiers;if(e instanceof dd)return e.literal?[e.literal]:[];if(e instanceof pd)return Pd(e.variable);if(e instanceof R)return Pd(e.op,e.expression);if(e instanceof ad)return Pd(e.leftExpression,e.op,e.rightExpression);if(e instanceof od)return Pd(e.expression,e.op);if(e instanceof sd)return Pd(e.value);if(e instanceof z)return Pd(e.callee,...e.args);if(e instanceof B)return Pd(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof V)return Pd(e.listOpenBracket,...Id(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof cd)return Pd(e.tupleOpenParen,...Id(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof ld)return Pd(...Id(e.elementList,e.commaList));if(e instanceof H)return Pd(e.callee,e.argumentList);if(e instanceof md)return Pd(e.expression);if(e instanceof gd)return Pd(e.array,e.indexer);if(e instanceof hd)return[];if(e instanceof td)return Pd(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof rd)return Pd(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof nd)return Pd(e.importKind,e.name);if(e instanceof fd)return Pd(e.token);throw e instanceof ud?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Id(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 Ld(e,t){let n=[...e.parseProject().values()].some(e=>e.getErrors().length>0),r=e.validateNode(t).getErrors().length>0,i=e.bindNode(t).getErrors().length>0;return!n&&!r&&!i}function Rd(e){if(!e)return[];if(T(e))return[{variables:[e],tupleElements:[]}];if(e instanceof ad){let t=vu(e);return t?[t]:[...Rd(e.leftExpression),...Rd(e.rightExpression)]}if(e instanceof R||e instanceof od)return Rd(e.expression);if(e instanceof cd){let t=vu(e);return t?[t]:e.elementList.flatMap(Rd)}return[]}function zd(e,n){let r=n.parentNode;if(!r||!E(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;E(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Bd(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:return}}var Vd=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=v(e.body,e=>e instanceof z);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof B)?[]: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]=v(e.body,e=>e instanceof z);return t.flatMap(e=>!e.callee||Ql(e.callee)?[]:[e.callee,...e.args].flatMap(Rd).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]=v(e.body,e=>e instanceof z);return t.flatMap(e=>!e.callee||Ql(e.callee)?[]:Rd(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=v(e.body,e=>e instanceof z);return t.flatMap(e=>!e.callee||Ql(e.callee)?[]:Rd(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=v(e.body,e=>e instanceof z);return t.flatMap(e=>!e.callee||Ql(e.callee)?[]:Rd(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},Hd=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 B&&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 z&&Ql(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]=v(e.body,e=>e instanceof I),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof B&&this.interpretSubBlock(e.body,t)}let r=this.diagramView.visibleEntities;return(n.has(`tables`)&&r.tables!==null||n.has(`tablegroups`)&&r.tableGroups!==null||n.has(`schemas`)&&r.schemas!==null)&&(n.has(`tables`)||(r.tables=[]),n.has(`tablegroups`)||(r.tableGroups=[]),n.has(`schemas`)||(r.schemas=[])),n.has(`tables`)&&this.diagramViewExplicitlySet.add(`tables`),n.has(`tablegroups`)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(`schemas`)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(`notes`)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,n){if(!n)return;if(e.body.some(e=>e instanceof z&&Ql(e.callee))){let e=this.diagramViewWildcards;switch(n){case`tables`:this.diagramView.visibleEntities.tables=[],e.add(`tables`);break;case`notes`:this.diagramView.visibleEntities.stickyNotes=[],e.add(`stickyNotes`);break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=[],e.add(`tableGroups`);break;case`schemas`:this.diagramView.visibleEntities.schemas=[],e.add(`schemas`);break}return}if(e.body.length===0)return;let r=[];for(let n of e.body){if(!(n instanceof z))continue;let e=n.callee&&this.compiler.nodeReferee(n.callee).getFiltered(t);if(e?.declaration instanceof I){let t=k(e.declaration.name)??[];if(t.length>0){let e=t[t.length-1],n=t.length>1?t.slice(0,-1).join(`.`):b;r.push({name:e,schemaName:n});continue}}let i=k(n.callee)??[];if(i.length===0)continue;let a=i[i.length-1],o=i.length>1?i[0]:b;r.push({name:a,schemaName:o})}switch(n){case`tables`:this.diagramView.visibleEntities.tables=r.length>0?r:null;break;case`notes`:this.diagramView.visibleEntities.stickyNotes=r.length>0?r.map(e=>({name:e.name})):null;break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=r.length>0?r.map(e=>({name:e.name})):null;break;case`schemas`:this.diagramView.visibleEntities.schemas=r.length>0?r.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?Uc(r.filter(e=>e.isKind(N.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function Ud(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}let Wd=function(e){return e.Table=`table`,e}({});const Gd={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new S(x.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},Kd={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return D(a,r.DiagramView)?new n(i.symbolFactory.create(Uu,{declaration:a,name:o},a.filepath)):O(a,r.DiagramView)&&a instanceof fd?new n(i.symbolFactory.create(Wu,{declaration:a,name:o},a.filepath)):O(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(qu,{declaration:a,name:o},a.filepath)):O(a,r.DiagramViewTables)?new n(i.symbolFactory.create(Gu,{declaration:a,name:o},a.filepath)):O(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(Ku,{declaration:a,name:o},a.filepath)):O(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(Ju,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&ou(a))return n.create(e);let o=qd(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)?Jd(i,c,a):o.isKind(r.DiagramViewNotes)?Yd(i,c,a,N.StickyNote):o.isKind(r.DiagramViewTableGroups)?Yd(i,c,a,N.TableGroup):o.isKind(r.DiagramViewSchemas)?Xd(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(N.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!D(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of gu(o))if(e instanceof z){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof I&&c.push(...gu(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(N.DiagramViewSchema,N.DiagramViewTableGroup,N.DiagramViewTable,N.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(gy).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(Gd.getFieldDuplicateError(n,e.kind,i)),s.push(Gd.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!D(a,r.DiagramView))return n.create(e);let o=new Vd(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 Uu?r.declaration instanceof I?new Hd(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function qd(e){let t=e.parentOfKind(z);if(!t)return;let n=t.parentNode;if(!(n instanceof B))return;let i=n.parentNode;if(!(i instanceof I)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof B))return;let o=a.parentNode;if(!(!(o instanceof I)||!o.isKind(r.DiagramView)))return i}function Jd(e,r,i){let a=Su(i);if(a===void 0)return n.create(void 0);if(E(i.parentNode)){let t=zd(e,i);if(t){if(t.isKind(N.Schema)){let r=du(i),o=e.lookupMembers(t,r?N.Table:N.Schema,a);return o?n.create(o):new n(void 0,[new S(x.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,N.Schema,a);return o?n.create(o):new n(void 0,[new S(x.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(N.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,N.Table,a);return s?n.create(s):new n(void 0,[new S(x.BINDING_ERROR,`Could not find table '${a}'`,i)])}function Yd(e,t,r,i){let a=Su(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 S(x.BINDING_ERROR,`Could not find ${i===N.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function Xd(e,t,r){let i=Su(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var Zd=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof z)return[];let t=e.body.filter(e=>e instanceof I);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Qd=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=M(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=M(t),n.name=j(t.callee);let r=C(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Tu(A(r.value)),token:M(r)},this.enum.values.push(n),[]})}};const $d={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new S(x.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},ef={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return D(a,r.Enum)?new n(i.symbolFactory.create(Pu,{declaration:a,name:o},a.filepath)):O(a,r.Enum)?new n(i.symbolFactory.create(Fu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(N.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof I))return new n([]);let o=gu(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(N.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push($d.getFieldDuplicateError(t,r)),c.push($d.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!D(a,r.Enum))return n.create(e);let o=new Zd(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 Pu?new Qd(t,r,i).interpret():n.create(e)}};var tf=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof I)||!this.declarationNode.parent.isKind(r.Table)||!(this.declarationNode.body instanceof B)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=k(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(Rd).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=Su(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new S(x.BINDING_ERROR,`No column named '${r}' inside Table '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},nf=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof B?new n(e.body.flatMap(e=>{if(!(e instanceof z)||!e.callee)return[];let n=[],r=M(e),a=[e.callee,...e.args],o,s,c,l,u;_(a)instanceof V&&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=A(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=A(e.value);t!==void 0&&(l={value:t,token:M(e)})}u=j(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof H))return e;let t=[],n=e;for(;n instanceof H&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=yu(e);if(t){for(let e of t.functional)n.push({value:e.value?.value??``,type:`expression`,token:M(e)});for(let e of t.nonFunctional)n.push({value:Su(e)??``,type:`column`,token:M(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}};const rf={nodeMetadata(t,i){if(!D(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!D(a,r.Table)&&!D(a,r.TablePartial)?n.create(e):n.create(new Cd(i))},nodeReferee(i,a){if(!T(a)||ou(a))return n.create(e);let o=a;for(;o&&!D(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!D(s,r.Table)&&!D(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=T(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,N.Column,l);if(u)return n.create(u);let d=D(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new S(x.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return D(i,r.Indexes)?n.create(void 0,new tf(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===vd.Indexes?r.declaration instanceof I?new nf(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function af(e,n){let r=_u(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof cd){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 cd)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function of(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 S(x.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new S(x.CIRCULAR_REF,`References with same endpoints exist`,n),new S(x.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var sf=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 I&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new S(x.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof I&&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(...cf(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 I)||!t.type)continue;let i=t;D(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),D(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),D(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of gu(e)){if(!(r instanceof z)||!r.callee||!cu(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=af(this.compiler,i.leftExpression),o=af(this.compiler,i.rightExpression);!a||!o||n.push(...of(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of gu(e)){if(!(a instanceof z)||!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 R)||!i.op||!Gl(i.op.value)||!i.expression)continue;let a=af(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...of(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of gu(e)){if(!(r instanceof z)||!r.callee)continue;let e=j(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 R&&(!r.op||!Gl(r.op.value)||r.expression&&T(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new S(x.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 I)||!i.type)continue;let a=i;if(!D(a,r.TableGroup))continue;let o=a.name?k(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=gu(a);for(let r of c){if(!(r instanceof z)||!r.callee)continue;let i=_u(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=k(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new S(x.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 cf(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 Nu&&a.push(...cf(e,t,r));return a}function lf(e,t,n){t.isKind(N.Table)?e.externals.tables.push(n):t.isKind(N.Enum)?e.externals.enums.push(n):t.isKind(N.TableGroup)?e.externals.tableGroups.push(n):t.isKind(N.TablePartial)?e.externals.tablePartials.push(n):t.isKind(N.StickyNote)&&e.externals.notes.push(n)}var uf={mysql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`,`mediumint`]),postgres:new Set([`int`,`integer`,`smallint`,`bigint`,`serial`,`bigserial`,`smallserial`]),mssql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`]),oracle:new Set([`int`,`integer`,`smallint`]),snowflake:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`])},df={mysql:new Set([`decimal`,`numeric`,`float`,`double`,`real`]),postgres:new Set([`decimal`,`numeric`,`real`,`float`,`double precision`]),mssql:new Set([`decimal`,`numeric`,`real`,`float`]),oracle:new Set([`number`,`decimal`,`numeric`,`float`,`real`]),snowflake:new Set([`number`,`decimal`,`numeric`,`float`,`double`,`real`])},ff={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},pf={mysql:new Set([`varchar`,`char`,`text`,`tinytext`,`mediumtext`,`longtext`,`string`]),postgres:new Set([`varchar`,`char`,`character`,`character varying`,`text`,`string`]),mssql:new Set([`varchar`,`char`,`nvarchar`,`nchar`,`text`,`ntext`,`string`]),oracle:new Set([`varchar`,`varchar2`,`char`,`nvarchar2`,`nchar`,`string`]),snowflake:new Set([`varchar`,`char`,`text`,`string`])},mf={mysql:new Set([`binary`,`varbinary`,`blob`,`tinyblob`,`mediumblob`,`longblob`]),postgres:new Set([`bytea`]),mssql:new Set([`binary`,`varbinary`]),oracle:new Set([`blob`,`raw`]),snowflake:new Set([`binary`,`varbinary`])},hf={mysql:new Set([`date`,`datetime`,`timestamp`,`time`]),postgres:new Set([`date`,`timestamp`,`timestamptz`,`timestamp with time zone`,`timestamp without time zone`,`time`,`timetz`,`time with time zone`,`time without time zone`]),mssql:new Set([`date`,`datetime`,`datetime2`,`smalldatetime`,`time`]),oracle:new Set([`date`,`timestamp`,`timestamp with time zone`,`timestamp with local time zone`]),snowflake:new Set([`date`,`datetime`,`timestamp`,`time`])},gf={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function _f(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function vf(e,t){let n=_f(e);return t?uf[t].has(n):Object.values(uf).some(e=>e.has(n))}function yf(e,t){let n=_f(e);return t?df[t].has(n):Object.values(df).some(e=>e.has(n))}function bf(e,t){return vf(e,t)||yf(e,t)}function xf(e,t){let n=_f(e);return t?ff[t].has(n):Object.values(ff).some(e=>e.has(n))}function Sf(e,t){let n=_f(e);return t?pf[t].has(n):Object.values(pf).some(e=>e.has(n))}function Cf(e,t){let n=_f(e);return t?mf[t].has(n):Object.values(mf).some(e=>e.has(n))}function wf(e,t){let n=_f(e);return t?hf[t].has(n):Object.values(hf).some(e=>e.has(n))}function Tf(e,t){let n=_f(e);return t?gf[t].has(n):Object.values(gf).some(e=>e.has(n))}function Ef(e,t){if(t)return`string`;if(vf(e))return`integer`;if(yf(e))return`real`;if(xf(e))return`bool`;if(Sf(e))return`string`;let n=_f(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:wf(e)?`datetime`:e}var Df=class extends Error{},Of=class extends Df{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},kf=class extends Df{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Af=class extends Df{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},jf=class extends Df{},Mf=class extends Df{constructor(e){super(`Invalid unit ${e}`)}},Nf=class extends Df{},Pf=class extends Df{constructor(){super(`Zone is an abstract class`)}},W=`numeric`,Ff=`short`,If=`long`,Lf={year:W,month:W,day:W},Rf={year:W,month:Ff,day:W},zf={year:W,month:Ff,day:W,weekday:Ff},Bf={year:W,month:If,day:W},Vf={year:W,month:If,day:W,weekday:If},Hf={hour:W,minute:W},Uf={hour:W,minute:W,second:W},Wf={hour:W,minute:W,second:W,timeZoneName:Ff},Gf={hour:W,minute:W,second:W,timeZoneName:If},Kf={hour:W,minute:W,hourCycle:`h23`},qf={hour:W,minute:W,second:W,hourCycle:`h23`},Jf={hour:W,minute:W,second:W,hourCycle:`h23`,timeZoneName:Ff},Yf={hour:W,minute:W,second:W,hourCycle:`h23`,timeZoneName:If},Xf={year:W,month:W,day:W,hour:W,minute:W},Zf={year:W,month:W,day:W,hour:W,minute:W,second:W},Qf={year:W,month:Ff,day:W,hour:W,minute:W},$f={year:W,month:Ff,day:W,hour:W,minute:W,second:W},ep={year:W,month:Ff,day:W,weekday:Ff,hour:W,minute:W},tp={year:W,month:If,day:W,hour:W,minute:W,timeZoneName:Ff},np={year:W,month:If,day:W,hour:W,minute:W,second:W,timeZoneName:Ff},rp={year:W,month:If,day:W,weekday:If,hour:W,minute:W,timeZoneName:If},ip={year:W,month:If,day:W,weekday:If,hour:W,minute:W,second:W,timeZoneName:If},ap=class{get type(){throw new Pf}get name(){throw new Pf}get ianaName(){return this.name}get isUniversal(){throw new Pf}offsetName(e,t){throw new Pf}formatOffset(e,t){throw new Pf}offset(e){throw new Pf}equals(e){throw new Pf}get isValid(){throw new Pf}},op=null,sp=class e extends ap{static get instance(){return op===null&&(op=new e),op}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Jm(e,t,n)}formatOffset(e,t){return Qm(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},cp=new Map;function lp(e){let t=cp.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`}),cp.set(e,t)),t}var up={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function dp(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 fp(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=up[t];t===`era`?r[a]=i:G(a)||(r[a]=parseInt(i,10))}return r}var pp=new Map,mp=class e extends ap{static create(t){let n=pp.get(t);return n===void 0&&pp.set(t,n=new e(t)),n}static resetCache(){pp.clear(),cp.clear()}static isValidSpecifier(e){return this.isValidZone(e)}static isValidZone(e){if(!e)return!1;try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).format(),!0}catch{return!1}}constructor(t){super(),this.zoneName=t,this.valid=e.isValidZone(t)}get type(){return`iana`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Jm(e,t,n,this.name)}formatOffset(e,t){return Qm(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=lp(this.name),[r,i,a,o,s,c,l]=n.formatToParts?fp(n,t):dp(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=Wm({year:r,month:i,day:a,hour:s===24?0:s,minute:c,second:l,millisecond:0}),d=+t,f=d%1e3;return d-=f>=0?f:1e3+f,(u-d)/(60*1e3)}equals(e){return e.type===`iana`&&e.name===this.name}get isValid(){return this.valid}},hp={};function gp(e,t={}){let n=JSON.stringify([e,t]),r=hp[n];return r||(r=new Intl.ListFormat(e,t),hp[n]=r),r}var _p=new Map;function vp(e,t={}){let n=JSON.stringify([e,t]),r=_p.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),_p.set(n,r)),r}var yp=new Map;function bp(e,t={}){let n=JSON.stringify([e,t]),r=yp.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),yp.set(n,r)),r}var xp=new Map;function Sp(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=xp.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),xp.set(i,a)),a}var Cp=null;function wp(){return Cp||(Cp=new Intl.DateTimeFormat().resolvedOptions().locale,Cp)}var Tp=new Map;function Ep(e){let t=Tp.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Tp.set(e,t)),t}var Dp=new Map;function Op(e){let t=Dp.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Rp,...t}),Dp.set(e,t)}return t}function kp(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=vp(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=vp(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Ap(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function jp(e){let t=[];for(let n=1;n<=12;n++){let r=R_.utc(2009,n,1);t.push(e(r))}return t}function Mp(e){let t=[];for(let n=1;n<=7;n++){let r=R_.utc(2016,11,13+n);t.push(e(r))}return t}function Np(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Pp(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Ep(e.locale).numberingSystem===`latn`}var Fp=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=bp(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return Im(this.floor?Math.floor(e):Bm(e,3),this.padTo)}},Ip=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&&mp.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=vp(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()}},Lp=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Dm()&&(this.rtf=Sp(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):_h(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Rp={firstDay:1,minimalDays:4,weekend:[6,7]},zp=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||am.defaultLocale;return new e(o||(a?`en-US`:wp()),n||am.defaultNumberingSystem,r||am.defaultOutputCalendar,Nm(i)||am.defaultWeekSettings,o)}static resetCache(){Cp=null,_p.clear(),yp.clear(),xp.clear(),Tp.clear(),Dp.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]=kp(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Ap(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??=Pp(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,Nm(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 Np(this,e,rh,()=>{let n=this.intl===`ja`||this.intl.startsWith(`ja-`);t&=!n;let r=t?{month:e,day:`numeric`}:{month:e},i=t?`format`:`standalone`;if(!this.monthsCache[i][e]){let t=n?e=>this.dtFormatter(e,r).format():e=>this.extract(e,r,`month`);this.monthsCache[i][e]=jp(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Np(this,e,sh,()=>{let n=t?{weekday:e,year:`numeric`,month:`long`,day:`numeric`}:{weekday:e},r=t?`format`:`standalone`;return this.weekdaysCache[r][e]||(this.weekdaysCache[r][e]=Mp(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Np(this,void 0,()=>ch,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[R_.utc(2016,11,13,9),R_.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Np(this,e,fh,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[R_.utc(-40,1,1),R_.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 Fp(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new Ip(e,this.intl,t)}relFormatter(e={}){return new Lp(this.intl,this.isEnglish(),e)}listFormatter(e={}){return gp(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Ep(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Om()?Op(this.locale):Rp}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})`}},Bp=null,Vp=class e extends ap{static get utcInstance(){return Bp===null&&(Bp=new e(0)),Bp}static instance(t){return t===0?e.utcInstance:new e(t)}static parseSpecifier(t){if(t){let n=t.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);if(n)return new e(Ym(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${Qm(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${Qm(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return Qm(this.fixed,t)}get isUniversal(){return!0}offset(){return this.fixed}equals(e){return e.type===`fixed`&&e.fixed===this.fixed}get isValid(){return!0}},Hp=class extends ap{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 Up(e,t){if(G(e)||e===null)return t;if(e instanceof ap)return e;if(Tm(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?sp.instance:n===`utc`||n===`gmt`?Vp.utcInstance:Vp.parseSpecifier(n)||mp.create(e)}else if(Cm(e))return Vp.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new Hp(e)}var Wp={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},Gp={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]},Kp=Wp.hanidec.replace(/[\[|\]]/g,``).split(``);function qp(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(Wp.hanidec)!==-1)t+=Kp.indexOf(e[n]);else for(let e in Gp){let[n,i]=Gp[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Jp=new Map;function Yp(){Jp.clear()}function Xp({numberingSystem:e},t=``){let n=e||`latn`,r=Jp.get(n);r===void 0&&(r=new Map,Jp.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Wp[n]}${t}`),r.set(t,i)),i}var Zp=()=>Date.now(),Qp=`system`,$p=null,em=null,tm=null,nm=60,rm,im=null,am=class{static get now(){return Zp}static set now(e){Zp=e}static set defaultZone(e){Qp=e}static get defaultZone(){return Up(Qp,sp.instance)}static get defaultLocale(){return $p}static set defaultLocale(e){$p=e}static get defaultNumberingSystem(){return em}static set defaultNumberingSystem(e){em=e}static get defaultOutputCalendar(){return tm}static set defaultOutputCalendar(e){tm=e}static get defaultWeekSettings(){return im}static set defaultWeekSettings(e){im=Nm(e)}static get twoDigitCutoffYear(){return nm}static set twoDigitCutoffYear(e){nm=e%100}static get throwOnInvalid(){return rm}static set throwOnInvalid(e){rm=e}static resetCaches(){zp.resetCache(),mp.resetCache(),R_.resetCache(),Yp()}},om=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},sm=[0,31,59,90,120,151,181,212,243,273,304,334],cm=[0,31,60,91,121,152,182,213,244,274,305,335];function lm(e,t){return new om(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function um(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 dm(e,t,n){return n+(Vm(e)?cm:sm)[t-1]}function fm(e,t){let n=Vm(e)?cm:sm,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function pm(e,t){return(e-t+7)%7+1}function mm(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=dm(r,i,a),s=pm(um(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=Km(l,t,n)):c>Km(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...$m(e)}}function hm(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=pm(um(r,1,t),n),s=Hm(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=Hm(l)):c>s?(l=r+1,c-=Hm(r)):l=r;let{month:u,day:d}=fm(l,c);return{year:l,month:u,day:d,...$m(e)}}function gm(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:dm(t,n,r),...$m(e)}}function _m(e){let{year:t,ordinal:n}=e,{month:r,day:i}=fm(t,n);return{year:t,month:r,day:i,...$m(e)}}function vm(e,t){if(!G(e.localWeekday)||!G(e.localWeekNumber)||!G(e.localWeekYear)){if(!G(e.weekday)||!G(e.weekNumber)||!G(e.weekYear))throw new jf(`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 ym(e,t=4,n=1){let r=wm(e.weekYear),i=Pm(e.weekNumber,1,Km(e.weekYear,t,n)),a=Pm(e.weekday,1,7);return r?i?a?!1:lm(`weekday`,e.weekday):lm(`week`,e.weekNumber):lm(`weekYear`,e.weekYear)}function bm(e){let t=wm(e.year),n=Pm(e.ordinal,1,Hm(e.year));return t?n?!1:lm(`ordinal`,e.ordinal):lm(`year`,e.year)}function xm(e){let t=wm(e.year),n=Pm(e.month,1,12),r=Pm(e.day,1,Um(e.year,e.month));return t?n?r?!1:lm(`day`,e.day):lm(`month`,e.month):lm(`year`,e.year)}function Sm(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Pm(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Pm(n,0,59),s=Pm(r,0,59),c=Pm(i,0,999);return a?o?s?c?!1:lm(`millisecond`,i):lm(`second`,r):lm(`minute`,n):lm(`hour`,t)}function G(e){return e===void 0}function Cm(e){return typeof e==`number`}function wm(e){return typeof e==`number`&&e%1==0}function Tm(e){return typeof e==`string`}function Em(e){return Object.prototype.toString.call(e)===`[object Date]`}function Dm(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Om(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function km(e){return Array.isArray(e)?e:[e]}function Am(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 jm(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Mm(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Nm(e){if(e==null)return null;if(typeof e!=`object`)throw new Nf(`Week settings must be an object`);if(!Pm(e.firstDay,1,7)||!Pm(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Pm(e,1,7)))throw new Nf(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Pm(e,t,n){return wm(e)&&e>=t&&e<=n}function Fm(e,t){return e-t*Math.floor(e/t)}function Im(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Lm(e){if(!(G(e)||e===null||e===``))return parseInt(e,10)}function Rm(e){if(!(G(e)||e===null||e===``))return parseFloat(e)}function zm(e){if(!(G(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Bm(e,t,n=`round`){let r=10**t;switch(n){case`expand`:return e>0?Math.ceil(e*r)/r:Math.floor(e*r)/r;case`trunc`:return Math.trunc(e*r)/r;case`round`:return Math.round(e*r)/r;case`floor`:return Math.floor(e*r)/r;case`ceil`:return Math.ceil(e*r)/r;default:throw RangeError(`Value rounding ${n} is out of range`)}}function Vm(e){return e%4==0&&(e%100!=0||e%400==0)}function Hm(e){return Vm(e)?366:365}function Um(e,t){let n=Fm(t-1,12)+1,r=e+(t-n)/12;return n===2?Vm(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function Wm(e){let t=Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second,e.millisecond);return e.year<100&&e.year>=0&&(t=new Date(t),t.setUTCFullYear(e.year,e.month-1,e.day)),+t}function Gm(e,t,n){return-pm(um(e,1,t),n)+t-1}function Km(e,t=4,n=1){let r=Gm(e,t,n),i=Gm(e+1,t,n);return(Hm(e)-r+i)/7}function qm(e){return e>99?e:e>am.twoDigitCutoffYear?1900+e:2e3+e}function Jm(e,t,n,r=null){let i=new Date(e),a={hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};r&&(a.timeZone=r);let o={timeZoneName:t,...a},s=new Intl.DateTimeFormat(n,o).formatToParts(i).find(e=>e.type.toLowerCase()===`timezonename`);return s?s.value:null}function Ym(e,t){let n=parseInt(e,10);Number.isNaN(n)&&(n=0);let r=parseInt(t,10)||0,i=n<0||Object.is(n,-0)?-r:r;return n*60+i}function Xm(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Nf(`Invalid unit value ${e}`);return t}function Zm(e,t){let n={};for(let r in e)if(Mm(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=Xm(i)}return n}function Qm(e,t){let n=Math.trunc(Math.abs(e/60)),r=Math.trunc(Math.abs(e%60)),i=e>=0?`+`:`-`;switch(t){case`short`:return`${i}${Im(n,2)}:${Im(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${Im(n,2)}${Im(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function $m(e){return jm(e,[`hour`,`minute`,`second`,`millisecond`])}var eh=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],th=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],nh=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function rh(e){switch(e){case`narrow`:return[...nh];case`short`:return[...th];case`long`:return[...eh];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`,`12`];case`2-digit`:return[`01`,`02`,`03`,`04`,`05`,`06`,`07`,`08`,`09`,`10`,`11`,`12`];default:return null}}var ih=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],ah=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],oh=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function sh(e){switch(e){case`narrow`:return[...oh];case`short`:return[...ah];case`long`:return[...ih];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var ch=[`AM`,`PM`],lh=[`Before Christ`,`Anno Domini`],uh=[`BC`,`AD`],dh=[`B`,`A`];function fh(e){switch(e){case`narrow`:return[...dh];case`short`:return[...uh];case`long`:return[...lh];default:return null}}function ph(e){return ch[e.hour<12?0:1]}function mh(e,t){return sh(t)[e.weekday-1]}function hh(e,t){return rh(t)[e.month-1]}function gh(e,t){return fh(t)[e.year<0?0:1]}function _h(e,t,n=`always`,r=!1){let i={years:[`year`,`yr.`],quarters:[`quarter`,`qtr.`],months:[`month`,`mo.`],weeks:[`week`,`wk.`],days:[`day`,`day`,`days`],hours:[`hour`,`hr.`],minutes:[`minute`,`min.`],seconds:[`second`,`sec.`]},a=[`hours`,`minutes`,`seconds`].indexOf(e)===-1;if(n===`auto`&&a){let n=e===`days`;switch(t){case 1:return n?`tomorrow`:`next ${i[e][0]}`;case-1:return n?`yesterday`:`last ${i[e][0]}`;case 0:return n?`today`:`this ${i[e][0]}`}}let o=Object.is(t,-0)||t<0,s=Math.abs(t),c=s===1,l=i[e],u=r?c?l[1]:l[2]||l[1]:c?i[e][0]:e;return o?`${s} ${u} ago`:`in ${s} ${u}`}function vh(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var yh={D:Lf,DD:Rf,DDD:Bf,DDDD:Vf,t:Hf,tt:Uf,ttt:Wf,tttt:Gf,T:Kf,TT:qf,TTT:Jf,TTTT:Yf,f:Xf,ff:Qf,fff:tp,ffff:rp,F:Zf,FF:$f,FFF:np,FFFF:ip},bh=class e{static create(t,n={}){return new e(t,n)}static parseFormat(e){let t=null,n=``,r=!1,i=[];for(let a=0;a<e.length;a++){let o=e.charAt(a);o===`'`?((n.length>0||r)&&i.push({literal:r||/^\s+$/.test(n),val:n===``?`'`:n}),t=null,n=``,r=!r):r||o===t?n+=o:(n.length>0&&i.push({literal:/^\s+$/.test(n),val:n}),n=o,t=o)}return n.length>0&&i.push({literal:r||/^\s+$/.test(n),val:n}),i}static macroTokenToFormatOpts(e){return yh[e]}constructor(e,t){this.opts=t,this.loc=e,this.systemLoc=null}formatWithSystemDefault(e,t){return this.systemLoc===null&&(this.systemLoc=this.loc.redefaultToSystem()),this.systemLoc.dtFormatter(e,{...this.opts,...t}).format()}dtFormatter(e,t={}){return this.loc.dtFormatter(e,{...this.opts,...t})}formatDateTime(e,t){return this.dtFormatter(e,t).format()}formatDateTimeParts(e,t){return this.dtFormatter(e,t).formatToParts()}formatInterval(e,t){return this.dtFormatter(e.start,t).dtf.formatRange(e.start.toJSDate(),e.end.toJSDate())}resolvedOptions(e,t){return this.dtFormatter(e,t).resolvedOptions()}num(e,t=0,n=void 0){if(this.opts.forceSimple)return Im(e,t);let r={...this.opts};return t>0&&(r.padTo=t),n&&(r.signDisplay=n),this.loc.numberFormatter(r).format(e)}formatDateTimeFromString(t,n){let r=this.loc.listingMode()===`en`,i=this.loc.outputCalendar&&this.loc.outputCalendar!==`gregory`,a=(e,n)=>this.loc.extract(t,e,n),o=e=>t.isOffsetFixed&&t.offset===0&&e.allowZ?`Z`:t.isValid?t.zone.formatOffset(t.ts,e.format):``,s=()=>r?ph(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?hh(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?mh(t,e):a(n?{weekday:e}:{weekday:e,month:`long`,day:`numeric`},`weekday`),u=n=>{let r=e.macroTokenToFormatOpts(n);return r?this.formatWithSystemDefault(t,r):n},d=e=>r?gh(t,e):a({era:e},`era`);return vh(e.parseFormat(n),e=>{switch(e){case`S`:return this.num(t.millisecond);case`u`:case`SSS`:return this.num(t.millisecond,3);case`s`:return this.num(t.second);case`ss`:return this.num(t.second,2);case`uu`:return this.num(Math.floor(t.millisecond/10),2);case`uuu`:return this.num(Math.floor(t.millisecond/100));case`m`:return this.num(t.minute);case`mm`:return this.num(t.minute,2);case`h`:return this.num(t.hour%12==0?12:t.hour%12);case`hh`:return this.num(t.hour%12==0?12:t.hour%12,2);case`H`:return this.num(t.hour);case`HH`:return this.num(t.hour,2);case`Z`:return o({format:`narrow`,allowZ:this.opts.allowZ});case`ZZ`:return o({format:`short`,allowZ:this.opts.allowZ});case`ZZZ`:return o({format:`techie`,allowZ:this.opts.allowZ});case`ZZZZ`:return t.zone.offsetName(t.ts,{format:`short`,locale:this.loc.locale});case`ZZZZZ`:return t.zone.offsetName(t.ts,{format:`long`,locale:this.loc.locale});case`z`:return t.zoneName;case`a`:return s();case`d`:return i?a({day:`numeric`},`day`):this.num(t.day);case`dd`:return i?a({day:`2-digit`},`day`):this.num(t.day,2);case`c`:return this.num(t.weekday);case`ccc`:return l(`short`,!0);case`cccc`:return l(`long`,!0);case`ccccc`:return l(`narrow`,!0);case`E`:return this.num(t.weekday);case`EEE`:return l(`short`,!1);case`EEEE`:return l(`long`,!1);case`EEEEE`:return l(`narrow`,!1);case`L`:return i?a({month:`numeric`,day:`numeric`},`month`):this.num(t.month);case`LL`:return i?a({month:`2-digit`,day:`numeric`},`month`):this.num(t.month,2);case`LLL`:return c(`short`,!0);case`LLLL`:return c(`long`,!0);case`LLLLL`:return c(`narrow`,!0);case`M`:return i?a({month:`numeric`},`month`):this.num(t.month);case`MM`:return i?a({month:`2-digit`},`month`):this.num(t.month,2);case`MMM`:return c(`short`,!1);case`MMMM`:return c(`long`,!1);case`MMMMM`:return c(`narrow`,!1);case`y`:return i?a({year:`numeric`},`year`):this.num(t.year);case`yy`:return i?a({year:`2-digit`},`year`):this.num(t.year.toString().slice(-2),2);case`yyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,4);case`yyyyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,6);case`G`:return d(`short`);case`GG`:return d(`long`);case`GGGGG`:return d(`narrow`);case`kk`:return this.num(t.weekYear.toString().slice(-2),2);case`kkkk`:return this.num(t.weekYear,4);case`W`:return this.num(t.weekNumber);case`WW`:return this.num(t.weekNumber,2);case`n`:return this.num(t.localWeekNumber);case`nn`:return this.num(t.localWeekNumber,2);case`ii`:return this.num(t.localWeekYear.toString().slice(-2),2);case`iiii`:return this.num(t.localWeekYear,4);case`o`:return this.num(t.ordinal);case`ooo`:return this.num(t.ordinal,3);case`q`:return this.num(t.quarter);case`qq`:return this.num(t.quarter,2);case`X`:return this.num(Math.floor(t.ts/1e3));case`x`:return this.num(t.ts);default:return u(e)}})}formatDurationFromString(t,n){let r=this.opts.signMode===`negativeLargestOnly`?-1:1,i=e=>{switch(e[0]){case`S`:return`milliseconds`;case`s`:return`seconds`;case`m`:return`minutes`;case`h`:return`hours`;case`d`:return`days`;case`w`:return`weeks`;case`M`:return`months`;case`y`:return`years`;default:return null}},a=(e,t)=>n=>{let a=i(n);if(a){let i=t.isNegativeDuration&&a!==t.largestUnit?r:1,o;return o=this.opts.signMode===`negativeLargestOnly`&&a!==t.largestUnit?`never`:this.opts.signMode===`all`?`always`:`auto`,this.num(e.get(a)*i,n.length,o)}else return n},o=e.parseFormat(n),s=o.reduce((e,{literal:t,val:n})=>t?e:e.concat(n),[]),c=t.shiftTo(...s.map(i).filter(e=>e));return vh(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},xh=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Sh(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Ch(...e){return t=>e.reduce(([e,n,r],i)=>{let[a,o,s]=i(t,r);return[{...e,...a},o||n,s]},[{},null,1]).slice(0,2)}function wh(e,...t){if(e==null)return[null,null];for(let[n,r]of t){let t=n.exec(e);if(t)return r(t)}return[null,null]}function Th(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Lm(t[n+i]);return[r,null,n+i]}}var Eh=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Dh=`(?:${Eh.source}?(?:\\[(${xh.source})\\])?)?`,Oh=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,kh=RegExp(`${Oh.source}${Dh}`),Ah=RegExp(`(?:[Tt]${kh.source})?`),jh=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Mh=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Nh=/(\d{4})-?(\d{3})/,Ph=Th(`weekYear`,`weekNumber`,`weekDay`),Fh=Th(`year`,`ordinal`),Ih=/(\d{4})-(\d\d)-(\d\d)/,Lh=RegExp(`${Oh.source} ?(?:${Eh.source}|(${xh.source}))?`),Rh=RegExp(`(?: ${Lh.source})?`);function zh(e,t,n){let r=e[t];return G(r)?n:Lm(r)}function Bh(e,t){return[{year:zh(e,t),month:zh(e,t+1,1),day:zh(e,t+2,1)},null,t+3]}function Vh(e,t){return[{hours:zh(e,t,0),minutes:zh(e,t+1,0),seconds:zh(e,t+2,0),milliseconds:zm(e[t+3])},null,t+4]}function Hh(e,t){let n=!e[t]&&!e[t+1],r=Ym(e[t+1],e[t+2]);return[{},n?null:Vp.instance(r),t+3]}function Uh(e,t){return[{},e[t]?mp.create(e[t]):null,t+1]}var Wh=RegExp(`^T?${Oh.source}$`),Gh=/^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;function Kh(e){let[t,n,r,i,a,o,s,c,l]=e,u=t[0]===`-`,d=c&&c[0]===`-`,f=(e,t=!1)=>e!==void 0&&(t||e&&u)?-e:e;return[{years:f(Rm(n)),months:f(Rm(r)),weeks:f(Rm(i)),days:f(Rm(a)),hours:f(Rm(o)),minutes:f(Rm(s)),seconds:f(Rm(c),c===`-0`),milliseconds:f(zm(l),d)}]}var qh={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Jh(e,t,n,r,i,a,o){let s={year:t.length===2?qm(Lm(t)):Lm(t),month:th.indexOf(n)+1,day:Lm(r),hour:Lm(i),minute:Lm(a)};return o&&(s.second=Lm(o)),e&&(s.weekday=e.length>3?ih.indexOf(e)+1:ah.indexOf(e)+1),s}var Yh=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;function Xh(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=Jh(t,i,r,n,a,o,s),p;return p=c?qh[c]:l?0:Ym(u,d),[f,new Vp(p)]}function Zh(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var Qh=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,$h=/^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,eg=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;function tg(e){let[,t,n,r,i,a,o,s]=e;return[Jh(t,i,r,n,a,o,s),Vp.utcInstance]}function ng(e){let[,t,n,r,i,a,o,s]=e;return[Jh(t,s,n,r,i,a,o),Vp.utcInstance]}var rg=Sh(jh,Ah),ig=Sh(Mh,Ah),ag=Sh(Nh,Ah),og=Sh(kh),sg=Ch(Bh,Vh,Hh,Uh),cg=Ch(Ph,Vh,Hh,Uh),lg=Ch(Fh,Vh,Hh,Uh),ug=Ch(Vh,Hh,Uh);function dg(e){return wh(e,[rg,sg],[ig,cg],[ag,lg],[og,ug])}function fg(e){return wh(Zh(e),[Yh,Xh])}function pg(e){return wh(e,[Qh,tg],[$h,tg],[eg,ng])}function mg(e){return wh(e,[Gh,Kh])}var hg=Ch(Vh);function gg(e){return wh(e,[Wh,hg])}var _g=Sh(Ih,Rh),vg=Sh(Lh),yg=Ch(Vh,Hh,Uh);function bg(e){return wh(e,[_g,sg],[vg,yg])}var xg=`Invalid Duration`,Sg={weeks:{days:7,hours:168,minutes:10080,seconds:10080*60,milliseconds:10080*60*1e3},days:{hours:24,minutes:1440,seconds:1440*60,milliseconds:1440*60*1e3},hours:{minutes:60,seconds:3600,milliseconds:3600*1e3},minutes:{seconds:60,milliseconds:60*1e3},seconds:{milliseconds:1e3}},Cg={years:{quarters:4,months:12,weeks:52,days:365,hours:365*24,minutes:365*24*60,seconds:365*24*60*60,milliseconds:365*24*60*60*1e3},quarters:{months:3,weeks:13,days:91,hours:2184,minutes:2184*60,seconds:2184*60*60,milliseconds:2184*60*60*1e3},months:{weeks:4,days:30,hours:720,minutes:720*60,seconds:720*60*60,milliseconds:720*60*60*1e3},...Sg},wg=146097/400,Tg=146097/4800,Eg={years:{quarters:4,months:12,weeks:wg/7,days:wg,hours:wg*24,minutes:wg*24*60,seconds:wg*24*60*60,milliseconds:wg*24*60*60*1e3},quarters:{months:3,weeks:wg/28,days:wg/4,hours:wg*24/4,minutes:wg*24*60/4,seconds:wg*24*60*60/4,milliseconds:wg*24*60*60*1e3/4},months:{weeks:Tg/7,days:Tg,hours:Tg*24,minutes:Tg*24*60,seconds:Tg*24*60*60,milliseconds:Tg*24*60*60*1e3},...Sg},Dg=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Og=Dg.slice(0).reverse();function kg(e,t,n=!1){return new Ng({values:n?t.values:{...e.values,...t.values||{}},loc:e.loc.clone(t.loc),conversionAccuracy:t.conversionAccuracy||e.conversionAccuracy,matrix:t.matrix||e.matrix})}function Ag(e,t){let n=t.milliseconds??0;for(let r of Og.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function jg(e,t){let n=Ag(e,t)<0?-1:1;Dg.reduceRight((r,i)=>{if(G(t[i]))return r;if(r){let a=t[r]*n,o=e[i][r],s=Math.floor(a/o);t[i]+=s*n,t[r]-=s*o*n}return i},null),Dg.reduce((n,r)=>{if(G(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Mg(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Ng=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Eg:Cg;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||zp.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 Nf(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:Zm(t,e.normalizeUnit),loc:zp.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Cm(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Nf(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=mg(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static fromISOTime(t,n){let[r]=gg(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static invalid(t,n=null){if(!t)throw new Nf(`need to specify a reason the Duration is invalid`);let r=t instanceof om?t:new om(t,n);if(am.throwOnInvalid)throw new Af(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 Mf(e);return t}static isDuration(e){return e&&e.isLuxonDuration||!1}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}toFormat(e,t={}){let n={...t,floor:t.round!==!1&&t.floor!==!1};return this.isValid?bh.create(this.loc,n).formatDurationFromString(this,e):xg}toHuman(e={}){if(!this.isValid)return xg;let t=e.showZeros!==!1,n=Dg.map(n=>{let r=this.values[n];return G(r)||r===0&&!t?null:this.loc.numberFormatter({style:`unit`,unitDisplay:`long`,...e,unit:n.slice(0,-1)}).format(r)}).filter(e=>e);return this.loc.listFormatter({type:`conjunction`,style:e.listStyle||`narrow`,...e}).format(n)}toObject(){return this.isValid?{...this.values}:{}}toISO(){if(!this.isValid)return null;let e=`P`;return this.years!==0&&(e+=this.years+`Y`),(this.months!==0||this.quarters!==0)&&(e+=this.months+this.quarters*3+`M`),this.weeks!==0&&(e+=this.weeks+`W`),this.days!==0&&(e+=this.days+`D`),(this.hours!==0||this.minutes!==0||this.seconds!==0||this.milliseconds!==0)&&(e+=`T`),this.hours!==0&&(e+=this.hours+`H`),this.minutes!==0&&(e+=this.minutes+`M`),(this.seconds!==0||this.milliseconds!==0)&&(e+=Bm(this.seconds+this.milliseconds/1e3,3)+`S`),e===`P`&&(e+=`T0S`),e}toISOTime(e={}){if(!this.isValid)return null;let t=this.toMillis();return t<0||t>=864e5?null:(e={suppressMilliseconds:!1,suppressSeconds:!1,includePrefix:!1,format:`extended`,...e,includeOffset:!1},R_.fromMillis(t,{zone:`UTC`}).toISOTime(e))}toJSON(){return this.toISO()}toString(){return this.toISO()}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Duration { values: ${JSON.stringify(this.values)} }`:`Duration { Invalid, reason: ${this.invalidReason} }`}toMillis(){return this.isValid?Ag(this.matrix,this.values):NaN}valueOf(){return this.toMillis()}plus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t),r={};for(let e of Dg)(Mm(n.values,e)||Mm(this.values,e))&&(r[e]=n.get(e)+this.get(e));return kg(this,{values:r},!0)}minus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t);return this.plus(n.negate())}mapUnits(e){if(!this.isValid)return this;let t={};for(let n of Object.keys(this.values))t[n]=Xm(e(this.values[n],n));return kg(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...Zm(t,e.normalizeUnit)};return kg(this,{values:n})}reconfigure({locale:e,numberingSystem:t,conversionAccuracy:n,matrix:r}={}){let i={loc:this.loc.clone({locale:e,numberingSystem:t}),matrix:r,conversionAccuracy:n};return kg(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return jg(this.matrix,e),kg(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Mg(this.normalize().shiftToAll().toObject());return kg(this,{values:e},!0)}shiftTo(...t){if(!this.isValid||t.length===0)return this;t=t.map(t=>e.normalizeUnit(t));let n={},r={},i=this.toObject(),a;for(let e of Dg)if(t.indexOf(e)>=0){a=e;let t=0;for(let n in r)t+=this.matrix[n][e]*r[n],r[n]=0;Cm(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Cm(i[e])&&(r[e]=i[e]);for(let e in r)r[e]!==0&&(n[a]+=e===a?r[e]:r[e]/this.matrix[a][e]);return jg(this.matrix,n),kg(this,{values:n},!0)}shiftToAll(){return this.isValid?this.shiftTo(`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`):this}negate(){if(!this.isValid)return this;let e={};for(let t of Object.keys(this.values))e[t]=this.values[t]===0?0:-this.values[t];return kg(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Mg(this.values);return kg(this,{values:e},!0)}get years(){return this.isValid?this.values.years||0:NaN}get quarters(){return this.isValid?this.values.quarters||0:NaN}get months(){return this.isValid?this.values.months||0:NaN}get weeks(){return this.isValid?this.values.weeks||0:NaN}get days(){return this.isValid?this.values.days||0:NaN}get hours(){return this.isValid?this.values.hours||0:NaN}get minutes(){return this.isValid?this.values.minutes||0:NaN}get seconds(){return this.isValid?this.values.seconds||0:NaN}get milliseconds(){return this.isValid?this.values.milliseconds||0:NaN}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}equals(e){if(!this.isValid||!e.isValid||!this.loc.equals(e.loc))return!1;function t(e,t){return e===void 0||e===0?t===void 0||t===0:e===t}for(let n of Dg)if(!t(this.values[n],e.values[n]))return!1;return!0}},Pg=`Invalid Interval`;function Fg(e,t){return!e||!e.isValid?Ig.invalid(`missing or invalid start`):!t||!t.isValid?Ig.invalid(`missing or invalid end`):t<e?Ig.invalid(`end before start`,`The end of an interval must be after its start, but you had start=${e.toISO()} and end=${t.toISO()}`):null}var Ig=class e{constructor(e){this.s=e.start,this.e=e.end,this.invalid=e.invalid||null,this.isLuxonInterval=!0}static invalid(t,n=null){if(!t)throw new Nf(`need to specify a reason the Interval is invalid`);let r=t instanceof om?t:new om(t,n);if(am.throwOnInvalid)throw new kf(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=z_(t),i=z_(n);return Fg(r,i)??new e({start:r,end:i})}static after(t,n){let r=Ng.fromDurationLike(n),i=z_(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Ng.fromDurationLike(n),i=z_(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=R_.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=R_.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Ng.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Ng.fromISO(r,n);if(t.isValid)return e.before(o,t)}}return e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static isInterval(e){return e&&e.isLuxonInterval||!1}get start(){return this.isValid?this.s:null}get end(){return this.isValid?this.e:null}get lastDateTime(){return this.isValid&&this.e?this.e.minus(1):null}get isValid(){return this.invalidReason===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}length(e=`milliseconds`){return this.isValid?this.toDuration(e).get(e):NaN}count(e=`milliseconds`,t){if(!this.isValid)return NaN;let n=this.start.startOf(e,t),r;return r=t?.useLocaleWeeks?this.end.reconfigure({locale:n.locale}):this.end,r=r.startOf(e,t),Math.floor(r.diff(n,e).get(e))+(r.valueOf()!==this.end.valueOf())}hasSame(e){return this.isValid?this.isEmpty()||this.e.minus(1).hasSame(this.s,e):!1}isEmpty(){return this.s.valueOf()===this.e.valueOf()}isAfter(e){return this.isValid?this.s>e:!1}isBefore(e){return this.isValid?this.e<=e:!1}contains(e){return this.isValid?this.s<=e&&this.e>e:!1}set({start:t,end:n}={}){return this.isValid?e.fromDateTimes(t||this.s,n||this.e):this}splitAt(...t){if(!this.isValid)return[];let n=t.map(z_).filter(e=>this.contains(e)).sort((e,t)=>e.toMillis()-t.toMillis()),r=[],{s:i}=this,a=0;for(;i<this.e;){let t=n[a]||this.e,o=+t>+this.e?this.e:t;r.push(e.fromDateTimes(i,o)),i=o,a+=1}return r}splitBy(t){let n=Ng.fromDurationLike(t);if(!this.isValid||!n.isValid||n.as(`milliseconds`)===0)return[];let{s:r}=this,i=1,a,o=[];for(;r<this.e;){let t=this.start.plus(n.mapUnits(e=>e*i));a=+t>+this.e?this.e:t,o.push(e.fromDateTimes(r,a)),r=a,i+=1}return o}divideEqually(e){return this.isValid?this.splitBy(this.length()/e).slice(0,e):[]}overlaps(e){return this.e>e.s&&this.s<e.e}abutsStart(e){return this.isValid?+this.e==+e.s:!1}abutsEnd(e){return this.isValid?+e.e==+this.s:!1}engulfs(e){return this.isValid?this.s<=e.s&&this.e>=e.e:!1}equals(e){return!this.isValid||!e.isValid?!1:this.s.equals(e.s)&&this.e.equals(e.e)}intersection(t){if(!this.isValid)return this;let n=this.s>t.s?this.s:t.s,r=this.e<t.e?this.e:t.e;return n>=r?null:e.fromDateTimes(n,r)}union(t){if(!this.isValid)return this;let n=this.s<t.s?this.s:t.s,r=this.e>t.e?this.e:t.e;return e.fromDateTimes(n,r)}static merge(e){let[t,n]=e.sort((e,t)=>e.s-t.s).reduce(([e,t],n)=>t?t.overlaps(n)||t.abutsStart(n)?[e,t.union(n)]:[e.concat([t]),n]:[e,n],[[],null]);return n&&t.push(n),t}static xor(t){let n=null,r=0,i=[],a=t.map(e=>[{time:e.s,type:`s`},{time:e.e,type:`e`}]),o=Array.prototype.concat(...a).sort((e,t)=>e.time-t.time);for(let t of o)r+=t.type===`s`?1:-1,r===1?n=t.time:(n&&+n!=+t.time&&i.push(e.fromDateTimes(n,t.time)),n=null);return e.merge(i)}difference(...t){return e.xor([this].concat(t)).map(e=>this.intersection(e)).filter(e=>e&&!e.isEmpty())}toString(){return this.isValid?`[${this.s.toISO()} – ${this.e.toISO()})`:Pg}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`:`Interval { Invalid, reason: ${this.invalidReason} }`}toLocaleString(e=Lf,t={}){return this.isValid?bh.create(this.s.loc.clone(t),e).formatInterval(this):Pg}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Pg}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Pg}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Pg}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Pg}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Ng.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Lg=class{static hasDST(e=am.defaultZone){let t=R_.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return mp.isValidZone(e)}static normalizeZone(e){return Up(e,am.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||zp.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||zp.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||zp.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||zp.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||zp.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||zp.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||zp.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return zp.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return zp.create(t,null,`gregory`).eras(e)}static features(){return{relative:Dm(),localeWeek:Om()}}};function Rg(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Ng.fromMillis(r).as(`days`))}function zg(e,t,n){let r=[[`years`,(e,t)=>t.year-e.year],[`quarters`,(e,t)=>t.quarter-e.quarter+(t.year-e.year)*4],[`months`,(e,t)=>t.month-e.month+(t.year-e.year)*12],[`weeks`,(e,t)=>{let n=Rg(e,t);return(n-n%7)/7}],[`days`,Rg]],i={},a=e,o,s;for(let[c,l]of r)n.indexOf(c)>=0&&(o=c,i[c]=l(e,t),s=a.plus(i),s>t?(i[c]--,e=a.plus(i),e>t&&(s=e,i[c]--,e=a.plus(i))):e=s);return[e,i,s,o]}function Bg(e,t,n,r){let[i,a,o,s]=zg(e,t,n),c=t-i,l=n.filter(e=>[`hours`,`minutes`,`seconds`,`milliseconds`].indexOf(e)>=0);l.length===0&&(o<t&&(o=i.plus({[s]:1})),o!==i&&(a[s]=(a[s]||0)+c/(o-i)));let u=Ng.fromObject(a,r);return l.length>0?Ng.fromMillis(c,r).shiftTo(...l).plus(u):u}var Vg=`missing Intl.DateTimeFormat.formatToParts support`;function K(e,t=e=>e){return{regex:e,deser:([e])=>t(qp(e))}}var Hg=`[ \xA0]`,Ug=new RegExp(Hg,`g`);function Wg(e){return e.replace(/\./g,`\\.?`).replace(Ug,Hg)}function Gg(e){return e.replace(/\./g,``).replace(Ug,` `).toLowerCase()}function Kg(e,t){return e===null?null:{regex:RegExp(e.map(Wg).join(`|`)),deser:([n])=>e.findIndex(e=>Gg(n)===Gg(e))+t}}function qg(e,t){return{regex:e,deser:([,e,t])=>Ym(e,t),groups:t}}function Jg(e){return{regex:e,deser:([e])=>e}}function Yg(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function Xg(e,t){let n=Xp(t),r=Xp(t,`{2}`),i=Xp(t,`{3}`),a=Xp(t,`{4}`),o=Xp(t,`{6}`),s=Xp(t,`{1,2}`),c=Xp(t,`{1,3}`),l=Xp(t,`{1,6}`),u=Xp(t,`{1,9}`),d=Xp(t,`{2,4}`),f=Xp(t,`{4,6}`),p=e=>({regex:RegExp(Yg(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return Kg(t.eras(`short`),0);case`GG`:return Kg(t.eras(`long`),0);case`y`:return K(l);case`yy`:return K(d,qm);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 Kg(t.months(`short`,!0),1);case`MMMM`:return Kg(t.months(`long`,!0),1);case`L`:return K(s);case`LL`:return K(r);case`LLL`:return Kg(t.months(`short`,!1),1);case`LLLL`:return Kg(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 Jg(u);case`uu`:return Jg(s);case`uuu`:return K(n);case`a`:return Kg(t.meridiems(),0);case`kkkk`:return K(a);case`kk`:return K(d,qm);case`W`:return K(s);case`WW`:return K(r);case`E`:case`c`:return K(n);case`EEE`:return Kg(t.weekdays(`short`,!1),1);case`EEEE`:return Kg(t.weekdays(`long`,!1),1);case`ccc`:return Kg(t.weekdays(`short`,!0),1);case`cccc`:return Kg(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return qg(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return qg(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return Jg(/[a-z_+-/]{1,256}?/i);case` `:return Jg(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:Vg};return m.token=e,m}var Zg={year:{"2-digit":`yy`,numeric:`yyyyy`},month:{numeric:`M`,"2-digit":`MM`,short:`MMM`,long:`MMMM`},day:{numeric:`d`,"2-digit":`dd`},weekday:{short:`EEE`,long:`EEEE`},dayperiod:`a`,dayPeriod:`a`,hour12:{numeric:`h`,"2-digit":`hh`},hour24:{numeric:`H`,"2-digit":`HH`},minute:{numeric:`m`,"2-digit":`mm`},second:{numeric:`s`,"2-digit":`ss`},timeZoneName:{long:`ZZZZZ`,short:`ZZZ`}};function Qg(e,t,n){let{type:r,value:i}=e;if(r===`literal`){let e=/^\s+$/.test(i);return{literal:!e,val:e?` `:i}}let a=t[r],o=r;r===`hour`&&(o=t.hour12==null?t.hourCycle==null?n.hour12?`hour12`:`hour24`:t.hourCycle===`h11`||t.hourCycle===`h12`?`hour12`:`hour24`:t.hour12?`hour12`:`hour24`);let s=Zg[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function $g(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function e_(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Mm(n,i)){let a=n[i],o=a.groups?a.groups+1:1;!a.literal&&a.token&&(e[a.token.val[0]]=a.deser(r.slice(t,t+o))),t+=o}return[r,e]}else return[r,{}]}function t_(e){let t=e=>{switch(e){case`S`:return`millisecond`;case`s`:return`second`;case`m`:return`minute`;case`h`:case`H`:return`hour`;case`d`:return`day`;case`o`:return`ordinal`;case`L`:case`M`:return`month`;case`y`:return`year`;case`E`:case`c`:return`weekday`;case`W`:return`weekNumber`;case`k`:return`weekYear`;case`q`:return`quarter`;default:return null}},n=null,r;return G(e.z)||(n=mp.create(e.z)),G(e.Z)||(n||=new Vp(e.Z),r=e.Z),G(e.q)||(e.M=(e.q-1)*3+1),G(e.h)||(e.h<12&&e.a===1?e.h+=12:e.h===12&&e.a===0&&(e.h=0)),e.G===0&&e.y&&(e.y=-e.y),G(e.u)||(e.S=zm(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var n_=null;function r_(){return n_||=R_.fromMillis(1555555555555),n_}function i_(e,t){if(e.literal)return e;let n=l_(bh.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function a_(e,t){return Array.prototype.concat(...e.map(e=>i_(e,t)))}var o_=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=a_(bh.parseFormat(t),e),this.units=this.tokens.map(t=>Xg(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=$g(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=e_(e,this.regex,this.handlers),[r,i,a]=n?t_(n):[null,null,void 0];if(Mm(n,`a`)&&Mm(n,`H`))throw new jf(`Can't include meridiem when specifying 24-hour format`);return{input:e,tokens:this.tokens,regex:this.regex,rawMatches:t,matches:n,result:r,zone:i,specificOffset:a}}else return{input:e,tokens:this.tokens,invalidReason:this.invalidReason}}get isValid(){return!this.disqualifyingUnit}get invalidReason(){return this.disqualifyingUnit?this.disqualifyingUnit.invalidReason:null}};function s_(e,t,n){return new o_(e,n).explainFromTokens(t)}function c_(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=s_(e,t,n);return[r,i,a,o]}function l_(e,t){if(!e)return null;let n=bh.create(t,e).dtFormatter(r_()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>Qg(t,e,i))}var u_=`Invalid DateTime`,d_=864e13;function f_(e){return new om(`unsupported zone`,`the zone "${e.name}" is not supported`)}function p_(e){return e.weekData===null&&(e.weekData=mm(e.c)),e.weekData}function m_(e){return e.localWeekData===null&&(e.localWeekData=mm(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function h_(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new R_({...n,...t,old:n})}function g_(e,t,n){let r=e-t*60*1e3,i=n.offset(r);if(t===i)return[r,t];r-=(i-t)*60*1e3;let a=n.offset(r);return i===a?[r,i]:[e-Math.min(i,a)*60*1e3,Math.max(i,a)]}function __(e,t){e+=t*60*1e3;let n=new Date(e);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),millisecond:n.getUTCMilliseconds()}}function v_(e,t,n){return g_(Wm(e),t,n)}function y_(e,t){let n=e.o,r=e.c.year+Math.trunc(t.years),i=e.c.month+Math.trunc(t.months)+Math.trunc(t.quarters)*3,a={...e.c,year:r,month:i,day:Math.min(e.c.day,Um(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Ng.fromObject({years:t.years-Math.trunc(t.years),quarters:t.quarters-Math.trunc(t.quarters),months:t.months-Math.trunc(t.months),weeks:t.weeks-Math.trunc(t.weeks),days:t.days-Math.trunc(t.days),hours:t.hours,minutes:t.minutes,seconds:t.seconds,milliseconds:t.milliseconds}).as(`milliseconds`),[s,c]=g_(Wm(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function b_(e,t,n,r,i,a){let{setZone:o,zone:s}=n;if(e&&Object.keys(e).length!==0||t){let r=t||s,i=R_.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return R_.invalid(new om(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function x_(e,t,n=!0){return e.isValid?bh.create(zp.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function S_(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=Im(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=Im(e.c.month),n===`month`)return i;i+=`-`}else if(i+=Im(e.c.month),n===`month`)return i;return i+=Im(e.c.day),i}function C_(e,t,n,r,i,a,o){let s=!n||e.c.millisecond!==0||e.c.second!==0,c=``;switch(o){case`day`:case`month`:case`year`:break;default:if(c+=Im(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=Im(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=Im(e.c.second))}else{if(c+=Im(e.c.minute),o===`minute`)break;s&&(c+=Im(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=Im(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=Im(Math.trunc(-e.o/60)),c+=`:`,c+=Im(Math.trunc(-e.o%60))):(c+=`+`,c+=Im(Math.trunc(e.o/60)),c+=`:`,c+=Im(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var w_={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},T_={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},E_={ordinal:1,hour:0,minute:0,second:0,millisecond:0},D_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],O_=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],k_=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function A_(e){let t={year:`year`,years:`year`,month:`month`,months:`month`,day:`day`,days:`day`,hour:`hour`,hours:`hour`,minute:`minute`,minutes:`minute`,quarter:`quarter`,quarters:`quarter`,second:`second`,seconds:`second`,millisecond:`millisecond`,milliseconds:`millisecond`,weekday:`weekday`,weekdays:`weekday`,weeknumber:`weekNumber`,weeksnumber:`weekNumber`,weeknumbers:`weekNumber`,weekyear:`weekYear`,weekyears:`weekYear`,ordinal:`ordinal`}[e.toLowerCase()];if(!t)throw new Mf(e);return t}function j_(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return A_(e)}}function M_(e){if(I_===void 0&&(I_=am.now()),e.type!==`iana`)return e.offset(I_);let t=e.name,n=L_.get(t);return n===void 0&&(n=e.offset(I_),L_.set(t,n)),n}function N_(e,t){let n=Up(t.zone,am.defaultZone);if(!n.isValid)return R_.invalid(f_(n));let r=zp.fromObject(t),i,a;if(G(e.year))i=am.now();else{for(let t of D_)G(e[t])&&(e[t]=w_[t]);let t=xm(e)||Sm(e);if(t)return R_.invalid(t);let r=M_(n);[i,a]=v_(e,r,n)}return new R_({ts:i,zone:n,loc:r,o:a})}function P_(e,t,n){let r=G(n.round)?!0:n.round,i=G(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Bm(e,r||n.calendary?0:2,n.calendary?`round`:i),t.loc.clone(n).relFormatter(n).format(e,a)),o=r=>n.calendary?t.hasSame(e,r)?0:t.startOf(r).diff(e.startOf(r),r).get(r):t.diff(e,r).get(r);if(n.unit)return a(o(n.unit),n.unit);for(let e of n.units){let t=o(e);if(Math.abs(t)>=1)return a(t,e)}return a(e>t?-0:0,n.units[n.units.length-1])}function F_(e){let t={},n;return e.length>0&&typeof e[e.length-1]==`object`?(t=e[e.length-1],n=Array.from(e).slice(0,e.length-1)):n=Array.from(e),[t,n]}var I_,L_=new Map,R_=class e{constructor(e){let t=e.zone||am.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new om(`invalid input`):null)||(t.isValid?null:f_(t));this.ts=G(e.ts)?am.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=Cm(e.o)&&!e.old?e.o:t.offset(this.ts);r=__(this.ts,a),n=Number.isNaN(r.year)?new om(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||zp.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=F_(arguments),[n,r,i,a,o,s,c]=t;return N_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=F_(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Vp.utcInstance,N_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Em(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Up(n.zone,am.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:zp.fromObject(n)}):e.invalid(f_(i))}static fromMillis(t,n={}){if(Cm(t))return t<-d_||t>d_?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Up(n.zone,am.defaultZone),loc:zp.fromObject(n)});throw new Nf(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(Cm(t))return new e({ts:t*1e3,zone:Up(n.zone,am.defaultZone),loc:zp.fromObject(n)});throw new Nf(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Up(n.zone,am.defaultZone);if(!r.isValid)return e.invalid(f_(r));let i=zp.fromObject(n),a=Zm(t,j_),{minDaysInFirstWeek:o,startOfWeek:s}=vm(a,i),c=am.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 jf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new jf(`Can't mix ordinal dates with month/day`);let h=m||a.weekday&&!p,ee,te,ne=__(c,l);h?(ee=O_,te=T_,ne=mm(ne,o,s)):u?(ee=k_,te=E_,ne=gm(ne)):(ee=D_,te=w_);let re=!1;for(let e of ee){let t=a[e];G(t)?re?a[e]=te[e]:a[e]=ne[e]:re=!0}let ie=(h?ym(a,o,s):u?bm(a):xm(a))||Sm(a);if(ie)return e.invalid(ie);let[ae,oe]=v_(h?hm(a,o,s):u?_m(a):a,l,r),se=new e({ts:ae,zone:r,o:oe,loc:i});return a.weekday&&p&&t.weekday!==se.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${se.toISO()}`):se.isValid?se:e.invalid(se.invalid)}static fromISO(e,t={}){let[n,r]=dg(e);return b_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=fg(e);return b_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=pg(e);return b_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(G(t)||G(n))throw new Nf(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=c_(zp.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):b_(o,s,r,`format ${n}`,t,c)}static fromString(t,n,r={}){return e.fromFormat(t,n,r)}static fromSQL(e,t={}){let[n,r]=bg(e);return b_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Nf(`need to specify a reason the DateTime is invalid`);let r=t instanceof om?t:new om(t,n);if(am.throwOnInvalid)throw new Of(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=l_(e,zp.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return a_(bh.parseFormat(e),zp.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){I_=void 0,L_.clear()}get(e){return this[e]}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}get outputCalendar(){return this.isValid?this.loc.outputCalendar:null}get zone(){return this._zone}get zoneName(){return this.isValid?this.zone.name:null}get year(){return this.isValid?this.c.year:NaN}get quarter(){return this.isValid?Math.ceil(this.c.month/3):NaN}get month(){return this.isValid?this.c.month:NaN}get day(){return this.isValid?this.c.day:NaN}get hour(){return this.isValid?this.c.hour:NaN}get minute(){return this.isValid?this.c.minute:NaN}get second(){return this.isValid?this.c.second:NaN}get millisecond(){return this.isValid?this.c.millisecond:NaN}get weekYear(){return this.isValid?p_(this).weekYear:NaN}get weekNumber(){return this.isValid?p_(this).weekNumber:NaN}get weekday(){return this.isValid?p_(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?m_(this).weekday:NaN}get localWeekNumber(){return this.isValid?m_(this).weekNumber:NaN}get localWeekYear(){return this.isValid?m_(this).weekYear:NaN}get ordinal(){return this.isValid?gm(this.c).ordinal:NaN}get monthShort(){return this.isValid?Lg.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Lg.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Lg.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Lg.weekdays(`long`,{locObj:this.loc})[this.weekday-1]:null}get offset(){return this.isValid?+this.o:NaN}get offsetNameShort(){return this.isValid?this.zone.offsetName(this.ts,{format:`short`,locale:this.locale}):null}get offsetNameLong(){return this.isValid?this.zone.offsetName(this.ts,{format:`long`,locale:this.locale}):null}get isOffsetFixed(){return this.isValid?this.zone.isUniversal:null}get isInDST(){return this.isOffsetFixed?!1:this.offset>this.set({month:1,day:1}).offset||this.offset>this.set({month:5}).offset}getPossibleOffsets(){if(!this.isValid||this.isOffsetFixed)return[this];let e=864e5,t=6e4,n=Wm(this.c),r=this.zone.offset(n-e),i=this.zone.offset(n+e),a=this.zone.offset(n-r*t),o=this.zone.offset(n-i*t);if(a===o)return[this];let s=n-a*t,c=n-o*t,l=__(s,a),u=__(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[h_(this,{ts:s}),h_(this,{ts:c})]:[this]}get isInLeapYear(){return Vm(this.year)}get daysInMonth(){return Um(this.year,this.month)}get daysInYear(){return this.isValid?Hm(this.year):NaN}get weeksInWeekYear(){return this.isValid?Km(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?Km(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=bh.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Vp.instance(e),t)}toLocal(){return this.setZone(am.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Up(t,am.defaultZone),t.equals(this.zone))return this;if(t.isValid){let e=this.ts;if(n||r){let n=t.offset(this.ts),r=this.toObject();[e]=v_(r,n,t)}return h_(this,{ts:e,zone:t})}else return e.invalid(f_(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return h_(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=Zm(e,j_),{minDaysInFirstWeek:n,startOfWeek:r}=vm(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 jf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new jf(`Can't mix ordinal dates with month/day`);let u;i?u=hm({...mm(this.c,n,r),...t},n,r):G(t.ordinal)?(u={...this.toObject(),...t},G(t.day)&&(u.day=Math.min(Um(u.year,u.month),u.day))):u=_m({...gm(this.c),...t});let[d,f]=v_(u,this.o,this.zone);return h_(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Ng.fromDurationLike(e);return h_(this,y_(this,t))}minus(e){if(!this.isValid)return this;let t=Ng.fromDurationLike(e).negate();return h_(this,y_(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Ng.normalizeUnit(e);switch(r){case`years`:n.month=1;case`quarters`:case`months`:n.day=1;case`weeks`:case`days`:n.hour=0;case`hours`:n.minute=0;case`minutes`:n.second=0;case`seconds`:n.millisecond=0;break}if(r===`weeks`)if(t){let e=this.loc.getStartOfWeek(),{weekday:t}=this;t<e&&(n.weekNumber=this.weekNumber-1),n.weekday=e}else n.weekday=1;return r===`quarters`&&(n.month=(Math.ceil(this.month/3)-1)*3+1),this.set(n)}endOf(e,t){return this.isValid?this.plus({[e]:1}).startOf(e,t).minus(1):this}toFormat(e,t={}){return this.isValid?bh.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):u_}toLocaleString(e=Lf,t={}){return this.isValid?bh.create(this.loc.clone(t),e).formatDateTime(this):u_}toLocaleParts(e={}){return this.isValid?bh.create(this.loc.clone(e),e).formatDateTimeParts(this):[]}toISO({format:e=`extended`,suppressSeconds:t=!1,suppressMilliseconds:n=!1,includeOffset:r=!0,extendedZone:i=!1,precision:a=`milliseconds`}={}){if(!this.isValid)return null;a=A_(a);let o=e===`extended`,s=S_(this,o,a);return D_.indexOf(a)>=3&&(s+=`T`),s+=C_(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?S_(this,e===`extended`,A_(t)):null}toISOWeekDate(){return x_(this,`kkkk-'W'WW-c`)}toISOTime({suppressMilliseconds:e=!1,suppressSeconds:t=!1,includeOffset:n=!0,includePrefix:r=!1,extendedZone:i=!1,format:a=`extended`,precision:o=`milliseconds`}={}){return this.isValid?(o=A_(o),(r&&D_.indexOf(o)>=3?`T`:``)+C_(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return x_(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return x_(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?S_(this,!0):null}toSQLTime({includeOffset:e=!0,includeZone:t=!1,includeOffsetSpace:n=!0}={}){let r=`HH:mm:ss.SSS`;return(t||e)&&(n&&(r+=` `),t?r+=`z`:e&&(r+=`ZZ`)),x_(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():u_}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`:`DateTime { Invalid, reason: ${this.invalidReason} }`}valueOf(){return this.toMillis()}toMillis(){return this.isValid?this.ts:NaN}toSeconds(){return this.isValid?this.ts/1e3:NaN}toUnixInteger(){return this.isValid?Math.floor(this.ts/1e3):NaN}toJSON(){return this.toISO()}toBSON(){return this.toJSDate()}toObject(e={}){if(!this.isValid)return{};let t={...this.c};return e.includeConfig&&(t.outputCalendar=this.outputCalendar,t.numberingSystem=this.loc.numberingSystem,t.locale=this.loc.locale),t}toJSDate(){return new Date(this.isValid?this.ts:NaN)}diff(e,t=`milliseconds`,n={}){if(!this.isValid||!e.isValid)return Ng.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=km(t).map(Ng.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Bg(a?this:e,a?e:this,i,r);return a?o.negate():o}diffNow(t=`milliseconds`,n={}){return this.diff(e.now(),t,n)}until(e){return this.isValid?Ig.fromDateTimes(this,e):this}hasSame(e,t,n){if(!this.isValid)return!1;let r=e.valueOf(),i=this.setZone(e.zone,{keepLocalTime:!0});return i.startOf(t,n)<=r&&r<=i.endOf(t,n)}equals(e){return this.isValid&&e.isValid&&this.valueOf()===e.valueOf()&&this.zone.equals(e.zone)&&this.loc.equals(e.loc)}toRelative(t={}){if(!this.isValid)return null;let n=t.base||e.fromObject({},{zone:this.zone}),r=t.padding?this<n?-t.padding:t.padding:0,i=[`years`,`months`,`days`,`hours`,`minutes`,`seconds`],a=t.unit;return Array.isArray(t.unit)&&(i=t.unit,a=void 0),P_(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?P_(t.base||e.fromObject({},{zone:this.zone}),this,{...t,numeric:`auto`,units:[`years`,`months`,`days`],calendary:!0}):null}static min(...t){if(!t.every(e.isDateTime))throw new Nf(`min requires all arguments be DateTimes`);return Am(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Nf(`max requires all arguments be DateTimes`);return Am(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return s_(zp.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new o_(zp.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(G(t)||G(n))throw new Nf(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=zp.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Nf(`fromFormatParser called with a locale of ${o}, but the format parser was created for ${n.locale}`);let{result:s,zone:c,specificOffset:l,invalidReason:u}=n.explainFromTokens(t);return u?e.invalid(u):b_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Lf}static get DATE_MED(){return Rf}static get DATE_MED_WITH_WEEKDAY(){return zf}static get DATE_FULL(){return Bf}static get DATE_HUGE(){return Vf}static get TIME_SIMPLE(){return Hf}static get TIME_WITH_SECONDS(){return Uf}static get TIME_WITH_SHORT_OFFSET(){return Wf}static get TIME_WITH_LONG_OFFSET(){return Gf}static get TIME_24_SIMPLE(){return Kf}static get TIME_24_WITH_SECONDS(){return qf}static get TIME_24_WITH_SHORT_OFFSET(){return Jf}static get TIME_24_WITH_LONG_OFFSET(){return Yf}static get DATETIME_SHORT(){return Xf}static get DATETIME_SHORT_WITH_SECONDS(){return Zf}static get DATETIME_MED(){return Qf}static get DATETIME_MED_WITH_SECONDS(){return $f}static get DATETIME_MED_WITH_WEEKDAY(){return ep}static get DATETIME_FULL(){return tp}static get DATETIME_FULL_WITH_SECONDS(){return np}static get DATETIME_HUGE(){return rp}static get DATETIME_HUGE_WITH_SECONDS(){return ip}};function z_(e){if(R_.isDateTime(e))return e;if(e&&e.valueOf&&Cm(e.valueOf()))return R_.fromJSDate(e);if(e&&typeof e==`object`)return R_.fromObject(e);throw new Nf(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function B_(e){return $l(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof hd}function V_(e){return A(e)===``}function H_(e){return e instanceof sd}function U_(e){let t=bu(e);if(t!==null)return t;if(Jl(e)&&e instanceof R&&e.expression){let t=e.op?.value,n=bu(e.expression);if(n!==null)return t===`-`?-n:n}return null}function W_(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=U_(e);if(t!==null)return t;let n=A(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function G_(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=U_(e);if(t!==null)return Number.isInteger(t)?t:null;let n=A(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}const K_=[`true`,`yes`,`y`,`t`,`1`],q_=[`false`,`no`,`n`,`f`,`0`];function J_(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 K_.includes(t)?!0:q_.includes(t)?!1:null}if($l(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=bu(e);if(t===0)return!1;if(t===1)return!0;let n=A(e)?.toLowerCase();if(n){if(K_.includes(n))return!0;if(q_.includes(n))return!1}return null}function Y_(e){if(e==null)return null;if(typeof e==`string`)return e;let t=k(e);return t?_(t):A(e)??null}function X_(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=A(e)??null??W_(e)??J_(e);return t===null?null:t.toString()}var Z_=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Q_=[`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`],$_=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function ev(e){if(e==null)return null;let t=typeof e==`string`?e:A(e)??null;if(t===null)return null;for(let e of $_){let n=R_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of Z_){let n=R_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Q_){let n=R_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=R_.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 tv(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 nv(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function rv(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 iv(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 av(e){return e.increment||Tf(e.typeName)}function ov(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function sv(e,t,n){return n.length===1?ov(e,t,n[0]):`(${n.map(n=>ov(e,t,n)).join(`, `)})`}function cv(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function lv(e,t,n){let{token:r}=t,i=e.nodeAtPosition(r.filepath,r.start.offset)??e.parse.ast(r.filepath);return new Fl(x.INVALID_RECORDS_FIELD,n,i)}var uv=e=>e>1?`Composite PK`:`PK`;function dv(e,t,n,r){if(jc(r.values))return[];let i=t.mergedColumns(e).map(t=>tv(t,e)),a=Nc(i,`name`),o=nv(r),s=gv(t,i,e),c=new Set(r.columns);return xc(s,i=>fv(e,t,n,i,o,c,a,r))}function fv(e,t,n,r,i,a,o,s){let c=t.schema(e),l=t.name??``,u=hv(n,r,a,o,c,l,s);if(!jc(u))return u;let d=ao(r.map(e=>o[e])),f=d.every(e=>e&&av(e)),[p,m]=v(i,e=>iv(e,r,d)),h=f?[]:pv(e,p,r,c,l),ee=mv(e,m,r,d,c,l);return[...h,...ee]}function pv(e,t,n,r,i){if(jc(t))return[];let a=`NULL in ${uv(n.length)}: ${sv(r,i,n)} cannot be NULL`;return xc(t,t=>n.map(n=>lv(e,t[n],a)))}function mv(e,t,n,r,i,a){return xc(lc(Ec(t,e=>rv(e,n,r)),e=>e.length>1),t=>{let r=uv(n.length),o=sv(i,a,n);return xc(t,t=>{let i=`Duplicate ${r}: ${o} = ${cv(t,n)}`;return n.map(n=>lv(e,t[n],i))})})}function hv(e,t,n,r,i,a,o){let s=nc(t,Array.from(n));if(jc(s))return[];let c=s.filter(e=>{let t=r[e];return!!(t&&!av(t)&&!t.dbdefault)});if(jc(c))return[];let l=`${uv(c.length)}: Column ${sv(i,a,c)} is missing from record and has no default value`;return o.values.map(()=>new Fl(x.INVALID_RECORDS_FIELD,l,e))}function gv(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 _v=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function vv(e,t,n){if(jc(n.values))return[];let r=t.mergedColumns(e).map(t=>tv(t,e)),i=Nc(r,`name`),a=nv(n),o=t.schema(e),s=t.name??``;return xc(yv(t,r,e),t=>bv(e,a,t,ao(t.map(e=>i[e])),o,s))}function yv(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 bv(e,t,n,r,i,a){return xc(lc(Ec(t.filter(e=>!iv(e,n,r)),e=>rv(e,n,r)),e=>e.length>1),t=>{let r=_v(n.length),o=sv(i,a,n);return xc(t,t=>{let i=`Duplicate ${r}: ${o} = ${cv(t,n)}`;return n.map(n=>lv(e,t[n],i))})})}function xv(e,t,n,r){return xc(t,t=>wv(e,t,n,r))}function Sv(e,t,n,r,i,a){if(!t.record||jc(t.record.values))return[];let o=nv(t.record),s=n.record?nv(n.record):[],c=new Set(s.map(e=>rv(e,i.fieldNames))),l=o.filter(e=>!iv(e,r.fieldNames)).filter(e=>{let t=rv(e,r.fieldNames);return!c.has(t)}),u=t.tableSymbol.interpretedName(e,a),d=n.tableSymbol.interpretedName(e,a);return xc(l,t=>{let n=sv(u.schema,u.name,r.fieldNames),a=sv(d.schema,d.name,i.fieldNames),o=`FK violation: ${n} = ${cv(t,r.fieldNames)} does not exist in ${a}`;return r.fieldNames.map(n=>lv(e,t[n],o))})}function Cv(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 wv(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=Cv(n,i,e,r),s=Cv(n,a,e,r);return!o||!s?[]:Tv(e,o,s,i,a,r)}function Tv(e,t,n,r,i,a){let o=r.relation,s=i.relation;return o===`1`&&s===`1`||o===`*`&&s===`*`?[...Sv(e,t,n,r,i,a),...Sv(e,n,t,i,r,a)]:o===`*`&&s===`1`?Sv(e,t,n,r,i,a):o===`1`&&s===`*`?Sv(e,n,t,i,r,a):[]}var Ev=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:M(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 Zu)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 Nu);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Nu){n.push(t);continue}if(!(t instanceof Zu))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 Iu?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Iu?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}]};lf(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 wd))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 vd.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 S(x.SAME_ENDPOINT,`Ref with same endpoints already exists`,i.declaration));break}n.add(e)}this.db.refs.push(e);break}case vd.Records:if(i instanceof wd){let e=i.table(this.compiler)?.originalSymbol.intern()??``,t=e?r.get(e):void 0;if(t&&t.count>1){this.errors.push(new S(x.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 vd.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 Xu)||!t.isKind(N.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:Wd.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 Nu))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(N.Table))continue;let t=e.originalSymbol;if(!(t instanceof Iu))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 wd))continue;let i=r.table(this.compiler);if(!(i instanceof Iu))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...dv(this.compiler,i,r.declaration,o)),e.push(...vv(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(...xv(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof xd),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 Qu&&t.declaration===e.declaration)))continue;let l=Bd(s);if(!l)continue;let u=a instanceof Vu&&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:M(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:M(i.rightToken())};n.push({token:M(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case N.Table:this.db.tables.push(t);break;case N.Enum:this.db.enums.push(t);break;case N.TableGroup:this.db.tableGroups.push(t);break;case N.TablePartial:this.db.tablePartials.push(t);break;case N.StickyNote:this.db.notes.push(t);break;case N.DiagramView:this.db.diagramViews.push(t);break;default:break}}};const Dv={nodeSymbol(t,r){return ru(r)?n.create(t.symbolFactory.create(Yu,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(N.Program))return n.create(e);if(!(i.declaration instanceof ed))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(b);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(N.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return ru(r)?new sf(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){return r instanceof Yu?r.declaration instanceof ed?Ld(t,r.declaration)?new Ev(t,r,i).interpret():n.create(void 0,[...t.validateNode(r.declaration).getErrors(),...t.bindNode(r.declaration).getErrors()]):n.create(void 0):n.create(e)}};var Ov=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof z)return[];let t=e.body.filter(e=>e instanceof I);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},kv=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=M(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}=Eu(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.type?.value.toLowerCase()){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 B?t.body.body[0]?.callee:t.body?.callee,n=e?A(e):void 0;return n&&(this.project.note={value:Tu(n),token:M(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()]=A(t.body.callee),[]}})}};const Av={nodeMetadata(t,i){return D(i,r.Project)?n.create(new Td(i)):n.create(e)},bindNode(t,i){return D(i,r.Project)?n.create(void 0,new Ov(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Td)||!(r.declaration instanceof I)?n.create(e):new kv(t,r.declaration,i).interpret()}};var jv=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 B&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof ed?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=xu(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=mu(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=Su(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new S(x.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new S(x.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new S(x.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 I)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Xl(e))return[];let i=mu(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=Su(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new S(x.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n));continue}}return a}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof z),n=e.body.filter(e=>e instanceof I);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof ld?e.callee.elementList:[e.callee]).flatMap(Rd).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():[])}},Mv=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Nv(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=Pv(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=M(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 Nv(e,n,i){let a=e.name,o=e.parent;if(o instanceof I&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Iu))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===j(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=xu(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,N.Schema,u);e&&(p=n.lookupMembers(e,N.Table,l))}if(p||=n.lookupMembers(f,N.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Iu))return;let h=m.mergedColumns(n),ee=s.args.map(e=>h.find(t=>t.name===j(e))).filter(Boolean),te=m.interpretedName(n,i);return{schemaName:te.schema,tableName:te.name,columns:ee}}function Pv(e,t,r){let i=[],a=[],o={},s=e.callee instanceof ld?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new S(x.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=Iv(n,l,r);i.push(...u.getErrors()),a.push(...u.getWarnings());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:M(n)})}return new n({row:c,columnNodes:o},i,a)}function Fv(e){return e instanceof sd&&e.value?.value||``}function Iv(e,t,r){let i=M(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=Ef(o,s),p=X_(e),m=p===null?Fv(e):p,h=p===null?`expression`:f;if(e instanceof sd)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(B_(e)||V_(e)&&!Sf(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Tf(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[new Fl(x.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(N.EnumField)).map(e=>e.name).filter(Boolean):[],s=A(e);return s===void 0&&(s=T(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 Fl(x.INVALID_RECORDS_FIELD,`Invalid enum value for column '${d}'`,e)])}if(vf(o)||yf(o)||Tf(o)){let t=U_(e);if(t===null)return new n({value:m,type:h,token:i},[],[new Fl(x.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${d}'`,e)]);if(vf(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[new Fl(x.INVALID_RECORDS_FIELD,`Invalid integer value ${t} for column '${d}': expected integer, got decimal`,e)]);let r=yf(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(yf(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 Fl(x.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 Fl(x.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(xf(o)){let t=J_(e);return t===null?new n({value:m,type:h,token:i},[],[new Fl(x.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${d}'`,e)]):new n({value:t,type:f,token:i},[],[])}if(wf(o)){let t=ev(e);return t===null?new n({value:m,type:h,token:i},[],[new Fl(x.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(Sf(o)){let t=X_(e);if(t===null)return new n({value:m,type:h,token:i},[],[new Fl(x.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 Fl(x.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:h,token:i},[],[])}const Lv={nodeMetadata(t,i){if(!D(i,r.Records))return n.create(e);let a=i.parent;if(a&&D(a,r.Table))return n.create(new wd(i));let o=i.name;return o instanceof H&&o.callee?n.create(new wd(i)):n.create(e)},nodeReferee(i,a){if(!T(a))return n.create(e);let o=a.parentOfKind(I);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(cd);if(l?.parentNode===o)return Rv(i,o,a);let u=a.parentOfKind(H);return u?.parentNode===o&&l?.parentNode===u?zv(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?Bv(i,c,a):Hv(i,c,a)},bindNode(t,i){return D(i,r.Records)?n.create(void 0,new jv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof wd?r.declaration instanceof I?new Mv(t,r,i).interpret():n.create(void 0):n.create(e)}};function Rv(e,i,a){let o=i.parent;if(o instanceof I&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return Vv(e,n,a)}return new n(void 0)}function zv(e,r,i){if(r.callee){let n;if(T(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=_u(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return Vv(e,n,i)}return new n(void 0)}function Bv(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode)){let a=e.lookupMembers(t,[N.Table,N.Schema],i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=zd(e,r);if(!a){let a=e.lookupMembers(t,[N.Table,N.Schema],i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Table,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function Vv(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``,a=e.lookupMembers(t,N.Column,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function Hv(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return new n(void 0);let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Enum,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(N.Enum)){let t=e.lookupMembers(a,N.EnumField,i);return t?n.create(t):new n(void 0,[new S(x.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(E(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,N.Enum,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var Uv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof ed)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Rd).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():[])}},Wv=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=M(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()];return n.create(this.ref,e)}interpretName(){if(!(this.declarationNode instanceof I))return[];let e=[],t=k(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new S(x.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(Jc(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new S(x.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=Bd(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=M(this.metadata.leftToken()),l=M(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof I?[{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 I))return[];let u=gu(this.declarationNode)[0];if(u.args[0]){let e=C(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof id?pu(t):j(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof id?pu(n):j(n),this.ref.color=e.color?.length?Du(e.color?.at(0)?.value):void 0}return[]}};function Gv(e){let t=e.parent;for(;t;){if(t instanceof I&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}const Kv={nodeReferee(r,i){if(!T(i)&&!E(i)||!Gv(i)||i.parentOfKind(L))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):Jv(r,o,i)},nodeMetadata(t,a){if(D(a,r.Ref)){let t=gu(a)[0];if(!(t instanceof z)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof ad)||!r.op?n.create(e):n.create(new bd(a))}if(a instanceof L){if(!(a.name instanceof id)||pu(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof I&&t.isKind(r.TablePartial)?n.create(new xd(a)):n.create(new bd(a))}return n.create(e)},bindNode(t,i){return D(i,r.Ref)?n.create(void 0,new Uv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof bd?new Wv(t,r,i).interpret():n.create(e)}};function qv(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Nu&&e.isPublicSchema())}function Jv(e,r,i){if(!T(i))return new n(void 0);let a=Su(i)??``;if(!E(i.parentNode)){let r=i.parentNode;if(r&&E(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=E(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(N.Table)){let r=e.lookupMembers(c,N.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 S(x.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=zd(e,i);if(o){if(o.isKind(N.Schema)){let t=e.lookupMembers(o,[N.Table,N.Schema],a);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(N.Table)){let r=e.lookupMembers(o,N.Column,a);return r?n.create(r):new n(void 0,[new S(x.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(E(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,N.Schema,a);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=qv(e,r);if(t){let r=e.lookupMembers(t,N.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,N.Table,a);return o?n.create(o):new n(void 0,[new S(x.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}const Yv={visibleName(e,n){let r=n instanceof P?n:n.useSpecifierDeclaration instanceof nd?n.useSpecifierDeclaration:n.declaration;if(r instanceof nd&&n instanceof Mu&&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)}},Xv={nodeSymbol(r,i){if(!nu(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===N.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(Zu,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:Yv.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new S(x.BINDING_ERROR,`Failed to resolve the import of ${a} '${(k(i.name)||[]).map(gy).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof Zu))return n.create(e);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!T(i)&&!eu(i))return n.create(e);let a=i.parentOfKind(nd);if(!a)return n.create(e);let o=a.name===i||E(a.name)&&a.name.rightExpression===i?a.getSymbolKind():N.Schema;if(o===void 0)return n.create(void 0);let s=k(i.parentOfKind(ad)),c=j(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(td);if(l?.importPath?.value===void 0)return n.create(void 0);let u=Al(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new S(x.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new S(x.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toString()}. Does the file exist?`,i)]);let d=i.parentOfKind(ad)?.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 S(x.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=Zv(r,u,c,o);return f?n.create(f):n.create(void 0,[new S(x.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toString()}`,i)])},bindNode(t,r){if(tu(r)){let e=[];if(r.importPath?.value){let n=Al(r.filepath,r.importPath.value);n?t.layout.exists(n)||e.push(new S(x.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath)):e.push(new S(x.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 rd?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):nu(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 Zu))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 Zv(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);if(s?.isKind(i))return s;let c=o.schemaMembers.find(e=>e.name===r);if(c?.isKind(N.Schema))return c;for(let t of o.reuses.selective)if(k(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(td);if(o?.importPath?.value){let s=Zv(e,Al(n,o.importPath.value),k(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=Zv(e,t,r,i,a);if(n)return n}}function Qv(e){if(e instanceof kl){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=ey(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof Yu?ty(this,e,i):ny(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 $v(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof nd?Yv.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof nd&&r.getSymbolKind()===N.Schema?a:a.length<=1?[b]: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 ey(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof td)||!e.specifiers||!e.importPath)continue;let n=Al(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof fd?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof fd?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 ty(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[b,e.symbolFactory.create(Nu,{name:b},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?b:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Nu,{name:i},s))}ry(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of ay(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Nu,{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 ny(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof I))continue;let i=$v(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(Xu,{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(Nu,{name:i.schemaName,parent:n},n.filepath))}iy(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of oy(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Nu,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function ry(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==N.Schema)continue;let t=Yv.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Nu,{name:t},r))}}function iy(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==N.Schema)continue;let t=Yv.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(Nu,{name:o,parent:n},n.filepath))}}function ay(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?b:r[0];i.push(a)}let a=ey(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==N.Schema)continue;let n=Yv.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function oy(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?[b]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=ey(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==N.Schema)continue;let n=Yv.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var sy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);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(_(n)instanceof V){let e=C(_(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=>!Wl(e.callee)))}tryToBindColumnType(e){let t=vu(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(w(e))return[];if(T(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&jl.includes(t))return[]}let t=vu(e);if(!t){if(E(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 Rd(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():[])}},cy=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??M(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}=Eu(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new S(x.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=Su(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=C(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Du(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Tu(A(n?.value)),token:M(n)},[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof z);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case r.Note:return this.table.note={value:Tu(A(e.body instanceof B?e.body.body[0].callee:e.body.callee)),token:M(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:M(e)};i.name=j(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),i=n?(this.compiler.symbolUses(n).getFiltered(t)??[]).find(e=>e.filepath.equals(this.filepath)):void 0;r.push(new S(x.UNSUPPORTED,`Import TablePartial from '${a.filepath}' first. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,i?.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(N.Column)).length?[]:[new S(x.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Wl(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=Su(e.callee),r.token=M(e);let o=ku(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:M(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 ly={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new S(x.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new S(x.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},uy={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return D(a,r.Table)?new n(i.symbolFactory.create(Iu,{declaration:a,name:o},a.filepath)):O(a,r.Table)?Wl(a.callee)?new n(i.symbolFactory.create(Hu,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Lu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(N.Table))return n.create(e);let a=i.declaration;if(!(a instanceof I))return new n([]);let o=gu(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(N.Column,N.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof I&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(N.Column)?(c.push(ly.getColumnDuplicateError(e.name,r)),c.push(ly.getColumnDuplicateError(e.name,n))):(c.push(ly.getPartialInjectionDuplicateError(e.name,r)),c.push(ly.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 z)||!Wl(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=j(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new S(x.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(Qu,{kind:N.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(N.Column)&&!(e instanceof Qu)).map(e=>e.name));return new n(Uc([...s.filter(e=>!(e instanceof Qu&&d.has(e.name)))].reverse(),e=>e.isKind(N.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(!iu(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):T(o)&&o.parentNode instanceof R&&o.parentNode.op?.value===`~`?dy(a,c,o):au(o,1)?fy(a,c,o):su(o,i.Ref)?py(a,c,o):au(o,0)?n.create(e):my(a,c,o)},bindNode(i,a){if(!D(a,r.Table))return n.create(e);let o=new sy(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 Iu?r.declaration instanceof I?new cy(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function dy(e,r,i){let a=j(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Nu&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,N.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,N.TablePartial,a);return s?n.create(s):new n(void 0,[new S(x.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function fy(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return n.create(e.lookupMembers(t,N.Enum,i));let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=du(r),o=e.lookupMembers(a,t?N.Enum:N.Schema,i);return o?n.create(o):new n(void 0,[new S(x.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,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function py(e,i,a){if(!T(a))return new n(void 0);let o=Su(a)??``;if(!E(a.parentNode)){let s=a.parent,c=s instanceof I&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,N.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,N.Column,o);return l?n.create(l):new n(void 0,[new S(x.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}let s=zd(e,a);if(s){if(s.isKind(N.Schema)){let t=e.lookupMembers(s,[N.Table,N.Schema],o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(N.Table)){let t=e.lookupMembers(s,N.Column,o);return t?n.create(t):new n(void 0,[new S(x.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(E(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,N.Schema,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,N.Table,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function my(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return jl.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,N.Enum,i));let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Enum,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(N.Enum)){let t=e.lookupMembers(a,N.EnumField,i);return t?n.create(t):new n(void 0,[new S(x.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(E(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,N.Enum,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function hy(e){return e?e.split(``).every(e=>Il(e)||Ll(e))&&!Ll(e[0]):!1}function gy(e){return hy(e)?e:`"${vy(e)}"`}function _y(e){let t=``,n=0,r={n:`
|
|
4
|
+
`)}function Eu(e){let t=k(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function Du(e){if(e instanceof md&&e.expression instanceof dd&&e.expression.literal?.kind===y.COLOR_LITERAL)return e.expression.literal.value}function Ou(e){if(e){if(w(e)){let t=A(e);if(t!==void 0)return{value:t,type:`string`}}if(Jl(e))return{type:`number`,value:wu(e)};if($l(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof sd&&e.value)return{value:e.value.value,type:`expression`};if(eu(e)){let t=_u(e)?.at(-1),n=t?j(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function ku(e,t){let r=``,i=null;if(t instanceof H){if(i=(t.argumentList?.elementList??[]).map(e=>Jl(e)?Cu(e):w(e)?A(e):j(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof H||t instanceof gd;)if(t instanceof H){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Jl(e)?Cu(e):w(e)?A(e):j(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof gd){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}=Eu(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new S(x.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}let N=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 Au={Table:N.Table,Enum:N.Enum,TableGroup:N.TableGroup,TablePartial:N.TablePartial,Note:N.StickyNote,Schema:N.Schema};var ju=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Mu=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 M(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()}},Nu=class e extends Mu{constructor({name:e,parent:t},n,r){super({kind:N.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(`.`)===b}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}},Pu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.Enum,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Fu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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=Tu(A(i));if(a)return{value:a,token:M(r)}}},Iu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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 Qu))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(N.Column))}partialInjections(e){return this.members(e).filter(e=>e.isKind(N.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=Tu(A(i));if(a)return{value:a,token:M(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?Du(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===vd.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===vd.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===vd.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===vd.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof z)||!Wl(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===vd.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===vd.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=Du(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=Tu(A(a));if(o)return{value:o,token:M(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Lu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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 Ou(n)}type(e){if(!(this.declaration instanceof z))return;let n=ku(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 Pu?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===vd.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=Tu(A(i));if(a)return{value:a,token:M(r)}}},Ru=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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(N.TableGroupField))}color(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.color?.length?Du(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=Tu(A(i));if(a)return{value:a,token:M(r)}}},zu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.TableGroupField,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Bu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.StickyNote,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Vu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.TablePartial,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Hu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.PartialInjection,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Uu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramView,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Wu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewTopLevelWildcard,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Gu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewTable,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Ku=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewTableGroup,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},qu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewNote,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Ju=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.DiagramViewSchema,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Yu=class extends Mu{constructor({declaration:e,name:t},n,r){super({kind:N.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 Nu&&r.inNestedSchema(e,t))return!0;return!1}},Xu=class extends Mu{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}},Zu=class extends Mu{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(td);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},Qu=class extends Lu{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},$u=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},P=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 Qc?rl(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 Qc?nl(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 I||e instanceof ed)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 F=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 ed=class extends P{constructor({body:e=[],eof:t,source:n},r,i){super(r,F.PROGRAM,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===F.ELEMENT_DECLARATION)}get uses(){return this.body.filter(e=>e.kind===F.USE_DECLARATION)}},td=class extends P{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,F.USE_DECLARATION,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return cl(this.useKeyword)}},nd=class extends P{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,F.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(N).find(t=>t.toLowerCase()===e)}},rd=class extends P{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,F.USE_SPECIFIER_LIST,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},I=class e extends P{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,F.ELEMENT_DECLARATION,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof z||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))}},id=class extends P{constructor({identifiers:e=[]},t,n){super(t,F.IDENTIFIER_STREAM,n,e||[]),this.identifiers=e}},L=class extends P{constructor({name:e,colon:t,value:n},r,i){super(r,F.ATTRIBUTE,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},R=class extends P{constructor({op:e,expression:t},n,r){super(n,F.PREFIX_EXPRESSION,r,[e,t]),this.op=e,this.expression=t}},ad=class extends P{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,F.INFIX_EXPRESSION,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},od=class extends P{constructor({op:e,expression:t},n,r){super(n,F.POSTFIX_EXPRESSION,r,[t,e]),this.op=e,this.expression=t}},sd=class extends P{constructor({value:e},t,n){super(t,F.FUNCTION_EXPRESSION,n,[e]),this.value=e}},z=class extends P{constructor({callee:e,args:t=[]},n,r){super(n,F.FUNCTION_APPLICATION,r,[e,...t]),this.callee=e,this.args=t}},B=class extends P{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,F.BLOCK_EXPRESSION,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},V=class extends P{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,F.LIST_EXPRESSION,a,[e,..._d(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},cd=class extends P{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,F.TUPLE_EXPRESSION,a,[e,..._d(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},ld=class extends P{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,F.COMMA_EXPRESSION,r,[..._d(e,t)]),this.elementList=e,this.commaList=t}},ud=class extends cd{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=F.GROUP_EXPRESSION}},H=class extends P{constructor({callee:e,argumentList:t},n,r){super(n,F.CALL_EXPRESSION,r,[e,t]),this.callee=e,this.argumentList=t}},dd=class extends P{constructor({literal:e},t,n){super(t,F.LITERAL,n,[e]),this.literal=e}},fd=class extends P{constructor({token:e},t,n){super(t,F.WILDCARD,n,[e]),this.token=e}},pd=class extends P{constructor({variable:e},t,n){super(t,F.VARIABLE,n,[e]),this.variable=e}},md=class extends P{constructor({expression:e},t,n){super(t,F.PRIMARY_EXPRESSION,n,[e]),this.expression=e}},hd=class extends P{constructor({prevToken:e},t,n){let r=Qc.create(y.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,F.EMPTY,n,[r])}},gd=class extends P{constructor({expression:e,indexer:t},n,r){super(n,F.ARRAY,r,[e,t]),this.array=e,this.indexer=t}};function _d(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?da(Jc(e,t)):da(Jc(t,e))).filter(e=>e!==null)}let vd=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 yd=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}`}},bd=class extends yd{constructor(e){super(e),this.kind=vd.Ref}container(e){let n=this.declaration.parentOfKind(I);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof I){let t=gu(this.declaration)[0];if(!(t instanceof z))return[];let n=t.callee;return n instanceof ad?Ed(e,n.leftExpression):[]}if(this.declaration instanceof L){let n=this.declaration.parentOfKind(z);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof I){let t=gu(this.declaration)[0];if(!(t instanceof z))return[];let n=t.callee;return n instanceof ad?Ed(e,n.rightExpression):[]}if(this.declaration instanceof L){let t=this.declaration.value;return t instanceof R?Ed(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof I){let t=gu(this.declaration)[0];if(!(t instanceof z))return;let n=t.callee;return n instanceof ad?Dd(e,n.leftExpression):void 0}if(this.declaration instanceof L)return this.container(e)}rightTable(e){if(this.declaration instanceof I){let t=gu(this.declaration)[0];if(!(t instanceof z))return;let n=t.callee;return n instanceof ad?Dd(e,n.rightExpression):void 0}if(this.declaration instanceof L){let t=this.declaration.value;return t instanceof R?Dd(e,t.expression)??this.container(e):void 0}}op(e){if(this.declaration instanceof I){let e=gu(this.declaration)[0];if(!(e instanceof z))return;let t=e.callee;return t instanceof ad?t.op?.value:void 0}if(this.declaration instanceof L){let e=this.declaration.value;return e instanceof R?e.op?.value:void 0}}leftToken(){if(this.declaration instanceof I){let e=gu(this.declaration)[0];if(e instanceof z){let t=e.callee;if(t instanceof ad&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof L){let e=this.declaration.parentOfKind(z);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof I){let e=gu(this.declaration)[0];if(e instanceof z){let t=e.callee;if(t instanceof ad&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof L,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))}},xd=class extends yd{constructor(e){super(e),this.kind=vd.PartialRef}container(e){let n=this.declaration.parentOfKind(I);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof L))return[];let n=this.declaration.parentOfKind(z);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof L))return[];let t=this.declaration.value;return t instanceof R?Ed(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof L)return this.container(e)}rightTable(e){if(!(this.declaration instanceof L))return;let t=this.declaration.value;if(t instanceof R)return Dd(e,t.expression)??this.container(e)}op(e){if(!(this.declaration instanceof L))return;let t=this.declaration.value;if(t instanceof R)return t.op?.value}leftToken(){if(this.declaration instanceof L){let e=this.declaration.parentOfKind(z);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof L,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))}},Sd=class extends yd{constructor(e){super(e),this.kind=vd.TableChecks,this.ownerTable=e.parentNode?.parentOfKind(I)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Cd=class extends yd{constructor(e){super(e),this.kind=vd.Indexes,this.ownerTable=e.parentNode?.parentOfKind(I)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},wd=class extends yd{constructor(e){super(e),this.kind=vd.Records}table(e){let n=this.declaration,i=n.parent;if(i instanceof I&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof H))return;let o=xu(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)):[]}},Td=class extends yd{constructor(e){super(e),this.kind=vd.Project}owners(e){let n=this.declaration.filepath,r=e.parseFile(n).getValue().ast,i=e.nodeSymbol(r).getFiltered(t);return i?[i]:[]}};function Ed(e,n){if(!n)return[];let r=vu(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 Dd(e,n){if(!n)return;let r=vu(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 Od=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},kd=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof B?new n(e.body.flatMap(e=>{if(!(e instanceof z))return[];let t=M(e),n=e.callee instanceof sd?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof V);return a&&(r=A(C(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}};const Ad={nodeMetadata(t,i){if(D(i,r.Checks)){let t=i.parent;return!t||!D(t,r.Table)&&!D(t,r.TablePartial)?n.create(e):n.create(new Sd(i))}return n.create(e)},bindNode(t,i){return D(i,r.Checks)?n.create(void 0,new Od(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===vd.TableChecks?r.declaration instanceof I?new kd(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function jd(e,t,n){let r=t,i=e;if(i instanceof H&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!$l(i)||r.length===0)return;let a=[...r],o=fu(i),s=a.pop();if(!(s instanceof B))return;let c=_(a)instanceof V?a.pop():void 0;if(a.length===3){let e=fu(a[1]);return!e||!al(e)?void 0:n.create(I,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(I,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(I,{type:o,attributeList:c,body:s})}function U(e){e&&(e instanceof Qc?Md(e):Nd(e))}function Md(e){e.kind!==y.EOF&&(e.isInvalid=!0)}function Nd(e){if(e instanceof I)U(e.type),U(e.name),U(e.as),U(e.alias),U(e.bodyColon),U(e.attributeList),U(e.body);else if(e instanceof id)e.identifiers.forEach(U);else if(e instanceof L)U(e.name),U(e.colon),U(e.value);else if(e instanceof R)U(e.op),U(e.expression);else if(e instanceof ad)U(e.leftExpression),U(e.op),U(e.rightExpression);else if(e instanceof od)U(e.op),U(e.expression);else if(e instanceof B)U(e.blockOpenBrace),e.body.forEach(U),U(e.blockCloseBrace);else if(e instanceof V)U(e.listOpenBracket),e.commaList.forEach(U),e.elementList.forEach(U),U(e.listCloseBracket);else if(e instanceof cd)U(e.tupleOpenParen),e.commaList.forEach(U),e.elementList.forEach(U),U(e.tupleCloseParen);else if(e instanceof ld)e.commaList.forEach(U),e.elementList.forEach(U);else if(e instanceof H)U(e.callee),U(e.argumentList);else if(e instanceof z)U(e.callee),e.args.forEach(U);else if(e instanceof md)U(e.expression);else if(e instanceof sd)U(e.value);else if(e instanceof pd)U(e.variable);else if(e instanceof dd)U(e.literal);else if(e instanceof ud)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof gd)U(e.array),U(e.indexer);else if(e instanceof ed)e.body.forEach(U),U(e.eof);else if(!(e instanceof hd))if(e instanceof td)U(e.useKeyword),U(e.specifiers),U(e.fromKeyword),U(e.importPath);else if(e instanceof rd)U(e.openBrace),e.specifiers.forEach(U),U(e.closeBrace);else if(e instanceof nd)U(e.importKind),U(e.name);else if(e instanceof fd)U(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Pd(...e){return e.filter(e=>e!==void 0)}function Fd(e){if(e instanceof ed)return Pd(...e.body,e.eof);if(e instanceof I)return Pd(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof L)return Pd(e.name,e.colon,e.value);if(e instanceof id)return e.identifiers;if(e instanceof dd)return e.literal?[e.literal]:[];if(e instanceof pd)return Pd(e.variable);if(e instanceof R)return Pd(e.op,e.expression);if(e instanceof ad)return Pd(e.leftExpression,e.op,e.rightExpression);if(e instanceof od)return Pd(e.expression,e.op);if(e instanceof sd)return Pd(e.value);if(e instanceof z)return Pd(e.callee,...e.args);if(e instanceof B)return Pd(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof V)return Pd(e.listOpenBracket,...Id(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof cd)return Pd(e.tupleOpenParen,...Id(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof ld)return Pd(...Id(e.elementList,e.commaList));if(e instanceof H)return Pd(e.callee,e.argumentList);if(e instanceof md)return Pd(e.expression);if(e instanceof gd)return Pd(e.array,e.indexer);if(e instanceof hd)return[];if(e instanceof td)return Pd(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof rd)return Pd(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof nd)return Pd(e.importKind,e.name);if(e instanceof fd)return Pd(e.token);throw e instanceof ud?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Id(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 Ld(e,t){let n=[...e.parseProject().values()].some(e=>e.getErrors().length>0),r=e.validateNode(t).getErrors().length>0,i=e.bindNode(t).getErrors().length>0;return!n&&!r&&!i}function Rd(e){if(!e)return[];if(T(e))return[{variables:[e],tupleElements:[]}];if(e instanceof ad){let t=vu(e);return t?[t]:[...Rd(e.leftExpression),...Rd(e.rightExpression)]}if(e instanceof R||e instanceof od)return Rd(e.expression);if(e instanceof cd){let t=vu(e);return t?[t]:e.elementList.flatMap(Rd)}return[]}function zd(e,n){let r=n.parentNode;if(!r||!E(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;E(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Bd(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:return}}var Vd=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=v(e.body,e=>e instanceof z);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof B)?[]: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]=v(e.body,e=>e instanceof z);return t.flatMap(e=>!e.callee||Ql(e.callee)?[]:[e.callee,...e.args].flatMap(Rd).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]=v(e.body,e=>e instanceof z);return t.flatMap(e=>!e.callee||Ql(e.callee)?[]:Rd(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=v(e.body,e=>e instanceof z);return t.flatMap(e=>!e.callee||Ql(e.callee)?[]:Rd(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=v(e.body,e=>e instanceof z);return t.flatMap(e=>!e.callee||Ql(e.callee)?[]:Rd(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},Hd=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 B&&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 z&&Ql(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]=v(e.body,e=>e instanceof I),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof B&&this.interpretSubBlock(e.body,t)}let r=this.diagramView.visibleEntities;return(n.has(`tables`)&&r.tables!==null||n.has(`tablegroups`)&&r.tableGroups!==null||n.has(`schemas`)&&r.schemas!==null)&&(n.has(`tables`)||(r.tables=[]),n.has(`tablegroups`)||(r.tableGroups=[]),n.has(`schemas`)||(r.schemas=[])),n.has(`tables`)&&this.diagramViewExplicitlySet.add(`tables`),n.has(`tablegroups`)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(`schemas`)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(`notes`)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,n){if(!n)return;if(e.body.some(e=>e instanceof z&&Ql(e.callee))){let e=this.diagramViewWildcards;switch(n){case`tables`:this.diagramView.visibleEntities.tables=[],e.add(`tables`);break;case`notes`:this.diagramView.visibleEntities.stickyNotes=[],e.add(`stickyNotes`);break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=[],e.add(`tableGroups`);break;case`schemas`:this.diagramView.visibleEntities.schemas=[],e.add(`schemas`);break}return}if(e.body.length===0)return;let r=[];for(let n of e.body){if(!(n instanceof z))continue;let e=n.callee&&this.compiler.nodeReferee(n.callee).getFiltered(t);if(e?.declaration instanceof I){let t=k(e.declaration.name)??[];if(t.length>0){let e=t[t.length-1],n=t.length>1?t.slice(0,-1).join(`.`):b;r.push({name:e,schemaName:n});continue}}let i=k(n.callee)??[];if(i.length===0)continue;let a=i[i.length-1],o=i.length>1?i[0]:b;r.push({name:a,schemaName:o})}switch(n){case`tables`:this.diagramView.visibleEntities.tables=r.length>0?r:null;break;case`notes`:this.diagramView.visibleEntities.stickyNotes=r.length>0?r.map(e=>({name:e.name})):null;break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=r.length>0?r.map(e=>({name:e.name})):null;break;case`schemas`:this.diagramView.visibleEntities.schemas=r.length>0?r.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?Uc(r.filter(e=>e.isKind(N.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function Ud(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}let Wd=function(e){return e.Table=`table`,e}({});const Gd={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new S(x.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},Kd={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return D(a,r.DiagramView)?new n(i.symbolFactory.create(Uu,{declaration:a,name:o},a.filepath)):O(a,r.DiagramView)&&a instanceof fd?new n(i.symbolFactory.create(Wu,{declaration:a,name:o},a.filepath)):O(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(qu,{declaration:a,name:o},a.filepath)):O(a,r.DiagramViewTables)?new n(i.symbolFactory.create(Gu,{declaration:a,name:o},a.filepath)):O(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(Ku,{declaration:a,name:o},a.filepath)):O(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(Ju,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&ou(a))return n.create(e);let o=qd(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)?Jd(i,c,a):o.isKind(r.DiagramViewNotes)?Yd(i,c,a,N.StickyNote):o.isKind(r.DiagramViewTableGroups)?Yd(i,c,a,N.TableGroup):o.isKind(r.DiagramViewSchemas)?Xd(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(N.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!D(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of gu(o))if(e instanceof z){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof I&&c.push(...gu(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(N.DiagramViewSchema,N.DiagramViewTableGroup,N.DiagramViewTable,N.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(gy).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(Gd.getFieldDuplicateError(n,e.kind,i)),s.push(Gd.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!D(a,r.DiagramView))return n.create(e);let o=new Vd(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 Uu?r.declaration instanceof I?new Hd(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function qd(e){let t=e.parentOfKind(z);if(!t)return;let n=t.parentNode;if(!(n instanceof B))return;let i=n.parentNode;if(!(i instanceof I)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof B))return;let o=a.parentNode;if(!(!(o instanceof I)||!o.isKind(r.DiagramView)))return i}function Jd(e,r,i){let a=Su(i);if(a===void 0)return n.create(void 0);if(E(i.parentNode)){let t=zd(e,i);if(t){if(t.isKind(N.Schema)){let r=du(i),o=e.lookupMembers(t,r?N.Table:N.Schema,a);return o?n.create(o):new n(void 0,[new S(x.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,N.Schema,a);return o?n.create(o):new n(void 0,[new S(x.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(N.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,N.Table,a);return s?n.create(s):new n(void 0,[new S(x.BINDING_ERROR,`Could not find table '${a}'`,i)])}function Yd(e,t,r,i){let a=Su(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 S(x.BINDING_ERROR,`Could not find ${i===N.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function Xd(e,t,r){let i=Su(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var Zd=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof z)return[];let t=e.body.filter(e=>e instanceof I);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Qd=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=M(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=M(t),n.name=j(t.callee);let r=C(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Tu(A(r.value)),token:M(r)},this.enum.values.push(n),[]})}};const $d={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new S(x.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},ef={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return D(a,r.Enum)?new n(i.symbolFactory.create(Pu,{declaration:a,name:o},a.filepath)):O(a,r.Enum)?new n(i.symbolFactory.create(Fu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(N.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof I))return new n([]);let o=gu(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(N.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push($d.getFieldDuplicateError(t,r)),c.push($d.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!D(a,r.Enum))return n.create(e);let o=new Zd(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 Pu?new Qd(t,r,i).interpret():n.create(e)}};var tf=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof I)||!this.declarationNode.parent.isKind(r.Table)||!(this.declarationNode.body instanceof B)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=k(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(Rd).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=Su(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new S(x.BINDING_ERROR,`No column named '${r}' inside Table '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},nf=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof B?new n(e.body.flatMap(e=>{if(!(e instanceof z)||!e.callee)return[];let n=[],r=M(e),a=[e.callee,...e.args],o,s,c,l,u;_(a)instanceof V&&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=A(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=A(e.value);t!==void 0&&(l={value:t,token:M(e)})}u=j(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof H))return e;let t=[],n=e;for(;n instanceof H&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=yu(e);if(t){for(let e of t.functional)n.push({value:e.value?.value??``,type:`expression`,token:M(e)});for(let e of t.nonFunctional)n.push({value:Su(e)??``,type:`column`,token:M(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}};const rf={nodeMetadata(t,i){if(!D(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!D(a,r.Table)&&!D(a,r.TablePartial)?n.create(e):n.create(new Cd(i))},nodeReferee(i,a){if(!T(a)||ou(a))return n.create(e);let o=a;for(;o&&!D(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!D(s,r.Table)&&!D(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=T(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,N.Column,l);if(u)return n.create(u);let d=D(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new S(x.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return D(i,r.Indexes)?n.create(void 0,new tf(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===vd.Indexes?r.declaration instanceof I?new nf(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function af(e,n){let r=_u(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof cd){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 cd)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function of(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 S(x.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new S(x.CIRCULAR_REF,`References with same endpoints exist`,n),new S(x.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var sf=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 I&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new S(x.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof I&&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(...cf(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 I)||!t.type)continue;let i=t;D(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),D(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),D(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of gu(e)){if(!(r instanceof z)||!r.callee||!cu(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=af(this.compiler,i.leftExpression),o=af(this.compiler,i.rightExpression);!a||!o||n.push(...of(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of gu(e)){if(!(a instanceof z)||!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 R)||!i.op||!Gl(i.op.value)||!i.expression)continue;let a=af(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...of(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of gu(e)){if(!(r instanceof z)||!r.callee)continue;let e=j(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 R&&(!r.op||!Gl(r.op.value)||r.expression&&T(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new S(x.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 I)||!i.type)continue;let a=i;if(!D(a,r.TableGroup))continue;let o=a.name?k(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=gu(a);for(let r of c){if(!(r instanceof z)||!r.callee)continue;let i=_u(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=k(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new S(x.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 cf(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 Nu&&a.push(...cf(e,t,r));return a}function lf(e,t,n){t.isKind(N.Table)?e.externals.tables.push(n):t.isKind(N.Enum)?e.externals.enums.push(n):t.isKind(N.TableGroup)?e.externals.tableGroups.push(n):t.isKind(N.TablePartial)?e.externals.tablePartials.push(n):t.isKind(N.StickyNote)&&e.externals.notes.push(n)}var uf={mysql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`,`mediumint`]),postgres:new Set([`int`,`integer`,`smallint`,`bigint`,`serial`,`bigserial`,`smallserial`]),mssql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`]),oracle:new Set([`int`,`integer`,`smallint`]),snowflake:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`])},df={mysql:new Set([`decimal`,`numeric`,`float`,`double`,`real`]),postgres:new Set([`decimal`,`numeric`,`real`,`float`,`double precision`]),mssql:new Set([`decimal`,`numeric`,`real`,`float`]),oracle:new Set([`number`,`decimal`,`numeric`,`float`,`real`]),snowflake:new Set([`number`,`decimal`,`numeric`,`float`,`double`,`real`])},ff={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},pf={mysql:new Set([`varchar`,`char`,`text`,`tinytext`,`mediumtext`,`longtext`,`string`]),postgres:new Set([`varchar`,`char`,`character`,`character varying`,`text`,`string`]),mssql:new Set([`varchar`,`char`,`nvarchar`,`nchar`,`text`,`ntext`,`string`]),oracle:new Set([`varchar`,`varchar2`,`char`,`nvarchar2`,`nchar`,`string`]),snowflake:new Set([`varchar`,`char`,`text`,`string`])},mf={mysql:new Set([`binary`,`varbinary`,`blob`,`tinyblob`,`mediumblob`,`longblob`]),postgres:new Set([`bytea`]),mssql:new Set([`binary`,`varbinary`]),oracle:new Set([`blob`,`raw`]),snowflake:new Set([`binary`,`varbinary`])},hf={mysql:new Set([`date`,`datetime`,`timestamp`,`time`]),postgres:new Set([`date`,`timestamp`,`timestamptz`,`timestamp with time zone`,`timestamp without time zone`,`time`,`timetz`,`time with time zone`,`time without time zone`]),mssql:new Set([`date`,`datetime`,`datetime2`,`smalldatetime`,`time`]),oracle:new Set([`date`,`timestamp`,`timestamp with time zone`,`timestamp with local time zone`]),snowflake:new Set([`date`,`datetime`,`timestamp`,`time`])},gf={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function _f(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function vf(e,t){let n=_f(e);return t?uf[t].has(n):Object.values(uf).some(e=>e.has(n))}function yf(e,t){let n=_f(e);return t?df[t].has(n):Object.values(df).some(e=>e.has(n))}function bf(e,t){return vf(e,t)||yf(e,t)}function xf(e,t){let n=_f(e);return t?ff[t].has(n):Object.values(ff).some(e=>e.has(n))}function Sf(e,t){let n=_f(e);return t?pf[t].has(n):Object.values(pf).some(e=>e.has(n))}function Cf(e,t){let n=_f(e);return t?mf[t].has(n):Object.values(mf).some(e=>e.has(n))}function wf(e,t){let n=_f(e);return t?hf[t].has(n):Object.values(hf).some(e=>e.has(n))}function Tf(e,t){let n=_f(e);return t?gf[t].has(n):Object.values(gf).some(e=>e.has(n))}function Ef(e,t){if(t)return`string`;if(vf(e))return`integer`;if(yf(e))return`real`;if(xf(e))return`bool`;if(Sf(e))return`string`;let n=_f(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:wf(e)?`datetime`:e}var Df=class extends Error{},Of=class extends Df{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},kf=class extends Df{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Af=class extends Df{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},jf=class extends Df{},Mf=class extends Df{constructor(e){super(`Invalid unit ${e}`)}},Nf=class extends Df{},Pf=class extends Df{constructor(){super(`Zone is an abstract class`)}},W=`numeric`,Ff=`short`,If=`long`,Lf={year:W,month:W,day:W},Rf={year:W,month:Ff,day:W},zf={year:W,month:Ff,day:W,weekday:Ff},Bf={year:W,month:If,day:W},Vf={year:W,month:If,day:W,weekday:If},Hf={hour:W,minute:W},Uf={hour:W,minute:W,second:W},Wf={hour:W,minute:W,second:W,timeZoneName:Ff},Gf={hour:W,minute:W,second:W,timeZoneName:If},Kf={hour:W,minute:W,hourCycle:`h23`},qf={hour:W,minute:W,second:W,hourCycle:`h23`},Jf={hour:W,minute:W,second:W,hourCycle:`h23`,timeZoneName:Ff},Yf={hour:W,minute:W,second:W,hourCycle:`h23`,timeZoneName:If},Xf={year:W,month:W,day:W,hour:W,minute:W},Zf={year:W,month:W,day:W,hour:W,minute:W,second:W},Qf={year:W,month:Ff,day:W,hour:W,minute:W},$f={year:W,month:Ff,day:W,hour:W,minute:W,second:W},ep={year:W,month:Ff,day:W,weekday:Ff,hour:W,minute:W},tp={year:W,month:If,day:W,hour:W,minute:W,timeZoneName:Ff},np={year:W,month:If,day:W,hour:W,minute:W,second:W,timeZoneName:Ff},rp={year:W,month:If,day:W,weekday:If,hour:W,minute:W,timeZoneName:If},ip={year:W,month:If,day:W,weekday:If,hour:W,minute:W,second:W,timeZoneName:If},ap=class{get type(){throw new Pf}get name(){throw new Pf}get ianaName(){return this.name}get isUniversal(){throw new Pf}offsetName(e,t){throw new Pf}formatOffset(e,t){throw new Pf}offset(e){throw new Pf}equals(e){throw new Pf}get isValid(){throw new Pf}},op=null,sp=class e extends ap{static get instance(){return op===null&&(op=new e),op}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Jm(e,t,n)}formatOffset(e,t){return Qm(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},cp=new Map;function lp(e){let t=cp.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`}),cp.set(e,t)),t}var up={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function dp(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 fp(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=up[t];t===`era`?r[a]=i:G(a)||(r[a]=parseInt(i,10))}return r}var pp=new Map,mp=class e extends ap{static create(t){let n=pp.get(t);return n===void 0&&pp.set(t,n=new e(t)),n}static resetCache(){pp.clear(),cp.clear()}static isValidSpecifier(e){return this.isValidZone(e)}static isValidZone(e){if(!e)return!1;try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).format(),!0}catch{return!1}}constructor(t){super(),this.zoneName=t,this.valid=e.isValidZone(t)}get type(){return`iana`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Jm(e,t,n,this.name)}formatOffset(e,t){return Qm(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=lp(this.name),[r,i,a,o,s,c,l]=n.formatToParts?fp(n,t):dp(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=Wm({year:r,month:i,day:a,hour:s===24?0:s,minute:c,second:l,millisecond:0}),d=+t,f=d%1e3;return d-=f>=0?f:1e3+f,(u-d)/(60*1e3)}equals(e){return e.type===`iana`&&e.name===this.name}get isValid(){return this.valid}},hp={};function gp(e,t={}){let n=JSON.stringify([e,t]),r=hp[n];return r||(r=new Intl.ListFormat(e,t),hp[n]=r),r}var _p=new Map;function vp(e,t={}){let n=JSON.stringify([e,t]),r=_p.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),_p.set(n,r)),r}var yp=new Map;function bp(e,t={}){let n=JSON.stringify([e,t]),r=yp.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),yp.set(n,r)),r}var xp=new Map;function Sp(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=xp.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),xp.set(i,a)),a}var Cp=null;function wp(){return Cp||(Cp=new Intl.DateTimeFormat().resolvedOptions().locale,Cp)}var Tp=new Map;function Ep(e){let t=Tp.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Tp.set(e,t)),t}var Dp=new Map;function Op(e){let t=Dp.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Rp,...t}),Dp.set(e,t)}return t}function kp(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=vp(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=vp(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Ap(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function jp(e){let t=[];for(let n=1;n<=12;n++){let r=R_.utc(2009,n,1);t.push(e(r))}return t}function Mp(e){let t=[];for(let n=1;n<=7;n++){let r=R_.utc(2016,11,13+n);t.push(e(r))}return t}function Np(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Pp(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Ep(e.locale).numberingSystem===`latn`}var Fp=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=bp(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return Im(this.floor?Math.floor(e):Bm(e,3),this.padTo)}},Ip=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&&mp.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=vp(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()}},Lp=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Dm()&&(this.rtf=Sp(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):_h(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Rp={firstDay:1,minimalDays:4,weekend:[6,7]},zp=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||am.defaultLocale;return new e(o||(a?`en-US`:wp()),n||am.defaultNumberingSystem,r||am.defaultOutputCalendar,Nm(i)||am.defaultWeekSettings,o)}static resetCache(){Cp=null,_p.clear(),yp.clear(),xp.clear(),Tp.clear(),Dp.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]=kp(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Ap(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??=Pp(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,Nm(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 Np(this,e,rh,()=>{let n=this.intl===`ja`||this.intl.startsWith(`ja-`);t&=!n;let r=t?{month:e,day:`numeric`}:{month:e},i=t?`format`:`standalone`;if(!this.monthsCache[i][e]){let t=n?e=>this.dtFormatter(e,r).format():e=>this.extract(e,r,`month`);this.monthsCache[i][e]=jp(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Np(this,e,sh,()=>{let n=t?{weekday:e,year:`numeric`,month:`long`,day:`numeric`}:{weekday:e},r=t?`format`:`standalone`;return this.weekdaysCache[r][e]||(this.weekdaysCache[r][e]=Mp(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Np(this,void 0,()=>ch,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[R_.utc(2016,11,13,9),R_.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Np(this,e,fh,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[R_.utc(-40,1,1),R_.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 Fp(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new Ip(e,this.intl,t)}relFormatter(e={}){return new Lp(this.intl,this.isEnglish(),e)}listFormatter(e={}){return gp(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Ep(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Om()?Op(this.locale):Rp}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})`}},Bp=null,Vp=class e extends ap{static get utcInstance(){return Bp===null&&(Bp=new e(0)),Bp}static instance(t){return t===0?e.utcInstance:new e(t)}static parseSpecifier(t){if(t){let n=t.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);if(n)return new e(Ym(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${Qm(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${Qm(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return Qm(this.fixed,t)}get isUniversal(){return!0}offset(){return this.fixed}equals(e){return e.type===`fixed`&&e.fixed===this.fixed}get isValid(){return!0}},Hp=class extends ap{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 Up(e,t){if(G(e)||e===null)return t;if(e instanceof ap)return e;if(Tm(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?sp.instance:n===`utc`||n===`gmt`?Vp.utcInstance:Vp.parseSpecifier(n)||mp.create(e)}else if(Cm(e))return Vp.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new Hp(e)}var Wp={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},Gp={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]},Kp=Wp.hanidec.replace(/[\[|\]]/g,``).split(``);function qp(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(Wp.hanidec)!==-1)t+=Kp.indexOf(e[n]);else for(let e in Gp){let[n,i]=Gp[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Jp=new Map;function Yp(){Jp.clear()}function Xp({numberingSystem:e},t=``){let n=e||`latn`,r=Jp.get(n);r===void 0&&(r=new Map,Jp.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Wp[n]}${t}`),r.set(t,i)),i}var Zp=()=>Date.now(),Qp=`system`,$p=null,em=null,tm=null,nm=60,rm,im=null,am=class{static get now(){return Zp}static set now(e){Zp=e}static set defaultZone(e){Qp=e}static get defaultZone(){return Up(Qp,sp.instance)}static get defaultLocale(){return $p}static set defaultLocale(e){$p=e}static get defaultNumberingSystem(){return em}static set defaultNumberingSystem(e){em=e}static get defaultOutputCalendar(){return tm}static set defaultOutputCalendar(e){tm=e}static get defaultWeekSettings(){return im}static set defaultWeekSettings(e){im=Nm(e)}static get twoDigitCutoffYear(){return nm}static set twoDigitCutoffYear(e){nm=e%100}static get throwOnInvalid(){return rm}static set throwOnInvalid(e){rm=e}static resetCaches(){zp.resetCache(),mp.resetCache(),R_.resetCache(),Yp()}},om=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},sm=[0,31,59,90,120,151,181,212,243,273,304,334],cm=[0,31,60,91,121,152,182,213,244,274,305,335];function lm(e,t){return new om(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function um(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 dm(e,t,n){return n+(Vm(e)?cm:sm)[t-1]}function fm(e,t){let n=Vm(e)?cm:sm,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function pm(e,t){return(e-t+7)%7+1}function mm(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=dm(r,i,a),s=pm(um(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=Km(l,t,n)):c>Km(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...$m(e)}}function hm(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=pm(um(r,1,t),n),s=Hm(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=Hm(l)):c>s?(l=r+1,c-=Hm(r)):l=r;let{month:u,day:d}=fm(l,c);return{year:l,month:u,day:d,...$m(e)}}function gm(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:dm(t,n,r),...$m(e)}}function _m(e){let{year:t,ordinal:n}=e,{month:r,day:i}=fm(t,n);return{year:t,month:r,day:i,...$m(e)}}function vm(e,t){if(!G(e.localWeekday)||!G(e.localWeekNumber)||!G(e.localWeekYear)){if(!G(e.weekday)||!G(e.weekNumber)||!G(e.weekYear))throw new jf(`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 ym(e,t=4,n=1){let r=wm(e.weekYear),i=Pm(e.weekNumber,1,Km(e.weekYear,t,n)),a=Pm(e.weekday,1,7);return r?i?a?!1:lm(`weekday`,e.weekday):lm(`week`,e.weekNumber):lm(`weekYear`,e.weekYear)}function bm(e){let t=wm(e.year),n=Pm(e.ordinal,1,Hm(e.year));return t?n?!1:lm(`ordinal`,e.ordinal):lm(`year`,e.year)}function xm(e){let t=wm(e.year),n=Pm(e.month,1,12),r=Pm(e.day,1,Um(e.year,e.month));return t?n?r?!1:lm(`day`,e.day):lm(`month`,e.month):lm(`year`,e.year)}function Sm(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Pm(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Pm(n,0,59),s=Pm(r,0,59),c=Pm(i,0,999);return a?o?s?c?!1:lm(`millisecond`,i):lm(`second`,r):lm(`minute`,n):lm(`hour`,t)}function G(e){return e===void 0}function Cm(e){return typeof e==`number`}function wm(e){return typeof e==`number`&&e%1==0}function Tm(e){return typeof e==`string`}function Em(e){return Object.prototype.toString.call(e)===`[object Date]`}function Dm(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Om(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function km(e){return Array.isArray(e)?e:[e]}function Am(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 jm(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Mm(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Nm(e){if(e==null)return null;if(typeof e!=`object`)throw new Nf(`Week settings must be an object`);if(!Pm(e.firstDay,1,7)||!Pm(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Pm(e,1,7)))throw new Nf(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Pm(e,t,n){return wm(e)&&e>=t&&e<=n}function Fm(e,t){return e-t*Math.floor(e/t)}function Im(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Lm(e){if(!(G(e)||e===null||e===``))return parseInt(e,10)}function Rm(e){if(!(G(e)||e===null||e===``))return parseFloat(e)}function zm(e){if(!(G(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Bm(e,t,n=`round`){let r=10**t;switch(n){case`expand`:return e>0?Math.ceil(e*r)/r:Math.floor(e*r)/r;case`trunc`:return Math.trunc(e*r)/r;case`round`:return Math.round(e*r)/r;case`floor`:return Math.floor(e*r)/r;case`ceil`:return Math.ceil(e*r)/r;default:throw RangeError(`Value rounding ${n} is out of range`)}}function Vm(e){return e%4==0&&(e%100!=0||e%400==0)}function Hm(e){return Vm(e)?366:365}function Um(e,t){let n=Fm(t-1,12)+1,r=e+(t-n)/12;return n===2?Vm(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function Wm(e){let t=Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second,e.millisecond);return e.year<100&&e.year>=0&&(t=new Date(t),t.setUTCFullYear(e.year,e.month-1,e.day)),+t}function Gm(e,t,n){return-pm(um(e,1,t),n)+t-1}function Km(e,t=4,n=1){let r=Gm(e,t,n),i=Gm(e+1,t,n);return(Hm(e)-r+i)/7}function qm(e){return e>99?e:e>am.twoDigitCutoffYear?1900+e:2e3+e}function Jm(e,t,n,r=null){let i=new Date(e),a={hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};r&&(a.timeZone=r);let o={timeZoneName:t,...a},s=new Intl.DateTimeFormat(n,o).formatToParts(i).find(e=>e.type.toLowerCase()===`timezonename`);return s?s.value:null}function Ym(e,t){let n=parseInt(e,10);Number.isNaN(n)&&(n=0);let r=parseInt(t,10)||0,i=n<0||Object.is(n,-0)?-r:r;return n*60+i}function Xm(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Nf(`Invalid unit value ${e}`);return t}function Zm(e,t){let n={};for(let r in e)if(Mm(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=Xm(i)}return n}function Qm(e,t){let n=Math.trunc(Math.abs(e/60)),r=Math.trunc(Math.abs(e%60)),i=e>=0?`+`:`-`;switch(t){case`short`:return`${i}${Im(n,2)}:${Im(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${Im(n,2)}${Im(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function $m(e){return jm(e,[`hour`,`minute`,`second`,`millisecond`])}var eh=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],th=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],nh=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function rh(e){switch(e){case`narrow`:return[...nh];case`short`:return[...th];case`long`:return[...eh];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`,`12`];case`2-digit`:return[`01`,`02`,`03`,`04`,`05`,`06`,`07`,`08`,`09`,`10`,`11`,`12`];default:return null}}var ih=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],ah=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],oh=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function sh(e){switch(e){case`narrow`:return[...oh];case`short`:return[...ah];case`long`:return[...ih];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var ch=[`AM`,`PM`],lh=[`Before Christ`,`Anno Domini`],uh=[`BC`,`AD`],dh=[`B`,`A`];function fh(e){switch(e){case`narrow`:return[...dh];case`short`:return[...uh];case`long`:return[...lh];default:return null}}function ph(e){return ch[e.hour<12?0:1]}function mh(e,t){return sh(t)[e.weekday-1]}function hh(e,t){return rh(t)[e.month-1]}function gh(e,t){return fh(t)[e.year<0?0:1]}function _h(e,t,n=`always`,r=!1){let i={years:[`year`,`yr.`],quarters:[`quarter`,`qtr.`],months:[`month`,`mo.`],weeks:[`week`,`wk.`],days:[`day`,`day`,`days`],hours:[`hour`,`hr.`],minutes:[`minute`,`min.`],seconds:[`second`,`sec.`]},a=[`hours`,`minutes`,`seconds`].indexOf(e)===-1;if(n===`auto`&&a){let n=e===`days`;switch(t){case 1:return n?`tomorrow`:`next ${i[e][0]}`;case-1:return n?`yesterday`:`last ${i[e][0]}`;case 0:return n?`today`:`this ${i[e][0]}`}}let o=Object.is(t,-0)||t<0,s=Math.abs(t),c=s===1,l=i[e],u=r?c?l[1]:l[2]||l[1]:c?i[e][0]:e;return o?`${s} ${u} ago`:`in ${s} ${u}`}function vh(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var yh={D:Lf,DD:Rf,DDD:Bf,DDDD:Vf,t:Hf,tt:Uf,ttt:Wf,tttt:Gf,T:Kf,TT:qf,TTT:Jf,TTTT:Yf,f:Xf,ff:Qf,fff:tp,ffff:rp,F:Zf,FF:$f,FFF:np,FFFF:ip},bh=class e{static create(t,n={}){return new e(t,n)}static parseFormat(e){let t=null,n=``,r=!1,i=[];for(let a=0;a<e.length;a++){let o=e.charAt(a);o===`'`?((n.length>0||r)&&i.push({literal:r||/^\s+$/.test(n),val:n===``?`'`:n}),t=null,n=``,r=!r):r||o===t?n+=o:(n.length>0&&i.push({literal:/^\s+$/.test(n),val:n}),n=o,t=o)}return n.length>0&&i.push({literal:r||/^\s+$/.test(n),val:n}),i}static macroTokenToFormatOpts(e){return yh[e]}constructor(e,t){this.opts=t,this.loc=e,this.systemLoc=null}formatWithSystemDefault(e,t){return this.systemLoc===null&&(this.systemLoc=this.loc.redefaultToSystem()),this.systemLoc.dtFormatter(e,{...this.opts,...t}).format()}dtFormatter(e,t={}){return this.loc.dtFormatter(e,{...this.opts,...t})}formatDateTime(e,t){return this.dtFormatter(e,t).format()}formatDateTimeParts(e,t){return this.dtFormatter(e,t).formatToParts()}formatInterval(e,t){return this.dtFormatter(e.start,t).dtf.formatRange(e.start.toJSDate(),e.end.toJSDate())}resolvedOptions(e,t){return this.dtFormatter(e,t).resolvedOptions()}num(e,t=0,n=void 0){if(this.opts.forceSimple)return Im(e,t);let r={...this.opts};return t>0&&(r.padTo=t),n&&(r.signDisplay=n),this.loc.numberFormatter(r).format(e)}formatDateTimeFromString(t,n){let r=this.loc.listingMode()===`en`,i=this.loc.outputCalendar&&this.loc.outputCalendar!==`gregory`,a=(e,n)=>this.loc.extract(t,e,n),o=e=>t.isOffsetFixed&&t.offset===0&&e.allowZ?`Z`:t.isValid?t.zone.formatOffset(t.ts,e.format):``,s=()=>r?ph(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?hh(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?mh(t,e):a(n?{weekday:e}:{weekday:e,month:`long`,day:`numeric`},`weekday`),u=n=>{let r=e.macroTokenToFormatOpts(n);return r?this.formatWithSystemDefault(t,r):n},d=e=>r?gh(t,e):a({era:e},`era`);return vh(e.parseFormat(n),e=>{switch(e){case`S`:return this.num(t.millisecond);case`u`:case`SSS`:return this.num(t.millisecond,3);case`s`:return this.num(t.second);case`ss`:return this.num(t.second,2);case`uu`:return this.num(Math.floor(t.millisecond/10),2);case`uuu`:return this.num(Math.floor(t.millisecond/100));case`m`:return this.num(t.minute);case`mm`:return this.num(t.minute,2);case`h`:return this.num(t.hour%12==0?12:t.hour%12);case`hh`:return this.num(t.hour%12==0?12:t.hour%12,2);case`H`:return this.num(t.hour);case`HH`:return this.num(t.hour,2);case`Z`:return o({format:`narrow`,allowZ:this.opts.allowZ});case`ZZ`:return o({format:`short`,allowZ:this.opts.allowZ});case`ZZZ`:return o({format:`techie`,allowZ:this.opts.allowZ});case`ZZZZ`:return t.zone.offsetName(t.ts,{format:`short`,locale:this.loc.locale});case`ZZZZZ`:return t.zone.offsetName(t.ts,{format:`long`,locale:this.loc.locale});case`z`:return t.zoneName;case`a`:return s();case`d`:return i?a({day:`numeric`},`day`):this.num(t.day);case`dd`:return i?a({day:`2-digit`},`day`):this.num(t.day,2);case`c`:return this.num(t.weekday);case`ccc`:return l(`short`,!0);case`cccc`:return l(`long`,!0);case`ccccc`:return l(`narrow`,!0);case`E`:return this.num(t.weekday);case`EEE`:return l(`short`,!1);case`EEEE`:return l(`long`,!1);case`EEEEE`:return l(`narrow`,!1);case`L`:return i?a({month:`numeric`,day:`numeric`},`month`):this.num(t.month);case`LL`:return i?a({month:`2-digit`,day:`numeric`},`month`):this.num(t.month,2);case`LLL`:return c(`short`,!0);case`LLLL`:return c(`long`,!0);case`LLLLL`:return c(`narrow`,!0);case`M`:return i?a({month:`numeric`},`month`):this.num(t.month);case`MM`:return i?a({month:`2-digit`},`month`):this.num(t.month,2);case`MMM`:return c(`short`,!1);case`MMMM`:return c(`long`,!1);case`MMMMM`:return c(`narrow`,!1);case`y`:return i?a({year:`numeric`},`year`):this.num(t.year);case`yy`:return i?a({year:`2-digit`},`year`):this.num(t.year.toString().slice(-2),2);case`yyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,4);case`yyyyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,6);case`G`:return d(`short`);case`GG`:return d(`long`);case`GGGGG`:return d(`narrow`);case`kk`:return this.num(t.weekYear.toString().slice(-2),2);case`kkkk`:return this.num(t.weekYear,4);case`W`:return this.num(t.weekNumber);case`WW`:return this.num(t.weekNumber,2);case`n`:return this.num(t.localWeekNumber);case`nn`:return this.num(t.localWeekNumber,2);case`ii`:return this.num(t.localWeekYear.toString().slice(-2),2);case`iiii`:return this.num(t.localWeekYear,4);case`o`:return this.num(t.ordinal);case`ooo`:return this.num(t.ordinal,3);case`q`:return this.num(t.quarter);case`qq`:return this.num(t.quarter,2);case`X`:return this.num(Math.floor(t.ts/1e3));case`x`:return this.num(t.ts);default:return u(e)}})}formatDurationFromString(t,n){let r=this.opts.signMode===`negativeLargestOnly`?-1:1,i=e=>{switch(e[0]){case`S`:return`milliseconds`;case`s`:return`seconds`;case`m`:return`minutes`;case`h`:return`hours`;case`d`:return`days`;case`w`:return`weeks`;case`M`:return`months`;case`y`:return`years`;default:return null}},a=(e,t)=>n=>{let a=i(n);if(a){let i=t.isNegativeDuration&&a!==t.largestUnit?r:1,o;return o=this.opts.signMode===`negativeLargestOnly`&&a!==t.largestUnit?`never`:this.opts.signMode===`all`?`always`:`auto`,this.num(e.get(a)*i,n.length,o)}else return n},o=e.parseFormat(n),s=o.reduce((e,{literal:t,val:n})=>t?e:e.concat(n),[]),c=t.shiftTo(...s.map(i).filter(e=>e));return vh(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},xh=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Sh(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Ch(...e){return t=>e.reduce(([e,n,r],i)=>{let[a,o,s]=i(t,r);return[{...e,...a},o||n,s]},[{},null,1]).slice(0,2)}function wh(e,...t){if(e==null)return[null,null];for(let[n,r]of t){let t=n.exec(e);if(t)return r(t)}return[null,null]}function Th(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Lm(t[n+i]);return[r,null,n+i]}}var Eh=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Dh=`(?:${Eh.source}?(?:\\[(${xh.source})\\])?)?`,Oh=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,kh=RegExp(`${Oh.source}${Dh}`),Ah=RegExp(`(?:[Tt]${kh.source})?`),jh=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Mh=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Nh=/(\d{4})-?(\d{3})/,Ph=Th(`weekYear`,`weekNumber`,`weekDay`),Fh=Th(`year`,`ordinal`),Ih=/(\d{4})-(\d\d)-(\d\d)/,Lh=RegExp(`${Oh.source} ?(?:${Eh.source}|(${xh.source}))?`),Rh=RegExp(`(?: ${Lh.source})?`);function zh(e,t,n){let r=e[t];return G(r)?n:Lm(r)}function Bh(e,t){return[{year:zh(e,t),month:zh(e,t+1,1),day:zh(e,t+2,1)},null,t+3]}function Vh(e,t){return[{hours:zh(e,t,0),minutes:zh(e,t+1,0),seconds:zh(e,t+2,0),milliseconds:zm(e[t+3])},null,t+4]}function Hh(e,t){let n=!e[t]&&!e[t+1],r=Ym(e[t+1],e[t+2]);return[{},n?null:Vp.instance(r),t+3]}function Uh(e,t){return[{},e[t]?mp.create(e[t]):null,t+1]}var Wh=RegExp(`^T?${Oh.source}$`),Gh=/^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;function Kh(e){let[t,n,r,i,a,o,s,c,l]=e,u=t[0]===`-`,d=c&&c[0]===`-`,f=(e,t=!1)=>e!==void 0&&(t||e&&u)?-e:e;return[{years:f(Rm(n)),months:f(Rm(r)),weeks:f(Rm(i)),days:f(Rm(a)),hours:f(Rm(o)),minutes:f(Rm(s)),seconds:f(Rm(c),c===`-0`),milliseconds:f(zm(l),d)}]}var qh={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Jh(e,t,n,r,i,a,o){let s={year:t.length===2?qm(Lm(t)):Lm(t),month:th.indexOf(n)+1,day:Lm(r),hour:Lm(i),minute:Lm(a)};return o&&(s.second=Lm(o)),e&&(s.weekday=e.length>3?ih.indexOf(e)+1:ah.indexOf(e)+1),s}var Yh=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;function Xh(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=Jh(t,i,r,n,a,o,s),p;return p=c?qh[c]:l?0:Ym(u,d),[f,new Vp(p)]}function Zh(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var Qh=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,$h=/^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,eg=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;function tg(e){let[,t,n,r,i,a,o,s]=e;return[Jh(t,i,r,n,a,o,s),Vp.utcInstance]}function ng(e){let[,t,n,r,i,a,o,s]=e;return[Jh(t,s,n,r,i,a,o),Vp.utcInstance]}var rg=Sh(jh,Ah),ig=Sh(Mh,Ah),ag=Sh(Nh,Ah),og=Sh(kh),sg=Ch(Bh,Vh,Hh,Uh),cg=Ch(Ph,Vh,Hh,Uh),lg=Ch(Fh,Vh,Hh,Uh),ug=Ch(Vh,Hh,Uh);function dg(e){return wh(e,[rg,sg],[ig,cg],[ag,lg],[og,ug])}function fg(e){return wh(Zh(e),[Yh,Xh])}function pg(e){return wh(e,[Qh,tg],[$h,tg],[eg,ng])}function mg(e){return wh(e,[Gh,Kh])}var hg=Ch(Vh);function gg(e){return wh(e,[Wh,hg])}var _g=Sh(Ih,Rh),vg=Sh(Lh),yg=Ch(Vh,Hh,Uh);function bg(e){return wh(e,[_g,sg],[vg,yg])}var xg=`Invalid Duration`,Sg={weeks:{days:7,hours:168,minutes:10080,seconds:10080*60,milliseconds:10080*60*1e3},days:{hours:24,minutes:1440,seconds:1440*60,milliseconds:1440*60*1e3},hours:{minutes:60,seconds:3600,milliseconds:3600*1e3},minutes:{seconds:60,milliseconds:60*1e3},seconds:{milliseconds:1e3}},Cg={years:{quarters:4,months:12,weeks:52,days:365,hours:365*24,minutes:365*24*60,seconds:365*24*60*60,milliseconds:365*24*60*60*1e3},quarters:{months:3,weeks:13,days:91,hours:2184,minutes:2184*60,seconds:2184*60*60,milliseconds:2184*60*60*1e3},months:{weeks:4,days:30,hours:720,minutes:720*60,seconds:720*60*60,milliseconds:720*60*60*1e3},...Sg},wg=146097/400,Tg=146097/4800,Eg={years:{quarters:4,months:12,weeks:wg/7,days:wg,hours:wg*24,minutes:wg*24*60,seconds:wg*24*60*60,milliseconds:wg*24*60*60*1e3},quarters:{months:3,weeks:wg/28,days:wg/4,hours:wg*24/4,minutes:wg*24*60/4,seconds:wg*24*60*60/4,milliseconds:wg*24*60*60*1e3/4},months:{weeks:Tg/7,days:Tg,hours:Tg*24,minutes:Tg*24*60,seconds:Tg*24*60*60,milliseconds:Tg*24*60*60*1e3},...Sg},Dg=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Og=Dg.slice(0).reverse();function kg(e,t,n=!1){return new Ng({values:n?t.values:{...e.values,...t.values||{}},loc:e.loc.clone(t.loc),conversionAccuracy:t.conversionAccuracy||e.conversionAccuracy,matrix:t.matrix||e.matrix})}function Ag(e,t){let n=t.milliseconds??0;for(let r of Og.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function jg(e,t){let n=Ag(e,t)<0?-1:1;Dg.reduceRight((r,i)=>{if(G(t[i]))return r;if(r){let a=t[r]*n,o=e[i][r],s=Math.floor(a/o);t[i]+=s*n,t[r]-=s*o*n}return i},null),Dg.reduce((n,r)=>{if(G(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Mg(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Ng=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Eg:Cg;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||zp.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 Nf(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:Zm(t,e.normalizeUnit),loc:zp.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Cm(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Nf(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=mg(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static fromISOTime(t,n){let[r]=gg(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static invalid(t,n=null){if(!t)throw new Nf(`need to specify a reason the Duration is invalid`);let r=t instanceof om?t:new om(t,n);if(am.throwOnInvalid)throw new Af(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 Mf(e);return t}static isDuration(e){return e&&e.isLuxonDuration||!1}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}toFormat(e,t={}){let n={...t,floor:t.round!==!1&&t.floor!==!1};return this.isValid?bh.create(this.loc,n).formatDurationFromString(this,e):xg}toHuman(e={}){if(!this.isValid)return xg;let t=e.showZeros!==!1,n=Dg.map(n=>{let r=this.values[n];return G(r)||r===0&&!t?null:this.loc.numberFormatter({style:`unit`,unitDisplay:`long`,...e,unit:n.slice(0,-1)}).format(r)}).filter(e=>e);return this.loc.listFormatter({type:`conjunction`,style:e.listStyle||`narrow`,...e}).format(n)}toObject(){return this.isValid?{...this.values}:{}}toISO(){if(!this.isValid)return null;let e=`P`;return this.years!==0&&(e+=this.years+`Y`),(this.months!==0||this.quarters!==0)&&(e+=this.months+this.quarters*3+`M`),this.weeks!==0&&(e+=this.weeks+`W`),this.days!==0&&(e+=this.days+`D`),(this.hours!==0||this.minutes!==0||this.seconds!==0||this.milliseconds!==0)&&(e+=`T`),this.hours!==0&&(e+=this.hours+`H`),this.minutes!==0&&(e+=this.minutes+`M`),(this.seconds!==0||this.milliseconds!==0)&&(e+=Bm(this.seconds+this.milliseconds/1e3,3)+`S`),e===`P`&&(e+=`T0S`),e}toISOTime(e={}){if(!this.isValid)return null;let t=this.toMillis();return t<0||t>=864e5?null:(e={suppressMilliseconds:!1,suppressSeconds:!1,includePrefix:!1,format:`extended`,...e,includeOffset:!1},R_.fromMillis(t,{zone:`UTC`}).toISOTime(e))}toJSON(){return this.toISO()}toString(){return this.toISO()}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Duration { values: ${JSON.stringify(this.values)} }`:`Duration { Invalid, reason: ${this.invalidReason} }`}toMillis(){return this.isValid?Ag(this.matrix,this.values):NaN}valueOf(){return this.toMillis()}plus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t),r={};for(let e of Dg)(Mm(n.values,e)||Mm(this.values,e))&&(r[e]=n.get(e)+this.get(e));return kg(this,{values:r},!0)}minus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t);return this.plus(n.negate())}mapUnits(e){if(!this.isValid)return this;let t={};for(let n of Object.keys(this.values))t[n]=Xm(e(this.values[n],n));return kg(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...Zm(t,e.normalizeUnit)};return kg(this,{values:n})}reconfigure({locale:e,numberingSystem:t,conversionAccuracy:n,matrix:r}={}){let i={loc:this.loc.clone({locale:e,numberingSystem:t}),matrix:r,conversionAccuracy:n};return kg(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return jg(this.matrix,e),kg(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Mg(this.normalize().shiftToAll().toObject());return kg(this,{values:e},!0)}shiftTo(...t){if(!this.isValid||t.length===0)return this;t=t.map(t=>e.normalizeUnit(t));let n={},r={},i=this.toObject(),a;for(let e of Dg)if(t.indexOf(e)>=0){a=e;let t=0;for(let n in r)t+=this.matrix[n][e]*r[n],r[n]=0;Cm(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Cm(i[e])&&(r[e]=i[e]);for(let e in r)r[e]!==0&&(n[a]+=e===a?r[e]:r[e]/this.matrix[a][e]);return jg(this.matrix,n),kg(this,{values:n},!0)}shiftToAll(){return this.isValid?this.shiftTo(`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`):this}negate(){if(!this.isValid)return this;let e={};for(let t of Object.keys(this.values))e[t]=this.values[t]===0?0:-this.values[t];return kg(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Mg(this.values);return kg(this,{values:e},!0)}get years(){return this.isValid?this.values.years||0:NaN}get quarters(){return this.isValid?this.values.quarters||0:NaN}get months(){return this.isValid?this.values.months||0:NaN}get weeks(){return this.isValid?this.values.weeks||0:NaN}get days(){return this.isValid?this.values.days||0:NaN}get hours(){return this.isValid?this.values.hours||0:NaN}get minutes(){return this.isValid?this.values.minutes||0:NaN}get seconds(){return this.isValid?this.values.seconds||0:NaN}get milliseconds(){return this.isValid?this.values.milliseconds||0:NaN}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}equals(e){if(!this.isValid||!e.isValid||!this.loc.equals(e.loc))return!1;function t(e,t){return e===void 0||e===0?t===void 0||t===0:e===t}for(let n of Dg)if(!t(this.values[n],e.values[n]))return!1;return!0}},Pg=`Invalid Interval`;function Fg(e,t){return!e||!e.isValid?Ig.invalid(`missing or invalid start`):!t||!t.isValid?Ig.invalid(`missing or invalid end`):t<e?Ig.invalid(`end before start`,`The end of an interval must be after its start, but you had start=${e.toISO()} and end=${t.toISO()}`):null}var Ig=class e{constructor(e){this.s=e.start,this.e=e.end,this.invalid=e.invalid||null,this.isLuxonInterval=!0}static invalid(t,n=null){if(!t)throw new Nf(`need to specify a reason the Interval is invalid`);let r=t instanceof om?t:new om(t,n);if(am.throwOnInvalid)throw new kf(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=z_(t),i=z_(n);return Fg(r,i)??new e({start:r,end:i})}static after(t,n){let r=Ng.fromDurationLike(n),i=z_(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Ng.fromDurationLike(n),i=z_(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=R_.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=R_.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Ng.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Ng.fromISO(r,n);if(t.isValid)return e.before(o,t)}}return e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static isInterval(e){return e&&e.isLuxonInterval||!1}get start(){return this.isValid?this.s:null}get end(){return this.isValid?this.e:null}get lastDateTime(){return this.isValid&&this.e?this.e.minus(1):null}get isValid(){return this.invalidReason===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}length(e=`milliseconds`){return this.isValid?this.toDuration(e).get(e):NaN}count(e=`milliseconds`,t){if(!this.isValid)return NaN;let n=this.start.startOf(e,t),r;return r=t?.useLocaleWeeks?this.end.reconfigure({locale:n.locale}):this.end,r=r.startOf(e,t),Math.floor(r.diff(n,e).get(e))+(r.valueOf()!==this.end.valueOf())}hasSame(e){return this.isValid?this.isEmpty()||this.e.minus(1).hasSame(this.s,e):!1}isEmpty(){return this.s.valueOf()===this.e.valueOf()}isAfter(e){return this.isValid?this.s>e:!1}isBefore(e){return this.isValid?this.e<=e:!1}contains(e){return this.isValid?this.s<=e&&this.e>e:!1}set({start:t,end:n}={}){return this.isValid?e.fromDateTimes(t||this.s,n||this.e):this}splitAt(...t){if(!this.isValid)return[];let n=t.map(z_).filter(e=>this.contains(e)).sort((e,t)=>e.toMillis()-t.toMillis()),r=[],{s:i}=this,a=0;for(;i<this.e;){let t=n[a]||this.e,o=+t>+this.e?this.e:t;r.push(e.fromDateTimes(i,o)),i=o,a+=1}return r}splitBy(t){let n=Ng.fromDurationLike(t);if(!this.isValid||!n.isValid||n.as(`milliseconds`)===0)return[];let{s:r}=this,i=1,a,o=[];for(;r<this.e;){let t=this.start.plus(n.mapUnits(e=>e*i));a=+t>+this.e?this.e:t,o.push(e.fromDateTimes(r,a)),r=a,i+=1}return o}divideEqually(e){return this.isValid?this.splitBy(this.length()/e).slice(0,e):[]}overlaps(e){return this.e>e.s&&this.s<e.e}abutsStart(e){return this.isValid?+this.e==+e.s:!1}abutsEnd(e){return this.isValid?+e.e==+this.s:!1}engulfs(e){return this.isValid?this.s<=e.s&&this.e>=e.e:!1}equals(e){return!this.isValid||!e.isValid?!1:this.s.equals(e.s)&&this.e.equals(e.e)}intersection(t){if(!this.isValid)return this;let n=this.s>t.s?this.s:t.s,r=this.e<t.e?this.e:t.e;return n>=r?null:e.fromDateTimes(n,r)}union(t){if(!this.isValid)return this;let n=this.s<t.s?this.s:t.s,r=this.e>t.e?this.e:t.e;return e.fromDateTimes(n,r)}static merge(e){let[t,n]=e.sort((e,t)=>e.s-t.s).reduce(([e,t],n)=>t?t.overlaps(n)||t.abutsStart(n)?[e,t.union(n)]:[e.concat([t]),n]:[e,n],[[],null]);return n&&t.push(n),t}static xor(t){let n=null,r=0,i=[],a=t.map(e=>[{time:e.s,type:`s`},{time:e.e,type:`e`}]),o=Array.prototype.concat(...a).sort((e,t)=>e.time-t.time);for(let t of o)r+=t.type===`s`?1:-1,r===1?n=t.time:(n&&+n!=+t.time&&i.push(e.fromDateTimes(n,t.time)),n=null);return e.merge(i)}difference(...t){return e.xor([this].concat(t)).map(e=>this.intersection(e)).filter(e=>e&&!e.isEmpty())}toString(){return this.isValid?`[${this.s.toISO()} – ${this.e.toISO()})`:Pg}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`:`Interval { Invalid, reason: ${this.invalidReason} }`}toLocaleString(e=Lf,t={}){return this.isValid?bh.create(this.s.loc.clone(t),e).formatInterval(this):Pg}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Pg}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Pg}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Pg}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Pg}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Ng.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Lg=class{static hasDST(e=am.defaultZone){let t=R_.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return mp.isValidZone(e)}static normalizeZone(e){return Up(e,am.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||zp.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||zp.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||zp.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||zp.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||zp.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||zp.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||zp.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return zp.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return zp.create(t,null,`gregory`).eras(e)}static features(){return{relative:Dm(),localeWeek:Om()}}};function Rg(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Ng.fromMillis(r).as(`days`))}function zg(e,t,n){let r=[[`years`,(e,t)=>t.year-e.year],[`quarters`,(e,t)=>t.quarter-e.quarter+(t.year-e.year)*4],[`months`,(e,t)=>t.month-e.month+(t.year-e.year)*12],[`weeks`,(e,t)=>{let n=Rg(e,t);return(n-n%7)/7}],[`days`,Rg]],i={},a=e,o,s;for(let[c,l]of r)n.indexOf(c)>=0&&(o=c,i[c]=l(e,t),s=a.plus(i),s>t?(i[c]--,e=a.plus(i),e>t&&(s=e,i[c]--,e=a.plus(i))):e=s);return[e,i,s,o]}function Bg(e,t,n,r){let[i,a,o,s]=zg(e,t,n),c=t-i,l=n.filter(e=>[`hours`,`minutes`,`seconds`,`milliseconds`].indexOf(e)>=0);l.length===0&&(o<t&&(o=i.plus({[s]:1})),o!==i&&(a[s]=(a[s]||0)+c/(o-i)));let u=Ng.fromObject(a,r);return l.length>0?Ng.fromMillis(c,r).shiftTo(...l).plus(u):u}var Vg=`missing Intl.DateTimeFormat.formatToParts support`;function K(e,t=e=>e){return{regex:e,deser:([e])=>t(qp(e))}}var Hg=`[ \xA0]`,Ug=new RegExp(Hg,`g`);function Wg(e){return e.replace(/\./g,`\\.?`).replace(Ug,Hg)}function Gg(e){return e.replace(/\./g,``).replace(Ug,` `).toLowerCase()}function Kg(e,t){return e===null?null:{regex:RegExp(e.map(Wg).join(`|`)),deser:([n])=>e.findIndex(e=>Gg(n)===Gg(e))+t}}function qg(e,t){return{regex:e,deser:([,e,t])=>Ym(e,t),groups:t}}function Jg(e){return{regex:e,deser:([e])=>e}}function Yg(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function Xg(e,t){let n=Xp(t),r=Xp(t,`{2}`),i=Xp(t,`{3}`),a=Xp(t,`{4}`),o=Xp(t,`{6}`),s=Xp(t,`{1,2}`),c=Xp(t,`{1,3}`),l=Xp(t,`{1,6}`),u=Xp(t,`{1,9}`),d=Xp(t,`{2,4}`),f=Xp(t,`{4,6}`),p=e=>({regex:RegExp(Yg(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return Kg(t.eras(`short`),0);case`GG`:return Kg(t.eras(`long`),0);case`y`:return K(l);case`yy`:return K(d,qm);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 Kg(t.months(`short`,!0),1);case`MMMM`:return Kg(t.months(`long`,!0),1);case`L`:return K(s);case`LL`:return K(r);case`LLL`:return Kg(t.months(`short`,!1),1);case`LLLL`:return Kg(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 Jg(u);case`uu`:return Jg(s);case`uuu`:return K(n);case`a`:return Kg(t.meridiems(),0);case`kkkk`:return K(a);case`kk`:return K(d,qm);case`W`:return K(s);case`WW`:return K(r);case`E`:case`c`:return K(n);case`EEE`:return Kg(t.weekdays(`short`,!1),1);case`EEEE`:return Kg(t.weekdays(`long`,!1),1);case`ccc`:return Kg(t.weekdays(`short`,!0),1);case`cccc`:return Kg(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return qg(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return qg(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return Jg(/[a-z_+-/]{1,256}?/i);case` `:return Jg(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:Vg};return m.token=e,m}var Zg={year:{"2-digit":`yy`,numeric:`yyyyy`},month:{numeric:`M`,"2-digit":`MM`,short:`MMM`,long:`MMMM`},day:{numeric:`d`,"2-digit":`dd`},weekday:{short:`EEE`,long:`EEEE`},dayperiod:`a`,dayPeriod:`a`,hour12:{numeric:`h`,"2-digit":`hh`},hour24:{numeric:`H`,"2-digit":`HH`},minute:{numeric:`m`,"2-digit":`mm`},second:{numeric:`s`,"2-digit":`ss`},timeZoneName:{long:`ZZZZZ`,short:`ZZZ`}};function Qg(e,t,n){let{type:r,value:i}=e;if(r===`literal`){let e=/^\s+$/.test(i);return{literal:!e,val:e?` `:i}}let a=t[r],o=r;r===`hour`&&(o=t.hour12==null?t.hourCycle==null?n.hour12?`hour12`:`hour24`:t.hourCycle===`h11`||t.hourCycle===`h12`?`hour12`:`hour24`:t.hour12?`hour12`:`hour24`);let s=Zg[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function $g(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function e_(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Mm(n,i)){let a=n[i],o=a.groups?a.groups+1:1;!a.literal&&a.token&&(e[a.token.val[0]]=a.deser(r.slice(t,t+o))),t+=o}return[r,e]}else return[r,{}]}function t_(e){let t=e=>{switch(e){case`S`:return`millisecond`;case`s`:return`second`;case`m`:return`minute`;case`h`:case`H`:return`hour`;case`d`:return`day`;case`o`:return`ordinal`;case`L`:case`M`:return`month`;case`y`:return`year`;case`E`:case`c`:return`weekday`;case`W`:return`weekNumber`;case`k`:return`weekYear`;case`q`:return`quarter`;default:return null}},n=null,r;return G(e.z)||(n=mp.create(e.z)),G(e.Z)||(n||=new Vp(e.Z),r=e.Z),G(e.q)||(e.M=(e.q-1)*3+1),G(e.h)||(e.h<12&&e.a===1?e.h+=12:e.h===12&&e.a===0&&(e.h=0)),e.G===0&&e.y&&(e.y=-e.y),G(e.u)||(e.S=zm(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var n_=null;function r_(){return n_||=R_.fromMillis(1555555555555),n_}function i_(e,t){if(e.literal)return e;let n=l_(bh.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function a_(e,t){return Array.prototype.concat(...e.map(e=>i_(e,t)))}var o_=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=a_(bh.parseFormat(t),e),this.units=this.tokens.map(t=>Xg(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=$g(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=e_(e,this.regex,this.handlers),[r,i,a]=n?t_(n):[null,null,void 0];if(Mm(n,`a`)&&Mm(n,`H`))throw new jf(`Can't include meridiem when specifying 24-hour format`);return{input:e,tokens:this.tokens,regex:this.regex,rawMatches:t,matches:n,result:r,zone:i,specificOffset:a}}else return{input:e,tokens:this.tokens,invalidReason:this.invalidReason}}get isValid(){return!this.disqualifyingUnit}get invalidReason(){return this.disqualifyingUnit?this.disqualifyingUnit.invalidReason:null}};function s_(e,t,n){return new o_(e,n).explainFromTokens(t)}function c_(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=s_(e,t,n);return[r,i,a,o]}function l_(e,t){if(!e)return null;let n=bh.create(t,e).dtFormatter(r_()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>Qg(t,e,i))}var u_=`Invalid DateTime`,d_=864e13;function f_(e){return new om(`unsupported zone`,`the zone "${e.name}" is not supported`)}function p_(e){return e.weekData===null&&(e.weekData=mm(e.c)),e.weekData}function m_(e){return e.localWeekData===null&&(e.localWeekData=mm(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function h_(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new R_({...n,...t,old:n})}function g_(e,t,n){let r=e-t*60*1e3,i=n.offset(r);if(t===i)return[r,t];r-=(i-t)*60*1e3;let a=n.offset(r);return i===a?[r,i]:[e-Math.min(i,a)*60*1e3,Math.max(i,a)]}function __(e,t){e+=t*60*1e3;let n=new Date(e);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),millisecond:n.getUTCMilliseconds()}}function v_(e,t,n){return g_(Wm(e),t,n)}function y_(e,t){let n=e.o,r=e.c.year+Math.trunc(t.years),i=e.c.month+Math.trunc(t.months)+Math.trunc(t.quarters)*3,a={...e.c,year:r,month:i,day:Math.min(e.c.day,Um(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Ng.fromObject({years:t.years-Math.trunc(t.years),quarters:t.quarters-Math.trunc(t.quarters),months:t.months-Math.trunc(t.months),weeks:t.weeks-Math.trunc(t.weeks),days:t.days-Math.trunc(t.days),hours:t.hours,minutes:t.minutes,seconds:t.seconds,milliseconds:t.milliseconds}).as(`milliseconds`),[s,c]=g_(Wm(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function b_(e,t,n,r,i,a){let{setZone:o,zone:s}=n;if(e&&Object.keys(e).length!==0||t){let r=t||s,i=R_.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return R_.invalid(new om(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function x_(e,t,n=!0){return e.isValid?bh.create(zp.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function S_(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=Im(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=Im(e.c.month),n===`month`)return i;i+=`-`}else if(i+=Im(e.c.month),n===`month`)return i;return i+=Im(e.c.day),i}function C_(e,t,n,r,i,a,o){let s=!n||e.c.millisecond!==0||e.c.second!==0,c=``;switch(o){case`day`:case`month`:case`year`:break;default:if(c+=Im(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=Im(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=Im(e.c.second))}else{if(c+=Im(e.c.minute),o===`minute`)break;s&&(c+=Im(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=Im(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=Im(Math.trunc(-e.o/60)),c+=`:`,c+=Im(Math.trunc(-e.o%60))):(c+=`+`,c+=Im(Math.trunc(e.o/60)),c+=`:`,c+=Im(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var w_={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},T_={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},E_={ordinal:1,hour:0,minute:0,second:0,millisecond:0},D_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],O_=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],k_=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function A_(e){let t={year:`year`,years:`year`,month:`month`,months:`month`,day:`day`,days:`day`,hour:`hour`,hours:`hour`,minute:`minute`,minutes:`minute`,quarter:`quarter`,quarters:`quarter`,second:`second`,seconds:`second`,millisecond:`millisecond`,milliseconds:`millisecond`,weekday:`weekday`,weekdays:`weekday`,weeknumber:`weekNumber`,weeksnumber:`weekNumber`,weeknumbers:`weekNumber`,weekyear:`weekYear`,weekyears:`weekYear`,ordinal:`ordinal`}[e.toLowerCase()];if(!t)throw new Mf(e);return t}function j_(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return A_(e)}}function M_(e){if(I_===void 0&&(I_=am.now()),e.type!==`iana`)return e.offset(I_);let t=e.name,n=L_.get(t);return n===void 0&&(n=e.offset(I_),L_.set(t,n)),n}function N_(e,t){let n=Up(t.zone,am.defaultZone);if(!n.isValid)return R_.invalid(f_(n));let r=zp.fromObject(t),i,a;if(G(e.year))i=am.now();else{for(let t of D_)G(e[t])&&(e[t]=w_[t]);let t=xm(e)||Sm(e);if(t)return R_.invalid(t);let r=M_(n);[i,a]=v_(e,r,n)}return new R_({ts:i,zone:n,loc:r,o:a})}function P_(e,t,n){let r=G(n.round)?!0:n.round,i=G(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Bm(e,r||n.calendary?0:2,n.calendary?`round`:i),t.loc.clone(n).relFormatter(n).format(e,a)),o=r=>n.calendary?t.hasSame(e,r)?0:t.startOf(r).diff(e.startOf(r),r).get(r):t.diff(e,r).get(r);if(n.unit)return a(o(n.unit),n.unit);for(let e of n.units){let t=o(e);if(Math.abs(t)>=1)return a(t,e)}return a(e>t?-0:0,n.units[n.units.length-1])}function F_(e){let t={},n;return e.length>0&&typeof e[e.length-1]==`object`?(t=e[e.length-1],n=Array.from(e).slice(0,e.length-1)):n=Array.from(e),[t,n]}var I_,L_=new Map,R_=class e{constructor(e){let t=e.zone||am.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new om(`invalid input`):null)||(t.isValid?null:f_(t));this.ts=G(e.ts)?am.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=Cm(e.o)&&!e.old?e.o:t.offset(this.ts);r=__(this.ts,a),n=Number.isNaN(r.year)?new om(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||zp.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=F_(arguments),[n,r,i,a,o,s,c]=t;return N_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=F_(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Vp.utcInstance,N_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Em(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Up(n.zone,am.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:zp.fromObject(n)}):e.invalid(f_(i))}static fromMillis(t,n={}){if(Cm(t))return t<-d_||t>d_?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Up(n.zone,am.defaultZone),loc:zp.fromObject(n)});throw new Nf(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(Cm(t))return new e({ts:t*1e3,zone:Up(n.zone,am.defaultZone),loc:zp.fromObject(n)});throw new Nf(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Up(n.zone,am.defaultZone);if(!r.isValid)return e.invalid(f_(r));let i=zp.fromObject(n),a=Zm(t,j_),{minDaysInFirstWeek:o,startOfWeek:s}=vm(a,i),c=am.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 jf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new jf(`Can't mix ordinal dates with month/day`);let h=m||a.weekday&&!p,ee,te,ne=__(c,l);h?(ee=O_,te=T_,ne=mm(ne,o,s)):u?(ee=k_,te=E_,ne=gm(ne)):(ee=D_,te=w_);let re=!1;for(let e of ee){let t=a[e];G(t)?re?a[e]=te[e]:a[e]=ne[e]:re=!0}let ie=(h?ym(a,o,s):u?bm(a):xm(a))||Sm(a);if(ie)return e.invalid(ie);let[ae,oe]=v_(h?hm(a,o,s):u?_m(a):a,l,r),se=new e({ts:ae,zone:r,o:oe,loc:i});return a.weekday&&p&&t.weekday!==se.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${se.toISO()}`):se.isValid?se:e.invalid(se.invalid)}static fromISO(e,t={}){let[n,r]=dg(e);return b_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=fg(e);return b_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=pg(e);return b_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(G(t)||G(n))throw new Nf(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=c_(zp.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):b_(o,s,r,`format ${n}`,t,c)}static fromString(t,n,r={}){return e.fromFormat(t,n,r)}static fromSQL(e,t={}){let[n,r]=bg(e);return b_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Nf(`need to specify a reason the DateTime is invalid`);let r=t instanceof om?t:new om(t,n);if(am.throwOnInvalid)throw new Of(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=l_(e,zp.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return a_(bh.parseFormat(e),zp.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){I_=void 0,L_.clear()}get(e){return this[e]}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}get outputCalendar(){return this.isValid?this.loc.outputCalendar:null}get zone(){return this._zone}get zoneName(){return this.isValid?this.zone.name:null}get year(){return this.isValid?this.c.year:NaN}get quarter(){return this.isValid?Math.ceil(this.c.month/3):NaN}get month(){return this.isValid?this.c.month:NaN}get day(){return this.isValid?this.c.day:NaN}get hour(){return this.isValid?this.c.hour:NaN}get minute(){return this.isValid?this.c.minute:NaN}get second(){return this.isValid?this.c.second:NaN}get millisecond(){return this.isValid?this.c.millisecond:NaN}get weekYear(){return this.isValid?p_(this).weekYear:NaN}get weekNumber(){return this.isValid?p_(this).weekNumber:NaN}get weekday(){return this.isValid?p_(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?m_(this).weekday:NaN}get localWeekNumber(){return this.isValid?m_(this).weekNumber:NaN}get localWeekYear(){return this.isValid?m_(this).weekYear:NaN}get ordinal(){return this.isValid?gm(this.c).ordinal:NaN}get monthShort(){return this.isValid?Lg.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Lg.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Lg.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Lg.weekdays(`long`,{locObj:this.loc})[this.weekday-1]:null}get offset(){return this.isValid?+this.o:NaN}get offsetNameShort(){return this.isValid?this.zone.offsetName(this.ts,{format:`short`,locale:this.locale}):null}get offsetNameLong(){return this.isValid?this.zone.offsetName(this.ts,{format:`long`,locale:this.locale}):null}get isOffsetFixed(){return this.isValid?this.zone.isUniversal:null}get isInDST(){return this.isOffsetFixed?!1:this.offset>this.set({month:1,day:1}).offset||this.offset>this.set({month:5}).offset}getPossibleOffsets(){if(!this.isValid||this.isOffsetFixed)return[this];let e=864e5,t=6e4,n=Wm(this.c),r=this.zone.offset(n-e),i=this.zone.offset(n+e),a=this.zone.offset(n-r*t),o=this.zone.offset(n-i*t);if(a===o)return[this];let s=n-a*t,c=n-o*t,l=__(s,a),u=__(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[h_(this,{ts:s}),h_(this,{ts:c})]:[this]}get isInLeapYear(){return Vm(this.year)}get daysInMonth(){return Um(this.year,this.month)}get daysInYear(){return this.isValid?Hm(this.year):NaN}get weeksInWeekYear(){return this.isValid?Km(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?Km(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=bh.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Vp.instance(e),t)}toLocal(){return this.setZone(am.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Up(t,am.defaultZone),t.equals(this.zone))return this;if(t.isValid){let e=this.ts;if(n||r){let n=t.offset(this.ts),r=this.toObject();[e]=v_(r,n,t)}return h_(this,{ts:e,zone:t})}else return e.invalid(f_(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return h_(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=Zm(e,j_),{minDaysInFirstWeek:n,startOfWeek:r}=vm(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 jf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new jf(`Can't mix ordinal dates with month/day`);let u;i?u=hm({...mm(this.c,n,r),...t},n,r):G(t.ordinal)?(u={...this.toObject(),...t},G(t.day)&&(u.day=Math.min(Um(u.year,u.month),u.day))):u=_m({...gm(this.c),...t});let[d,f]=v_(u,this.o,this.zone);return h_(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Ng.fromDurationLike(e);return h_(this,y_(this,t))}minus(e){if(!this.isValid)return this;let t=Ng.fromDurationLike(e).negate();return h_(this,y_(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Ng.normalizeUnit(e);switch(r){case`years`:n.month=1;case`quarters`:case`months`:n.day=1;case`weeks`:case`days`:n.hour=0;case`hours`:n.minute=0;case`minutes`:n.second=0;case`seconds`:n.millisecond=0;break}if(r===`weeks`)if(t){let e=this.loc.getStartOfWeek(),{weekday:t}=this;t<e&&(n.weekNumber=this.weekNumber-1),n.weekday=e}else n.weekday=1;return r===`quarters`&&(n.month=(Math.ceil(this.month/3)-1)*3+1),this.set(n)}endOf(e,t){return this.isValid?this.plus({[e]:1}).startOf(e,t).minus(1):this}toFormat(e,t={}){return this.isValid?bh.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):u_}toLocaleString(e=Lf,t={}){return this.isValid?bh.create(this.loc.clone(t),e).formatDateTime(this):u_}toLocaleParts(e={}){return this.isValid?bh.create(this.loc.clone(e),e).formatDateTimeParts(this):[]}toISO({format:e=`extended`,suppressSeconds:t=!1,suppressMilliseconds:n=!1,includeOffset:r=!0,extendedZone:i=!1,precision:a=`milliseconds`}={}){if(!this.isValid)return null;a=A_(a);let o=e===`extended`,s=S_(this,o,a);return D_.indexOf(a)>=3&&(s+=`T`),s+=C_(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?S_(this,e===`extended`,A_(t)):null}toISOWeekDate(){return x_(this,`kkkk-'W'WW-c`)}toISOTime({suppressMilliseconds:e=!1,suppressSeconds:t=!1,includeOffset:n=!0,includePrefix:r=!1,extendedZone:i=!1,format:a=`extended`,precision:o=`milliseconds`}={}){return this.isValid?(o=A_(o),(r&&D_.indexOf(o)>=3?`T`:``)+C_(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return x_(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return x_(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?S_(this,!0):null}toSQLTime({includeOffset:e=!0,includeZone:t=!1,includeOffsetSpace:n=!0}={}){let r=`HH:mm:ss.SSS`;return(t||e)&&(n&&(r+=` `),t?r+=`z`:e&&(r+=`ZZ`)),x_(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():u_}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`:`DateTime { Invalid, reason: ${this.invalidReason} }`}valueOf(){return this.toMillis()}toMillis(){return this.isValid?this.ts:NaN}toSeconds(){return this.isValid?this.ts/1e3:NaN}toUnixInteger(){return this.isValid?Math.floor(this.ts/1e3):NaN}toJSON(){return this.toISO()}toBSON(){return this.toJSDate()}toObject(e={}){if(!this.isValid)return{};let t={...this.c};return e.includeConfig&&(t.outputCalendar=this.outputCalendar,t.numberingSystem=this.loc.numberingSystem,t.locale=this.loc.locale),t}toJSDate(){return new Date(this.isValid?this.ts:NaN)}diff(e,t=`milliseconds`,n={}){if(!this.isValid||!e.isValid)return Ng.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=km(t).map(Ng.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Bg(a?this:e,a?e:this,i,r);return a?o.negate():o}diffNow(t=`milliseconds`,n={}){return this.diff(e.now(),t,n)}until(e){return this.isValid?Ig.fromDateTimes(this,e):this}hasSame(e,t,n){if(!this.isValid)return!1;let r=e.valueOf(),i=this.setZone(e.zone,{keepLocalTime:!0});return i.startOf(t,n)<=r&&r<=i.endOf(t,n)}equals(e){return this.isValid&&e.isValid&&this.valueOf()===e.valueOf()&&this.zone.equals(e.zone)&&this.loc.equals(e.loc)}toRelative(t={}){if(!this.isValid)return null;let n=t.base||e.fromObject({},{zone:this.zone}),r=t.padding?this<n?-t.padding:t.padding:0,i=[`years`,`months`,`days`,`hours`,`minutes`,`seconds`],a=t.unit;return Array.isArray(t.unit)&&(i=t.unit,a=void 0),P_(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?P_(t.base||e.fromObject({},{zone:this.zone}),this,{...t,numeric:`auto`,units:[`years`,`months`,`days`],calendary:!0}):null}static min(...t){if(!t.every(e.isDateTime))throw new Nf(`min requires all arguments be DateTimes`);return Am(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Nf(`max requires all arguments be DateTimes`);return Am(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return s_(zp.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new o_(zp.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(G(t)||G(n))throw new Nf(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=zp.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Nf(`fromFormatParser called with a locale of ${o}, but the format parser was created for ${n.locale}`);let{result:s,zone:c,specificOffset:l,invalidReason:u}=n.explainFromTokens(t);return u?e.invalid(u):b_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Lf}static get DATE_MED(){return Rf}static get DATE_MED_WITH_WEEKDAY(){return zf}static get DATE_FULL(){return Bf}static get DATE_HUGE(){return Vf}static get TIME_SIMPLE(){return Hf}static get TIME_WITH_SECONDS(){return Uf}static get TIME_WITH_SHORT_OFFSET(){return Wf}static get TIME_WITH_LONG_OFFSET(){return Gf}static get TIME_24_SIMPLE(){return Kf}static get TIME_24_WITH_SECONDS(){return qf}static get TIME_24_WITH_SHORT_OFFSET(){return Jf}static get TIME_24_WITH_LONG_OFFSET(){return Yf}static get DATETIME_SHORT(){return Xf}static get DATETIME_SHORT_WITH_SECONDS(){return Zf}static get DATETIME_MED(){return Qf}static get DATETIME_MED_WITH_SECONDS(){return $f}static get DATETIME_MED_WITH_WEEKDAY(){return ep}static get DATETIME_FULL(){return tp}static get DATETIME_FULL_WITH_SECONDS(){return np}static get DATETIME_HUGE(){return rp}static get DATETIME_HUGE_WITH_SECONDS(){return ip}};function z_(e){if(R_.isDateTime(e))return e;if(e&&e.valueOf&&Cm(e.valueOf()))return R_.fromJSDate(e);if(e&&typeof e==`object`)return R_.fromObject(e);throw new Nf(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function B_(e){return $l(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof hd}function V_(e){return A(e)===``}function H_(e){return e instanceof sd}function U_(e){let t=bu(e);if(t!==null)return t;if(Jl(e)&&e instanceof R&&e.expression){let t=e.op?.value,n=bu(e.expression);if(n!==null)return t===`-`?-n:n}return null}function W_(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=U_(e);if(t!==null)return t;let n=A(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function G_(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=U_(e);if(t!==null)return Number.isInteger(t)?t:null;let n=A(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}const K_=[`true`,`yes`,`y`,`t`,`1`],q_=[`false`,`no`,`n`,`f`,`0`];function J_(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 K_.includes(t)?!0:q_.includes(t)?!1:null}if($l(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=bu(e);if(t===0)return!1;if(t===1)return!0;let n=A(e)?.toLowerCase();if(n){if(K_.includes(n))return!0;if(q_.includes(n))return!1}return null}function Y_(e){if(e==null)return null;if(typeof e==`string`)return e;let t=k(e);return t?_(t):A(e)??null}function X_(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=A(e)??null??W_(e)??J_(e);return t===null?null:t.toString()}var Z_=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Q_=[`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`],$_=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function ev(e){if(e==null)return null;let t=typeof e==`string`?e:A(e)??null;if(t===null)return null;for(let e of $_){let n=R_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of Z_){let n=R_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Q_){let n=R_.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=R_.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 tv(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 nv(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function rv(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 iv(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 av(e){return e.increment||Tf(e.typeName)}function ov(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function sv(e,t,n){return n.length===1?ov(e,t,n[0]):`(${n.map(n=>ov(e,t,n)).join(`, `)})`}function cv(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function lv(e,t,n){let{token:r}=t,i=e.nodeAtPosition(r.filepath,r.start.offset)??e.parse.ast(r.filepath);return new Fl(x.INVALID_RECORDS_FIELD,n,i)}var uv=e=>e>1?`Composite PK`:`PK`;function dv(e,t,n,r){if(jc(r.values))return[];let i=t.mergedColumns(e).map(t=>tv(t,e)),a=Nc(i,`name`),o=nv(r),s=gv(t,i,e),c=new Set(r.columns);return xc(s,i=>fv(e,t,n,i,o,c,a,r))}function fv(e,t,n,r,i,a,o,s){let c=t.schema(e),l=t.name??``,u=hv(n,r,a,o,c,l,s);if(!jc(u))return u;let d=ao(r.map(e=>o[e])),f=d.every(e=>e&&av(e)),[p,m]=v(i,e=>iv(e,r,d)),h=f?[]:pv(e,p,r,c,l),ee=mv(e,m,r,d,c,l);return[...h,...ee]}function pv(e,t,n,r,i){if(jc(t))return[];let a=`NULL in ${uv(n.length)}: ${sv(r,i,n)} cannot be NULL`;return xc(t,t=>n.map(n=>lv(e,t[n],a)))}function mv(e,t,n,r,i,a){return xc(lc(Ec(t,e=>rv(e,n,r)),e=>e.length>1),t=>{let r=uv(n.length),o=sv(i,a,n);return xc(t,t=>{let i=`Duplicate ${r}: ${o} = ${cv(t,n)}`;return n.map(n=>lv(e,t[n],i))})})}function hv(e,t,n,r,i,a,o){let s=nc(t,Array.from(n));if(jc(s))return[];let c=s.filter(e=>{let t=r[e];return!!(t&&!av(t)&&!t.dbdefault)});if(jc(c))return[];let l=`${uv(c.length)}: Column ${sv(i,a,c)} is missing from record and has no default value`;return o.values.map(()=>new Fl(x.INVALID_RECORDS_FIELD,l,e))}function gv(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 _v=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function vv(e,t,n){if(jc(n.values))return[];let r=t.mergedColumns(e).map(t=>tv(t,e)),i=Nc(r,`name`),a=nv(n),o=t.schema(e),s=t.name??``;return xc(yv(t,r,e),t=>bv(e,a,t,ao(t.map(e=>i[e])),o,s))}function yv(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 bv(e,t,n,r,i,a){return xc(lc(Ec(t.filter(e=>!iv(e,n,r)),e=>rv(e,n,r)),e=>e.length>1),t=>{let r=_v(n.length),o=sv(i,a,n);return xc(t,t=>{let i=`Duplicate ${r}: ${o} = ${cv(t,n)}`;return n.map(n=>lv(e,t[n],i))})})}function xv(e,t,n,r){return xc(t,t=>wv(e,t,n,r))}function Sv(e,t,n,r,i,a){if(!t.record||jc(t.record.values))return[];let o=nv(t.record),s=n.record?nv(n.record):[],c=new Set(s.map(e=>rv(e,i.fieldNames))),l=o.filter(e=>!iv(e,r.fieldNames)).filter(e=>{let t=rv(e,r.fieldNames);return!c.has(t)}),u=t.tableSymbol.interpretedName(e,a),d=n.tableSymbol.interpretedName(e,a);return xc(l,t=>{let n=sv(u.schema,u.name,r.fieldNames),a=sv(d.schema,d.name,i.fieldNames),o=`FK violation: ${n} = ${cv(t,r.fieldNames)} does not exist in ${a}`;return r.fieldNames.map(n=>lv(e,t[n],o))})}function Cv(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 wv(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=Cv(n,i,e,r),s=Cv(n,a,e,r);return!o||!s?[]:Tv(e,o,s,i,a,r)}function Tv(e,t,n,r,i,a){let o=r.relation,s=i.relation;return o===`1`&&s===`1`||o===`*`&&s===`*`?[...Sv(e,t,n,r,i,a),...Sv(e,n,t,i,r,a)]:o===`*`&&s===`1`?Sv(e,t,n,r,i,a):o===`1`&&s===`*`?Sv(e,n,t,i,r,a):[]}var Ev=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:M(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 Zu)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 Nu);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Nu){n.push(t);continue}if(!(t instanceof Zu))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 Iu?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Iu?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}]};lf(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 wd))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 vd.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 S(x.SAME_ENDPOINT,`Ref with same endpoints already exists`,i.declaration));break}n.add(e)}this.db.refs.push(e);break}case vd.Records:if(i instanceof wd){let e=i.table(this.compiler)?.originalSymbol.intern()??``,t=e?r.get(e):void 0;if(t&&t.count>1){this.errors.push(new S(x.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 vd.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 Xu)||!t.isKind(N.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:Wd.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 Nu))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(N.Table))continue;let t=e.originalSymbol;if(!(t instanceof Iu))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 wd))continue;let i=r.table(this.compiler);if(!(i instanceof Iu))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...dv(this.compiler,i,r.declaration,o)),e.push(...vv(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(...xv(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof xd),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 Qu&&t.declaration===e.declaration)))continue;let l=Bd(s);if(!l)continue;let u=a instanceof Vu&&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:M(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:M(i.rightToken())};n.push({token:M(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case N.Table:this.db.tables.push(t);break;case N.Enum:this.db.enums.push(t);break;case N.TableGroup:this.db.tableGroups.push(t);break;case N.TablePartial:this.db.tablePartials.push(t);break;case N.StickyNote:this.db.notes.push(t);break;case N.DiagramView:this.db.diagramViews.push(t);break;default:break}}};const Dv={nodeSymbol(t,r){return ru(r)?n.create(t.symbolFactory.create(Yu,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(N.Program))return n.create(e);if(!(i.declaration instanceof ed))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(b);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(N.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return ru(r)?new sf(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){return r instanceof Yu?r.declaration instanceof ed?Ld(t,r.declaration)?new Ev(t,r,i).interpret():n.create(void 0,[...t.validateNode(r.declaration).getErrors(),...t.bindNode(r.declaration).getErrors()]):n.create(void 0):n.create(e)}};var Ov=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof z)return[];let t=e.body.filter(e=>e instanceof I);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},kv=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=M(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}=Eu(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 B?t.body.body[0]?.callee:t.body?.callee,n=e?A(e):void 0;return n&&(this.project.note={value:Tu(n),token:M(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()]=A(t.body.callee),[]}})}};const Av={nodeMetadata(t,i){return D(i,r.Project)?n.create(new Td(i)):n.create(e)},bindNode(t,i){return D(i,r.Project)?n.create(void 0,new Ov(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Td)||!(r.declaration instanceof I)?n.create(e):new kv(t,r.declaration,i).interpret()}};var jv=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 B&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof ed?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=xu(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=mu(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=Su(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new S(x.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new S(x.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new S(x.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 I)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Xl(e))return[];let i=mu(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=Su(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new S(x.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n));continue}}return a}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof z),n=e.body.filter(e=>e instanceof I);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof ld?e.callee.elementList:[e.callee]).flatMap(Rd).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():[])}},Mv=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Nv(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=Pv(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=M(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 Nv(e,n,i){let a=e.name,o=e.parent;if(o instanceof I&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Iu))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===j(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=xu(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,N.Schema,u);e&&(p=n.lookupMembers(e,N.Table,l))}if(p||=n.lookupMembers(f,N.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Iu))return;let h=m.mergedColumns(n),ee=s.args.map(e=>h.find(t=>t.name===j(e))).filter(Boolean),te=m.interpretedName(n,i);return{schemaName:te.schema,tableName:te.name,columns:ee}}function Pv(e,t,r){let i=[],a=[],o={},s=e.callee instanceof ld?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new S(x.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=Iv(n,l,r);i.push(...u.getErrors()),a.push(...u.getWarnings());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:M(n)})}return new n({row:c,columnNodes:o},i,a)}function Fv(e){return e instanceof sd&&e.value?.value||``}function Iv(e,t,r){let i=M(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=Ef(o,s),p=X_(e),m=p===null?Fv(e):p,h=p===null?`expression`:f;if(e instanceof sd)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(B_(e)||V_(e)&&!Sf(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Tf(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[new Fl(x.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(N.EnumField)).map(e=>e.name).filter(Boolean):[],s=A(e);return s===void 0&&(s=T(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 Fl(x.INVALID_RECORDS_FIELD,`Invalid enum value for column '${d}'`,e)])}if(vf(o)||yf(o)||Tf(o)){let t=U_(e);if(t===null)return new n({value:m,type:h,token:i},[],[new Fl(x.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${d}'`,e)]);if(vf(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[new Fl(x.INVALID_RECORDS_FIELD,`Invalid integer value ${t} for column '${d}': expected integer, got decimal`,e)]);let r=yf(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(yf(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 Fl(x.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 Fl(x.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(xf(o)){let t=J_(e);return t===null?new n({value:m,type:h,token:i},[],[new Fl(x.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${d}'`,e)]):new n({value:t,type:f,token:i},[],[])}if(wf(o)){let t=ev(e);return t===null?new n({value:m,type:h,token:i},[],[new Fl(x.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(Sf(o)){let t=X_(e);if(t===null)return new n({value:m,type:h,token:i},[],[new Fl(x.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 Fl(x.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:h,token:i},[],[])}const Lv={nodeMetadata(t,i){if(!D(i,r.Records))return n.create(e);let a=i.parent;if(a&&D(a,r.Table))return n.create(new wd(i));let o=i.name;return o instanceof H&&o.callee?n.create(new wd(i)):n.create(e)},nodeReferee(i,a){if(!T(a))return n.create(e);let o=a.parentOfKind(I);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(cd);if(l?.parentNode===o)return Rv(i,o,a);let u=a.parentOfKind(H);return u?.parentNode===o&&l?.parentNode===u?zv(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?Bv(i,c,a):Hv(i,c,a)},bindNode(t,i){return D(i,r.Records)?n.create(void 0,new jv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof wd?r.declaration instanceof I?new Mv(t,r,i).interpret():n.create(void 0):n.create(e)}};function Rv(e,i,a){let o=i.parent;if(o instanceof I&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return Vv(e,n,a)}return new n(void 0)}function zv(e,r,i){if(r.callee){let n;if(T(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=_u(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return Vv(e,n,i)}return new n(void 0)}function Bv(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode)){let a=e.lookupMembers(t,[N.Table,N.Schema],i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=zd(e,r);if(!a){let a=e.lookupMembers(t,[N.Table,N.Schema],i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Table,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function Vv(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``,a=e.lookupMembers(t,N.Column,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function Hv(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return new n(void 0);let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Enum,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(N.Enum)){let t=e.lookupMembers(a,N.EnumField,i);return t?n.create(t):new n(void 0,[new S(x.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(E(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,N.Enum,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var Uv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof ed)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Rd).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():[])}},Wv=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=M(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()];return n.create(this.ref,e)}interpretName(){if(!(this.declarationNode instanceof I))return[];let e=[],t=k(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new S(x.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(Jc(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new S(x.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=Bd(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=M(this.metadata.leftToken()),l=M(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof I?[{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 I))return[];let u=gu(this.declarationNode)[0];if(u.args[0]){let e=C(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof id?pu(t):j(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof id?pu(n):j(n),this.ref.color=e.color?.length?Du(e.color?.at(0)?.value):void 0}return[]}};function Gv(e){let t=e.parent;for(;t;){if(t instanceof I&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}const Kv={nodeReferee(r,i){if(!T(i)&&!E(i)||!Gv(i)||i.parentOfKind(L))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):Jv(r,o,i)},nodeMetadata(t,a){if(D(a,r.Ref)){let t=gu(a)[0];if(!(t instanceof z)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof ad)||!r.op?n.create(e):n.create(new bd(a))}if(a instanceof L){if(!(a.name instanceof id)||pu(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof I&&t.isKind(r.TablePartial)?n.create(new xd(a)):n.create(new bd(a))}return n.create(e)},bindNode(t,i){return D(i,r.Ref)?n.create(void 0,new Uv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof bd?new Wv(t,r,i).interpret():n.create(e)}};function qv(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Nu&&e.isPublicSchema())}function Jv(e,r,i){if(!T(i))return new n(void 0);let a=Su(i)??``;if(!E(i.parentNode)){let r=i.parentNode;if(r&&E(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=E(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(N.Table)){let r=e.lookupMembers(c,N.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 S(x.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=zd(e,i);if(o){if(o.isKind(N.Schema)){let t=e.lookupMembers(o,[N.Table,N.Schema],a);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(N.Table)){let r=e.lookupMembers(o,N.Column,a);return r?n.create(r):new n(void 0,[new S(x.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(E(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,N.Schema,a);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=qv(e,r);if(t){let r=e.lookupMembers(t,N.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,N.Table,a);return o?n.create(o):new n(void 0,[new S(x.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}const Yv={visibleName(e,n){let r=n instanceof P?n:n.useSpecifierDeclaration instanceof nd?n.useSpecifierDeclaration:n.declaration;if(r instanceof nd&&n instanceof Mu&&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)}},Xv={nodeSymbol(r,i){if(!nu(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===N.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(Zu,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:Yv.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new S(x.BINDING_ERROR,`Failed to resolve the import of ${a} '${(k(i.name)||[]).map(gy).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof Zu))return n.create(e);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!T(i)&&!eu(i))return n.create(e);let a=i.parentOfKind(nd);if(!a)return n.create(e);let o=a.name===i||E(a.name)&&a.name.rightExpression===i?a.getSymbolKind():N.Schema;if(o===void 0)return n.create(void 0);let s=k(i.parentOfKind(ad)),c=j(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(td);if(l?.importPath?.value===void 0)return n.create(void 0);let u=Al(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new S(x.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new S(x.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toString()}. Does the file exist?`,i)]);let d=i.parentOfKind(ad)?.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 S(x.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=Zv(r,u,c,o);return f?n.create(f):n.create(void 0,[new S(x.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toString()}`,i)])},bindNode(t,r){if(tu(r)){let e=[];if(r.importPath?.value){let n=Al(r.filepath,r.importPath.value);n?t.layout.exists(n)||e.push(new S(x.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath)):e.push(new S(x.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 rd?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):nu(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 Zu))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 Zv(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);if(s?.isKind(i))return s;let c=o.schemaMembers.find(e=>e.name===r);if(c?.isKind(N.Schema))return c;for(let t of o.reuses.selective)if(k(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(td);if(o?.importPath?.value){let s=Zv(e,Al(n,o.importPath.value),k(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=Zv(e,t,r,i,a);if(n)return n}}function Qv(e){if(e instanceof kl){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=ey(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof Yu?ty(this,e,i):ny(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 $v(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof nd?Yv.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof nd&&r.getSymbolKind()===N.Schema?a:a.length<=1?[b]: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 ey(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof td)||!e.specifiers||!e.importPath)continue;let n=Al(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof fd?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof fd?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 ty(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[b,e.symbolFactory.create(Nu,{name:b},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?b:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Nu,{name:i},s))}ry(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of ay(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Nu,{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 ny(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof I))continue;let i=$v(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(Xu,{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(Nu,{name:i.schemaName,parent:n},n.filepath))}iy(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of oy(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Nu,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function ry(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==N.Schema)continue;let t=Yv.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Nu,{name:t},r))}}function iy(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==N.Schema)continue;let t=Yv.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(Nu,{name:o,parent:n},n.filepath))}}function ay(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?b:r[0];i.push(a)}let a=ey(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==N.Schema)continue;let n=Yv.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function oy(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?[b]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=ey(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==N.Schema)continue;let n=Yv.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var sy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);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(_(n)instanceof V){let e=C(_(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=>!Wl(e.callee)))}tryToBindColumnType(e){let t=vu(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(w(e))return[];if(T(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&jl.includes(t))return[]}let t=vu(e);if(!t){if(E(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 Rd(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():[])}},cy=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??M(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}=Eu(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new S(x.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=Su(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=C(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Du(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Tu(A(n?.value)),token:M(n)},[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof z);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:Tu(A(e.body instanceof B?e.body.body[0].callee:e.body.callee)),token:M(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:M(e)};i.name=j(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 S(x.UNSUPPORTED,`Import TablePartial ${i.name} from '${a.filepath}' first. 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(N.Column)).length?[]:[new S(x.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Wl(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=Su(e.callee),r.token=M(e);let o=ku(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:M(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 ly={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new S(x.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new S(x.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},uy={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return D(a,r.Table)?new n(i.symbolFactory.create(Iu,{declaration:a,name:o},a.filepath)):O(a,r.Table)?Wl(a.callee)?new n(i.symbolFactory.create(Hu,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Lu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(N.Table))return n.create(e);let a=i.declaration;if(!(a instanceof I))return new n([]);let o=gu(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(N.Column,N.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof I&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(N.Column)?(c.push(ly.getColumnDuplicateError(e.name,r)),c.push(ly.getColumnDuplicateError(e.name,n))):(c.push(ly.getPartialInjectionDuplicateError(e.name,r)),c.push(ly.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 z)||!Wl(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=j(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new S(x.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(Qu,{kind:N.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(N.Column)&&!(e instanceof Qu)).map(e=>e.name));return new n(Uc([...s.filter(e=>!(e instanceof Qu&&d.has(e.name)))].reverse(),e=>e.isKind(N.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(!iu(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):T(o)&&o.parentNode instanceof R&&o.parentNode.op?.value===`~`?dy(a,c,o):au(o,1)?fy(a,c,o):su(o,i.Ref)?py(a,c,o):au(o,0)?n.create(e):my(a,c,o)},bindNode(i,a){if(!D(a,r.Table))return n.create(e);let o=new sy(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 Iu?r.declaration instanceof I?new cy(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function dy(e,r,i){let a=j(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Nu&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,N.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,N.TablePartial,a);return s?n.create(s):new n(void 0,[new S(x.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function fy(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return n.create(e.lookupMembers(t,N.Enum,i));let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=du(r),o=e.lookupMembers(a,t?N.Enum:N.Schema,i);return o?n.create(o):new n(void 0,[new S(x.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,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function py(e,i,a){if(!T(a))return new n(void 0);let o=Su(a)??``;if(!E(a.parentNode)){let s=a.parent,c=s instanceof I&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,N.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,N.Column,o);return l?n.create(l):new n(void 0,[new S(x.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}let s=zd(e,a);if(s){if(s.isKind(N.Schema)){let t=e.lookupMembers(s,[N.Table,N.Schema],o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(N.Table)){let t=e.lookupMembers(s,N.Column,o);return t?n.create(t):new n(void 0,[new S(x.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(E(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,N.Schema,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,N.Table,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function my(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return jl.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,N.Enum,i));let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Enum,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(N.Enum)){let t=e.lookupMembers(a,N.EnumField,i);return t?n.create(t):new n(void 0,[new S(x.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(E(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,N.Enum,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function hy(e){return e?e.split(``).every(e=>Il(e)||Ll(e))&&!Ll(e[0]):!1}function gy(e){return hy(e)?e:`"${vy(e)}"`}function _y(e){let t=``,n=0,r={n:`
|
|
5
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 vy(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 yy(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`'${vy(e)}'`;let{value:t,type:n}=e;if(t==null||xf(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(xf(n)){let e=J_(t);return e===null?`\`${t}\``:e?`true`:`false`}if(bf(n)){let e=W_(t);return e===null?`\`${t}\``:String(e)}if(wf(n)){let e=ev(t);return e===null?`\`${t}\``:`'${vy(e)}'`}let r=X_(t);return r===null?`\`${t}\``:`'${vy(r)}'`}function by(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?_y(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function xy(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 Sy(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 Nu&&n.isKind(N.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 Cy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Rd).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof Zu?[...r.getErrors(),new S(x.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():[])}},wy=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=M(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}=Eu(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new S(x.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]=v(e.body,e=>e instanceof z);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case`note`:this.tableGroup.note={value:Tu(A(e.body instanceof B?e.body.body[0].callee:e.body.callee)),token:M(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(N.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=k(e.callee);return i.length>2&&n.push(new S(x.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=C(e).getValue();this.tableGroup.color=t.color?.length?Du(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Tu(A(n?.value)),token:M(n)},[]}};const Ty={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new S(x.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Ey={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return D(a,r.TableGroup)?new n(i.symbolFactory.create(Ru,{declaration:a,name:s},a.filepath)):O(a,r.TableGroup)?new n(i.symbolFactory.create(zu,{declaration:a,name:o?.map(gy).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(N.TableGroup)){let e=i.declaration;if(!(e instanceof I))return new n([]);let a=gu(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(N.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof I&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Ty.getFieldDuplicateError(e.name,r)),s.push(Ty.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(N.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!T(a)||!iu(a,r.TableGroup)||a.parent&&ou(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):Dy(i,s,a)},bindNode(i,a){if(!D(a,r.TableGroup))return n.create(e);let o=new Cy(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!D(o,r.TableGroup)||!(i instanceof Ru)?n.create(e):Ld(t,o)?new wy(t,i,a).interpret():n.create(void 0)}};function Dy(e,r,i){let a=Su(i)??``;if(!E(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Nu&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,N.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,N.Table,a);return s?n.create(s):new n(void 0,[new S(x.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=zd(e,i);if(o){if(o.isKind(N.Schema)){let t=e.lookupMembers(o,[N.Table,N.Schema],a);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,N.Schema,a);return s?n.create(s):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var Oy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);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(_(n)instanceof V){let e=C(_(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=vu(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return Rd(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():[])}},ky=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??M(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}=Eu(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=C(e).getValue(),n=hc(t[i.HeaderColor]);this.tablePartial.headerColor=n?Du(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Tu(A(r?.value)),token:M(r)},[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof z);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case r.Note:return this.tablePartial.note={value:Tu(A(e.body instanceof B?e.body.body[0].callee:e.body.callee)),token:M(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=Su(e.callee)??``,r.token=M(e);let o=ku(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 xd))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:M(n.rightToken())}}),r.checks=(c[i.Check]||[]).map(e=>({token:M(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 Ay={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},jy={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return D(a,r.TablePartial)?new n(i.symbolFactory.create(Vu,{declaration:a,name:o},a.filepath)):O(a,r.TablePartial)?new n(i.symbolFactory.create(Lu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(N.TablePartial)){let e=a.declaration;if(!(e instanceof I))return new n([]);let r=gu(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(N.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof I&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(ly.getColumnDuplicateError(t,r)),s.push(ly.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(N.Column)&&D(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!T(o)&&!E(o)||!iu(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):au(o,1)?My(a,c,o):su(o,i.Ref)?Ny(a,c,o):Py(a,c,o)},bindNode(i,a){if(!D(a,r.TablePartial))return n.create(e);let o=new Oy(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 Vu?r.declaration instanceof I?new ky(t,r,i).interpret():n.create(void 0):n.create(e)}};function My(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return n.create(e.lookupMembers(t,N.Enum,i));let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Enum,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.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,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Ny(e,i,a){if(!T(a))return new n(void 0);let o=Su(a)??``;if(!E(a.parentNode)){let s=a.parent;if(s instanceof I&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,N.Column,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,N.Column,o);return c?n.create(c):new n(void 0,[new S(x.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=zd(e,a);if(s){if(s.isKind(N.Schema)){let t=e.lookupMembers(s,[N.Table,N.Schema],o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(N.Table)){let t=e.lookupMembers(s,N.Column,o);return t?n.create(t):new n(void 0,[new S(x.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(E(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,N.Schema,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,N.Table,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function Py(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return jl.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,N.Enum,i));let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Enum,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(N.Enum)){let t=e.lookupMembers(a,N.EnumField,i);return t?n.create(t):new n(void 0,[new S(x.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(E(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,N.Enum,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}const Fy={symbolMembers(r,i){if(!i.isKind(N.Schema)||!(i instanceof Nu))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=Ly(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...Ry(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...By(r,i,e,t,c));for(let e of o.uses.selective){let n=Ly(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...Ry(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...By(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(N.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(N.TableGroup)))}}for(let t of e)u.push(...Hy(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof Zu&&e.isKind(N.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(N.Schema))continue;let t=e instanceof Zu?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof I&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(Iy(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function Iy(e,t,n,r){switch(e){case N.Table:return ly.getDuplicateError(t,n,r);case N.Enum:return $d.getDuplicateError(t,n,r);case N.TablePartial:return Ay.getDuplicateError(t,n,r);case N.TableGroup:return Ty.getDuplicateError(t,n,r);case N.DiagramView:return Gd.getDuplicateError(t,n,r);default:return new S(x.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function Ly(e,r,i,a){let o=$v(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(Nu,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function Ry(e,n,r,i=new Set){if(r.getSymbolKind()!==N.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(N.Schema))return[];let o=Yv.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:zy(e,n,r,a,i)}function zy(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(Zu,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(N.TableGroup)&&c.push(...Hy(e,n,t));for(let i of s.reuses.selective)if(c.push(...Ry(e,n,i,a)),$v(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(Zu,{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=Vy(e,t,n.qualifiedName);i&&c.push(...zy(e,n,r,i,a))}return c}function By(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=Vy(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(Zu,{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(Nu,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=Ly(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...Ry(e,n,r))}for(let{importPath:t}of d)l.push(...By(e,n,t,i,a,o));return l}function Vy(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 Hy(e,n,r){if(!r.isKind(N.TableGroup)||!(r instanceof Zu))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(N.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=k(n);if(!i||i.length===0)continue;let a=i.length<=1?[b]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=Uy(e,c,i);l&&s.push(e.symbolFactory.create(Zu,{kind:N.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function Uy(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(N.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(N.Table)&&e.name===a)}var Wy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof z)return[];let t=e.body.filter(e=>e instanceof I);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Gy=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=M(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=C(e).getValue();return this.note.headerColor=t.headercolor?.length?Du(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof z);return t.length!==1||n.length>0?[new S(x.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=na(e,`callee.expression.literal.value`,``);return this.note.content=Tu(t),[]}};const Ky={nodeSymbol(i,a){return!D(a,r.Note)||!(a.parentNode instanceof ed)?n.create(e):new n(i.symbolFactory.create(Bu,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(N.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return D(i,r.Note)?n.create(void 0,new Wy(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Bu?r.declaration instanceof I?new Gy(t,r,i).interpret():n.create(void 0):n.create(e)}},qy=[uy,ef,Lv,rf,Ad,Kv,Av,Ey,jy,Ky,Xv,Fy,Kd,Dv];function Jy(t,...r){for(let i of qy){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function Yy(r){let i=Jy(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Xy(r){let i=Jy(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Zy(r){let i=Jy(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Qy(r){let i=Jy(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function $y(r){let i=Jy(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function eb(r,i){let a=Jy(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function tb(r,i){let a=Jy(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var nb=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 S(x.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof ed?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new S(x.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=v(e.body,e=>e instanceof z);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 _(n)instanceof V&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof sd))&&t.push(new S(x.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=C(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 S(x.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{w(t.value)||n.push(new S(x.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new S(x.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const rb={validateNode(t,i){if(!D(i,r.Checks))return n.create(e);let a=new nb(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return D(i,r.Checks)?i.name?new n(void 0,[new S(x.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Checks)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Checks)?i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}};var ib=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 I&&this.declarationNode.parent.isKind(r.Project)?[]:[new S(x.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e?[new S(x.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof B)return[new S(x.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return w(e.callee)||t.push(new S(x.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 S(x.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function ab(e){return e instanceof I&&!!e.type?.value}const ob={validateNode(t,r){if(!ab(r))return n.create(e);let i=new ib(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return ab(r)?r.name?new n(void 0,[new S(x.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return ab(r)?r.alias?new n(void 0,[new S(x.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return ab(r)?r.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}};var sb=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 I?[new S(x.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Hl(e)?[]:[new S(x.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new S(x.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=C(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new S(x.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof z)return{errors:[new S(x.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=v(e.body,e=>e instanceof z),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Ql(e.callee)?e.args.length>0?e.args.map(e=>new S(x.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new S(x.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 S(x.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(Ul(e))return t.push(new S(x.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof B))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof z&&Ql(e.callee)),a=r.body.some(e=>e instanceof z&&!Ql(e.callee));return i&&a&&n.push(new Fl(x.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 B))return t;let n=e.body.body.filter(e=>e instanceof z);for(let e of n)Ql(e.callee)||(e.args.length>0||!k(e.callee))&&t.push(...e.args.map(e=>new S(x.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}};const cb={validateNode(t,i){if(!D(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new sb(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(D(i,r.DiagramView)){if(!i.name)return new n(void 0,[new S(x.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=k(i.name);return e?new n(e):new n(void 0)}else if(O(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=k(i.callee);return e?(e.length===1&&O(i,r.DiagramViewTables)&&e.unshift(b),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return D(i,r.DiagramView)?new n(void 0):n.create(e)}};var lb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof I?[new S(x.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Bl(e)?[]:[new S(x.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new S(x.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new S(x.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!T(n.callee)&&t.push(new S(x.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];_(e)instanceof V?(t.push(...this.validateFieldSettings(_(e))),e.pop()):e[0]instanceof V&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new S(x.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=C(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 S(x.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{w(e.value)||n.push(new S(x.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new S(x.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 ub={validateNode(t,i){return D(i,r.Enum)?n.create(void 0,new lb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(D(i,r.Enum)){if(!i.name)return new n(void 0,[new S(x.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Bl(i.name))return new n(void 0,[new S(x.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=k(i.name);return e?.length===1&&e.unshift(b),new n(e)}if(O(i,r.Enum)){let e=j(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return D(i,r.Enum)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):O(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(D(a,r.Enum))return a.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(O(a,r.Enum)){let e=[...a.args],t;if(_(e)instanceof V?t=_(e):e[0]instanceof V&&(t=e[0]),!t)return new n({});let r=C(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 S(x.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{w(e.value)||o.push(new S(x.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new S(x.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return 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(){let e=new S(x.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof ed?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new S(x.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=v(e.body,e=>e instanceof z);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 _(n)instanceof V&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof H;)e.argumentList&&yu(e.argumentList)===void 0&&t.push(new S(x.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;yu(e)===void 0&&t.push(new S(x.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=C(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 S(x.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{w(t.value)||n.push(new S(x.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new S(x.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new S(x.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new S(x.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{T(e.value)||n.push(new S(x.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new S(x.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const fb={validateNode(t,i){return D(i,r.Indexes)?n.create(void 0,new db(t,i).validate()):n.create(e)},nodeFullname(t,i){return D(i,r.Indexes)?i.name?new n(void 0,[new S(x.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):O(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Indexes)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):O(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(D(a,r.Indexes))return a.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(O(a,r.Indexes)){let e=[a.callee,...a.args],t;if(_(e)instanceof V&&(t=_(e)),!t)return new n({});let r=C(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 S(x.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{w(t.value)||o.push(new S(x.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 S(x.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{T(e.value)||o.push(new S(x.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new S(x.UNKNOWN_INDEX_SETTING,`Unknown index 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=this.declarationNode.parent;return!(e instanceof ed)&&!(e instanceof I&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project))?[new S(x.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 S(x.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new S(x.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new S(x.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),w(e[0].callee)||t.push(new S(x.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 S(x.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 mb={validateNode(t,i){return D(i,r.Note)?n.create(void 0,new pb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!D(i,r.Note))return n.create(e);if(!(i.parent instanceof ed))return i.name?new n(void 0,[new S(x.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new S(x.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof fd)return new n(void 0,[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=k(i.name);return a===void 0?new n(void 0,[new S(x.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return D(i,r.Note)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Note)?i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}};var hb=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 gb={validateNode(t,r){return ru(r)?n.create(void 0,new hb(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return ru(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return ru(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return ru(r)?new n({}):n.create(e)}};var _b=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 I?[new S(x.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Hl(e)?new n(k(e)):new n(void 0,[new S(x.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 S(x.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof z);return[...t.map(e=>new S(x.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 vb={validateNode(t,i){return D(i,r.Project)?n.create(void 0,new _b(t,i).validate()):n.create(e)},nodeFullname(t,i){return D(i,r.Project)?i.name?Hl(i.name)?new n(k(i.name)):new n(void 0,[new S(x.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):O(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Project)&&i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):O(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Project)?i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):O(i,r.Project)?new n({}):n.create(e)}};var yb=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 ed||e instanceof I&&e.isKind(r.Table)?[]:[new S(x.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof ed?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof H))return[new S(x.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||!Bl(e.callee))&&t.push(new S(x.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Xl(e.argumentList))&&t.push(new S(x.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Xl(e)?[new S(x.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return this.validateDataRow(e);let[t,n]=v(e.body,e=>e instanceof z);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 S(x.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof ld)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new S(x.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 S(x.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 hd||Jl(e)||w(e)||e instanceof sd)return!0;if(T(e)){let t=e.expression.variable.value.toLowerCase();return jl.includes(t)}if(E(e)){let t=k(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const bb={validateNode(t,i){return D(i,r.Records)?n.create(void 0,new yb(t,i).validate()):n.create(e)},nodeFullname(i,a){if(D(a,r.Records)){if(a.name instanceof fd)return new n(void 0,[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof ed){if(!(a.name instanceof H))return new n(void 0,[new S(x.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||!Bl(a.name.callee))&&e.push(new S(x.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Xl(a.name.argumentList))&&e.push(new S(x.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=k(a.name.callee);return t?.length===1&&t.unshift(b),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Xl(a.name)?new n(e,[new S(x.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return O(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Records)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):O(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Records)?i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,i.attributeList)]):new n({}):O(i,r.Records)?new n({}):n.create(e)}};var xb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof ed?[]:[new S(x.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:Hl(e)?[]:[new S(x.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new S(x.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 S(x.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!cu(e.callee)&&t.push(new S(x.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&cu(e.callee)){let n=vu(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=vu(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new S(x.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new S(x.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!lu(e.callee)&&t.push(new S(x.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(_(n)instanceof V){let e=this.validateFieldSettings(_(n));t.push(...e),n.pop()}else n[0]instanceof V&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new S(x.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return Cb(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function Sb(e){if(!(T(e)&&e.expression.variable.kind!==y.QUOTED_STRING)&&!(e instanceof id))return!1;let t;if(t=e instanceof id?pu(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 Cb(e){let t=C(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 S(x.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Sb(t.value)||r.push(new S(x.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 S(x.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Kl(e.value)||r.push(new S(x.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new S(x.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}const wb={validateNode(t,i){return D(i,r.Ref)?n.create(void 0,new xb(t,i).validate()):n.create(e)},nodeFullname(t,i){return D(i,r.Ref)?i.name?Hl(i.name)?new n(k(i.name)):new n(void 0,[new S(x.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):O(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Ref)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):O(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(D(i,r.Ref))return i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(O(i,r.Ref)){let e=[...i.args],t;return _(e)instanceof V?t=_(e):e[0]instanceof V&&(t=e[0]),t?Cb(t):new n({})}return n.create(e)}};var Tb=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 I?[new S(x.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof gd?[new S(x.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Bl(e)?[]:[new S(x.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new S(x.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Vl(e)?[]:[new S(x.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=C(e),n=t.getErrors();return Cc(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new S(x.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Kl(e.value)||n.push(new S(x.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 S(x.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{w(e.value)||n.push(new S(x.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new S(x.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof z);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 S(x.INVALID_COLUMN,`A column must have a type`,e.callee)),T(e.callee)||t.push(new S(x.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Zl(e.args[0])&&t.push(new S(x.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?(Wl(e.callee)||t.push(new S(x.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 S(x.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof R&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){if(!e.slice(0,-1).every($l)||!e.slice(-1).every(e=>$l(e)||e instanceof V))return e.map(e=>new S(x.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let t;_(e)instanceof V&&(t=e.pop());let n=C(t),r=n.getErrors(),a=n.getValue();e.forEach(e=>{let t=(j(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(a,(e,t)=>{switch(t){case i.Note:e.length>1&&r.push(...e.map(e=>new S(x.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{w(e.value)||r.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Yl(e.value)||r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&r.push(new S(x.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 S(x.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 S(x.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 S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{ql(e.value)||r.push(new S(x.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 sd||r.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new S(x.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 S(x.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Eb(e){let t=C(e),r=t.getErrors(),a=t.getValue();return Cc(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new S(x.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Kl(e.value)||r.push(new S(x.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 S(x.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{w(e.value)||r.push(new S(x.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new S(x.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Db(e){if(!e.slice(0,-1).every($l)||!e.slice(-1).every(e=>$l(e)||e instanceof V))return new n({},e.map(e=>new S(x.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;_(e)instanceof V&&(t=e.pop());let r=C(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(j(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new S(x.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{w(e.value)||a.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Yl(e.value)||a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.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 S(x.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 S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{ql(e.value)||a.push(new S(x.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 sd||a.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new S(x.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(o,a)}const Ob={validateNode(t,i){return D(i,r.Table)?n.create(void 0,new Tb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(D(i,r.Table)){if(!i.name)return new n(void 0,[new S(x.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof gd)return new n(void 0,[new S(x.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=k(i.name);return e?.length===1&&e.unshift(b),new n(e)}if(O(i,r.Table)){if(Wl(i.callee)){let e=j(i.callee.expression);return new n(e?[e]:void 0)}let e=j(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return D(i,r.Table)?i.alias?Vl(i.alias)?new n(j(i.alias)):new n(void 0,[new S(x.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):O(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Table)?i.attributeList?Eb(i.attributeList):new n({}):O(i,r.Table)?Db(i.args.slice(1)):n.create(e)}};var kb=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 I?[new S(x.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:Hl(e)?[]:[new S(x.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new S(x.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=C(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 S(x.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Kl(e.value)||n.push(new S(x.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 S(x.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!w(e.value)).forEach(e=>{n.push(new S(x.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...t.map(t=>new S(x.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return n}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof z);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&k(e.callee)===void 0&&t.push(new S(x.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 S(x.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 S(x.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Ab(e){let t=C(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 S(x.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Kl(e.value)||r.push(new S(x.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 S(x.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!w(e.value)).forEach(e=>{r.push(new S(x.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 S(x.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return new n(a,r)}const jb={validateNode(t,i){return D(i,r.TableGroup)?n.create(void 0,new kb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(D(i,r.TableGroup))return i.name?Hl(i.name)?new n(k(i.name)):new n(void 0,[new S(x.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new S(x.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(O(i,r.TableGroup)){let e=k(i.callee);return e?.length===1&&e.unshift(b),new n(e)}return n.create(e)},nodeAlias(t,i){return D(i,r.TableGroup)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):O(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.TableGroup)?Ab(i.attributeList):O(i,r.TableGroup)?new n({}):n.create(e)}};var Mb=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 I?[new S(x.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:Hl(e)?[]:[new S(x.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new S(x.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=C(e),n=t.getErrors();return Cc(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new S(x.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Kl(e.value)||n.push(new S(x.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 S(x.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{w(e.value)||n.push(new S(x.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new S(x.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof z);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 S(x.INVALID_COLUMN,`A column must have a type`,e.callee)),T(e.callee)||t.push(new S(x.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Zl(e.args[0])&&t.push(new S(x.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=_(e);if(!e.slice(0,-1).every($l)||!($l(t)||t instanceof V))return e.map(e=>new S(x.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;_(e)instanceof V&&(n=e.pop());let r=C(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(j(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{w(e.value)||a.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Yl(e.value)||a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.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 S(x.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 S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{ql(e.value)||a.push(new S(x.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 sd||a.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new S(x.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 S(x.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Nb(e){let t=C(e),r=t.getErrors(),a=t.getValue();return Cc(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new S(x.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Kl(e.value)||r.push(new S(x.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 S(x.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{w(e.value)||r.push(new S(x.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new S(x.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Pb(e){let t=_(e);if(e.length>0&&(!e.slice(0,-1).every($l)||!($l(t)||t instanceof V)))return new n({},e.map(e=>new S(x.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;_(e)instanceof V&&(r=e.pop());let a=C(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(j(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{w(e.value)||o.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Yl(e.value)||o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&o.push(new S(x.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 S(x.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 S(x.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 S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{ql(e.value)||o.push(new S(x.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 sd||o.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>o.push(new S(x.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(s,o)}const Fb={validateNode(t,i){return D(i,r.TablePartial)?n.create(void 0,new Mb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(D(i,r.TablePartial))return i.name?Hl(i.name)?new n(k(i.name)):new n(void 0,[new S(x.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new S(x.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(O(i,r.TablePartial)){let e=j(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return D(i,r.TablePartial)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(j(i.alias)):O(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.TablePartial)?Nb(i.attributeList):O(i,r.TablePartial)?Pb(i.args.slice(1)):n.create(e)}};var Ib=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof ed?[]:[new S(x.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.importPath&&!kl.isRelative(this.declarationNode.importPath.value)&&e.push(new S(x.INVALID_USE_SPECIFIER_NAME,`Import path must be a relative path (starting with './' or '../')`,this.declarationNode.importPath)),this.declarationNode.specifiers instanceof fd)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 S(x.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Au))||t.push(new S(x.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 Lb={validateNode(t,r){return r instanceof td?n.create(void 0,new Ib(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!nu(r))return n.create(e);let i=k(r.name);return!i||i.length===0?n.create(void 0,[new S(x.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Au.TableGroup)&&i.length>1?n.create(i,[new S(x.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Au.TablePartial)&&i.length>1?n.create(i,[new S(x.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Au.Note)&&i.length>1?n.create(i,[new S(x.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Au.Schema)&&i.unshift(b),new n(i))},nodeAlias(t,r){return nu(r)?r.alias?Vl(r.alias)?new n(j(r.alias)):new n(void 0,[new S(x.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 td?n.create({}):n.create(e)}},Rb=[Ob,ub,bb,fb,rb,wb,vb,jb,Fb,mb,cb,gb,Lb,ob];function zb(t,...r){for(let n of Rb){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function Bb(r){let i=zb(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function Vb(r){let i=zb(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function Hb(r){let i=zb(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function Ub(r){let i=zb(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var Wb=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())})},Gb=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Kb(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}),Gb&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function qb(e,t,...n){return Kb(t,n)}function Jb(e){}var Yb;const Xb=`en`;var Zb=!1,Qb=!1,$b=!1,ex=!1,tx=!1,nx=!1,rx=!1,ix=void 0,ax=`en`,ox=void 0;const sx=typeof self==`object`?self:typeof global==`object`?global:{};var cx=void 0;sx.vscode!==void 0&&sx.vscode.process!==void 0?cx=sx.vscode.process:typeof process<`u`&&(cx=process);var lx=typeof(Yb=cx?.versions)?.electron==`string`&&cx?.type===`renderer`;if(typeof navigator==`object`&&!lx)ox=navigator.userAgent,Zb=ox.indexOf(`Windows`)>=0,Qb=ox.indexOf(`Macintosh`)>=0,(ox.indexOf(`Macintosh`)>=0||ox.indexOf(`iPad`)>=0||ox.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,$b=ox.indexOf(`Linux`)>=0,ox?.indexOf(`Mobi`),tx=!0,ix=(qb({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),`en`),navigator.language;else if(typeof cx==`object`){Zb=cx.platform===`win32`,Qb=cx.platform===`darwin`,$b=cx.platform===`linux`,$b&&cx.env.SNAP&&cx.env.SNAP_REVISION,cx.env.CI||cx.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=cx.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 ux=Zb,dx=Qb,fx=tx&&typeof sx.importScripts==`function`,px=ox,mx=typeof sx.postMessage==`function`&&!sx.importScripts,hx=(()=>{if(mx){let e=[];sx.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}),sx.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})(),gx=!!(px&&px.indexOf(`Chrome`)>=0),_x=!!(px&&px.indexOf(`Firefox`)>=0),vx=!!(!gx&&px&&px.indexOf(`Safari`)>=0),yx=!!(px&&px.indexOf(`Edg/`)>=0),bx=!!(px&&px.indexOf(`Android`)>=0);var xx;if(sx.vscode!==void 0&&sx.vscode.process!==void 0){let e=sx.vscode.process;xx={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else xx=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 ux?`win32`:dx?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};const Sx=xx.cwd,Cx=xx.env,wx=xx.platform;var Tx=65,Ex=97,Dx=90,Ox=122,kx=46,Ax=47,jx=92,Mx=58,Nx=63,Px=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 Fx(e,t){if(typeof e!=`object`||!e)throw new Px(t,`Object`,e)}function Ix(e,t){if(typeof e!=`string`)throw new Px(t,`string`,e)}var Lx=wx===`win32`;function q(e){return e===Ax||e===jx}function Rx(e){return e===Ax}function zx(e){return e>=Tx&&e<=Dx||e>=Ex&&e<=Ox}function Bx(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=Ax;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==kx||i.charCodeAt(i.length-2)!==kx){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===kx&&s!==-1?++s:s=-1}return i}function Vx(e,t){Fx(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 Hx={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],Ix(a,`path`),a.length===0)continue}else t.length===0?a=Sx():(a=Cx[`=${t}`]||Sx(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===jx)&&(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 zx(u)&&a.charCodeAt(1)===Mx&&(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=Bx(n,!r,`\\`,q),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){Ix(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return Rx(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 zx(a)&&e.charCodeAt(1)===Mx&&(r=e.slice(0,2),n=2,t>2&&q(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?Bx(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){Ix(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return q(n)||t>2&&zx(n)&&e.charCodeAt(1)===Mx&&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];Ix(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 Hx.normalize(t)},relative(e,t){if(Ix(e,`from`),Ix(t,`to`),e===t)return``;let n=Hx.resolve(e),r=Hx.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===jx;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===jx;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===jx;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===jx;)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===jx&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===jx)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===jx?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)===jx)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===jx&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=Hx.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===jx){if(t.charCodeAt(1)===jx){let e=t.charCodeAt(2);if(e!==Nx&&e!==kx)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(zx(t.charCodeAt(0))&&t.charCodeAt(1)===Mx&&t.charCodeAt(2)===jx)return`\\\\?\\${t}`;return e},dirname(e){Ix(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 zx(i)&&e.charCodeAt(1)===Mx&&(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&&Ix(t,`ext`),Ix(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&zx(e.charCodeAt(0))&&e.charCodeAt(1)===Mx&&(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){Ix(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Mx&&zx(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===kx?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:Vx.bind(null,`\\`),parse(e){Ix(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(zx(i)&&e.charCodeAt(1)===Mx){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===kx?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 Ux=(()=>{if(Lx){let e=/\\/g;return()=>{let t=Sx().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Sx()})();const Wx={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:Ux();Ix(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Ax)}return t=Bx(t,!n,`/`,Rx),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(Ix(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Ax,n=e.charCodeAt(e.length-1)===Ax;return e=Bx(e,!t,`/`,Rx),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return Ix(e,`path`),e.length>0&&e.charCodeAt(0)===Ax},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];Ix(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:Wx.normalize(t)},relative(e,t){if(Ix(e,`from`),Ix(t,`to`),e===t||(e=Wx.resolve(e),t=Wx.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===Ax&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===Ax)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Ax?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Ax)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(Ix(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Ax,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Ax){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&&Ix(t,`ext`),Ix(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===Ax){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)===Ax){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Ix(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===Ax){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===kx?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:Vx.bind(null,`/`),parse(e){Ix(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Ax,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===Ax){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===kx?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};Wx.win32=Hx.win32=Hx,Wx.posix=Hx.posix=Wx;const Gx=Lx?Hx.normalize:Wx.normalize,Kx=Lx?Hx.resolve:Wx.resolve,qx=Lx?Hx.relative:Wx.relative,Jx=Lx?Hx.dirname:Wx.dirname,Yx=Lx?Hx.basename:Wx.basename,Xx=Lx?Hx.extname:Wx.extname,Zx=Lx?Hx.sep:Wx.sep;var Qx=/^\w[\w\d+.-]*$/,$x=/^\//,eS=/^\/\//;function tS(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&&!Qx.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!$x.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(eS.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 nS(e,t){return!e&&!t?`file`:e}function rS(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==iS&&(t=iS+t):t=iS;break}return t}var J=``,iS=`/`,aS=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,oS=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=nS(e,a),this.authority=t||J,this.path=rS(this.scheme,n||J),this.query=r||J,this.fragment=i||J,tS(this,a))}get fsPath(){return fS(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 cS(t,n,r,i,a)}static parse(e,t=!1){let n=aS.exec(e);return n?new cS(n[2]||J,gS(n[4]||J),gS(n[5]||J),gS(n[7]||J),gS(n[9]||J),t):new cS(J,J,J,J,J)}static file(e){let t=J;if(ux&&(e=e.replace(/\\/g,iS)),e[0]===iS&&e[1]===iS){let n=e.indexOf(iS,2);n===-1?(t=e.substring(2),e=iS):(t=e.substring(2,n),e=e.substring(n)||iS)}return new cS(`file`,t,e,J,J)}static from(e,t){return new cS(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=ux&&t.scheme===`file`?e.file(Hx.join(fS(t,!0),...n)).path:Wx.join(t.path,...n),t.with({path:r})}toString(e=!1){return pS(this,e)}toJSON(){return this}static revive(t){if(t){if(t instanceof e)return t;{let e=new cS(t);return e._formatted=t.external??null,e._fsPath=t._sep===sS?t.fsPath??null:null,e}}else return t}},sS=ux?1:void 0,cS=class extends oS{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=fS(this,!1),this._fsPath}toString(e=!1){return e?pS(this,!0):(this._formatted||=pS(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=sS),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}},lS={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 uS(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=lS[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 dS(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+=lS[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function fS(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,ux&&(n=n.replace(/\//g,`\\`)),n}function pS(e,t){let n=t?dS:uS,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=iS,r+=iS),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:uS(c,!1,!1)),r}function mS(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+mS(e.substr(3)):e}}var hS=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function gS(e){return e.match(hS)?e.replace(hS,e=>mS(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}({}),_S=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 vS(e,t){return e.getOffsetAt(t)}function yS(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 bS=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=kl.fromUri(String(e.uri)),a=vS(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);if(n.hasValue(t))continue;let i=n.getValue();if(!i)continue;let a;if(i.declaration&&[F.PRIMARY_EXPRESSION,F.VARIABLE].includes(e.kind)&&({declaration:a}=i),a){let{startPos:e,endPos:t}=a,n=r;return r&&a.filepath&&(n=oS.parse(a.filepath.toUri())),[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}]}}return[]}},xS=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`?_S.Error:_S.Warning}},SS=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=kl.fromUri(String(r)),a=vS(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[F.ELEMENT_DECLARATION,F.FUNCTION_APPLICATION,F.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=oS.parse(e.filepath.toUri())),{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 CS(e,t){return e>=t.start&&e<t.end}function wS(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 TS(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 rd)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=j(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?j(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof fd&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof fd)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function ES(e,t,n,r,i,a){let o=TS(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:DS(Vc([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
|
|
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 yy(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`'${vy(e)}'`;let{value:t,type:n}=e;if(t==null||xf(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(xf(n)){let e=J_(t);return e===null?`\`${t}\``:e?`true`:`false`}if(bf(n)){let e=W_(t);return e===null?`\`${t}\``:String(e)}if(wf(n)){let e=ev(t);return e===null?`\`${t}\``:`'${vy(e)}'`}let r=X_(t);return r===null?`\`${t}\``:`'${vy(r)}'`}function by(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?_y(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function xy(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 Sy(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 Nu&&n.isKind(N.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 Cy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Rd).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof Zu?[...r.getErrors(),new S(x.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():[])}},wy=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=M(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}=Eu(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new S(x.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]=v(e.body,e=>e instanceof z);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:Tu(A(e.body instanceof B?e.body.body[0].callee:e.body.callee)),token:M(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(N.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=k(e.callee);return i.length>2&&n.push(new S(x.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=C(e).getValue();this.tableGroup.color=t.color?.length?Du(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Tu(A(n?.value)),token:M(n)},[]}};const Ty={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new S(x.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Ey={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return D(a,r.TableGroup)?new n(i.symbolFactory.create(Ru,{declaration:a,name:s},a.filepath)):O(a,r.TableGroup)?new n(i.symbolFactory.create(zu,{declaration:a,name:o?.map(gy).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(N.TableGroup)){let e=i.declaration;if(!(e instanceof I))return new n([]);let a=gu(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(N.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof I&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Ty.getFieldDuplicateError(e.name,r)),s.push(Ty.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(N.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!T(a)||!iu(a,r.TableGroup)||a.parent&&ou(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):Dy(i,s,a)},bindNode(i,a){if(!D(a,r.TableGroup))return n.create(e);let o=new Cy(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!D(o,r.TableGroup)||!(i instanceof Ru)?n.create(e):Ld(t,o)?new wy(t,i,a).interpret():n.create(void 0)}};function Dy(e,r,i){let a=Su(i)??``;if(!E(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Nu&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,N.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,N.Table,a);return s?n.create(s):new n(void 0,[new S(x.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=zd(e,i);if(o){if(o.isKind(N.Schema)){let t=e.lookupMembers(o,[N.Table,N.Schema],a);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,N.Schema,a);return s?n.create(s):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var Oy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof B?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof z)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof z);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(_(n)instanceof V){let e=C(_(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=vu(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return Rd(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():[])}},ky=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??M(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}=Eu(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=C(e).getValue(),n=hc(t[i.HeaderColor]);this.tablePartial.headerColor=n?Du(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Tu(A(r?.value)),token:M(r)},[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof z);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:Tu(A(e.body instanceof B?e.body.body[0].callee:e.body.callee)),token:M(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=Su(e.callee)??``,r.token=M(e);let o=ku(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 xd))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:M(n.rightToken())}}),r.checks=(c[i.Check]||[]).map(e=>({token:M(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 Ay={getDuplicateError(e,t,n){return new S(x.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},jy={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return D(a,r.TablePartial)?new n(i.symbolFactory.create(Vu,{declaration:a,name:o},a.filepath)):O(a,r.TablePartial)?new n(i.symbolFactory.create(Lu,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(N.TablePartial)){let e=a.declaration;if(!(e instanceof I))return new n([]);let r=gu(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(N.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof I&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(ly.getColumnDuplicateError(t,r)),s.push(ly.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(N.Column)&&D(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!T(o)&&!E(o)||!iu(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):au(o,1)?My(a,c,o):su(o,i.Ref)?Ny(a,c,o):Py(a,c,o)},bindNode(i,a){if(!D(a,r.TablePartial))return n.create(e);let o=new Oy(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 Vu?r.declaration instanceof I?new ky(t,r,i).interpret():n.create(void 0):n.create(e)}};function My(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return n.create(e.lookupMembers(t,N.Enum,i));let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Enum,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.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,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Ny(e,i,a){if(!T(a))return new n(void 0);let o=Su(a)??``;if(!E(a.parentNode)){let s=a.parent;if(s instanceof I&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,N.Column,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,N.Column,o);return c?n.create(c):new n(void 0,[new S(x.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=zd(e,a);if(s){if(s.isKind(N.Schema)){let t=e.lookupMembers(s,[N.Table,N.Schema],o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(N.Table)){let t=e.lookupMembers(s,N.Column,o);return t?n.create(t):new n(void 0,[new S(x.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(E(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,N.Schema,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,N.Table,o);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function Py(e,t,r){if(!T(r))return new n(void 0);let i=Su(r)??``;if(!E(r.parentNode))return jl.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,N.Enum,i));let a=zd(e,r);if(a){if(a.isKind(N.Schema)){let t=e.lookupMembers(a,[N.Enum,N.Schema],i);return t?n.create(t):new n(void 0,[new S(x.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(N.Enum)){let t=e.lookupMembers(a,N.EnumField,i);return t?n.create(t):new n(void 0,[new S(x.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(E(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,N.Schema,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,N.Enum,i);return a?n.create(a):new n(void 0,[new S(x.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}const Fy={symbolMembers(r,i){if(!i.isKind(N.Schema)||!(i instanceof Nu))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=Ly(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...Ry(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...By(r,i,e,t,c));for(let e of o.uses.selective){let n=Ly(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...Ry(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...By(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(N.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(N.TableGroup)))}}for(let t of e)u.push(...Hy(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof Zu&&e.isKind(N.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(N.Schema))continue;let t=e instanceof Zu?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof I&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(Iy(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function Iy(e,t,n,r){switch(e){case N.Table:return ly.getDuplicateError(t,n,r);case N.Enum:return $d.getDuplicateError(t,n,r);case N.TablePartial:return Ay.getDuplicateError(t,n,r);case N.TableGroup:return Ty.getDuplicateError(t,n,r);case N.DiagramView:return Gd.getDuplicateError(t,n,r);default:return new S(x.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function Ly(e,r,i,a){let o=$v(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(Nu,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function Ry(e,n,r,i=new Set){if(r.getSymbolKind()!==N.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(N.Schema))return[];let o=Yv.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:zy(e,n,r,a,i)}function zy(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(Zu,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(N.TableGroup)&&c.push(...Hy(e,n,t));for(let i of s.reuses.selective)if(c.push(...Ry(e,n,i,a)),$v(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(Zu,{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=Vy(e,t,n.qualifiedName);i&&c.push(...zy(e,n,r,i,a))}return c}function By(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=Vy(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(Zu,{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(Nu,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=Ly(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...Ry(e,n,r))}for(let{importPath:t}of d)l.push(...By(e,n,t,i,a,o));return l}function Vy(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 Hy(e,n,r){if(!r.isKind(N.TableGroup)||!(r instanceof Zu))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(N.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=k(n);if(!i||i.length===0)continue;let a=i.length<=1?[b]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=Uy(e,c,i);l&&s.push(e.symbolFactory.create(Zu,{kind:N.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function Uy(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(N.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(N.Table)&&e.name===a)}var Wy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof z)return[];let t=e.body.filter(e=>e instanceof I);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Gy=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=M(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=C(e).getValue();return this.note.headerColor=t.headercolor?.length?Du(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof z);return t.length!==1||n.length>0?[new S(x.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=na(e,`callee.expression.literal.value`,``);return this.note.content=Tu(t),[]}};const Ky={nodeSymbol(i,a){return!D(a,r.Note)||!(a.parentNode instanceof ed)?n.create(e):new n(i.symbolFactory.create(Bu,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(N.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return D(i,r.Note)?n.create(void 0,new Wy(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Bu?r.declaration instanceof I?new Gy(t,r,i).interpret():n.create(void 0):n.create(e)}},qy=[uy,ef,Lv,rf,Ad,Kv,Av,Ey,jy,Ky,Xv,Fy,Kd,Dv];function Jy(t,...r){for(let i of qy){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function Yy(r){let i=Jy(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Xy(r){let i=Jy(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Zy(r){let i=Jy(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Qy(r){let i=Jy(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function $y(r){let i=Jy(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function eb(r,i){let a=Jy(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function tb(r,i){let a=Jy(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var nb=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 S(x.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof ed?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new S(x.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=v(e.body,e=>e instanceof z);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 _(n)instanceof V&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof sd))&&t.push(new S(x.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=C(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 S(x.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{w(t.value)||n.push(new S(x.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new S(x.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const rb={validateNode(t,i){if(!D(i,r.Checks))return n.create(e);let a=new nb(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return D(i,r.Checks)?i.name?new n(void 0,[new S(x.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Checks)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Checks)?i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}};var ib=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 I&&this.declarationNode.parent.isKind(r.Project)?[]:[new S(x.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e?[new S(x.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof B)return[new S(x.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return w(e.callee)||t.push(new S(x.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 S(x.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function ab(e){return e instanceof I&&!!e.type?.value}const ob={validateNode(t,r){if(!ab(r))return n.create(e);let i=new ib(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return ab(r)?r.name?new n(void 0,[new S(x.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return ab(r)?r.alias?new n(void 0,[new S(x.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return ab(r)?r.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}};var sb=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 I?[new S(x.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Hl(e)?[]:[new S(x.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new S(x.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=C(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new S(x.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof z)return{errors:[new S(x.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=v(e.body,e=>e instanceof z),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Ql(e.callee)?e.args.length>0?e.args.map(e=>new S(x.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new S(x.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 S(x.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(Ul(e))return t.push(new S(x.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof B))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof z&&Ql(e.callee)),a=r.body.some(e=>e instanceof z&&!Ql(e.callee));return i&&a&&n.push(new Fl(x.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 B))return t;let n=e.body.body.filter(e=>e instanceof z);for(let e of n)Ql(e.callee)||(e.args.length>0||!k(e.callee))&&t.push(...e.args.map(e=>new S(x.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}};const cb={validateNode(t,i){if(!D(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new sb(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(D(i,r.DiagramView)){if(!i.name)return new n(void 0,[new S(x.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=k(i.name);return e?new n(e):new n(void 0)}else if(O(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=k(i.callee);return e?(e.length===1&&O(i,r.DiagramViewTables)&&e.unshift(b),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return D(i,r.DiagramView)?new n(void 0):n.create(e)}};var lb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof I?[new S(x.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Bl(e)?[]:[new S(x.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new S(x.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new S(x.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!T(n.callee)&&t.push(new S(x.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];_(e)instanceof V?(t.push(...this.validateFieldSettings(_(e))),e.pop()):e[0]instanceof V&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new S(x.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=C(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 S(x.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{w(e.value)||n.push(new S(x.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new S(x.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 ub={validateNode(t,i){return D(i,r.Enum)?n.create(void 0,new lb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(D(i,r.Enum)){if(!i.name)return new n(void 0,[new S(x.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Bl(i.name))return new n(void 0,[new S(x.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=k(i.name);return e?.length===1&&e.unshift(b),new n(e)}if(O(i,r.Enum)){let e=j(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return D(i,r.Enum)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):O(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(D(a,r.Enum))return a.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(O(a,r.Enum)){let e=[...a.args],t;if(_(e)instanceof V?t=_(e):e[0]instanceof V&&(t=e[0]),!t)return new n({});let r=C(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 S(x.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{w(e.value)||o.push(new S(x.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new S(x.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return 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(){let e=new S(x.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof ed?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new S(x.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=v(e.body,e=>e instanceof z);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 _(n)instanceof V&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof H;)e.argumentList&&yu(e.argumentList)===void 0&&t.push(new S(x.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;yu(e)===void 0&&t.push(new S(x.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=C(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 S(x.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{w(t.value)||n.push(new S(x.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new S(x.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new S(x.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new S(x.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{T(e.value)||n.push(new S(x.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new S(x.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const fb={validateNode(t,i){return D(i,r.Indexes)?n.create(void 0,new db(t,i).validate()):n.create(e)},nodeFullname(t,i){return D(i,r.Indexes)?i.name?new n(void 0,[new S(x.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):O(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Indexes)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):O(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(D(a,r.Indexes))return a.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(O(a,r.Indexes)){let e=[a.callee,...a.args],t;if(_(e)instanceof V&&(t=_(e)),!t)return new n({});let r=C(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 S(x.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{w(t.value)||o.push(new S(x.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 S(x.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{T(e.value)||o.push(new S(x.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new S(x.UNKNOWN_INDEX_SETTING,`Unknown index 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=this.declarationNode.parent;return!(e instanceof ed)&&!(e instanceof I&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project))?[new S(x.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 S(x.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new S(x.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new S(x.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),w(e[0].callee)||t.push(new S(x.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 S(x.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 mb={validateNode(t,i){return D(i,r.Note)?n.create(void 0,new pb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!D(i,r.Note))return n.create(e);if(!(i.parent instanceof ed))return i.name?new n(void 0,[new S(x.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new S(x.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof fd)return new n(void 0,[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=k(i.name);return a===void 0?new n(void 0,[new S(x.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return D(i,r.Note)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Note)?i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}};var hb=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 gb={validateNode(t,r){return ru(r)?n.create(void 0,new hb(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return ru(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return ru(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return ru(r)?new n({}):n.create(e)}};var _b=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 I?[new S(x.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Hl(e)?new n(k(e)):new n(void 0,[new S(x.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 S(x.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof z);return[...t.map(e=>new S(x.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 vb={validateNode(t,i){return D(i,r.Project)?n.create(void 0,new _b(t,i).validate()):n.create(e)},nodeFullname(t,i){return D(i,r.Project)?i.name?Hl(i.name)?new n(k(i.name)):new n(void 0,[new S(x.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):O(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Project)&&i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):O(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Project)?i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):O(i,r.Project)?new n({}):n.create(e)}};var yb=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 ed||e instanceof I&&e.isKind(r.Table)?[]:[new S(x.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof ed?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof H))return[new S(x.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||!Bl(e.callee))&&t.push(new S(x.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Xl(e.argumentList))&&t.push(new S(x.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Xl(e)?[new S(x.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return this.validateDataRow(e);let[t,n]=v(e.body,e=>e instanceof z);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 S(x.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof ld)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new S(x.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 S(x.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 hd||Jl(e)||w(e)||e instanceof sd)return!0;if(T(e)){let t=e.expression.variable.value.toLowerCase();return jl.includes(t)}if(E(e)){let t=k(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};const bb={validateNode(t,i){return D(i,r.Records)?n.create(void 0,new yb(t,i).validate()):n.create(e)},nodeFullname(i,a){if(D(a,r.Records)){if(a.name instanceof fd)return new n(void 0,[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof ed){if(!(a.name instanceof H))return new n(void 0,[new S(x.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||!Bl(a.name.callee))&&e.push(new S(x.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Xl(a.name.argumentList))&&e.push(new S(x.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=k(a.name.callee);return t?.length===1&&t.unshift(b),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Xl(a.name)?new n(e,[new S(x.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return O(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Records)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):O(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Records)?i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,i.attributeList)]):new n({}):O(i,r.Records)?new n({}):n.create(e)}};var xb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof ed?[]:[new S(x.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:Hl(e)?[]:[new S(x.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new S(x.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof z)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof z);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new S(x.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 S(x.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!cu(e.callee)&&t.push(new S(x.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&cu(e.callee)){let n=vu(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=vu(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new S(x.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new S(x.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!lu(e.callee)&&t.push(new S(x.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(_(n)instanceof V){let e=this.validateFieldSettings(_(n));t.push(...e),n.pop()}else n[0]instanceof V&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new S(x.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return Cb(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function Sb(e){if(!(T(e)&&e.expression.variable.kind!==y.QUOTED_STRING)&&!(e instanceof id))return!1;let t;if(t=e instanceof id?pu(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 Cb(e){let t=C(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 S(x.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Sb(t.value)||r.push(new S(x.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 S(x.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Kl(e.value)||r.push(new S(x.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new S(x.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}const wb={validateNode(t,i){return D(i,r.Ref)?n.create(void 0,new xb(t,i).validate()):n.create(e)},nodeFullname(t,i){return D(i,r.Ref)?i.name?Hl(i.name)?new n(k(i.name)):new n(void 0,[new S(x.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):O(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return D(i,r.Ref)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):O(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(D(i,r.Ref))return i.attributeList?new n({},[new S(x.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(O(i,r.Ref)){let e=[...i.args],t;return _(e)instanceof V?t=_(e):e[0]instanceof V&&(t=e[0]),t?Cb(t):new n({})}return n.create(e)}};var Tb=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 I?[new S(x.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof gd?[new S(x.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Bl(e)?[]:[new S(x.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new S(x.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Vl(e)?[]:[new S(x.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=C(e),n=t.getErrors();return Cc(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new S(x.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Kl(e.value)||n.push(new S(x.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 S(x.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{w(e.value)||n.push(new S(x.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new S(x.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof z);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 S(x.INVALID_COLUMN,`A column must have a type`,e.callee)),T(e.callee)||t.push(new S(x.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Zl(e.args[0])&&t.push(new S(x.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?(Wl(e.callee)||t.push(new S(x.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 S(x.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof R&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){if(!e.slice(0,-1).every($l)||!e.slice(-1).every(e=>$l(e)||e instanceof V))return e.map(e=>new S(x.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let t;_(e)instanceof V&&(t=e.pop());let n=C(t),r=n.getErrors(),a=n.getValue();e.forEach(e=>{let t=(j(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(a,(e,t)=>{switch(t){case i.Note:e.length>1&&r.push(...e.map(e=>new S(x.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{w(e.value)||r.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Yl(e.value)||r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&r.push(new S(x.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 S(x.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 S(x.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 S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&r.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{ql(e.value)||r.push(new S(x.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 sd||r.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new S(x.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 S(x.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Eb(e){let t=C(e),r=t.getErrors(),a=t.getValue();return Cc(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new S(x.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Kl(e.value)||r.push(new S(x.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 S(x.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{w(e.value)||r.push(new S(x.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new S(x.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Db(e){if(!e.slice(0,-1).every($l)||!e.slice(-1).every(e=>$l(e)||e instanceof V))return new n({},e.map(e=>new S(x.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;_(e)instanceof V&&(t=e.pop());let r=C(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(j(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new S(x.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{w(e.value)||a.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Yl(e.value)||a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.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 S(x.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 S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{ql(e.value)||a.push(new S(x.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 sd||a.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new S(x.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(o,a)}const Ob={validateNode(t,i){return D(i,r.Table)?n.create(void 0,new Tb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(D(i,r.Table)){if(!i.name)return new n(void 0,[new S(x.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof gd)return new n(void 0,[new S(x.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=k(i.name);return e?.length===1&&e.unshift(b),new n(e)}if(O(i,r.Table)){if(Wl(i.callee)){let e=j(i.callee.expression);return new n(e?[e]:void 0)}let e=j(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return D(i,r.Table)?i.alias?Vl(i.alias)?new n(j(i.alias)):new n(void 0,[new S(x.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):O(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.Table)?i.attributeList?Eb(i.attributeList):new n({}):O(i,r.Table)?Db(i.args.slice(1)):n.create(e)}};var kb=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 I?[new S(x.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:Hl(e)?[]:[new S(x.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new S(x.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=C(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 S(x.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Kl(e.value)||n.push(new S(x.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 S(x.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!w(e.value)).forEach(e=>{n.push(new S(x.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...t.map(t=>new S(x.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return n}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof z);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&k(e.callee)===void 0&&t.push(new S(x.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 S(x.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 S(x.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Ab(e){let t=C(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 S(x.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Kl(e.value)||r.push(new S(x.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 S(x.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!w(e.value)).forEach(e=>{r.push(new S(x.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 S(x.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return new n(a,r)}const jb={validateNode(t,i){return D(i,r.TableGroup)?n.create(void 0,new kb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(D(i,r.TableGroup))return i.name?Hl(i.name)?new n(k(i.name)):new n(void 0,[new S(x.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new S(x.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(O(i,r.TableGroup)){let e=k(i.callee);return e?.length===1&&e.unshift(b),new n(e)}return n.create(e)},nodeAlias(t,i){return D(i,r.TableGroup)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):O(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.TableGroup)?Ab(i.attributeList):O(i,r.TableGroup)?new n({}):n.create(e)}};var Mb=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 I?[new S(x.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof fd?[new S(x.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:Hl(e)?[]:[new S(x.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new S(x.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new S(x.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=C(e),n=t.getErrors();return Cc(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new S(x.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Kl(e.value)||n.push(new S(x.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 S(x.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{w(e.value)||n.push(new S(x.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new S(x.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof z)return[new S(x.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof z);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 S(x.INVALID_COLUMN,`A column must have a type`,e.callee)),T(e.callee)||t.push(new S(x.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Zl(e.args[0])&&t.push(new S(x.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=_(e);if(!e.slice(0,-1).every($l)||!($l(t)||t instanceof V))return e.map(e=>new S(x.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;_(e)instanceof V&&(n=e.pop());let r=C(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(j(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{w(e.value)||a.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Yl(e.value)||a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.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 S(x.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 S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&a.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{ql(e.value)||a.push(new S(x.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 sd||a.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new S(x.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 S(x.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Nb(e){let t=C(e),r=t.getErrors(),a=t.getValue();return Cc(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new S(x.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Kl(e.value)||r.push(new S(x.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 S(x.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{w(e.value)||r.push(new S(x.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new S(x.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Pb(e){let t=_(e);if(e.length>0&&(!e.slice(0,-1).every($l)||!($l(t)||t instanceof V)))return new n({},e.map(e=>new S(x.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;_(e)instanceof V&&(r=e.pop());let a=C(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(j(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{w(e.value)||o.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Yl(e.value)||o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&o.push(new S(x.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 S(x.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 S(x.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 S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof L&&e.value!==void 0&&o.push(new S(x.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 S(x.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{ql(e.value)||o.push(new S(x.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 sd||o.push(new S(x.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>o.push(new S(x.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(s,o)}const Fb={validateNode(t,i){return D(i,r.TablePartial)?n.create(void 0,new Mb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(D(i,r.TablePartial))return i.name?Hl(i.name)?new n(k(i.name)):new n(void 0,[new S(x.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new S(x.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(O(i,r.TablePartial)){let e=j(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return D(i,r.TablePartial)?i.alias?new n(void 0,[new S(x.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(j(i.alias)):O(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return D(i,r.TablePartial)?Nb(i.attributeList):O(i,r.TablePartial)?Pb(i.args.slice(1)):n.create(e)}};var Ib=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof ed?[]:[new S(x.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.importPath&&!kl.isRelative(this.declarationNode.importPath.value)&&e.push(new S(x.INVALID_USE_SPECIFIER_NAME,`Import path must be a relative path (starting with './' or '../')`,this.declarationNode.importPath)),this.declarationNode.specifiers instanceof fd)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 S(x.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Au))||t.push(new S(x.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 Lb={validateNode(t,r){return r instanceof td?n.create(void 0,new Ib(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!nu(r))return n.create(e);let i=k(r.name);return!i||i.length===0?n.create(void 0,[new S(x.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Au.TableGroup)&&i.length>1?n.create(i,[new S(x.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Au.TablePartial)&&i.length>1?n.create(i,[new S(x.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Au.Note)&&i.length>1?n.create(i,[new S(x.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Au.Schema)&&i.unshift(b),new n(i))},nodeAlias(t,r){return nu(r)?r.alias?Vl(r.alias)?new n(j(r.alias)):new n(void 0,[new S(x.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 td?n.create({}):n.create(e)}},Rb=[Ob,ub,bb,fb,rb,wb,vb,jb,Fb,mb,cb,gb,Lb,ob];function zb(t,...r){for(let n of Rb){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function Bb(r){let i=zb(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function Vb(r){let i=zb(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function Hb(r){let i=zb(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function Ub(r){let i=zb(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var Wb=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())})},Gb=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Kb(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}),Gb&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function qb(e,t,...n){return Kb(t,n)}function Jb(e){}var Yb;const Xb=`en`;var Zb=!1,Qb=!1,$b=!1,ex=!1,tx=!1,nx=!1,rx=!1,ix=void 0,ax=`en`,ox=void 0;const sx=typeof self==`object`?self:typeof global==`object`?global:{};var cx=void 0;sx.vscode!==void 0&&sx.vscode.process!==void 0?cx=sx.vscode.process:typeof process<`u`&&(cx=process);var lx=typeof(Yb=cx?.versions)?.electron==`string`&&cx?.type===`renderer`;if(typeof navigator==`object`&&!lx)ox=navigator.userAgent,Zb=ox.indexOf(`Windows`)>=0,Qb=ox.indexOf(`Macintosh`)>=0,(ox.indexOf(`Macintosh`)>=0||ox.indexOf(`iPad`)>=0||ox.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,$b=ox.indexOf(`Linux`)>=0,ox?.indexOf(`Mobi`),tx=!0,ix=(qb({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),`en`),navigator.language;else if(typeof cx==`object`){Zb=cx.platform===`win32`,Qb=cx.platform===`darwin`,$b=cx.platform===`linux`,$b&&cx.env.SNAP&&cx.env.SNAP_REVISION,cx.env.CI||cx.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=cx.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 ux=Zb,dx=Qb,fx=tx&&typeof sx.importScripts==`function`,px=ox,mx=typeof sx.postMessage==`function`&&!sx.importScripts,hx=(()=>{if(mx){let e=[];sx.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}),sx.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})(),gx=!!(px&&px.indexOf(`Chrome`)>=0),_x=!!(px&&px.indexOf(`Firefox`)>=0),vx=!!(!gx&&px&&px.indexOf(`Safari`)>=0),yx=!!(px&&px.indexOf(`Edg/`)>=0),bx=!!(px&&px.indexOf(`Android`)>=0);var xx;if(sx.vscode!==void 0&&sx.vscode.process!==void 0){let e=sx.vscode.process;xx={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else xx=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 ux?`win32`:dx?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};const Sx=xx.cwd,Cx=xx.env,wx=xx.platform;var Tx=65,Ex=97,Dx=90,Ox=122,kx=46,Ax=47,jx=92,Mx=58,Nx=63,Px=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 Fx(e,t){if(typeof e!=`object`||!e)throw new Px(t,`Object`,e)}function Ix(e,t){if(typeof e!=`string`)throw new Px(t,`string`,e)}var Lx=wx===`win32`;function q(e){return e===Ax||e===jx}function Rx(e){return e===Ax}function zx(e){return e>=Tx&&e<=Dx||e>=Ex&&e<=Ox}function Bx(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=Ax;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==kx||i.charCodeAt(i.length-2)!==kx){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===kx&&s!==-1?++s:s=-1}return i}function Vx(e,t){Fx(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 Hx={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],Ix(a,`path`),a.length===0)continue}else t.length===0?a=Sx():(a=Cx[`=${t}`]||Sx(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===jx)&&(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 zx(u)&&a.charCodeAt(1)===Mx&&(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=Bx(n,!r,`\\`,q),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){Ix(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return Rx(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 zx(a)&&e.charCodeAt(1)===Mx&&(r=e.slice(0,2),n=2,t>2&&q(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?Bx(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){Ix(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return q(n)||t>2&&zx(n)&&e.charCodeAt(1)===Mx&&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];Ix(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 Hx.normalize(t)},relative(e,t){if(Ix(e,`from`),Ix(t,`to`),e===t)return``;let n=Hx.resolve(e),r=Hx.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===jx;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===jx;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===jx;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===jx;)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===jx&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===jx)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===jx?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)===jx)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===jx&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=Hx.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===jx){if(t.charCodeAt(1)===jx){let e=t.charCodeAt(2);if(e!==Nx&&e!==kx)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(zx(t.charCodeAt(0))&&t.charCodeAt(1)===Mx&&t.charCodeAt(2)===jx)return`\\\\?\\${t}`;return e},dirname(e){Ix(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 zx(i)&&e.charCodeAt(1)===Mx&&(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&&Ix(t,`ext`),Ix(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&zx(e.charCodeAt(0))&&e.charCodeAt(1)===Mx&&(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){Ix(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Mx&&zx(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===kx?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:Vx.bind(null,`\\`),parse(e){Ix(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(zx(i)&&e.charCodeAt(1)===Mx){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===kx?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 Ux=(()=>{if(Lx){let e=/\\/g;return()=>{let t=Sx().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Sx()})();const Wx={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:Ux();Ix(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Ax)}return t=Bx(t,!n,`/`,Rx),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(Ix(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Ax,n=e.charCodeAt(e.length-1)===Ax;return e=Bx(e,!t,`/`,Rx),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return Ix(e,`path`),e.length>0&&e.charCodeAt(0)===Ax},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];Ix(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:Wx.normalize(t)},relative(e,t){if(Ix(e,`from`),Ix(t,`to`),e===t||(e=Wx.resolve(e),t=Wx.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===Ax&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===Ax)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Ax?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Ax)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(Ix(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Ax,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Ax){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&&Ix(t,`ext`),Ix(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===Ax){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)===Ax){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Ix(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===Ax){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===kx?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:Vx.bind(null,`/`),parse(e){Ix(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Ax,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===Ax){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===kx?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};Wx.win32=Hx.win32=Hx,Wx.posix=Hx.posix=Wx;const Gx=Lx?Hx.normalize:Wx.normalize,Kx=Lx?Hx.resolve:Wx.resolve,qx=Lx?Hx.relative:Wx.relative,Jx=Lx?Hx.dirname:Wx.dirname,Yx=Lx?Hx.basename:Wx.basename,Xx=Lx?Hx.extname:Wx.extname,Zx=Lx?Hx.sep:Wx.sep;var Qx=/^\w[\w\d+.-]*$/,$x=/^\//,eS=/^\/\//;function tS(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&&!Qx.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!$x.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(eS.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 nS(e,t){return!e&&!t?`file`:e}function rS(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==iS&&(t=iS+t):t=iS;break}return t}var J=``,iS=`/`,aS=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,oS=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=nS(e,a),this.authority=t||J,this.path=rS(this.scheme,n||J),this.query=r||J,this.fragment=i||J,tS(this,a))}get fsPath(){return fS(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 cS(t,n,r,i,a)}static parse(e,t=!1){let n=aS.exec(e);return n?new cS(n[2]||J,gS(n[4]||J),gS(n[5]||J),gS(n[7]||J),gS(n[9]||J),t):new cS(J,J,J,J,J)}static file(e){let t=J;if(ux&&(e=e.replace(/\\/g,iS)),e[0]===iS&&e[1]===iS){let n=e.indexOf(iS,2);n===-1?(t=e.substring(2),e=iS):(t=e.substring(2,n),e=e.substring(n)||iS)}return new cS(`file`,t,e,J,J)}static from(e,t){return new cS(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=ux&&t.scheme===`file`?e.file(Hx.join(fS(t,!0),...n)).path:Wx.join(t.path,...n),t.with({path:r})}toString(e=!1){return pS(this,e)}toJSON(){return this}static revive(t){if(t){if(t instanceof e)return t;{let e=new cS(t);return e._formatted=t.external??null,e._fsPath=t._sep===sS?t.fsPath??null:null,e}}else return t}},sS=ux?1:void 0,cS=class extends oS{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=fS(this,!1),this._fsPath}toString(e=!1){return e?pS(this,!0):(this._formatted||=pS(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=sS),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}},lS={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 uS(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=lS[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 dS(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+=lS[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function fS(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,ux&&(n=n.replace(/\//g,`\\`)),n}function pS(e,t){let n=t?dS:uS,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=iS,r+=iS),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:uS(c,!1,!1)),r}function mS(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+mS(e.substr(3)):e}}var hS=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function gS(e){return e.match(hS)?e.replace(hS,e=>mS(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}({}),_S=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 vS(e,t){return e.getOffsetAt(t)}function yS(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 bS=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=kl.fromUri(String(e.uri)),a=vS(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);if(n.hasValue(t))continue;let i=n.getValue();if(!i)continue;let a;if(i.declaration&&[F.PRIMARY_EXPRESSION,F.VARIABLE].includes(e.kind)&&({declaration:a}=i),a){let{startPos:e,endPos:t}=a,n=r;return r&&a.filepath&&(n=oS.parse(a.filepath.toUri())),[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}]}}return[]}},xS=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`?_S.Error:_S.Warning}},SS=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=kl.fromUri(String(r)),a=vS(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[F.ELEMENT_DECLARATION,F.FUNCTION_APPLICATION,F.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=oS.parse(e.filepath.toUri())),{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 CS(e,t){return e>=t.start&&e<t.end}function wS(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 TS(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 rd)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=j(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?j(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof fd&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof fd)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function ES(e,t,n,r,i,a){let o=TS(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:DS(Vc([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
|
|
7
7
|
`),removeRange:OS(a,e.startOffset,e.endOffset)}}return{topInsert:DS([l],s,`
|
|
8
8
|
`)}}function DS(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function OS(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]===`
|