@dbml/parse 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dbml-parse.js +18 -18
- package/dist/dbml-parse.mjs +4637 -4315
- package/dist/src/compiler/types.d.ts +2 -1
- package/dist/src/core/global_modules/metadata/bind.d.ts +11 -0
- package/dist/src/core/global_modules/metadata/index.d.ts +2 -0
- package/dist/src/core/global_modules/metadata/interpret.d.ts +14 -0
- package/dist/src/core/global_modules/metadata/utils.d.ts +29 -0
- package/dist/src/core/global_modules/note/interpret.d.ts +3 -1
- package/dist/src/core/global_modules/table/interpret.d.ts +12 -1
- package/dist/src/core/global_modules/tableGroup/interpret.d.ts +3 -1
- package/dist/src/core/global_modules/utils.d.ts +3 -0
- package/dist/src/core/local_modules/metadata/index.d.ts +2 -0
- package/dist/src/core/local_modules/metadata/utils.d.ts +7 -0
- package/dist/src/core/local_modules/metadata/validate.d.ts +14 -0
- package/dist/src/core/types/errors.d.ts +4 -1
- package/dist/src/core/types/keywords.d.ts +2 -1
- package/dist/src/core/types/nodes.d.ts +14 -3
- package/dist/src/core/types/schemaJson/types.d.ts +10 -1
- package/dist/src/core/types/symbol/metadata.d.ts +15 -2
- package/dist/src/core/types/symbol/symbols.d.ts +8 -0
- package/dist/src/core/utils/interpret.d.ts +12 -2
- package/dist/src/core/utils/tokens.d.ts +3 -0
- package/dist/src/core/utils/validate.d.ts +14 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/services/suggestions/provider.d.ts +19 -0
- package/package.json +4 -3
package/dist/dbml-parse.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(`PASS_THROUGH`),t=Symbol(`UNHANDLED`),n=class e{static create(t,n,r,i){return new e(t,n,r,i)}constructor(e,t,n,r){this.value=e,this.errors=t??[],this.warnings=n,this.infos=r}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings,this.infos):this}hasValue(e){return this.value===e}getFiltered(e){return this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings??[]}getInfos(){return this.infos??[]}chainFiltered(t,n){if(this.value===n)return new e(void 0,this.errors,this.warnings,this.infos);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()],o=[...this.getInfos(),...r.getInfos()];return new e(r.value,i,a,o)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()],a=[...this.getInfos(),...n.getInfos()];return new e(n.value,r,i,a)}mapFiltered(t,n){return this.value===n?new e(void 0,this.errors,this.warnings,this.infos):new e(t(this.value),this.errors,this.warnings,this.infos)}map(t){return new e(t(this.value),this.errors,this.warnings,this.infos)}},r=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e}({}),i=function(e){return e.Color=`color`,e.HeaderColor=`headercolor`,e.Note=`note`,e.PK=`pk`,e.PrimaryKey=`primary key`,e.Unique=`unique`,e.Ref=`ref`,e.NotNull=`not null`,e.Null=`null`,e.Increment=`increment`,e.Default=`default`,e.Name=`name`,e.Type=`type`,e.Check=`check`,e.Update=`update`,e.Delete=`delete`,e.Inactive=`inactive`,e}({}),a=typeof global==`object`&&global&&global.Object===Object&&global,o=typeof self==`object`&&self&&self.Object===Object&&self,s=a||o||Function(`return this`)(),c=s.Symbol,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function p(e){var t=u.call(e,f),n=e[f];try{e[f]=void 0;var r=!0}catch{}var i=d.call(e);return r&&(t?e[f]=n:delete e[f]),i}var m=Object.prototype.toString;function h(e){return m.call(e)}var ee=`[object Null]`,te=`[object Undefined]`,ne=c?c.toStringTag:void 0;function re(e){return e==null?e===void 0?te:ee:ne&&ne in Object(e)?p(e):h(e)}function ie(e){return typeof e==`object`&&!!e}var ae=`[object Symbol]`;function oe(e){return typeof e==`symbol`||ie(e)&&re(e)==ae}function se(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var ce=Array.isArray,le=1/0,ue=c?c.prototype:void 0,de=ue?ue.toString:void 0;function fe(e){if(typeof e==`string`)return e;if(ce(e))return se(e,fe)+``;if(oe(e))return de?de.call(e):``;var t=e+``;return t==`0`&&1/e==-le?`-0`:t}var pe=/\s/;function me(e){for(var t=e.length;t--&&pe.test(e.charAt(t)););return t}var he=/^\s+/;function ge(e){return e&&e.slice(0,me(e)+1).replace(he,``)}function _e(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var ve=NaN,ye=/^[-+]0x[0-9a-f]+$/i,be=/^0b[01]+$/i,xe=/^0o[0-7]+$/i,Se=parseInt;function Ce(e){if(typeof e==`number`)return e;if(oe(e))return ve;if(_e(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=_e(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=ge(e);var n=be.test(e);return n||xe.test(e)?Se(e.slice(2),n?2:8):ye.test(e)?ve:+e}var we=1/0,Te=17976931348623157e292;function Ee(e){return e?(e=Ce(e),e===we||e===-we?(e<0?-1:1)*Te:e===e?e:0):e===0?e:0}function De(e){var t=Ee(e),n=t%1;return t===t?n?t-n:t:0}function Oe(e){return e}var ke=`[object AsyncFunction]`,Ae=`[object Function]`,je=`[object GeneratorFunction]`,Me=`[object Proxy]`;function Ne(e){if(!_e(e))return!1;var t=re(e);return t==Ae||t==je||t==ke||t==Me}var Pe=s[`__core-js_shared__`],Fe=function(){var e=/[^.]+$/.exec(Pe&&Pe.keys&&Pe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Ie(e){return!!Fe&&Fe in e}var Le=Function.prototype.toString;function Re(e){if(e!=null){try{return Le.call(e)}catch{}try{return e+``}catch{}}return``}var ze=/[\\^$.*+?()[\]{}|]/g,Be=/^\[object .+?Constructor\]$/,Ve=Function.prototype,He=Object.prototype,Ue=Ve.toString,We=He.hasOwnProperty,Ge=RegExp(`^`+Ue.call(We).replace(ze,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function Ke(e){return!_e(e)||Ie(e)?!1:(Ne(e)?Ge:Be).test(Re(e))}function qe(e,t){return e?.[t]}function Je(e,t){var n=qe(e,t);return Ke(n)?n:void 0}var Ye=Je(s,`WeakMap`);function Xe(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}function Ze(){}var Qe=800,$e=16,et=Date.now;function tt(e){var t=0,n=0;return function(){var r=et(),i=$e-(r-n);if(n=r,i>0){if(++t>=Qe)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function nt(e){return function(){return e}}var rt=function(){try{var e=Je(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),it=tt(rt?function(e,t){return rt(e,`toString`,{configurable:!0,enumerable:!1,value:nt(t),writable:!0})}:Oe);function at(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1}function ot(e){return e!==e}function st(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function ct(e,t,n){return t===t?st(e,t,n):at(e,ot,n)}function lt(e,t){return!!(e!=null&&e.length)&&ct(e,t,0)>-1}var ut=9007199254740991,dt=/^(?:0|[1-9]\d*)$/;function ft(e,t){var n=typeof e;return t??=ut,!!t&&(n==`number`||n!=`symbol`&&dt.test(e))&&e>-1&&e%1==0&&e<t}function pt(e,t,n){t==`__proto__`&&rt?rt(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function mt(e,t){return e===t||e!==e&&t!==t}var ht=Math.max;function gt(e,t,n){return t=ht(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=ht(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Xe(e,this,s)}}function _t(e,t){return it(gt(e,t,Oe),e+``)}var vt=9007199254740991;function yt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=vt}function bt(e){return e!=null&&yt(e.length)&&!Ne(e)}var xt=Object.prototype;function St(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||xt)}function Ct(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var wt=`[object Arguments]`;function Tt(e){return ie(e)&&re(e)==wt}var Et=Object.prototype,Dt=Et.hasOwnProperty,Ot=Et.propertyIsEnumerable,kt=Tt(function(){return arguments}())?Tt:function(e){return ie(e)&&Dt.call(e,`callee`)&&!Ot.call(e,`callee`)};function At(){return!1}var jt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Mt=jt&&typeof module==`object`&&module&&!module.nodeType&&module,Nt=Mt&&Mt.exports===jt?s.Buffer:void 0,Pt=(Nt?Nt.isBuffer:void 0)||At,Ft=`[object Arguments]`,It=`[object Array]`,Lt=`[object Boolean]`,Rt=`[object Date]`,zt=`[object Error]`,Bt=`[object Function]`,Vt=`[object Map]`,Ht=`[object Number]`,Ut=`[object Object]`,Wt=`[object RegExp]`,Gt=`[object Set]`,Kt=`[object String]`,qt=`[object WeakMap]`,Jt=`[object ArrayBuffer]`,Yt=`[object DataView]`,Xt=`[object Float32Array]`,Zt=`[object Float64Array]`,Qt=`[object Int8Array]`,$t=`[object Int16Array]`,en=`[object Int32Array]`,tn=`[object Uint8Array]`,nn=`[object Uint8ClampedArray]`,rn=`[object Uint16Array]`,an=`[object Uint32Array]`,g={};g[Xt]=g[Zt]=g[Qt]=g[$t]=g[en]=g[tn]=g[nn]=g[rn]=g[an]=!0,g[Ft]=g[It]=g[Jt]=g[Lt]=g[Yt]=g[Rt]=g[zt]=g[Bt]=g[Vt]=g[Ht]=g[Ut]=g[Wt]=g[Gt]=g[Kt]=g[qt]=!1;function on(e){return ie(e)&&yt(e.length)&&!!g[re(e)]}function sn(e){return function(t){return e(t)}}var cn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,ln=cn&&typeof module==`object`&&module&&!module.nodeType&&module,un=ln&&ln.exports===cn&&a.process,dn=function(){try{return ln&&ln.require&&ln.require(`util`).types||un&&un.binding&&un.binding(`util`)}catch{}}(),fn=dn&&dn.isTypedArray,pn=fn?sn(fn):on,mn=Object.prototype.hasOwnProperty;function hn(e,t){var n=ce(e),r=!n&&kt(e),i=!n&&!r&&Pt(e),a=!n&&!r&&!i&&pn(e),o=n||r||i||a,s=o?Ct(e.length,String):[],c=s.length;for(var l in e)(t||mn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||ft(l,c)))&&s.push(l);return s}function gn(e,t){return function(n){return e(t(n))}}var _n=gn(Object.keys,Object),vn=Object.prototype.hasOwnProperty;function yn(e){if(!St(e))return _n(e);var t=[];for(var n in Object(e))vn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function bn(e){return bt(e)?hn(e):yn(e)}function xn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Sn=Object.prototype.hasOwnProperty;function Cn(e){if(!_e(e))return xn(e);var t=St(e),n=[];for(var r in e)r==`constructor`&&(t||!Sn.call(e,r))||n.push(r);return n}function wn(e){return bt(e)?hn(e,!0):Cn(e)}var Tn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,En=/^\w*$/;function Dn(e,t){if(ce(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||oe(e)?!0:En.test(e)||!Tn.test(e)||t!=null&&e in Object(t)}var On=Je(Object,`create`);function kn(){this.__data__=On?On(null):{},this.size=0}function An(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var jn=`__lodash_hash_undefined__`,Mn=Object.prototype.hasOwnProperty;function Nn(e){var t=this.__data__;if(On){var n=t[e];return n===jn?void 0:n}return Mn.call(t,e)?t[e]:void 0}var Pn=Object.prototype.hasOwnProperty;function Fn(e){var t=this.__data__;return On?t[e]!==void 0:Pn.call(t,e)}var In=`__lodash_hash_undefined__`;function Ln(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=On&&t===void 0?In:t,this}function Rn(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])}}Rn.prototype.clear=kn,Rn.prototype.delete=An,Rn.prototype.get=Nn,Rn.prototype.has=Fn,Rn.prototype.set=Ln;function zn(){this.__data__=[],this.size=0}function Bn(e,t){for(var n=e.length;n--;)if(mt(e[n][0],t))return n;return-1}var Vn=Array.prototype.splice;function Hn(e){var t=this.__data__,n=Bn(t,e);return n<0?!1:(n==t.length-1?t.pop():Vn.call(t,n,1),--this.size,!0)}function Un(e){var t=this.__data__,n=Bn(t,e);return n<0?void 0:t[n][1]}function Wn(e){return Bn(this.__data__,e)>-1}function Gn(e,t){var n=this.__data__,r=Bn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function Kn(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])}}Kn.prototype.clear=zn,Kn.prototype.delete=Hn,Kn.prototype.get=Un,Kn.prototype.has=Wn,Kn.prototype.set=Gn;var qn=Je(s,`Map`);function Jn(){this.size=0,this.__data__={hash:new Rn,map:new(qn||Kn),string:new Rn}}function Yn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Xn(e,t){var n=e.__data__;return Yn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function Zn(e){var t=Xn(this,e).delete(e);return this.size-=+!!t,t}function Qn(e){return Xn(this,e).get(e)}function $n(e){return Xn(this,e).has(e)}function er(e,t){var n=Xn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function tr(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])}}tr.prototype.clear=Jn,tr.prototype.delete=Zn,tr.prototype.get=Qn,tr.prototype.has=$n,tr.prototype.set=er;var nr=`Expected a function`;function rr(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(nr);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(rr.Cache||tr),n}rr.Cache=tr;var ir=500;function ar(e){var t=rr(e,function(e){return n.size===ir&&n.clear(),e}),n=t.cache;return t}var or=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,sr=/\\(\\)?/g,cr=ar(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(or,function(e,n,r,i){t.push(r?i.replace(sr,`$1`):n||e)}),t});function lr(e){return e==null?``:fe(e)}function ur(e,t){return ce(e)?e:Dn(e,t)?[e]:cr(lr(e))}var dr=1/0;function fr(e){if(typeof e==`string`||oe(e))return e;var t=e+``;return t==`0`&&1/e==-dr?`-0`:t}function pr(e,t){t=ur(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[fr(t[n++])];return n&&n==r?e:void 0}function mr(e,t,n){var r=e==null?void 0:pr(e,t);return r===void 0?n:r}function hr(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var gr=c?c.isConcatSpreadable:void 0;function _r(e){return ce(e)||kt(e)||!!(gr&&e&&e[gr])}function vr(e,t,n,r,i){var a=-1,o=e.length;for(n||=_r,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?vr(s,t-1,n,r,i):hr(i,s):r||(i[i.length]=s)}return i}function yr(e){return e!=null&&e.length?vr(e,1):[]}function br(){this.__data__=new Kn,this.size=0}function xr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Sr(e){return this.__data__.get(e)}function Cr(e){return this.__data__.has(e)}var wr=200;function Tr(e,t){var n=this.__data__;if(n instanceof Kn){var r=n.__data__;if(!qn||r.length<wr-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new tr(r)}return n.set(e,t),this.size=n.size,this}function Er(e){var t=this.__data__=new Kn(e);this.size=t.size}Er.prototype.clear=br,Er.prototype.delete=xr,Er.prototype.get=Sr,Er.prototype.has=Cr,Er.prototype.set=Tr;function Dr(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}function Or(){return[]}var kr=Object.prototype.propertyIsEnumerable,Ar=Object.getOwnPropertySymbols,jr=Ar?function(e){return e==null?[]:(e=Object(e),Dr(Ar(e),function(t){return kr.call(e,t)}))}:Or;function Mr(e,t,n){var r=t(e);return ce(e)?r:hr(r,n(e))}function Nr(e){return Mr(e,bn,jr)}var Pr=Je(s,`DataView`),Fr=Je(s,`Promise`),Ir=Je(s,`Set`),Lr=`[object Map]`,Rr=`[object Object]`,zr=`[object Promise]`,Br=`[object Set]`,Vr=`[object WeakMap]`,Hr=`[object DataView]`,Ur=Re(Pr),Wr=Re(qn),Gr=Re(Fr),Kr=Re(Ir),qr=Re(Ye),Jr=re;(Pr&&Jr(new Pr(new ArrayBuffer(1)))!=Hr||qn&&Jr(new qn)!=Lr||Fr&&Jr(Fr.resolve())!=zr||Ir&&Jr(new Ir)!=Br||Ye&&Jr(new Ye)!=Vr)&&(Jr=function(e){var t=re(e),n=t==Rr?e.constructor:void 0,r=n?Re(n):``;if(r)switch(r){case Ur:return Hr;case Wr:return Lr;case Gr:return zr;case Kr:return Br;case qr:return Vr}return t});var Yr=Jr,Xr=s.Uint8Array;function Zr(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 Qr=`__lodash_hash_undefined__`;function $r(e){return this.__data__.set(e,Qr),this}function ei(e){return this.__data__.has(e)}function ti(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new tr;++t<n;)this.add(e[t])}ti.prototype.add=ti.prototype.push=$r,ti.prototype.has=ei;function ni(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function ri(e,t){return e.has(t)}var ii=1,ai=2;function oi(e,t,n,r,i,a){var o=n&ii,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&ai?new ti: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(!ni(t,function(e,t){if(!ri(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===h||i(m,h,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}function si(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function ci(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var li=1,ui=2,di=`[object Boolean]`,fi=`[object Date]`,pi=`[object Error]`,mi=`[object Map]`,hi=`[object Number]`,gi=`[object RegExp]`,_i=`[object Set]`,vi=`[object String]`,yi=`[object Symbol]`,bi=`[object ArrayBuffer]`,xi=`[object DataView]`,Si=c?c.prototype:void 0,Ci=Si?Si.valueOf:void 0;function wi(e,t,n,r,i,a,o){switch(n){case xi:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case bi:return!(e.byteLength!=t.byteLength||!a(new Xr(e),new Xr(t)));case di:case fi:case hi:return mt(+e,+t);case pi:return e.name==t.name&&e.message==t.message;case gi:case vi:return e==t+``;case mi:var s=si;case _i:var c=r&li;if(s||=ci,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=ui,o.set(e,t);var u=oi(s(e),s(t),r,i,a,o);return o.delete(e),u;case yi:if(Ci)return Ci.call(e)==Ci.call(t)}return!1}var Ti=1,Ei=Object.prototype.hasOwnProperty;function Di(e,t,n,r,i,a){var o=n&Ti,s=Nr(e),c=s.length;if(c!=Nr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Ei.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 Oi=1,ki=`[object Arguments]`,Ai=`[object Array]`,ji=`[object Object]`,Mi=Object.prototype.hasOwnProperty;function Ni(e,t,n,r,i,a){var o=ce(e),s=ce(t),c=o?Ai:Yr(e),l=s?Ai:Yr(t);c=c==ki?ji:c,l=l==ki?ji:l;var u=c==ji,d=l==ji,f=c==l;if(f&&Pt(e)){if(!Pt(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Er,o||pn(e)?oi(e,t,n,r,i,a):wi(e,t,c,n,r,i,a);if(!(n&Oi)){var p=u&&Mi.call(e,`__wrapped__`),m=d&&Mi.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,ee=m?t.value():t;return a||=new Er,i(h,ee,n,r,a)}}return f?(a||=new Er,Di(e,t,n,r,i,a)):!1}function Pi(e,t,n,r,i){return e===t?!0:e==null||t==null||!ie(e)&&!ie(t)?e!==e&&t!==t:Ni(e,t,n,r,Pi,i)}var Fi=1,Ii=2;function Li(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 Er;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Pi(u,l,Fi|Ii,r,d):f))return!1}}return!0}function Ri(e){return e===e&&!_e(e)}function zi(e){for(var t=bn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Ri(i)]}return t}function Bi(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function Vi(e){var t=zi(e);return t.length==1&&t[0][2]?Bi(t[0][0],t[0][1]):function(n){return n===e||Li(n,e,t)}}function Hi(e,t){return e!=null&&t in Object(e)}function Ui(e,t,n){t=ur(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=fr(t[r]);if(!(a=e!=null&&n(e,o)))break;e=e[o]}return a||++r!=i?a:(i=e==null?0:e.length,!!i&&yt(i)&&ft(o,i)&&(ce(e)||kt(e)))}function Wi(e,t){return e!=null&&Ui(e,t,Hi)}var Gi=1,Ki=2;function qi(e,t){return Dn(e)&&Ri(t)?Bi(fr(e),t):function(n){var r=mr(n,e);return r===void 0&&r===t?Wi(n,e):Pi(t,r,Gi|Ki)}}function Ji(e){return function(t){return t?.[e]}}function Yi(e){return function(t){return pr(t,e)}}function Xi(e){return Dn(e)?Ji(fr(e)):Yi(e)}function Zi(e){return typeof e==`function`?e:e==null?Oe:typeof e==`object`?ce(e)?qi(e[0],e[1]):Vi(e):Xi(e)}function Qi(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}function $i(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 ea=$i();function ta(e,t){return e&&ea(e,t,bn)}function na(e,t){return function(n,r){if(n==null)return n;if(!bt(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var ra=na(ta);function ia(e,t,n,r){return ra(e,function(e,i,a){t(r,e,n(e),a)}),r}function aa(e,t){return function(n,r){var i=ce(n)?Qi:ia,a=t?t():{};return i(n,e,Zi(r,2),a)}}function oa(e){return ie(e)&&bt(e)}function sa(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 ca=200;function la(e,t,n,r){var i=-1,a=lt,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=se(t,sn(n))),r?(a=sa,o=!1):t.length>=ca&&(a=ri,o=!1,t=new ti(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 ua=_t(function(e,t){return oa(e)?la(e,vr(t,1,oa,!0)):[]});function _(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function da(e){return typeof e==`function`?e:Oe}function fa(e,t){var n=[];return ra(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function pa(e,t){return(ce(e)?Dr:fa)(e,Zi(t,3))}var ma=Math.max,ha=Math.min;function ga(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=De(n),i=n<0?ma(r+i,0):ha(i,r-1)),at(e,Zi(t,3),i,!0)}function _a(e){return e&&e.length?e[0]:void 0}function va(e,t){var n=-1,r=bt(e)?Array(e.length):[];return ra(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function ya(e,t){return(ce(e)?se:va)(e,Zi(t,3))}function ba(e,t){return vr(ya(e,t),1)}function xa(e,t){return e==null?e:ea(e,da(t),wn)}var Sa=Object.prototype.hasOwnProperty,Ca=aa(function(e,t,n){Sa.call(e,n)?e[n].push(t):pt(e,n,[t])}),wa=`[object Map]`,Ta=`[object Set]`,Ea=Object.prototype.hasOwnProperty;function Da(e){if(e==null)return!0;if(bt(e)&&(ce(e)||typeof e==`string`||typeof e.splice==`function`||Pt(e)||pn(e)||kt(e)))return!e.length;var t=Yr(e);if(t==wa||t==Ta)return!e.size;if(St(e))return!yn(e).length;for(var n in e)if(Ea.call(e,n))return!1;return!0}var Oa=aa(function(e,t,n){pt(e,n,t)}),v=aa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),ka=Ir&&1/ci(new Ir([,-0]))[1]==1/0?function(e){return new Ir(e)}:Ze,Aa=200;function ja(e,t,n){var r=-1,i=lt,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=sa;else if(a>=Aa){var l=t?null:ka(e);if(l)return ci(l);o=!1,i=ri,c=new ti}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}function Ma(e){return e&&e.length?ja(e):[]}function Na(e,t){return e&&e.length?ja(e,Zi(t,2)):[]}var Pa=Math.max;function Fa(e){if(!(e&&e.length))return[];var t=0;return e=Dr(e,function(e){if(oa(e))return t=Pa(e.length,t),!0}),Ct(t,function(t){return se(e,Ji(t))})}var Ia=_t(Fa),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 La(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:return!0;default:return!1}}function Ra(e){if(!e)return!1;switch(e){case`+`:case`-`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`?`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function za(e){return e!==void 0&&e.kind===`<op>`}var Ba=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 Va(e){return e.trailingTrivia.find(({kind:e})=>e===y.NEWLINE)!==void 0}function Ha(e,t){return t.leadingTrivia.find(({kind:e})=>e===y.NEWLINE)!==void 0||Va(e)}function Ua(e){return e.trailingTrivia.find(({kind:e})=>[y.SPACE,y.TAB].includes(e))!==void 0}function Wa(e){return e.trailingTrivia.length===0?e.end:Wa(_(e.trailingTrivia))}function Ga(e){return e.leadingTrivia.length===0?e.start:Ga(e.leadingTrivia[0])}function Ka(e){return[y.SINGLE_LINE_COMMENT,y.MULTILINE_COMMENT].includes(e.kind)}function qa(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`as`}function Ja(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`use`}function Ya(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`from`}function Xa(e){return e?.kind===y.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function Za(e){return!!e?.isInvalid}var Qa=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},$a=/^[A-Za-z]:\//;function eo(e=``){return e&&e.replace(/\\/g,`/`).replace($a,e=>e.toUpperCase())}var to=/^[/\\]{2}/,no=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,ro=/^[A-Za-z]:$/,io=/^\/([A-Za-z]:)?$/,ao=/.(\.[^./]+|\.)$/,oo=function(e){if(e.length===0)return`.`;e=eo(e);let t=e.match(to),n=fo(e),r=e[e.length-1]===`/`;return e=uo(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),ro.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!fo(e)?`/${e}`:e)},so=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 oo(t)};function co(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var lo=function(...e){e=e.map(e=>eo(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:co();!i||i.length===0||(t=`${i}/${t}`,n=fo(i))}return t=uo(t,!n),n&&!fo(t)?`/${t}`:t.length>0?t:`.`};function uo(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 fo=function(e){return no.test(e)},po=function(e){if(e===`..`)return``;let t=ao.exec(eo(e));return t&&t[1]||``},mo=function(e,t){let n=lo(e).replace(io,`$1`).split(`/`),r=lo(t).replace(io,`$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(`/`)},ho=function(e){let t=eo(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&ro.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(fo(e)?`/`:`.`)},go=function(e,t){let n=eo(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},_o=/^[a-zA-Z]:\//,vo=class e{constructor(e,t={}){let n=oo(e);if(!fo(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(lo(t,n))}static fromUri(t){try{let n=new URL(t);return new e(oo(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(oo(t))}}get absolute(){return this.path}get dirname(){return ho(this.path)}get basename(){return go(this.path)}get extname(){return po(this.path)}resolve(t){return new e(lo(this.dirname,t))}join(...t){return new e(so(this.path,...t))}relativeTo(e){let t=mo(e,this.path);return!t.startsWith(`./`)&&!t.startsWith(`../`)&&![`.`,`..`].includes(t)?`./${t}`:t}toString(){return this.path}equals(e){return this.path===e.path}isParentOf(e){if(this.path===e.path)return!1;let t=this.path.endsWith(`/`)?this.path:`${this.path}/`;return e.path.startsWith(t)}toUri(e={}){let t=e.protocol||this.protocol;if(!t)return this.path;let n=_o.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!fo(oo(e))}};function yo(e,t){if(!vo.isRelative(t))return;let n=vo.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:vo.from(n.absolute+`.dbml`)}var bo=[`null`,`true`,`false`],xo=`none`,So=`.dbml`,Co=[`-`,`+`],b=`public`,wo=vo.from(`/main.dbml`),To={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`])},Eo={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`])},Do={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},Oo={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`])},ko={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`])},Ao={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`])},jo={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function Mo(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function No(e,t){let n=Mo(e);return t?To[t].has(n):Object.values(To).some(e=>e.has(n))}function Po(e,t){let n=Mo(e);return t?Eo[t].has(n):Object.values(Eo).some(e=>e.has(n))}function Fo(e,t){return No(e,t)||Po(e,t)}function Io(e,t){let n=Mo(e);return t?Do[t].has(n):Object.values(Do).some(e=>e.has(n))}function Lo(e,t){let n=Mo(e);return t?Oo[t].has(n):Object.values(Oo).some(e=>e.has(n))}function Ro(e,t){let n=Mo(e);return t?ko[t].has(n):Object.values(ko).some(e=>e.has(n))}function zo(e,t){let n=Mo(e);return t?Ao[t].has(n):Object.values(Ao).some(e=>e.has(n))}function Bo(e,t){let n=Mo(e);return t?jo[t].has(n):Object.values(jo).some(e=>e.has(n))}function Vo(e,t){if(t)return`string`;if(No(e))return`integer`;if(Po(e))return`real`;if(Io(e))return`bool`;if(Lo(e))return`string`;let n=Mo(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:zo(e)?`datetime`:e}var Ho=class extends Error{},Uo=class extends Ho{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Wo=class extends Ho{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Go=class extends Ho{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Ko=class extends Ho{},qo=class extends Ho{constructor(e){super(`Invalid unit ${e}`)}},Jo=class extends Ho{},Yo=class extends Ho{constructor(){super(`Zone is an abstract class`)}},x=`numeric`,Xo=`short`,Zo=`long`,Qo={year:x,month:x,day:x},$o={year:x,month:Xo,day:x},es={year:x,month:Xo,day:x,weekday:Xo},ts={year:x,month:Zo,day:x},ns={year:x,month:Zo,day:x,weekday:Zo},rs={hour:x,minute:x},is={hour:x,minute:x,second:x},as={hour:x,minute:x,second:x,timeZoneName:Xo},os={hour:x,minute:x,second:x,timeZoneName:Zo},ss={hour:x,minute:x,hourCycle:`h23`},cs={hour:x,minute:x,second:x,hourCycle:`h23`},ls={hour:x,minute:x,second:x,hourCycle:`h23`,timeZoneName:Xo},us={hour:x,minute:x,second:x,hourCycle:`h23`,timeZoneName:Zo},ds={year:x,month:x,day:x,hour:x,minute:x},fs={year:x,month:x,day:x,hour:x,minute:x,second:x},ps={year:x,month:Xo,day:x,hour:x,minute:x},ms={year:x,month:Xo,day:x,hour:x,minute:x,second:x},hs={year:x,month:Xo,day:x,weekday:Xo,hour:x,minute:x},gs={year:x,month:Zo,day:x,hour:x,minute:x,timeZoneName:Xo},_s={year:x,month:Zo,day:x,hour:x,minute:x,second:x,timeZoneName:Xo},vs={year:x,month:Zo,day:x,weekday:Zo,hour:x,minute:x,timeZoneName:Zo},ys={year:x,month:Zo,day:x,weekday:Zo,hour:x,minute:x,second:x,timeZoneName:Zo},bs=class{get type(){throw new Yo}get name(){throw new Yo}get ianaName(){return this.name}get isUniversal(){throw new Yo}offsetName(e,t){throw new Yo}formatOffset(e,t){throw new Yo}offset(e){throw new Yo}equals(e){throw new Yo}get isValid(){throw new Yo}},xs=null,Ss=class e extends bs{static get instance(){return xs===null&&(xs=new e),xs}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return ll(e,t,n)}formatOffset(e,t){return pl(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},Cs=new Map;function ws(e){let t=Cs.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`}),Cs.set(e,t)),t}var Ts={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function Es(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 Ds(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=Ts[t];t===`era`?r[a]=i:S(a)||(r[a]=parseInt(i,10))}return r}var Os=new Map,ks=class e extends bs{static create(t){let n=Os.get(t);return n===void 0&&Os.set(t,n=new e(t)),n}static resetCache(){Os.clear(),Cs.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 ll(e,t,n,this.name)}formatOffset(e,t){return pl(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=ws(this.name),[r,i,a,o,s,c,l]=n.formatToParts?Ds(n,t):Es(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=al({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}},As={};function js(e,t={}){let n=JSON.stringify([e,t]),r=As[n];return r||(r=new Intl.ListFormat(e,t),As[n]=r),r}var Ms=new Map;function Ns(e,t={}){let n=JSON.stringify([e,t]),r=Ms.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),Ms.set(n,r)),r}var Ps=new Map;function Fs(e,t={}){let n=JSON.stringify([e,t]),r=Ps.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Ps.set(n,r)),r}var Is=new Map;function Ls(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=Is.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),Is.set(i,a)),a}var Rs=null;function zs(){return Rs||(Rs=new Intl.DateTimeFormat().resolvedOptions().locale,Rs)}var Bs=new Map;function Vs(e){let t=Bs.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Bs.set(e,t)),t}var Hs=new Map;function Us(e){let t=Hs.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...$s,...t}),Hs.set(e,t)}return t}function Ws(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=Ns(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=Ns(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Gs(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Ks(e){let t=[];for(let n=1;n<=12;n++){let r=w.utc(2009,n,1);t.push(e(r))}return t}function qs(e){let t=[];for(let n=1;n<=7;n++){let r=w.utc(2016,11,13+n);t.push(e(r))}return t}function Js(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Ys(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Vs(e.locale).numberingSystem===`latn`}var Xs=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=Fs(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return Zc(this.floor?Math.floor(e):tl(e,3),this.padTo)}},Zs=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&&ks.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=Ns(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()}},Qs=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Hc()&&(this.rtf=Ls(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):Ml(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},$s={firstDay:1,minimalDays:4,weekend:[6,7]},ec=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||bc.defaultLocale;return new e(o||(a?`en-US`:zs()),n||bc.defaultNumberingSystem,r||bc.defaultOutputCalendar,Jc(i)||bc.defaultWeekSettings,o)}static resetCache(){Rs=null,Ms.clear(),Ps.clear(),Is.clear(),Bs.clear(),Hs.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]=Ws(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Gs(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??=Ys(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,Jc(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 Js(this,e,vl,()=>{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]=Ks(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Js(this,e,Sl,()=>{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]=qs(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Js(this,void 0,()=>Cl,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[w.utc(2016,11,13,9),w.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Js(this,e,Dl,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[w.utc(-40,1,1),w.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 Xs(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new Zs(e,this.intl,t)}relFormatter(e={}){return new Qs(this.intl,this.isEnglish(),e)}listFormatter(e={}){return js(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Vs(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Uc()?Us(this.locale):$s}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})`}},tc=null,nc=class e extends bs{static get utcInstance(){return tc===null&&(tc=new e(0)),tc}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(ul(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${pl(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${pl(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return pl(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}},rc=class extends bs{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 ic(e,t){if(S(e)||e===null)return t;if(e instanceof bs)return e;if(Bc(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?Ss.instance:n===`utc`||n===`gmt`?nc.utcInstance:nc.parseSpecifier(n)||ks.create(e)}else if(Rc(e))return nc.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new rc(e)}var ac={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},oc={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]},sc=ac.hanidec.replace(/[\[|\]]/g,``).split(``);function cc(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(ac.hanidec)!==-1)t+=sc.indexOf(e[n]);else for(let e in oc){let[n,i]=oc[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var lc=new Map;function uc(){lc.clear()}function dc({numberingSystem:e},t=``){let n=e||`latn`,r=lc.get(n);r===void 0&&(r=new Map,lc.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${ac[n]}${t}`),r.set(t,i)),i}var fc=()=>Date.now(),pc=`system`,mc=null,hc=null,gc=null,_c=60,vc,yc=null,bc=class{static get now(){return fc}static set now(e){fc=e}static set defaultZone(e){pc=e}static get defaultZone(){return ic(pc,Ss.instance)}static get defaultLocale(){return mc}static set defaultLocale(e){mc=e}static get defaultNumberingSystem(){return hc}static set defaultNumberingSystem(e){hc=e}static get defaultOutputCalendar(){return gc}static set defaultOutputCalendar(e){gc=e}static get defaultWeekSettings(){return yc}static set defaultWeekSettings(e){yc=Jc(e)}static get twoDigitCutoffYear(){return _c}static set twoDigitCutoffYear(e){_c=e%100}static get throwOnInvalid(){return vc}static set throwOnInvalid(e){vc=e}static resetCaches(){ec.resetCache(),ks.resetCache(),w.resetCache(),uc()}},xc=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},Sc=[0,31,59,90,120,151,181,212,243,273,304,334],Cc=[0,31,60,91,121,152,182,213,244,274,305,335];function wc(e,t){return new xc(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function Tc(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 Ec(e,t,n){return n+(nl(e)?Cc:Sc)[t-1]}function Dc(e,t){let n=nl(e)?Cc:Sc,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function Oc(e,t){return(e-t+7)%7+1}function kc(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Ec(r,i,a),s=Oc(Tc(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=sl(l,t,n)):c>sl(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...ml(e)}}function Ac(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=Oc(Tc(r,1,t),n),s=rl(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=rl(l)):c>s?(l=r+1,c-=rl(r)):l=r;let{month:u,day:d}=Dc(l,c);return{year:l,month:u,day:d,...ml(e)}}function jc(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Ec(t,n,r),...ml(e)}}function Mc(e){let{year:t,ordinal:n}=e,{month:r,day:i}=Dc(t,n);return{year:t,month:r,day:i,...ml(e)}}function Nc(e,t){if(!S(e.localWeekday)||!S(e.localWeekNumber)||!S(e.localWeekYear)){if(!S(e.weekday)||!S(e.weekNumber)||!S(e.weekYear))throw new Ko(`Cannot mix locale-based week fields with ISO-based week fields`);return S(e.localWeekday)||(e.weekday=e.localWeekday),S(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),S(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 Pc(e,t=4,n=1){let r=zc(e.weekYear),i=Yc(e.weekNumber,1,sl(e.weekYear,t,n)),a=Yc(e.weekday,1,7);return r?i?a?!1:wc(`weekday`,e.weekday):wc(`week`,e.weekNumber):wc(`weekYear`,e.weekYear)}function Fc(e){let t=zc(e.year),n=Yc(e.ordinal,1,rl(e.year));return t?n?!1:wc(`ordinal`,e.ordinal):wc(`year`,e.year)}function Ic(e){let t=zc(e.year),n=Yc(e.month,1,12),r=Yc(e.day,1,il(e.year,e.month));return t?n?r?!1:wc(`day`,e.day):wc(`month`,e.month):wc(`year`,e.year)}function Lc(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Yc(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Yc(n,0,59),s=Yc(r,0,59),c=Yc(i,0,999);return a?o?s?c?!1:wc(`millisecond`,i):wc(`second`,r):wc(`minute`,n):wc(`hour`,t)}function S(e){return e===void 0}function Rc(e){return typeof e==`number`}function zc(e){return typeof e==`number`&&e%1==0}function Bc(e){return typeof e==`string`}function Vc(e){return Object.prototype.toString.call(e)===`[object Date]`}function Hc(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Uc(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Wc(e){return Array.isArray(e)?e:[e]}function Gc(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 Kc(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function qc(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Jc(e){if(e==null)return null;if(typeof e!=`object`)throw new Jo(`Week settings must be an object`);if(!Yc(e.firstDay,1,7)||!Yc(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Yc(e,1,7)))throw new Jo(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Yc(e,t,n){return zc(e)&&e>=t&&e<=n}function Xc(e,t){return e-t*Math.floor(e/t)}function Zc(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Qc(e){if(!(S(e)||e===null||e===``))return parseInt(e,10)}function $c(e){if(!(S(e)||e===null||e===``))return parseFloat(e)}function el(e){if(!(S(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function tl(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 nl(e){return e%4==0&&(e%100!=0||e%400==0)}function rl(e){return nl(e)?366:365}function il(e,t){let n=Xc(t-1,12)+1,r=e+(t-n)/12;return n===2?nl(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function al(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 ol(e,t,n){return-Oc(Tc(e,1,t),n)+t-1}function sl(e,t=4,n=1){let r=ol(e,t,n),i=ol(e+1,t,n);return(rl(e)-r+i)/7}function cl(e){return e>99?e:e>bc.twoDigitCutoffYear?1900+e:2e3+e}function ll(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 ul(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 dl(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Jo(`Invalid unit value ${e}`);return t}function fl(e,t){let n={};for(let r in e)if(qc(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=dl(i)}return n}function pl(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}${Zc(n,2)}:${Zc(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${Zc(n,2)}${Zc(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function ml(e){return Kc(e,[`hour`,`minute`,`second`,`millisecond`])}var hl=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],gl=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],_l=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function vl(e){switch(e){case`narrow`:return[..._l];case`short`:return[...gl];case`long`:return[...hl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`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 yl=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],bl=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],xl=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function Sl(e){switch(e){case`narrow`:return[...xl];case`short`:return[...bl];case`long`:return[...yl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var Cl=[`AM`,`PM`],wl=[`Before Christ`,`Anno Domini`],Tl=[`BC`,`AD`],El=[`B`,`A`];function Dl(e){switch(e){case`narrow`:return[...El];case`short`:return[...Tl];case`long`:return[...wl];default:return null}}function Ol(e){return Cl[e.hour<12?0:1]}function kl(e,t){return Sl(t)[e.weekday-1]}function Al(e,t){return vl(t)[e.month-1]}function jl(e,t){return Dl(t)[e.year<0?0:1]}function Ml(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 Nl(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var Pl={D:Qo,DD:$o,DDD:ts,DDDD:ns,t:rs,tt:is,ttt:as,tttt:os,T:ss,TT:cs,TTT:ls,TTTT:us,f:ds,ff:ps,fff:gs,ffff:vs,F:fs,FF:ms,FFF:_s,FFFF:ys},Fl=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 Pl[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 Zc(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?Ol(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?Al(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?kl(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?jl(t,e):a({era:e},`era`);return Nl(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 Nl(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Il=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Ll(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Rl(...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 zl(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 Bl(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Qc(t[n+i]);return[r,null,n+i]}}var Vl=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Hl=`(?:${Vl.source}?(?:\\[(${Il.source})\\])?)?`,Ul=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Wl=RegExp(`${Ul.source}${Hl}`),Gl=RegExp(`(?:[Tt]${Wl.source})?`),Kl=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,ql=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Jl=/(\d{4})-?(\d{3})/,Yl=Bl(`weekYear`,`weekNumber`,`weekDay`),Xl=Bl(`year`,`ordinal`),Zl=/(\d{4})-(\d\d)-(\d\d)/,Ql=RegExp(`${Ul.source} ?(?:${Vl.source}|(${Il.source}))?`),$l=RegExp(`(?: ${Ql.source})?`);function eu(e,t,n){let r=e[t];return S(r)?n:Qc(r)}function tu(e,t){return[{year:eu(e,t),month:eu(e,t+1,1),day:eu(e,t+2,1)},null,t+3]}function nu(e,t){return[{hours:eu(e,t,0),minutes:eu(e,t+1,0),seconds:eu(e,t+2,0),milliseconds:el(e[t+3])},null,t+4]}function ru(e,t){let n=!e[t]&&!e[t+1],r=ul(e[t+1],e[t+2]);return[{},n?null:nc.instance(r),t+3]}function iu(e,t){return[{},e[t]?ks.create(e[t]):null,t+1]}var au=RegExp(`^T?${Ul.source}$`),ou=/^-?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 su(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($c(n)),months:f($c(r)),weeks:f($c(i)),days:f($c(a)),hours:f($c(o)),minutes:f($c(s)),seconds:f($c(c),c===`-0`),milliseconds:f(el(l),d)}]}var cu={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function lu(e,t,n,r,i,a,o){let s={year:t.length===2?cl(Qc(t)):Qc(t),month:gl.indexOf(n)+1,day:Qc(r),hour:Qc(i),minute:Qc(a)};return o&&(s.second=Qc(o)),e&&(s.weekday=e.length>3?yl.indexOf(e)+1:bl.indexOf(e)+1),s}var uu=/^(?:(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 du(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=lu(t,i,r,n,a,o,s),p;return p=c?cu[c]:l?0:ul(u,d),[f,new nc(p)]}function fu(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var pu=/^(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$/,mu=/^(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$/,hu=/^(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 gu(e){let[,t,n,r,i,a,o,s]=e;return[lu(t,i,r,n,a,o,s),nc.utcInstance]}function _u(e){let[,t,n,r,i,a,o,s]=e;return[lu(t,s,n,r,i,a,o),nc.utcInstance]}var vu=Ll(Kl,Gl),yu=Ll(ql,Gl),bu=Ll(Jl,Gl),xu=Ll(Wl),Su=Rl(tu,nu,ru,iu),Cu=Rl(Yl,nu,ru,iu),wu=Rl(Xl,nu,ru,iu),Tu=Rl(nu,ru,iu);function Eu(e){return zl(e,[vu,Su],[yu,Cu],[bu,wu],[xu,Tu])}function Du(e){return zl(fu(e),[uu,du])}function Ou(e){return zl(e,[pu,gu],[mu,gu],[hu,_u])}function ku(e){return zl(e,[ou,su])}var Au=Rl(nu);function ju(e){return zl(e,[au,Au])}var Mu=Ll(Zl,$l),Nu=Ll(Ql),Pu=Rl(nu,ru,iu);function Fu(e){return zl(e,[Mu,Su],[Nu,Pu])}var Iu=`Invalid Duration`,Lu={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}},Ru={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},...Lu},zu=146097/400,Bu=146097/4800,Vu={years:{quarters:4,months:12,weeks:zu/7,days:zu,hours:zu*24,minutes:zu*24*60,seconds:zu*24*60*60,milliseconds:zu*24*60*60*1e3},quarters:{months:3,weeks:zu/28,days:zu/4,hours:zu*24/4,minutes:zu*24*60/4,seconds:zu*24*60*60/4,milliseconds:zu*24*60*60*1e3/4},months:{weeks:Bu/7,days:Bu,hours:Bu*24,minutes:Bu*24*60,seconds:Bu*24*60*60,milliseconds:Bu*24*60*60*1e3},...Lu},Hu=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Uu=Hu.slice(0).reverse();function Wu(e,t,n=!1){return new Ju({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 Gu(e,t){let n=t.milliseconds??0;for(let r of Uu.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Ku(e,t){let n=Gu(e,t)<0?-1:1;Hu.reduceRight((r,i)=>{if(S(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),Hu.reduce((n,r)=>{if(S(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function qu(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Ju=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Vu:Ru;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||ec.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 Jo(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:fl(t,e.normalizeUnit),loc:ec.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Rc(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Jo(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=ku(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]=ju(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 Jo(`need to specify a reason the Duration is invalid`);let r=t instanceof xc?t:new xc(t,n);if(bc.throwOnInvalid)throw new Go(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 qo(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?Fl.create(this.loc,n).formatDurationFromString(this,e):Iu}toHuman(e={}){if(!this.isValid)return Iu;let t=e.showZeros!==!1,n=Hu.map(n=>{let r=this.values[n];return S(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+=tl(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},w.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?Gu(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 Hu)(qc(n.values,e)||qc(this.values,e))&&(r[e]=n.get(e)+this.get(e));return Wu(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]=dl(e(this.values[n],n));return Wu(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...fl(t,e.normalizeUnit)};return Wu(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 Wu(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Ku(this.matrix,e),Wu(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=qu(this.normalize().shiftToAll().toObject());return Wu(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 Hu)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;Rc(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Rc(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 Ku(this.matrix,n),Wu(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 Wu(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=qu(this.values);return Wu(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 Hu)if(!t(this.values[n],e.values[n]))return!1;return!0}},Yu=`Invalid Interval`;function Xu(e,t){return!e||!e.isValid?Zu.invalid(`missing or invalid start`):!t||!t.isValid?Zu.invalid(`missing or invalid end`):t<e?Zu.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 Zu=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 Jo(`need to specify a reason the Interval is invalid`);let r=t instanceof xc?t:new xc(t,n);if(bc.throwOnInvalid)throw new Wo(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=$d(t),i=$d(n);return Xu(r,i)??new e({start:r,end:i})}static after(t,n){let r=Ju.fromDurationLike(n),i=$d(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Ju.fromDurationLike(n),i=$d(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=w.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=w.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Ju.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Ju.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($d).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=Ju.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()})`:Yu}[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=Qo,t={}){return this.isValid?Fl.create(this.s.loc.clone(t),e).formatInterval(this):Yu}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Yu}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Yu}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Yu}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Yu}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Ju.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Qu=class{static hasDST(e=bc.defaultZone){let t=w.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return ks.isValidZone(e)}static normalizeZone(e){return ic(e,bc.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||ec.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||ec.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||ec.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||ec.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||ec.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||ec.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||ec.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return ec.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return ec.create(t,null,`gregory`).eras(e)}static features(){return{relative:Hc(),localeWeek:Uc()}}};function $u(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Ju.fromMillis(r).as(`days`))}function ed(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=$u(e,t);return(n-n%7)/7}],[`days`,$u]],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 td(e,t,n,r){let[i,a,o,s]=ed(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=Ju.fromObject(a,r);return l.length>0?Ju.fromMillis(c,r).shiftTo(...l).plus(u):u}var nd=`missing Intl.DateTimeFormat.formatToParts support`;function C(e,t=e=>e){return{regex:e,deser:([e])=>t(cc(e))}}var rd=`[ \xA0]`,id=new RegExp(rd,`g`);function ad(e){return e.replace(/\./g,`\\.?`).replace(id,rd)}function od(e){return e.replace(/\./g,``).replace(id,` `).toLowerCase()}function sd(e,t){return e===null?null:{regex:RegExp(e.map(ad).join(`|`)),deser:([n])=>e.findIndex(e=>od(n)===od(e))+t}}function cd(e,t){return{regex:e,deser:([,e,t])=>ul(e,t),groups:t}}function ld(e){return{regex:e,deser:([e])=>e}}function ud(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function dd(e,t){let n=dc(t),r=dc(t,`{2}`),i=dc(t,`{3}`),a=dc(t,`{4}`),o=dc(t,`{6}`),s=dc(t,`{1,2}`),c=dc(t,`{1,3}`),l=dc(t,`{1,6}`),u=dc(t,`{1,9}`),d=dc(t,`{2,4}`),f=dc(t,`{4,6}`),p=e=>({regex:RegExp(ud(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return sd(t.eras(`short`),0);case`GG`:return sd(t.eras(`long`),0);case`y`:return C(l);case`yy`:return C(d,cl);case`yyyy`:return C(a);case`yyyyy`:return C(f);case`yyyyyy`:return C(o);case`M`:return C(s);case`MM`:return C(r);case`MMM`:return sd(t.months(`short`,!0),1);case`MMMM`:return sd(t.months(`long`,!0),1);case`L`:return C(s);case`LL`:return C(r);case`LLL`:return sd(t.months(`short`,!1),1);case`LLLL`:return sd(t.months(`long`,!1),1);case`d`:return C(s);case`dd`:return C(r);case`o`:return C(c);case`ooo`:return C(i);case`HH`:return C(r);case`H`:return C(s);case`hh`:return C(r);case`h`:return C(s);case`mm`:return C(r);case`m`:return C(s);case`q`:return C(s);case`qq`:return C(r);case`s`:return C(s);case`ss`:return C(r);case`S`:return C(c);case`SSS`:return C(i);case`u`:return ld(u);case`uu`:return ld(s);case`uuu`:return C(n);case`a`:return sd(t.meridiems(),0);case`kkkk`:return C(a);case`kk`:return C(d,cl);case`W`:return C(s);case`WW`:return C(r);case`E`:case`c`:return C(n);case`EEE`:return sd(t.weekdays(`short`,!1),1);case`EEEE`:return sd(t.weekdays(`long`,!1),1);case`ccc`:return sd(t.weekdays(`short`,!0),1);case`cccc`:return sd(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return cd(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return cd(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return ld(/[a-z_+-/]{1,256}?/i);case` `:return ld(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:nd};return m.token=e,m}var fd={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 pd(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=fd[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function md(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function hd(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(qc(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 gd(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 S(e.z)||(n=ks.create(e.z)),S(e.Z)||(n||=new nc(e.Z),r=e.Z),S(e.q)||(e.M=(e.q-1)*3+1),S(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),S(e.u)||(e.S=el(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var _d=null;function vd(){return _d||=w.fromMillis(1555555555555),_d}function yd(e,t){if(e.literal)return e;let n=wd(Fl.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function bd(e,t){return Array.prototype.concat(...e.map(e=>yd(e,t)))}var xd=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=bd(Fl.parseFormat(t),e),this.units=this.tokens.map(t=>dd(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=md(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=hd(e,this.regex,this.handlers),[r,i,a]=n?gd(n):[null,null,void 0];if(qc(n,`a`)&&qc(n,`H`))throw new Ko(`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 Sd(e,t,n){return new xd(e,n).explainFromTokens(t)}function Cd(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=Sd(e,t,n);return[r,i,a,o]}function wd(e,t){if(!e)return null;let n=Fl.create(t,e).dtFormatter(vd()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>pd(t,e,i))}var Td=`Invalid DateTime`,Ed=864e13;function Dd(e){return new xc(`unsupported zone`,`the zone "${e.name}" is not supported`)}function Od(e){return e.weekData===null&&(e.weekData=kc(e.c)),e.weekData}function kd(e){return e.localWeekData===null&&(e.localWeekData=kc(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function Ad(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new w({...n,...t,old:n})}function jd(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 Md(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 Nd(e,t,n){return jd(al(e),t,n)}function Pd(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,il(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Ju.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]=jd(al(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function Fd(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=w.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return w.invalid(new xc(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function Id(e,t,n=!0){return e.isValid?Fl.create(ec.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function Ld(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=Zc(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=Zc(e.c.month),n===`month`)return i;i+=`-`}else if(i+=Zc(e.c.month),n===`month`)return i;return i+=Zc(e.c.day),i}function Rd(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+=Zc(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=Zc(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=Zc(e.c.second))}else{if(c+=Zc(e.c.minute),o===`minute`)break;s&&(c+=Zc(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=Zc(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=Zc(Math.trunc(-e.o/60)),c+=`:`,c+=Zc(Math.trunc(-e.o%60))):(c+=`+`,c+=Zc(Math.trunc(e.o/60)),c+=`:`,c+=Zc(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var zd={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Bd={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Vd={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Hd=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],Ud=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],Wd=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function Gd(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 qo(e);return t}function Kd(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return Gd(e)}}function qd(e){if(Zd===void 0&&(Zd=bc.now()),e.type!==`iana`)return e.offset(Zd);let t=e.name,n=Qd.get(t);return n===void 0&&(n=e.offset(Zd),Qd.set(t,n)),n}function Jd(e,t){let n=ic(t.zone,bc.defaultZone);if(!n.isValid)return w.invalid(Dd(n));let r=ec.fromObject(t),i,a;if(S(e.year))i=bc.now();else{for(let t of Hd)S(e[t])&&(e[t]=zd[t]);let t=Ic(e)||Lc(e);if(t)return w.invalid(t);let r=qd(n);[i,a]=Nd(e,r,n)}return new w({ts:i,zone:n,loc:r,o:a})}function Yd(e,t,n){let r=S(n.round)?!0:n.round,i=S(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=tl(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 Xd(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 Zd,Qd=new Map,w=class e{constructor(e){let t=e.zone||bc.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new xc(`invalid input`):null)||(t.isValid?null:Dd(t));this.ts=S(e.ts)?bc.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=Rc(e.o)&&!e.old?e.o:t.offset(this.ts);r=Md(this.ts,a),n=Number.isNaN(r.year)?new xc(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||ec.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]=Xd(arguments),[n,r,i,a,o,s,c]=t;return Jd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=Xd(arguments),[n,r,i,a,o,s,c]=t;return e.zone=nc.utcInstance,Jd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Vc(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=ic(n.zone,bc.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:ec.fromObject(n)}):e.invalid(Dd(i))}static fromMillis(t,n={}){if(!Rc(t))throw new Jo(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>Ed?e.invalid(`Timestamp out of range`):new e({ts:t,zone:ic(n.zone,bc.defaultZone),loc:ec.fromObject(n)})}static fromSeconds(t,n={}){if(Rc(t))return new e({ts:t*1e3,zone:ic(n.zone,bc.defaultZone),loc:ec.fromObject(n)});throw new Jo(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=ic(n.zone,bc.defaultZone);if(!r.isValid)return e.invalid(Dd(r));let i=ec.fromObject(n),a=fl(t,Kd),{minDaysInFirstWeek:o,startOfWeek:s}=Nc(a,i),c=bc.now(),l=S(n.specificOffset)?r.offset(c):n.specificOffset,u=!S(a.ordinal),d=!S(a.year),f=!S(a.month)||!S(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new Ko(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Ko(`Can't mix ordinal dates with month/day`);let h=m||a.weekday&&!p,ee,te,ne=Md(c,l);h?(ee=Ud,te=Bd,ne=kc(ne,o,s)):u?(ee=Wd,te=Vd,ne=jc(ne)):(ee=Hd,te=zd);let re=!1;for(let e of ee){let t=a[e];S(t)?re?a[e]=te[e]:a[e]=ne[e]:re=!0}let ie=(h?Pc(a,o,s):u?Fc(a):Ic(a))||Lc(a);if(ie)return e.invalid(ie);let[ae,oe]=Nd(h?Ac(a,o,s):u?Mc(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]=Eu(e);return Fd(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=Du(e);return Fd(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=Ou(e);return Fd(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(S(t)||S(n))throw new Jo(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=Cd(ec.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):Fd(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]=Fu(e);return Fd(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Jo(`need to specify a reason the DateTime is invalid`);let r=t instanceof xc?t:new xc(t,n);if(bc.throwOnInvalid)throw new Uo(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=wd(e,ec.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return bd(Fl.parseFormat(e),ec.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){Zd=void 0,Qd.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?Od(this).weekYear:NaN}get weekNumber(){return this.isValid?Od(this).weekNumber:NaN}get weekday(){return this.isValid?Od(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?kd(this).weekday:NaN}get localWeekNumber(){return this.isValid?kd(this).weekNumber:NaN}get localWeekYear(){return this.isValid?kd(this).weekYear:NaN}get ordinal(){return this.isValid?jc(this.c).ordinal:NaN}get monthShort(){return this.isValid?Qu.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Qu.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Qu.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Qu.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=al(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=Md(s,a),u=Md(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[Ad(this,{ts:s}),Ad(this,{ts:c})]:[this]}get isInLeapYear(){return nl(this.year)}get daysInMonth(){return il(this.year,this.month)}get daysInYear(){return this.isValid?rl(this.year):NaN}get weeksInWeekYear(){return this.isValid?sl(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?sl(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=Fl.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(nc.instance(e),t)}toLocal(){return this.setZone(bc.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=ic(t,bc.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]=Nd(r,n,t)}return Ad(this,{ts:e,zone:t})}else return e.invalid(Dd(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return Ad(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=fl(e,Kd),{minDaysInFirstWeek:n,startOfWeek:r}=Nc(t,this.loc),i=!S(t.weekYear)||!S(t.weekNumber)||!S(t.weekday),a=!S(t.ordinal),o=!S(t.year),s=!S(t.month)||!S(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new Ko(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Ko(`Can't mix ordinal dates with month/day`);let u;i?u=Ac({...kc(this.c,n,r),...t},n,r):S(t.ordinal)?(u={...this.toObject(),...t},S(t.day)&&(u.day=Math.min(il(u.year,u.month),u.day))):u=Mc({...jc(this.c),...t});let[d,f]=Nd(u,this.o,this.zone);return Ad(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Ju.fromDurationLike(e);return Ad(this,Pd(this,t))}minus(e){if(!this.isValid)return this;let t=Ju.fromDurationLike(e).negate();return Ad(this,Pd(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Ju.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?Fl.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):Td}toLocaleString(e=Qo,t={}){return this.isValid?Fl.create(this.loc.clone(t),e).formatDateTime(this):Td}toLocaleParts(e={}){return this.isValid?Fl.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=Gd(a);let o=e===`extended`,s=Ld(this,o,a);return Hd.indexOf(a)>=3&&(s+=`T`),s+=Rd(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?Ld(this,e===`extended`,Gd(t)):null}toISOWeekDate(){return Id(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=Gd(o),(r&&Hd.indexOf(o)>=3?`T`:``)+Rd(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return Id(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return Id(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?Ld(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`)),Id(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():Td}[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 Ju.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Wc(t).map(Ju.normalizeUnit),a=e.valueOf()>this.valueOf(),o=td(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?Zu.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),Yd(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?Yd(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 Jo(`min requires all arguments be DateTimes`);return Gc(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Jo(`max requires all arguments be DateTimes`);return Gc(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return Sd(ec.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 xd(ec.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(S(t)||S(n))throw new Jo(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=ec.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Jo(`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):Fd(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Qo}static get DATE_MED(){return $o}static get DATE_MED_WITH_WEEKDAY(){return es}static get DATE_FULL(){return ts}static get DATE_HUGE(){return ns}static get TIME_SIMPLE(){return rs}static get TIME_WITH_SECONDS(){return is}static get TIME_WITH_SHORT_OFFSET(){return as}static get TIME_WITH_LONG_OFFSET(){return os}static get TIME_24_SIMPLE(){return ss}static get TIME_24_WITH_SECONDS(){return cs}static get TIME_24_WITH_SHORT_OFFSET(){return ls}static get TIME_24_WITH_LONG_OFFSET(){return us}static get DATETIME_SHORT(){return ds}static get DATETIME_SHORT_WITH_SECONDS(){return fs}static get DATETIME_MED(){return ps}static get DATETIME_MED_WITH_SECONDS(){return ms}static get DATETIME_MED_WITH_WEEKDAY(){return hs}static get DATETIME_FULL(){return gs}static get DATETIME_FULL_WITH_SECONDS(){return _s}static get DATETIME_HUGE(){return vs}static get DATETIME_HUGE_WITH_SECONDS(){return ys}};function $d(e){if(w.isDateTime(e))return e;if(e&&e.valueOf&&Rc(e.valueOf()))return w.fromJSDate(e);if(e&&typeof e==`object`)return w.fromObject(e);throw new Jo(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function ef(e){if(e===`*`)return{min:1,max:`*`};let[t,n]=e.split(`..`),r=Number(t);return n===void 0?{min:r,max:r}:{min:r,max:n===`*`?`*`:Number(n)}}var tf=`1`,nf=`0..1`,rf=`*`,af=`0..*`,of=new Map([[`-`,[`1`,`1`]],[`<>`,[`*`,`*`]],[`>`,[`*`,`1`]],[`<`,[`1`,`*`]],[`-?`,[`1`,nf]],[`?-`,[nf,`1`]],[`?-?`,[nf,nf]],[`?>`,[af,`1`]],[`>?`,[`*`,nf]],[`?>?`,[af,nf]],[`?<`,[nf,`*`]],[`<?`,[`1`,af]],[`?<?`,[nf,af]],[`?<>`,[af,`*`]],[`<>?`,[`*`,af]],[`?<>?`,[af,af]]]),sf=new Map([...of.entries()].map(([e,[t,n]])=>[`${t}-${n}`,e]));function cf(e){return of.get(e)}function lf(e){return ef(e).max===1}function uf(e){return ef(e).max===`*`}function df(e){return ef(e).min===0}function ff(e){return ef(e).min>=1}function pf(e){return e.replace(/\?/g,``)}function mf(e,t){return sf.get(`${e}-${t}`)??`<>`}function hf(e){let{min:t,max:n}=ef(e);return t===0?e:n===`*`?af:nf}function gf(e){let{min:t,max:n}=ef(e);return t>=1?e:n===`*`?`*`:`1`}function _f(e){let{min:t,max:n}=ef(e);return n===`*`?e:t===0?af:`*`}var T=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.UNKNOWN_NOTE_SETTING=3047]=`UNKNOWN_NOTE_SETTING`,e[e.DUPLICATE_NOTE_SETTING=3048]=`DUPLICATE_NOTE_SETTING`,e[e.INVALID_NOTE_SETTING_VALUE=3049]=`INVALID_NOTE_SETTING_VALUE`,e[e.INVALID_INDEXES_CONTEXT=3050]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3051]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3052]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3053]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3054]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3055]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3056]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3057]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3058]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3059]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3060]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3061]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3062]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3063]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3064]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3065]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3066]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3067]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3068]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3069]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3070]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3071]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3072]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3073]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3074]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3075]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3076]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3077]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3078]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3079]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3080]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3081]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3082]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3083]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3084]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.INVALID_USE_CONTEXT=3085]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3086]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3087]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3088]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3089]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3090]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3091]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.UNEQUAL_FIELDS_BINARY_REF=5003]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5004]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e}({}),E=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 vf(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},vf=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,E.prototype)}get filepath(){return this.nodeOrToken.filepath}},yf=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.quickFixes=i?.quickFixes,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}get filepath(){return this.nodeOrToken.filepath}};function bf(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function xf(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Sf(e){let[t]=e;return xf(t)||bf(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Cf(e){return bf(e)||xf(e)}function wf(e){let t=N(e);return t!==void 0&&t.length>0}function Tf(e){return Ef(e)}function Ef(e){return e instanceof hm&&e.expression instanceof mm}function Df(e){return!!e.bodyColon}function Of(e){return e instanceof H&&e.op?.value===`~`&&k(e.expression)}function kf(e){return e!==void 0&&of.has(e)}function Af(e){if(!(e instanceof hm)||!(e.expression instanceof fm)||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(!Sf(t[e]))return!1;return!0}function jf(e){if(O(e)||Mf(e)||Lf(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof H&&Co.includes(e.op?.value)&&Mf(e.expression)||e instanceof sm)return!0;if(!e||!Rf(e))return!1;let t=np(e);return t.length===2||t.length===3}function Mf(e){return e instanceof H?Co.includes(e.op.value)?Mf(e.expression):!1:e instanceof hm&&e.expression instanceof fm&&e.expression.literal?.kind===y.NUMERIC_LITERAL}function Nf(e){if(!(e instanceof H)||!kf(e.op?.value))return!1;let t=N(e.expression);return t!==void 0&&t.length>0}function Pf(e){return e instanceof cm&&e.elementList.every(k)}function Ff(e){if(!(e instanceof dm||A(e)||e instanceof hm||e instanceof _m))return!1;for(;e instanceof dm||e instanceof _m;)if(e instanceof dm){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Mf(e)||O(e)||Lf(e)))return!1;e=e.callee}else if(e instanceof _m){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Mf(e.name)))return!1;e=e.array}let t=N(e);return t!==void 0&&t.length>0}function D(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof hm){r.push(new E(T.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=Qf(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 O(e){return e instanceof hm&&(e.expression instanceof mm&&e.expression.variable instanceof Ba&&e.expression.variable.kind===y.QUOTED_STRING||e.expression instanceof fm&&e.expression.literal?.kind===y.STRING_LITERAL)}function k(e){return e instanceof hm&&e.expression instanceof mm&&e.expression.variable instanceof Ba}function If(e){return e?e instanceof pm:!1}function Lf(e){return e instanceof hm&&e.expression instanceof mm&&e.expression.variable?.kind===y.IDENTIFIER}function A(e){return e instanceof am&&e.leftExpression instanceof R&&e.rightExpression instanceof R&&e.op?.value===`.`}function Rf(e){return k(e)?!0:A(e)&&k(e.rightExpression)&&Rf(e.leftExpression)}function j(e,t){return e instanceof B&&e.isKind(t)}function zf(e){return e instanceof tm}function Bf(e,t){return e instanceof nm&&(t===void 0||e.isKind(t))}function Vf(e){return e instanceof z}function M(e,...t){return e instanceof U&&e.parent instanceof B&&e.parent.isKind(...t)}function Hf(e,t){let n=e.parent;return n instanceof B&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Uf(e,t){let n=e.parentOfKind(U);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 Wf(e){return!!e.parentOfKind(G)}function Gf(e,t){let n=e.parentOfKind(V);return!n||(n.name instanceof hm?F(n.name):Qf(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function Kf(e){return!(e instanceof am)||!kf(e.op?.value)?!1:rp(e.leftExpression)!==void 0&&rp(e.rightExpression)!==void 0}function qf(e){let t=rp(e.leftExpression),n=rp(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function Jf(e){return e instanceof hm&&e.expression instanceof mm||e instanceof sm}function Yf(e){if(k(e))return e;if(A(e)){let t=e.rightExpression;if(t&&k(t))return t}}function Xf(e){let t=e.parentNode;return!A(t)||t.rightExpression!==e?!1:!(A(t.parentNode)&&t.parentNode.leftExpression===t)}function Zf(e){if(k(e))return e.expression.variable}function Qf(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function $f(e){if(!(e instanceof B))return;let t=N(e?.name);return t===void 0?void 0:t.join(`.`)}function ep(e){return e.elementList.length===0}function tp(e){return e?.body?e.body instanceof W?e.body.body:[e.body]:[]}function np(e){if(!e)return;if(!A(e))return[e];let t=np(e.leftExpression);if(t)return t.push(e.rightExpression),t}function N(e){if(e===void 0)return;let t=np(e);if(!t)return;let n=[];for(let e of t){let t=F(e);if(typeof t!=`string`)return;n.push(t)}return n}function rp(e){if(e===void 0)return;let t=np(e);if(!t||t.length===0)return;let n=[];if(!k(_(t))){let e=t.pop();if(Pf(e))n=e.elementList;else return}let r=t;if(r.every(k))return{variables:r,tupleElements:n}}function ip(e){if(Jf(e))return e instanceof sm?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof cm&&e.elementList.every(Jf))return{functional:e.elementList.filter(e=>e instanceof sm),nonFunctional:e.elementList.filter(k)}}function P(e){if(O(e))return e.expression instanceof mm?e?.expression?.variable?.value:e.expression.literal.value}function ap(e){return e instanceof hm&&e.expression instanceof fm&&e.expression.literal?.kind===y.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function op(e){if(!(e instanceof dm)||!e.callee)return;let t=np(e.callee);if(!t||t.length===0||!t.every(k))return;let n=[];return Pf(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function F(e){if(k(e))return e.expression.variable.value}function sp(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function cp(e){return Lf(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof gm}function lp(e){return P(e)===``}function up(e){return e instanceof sm}function dp(e){let t=ap(e);if(t!==null)return t;if(Mf(e)&&e instanceof H&&e.expression){let t=e.op?.value,n=ap(e.expression);if(n!==null)return t===`-`?-n:n}return null}function fp(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return+!!e;let t=dp(e);if(t!==null)return t;let n=P(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function pp(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return+!!e;let t=dp(e);if(t!==null)return Number.isInteger(t)?t:null;let n=P(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var mp=[`true`,`yes`,`y`,`t`,`1`],hp=[`false`,`no`,`n`,`f`,`0`];function gp(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 mp.includes(t)?!0:hp.includes(t)?!1:null}if(Lf(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=ap(e);if(t===0)return!1;if(t===1)return!0;let n=P(e)?.toLowerCase();if(n){if(mp.includes(n))return!0;if(hp.includes(n))return!1}return null}function _p(e){if(e==null)return null;if(typeof e==`string`)return e;let t=N(e);return t?_(t):P(e)??null}function vp(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=P(e)??null??fp(e)??gp(e);return t===null?null:t.toString()}var yp=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],bp=[`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`],xp=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Sp(e){if(e==null)return null;let t=typeof e==`string`?e:P(e)??null;if(t===null)return null;for(let e of xp){let n=w.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of yp){let n=w.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of bp){let n=w.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=w.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 Cp(e){return e instanceof H?`${e.op?.value}${Cp(e.expression)}`:e.expression.literal.value}function wp(e){return e instanceof H?e.op?.value===`-`?-wp(e.expression):wp(e.expression):Number.parseFloat(e.expression.literal.value)}function I(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 Tp(e){let t=e.split(`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(`PASS_THROUGH`),t=Symbol(`UNHANDLED`),n=class e{static create(t,n,r,i){return new e(t,n,r,i)}constructor(e,t,n,r){this.value=e,this.errors=t??[],this.warnings=n,this.infos=r}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings,this.infos):this}hasValue(e){return this.value===e}getFiltered(e){return this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings??[]}getInfos(){return this.infos??[]}chainFiltered(t,n){if(this.value===n)return new e(void 0,this.errors,this.warnings,this.infos);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()],o=[...this.getInfos(),...r.getInfos()];return new e(r.value,i,a,o)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()],a=[...this.getInfos(),...n.getInfos()];return new e(n.value,r,i,a)}mapFiltered(t,n){return this.value===n?new e(void 0,this.errors,this.warnings,this.infos):new e(t(this.value),this.errors,this.warnings,this.infos)}map(t){return new e(t(this.value),this.errors,this.warnings,this.infos)}},r=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e.Metadata=`metadata`,e}({}),i=function(e){return e.Color=`color`,e.HeaderColor=`headercolor`,e.Note=`note`,e.PK=`pk`,e.PrimaryKey=`primary key`,e.Unique=`unique`,e.Ref=`ref`,e.NotNull=`not null`,e.Null=`null`,e.Increment=`increment`,e.Default=`default`,e.Name=`name`,e.Type=`type`,e.Check=`check`,e.Update=`update`,e.Delete=`delete`,e.Inactive=`inactive`,e}({}),a=typeof global==`object`&&global&&global.Object===Object&&global,o=typeof self==`object`&&self&&self.Object===Object&&self,s=a||o||Function(`return this`)(),c=s.Symbol,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function p(e){var t=u.call(e,f),n=e[f];try{e[f]=void 0;var r=!0}catch{}var i=d.call(e);return r&&(t?e[f]=n:delete e[f]),i}var m=Object.prototype.toString;function ee(e){return m.call(e)}var te=`[object Null]`,ne=`[object Undefined]`,re=c?c.toStringTag:void 0;function ie(e){return e==null?e===void 0?ne:te:re&&re in Object(e)?p(e):ee(e)}function ae(e){return typeof e==`object`&&!!e}var oe=`[object Symbol]`;function se(e){return typeof e==`symbol`||ae(e)&&ie(e)==oe}function ce(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var le=Array.isArray,ue=1/0,de=c?c.prototype:void 0,fe=de?de.toString:void 0;function pe(e){if(typeof e==`string`)return e;if(le(e))return ce(e,pe)+``;if(se(e))return fe?fe.call(e):``;var t=e+``;return t==`0`&&1/e==-ue?`-0`:t}var me=/\s/;function he(e){for(var t=e.length;t--&&me.test(e.charAt(t)););return t}var ge=/^\s+/;function _e(e){return e&&e.slice(0,he(e)+1).replace(ge,``)}function ve(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var ye=NaN,be=/^[-+]0x[0-9a-f]+$/i,xe=/^0b[01]+$/i,Se=/^0o[0-7]+$/i,Ce=parseInt;function we(e){if(typeof e==`number`)return e;if(se(e))return ye;if(ve(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=ve(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=_e(e);var n=xe.test(e);return n||Se.test(e)?Ce(e.slice(2),n?2:8):be.test(e)?ye:+e}var Te=1/0,Ee=17976931348623157e292;function De(e){return e?(e=we(e),e===Te||e===-Te?(e<0?-1:1)*Ee:e===e?e:0):e===0?e:0}function Oe(e){var t=De(e),n=t%1;return t===t?n?t-n:t:0}function ke(e){return e}var Ae=`[object AsyncFunction]`,je=`[object Function]`,Me=`[object GeneratorFunction]`,Ne=`[object Proxy]`;function Pe(e){if(!ve(e))return!1;var t=ie(e);return t==je||t==Me||t==Ae||t==Ne}var Fe=s[`__core-js_shared__`],Ie=function(){var e=/[^.]+$/.exec(Fe&&Fe.keys&&Fe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Le(e){return!!Ie&&Ie in e}var Re=Function.prototype.toString;function ze(e){if(e!=null){try{return Re.call(e)}catch{}try{return e+``}catch{}}return``}var Be=/[\\^$.*+?()[\]{}|]/g,Ve=/^\[object .+?Constructor\]$/,He=Function.prototype,Ue=Object.prototype,We=He.toString,Ge=Ue.hasOwnProperty,Ke=RegExp(`^`+We.call(Ge).replace(Be,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function qe(e){return!ve(e)||Le(e)?!1:(Pe(e)?Ke:Ve).test(ze(e))}function Je(e,t){return e?.[t]}function Ye(e,t){var n=Je(e,t);return qe(n)?n:void 0}var Xe=Ye(s,`WeakMap`);function Ze(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}function Qe(){}var $e=800,et=16,tt=Date.now;function nt(e){var t=0,n=0;return function(){var r=tt(),i=et-(r-n);if(n=r,i>0){if(++t>=$e)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function rt(e){return function(){return e}}var it=function(){try{var e=Ye(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),at=nt(it?function(e,t){return it(e,`toString`,{configurable:!0,enumerable:!1,value:rt(t),writable:!0})}:ke);function ot(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1}function st(e){return e!==e}function ct(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function lt(e,t,n){return t===t?ct(e,t,n):ot(e,st,n)}function ut(e,t){return!!(e!=null&&e.length)&<(e,t,0)>-1}var dt=9007199254740991,ft=/^(?:0|[1-9]\d*)$/;function pt(e,t){var n=typeof e;return t??=dt,!!t&&(n==`number`||n!=`symbol`&&ft.test(e))&&e>-1&&e%1==0&&e<t}function mt(e,t,n){t==`__proto__`&&it?it(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function ht(e,t){return e===t||e!==e&&t!==t}var gt=Math.max;function _t(e,t,n){return t=gt(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=gt(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Ze(e,this,s)}}function vt(e,t){return at(_t(e,t,ke),e+``)}var yt=9007199254740991;function bt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=yt}function xt(e){return e!=null&&bt(e.length)&&!Pe(e)}var St=Object.prototype;function Ct(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||St)}function wt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var Tt=`[object Arguments]`;function Et(e){return ae(e)&&ie(e)==Tt}var Dt=Object.prototype,Ot=Dt.hasOwnProperty,kt=Dt.propertyIsEnumerable,At=Et(function(){return arguments}())?Et:function(e){return ae(e)&&Ot.call(e,`callee`)&&!kt.call(e,`callee`)};function jt(){return!1}var Mt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Nt=Mt&&typeof module==`object`&&module&&!module.nodeType&&module,Pt=Nt&&Nt.exports===Mt?s.Buffer:void 0,Ft=(Pt?Pt.isBuffer:void 0)||jt,It=`[object Arguments]`,Lt=`[object Array]`,Rt=`[object Boolean]`,zt=`[object Date]`,Bt=`[object Error]`,Vt=`[object Function]`,Ht=`[object Map]`,Ut=`[object Number]`,Wt=`[object Object]`,Gt=`[object RegExp]`,Kt=`[object Set]`,qt=`[object String]`,Jt=`[object WeakMap]`,Yt=`[object ArrayBuffer]`,Xt=`[object DataView]`,Zt=`[object Float32Array]`,Qt=`[object Float64Array]`,$t=`[object Int8Array]`,en=`[object Int16Array]`,tn=`[object Int32Array]`,nn=`[object Uint8Array]`,rn=`[object Uint8ClampedArray]`,an=`[object Uint16Array]`,on=`[object Uint32Array]`,h={};h[Zt]=h[Qt]=h[$t]=h[en]=h[tn]=h[nn]=h[rn]=h[an]=h[on]=!0,h[It]=h[Lt]=h[Yt]=h[Rt]=h[Xt]=h[zt]=h[Bt]=h[Vt]=h[Ht]=h[Ut]=h[Wt]=h[Gt]=h[Kt]=h[qt]=h[Jt]=!1;function sn(e){return ae(e)&&bt(e.length)&&!!h[ie(e)]}function cn(e){return function(t){return e(t)}}var ln=typeof exports==`object`&&exports&&!exports.nodeType&&exports,un=ln&&typeof module==`object`&&module&&!module.nodeType&&module,dn=un&&un.exports===ln&&a.process,fn=function(){try{return un&&un.require&&un.require(`util`).types||dn&&dn.binding&&dn.binding(`util`)}catch{}}(),pn=fn&&fn.isTypedArray,mn=pn?cn(pn):sn,hn=Object.prototype.hasOwnProperty;function gn(e,t){var n=le(e),r=!n&&At(e),i=!n&&!r&&Ft(e),a=!n&&!r&&!i&&mn(e),o=n||r||i||a,s=o?wt(e.length,String):[],c=s.length;for(var l in e)(t||hn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||pt(l,c)))&&s.push(l);return s}function _n(e,t){return function(n){return e(t(n))}}var vn=_n(Object.keys,Object),yn=Object.prototype.hasOwnProperty;function bn(e){if(!Ct(e))return vn(e);var t=[];for(var n in Object(e))yn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function xn(e){return xt(e)?gn(e):bn(e)}function Sn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Cn=Object.prototype.hasOwnProperty;function wn(e){if(!ve(e))return Sn(e);var t=Ct(e),n=[];for(var r in e)r==`constructor`&&(t||!Cn.call(e,r))||n.push(r);return n}function Tn(e){return xt(e)?gn(e,!0):wn(e)}var En=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Dn=/^\w*$/;function On(e,t){if(le(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||se(e)?!0:Dn.test(e)||!En.test(e)||t!=null&&e in Object(t)}var kn=Ye(Object,`create`);function An(){this.__data__=kn?kn(null):{},this.size=0}function jn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Mn=`__lodash_hash_undefined__`,Nn=Object.prototype.hasOwnProperty;function Pn(e){var t=this.__data__;if(kn){var n=t[e];return n===Mn?void 0:n}return Nn.call(t,e)?t[e]:void 0}var Fn=Object.prototype.hasOwnProperty;function In(e){var t=this.__data__;return kn?t[e]!==void 0:Fn.call(t,e)}var Ln=`__lodash_hash_undefined__`;function Rn(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=kn&&t===void 0?Ln:t,this}function zn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}zn.prototype.clear=An,zn.prototype.delete=jn,zn.prototype.get=Pn,zn.prototype.has=In,zn.prototype.set=Rn;function Bn(){this.__data__=[],this.size=0}function Vn(e,t){for(var n=e.length;n--;)if(ht(e[n][0],t))return n;return-1}var Hn=Array.prototype.splice;function Un(e){var t=this.__data__,n=Vn(t,e);return n<0?!1:(n==t.length-1?t.pop():Hn.call(t,n,1),--this.size,!0)}function Wn(e){var t=this.__data__,n=Vn(t,e);return n<0?void 0:t[n][1]}function Gn(e){return Vn(this.__data__,e)>-1}function Kn(e,t){var n=this.__data__,r=Vn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function qn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}qn.prototype.clear=Bn,qn.prototype.delete=Un,qn.prototype.get=Wn,qn.prototype.has=Gn,qn.prototype.set=Kn;var Jn=Ye(s,`Map`);function Yn(){this.size=0,this.__data__={hash:new zn,map:new(Jn||qn),string:new zn}}function Xn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Zn(e,t){var n=e.__data__;return Xn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function Qn(e){var t=Zn(this,e).delete(e);return this.size-=+!!t,t}function $n(e){return Zn(this,e).get(e)}function er(e){return Zn(this,e).has(e)}function tr(e,t){var n=Zn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function nr(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}nr.prototype.clear=Yn,nr.prototype.delete=Qn,nr.prototype.get=$n,nr.prototype.has=er,nr.prototype.set=tr;var rr=`Expected a function`;function ir(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(rr);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],a=n.cache;if(a.has(i))return a.get(i);var o=e.apply(this,r);return n.cache=a.set(i,o)||a,o};return n.cache=new(ir.Cache||nr),n}ir.Cache=nr;var ar=500;function or(e){var t=ir(e,function(e){return n.size===ar&&n.clear(),e}),n=t.cache;return t}var sr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,cr=/\\(\\)?/g,lr=or(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(sr,function(e,n,r,i){t.push(r?i.replace(cr,`$1`):n||e)}),t});function ur(e){return e==null?``:pe(e)}function dr(e,t){return le(e)?e:On(e,t)?[e]:lr(ur(e))}var fr=1/0;function pr(e){if(typeof e==`string`||se(e))return e;var t=e+``;return t==`0`&&1/e==-fr?`-0`:t}function mr(e,t){t=dr(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[pr(t[n++])];return n&&n==r?e:void 0}function hr(e,t,n){var r=e==null?void 0:mr(e,t);return r===void 0?n:r}function gr(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var _r=c?c.isConcatSpreadable:void 0;function vr(e){return le(e)||At(e)||!!(_r&&e&&e[_r])}function yr(e,t,n,r,i){var a=-1,o=e.length;for(n||=vr,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?yr(s,t-1,n,r,i):gr(i,s):r||(i[i.length]=s)}return i}function br(e){return e!=null&&e.length?yr(e,1):[]}function xr(){this.__data__=new qn,this.size=0}function Sr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Cr(e){return this.__data__.get(e)}function wr(e){return this.__data__.has(e)}var Tr=200;function Er(e,t){var n=this.__data__;if(n instanceof qn){var r=n.__data__;if(!Jn||r.length<Tr-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new nr(r)}return n.set(e,t),this.size=n.size,this}function Dr(e){var t=this.__data__=new qn(e);this.size=t.size}Dr.prototype.clear=xr,Dr.prototype.delete=Sr,Dr.prototype.get=Cr,Dr.prototype.has=wr,Dr.prototype.set=Er;function Or(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}function kr(){return[]}var Ar=Object.prototype.propertyIsEnumerable,jr=Object.getOwnPropertySymbols,Mr=jr?function(e){return e==null?[]:(e=Object(e),Or(jr(e),function(t){return Ar.call(e,t)}))}:kr;function Nr(e,t,n){var r=t(e);return le(e)?r:gr(r,n(e))}function Pr(e){return Nr(e,xn,Mr)}var Fr=Ye(s,`DataView`),Ir=Ye(s,`Promise`),Lr=Ye(s,`Set`),Rr=`[object Map]`,zr=`[object Object]`,Br=`[object Promise]`,Vr=`[object Set]`,Hr=`[object WeakMap]`,Ur=`[object DataView]`,Wr=ze(Fr),Gr=ze(Jn),Kr=ze(Ir),qr=ze(Lr),Jr=ze(Xe),Yr=ie;(Fr&&Yr(new Fr(new ArrayBuffer(1)))!=Ur||Jn&&Yr(new Jn)!=Rr||Ir&&Yr(Ir.resolve())!=Br||Lr&&Yr(new Lr)!=Vr||Xe&&Yr(new Xe)!=Hr)&&(Yr=function(e){var t=ie(e),n=t==zr?e.constructor:void 0,r=n?ze(n):``;if(r)switch(r){case Wr:return Ur;case Gr:return Rr;case Kr:return Br;case qr:return Vr;case Jr:return Hr}return t});var Xr=Yr,Zr=s.Uint8Array;function Qr(e){for(var t=-1,n=e==null?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i}var $r=`__lodash_hash_undefined__`;function ei(e){return this.__data__.set(e,$r),this}function ti(e){return this.__data__.has(e)}function ni(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new nr;++t<n;)this.add(e[t])}ni.prototype.add=ni.prototype.push=ei,ni.prototype.has=ti;function ri(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function ii(e,t){return e.has(t)}var ai=1,oi=2;function si(e,t,n,r,i,a){var o=n&ai,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,p=n&oi?new ni:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],ee=t[d];if(r)var te=o?r(ee,m,d,t,e,a):r(m,ee,d,e,t,a);if(te!==void 0){if(te)continue;f=!1;break}if(p){if(!ri(t,function(e,t){if(!ii(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===ee||i(m,ee,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}function ci(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function li(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var ui=1,di=2,fi=`[object Boolean]`,pi=`[object Date]`,mi=`[object Error]`,hi=`[object Map]`,gi=`[object Number]`,_i=`[object RegExp]`,vi=`[object Set]`,yi=`[object String]`,bi=`[object Symbol]`,xi=`[object ArrayBuffer]`,Si=`[object DataView]`,Ci=c?c.prototype:void 0,wi=Ci?Ci.valueOf:void 0;function Ti(e,t,n,r,i,a,o){switch(n){case Si:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case xi:return!(e.byteLength!=t.byteLength||!a(new Zr(e),new Zr(t)));case fi:case pi:case gi:return ht(+e,+t);case mi:return e.name==t.name&&e.message==t.message;case _i:case yi:return e==t+``;case hi:var s=ci;case vi:var c=r&ui;if(s||=li,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=di,o.set(e,t);var u=si(s(e),s(t),r,i,a,o);return o.delete(e),u;case bi:if(wi)return wi.call(e)==wi.call(t)}return!1}var Ei=1,Di=Object.prototype.hasOwnProperty;function Oi(e,t,n,r,i,a){var o=n&Ei,s=Pr(e),c=s.length;if(c!=Pr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Di.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var ee=e[u],te=t[u];if(r)var ne=o?r(te,ee,u,t,e,a):r(ee,te,u,e,t,a);if(!(ne===void 0?ee===te||i(ee,te,n,r,a):ne)){p=!1;break}m||=u==`constructor`}if(p&&!m){var re=e.constructor,ie=t.constructor;re!=ie&&`constructor`in e&&`constructor`in t&&!(typeof re==`function`&&re instanceof re&&typeof ie==`function`&&ie instanceof ie)&&(p=!1)}return a.delete(e),a.delete(t),p}var ki=1,Ai=`[object Arguments]`,ji=`[object Array]`,Mi=`[object Object]`,Ni=Object.prototype.hasOwnProperty;function Pi(e,t,n,r,i,a){var o=le(e),s=le(t),c=o?ji:Xr(e),l=s?ji:Xr(t);c=c==Ai?Mi:c,l=l==Ai?Mi:l;var u=c==Mi,d=l==Mi,f=c==l;if(f&&Ft(e)){if(!Ft(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Dr,o||mn(e)?si(e,t,n,r,i,a):Ti(e,t,c,n,r,i,a);if(!(n&ki)){var p=u&&Ni.call(e,`__wrapped__`),m=d&&Ni.call(t,`__wrapped__`);if(p||m){var ee=p?e.value():e,te=m?t.value():t;return a||=new Dr,i(ee,te,n,r,a)}}return f?(a||=new Dr,Oi(e,t,n,r,i,a)):!1}function Fi(e,t,n,r,i){return e===t?!0:e==null||t==null||!ae(e)&&!ae(t)?e!==e&&t!==t:Pi(e,t,n,r,Fi,i)}var Ii=1,Li=2;function Ri(e,t,n,r){var i=n.length,a=i,o=!r;if(e==null)return!a;for(e=Object(e);i--;){var s=n[i];if(o&&s[2]?s[1]!==e[s[0]]:!(s[0]in e))return!1}for(;++i<a;){s=n[i];var c=s[0],l=e[c],u=s[1];if(o&&s[2]){if(l===void 0&&!(c in e))return!1}else{var d=new Dr;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Fi(u,l,Ii|Li,r,d):f))return!1}}return!0}function zi(e){return e===e&&!ve(e)}function Bi(e){for(var t=xn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,zi(i)]}return t}function Vi(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function Hi(e){var t=Bi(e);return t.length==1&&t[0][2]?Vi(t[0][0],t[0][1]):function(n){return n===e||Ri(n,e,t)}}function Ui(e,t){return e!=null&&t in Object(e)}function Wi(e,t,n){t=dr(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=pr(t[r]);if(!(a=e!=null&&n(e,o)))break;e=e[o]}return a||++r!=i?a:(i=e==null?0:e.length,!!i&&bt(i)&&pt(o,i)&&(le(e)||At(e)))}function Gi(e,t){return e!=null&&Wi(e,t,Ui)}var Ki=1,qi=2;function Ji(e,t){return On(e)&&zi(t)?Vi(pr(e),t):function(n){var r=hr(n,e);return r===void 0&&r===t?Gi(n,e):Fi(t,r,Ki|qi)}}function Yi(e){return function(t){return t?.[e]}}function Xi(e){return function(t){return mr(t,e)}}function Zi(e){return On(e)?Yi(pr(e)):Xi(e)}function Qi(e){return typeof e==`function`?e:e==null?ke:typeof e==`object`?le(e)?Ji(e[0],e[1]):Hi(e):Zi(e)}function $i(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}function ea(e){return function(t,n,r){for(var i=-1,a=Object(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}var ta=ea();function na(e,t){return e&&ta(e,t,xn)}function ra(e,t){return function(n,r){if(n==null)return n;if(!xt(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var ia=ra(na);function aa(e,t,n,r){return ia(e,function(e,i,a){t(r,e,n(e),a)}),r}function oa(e,t){return function(n,r){var i=le(n)?$i:aa,a=t?t():{};return i(n,e,Qi(r,2),a)}}function sa(e){return ae(e)&&xt(e)}function ca(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}var la=200;function ua(e,t,n,r){var i=-1,a=ut,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ce(t,cn(n))),r?(a=ca,o=!1):t.length>=la&&(a=ii,o=!1,t=new ni(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var da=vt(function(e,t){return sa(e)?ua(e,yr(t,1,sa,!0)):[]});function g(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function fa(e){return typeof e==`function`?e:ke}function pa(e,t){var n=[];return ia(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ma(e,t){return(le(e)?Or:pa)(e,Qi(t,3))}var ha=Math.max,ga=Math.min;function _a(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Oe(n),i=n<0?ha(r+i,0):ga(i,r-1)),ot(e,Qi(t,3),i,!0)}function va(e){return e&&e.length?e[0]:void 0}function ya(e,t){var n=-1,r=xt(e)?Array(e.length):[];return ia(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function ba(e,t){return(le(e)?ce:ya)(e,Qi(t,3))}function xa(e,t){return yr(ba(e,t),1)}function Sa(e,t){return e==null?e:ta(e,fa(t),Tn)}var Ca=Object.prototype.hasOwnProperty,wa=oa(function(e,t,n){Ca.call(e,n)?e[n].push(t):mt(e,n,[t])}),Ta=`[object Map]`,Ea=`[object Set]`,Da=Object.prototype.hasOwnProperty;function Oa(e){if(e==null)return!0;if(xt(e)&&(le(e)||typeof e==`string`||typeof e.splice==`function`||Ft(e)||mn(e)||At(e)))return!e.length;var t=Xr(e);if(t==Ta||t==Ea)return!e.size;if(Ct(e))return!bn(e).length;for(var n in e)if(Da.call(e,n))return!1;return!0}var ka=oa(function(e,t,n){mt(e,n,t)}),_=oa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),Aa=Lr&&1/li(new Lr([,-0]))[1]==1/0?function(e){return new Lr(e)}:Qe,ja=200;function Ma(e,t,n){var r=-1,i=ut,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=ca;else if(a>=ja){var l=t?null:Aa(e);if(l)return li(l);o=!1,i=ii,c=new ni}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}function Na(e){return e&&e.length?Ma(e):[]}function Pa(e,t){return e&&e.length?Ma(e,Qi(t,2)):[]}var Fa=Math.max;function Ia(e){if(!(e&&e.length))return[];var t=0;return e=Or(e,function(e){if(sa(e))return t=Fa(e.length,t),!0}),wt(t,function(t){return ce(e,Yi(t))})}var La=vt(Ia),v=function(e){return e.SPACE=`<space>`,e.TAB=`<tab>`,e.NEWLINE=`<newline>`,e.COMMA=`<comma>`,e.LPAREN=`<lparen>`,e.RPAREN=`<rparen>`,e.LBRACE=`<lbrace>`,e.RBRACE=`<rbrace>`,e.LBRACKET=`<lbracket>`,e.RBRACKET=`<rbracket>`,e.LANGLE=`<langle>`,e.RANGLE=`<rangle>`,e.OP=`<op>`,e.EOF=`<eof>`,e.NUMERIC_LITERAL=`<number>`,e.STRING_LITERAL=`<string>`,e.COLOR_LITERAL=`<color>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.QUOTED_STRING=`<variable>`,e.IDENTIFIER=`<identifier>`,e.SEMICOLON=`<semicolon>`,e.COLON=`<colon>`,e.SINGLE_LINE_COMMENT=`<single-line-comment>`,e.MULTILINE_COMMENT=`<multiline-comment>`,e.WILDCARD=`<wildcard>`,e}({});function Ra(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:return!0;default:return!1}}function za(e){if(!e)return!1;switch(e){case`+`:case`-`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`?`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function Ba(e){return e!==void 0&&e.kind===`<op>`}var Va=class e{constructor(e,t,n,r,i,a){this.kind=e,this.filepath=t,this.startPos=n,this.endPos=r,this.value=i,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=a,this.start=n.offset,this.end=r.offset}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}};function Ha(e){return e.trailingTrivia.find(({kind:e})=>e===v.NEWLINE)!==void 0}function Ua(e,t){return t.leadingTrivia.find(({kind:e})=>e===v.NEWLINE)!==void 0||Ha(e)}function Wa(e){return e.trailingTrivia.find(({kind:e})=>[v.SPACE,v.TAB].includes(e))!==void 0}function Ga(e){return e.trailingTrivia.length===0?e.end:Ga(g(e.trailingTrivia))}function Ka(e){return e.leadingTrivia.length===0?e.start:Ka(e.leadingTrivia[0])}function qa(e){return[v.SINGLE_LINE_COMMENT,v.MULTILINE_COMMENT].includes(e.kind)}function Ja(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`as`}function Ya(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`use`}function Xa(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`metadata`}function Za(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`from`}function Qa(e){return e?.kind===v.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function $a(e){return!!e?.isInvalid}var eo=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},to=/^[A-Za-z]:\//;function no(e=``){return e&&e.replace(/\\/g,`/`).replace(to,e=>e.toUpperCase())}var ro=/^[/\\]{2}/,io=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,ao=/^[A-Za-z]:$/,oo=/^\/([A-Za-z]:)?$/,so=/.(\.[^./]+|\.)$/,co=function(e){if(e.length===0)return`.`;e=no(e);let t=e.match(ro),n=mo(e),r=e[e.length-1]===`/`;return e=po(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),ao.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!mo(e)?`/${e}`:e)},lo=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 co(t)};function uo(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var fo=function(...e){e=e.map(e=>no(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:uo();!i||i.length===0||(t=`${i}/${t}`,n=mo(i))}return t=po(t,!n),n&&!mo(t)?`/${t}`:t.length>0?t:`.`};function po(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 mo=function(e){return io.test(e)},ho=function(e){if(e===`..`)return``;let t=so.exec(no(e));return t&&t[1]||``},go=function(e,t){let n=fo(e).replace(oo,`$1`).split(`/`),r=fo(t).replace(oo,`$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(`/`)},_o=function(e){let t=no(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&ao.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(mo(e)?`/`:`.`)},vo=function(e,t){let n=no(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},yo=/^[a-zA-Z]:\//,bo=class e{constructor(e,t={}){let n=co(e);if(!mo(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(fo(t,n))}static fromUri(t){try{let n=new URL(t);return new e(co(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(co(t))}}get absolute(){return this.path}get dirname(){return _o(this.path)}get basename(){return vo(this.path)}get extname(){return ho(this.path)}resolve(t){return new e(fo(this.dirname,t))}join(...t){return new e(lo(this.path,...t))}relativeTo(e){let t=go(e,this.path);return!t.startsWith(`./`)&&!t.startsWith(`../`)&&![`.`,`..`].includes(t)?`./${t}`:t}toString(){return this.path}equals(e){return this.path===e.path}isParentOf(e){if(this.path===e.path)return!1;let t=this.path.endsWith(`/`)?this.path:`${this.path}/`;return e.path.startsWith(t)}toUri(e={}){let t=e.protocol||this.protocol;if(!t)return this.path;let n=yo.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!mo(co(e))}};function xo(e,t){if(!bo.isRelative(t))return;let n=bo.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:bo.from(n.absolute+`.dbml`)}var So=[`null`,`true`,`false`],Co=`none`,wo=`.dbml`,To=[`-`,`+`],y=`public`,Eo=bo.from(`/main.dbml`),Do={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`])},Oo={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`])},ko={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},Ao={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`])},jo={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`])},Mo={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`])},No={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function Po(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function Fo(e,t){let n=Po(e);return t?Do[t].has(n):Object.values(Do).some(e=>e.has(n))}function Io(e,t){let n=Po(e);return t?Oo[t].has(n):Object.values(Oo).some(e=>e.has(n))}function Lo(e,t){return Fo(e,t)||Io(e,t)}function Ro(e,t){let n=Po(e);return t?ko[t].has(n):Object.values(ko).some(e=>e.has(n))}function zo(e,t){let n=Po(e);return t?Ao[t].has(n):Object.values(Ao).some(e=>e.has(n))}function Bo(e,t){let n=Po(e);return t?jo[t].has(n):Object.values(jo).some(e=>e.has(n))}function Vo(e,t){let n=Po(e);return t?Mo[t].has(n):Object.values(Mo).some(e=>e.has(n))}function Ho(e,t){let n=Po(e);return t?No[t].has(n):Object.values(No).some(e=>e.has(n))}function Uo(e,t){if(t)return`string`;if(Fo(e))return`integer`;if(Io(e))return`real`;if(Ro(e))return`bool`;if(zo(e))return`string`;let n=Po(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:Vo(e)?`datetime`:e}var Wo=class extends Error{},Go=class extends Wo{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Ko=class extends Wo{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},qo=class extends Wo{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Jo=class extends Wo{},Yo=class extends Wo{constructor(e){super(`Invalid unit ${e}`)}},Xo=class extends Wo{},Zo=class extends Wo{constructor(){super(`Zone is an abstract class`)}},b=`numeric`,Qo=`short`,$o=`long`,es={year:b,month:b,day:b},ts={year:b,month:Qo,day:b},ns={year:b,month:Qo,day:b,weekday:Qo},rs={year:b,month:$o,day:b},is={year:b,month:$o,day:b,weekday:$o},as={hour:b,minute:b},os={hour:b,minute:b,second:b},ss={hour:b,minute:b,second:b,timeZoneName:Qo},cs={hour:b,minute:b,second:b,timeZoneName:$o},ls={hour:b,minute:b,hourCycle:`h23`},us={hour:b,minute:b,second:b,hourCycle:`h23`},ds={hour:b,minute:b,second:b,hourCycle:`h23`,timeZoneName:Qo},fs={hour:b,minute:b,second:b,hourCycle:`h23`,timeZoneName:$o},ps={year:b,month:b,day:b,hour:b,minute:b},ms={year:b,month:b,day:b,hour:b,minute:b,second:b},hs={year:b,month:Qo,day:b,hour:b,minute:b},gs={year:b,month:Qo,day:b,hour:b,minute:b,second:b},_s={year:b,month:Qo,day:b,weekday:Qo,hour:b,minute:b},vs={year:b,month:$o,day:b,hour:b,minute:b,timeZoneName:Qo},ys={year:b,month:$o,day:b,hour:b,minute:b,second:b,timeZoneName:Qo},bs={year:b,month:$o,day:b,weekday:$o,hour:b,minute:b,timeZoneName:$o},xs={year:b,month:$o,day:b,weekday:$o,hour:b,minute:b,second:b,timeZoneName:$o},Ss=class{get type(){throw new Zo}get name(){throw new Zo}get ianaName(){return this.name}get isUniversal(){throw new Zo}offsetName(e,t){throw new Zo}formatOffset(e,t){throw new Zo}offset(e){throw new Zo}equals(e){throw new Zo}get isValid(){throw new Zo}},Cs=null,ws=class e extends Ss{static get instance(){return Cs===null&&(Cs=new e),Cs}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return ul(e,t,n)}formatOffset(e,t){return ml(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},Ts=new Map;function Es(e){let t=Ts.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`}),Ts.set(e,t)),t}var Ds={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function Os(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 ks(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=Ds[t];t===`era`?r[a]=i:S(a)||(r[a]=parseInt(i,10))}return r}var As=new Map,js=class e extends Ss{static create(t){let n=As.get(t);return n===void 0&&As.set(t,n=new e(t)),n}static resetCache(){As.clear(),Ts.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 ul(e,t,n,this.name)}formatOffset(e,t){return ml(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=Es(this.name),[r,i,a,o,s,c,l]=n.formatToParts?ks(n,t):Os(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=ol({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}},Ms={};function Ns(e,t={}){let n=JSON.stringify([e,t]),r=Ms[n];return r||(r=new Intl.ListFormat(e,t),Ms[n]=r),r}var Ps=new Map;function Fs(e,t={}){let n=JSON.stringify([e,t]),r=Ps.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),Ps.set(n,r)),r}var Is=new Map;function Ls(e,t={}){let n=JSON.stringify([e,t]),r=Is.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Is.set(n,r)),r}var Rs=new Map;function zs(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=Rs.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),Rs.set(i,a)),a}var Bs=null;function Vs(){return Bs||(Bs=new Intl.DateTimeFormat().resolvedOptions().locale,Bs)}var Hs=new Map;function Us(e){let t=Hs.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Hs.set(e,t)),t}var Ws=new Map;function Gs(e){let t=Ws.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...tc,...t}),Ws.set(e,t)}return t}function Ks(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=Fs(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=Fs(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function qs(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Js(e){let t=[];for(let n=1;n<=12;n++){let r=w.utc(2009,n,1);t.push(e(r))}return t}function Ys(e){let t=[];for(let n=1;n<=7;n++){let r=w.utc(2016,11,13+n);t.push(e(r))}return t}function Xs(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Zs(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Us(e.locale).numberingSystem===`latn`}var Qs=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=Ls(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return Qc(this.floor?Math.floor(e):nl(e,3),this.padTo)}},$s=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&&js.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=Fs(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()}},ec=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Uc()&&(this.rtf=zs(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):Nl(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},tc={firstDay:1,minimalDays:4,weekend:[6,7]},x=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||xc.defaultLocale;return new e(o||(a?`en-US`:Vs()),n||xc.defaultNumberingSystem,r||xc.defaultOutputCalendar,Yc(i)||xc.defaultWeekSettings,o)}static resetCache(){Bs=null,Ps.clear(),Is.clear(),Rs.clear(),Hs.clear(),Ws.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]=Ks(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=qs(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??=Zs(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,Yc(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 Xs(this,e,yl,()=>{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]=Js(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Xs(this,e,Cl,()=>{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]=Ys(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Xs(this,void 0,()=>wl,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[w.utc(2016,11,13,9),w.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Xs(this,e,Ol,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[w.utc(-40,1,1),w.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 Qs(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new $s(e,this.intl,t)}relFormatter(e={}){return new ec(this.intl,this.isEnglish(),e)}listFormatter(e={}){return Ns(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Us(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Wc()?Gs(this.locale):tc}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})`}},nc=null,rc=class e extends Ss{static get utcInstance(){return nc===null&&(nc=new e(0)),nc}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(dl(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${ml(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${ml(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return ml(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}},ic=class extends Ss{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 ac(e,t){if(S(e)||e===null)return t;if(e instanceof Ss)return e;if(Vc(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?ws.instance:n===`utc`||n===`gmt`?rc.utcInstance:rc.parseSpecifier(n)||js.create(e)}else if(zc(e))return rc.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new ic(e)}var oc={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},sc={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]},cc=oc.hanidec.replace(/[\[|\]]/g,``).split(``);function lc(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(oc.hanidec)!==-1)t+=cc.indexOf(e[n]);else for(let e in sc){let[n,i]=sc[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var uc=new Map;function dc(){uc.clear()}function fc({numberingSystem:e},t=``){let n=e||`latn`,r=uc.get(n);r===void 0&&(r=new Map,uc.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${oc[n]}${t}`),r.set(t,i)),i}var pc=()=>Date.now(),mc=`system`,hc=null,gc=null,_c=null,vc=60,yc,bc=null,xc=class{static get now(){return pc}static set now(e){pc=e}static set defaultZone(e){mc=e}static get defaultZone(){return ac(mc,ws.instance)}static get defaultLocale(){return hc}static set defaultLocale(e){hc=e}static get defaultNumberingSystem(){return gc}static set defaultNumberingSystem(e){gc=e}static get defaultOutputCalendar(){return _c}static set defaultOutputCalendar(e){_c=e}static get defaultWeekSettings(){return bc}static set defaultWeekSettings(e){bc=Yc(e)}static get twoDigitCutoffYear(){return vc}static set twoDigitCutoffYear(e){vc=e%100}static get throwOnInvalid(){return yc}static set throwOnInvalid(e){yc=e}static resetCaches(){x.resetCache(),js.resetCache(),w.resetCache(),dc()}},Sc=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},Cc=[0,31,59,90,120,151,181,212,243,273,304,334],wc=[0,31,60,91,121,152,182,213,244,274,305,335];function Tc(e,t){return new Sc(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function Ec(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 Dc(e,t,n){return n+(rl(e)?wc:Cc)[t-1]}function Oc(e,t){let n=rl(e)?wc:Cc,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function kc(e,t){return(e-t+7)%7+1}function Ac(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Dc(r,i,a),s=kc(Ec(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=cl(l,t,n)):c>cl(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...hl(e)}}function jc(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=kc(Ec(r,1,t),n),s=il(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=il(l)):c>s?(l=r+1,c-=il(r)):l=r;let{month:u,day:d}=Oc(l,c);return{year:l,month:u,day:d,...hl(e)}}function Mc(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Dc(t,n,r),...hl(e)}}function Nc(e){let{year:t,ordinal:n}=e,{month:r,day:i}=Oc(t,n);return{year:t,month:r,day:i,...hl(e)}}function Pc(e,t){if(!S(e.localWeekday)||!S(e.localWeekNumber)||!S(e.localWeekYear)){if(!S(e.weekday)||!S(e.weekNumber)||!S(e.weekYear))throw new Jo(`Cannot mix locale-based week fields with ISO-based week fields`);return S(e.localWeekday)||(e.weekday=e.localWeekday),S(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),S(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 Fc(e,t=4,n=1){let r=Bc(e.weekYear),i=Xc(e.weekNumber,1,cl(e.weekYear,t,n)),a=Xc(e.weekday,1,7);return r?i?a?!1:Tc(`weekday`,e.weekday):Tc(`week`,e.weekNumber):Tc(`weekYear`,e.weekYear)}function Ic(e){let t=Bc(e.year),n=Xc(e.ordinal,1,il(e.year));return t?n?!1:Tc(`ordinal`,e.ordinal):Tc(`year`,e.year)}function Lc(e){let t=Bc(e.year),n=Xc(e.month,1,12),r=Xc(e.day,1,al(e.year,e.month));return t?n?r?!1:Tc(`day`,e.day):Tc(`month`,e.month):Tc(`year`,e.year)}function Rc(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Xc(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Xc(n,0,59),s=Xc(r,0,59),c=Xc(i,0,999);return a?o?s?c?!1:Tc(`millisecond`,i):Tc(`second`,r):Tc(`minute`,n):Tc(`hour`,t)}function S(e){return e===void 0}function zc(e){return typeof e==`number`}function Bc(e){return typeof e==`number`&&e%1==0}function Vc(e){return typeof e==`string`}function Hc(e){return Object.prototype.toString.call(e)===`[object Date]`}function Uc(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Wc(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Gc(e){return Array.isArray(e)?e:[e]}function Kc(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 qc(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Jc(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Yc(e){if(e==null)return null;if(typeof e!=`object`)throw new Xo(`Week settings must be an object`);if(!Xc(e.firstDay,1,7)||!Xc(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Xc(e,1,7)))throw new Xo(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Xc(e,t,n){return Bc(e)&&e>=t&&e<=n}function Zc(e,t){return e-t*Math.floor(e/t)}function Qc(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function $c(e){if(!(S(e)||e===null||e===``))return parseInt(e,10)}function el(e){if(!(S(e)||e===null||e===``))return parseFloat(e)}function tl(e){if(!(S(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function nl(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 rl(e){return e%4==0&&(e%100!=0||e%400==0)}function il(e){return rl(e)?366:365}function al(e,t){let n=Zc(t-1,12)+1,r=e+(t-n)/12;return n===2?rl(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function ol(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 sl(e,t,n){return-kc(Ec(e,1,t),n)+t-1}function cl(e,t=4,n=1){let r=sl(e,t,n),i=sl(e+1,t,n);return(il(e)-r+i)/7}function ll(e){return e>99?e:e>xc.twoDigitCutoffYear?1900+e:2e3+e}function ul(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 dl(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 fl(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Xo(`Invalid unit value ${e}`);return t}function pl(e,t){let n={};for(let r in e)if(Jc(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=fl(i)}return n}function ml(e,t){let n=Math.trunc(Math.abs(e/60)),r=Math.trunc(Math.abs(e%60)),i=e>=0?`+`:`-`;switch(t){case`short`:return`${i}${Qc(n,2)}:${Qc(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${Qc(n,2)}${Qc(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function hl(e){return qc(e,[`hour`,`minute`,`second`,`millisecond`])}var gl=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],_l=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],vl=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function yl(e){switch(e){case`narrow`:return[...vl];case`short`:return[..._l];case`long`:return[...gl];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 bl=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],xl=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Sl=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function Cl(e){switch(e){case`narrow`:return[...Sl];case`short`:return[...xl];case`long`:return[...bl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var wl=[`AM`,`PM`],Tl=[`Before Christ`,`Anno Domini`],El=[`BC`,`AD`],Dl=[`B`,`A`];function Ol(e){switch(e){case`narrow`:return[...Dl];case`short`:return[...El];case`long`:return[...Tl];default:return null}}function kl(e){return wl[e.hour<12?0:1]}function Al(e,t){return Cl(t)[e.weekday-1]}function jl(e,t){return yl(t)[e.month-1]}function Ml(e,t){return Ol(t)[e.year<0?0:1]}function Nl(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 Pl(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var Fl={D:es,DD:ts,DDD:rs,DDDD:is,t:as,tt:os,ttt:ss,tttt:cs,T:ls,TT:us,TTT:ds,TTTT:fs,f:ps,ff:hs,fff:vs,ffff:bs,F:ms,FF:gs,FFF:ys,FFFF:xs},Il=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 Fl[e]}constructor(e,t){this.opts=t,this.loc=e,this.systemLoc=null}formatWithSystemDefault(e,t){return this.systemLoc===null&&(this.systemLoc=this.loc.redefaultToSystem()),this.systemLoc.dtFormatter(e,{...this.opts,...t}).format()}dtFormatter(e,t={}){return this.loc.dtFormatter(e,{...this.opts,...t})}formatDateTime(e,t){return this.dtFormatter(e,t).format()}formatDateTimeParts(e,t){return this.dtFormatter(e,t).formatToParts()}formatInterval(e,t){return this.dtFormatter(e.start,t).dtf.formatRange(e.start.toJSDate(),e.end.toJSDate())}resolvedOptions(e,t){return this.dtFormatter(e,t).resolvedOptions()}num(e,t=0,n=void 0){if(this.opts.forceSimple)return Qc(e,t);let r={...this.opts};return t>0&&(r.padTo=t),n&&(r.signDisplay=n),this.loc.numberFormatter(r).format(e)}formatDateTimeFromString(t,n){let r=this.loc.listingMode()===`en`,i=this.loc.outputCalendar&&this.loc.outputCalendar!==`gregory`,a=(e,n)=>this.loc.extract(t,e,n),o=e=>t.isOffsetFixed&&t.offset===0&&e.allowZ?`Z`:t.isValid?t.zone.formatOffset(t.ts,e.format):``,s=()=>r?kl(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?jl(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?Al(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?Ml(t,e):a({era:e},`era`);return Pl(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 Pl(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Ll=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Rl(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function zl(...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 Bl(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 Vl(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=$c(t[n+i]);return[r,null,n+i]}}var Hl=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Ul=`(?:${Hl.source}?(?:\\[(${Ll.source})\\])?)?`,Wl=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Gl=RegExp(`${Wl.source}${Ul}`),Kl=RegExp(`(?:[Tt]${Gl.source})?`),ql=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Jl=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Yl=/(\d{4})-?(\d{3})/,Xl=Vl(`weekYear`,`weekNumber`,`weekDay`),Zl=Vl(`year`,`ordinal`),Ql=/(\d{4})-(\d\d)-(\d\d)/,$l=RegExp(`${Wl.source} ?(?:${Hl.source}|(${Ll.source}))?`),eu=RegExp(`(?: ${$l.source})?`);function tu(e,t,n){let r=e[t];return S(r)?n:$c(r)}function nu(e,t){return[{year:tu(e,t),month:tu(e,t+1,1),day:tu(e,t+2,1)},null,t+3]}function ru(e,t){return[{hours:tu(e,t,0),minutes:tu(e,t+1,0),seconds:tu(e,t+2,0),milliseconds:tl(e[t+3])},null,t+4]}function iu(e,t){let n=!e[t]&&!e[t+1],r=dl(e[t+1],e[t+2]);return[{},n?null:rc.instance(r),t+3]}function au(e,t){return[{},e[t]?js.create(e[t]):null,t+1]}var ou=RegExp(`^T?${Wl.source}$`),su=/^-?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 cu(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(el(n)),months:f(el(r)),weeks:f(el(i)),days:f(el(a)),hours:f(el(o)),minutes:f(el(s)),seconds:f(el(c),c===`-0`),milliseconds:f(tl(l),d)}]}var lu={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function uu(e,t,n,r,i,a,o){let s={year:t.length===2?ll($c(t)):$c(t),month:_l.indexOf(n)+1,day:$c(r),hour:$c(i),minute:$c(a)};return o&&(s.second=$c(o)),e&&(s.weekday=e.length>3?bl.indexOf(e)+1:xl.indexOf(e)+1),s}var du=/^(?:(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 fu(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=uu(t,i,r,n,a,o,s),p;return p=c?lu[c]:l?0:dl(u,d),[f,new rc(p)]}function pu(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var mu=/^(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$/,hu=/^(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$/,gu=/^(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 _u(e){let[,t,n,r,i,a,o,s]=e;return[uu(t,i,r,n,a,o,s),rc.utcInstance]}function vu(e){let[,t,n,r,i,a,o,s]=e;return[uu(t,s,n,r,i,a,o),rc.utcInstance]}var yu=Rl(ql,Kl),bu=Rl(Jl,Kl),xu=Rl(Yl,Kl),Su=Rl(Gl),Cu=zl(nu,ru,iu,au),wu=zl(Xl,ru,iu,au),Tu=zl(Zl,ru,iu,au),Eu=zl(ru,iu,au);function Du(e){return Bl(e,[yu,Cu],[bu,wu],[xu,Tu],[Su,Eu])}function Ou(e){return Bl(pu(e),[du,fu])}function ku(e){return Bl(e,[mu,_u],[hu,_u],[gu,vu])}function Au(e){return Bl(e,[su,cu])}var ju=zl(ru);function Mu(e){return Bl(e,[ou,ju])}var Nu=Rl(Ql,eu),Pu=Rl($l),Fu=zl(ru,iu,au);function Iu(e){return Bl(e,[Nu,Cu],[Pu,Fu])}var Lu=`Invalid Duration`,Ru={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}},zu={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},...Ru},Bu=146097/400,Vu=146097/4800,Hu={years:{quarters:4,months:12,weeks:Bu/7,days:Bu,hours:Bu*24,minutes:Bu*24*60,seconds:Bu*24*60*60,milliseconds:Bu*24*60*60*1e3},quarters:{months:3,weeks:Bu/28,days:Bu/4,hours:Bu*24/4,minutes:Bu*24*60/4,seconds:Bu*24*60*60/4,milliseconds:Bu*24*60*60*1e3/4},months:{weeks:Vu/7,days:Vu,hours:Vu*24,minutes:Vu*24*60,seconds:Vu*24*60*60,milliseconds:Vu*24*60*60*1e3},...Ru},Uu=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Wu=Uu.slice(0).reverse();function Gu(e,t,n=!1){return new Yu({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 Ku(e,t){let n=t.milliseconds??0;for(let r of Wu.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function qu(e,t){let n=Ku(e,t)<0?-1:1;Uu.reduceRight((r,i)=>{if(S(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),Uu.reduce((n,r)=>{if(S(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Ju(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Yu=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Hu:zu;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||x.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 Xo(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:pl(t,e.normalizeUnit),loc:x.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(zc(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Xo(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=Au(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]=Mu(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 Xo(`need to specify a reason the Duration is invalid`);let r=t instanceof Sc?t:new Sc(t,n);if(xc.throwOnInvalid)throw new qo(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 Yo(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?Il.create(this.loc,n).formatDurationFromString(this,e):Lu}toHuman(e={}){if(!this.isValid)return Lu;let t=e.showZeros!==!1,n=Uu.map(n=>{let r=this.values[n];return S(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+=nl(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},w.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?Ku(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 Uu)(Jc(n.values,e)||Jc(this.values,e))&&(r[e]=n.get(e)+this.get(e));return Gu(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]=fl(e(this.values[n],n));return Gu(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...pl(t,e.normalizeUnit)};return Gu(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 Gu(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return qu(this.matrix,e),Gu(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Ju(this.normalize().shiftToAll().toObject());return Gu(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 Uu)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;zc(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else zc(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 qu(this.matrix,n),Gu(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 Gu(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Ju(this.values);return Gu(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 Uu)if(!t(this.values[n],e.values[n]))return!1;return!0}},Xu=`Invalid Interval`;function Zu(e,t){return!e||!e.isValid?Qu.invalid(`missing or invalid start`):!t||!t.isValid?Qu.invalid(`missing or invalid end`):t<e?Qu.invalid(`end before start`,`The end of an interval must be after its start, but you had start=${e.toISO()} and end=${t.toISO()}`):null}var Qu=class e{constructor(e){this.s=e.start,this.e=e.end,this.invalid=e.invalid||null,this.isLuxonInterval=!0}static invalid(t,n=null){if(!t)throw new Xo(`need to specify a reason the Interval is invalid`);let r=t instanceof Sc?t:new Sc(t,n);if(xc.throwOnInvalid)throw new Ko(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=ef(t),i=ef(n);return Zu(r,i)??new e({start:r,end:i})}static after(t,n){let r=Yu.fromDurationLike(n),i=ef(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Yu.fromDurationLike(n),i=ef(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=w.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=w.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Yu.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Yu.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(ef).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=Yu.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()})`:Xu}[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=es,t={}){return this.isValid?Il.create(this.s.loc.clone(t),e).formatInterval(this):Xu}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Xu}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Xu}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Xu}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Xu}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Yu.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},$u=class{static hasDST(e=xc.defaultZone){let t=w.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return js.isValidZone(e)}static normalizeZone(e){return ac(e,xc.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||x.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||x.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||x.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||x.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||x.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||x.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||x.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return x.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return x.create(t,null,`gregory`).eras(e)}static features(){return{relative:Uc(),localeWeek:Wc()}}};function ed(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Yu.fromMillis(r).as(`days`))}function td(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=ed(e,t);return(n-n%7)/7}],[`days`,ed]],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 nd(e,t,n,r){let[i,a,o,s]=td(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=Yu.fromObject(a,r);return l.length>0?Yu.fromMillis(c,r).shiftTo(...l).plus(u):u}var rd=`missing Intl.DateTimeFormat.formatToParts support`;function C(e,t=e=>e){return{regex:e,deser:([e])=>t(lc(e))}}var id=`[ \xA0]`,ad=new RegExp(id,`g`);function od(e){return e.replace(/\./g,`\\.?`).replace(ad,id)}function sd(e){return e.replace(/\./g,``).replace(ad,` `).toLowerCase()}function cd(e,t){return e===null?null:{regex:RegExp(e.map(od).join(`|`)),deser:([n])=>e.findIndex(e=>sd(n)===sd(e))+t}}function ld(e,t){return{regex:e,deser:([,e,t])=>dl(e,t),groups:t}}function ud(e){return{regex:e,deser:([e])=>e}}function dd(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function fd(e,t){let n=fc(t),r=fc(t,`{2}`),i=fc(t,`{3}`),a=fc(t,`{4}`),o=fc(t,`{6}`),s=fc(t,`{1,2}`),c=fc(t,`{1,3}`),l=fc(t,`{1,6}`),u=fc(t,`{1,9}`),d=fc(t,`{2,4}`),f=fc(t,`{4,6}`),p=e=>({regex:RegExp(dd(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return cd(t.eras(`short`),0);case`GG`:return cd(t.eras(`long`),0);case`y`:return C(l);case`yy`:return C(d,ll);case`yyyy`:return C(a);case`yyyyy`:return C(f);case`yyyyyy`:return C(o);case`M`:return C(s);case`MM`:return C(r);case`MMM`:return cd(t.months(`short`,!0),1);case`MMMM`:return cd(t.months(`long`,!0),1);case`L`:return C(s);case`LL`:return C(r);case`LLL`:return cd(t.months(`short`,!1),1);case`LLLL`:return cd(t.months(`long`,!1),1);case`d`:return C(s);case`dd`:return C(r);case`o`:return C(c);case`ooo`:return C(i);case`HH`:return C(r);case`H`:return C(s);case`hh`:return C(r);case`h`:return C(s);case`mm`:return C(r);case`m`:return C(s);case`q`:return C(s);case`qq`:return C(r);case`s`:return C(s);case`ss`:return C(r);case`S`:return C(c);case`SSS`:return C(i);case`u`:return ud(u);case`uu`:return ud(s);case`uuu`:return C(n);case`a`:return cd(t.meridiems(),0);case`kkkk`:return C(a);case`kk`:return C(d,ll);case`W`:return C(s);case`WW`:return C(r);case`E`:case`c`:return C(n);case`EEE`:return cd(t.weekdays(`short`,!1),1);case`EEEE`:return cd(t.weekdays(`long`,!1),1);case`ccc`:return cd(t.weekdays(`short`,!0),1);case`cccc`:return cd(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return ld(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return ld(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return ud(/[a-z_+-/]{1,256}?/i);case` `:return ud(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:rd};return m.token=e,m}var pd={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 md(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=pd[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function hd(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function gd(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Jc(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 _d(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 S(e.z)||(n=js.create(e.z)),S(e.Z)||(n||=new rc(e.Z),r=e.Z),S(e.q)||(e.M=(e.q-1)*3+1),S(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),S(e.u)||(e.S=tl(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var vd=null;function yd(){return vd||=w.fromMillis(1555555555555),vd}function bd(e,t){if(e.literal)return e;let n=Td(Il.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function xd(e,t){return Array.prototype.concat(...e.map(e=>bd(e,t)))}var Sd=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=xd(Il.parseFormat(t),e),this.units=this.tokens.map(t=>fd(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=hd(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=gd(e,this.regex,this.handlers),[r,i,a]=n?_d(n):[null,null,void 0];if(Jc(n,`a`)&&Jc(n,`H`))throw new Jo(`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 Cd(e,t,n){return new Sd(e,n).explainFromTokens(t)}function wd(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=Cd(e,t,n);return[r,i,a,o]}function Td(e,t){if(!e)return null;let n=Il.create(t,e).dtFormatter(yd()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>md(t,e,i))}var Ed=`Invalid DateTime`,Dd=864e13;function Od(e){return new Sc(`unsupported zone`,`the zone "${e.name}" is not supported`)}function kd(e){return e.weekData===null&&(e.weekData=Ac(e.c)),e.weekData}function Ad(e){return e.localWeekData===null&&(e.localWeekData=Ac(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function jd(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new w({...n,...t,old:n})}function Md(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 Nd(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 Pd(e,t,n){return Md(ol(e),t,n)}function Fd(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,al(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Yu.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]=Md(ol(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function Id(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=w.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return w.invalid(new Sc(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function Ld(e,t,n=!0){return e.isValid?Il.create(x.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function Rd(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=Qc(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=Qc(e.c.month),n===`month`)return i;i+=`-`}else if(i+=Qc(e.c.month),n===`month`)return i;return i+=Qc(e.c.day),i}function zd(e,t,n,r,i,a,o){let s=!n||e.c.millisecond!==0||e.c.second!==0,c=``;switch(o){case`day`:case`month`:case`year`:break;default:if(c+=Qc(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=Qc(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=Qc(e.c.second))}else{if(c+=Qc(e.c.minute),o===`minute`)break;s&&(c+=Qc(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=Qc(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=Qc(Math.trunc(-e.o/60)),c+=`:`,c+=Qc(Math.trunc(-e.o%60))):(c+=`+`,c+=Qc(Math.trunc(e.o/60)),c+=`:`,c+=Qc(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Bd={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Vd={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Hd={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Ud=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],Wd=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],Gd=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function Kd(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 Yo(e);return t}function qd(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return Kd(e)}}function Jd(e){if(Qd===void 0&&(Qd=xc.now()),e.type!==`iana`)return e.offset(Qd);let t=e.name,n=$d.get(t);return n===void 0&&(n=e.offset(Qd),$d.set(t,n)),n}function Yd(e,t){let n=ac(t.zone,xc.defaultZone);if(!n.isValid)return w.invalid(Od(n));let r=x.fromObject(t),i,a;if(S(e.year))i=xc.now();else{for(let t of Ud)S(e[t])&&(e[t]=Bd[t]);let t=Lc(e)||Rc(e);if(t)return w.invalid(t);let r=Jd(n);[i,a]=Pd(e,r,n)}return new w({ts:i,zone:n,loc:r,o:a})}function Xd(e,t,n){let r=S(n.round)?!0:n.round,i=S(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=nl(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 Zd(e){let t={},n;return e.length>0&&typeof e[e.length-1]==`object`?(t=e[e.length-1],n=Array.from(e).slice(0,e.length-1)):n=Array.from(e),[t,n]}var Qd,$d=new Map,w=class e{constructor(e){let t=e.zone||xc.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new Sc(`invalid input`):null)||(t.isValid?null:Od(t));this.ts=S(e.ts)?xc.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=zc(e.o)&&!e.old?e.o:t.offset(this.ts);r=Nd(this.ts,a),n=Number.isNaN(r.year)?new Sc(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||x.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]=Zd(arguments),[n,r,i,a,o,s,c]=t;return Yd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=Zd(arguments),[n,r,i,a,o,s,c]=t;return e.zone=rc.utcInstance,Yd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Hc(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=ac(n.zone,xc.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:x.fromObject(n)}):e.invalid(Od(i))}static fromMillis(t,n={}){if(!zc(t))throw new Xo(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>Dd?e.invalid(`Timestamp out of range`):new e({ts:t,zone:ac(n.zone,xc.defaultZone),loc:x.fromObject(n)})}static fromSeconds(t,n={}){if(zc(t))return new e({ts:t*1e3,zone:ac(n.zone,xc.defaultZone),loc:x.fromObject(n)});throw new Xo(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=ac(n.zone,xc.defaultZone);if(!r.isValid)return e.invalid(Od(r));let i=x.fromObject(n),a=pl(t,qd),{minDaysInFirstWeek:o,startOfWeek:s}=Pc(a,i),c=xc.now(),l=S(n.specificOffset)?r.offset(c):n.specificOffset,u=!S(a.ordinal),d=!S(a.year),f=!S(a.month)||!S(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new Jo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Jo(`Can't mix ordinal dates with month/day`);let ee=m||a.weekday&&!p,te,ne,re=Nd(c,l);ee?(te=Wd,ne=Vd,re=Ac(re,o,s)):u?(te=Gd,ne=Hd,re=Mc(re)):(te=Ud,ne=Bd);let ie=!1;for(let e of te){let t=a[e];S(t)?ie?a[e]=ne[e]:a[e]=re[e]:ie=!0}let ae=(ee?Fc(a,o,s):u?Ic(a):Lc(a))||Rc(a);if(ae)return e.invalid(ae);let[oe,se]=Pd(ee?jc(a,o,s):u?Nc(a):a,l,r),ce=new e({ts:oe,zone:r,o:se,loc:i});return a.weekday&&p&&t.weekday!==ce.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${ce.toISO()}`):ce.isValid?ce:e.invalid(ce.invalid)}static fromISO(e,t={}){let[n,r]=Du(e);return Id(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=Ou(e);return Id(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=ku(e);return Id(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(S(t)||S(n))throw new Xo(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=wd(x.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):Id(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]=Iu(e);return Id(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Xo(`need to specify a reason the DateTime is invalid`);let r=t instanceof Sc?t:new Sc(t,n);if(xc.throwOnInvalid)throw new Go(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=Td(e,x.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return xd(Il.parseFormat(e),x.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){Qd=void 0,$d.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?kd(this).weekYear:NaN}get weekNumber(){return this.isValid?kd(this).weekNumber:NaN}get weekday(){return this.isValid?kd(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?Ad(this).weekday:NaN}get localWeekNumber(){return this.isValid?Ad(this).weekNumber:NaN}get localWeekYear(){return this.isValid?Ad(this).weekYear:NaN}get ordinal(){return this.isValid?Mc(this.c).ordinal:NaN}get monthShort(){return this.isValid?$u.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?$u.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?$u.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?$u.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=ol(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=Nd(s,a),u=Nd(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[jd(this,{ts:s}),jd(this,{ts:c})]:[this]}get isInLeapYear(){return rl(this.year)}get daysInMonth(){return al(this.year,this.month)}get daysInYear(){return this.isValid?il(this.year):NaN}get weeksInWeekYear(){return this.isValid?cl(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?cl(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=Il.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(rc.instance(e),t)}toLocal(){return this.setZone(xc.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=ac(t,xc.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]=Pd(r,n,t)}return jd(this,{ts:e,zone:t})}else return e.invalid(Od(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return jd(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=pl(e,qd),{minDaysInFirstWeek:n,startOfWeek:r}=Pc(t,this.loc),i=!S(t.weekYear)||!S(t.weekNumber)||!S(t.weekday),a=!S(t.ordinal),o=!S(t.year),s=!S(t.month)||!S(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new Jo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Jo(`Can't mix ordinal dates with month/day`);let u;i?u=jc({...Ac(this.c,n,r),...t},n,r):S(t.ordinal)?(u={...this.toObject(),...t},S(t.day)&&(u.day=Math.min(al(u.year,u.month),u.day))):u=Nc({...Mc(this.c),...t});let[d,f]=Pd(u,this.o,this.zone);return jd(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Yu.fromDurationLike(e);return jd(this,Fd(this,t))}minus(e){if(!this.isValid)return this;let t=Yu.fromDurationLike(e).negate();return jd(this,Fd(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Yu.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?Il.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):Ed}toLocaleString(e=es,t={}){return this.isValid?Il.create(this.loc.clone(t),e).formatDateTime(this):Ed}toLocaleParts(e={}){return this.isValid?Il.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=Kd(a);let o=e===`extended`,s=Rd(this,o,a);return Ud.indexOf(a)>=3&&(s+=`T`),s+=zd(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?Rd(this,e===`extended`,Kd(t)):null}toISOWeekDate(){return Ld(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=Kd(o),(r&&Ud.indexOf(o)>=3?`T`:``)+zd(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return Ld(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return Ld(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?Rd(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`)),Ld(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():Ed}[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 Yu.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Gc(t).map(Yu.normalizeUnit),a=e.valueOf()>this.valueOf(),o=nd(a?this:e,a?e:this,i,r);return a?o.negate():o}diffNow(t=`milliseconds`,n={}){return this.diff(e.now(),t,n)}until(e){return this.isValid?Qu.fromDateTimes(this,e):this}hasSame(e,t,n){if(!this.isValid)return!1;let r=e.valueOf(),i=this.setZone(e.zone,{keepLocalTime:!0});return i.startOf(t,n)<=r&&r<=i.endOf(t,n)}equals(e){return this.isValid&&e.isValid&&this.valueOf()===e.valueOf()&&this.zone.equals(e.zone)&&this.loc.equals(e.loc)}toRelative(t={}){if(!this.isValid)return null;let n=t.base||e.fromObject({},{zone:this.zone}),r=t.padding?this<n?-t.padding:t.padding:0,i=[`years`,`months`,`days`,`hours`,`minutes`,`seconds`],a=t.unit;return Array.isArray(t.unit)&&(i=t.unit,a=void 0),Xd(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?Xd(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 Xo(`min requires all arguments be DateTimes`);return Kc(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Xo(`max requires all arguments be DateTimes`);return Kc(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return Cd(x.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 Sd(x.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(S(t)||S(n))throw new Xo(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=x.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Xo(`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):Id(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return es}static get DATE_MED(){return ts}static get DATE_MED_WITH_WEEKDAY(){return ns}static get DATE_FULL(){return rs}static get DATE_HUGE(){return is}static get TIME_SIMPLE(){return as}static get TIME_WITH_SECONDS(){return os}static get TIME_WITH_SHORT_OFFSET(){return ss}static get TIME_WITH_LONG_OFFSET(){return cs}static get TIME_24_SIMPLE(){return ls}static get TIME_24_WITH_SECONDS(){return us}static get TIME_24_WITH_SHORT_OFFSET(){return ds}static get TIME_24_WITH_LONG_OFFSET(){return fs}static get DATETIME_SHORT(){return ps}static get DATETIME_SHORT_WITH_SECONDS(){return ms}static get DATETIME_MED(){return hs}static get DATETIME_MED_WITH_SECONDS(){return gs}static get DATETIME_MED_WITH_WEEKDAY(){return _s}static get DATETIME_FULL(){return vs}static get DATETIME_FULL_WITH_SECONDS(){return ys}static get DATETIME_HUGE(){return bs}static get DATETIME_HUGE_WITH_SECONDS(){return xs}};function ef(e){if(w.isDateTime(e))return e;if(e&&e.valueOf&&zc(e.valueOf()))return w.fromJSDate(e);if(e&&typeof e==`object`)return w.fromObject(e);throw new Xo(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function tf(e){if(e===`*`)return{min:1,max:`*`};let[t,n]=e.split(`..`),r=Number(t);return n===void 0?{min:r,max:r}:{min:r,max:n===`*`?`*`:Number(n)}}var nf=`1`,rf=`0..1`,af=`*`,of=`0..*`,sf=new Map([[`-`,[`1`,`1`]],[`<>`,[`*`,`*`]],[`>`,[`*`,`1`]],[`<`,[`1`,`*`]],[`-?`,[`1`,rf]],[`?-`,[rf,`1`]],[`?-?`,[rf,rf]],[`?>`,[of,`1`]],[`>?`,[`*`,rf]],[`?>?`,[of,rf]],[`?<`,[rf,`*`]],[`<?`,[`1`,of]],[`?<?`,[rf,of]],[`?<>`,[of,`*`]],[`<>?`,[`*`,of]],[`?<>?`,[of,of]]]),cf=new Map([...sf.entries()].map(([e,[t,n]])=>[`${t}-${n}`,e]));function lf(e){return sf.get(e)}function uf(e){return tf(e).max===1}function df(e){return tf(e).max===`*`}function ff(e){return tf(e).min===0}function pf(e){return tf(e).min>=1}function mf(e){return e.replace(/\?/g,``)}function hf(e,t){return cf.get(`${e}-${t}`)??`<>`}function gf(e){let{min:t,max:n}=tf(e);return t===0?e:n===`*`?of:rf}function _f(e){let{min:t,max:n}=tf(e);return t>=1?e:n===`*`?`*`:`1`}function vf(e){let{min:t,max:n}=tf(e);return n===`*`?e:t===0?of:`*`}var T=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.UNKNOWN_NOTE_SETTING=3047]=`UNKNOWN_NOTE_SETTING`,e[e.DUPLICATE_NOTE_SETTING=3048]=`DUPLICATE_NOTE_SETTING`,e[e.INVALID_NOTE_SETTING_VALUE=3049]=`INVALID_NOTE_SETTING_VALUE`,e[e.INVALID_INDEXES_CONTEXT=3050]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3051]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3052]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3053]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3054]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3055]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3056]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3057]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3058]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3059]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3060]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3061]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3062]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3063]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3064]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3065]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3066]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3067]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3068]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3069]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3070]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3071]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3072]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3073]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3074]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3075]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3076]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3077]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3078]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3079]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3080]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3081]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3082]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3083]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3084]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.INVALID_USE_CONTEXT=3085]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3086]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3087]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3088]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3089]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3090]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3091]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.UNEQUAL_FIELDS_BINARY_REF=5003]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5004]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e[e.INVALID_METADATA_TARGET_KIND=5006]=`INVALID_METADATA_TARGET_KIND`,e[e.INVALID_METADATA_FIELD=5007]=`INVALID_METADATA_FIELD`,e[e.DUPLICATE_METADATA_FIELD=5008]=`DUPLICATE_METADATA_FIELD`,e}({}),E=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 yf(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},yf=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,E.prototype)}get filepath(){return this.nodeOrToken.filepath}},bf=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.quickFixes=i?.quickFixes,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}get filepath(){return this.nodeOrToken.filepath}};function xf(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Sf(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Cf(e){let[t]=e;return Sf(t)||xf(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function wf(e){return xf(e)||Sf(e)}function Tf(e){let t=j(e);return t!==void 0&&t.length>0}function Ef(e){return Df(e)}function Df(e){return e instanceof Sm&&e.expression instanceof xm}function Of(e){return!!e.bodyColon}function kf(e){return e instanceof B&&e.op?.value===`~`&&D(e.expression)}function Af(e){return e!==void 0&&sf.has(e)}function jf(e){if(!(e instanceof Sm)||!(e.expression instanceof ym)||e.expression.literal?.kind!==v.COLOR_LITERAL)return!1;let t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!==`#`)return!1;for(let e=1;e<t.length;e+=1)if(!Cf(t[e]))return!1;return!0}function Mf(e){return jf(e)?!0:Hf(e)&&e.expression.variable.value.toLowerCase()===`none`}function Nf(e){if(Bf(e)||Pf(e)||Hf(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof B&&To.includes(e.op?.value)&&Pf(e.expression)||e instanceof hm)return!0;if(!e||!Uf(e))return!1;let t=sp(e);return t.length===2||t.length===3}function Pf(e){return e instanceof B?To.includes(e.op.value)?Pf(e.expression):!1:e instanceof Sm&&e.expression instanceof ym&&e.expression.literal?.kind===v.NUMERIC_LITERAL}function Ff(e){if(!(e instanceof B)||!Af(e.op?.value))return!1;let t=j(e.expression);return t!==void 0&&t.length>0}function If(e){return e instanceof gm&&e.elementList.every(D)}function Lf(e){if(!(e instanceof W||O(e)||e instanceof Sm||e instanceof wm))return!1;for(;e instanceof W||e instanceof wm;)if(e instanceof W){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Pf(e)||Bf(e)||Hf(e)))return!1;e=e.callee}else if(e instanceof wm){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Pf(e.name)))return!1;e=e.array}let t=j(e);return t!==void 0&&t.length>0}function Rf(e){return Bf(e)||jf(e)}function zf(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof Sm){r.push(new E(T.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=rp(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 Bf(e){return e instanceof Sm&&(e.expression instanceof xm&&e.expression.variable instanceof Va&&e.expression.variable.kind===v.QUOTED_STRING||e.expression instanceof ym&&e.expression.literal?.kind===v.STRING_LITERAL)}function D(e){return e instanceof Sm&&e.expression instanceof xm&&e.expression.variable instanceof Va}function Vf(e){return e?e instanceof bm:!1}function Hf(e){return e instanceof Sm&&e.expression instanceof xm&&e.expression.variable?.kind===v.IDENTIFIER}function O(e){return e instanceof pm&&e.leftExpression instanceof I&&e.rightExpression instanceof I&&e.op?.value===`.`}function Uf(e){return D(e)?!0:O(e)&&D(e.rightExpression)&&Uf(e.leftExpression)}function k(e,t){return e instanceof R&&e.isKind(t)}function Wf(e){return e instanceof lm}function Gf(e,t){return e instanceof um&&(t===void 0||e.isKind(t))}function Kf(e){return e instanceof L}function A(e,...t){return e instanceof V&&e.parent instanceof R&&e.parent.isKind(...t)}function qf(e,t){let n=e.parent;return n instanceof R&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Jf(e,t){let n=e.parentOfKind(V);if(!n||t<0)return!1;if(t===0)return n.callee?n.callee.containsEq(e):!1;let r=n.args[t-1];return r?r.containsEq(e):!1}function Yf(e){return!!e.parentOfKind(U)}function Xf(e,t){let n=e.parentOfKind(z);return!n||(n.name instanceof Sm?N(n.name):rp(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function Zf(e){return!(e instanceof pm)||!Af(e.op?.value)?!1:cp(e.leftExpression)!==void 0&&cp(e.rightExpression)!==void 0}function Qf(e){let t=cp(e.leftExpression),n=cp(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function $f(e){return e instanceof Sm&&e.expression instanceof xm||e instanceof hm}function ep(e){if(D(e))return e;if(O(e)){let t=e.rightExpression;if(t&&D(t))return t}}function tp(e){let t=e.parentNode;return!O(t)||t.rightExpression!==e?!1:!(O(t.parentNode)&&t.parentNode.leftExpression===t)}function np(e){if(D(e))return e.expression.variable}function rp(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function ip(e){if(!(e instanceof R))return;let t=j(e?.name);return t===void 0?void 0:t.join(`.`)}function ap(e){return e.elementList.length===0}function op(e){return e?.body?e.body instanceof H?e.body.body:[e.body]:[]}function sp(e){if(!e)return;if(!O(e))return[e];let t=sp(e.leftExpression);if(t)return t.push(e.rightExpression),t}function j(e){if(e===void 0)return;let t=sp(e);if(!t)return;let n=[];for(let e of t){let t=N(e);if(typeof t!=`string`)return;n.push(t)}return n}function cp(e){if(e===void 0)return;let t=sp(e);if(!t||t.length===0)return;let n=[];if(!D(g(t))){let e=t.pop();if(If(e))n=e.elementList;else return}let r=t;if(r.every(D))return{variables:r,tupleElements:n}}function lp(e){if($f(e))return e instanceof hm?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof gm&&e.elementList.every($f))return{functional:e.elementList.filter(e=>e instanceof hm),nonFunctional:e.elementList.filter(D)}}function M(e){if(Bf(e))return e.expression instanceof xm?e?.expression?.variable?.value:e.expression.literal.value}function up(e){return e instanceof Sm&&e.expression instanceof ym&&e.expression.literal?.kind===v.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function dp(e){if(!(e instanceof W)||!e.callee)return;let t=sp(e.callee);if(!t||t.length===0||!t.every(D))return;let n=[];return If(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function N(e){if(D(e))return e.expression.variable.value}function fp(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function pp(e){return Hf(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Cm}function mp(e){return M(e)===``}function hp(e){return e instanceof hm}function gp(e){let t=up(e);if(t!==null)return t;if(Pf(e)&&e instanceof B&&e.expression){let t=e.op?.value,n=up(e.expression);if(n!==null)return t===`-`?-n:n}return null}function _p(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return+!!e;let t=gp(e);if(t!==null)return t;let n=M(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function vp(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return+!!e;let t=gp(e);if(t!==null)return Number.isInteger(t)?t:null;let n=M(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var yp=[`true`,`yes`,`y`,`t`,`1`],bp=[`false`,`no`,`n`,`f`,`0`];function xp(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 yp.includes(t)?!0:bp.includes(t)?!1:null}if(Hf(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=up(e);if(t===0)return!1;if(t===1)return!0;let n=M(e)?.toLowerCase();if(n){if(yp.includes(n))return!0;if(bp.includes(n))return!1}return null}function Sp(e){if(e==null)return null;if(typeof e==`string`)return e;let t=j(e);return t?g(t):M(e)??null}function Cp(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=M(e)??null??_p(e)??xp(e);return t===null?null:t.toString()}var wp=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Tp=[`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`],Ep=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Dp(e){if(e==null)return null;let t=typeof e==`string`?e:M(e)??null;if(t===null)return null;for(let e of Ep){let n=w.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of wp){let n=w.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Tp){let n=w.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=w.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 Op(e){return e instanceof B?`${e.op?.value}${Op(e.expression)}`:e.expression.literal.value}function kp(e){return e instanceof B?e.op?.value===`-`?-kp(e.expression):kp(e.expression):Number.parseFloat(e.expression.literal.value)}function P(e){return{start:{offset:e.startPos.offset,line:e.startPos.line+1,column:e.startPos.column+1},end:{offset:e.endPos.offset,line:e.endPos.line+1,column:e.endPos.column+1},filepath:e.filepath}}function Ap(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 Ep(e){let t=N(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function Dp(e){if(e instanceof hm&&e.expression instanceof fm&&e.expression.literal?.kind===y.COLOR_LITERAL)return e.expression.literal.value;if(Lf(e)&&F(e)?.toLowerCase()===`none`)return xo}function Op(e){if(e){if(O(e)){let t=P(e);if(t!==void 0)return{value:t,type:`string`}}if(Mf(e))return{type:`number`,value:wp(e)};if(Lf(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof sm&&e.value)return{value:e.value.value,type:`expression`};if(Rf(e)){let t=np(e)?.at(-1),n=t?F(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function kp(e,t){let r=``,i=null;if(t instanceof dm){if(i=(t.argumentList?.elementList??[]).map(e=>Mf(e)?Cp(e):O(e)?P(e):F(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof dm||t instanceof _m;)if(t instanceof dm){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Mf(e)?Cp(e):O(e)?P(e):F(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof _m){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}=Ep(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new E(T.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}var L=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}({}),Ap={Table:`Table`,Enum:`Enum`,TableGroup:`TableGroup`,TablePartial:`TablePartial`,Note:`Note`,Schema:`Schema`},jp=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Mp=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 I(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()}},Np=class e extends Mp{constructor({name:e,parent:t},n,r){super({kind:`Schema`},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===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}},Pp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`Enum`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Fp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`Enum field`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Tp(P(i));if(a)return{value:a,token:I(r)}}},Ip=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`Table`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}schema(e){let t=this.canonicalName(e,this.filepath);return t?t.schema===`public`?null:t.schema:null}columns(e){return this.mergedColumns(e).filter(e=>!(e instanceof Qp))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(`Column`))}partialInjections(e){return this.members(e).filter(e=>e.isKind(`PartialInjection`))}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Tp(P(i));if(a)return{value:a,token:I(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?Dp(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===ym.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===ym.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===ym.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===ym.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof U)||!Of(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===ym.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===ym.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=Dp(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=Tp(P(a));if(o)return{value:o,token:I(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Lp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`Column`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}qualifiedName(e){let n=this.name??``,r=(this instanceof Qp?this.injectionDeclaration:this.declaration)?.parentOfKind(B);if(!r)return[n];let i=e.nodeSymbol(r).getFiltered(t);if(!i)return[n];let{schema:a,name:o}=i.interpretedName(e,this.filepath);return a?[a,o,n]:[o,n]}pk(e){if(!this.declaration)return!1;let n=e.nodeSettings(this.declaration).getFiltered(t);return!!(n?.[i.PK]?.length||n?.[i.PrimaryKey]?.length)}isUniqueSet(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Unique]?.length:!1}unique(e){return this.isUniqueSet(e)||this.pk(e)||this.increment(e)}nullable(e){return this.declaration?!(this.pk(e)||this.increment(e)||this.isInPkIndex(e)||e.nodeSettings(this.declaration).getFiltered(t)?.[i.NotNull]?.length):!0}isInPkIndex(e){if(!this.declaration||!this.name)return!1;let n=(this instanceof Qp?this.injectionDeclaration:this.declaration).parentOfKind(B);if(!n)return!1;let r=e.nodeSymbol(n).getFiltered(t);if(!(r instanceof Ip))return!1;for(let t of r.mergedIndexes(e)){let n=e.interpretMetadata(t,this.filepath).getValue();if(!(!n||!Array.isArray(n))){for(let e of n)if(e.pk&&e.columns.some(e=>e.value===this.name))return!0}}return!1}isNotNullSet(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(n?.[i.NotNull]?.length)return!0;if(n?.[i.Null]?.length)return!1}isIncrementSet(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Increment]?.length:!1}increment(e){return this.isIncrementSet(e)||Bo(this.type(e)?.name??``)}default(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t)?.[i.Default]?.at(0)?.value;if(n)return Op(n)}type(e){if(!(this.declaration instanceof U))return;let n=kp(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 Pp?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===ym.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=Tp(P(i));if(a)return{value:a,token:I(r)}}},Rp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`TableGroup`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}fields(e){return this.members(e).filter(e=>e.isKind(`TableGroup field`))}color(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.color?.length?Dp(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=Tp(P(i));if(a)return{value:a,token:I(r)}}},zp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`TableGroup field`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Bp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`Note`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Vp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`TablePartial`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Hp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`PartialInjection`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Up=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Wp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView top-level wildcard`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Gp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView table`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Kp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView tablegroup`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},qp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView note`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Jp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView schema`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Yp=class extends Mp{constructor({declaration:e,name:t},n,r){super({kind:`Program`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}inNestedSchema(e,t){let n=this.members(e);if(n.some(e=>e.originalSymbol===t.originalSymbol))return!0;for(let r of n)if(r instanceof Np&&r.inNestedSchema(e,t))return!0;return!1}},Xp=class extends Mp{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}},Zp=class extends Mp{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(tm);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},Qp=class extends Lp{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},$p=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},R=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 Ba?Ga(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 Ba?Wa(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 B||e instanceof z)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}},em=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}({}),z=class extends R{constructor({body:e=[],eof:t,source:n},r,i){super(r,`<program>`,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===`<element-declaration>`)}get uses(){return this.body.filter(e=>e.kind===`<use-declaration>`)}},tm=class extends R{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,`<use-declaration>`,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return Xa(this.useKeyword)}},nm=class extends R{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,`<use-specifier>`,a,[e,t,n,r]),this.importKind=e,this.name=t,this.asKeyword=n,this.alias=r}isKind(...e){return this.importKind?.value!==void 0&&e.map(e=>e.toLowerCase()).includes(this.importKind.value.toLowerCase())}getSymbolKind(){let e=this.importKind?.value?.toLowerCase();if(e!==void 0)return Object.values(L).find(t=>t.toLowerCase()===e)}},rm=class extends R{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,`<use-specifier-list>`,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},B=class e extends R{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,`<element-declaration>`,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof U||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))}},im=class extends R{constructor({identifiers:e=[]},t,n){super(t,`<identifier-stream>`,n,e||[]),this.identifiers=e}},V=class extends R{constructor({name:e,colon:t,value:n},r,i){super(r,`<attribute>`,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},H=class extends R{constructor({op:e,expression:t},n,r){super(n,`<prefix-expression>`,r,[e,t]),this.op=e,this.expression=t}},am=class extends R{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,`<infix-expression>`,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},om=class extends R{constructor({op:e,expression:t},n,r){super(n,`<postfix-expression>`,r,[t,e]),this.op=e,this.expression=t}},sm=class extends R{constructor({value:e},t,n){super(t,`<function-expression>`,n,[e]),this.value=e}},U=class extends R{constructor({callee:e,args:t=[]},n,r){super(n,`<function-application>`,r,[e,...t]),this.callee=e,this.args=t}},W=class extends R{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,`<block-expression>`,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},G=class extends R{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,`<list-expression>`,a,[e,...vm(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},cm=class extends R{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,`<tuple-expression>`,a,[e,...vm(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},lm=class extends R{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,`<comma-expression>`,r,[...vm(e,t)]),this.elementList=e,this.commaList=t}},um=class extends cm{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=`<group-expression>`}},dm=class extends R{constructor({callee:e,argumentList:t},n,r){super(n,`<call-expression>`,r,[e,t]),this.callee=e,this.argumentList=t}},fm=class extends R{constructor({literal:e},t,n){super(t,`<literal>`,n,[e]),this.literal=e}},pm=class extends R{constructor({token:e},t,n){super(t,`<wildcard>`,n,[e]),this.token=e}},mm=class extends R{constructor({variable:e},t,n){super(t,`<variable>`,n,[e]),this.variable=e}},hm=class extends R{constructor({expression:e},t,n){super(t,`<primary-expression>`,n,[e]),this.expression=e}},gm=class extends R{constructor({prevToken:e},t,n){let r=Ba.create(y.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,`<dummy>`,n,[r])}},_m=class extends R{constructor({expression:e,indexer:t},n,r){super(n,`<array>`,r,[e,t]),this.array=e,this.indexer=t}};function vm(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?yr(Ia(e,t)):yr(Ia(t,e))).filter(e=>e!==null)}var ym=function(e){return e.Ref=`ref`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e}({}),bm=class e{static{this.id=0}constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}},xm=class extends bm{constructor(e){super(e),this.kind=`ref`}container(e){let n=this.declaration.parentOfKind(B);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof B){let t=tp(this.declaration)[0];if(!(t instanceof U))return[];let n=t.callee;return n instanceof am?Dm(e,n.leftExpression):[]}if(this.declaration instanceof V){let n=this.declaration.parentOfKind(U);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof B){let t=tp(this.declaration)[0];if(!(t instanceof U))return[];let n=t.callee;return n instanceof am?Dm(e,n.rightExpression):[]}if(this.declaration instanceof V){let t=this.declaration.value;return t instanceof H?Dm(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof B){let t=tp(this.declaration)[0];if(!(t instanceof U))return;let n=t.callee;return n instanceof am?Om(e,n.leftExpression):void 0}if(this.declaration instanceof V)return this.container(e)}rightTable(e){if(this.declaration instanceof B){let t=tp(this.declaration)[0];if(!(t instanceof U))return;let n=t.callee;return n instanceof am?Om(e,n.rightExpression):void 0}if(this.declaration instanceof V){let t=this.declaration.value;return t instanceof H?Om(e,t.expression)??this.container(e):void 0}}op(e){return this.opToken()?.value}opToken(){if(this.declaration instanceof B){let e=tp(this.declaration)[0];if(!(e instanceof U))return;let t=e.callee;return t instanceof am?t.op:void 0}if(this.declaration instanceof V){let e=this.declaration.value;return e instanceof H?e.op:void 0}}cardinalities(e){let t=this.op(e);return t?cf(t):void 0}leftCardinality(e){let t=this.cardinalities(e);return t?ef(t[0]):void 0}rightCardinality(e){let t=this.cardinalities(e);return t?ef(t[1]):void 0}active(e){if(!(this.declaration instanceof B))return!0;let n=tp(this.declaration)[0];return n?!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length:!0}leftToken(){if(this.declaration instanceof B){let e=tp(this.declaration)[0];if(e instanceof U){let t=e.callee;if(t instanceof am&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof V){let e=this.declaration.parentOfKind(U);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof B){let e=tp(this.declaration)[0];if(e instanceof U){let t=e.callee;if(t instanceof am&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof V,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))}},Sm=class extends bm{constructor(e){super(e),this.kind=`partial ref`}container(e){let n=this.declaration.parentOfKind(B);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof V))return[];let n=this.declaration.parentOfKind(U);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof V))return[];let t=this.declaration.value;return t instanceof H?Dm(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof V)return this.container(e)}rightTable(e){if(!(this.declaration instanceof V))return;let t=this.declaration.value;if(t instanceof H)return Om(e,t.expression)??this.container(e)}op(e){return this.opToken()?.value}opToken(){if(!(this.declaration instanceof V))return;let e=this.declaration.value;if(e instanceof H)return e.op}cardinalities(e){let t=this.op(e);return t?cf(t):void 0}leftToken(){if(this.declaration instanceof V){let e=this.declaration.parentOfKind(U);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof V,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))}},Cm=class extends bm{constructor(e){super(e),this.kind=`table checks`,this.ownerTable=e.parentNode?.parentOfKind(B)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},wm=class extends bm{constructor(e){super(e),this.kind=`indexes`,this.ownerTable=e.parentNode?.parentOfKind(B)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Tm=class extends bm{constructor(e){super(e),this.kind=`records`}table(e){let n=this.declaration,i=n.parent;if(i instanceof B&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof dm))return;let o=op(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)):[]}},Em=class extends bm{constructor(e){super(e),this.kind=`project`}owners(e){let n=this.declaration.filepath,r=e.parseFile(n).getValue().ast,i=e.nodeSymbol(r).getFiltered(t);return i?[i]:[]}};function Dm(e,n){if(!n)return[];let r=rp(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 Om(e,n){if(!n)return;let r=rp(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 km=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},Am=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof W?new n(e.body.flatMap(e=>{if(!(e instanceof U))return[];let t=I(e),n=e.callee instanceof sm?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof G);return a&&(r=P(D(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}},jm={nodeMetadata(t,i){if(j(i,r.Checks)){let t=i.parent;return!t||!j(t,r.Table)&&!j(t,r.TablePartial)?n.create(e):n.create(new Cm(i))}return n.create(e)},bindNode(t,i){return j(i,r.Checks)?n.create(void 0,new km(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===ym.TableChecks?r.declaration instanceof B?new Am(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function Mm(e,t,n){let r=t,i=e;if(i instanceof dm&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Lf(i)||r.length===0)return;let a=[...r],o=Zf(i),s=a.pop();if(!(s instanceof W))return;let c=_(a)instanceof G?a.pop():void 0;if(a.length===3){let e=Zf(a[1]);return!e||!qa(e)?void 0:n.create(B,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(B,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(B,{type:o,attributeList:c,body:s})}function K(e){e&&(e instanceof Ba?Nm(e):Pm(e))}function Nm(e){e.kind!==y.EOF&&(e.isInvalid=!0)}function Pm(e){if(e instanceof B)K(e.type),K(e.name),K(e.as),K(e.alias),K(e.bodyColon),K(e.attributeList),K(e.body);else if(e instanceof im)e.identifiers.forEach(K);else if(e instanceof V)K(e.name),K(e.colon),K(e.value);else if(e instanceof H)K(e.op),K(e.expression);else if(e instanceof am)K(e.leftExpression),K(e.op),K(e.rightExpression);else if(e instanceof om)K(e.op),K(e.expression);else if(e instanceof W)K(e.blockOpenBrace),e.body.forEach(K),K(e.blockCloseBrace);else if(e instanceof G)K(e.listOpenBracket),e.commaList.forEach(K),e.elementList.forEach(K),K(e.listCloseBracket);else if(e instanceof cm)K(e.tupleOpenParen),e.commaList.forEach(K),e.elementList.forEach(K),K(e.tupleCloseParen);else if(e instanceof lm)e.commaList.forEach(K),e.elementList.forEach(K);else if(e instanceof dm)K(e.callee),K(e.argumentList);else if(e instanceof U)K(e.callee),e.args.forEach(K);else if(e instanceof hm)K(e.expression);else if(e instanceof sm)K(e.value);else if(e instanceof mm)K(e.variable);else if(e instanceof fm)K(e.literal);else if(e instanceof um)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof _m)K(e.array),K(e.indexer);else if(e instanceof z)e.body.forEach(K),K(e.eof);else if(!(e instanceof gm))if(e instanceof tm)K(e.useKeyword),K(e.specifiers),K(e.fromKeyword),K(e.importPath);else if(e instanceof rm)K(e.openBrace),e.specifiers.forEach(K),K(e.closeBrace);else if(e instanceof nm)K(e.importKind),K(e.name),K(e.asKeyword),K(e.alias);else if(e instanceof pm)K(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Fm(...e){return e.filter(e=>e!==void 0)}function Im(e){if(e instanceof z)return Fm(...e.body,e.eof);if(e instanceof B)return Fm(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof V)return Fm(e.name,e.colon,e.value);if(e instanceof im)return e.identifiers;if(e instanceof fm)return e.literal?[e.literal]:[];if(e instanceof mm)return Fm(e.variable);if(e instanceof H)return Fm(e.op,e.expression);if(e instanceof am)return Fm(e.leftExpression,e.op,e.rightExpression);if(e instanceof om)return Fm(e.expression,e.op);if(e instanceof sm)return Fm(e.value);if(e instanceof U)return Fm(e.callee,...e.args);if(e instanceof W)return Fm(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof G)return Fm(e.listOpenBracket,...Lm(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof cm)return Fm(e.tupleOpenParen,...Lm(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof lm)return Fm(...Lm(e.elementList,e.commaList));if(e instanceof dm)return Fm(e.callee,e.argumentList);if(e instanceof hm)return Fm(e.expression);if(e instanceof _m)return Fm(e.array,e.indexer);if(e instanceof gm)return[];if(e instanceof tm)return Fm(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof rm)return Fm(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof nm)return Fm(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof pm)return Fm(e.token);throw e instanceof um?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Lm(e,t){let n=[],r=Math.min(e.length,t.length);for(let i=0;i<r;i+=1)n.push(e[i],t[i]);return n.push(...e.slice(r),...t.slice(r)),n}function Rm(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function zm(e){if(!e)return[];if(k(e))return[{variables:[e],tupleElements:[]}];if(e instanceof am){let t=rp(e);return t?[t]:[...zm(e.leftExpression),...zm(e.rightExpression)]}if(e instanceof H||e instanceof om)return zm(e.expression);if(e instanceof cm){let t=rp(e);return t?[t]:e.elementList.flatMap(zm)}return[]}function Bm(e,n){let r=n.parentNode;if(!r||!A(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;A(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}var Vm=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof W?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=v(e.body,e=>e instanceof U);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof W)?[]: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 U);return t.flatMap(e=>!e.callee||If(e.callee)?[]:[e.callee,...e.args].flatMap(zm).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables.pop();return[...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}))}bindNoteReferences(e){let[t]=v(e.body,e=>e instanceof U);return t.flatMap(e=>!e.callee||If(e.callee)?[]:zm(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 U);return t.flatMap(e=>!e.callee||If(e.callee)?[]:zm(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 U);return t.flatMap(e=>!e.callee||If(e.callee)?[]:zm(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},Hm=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 W&&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 U&&If(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 B),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof W&&this.interpretSubBlock(e.body,t)}let i=this.diagramView.visibleEntities;return(n.has(`tables`)&&i.tables!==null||n.has(`tablegroups`)&&i.tableGroups!==null||n.has(`schemas`)&&i.schemas!==null)&&(n.has(`tables`)||(i.tables=[]),n.has(`tablegroups`)||(i.tableGroups=[]),n.has(`schemas`)||(i.schemas=[])),n.has(r.DiagramViewTables)&&this.diagramViewExplicitlySet.add(`tables`),n.has(r.DiagramViewTableGroups)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(r.DiagramViewSchemas)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(r.DiagramViewNotes)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,n){if(!n)return;if(e.body.some(e=>e instanceof U&&If(e.callee))){let e=this.diagramViewWildcards;switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=[],e.add(`tables`);break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=[],e.add(`stickyNotes`);break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=[],e.add(`tableGroups`);break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=[],e.add(`schemas`);break}return}if(e.body.length===0)return;let i=[];for(let n of e.body){if(!(n instanceof U))continue;let e=n.callee&&Yf(n.callee),r=e&&this.compiler.nodeReferee(e).getFiltered(t);if(r?.declaration instanceof B){let e=N(r.declaration.name)??[];if(e.length>0){let t=e[e.length-1],n=e.length>1?e.slice(0,-1).join(`.`):b;i.push({name:t,schemaName:n});continue}}let a=N(n.callee)??[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[0]:b;i.push({name:o,schemaName:s})}switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=i.length>0?i:null;break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=i.length>0?i.map(e=>({name:e.name})):null;break}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;if(!(!t||!e)){if(t.has(`tables`)||t.has(`schemas`)){e.tables=[],e.tableGroups=[],e.schemas=[];return}t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames())}}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n)return[];let r=this.compiler.symbolMembers(n).getFiltered(t);return r?Na(r.filter(e=>e.isKind(L.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function Um(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var Wm=function(e){return e.Table=`table`,e}({}),Gm={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new E(T.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},Km={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return j(a,r.DiagramView)?new n(i.symbolFactory.create(Up,{declaration:a,name:o},a.filepath)):M(a,r.DiagramView)&&a instanceof pm?new n(i.symbolFactory.create(Wp,{declaration:a,name:o},a.filepath)):M(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(qp,{declaration:a,name:o},a.filepath)):M(a,r.DiagramViewTables)?new n(i.symbolFactory.create(Gp,{declaration:a,name:o},a.filepath)):M(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(Kp,{declaration:a,name:o},a.filepath)):M(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(Jp,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&Wf(a))return n.create(e);let o=qm(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)?Jm(i,c,a):o.isKind(r.DiagramViewNotes)?Ym(i,c,a,L.StickyNote):o.isKind(r.DiagramViewTableGroups)?Ym(i,c,a,L.TableGroup):o.isKind(r.DiagramViewSchemas)?Xm(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(L.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!j(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of tp(o))if(e instanceof U){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof B&&c.push(...tp(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(L.DiagramViewSchema,L.DiagramViewTableGroup,L.DiagramViewTable,L.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(Mg).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(Gm.getFieldDuplicateError(n,e.kind,i)),s.push(Gm.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!j(a,r.DiagramView))return n.create(e);let o=new Vm(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 Up?r.declaration instanceof B?new Hm(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function qm(e){let t=e.parentOfKind(U);if(!t)return;let n=t.parentNode;if(!(n instanceof W))return;let i=n.parentNode;if(!(i instanceof B)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof W))return;let o=a.parentNode;if(!(!(o instanceof B)||!o.isKind(r.DiagramView)))return i}function Jm(e,r,i){let a=sp(i);if(a===void 0)return n.create(void 0);if(A(i.parentNode)){let t=Bm(e,i);if(t){if(t.isKind(L.Schema)){let r=Xf(i),o=e.lookupMembers(t,r?L.Table:L.Schema,a);return o?n.create(o):new n(void 0,[new E(T.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,L.Schema,a);return o?n.create(o):new n(void 0,[new E(T.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(L.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,L.Table,a);return s?n.create(s):new n(void 0,[new E(T.BINDING_ERROR,`Could not find table '${a}'`,i)])}function Ym(e,t,r,i){let a=sp(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 E(T.BINDING_ERROR,`Could not find ${i===L.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function Xm(e,t,r){let i=sp(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,L.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var Zm=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof W?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof U)return[];let t=e.body.filter(e=>e instanceof B);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Qm=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=I(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=I(t),n.name=F(t.callee);let r=D(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Tp(P(r.value)),token:I(r)},this.enum.values.push(n),[]})}},$m={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new E(T.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},eh={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return j(a,r.Enum)?new n(i.symbolFactory.create(Pp,{declaration:a,name:o},a.filepath)):M(a,r.Enum)?new n(i.symbolFactory.create(Fp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(L.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof B))return new n([]);let o=tp(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(L.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push($m.getFieldDuplicateError(t,r)),c.push($m.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!j(a,r.Enum))return n.create(e);let o=new Zm(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 Pp?new Qm(t,r,i).interpret():n.create(e)}},th=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof B)||!this.declarationNode.parent.isKind(r.Table)&&!this.declarationNode.parent.isKind(r.TablePartial)||!(this.declarationNode.body instanceof W)?[]:this.bindBody(this.declarationNode.body)}get ownerContainerKind(){return this.declarationNode.parent.isKind(r.TablePartial)?`TablePartial`:`Table`}bindBody(e){if(!e)return[];if(e instanceof U)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof U);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=N(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(zm).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=sp(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new E(T.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},nh=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof W?new n(e.body.flatMap(e=>{if(!(e instanceof U)||!e.callee)return[];let n=[],r=I(e),a=[e.callee,...e.args],o,s,c,l,u;_(a)instanceof G&&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=P(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=P(e.value);t!==void 0&&(l={value:t,token:I(e)})}u=F(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof dm))return e;let t=[],n=e;for(;n instanceof dm&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=ip(e);if(t){for(let e of t.functional)n.push({value:e.value?.value??``,type:`expression`,token:I(e)});for(let e of t.nonFunctional)n.push({value:sp(e)??``,type:`column`,token:I(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}},rh={nodeMetadata(t,i){if(!j(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!j(a,r.Table)&&!j(a,r.TablePartial)?n.create(e):n.create(new wm(i))},nodeReferee(i,a){if(!k(a)||Wf(a))return n.create(e);let o=a;for(;o&&!j(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!j(s,r.Table)&&!j(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=k(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,L.Column,l);if(u)return n.create(u);let d=j(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new E(T.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return j(i,r.Indexes)?n.create(void 0,new th(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===ym.Indexes?r.declaration instanceof B?new nh(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function ih(e,n){let r=np(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof cm){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 cm)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function ah(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 E(T.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new E(T.CIRCULAR_REF,`References with same endpoints exist`,n),new E(T.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var oh=class{constructor(e,t){this.compiler=t,this.ast=e}resolve(){let e=[],i=this.compiler.reachableFiles(this.ast.filepath);for(let n of i){let{ast:i}=this.compiler.parseFile(n).getFiltered(t)||{ast:void 0};if(!i)continue;let a=i.body.filter(e=>e instanceof B&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new E(T.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof B&&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(...sh(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 B)||!t.type)continue;let i=t;j(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),j(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),j(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of tp(e)){if(!(r instanceof U)||!r.callee||!Kf(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=ih(this.compiler,i.leftExpression),o=ih(this.compiler,i.rightExpression);!a||!o||n.push(...ah(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of tp(e)){if(!(a instanceof U)||!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 H)||!i.op||!kf(i.op.value)||!i.expression)continue;let a=ih(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...ah(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of tp(e)){if(!(r instanceof U)||!r.callee)continue;let e=F(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 H&&(!r.op||!kf(r.op.value)||r.expression&&k(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new E(T.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 B)||!i.type)continue;let a=i;if(!j(a,r.TableGroup))continue;let o=a.name?N(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=tp(a);for(let r of c){if(!(r instanceof U)||!r.callee)continue;let i=np(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=N(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new E(T.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 sh(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 Np&&a.push(...sh(e,t,r));return a}function ch(e,t,n){t.isKind(L.Table)?e.externals.tables.push(n):t.isKind(L.Enum)?e.externals.enums.push(n):t.isKind(L.TableGroup)?e.externals.tableGroups.push(n):t.isKind(L.TablePartial)?e.externals.tablePartials.push(n):t.isKind(L.StickyNote)&&e.externals.notes.push(n)}function lh(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function uh(e,t){return e?`${e}.${t}`:`${b}.${t}`}function dh(e,t,n){return n.map(n=>{let r=t[n.name??``]?.value;if(r==null){let t=n.default(e);if(t)return JSON.stringify(t.value)}return JSON.stringify(r)}).join(`|`)}function fh(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function ph(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function mh(e,t,n){return n.length===1?ph(e,t,n[0]):`(${n.map(n=>ph(e,t,n)).join(`, `)})`}function hh(e,t,n){let r=n.map(n=>{let r=n.name??``,i=t[r]===void 0?n.default(e)?.value:t[r].value;return JSON.stringify(i)}).join(`, `);return n.length===1?r:`(${r})`}function gh(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function _h(e,t,n){let{token:r}=t,i=e.nodeAtPosition(r.filepath,r.start.offset)??e.parse.ast(r.filepath);return new vf(T.INVALID_RECORDS_FIELD,n,i)}var vh=e=>e>1?`Composite PK`:`PK`;function yh(e,t,n,r){return Da(r.values)?[]:ba(wh(t,e),i=>bh(e,t,n,i,r))}function bh(e,t,n,r,i){let a=lh(i),o=Ch(e,t,n,r,i);if(!Da(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=v(a,t=>fh(e,t,s)),u=xh(e,t,s.map(e=>e.name??``),c),d=r.some(t=>t.increment(e))?[]:Sh(e,t,r,l);return[...u,...d]}function xh(e,t,n,r){if(Da(r))return[];let i=t.schema(e),a=t.name??``,o=`NULL in ${vh(n.length)}: ${mh(i,a,n)} cannot be NULL`;return ba(r,t=>gh(t,n).map(t=>_h(e,t,o)))}function Sh(e,t,n,r){let i=n.map(e=>e.name??``),a=t.schema(e),o=t.name??``;return ba(pa(Ca(r,t=>dh(e,t,n)),e=>e.length>1),t=>{let r=vh(i.length),s=mh(a,o,i);return ba(t,t=>{let a=`Duplicate ${r}: ${s} = ${hh(e,t,n)}`;return gh(t,i).map(t=>_h(e,t,a))})})}function Ch(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=t.schema(e),c=t.name??``,l=ua(a,Array.from(o));if(Da(l))return[];let u=new Set(l),d=r.filter(e=>u.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e)).map(e=>e.name??``);if(Da(d))return[];let f=`${vh(d.length)}: Column ${mh(s,c,d)} is missing from record and has no default value`;return i.values.map(()=>new vf(T.INVALID_RECORDS_FIELD,f,n))}function wh(e,t){let n=e.mergedColumns(t),r=Oa(n,e=>e.name??``);return[...n.filter(e=>e.pk(t)).map(e=>[e]),...e.mergedIndexes(t).flatMap(e=>{let n=t.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.pk).map(e=>Zr(e.columns.map(e=>r[e.value]))):[]})]}function Th(e,t,n){if(Da(n.values))return[];let r=lh(n);return ba(Eh(e,t),n=>Dh(e,t,n,r))}function Eh(e,t){let n=t.mergedColumns(e),r=Oa(n,e=>e.name??``);return[...n.filter(t=>t.isUniqueSet(e)).map(e=>[e]),...t.mergedIndexes(e).flatMap(t=>{let n=e.interpretMetadata(t,t.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.unique).map(e=>Zr(e.columns.map(e=>r[e.value]))):[]})]}function Dh(e,t,n,r){let i=n.map(e=>e.name??``);return ba(pa(Ca(r.filter(t=>!fh(e,t,n)),t=>dh(e,t,n)),e=>e.length>1),r=>{let a=n.length>1?`Composite UNIQUE`:`UNIQUE`,o=mh(t.schema(e),t.name??``,i);return ba(r,t=>{let r=`Duplicate ${a}: ${o} = ${hh(e,t,n)}`;return gh(t,i).map(t=>_h(e,t,r))})})}function Oh(e,t,n){let r=new Map;for(let i of e.values()){let{name:e,schema:a}=i.tableSymbol.interpretedName(t,n);r.set(uh(a,e),i)}return r}function kh(e,t,n,r){let i=Oh(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!Da(t.record.values)&&a.add(e);return ba(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(uh(e.schemaName,e.tableName))):!1),t=>Ah(e,t,i,r))}function Ah(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(uh(i.schemaName,i.tableName)),s=n.get(uh(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=Zr(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=Zr(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=ef(i.relation),{min:m,max:h}=ef(a.relation),ee=p===1&&m===0||p!==`*`&&h!==`*`,te=h===1&&f===0;return[...ee?[]:jh(e,o,u,s,d,a.relation,r),...te?[]:jh(e,s,d,o,u,i.relation,r)]}function jh(e,t,n,r,i,a,o){if(!t.record||Da(t.record.values))return[];let{min:s}=ef(a),c=Zr(n.map(e=>e.name)),l=Zr(i.map(e=>e.name)),u=s===0,d=lh(t.record),f=r.record?lh(r.record):[],p=new Set(f.map(t=>dh(e,t,i))),m=t.tableSymbol.interpretedName(e,o),h=r.tableSymbol.interpretedName(e,o);return ba(d,t=>{if(fh(e,t,n)){if(u)return[];let r=`FK violation: ${mh(m.schema,m.name,c)} = ${hh(e,t,n)} must not be null`;return gh(t,c).map(t=>_h(e,t,r))}let r=dh(e,t,n);if(p.has(r))return[];let i=mh(m.schema,m.name,c),a=mh(h.schema,h.name,l),o=`FK violation: ${i} = ${hh(e,t,n)} does not exist in ${a}`;return gh(t,c).map(t=>_h(e,t,o))})}function Mh(e,t){if(e instanceof U){let n=e.args.find(e=>e instanceof G);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}}if(e instanceof B){let n=e.attributeList;if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}}return{start:e.end,end:e.end,newText:` [${t}]`}}function Nh(e,t,n){let r=Ph(n,e,t);if(!r)return;let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function Ph(e,t,n){if(!(t instanceof U)&&!(t instanceof B))return;let r=t instanceof U?t.args.find(e=>e instanceof G):t.attributeList;if(!r)return;let i=r.elementList??[],a=i.findIndex(t=>t instanceof V?(t.name?e.substring(t.name.start,t.name.end).trim():e.substring(t.start,t.end).trim())===n:!1);if(a!==-1)return{settingsList:r,settingNode:i[a],settingIndex:a}}function Fh(e,t,n,r){let{allowOtherColFix:i=!0,allowOwnColFix:a=!0}=r??{},o=t.op(e),s=t.opToken(),c=t.cardinalities(e);if(!o||!s||!c)return[];let l=n===`left`?c[0]:c[1],u=ef(l),d=n===`left`?c[1]:c[0],f=ef(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),h=n===`left`?t.leftToken():t.rightToken(),ee=n===`left`?t.rightToken():t.leftToken(),te=[];function ne(e,t,n,r){te.push(new yf(T.INVALID_REF_RELATIONSHIP,n,e,{quickFixes:r}));for(let e of t)e.declaration&&te.push(new yf(T.INVALID_REF_RELATIONSHIP,n,e.declaration,{quickFixes:r}))}let re=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&re&&m.length>0&&m.every(t=>t.nullable(e))){let t=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `);ne(ee,m,m.length===1?`Column '${t}' is nullable but operator '${o}' requires it to be NOT NULL`:`Columns (${t}) are all nullable but operator '${o}' requires at least one to be NOT NULL`,[s&&Lh(s,hf(l),d,n,`Make '${t}' optional in the ref`),...i?m.map(t=>Rh(t,e)).filter(e=>!!e):[]].filter(e=>!!e))}if(u.min===0&&re&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let t=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `);ne(ee,m,m.length===1?`Column '${t}' is NOT NULL but operator '${o}' allows it to be optional`:`Columns (${t}) are NOT NULL but operator '${o}' allows them to be optional`,[s&&Lh(s,gf(l),d,n,`Make '${t}' required in the ref`),...i?m.map(t=>zh(t,e)).filter(e=>!!e):[]].filter(e=>!!e))}if(u.max===`*`&&Bh(e,p)){let t=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `);ne(h,p,p.length===1?`Column '${t}' is unique but operator '${o}' allows many`:`Columns (${t}) have a unique index but operator '${o}' allows many`,[s&&Lh(s,`1`,d,n,`Make '${t}' one in the ref`)].filter(e=>!!e))}if(u.max===1&&!Bh(e,p)){let t=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `);ne(h,p,p.length===1?`Column '${t}' should be unique or primary key for operator '${o}'`:`Columns (${t}) should have a composite unique index for operator '${o}'`,[s&&Lh(s,_f(l),d,n,`Make '${t}' many in the ref`),a&&p.length===1&&Vh(p[0],e)].filter(e=>!!e))}return te}function Ih(e,t){return[...Fh(e,t,`right`,{allowOtherColFix:!1}),...Fh(e,t,`left`,{allowOwnColFix:!1})]}function Lh(e,t,n,r,i){let a=mf(r===`left`?t:n,r===`right`?t:n);return{title:`${i} (change operator to '${a}')`,filepath:e.filepath,edits:[{start:e.start,end:e.end,newText:a}]}}function Rh(e,t){if(!e.declaration||e.pk(t)||e.increment(t)||e.isNotNullSet(t))return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=e.qualifiedName(t).join(`.`),i=Nh(e.declaration,`null`,n);if(i)return{title:`Mark '${r}' as NOT NULL`,filepath:e.declaration.filepath,edits:[i]};let a=Mh(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,filepath:e.declaration.filepath,edits:[a]}}function zh(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=Nh(e.declaration,`not null`,n);if(r)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as NULL`,filepath:e.declaration.filepath,edits:[r]}}function Bh(e,n){if(n.length===0)return!1;if(n.length===1&&n[0].unique(e))return!0;let r=n[0],i=(r instanceof Qp?r.injectionDeclaration:r.declaration)?.parentOfKind(B);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof Ip))return!1;let o=a.mergedIndexes(e),s=new Set(n.map(e=>e.name));for(let t of o){let r=e.interpretMetadata(t,n[0].filepath).getValue();if(!(!r||!Array.isArray(r))){for(let e of r)if(!(!e.unique&&!e.pk)&&e.columns.length===s.size&&e.columns.every(e=>s.has(e.value)))return!0}}return!1}function Vh(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=Mh(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,filepath:e.declaration.filepath,edits:[n]}}var Hh=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:I(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.warnings.push(...this.validateRecords()),new n(this.db,this.errors,this.warnings,this.infos)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof Zp)continue;let r=this.compiler.interpretSymbol(n,this.filepath);if(r.hasValue(t))continue;this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let i=r.getValue();i&&this.pushElement(n,i)}let e=new Set,n=(this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[]).filter(e=>e instanceof Np);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Np){n.push(t);continue}if(!(t instanceof Zp))continue;let r=t.originalSymbol.intern();e.has(r)||(e.add(r),this.interpretUseSymbol(t))}}}interpretUseSymbol(e){let n=e.originalSymbol,r=this.compiler.interpretSymbol(n,this.filepath);if(!r.hasValue(t)){this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let t=r.getValue();t&&this.pushElement(e,t)}let i=n instanceof Ip?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Ip?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}]};ch(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 Tm))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()),this.infos.push(...e.getInfos());let a=e.getValue();if(a!==void 0)switch(i.kind){case ym.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 E(T.SAME_ENDPOINT,`Ref with same endpoints already exists`,i.declaration));break}n.add(e)}this.db.refs.push(e);break}case ym.Records:if(i instanceof Tm){let e=i.table(this.compiler)?.originalSymbol.intern()??``,t=e?r.get(e):void 0;if(t&&t.count>1){this.errors.push(new E(T.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 ym.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 Xp)||!t.isKind(L.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:Wm.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 Np))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(L.Table))continue;let t=e.originalSymbol;if(!(t instanceof Ip))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 Tm))continue;let i=r.table(this.compiler);if(!(i instanceof Ip))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...yh(this.compiler,i,r.declaration,o)),e.push(...Th(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(...kh(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Sm);for(let t of e)this.infos.push(...Ih(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Sm),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 Qp&&t.declaration===e.declaration)))continue;let l=cf(s);if(!l)continue;let u=a instanceof Vp&&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:I(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:I(i.rightToken())};n.push({token:I(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case L.Table:this.db.tables.push(t);break;case L.Enum:this.db.enums.push(t);break;case L.TableGroup:this.db.tableGroups.push(t);break;case L.TablePartial:this.db.tablePartials.push(t);break;case L.StickyNote:this.db.notes.push(t);break;case L.DiagramView:this.db.diagramViews.push(t);break;default:break}}},Uh={nodeSymbol(t,r){return Vf(r)?n.create(t.symbolFactory.create(Yp,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(L.Program))return n.create(e);if(!(i.declaration instanceof z))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(L.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Vf(r)?new oh(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof Yp))return n.create(e);if(!(r.declaration instanceof z))return n.create(void 0);if(!Rm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new Hh(t,r,i).interpret()}},Wh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof W?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof U)return[];let t=e.body.filter(e=>e instanceof B);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Gh=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=I(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}=Ep(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 W?t.body.body[0]?.callee:t.body?.callee,n=e?P(e):void 0;return n&&(this.project.note={value:Tp(n),token:I(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()]=P(t.body.callee),[]}})}},Kh={nodeMetadata(t,i){return j(i,r.Project)?n.create(new Em(i)):n.create(e)},bindNode(t,i){return j(i,r.Project)?n.create(void 0,new Wh(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Em)||!(r.declaration instanceof B)?n.create(e):new Gh(t,r.declaration,i).interpret()}},qh=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 W&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof z?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=op(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=$f(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=sp(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new E(T.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new E(T.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new E(T.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 B)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Pf(e))return[];let i=$f(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=sp(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new E(T.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n));continue}}return a}bindBody(e){if(!e)return[];if(e instanceof U)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof U),n=e.body.filter(e=>e instanceof B);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof lm?e.callee.elementList:[e.callee]).flatMap(zm).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();return!t||!n?[]:[...e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors()),...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}):[]}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Jh=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Yh(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=Xh(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=I(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 Yh(e,n,i){let a=e.name,o=e.parent;if(o instanceof B&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Ip))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===F(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=op(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,L.Schema,u);e&&(p=n.lookupMembers(e,L.Table,l))}if(p||=n.lookupMembers(f,L.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Ip))return;let h=m.mergedColumns(n),ee=s.args.map(e=>h.find(t=>t.name===F(e))).filter(Boolean),te=m.interpretedName(n,i);return{schemaName:te.schema,tableName:te.name,columns:ee}}function Xh(e,t,r){let i=[],a=[],o={},s=e.callee instanceof lm?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new E(T.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=Qh(n,l,r);i.push(...u.getErrors()),a.push(...u.getWarnings());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:I(n)})}return new n({row:c,columnNodes:o},i,a)}function Zh(e){return e instanceof sm&&e.value?.value||``}function Qh(e,t,r){let i=I(e),a=t.type(r),o=(a?.name??``).split(`(`)[0],s=!!a?.enumSymbol,c=t.increment(r),l=t.isNotNullSet(r)===!0,u=t.default(r),d=t.name??``,f=Vo(o,s),p=vp(e),m=p===null?Zh(e):p,h=p===null?`expression`:f;if(e instanceof sm)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(cp(e)||lp(e)&&!Lo(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Bo(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[new vf(T.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(L.EnumField)).map(e=>e.name).filter(Boolean):[],s=P(e);return s===void 0&&(s=k(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 vf(T.INVALID_RECORDS_FIELD,`Invalid enum value for column '${d}'`,e)])}if(No(o)||Po(o)||Bo(o)){let t=dp(e);if(t===null)return new n({value:m,type:h,token:i},[],[new vf(T.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${d}'`,e)]);if(No(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[new vf(T.INVALID_RECORDS_FIELD,`Invalid integer value ${t} for column '${d}': expected integer, got decimal`,e)]);let r=Po(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Po(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 vf(T.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 vf(T.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(Io(o)){let t=gp(e);return t===null?new n({value:m,type:h,token:i},[],[new vf(T.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${d}'`,e)]):new n({value:t,type:f,token:i},[],[])}if(zo(o)){let t=Sp(e);return t===null?new n({value:m,type:h,token:i},[],[new vf(T.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(Lo(o)){let t=vp(e);if(t===null)return new n({value:m,type:h,token:i},[],[new vf(T.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 vf(T.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},[],[])}var $h={nodeMetadata(t,i){if(!j(i,r.Records))return n.create(e);let a=i.parent;if(a&&j(a,r.Table))return n.create(new Tm(i));let o=i.name;return o instanceof dm&&o.callee?n.create(new Tm(i)):n.create(e)},nodeReferee(i,a){if(!k(a))return n.create(e);let o=a.parentOfKind(B);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(cm);if(l?.parentNode===o)return eg(i,o,a);let u=a.parentOfKind(dm);return u?.parentNode===o&&l?.parentNode===u?tg(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?ng(i,c,a):ig(i,c,a)},bindNode(t,i){return j(i,r.Records)?n.create(void 0,new qh(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Tm?r.declaration instanceof B?new Jh(t,r,i).interpret():n.create(void 0):n.create(e)}};function eg(e,i,a){let o=i.parent;if(o instanceof B&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return rg(e,n,a)}return new n(void 0)}function tg(e,r,i){if(r.callee){let n;if(k(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=np(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return rg(e,n,i)}return new n(void 0)}function ng(e,t,r){if(!k(r))return new n(void 0);let i=sp(r)??``;if(!A(r.parentNode)){let a=e.lookupMembers(t,[L.Table,L.Schema],i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Bm(e,r);if(!a){let a=e.lookupMembers(t,[L.Table,L.Schema],i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(L.Schema)){let t=e.lookupMembers(a,[L.Table,L.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function rg(e,t,r){if(!k(r))return new n(void 0);let i=sp(r)??``,a=e.lookupMembers(t,L.Column,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function ig(e,t,r){if(!k(r))return new n(void 0);let i=sp(r)??``;if(!A(r.parentNode))return new n(void 0);let a=Bm(e,r);if(a){if(a.isKind(L.Schema)){let t=e.lookupMembers(a,[L.Enum,L.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(L.Enum)){let t=e.lookupMembers(a,L.EnumField,i);return t?n.create(t):new n(void 0,[new E(T.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(A(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,L.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,L.Enum,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var ag=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof z)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof U)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof U);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(zm).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();return!t||!n?[]:(Array.isArray(t)||(t=[t]),[...e.variables,n,...t].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},og=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=I(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()],{infos:t}=this.validateRefConstraints();return n.create(this.ref,e,void 0,t)}interpretName(){if(!(this.declarationNode instanceof B))return[];let e=[],t=N(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new E(T.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(Ia(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new E(T.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=cf(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=I(this.metadata.leftToken()),l=I(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof B?[{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 B))return[];let u=tp(this.declarationNode)[0];if(u.args[0]){let e=D(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof im?Qf(t):F(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof im?Qf(n):F(n),this.ref.color=e.color?.length?Dp(e.color?.at(0)?.value):void 0,this.ref.inactive=e.inactive?.length?!0:void 0}return[]}validateRefConstraints(){return this.metadata.cardinalities(this.compiler)?{infos:[...Fh(this.compiler,this.metadata,`right`),...Fh(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function sg(e){let t=e.parent;for(;t;){if(t instanceof B&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var cg={nodeReferee(r,i){if(!k(i)&&!A(i)||!sg(i)||i.parentOfKind(V))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):ug(r,o,i)},nodeMetadata(t,a){if(j(a,r.Ref)){let t=tp(a)[0];if(!(t instanceof U)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof am)||!r.op?n.create(e):n.create(new xm(a))}if(a instanceof V){if(!(a.name instanceof im)||Qf(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof B&&t.isKind(r.TablePartial)?n.create(new Sm(a)):n.create(new xm(a))}return n.create(e)},bindNode(t,i){return j(i,r.Ref)?n.create(void 0,new ag(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof xm?new og(t,r,i).interpret():n.create(e)}};function lg(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Np&&e.isPublicSchema())}function ug(e,r,i){if(!k(i))return new n(void 0);let a=sp(i)??``;if(!A(i.parentNode)){let r=i.parentNode;if(r&&A(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=A(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(L.Table)){let r=e.lookupMembers(c,L.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 E(T.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Bm(e,i);if(o){if(o.isKind(L.Schema)){let t=e.lookupMembers(o,[L.Table,L.Schema],a);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(L.Table)){let r=e.lookupMembers(o,L.Column,a);return r?n.create(r):new n(void 0,[new E(T.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(A(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,L.Schema,a);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=lg(e,r);if(t){let r=e.lookupMembers(t,L.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,L.Table,a);return o?n.create(o):new n(void 0,[new E(T.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var dg={visibleName(e,n){let r=n instanceof R?n:n.useSpecifierDeclaration instanceof nm?n.useSpecifierDeclaration:n.declaration;if(r instanceof nm&&n instanceof Mp&&r.getSymbolKind()!==n.kind&&(r=n.declaration),!r)return;let i=e.nodeAlias(r).getFiltered(t);return i===void 0?e.nodeFullname(r).getFiltered(t):[i]}},fg={nodeSymbol(r,i){if(!Bf(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===L.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(Zp,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:dg.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new E(T.BINDING_ERROR,`Failed to resolve the import of ${a} '${(N(i.name)||[]).map(Mg).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof Zp))return n.create(e);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!k(i)&&!Rf(i))return n.create(e);let a=i.parentOfKind(nm);if(!a)return n.create(e);let o=a.name===i||A(a.name)&&a.name.rightExpression===i?a.getSymbolKind():L.Schema;if(o===void 0)return n.create(void 0);let s=N(i.parentOfKind(am)),c=F(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(tm);if(l?.importPath?.value===void 0)return n.create(void 0);let u=yo(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new E(T.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new E(T.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toString()}. Does the file exist?`,i)]);let d=i.parentOfKind(am)?.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 E(T.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=pg(r,u,c,o);return f?n.create(f):n.create(void 0,[new E(T.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toString()}`,i)])},bindNode(t,r){if(zf(r)){let e=[];if(r.importPath?.value){let n=yo(r.filepath,r.importPath.value);n?t.layout.exists(n)||e.push(new E(T.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath)):e.push(new E(T.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 rm?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):Bf(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 Zp))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 pg(e,n,r,i,a=new Set){if(!n||a.has(n.intern()))return;a.add(n.intern());let o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.nonSchemaMembers.find(e=>e.name===r&&e.isKind(i));if(s)return s;let c=o.schemaMembers.find(e=>e.name===r);if(c?.isKind(L.Schema))return c;for(let t of o.reuses.selective)if(N(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(tm);if(o?.importPath?.value){let s=pg(e,yo(n,o.importPath.value),N(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=pg(e,t,r,i,a);if(n)return n}}function mg(e){if(e instanceof vo){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=gg(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof Yp?_g(this,e,i):vg(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 hg(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof nm?dg.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof nm&&r.getSymbolKind()===L.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 gg(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof tm)||!e.specifiers||!e.importPath)continue;let n=yo(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof pm?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof pm?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 _g(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[b,e.symbolFactory.create(Np,{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(Np,{name:i},s))}yg(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of xg(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Np,{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 vg(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof B))continue;let i=hg(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(Xp,{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(Np,{name:i.schemaName,parent:n},n.filepath))}bg(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of Sg(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Np,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function yg(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==L.Schema)continue;let t=dg.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Np,{name:t},r))}}function bg(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==L.Schema)continue;let t=dg.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(Np,{name:o,parent:n},n.filepath))}}function xg(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=gg(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==L.Schema)continue;let n=dg.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function Sg(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=gg(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==L.Schema)continue;let n=dg.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var Cg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof W?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof U)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof U);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 G){let e=D(_(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=>!Of(e.callee)))}tryToBindColumnType(e){let t=rp(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(O(e))return[];if(k(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&bo.includes(t))return[]}let t=rp(e);if(!t){if(A(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return zm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},wg=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??I(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}=Ep(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new E(T.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=sp(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=D(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Dp(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Tp(P(n?.value)),token:I(n)},[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof U);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:Tp(P(e.body instanceof W?e.body.body[0].callee:e.body.callee)),token:I(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:I(e)};i.name=F(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 E(T.UNSUPPORTED,`TablePartial ${i.name} from '${a.filepath}' should be imported. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,o?.useSpecifierDeclaration??e))}return this.table.partials.push(i),r}interpretFields(e){let n=this.symbol??this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),r=(n?this.compiler.symbolMembers(n).getFiltered(t)??[]:[]).filter(e=>e.isKind(L.Column)).length?[]:[new E(T.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Of(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=sp(e.callee),r.token=I(e);let o=kp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||!1,r.unique=a?.isUniqueSet(this.compiler)||!1,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{},c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.endpoints?.[0])return[];let s=o.endpoints[0],c=r.op(this.compiler);return c?{schemaName:s.schemaName,tableName:s.tableName,fieldNames:s.fieldNames,relation:c,token:s.token}:[]}),r.checks=(s[i.Check]||[]).map(e=>({token:I(e),expression:e.value.value.value})),this.table.fields.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.indexes.push(...i):i&&this.table.indexes.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.checks.push(...i):i&&this.table.checks.push(i),r.getErrors()}},Tg={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new E(T.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new E(T.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},Eg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return j(a,r.Table)?new n(i.symbolFactory.create(Ip,{declaration:a,name:o},a.filepath)):M(a,r.Table)?Of(a.callee)?new n(i.symbolFactory.create(Hp,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Lp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(L.Table))return n.create(e);let a=i.declaration;if(!(a instanceof B))return new n([]);let o=tp(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(L.Column,L.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof B&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(L.Column)?(c.push(Tg.getColumnDuplicateError(e.name,r)),c.push(Tg.getColumnDuplicateError(e.name,n))):(c.push(Tg.getPartialInjectionDuplicateError(e.name,r)),c.push(Tg.getPartialInjectionDuplicateError(e.name,n))):l.set(t,n)}}let u=[];for(let e=0;e<s.length;e++){let n=s[e];if(!(n.declaration instanceof U)||!Of(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=F(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new E(T.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(Qp,{kind:L.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(L.Column)&&!(e instanceof Qp)).map(e=>e.name));return new n(Na([...s.filter(e=>!(e instanceof Qp&&d.has(e.name)))].reverse(),e=>e.isKind(L.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(!Hf(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):k(o)&&o.parentNode instanceof H&&o.parentNode.op?.value===`~`?Dg(a,c,o):Uf(o,1)?Og(a,c,o):Gf(o,i.Ref)?kg(a,c,o):Uf(o,0)?n.create(e):Ag(a,c,o)},bindNode(i,a){if(!j(a,r.Table))return n.create(e);let o=new Cg(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 Ip?r.declaration instanceof B?new wg(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function Dg(e,r,i){let a=F(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Np&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,L.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,L.TablePartial,a);return s?n.create(s):new n(void 0,[new E(T.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function Og(e,t,r){if(!k(r))return new n(void 0);let i=sp(r)??``;if(!A(r.parentNode))return n.create(e.lookupMembers(t,L.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(L.Schema)){let t=Xf(r),o=e.lookupMembers(a,t?L.Enum:L.Schema,i);return o?n.create(o):new n(void 0,[new E(T.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,L.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function kg(e,i,a){if(!k(a))return new n(void 0);let o=sp(a)??``;if(!A(a.parentNode)){let s=a.parent,c=s instanceof B&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,L.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,L.Column,o);return l?n.create(l):new n(void 0,[new E(T.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}let s=Bm(e,a);if(s){if(s.isKind(L.Schema)){let t=e.lookupMembers(s,[L.Table,L.Schema],o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(L.Table)){let t=e.lookupMembers(s,L.Column,o);return t?n.create(t):new n(void 0,[new E(T.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(A(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,L.Schema,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,L.Table,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function Ag(e,t,r){if(!k(r))return new n(void 0);let i=sp(r)??``;if(!A(r.parentNode))return bo.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,L.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(L.Schema)){let t=e.lookupMembers(a,[L.Enum,L.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(L.Enum)){let t=e.lookupMembers(a,L.EnumField,i);return t?n.create(t):new n(void 0,[new E(T.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(A(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,L.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,L.Enum,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function jg(e){return e?e.split(``).every(e=>bf(e)||xf(e))&&!xf(e[0]):!1}function Mg(e){return jg(e)?e:`"${Pg(e)}"`}function Ng(e){let t=``,n=0,r={n:`
|
|
5
|
-
`,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function
|
|
6
|
-
`:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function Fg(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`'${Pg(e)}'`;let{value:t,type:n}=e;if(t==null||Io(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(Io(n)){let e=gp(t);return e===null?`\`${t}\``:e?`true`:`false`}if(Fo(n)){let e=fp(t);return e===null?`\`${t}\``:String(e)}if(zo(n)){let e=Sp(t);return e===null?`\`${t}\``:`'${Pg(e)}'`}let r=vp(t);return r===null?`\`${t}\``:`'${Pg(r)}'`}function Ig(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?Ng(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function Lg(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 Rg(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 Np&&n.isKind(L.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 zg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof W?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof U)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof U);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(zm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof Zp?[...r.getErrors(),new E(T.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():[])}},Bg=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=I(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}=Ep(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new E(T.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 U);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:Tp(P(e.body instanceof W?e.body.body[0].callee:e.body.callee)),token:I(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(L.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=N(e.callee);return i.length>2&&n.push(new E(T.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=D(e).getValue();this.tableGroup.color=t.color?.length?Dp(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Tp(P(n?.value)),token:I(n)},[]}},Vg={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new E(T.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Hg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return j(a,r.TableGroup)?new n(i.symbolFactory.create(Rp,{declaration:a,name:s},a.filepath)):M(a,r.TableGroup)?new n(i.symbolFactory.create(zp,{declaration:a,name:o?.map(Mg).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(L.TableGroup)){let e=i.declaration;if(!(e instanceof B))return new n([]);let a=tp(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(L.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof B&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Vg.getFieldDuplicateError(e.name,r)),s.push(Vg.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(L.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!k(a)||!Hf(a,r.TableGroup)||a.parent&&Wf(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):Ug(i,s,a)},bindNode(i,a){if(!j(a,r.TableGroup))return n.create(e);let o=new zg(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!j(o,r.TableGroup)||!(i instanceof Rp)?n.create(e):Rm(t,o)?new Bg(t,i,a).interpret():n.create(void 0)}};function Ug(e,r,i){let a=sp(i)??``;if(!A(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Np&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,L.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,L.Table,a);return s?n.create(s):new n(void 0,[new E(T.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Bm(e,i);if(o){if(o.isKind(L.Schema)){let t=e.lookupMembers(o,[L.Table,L.Schema],a);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,L.Schema,a);return s?n.create(s):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var Wg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof W?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof U)return this.bindFields([e]);let[t,n]=v(e.body,e=>e instanceof U);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 G){let e=D(_(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=rp(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return zm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];if(n){let r=[],i=e.variables;for(let e of i)r.push(...this.compiler.nodeReferee(e).getErrors());let a=this.compiler.nodeReferee(n);return r.push(...a.getErrors()),a.getValue()&&r.push(...this.compiler.nodeReferee(t).getErrors()),r}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Gg=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??I(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}=Ep(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=D(e).getValue(),n=_a(t[i.HeaderColor]);this.tablePartial.headerColor=n?Dp(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Tp(P(r?.value)),token:I(r)},[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof U);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:Tp(P(e.body instanceof W?e.body.body[0].callee:e.body.callee)),token:I(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=sp(e.callee)??``,r.token=I(e);let o=kp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||void 0,r.unique=a?.isUniqueSet(this.compiler)||void 0,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{},c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!(n instanceof Sm))return[];let r=n.owners(this.compiler);if(l&&r.length>0&&!r.some(e=>e===l))return[];let i=n.op(this.compiler);if(!i)return[];let a=n.rightTable(this.compiler),o=n.rightColumns(this.compiler);if(!a||o.length===0)return[];let s=a.interpretedName(this.compiler,this.filepath);return{schemaName:s.schema,tableName:s.name,fieldNames:o.map(e=>e.name??``),relation:i,token:I(n.rightToken())}}),r.checks=(s[i.Check]||[]).map(e=>({token:I(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()}},Kg={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},qg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return j(a,r.TablePartial)?new n(i.symbolFactory.create(Vp,{declaration:a,name:o},a.filepath)):M(a,r.TablePartial)?new n(i.symbolFactory.create(Lp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(L.TablePartial)){let e=a.declaration;if(!(e instanceof B))return new n([]);let r=tp(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(L.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof B&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Tg.getColumnDuplicateError(t,r)),s.push(Tg.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(L.Column)&&j(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!k(o)&&!A(o)||!Hf(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):Uf(o,1)?Jg(a,c,o):Gf(o,i.Ref)?Yg(a,c,o):Xg(a,c,o)},bindNode(i,a){if(!j(a,r.TablePartial))return n.create(e);let o=new Wg(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 Vp?r.declaration instanceof B?new Gg(t,r,i).interpret():n.create(void 0):n.create(e)}};function Jg(e,t,r){if(!k(r))return new n(void 0);let i=sp(r)??``;if(!A(r.parentNode))return n.create(e.lookupMembers(t,L.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(L.Schema)){let t=e.lookupMembers(a,[L.Enum,L.Schema],i);return t?n.create(t):new n(void 0,[new E(T.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,L.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Yg(e,i,a){if(!k(a))return new n(void 0);let o=sp(a)??``;if(!A(a.parentNode)){let s=a.parent;if(s instanceof B&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,L.Column,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,L.Column,o);return c?n.create(c):new n(void 0,[new E(T.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Bm(e,a);if(s){if(s.isKind(L.Schema)){let t=e.lookupMembers(s,[L.Table,L.Schema],o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(L.Table)){let t=e.lookupMembers(s,L.Column,o);return t?n.create(t):new n(void 0,[new E(T.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(A(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,L.Schema,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,L.Table,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function Xg(e,t,r){if(!k(r))return new n(void 0);let i=sp(r)??``;if(!A(r.parentNode))return bo.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,L.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(L.Schema)){let t=e.lookupMembers(a,[L.Enum,L.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(L.Enum)){let t=e.lookupMembers(a,L.EnumField,i);return t?n.create(t):new n(void 0,[new E(T.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(A(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,L.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,L.Enum,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var Zg={symbolMembers(r,i){if(!i.isKind(L.Schema)||!(i instanceof Np))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=$g(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...e_(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...n_(r,i,e,t,c));for(let e of o.uses.selective){let n=$g(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...e_(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...n_(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(L.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(L.TableGroup)))}}for(let t of e)u.push(...i_(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof Zp&&e.isKind(L.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(L.Schema))continue;let t=e instanceof Zp?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof B&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(Qg(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function Qg(e,t,n,r){switch(e){case L.Table:return Tg.getDuplicateError(t,n,r);case L.Enum:return $m.getDuplicateError(t,n,r);case L.TablePartial:return Kg.getDuplicateError(t,n,r);case L.TableGroup:return Vg.getDuplicateError(t,n,r);case L.DiagramView:return Gm.getDuplicateError(t,n,r);default:return new E(T.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function $g(e,r,i,a){let o=hg(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(Np,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function e_(e,n,r,i=new Set){if(r.getSymbolKind()!==L.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(L.Schema))return[];let o=dg.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:t_(e,n,r,a,i)}function t_(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(Zp,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(L.TableGroup)&&c.push(...i_(e,n,t));for(let i of s.reuses.selective)if(c.push(...e_(e,n,i,a)),hg(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(Zp,{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=r_(e,t,n.qualifiedName);i&&c.push(...t_(e,n,r,i,a))}return c}function n_(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=r_(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(Zp,{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(Np,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=$g(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...e_(e,n,r))}for(let{importPath:t}of d)l.push(...n_(e,n,t,i,a,o));return l}function r_(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 i_(e,n,r){if(!r.isKind(L.TableGroup)||!(r instanceof Zp))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(L.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=N(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=a_(e,c,i);l&&s.push(e.symbolFactory.create(Zp,{kind:L.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function a_(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(L.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(L.Table)&&e.name===a)}var o_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof U)return[];let t=e.body.filter(e=>e instanceof B);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},s_=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=I(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=D(e).getValue();return t.color?.length&&(this.note.color=Dp(t.color.at(0)?.value)),[]}interpretBody(e){let[t,n]=v(e.body,e=>e instanceof U);return t.length!==1||n.length>0?[new E(T.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=P(e.callee)??``;return this.note.content=Tp(t),[]}},c_=[Eg,eh,$h,rh,jm,cg,Kh,Hg,qg,{nodeSymbol(i,a){return!j(a,r.Note)||!(a.parentNode instanceof z)?n.create(e):new n(i.symbolFactory.create(Bp,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(L.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return j(i,r.Note)?n.create(void 0,new o_(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Bp?r.declaration instanceof B?new s_(t,r,i).interpret():n.create(void 0):n.create(e)}},fg,Zg,Km,Uh];function l_(t,...r){for(let i of c_){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function u_(r){let i=l_(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function d_(r){let i=l_(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function f_(r){let i=l_(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function p_(r){let i=l_(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function m_(r){let i=l_(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function h_(r,i){let a=l_(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function g_(r,i){let a=l_(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var __=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 E(T.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof z?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=v(e.body,e=>e instanceof U);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 G&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof sm))&&t.push(new E(T.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=D(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 E(T.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{O(t.value)||n.push(new E(T.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},v_={validateNode(t,i){if(!j(i,r.Checks))return n.create(e);let a=new __(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return j(i,r.Checks)?i.name?new n(void 0,[new E(T.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return j(i,r.Checks)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return j(i,r.Checks)?i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},y_=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 B&&this.declarationNode.parent.isKind(r.Project)?[]:[new E(T.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof W)return[new E(T.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return O(e.callee)||t.push(new E(T.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 E(T.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function b_(e){return e instanceof B&&!!e.type?.value}var x_={validateNode(t,r){if(!b_(r))return n.create(e);let i=new y_(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return b_(r)?r.name?new n(void 0,[new E(T.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return b_(r)?r.alias?new n(void 0,[new E(T.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return b_(r)?r.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},S_=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 B?[new E(T.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Ef(e)?[]:[new E(T.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new E(T.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=D(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new E(T.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof U)return{errors:[new E(T.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=v(e.body,e=>e instanceof U),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>If(e.callee)?e.args.length>0?e.args.map(e=>new E(T.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new E(T.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 E(T.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(Df(e))return t.push(new E(T.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof W))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof U&&If(e.callee)),a=r.body.some(e=>e instanceof U&&!If(e.callee));return i&&a&&n.push(new vf(T.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 W))return t;let n=e.body.body.filter(e=>e instanceof U);for(let e of n)If(e.callee)||(e.args.length>0||!N(e.callee))&&t.push(...e.args.map(e=>new E(T.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},C_={validateNode(t,i){if(!j(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new S_(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(j(i,r.DiagramView)){if(!i.name)return new n(void 0,[new E(T.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=N(i.name);return e?new n(e):new n(void 0)}else if(M(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=N(i.callee);return e?(e.length===1&&M(i,r.DiagramViewTables)&&e.unshift(b),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return j(i,r.DiagramView)?new n(void 0):n.create(e)}},w_=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 B?[new E(T.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof pm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:wf(e)?[]:[new E(T.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new E(T.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof U);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new E(T.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!k(n.callee)&&t.push(new E(T.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];_(e)instanceof G?(t.push(...this.validateFieldSettings(_(e))),e.pop()):e[0]instanceof G&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new E(T.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=D(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 E(T.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{O(e.value)||n.push(new E(T.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},T_={validateNode(t,i){return j(i,r.Enum)?n.create(void 0,new w_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(j(i,r.Enum)){if(!i.name)return new n(void 0,[new E(T.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!wf(i.name))return new n(void 0,[new E(T.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=N(i.name);return e?.length===1&&e.unshift(b),new n(e)}if(M(i,r.Enum)){let e=F(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return j(i,r.Enum)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):M(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(j(a,r.Enum))return a.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(M(a,r.Enum)){let e=[...a.args],t;if(_(e)instanceof G?t=_(e):e[0]instanceof G&&(t=e[0]),!t)return new n({});let r=D(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 E(T.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{O(e.value)||o.push(new E(T.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new E(T.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},E_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new E(T.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof z?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return[new E(T.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=v(e.body,e=>e instanceof U);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 G&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof dm;)e.argumentList&&ip(e.argumentList)===void 0&&t.push(new E(T.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;ip(e)===void 0&&t.push(new E(T.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=D(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 E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{O(t.value)||n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new E(T.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{k(e.value)||n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},D_={validateNode(t,i){return j(i,r.Indexes)?n.create(void 0,new E_(t,i).validate()):n.create(e)},nodeFullname(t,i){return j(i,r.Indexes)?i.name?new n(void 0,[new E(T.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):M(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return j(i,r.Indexes)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):M(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(j(a,r.Indexes))return a.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(M(a,r.Indexes)){let e=[a.callee,...a.args],t;if(_(e)instanceof G&&(t=_(e)),!t)return new n({});let r=D(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 E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{O(t.value)||o.push(new E(T.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 E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{k(e.value)||o.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new E(T.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},O_=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 z)&&!(e instanceof B&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project))?[new E(T.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 E(T.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof z}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new E(T.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=D(e),n=t.getErrors();return xa(t.getValue(),(e,t)=>{switch(t){case i.Color:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{let t=Lf(e.value)&&e.value.expression.variable.value.toLowerCase()===`none`;!Af(e.value)&&!t&&n.push(new E(T.INVALID_NOTE_SETTING_VALUE,`'color' must be a color literal or 'none'`,e.value||e.name))});break;default:n.push(...e.map(e=>new E(T.UNKNOWN_NOTE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof U)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof U);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new E(T.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new E(T.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),O(e[0].callee)||t.push(new E(T.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 E(T.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():[])}},k_={validateNode(t,i){return j(i,r.Note)?n.create(void 0,new O_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!j(i,r.Note))return n.create(e);if(!(i.parent instanceof z))return i.name?new n(void 0,[new E(T.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new E(T.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof pm)return new n(void 0,[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=N(i.name);return a===void 0?new n(void 0,[new E(T.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return j(i,r.Note)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return j(i,r.Note)?i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},A_=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)}},j_={validateNode(t,r){return Vf(r)?n.create(void 0,new A_(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Vf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Vf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Vf(r)?new n({}):n.create(e)}},M_=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 B?[new E(T.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Ef(e)?new n(N(e)):new n(void 0,[new E(T.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 E(T.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof U)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof U);return[...t.map(e=>new E(T.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():[])}},N_={validateNode(t,i){return j(i,r.Project)?n.create(void 0,new M_(t,i).validate()):n.create(e)},nodeFullname(t,i){return j(i,r.Project)?i.name?Ef(i.name)?new n(N(i.name)):new n(void 0,[new E(T.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):M(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return j(i,r.Project)&&i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):M(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return j(i,r.Project)?i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):M(i,r.Project)?new n({}):n.create(e)}},P_=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 z||e instanceof B&&e.isKind(r.Table)?[]:[new E(T.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof pm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof z?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof dm))return[new E(T.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||!wf(e.callee))&&t.push(new E(T.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Pf(e.argumentList))&&t.push(new E(T.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Pf(e)?[new E(T.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return this.validateDataRow(e);let[t,n]=v(e.body,e=>e instanceof U);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 E(T.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof lm)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new E(T.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 E(T.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 gm||Mf(e)||O(e)||e instanceof sm)return!0;if(k(e)){let t=e.expression.variable.value.toLowerCase();return bo.includes(t)}if(A(e)){let t=N(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},F_={validateNode(t,i){return j(i,r.Records)?n.create(void 0,new P_(t,i).validate()):n.create(e)},nodeFullname(i,a){if(j(a,r.Records)){if(a.name instanceof pm)return new n(void 0,[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof z){if(!(a.name instanceof dm))return new n(void 0,[new E(T.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||!wf(a.name.callee))&&e.push(new E(T.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Pf(a.name.argumentList))&&e.push(new E(T.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=N(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&&!Pf(a.name)?new n(e,[new E(T.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return M(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return j(i,r.Records)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):M(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return j(i,r.Records)?i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,i.attributeList)]):new n({}):M(i,r.Records)?new n({}):n.create(e)}},I_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof z?[]:[new E(T.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof pm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:Ef(e)?[]:[new E(T.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return this.validateFields([e]);let[t,n]=v(e.body,e=>e instanceof U);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new E(T.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 E(T.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Kf(e.callee)&&t.push(new E(T.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Kf(e.callee)){let n=rp(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=rp(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new E(T.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new E(T.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!qf(e.callee)&&t.push(new E(T.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(_(n)instanceof G){let e=this.validateFieldSettings(_(n));t.push(...e),n.pop()}else n[0]instanceof G&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new E(T.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return R_(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function L_(e){if(!(k(e)&&e.expression.variable.kind!==y.QUOTED_STRING)&&!(e instanceof im))return!1;let t;if(t=e instanceof im?Qf(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 R_(e){let t=D(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 E(T.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{L_(t.value)||r.push(new E(T.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 E(T.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Af(e.value)||r.push(new E(T.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),o[e]=t;break;case i.Inactive:t.length>1&&r.push(...t.map(e=>new E(T.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new E(T.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new E(T.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var z_={validateNode(t,i){return j(i,r.Ref)?n.create(void 0,new I_(t,i).validate()):n.create(e)},nodeFullname(t,i){return j(i,r.Ref)?i.name?Ef(i.name)?new n(N(i.name)):new n(void 0,[new E(T.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):M(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return j(i,r.Ref)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):M(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(j(i,r.Ref))return i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(M(i,r.Ref)){let e=[...i.args],t;return _(e)instanceof G?t=_(e):e[0]instanceof G&&(t=e[0]),t?R_(t):new n({})}return n.create(e)}},B_=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof B?[new E(T.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof _m?[new E(T.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof pm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:wf(e)?[]:[new E(T.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new E(T.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Tf(e)?[]:[new E(T.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=D(e),n=t.getErrors();return xa(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Af(e.value)||n.push(new E(T.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 E(T.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{O(e.value)||n.push(new E(T.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new E(T.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof U)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof U);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 E(T.INVALID_COLUMN,`A column must have a type`,e.callee)),k(e.callee)||t.push(new E(T.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Ff(e.args[0])&&t.push(new E(T.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?(Of(e.callee)||t.push(new E(T.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 E(T.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof H&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){if(!e.slice(0,-1).every(Lf)||!e.slice(-1).every(e=>Lf(e)||e instanceof G))return e.map(e=>new E(T.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 G&&(t=e.pop());let n=D(t),r=n.getErrors(),a=n.getValue();e.forEach(e=>{let t=(F(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){r.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),xa(a,(e,t)=>{switch(t){case i.Note:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{O(e.value)||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||r.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&r.push(new E(T.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 E(T.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 E(T.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 E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&r.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&r.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{jf(e.value)||r.push(new E(T.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 sm||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new E(T.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 E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function V_(e){let t=D(e),r=t.getErrors(),a=t.getValue();return xa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Af(e.value)||r.push(new E(T.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 E(T.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{O(e.value)||r.push(new E(T.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new E(T.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function H_(e){if(!e.slice(0,-1).every(Lf)||!e.slice(-1).every(e=>Lf(e)||e instanceof G))return new n({},e.map(e=>new E(T.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 G&&(t=e.pop());let r=D(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(F(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),xa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{O(e.value)||a.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&a.push(new E(T.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 E(T.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 E(T.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 E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{jf(e.value)||a.push(new E(T.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 sm||a.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new E(T.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(o,a)}var U_={validateNode(t,i){return j(i,r.Table)?n.create(void 0,new B_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(j(i,r.Table)){if(!i.name)return new n(void 0,[new E(T.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof _m)return new n(void 0,[new E(T.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=N(i.name);return e?.length===1&&e.unshift(b),new n(e)}if(M(i,r.Table)){if(Of(i.callee)){let e=F(i.callee.expression);return new n(e?[e]:void 0)}let e=F(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return j(i,r.Table)?i.alias?Tf(i.alias)?new n(F(i.alias)):new n(void 0,[new E(T.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):M(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return j(i,r.Table)?i.attributeList?V_(i.attributeList):new n({}):M(i,r.Table)?H_(i.args.slice(1)):n.create(e)}},W_=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 B?[new E(T.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof pm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:Ef(e)?[]:[new E(T.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new E(T.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=D(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 E(T.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Af(e.value)||n.push(new E(T.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 E(T.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!O(e.value)).forEach(e=>{n.push(new E(T.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...t.map(t=>new E(T.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return n}validateBody(e){if(!e)return[];if(e instanceof U)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof U);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&N(e.callee)===void 0&&t.push(new E(T.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 E(T.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 E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function G_(e){let t=D(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 E(T.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Af(e.value)||r.push(new E(T.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 E(T.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!O(e.value)).forEach(e=>{r.push(new E(T.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 E(T.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return new n(a,r)}var K_={validateNode(t,i){return j(i,r.TableGroup)?n.create(void 0,new W_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(j(i,r.TableGroup))return i.name?Ef(i.name)?new n(N(i.name)):new n(void 0,[new E(T.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new E(T.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(M(i,r.TableGroup)){let e=N(i.callee);return e?.length===1&&e.unshift(b),new n(e)}return n.create(e)},nodeAlias(t,i){return j(i,r.TableGroup)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):M(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return j(i,r.TableGroup)?G_(i.attributeList):M(i,r.TableGroup)?new n({}):n.create(e)}},q_=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 B?[new E(T.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof pm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:Ef(e)?[]:[new E(T.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new E(T.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=D(e),n=t.getErrors();return xa(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Af(e.value)||n.push(new E(T.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 E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{O(e.value)||n.push(new E(T.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new E(T.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof U)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=v(e.body,e=>e instanceof U);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 E(T.INVALID_COLUMN,`A column must have a type`,e.callee)),k(e.callee)||t.push(new E(T.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Ff(e.args[0])&&t.push(new E(T.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(Lf)||!(Lf(t)||t instanceof G))return e.map(e=>new E(T.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 G&&(n=e.pop());let r=D(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(F(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),xa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{O(e.value)||a.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&a.push(new E(T.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 E(T.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 E(T.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 E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{jf(e.value)||a.push(new E(T.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 sm||a.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>a.push(new E(T.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 E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function J_(e){let t=D(e),r=t.getErrors(),a=t.getValue();return xa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Af(e.value)||r.push(new E(T.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 E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{O(e.value)||r.push(new E(T.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new E(T.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Y_(e){let t=_(e);if(e.length>0&&(!e.slice(0,-1).every(Lf)||!(Lf(t)||t instanceof G)))return new n({},e.map(e=>new E(T.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 G&&(r=e.pop());let a=D(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(F(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),xa(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{O(e.value)||o.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Nf(e.value)||o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&o.push(new E(T.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 E(T.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 E(T.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 E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof V&&e.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{jf(e.value)||o.push(new E(T.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 sm||o.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>o.push(new E(T.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new n(s,o)}var X_={validateNode(t,i){return j(i,r.TablePartial)?n.create(void 0,new q_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(j(i,r.TablePartial))return i.name?Ef(i.name)?new n(N(i.name)):new n(void 0,[new E(T.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new E(T.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(M(i,r.TablePartial)){let e=F(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return j(i,r.TablePartial)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(F(i.alias)):M(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return j(i,r.TablePartial)?J_(i.attributeList):M(i,r.TablePartial)?Y_(i.args.slice(1)):n.create(e)}},Z_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof z?[]:[new E(T.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.importPath&&!vo.isRelative(this.declarationNode.importPath.value)&&e.push(new E(T.INVALID_USE_SPECIFIER_NAME,`Import path must be a relative path (starting with './' or '../')`,this.declarationNode.importPath)),this.declarationNode.specifiers instanceof pm)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 E(T.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Ap))||t.push(new E(T.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()]}},Q_=[U_,T_,F_,D_,v_,z_,N_,K_,X_,k_,C_,j_,{validateNode(t,r){return r instanceof tm?n.create(void 0,new Z_(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!Bf(r))return n.create(e);let i=N(r.name);return!i||i.length===0?n.create(void 0,[new E(T.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Ap.TableGroup)&&i.length>1?n.create(i,[new E(T.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Ap.TablePartial)&&i.length>1?n.create(i,[new E(T.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Ap.Note)&&i.length>1?n.create(i,[new E(T.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Ap.Schema)&&i.unshift(b),new n(i))},nodeAlias(t,r){return Bf(r)?r.alias?Tf(r.alias)?new n(F(r.alias)):new n(void 0,[new E(T.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 tm?n.create({}):n.create(e)}},x_];function $_(t,...r){for(let n of Q_){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function ev(r){let i=$_(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function tv(r){let i=$_(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function nv(r){let i=$_(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function rv(r){let i=$_(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var iv=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function av(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}),iv&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function ov(e,t,...n){return av(t,n)}var sv=!1,cv=!1,lv=!1,uv=!1,dv=void 0,fv=typeof self==`object`?self:typeof global==`object`?global:{},pv=void 0;fv.vscode!==void 0&&fv.vscode.process!==void 0?pv=fv.vscode.process:typeof process<`u`&&(pv=process);var mv=typeof pv?.versions?.electron==`string`&&pv?.type===`renderer`;if(typeof navigator==`object`&&!mv)dv=navigator.userAgent,sv=dv.indexOf(`Windows`)>=0,cv=dv.indexOf(`Macintosh`)>=0,(dv.indexOf(`Macintosh`)>=0||dv.indexOf(`iPad`)>=0||dv.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,lv=dv.indexOf(`Linux`)>=0,dv?.indexOf(`Mobi`),uv=!0,ov({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof pv==`object`){sv=pv.platform===`win32`,cv=pv.platform===`darwin`,lv=pv.platform===`linux`,lv&&pv.env.SNAP&&pv.env.SNAP_REVISION,pv.env.CI||pv.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=pv.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.availableLanguages[`*`],t.locale,t.osLocale,t._translationsConfigFile}catch{}}else console.error(`Unable to resolve platform.`);var hv=sv,gv=cv;uv&&fv.importScripts;var _v=dv,vv=typeof fv.postMessage==`function`&&!fv.importScripts;(()=>{if(vv){let e=[];fv.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}),fv.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var yv=!!(_v&&_v.indexOf(`Chrome`)>=0);_v&&_v.indexOf(`Firefox`),!yv&&_v&&_v.indexOf(`Safari`),_v&&_v.indexOf(`Edg/`),_v&&_v.indexOf(`Android`);var bv;if(fv.vscode!==void 0&&fv.vscode.process!==void 0){let e=fv.vscode.process;bv={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else bv=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 hv?`win32`:gv?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var xv=bv.cwd,Sv=bv.env,Cv=bv.platform,wv=65,Tv=97,Ev=90,Dv=122,Ov=46,kv=47,Av=92,jv=58,Mv=63,Nv=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 Pv(e,t){if(typeof e!=`object`||!e)throw new Nv(t,`Object`,e)}function Fv(e,t){if(typeof e!=`string`)throw new Nv(t,`string`,e)}var Iv=Cv===`win32`;function q(e){return e===kv||e===Av}function Lv(e){return e===kv}function Rv(e){return e>=wv&&e<=Ev||e>=Tv&&e<=Dv}function zv(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=kv;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==Ov||i.charCodeAt(i.length-2)!==Ov){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===Ov&&s!==-1?++s:s=-1}return i}function Bv(e,t){Pv(t,`pathObject`);let n=t.dir||t.root,r=t.base||`${t.name||``}${t.ext||``}`;return n?n===t.root?`${n}${r}`:`${n}${e}${r}`:r}var Vv={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],Fv(a,`path`),a.length===0)continue}else t.length===0?a=xv():(a=Sv[`=${t}`]||xv(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Av)&&(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 Rv(u)&&a.charCodeAt(1)===jv&&(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=zv(n,!r,`\\`,q),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){Fv(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return Lv(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 Rv(a)&&e.charCodeAt(1)===jv&&(r=e.slice(0,2),n=2,t>2&&q(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?zv(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){Fv(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return q(n)||t>2&&Rv(n)&&e.charCodeAt(1)===jv&&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];Fv(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 Vv.normalize(t)},relative(e,t){if(Fv(e,`from`),Fv(t,`to`),e===t)return``;let n=Vv.resolve(e),r=Vv.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Av;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Av;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Av;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Av;)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===Av&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Av)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Av?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)===Av)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Av&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=Vv.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Av){if(t.charCodeAt(1)===Av){let e=t.charCodeAt(2);if(e!==Mv&&e!==Ov)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(Rv(t.charCodeAt(0))&&t.charCodeAt(1)===jv&&t.charCodeAt(2)===Av)return`\\\\?\\${t}`;return e},dirname(e){Fv(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 Rv(i)&&e.charCodeAt(1)===jv&&(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&&Fv(t,`ext`),Fv(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&Rv(e.charCodeAt(0))&&e.charCodeAt(1)===jv&&(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){Fv(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===jv&&Rv(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===Ov?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:Bv.bind(null,`\\`),parse(e){Fv(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(Rv(i)&&e.charCodeAt(1)===jv){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===Ov?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},Hv=(()=>{if(Iv){let e=/\\/g;return()=>{let t=xv().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>xv()})(),Uv={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:Hv();Fv(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===kv)}return t=zv(t,!n,`/`,Lv),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(Fv(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===kv,n=e.charCodeAt(e.length-1)===kv;return e=zv(e,!t,`/`,Lv),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return Fv(e,`path`),e.length>0&&e.charCodeAt(0)===kv},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];Fv(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:Uv.normalize(t)},relative(e,t){if(Fv(e,`from`),Fv(t,`to`),e===t||(e=Uv.resolve(e),t=Uv.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===kv&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===kv)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===kv?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===kv)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(Fv(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===kv,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===kv){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&&Fv(t,`ext`),Fv(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===kv){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)===kv){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Fv(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===kv){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===Ov?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:Bv.bind(null,`/`),parse(e){Fv(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===kv,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===kv){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===Ov?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};Uv.win32=Vv.win32=Vv,Uv.posix=Vv.posix=Uv,Iv?Vv.normalize:Uv.normalize,Iv?Vv.resolve:Uv.resolve,Iv?Vv.relative:Uv.relative,Iv?Vv.dirname:Uv.dirname,Iv?Vv.basename:Uv.basename,Iv?Vv.extname:Uv.extname,Iv?Vv.sep:Uv.sep;var Wv=/^\w[\w\d+.-]*$/,Gv=/^\//,Kv=/^\/\//;function qv(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&&!Wv.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!Gv.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(Kv.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 Jv(e,t){return!e&&!t?`file`:e}function Yv(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==Xv&&(t=Xv+t):t=Xv;break}return t}var J=``,Xv=`/`,Zv=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,Qv=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=Jv(e,a),this.authority=t||J,this.path=Yv(this.scheme,n||J),this.query=r||J,this.fragment=i||J,qv(this,a))}get fsPath(){return iy(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 ey(t,n,r,i,a)}static parse(e,t=!1){let n=Zv.exec(e);return n?new ey(n[2]||J,cy(n[4]||J),cy(n[5]||J),cy(n[7]||J),cy(n[9]||J),t):new ey(J,J,J,J,J)}static file(e){let t=J;if(hv&&(e=e.replace(/\\/g,Xv)),e[0]===Xv&&e[1]===Xv){let n=e.indexOf(Xv,2);n===-1?(t=e.substring(2),e=Xv):(t=e.substring(2,n),e=e.substring(n)||Xv)}return new ey(`file`,t,e,J,J)}static from(e,t){return new ey(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=hv&&t.scheme===`file`?e.file(Vv.join(iy(t,!0),...n)).path:Uv.join(t.path,...n),t.with({path:r})}toString(e=!1){return ay(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new ey(t);return e._formatted=t.external??null,e._fsPath=t._sep===$v?t.fsPath??null:null,e}}},$v=hv?1:void 0,ey=class extends Qv{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=iy(this,!1),this._fsPath}toString(e=!1){return e?ay(this,!0):(this._formatted||=ay(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=$v),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}},ty={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 ny(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=ty[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 ry(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+=ty[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function iy(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,hv&&(n=n.replace(/\//g,`\\`)),n}function ay(e,t){let n=t?ry:ny,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=Xv,r+=Xv),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:ny(c,!1,!1)),r}function oy(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+oy(e.substr(3)):e}}var sy=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function cy(e){return e.match(sy)?e.replace(sy,e=>oy(e)):e}var Y=function(e){return e[e.Function=1]=`Function`,e[e.Constructor=2]=`Constructor`,e[e.Field=3]=`Field`,e[e.Variable=4]=`Variable`,e[e.Class=5]=`Class`,e[e.Struct=6]=`Struct`,e[e.Interface=7]=`Interface`,e[e.Module=8]=`Module`,e[e.Property=9]=`Property`,e[e.Event=10]=`Event`,e[e.Operator=11]=`Operator`,e[e.Unit=12]=`Unit`,e[e.Value=13]=`Value`,e[e.Constant=14]=`Constant`,e[e.Enum=15]=`Enum`,e[e.EnumMember=16]=`EnumMember`,e[e.Keyword=17]=`Keyword`,e[e.Text=18]=`Text`,e[e.Color=19]=`Color`,e[e.File=20]=`File`,e[e.Reference=21]=`Reference`,e[e.Customcolor=22]=`Customcolor`,e[e.Folder=23]=`Folder`,e[e.TypeParameter=24]=`TypeParameter`,e[e.User=25]=`User`,e[e.Issue=26]=`Issue`,e[e.Snippet=27]=`Snippet`,e}({}),X=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),ly=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 uy(e,t){return e.getOffsetAt(t)}function dy(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 fy=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=vo.fromUri(String(e.uri)),a=this.compiler.interpretProject().getInfos().filter(e=>e.quickFixes?.length&&e.filepath.equals(i));if(!a.length)return;let o=[];for(let t of n.markers)for(let n of a){let r=dy(e,n.nodeOrToken);if(!(r.startLineNumber!==t.startLineNumber||r.startColumn!==t.startColumn||r.endLineNumber!==t.endLineNumber||r.endColumn!==t.endColumn))for(let r of n.quickFixes??[]){let n=this.quickFixToCodeAction(r,e,t);n&&o.push(n)}}let s=Na(o,e=>{let t=e.diagnostics?.[0];return`${e.title}@${t?.startLineNumber}:${t?.startColumn}`});if(s.length)return{actions:s,dispose(){}}}quickFixToCodeAction(e,t,n){let r=vo.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=Qv.parse(e.filepath.toUri({protocol:t.uri.scheme})),a={edits:e.edits.map(e=>{let n=t.getPositionAt(e.start),r=t.getPositionAt(e.end);return{resource:i,textEdit:{range:{startLineNumber:n.lineNumber,startColumn:n.column,endLineNumber:r.lineNumber,endColumn:r.column},text:e.newText},versionId:t.getVersionId()}})};return{title:e.title,kind:`quickfix`,edit:a,diagnostics:[n]}}},py=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=vo.fromUri(String(e.uri)),a=uy(e,n),o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(!e)continue;let n=this.compiler.nodeReferee(e).getFiltered(t);if(!n)continue;let i;if(n.declaration&&[em.PRIMARY_EXPRESSION,em.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=Qv.parse(i.filepath.toUri({protocol:r.scheme}))),[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}]}}return[]}},my=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e),...this.provideInfos(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideInfos(e){return e?this.compiler.interpretFile(e).getInfos().map(e=>this.createDiagnostic(e,`info`)):this.compiler.interpretProject().getInfos().map(e=>this.createDiagnostic(e,`info`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos;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`?ly.Error:e===`warning`?ly.Warning:ly.Info}},hy=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=vo.fromUri(String(r)),a=uy(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[em.ELEMENT_DECLARATION,em.FUNCTION_APPLICATION,em.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=Qv.parse(e.filepath.toUri({protocol:r.scheme}))),{range:{startColumn:e.startPos.column+1,startLineNumber:e.startPos.line+1,endColumn:e.endPos.column+1,endLineNumber:e.endPos.line+1},uri:t}})}}return[]}};function gy(e,t){return e>=t.start&&e<t.end}function _y(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 vy(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 rm)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=F(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?F(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof pm&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof pm)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function yy(e,t,n,r,i,a){let o=vy(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:by(Ma([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
|
|
7
|
-
`),removeRange:
|
|
8
|
-
`)}}function
|
|
4
|
+
`)}function jp(e){let t=j(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function Mp(e){if(jf(e))return e.expression.literal.value;if(Hf(e)&&N(e)?.toLowerCase()===`none`)return Co}function Np(e){if(e){if(Bf(e)){let t=M(e);if(t!==void 0)return{value:t,type:`string`}}if(Pf(e))return{type:`number`,value:kp(e)};if(Hf(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof hm&&e.value)return{value:e.value.value,type:`expression`};if(Uf(e)){let t=sp(e)?.at(-1),n=t?N(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function Pp(e,t){let r=``,i=null;if(t instanceof W){if(i=(t.argumentList?.elementList??[]).map(e=>Pf(e)?Op(e):Bf(e)?M(e):N(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof W||t instanceof wm;)if(t instanceof W){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Pf(e)?Op(e):Bf(e)?M(e):N(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof wm){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}=jp(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new E(T.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}function Fp(e,t){let n=new Set(t.map(e=>e.toLowerCase())),r={};for(let[t,i]of Object.entries(e)){if(n.has(t.toLowerCase()))continue;let e=i[0],a=Ip(e.value);a!==void 0&&(r[t]=a)}return r}function Ip(e){if(!e)return;let t=M(e);if(t!==void 0)return t;let n=Mp(e);if(n!==void 0)return n}var F=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.StickyNote=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewTopLevelWildcard=`DiagramView top-level wildcard`,e.DiagramViewTable=`DiagramView table`,e.DiagramViewTableGroup=`DiagramView tablegroup`,e.DiagramViewNote=`DiagramView note`,e.DiagramViewSchema=`DiagramView schema`,e.Metadata=`Metadata`,e.Program=`Program`,e}({}),Lp={Table:`Table`,Enum:`Enum`,TableGroup:`TableGroup`,TablePartial:`TablePartial`,Note:`Note`,Schema:`Schema`},Rp=function(e){return e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.Note=`Note`,e}({}),zp=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Bp=class{constructor({kind:e,declaration:t,name:n},r,i){this.id=r,this.kind=e,this.declaration=t,this.filepath=i,this.name=n}get originalFilepath(){return this.originalSymbol.filepath}intern(){return`symbol@${this.filepath.intern()}:${this.id}`}isKind(...e){return e.includes(this.kind)}canonicalName(e,t){return e.canonicalName(t,this).getValue()}interpretedName(e,t){if(!t)return{schema:null,name:this.name??``};let n=this.canonicalName(e,t);return n?{schema:n.schema===`public`?null:n.schema,name:n.name}:{schema:null,name:this.name??``}}settings(e){if(this.declaration)return e.nodeSettings(this.declaration).getFiltered(t)}get token(){if(this.declaration)return P(this.declaration)}references(e){return e.symbolReferences(this)}metadata(e){return e.symbolMetadata(this)}members(e){let n=e.symbolMembers(this);return n.hasValue(t)?[]:n.getValue()}},Vp=class e extends Bp{constructor({name:e,parent:t},n,r){super({kind:`Schema`},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===y}inNestedSchema(t,n){let r=this.members(t);if(r.some(e=>e.originalSymbol===n.originalSymbol))return!0;for(let i of r)if(i instanceof e&&i.inNestedSchema(t,n))return!0;return!1}},Hp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`Enum`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Up=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`Enum field`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Ap(M(i));if(a)return{value:a,token:P(r)}}},Wp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`Table`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}schema(e){let t=this.canonicalName(e,this.filepath);return t?t.schema===`public`?null:t.schema:null}columns(e){return this.mergedColumns(e).filter(e=>!(e instanceof om))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(`Column`))}partialInjections(e){return this.members(e).filter(e=>e.isKind(`PartialInjection`))}note(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=Ap(M(i));if(a)return{value:a,token:P(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?Mp(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===Lm.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===Lm.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===Lm.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===Lm.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof V)||!kf(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===Lm.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===Lm.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=Mp(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=Ap(M(a));if(o)return{value:o,token:P(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Gp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`Column`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}qualifiedName(e){let n=this.name??``,r=(this instanceof om?this.injectionDeclaration:this.declaration)?.parentOfKind(R);if(!r)return[n];let i=e.nodeSymbol(r).getFiltered(t);if(!i)return[n];let{schema:a,name:o}=i.interpretedName(e,this.filepath);return a?[a,o,n]:[o,n]}pk(e){if(!this.declaration)return!1;let n=e.nodeSettings(this.declaration).getFiltered(t);return!!(n?.[i.PK]?.length||n?.[i.PrimaryKey]?.length)}isUniqueSet(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Unique]?.length:!1}unique(e){return this.isUniqueSet(e)||this.pk(e)||this.increment(e)}nullable(e){return this.declaration?!(this.pk(e)||this.increment(e)||this.isInPkIndex(e)||e.nodeSettings(this.declaration).getFiltered(t)?.[i.NotNull]?.length):!0}isInPkIndex(e){if(!this.declaration||!this.name)return!1;let n=(this instanceof om?this.injectionDeclaration:this.declaration).parentOfKind(R);if(!n)return!1;let r=e.nodeSymbol(n).getFiltered(t);if(!(r instanceof Wp))return!1;for(let t of r.mergedIndexes(e)){let n=e.interpretMetadata(t,this.filepath).getValue();if(!(!n||!Array.isArray(n))){for(let e of n)if(e.pk&&e.columns.some(e=>e.value===this.name))return!0}}return!1}isNotNullSet(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);if(n?.[i.NotNull]?.length)return!0;if(n?.[i.Null]?.length)return!1}isIncrementSet(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Increment]?.length:!1}increment(e){return this.isIncrementSet(e)||Ho(this.type(e)?.name??``)}default(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t)?.[i.Default]?.at(0)?.value;if(n)return Np(n)}type(e){if(!(this.declaration instanceof V))return;let n=Pp(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 Hp?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===Lm.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=Ap(M(i));if(a)return{value:a,token:P(r)}}},Kp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`TableGroup`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}fields(e){return this.members(e).filter(e=>e.isKind(`TableGroup field`))}color(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.color?.length?Mp(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=Ap(M(i));if(a)return{value:a,token:P(r)}}},qp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`TableGroup field`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Jp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`Note`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Yp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`TablePartial`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Xp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`PartialInjection`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Zp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Qp=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView top-level wildcard`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},$p=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView table`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},em=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView tablegroup`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},tm=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView note`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},nm=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView schema`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},rm=class extends Bp{constructor({declaration:e,name:t},n,r){super({kind:`Program`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}inNestedSchema(e,t){let n=this.members(e);if(n.some(e=>e.originalSymbol===t.originalSymbol))return!0;for(let r of n)if(r instanceof Vp&&r.inNestedSchema(e,t))return!0;return!1}},im=class extends Bp{constructor({kind:e,declaration:t,aliasedSymbol:n,name:r},i,a){super({kind:e,declaration:t,name:r},i,a),this.aliasedSymbol=n}get canBeImported(){return this.aliasedSymbol.canBeImported}get originalSymbol(){return this.aliasedSymbol.originalSymbol}},am=class extends Bp{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(lm);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},om=class extends Gp{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},sm=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},I=class{constructor(e,t,n,r){this.id=e,this.kind=t,this.filepath=n;let i=r.find(e=>e!==void 0&&!Number.isNaN(e.start));i?(this.startPos=i.startPos,this.fullStart=i instanceof Va?Ka(i):i.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let a=[...r].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));a?(this.endPos=a.endPos,this.fullEnd=a instanceof Va?Ga(a):a.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}intern(){return`node@${this.filepath.intern()}:${this.id}`}get parent(){let e=this.parentNode;for(;e;){if(e instanceof R||e instanceof L)return e;e=e.parentNode}}parentOfKind(e){let t=this;for(;t;){if(t instanceof e)return t;t=t.parentNode}}strictlyContains(e){if(typeof e==`number`)return this.start<e&&this.end>e;let{start:t,end:n}=e,r=this.start<t,i=r||this.start===t,a=this.end>n,o=a||this.end===n;return r&&o||i&&a}containsEq(e){if(typeof e==`number`)return this.start<=e&&this.end>=e;let{start:t,end:n}=e;return this.start<=t&&this.end>=n}},cm=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.USE_DECLARATION=`<use-declaration>`,e.USE_SPECIFIER=`<use-specifier>`,e.USE_SPECIFIER_LIST=`<use-specifier-list>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifier-stream>`,e.LITERAL=`<literal>`,e.VARIABLE=`<variable>`,e.PREFIX_EXPRESSION=`<prefix-expression>`,e.INFIX_EXPRESSION=`<infix-expression>`,e.POSTFIX_EXPRESSION=`<postfix-expression>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.FUNCTION_APPLICATION=`<function-application>`,e.BLOCK_EXPRESSION=`<block-expression>`,e.LIST_EXPRESSION=`<list-expression>`,e.TUPLE_EXPRESSION=`<tuple-expression>`,e.CALL_EXPRESSION=`<call-expression>`,e.PRIMARY_EXPRESSION=`<primary-expression>`,e.GROUP_EXPRESSION=`<group-expression>`,e.COMMA_EXPRESSION=`<comma-expression>`,e.EMPTY=`<dummy>`,e.ARRAY=`<array>`,e.WILDCARD=`<wildcard>`,e}({}),L=class extends I{constructor({body:e=[],eof:t,source:n},r,i){super(r,`<program>`,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===`<element-declaration>`)}get uses(){return this.body.filter(e=>e.kind===`<use-declaration>`)}},lm=class extends I{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,`<use-declaration>`,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return Qa(this.useKeyword)}},um=class extends I{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,`<use-specifier>`,a,[e,t,n,r]),this.importKind=e,this.name=t,this.asKeyword=n,this.alias=r}isKind(...e){return this.importKind?.value!==void 0&&e.map(e=>e.toLowerCase()).includes(this.importKind.value.toLowerCase())}getSymbolKind(){let e=this.importKind?.value?.toLowerCase();if(e!==void 0)return Object.values(F).find(t=>t.toLowerCase()===e)}},dm=class extends I{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,`<use-specifier-list>`,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},R=class e extends I{constructor({type:t,targetKind:n,name:r,as:i,alias:a,attributeList:o,bodyColon:s,body:c},l,u){if(super(l,`<element-declaration>`,u,[t,n,r,i,a,o,s,c]),c&&s&&!(c instanceof V||c instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.targetKind=n,this.name=r,this.as=i,this.alias=a,this.attributeList=o,this.bodyColon=s,this.body=c}isKind(...e){return e.some(e=>this.type?.value.toLowerCase()===e)}getElementKind(){return Object.values(r).find(e=>this.isKind(e))}},fm=class extends I{constructor({identifiers:e=[]},t,n){super(t,`<identifier-stream>`,n,e||[]),this.identifiers=e}},z=class extends I{constructor({name:e,colon:t,value:n},r,i){super(r,`<attribute>`,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},B=class extends I{constructor({op:e,expression:t},n,r){super(n,`<prefix-expression>`,r,[e,t]),this.op=e,this.expression=t}},pm=class extends I{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,`<infix-expression>`,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},mm=class extends I{constructor({op:e,expression:t},n,r){super(n,`<postfix-expression>`,r,[t,e]),this.op=e,this.expression=t}},hm=class extends I{constructor({value:e},t,n){super(t,`<function-expression>`,n,[e]),this.value=e}},V=class extends I{constructor({callee:e,args:t=[]},n,r){super(n,`<function-application>`,r,[e,...t]),this.callee=e,this.args=t}},H=class extends I{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,`<block-expression>`,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},U=class extends I{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,`<list-expression>`,a,[e,...Tm(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},gm=class extends I{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,`<tuple-expression>`,a,[e,...Tm(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},_m=class extends I{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,`<comma-expression>`,r,[...Tm(e,t)]),this.elementList=e,this.commaList=t}},vm=class extends gm{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=`<group-expression>`}},W=class extends I{constructor({callee:e,argumentList:t},n,r){super(n,`<call-expression>`,r,[e,t]),this.callee=e,this.argumentList=t}},ym=class extends I{constructor({literal:e},t,n){super(t,`<literal>`,n,[e]),this.literal=e}},bm=class extends I{constructor({token:e},t,n){super(t,`<wildcard>`,n,[e]),this.token=e}},xm=class extends I{constructor({variable:e},t,n){super(t,`<variable>`,n,[e]),this.variable=e}},Sm=class extends I{constructor({expression:e},t,n){super(t,`<primary-expression>`,n,[e]),this.expression=e}},Cm=class extends I{constructor({prevToken:e},t,n){let r=Va.create(v.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,`<dummy>`,n,[r])}},wm=class extends I{constructor({expression:e,indexer:t},n,r){super(n,`<array>`,r,[e,t]),this.array=e,this.indexer=t}};function Tm(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];let[n]=e,[r]=t;return(n.start<r.start?br(La(e,t)):br(La(t,e))).filter(e=>e!==null)}function Em(e,t,n){let r=t,i=e;if(i instanceof W&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Hf(i)||r.length===0)return;let a=[...r],o=np(i),s=a.pop();if(!(s instanceof H))return;let c=g(a)instanceof U?a.pop():void 0;if(a.length===3){let e=np(a[1]);return!e||!Ja(e)?void 0:n.create(R,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(R,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(R,{type:o,attributeList:c,body:s})}function G(e){e&&(e instanceof Va?Dm(e):Om(e))}function Dm(e){e.kind!==v.EOF&&(e.isInvalid=!0)}function Om(e){if(e instanceof R)G(e.type),G(e.targetKind),G(e.name),G(e.as),G(e.alias),G(e.bodyColon),G(e.attributeList),G(e.body);else if(e instanceof fm)e.identifiers.forEach(G);else if(e instanceof z)G(e.name),G(e.colon),G(e.value);else if(e instanceof B)G(e.op),G(e.expression);else if(e instanceof pm)G(e.leftExpression),G(e.op),G(e.rightExpression);else if(e instanceof mm)G(e.op),G(e.expression);else if(e instanceof H)G(e.blockOpenBrace),e.body.forEach(G),G(e.blockCloseBrace);else if(e instanceof U)G(e.listOpenBracket),e.commaList.forEach(G),e.elementList.forEach(G),G(e.listCloseBracket);else if(e instanceof gm)G(e.tupleOpenParen),e.commaList.forEach(G),e.elementList.forEach(G),G(e.tupleCloseParen);else if(e instanceof _m)e.commaList.forEach(G),e.elementList.forEach(G);else if(e instanceof W)G(e.callee),G(e.argumentList);else if(e instanceof V)G(e.callee),e.args.forEach(G);else if(e instanceof Sm)G(e.expression);else if(e instanceof hm)G(e.value);else if(e instanceof xm)G(e.variable);else if(e instanceof ym)G(e.literal);else if(e instanceof vm)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof wm)G(e.array),G(e.indexer);else if(e instanceof L)e.body.forEach(G),G(e.eof);else if(!(e instanceof Cm))if(e instanceof lm)G(e.useKeyword),G(e.specifiers),G(e.fromKeyword),G(e.importPath);else if(e instanceof dm)G(e.openBrace),e.specifiers.forEach(G),G(e.closeBrace);else if(e instanceof um)G(e.importKind),G(e.name),G(e.asKeyword),G(e.alias);else if(e instanceof bm)G(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function km(...e){return e.filter(e=>e!==void 0)}function Am(e){if(e instanceof L)return km(...e.body,e.eof);if(e instanceof R)return km(e.type,e.targetKind,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof z)return km(e.name,e.colon,e.value);if(e instanceof fm)return e.identifiers;if(e instanceof ym)return e.literal?[e.literal]:[];if(e instanceof xm)return km(e.variable);if(e instanceof B)return km(e.op,e.expression);if(e instanceof pm)return km(e.leftExpression,e.op,e.rightExpression);if(e instanceof mm)return km(e.expression,e.op);if(e instanceof hm)return km(e.value);if(e instanceof V)return km(e.callee,...e.args);if(e instanceof H)return km(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof U)return km(e.listOpenBracket,...jm(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof gm)return km(e.tupleOpenParen,...jm(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof _m)return km(...jm(e.elementList,e.commaList));if(e instanceof W)return km(e.callee,e.argumentList);if(e instanceof Sm)return km(e.expression);if(e instanceof wm)return km(e.array,e.indexer);if(e instanceof Cm)return[];if(e instanceof lm)return km(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof dm)return km(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof um)return km(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof bm)return km(e.token);throw e instanceof vm?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function jm(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 Mm(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function Nm(e){if(!e)return[];if(D(e))return[{variables:[e],tupleElements:[]}];if(e instanceof pm){let t=cp(e);return t?[t]:[...Nm(e.leftExpression),...Nm(e.rightExpression)]}if(e instanceof B||e instanceof mm)return Nm(e.expression);if(e instanceof gm){let t=cp(e);return t?[t]:e.elementList.flatMap(Nm)}return[]}function Pm(e,n){let r=n.parentNode;if(!r||!O(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;O(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Fm(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Vp&&e.isPublicSchema())}function Im(e,n){let r=e.parseFile(n).getValue().ast;return e.nodeSymbol(r).getFiltered(t)}var Lm=function(e){return e.Ref=`ref`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e.MetadataElement=`metadata element`,e}({}),Rm=class e{static{this.id=0}constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}resolveOwnerPrograms(e,t){let n=this.declaration.filepath;return e.reachableFiles().flatMap(t=>Im(e,t)||[]).filter(r=>e.reachableFiles(r.filepath).some(e=>e.equals(n))&&t.every(t=>r.inNestedSchema(e,t)))}},zm=class extends Rm{constructor(e){super(e),this.kind=`ref`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof R){let t=op(this.declaration)[0];if(!(t instanceof V))return[];let n=t.callee;return n instanceof pm?Km(e,n.leftExpression):[]}if(this.declaration instanceof z){let n=this.declaration.parentOfKind(V);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof R){let t=op(this.declaration)[0];if(!(t instanceof V))return[];let n=t.callee;return n instanceof pm?Km(e,n.rightExpression):[]}if(this.declaration instanceof z){let t=this.declaration.value;return t instanceof B?Km(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof R){let t=op(this.declaration)[0];if(!(t instanceof V))return;let n=t.callee;return n instanceof pm?qm(e,n.leftExpression):void 0}if(this.declaration instanceof z)return this.container(e)}rightTable(e){if(this.declaration instanceof R){let t=op(this.declaration)[0];if(!(t instanceof V))return;let n=t.callee;return n instanceof pm?qm(e,n.rightExpression):void 0}if(this.declaration instanceof z){let t=this.declaration.value;return t instanceof B?qm(e,t.expression)??this.container(e):void 0}}op(e){return this.opToken()?.value}opToken(){if(this.declaration instanceof R){let e=op(this.declaration)[0];if(!(e instanceof V))return;let t=e.callee;return t instanceof pm?t.op:void 0}if(this.declaration instanceof z){let e=this.declaration.value;return e instanceof B?e.op:void 0}}cardinalities(e){let t=this.op(e);return t?lf(t):void 0}leftCardinality(e){let t=this.cardinalities(e);return t?tf(t[0]):void 0}rightCardinality(e){let t=this.cardinalities(e);return t?tf(t[1]):void 0}active(e){if(!(this.declaration instanceof R))return!0;let n=op(this.declaration)[0];return n?!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length:!0}leftToken(){if(this.declaration instanceof R){let e=op(this.declaration)[0];if(e instanceof V){let t=e.callee;if(t instanceof pm&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof z){let e=this.declaration.parentOfKind(V);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof R){let e=op(this.declaration)[0];if(e instanceof V){let t=e.callee;if(t instanceof pm&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof z,this.declaration}owners(e){let t=this.leftTable(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Bm=class extends Rm{constructor(e){super(e),this.kind=`partial ref`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof z))return[];let n=this.declaration.parentOfKind(V);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof z))return[];let t=this.declaration.value;return t instanceof B?Km(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof z)return this.container(e)}rightTable(e){if(!(this.declaration instanceof z))return;let t=this.declaration.value;if(t instanceof B)return qm(e,t.expression)??this.container(e)}op(e){return this.opToken()?.value}opToken(){if(!(this.declaration instanceof z))return;let e=this.declaration.value;if(e instanceof B)return e.op}cardinalities(e){let t=this.op(e);return t?lf(t):void 0}leftToken(){if(this.declaration instanceof z){let e=this.declaration.parentOfKind(V);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof z,this.declaration}owners(e){let t=this.leftTablePartial(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Vm=class extends Rm{constructor(e){super(e),this.kind=`table checks`,this.ownerTable=e.parentNode?.parentOfKind(R)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Hm=class extends Rm{constructor(e){super(e),this.kind=`indexes`,this.ownerTable=e.parentNode?.parentOfKind(R)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Um=class extends Rm{constructor(e){super(e),this.kind=`records`}table(e){let n=this.declaration,i=n.parent;if(i instanceof R&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof W))return;let o=dp(a);if(!o)return;let s=o.variables.at(-1);if(s)return e.nodeReferee(s).getFiltered(t)?.originalSymbol}owners(e){let t=this.table(e);return t?this.resolveOwnerPrograms(e,[t]):[]}},Wm=class extends Rm{constructor(e){super(e),this.kind=`metadata element`}target(e){let n=this.declaration.name;if(!n)return;let r=ep(n)??n;return e.nodeReferee(r).getFiltered(t)?.originalSymbol}owners(e){let n=this.target(e);if(!n)return[];if(n.kind===F.Column){let r=n.declaration?.parentOfKind(R),i=r?e.nodeSymbol(r).getFiltered(t)?.originalSymbol:void 0;if(!i)return[];n=i}return this.resolveOwnerPrograms(e,[n])}},Gm=class extends Rm{constructor(e){super(e),this.kind=`project`}owners(e){let n=this.declaration.filepath,r=e.parseFile(n).getValue().ast,i=e.nodeSymbol(r).getFiltered(t);return i?[i]:[]}};function Km(e,n){if(!n)return[];let r=cp(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 qm(e,n){if(!n)return;let r=cp(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 Jm=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},Ym=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof H?new n(e.body.flatMap(e=>{if(!(e instanceof V))return[];let t=P(e),n=e.callee instanceof hm?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof U);return a&&(r=M(zf(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}},Xm={nodeMetadata(t,i){if(k(i,r.Checks)){let t=i.parent;return!t||!k(t,r.Table)&&!k(t,r.TablePartial)?n.create(e):n.create(new Vm(i))}return n.create(e)},bindNode(t,i){return k(i,r.Checks)?n.create(void 0,new Jm(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Lm.TableChecks?r.declaration instanceof R?new Ym(t,r.declaration).interpret():n.create(void 0):n.create(e)}},Zm=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=_(e.body,e=>e instanceof V);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof H)?[]:e.isKind(r.DiagramViewTables)?this.bindTableReferences(e.body):e.isKind(r.DiagramViewNotes)?this.bindNoteReferences(e.body):e.isKind(r.DiagramViewTableGroups)?this.bindTableGroupReferences(e.body):e.isKind(r.DiagramViewSchemas)?this.bindSchemaReferences(e.body):[])}bindTableReferences(e){let[t]=_(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||Vf(e.callee)?[]:[e.callee,...e.args].flatMap(Nm).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables.pop();return[...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}))}bindNoteReferences(e){let[t]=_(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||Vf(e.callee)?[]:Nm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=_(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||Vf(e.callee)?[]:Nm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=_(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||Vf(e.callee)?[]:Nm(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},Qm=class{constructor(e,t,n,r){this.diagramViewWildcards=new Set,this.diagramViewExplicitlySet=new Set,this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r??t.filepath,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null}}}interpret(){let e=[];this.diagramView.token=this.symbol.token;let{name:t,schema:r}=this.symbol.interpretedName(this.compiler,this.filepath);return this.diagramView.name=t,this.diagramView.schemaName=r,this.declarationNode.body instanceof H&&e.push(...this.interpretBody(this.declarationNode.body)),this.expandDiagramViewWildcards(),new n(this.diagramView,e)}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof V&&Vf(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramViewWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramViewExplicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=_(e.body,e=>e instanceof R),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof H&&this.interpretSubBlock(e.body,t)}let i=this.diagramView.visibleEntities;return(n.has(`tables`)&&i.tables!==null||n.has(`tablegroups`)&&i.tableGroups!==null||n.has(`schemas`)&&i.schemas!==null)&&(n.has(`tables`)||(i.tables=[]),n.has(`tablegroups`)||(i.tableGroups=[]),n.has(`schemas`)||(i.schemas=[])),n.has(r.DiagramViewTables)&&this.diagramViewExplicitlySet.add(`tables`),n.has(r.DiagramViewTableGroups)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(r.DiagramViewSchemas)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(r.DiagramViewNotes)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,n){if(!n)return;if(e.body.some(e=>e instanceof V&&Vf(e.callee))){let e=this.diagramViewWildcards;switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=[],e.add(`tables`);break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=[],e.add(`stickyNotes`);break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=[],e.add(`tableGroups`);break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=[],e.add(`schemas`);break}return}if(e.body.length===0)return;let i=[];for(let n of e.body){if(!(n instanceof V))continue;let e=n.callee&&ep(n.callee),r=e&&this.compiler.nodeReferee(e).getFiltered(t);if(r?.declaration instanceof R){let e=j(r.declaration.name)??[];if(e.length>0){let t=e[e.length-1],n=e.length>1?e.slice(0,-1).join(`.`):y;i.push({name:t,schemaName:n});continue}}let a=j(n.callee)??[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[0]:y;i.push({name:o,schemaName:s})}switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=i.length>0?i:null;break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=i.length>0?i.map(e=>({name:e.name})):null;break}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;if(!(!t||!e)){if(t.has(`tables`)||t.has(`schemas`)){e.tables=[],e.tableGroups=[],e.schemas=[];return}t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames())}}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n)return[];let r=this.compiler.symbolMembers(n).getFiltered(t);return r?Pa(r.filter(e=>e.isKind(F.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function $m(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var eh=function(e){return e.Table=`table`,e}({}),th={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new E(T.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},nh={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.DiagramView)?new n(i.symbolFactory.create(Zp,{declaration:a,name:o},a.filepath)):A(a,r.DiagramView)&&a instanceof bm?new n(i.symbolFactory.create(Qp,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(tm,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewTables)?new n(i.symbolFactory.create($p,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(em,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(nm,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&Yf(a))return n.create(e);let o=rh(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)?ih(i,c,a):o.isKind(r.DiagramViewNotes)?ah(i,c,a,F.StickyNote):o.isKind(r.DiagramViewTableGroups)?ah(i,c,a,F.TableGroup):o.isKind(r.DiagramViewSchemas)?oh(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(F.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!k(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of op(o))if(e instanceof V){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof R&&c.push(...op(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(F.DiagramViewSchema,F.DiagramViewTableGroup,F.DiagramViewTable,F.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(Zg).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(th.getFieldDuplicateError(n,e.kind,i)),s.push(th.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!k(a,r.DiagramView))return n.create(e);let o=new Zm(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Zp?r.declaration instanceof R?new Qm(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function rh(e){let t=e.parentOfKind(V);if(!t)return;let n=t.parentNode;if(!(n instanceof H))return;let i=n.parentNode;if(!(i instanceof R)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof H))return;let o=a.parentNode;if(!(!(o instanceof R)||!o.isKind(r.DiagramView)))return i}function ih(e,r,i){let a=fp(i);if(a===void 0)return n.create(void 0);if(O(i.parentNode)){let t=Pm(e,i);if(t){if(t.isKind(F.Schema)){let r=tp(i),o=e.lookupMembers(t,r?F.Table:F.Schema,a);return o?n.create(o):new n(void 0,[new E(T.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,F.Schema,a);return o?n.create(o):new n(void 0,[new E(T.BINDING_ERROR,`Could not find schema '${a}'`,i)])}let o=e.symbolMembers(r).getFiltered(t)||[];for(let e of o){let t=e.name;if(e.isKind(F.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,F.Table,a);return s?n.create(s):new n(void 0,[new E(T.BINDING_ERROR,`Could not find table '${a}'`,i)])}function ah(e,t,r,i){let a=fp(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 E(T.BINDING_ERROR,`Could not find ${i===F.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function oh(e,t,r){let i=fp(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var sh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof V)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},ch=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.enum={values:[]}}interpret(){this.enum.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody(this.declarationNode.body)];return n.create(this.enum,e)}interpretName(){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);return this.enum.name=e,this.enum.schemaName=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=P(t),n.name=N(t.callee);let r=zf(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Ap(M(r.value)),token:P(r)},this.enum.values.push(n),[]})}},lh={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new E(T.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},uh={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.Enum)?new n(i.symbolFactory.create(Hp,{declaration:a,name:o},a.filepath)):A(a,r.Enum)?new n(i.symbolFactory.create(Up,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof R))return new n([]);let o=op(a),s=[],c=[];for(let e of o){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(s.push(i),c.push(...n.getErrors()))}let l=new Map;for(let e of s){if(!e.isKind(F.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push(lh.getFieldDuplicateError(t,r)),c.push(lh.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!k(a,r.Enum))return n.create(e);let o=new sh(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Hp?new ch(t,r,i).interpret():n.create(e)}},dh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof R)||!this.declarationNode.parent.isKind(r.Table)&&!this.declarationNode.parent.isKind(r.TablePartial)||!(this.declarationNode.body instanceof H)?[]:this.bindBody(this.declarationNode.body)}get ownerContainerKind(){return this.declarationNode.parent.isKind(r.TablePartial)?`TablePartial`:`Table`}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=j(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(Nm).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=fp(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new E(T.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},fh=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof H?new n(e.body.flatMap(e=>{if(!(e instanceof V)||!e.callee)return[];let n=[],r=P(e),a=[e.callee,...e.args],o,s,c,l,u;g(a)instanceof U&&a.pop();let d=this.compiler.nodeSettings(e).getFiltered(t);if(d){o=!!d[i.PK]?.length||void 0,s=!!d[i.Unique]?.length||void 0,c=M(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=M(e.value);t!==void 0&&(l={value:t,token:P(e)})}u=N(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof W))return e;let t=[],n=e;for(;n instanceof W&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=lp(e);if(t){for(let e of t.functional)n.push({value:e.value?.value??``,type:`expression`,token:P(e)});for(let e of t.nonFunctional)n.push({value:fp(e)??``,type:`column`,token:P(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}},ph={nodeMetadata(t,i){if(!k(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!k(a,r.Table)&&!k(a,r.TablePartial)?n.create(e):n.create(new Hm(i))},nodeReferee(i,a){if(!D(a)||Yf(a))return n.create(e);let o=a;for(;o&&!k(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!k(s,r.Table)&&!k(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=D(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,F.Column,l);if(u)return n.create(u);let d=k(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new E(T.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return k(i,r.Indexes)?n.create(void 0,new dh(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Lm.Indexes?r.declaration instanceof R?new fh(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function mh(e,n){let r=sp(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof gm){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 gm)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function hh(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 E(T.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new E(T.CIRCULAR_REF,`References with same endpoints exist`,n),new E(T.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var gh=class{constructor(e,t){this.compiler=t,this.ast=e}resolve(){let e=[],i=this.compiler.reachableFiles(this.ast.filepath);for(let n of i){let{ast:i}=this.compiler.parseFile(n).getFiltered(t)||{ast:void 0};if(!i)continue;let a=i.body.filter(e=>e instanceof R&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new E(T.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof R&&t.type){let n=t;e.push(...this.compiler.bindNode(n).getErrors())}else e.push(...this.compiler.bindNode(t).getErrors())}let a=this.compiler.nodeSymbol(this.ast).getFiltered(t);return a&&e.push(..._h(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 R)||!t.type)continue;let i=t;k(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),k(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),k(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of op(e)){if(!(r instanceof V)||!r.callee||!Zf(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=mh(this.compiler,i.leftExpression),o=mh(this.compiler,i.rightExpression);!a||!o||n.push(...hh(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of op(e)){if(!(a instanceof V)||!a.callee)continue;let e=this.compiler.nodeSymbol(a).getFiltered(t);if(!e)continue;let o=this.compiler.nodeSettings(a).getFiltered(t);if(!o)continue;let s=o[i.Ref];if(!(!s||s.length===0))for(let t of s){let i=t.value;if(!(i instanceof B)||!i.op||!Af(i.op.value)||!i.expression)continue;let a=mh(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...hh(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of op(e)){if(!(r instanceof V)||!r.callee)continue;let e=N(r.callee);if(!e)continue;let a=this.compiler.nodeSettings(r).getFiltered(t);if(!a)continue;let o=a[i.Ref];if(!(!o||o.length===0))for(let t of o){let r=t.value;r instanceof B&&(!r.op||!Af(r.op.value)||r.expression&&D(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new E(T.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 R)||!i.type)continue;let a=i;if(!k(a,r.TableGroup))continue;let o=a.name?j(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=op(a);for(let r of c){if(!(r instanceof V)||!r.callee)continue;let i=sp(r.callee);if(!i||i.length===0)continue;let a=i[i.length-1],o=this.compiler.nodeReferee(a).getFiltered(t)?.originalSymbol;if(!o)continue;let c=n.get(o.id);if(c){let t=j(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new E(T.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 _h(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 Vp&&a.push(..._h(e,t,r));return a}function vh(e,t,n){t.isKind(F.Table)?e.externals.tables.push(n):t.isKind(F.Enum)?e.externals.enums.push(n):t.isKind(F.TableGroup)?e.externals.tableGroups.push(n):t.isKind(F.TablePartial)?e.externals.tablePartials.push(n):t.isKind(F.StickyNote)&&e.externals.notes.push(n)}function yh(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function bh(e,t){return e?`${e}.${t}`:`${y}.${t}`}function xh(e,t,n){return n.map(n=>{let r=t[n.name??``]?.value;if(r==null){let t=n.default(e);if(t)return JSON.stringify(t.value)}return JSON.stringify(r)}).join(`|`)}function Sh(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function Ch(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function wh(e,t,n){return n.length===1?Ch(e,t,n[0]):`(${n.map(n=>Ch(e,t,n)).join(`, `)})`}function Th(e,t,n){let r=n.map(n=>{let r=n.name??``,i=t[r]===void 0?n.default(e)?.value:t[r].value;return JSON.stringify(i)}).join(`, `);return n.length===1?r:`(${r})`}function Eh(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function Dh(e,t,n){let{token:r}=t,i=e.nodeAtPosition(r.filepath,r.start.offset)??e.parse.ast(r.filepath);return new yf(T.INVALID_RECORDS_FIELD,n,i)}var Oh=e=>e>1?`Composite PK`:`PK`;function kh(e,t,n,r){return Oa(r.values)?[]:xa(Ph(t,e),i=>Ah(e,t,n,i,r))}function Ah(e,t,n,r,i){let a=yh(i),o=Nh(e,t,n,r,i);if(!Oa(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=_(a,t=>Sh(e,t,s)),u=jh(e,t,s.map(e=>e.name??``),c),d=r.some(t=>t.increment(e))?[]:Mh(e,t,r,l);return[...u,...d]}function jh(e,t,n,r){if(Oa(r))return[];let i=t.schema(e),a=t.name??``,o=`NULL in ${Oh(n.length)}: ${wh(i,a,n)} cannot be NULL`;return xa(r,t=>Eh(t,n).map(t=>Dh(e,t,o)))}function Mh(e,t,n,r){let i=n.map(e=>e.name??``),a=t.schema(e),o=t.name??``;return xa(ma(wa(r,t=>xh(e,t,n)),e=>e.length>1),t=>{let r=Oh(i.length),s=wh(a,o,i);return xa(t,t=>{let a=`Duplicate ${r}: ${s} = ${Th(e,t,n)}`;return Eh(t,i).map(t=>Dh(e,t,a))})})}function Nh(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=t.schema(e),c=t.name??``,l=da(a,Array.from(o));if(Oa(l))return[];let u=new Set(l),d=r.filter(e=>u.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e)).map(e=>e.name??``);if(Oa(d))return[];let f=`${Oh(d.length)}: Column ${wh(s,c,d)} is missing from record and has no default value`;return i.values.map(()=>new yf(T.INVALID_RECORDS_FIELD,f,n))}function Ph(e,t){let n=e.mergedColumns(t),r=ka(n,e=>e.name??``);return[...n.filter(e=>e.pk(t)).map(e=>[e]),...e.mergedIndexes(t).flatMap(e=>{let n=t.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.pk).map(e=>Qr(e.columns.map(e=>r[e.value]))):[]})]}function Fh(e,t,n){if(Oa(n.values))return[];let r=yh(n);return xa(Ih(e,t),n=>Lh(e,t,n,r))}function Ih(e,t){let n=t.mergedColumns(e),r=ka(n,e=>e.name??``);return[...n.filter(t=>t.isUniqueSet(e)).map(e=>[e]),...t.mergedIndexes(e).flatMap(t=>{let n=e.interpretMetadata(t,t.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.unique).map(e=>Qr(e.columns.map(e=>r[e.value]))):[]})]}function Lh(e,t,n,r){let i=n.map(e=>e.name??``);return xa(ma(wa(r.filter(t=>!Sh(e,t,n)),t=>xh(e,t,n)),e=>e.length>1),r=>{let a=n.length>1?`Composite UNIQUE`:`UNIQUE`,o=wh(t.schema(e),t.name??``,i);return xa(r,t=>{let r=`Duplicate ${a}: ${o} = ${Th(e,t,n)}`;return Eh(t,i).map(t=>Dh(e,t,r))})})}function Rh(e,t,n){let r=new Map;for(let i of e.values()){let{name:e,schema:a}=i.tableSymbol.interpretedName(t,n);r.set(bh(a,e),i)}return r}function zh(e,t,n,r){let i=Rh(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!Oa(t.record.values)&&a.add(e);return xa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(bh(e.schemaName,e.tableName))):!1),t=>Bh(e,t,i,r))}function Bh(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(bh(i.schemaName,i.tableName)),s=n.get(bh(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=Qr(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=Qr(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=tf(i.relation),{min:m,max:ee}=tf(a.relation),te=p===1&&m===0||p!==`*`&&ee!==`*`,ne=ee===1&&f===0;return[...te?[]:Vh(e,o,u,s,d,a.relation,r),...ne?[]:Vh(e,s,d,o,u,i.relation,r)]}function Vh(e,t,n,r,i,a,o){if(!t.record||Oa(t.record.values))return[];let{min:s}=tf(a),c=Qr(n.map(e=>e.name)),l=Qr(i.map(e=>e.name)),u=s===0,d=yh(t.record),f=r.record?yh(r.record):[],p=new Set(f.map(t=>xh(e,t,i))),m=t.tableSymbol.interpretedName(e,o),ee=r.tableSymbol.interpretedName(e,o);return xa(d,t=>{if(Sh(e,t,n)){if(u)return[];let r=`FK violation: ${wh(m.schema,m.name,c)} = ${Th(e,t,n)} must not be null`;return Eh(t,c).map(t=>Dh(e,t,r))}let r=xh(e,t,n);if(p.has(r))return[];let i=wh(m.schema,m.name,c),a=wh(ee.schema,ee.name,l),o=`FK violation: ${i} = ${Th(e,t,n)} does not exist in ${a}`;return Eh(t,c).map(t=>Dh(e,t,o))})}function Hh(e,t){if(e instanceof V){let n=e.args.find(e=>e instanceof U);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}}if(e instanceof R){let n=e.attributeList;if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}}return{start:e.end,end:e.end,newText:` [${t}]`}}function Uh(e,t,n){let r=Wh(n,e,t);if(!r)return;let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function Wh(e,t,n){if(!(t instanceof V)&&!(t instanceof R))return;let r=t instanceof V?t.args.find(e=>e instanceof U):t.attributeList;if(!r)return;let i=r.elementList??[],a=i.findIndex(t=>t instanceof z?(t.name?e.substring(t.name.start,t.name.end).trim():e.substring(t.start,t.end).trim())===n:!1);if(a!==-1)return{settingsList:r,settingNode:i[a],settingIndex:a}}function Gh(e,t,n,r){let{allowOtherColFix:i=!0,allowOwnColFix:a=!0}=r??{},o=t.op(e),s=t.opToken(),c=t.cardinalities(e);if(!o||!s||!c)return[];let l=n===`left`?c[0]:c[1],u=tf(l),d=n===`left`?c[1]:c[0],f=tf(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),ee=n===`left`?t.leftToken():t.rightToken(),te=n===`left`?t.rightToken():t.leftToken(),ne=[];function re(e,t,n,r){ne.push(new bf(T.INVALID_REF_RELATIONSHIP,n,e,{quickFixes:r}));for(let e of t)e.declaration&&ne.push(new bf(T.INVALID_REF_RELATIONSHIP,n,e.declaration,{quickFixes:r}))}let ie=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&ie&&m.length>0&&m.every(t=>t.nullable(e))){let t=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `);re(te,m,m.length===1?`Column '${t}' is nullable but operator '${o}' requires it to be NOT NULL`:`Columns (${t}) are all nullable but operator '${o}' requires at least one to be NOT NULL`,[s&&qh(s,gf(l),d,n,`Make '${t}' optional in the ref`),...i?m.map(t=>Jh(t,e)).filter(e=>!!e):[]].filter(e=>!!e))}if(u.min===0&&ie&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let t=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `);re(te,m,m.length===1?`Column '${t}' is NOT NULL but operator '${o}' allows it to be optional`:`Columns (${t}) are NOT NULL but operator '${o}' allows them to be optional`,[s&&qh(s,_f(l),d,n,`Make '${t}' required in the ref`),...i?m.map(t=>Yh(t,e)).filter(e=>!!e):[]].filter(e=>!!e))}if(u.max===`*`&&Xh(e,p)){let t=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `);re(ee,p,p.length===1?`Column '${t}' is unique but operator '${o}' allows many`:`Columns (${t}) have a unique index but operator '${o}' allows many`,[s&&qh(s,`1`,d,n,`Make '${t}' one in the ref`)].filter(e=>!!e))}if(u.max===1&&!Xh(e,p)){let t=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `);re(ee,p,p.length===1?`Column '${t}' should be unique or primary key for operator '${o}'`:`Columns (${t}) should have a composite unique index for operator '${o}'`,[s&&qh(s,vf(l),d,n,`Make '${t}' many in the ref`),a&&p.length===1&&Zh(p[0],e)].filter(e=>!!e))}return ne}function Kh(e,t){return[...Gh(e,t,`right`,{allowOtherColFix:!1}),...Gh(e,t,`left`,{allowOwnColFix:!1})]}function qh(e,t,n,r,i){let a=hf(r===`left`?t:n,r===`right`?t:n);return{title:`${i} (change operator to '${a}')`,filepath:e.filepath,edits:[{start:e.start,end:e.end,newText:a}]}}function Jh(e,t){if(!e.declaration||e.pk(t)||e.increment(t)||e.isNotNullSet(t))return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=e.qualifiedName(t).join(`.`),i=Uh(e.declaration,`null`,n);if(i)return{title:`Mark '${r}' as NOT NULL`,filepath:e.declaration.filepath,edits:[i]};let a=Hh(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,filepath:e.declaration.filepath,edits:[a]}}function Yh(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=Uh(e.declaration,`not null`,n);if(r)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as NULL`,filepath:e.declaration.filepath,edits:[r]}}function Xh(e,n){if(n.length===0)return!1;if(n.length===1&&n[0].unique(e))return!0;let r=n[0],i=(r instanceof om?r.injectionDeclaration:r.declaration)?.parentOfKind(R);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof Wp))return!1;let o=a.mergedIndexes(e),s=new Set(n.map(e=>e.name));for(let t of o){let r=e.interpretMetadata(t,n[0].filepath).getValue();if(!(!r||!Array.isArray(r))){for(let e of r)if(!(!e.unique&&!e.pk)&&e.columns.length===s.size&&e.columns.every(e=>s.has(e.value)))return!0}}return!1}function Zh(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=Hh(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,filepath:e.declaration.filepath,edits:[n]}}var Qh=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:P(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.warnings.push(...this.validateRecords()),new n(this.db,this.errors,this.warnings,this.infos)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof am)continue;let r=this.compiler.interpretSymbol(n,this.filepath);if(r.hasValue(t))continue;this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let i=r.getValue();i&&this.pushElement(n,i)}let e=new Set,n=(this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[]).filter(e=>e instanceof Vp);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Vp){n.push(t);continue}if(!(t instanceof am))continue;let r=t.originalSymbol.intern();e.has(r)||(e.add(r),this.interpretUseSymbol(t))}}}interpretUseSymbol(e){let n=e.originalSymbol,r=this.compiler.interpretSymbol(n,this.filepath);if(!r.hasValue(t)){this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let t=r.getValue();t&&this.pushElement(e,t)}let i=n instanceof Wp?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Wp?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}]};vh(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 Um))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()),this.infos.push(...e.getInfos());let a=e.getValue();if(a!==void 0)switch(i.kind){case Lm.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 E(T.SAME_ENDPOINT,`Ref with same endpoints already exists`,i.declaration));break}n.add(e)}this.db.refs.push(e);break}case Lm.Records:if(i instanceof Um){let e=i.table(this.compiler)?.originalSymbol.intern()??``,t=e?r.get(e):void 0;if(t&&t.count>1){this.errors.push(new E(T.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 Lm.Project:this.db.project=a;break;case Lm.MetadataElement:default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof im)||!t.isKind(F.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:eh.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 Vp))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(F.Table))continue;let t=e.originalSymbol;if(!(t instanceof Wp))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 Um))continue;let i=r.table(this.compiler);if(!(i instanceof Wp))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...kh(this.compiler,i,r.declaration,o)),e.push(...Fh(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(...zh(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Bm);for(let t of e)this.infos.push(...Kh(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Bm),n=[];for(let{tableSymbol:r}of e.values())for(let e of r.resolvedPartials(this.compiler))for(let i of t){if(i.leftTablePartial(this.compiler)?.originalSymbol!==e.originalSymbol)continue;let t=i.leftColumns(this.compiler),a=i.rightTable(this.compiler),o=i.rightColumns(this.compiler),s=i.op(this.compiler);if(!a||!s||t.length===0||o.length===0)continue;let c=r.mergedColumns(this.compiler);if(!t.some(e=>c.some(t=>t instanceof om&&t.declaration===e.declaration)))continue;let l=lf(s);if(!l)continue;let u=a instanceof Yp&&a.originalSymbol===e.originalSymbol?r:a,d=r.interpretedName(this.compiler,this.filepath),f=u.interpretedName(this.compiler,this.filepath),p={schemaName:d.schema,tableName:d.name,fieldNames:t.map(e=>e.name??``),relation:l[0],token:P(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:P(i.rightToken())};n.push({token:P(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case F.Table:this.db.tables.push(t);break;case F.Enum:this.db.enums.push(t);break;case F.TableGroup:this.db.tableGroups.push(t);break;case F.TablePartial:this.db.tablePartials.push(t);break;case F.StickyNote:this.db.notes.push(t);break;case F.DiagramView:this.db.diagramViews.push(t);break;default:break}}},$h={nodeSymbol(t,r){return Kf(r)?n.create(t.symbolFactory.create(rm,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Program))return n.create(e);if(!(i.declaration instanceof L))return n.create([]);let a=new Map;for(let e of r.reachableFiles(i.filepath)){let{schemaMembers:t}=r.usableMembers(e).getValue();for(let e of t)a.has(e.name)||a.set(e.name,e)}let o=a.get(y);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(F.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Kf(r)?new gh(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof rm))return n.create(e);if(!(r.declaration instanceof L))return n.create(void 0);if(!Mm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new Qh(t,r,i).interpret()}},eg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof V)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},tg=class{constructor(e,t,n){this.declarationNode=t,this.compiler=e,this.filepath=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){this.project.token=P(this.declarationNode);let e=[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)];return new n(this.project,e)}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=jp(e);return this.project.name=t,[]}interpretSubElement(e){let r=this.compiler.nodeSymbol(e).getFiltered(t);if(r){let e=this.compiler.interpretSymbol(r,this.filepath);if(!e.hasValue(t))return e}return n.create(void 0)}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.getElementKind()){case r.Table:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tables?.push(e.getValue()),e.getErrors()}case r.TableGroup:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tableGroups?.push(e.getValue()),e.getErrors()}case r.Enum:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.enums?.push(e.getValue()),e.getErrors()}case r.Note:{let e=t.body instanceof H?t.body.body[0]?.callee:t.body?.callee,n=e?M(e):void 0;return n&&(this.project.note={value:Ap(n),token:P(t)}),[]}case r.TablePartial:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tablePartials?.push(e.getValue()),e.getErrors()}default:return this.project[t.type.value.toLowerCase()]=M(t.body.callee),[]}})}},ng={nodeMetadata(t,i){return k(i,r.Project)?n.create(new Gm(i)):n.create(e)},bindNode(t,i){return k(i,r.Project)?n.create(void 0,new eg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Gm)||!(r.declaration instanceof R)?n.create(e):new tg(t,r.declaration,i).interpret()}},rg=class{constructor(e,t){this.compiler=e,this.declarationNode=t,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof H&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof L?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=dp(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=ip(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=fp(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new E(T.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new E(T.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new E(T.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,e))),this.boundColumns.set(r,e)}return c}bindInsideTableName(e){let n=this.declarationNode.parent;if(!(n instanceof R)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!If(e))return[];let i=ip(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=fp(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new E(T.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n));continue}}return a}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof V),n=e.body.filter(e=>e instanceof R);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof _m?e.callee.elementList:[e.callee]).flatMap(Nm).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():[])}},ig=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=ag(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=og(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=P(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 ag(e,n,i){let a=e.name,o=e.parent;if(o instanceof R&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Wp))return;let r=e.mergedColumns(n),s=e.interpretedName(n,i),c=s.schema,l=s.name;return a?{schemaName:c,tableName:l,columns:a.elementList.flatMap(e=>r.find(t=>t.name===N(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=dp(a);if(!s)return;let c=s.variables.map(e=>e.expression.variable?.value??``),l=c.at(-1)??``,u=c.length>1?c.slice(0,-1).join(`.`):void 0,d=n.parseFile(e.filepath).getValue().ast,f=n.nodeSymbol(d).getFiltered(t);if(!f)return;let p;if(u){let e=n.lookupMembers(f,F.Schema,u);e&&(p=n.lookupMembers(e,F.Table,l))}if(p||=n.lookupMembers(f,F.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Wp))return;let ee=m.mergedColumns(n),te=s.args.map(e=>ee.find(t=>t.name===N(e))).filter(Boolean),ne=m.interpretedName(n,i);return{schemaName:ne.schema,tableName:ne.name,columns:te}}function og(e,t,r){let i=[],a=[],o={},s=e.callee instanceof _m?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new E(T.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=cg(n,l,r);i.push(...u.getErrors()),a.push(...u.getWarnings());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:P(n)})}return new n({row:c,columnNodes:o},i,a)}function sg(e){return e instanceof hm&&e.value?.value||``}function cg(e,t,r){let i=P(e),a=t.type(r),o=(a?.name??``).split(`(`)[0],s=!!a?.enumSymbol,c=t.increment(r),l=t.isNotNullSet(r)===!0,u=t.default(r),d=t.name??``,f=Uo(o,s),p=Cp(e),m=p===null?sg(e):p,ee=p===null?`expression`:f;if(e instanceof hm)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(pp(e)||mp(e)&&!zo(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Ho(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[new yf(T.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(F.EnumField)).map(e=>e.name).filter(Boolean):[],s=M(e);return s===void 0&&(s=D(e)?e.expression.variable.value:void 0),o.includes(s)?new n({value:s,type:f,token:i},[],[]):new n({value:s,type:f,token:i},[],[new yf(T.INVALID_RECORDS_FIELD,`Invalid enum value for column '${d}'`,e)])}if(Fo(o)||Io(o)||Ho(o)){let t=gp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[new yf(T.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${d}'`,e)]);if(Fo(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[new yf(T.INVALID_RECORDS_FIELD,`Invalid integer value ${t} for column '${d}': expected integer, got decimal`,e)]);let r=Io(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Io(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 yf(T.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 yf(T.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(Ro(o)){let t=xp(e);return t===null?new n({value:m,type:ee,token:i},[],[new yf(T.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${d}'`,e)]):new n({value:t,type:f,token:i},[],[])}if(Vo(o)){let t=Dp(e);return t===null?new n({value:m,type:ee,token:i},[],[new yf(T.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(zo(o)){let t=Cp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[new yf(T.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 yf(T.INVALID_RECORDS_FIELD,`String value for column '${d}' exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e)])}return new n({value:t,type:`string`,token:i},[],[])}return new n({value:m,type:ee,token:i},[],[])}var lg={nodeMetadata(t,i){if(!k(i,r.Records))return n.create(e);let a=i.parent;if(a&&k(a,r.Table))return n.create(new Um(i));let o=i.name;return o instanceof W&&o.callee?n.create(new Um(i)):n.create(e)},nodeReferee(i,a){if(!D(a))return n.create(e);let o=a.parentOfKind(R);if(!o?.isKind(r.Records))return n.create(e);let s=i.parseFile(a.filepath).getValue().ast,c=i.nodeSymbol(s).getFiltered(t);if(!c)return n.create(void 0);let l=a.parentOfKind(gm);if(l?.parentNode===o)return ug(i,o,a);let u=a.parentOfKind(W);return u?.parentNode===o&&l?.parentNode===u?dg(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?fg(i,c,a):mg(i,c,a)},bindNode(t,i){return k(i,r.Records)?n.create(void 0,new rg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Um?r.declaration instanceof R?new ig(t,r,i).interpret():n.create(void 0):n.create(e)}};function ug(e,i,a){let o=i.parent;if(o instanceof R&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return pg(e,n,a)}return new n(void 0)}function dg(e,r,i){if(r.callee){let n;if(D(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=sp(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return pg(e,n,i)}return new n(void 0)}function fg(e,t,r){if(!D(r))return new n(void 0);let i=fp(r)??``;if(!O(r.parentNode)){let a=e.lookupMembers(t,[F.Table,F.Schema],i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Pm(e,r);if(!a){let a=e.lookupMembers(t,[F.Table,F.Schema],i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Table,F.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function pg(e,t,r){if(!D(r))return new n(void 0);let i=fp(r)??``,a=e.lookupMembers(t,F.Column,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function mg(e,t,r){if(!D(r))return new n(void 0);let i=fp(r)??``;if(!O(r.parentNode))return new n(void 0);let a=Pm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var hg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Nm).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():[])}},gg=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()],{infos:t}=this.validateRefConstraints();return n.create(this.ref,e,void 0,t)}interpretName(){if(!(this.declarationNode instanceof R))return[];let e=[],t=j(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new E(T.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if(La(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new E(T.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=lf(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=P(this.metadata.leftToken()),l=P(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof R?[{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c},{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l}]:[{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l},{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c}],!(this.declarationNode instanceof R))return[];let u=op(this.declarationNode)[0];if(u.args[0]){let e=zf(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof fm?rp(t):N(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof fm?rp(n):N(n),this.ref.color=e.color?.length?Mp(e.color?.at(0)?.value):void 0,this.ref.inactive=e.inactive?.length?!0:void 0}return[]}validateRefConstraints(){return this.metadata.cardinalities(this.compiler)?{infos:[...Gh(this.compiler,this.metadata,`right`),...Gh(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function _g(e){let t=e.parent;for(;t;){if(t instanceof R&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var vg={nodeReferee(r,i){if(!D(i)&&!O(i)||!_g(i)||i.parentOfKind(z))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):yg(r,o,i)},nodeMetadata(t,a){if(k(a,r.Ref)){let t=op(a)[0];if(!(t instanceof V)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof pm)||!r.op?n.create(e):n.create(new zm(a))}if(a instanceof z){if(!(a.name instanceof fm)||rp(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof R&&t.isKind(r.TablePartial)?n.create(new Bm(a)):n.create(new zm(a))}return n.create(e)},bindNode(t,i){return k(i,r.Ref)?n.create(void 0,new hg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof zm?new gg(t,r,i).interpret():n.create(e)}};function yg(e,r,i){if(!D(i))return new n(void 0);let a=fp(i)??``;if(!O(i.parentNode)){let r=i.parentNode;if(r&&O(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=O(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(F.Table)){let r=e.lookupMembers(c,F.Column,a);if(r)return n.create(r);let o=c.declaration?e.nodeFullname(c.declaration).getFiltered(t)?.join(`.`)??c.name:c.name;return new n(void 0,[new E(T.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Pm(e,i);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(F.Table)){let r=e.lookupMembers(o,F.Column,a);return r?n.create(r):new n(void 0,[new E(T.BINDING_ERROR,`Column '${a}' does not exist in Table '${o.declaration?e.nodeFullname(o.declaration).getFiltered(t)?.join(`.`)??o.name:o.name}'`,i)])}return new n(void 0)}let s=i.parentNode;if(s.leftExpression===i){if(O(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,F.Schema,a);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Fm(e,r);if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,F.Table,a);return o?n.create(o):new n(void 0,[new E(T.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var bg={visibleName(e,n){let r=n instanceof I?n:n.useSpecifierDeclaration instanceof um?n.useSpecifierDeclaration:n.declaration;if(r instanceof um&&n instanceof Bp&&r.getSymbolKind()!==n.kind&&(r=n.declaration),!r)return;let i=e.nodeAlias(r).getFiltered(t);return i===void 0?e.nodeFullname(r).getFiltered(t):[i]}},xg={nodeSymbol(r,i){if(!Gf(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===F.Schema)return n.create(e);let o=r.nodeReferee(i.name).getFiltered(t);return o&&!o.canBeImported?n.create(e):n.create(r.symbolFactory.create(am,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:bg.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new E(T.BINDING_ERROR,`Failed to resolve the import of ${a} '${(j(i.name)||[]).map(Zg).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof am))return n.create(e);if(i.originalSymbol===i)return n.create([]);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!D(i)&&!Uf(i))return n.create(e);let a=i.parentOfKind(um);if(!a)return n.create(e);let o=a.name===i||O(a.name)&&a.name.rightExpression===i?a.getSymbolKind():F.Schema;if(o===void 0)return n.create(void 0);let s=j(i.parentOfKind(pm)),c=N(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(lm);if(l?.importPath?.value===void 0)return n.create(void 0);let u=xo(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new E(T.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new E(T.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toString()}. Does the file exist?`,i)]);let d=i.parentOfKind(pm)?.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 E(T.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=Sg(r,u,c,o);return f?n.create(f):n.create(void 0,[new E(T.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toString()}`,i)])},bindNode(t,r){if(Wf(r)){let e=[];if(r.importPath?.value){let n=xo(r.filepath,r.importPath.value);n?t.layout.exists(n)||e.push(new E(T.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath)):e.push(new E(T.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 dm?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):Gf(r)?r.name?new n(void 0,t.nodeReferee(r.name).getErrors()):new n(void 0):n.create(e)},interpretSymbol(r,i,a){if(!(i instanceof am))return n.create(e);if(!i.usedSymbol)return n.create(void 0);let o=r.interpretSymbol(i.usedSymbol,a);if(o.hasValue(t))return n.create(void 0);let s=o.getValue();if(!s||Array.isArray(s))return o;let c=i.name;return c&&`name`in s?n.create({...s,name:c}):n.create(s)}};function Sg(e,n,r,i,a=new Set){if(!n||a.has(n.intern()))return;a.add(n.intern());let o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.nonSchemaMembers.find(e=>e.name===r&&e.isKind(i));if(s)return s;let c=o.schemaMembers.find(e=>e.name===r);if(c?.isKind(F.Schema))return c;for(let t of o.reuses.selective)if(j(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(lm);if(o?.importPath?.value){let s=Sg(e,xo(n,o.importPath.value),j(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=Sg(e,t,r,i,a);if(n)return n}}function Cg(e){if(e instanceof bo){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=Tg(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof rm?Eg(this,e,i):Dg(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 wg(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof um?bg.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof um&&r.getSymbolKind()===F.Schema?a:a.length<=1?[y]:a.slice(0,-1);return o.length<i.length||!i.every((e,t)=>e===o[t])?{kind:`none`}:o.length===i.length?{kind:`direct`}:{kind:`child`,schemaName:o[i.length]}}function Tg(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof lm)||!e.specifiers||!e.importPath)continue;let n=xo(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof bm?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof bm?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 Eg(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[y,e.symbolFactory.create(Vp,{name:y},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?y:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Vp,{name:i},s))}Og(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of Ag(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Vp,{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 Dg(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof R))continue;let i=wg(e,n,r),a=e.nodeAlias(r).getFiltered(t),o=e.nodeSymbol(r).getFiltered(t);if(a!==void 0&&n.isPublicSchema()&&o&&s.push(e.symbolFactory.create(im,{kind:o.kind,declaration:r,aliasedSymbol:o,name:a},n.filepath)),i.kind!==`none`)if(i.kind===`direct`){let n=e.nodeSymbol(r).getFiltered(t);if(!n)continue;s.push(n)}else c.has(i.schemaName)||c.set(i.schemaName,e.symbolFactory.create(Vp,{name:i.schemaName,parent:n},n.filepath))}kg(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of jg(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Vp,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function Og(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==F.Schema)continue;let t=bg.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Vp,{name:t},r))}}function kg(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==F.Schema)continue;let t=bg.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(Vp,{name:o,parent:n},n.filepath))}}function Ag(e,n){let{ast:r}=e.parseFile(n).getValue(),i=[];for(let n of r.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],a=r.length<=1?y:r[0];i.push(a)}let a=Tg(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==F.Schema)continue;let n=bg.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function jg(e,n,r){let{ast:i}=e.parseFile(n).getValue(),a=[];for(let n of i.declarations){let i=e.nodeFullname(n).getFiltered(t)||[],o=i.length<=1?[y]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=Tg(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==F.Schema)continue;let n=bg.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var Mg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return(e=>e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(g(n)instanceof U){let e=zf(g(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!kf(e.callee)))}tryToBindColumnType(e){let t=cp(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(Bf(e))return[];if(D(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&So.includes(t))return[]}let t=cp(e);if(!t){if(O(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return Nm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}};function Ng(e){let t=e.targetKind?.value?.toLowerCase();return Object.values(Rp).find(e=>e.toLowerCase()===t)}function Pg(e,t,n){let r=[];return t.length>1&&r.push(...t.map(t=>new E(n.duplicate,`'${e}' can only appear once`,t))),t.forEach(t=>{Rf(t.value)||r.push(new E(n.invalidValue,`Custom setting '${e}' must be a string or a color literal`,t.value||t.name||t))}),r}function Fg(e,t,n){if(!n.length)return;let{name:r,symbolKind:i}=n[0],a=e.lookupMembers(t,i,r);return n.length>1&&a?Fg(e,a,n.slice(1)):a}function Ig(e,t){if(e.length===0)return[];let n;switch(t){case Rp.Table:n=[...Array(e.length-1).fill(F.Schema),F.Table];break;case Rp.Column:n=e.length===1?[F.Column]:[...Array(e.length-2).fill(F.Schema),F.Table,F.Column];break;case Rp.TableGroup:n=[...Array(e.length-1).fill(F.Schema),F.TableGroup];break;case Rp.Note:n=[...Array(e.length-1).fill(F.Schema),F.StickyNote];break;default:break}return e.map((e,t)=>({name:e,symbolKind:n[t]}))}function Lg(e,t){let n=Im(e,t.filepath);if(!n)return;let r=Ng(t),i=j(t.name);if(!i?.length||!r)return;let a=Ig(i,r),{name:o,symbolKind:s}=a[0];if(o===`public`&&s===F.Schema){let t=Fm(e,n);if(t)return Fg(e,t,a.slice(1))}return Fg(e,n,a)}function Rg(e,t){let n=[],r=new Set,i=t=>{let a=t.intern();if(!r.has(a)){r.add(a);for(let n of e.fileDependencies(t))i(n);n.push(t)}};i(t);let a=new Map;return n.forEach((e,t)=>a.set(e.intern(),t)),a}function zg(e,n,r,i,a){let o=Im(e,a);if(!o)return;let s=e.symbolMetadata(r).filter(t=>t.owners(e).includes(o));if(!s.length)return;let c=Rg(e,a),l=[...s].sort((e,t)=>{let n=c.get(e.declaration.filepath.intern())??-1,r=c.get(t.declaration.filepath.intern())??-1;return n===r?e.declaration.start-t.declaration.start:n-r}).map(n=>e.interpretMetadata(n,a).getFiltered(t)).filter(e=>!!e);if(!l.length)return;let u={};for(let e of l)for(let[t,{value:n,token:r}]of Object.entries(e))u[t.toLowerCase()]={originalKey:t,value:n,token:r};let d=n.metadata?Object.fromEntries(Object.entries(n.metadata).map(([e,t])=>[e.toLowerCase(),{originalKey:e,value:t}])):{};Object.entries(u).forEach(([e,t])=>{let{originalKey:r,value:a,token:o}=t;i[e]?i[e].assignBuiltinField(n,a,o):d[e]={originalKey:r,value:a}}),n.metadata=Object.fromEntries(Object.values(d).map(e=>[e.originalKey,e.value]))}var Bg=class{constructor(e,t,n,r){this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=this.symbol?.token??P(this.declarationNode);let e=[];if(this.symbol){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);this.table.name=e,this.table.schemaName=t}else e.push(...this.interpretName(this.declarationNode.name));let t=[...e,...this.interpretAlias(this.declarationNode.alias),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.table.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),this.attachTableAndColumnMetadata(),n.create(this.table,t)}attachTableAndColumnMetadata(){if(!this.symbol)return;zg(this.compiler,this.table,this.symbol,Hg,this.filepath);let e=this.compiler.symbolMembers(this.symbol).getFiltered(t)??[];for(let t of e){if(!t.isKind(F.Column))continue;let e=this.table.fields.find(e=>e.name===t.name);e&&zg(this.compiler,e,t,Ug,this.filepath)}}interpretName(e){let{name:t,schemaName:n}=jp(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new E(T.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=fp(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=zf(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Mp(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Ap(M(n?.value)),token:P(n)},this.table.metadata=Fp(t,Object.keys(Hg)),[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:Ap(M(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:P(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);case r.Records:return[];default:return[]}})}interpretInjection(e,n){let r=[],i={order:n,token:P(e)};i.name=N(e.expression)||``;let a=e.expression?this.compiler.nodeReferee(e.expression).getFiltered(t):void 0,o=this.compiler.parseFile(this.filepath).getValue().ast,s=this.compiler.nodeSymbol(o).getFiltered(t);if(a&&!s.inNestedSchema(this.compiler,a)){let n=this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),o=n?(this.compiler.symbolUses(n).getFiltered(t)??[]).find(e=>e.filepath.equals(this.filepath)):void 0;r.push(new E(T.UNSUPPORTED,`TablePartial ${i.name} from '${a.filepath}' should be imported. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,o?.useSpecifierDeclaration??e))}return this.table.partials.push(i),r}interpretFields(e){let n=this.symbol??this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),r=(n?this.compiler.symbolMembers(n).getFiltered(t)??[]:[]).filter(e=>e.isKind(F.Column)).length?[]:[new E(T.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>kf(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=fp(e.callee),r.token=P(e);let o=Pp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||!1,r.unique=a?.isUniqueSet(this.compiler)||!1,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{};r.metadata=Fp(s,Vg);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.endpoints?.[0])return[];let s=o.endpoints[0],c=r.op(this.compiler);return c?{schemaName:s.schemaName,tableName:s.tableName,fieldNames:s.fieldNames,relation:c,token:s.token}:[]}),r.checks=(s[i.Check]||[]).map(e=>({token:P(e),expression:e.value.value.value})),this.table.fields.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.indexes.push(...i):i&&this.table.indexes.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.checks.push(...i):i&&this.table.checks.push(i),r.getErrors()}},Vg=[i.Note,i.Ref,i.PrimaryKey,i.PK,i.NotNull,i.Null,i.Unique,i.Increment,i.Default,i.Check],Hg={[i.Note]:{isValidBuiltinFieldValue:Bf,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.HeaderColor]:{isValidBuiltinFieldValue:jf,message:`'headercolor' must be a color literal`,assignBuiltinField(e,t){e.headerColor=t}}},Ug={[i.Note]:{isValidBuiltinFieldValue:Bf,message:`'note' must be a quoted string`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}}},Wg={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new E(T.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new E(T.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},Gg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.Table)?new n(i.symbolFactory.create(Wp,{declaration:a,name:o},a.filepath)):A(a,r.Table)?kf(a.callee)?new n(i.symbolFactory.create(Xp,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Gp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(F.Table))return n.create(e);let a=i.declaration;if(!(a instanceof R))return new n([]);let o=op(a),s=[],c=[];for(let e of o){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(s.push(i),c.push(...n.getErrors()))}let l=new Map;for(let e of s){if(!e.isKind(F.Column,F.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(F.Column)?(c.push(Wg.getColumnDuplicateError(e.name,r)),c.push(Wg.getColumnDuplicateError(e.name,n))):(c.push(Wg.getPartialInjectionDuplicateError(e.name,r)),c.push(Wg.getPartialInjectionDuplicateError(e.name,n))):l.set(t,n)}}let u=[];for(let e=0;e<s.length;e++){let n=s[e];if(!(n.declaration instanceof V)||!kf(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=N(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new E(T.BINDING_ERROR,`TablePartial '${o}' does not exist in Schema 'public'`,i||a));continue}let d=r.symbolMembers(l).getFiltered(t);if(d){let t=d.flatMap(e=>{if(!e.declaration)return[];let t=e.name;return t===void 0?e:r.symbolFactory.create(om,{kind:F.Column,injectionDeclaration:n.declaration,declaration:e.declaration,name:t},a.filepath)});u.push({index:e,partialMembers:t})}}for(let e=u.length-1;e>=0;e--){let{index:t,partialMembers:n}=u[e];s.splice(t,0,...n)}let d=new Set(s.filter(e=>e.isKind(F.Column)&&!(e instanceof om)).map(e=>e.name));return new n(Pa([...s.filter(e=>!(e instanceof om&&d.has(e.name)))].reverse(),e=>e.isKind(F.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(!qf(o,r.Table))return n.create(e);let s=a.parseFile(o.filepath).getValue().ast,c=a.nodeSymbol(s).getValue();return c===t?n.create(void 0):D(o)&&o.parentNode instanceof B&&o.parentNode.op?.value===`~`?Kg(a,c,o):Jf(o,1)?qg(a,c,o):Xf(o,i.Ref)?Jg(a,c,o):Jf(o,0)?n.create(e):Yg(a,c,o)},bindNode(i,a){if(!k(a,r.Table))return n.create(e);let o=new Mg(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 Wp?r.declaration instanceof R?new Bg(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function Kg(e,r,i){let a=N(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Vp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,F.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,F.TablePartial,a);return s?n.create(s):new n(void 0,[new E(T.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function qg(e,t,r){if(!D(r))return new n(void 0);let i=fp(r)??``;if(!O(r.parentNode))return n.create(e.lookupMembers(t,F.Enum,i));let a=Pm(e,r);if(a){if(a.isKind(F.Schema)){let t=tp(r),o=e.lookupMembers(a,t?F.Enum:F.Schema,i);return o?n.create(o):new n(void 0,[new E(T.BINDING_ERROR,t?`Enum '${i}' does not exist in Schema 'public'`:`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Jg(e,i,a){if(!D(a))return new n(void 0);let o=fp(a)??``;if(!O(a.parentNode)){let s=a.parent,c=s instanceof R&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,F.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,F.Column,o);return l?n.create(l):new n(void 0,[new E(T.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}let s=Pm(e,a);if(s){if(s.isKind(F.Schema)){let t=e.lookupMembers(s,[F.Table,F.Schema],o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(F.Table)){let t=e.lookupMembers(s,F.Column,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${s.name}'`,a)])}return new n(void 0)}let c=a.parentNode;if(c.leftExpression===a){if(O(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,F.Schema,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,F.Table,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function Yg(e,t,r){if(!D(r))return new n(void 0);let i=fp(r)??``;if(!O(r.parentNode))return So.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,F.Enum,i));let a=Pm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Xg(e){return e?e.split(``).every(e=>xf(e)||Sf(e))&&!Sf(e[0]):!1}function Zg(e){return Xg(e)?e:`"${$g(e)}"`}function Qg(e){let t=``,n=0,r={n:`
|
|
5
|
+
`,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function $g(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 e_(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`'${$g(e)}'`;let{value:t,type:n}=e;if(t==null||Ro(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(Ro(n)){let e=xp(t);return e===null?`\`${t}\``:e?`true`:`false`}if(Lo(n)){let e=_p(t);return e===null?`\`${t}\``:String(e)}if(Vo(n)){let e=Dp(t);return e===null?`\`${t}\``:`'${$g(e)}'`}let r=Cp(t);return r===null?`\`${t}\``:`'${$g(r)}'`}function t_(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?Qg(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function n_(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 r_(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 Vp&&n.isKind(F.Schema)){let o=e.symbolMembers(n);i.push(...o.getErrors()),a.push(...o.getWarnings()),r.push(...o.getFiltered(t)??[])}}return new n(r,i,a)}var i_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Nm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof am?[...r.getErrors(),new E(T.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():[])}},a_={[i.Note]:{isValidBuiltinFieldValue:Bf,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.Color]:{isValidBuiltinFieldValue:jf,message:`'color' must be a color literal`,assignBuiltinField(e,t){e.color=t}}},o_=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=P(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),zg(this.compiler,this.tableGroup,this.symbol,a_,this.filepath),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=jp(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new E(T.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name))),this.tableGroup.name=n,this.tableGroup.schemaName=r[0]||null,t}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:Ap(M(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:P(e)};break;default:break}return[]})}interpretFields(e){let n=[];return this.tableGroup.tables=e.map(e=>{let r=e.callee?this.compiler.nodeReferee(e.callee).getFiltered(t):void 0;if(r?.isKind(F.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=j(e.callee);return i.length>2&&n.push(new E(T.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=zf(e).getValue();this.tableGroup.color=t.color?.length?Mp(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Ap(M(n?.value)),token:P(n)},this.tableGroup.metadata=Fp(t,Object.keys(a_)),[]}},s_={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new E(T.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},c_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return k(a,r.TableGroup)?new n(i.symbolFactory.create(Kp,{declaration:a,name:s},a.filepath)):A(a,r.TableGroup)?new n(i.symbolFactory.create(qp,{declaration:a,name:o?.map(Zg).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(F.TableGroup)){let e=i.declaration;if(!(e instanceof R))return new n([]);let a=op(e),o=[],s=[];for(let e of a){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(o.push(i),s.push(...n.getErrors()))}let c=new Map;for(let e of o){if(!e.isKind(F.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(s_.getFieldDuplicateError(e.name,r)),s.push(s_.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(F.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!D(a)||!qf(a,r.TableGroup)||a.parent&&Yf(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):l_(i,s,a)},bindNode(i,a){if(!k(a,r.TableGroup))return n.create(e);let o=new i_(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,i,a){let o=i.declaration;return!k(o,r.TableGroup)||!(i instanceof Kp)?n.create(e):Mm(t,o)?new o_(t,i,a).interpret():n.create(void 0)}};function l_(e,r,i){let a=fp(i)??``;if(!O(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Vp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,F.Table,a);return s?n.create(s):new n(void 0,[new E(T.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Pm(e,i);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,F.Schema,a);return s?n.create(s):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var u_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(g(n)instanceof U){let e=zf(g(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t})}tryToBindColumnType(e){let t=cp(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return Nm(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():[])}},d_=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=this.symbol?.token??P(this.declarationNode),this.symbol?this.tablePartial.name=this.symbol.interpretedName(this.compiler,this.filepath).name:this.interpretName(this.declarationNode.name);let e=[...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.tablePartial.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),pk:!0,token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath}}),this.pkColumns.forEach(e=>{e.pk=!1})),new n(this.tablePartial,e)}interpretName(e){let{name:t}=jp(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=zf(e).getValue(),n=va(t[i.HeaderColor]);this.tablePartial.headerColor=n?Mp(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Ap(M(r?.value)),token:P(r)},[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:Ap(M(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:P(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let n=[],r={},a=this.compiler.nodeSymbol(e).getFiltered(t);r.name=fp(e.callee)??``,r.token=P(e);let o=Pp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||void 0,r.unique=a?.isUniqueSet(this.compiler)||void 0,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{};r.metadata=Fp(s,Vg);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!(n instanceof Bm))return[];let r=n.owners(this.compiler);if(l&&r.length>0&&!r.some(e=>e===l))return[];let i=n.op(this.compiler);if(!i)return[];let a=n.rightTable(this.compiler),o=n.rightColumns(this.compiler);if(!a||o.length===0)return[];let s=a.interpretedName(this.compiler,this.filepath);return{schemaName:s.schema,tableName:s.name,fieldNames:o.map(e=>e.name??``),relation:i,token:P(n.rightToken())}}),r.checks=(s[i.Check]||[]).map(e=>({token:P(e),expression:e.value.value.value})),this.tablePartial.fields?.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.indexes?.push(...i):i&&this.tablePartial.indexes?.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.checks?.push(...i):i&&this.tablePartial.checks?.push(i),r.getErrors()}},f_={getDuplicateError(e,t,n){return new E(T.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},p_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.TablePartial)?new n(i.symbolFactory.create(Yp,{declaration:a,name:o},a.filepath)):A(a,r.TablePartial)?new n(i.symbolFactory.create(Gp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(F.TablePartial)){let e=a.declaration;if(!(e instanceof R))return new n([]);let r=op(e),o=[],s=[];for(let e of r){let n=i.nodeSymbol(e),r=n.getFiltered(t);r&&(o.push(r),s.push(...n.getErrors()))}let c=new Map;for(let e of o){if(!e.isKind(F.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Wg.getColumnDuplicateError(t,r)),s.push(Wg.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(F.Column)&&k(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!D(o)&&!O(o)||!qf(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):Jf(o,1)?m_(a,c,o):Xf(o,i.Ref)?h_(a,c,o):g_(a,c,o)},bindNode(i,a){if(!k(a,r.TablePartial))return n.create(e);let o=new u_(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Yp?r.declaration instanceof R?new d_(t,r,i).interpret():n.create(void 0):n.create(e)}};function m_(e,t,r){if(!D(r))return new n(void 0);let i=fp(r)??``;if(!O(r.parentNode))return n.create(e.lookupMembers(t,F.Enum,i));let a=Pm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function h_(e,i,a){if(!D(a))return new n(void 0);let o=fp(a)??``;if(!O(a.parentNode)){let s=a.parent;if(s instanceof R&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,F.Column,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,F.Column,o);return c?n.create(c):new n(void 0,[new E(T.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Pm(e,a);if(s){if(s.isKind(F.Schema)){let t=e.lookupMembers(s,[F.Table,F.Schema],o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(F.Table)){let t=e.lookupMembers(s,F.Column,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${s.name}'`,a)])}return new n(void 0)}let c=a.parentNode;if(c.leftExpression===a){if(O(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,F.Schema,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,F.Table,o);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function g_(e,t,r){if(!D(r))return new n(void 0);let i=fp(r)??``;if(!O(r.parentNode))return So.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,F.Enum,i));let a=Pm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new E(T.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new E(T.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var __={symbolMembers(r,i){if(!i.isKind(F.Schema)||!(i instanceof Vp))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=y_(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...b_(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...S_(r,i,e,t,c));for(let e of o.uses.selective){let n=y_(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...b_(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...S_(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(F.TableGroup));if(!i.isPublicSchema()){let n=r.usableMembers(i.filepath).getFiltered(t)?.schemaMembers.find(e=>e.isPublicSchema());if(n){let i=r.symbolMembers(n).getFiltered(t);i&&e.push(...i.filter(e=>e.isKind(F.TableGroup)))}}for(let t of e)u.push(...w_(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof am&&e.isKind(F.Schema))return!1;let t=`${e.originalSymbol.intern()}:${e.name??``}`;return d.has(t)?!1:(d.add(t),!0)}),p=new Map;for(let e of f){let t=`${e.kind}:${e.name}`;if(p.get(t)){if(e.isKind(F.Schema))continue;let t=e instanceof am?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(v_(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function v_(e,t,n,r){switch(e){case F.Table:return Wg.getDuplicateError(t,n,r);case F.Enum:return lh.getDuplicateError(t,n,r);case F.TablePartial:return f_.getDuplicateError(t,n,r);case F.TableGroup:return s_.getDuplicateError(t,n,r);case F.DiagramView:return th.getDuplicateError(t,n,r);default:return new E(T.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function y_(e,r,i,a){let o=wg(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(Vp,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function b_(e,n,r,i=new Set){if(r.getSymbolKind()!==F.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(F.Schema))return[];let o=bg.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:x_(e,n,r,a,i)}function x_(e,n,r,i,a){let o=i.intern();if(a.has(o))return[];a.add(o);let s=e.usableMembers(i).getFiltered(t);if(!s)return[];let c=s.nonSchemaMembers.filter(e=>e.canBeImported).map(t=>e.symbolFactory.create(am,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(F.TableGroup)&&c.push(...w_(e,n,t));for(let i of s.reuses.selective)if(c.push(...b_(e,n,i,a)),wg(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(am,{kind:a.kind,declaration:a.originalSymbol.declaration,usedSymbol:a.originalSymbol,useSpecifierDeclaration:r,name:a.name},n.filepath))}for(let{importPath:t}of s.reuses.wildcard){let i=C_(e,t,n.qualifiedName);i&&c.push(...x_(e,n,r,i,a))}return c}function S_(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=C_(e,r,n.qualifiedName);if(!s)return[];let c=e.usableMembers(s).getFiltered(t);if(!c)return[];let l=c.nonSchemaMembers.filter(e=>e.canBeImported).map(t=>e.symbolFactory.create(am,{kind:t.kind,declaration:t.declaration,usedSymbol:t,useSpecifierDeclaration:i,name:t.name},n.filepath));for(let t of c.schemaMembers)a.has(t.name)||a.set(t.name,e.symbolFactory.create(Vp,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=y_(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...b_(e,n,r))}for(let{importPath:t}of d)l.push(...S_(e,n,t,i,a,o));return l}function C_(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 w_(e,n,r){if(!r.isKind(F.TableGroup)||!(r instanceof am))return[];let i=r.originalSymbol,a=e.symbolMembers(i).getFiltered(t);if(!a)return[];let o=n.qualifiedName,s=[];for(let t of a){if(!t.isKind(F.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=j(n);if(!i||i.length===0)continue;let a=i.length<=1?[y]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=T_(e,c,i);l&&s.push(e.symbolFactory.create(am,{kind:F.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function T_(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(F.Table)&&e.name===r[0]):void 0}let i=r[0],a=r[r.length-1],o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.schemaMembers.find(e=>e.name===i);if(!s)return;let c=e.usableMembers(s).getFiltered(t);if(c)return c.nonSchemaMembers.find(e=>e.isKind(F.Table)&&e.name===a)}var E_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof V)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},D_={[i.Color]:{isValidBuiltinFieldValue:Mf,message:`'color' must be a color literal or 'none'`,assignBuiltinField(e,t){e.color=t}}},O_=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){this.note.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return zg(this.compiler,this.note,this.symbol,D_,this.filepath),n.create(this.note,e)}interpretName(){let{name:e}=this.symbol.interpretedName(this.compiler,this.filepath);return this.note.name=e,[]}interpretSettingList(e){let t=zf(e).getValue();return t.color?.length&&(this.note.color=Mp(t.color.at(0)?.value)),this.note.metadata=Fp(t,Object.keys(D_)),[]}interpretBody(e){let[t,n]=_(e.body,e=>e instanceof V);return t.length!==1||n.length>0?[new E(T.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=M(e.callee)??``;return this.note.content=Ap(t),[]}},k_={nodeSymbol(i,a){return!k(a,r.Note)||!(a.parentNode instanceof L)?n.create(e):new n(i.symbolFactory.create(Jp,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(F.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return k(i,r.Note)?n.create(void 0,new E_(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Jp?r.declaration instanceof R?new O_(t,r,i).interpret():n.create(void 0):n.create(e)}},A_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[...this.bindTargetElement(this.declarationNode.name),...this.bindBody(this.declarationNode.body)]}bindTargetElement(e){let t=Ng(this.declarationNode);return!j(e)?.length||!t||Lg(this.compiler,this.declarationNode)?[]:[new E(T.BINDING_ERROR,`cannot find metadata target element`,e??this.declarationNode)]}bindBody(e){return e instanceof H?e.body.filter(e=>e instanceof R).flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[]):[]}},j_=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.filepath=n,this.values={}}interpret(){let e=this.interpretValues(this.declarationNode.body);return new n(this.values,e)}interpretValues(e){if(!(e instanceof H))return[];for(let t of e.body){if(!(t instanceof R))continue;let e=t.type?.value;if(!e)continue;let n=Ip(t.body instanceof V?t.body.callee:void 0);n&&(this.values[e]={value:e===`note`?Ap(n):n,token:P(t)})}return[]}},M_=[xg,Gg,uh,lg,ph,Xm,vg,ng,c_,p_,k_,{nodeMetadata(t,i){return k(i,r.Metadata)?new n(new Wm(i)):new n(e)},nodeReferee(t,i){if(!D(i))return new n(e);let a=i.parentOfKind(R);return!a||!k(a,r.Metadata)||!a.name?.containsEq(i)?new n(e):!j(a.name)||!Ng(a)?new n(void 0):new n(Lg(t,a))},bindNode(t,i){return k(i,r.Metadata)?new n(void 0,new A_(t,i).bind()):new n(e)},interpretMetadata(t,i,a){return i instanceof Wm?k(i.declaration,r.Metadata)?new j_(t,i,a).interpret():new n(void 0):new n(e)}},__,nh,$h];function N_(t,...r){for(let i of M_){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function P_(r){let i=N_(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function F_(r){let i=N_(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function I_(r){let i=N_(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function L_(r){let i=N_(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function R_(r){let i=N_(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function z_(r,i){let a=N_(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function B_(r,i){let a=N_(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var V_=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 E(T.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return g(n)instanceof U&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof hm))&&t.push(new E(T.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=zf(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 E(T.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Bf(t.value)||n.push(new E(T.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},H_={validateNode(t,i){if(!k(i,r.Checks))return n.create(e);let a=new V_(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return k(i,r.Checks)?i.name?new n(void 0,[new E(T.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Checks)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Checks)?i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},U_=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Project)?[]:[new E(T.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new E(T.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return Bf(e.callee)||t.push(new E(T.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 E(T.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function W_(e){return e instanceof R&&!!e.type?.value}var G_={validateNode(t,r){if(!W_(r))return n.create(e);let i=new U_(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return W_(r)?r.name?new n(void 0,[new E(T.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return W_(r)?r.alias?new n(void 0,[new E(T.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return W_(r)?r.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},K_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList)],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof R?[new E(T.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Df(e)?[]:[new E(T.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new E(T.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=zf(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new E(T.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof V)return{errors:[new E(T.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=_(e.body,e=>e instanceof V),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Vf(e.callee)?e.args.length>0?e.args.map(e=>new E(T.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new E(T.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 E(T.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(Of(e))return t.push(new E(T.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof H))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof V&&Vf(e.callee)),a=r.body.some(e=>e instanceof V&&!Vf(e.callee));return i&&a&&n.push(new yf(T.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t.push(...this.validateSubBlockFields(e)),{errors:t,warnings:n}}validateSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof H))return t;let n=e.body.body.filter(e=>e instanceof V);for(let e of n)Vf(e.callee)||(e.args.length>0||!j(e.callee))&&t.push(...e.args.map(e=>new E(T.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},q_={validateNode(t,i){if(!k(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new K_(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(k(i,r.DiagramView)){if(!i.name)return new n(void 0,[new E(T.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=j(i.name);return e?new n(e):new n(void 0)}else if(A(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=j(i.callee);return e?(e.length===1&&A(i,r.DiagramViewTables)&&e.unshift(y),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return k(i,r.DiagramView)?new n(void 0):n.create(e)}},J_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new E(T.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof bm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Tf(e)?[]:[new E(T.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new E(T.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new E(T.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!D(n.callee)&&t.push(new E(T.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];g(e)instanceof U?(t.push(...this.validateFieldSettings(g(e))),e.pop()):e[0]instanceof U&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new E(T.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=zf(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 E(T.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{Bf(e.value)||n.push(new E(T.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new E(T.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():[])}},Y_={validateNode(t,i){return k(i,r.Enum)?n.create(void 0,new J_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.Enum)){if(!i.name)return new n(void 0,[new E(T.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Tf(i.name))return new n(void 0,[new E(T.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=j(i.name);return e?.length===1&&e.unshift(y),new n(e)}if(A(i,r.Enum)){let e=N(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return k(i,r.Enum)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(k(a,r.Enum))return a.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(A(a,r.Enum)){let e=[...a.args],t;if(g(e)instanceof U?t=g(e):e[0]instanceof U&&(t=e[0]),!t)return new n({});let r=zf(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 E(T.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{Bf(e.value)||o.push(new E(T.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new E(T.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},X_=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 E(T.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return[new E(T.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return g(n)instanceof U&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof W;)e.argumentList&&lp(e.argumentList)===void 0&&t.push(new E(T.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;lp(e)===void 0&&t.push(new E(T.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=zf(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 E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Bf(t.value)||n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new E(T.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{D(e.value)||n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Z_={validateNode(t,i){return k(i,r.Indexes)?n.create(void 0,new X_(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Indexes)?i.name?new n(void 0,[new E(T.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):A(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Indexes)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(k(a,r.Indexes))return a.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(A(a,r.Indexes)){let e=[a.callee,...a.args],t;if(g(e)instanceof U&&(t=g(e)),!t)return new n({});let r=zf(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 E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Bf(t.value)||o.push(new E(T.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 E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{D(e.value)||o.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new E(T.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Q_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return!(e instanceof L)&&!(e instanceof R&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project))?[new E(T.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 E(T.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof L}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new E(T.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=zf(e),n=t.getErrors();return Sa(t.getValue(),(e,t)=>{switch(t){case i.Color:{let t=D_[i.Color];e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{t.isValidBuiltinFieldValue(e.value)||n.push(new E(T.INVALID_NOTE_SETTING_VALUE,t.message,e.value||e.name))});break}default:n.push(...Pg(t,e,{duplicate:T.DUPLICATE_NOTE_SETTING,invalidValue:T.INVALID_NOTE_SETTING_VALUE}))}}),n}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new E(T.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new E(T.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),Bf(e[0].callee)||t.push(new E(T.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 E(T.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():[])}},$_={validateNode(t,i){return k(i,r.Note)?n.create(void 0,new Q_(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!k(i,r.Note))return n.create(e);if(!(i.parent instanceof L))return i.name?new n(void 0,[new E(T.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new E(T.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof bm)return new n(void 0,[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=j(i.name);return a===void 0?new n(void 0,[new E(T.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return k(i,r.Note)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Note)?i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},ev={[Rp.Table]:Hg,[Rp.Column]:Ug,[Rp.TableGroup]:a_,[Rp.Note]:D_},tv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateTargetKind(),...this.validateTargetName(this.declarationNode.name),...this.validateBody(this.declarationNode.body)]}validateTargetKind(){return Ng(this.declarationNode)?[]:[new E(T.INVALID_METADATA_TARGET_KIND,`A Metadata target kind must be one of: ${Object.values(Rp).join(`, `)}`,this.declarationNode.targetKind??this.declarationNode)]}validateTargetName(e){return e?e instanceof bm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Metadata target's name`,e)]:Tf(e)?[]:[new E(T.INVALID_NAME,`A Metadata target's name must be of the form <schema>.<table>, <table>.<column>, <schema>.<table>.<column> or a single identifier`,e)]:[new E(T.NAME_NOT_FOUND,`A Metadata target must have a name`,this.declarationNode)]}validateBody(e){if(!e)return[];if(e instanceof V)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Metadata's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.map(e=>new E(T.INVALID_METADATA_FIELD,`A Metadata field must use the 'key: value' syntax`,e))}validateSubElements(e){let t={},n=Ng(this.declarationNode),r=e.flatMap(e=>{if(!e.type)return[];if(e.body instanceof H)return[new E(T.UNEXPECTED_COMPLEX_BODY,`A Metadata field can only have an inline value`,e.body)];let r=e.type.value.toLowerCase();t[r]||(t[r]=[]),t[r].push(e);let i=n?ev[n][r]:void 0;return i?i.isValidBuiltinFieldValue(e.body?.callee)?[]:[new E(T.INVALID_METADATA_FIELD,i.message,e)]:Rf(e.body?.callee)?[]:[new E(T.INVALID_METADATA_FIELD,`A Metadata field value must be a string or a color literal`,e.body??e)]});return r.push(...Object.values(t).flatMap(e=>e.length<=1?[]:e.map(e=>new E(T.DUPLICATE_METADATA_FIELD,`Duplicate Metadata fields are defined`,e)))),r}},nv={validateNode(t,i){return k(i,r.Metadata)?new n(void 0,new tv(t,i).validate()):new n(e)},nodeFullname(t,i){return k(i,r.Metadata)?new n(void 0):new n(e)},nodeAlias(t,i){return k(i,r.Metadata)?new n(void 0):new n(e)},nodeSettings(t,i){return k(i,r.Metadata)?new n({}):new n(e)}},rv=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)}},iv={validateNode(t,r){return Kf(r)?n.create(void 0,new rv(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Kf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Kf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Kf(r)?new n({}):n.create(e)}},av=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name).getErrors(),...this.validateAlias(this.declarationNode.alias).getErrors(),...this.validateSettingList(this.declarationNode.attributeList).getErrors(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new E(T.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Df(e)?new n(j(e)):new n(void 0,[new E(T.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 E(T.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof V)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...t.map(e=>new E(T.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():[])}},ov={validateNode(t,i){return k(i,r.Project)?n.create(void 0,new av(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Project)?i.name?Df(i.name)?new n(j(i.name)):new n(void 0,[new E(T.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):A(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Project)&&i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):A(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Project)?i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):A(i,r.Project)?new n({}):n.create(e)}},sv=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return e instanceof L||e instanceof R&&e.isKind(r.Table)?[]:[new E(T.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof bm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof L?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof W))return[new E(T.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||!Tf(e.callee))&&t.push(new E(T.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!If(e.argumentList))&&t.push(new E(T.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!If(e)?[new E(T.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateDataRow(e);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateDataRows(t),...this.validateSubElements(n)]}validateDataRows(e){return e.flatMap(e=>this.validateDataRow(e))}validateDataRow(e){let t=[];if(!e.callee||e.args.length>0)return t.push(new E(T.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof _m)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new E(T.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 E(T.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 Cm||Pf(e)||Bf(e)||e instanceof hm)return!0;if(D(e)){let t=e.expression.variable.value.toLowerCase();return So.includes(t)}if(O(e)){let t=j(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},cv={validateNode(t,i){return k(i,r.Records)?n.create(void 0,new sv(t,i).validate()):n.create(e)},nodeFullname(i,a){if(k(a,r.Records)){if(a.name instanceof bm)return new n(void 0,[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof L){if(!(a.name instanceof W))return new n(void 0,[new E(T.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||!Tf(a.name.callee))&&e.push(new E(T.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!If(a.name.argumentList))&&e.push(new E(T.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=j(a.name.callee);return t?.length===1&&t.unshift(y),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!If(a.name)?new n(e,[new E(T.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return A(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Records)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):A(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Records)?i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,i.attributeList)]):new n({}):A(i,r.Records)?new n({}):n.create(e)}},lv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new E(T.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof bm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:Df(e)?[]:[new E(T.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new E(T.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 E(T.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Zf(e.callee)&&t.push(new E(T.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Zf(e.callee)){let n=cp(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=cp(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new E(T.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new E(T.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Qf(e.callee)&&t.push(new E(T.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(g(n)instanceof U){let e=this.validateFieldSettings(g(n));t.push(...e),n.pop()}else n[0]instanceof U&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new E(T.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return dv(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function uv(e){if(!(D(e)&&e.expression.variable.kind!==v.QUOTED_STRING)&&!(e instanceof fm))return!1;let t;if(t=e instanceof fm?rp(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 dv(e){let t=zf(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 E(T.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{uv(t.value)||r.push(new E(T.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 E(T.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{jf(e.value)||r.push(new E(T.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),o[e]=t;break;case i.Inactive:t.length>1&&r.push(...t.map(e=>new E(T.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new E(T.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new E(T.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var fv={validateNode(t,i){return k(i,r.Ref)?n.create(void 0,new lv(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Ref)?i.name?Df(i.name)?new n(j(i.name)):new n(void 0,[new E(T.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):A(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Ref)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(k(i,r.Ref))return i.attributeList?new n({},[new E(T.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(A(i,r.Ref)){let e=[...i.args],t;return g(e)instanceof U?t=g(e):e[0]instanceof U&&(t=e[0]),t?dv(t):new n({})}return n.create(e)}},pv=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new E(T.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof wm?[new E(T.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof bm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Tf(e)?[]:[new E(T.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new E(T.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Ef(e)?[]:[new E(T.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){return mv(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=e=>{let t=[];if(!e.callee)return[];e.args.length===0&&t.push(new E(T.INVALID_COLUMN,`A column must have a type`,e.callee)),D(e.callee)||t.push(new E(T.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Lf(e.args[0])&&t.push(new E(T.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?(kf(e.callee)||t.push(new E(T.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 E(T.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof B&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){return hv(e).getErrors()}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function mv(e){let t=zf(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{let t=Hg[i.HeaderColor];t.isValidBuiltinFieldValue(e.value)||r.push(new E(T.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{let t=Hg[i.Note];t.isValidBuiltinFieldValue(e.value)||r.push(new E(T.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;default:r.push(...Pg(t,e,{duplicate:T.DUPLICATE_TABLE_SETTING,invalidValue:T.INVALID_TABLE_SETTING_VALUE}))}}),new n(a,r)}function hv(e){if(!e.slice(0,-1).every(Hf)||!e.slice(-1).every(e=>Hf(e)||e instanceof U))return new n({},e.map(e=>new E(T.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let t;g(e)instanceof U&&(t=e.pop());let r=zf(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{let t=Ug[i.Note];t.isValidBuiltinFieldValue(e.value)||a.push(new E(T.INVALID_COLUMN_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Ff(e.value)||a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new E(T.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 E(T.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 E(T.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 E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Nf(e.value)||a.push(new E(T.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 hm||a.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...Pg(t,e,{duplicate:T.DUPLICATE_COLUMN_SETTING,invalidValue:T.INVALID_COLUMN_SETTING_VALUE}))}}),new n(o,a)}var gv={validateNode(t,i){return k(i,r.Table)?n.create(void 0,new pv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.Table)){if(!i.name)return new n(void 0,[new E(T.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof wm)return new n(void 0,[new E(T.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,i.name)]);let e=j(i.name);return e?.length===1&&e.unshift(y),new n(e)}if(A(i,r.Table)){if(kf(i.callee)){let e=N(i.callee.expression);return new n(e?[e]:void 0)}let e=N(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return k(i,r.Table)?i.alias?Ef(i.alias)?new n(N(i.alias)):new n(void 0,[new E(T.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):A(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Table)?i.attributeList?mv(i.attributeList):new n({}):A(i,r.Table)?hv(i.args.slice(1)):n.create(e)}},_v=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new E(T.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof bm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:Df(e)?[]:[new E(T.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new E(T.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){return vv(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&j(e.callee)===void 0&&t.push(new E(T.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 E(T.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 E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function vv(e){let t=zf(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Color:case i.Note:{let n=a_[e];t.length>1&&r.push(...t.map(t=>new E(T.DUPLICATE_TABLE_SETTING,`'${e}' can only appear once`,t))),t.forEach(e=>{n.isValidBuiltinFieldValue(e.value)||r.push(new E(T.INVALID_TABLE_SETTING_VALUE,n.message,e.value||e.name))}),o[e]=t;break}default:r.push(...Pg(e,t,{duplicate:T.DUPLICATE_TABLE_SETTING,invalidValue:T.INVALID_TABLE_SETTING_VALUE})),o[e]=t;break}return new n(o,r)}var yv={validateNode(t,i){return k(i,r.TableGroup)?n.create(void 0,new _v(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.TableGroup))return i.name?Df(i.name)?new n(j(i.name)):new n(void 0,[new E(T.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new E(T.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(A(i,r.TableGroup)){let e=j(i.callee);return e?.length===1&&e.unshift(y),new n(e)}return n.create(e)},nodeAlias(t,i){return k(i,r.TableGroup)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.TableGroup)?vv(i.attributeList):A(i,r.TableGroup)?new n({}):n.create(e)}},bv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new E(T.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof bm?[new E(T.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:Df(e)?[]:[new E(T.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new E(T.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=zf(e),n=t.getErrors();return Sa(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{jf(e.value)||n.push(new E(T.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 E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Bf(e.value)||n.push(new E(T.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new E(T.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof V)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=_(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[];e.args.length===0&&t.push(new E(T.INVALID_COLUMN,`A column must have a type`,e.callee)),D(e.callee)||t.push(new E(T.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Lf(e.args[0])&&t.push(new E(T.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t})}validateFieldSetting(e){let t=g(e);if(!e.slice(0,-1).every(Hf)||!(Hf(t)||t instanceof U))return e.map(e=>new E(T.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;g(e)instanceof U&&(n=e.pop());let r=zf(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Bf(e.value)||a.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Ff(e.value)||a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new E(T.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 E(T.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 E(T.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 E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Nf(e.value)||a.push(new E(T.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 hm||a.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...Pg(t,e,{duplicate:T.DUPLICATE_COLUMN_SETTING,invalidValue:T.INVALID_COLUMN_SETTING_VALUE}))}}),a}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function xv(e){let t=zf(e),r=t.getErrors(),a=t.getValue();return Sa(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{jf(e.value)||r.push(new E(T.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 E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Bf(e.value)||r.push(new E(T.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new E(T.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Sv(e){let t=g(e);if(e.length>0&&(!e.slice(0,-1).every(Hf)||!(Hf(t)||t instanceof U)))return new n({},e.map(e=>new E(T.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let r;g(e)instanceof U&&(r=e.pop());let a=zf(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sa(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Bf(e.value)||o.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Ff(e.value)||o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new E(T.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 E(T.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 E(T.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 E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new E(T.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 E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Nf(e.value)||o.push(new E(T.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 hm||o.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:o.push(...Pg(t,e,{duplicate:T.DUPLICATE_COLUMN_SETTING,invalidValue:T.INVALID_COLUMN_SETTING_VALUE}))}}),new n(s,o)}var Cv={validateNode(t,i){return k(i,r.TablePartial)?n.create(void 0,new bv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.TablePartial))return i.name?Df(i.name)?new n(j(i.name)):new n(void 0,[new E(T.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new E(T.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(A(i,r.TablePartial)){let e=N(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return k(i,r.TablePartial)?i.alias?new n(void 0,[new E(T.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(N(i.alias)):A(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.TablePartial)?xv(i.attributeList):A(i,r.TablePartial)?Sv(i.args.slice(1)):n.create(e)}},wv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new E(T.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.importPath&&!bo.isRelative(this.declarationNode.importPath.value)&&e.push(new E(T.INVALID_USE_SPECIFIER_NAME,`Import path must be a relative path (starting with './' or '../')`,this.declarationNode.importPath)),this.declarationNode.specifiers instanceof bm)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 E(T.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Lp))||t.push(new E(T.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()]}},Tv=[gv,Y_,cv,Z_,H_,fv,ov,yv,Cv,$_,nv,q_,iv,{validateNode(t,r){return r instanceof lm?n.create(void 0,new wv(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!Gf(r))return n.create(e);let i=j(r.name);return!i||i.length===0?n.create(void 0,[new E(T.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Lp.TableGroup)&&i.length>1?n.create(i,[new E(T.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Lp.TablePartial)&&i.length>1?n.create(i,[new E(T.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Lp.Note)&&i.length>1?n.create(i,[new E(T.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Lp.Schema)&&i.unshift(y),new n(i))},nodeAlias(t,r){return Gf(r)?r.alias?Ef(r.alias)?new n(N(r.alias)):new n(void 0,[new E(T.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 lm?n.create({}):n.create(e)}},G_];function Ev(t,...r){for(let n of Tv){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function Dv(r){let i=Ev(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function Ov(r){let i=Ev(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function kv(r){let i=Ev(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function Av(r){let i=Ev(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var jv=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Mv(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}),jv&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function Nv(e,t,...n){return Mv(t,n)}var Pv=!1,Fv=!1,Iv=!1,Lv=!1,Rv=void 0,zv=typeof self==`object`?self:typeof global==`object`?global:{},Bv=void 0;zv.vscode!==void 0&&zv.vscode.process!==void 0?Bv=zv.vscode.process:typeof process<`u`&&(Bv=process);var Vv=typeof Bv?.versions?.electron==`string`&&Bv?.type===`renderer`;if(typeof navigator==`object`&&!Vv)Rv=navigator.userAgent,Pv=Rv.indexOf(`Windows`)>=0,Fv=Rv.indexOf(`Macintosh`)>=0,(Rv.indexOf(`Macintosh`)>=0||Rv.indexOf(`iPad`)>=0||Rv.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,Iv=Rv.indexOf(`Linux`)>=0,Rv?.indexOf(`Mobi`),Lv=!0,Nv({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof Bv==`object`){Pv=Bv.platform===`win32`,Fv=Bv.platform===`darwin`,Iv=Bv.platform===`linux`,Iv&&Bv.env.SNAP&&Bv.env.SNAP_REVISION,Bv.env.CI||Bv.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=Bv.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.availableLanguages[`*`],t.locale,t.osLocale,t._translationsConfigFile}catch{}}else console.error(`Unable to resolve platform.`);var Hv=Pv,Uv=Fv;Lv&&zv.importScripts;var Wv=Rv,Gv=typeof zv.postMessage==`function`&&!zv.importScripts;(()=>{if(Gv){let e=[];zv.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}),zv.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var Kv=!!(Wv&&Wv.indexOf(`Chrome`)>=0);Wv&&Wv.indexOf(`Firefox`),!Kv&&Wv&&Wv.indexOf(`Safari`),Wv&&Wv.indexOf(`Edg/`),Wv&&Wv.indexOf(`Android`);var qv;if(zv.vscode!==void 0&&zv.vscode.process!==void 0){let e=zv.vscode.process;qv={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else qv=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 Hv?`win32`:Uv?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var Jv=qv.cwd,Yv=qv.env,Xv=qv.platform,Zv=65,Qv=97,$v=90,ey=122,ty=46,ny=47,ry=92,iy=58,ay=63,oy=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 sy(e,t){if(typeof e!=`object`||!e)throw new oy(t,`Object`,e)}function cy(e,t){if(typeof e!=`string`)throw new oy(t,`string`,e)}var ly=Xv===`win32`;function K(e){return e===ny||e===ry}function uy(e){return e===ny}function dy(e){return e>=Zv&&e<=$v||e>=Qv&&e<=ey}function fy(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=ny;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==ty||i.charCodeAt(i.length-2)!==ty){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===ty&&s!==-1?++s:s=-1}return i}function py(e,t){sy(t,`pathObject`);let n=t.dir||t.root,r=t.base||`${t.name||``}${t.ext||``}`;return n?n===t.root?`${n}${r}`:`${n}${e}${r}`:r}var my={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],cy(a,`path`),a.length===0)continue}else t.length===0?a=Jv():(a=Yv[`=${t}`]||Jv(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===ry)&&(a=`${t}\\`));let o=a.length,s=0,c=``,l=!1,u=a.charCodeAt(0);if(o===1)K(u)&&(s=1,l=!0);else if(K(u))if(l=!0,K(a.charCodeAt(1))){let e=2,t=e;for(;e<o&&!K(a.charCodeAt(e));)e++;if(e<o&&e!==t){let n=a.slice(t,e);for(t=e;e<o&&K(a.charCodeAt(e));)e++;if(e<o&&e!==t){for(t=e;e<o&&!K(a.charCodeAt(e));)e++;(e===o||e!==t)&&(c=`\\\\${n}\\${a.slice(t,e)}`,s=e)}}}else s=1;else dy(u)&&a.charCodeAt(1)===iy&&(c=a.slice(0,2),s=2,o>2&&K(a.charCodeAt(2))&&(l=!0,s=3));if(c.length>0)if(t.length>0){if(c.toLowerCase()!==t.toLowerCase())continue}else t=c;if(r){if(t.length>0)break}else if(n=`${a.slice(s)}\\${n}`,r=l,l&&t.length>0)break}return n=fy(n,!r,`\\`,K),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){cy(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return uy(a)?`\\`:e;if(K(a))if(i=!0,K(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!K(e.charCodeAt(i));)i++;if(i<t&&i!==a){let o=e.slice(a,i);for(a=i;i<t&&K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!K(e.charCodeAt(i));)i++;if(i===t)return`\\\\${o}\\${e.slice(a)}\\`;i!==a&&(r=`\\\\${o}\\${e.slice(a,i)}`,n=i)}}}else n=1;else dy(a)&&e.charCodeAt(1)===iy&&(r=e.slice(0,2),n=2,t>2&&K(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?fy(e.slice(n),!i,`\\`,K):``;return o.length===0&&!i&&(o=`.`),o.length>0&&K(e.charCodeAt(t-1))&&(o+=`\\`),r===void 0?i?`\\${o}`:o:i?`${r}\\${o}`:`${r}${o}`},isAbsolute(e){cy(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return K(n)||t>2&&dy(n)&&e.charCodeAt(1)===iy&&K(e.charCodeAt(2))},join(...e){if(e.length===0)return`.`;let t,n;for(let r=0;r<e.length;++r){let i=e[r];cy(i,`path`),i.length>0&&(t===void 0?t=n=i:t+=`\\${i}`)}if(t===void 0)return`.`;let r=!0,i=0;if(typeof n==`string`&&K(n.charCodeAt(0))){++i;let e=n.length;e>1&&K(n.charCodeAt(1))&&(++i,e>2&&(K(n.charCodeAt(2))?++i:r=!1))}if(r){for(;i<t.length&&K(t.charCodeAt(i));)i++;i>=2&&(t=`\\${t.slice(i)}`)}return my.normalize(t)},relative(e,t){if(cy(e,`from`),cy(t,`to`),e===t)return``;let n=my.resolve(e),r=my.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===ry;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===ry;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===ry;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===ry;)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===ry&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===ry)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===ry?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)===ry)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===ry&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=my.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===ry){if(t.charCodeAt(1)===ry){let e=t.charCodeAt(2);if(e!==ay&&e!==ty)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(dy(t.charCodeAt(0))&&t.charCodeAt(1)===iy&&t.charCodeAt(2)===ry)return`\\\\?\\${t}`;return e},dirname(e){cy(e,`path`);let t=e.length;if(t===0)return`.`;let n=-1,r=0,i=e.charCodeAt(0);if(t===1)return K(i)?e:`.`;if(K(i)){if(n=r=1,K(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!K(e.charCodeAt(i));)i++;if(i===t)return e;i!==a&&(n=r=i+1)}}}}else dy(i)&&e.charCodeAt(1)===iy&&(n=t>2&&K(e.charCodeAt(2))?3:2,r=n);let a=-1,o=!0;for(let n=t-1;n>=r;--n)if(K(e.charCodeAt(n))){if(!o){a=n;break}}else o=!1;if(a===-1){if(n===-1)return`.`;a=n}return e.slice(0,a)},basename(e,t){t!==void 0&&cy(t,`ext`),cy(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&dy(e.charCodeAt(0))&&e.charCodeAt(1)===iy&&(n=2),t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=n;--a){let c=e.charCodeAt(a);if(K(c)){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=n;--a)if(K(e.charCodeAt(a))){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){cy(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===iy&&dy(e.charCodeAt(0))&&(t=r=2);for(let s=e.length-1;s>=t;--s){let t=e.charCodeAt(s);if(K(t)){if(!a){r=s+1;break}continue}i===-1&&(a=!1,i=s+1),t===ty?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:py.bind(null,`\\`),parse(e){cy(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.length,r=0,i=e.charCodeAt(0);if(n===1)return K(i)?(t.root=t.dir=e,t):(t.base=t.name=e,t);if(K(i)){if(r=1,K(e.charCodeAt(1))){let t=2,i=t;for(;t<n&&!K(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&K(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&!K(e.charCodeAt(t));)t++;t===n?r=t:t!==i&&(r=t+1)}}}}else if(dy(i)&&e.charCodeAt(1)===iy){if(n<=2)return t.root=t.dir=e,t;if(r=2,K(e.charCodeAt(2))){if(n===3)return t.root=t.dir=e,t;r=3}}r>0&&(t.root=e.slice(0,r));let a=-1,o=r,s=-1,c=!0,l=e.length-1,u=0;for(;l>=r;--l){if(i=e.charCodeAt(l),K(i)){if(!c){o=l+1;break}continue}s===-1&&(c=!1,s=l+1),i===ty?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},hy=(()=>{if(ly){let e=/\\/g;return()=>{let t=Jv().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Jv()})(),gy={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:hy();cy(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===ny)}return t=fy(t,!n,`/`,uy),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(cy(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===ny,n=e.charCodeAt(e.length-1)===ny;return e=fy(e,!t,`/`,uy),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return cy(e,`path`),e.length>0&&e.charCodeAt(0)===ny},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];cy(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:gy.normalize(t)},relative(e,t){if(cy(e,`from`),cy(t,`to`),e===t||(e=gy.resolve(e),t=gy.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===ny&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===ny)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===ny?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===ny)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(cy(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===ny,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===ny){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&&cy(t,`ext`),cy(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===ny){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)===ny){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){cy(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===ny){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===ty?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:py.bind(null,`/`),parse(e){cy(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===ny,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===ny){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===ty?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};gy.win32=my.win32=my,gy.posix=my.posix=gy,ly?my.normalize:gy.normalize,ly?my.resolve:gy.resolve,ly?my.relative:gy.relative,ly?my.dirname:gy.dirname,ly?my.basename:gy.basename,ly?my.extname:gy.extname,ly?my.sep:gy.sep;var _y=/^\w[\w\d+.-]*$/,vy=/^\//,yy=/^\/\//;function by(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&&!_y.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!vy.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(yy.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 xy(e,t){return!e&&!t?`file`:e}function Sy(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==Cy&&(t=Cy+t):t=Cy;break}return t}var q=``,Cy=`/`,wy=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,Ty=class e{static isUri(t){return t instanceof e?!0:t?typeof t.authority==`string`&&typeof t.fragment==`string`&&typeof t.path==`string`&&typeof t.query==`string`&&typeof t.scheme==`string`&&typeof t.fsPath==`string`&&typeof t.with==`function`&&typeof t.toString==`function`:!1}constructor(e,t,n,r,i,a=!1){typeof e==`object`?(this.scheme=e.scheme||q,this.authority=e.authority||q,this.path=e.path||q,this.query=e.query||q,this.fragment=e.fragment||q):(this.scheme=xy(e,a),this.authority=t||q,this.path=Sy(this.scheme,n||q),this.query=r||q,this.fragment=i||q,by(this,a))}get fsPath(){return jy(this,!1)}with(e){if(!e)return this;let{scheme:t,authority:n,path:r,query:i,fragment:a}=e;return t===void 0?t=this.scheme:t===null&&(t=q),n===void 0?n=this.authority:n===null&&(n=q),r===void 0?r=this.path:r===null&&(r=q),i===void 0?i=this.query:i===null&&(i=q),a===void 0?a=this.fragment:a===null&&(a=q),t===this.scheme&&n===this.authority&&r===this.path&&i===this.query&&a===this.fragment?this:new Dy(t,n,r,i,a)}static parse(e,t=!1){let n=wy.exec(e);return n?new Dy(n[2]||q,Fy(n[4]||q),Fy(n[5]||q),Fy(n[7]||q),Fy(n[9]||q),t):new Dy(q,q,q,q,q)}static file(e){let t=q;if(Hv&&(e=e.replace(/\\/g,Cy)),e[0]===Cy&&e[1]===Cy){let n=e.indexOf(Cy,2);n===-1?(t=e.substring(2),e=Cy):(t=e.substring(2,n),e=e.substring(n)||Cy)}return new Dy(`file`,t,e,q,q)}static from(e,t){return new Dy(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=Hv&&t.scheme===`file`?e.file(my.join(jy(t,!0),...n)).path:gy.join(t.path,...n),t.with({path:r})}toString(e=!1){return My(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new Dy(t);return e._formatted=t.external??null,e._fsPath=t._sep===Ey?t.fsPath??null:null,e}}},Ey=Hv?1:void 0,Dy=class extends Ty{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=jy(this,!1),this._fsPath}toString(e=!1){return e?My(this,!0):(this._formatted||=My(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=Ey),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}},Oy={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 ky(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=Oy[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 Ay(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+=Oy[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function jy(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,Hv&&(n=n.replace(/\//g,`\\`)),n}function My(e,t){let n=t?Ay:ky,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=Cy,r+=Cy),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:ky(c,!1,!1)),r}function Ny(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+Ny(e.substr(3)):e}}var Py=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function Fy(e){return e.match(Py)?e.replace(Py,e=>Ny(e)):e}var J=function(e){return e[e.Function=1]=`Function`,e[e.Constructor=2]=`Constructor`,e[e.Field=3]=`Field`,e[e.Variable=4]=`Variable`,e[e.Class=5]=`Class`,e[e.Struct=6]=`Struct`,e[e.Interface=7]=`Interface`,e[e.Module=8]=`Module`,e[e.Property=9]=`Property`,e[e.Event=10]=`Event`,e[e.Operator=11]=`Operator`,e[e.Unit=12]=`Unit`,e[e.Value=13]=`Value`,e[e.Constant=14]=`Constant`,e[e.Enum=15]=`Enum`,e[e.EnumMember=16]=`EnumMember`,e[e.Keyword=17]=`Keyword`,e[e.Text=18]=`Text`,e[e.Color=19]=`Color`,e[e.File=20]=`File`,e[e.Reference=21]=`Reference`,e[e.Customcolor=22]=`Customcolor`,e[e.Folder=23]=`Folder`,e[e.TypeParameter=24]=`TypeParameter`,e[e.User=25]=`User`,e[e.Issue=26]=`Issue`,e[e.Snippet=27]=`Snippet`,e}({}),Y=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),Iy=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 Ly(e,t){return e.getOffsetAt(t)}function Ry(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 zy=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=bo.fromUri(String(e.uri)),a=this.compiler.interpretProject().getInfos().filter(e=>e.quickFixes?.length&&e.filepath.equals(i));if(!a.length)return;let o=[];for(let t of n.markers)for(let n of a){let r=Ry(e,n.nodeOrToken);if(!(r.startLineNumber!==t.startLineNumber||r.startColumn!==t.startColumn||r.endLineNumber!==t.endLineNumber||r.endColumn!==t.endColumn))for(let r of n.quickFixes??[]){let n=this.quickFixToCodeAction(r,e,t);n&&o.push(n)}}let s=Pa(o,e=>{let t=e.diagnostics?.[0];return`${e.title}@${t?.startLineNumber}:${t?.startColumn}`});if(s.length)return{actions:s,dispose(){}}}quickFixToCodeAction(e,t,n){let r=bo.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=Ty.parse(e.filepath.toUri({protocol:t.uri.scheme})),a={edits:e.edits.map(e=>{let n=t.getPositionAt(e.start),r=t.getPositionAt(e.end);return{resource:i,textEdit:{range:{startLineNumber:n.lineNumber,startColumn:n.column,endLineNumber:r.lineNumber,endColumn:r.column},text:e.newText},versionId:t.getVersionId()}})};return{title:e.title,kind:`quickfix`,edit:a,diagnostics:[n]}}},By=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=bo.fromUri(String(e.uri)),a=Ly(e,n),o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(!e)continue;let n=this.compiler.nodeReferee(e).getFiltered(t);if(!n)continue;let i;if(n.declaration&&[cm.PRIMARY_EXPRESSION,cm.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=Ty.parse(i.filepath.toUri({protocol:r.scheme}))),[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}]}}return[]}},Vy=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e),...this.provideInfos(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideInfos(e){return e?this.compiler.interpretFile(e).getInfos().map(e=>this.createDiagnostic(e,`info`)):this.compiler.interpretProject().getInfos().map(e=>this.createDiagnostic(e,`info`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos;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`?Iy.Error:e===`warning`?Iy.Warning:Iy.Info}},Hy=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=bo.fromUri(String(r)),a=Ly(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[cm.ELEMENT_DECLARATION,cm.FUNCTION_APPLICATION,cm.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=Ty.parse(e.filepath.toUri({protocol:r.scheme}))),{range:{startColumn:e.startPos.column+1,startLineNumber:e.startPos.line+1,endColumn:e.endPos.column+1,endLineNumber:e.endPos.line+1},uri:t}})}}return[]}};function Uy(e,t){return e>=t.start&&e<t.end}function Wy(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 Gy(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 dm)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=N(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?N(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof bm&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof bm)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function Ky(e,t,n,r,i,a){let o=Gy(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:qy(Na([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
|
|
7
|
+
`),removeRange:Jy(a,e.startOffset,e.endOffset)}}return{topInsert:qy([l],s,`
|
|
8
|
+
`)}}function qy(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function Jy(e,t,n){let r=e.lastIndexOf(`
|
|
9
9
|
`,t-1)+1,i=n;for(;i<e.length&&(e[i]===` `||e[i]===` `);)i++;return i<e.length&&e[i]===`\r`&&i++,i<e.length&&e[i]===`
|
|
10
|
-
`&&i++,{startOffset:r,endOffset:i}}function
|
|
11
|
-
`?(n++,r=1):r++;return{line:n,column:r}}function Ay(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof B)||!o.isKind(r.Records)||!(o.body instanceof W)||!o.body||!gy(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof z?jy(e,o):My(e,o)}function jy(e,n){if(!(n.name instanceof dm))return Z();let r=n.name.argumentList?.elementList||[],i=r.map(n=>e.nodeReferee(n).getFiltered(t));if(!i||i.length===0)return Z();let a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Lp||r instanceof Qp))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}});return a.length===0?Z():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function My(e,n){let r=n.parent;if(!(r instanceof B))return Z();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof Ip))return Z();let a;if(n.name instanceof cm){let r=n.name.elementList,i=r.map(n=>e.nodeReferee(n).getFiltered(t)).filter(e=>e!==void 0);a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Lp||r instanceof Qp))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}})}else{let t=i.mergedColumns(e).flatMap(t=>{let{name:n}=t.canonicalName(e,t.filepath),{name:r}=t.type(e);return{name:n,type:r}});if(!t)return Z();a=t}return a.length===0?Z():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function Ny(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof tm&&n>=o.start&&n<=o.fullEnd)return Py(e,t,n,o,i,r);return null}function Py(e,t,n,r,i,a){if(r.importPath&&gy(n,r.importPath))return zy(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return Z();if(r.fromKeyword&&n>r.fromKeyword.end)return zy(e,t,void 0,i,r);if(r.specifiers instanceof rm){if(!r.specifiers.openBrace){let e=Ry();return Cy(r.useKeyword,n)?wy(e):e}return Fy(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof pm)return Z();let o=Ry();return Cy(r.useKeyword,n)?wy(o):o}function Fy(e,t,n,r,i,a){for(let o of r.specifiers){let r=!Number.isNaN(o.start)&&n>=o.start&&n<=o.end,s=a===o.importKind||a===o.asKeyword;if(r||s){if(o.importKind&&n>o.importKind.end){let n=o.getSymbolKind();if(n!==void 0&&n!==L.Schema)return Ly(e,t,i,n)}return Iy()}}return Iy()}function Iy(){return{suggestions:Object.keys(Ap).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}}function Ly(e,n,r,i){if(!r)return Z();let a=yo(n,r.value);if(!a)return Z();let o=e.usableMembers(a).getFiltered(t);if(!o)return Z();let s=new Set;for(let n of o.schemaMembers){let r=e.symbolMembers(n).getFiltered(t)??[];for(let e of r){if(e.kind!==i||e instanceof Zp&&!e.canBeImported)continue;let t=e.name;t&&(n.isPublicSchema()?s.add(t):s.add(`${n.name}.${t}`))}}return{suggestions:[...s].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Sy(i),range:void 0}))}}function Ry(){return{suggestions:[{label:`* from`,detail:`import all`,insertText:"* from '${1:./path}'",insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0},{label:`{ } from`,detail:`import named`,insertText:"{ ${1:type} ${2:name} } from '${3:./path}'",insertTextRules:X.InsertAsSnippet,kind:Y.Snippet,range:void 0}]}}function zy(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=dy(r,n);c={startLineNumber:e.startLineNumber,startColumn:e.startColumn+1,endLineNumber:e.endLineNumber,endColumn:e.endColumn-1}}let l=new Map,u=new Map,d=Na(e.layout.getEntrypoints().flatMap(t=>[...e.reachableFiles(t)]),e=>e.intern());for(let n of d){if(n.equals(t))continue;let r=n.relativeTo(a);if(r.endsWith(`.dbml`)&&(r=r.slice(0,-So.length)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=vo.resolve(a,d),p=e.layout.isDirectory(f);if(Vy(e,n,By(i))&&u.set(d,!0),l.has(d))continue;let m=s?`'${d}'`:d;l.set(d,{label:d,insertText:m,insertTextRules:X.KeepWhitespace,kind:p?Y.Folder:Y.File,sortText:`${p?`2`:`3`}${d}`,range:c})}for(let[e,t]of l)u.get(e)&&(t.sortText=`${t.kind===Y.File?`0`:`1`}${e}`,t.detail=`best match`);return{suggestions:[...l.values()]}}function By(e){let t=e.specifiers;return t instanceof rm?t.specifiers.flatMap(e=>{let t=F(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function Vy(e,n,r){if(r.length===0)return!1;let i=e.usableMembers(n).getFiltered(t);return i?r.every(({name:e,kind:t})=>i.nonSchemaMembers.some(n=>n.kind===t&&n.name===e)):!1}var Hy=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=vo.fromUri(String(e.uri)),r=uy(e,t),i=Ay(this.compiler,e,t,n,r);if(i!==null)return i;let a=this.compiler.token.flatStream(n),{token:o,index:s}=this.compiler.container.token(n,r),c=s===void 0?a[0]:a[s+1];if([...o?.trailingTrivia||[],...o?.leadingTrivia||[],...c?.leadingTrivia||[]].find(e=>Ka(e)&&gy(r,e)))return Z();if(s===void 0)return tb();let l=Ny(this.compiler,n,r,o,e);if(l!==null)return l;if([y.STRING_LITERAL,y.QUOTED_STRING].includes(o.kind)&&gy(r,o))return Z();let u=this.compiler.container.element(n,r);if(this.compiler.container.scopeKind(n,r)===Q.TOPLEVEL||u instanceof B&&u.type&&u.type.start<=r&&u.type.end>=r)return tb();let d=[...this.compiler.container.stack(n,r)].reverse();for(let e of d)if(e instanceof H)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return Wy(this.compiler,n,r,e);case`~`:return Uy(this.compiler,n,r);default:}else if(e instanceof am)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return Wy(this.compiler,n,r,e);case`.`:return $y(this.compiler,n,r,e);default:}else if(e instanceof V)return Yy(this.compiler,n,r,e);else if(e instanceof G)return Yy(this.compiler,n,r,e);else if(e instanceof cm)return qy(this.compiler,n,r,e);else if(e instanceof lm)return Jy(this.compiler,n,r);else if(e instanceof dm)return sb(this.compiler,n,r,e);else if(e instanceof U)return eb(this.compiler,n,r,e);else if(e instanceof B){if(_y(r,e))return ob(this.compiler,n,r,e);if(e.bodyColon&&r>=e.bodyColon.end||e.body&&gy(r,e.body))return eb(this.compiler,n,r,void 0)}return Z()}};function Uy(e,t,n){return Ky(e,t,n,e.parse.ast(t),[L.TablePartial])}function Wy(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=Ky(e,t,n,e.container.element(t,n),[L.Table,L.Schema,L.Column]);return Cy(r.op,n)?wy(i):i}return Z()}function Gy(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?Ty({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof Np&&e.isPublicSchema())).flatMap(e=>{let t=e.name;if(t===void 0)return[];let r=e.originalFilepath,i=r&&!r.equals(n.filepath)?`from ${r.basename}`:`this file`;return{label:t,insertText:t,insertTextRules:X.KeepWhitespace,kind:Sy(e.kind),sortText:Sy(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):Z()}function Ky(e,n,r,i,a){if(i===void 0)return Z();let o=i,s={suggestions:[]},c;for(;o;){o instanceof z&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=Gy(e,n,a).suggestions,r=e=>{switch(e){case Y.Field:return 0;case Y.Module:return 1;case Y.Class:return 2;default:return 3}};t.sort((e,t)=>r(e.kind)-r(t.kind)),s.suggestions.push(...t)}o=o instanceof B?o.parent:void 0}if(c?.filepath){let t=c.filepath,n=new Set(s.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label));for(let r of Dy(e,a,t)){let e=typeof r.label==`string`?r.label:r.label.label;n.has(e)||(n.add(e),s.suggestions.push(r))}}return Ty(s)}function qy(e,n,i,a){let o=e.container.scopeKind(n,i),s=e.container.element(n,i),c=[...e.container.stack(n,i)];for(let t of c)if(t instanceof dm&&t.argumentList===a)return sb(e,n,i,t);if(s instanceof B&&s.isKind(r.Records)&&!(s.name instanceof dm)&&_y(i,s)){let n=s.parent?e.nodeSymbol(s.parent).getFiltered(t):void 0,r=s.name?e.nodeReferee(s.name).getFiltered(t):void 0,i=n||r;if(i){let t=Gy(e,i,[L.Column]);return ep(a)?Ey(t):t}}switch(o){case Q.INDEXES:return db(e,n,i);case Q.REF:for(;c.length>0;){let t=c.pop();if(t instanceof am&&t.op?.value===`.`)return $y(e,n,i,t)}return ab(e,n,i);default:break}return Z()}function Jy(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?Ky(e,t,n,e.container.element(t,n),[L.Schema,L.Enum,L.EnumField]):Z()}function Yy(e,t,n,r){let{token:i}=e.container.token(t,n);if([y.COMMA,y.LBRACKET].includes(i?.kind)){let r=Xy(e,t,n);return i?.kind===y.COMMA&&Cy(i,n)?wy(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return Xy(e,t,n);if(r.name instanceof im){let a=Zy(e,t,n,Qf(r.name)??``);return i?.kind===y.COLON&&Cy(i,n)?wy(a):a}return Z()}function Xy(e,t,n){let r=e.container.element(t,n);if(r instanceof z)return Z();let a=e.container.scopeKind(t,n);if(r.body&&!gy(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=[i.HeaderColor,i.Note];break;case Q.TABLEGROUP:e=[i.Color,i.Note];break;case Q.NOTE:e=[i.Color];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:Y.Field,insertTextRules:X.KeepWhitespace,range:void 0}))}}switch(a){case Q.TABLE:case Q.TABLEPARTIAL:return{suggestions:[...[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique].map(e=>({label:e,insertText:e,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0})),...[i.Ref,i.Default,i.Note,i.Check].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.ENUM:return{suggestions:[...[i.Note].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.INDEXES:return{suggestions:[...[i.Unique,i.PK].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Property,range:void 0})),...[i.Note,i.Name,i.Type].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.REF:return{suggestions:[{label:i.Inactive,insertText:i.Inactive,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0},...[i.Update,i.Delete,i.Color].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))]};case Q.CHECKS:return{suggestions:[i.Name].map(e=>({label:e,insertText:`${e}: `,kind:Y.Property,insertTextRules:X.KeepWhitespace,range:void 0}))};default:break}return Z()}function Zy(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};case`color`:if(e.container.scopeKind(t,n)===Q.NOTE)return{suggestions:[xo].map(e=>({label:e,insertText:e,kind:Y.Value,insertTextRules:X.KeepWhitespace,range:void 0}))};break;case`default`:return Ky(e,t,n,e.container.element(t,n),[L.Schema,L.Enum]);default:break}return Z()}function Qy(e,n,r){if(!r)return[];let i=[],a=r;for(;a;){let n=e.nodeSymbol(a).getFiltered(t);if(n){let r=e.symbolMembers(n).getFiltered(t);i.push(...r||[])}a=a instanceof B?a.parent:void 0}for(let e of n){let t=i.filter(t=>t.name===e);if(t.length===0)return[];i=t}return i}function $y(e,n,r,i){let a=np(i)??[];return a.pop(),a.some(e=>!k(e))?Z():Ty({suggestions:Qy(e,a.map(e=>F(e)),e.container.element(n,r)).flatMap(n=>e.symbolMembers(n).getFiltered(t)||[]).flatMap(e=>{let t=e.name;return t===void 0?[]:{label:t,insertText:t,kind:Sy(e.kind),range:void 0}})})}function eb(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return rb(e,t,n,i);case Q.PROJECT:return ib(e,t,n,i);case Q.INDEXES:return lb(e,t,n);case Q.ENUM:return nb(e,t,n,i);case Q.REF:{let r=ab(e,t,n);return e.container.token(t,n).token?.kind===y.COLON&&Cy(e.container.token(t,n).token,n)?wy(r):r}case Q.TABLEGROUP:return cb(e,t);case Q.DIAGRAMVIEW:return mb();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof B){let a=i.parentNode,o=a instanceof W?a.parentNode:void 0;if(o instanceof B&&o.isKind(r.DiagramView))return hb(e,t,n,i)}return Z()}default:return Z()}}function tb(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`,`DiagramView`,`Note`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}}function nb(e,t,n,r){return r?.callee&&fb(n,r)===1?Ky(e,t,n,e.container.element(t,n),[L.Schema,L.Table,L.Column]):Z()}function rb(e,t,n,r){let i=[`Note`,`indexes`,`checks`,`Records`];if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))};let a=fb(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}:a===1?ub(e,t,n):Z()}function ib(e,t,n,r){return!r?.callee||fb(n,r)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))}:Z()}function ab(e,t,n){return Ky(e,t,n,e.container.element(t,n),[L.Schema,L.Table,L.Column])}function ob(e,t,n,i){return i.isKind(r.Records)?Ky(e,t,n,i.parent,[L.Schema,L.Table]):Z()}function sb(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&gy(i,a.callee),c=a.argumentList&&gy(i,a.argumentList);if(o instanceof B&&o.isKind(r.Records)&&_y(i,o)){if(s)return Ky(e,n,i,o.parent,[L.Schema,L.Table]);if(!c)return Z();let r=a.callee;if(!r)return Z();let l=np(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return Z();let f=Gy(e,d,[L.Column]),{argumentList:p}=a;return!p||!ep(p)?f:Ey(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof U)||o.callee!==a||(F(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return Z();let l=Gy(e,s,[L.Column]),{argumentList:u}=a;return!u||!ep(u)?l:Ey(l)}return Z()}function cb(e,t){return{suggestions:[...Ty({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==L.Table&&e.kind!==L.Schema)return[];let t=e.name;return t===void 0||e instanceof Np&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:X.KeepWhitespace,kind:Sy(e.kind),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0}))]}}function lb(e,t,n){return db(e,t,n)}function ub(e,t,n){return{suggestions:[...`integer.int.tinyint.smallint.mediumint.bigint.bit.bool.binary.varbinary.logical.char.nchar.varchar.varchar2.nvarchar.nvarchar2.binary_float.binary_double.float.double.decimal.dec.real.money.smallmoney.enum.tinyblob.tinytext.blob.text.mediumblob.mediumtext.longblob.longtext.ntext.set.inet6.uuid.image.date.time.datetime.datetime2.timestamp.year.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`).map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.TypeParameter,sortText:Y.TypeParameter.toString().padStart(2,`0`),range:void 0})),...Ky(e,t,n,e.container.element(t,n),[L.Enum,L.Schema]).suggestions]}}function db(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(L.Table))return Z();let o=e.symbolMembers(a).getFiltered(t);return o?Ty({suggestions:o.flatMap(n=>{let r=n.declaration?e.nodeFullname(n.declaration):void 0,i=r&&!r.hasValue(t)?r.getValue()?.at(-1):void 0;return i?{label:i,insertText:i,insertTextRules:X.KeepWhitespace,kind:Sy(L.Column),range:void 0}:[]})}):Z()}function fb(e,t){if(!t.callee)return-1;let n=[t.callee,...t.args],r=n.findIndex(t=>e<=t.end);return r===-1?n.length:r}var pb={label:`*`,insertText:`*`,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0};function mb(){return{suggestions:[...[`Tables`,`TableGroups`,`Notes`,`Schemas`].map(e=>({label:e,insertText:e,insertTextRules:X.KeepWhitespace,kind:Y.Keyword,range:void 0})),pb]}}function hb(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[pb,...Ky(e,t,n,e.parse.ast(t),[L.Table,L.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[pb,...Ky(e,t,n,e.parse.ast(t),[L.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[pb,{label:b,insertText:b,insertTextRules:X.KeepWhitespace,kind:Y.Module,range:void 0},...Ky(e,t,n,e.parse.ast(t),[L.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[pb,...Ky(e,t,n,e.parse.ast(t),[L.StickyNote]).suggestions]};default:return Z()}}var gb={comments:{lineComment:`//`,blockComment:[`/*`,`*/`]},brackets:[[`{`,`}`],[`[`,`]`],[`(`,`)`]],autoClosingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:"`",close:"`"}],surroundingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:"`",close:"`"}],indentationRules:{increaseIndentPattern:/^(.*\{[^}]*|\s*[{[].*)$/,decreaseIndentPattern:/^(.*\}.*|\s*[}\]].*)$/}},_b={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`none`,`check`,`tables`,`tablegroups`,`notes`,`schemas`,`inactive`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>~-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}};function vb(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:ga(n,e=>!e.isInvalid,r);if(a===-1)return[this.parse.ast(e)];let o=n[a].start,s=this.parse.ast(e),c=[s];for(;;){let e=Im(s).find(e=>gy(o,e));if(e===void 0||e instanceof Ba)break;c.push(e),s=e}if(i?.kind===y.COLON)return c;for(;c.length>0;){let n=!1,r=_(c);if(r instanceof U){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
|
|
12
|
-
`&&(c.pop(),n=!0)}else r instanceof
|
|
13
|
-
`?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,e}peek(e=0){if(!(this.current.offset+e>=this.text.length))return this.text[this.current.offset+e]}check(e){for(let t=0;t<e.length;t+=1)if(e[t]!==this.peek(t))return!1;return!0}match(e){return this.check(e)?(e.split(``).forEach(()=>this.advance()),!0):!1}addToken(e,t=!1){this.tokens.push(this.createToken(e,t))}createToken(e,t=!1){return
|
|
14
|
-
`:this.addToken(
|
|
10
|
+
`&&i++,{startOffset:r,endOffset:i}}function Yy(e){switch(e){case F.Schema:return J.Module;case F.Table:case F.TablePartial:case F.Metadata:return J.Class;case F.Column:case F.TableGroupField:return J.Field;case F.Enum:return J.Enum;case F.EnumField:return J.EnumMember;case F.TableGroup:return J.Struct;default:return J.Text}}function Xy(e,t){if(!e||Wa(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===v.NEWLINE&&n.end<=t)return!1}return!0}function X(){return{suggestions:[]}}function Zy(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function Qy(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:Zg(e.insertText??``),quoted:!0}))}}function $y(e,t=`, `){let n=e.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label).join(t);return n?{...e,suggestions:[{label:`* (all)`,insertText:n,insertTextRules:Y.KeepWhitespace,kind:J.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function eb(e,n,r){let i=[],a=new Set,o=e.layout.getSource(r)??``;for(let s of e.layout.getEntrypoints()){if(s.equals(r))continue;let c=e.usableMembers(s).getFiltered(t);if(c)for(let t of[...c.nonSchemaMembers,...c.schemaMembers]){if(!n.includes(t.kind))continue;let c=t.name;!c||a.has(c)||(a.add(c),i.push(tb(e,c,t.kind,s,r,o)))}}return i}function tb(e,t,n,r,i,a){let o=Ky(e,t,n,r,i,a),s=[];if(o.topInsert&&s.push({range:{startLineNumber:1,startColumn:1,endLineNumber:1,endColumn:1},text:o.topInsert}),o.removeRange){let e=nb(a,o.removeRange.startOffset),t=nb(a,o.removeRange.endOffset);s.push({range:{startLineNumber:e.line,startColumn:e.column,endLineNumber:t.line,endColumn:t.column},text:``})}return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:Yy(n),detail:`from ${r.basename}`,sortText:`zzz_${Yy(n).toString().padStart(2,`0`)}_${t}`,range:void 0,additionalTextEdits:s}}function nb(e,t){let n=1,r=1;for(let i=0;i<t&&i<e.length;i++)e[i]===`
|
|
11
|
+
`?(n++,r=1):r++;return{line:n,column:r}}function rb(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof R)||!o.isKind(r.Records)||!(o.body instanceof H)||!o.body||!Uy(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof L?ib(e,o):ab(e,o)}function ib(e,n){if(!(n.name instanceof W))return X();let r=n.name.argumentList?.elementList||[],i=r.map(n=>e.nodeReferee(n).getFiltered(t));if(!i||i.length===0)return X();let a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Gp||r instanceof om))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}});return a.length===0?X():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function ab(e,n){let r=n.parent;if(!(r instanceof R))return X();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof Wp))return X();let a;if(n.name instanceof gm){let r=n.name.elementList,i=r.map(n=>e.nodeReferee(n).getFiltered(t)).filter(e=>e!==void 0);a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Gp||r instanceof om))return[];let{name:a}=r.canonicalName(e,t.filepath),{name:o}=r.type(e);return{name:a,type:o}})}else{let t=i.mergedColumns(e).flatMap(t=>{let{name:n}=t.canonicalName(e,t.filepath),{name:r}=t.type(e);return{name:n,type:r}});if(!t)return X();a=t}return a.length===0?X():{suggestions:[{label:`Record row snippet`,insertText:a.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function ob(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof lm&&n>=o.start&&n<=o.fullEnd)return sb(e,t,n,o,i,r);return null}function sb(e,t,n,r,i,a){if(r.importPath&&Uy(n,r.importPath))return fb(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return X();if(r.fromKeyword&&n>r.fromKeyword.end)return fb(e,t,void 0,i,r);if(r.specifiers instanceof dm){if(!r.specifiers.openBrace){let e=db();return Xy(r.useKeyword,n)?Zy(e):e}return cb(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof bm)return X();let o=db();return Xy(r.useKeyword,n)?Zy(o):o}function cb(e,t,n,r,i,a){for(let o of r.specifiers){let r=!Number.isNaN(o.start)&&n>=o.start&&n<=o.end,s=a===o.importKind||a===o.asKeyword;if(r||s){if(o.importKind&&n>o.importKind.end){let n=o.getSymbolKind();if(n!==void 0&&n!==F.Schema)return ub(e,t,i,n)}return lb()}}return lb()}function lb(){return{suggestions:Object.keys(Lp).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function ub(e,n,r,i){if(!r)return X();let a=xo(n,r.value);if(!a)return X();let o=e.usableMembers(a).getFiltered(t);if(!o)return X();let s=new Set;for(let n of o.schemaMembers){let r=e.symbolMembers(n).getFiltered(t)??[];for(let e of r){if(e.kind!==i||e instanceof am&&!e.canBeImported)continue;let t=e.name;t&&(n.isPublicSchema()?s.add(t):s.add(`${n.name}.${t}`))}}return{suggestions:[...s].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:Yy(i),range:void 0}))}}function db(){return{suggestions:[{label:`* from`,detail:`import all`,insertText:"* from '${1:./path}'",insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0},{label:`{ } from`,detail:`import named`,insertText:"{ ${1:type} ${2:name} } from '${3:./path}'",insertTextRules:Y.InsertAsSnippet,kind:J.Snippet,range:void 0}]}}function fb(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=Ry(r,n);c={startLineNumber:e.startLineNumber,startColumn:e.startColumn+1,endLineNumber:e.endLineNumber,endColumn:e.endColumn-1}}let l=new Map,u=new Map,d=Pa(e.layout.getEntrypoints().flatMap(t=>[...e.reachableFiles(t)]),e=>e.intern());for(let n of d){if(n.equals(t))continue;let r=n.relativeTo(a);if(r.endsWith(`.dbml`)&&(r=r.slice(0,-wo.length)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=bo.resolve(a,d),p=e.layout.isDirectory(f);if(mb(e,n,pb(i))&&u.set(d,!0),l.has(d))continue;let m=s?`'${d}'`:d;l.set(d,{label:d,insertText:m,insertTextRules:Y.KeepWhitespace,kind:p?J.Folder:J.File,sortText:`${p?`2`:`3`}${d}`,range:c})}for(let[e,t]of l)u.get(e)&&(t.sortText=`${t.kind===J.File?`0`:`1`}${e}`,t.detail=`best match`);return{suggestions:[...l.values()]}}function pb(e){let t=e.specifiers;return t instanceof dm?t.specifiers.flatMap(e=>{let t=N(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function mb(e,n,r){if(r.length===0)return!1;let i=e.usableMembers(n).getFiltered(t);return i?r.every(({name:e,kind:t})=>i.nonSchemaMembers.some(n=>n.kind===t&&n.name===e)):!1}var Z={Table:`Table`,TableGroup:`TableGroup`,Enum:`Enum`,Project:`Project`,Ref:`Ref`,TablePartial:`TablePartial`,Records:`Records`,DiagramView:`DiagramView`,Note:`Note`,Metadata:`Metadata`,Indexes:`indexes`,Checks:`checks`,Tables:`Tables`,TableGroups:`TableGroups`,Notes:`Notes`,Schemas:`Schemas`,Column:`Column`},hb=`integer.int.tinyint.smallint.mediumint.bigint.bit.bool.binary.varbinary.logical.char.nchar.varchar.varchar2.nvarchar.nvarchar2.binary_float.binary_double.float.double.decimal.dec.real.money.smallmoney.enum.tinyblob.tinytext.blob.text.mediumblob.mediumtext.longblob.longtext.ntext.set.inet6.uuid.image.date.time.datetime.datetime2.timestamp.year.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),gb=[i.HeaderColor,i.Note];gb.map(e=>`${e}: `);var _b=[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique],vb=[i.Ref,i.Default,i.Note,i.Check],yb=[..._b,...vb],bb=[..._b,...vb.map(e=>`${e}: `)],xb=[i.Unique,i.PK],Sb=[i.Note,i.Name,i.Type],Cb=[...xb,...Sb],wb=[...xb,...Sb.map(e=>`${e}: `)],Tb=[i.Inactive],Eb=[i.Update,i.Delete,i.Color],Db=[...Tb,...Eb],Ob=[...Tb,...Eb.map(e=>`${e}: `)],kb=[i.Note],Ab=kb.map(e=>`${e}: `),jb=[i.Name],Mb=jb.map(e=>`${e}: `),Nb=[`cascade`,`set default`,`set null`,`restrict`],Pb=[`btree`,`hash`],Fb=[Z.Note,Z.Indexes,Z.Checks,Z.Records],Ib=[Z.Table,Z.TableGroup,Z.Enum,Z.Note,Z.Ref,Z.TablePartial],Lb=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=bo.fromUri(String(e.uri)),i=Ly(e,t),a=rb(this.compiler,e,t,n,i);if(a!==null)return a;let o=this.compiler.token.flatStream(n),{token:s,index:c}=this.compiler.container.token(n,i),l=c===void 0?o[0]:o[c+1];if([...s?.trailingTrivia||[],...s?.leadingTrivia||[],...l?.leadingTrivia||[]].find(e=>qa(e)&&Uy(i,e)))return X();if(c===void 0)return Qb();let u=ob(this.compiler,n,i,s,e);if(u!==null)return u;if([v.STRING_LITERAL,v.QUOTED_STRING].includes(s.kind)&&Uy(i,s))return X();let d=this.compiler.container.element(n,i);if(this.compiler.container.scopeKind(n,i)===Q.TOPLEVEL||d instanceof R&&d.type&&d.type.start<=i&&d.type.end>=i)return Qb();let f=[...this.compiler.container.stack(n,i)].reverse();for(let e of f)if(e instanceof B)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return zb(this.compiler,n,i,e);case`~`:return Rb(this.compiler,n,i);default:}else if(e instanceof pm)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return zb(this.compiler,n,i,e);case`.`:return Yb(this.compiler,n,i,e);default:}else if(e instanceof z)return Wb(this.compiler,n,i,e);else if(e instanceof U)return Wb(this.compiler,n,i,e);else if(e instanceof gm)return Hb(this.compiler,n,i,e);else if(e instanceof _m)return Ub(this.compiler,n,i);else if(e instanceof W)return cx(this.compiler,n,i,e);else if(e instanceof V)return Xb(this.compiler,n,i,e);else if(e instanceof R){if(Wy(i,e))return k(e,r.Metadata)?ox(this.compiler,n,i,e):sx(this.compiler,n,i,e);if(e.bodyColon&&i>=e.bodyColon.end||e.body&&Uy(i,e.body))return Xb(this.compiler,n,i,void 0)}return X()}};function Rb(e,t,n){return Vb(e,t,n,e.parse.ast(t),[F.TablePartial])}function zb(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=Vb(e,t,n,e.container.element(t,n),[F.Table,F.Schema,F.Column]);return Xy(r.op,n)?Zy(i):i}return X()}function Bb(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?Qy({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof Vp&&e.isPublicSchema())).flatMap(e=>{let t=e.name;if(t===void 0)return[];let r=e.originalFilepath,i=r&&!r.equals(n.filepath)?`from ${r.basename}`:`this file`;return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:Yy(e.kind),sortText:Yy(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):X()}function Vb(e,n,r,i,a){if(i===void 0)return X();let o=i,s={suggestions:[]},c;for(;o;){o instanceof L&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=Bb(e,n,a).suggestions,r=e=>{switch(e){case J.Field:return 0;case J.Module:return 1;case J.Class:return 2;default:return 3}};t.sort((e,t)=>r(e.kind)-r(t.kind)),s.suggestions.push(...t)}o=o instanceof R?o.parent:void 0}if(c?.filepath){let t=c.filepath,n=new Set(s.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label));for(let r of eb(e,a,t)){let e=typeof r.label==`string`?r.label:r.label.label;n.has(e)||(n.add(e),s.suggestions.push(r))}}return Qy(s)}function Hb(e,n,i,a){let o=e.container.scopeKind(n,i),s=e.container.element(n,i),c=[...e.container.stack(n,i)];for(let t of c)if(t instanceof W&&t.argumentList===a)return cx(e,n,i,t);if(s instanceof R&&s.isKind(r.Records)&&!(s.name instanceof W)&&Wy(i,s)){let n=s.parent?e.nodeSymbol(s.parent).getFiltered(t):void 0,r=s.name?e.nodeReferee(s.name).getFiltered(t):void 0,i=n||r;if(i){let t=Bb(e,i,[F.Column]);return ap(a)?$y(t):t}}switch(o){case Q.INDEXES:return fx(e,n,i);case Q.REF:for(;c.length>0;){let t=c.pop();if(t instanceof pm&&t.op?.value===`.`)return Yb(e,n,i,t)}return nx(e,n,i);default:break}return X()}function Ub(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?Vb(e,t,n,e.container.element(t,n),[F.Schema,F.Enum,F.EnumField]):X()}function Wb(e,t,n,r){let{token:i}=e.container.token(t,n);if([v.COMMA,v.LBRACKET].includes(i?.kind)){let r=Gb(e,t,n);return i?.kind===v.COMMA&&Xy(i,n)?Zy(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return Gb(e,t,n);if(r.name instanceof fm){let a=qb(e,t,n,rp(r.name)??``);return i?.kind===v.COLON&&Xy(i,n)?Zy(a):a}return X()}function Gb(e,t,n){let r=e.container.element(t,n);if(r instanceof L)return X();let a=e.container.scopeKind(t,n);if(r.body&&!Uy(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=gb;break;case Q.TABLEGROUP:e=[i.Color,i.Note];break;case Q.NOTE:e=[i.Color];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}))}}switch(a){case Q.TABLE:case Q.TABLEPARTIAL:return{suggestions:Kb(yb,bb)};case Q.ENUM:return{suggestions:Kb(kb,Ab)};case Q.INDEXES:return{suggestions:Kb(Cb,wb)};case Q.REF:return{suggestions:Kb(Db,Ob)};case Q.CHECKS:return{suggestions:Kb(jb,Mb)};default:break}return X()}function Kb(e,t){return e.map((e,n)=>({label:e,insertText:t[n],kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))}function qb(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:Nb.map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:Pb.map(e=>({label:e,insertText:`${e}`,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`color`:if(e.container.scopeKind(t,n)===Q.NOTE)return{suggestions:[Co].map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};break;case`default`:return Vb(e,t,n,e.container.element(t,n),[F.Schema,F.Enum]);default:break}return X()}function Jb(e,n,r){if(!r)return[];let i=[],a=r;for(;a;){let n=e.nodeSymbol(a).getFiltered(t);if(n){let r=e.symbolMembers(n).getFiltered(t);i.push(...r||[])}a=a instanceof R?a.parent:void 0}for(let e of n){let t=i.filter(t=>t.name===e);if(t.length===0)return[];i=t}return i}function Yb(e,n,r,i){let a=sp(i)??[];return a.pop(),a.some(e=>!D(e))?X():Qy({suggestions:Jb(e,a.map(e=>N(e)),e.container.element(n,r)).flatMap(n=>e.symbolMembers(n).getFiltered(t)||[]).flatMap(e=>{let t=e.name;return t===void 0?[]:{label:t,insertText:t,kind:Yy(e.kind),range:void 0}})})}function Xb(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return ex(e,t,n,i);case Q.PROJECT:return tx(e,t,n,i);case Q.INDEXES:return ux(e,t,n);case Q.ENUM:return $b(e,t,n,i);case Q.REF:{let r=nx(e,t,n);return e.container.token(t,n).token?.kind===v.COLON&&Xy(e.container.token(t,n).token,n)?Zy(r):r}case Q.TABLEGROUP:return lx(e,t);case Q.DIAGRAMVIEW:return hx();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof R){let a=i.parentNode,o=a instanceof H?a.parentNode:void 0;if(o instanceof R&&o.isKind(r.DiagramView))return gx(e,t,n,i)}return X()}default:return X()}}var Zb=[Z.Table,Z.TableGroup,Z.Enum,Z.Project,Z.Ref,Z.TablePartial,Z.Records,Z.DiagramView,Z.Note,Z.Metadata];function Qb(){return{suggestions:Zb.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function $b(e,t,n,r){return r?.callee&&px(n,r)===1?Vb(e,t,n,e.container.element(t,n),[F.Schema,F.Table,F.Column]):X()}function ex(e,t,n,r){let i=Fb;if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))};let a=px(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:a===1?dx(e,t,n):X()}function tx(e,t,n,r){let i=Ib;return!r?.callee||px(n,r)===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:X()}function nx(e,t,n){return Vb(e,t,n,e.container.element(t,n),[F.Schema,F.Table,F.Column])}var rx={[Rp.Table]:[F.Schema,F.Table],[Rp.Column]:[F.Schema,F.Table,F.Column],[Rp.TableGroup]:[F.TableGroup],[Rp.Note]:[F.StickyNote]},ix={[Rp.Table]:Z.Table,[Rp.Column]:Z.Column,[Rp.TableGroup]:Z.TableGroup,[Rp.Note]:Z.Note};function ax(){return{suggestions:Object.values(Rp).map(e=>{let t=ix[e];return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}})}}function ox(e,t,n,r){let i=Ng(r);if(!i||n<=r.targetKind.end&&n>=r.targetKind.start)return ax();let a=rx[i];return a?Vb(e,t,n,r.parent,a):X()}function sx(e,t,n,i){return i.isKind(r.Records)?Vb(e,t,n,i.parent,[F.Schema,F.Table]):X()}function cx(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&Uy(i,a.callee),c=a.argumentList&&Uy(i,a.argumentList);if(o instanceof R&&o.isKind(r.Records)&&Wy(i,o)){if(s)return Vb(e,n,i,o.parent,[F.Schema,F.Table]);if(!c)return X();let r=a.callee;if(!r)return X();let l=sp(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return X();let f=Bb(e,d,[F.Column]),{argumentList:p}=a;return!p||!ap(p)?f:$y(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof V)||o.callee!==a||(N(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return X();let l=Bb(e,s,[F.Column]),{argumentList:u}=a;return!u||!ap(u)?l:$y(l)}return X()}function lx(e,t){return{suggestions:[...Qy({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==F.Table&&e.kind!==F.Schema)return[];let t=e.name;return t===void 0||e instanceof Vp&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:Yy(e.kind),range:void 0}})}).suggestions,...[Z.Note].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))]}}function ux(e,t,n){return fx(e,t,n)}function dx(e,t,n){return{suggestions:[...hb.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.TypeParameter,sortText:J.TypeParameter.toString().padStart(2,`0`),range:void 0})),...Vb(e,t,n,e.container.element(t,n),[F.Enum,F.Schema]).suggestions]}}function fx(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(F.Table))return X();let o=e.symbolMembers(a).getFiltered(t);return o?Qy({suggestions:o.flatMap(n=>{let r=n.declaration?e.nodeFullname(n.declaration):void 0,i=r&&!r.hasValue(t)?r.getValue()?.at(-1):void 0;return i?{label:i,insertText:i,insertTextRules:Y.KeepWhitespace,kind:Yy(F.Column),range:void 0}:[]})}):X()}function px(e,t){if(!t.callee)return-1;let n=[t.callee,...t.args],r=n.findIndex(t=>e<=t.end);return r===-1?n.length:r}var mx={label:`*`,insertText:`*`,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0};function hx(){return{suggestions:[...[Z.Tables,Z.TableGroups,Z.Notes,Z.Schemas].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0})),mx]}}function gx(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[mx,...Vb(e,t,n,e.parse.ast(t),[F.Table,F.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[mx,...Vb(e,t,n,e.parse.ast(t),[F.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[mx,{label:y,insertText:y,insertTextRules:Y.KeepWhitespace,kind:J.Module,range:void 0},...Vb(e,t,n,e.parse.ast(t),[F.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[mx,...Vb(e,t,n,e.parse.ast(t),[F.StickyNote]).suggestions]};default:return X()}}var _x={comments:{lineComment:`//`,blockComment:[`/*`,`*/`]},brackets:[[`{`,`}`],[`[`,`]`],[`(`,`)`]],autoClosingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:"`",close:"`"}],surroundingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:"`",close:"`"}],indentationRules:{increaseIndentPattern:/^(.*\{[^}]*|\s*[{[].*)$/,decreaseIndentPattern:/^(.*\}.*|\s*[}\]].*)$/}},vx={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`,`metadata`],metadataTarget:[`table`,`tablegroup`,`schema`,`column`,`note`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`none`,`check`,`tables`,`tablegroups`,`notes`,`schemas`,`inactive`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>~-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":{cases:{"$3@metadataTarget":[`keyword`,``,`keyword`,``,`identifier`],"@default":[`keyword`,``,`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`identifier`,``,`identifier`]}}],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@metadataTarget":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}};function yx(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:_a(n,e=>!e.isInvalid,r);if(a===-1)return[this.parse.ast(e)];let o=n[a].start,s=this.parse.ast(e),c=[s];for(;;){let e=Am(s).find(e=>Uy(o,e));if(e===void 0||e instanceof Va)break;c.push(e),s=e}if(i?.kind===v.COLON)return c;for(;c.length>0;){let n=!1,r=g(c);if(r instanceof V){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
|
|
12
|
+
`&&(c.pop(),n=!0)}else r instanceof B||r instanceof pm?this.container.token(e,t).token!==r.op&&(c.pop(),n=!0):r instanceof U?r.listCloseBracket&&r.end<=t&&(c.pop(),n=!0):r instanceof gm?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof _m?r.end<=t&&(c.pop(),n=!0):r instanceof H?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof fm||r.end<t&&(c.pop(),n=!0);if(n){let e=g(c);e instanceof R&&e.end<=t&&c.pop()}if(!n)break}return c}function bx(e,t){let n=this.token.flatStream(e).findIndex(e=>e.start>=t);return n===void 0||n<=0?{token:void 0,index:void 0}:{token:this.token.flatStream(e)[n-1],index:n-1}}function xx(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof R)return n[e];return this.parse.ast(e)}function Sx(e,n){let r=this.container.element(e,n);if(!r)return;let i=this.nodeSymbol(r);if(i.hasValue(t))return;let a=this.symbolMembers(i.getValue());if(!a.hasValue(t))return a.getValue()}var Q=function(e){return e[e.TABLE=0]=`TABLE`,e[e.ENUM=1]=`ENUM`,e[e.TABLEGROUP=2]=`TABLEGROUP`,e[e.INDEXES=3]=`INDEXES`,e[e.NOTE=4]=`NOTE`,e[e.REF=5]=`REF`,e[e.PROJECT=6]=`PROJECT`,e[e.CUSTOM=7]=`CUSTOM`,e[e.TOPLEVEL=8]=`TOPLEVEL`,e[e.TABLEPARTIAL=9]=`TABLEPARTIAL`,e[e.CHECKS=10]=`CHECKS`,e[e.RECORDS=11]=`RECORDS`,e[e.DIAGRAMVIEW=12]=`DIAGRAMVIEW`,e[e.METADATA=13]=`METADATA`,e}({});function Cx(e,t){let n=this.container.element(e,t);if(n instanceof L)return Q.TOPLEVEL;switch(n.type?.value.toLowerCase()){case`table`:return Q.TABLE;case`enum`:return Q.ENUM;case`ref`:return Q.REF;case`tablegroup`:return Q.TABLEGROUP;case`indexes`:return Q.INDEXES;case`note`:return Q.NOTE;case`project`:return Q.PROJECT;case`tablepartial`:return Q.TABLEPARTIAL;case`checks`:return Q.CHECKS;case`records`:return Q.RECORDS;case`diagramview`:return Q.DIAGRAMVIEW;case`metadata`:return Q.METADATA;default:return Q.CUSTOM}}function wx(e,t){let r=t.originalSymbol;if(r.filepath.equals(e))return n.create(Ex(this,r));let i=[...this.symbolUses(r).getValue(),...this.symbolAliases(r).getValue()].filter(t=>t.filepath.equals(e));for(let e of i){let t=e.name;if(!t)continue;if(t!==r.name)return n.create({schema:``,name:t});let i=Tx(this,e);if(i.length>0)return n.create({schema:i.join(`.`),name:t});let a=Ex(this,r);return a?n.create({...a,name:t}):n.create({schema:y,name:t})}return n.create(Ex(this,r))}function Tx(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof Vp&&e.isKind(F.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function Ex(e,n){if(!n.declaration)return n.name?{schema:y,name:n.name}:void 0;let r=e.nodeFullname(n.declaration).getFiltered(t);if(!r||r.length===0)return n.name?{schema:y,name:n.name}:void 0;let i=r[r.length-1];return{schema:r.length>1?r.slice(0,-1).join(`.`):y,name:i}}function Dx(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof lm)||!i.importPath)continue;let t=xo(e,i.importPath.value);!t||r.has(t.absolute)||(r.add(t.absolute),n.push(t))}return n}function Ox(e,t){let n=new Set,r=[],i=[...t],a=0;for(;a<i.length;){let t=i[a++],o=t.intern();if(!n.has(o)){n.add(o),r.push(t);for(let n of e.fileDependencies(t))i.push(n)}}return r}function kx(e){return Ox(this,e?[e]:this.layout.getEntrypoints())}function Ax(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function jx(e){return this.interpretFile(e).getErrors()}function Mx(e){return this.interpretFile(e).getWarnings()}function Nx(e){return this.parseFile(e).getValue().tokens}function Px(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.interpretSymbol(r,e).getFiltered(t)}function Fx(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.symbolMembers(r).getFiltered(t)}function Ix(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function Lx(e){return this.parseFile(e).getValue().tokens.filter($a)}function Rx(e,t){let n=this.parse.ast(e);for(;;){let e=Am(n).find(e=>Uy(t,e));if(e===void 0)return n;if(e instanceof Va)return e;n=e}}function zx(e){let t=this.validateFile(e),r=this.parseFile(e).getValue().ast,i=this.bindNode(r).map(()=>void 0);return new n(void 0,[...t.getErrors(),...i.getErrors()],[...t.getWarnings(),...i.getWarnings()])}function Bx(){let e=n_(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.bindFile(n);t.set(n.absolute,e)}return t}function Vx(e){let{ast:r}=this.parseFile(e).getValue(),i=this.nodeSymbol(r).getFiltered(t);return i?this.interpretSymbol(i,e).map(e=>e===t||!e?void 0:e):n.create(void 0)}function Hx(){let e=[],r=[],i=[],a=new Set,o=[];for(let e of this.layout.getEntrypoints())for(let t of this.reachableFiles(e)){let e=t.intern();a.has(e)||(a.add(e),o.push(t))}let s=new Map;for(let a of o){let o=this.parseFile(a);e.push(...o.getErrors()),r.push(...o.getWarnings()),i.push(...o.getInfos());let c=this.bindFile(a);e.push(...c.getErrors()),r.push(...c.getWarnings()),i.push(...c.getInfos());let{ast:l}=o.getValue(),u=this.nodeSymbol(l).getFiltered(t),d=u?this.interpretSymbol(u,a):n.create(t),f=d.getFiltered(t);f&&s.set(a.absolute,f),e.push(...d.getErrors()),r.push(...d.getWarnings()),i.push(...d.getInfos())}let c={};for(let[e,t]of s)c[e]=t;return new n({files:c},e,r,i)}function Ux(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var Wx=class{constructor(e,t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
|
|
13
|
+
`?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,e}peek(e=0){if(!(this.current.offset+e>=this.text.length))return this.text[this.current.offset+e]}check(e){for(let t=0;t<e.length;t+=1)if(e[t]!==this.peek(t))return!1;return!0}match(e){return this.check(e)?(e.split(``).forEach(()=>this.advance()),!0):!1}addToken(e,t=!1){this.tokens.push(this.createToken(e,t))}createToken(e,t=!1){return Va.create(e,this.filepath,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),t)}lex(){return this.scanTokens(),this.tokens.push(Va.create(v.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new n(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(v.SPACE);break;case`\r`:break;case`
|
|
14
|
+
`:this.addToken(v.NEWLINE);break;case` `:this.addToken(v.TAB);break;case`,`:this.addToken(v.COMMA);break;case`(`:this.addToken(v.LPAREN);break;case`)`:this.addToken(v.RPAREN);break;case`[`:this.addToken(v.LBRACKET);break;case`]`:this.addToken(v.RBRACKET);break;case`{`:this.addToken(v.LBRACE);break;case`}`:this.addToken(v.RBRACE);break;case`;`:this.addToken(v.SEMICOLON);break;case`:`:this.addToken(v.COLON);break;case`'`:this.match(`''`)?this.multilineStringLiteral():this.singleLineStringLiteral();break;case`"`:this.quotedVariable();break;case"`":this.functionExpression();break;case`#`:this.colorLiteral();break;case`/`:this.match(`/`)?this.singleLineComment():this.match(`*`)?this.multilineComment():this.operator(e);break;case`*`:this.addToken(v.WILDCARD);break;default:if(za(e)){this.operator(e);break}if(xf(e)){this.identifier();break}if(Sf(e)){this.numericLiteralOrIdentifier();break}this.addToken(v.OP,!0),this.errors.push(new E(T.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(v.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)Ra(i)?(t.push(i),i.kind===v.NEWLINE&&n&&(n.trailingTrivia=t,e=!0,n=void 0,t=[])):(e?i.leadingTrivia=t:n.trailingTrivia=t,r.push(i),t=[],n=i,e=!1);this.tokens=r}gatherInvalid(){let e,t=[],n=[];for(e=0;e<this.tokens.length&&$a(this.tokens[e]);e+=1)n.push(this.tokens[e]);let r=this.tokens[e];for(r.leadingInvalid=[...n,...r.leadingInvalid];e<this.tokens.length;e+=1){let n=this.tokens[e];$a(n)?r.trailingInvalid.push(n):(r=n,t.push(n))}this.tokens=t}consumeUntil(e,t,{allowNewline:n,allowEof:r,raw:i,consumeStopSequence:a=!0}){let o=``;for(;!this.isAtEnd()&&(n||!this.check(`
|
|
15
15
|
`))&&!this.check(t);)this.peek()===`\\`&&!i?(this.advance(),o+=this.escapedString()):o+=this.advance();if(this.isAtEnd()&&!r){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new E(T.UNEXPECTED_EOF,`EOF reached while parsing`,t));return}if(this.check(`
|
|
16
|
-
`)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new E(T.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(
|
|
17
|
-
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(
|
|
16
|
+
`)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new E(T.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(Va.create(e,this.filepath,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(v.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(v.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(v.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(v.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(v.SINGLE_LINE_COMMENT,`
|
|
17
|
+
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(v.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&wf(this.peek());)this.advance();this.addToken(v.IDENTIFIER)}operator(e){switch(e){case`<`:this.peek()===`=`?this.advance():(this.peek()===`>`&&this.advance(),this.peek()===`?`&&this.advance());break;case`>`:(this.peek()===`=`||this.peek()===`?`)&&this.advance();break;case`-`:this.peek()===`?`&&this.advance();break;case`?`:this.peek()===`-`?(this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`<`?(this.advance(),this.peek()===`>`&&this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`>`&&(this.advance(),this.peek()===`?`&&this.advance());break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(v.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(v.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=+!!t,e>1)break;if(this.check(`e`)||this.check(`E`)){let e=this.peek(1),t=e===`+`||e===`-`,n=t?this.peek(2):e;if(n&&Sf(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Sf(this.peek());)this.advance();if(this.isAtEnd()||!wf(this.peek()))return this.addToken(v.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(v.NUMERIC_LITERAL);if(!t&&!wf(this.peek()))return this.addToken(v.NUMERIC_LITERAL);if(!t&&!Sf(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||wf(this.peek()));)this.advance();let e=this.createToken(v.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new E(T.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&wf(this.peek());)this.advance();let e=this.createToken(v.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&wf(this.peek());)this.advance();this.addToken(v.COLOR_LITERAL)}escapedString(){let e={column:this.current.column-1,offset:this.current.offset-1,line:this.current.line};if(this.isAtEnd())return`\\`;switch(this.advance()){case`\r`:return this.check(`
|
|
18
18
|
`)&&this.advance(),``;case`
|
|
19
19
|
`:return``;case`t`:return` `;case`n`:return`
|
|
20
|
-
`;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!Cf(this.peek()))return this.errors.push(new E(T.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Ba.create(y.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},Wb=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),Gb=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return _(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case y.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case y.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case y.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case y.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},Kb=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},qb=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Gb,this.useSpecifierList=this.contextStack.withContextDo(Wb.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(rm,e);try{this.consume(`Expect an opening brace '{'`,y.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(y.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof nm&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(y.IDENTIFIER)&&Ya(this.peek()))break;!Va(this.previous())&&!this.check(y.RBRACE)&&this.logError(this.peek(),T.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,y.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(y.RBRACE))for(K(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(y.RBRACE)||this.check(y.STRING_LITERAL)||this.check(y.IDENTIFIER)&&Ya(e)||Ha(this.previous(),e))break;K(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===y.EOF?this.logError(e,T.UNEXPECTED_EOF,`Unexpected EOF`):K(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(qa(e)||this.check(y.COLON,y.LBRACE,y.LBRACKET))break;K(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(y.COLON,y.LBRACE,y.LBRACKET))break;K(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Wb.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(W,e);try{this.consume(`Expect an opening brace '{'`,y.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(y.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,y.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(y.RBRACE))for(K(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(y.RBRACE)||Ha(this.previous(),e))break;K(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Wb.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(um,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(cm,e);try{this.consume(`Expect an opening parenthesis '('`,y.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(y.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(y.RPAREN);)try{this.consume(`Expect a comma ','`,y.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof R&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,y.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(y.RPAREN,y.COMMA))break;K(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Wb.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(G,e);try{this.consume(`Expect an opening bracket '['`,y.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(y.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(y.RBRACKET);)try{this.consume(`Expect a comma ','`,y.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof R&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,y.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(y.COMMA,y.RBRACKET))break;K(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(y.COMMA,y.RBRACKET,y.COLON))break;K(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(y.COMMA,y.RBRACKET))break;K(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Kb(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===y.EOF}advance(){return this.isAtEnd()?_(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?_(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),T.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(K(this.peek()),this.logError(this.advance(),T.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)K(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(z,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Im(e).forEach(t=>{t instanceof R&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Ja(this.peek())||Xa(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof tm&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(tm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===y.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(pm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof rm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof pm?`'*'`:`specifier list`;return Ya(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(y.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(nm,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,y.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(y.IDENTIFIER,y.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof R&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect an element name`);if(qa(this.peek())){e.asKeyword=this.advance();try{if(!this.check(y.IDENTIFIER,y.QUOTED_STRING))throw this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(B,e);try{this.consume(`Expect an identifier`,y.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(y.COLON,y.LBRACE,y.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(qa(this.peek()))if(e.as=this.advance(),this.check(y.COLON,y.LBRACE,y.LBRACKET))this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(y.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,y.LBRACE,y.COLON))return t();try{if(this.match(y.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof B?(K(t),this.logError(t,T.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(B,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(B,e);try{this.consume(`Expect an identifier`,y.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,y.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof B?this.errors.push(new E(T.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(B,e)}expression(){let e={args:[]},t=()=>Mm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(U,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Ua(this.previous())||this.logError(n,T.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Va(this.previous()))return!0;let e=this.peek().kind;return[y.RBRACE,y.RBRACKET,y.RPAREN,y.COMMA,y.COLON].includes(e)}commaExpression(){let e=this.check(y.COMMA)?this.nodeFactory.create(gm,{prevToken:this.previous()}):this.normalExpression();if(!this.check(y.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(gm,{prevToken:this.previous()}));break}if(this.check(y.COMMA)){t.elementList.push(this.nodeFactory.create(gm,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(lm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(y.COMMA));return this.nodeFactory.create(lm,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Va(this.previous()))return!0;let e=this.peek().kind;return[y.RBRACE,y.LBRACE,y.RBRACKET,y.LBRACKET,y.RPAREN,y.LPAREN,y.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===y.LPAREN){let{left:r}=rx(n);if(r<e||Ha(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(dm,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(dm,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===y.LBRACKET){if(Ua(this.previous()))break;try{t=this.nodeFactory.create(_m,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(_m,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(za(n)){let r=n,i=rx(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(om,{expression:t,op:r})}else{let n=$b(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(am,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(am,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(za(this.peek())){let t={};t.op=this.peek();let n=tx(t.op);if(n.right===null)throw this.logError(t.op,T.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(gm,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(H,t),e.handlerContext)):e}e=this.nodeFactory.create(H,t)}else if(e=this.extractOperand(),e instanceof gm)throw new $(this.peek(),this.nodeFactory.create(gm,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(y.WILDCARD)?this.wildcardExpression():this.check(y.NUMERIC_LITERAL,y.STRING_LITERAL,y.COLOR_LITERAL,y.QUOTED_STRING,y.IDENTIFIER)?this.primaryExpression():this.check(y.FUNCTION_EXPRESSION)?this.functionExpression():this.check(y.LBRACKET)?this.listExpression():this.check(y.LBRACE)?this.blockExpression():this.check(y.LPAREN)?this.tupleExpression():(this.peek().kind===y.EOF?this.logError(this.peek(),T.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),T.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(gm,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,y.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(sm,e),t.handlerContext):t}return this.nodeFactory.create(sm,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(pm,{token:this.previous()})}canBeField(){return this.peek().kind===y.IDENTIFIER&&this.peek(1).kind===y.COLON}primaryExpression(){if(this.match(y.COLOR_LITERAL,y.STRING_LITERAL,y.NUMERIC_LITERAL))return this.nodeFactory.create(hm,{expression:this.nodeFactory.create(fm,{literal:this.previous()})});if(this.match(y.QUOTED_STRING,y.IDENTIFIER))return this.nodeFactory.create(hm,{expression:this.nodeFactory.create(mm,{variable:this.previous()})});throw this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(y.COLON,y.RBRACKET,y.COMMA)){let t=this.peek();this.logError(t,T.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(im,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(V,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(y.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(V,e)}attributeValue(){let e;try{e=this.peek().kind===y.IDENTIFIER&&this.peek(1).kind===y.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==y.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(y.COLON,y.COMMA,y.RBRACKET);)try{this.consume(`Expect an identifier`,y.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(im,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(im,{identifiers:e})}logError(e,t,n){this.errors.push(new E(t,n,e))}},Jb=e=>({left:e,right:e+1}),Yb=e=>({left:null,right:e}),Xb=e=>({left:e,right:null}),Zb={left:null,right:null},Qb={".":Jb(16),"/":Jb(11),"%":Jb(11),"+":Jb(9),"=":Jb(2),"==":Jb(4),"!=":Jb(4),"-":Jb(9),"-?":Jb(9),"?-":Jb(9),"?-?":Jb(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`].map(e=>[e,Jb(7)]))};function $b(e){return Qb[e.value]??Zb}var ex=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`!`,`~`].map(e=>[e,Yb(15)]));function tx(e){return ex[e.value]??Zb}var nx={"(":Xb(14)};function rx(e){return nx[e.value]??Zb}function ix(e){let t=this.getSource(e);return new Ub(t??``,e).lex().chain(n=>new qb(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function ax(){let e=Lg(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function ox(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof Zp?dg.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function sx(e,n,r){let i;if(e instanceof Mp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Mp))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function cx(e){let t=e.originalSymbol;return Rg(this).map(n=>n.filter(n=>n instanceof Xp&&n.originalSymbol===t&&n!==e))}function lx(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(k(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof cm&&A(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=Yf(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Im(e))t instanceof R&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Np&&t.isKind(L.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function ux(e){return this.resolutionIndex().parents.get(e.intern())??[]}function dx(e){return this.resolutionIndex().references.get(e.intern())??[]}function fx(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function px(e){let t=e.originalSymbol;return Rg(this).map(n=>n.filter(n=>n instanceof Zp&&n.originalSymbol===t&&n!==e))}function mx(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function hx(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=Ig(e);if(t.length===0)return{schema:b,table:``};if(t.length===1)return{schema:b,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function gx(e,n,r,i){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return null;if(r===`public`)return e.lookupMembers(o,L.Table,i)??null;let s=e.lookupMembers(o,L.Schema,r);return s?e.lookupMembers(s,L.Table,i)??null:null}function _x(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function vx(e,t){if(!e||!(e instanceof B))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function yx(e,t,n){let r=!jg(t),i=!jg(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function bx(e,t,n,r,i,a){return n===i&&r===a?!1:gx(e,t,i,a)!==null}function xx(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return _x(n.substring(i,a))===t?{start:i,end:e.end}:null}function Sx(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function Cx(e,t,n,r,i){let a=[],o=new Set,s=Sx(r);for(let r of e){if(_x(i.substring(r.start,r.end))!==n)continue;let e=xx(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function wx(e,n,r){let i=hx(n),a=hx(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=gx(this,e,o,s);if(!u||u instanceof Xp||bx(this,e,o,s,c,l))return new Map;if(u instanceof Zp&&u.useSpecifierDeclaration instanceof nm&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return Tx(this,e,n,u,c,l)}return Ex(this,u,o,s,c,l)}function Tx(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=yx(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,mx(o,c)]])}function Ex(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof B))return new Map;let c=s.filepath;if(!c)return new Map;let l=yx(i,a,vx(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:Sx(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of Cx([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,mx(r,n))}return m}function Dx(e){let t=[],n=new Ub(e,wo).lex();if(n.getErrors().length>0)return t;let i=new qb(e,n.getValue(),new $p,wo).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?N(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function Ox(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function kx(e,t){e.push(` ${t} { * }`)}function Ax(e){return e==null?`null`:e.length===0?`empty`:`items`}function jx(e,t){let n=`DiagramView ${Mg(e)} {`,r=e=>Mg(e.name),i=t?.tables?.map(e=>{let t=Mg(e.name);return e.schemaName===`public`?t:`${Mg(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:Ax(t.tables),tableGroups:Ax(t.tableGroups),schemas:Ax(t.schemas),stickyNotes:Ax(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&Ox(d,`Tables`,i),c.tableGroups===`items`&&Ox(d,`TableGroups`,a),c.schemas===`items`&&Ox(d,`Schemas`,o)):u&&kx(d,`Tables`),c.stickyNotes===`items`?Ox(d,`Notes`,s):c.stickyNotes===`empty`&&kx(d,`Notes`),d.push(`}`),d.join(`
|
|
21
|
-
`)}function
|
|
20
|
+
`;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!wf(this.peek()))return this.errors.push(new E(T.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Va.create(v.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},Gx=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),Kx=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return g(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case v.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case v.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case v.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case v.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},qx=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},Jx=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Kx,this.useSpecifierList=this.contextStack.withContextDo(Gx.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(dm,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof um&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(v.IDENTIFIER)&&Za(this.peek()))break;!Ha(this.previous())&&!this.check(v.RBRACE)&&this.logError(this.peek(),T.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(v.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||this.check(v.STRING_LITERAL)||this.check(v.IDENTIFIER)&&Za(e)||Ua(this.previous(),e))break;G(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===v.EOF?this.logError(e,T.UNEXPECTED_EOF,`Unexpected EOF`):G(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ja(e)||this.check(v.COLON,v.LBRACE,v.LBRACKET))break;G(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COLON,v.LBRACE,v.LBRACKET))break;G(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Gx.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(H,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(v.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||Ua(this.previous(),e))break;G(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Gx.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(vm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(gm,e);try{this.consume(`Expect an opening parenthesis '('`,v.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(v.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(v.RPAREN);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof I&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,v.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.RPAREN,v.COMMA))break;G(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Gx.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(U,e);try{this.consume(`Expect an opening bracket '['`,v.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(v.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(v.RBRACKET);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof I&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,v.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;G(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET,v.COLON))break;G(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;G(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new qx(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===v.EOF}advance(){return this.isAtEnd()?g(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?g(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),T.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(G(this.peek()),this.logError(this.advance(),T.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)G(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(L,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Am(e).forEach(t=>{t instanceof I&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Ya(this.peek())||Qa(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof lm&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(lm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===v.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(bm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof dm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof bm?`'*'`:`specifier list`;return Za(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(v.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(um,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,v.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(v.IDENTIFIER,v.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof I&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect an element name`);if(Ja(this.peek())){e.asKeyword=this.advance();try{if(!this.check(v.IDENTIFIER,v.QUOTED_STRING))throw this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(Xa(e.type))try{this.consume(`Expect a metadata target kind`,v.IDENTIFIER),e.targetKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(v.COLON,v.LBRACE,v.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ja(this.peek()))if(e.as=this.advance(),this.check(v.COLON,v.LBRACE,v.LBRACKET))this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(v.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,v.LBRACE,v.COLON))return t();try{if(this.match(v.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof R?(G(t),this.logError(t,T.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,v.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof R?this.errors.push(new E(T.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}expression(){let e={args:[]},t=()=>Em(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(V,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Wa(this.previous())||this.logError(n,T.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.RBRACKET,v.RPAREN,v.COMMA,v.COLON].includes(e)}commaExpression(){let e=this.check(v.COMMA)?this.nodeFactory.create(Cm,{prevToken:this.previous()}):this.normalExpression();if(!this.check(v.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(Cm,{prevToken:this.previous()}));break}if(this.check(v.COMMA)){t.elementList.push(this.nodeFactory.create(Cm,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(_m,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(v.COMMA));return this.nodeFactory.create(_m,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.LBRACE,v.RBRACKET,v.LBRACKET,v.RPAREN,v.LPAREN,v.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===v.LPAREN){let{left:r}=iS(n);if(r<e||Ua(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(W,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(W,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===v.LBRACKET){if(Wa(this.previous()))break;try{t=this.nodeFactory.create(wm,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(wm,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Ba(n)){let r=n,i=iS(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(mm,{expression:t,op:r})}else{let n=eS(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(pm,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(pm,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Ba(this.peek())){let t={};t.op=this.peek();let n=nS(t.op);if(n.right===null)throw this.logError(t.op,T.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Cm,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(B,t),e.handlerContext)):e}e=this.nodeFactory.create(B,t)}else if(e=this.extractOperand(),e instanceof Cm)throw new $(this.peek(),this.nodeFactory.create(Cm,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(v.WILDCARD)?this.wildcardExpression():this.check(v.NUMERIC_LITERAL,v.STRING_LITERAL,v.COLOR_LITERAL,v.QUOTED_STRING,v.IDENTIFIER)?this.primaryExpression():this.check(v.FUNCTION_EXPRESSION)?this.functionExpression():this.check(v.LBRACKET)?this.listExpression():this.check(v.LBRACE)?this.blockExpression():this.check(v.LPAREN)?this.tupleExpression():(this.peek().kind===v.EOF?this.logError(this.peek(),T.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),T.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Cm,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,v.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(hm,e),t.handlerContext):t}return this.nodeFactory.create(hm,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(bm,{token:this.previous()})}canBeField(){return this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.COLON}primaryExpression(){if(this.match(v.COLOR_LITERAL,v.STRING_LITERAL,v.NUMERIC_LITERAL))return this.nodeFactory.create(Sm,{expression:this.nodeFactory.create(ym,{literal:this.previous()})});if(this.match(v.QUOTED_STRING,v.IDENTIFIER))return this.nodeFactory.create(Sm,{expression:this.nodeFactory.create(xm,{variable:this.previous()})});throw this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(v.COLON,v.RBRACKET,v.COMMA)){let t=this.peek();this.logError(t,T.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(fm,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(z,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(v.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(z,e)}attributeValue(){let e;try{e=this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==v.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(v.COLON,v.COMMA,v.RBRACKET);)try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(fm,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(fm,{identifiers:e})}logError(e,t,n){this.errors.push(new E(t,n,e))}},Yx=e=>({left:e,right:e+1}),Xx=e=>({left:null,right:e}),Zx=e=>({left:e,right:null}),Qx={left:null,right:null},$x={".":Yx(16),"/":Yx(11),"%":Yx(11),"+":Yx(9),"=":Yx(2),"==":Yx(4),"!=":Yx(4),"-":Yx(9),"-?":Yx(9),"?-":Yx(9),"?-?":Yx(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`].map(e=>[e,Yx(7)]))};function eS(e){return $x[e.value]??Qx}var tS=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`!`,`~`].map(e=>[e,Xx(15)]));function nS(e){return tS[e.value]??Qx}var rS={"(":Zx(14)};function iS(e){return rS[e.value]??Qx}function aS(e){let t=this.getSource(e);return new Wx(t??``,e).lex().chain(n=>new Jx(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function oS(){let e=n_(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function sS(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof am?bg.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function cS(e,n,r){let i;if(e instanceof Bp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Bp))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function lS(e){let t=e.originalSymbol;return r_(this).map(n=>n.filter(n=>n instanceof im&&n.originalSymbol===t&&n!==e))}function uS(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{if(e instanceof Wm){let t=e.target(this);if(!t)return;let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e);return}for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(D(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof gm&&O(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ep(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Am(e))t instanceof I&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Vp&&t.isKind(F.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function dS(e){return this.resolutionIndex().parents.get(e.intern())??[]}function fS(e){return this.resolutionIndex().references.get(e.intern())??[]}function pS(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function mS(e){let t=e.originalSymbol;return r_(this).map(n=>n.filter(n=>n instanceof am&&n.originalSymbol===t&&n!==e))}function hS(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function gS(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=t_(e);if(t.length===0)return{schema:y,table:``};if(t.length===1)return{schema:y,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function _S(e,n,r,i){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return null;if(r===`public`)return e.lookupMembers(o,F.Table,i)??null;let s=e.lookupMembers(o,F.Schema,r);return s?e.lookupMembers(s,F.Table,i)??null:null}function vS(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function yS(e,t){if(!e||!(e instanceof R))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function bS(e,t,n){let r=!Xg(t),i=!Xg(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function xS(e,t,n,r,i,a){return n===i&&r===a?!1:_S(e,t,i,a)!==null}function SS(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return vS(n.substring(i,a))===t?{start:i,end:e.end}:null}function CS(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function wS(e,t,n,r,i){let a=[],o=new Set,s=CS(r);for(let r of e){if(vS(i.substring(r.start,r.end))!==n)continue;let e=SS(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function TS(e,n,r){let i=gS(n),a=gS(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=_S(this,e,o,s);if(!u||u instanceof im||xS(this,e,o,s,c,l))return new Map;if(u instanceof am&&u.useSpecifierDeclaration instanceof um&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return ES(this,e,n,u,c,l)}return DS(this,u,o,s,c,l)}function ES(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=bS(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,hS(o,c)]])}function DS(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof R))return new Map;let c=s.filepath;if(!c)return new Map;let l=bS(i,a,yS(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:CS(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of wS([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,hS(r,n))}return m}function OS(e){let t=[],n=new Wx(e,Eo).lex();if(n.getErrors().length>0)return t;let i=new Jx(e,n.getValue(),new sm,Eo).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?j(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function kS(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function AS(e,t){e.push(` ${t} { * }`)}function jS(e){return e==null?`null`:e.length===0?`empty`:`items`}function MS(e,t){let n=`DiagramView ${Zg(e)} {`,r=e=>Zg(e.name),i=t?.tables?.map(e=>{let t=Zg(e.name);return e.schemaName===`public`?t:`${Zg(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:jS(t.tables),tableGroups:jS(t.tableGroups),schemas:jS(t.schemas),stickyNotes:jS(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&kS(d,`Tables`,i),c.tableGroups===`items`&&kS(d,`TableGroups`,a),c.schemas===`items`&&kS(d,`Schemas`,o)):u&&AS(d,`Tables`),c.stickyNotes===`items`?kS(d,`Notes`,s):c.stickyNotes===`empty`&&AS(d,`Notes`),d.push(`}`),d.join(`
|
|
21
|
+
`)}function NS(e,t,n){let r=this.getSource(e)??``,i=n??OS(r),a=[];for(let e of t){let t=PS(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:hS(r,a,!0),edits:a}}function PS(e,t,n){switch(t.operation){case`create`:return FS(e,t,n);case`update`:return IS(e,t,n);case`delete`:return LS(e,t,n);default:return[]}}function FS(e,t,n){if(n.find(e=>e.name===t.name))return IS(e,t,n);let r=`
|
|
22
22
|
|
|
23
|
-
`+
|
|
24
|
-
`;return[{start:e.length,end:e.length,newText:r}]}function
|
|
23
|
+
`+MS(t.name,t.visibleEntities)+`
|
|
24
|
+
`;return[{start:e.length,end:e.length,newText:r}]}function IS(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=MS(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function LS(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
|
|
25
25
|
`;){i--,i>0&&e[i-1]===`\r`&&i--;let t=e.lastIndexOf(`
|
|
26
26
|
`,i-1)+1;if(e.substring(t,i).trim()!==``){i=r.startIndex,i>0&&e[i-1]===`
|
|
27
27
|
`&&(i--,i>0&&e[i-1]===`\r`&&i--);break}}return a<e.length&&e[a]===`\r`&&a++,a<e.length&&e[a]===`
|
|
28
|
-
`&&a++,[{start:i,end:a,newText:``}]}var
|
|
28
|
+
`&&a++,[{start:i,end:a,newText:``}]}var RS=Symbol(`COMPUTING`),zS=class{constructor(e){this.layout=e,this.nodeIdGenerator=new sm,this.symbolIdGenerator=new zp,this.symbolFactory=new eo(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(aS),this.parseProject=this.globalQuery(oS),this.validateNode=this.localQuery(Dv),this.validateFile=this.localQuery(Ux),this.nodeFullname=this.localQuery(kv),this.nodeAlias=this.localQuery(Av),this.nodeSettings=this.localQuery(Ov),this.canonicalName=this.globalQuery(wx),this.bindNode=this.globalQuery(L_),this.bindFile=this.globalQuery(zx),this.bindProject=this.globalQuery(Bx),this.interpretSymbol=this.globalQuery(z_),this.interpretMetadata=this.globalQuery(B_),this.interpretFile=this.globalQuery(Vx),this.interpretProject=this.globalQuery(Hx),this.nodeSymbol=this.globalQuery(P_),this.nodeMetadata=this.globalQuery(R_),this.symbolMembers=this.globalQuery(F_),this.symbolMembersLookupMap=this.globalQuery(sS),this.lookupMembers=this.globalQuery(cS),this.nodeReferee=this.globalQuery(I_),this.resolutionIndex=this.globalQuery(uS),this.symbolReferences=this.globalQuery(fS),this.symbolParent=this.globalQuery(dS),this.symbolMetadata=this.globalQuery(pS),this.symbolAliases=this.globalQuery(lS),this.symbolUses=this.globalQuery(mS),this.fileDependencies=this.localQuery(Dx),this.reachableFiles=this.globalQuery(kx),this.usableMembers=this.globalQuery(Cg),this.nodeAtPosition=this.localQuery(Rx),this.renameTable=TS.bind(this),this.syncDiagramView=NS.bind(this),this.token={invalidStream:this.localQuery(Lx),flatStream:this.localQuery(Ix)},this.parse={source:e=>this.getSource(e)||``,ast:(e=Eo)=>Ax.call(this,e),errors:(e=Eo)=>jx.call(this,e),warnings:(e=Eo)=>Mx.call(this,e),tokens:(e=Eo)=>Nx.call(this,e),rawDb:(e=Eo)=>Px.call(this,e),publicSymbolTable:(e=Eo)=>Fx.call(this,e)},this.container={stack:this.localQuery(yx),token:this.localQuery(bx),element:this.localQuery(xx),scope:this.localQuery(Sx),scopeKind:this.localQuery(Cx)}}getSource(e){return this.layout.getSource(e)}cleanStaleLocalCache(e){let t=this.layout.getSource(e),n=e.absolute,r=this.sourceSnapshot.get(n);r===void 0?this.sourceSnapshot.set(n,t):r!==t&&(this.localCache.delete(e.intern()),this.globalCache.clear(),this.sourceSnapshot.set(n,t))}cleanStaleGlobalCache(){let e=this.layout.getEntrypoints(),t=!1;this.entrypointsSnapshot!==void 0&&(this.entrypointsSnapshot.length!==e.length||this.entrypointsSnapshot.some((t,n)=>t.absolute!==e[n].absolute))&&(t=!0),this.entrypointsSnapshot=e;for(let t of Ox(this,e))this.cleanStaleLocalCache(t);t&&this.globalCache.clear()}globalQuery(e){let t=Symbol();return((...n)=>{let r=!this.globallyQuerying;r&&(this.globallyQuerying=!0,this.cleanStaleGlobalCache());try{let r=this.globalCache.get(t);r||(r=new Map,this.globalCache.set(t,r));let i=n.length===0?``:n.length===1?$m(n[0]):n.map(e=>$m(e)).join(`\0`),a=r.get(i);if(a){if(a===RS)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,RS);try{let t=e.apply(this,n);return r.set(i,t),t}catch(e){throw r.delete(i),e}}finally{r&&(this.globallyQuerying=!1)}})}localQuery(e){let t=Symbol();return((...n)=>{let[r]=n,i=r instanceof I?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?$m(n[0]):n.map(e=>$m(e)).join(`\0`),s=this.localCache.get(a);s||(s=new Map,this.localCache.set(a,s));let c=s.get(t);if(c||(c=new Map,s.set(t,c)),c.has(o)){let t=c.get(o);if(t===RS)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,RS);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}findDiagramViewBlocks(e){return OS(this.getSource(e)??``)}initMonacoServices(e){let t=e?.autocompletion?.triggerCharacters??[];return{definitionProvider:new By(this),referenceProvider:new Hy(this),autocompletionProvider:new Lb(this,{triggerCharacters:t}),diagnosticsProvider:new Vy(this),codeActionProvider:new zy(this)}}},BS=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(bo.from)}getEntrypoints(){return[...this.files.keys()].map(bo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=wm,exports.AttributeNode=z,exports.BlockExpressionNode=H,exports.CARDINALITY_MANY=of,exports.CARDINALITY_MAYBE=rf,exports.CARDINALITY_ONE=nf,exports.CARDINALITY_SOME=af,exports.CallExpressionNode=W,exports.CommaExpressionNode=_m,exports.CompileError=E,exports.CompileErrorCode=T,exports.Compiler=zS,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=zy,exports.DBMLCompletionItemProvider=Lb,exports.DBMLDefinitionProvider=By,exports.DBMLDiagnosticsProvider=Vy,exports.DBMLReferencesProvider=Hy,exports.DEFAULT_ENTRY=Eo,exports.ElementDeclarationNode=R,exports.ElementKind=r,exports.EmptyNode=Cm,exports.FALSY_VALUES=bp,exports.Filepath=bo,exports.FunctionApplicationNode=V,exports.FunctionExpressionNode=hm,exports.GroupExpressionNode=vm,exports.IdentifierStreamNode=fm,exports.InfixExpressionNode=pm,exports.ListExpressionNode=U,exports.LiteralNode=ym,exports.MarkerSeverity=Iy,exports.MemoryProjectLayout=BS,exports.PostfixExpressionNode=mm,exports.PrefixExpressionNode=B,exports.PrimaryExpressionNode=Sm,exports.ProgramNode=L,exports.ScopeKind=Q,exports.SymbolKind=F,exports.SyntaxNode=I,exports.SyntaxNodeIdGenerator=sm,exports.SyntaxNodeKind=cm,exports.SyntaxToken=Va,exports.SyntaxTokenKind=v,exports.TRUTHY_VALUES=yp,exports.TupleExpressionNode=gm,exports.UNHANDLED=t,exports.Uri=Ty,exports.UseDeclarationNode=lm,exports.UseSpecifierListNode=dm,exports.UseSpecifierNode=um,exports.VariableNode=xm,exports.WildcardNode=bm,exports.addDoubleQuoteIfNeeded=Zg,exports.dbmlLanguageConfig=_x,exports.dbmlMonarchTokensProvider=vx,exports.escapeString=$g,exports.extractNumericLiteral=up,exports.extractSignedNumber=gp,exports.formatRecordValue=e_,exports.getMultiplicities=lf,exports.getRecordValueType=Uo,exports.getRelationshipOp=hf,exports.isBinaryType=Bo,exports.isBooleanType=Ro,exports.isDateTimeType=Vo,exports.isEmptyStringLiteral=mp,exports.isEndpointManySide=df,exports.isEndpointOneSide=uf,exports.isEndpointOptional=ff,exports.isEndpointRequired=pf,exports.isFloatType=Io,exports.isFunctionExpression=hp,exports.isIntegerType=Fo,exports.isNullish=pp,exports.isNumericType=Lo,exports.isOp=za,exports.isOpToken=Ba,exports.isSerialType=Ho,exports.isStringType=zo,exports.isTriviaToken=Ra,exports.isValidIdentifier=Xg,exports.makeCardinalityOptional=gf,exports.makeCardinalityRequired=_f,exports.makeRelationshipRequired=mf,exports.normalizeTypeName=Po,exports.parseCardinality=tf,exports.splitQualifiedIdentifier=t_,exports.tryExtractBoolean=xp,exports.tryExtractDateTime=Dp,exports.tryExtractEnum=Sp,exports.tryExtractInteger=vp,exports.tryExtractNumeric=_p,exports.tryExtractString=Cp,exports.unescapeString=Qg,exports.validateForeignKeys=zh,exports.validatePrimaryKey=kh,exports.validateUnique=Fh;
|