@dbml/parse 10.4.0-alpha.2 → 11.0.0-alpha.2

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.
Files changed (36) hide show
  1. package/LICENSE +0 -0
  2. package/dist/dbml-parse.js +38 -28
  3. package/dist/dbml-parse.mjs +5991 -4945
  4. package/dist/src/compiler/index.d.ts +40 -8
  5. package/dist/src/compiler/projectLayout/layout.d.ts +0 -7
  6. package/dist/src/compiler/queries/files/fileKind.d.ts +18 -0
  7. package/dist/src/compiler/queries/transform/index.d.ts +2 -1
  8. package/dist/src/compiler/queries/transform/renameElement.d.ts +13 -0
  9. package/dist/src/compiler/queries/transform/types.d.ts +10 -1
  10. package/dist/src/compiler/queries/transform/utils/arch.d.ts +6 -0
  11. package/dist/src/core/arch/icons.d.ts +5 -0
  12. package/dist/src/core/arch/read.d.ts +51 -0
  13. package/dist/src/core/arch/vocabulary.d.ts +11 -0
  14. package/dist/src/core/global_modules/arch/index.d.ts +2 -0
  15. package/dist/src/core/global_modules/arch/interpret.d.ts +11 -0
  16. package/dist/src/core/global_modules/arch/utils.d.ts +7 -0
  17. package/dist/src/core/global_modules/index.d.ts +15 -1
  18. package/dist/src/core/global_modules/metadata/utils.d.ts +3 -1
  19. package/dist/src/core/global_modules/program/bind.d.ts +1 -0
  20. package/dist/src/core/global_modules/program/interpret.d.ts +2 -0
  21. package/dist/src/core/lexer/lexer.d.ts +23 -1
  22. package/dist/src/core/local_modules/arch/index.d.ts +2 -0
  23. package/dist/src/core/local_modules/index.d.ts +1 -0
  24. package/dist/src/core/parser/parser.d.ts +18 -1
  25. package/dist/src/core/types/errors.d.ts +17 -1
  26. package/dist/src/core/types/filepath.d.ts +1 -3
  27. package/dist/src/core/types/nodes.d.ts +1 -0
  28. package/dist/src/core/types/schemaJson/types.d.ts +63 -1
  29. package/dist/src/core/types/symbol/metadata.d.ts +12 -1
  30. package/dist/src/core/types/symbol/symbols.d.ts +18 -0
  31. package/dist/src/core/types/tokens.d.ts +2 -0
  32. package/dist/src/index.d.ts +19 -4
  33. package/dist/src/services/definition/provider.d.ts +0 -1
  34. package/dist/src/services/suggestions/provider.d.ts +1 -3
  35. package/dist/src/services/suggestions/use.d.ts +1 -4
  36. package/package.json +3 -3
@@ -1,42 +1,52 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(`PASS_THROUGH`),t=Symbol(`UNHANDLED`),n=class e{static create(t,n,r,i){return new e(t,n,r,i)}constructor(e,t,n,r){this.value=e,this.errors=t??[],this.warnings=n,this.infos=r}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings,this.infos):this}hasValue(e){return this.value===e}getFiltered(e){return this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings??[]}getInfos(){return this.infos??[]}chainFiltered(t,n){if(this.value===n)return new e(void 0,this.errors,this.warnings,this.infos);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()],o=[...this.getInfos(),...r.getInfos()];return new e(r.value,i,a,o)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()],a=[...this.getInfos(),...n.getInfos()];return new e(n.value,r,i,a)}mapFiltered(t,n){return this.value===n?new e(void 0,this.errors,this.warnings,this.infos):new e(t(this.value),this.errors,this.warnings,this.infos)}map(t){return new e(t(this.value),this.errors,this.warnings,this.infos)}},r=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Dep=`dep`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e.Metadata=`metadata`,e}({}),i=function(e){return e.Color=`color`,e.HeaderColor=`headercolor`,e.Note=`note`,e.PK=`pk`,e.PrimaryKey=`primary key`,e.Unique=`unique`,e.Ref=`ref`,e.Dep=`dep`,e.NotNull=`not null`,e.Null=`null`,e.Increment=`increment`,e.Default=`default`,e.Name=`name`,e.Type=`type`,e.Check=`check`,e.Update=`update`,e.Delete=`delete`,e.Inactive=`inactive`,e.Example=`example`,e}({}),a=typeof global==`object`&&global&&global.Object===Object&&global,o=typeof self==`object`&&self&&self.Object===Object&&self,s=a||o||Function(`return this`)(),c=s.Symbol,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function p(e){var t=u.call(e,f),n=e[f];try{e[f]=void 0;var r=!0}catch{}var i=d.call(e);return r&&(t?e[f]=n:delete e[f]),i}var m=Object.prototype.toString;function ee(e){return m.call(e)}var te=`[object Null]`,ne=`[object Undefined]`,re=c?c.toStringTag:void 0;function ie(e){return e==null?e===void 0?ne:te:re&&re in Object(e)?p(e):ee(e)}function ae(e){return typeof e==`object`&&!!e}var oe=`[object Symbol]`;function se(e){return typeof e==`symbol`||ae(e)&&ie(e)==oe}function ce(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var le=Array.isArray,ue=1/0,de=c?c.prototype:void 0,fe=de?de.toString:void 0;function pe(e){if(typeof e==`string`)return e;if(le(e))return ce(e,pe)+``;if(se(e))return fe?fe.call(e):``;var t=e+``;return t==`0`&&1/e==-ue?`-0`:t}var me=/\s/;function he(e){for(var t=e.length;t--&&me.test(e.charAt(t)););return t}var ge=/^\s+/;function _e(e){return e&&e.slice(0,he(e)+1).replace(ge,``)}function ve(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var ye=NaN,be=/^[-+]0x[0-9a-f]+$/i,xe=/^0b[01]+$/i,Se=/^0o[0-7]+$/i,Ce=parseInt;function we(e){if(typeof e==`number`)return e;if(se(e))return ye;if(ve(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=ve(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=_e(e);var n=xe.test(e);return n||Se.test(e)?Ce(e.slice(2),n?2:8):be.test(e)?ye:+e}var Te=1/0,Ee=17976931348623157e292;function De(e){return e?(e=we(e),e===Te||e===-Te?(e<0?-1:1)*Ee:e===e?e:0):e===0?e:0}function Oe(e){var t=De(e),n=t%1;return t===t?n?t-n:t:0}function ke(e){return e}var Ae=`[object AsyncFunction]`,je=`[object Function]`,Me=`[object GeneratorFunction]`,Ne=`[object Proxy]`;function Pe(e){if(!ve(e))return!1;var t=ie(e);return t==je||t==Me||t==Ae||t==Ne}var Fe=s[`__core-js_shared__`],Ie=function(){var e=/[^.]+$/.exec(Fe&&Fe.keys&&Fe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Le(e){return!!Ie&&Ie in e}var Re=Function.prototype.toString;function ze(e){if(e!=null){try{return Re.call(e)}catch{}try{return e+``}catch{}}return``}var Be=/[\\^$.*+?()[\]{}|]/g,Ve=/^\[object .+?Constructor\]$/,He=Function.prototype,Ue=Object.prototype,We=He.toString,Ge=Ue.hasOwnProperty,Ke=RegExp(`^`+We.call(Ge).replace(Be,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function qe(e){return!ve(e)||Le(e)?!1:(Pe(e)?Ke:Ve).test(ze(e))}function Je(e,t){return e?.[t]}function Ye(e,t){var n=Je(e,t);return qe(n)?n:void 0}var Xe=Ye(s,`WeakMap`);function Ze(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}function Qe(){}var $e=800,et=16,tt=Date.now;function nt(e){var t=0,n=0;return function(){var r=tt(),i=et-(r-n);if(n=r,i>0){if(++t>=$e)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function rt(e){return function(){return e}}var it=function(){try{var e=Ye(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),at=nt(it?function(e,t){return it(e,`toString`,{configurable:!0,enumerable:!1,value:rt(t),writable:!0})}:ke);function ot(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1}function st(e){return e!==e}function ct(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function lt(e,t,n){return t===t?ct(e,t,n):ot(e,st,n)}function ut(e,t){return!!(e!=null&&e.length)&&lt(e,t,0)>-1}var dt=9007199254740991,ft=/^(?:0|[1-9]\d*)$/;function pt(e,t){var n=typeof e;return t??=dt,!!t&&(n==`number`||n!=`symbol`&&ft.test(e))&&e>-1&&e%1==0&&e<t}function mt(e,t,n){t==`__proto__`&&it?it(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function ht(e,t){return e===t||e!==e&&t!==t}var gt=Math.max;function _t(e,t,n){return t=gt(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=gt(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Ze(e,this,s)}}function vt(e,t){return at(_t(e,t,ke),e+``)}var yt=9007199254740991;function bt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=yt}function xt(e){return e!=null&&bt(e.length)&&!Pe(e)}var St=Object.prototype;function Ct(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||St)}function wt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var Tt=`[object Arguments]`;function Et(e){return ae(e)&&ie(e)==Tt}var Dt=Object.prototype,Ot=Dt.hasOwnProperty,kt=Dt.propertyIsEnumerable,At=Et(function(){return arguments}())?Et:function(e){return ae(e)&&Ot.call(e,`callee`)&&!kt.call(e,`callee`)};function jt(){return!1}var Mt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Nt=Mt&&typeof module==`object`&&module&&!module.nodeType&&module,Pt=Nt&&Nt.exports===Mt?s.Buffer:void 0,Ft=(Pt?Pt.isBuffer:void 0)||jt,It=`[object Arguments]`,Lt=`[object Array]`,Rt=`[object Boolean]`,zt=`[object Date]`,Bt=`[object Error]`,Vt=`[object Function]`,Ht=`[object Map]`,Ut=`[object Number]`,Wt=`[object Object]`,Gt=`[object RegExp]`,Kt=`[object Set]`,qt=`[object String]`,Jt=`[object WeakMap]`,Yt=`[object ArrayBuffer]`,Xt=`[object DataView]`,Zt=`[object Float32Array]`,Qt=`[object Float64Array]`,$t=`[object Int8Array]`,en=`[object Int16Array]`,tn=`[object Int32Array]`,nn=`[object Uint8Array]`,rn=`[object Uint8ClampedArray]`,an=`[object Uint16Array]`,on=`[object Uint32Array]`,sn={};sn[Zt]=sn[Qt]=sn[$t]=sn[en]=sn[tn]=sn[nn]=sn[rn]=sn[an]=sn[on]=!0,sn[It]=sn[Lt]=sn[Yt]=sn[Rt]=sn[Xt]=sn[zt]=sn[Bt]=sn[Vt]=sn[Ht]=sn[Ut]=sn[Wt]=sn[Gt]=sn[Kt]=sn[qt]=sn[Jt]=!1;function cn(e){return ae(e)&&bt(e.length)&&!!sn[ie(e)]}function ln(e){return function(t){return e(t)}}var un=typeof exports==`object`&&exports&&!exports.nodeType&&exports,dn=un&&typeof module==`object`&&module&&!module.nodeType&&module,fn=dn&&dn.exports===un&&a.process,pn=function(){try{return dn&&dn.require&&dn.require(`util`).types||fn&&fn.binding&&fn.binding(`util`)}catch{}}(),mn=pn&&pn.isTypedArray,hn=mn?ln(mn):cn,gn=Object.prototype.hasOwnProperty;function _n(e,t){var n=le(e),r=!n&&At(e),i=!n&&!r&&Ft(e),a=!n&&!r&&!i&&hn(e),o=n||r||i||a,s=o?wt(e.length,String):[],c=s.length;for(var l in e)(t||gn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||pt(l,c)))&&s.push(l);return s}function vn(e,t){return function(n){return e(t(n))}}var yn=vn(Object.keys,Object),bn=Object.prototype.hasOwnProperty;function xn(e){if(!Ct(e))return yn(e);var t=[];for(var n in Object(e))bn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function Sn(e){return xt(e)?_n(e):xn(e)}function Cn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var wn=Object.prototype.hasOwnProperty;function Tn(e){if(!ve(e))return Cn(e);var t=Ct(e),n=[];for(var r in e)(r!=`constructor`||!t&&wn.call(e,r))&&n.push(r);return n}function En(e){return xt(e)?_n(e,!0):Tn(e)}var Dn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,On=/^\w*$/;function kn(e,t){if(le(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||se(e)?!0:On.test(e)||!Dn.test(e)||t!=null&&e in Object(t)}var An=Ye(Object,`create`);function jn(){this.__data__=An?An(null):{},this.size=0}function Mn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Nn=`__lodash_hash_undefined__`,Pn=Object.prototype.hasOwnProperty;function Fn(e){var t=this.__data__;if(An){var n=t[e];return n===Nn?void 0:n}return Pn.call(t,e)?t[e]:void 0}var In=Object.prototype.hasOwnProperty;function Ln(e){var t=this.__data__;return An?t[e]!==void 0:In.call(t,e)}var Rn=`__lodash_hash_undefined__`;function zn(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=An&&t===void 0?Rn:t,this}function Bn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Bn.prototype.clear=jn,Bn.prototype.delete=Mn,Bn.prototype.get=Fn,Bn.prototype.has=Ln,Bn.prototype.set=zn;function Vn(){this.__data__=[],this.size=0}function Hn(e,t){for(var n=e.length;n--;)if(ht(e[n][0],t))return n;return-1}var Un=Array.prototype.splice;function Wn(e){var t=this.__data__,n=Hn(t,e);return n<0?!1:(n==t.length-1?t.pop():Un.call(t,n,1),--this.size,!0)}function Gn(e){var t=this.__data__,n=Hn(t,e);return n<0?void 0:t[n][1]}function Kn(e){return Hn(this.__data__,e)>-1}function qn(e,t){var n=this.__data__,r=Hn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function Jn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Jn.prototype.clear=Vn,Jn.prototype.delete=Wn,Jn.prototype.get=Gn,Jn.prototype.has=Kn,Jn.prototype.set=qn;var Yn=Ye(s,`Map`);function Xn(){this.size=0,this.__data__={hash:new Bn,map:new(Yn||Jn),string:new Bn}}function Zn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Qn(e,t){var n=e.__data__;return Zn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function $n(e){var t=Qn(this,e).delete(e);return this.size-=+!!t,t}function er(e){return Qn(this,e).get(e)}function tr(e){return Qn(this,e).has(e)}function nr(e,t){var n=Qn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function rr(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}rr.prototype.clear=Xn,rr.prototype.delete=$n,rr.prototype.get=er,rr.prototype.has=tr,rr.prototype.set=nr;var ir=`Expected a function`;function ar(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(ir);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],a=n.cache;if(a.has(i))return a.get(i);var o=e.apply(this,r);return n.cache=a.set(i,o)||a,o};return n.cache=new(ar.Cache||rr),n}ar.Cache=rr;var or=500;function sr(e){var t=ar(e,function(e){return n.size===or&&n.clear(),e}),n=t.cache;return t}var cr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,lr=/\\(\\)?/g,ur=sr(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(cr,function(e,n,r,i){t.push(r?i.replace(lr,`$1`):n||e)}),t});function dr(e){return e==null?``:pe(e)}function fr(e,t){return le(e)?e:kn(e,t)?[e]:ur(dr(e))}var pr=1/0;function mr(e){if(typeof e==`string`||se(e))return e;var t=e+``;return t==`0`&&1/e==-pr?`-0`:t}function hr(e,t){t=fr(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[mr(t[n++])];return n&&n==r?e:void 0}function gr(e,t,n){var r=e==null?void 0:hr(e,t);return r===void 0?n:r}function _r(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var vr=c?c.isConcatSpreadable:void 0;function yr(e){return le(e)||At(e)||!!(vr&&e&&e[vr])}function br(e,t,n,r,i){var a=-1,o=e.length;for(n||=yr,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?br(s,t-1,n,r,i):_r(i,s):r||(i[i.length]=s)}return i}function xr(e){return e!=null&&e.length?br(e,1):[]}function Sr(){this.__data__=new Jn,this.size=0}function Cr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function wr(e){return this.__data__.get(e)}function Tr(e){return this.__data__.has(e)}var Er=200;function Dr(e,t){var n=this.__data__;if(n instanceof Jn){var r=n.__data__;if(!Yn||r.length<Er-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new rr(r)}return n.set(e,t),this.size=n.size,this}function Or(e){var t=this.__data__=new Jn(e);this.size=t.size}Or.prototype.clear=Sr,Or.prototype.delete=Cr,Or.prototype.get=wr,Or.prototype.has=Tr,Or.prototype.set=Dr;function kr(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}function Ar(){return[]}var jr=Object.prototype.propertyIsEnumerable,Mr=Object.getOwnPropertySymbols,Nr=Mr?function(e){return e==null?[]:(e=Object(e),kr(Mr(e),function(t){return jr.call(e,t)}))}:Ar;function Pr(e,t,n){var r=t(e);return le(e)?r:_r(r,n(e))}function Fr(e){return Pr(e,Sn,Nr)}var Ir=Ye(s,`DataView`),Lr=Ye(s,`Promise`),Rr=Ye(s,`Set`),zr=`[object Map]`,Br=`[object Object]`,Vr=`[object Promise]`,Hr=`[object Set]`,Ur=`[object WeakMap]`,Wr=`[object DataView]`,Gr=ze(Ir),Kr=ze(Yn),qr=ze(Lr),Jr=ze(Rr),Yr=ze(Xe),Xr=ie;(Ir&&Xr(new Ir(new ArrayBuffer(1)))!=Wr||Yn&&Xr(new Yn)!=zr||Lr&&Xr(Lr.resolve())!=Vr||Rr&&Xr(new Rr)!=Hr||Xe&&Xr(new Xe)!=Ur)&&(Xr=function(e){var t=ie(e),n=t==Br?e.constructor:void 0,r=n?ze(n):``;if(r)switch(r){case Gr:return Wr;case Kr:return zr;case qr:return Vr;case Jr:return Hr;case Yr:return Ur}return t});var Zr=Xr,Qr=s.Uint8Array;function $r(e){for(var t=-1,n=e==null?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i}var ei=`__lodash_hash_undefined__`;function ti(e){return this.__data__.set(e,ei),this}function ni(e){return this.__data__.has(e)}function ri(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new rr;++t<n;)this.add(e[t])}ri.prototype.add=ri.prototype.push=ti,ri.prototype.has=ni;function ii(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function ai(e,t){return e.has(t)}var oi=1,si=2;function ci(e,t,n,r,i,a){var o=n&oi,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,p=n&si?new ri:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],ee=t[d];if(r)var te=o?r(ee,m,d,t,e,a):r(m,ee,d,e,t,a);if(te!==void 0){if(te)continue;f=!1;break}if(p){if(!ii(t,function(e,t){if(!ai(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===ee||i(m,ee,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}function li(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function ui(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var di=1,fi=2,pi=`[object Boolean]`,mi=`[object Date]`,hi=`[object Error]`,gi=`[object Map]`,_i=`[object Number]`,vi=`[object RegExp]`,yi=`[object Set]`,bi=`[object String]`,xi=`[object Symbol]`,Si=`[object ArrayBuffer]`,Ci=`[object DataView]`,wi=c?c.prototype:void 0,Ti=wi?wi.valueOf:void 0;function Ei(e,t,n,r,i,a,o){switch(n){case Ci:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Si:return!(e.byteLength!=t.byteLength||!a(new Qr(e),new Qr(t)));case pi:case mi:case _i:return ht(+e,+t);case hi:return e.name==t.name&&e.message==t.message;case vi:case bi:return e==t+``;case gi:var s=li;case yi:var c=r&di;if(s||=ui,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=fi,o.set(e,t);var u=ci(s(e),s(t),r,i,a,o);return o.delete(e),u;case xi:if(Ti)return Ti.call(e)==Ti.call(t)}return!1}var Di=1,Oi=Object.prototype.hasOwnProperty;function ki(e,t,n,r,i,a){var o=n&Di,s=Fr(e),c=s.length;if(c!=Fr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Oi.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var ee=e[u],te=t[u];if(r)var ne=o?r(te,ee,u,t,e,a):r(ee,te,u,e,t,a);if(!(ne===void 0?ee===te||i(ee,te,n,r,a):ne)){p=!1;break}m||=u==`constructor`}if(p&&!m){var re=e.constructor,ie=t.constructor;re!=ie&&`constructor`in e&&`constructor`in t&&!(typeof re==`function`&&re instanceof re&&typeof ie==`function`&&ie instanceof ie)&&(p=!1)}return a.delete(e),a.delete(t),p}var Ai=1,ji=`[object Arguments]`,Mi=`[object Array]`,Ni=`[object Object]`,Pi=Object.prototype.hasOwnProperty;function Fi(e,t,n,r,i,a){var o=le(e),s=le(t),c=o?Mi:Zr(e),l=s?Mi:Zr(t);c=c==ji?Ni:c,l=l==ji?Ni:l;var u=c==Ni,d=l==Ni,f=c==l;if(f&&Ft(e)){if(!Ft(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Or,o||hn(e)?ci(e,t,n,r,i,a):Ei(e,t,c,n,r,i,a);if(!(n&Ai)){var p=u&&Pi.call(e,`__wrapped__`),m=d&&Pi.call(t,`__wrapped__`);if(p||m){var ee=p?e.value():e,te=m?t.value():t;return a||=new Or,i(ee,te,n,r,a)}}return f?(a||=new Or,ki(e,t,n,r,i,a)):!1}function Ii(e,t,n,r,i){return e===t?!0:e==null||t==null||!ae(e)&&!ae(t)?e!==e&&t!==t:Fi(e,t,n,r,Ii,i)}var Li=1,Ri=2;function zi(e,t,n,r){var i=n.length,a=i,o=!r;if(e==null)return!a;for(e=Object(e);i--;){var s=n[i];if(o&&s[2]?s[1]!==e[s[0]]:!(s[0]in e))return!1}for(;++i<a;){s=n[i];var c=s[0],l=e[c],u=s[1];if(o&&s[2]){if(l===void 0&&!(c in e))return!1}else{var d=new Or;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Ii(u,l,Li|Ri,r,d):f))return!1}}return!0}function Bi(e){return e===e&&!ve(e)}function Vi(e){for(var t=Sn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Bi(i)]}return t}function Hi(e,t){return function(n){return n!=null&&n[e]===t&&(t!==void 0||e in Object(n))}}function Ui(e){var t=Vi(e);return t.length==1&&t[0][2]?Hi(t[0][0],t[0][1]):function(n){return n===e||zi(n,e,t)}}function Wi(e,t){return e!=null&&t in Object(e)}function Gi(e,t,n){t=fr(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=mr(t[r]);if(!(a=e!=null&&n(e,o)))break;e=e[o]}return a||++r!=i?a:(i=e==null?0:e.length,!!i&&bt(i)&&pt(o,i)&&(le(e)||At(e)))}function Ki(e,t){return e!=null&&Gi(e,t,Wi)}var qi=1,Ji=2;function Yi(e,t){return kn(e)&&Bi(t)?Hi(mr(e),t):function(n){var r=gr(n,e);return r===void 0&&r===t?Ki(n,e):Ii(t,r,qi|Ji)}}function Xi(e){return function(t){return t?.[e]}}function Zi(e){return function(t){return hr(t,e)}}function Qi(e){return kn(e)?Xi(mr(e)):Zi(e)}function $i(e){return typeof e==`function`?e:e==null?ke:typeof e==`object`?le(e)?Yi(e[0],e[1]):Ui(e):Qi(e)}function ea(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}function ta(e){return function(t,n,r){for(var i=-1,a=Object(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}var na=ta();function ra(e,t){return e&&na(e,t,Sn)}function ia(e,t){return function(n,r){if(n==null)return n;if(!xt(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var aa=ia(ra);function oa(e,t,n,r){return aa(e,function(e,i,a){t(r,e,n(e),a)}),r}function sa(e,t){return function(n,r){var i=le(n)?ea:oa,a=t?t():{};return i(n,e,$i(r,2),a)}}function ca(e){return ae(e)&&xt(e)}function la(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}var ua=200;function da(e,t,n,r){var i=-1,a=ut,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ce(t,ln(n))),r?(a=la,o=!1):t.length>=ua&&(a=ai,o=!1,t=new ri(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var fa=vt(function(e,t){return ca(e)?da(e,br(t,1,ca,!0)):[]});function h(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function pa(e){return typeof e==`function`?e:ke}function ma(e,t){var n=[];return aa(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ha(e,t){return(le(e)?kr:ma)(e,$i(t,3))}var ga=Math.max,_a=Math.min;function va(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Oe(n),i=n<0?ga(r+i,0):_a(i,r-1)),ot(e,$i(t,3),i,!0)}function ya(e){return e&&e.length?e[0]:void 0}function ba(e,t){var n=-1,r=xt(e)?Array(e.length):[];return aa(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function xa(e,t){return(le(e)?ce:ba)(e,$i(t,3))}function Sa(e,t){return br(xa(e,t),1)}function Ca(e,t){return e==null?e:na(e,pa(t),En)}var wa=Object.prototype.hasOwnProperty,Ta=sa(function(e,t,n){wa.call(e,n)?e[n].push(t):mt(e,n,[t])}),Ea=`[object Map]`,Da=`[object Set]`,Oa=Object.prototype.hasOwnProperty;function ka(e){if(e==null)return!0;if(xt(e)&&(le(e)||typeof e==`string`||typeof e.splice==`function`||Ft(e)||hn(e)||At(e)))return!e.length;var t=Zr(e);if(t==Ea||t==Da)return!e.size;if(Ct(e))return!xn(e).length;for(var n in e)if(Oa.call(e,n))return!1;return!0}var Aa=sa(function(e,t,n){mt(e,n,t)}),g=sa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),ja=Rr&&1/ui(new Rr([,-0]))[1]==1/0?function(e){return new Rr(e)}:Qe,Ma=200;function Na(e,t,n){var r=-1,i=ut,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=la;else if(a>=Ma){var l=t?null:ja(e);if(l)return ui(l);o=!1,i=ai,c=new ri}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}function Pa(e){return e&&e.length?Na(e):[]}function Fa(e,t){return e&&e.length?Na(e,$i(t,2)):[]}var Ia=Math.max;function La(e){if(!(e&&e.length))return[];var t=0;return e=kr(e,function(e){if(ca(e))return t=Ia(e.length,t),!0}),wt(t,function(t){return ce(e,Xi(t))})}var Ra=vt(La),_=function(e){return e.SPACE=`<space>`,e.TAB=`<tab>`,e.NEWLINE=`<newline>`,e.COMMA=`<comma>`,e.LPAREN=`<lparen>`,e.RPAREN=`<rparen>`,e.LBRACE=`<lbrace>`,e.RBRACE=`<rbrace>`,e.LBRACKET=`<lbracket>`,e.RBRACKET=`<rbracket>`,e.LANGLE=`<langle>`,e.RANGLE=`<rangle>`,e.OP=`<op>`,e.EOF=`<eof>`,e.NUMERIC_LITERAL=`<number>`,e.STRING_LITERAL=`<string>`,e.COLOR_LITERAL=`<color>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.QUOTED_STRING=`<variable>`,e.IDENTIFIER=`<identifier>`,e.SEMICOLON=`<semicolon>`,e.COLON=`<colon>`,e.SINGLE_LINE_COMMENT=`<single-line-comment>`,e.MULTILINE_COMMENT=`<multiline-comment>`,e.WILDCARD=`<wildcard>`,e}({});function za(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:return!0;default:return!1}}function Ba(e){if(!e)return!1;switch(e){case`+`:case`-`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`?`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function Va(e){return e!==void 0&&e.kind===`<op>`}var Ha=class e{constructor(e,t,n,r,i,a){this.kind=e,this.filepath=t,this.startPos=n,this.endPos=r,this.value=i,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=a,this.start=n.offset,this.end=r.offset}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}};function Ua(e){return e.trailingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0}function Wa(e,t){return t.leadingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0||Ua(e)}function Ga(e){return e.trailingTrivia.find(({kind:e})=>[_.SPACE,_.TAB].includes(e))!==void 0}function Ka(e){return e.trailingTrivia.length===0?e.end:Ka(h(e.trailingTrivia))}function qa(e){return e.leadingTrivia.length===0?e.start:qa(e.leadingTrivia[0])}function Ja(e){return[_.SINGLE_LINE_COMMENT,_.MULTILINE_COMMENT].includes(e.kind)}function Ya(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`as`}function Xa(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`use`}function Za(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`metadata`}function Qa(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`from`}function $a(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function eo(e){return!!e?.isInvalid}var to=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},no=/^[A-Za-z]:\//;function ro(e=``){return e&&e.replace(/\\/g,`/`).replace(no,e=>e.toUpperCase())}var io=/^[/\\]{2}/,ao=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,oo=/^[A-Za-z]:$/,so=/^\/([A-Za-z]:)?$/,co=/.(\.[^./]+|\.)$/,lo=/^[/\\]|^[a-zA-Z]:[/\\]/,uo=function(e){if(e.length===0)return`.`;e=ro(e);let t=e.match(io),n=go(e),r=e[e.length-1]===`/`;return e=ho(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),oo.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!go(e)?`/${e}`:e)},fo=function(...e){let t=``;for(let n of e)if(n){if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;t+=e&&r?n.slice(1):e||r?n:`/${n}`}else t+=n}return uo(t)};function po(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var mo=function(...e){e=e.map(e=>ro(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:po();i&&i.length!==0&&(t=`${i}/${t}`,n=go(i))}return t=ho(t,!n),n&&!go(t)?`/${t}`:t.length>0?t:`.`};function ho(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}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 go=function(e){return ao.test(e)},_o=function(e){if(e===`..`)return``;let t=co.exec(ro(e));return t&&t[1]||``},vo=function(e,t){let n=mo(e).replace(so,`$1`).split(`/`),r=mo(t).replace(so,`$1`).split(`/`);if(r[0][1]===`:`&&n[0][1]===`:`&&n[0]!==r[0])return r.join(`/`);let i=[...n];for(let e of i){if(r[0]!==e)break;n.shift(),r.shift()}return[...n.map(()=>`..`),...r].join(`/`)},yo=function(e){let t=ro(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&oo.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(go(e)?`/`:`.`)},bo=function(e,t){let n=ro(e).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return t&&r.endsWith(t)?r.slice(0,-t.length):r},xo=function(e){let t=lo.exec(e)?.[0]?.replace(/\\/g,`/`)||``,n=bo(e),r=_o(n);return{root:t,dir:yo(e),base:n,ext:r,name:n.slice(0,n.length-r.length)}},So=class e{constructor(e,t={}){let n=uo(e);if(!go(n))throw Error(`FilePath requires an absolute path, got: "${e}"`);let r=xo(n);this.root=r.root;let i=n.slice(this.root.length);this.segments=i?i.split(`/`).filter(Boolean):[],this.protocol=t.protocol?.replace(/:$/,``)}get path(){return this.segments.length>0?this.root+this.segments.join(`/`):this.root}intern(){return`filepath@${this.toKey()}`}static from(t){return new e(t)}static resolve(t,n){return new e(mo(t,n))}static fromUri(t){if(Co(t))return new e(t);try{let n=new URL(t),r=n.host?`/${n.host}${n.pathname}`:n.pathname,i=Co(r.slice(1))?r.slice(1):r;return new e(wo(i),{protocol:n.protocol})}catch{return new e(uo(t))}}get absolute(){return this.path}get fsPath(){return this.path}get dirname(){return yo(this.path)}get basename(){return bo(this.path)}get extname(){return _o(this.path)}resolve(t){return new e(mo(this.dirname,t))}join(...t){return new e(fo(this.path,...t))}relativeTo(e){let t=vo(e,this.path);return!t.startsWith(`./`)&&!t.startsWith(`../`)&&![`.`,`..`].includes(t)?`./${t}`:t}toKey(){return this.root+this.segments.map(encodeURIComponent).join(`/`)}equals(e){return this.toKey()===e.toKey()}isParentOf(e){if(this.path===e.path)return!1;let t=this.path.endsWith(`/`)?this.path:`${this.path}/`;return e.path.startsWith(t)}toUri(e={}){let t=e.protocol||this.protocol;if(!t)return this.path;let n=this.root+this.segments.map(encodeURIComponent).join(`/`);return(this.root.length>1?`${t}:///`:`${t}://`)+n}static isRelative(e){return!go(uo(e))}};function Co(e){return xo(uo(e)).root.length>1}function wo(e){let t=uo(e),{root:n}=xo(t),r=t.slice(n.length);return r?n+r.split(`/`).map(e=>{try{return decodeURIComponent(e)}catch{return e}}).join(`/`):n}var To=[`null`,`true`,`false`],Eo=`none`,Do=[`-`,`+`],v=`public`,Oo=So.from(`/main.dbml`),ko={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`])},Ao={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`])},jo={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},Mo={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`])},No={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`])},Po={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`])},Fo={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function Io(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function Lo(e,t){let n=Io(e);return t?ko[t].has(n):Object.values(ko).some(e=>e.has(n))}function Ro(e,t){let n=Io(e);return t?Ao[t].has(n):Object.values(Ao).some(e=>e.has(n))}function zo(e,t){return Lo(e,t)||Ro(e,t)}function Bo(e,t){let n=Io(e);return t?jo[t].has(n):Object.values(jo).some(e=>e.has(n))}function Vo(e,t){let n=Io(e);return t?Mo[t].has(n):Object.values(Mo).some(e=>e.has(n))}function Ho(e,t){let n=Io(e);return t?No[t].has(n):Object.values(No).some(e=>e.has(n))}function Uo(e,t){let n=Io(e);return t?Po[t].has(n):Object.values(Po).some(e=>e.has(n))}function Wo(e,t){let n=Io(e);return t?Fo[t].has(n):Object.values(Fo).some(e=>e.has(n))}function Go(e,t){if(t)return`string`;if(Lo(e))return`integer`;if(Ro(e))return`real`;if(Bo(e))return`bool`;if(Vo(e))return`string`;let n=Io(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:Uo(e)?`datetime`:e}var Ko=class extends Error{},qo=class extends Ko{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Jo=class extends Ko{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Yo=class extends Ko{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Xo=class extends Ko{},Zo=class extends Ko{constructor(e){super(`Invalid unit ${e}`)}},Qo=class extends Ko{},$o=class extends Ko{constructor(){super(`Zone is an abstract class`)}},y=`numeric`,es=`short`,ts=`long`,ns={year:y,month:y,day:y},rs={year:y,month:es,day:y},is={year:y,month:es,day:y,weekday:es},as={year:y,month:ts,day:y},os={year:y,month:ts,day:y,weekday:ts},ss={hour:y,minute:y},cs={hour:y,minute:y,second:y},ls={hour:y,minute:y,second:y,timeZoneName:es},us={hour:y,minute:y,second:y,timeZoneName:ts},ds={hour:y,minute:y,hourCycle:`h23`},fs={hour:y,minute:y,second:y,hourCycle:`h23`},ps={hour:y,minute:y,second:y,hourCycle:`h23`,timeZoneName:es},ms={hour:y,minute:y,second:y,hourCycle:`h23`,timeZoneName:ts},hs={year:y,month:y,day:y,hour:y,minute:y},gs={year:y,month:y,day:y,hour:y,minute:y,second:y},_s={year:y,month:es,day:y,hour:y,minute:y},vs={year:y,month:es,day:y,hour:y,minute:y,second:y},ys={year:y,month:es,day:y,weekday:es,hour:y,minute:y},bs={year:y,month:ts,day:y,hour:y,minute:y,timeZoneName:es},xs={year:y,month:ts,day:y,hour:y,minute:y,second:y,timeZoneName:es},Ss={year:y,month:ts,day:y,weekday:ts,hour:y,minute:y,timeZoneName:ts},Cs={year:y,month:ts,day:y,weekday:ts,hour:y,minute:y,second:y,timeZoneName:ts},ws=class{get type(){throw new $o}get name(){throw new $o}get ianaName(){return this.name}get isUniversal(){throw new $o}offsetName(e,t){throw new $o}formatOffset(e,t){throw new $o}offset(e){throw new $o}equals(e){throw new $o}get isValid(){throw new $o}},Ts=null,Es=class e extends ws{static get instance(){return Ts===null&&(Ts=new e),Ts}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return pl(e,t,n)}formatOffset(e,t){return _l(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},Ds=new Map;function Os(e){let t=Ds.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`}),Ds.set(e,t)),t}var ks={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function As(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 js(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=ks[t];t===`era`?r[a]=i:b(a)||(r[a]=parseInt(i,10))}return r}var Ms=new Map,Ns=class e extends ws{static create(t){let n=Ms.get(t);return n===void 0&&Ms.set(t,n=new e(t)),n}static resetCache(){Ms.clear(),Ds.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 pl(e,t,n,this.name)}formatOffset(e,t){return _l(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=Os(this.name),[r,i,a,o,s,c,l]=n.formatToParts?js(n,t):As(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=ll({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)/6e4}equals(e){return e.type===`iana`&&e.name===this.name}get isValid(){return this.valid}},Ps={};function Fs(e,t={}){let n=JSON.stringify([e,t]),r=Ps[n];return r||(r=new Intl.ListFormat(e,t),Ps[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.DateTimeFormat(e,t),Is.set(n,r)),r}var Rs=new Map;function zs(e,t={}){let n=JSON.stringify([e,t]),r=Rs.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Rs.set(n,r)),r}var Bs=new Map;function Vs(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=Bs.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),Bs.set(i,a)),a}var Hs=null;function Us(){return Hs||(Hs=new Intl.DateTimeFormat().resolvedOptions().locale,Hs)}var Ws=new Map;function Gs(e){let t=Ws.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Ws.set(e,t)),t}var Ks=new Map;function qs(e){let t=Ks.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...rc,...t}),Ks.set(e,t)}return t}function Js(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=Ls(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=Ls(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Ys(e,t,n){return(n||t)&&(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`)),e}function Xs(e){let t=[];for(let n=1;n<=12;n++){let r=S.utc(2009,n,1);t.push(e(r))}return t}function Zs(e){let t=[];for(let n=1;n<=7;n++){let r=S.utc(2016,11,13+n);t.push(e(r))}return t}function Qs(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function $s(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Gs(e.locale).numberingSystem===`latn`}var ec=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=zs(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}return tl(this.floor?Math.floor(e):al(e,3),this.padTo)}},tc=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&&Ns.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=Ls(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}}return e}):e}resolvedOptions(){return this.dtf.resolvedOptions()}},nc=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Kc()&&(this.rtf=Vs(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):Il(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},rc={firstDay:1,minimalDays:4,weekend:[6,7]},ic=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||wc.defaultLocale,s=o||(a?`en-US`:Us()),c=n||wc.defaultNumberingSystem,l=r||wc.defaultOutputCalendar,u=Qc(i)||wc.defaultWeekSettings;return new e(s,c,l,u,o)}static resetCache(){Hs=null,Is.clear(),Rs.clear(),Bs.clear(),Ws.clear(),Ks.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]=Js(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Ys(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??=$s(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,Qc(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 Qs(this,e,Sl,()=>{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]=Xs(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Qs(this,e,El,()=>{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]=Zs(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Qs(this,void 0,()=>Dl,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[S.utc(2016,11,13,9),S.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Qs(this,e,jl,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[S.utc(-40,1,1),S.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 ec(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new tc(e,this.intl,t)}relFormatter(e={}){return new nc(this.intl,this.isEnglish(),e)}listFormatter(e={}){return Fs(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Gs(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:qc()?qs(this.locale):rc}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})`}},ac=null,oc=class e extends ws{static get utcInstance(){return ac===null&&(ac=new e(0)),ac}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(ml(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${_l(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${_l(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return _l(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}},sc=class extends ws{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 cc(e,t){if(b(e)||e===null)return t;if(e instanceof ws)return e;if(Wc(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?Es.instance:n===`utc`||n===`gmt`?oc.utcInstance:oc.parseSpecifier(n)||Ns.create(e)}return Hc(e)?oc.instance(e):typeof e==`object`&&`offset`in e&&typeof e.offset==`function`?e:new sc(e)}var lc={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},uc={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]},dc=lc.hanidec.replace(/[\[|\]]/g,``).split(``);function fc(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(lc.hanidec)!==-1)t+=dc.indexOf(e[n]);else for(let e in uc){let[n,i]=uc[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}return t}var pc=new Map;function mc(){pc.clear()}function hc({numberingSystem:e},t=``){let n=e||`latn`,r=pc.get(n);r===void 0&&(r=new Map,pc.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${lc[n]}${t}`),r.set(t,i)),i}var gc=()=>Date.now(),_c=`system`,vc=null,yc=null,bc=null,xc=60,Sc,Cc=null,wc=class{static get now(){return gc}static set now(e){gc=e}static set defaultZone(e){_c=e}static get defaultZone(){return cc(_c,Es.instance)}static get defaultLocale(){return vc}static set defaultLocale(e){vc=e}static get defaultNumberingSystem(){return yc}static set defaultNumberingSystem(e){yc=e}static get defaultOutputCalendar(){return bc}static set defaultOutputCalendar(e){bc=e}static get defaultWeekSettings(){return Cc}static set defaultWeekSettings(e){Cc=Qc(e)}static get twoDigitCutoffYear(){return xc}static set twoDigitCutoffYear(e){xc=e%100}static get throwOnInvalid(){return Sc}static set throwOnInvalid(e){Sc=e}static resetCaches(){ic.resetCache(),Ns.resetCache(),S.resetCache(),mc()}},Tc=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},Ec=[0,31,59,90,120,151,181,212,243,273,304,334],Dc=[0,31,60,91,121,152,182,213,244,274,305,335];function Oc(e,t){return new Tc(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function kc(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 Ac(e,t,n){return n+(ol(e)?Dc:Ec)[t-1]}function jc(e,t){let n=ol(e)?Dc:Ec,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function Mc(e,t){return(e-t+7)%7+1}function Nc(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Ac(r,i,a),s=Mc(kc(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=dl(l,t,n)):c>dl(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...vl(e)}}function Pc(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=Mc(kc(r,1,t),n),s=sl(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=sl(l)):c>s?(l=r+1,c-=sl(r)):l=r;let{month:u,day:d}=jc(l,c);return{year:l,month:u,day:d,...vl(e)}}function Fc(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Ac(t,n,r),...vl(e)}}function Ic(e){let{year:t,ordinal:n}=e,{month:r,day:i}=jc(t,n);return{year:t,month:r,day:i,...vl(e)}}function Lc(e,t){if(!b(e.localWeekday)||!b(e.localWeekNumber)||!b(e.localWeekYear)){if(!b(e.weekday)||!b(e.weekNumber)||!b(e.weekYear))throw new Xo(`Cannot mix locale-based week fields with ISO-based week fields`);return b(e.localWeekday)||(e.weekday=e.localWeekday),b(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),b(e.localWeekYear)||(e.weekYear=e.localWeekYear),delete e.localWeekday,delete e.localWeekNumber,delete e.localWeekYear,{minDaysInFirstWeek:t.getMinDaysInFirstWeek(),startOfWeek:t.getStartOfWeek()}}return{minDaysInFirstWeek:4,startOfWeek:1}}function Rc(e,t=4,n=1){let r=Uc(e.weekYear),i=$c(e.weekNumber,1,dl(e.weekYear,t,n)),a=$c(e.weekday,1,7);return r?i?!a&&Oc(`weekday`,e.weekday):Oc(`week`,e.weekNumber):Oc(`weekYear`,e.weekYear)}function zc(e){let t=Uc(e.year),n=$c(e.ordinal,1,sl(e.year));return t?!n&&Oc(`ordinal`,e.ordinal):Oc(`year`,e.year)}function Bc(e){let t=Uc(e.year),n=$c(e.month,1,12),r=$c(e.day,1,cl(e.year,e.month));return t?n?!r&&Oc(`day`,e.day):Oc(`month`,e.month):Oc(`year`,e.year)}function Vc(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=$c(t,0,23)||t===24&&n===0&&r===0&&i===0,o=$c(n,0,59),s=$c(r,0,59),c=$c(i,0,999);return a?o?s?!c&&Oc(`millisecond`,i):Oc(`second`,r):Oc(`minute`,n):Oc(`hour`,t)}function b(e){return e===void 0}function Hc(e){return typeof e==`number`}function Uc(e){return typeof e==`number`&&e%1==0}function Wc(e){return typeof e==`string`}function Gc(e){return Object.prototype.toString.call(e)===`[object Date]`}function Kc(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function qc(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Jc(e){return Array.isArray(e)?e:[e]}function Yc(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 Xc(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Zc(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Qc(e){if(e==null)return null;if(typeof e!=`object`)throw new Qo(`Week settings must be an object`);if(!$c(e.firstDay,1,7)||!$c(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!$c(e,1,7)))throw new Qo(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function $c(e,t,n){return Uc(e)&&e>=t&&e<=n}function el(e,t){return e-t*Math.floor(e/t)}function tl(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function nl(e){if(!(b(e)||e===null||e===``))return parseInt(e,10)}function rl(e){if(!(b(e)||e===null||e===``))return parseFloat(e)}function il(e){if(!(b(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function al(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 ol(e){return e%4==0&&(e%100!=0||e%400==0)}function sl(e){return ol(e)?366:365}function cl(e,t){let n=el(t-1,12)+1,r=e+(t-n)/12;return n===2?ol(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function ll(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 ul(e,t,n){return-Mc(kc(e,1,t),n)+t-1}function dl(e,t=4,n=1){let r=ul(e,t,n),i=ul(e+1,t,n);return(sl(e)-r+i)/7}function fl(e){return e>99?e:e>wc.twoDigitCutoffYear?1900+e:2e3+e}function pl(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 ml(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 hl(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Qo(`Invalid unit value ${e}`);return t}function gl(e,t){let n={};for(let r in e)if(Zc(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=hl(i)}return n}function _l(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}${tl(n,2)}:${tl(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${tl(n,2)}${tl(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function vl(e){return Xc(e,[`hour`,`minute`,`second`,`millisecond`])}var yl=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],bl=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],xl=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];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`,`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 Cl=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],wl=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Tl=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function El(e){switch(e){case`narrow`:return[...Tl];case`short`:return[...wl];case`long`:return[...Cl];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var Dl=[`AM`,`PM`],Ol=[`Before Christ`,`Anno Domini`],kl=[`BC`,`AD`],Al=[`B`,`A`];function jl(e){switch(e){case`narrow`:return[...Al];case`short`:return[...kl];case`long`:return[...Ol];default:return null}}function Ml(e){return Dl[e.hour<12?0:1]}function Nl(e,t){return El(t)[e.weekday-1]}function Pl(e,t){return Sl(t)[e.month-1]}function Fl(e,t){return jl(t)[e.year<0?0:1]}function Il(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 Ll(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var Rl={D:ns,DD:rs,DDD:as,DDDD:os,t:ss,tt:cs,ttt:ls,tttt:us,T:ds,TT:fs,TTT:ps,TTTT:ms,f:hs,ff:_s,fff:bs,ffff:Ss,F:gs,FF:vs,FFF:xs,FFFF:Cs},zl=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 Rl[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 tl(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?Ml(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?Pl(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?Nl(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?Fl(t,e):a({era:e},`era`);return Ll(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)}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 Ll(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Bl=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Vl(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Hl(...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 Ul(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 Wl(...e){return(t,n)=>{let r={},i=0;for(;i<e.length;i++)r[e[i]]=nl(t[n+i]);return[r,null,n+i]}}var Gl=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Kl=`(?:${Gl.source}?(?:\\[(${Bl.source})\\])?)?`,ql=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Jl=RegExp(`${ql.source}${Kl}`),Yl=RegExp(`(?:[Tt]${Jl.source})?`),Xl=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Zl=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Ql=/(\d{4})-?(\d{3})/,$l=Wl(`weekYear`,`weekNumber`,`weekDay`),eu=Wl(`year`,`ordinal`),tu=/(\d{4})-(\d\d)-(\d\d)/,nu=RegExp(`${ql.source} ?(?:${Gl.source}|(${Bl.source}))?`),ru=RegExp(`(?: ${nu.source})?`);function iu(e,t,n){let r=e[t];return b(r)?n:nl(r)}function au(e,t){return[{year:iu(e,t),month:iu(e,t+1,1),day:iu(e,t+2,1)},null,t+3]}function ou(e,t){return[{hours:iu(e,t,0),minutes:iu(e,t+1,0),seconds:iu(e,t+2,0),milliseconds:il(e[t+3])},null,t+4]}function su(e,t){let n=!e[t]&&!e[t+1],r=ml(e[t+1],e[t+2]);return[{},n?null:oc.instance(r),t+3]}function cu(e,t){return[{},e[t]?Ns.create(e[t]):null,t+1]}var lu=RegExp(`^T?${ql.source}$`),uu=/^-?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 du(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(rl(n)),months:f(rl(r)),weeks:f(rl(i)),days:f(rl(a)),hours:f(rl(o)),minutes:f(rl(s)),seconds:f(rl(c),c===`-0`),milliseconds:f(il(l),d)}]}var fu={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function pu(e,t,n,r,i,a,o){let s={year:t.length===2?fl(nl(t)):nl(t),month:bl.indexOf(n)+1,day:nl(r),hour:nl(i),minute:nl(a)};return o&&(s.second=nl(o)),e&&(s.weekday=e.length>3?Cl.indexOf(e)+1:wl.indexOf(e)+1),s}var mu=/^(?:(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 hu(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=pu(t,i,r,n,a,o,s),p;return p=c?fu[c]:l?0:ml(u,d),[f,new oc(p)]}function gu(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var _u=/^(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$/,vu=/^(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$/,yu=/^(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 bu(e){let[,t,n,r,i,a,o,s]=e;return[pu(t,i,r,n,a,o,s),oc.utcInstance]}function xu(e){let[,t,n,r,i,a,o,s]=e;return[pu(t,s,n,r,i,a,o),oc.utcInstance]}var Su=Vl(Xl,Yl),Cu=Vl(Zl,Yl),wu=Vl(Ql,Yl),Tu=Vl(Jl),Eu=Hl(au,ou,su,cu),Du=Hl($l,ou,su,cu),Ou=Hl(eu,ou,su,cu),ku=Hl(ou,su,cu);function Au(e){return Ul(e,[Su,Eu],[Cu,Du],[wu,Ou],[Tu,ku])}function ju(e){return Ul(gu(e),[mu,hu])}function Mu(e){return Ul(e,[_u,bu],[vu,bu],[yu,xu])}function Nu(e){return Ul(e,[uu,du])}var Pu=Hl(ou);function Fu(e){return Ul(e,[lu,Pu])}var Iu=Vl(tu,ru),Lu=Vl(nu),Ru=Hl(ou,su,cu);function zu(e){return Ul(e,[Iu,Eu],[Lu,Ru])}var Bu=`Invalid Duration`,Vu={weeks:{days:7,hours:168,minutes:10080,seconds:604800,milliseconds:6048e5},days:{hours:24,minutes:1440,seconds:86400,milliseconds:864e5},hours:{minutes:60,seconds:3600,milliseconds:36e5},minutes:{seconds:60,milliseconds:6e4},seconds:{milliseconds:1e3}},Hu={years:{quarters:4,months:12,weeks:52,days:365,hours:8760,minutes:525600,seconds:31536e3,milliseconds:31536e6},quarters:{months:3,weeks:13,days:91,hours:2184,minutes:131040,seconds:7862400,milliseconds:78624e5},months:{weeks:4,days:30,hours:720,minutes:43200,seconds:2592e3,milliseconds:2592e6},...Vu},Uu=146097/400,Wu=146097/4800,Gu={years:{quarters:4,months:12,weeks:Uu/7,days:Uu,hours:Uu*24,minutes:Uu*24*60,seconds:Uu*24*60*60,milliseconds:Uu*24*60*60*1e3},quarters:{months:3,weeks:Uu/28,days:Uu/4,hours:Uu*24/4,minutes:Uu*24*60/4,seconds:Uu*24*60*60/4,milliseconds:Uu*24*60*60*1e3/4},months:{weeks:Wu/7,days:Wu,hours:Wu*24,minutes:Wu*24*60,seconds:Wu*24*60*60,milliseconds:Wu*24*60*60*1e3},...Vu},Ku=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],qu=Ku.slice(0).reverse();function Ju(e,t,n=!1){return new Qu({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 Yu(e,t){let n=t.milliseconds??0;for(let r of qu.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Xu(e,t){let n=Yu(e,t)<0?-1:1;Ku.reduceRight((r,i)=>{if(b(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),Ku.reduce((n,r)=>{if(b(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Zu(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Qu=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Gu:Hu;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||ic.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 Qo(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:gl(t,e.normalizeUnit),loc:ic.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Hc(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Qo(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=Nu(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static fromISOTime(t,n){let[r]=Fu(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 Qo(`need to specify a reason the Duration is invalid`);let r=t instanceof Tc?t:new Tc(t,n);if(wc.throwOnInvalid)throw new Yo(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 Zo(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?zl.create(this.loc,n).formatDurationFromString(this,e):Bu}toHuman(e={}){if(!this.isValid)return Bu;let t=e.showZeros!==!1,n=Ku.map(n=>{let r=this.values[n];return b(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+=al(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},S.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?Yu(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 Ku)(Zc(n.values,e)||Zc(this.values,e))&&(r[e]=n.get(e)+this.get(e));return Ju(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]=hl(e(this.values[n],n));return Ju(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...gl(t,e.normalizeUnit)};return Ju(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 Ju(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Xu(this.matrix,e),Ju(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Zu(this.normalize().shiftToAll().toObject());return Ju(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 Ku)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;Hc(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Hc(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 Xu(this.matrix,n),Ju(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 Ju(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Zu(this.values);return Ju(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 Ku)if(!t(this.values[n],e.values[n]))return!1;return!0}},$u=`Invalid Interval`;function ed(e,t){return!e||!e.isValid?td.invalid(`missing or invalid start`):!t||!t.isValid?td.invalid(`missing or invalid end`):t<e?td.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 td=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 Qo(`need to specify a reason the Interval is invalid`);let r=t instanceof Tc?t:new Tc(t,n);if(wc.throwOnInvalid)throw new Jo(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=rf(t),i=rf(n);return ed(r,i)??new e({start:r,end:i})}static after(t,n){let r=Qu.fromDurationLike(n),i=rf(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Qu.fromDurationLike(n),i=rf(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=S.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=S.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Qu.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Qu.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(rf).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=Qu.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()})`:$u}[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=ns,t={}){return this.isValid?zl.create(this.s.loc.clone(t),e).formatInterval(this):$u}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:$u}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:$u}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:$u}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:$u}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Qu.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},nd=class{static hasDST(e=wc.defaultZone){let t=S.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return Ns.isValidZone(e)}static normalizeZone(e){return cc(e,wc.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||ic.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||ic.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||ic.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||ic.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||ic.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||ic.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||ic.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return ic.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return ic.create(t,null,`gregory`).eras(e)}static features(){return{relative:Kc(),localeWeek:qc()}}};function rd(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Qu.fromMillis(r).as(`days`))}function id(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=rd(e,t);return(n-n%7)/7}],[`days`,rd]],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 ad(e,t,n,r){let[i,a,o,s]=id(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=Qu.fromObject(a,r);return l.length>0?Qu.fromMillis(c,r).shiftTo(...l).plus(u):u}var od=`missing Intl.DateTimeFormat.formatToParts support`;function x(e,t=e=>e){return{regex:e,deser:([e])=>t(fc(e))}}var sd=`[ \xA0]`,cd=new RegExp(sd,`g`);function ld(e){return e.replace(/\./g,`\\.?`).replace(cd,sd)}function ud(e){return e.replace(/\./g,``).replace(cd,` `).toLowerCase()}function dd(e,t){return e===null?null:{regex:RegExp(e.map(ld).join(`|`)),deser:([n])=>e.findIndex(e=>ud(n)===ud(e))+t}}function fd(e,t){return{regex:e,deser:([,e,t])=>ml(e,t),groups:t}}function pd(e){return{regex:e,deser:([e])=>e}}function md(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function hd(e,t){let n=hc(t),r=hc(t,`{2}`),i=hc(t,`{3}`),a=hc(t,`{4}`),o=hc(t,`{6}`),s=hc(t,`{1,2}`),c=hc(t,`{1,3}`),l=hc(t,`{1,6}`),u=hc(t,`{1,9}`),d=hc(t,`{2,4}`),f=hc(t,`{4,6}`),p=e=>({regex:RegExp(md(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return dd(t.eras(`short`),0);case`GG`:return dd(t.eras(`long`),0);case`y`:return x(l);case`yy`:return x(d,fl);case`yyyy`:return x(a);case`yyyyy`:return x(f);case`yyyyyy`:return x(o);case`M`:return x(s);case`MM`:return x(r);case`MMM`:return dd(t.months(`short`,!0),1);case`MMMM`:return dd(t.months(`long`,!0),1);case`L`:return x(s);case`LL`:return x(r);case`LLL`:return dd(t.months(`short`,!1),1);case`LLLL`:return dd(t.months(`long`,!1),1);case`d`:return x(s);case`dd`:return x(r);case`o`:return x(c);case`ooo`:return x(i);case`HH`:return x(r);case`H`:return x(s);case`hh`:return x(r);case`h`:return x(s);case`mm`:return x(r);case`m`:return x(s);case`q`:return x(s);case`qq`:return x(r);case`s`:return x(s);case`ss`:return x(r);case`S`:return x(c);case`SSS`:return x(i);case`u`:return pd(u);case`uu`:return pd(s);case`uuu`:return x(n);case`a`:return dd(t.meridiems(),0);case`kkkk`:return x(a);case`kk`:return x(d,fl);case`W`:return x(s);case`WW`:return x(r);case`E`:case`c`:return x(n);case`EEE`:return dd(t.weekdays(`short`,!1),1);case`EEEE`:return dd(t.weekdays(`long`,!1),1);case`ccc`:return dd(t.weekdays(`short`,!0),1);case`cccc`:return dd(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return fd(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return fd(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return pd(/[a-z_+-/]{1,256}?/i);case` `:return pd(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:od};return m.token=e,m}var gd={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 _d(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=gd[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function vd(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function yd(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Zc(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]}return[r,{}]}function bd(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 b(e.z)||(n=Ns.create(e.z)),b(e.Z)||(n||=new oc(e.Z),r=e.Z),b(e.q)||(e.M=(e.q-1)*3+1),b(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),b(e.u)||(e.S=il(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var xd=null;function Sd(){return xd||=S.fromMillis(1555555555555),xd}function Cd(e,t){if(e.literal)return e;let n=Od(zl.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function wd(e,t){return Array.prototype.concat(...e.map(e=>Cd(e,t)))}var Td=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=wd(zl.parseFormat(t),e),this.units=this.tokens.map(t=>hd(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=vd(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=yd(e,this.regex,this.handlers),[r,i,a]=n?bd(n):[null,null,void 0];if(Zc(n,`a`)&&Zc(n,`H`))throw new Xo(`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}}return{input:e,tokens:this.tokens,invalidReason:this.invalidReason}}get isValid(){return!this.disqualifyingUnit}get invalidReason(){return this.disqualifyingUnit?this.disqualifyingUnit.invalidReason:null}};function Ed(e,t,n){return new Td(e,n).explainFromTokens(t)}function Dd(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=Ed(e,t,n);return[r,i,a,o]}function Od(e,t){if(!e)return null;let n=zl.create(t,e).dtFormatter(Sd()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>_d(t,e,i))}var kd=`Invalid DateTime`,Ad=864e13;function jd(e){return new Tc(`unsupported zone`,`the zone "${e.name}" is not supported`)}function Md(e){return e.weekData===null&&(e.weekData=Nc(e.c)),e.weekData}function Nd(e){return e.localWeekData===null&&(e.localWeekData=Nc(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function Pd(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new S({...n,...t,old:n})}function Fd(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 Id(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 Ld(e,t,n){return Fd(ll(e),t,n)}function Rd(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,cl(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Qu.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]=Fd(ll(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function zd(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=S.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}return S.invalid(new Tc(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function Bd(e,t,n=!0){return e.isValid?zl.create(ic.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function Vd(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=tl(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=tl(e.c.month),n===`month`)return i;i+=`-`}else if(i+=tl(e.c.month),n===`month`)return i;return i+=tl(e.c.day),i}function Hd(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+=tl(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=tl(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=tl(e.c.second))}else{if(c+=tl(e.c.minute),o===`minute`)break;s&&(c+=tl(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=tl(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=tl(Math.trunc(-e.o/60)),c+=`:`,c+=tl(Math.trunc(-e.o%60))):(c+=`+`,c+=tl(Math.trunc(e.o/60)),c+=`:`,c+=tl(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Ud={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Wd={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Gd={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Kd=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],qd=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],Jd=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function Yd(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 Zo(e);return t}function Xd(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return Yd(e)}}function Zd(e){if(tf===void 0&&(tf=wc.now()),e.type!==`iana`)return e.offset(tf);let t=e.name,n=nf.get(t);return n===void 0&&(n=e.offset(tf),nf.set(t,n)),n}function Qd(e,t){let n=cc(t.zone,wc.defaultZone);if(!n.isValid)return S.invalid(jd(n));let r=ic.fromObject(t),i,a;if(b(e.year))i=wc.now();else{for(let t of Kd)b(e[t])&&(e[t]=Ud[t]);let t=Bc(e)||Vc(e);if(t)return S.invalid(t);let r=Zd(n);[i,a]=Ld(e,r,n)}return new S({ts:i,zone:n,loc:r,o:a})}function $d(e,t,n){let r=b(n.round)?!0:n.round,i=b(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=al(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 ef(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 tf,nf=new Map,S=class e{constructor(e){let t=e.zone||wc.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new Tc(`invalid input`):null)||(t.isValid?null:jd(t));this.ts=b(e.ts)?wc.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=Hc(e.o)&&!e.old?e.o:t.offset(this.ts);r=Id(this.ts,a),n=Number.isNaN(r.year)?new Tc(`invalid input`):null,r=n?null:r,i=n?null:a}}this._zone=t,this.loc=e.loc||ic.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]=ef(arguments),[n,r,i,a,o,s,c]=t;return Qd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=ef(arguments),[n,r,i,a,o,s,c]=t;return e.zone=oc.utcInstance,Qd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Gc(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=cc(n.zone,wc.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:ic.fromObject(n)}):e.invalid(jd(i))}static fromMillis(t,n={}){if(!Hc(t))throw new Qo(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>Ad?e.invalid(`Timestamp out of range`):new e({ts:t,zone:cc(n.zone,wc.defaultZone),loc:ic.fromObject(n)})}static fromSeconds(t,n={}){if(Hc(t))return new e({ts:t*1e3,zone:cc(n.zone,wc.defaultZone),loc:ic.fromObject(n)});throw new Qo(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=cc(n.zone,wc.defaultZone);if(!r.isValid)return e.invalid(jd(r));let i=ic.fromObject(n),a=gl(t,Xd),{minDaysInFirstWeek:o,startOfWeek:s}=Lc(a,i),c=wc.now(),l=b(n.specificOffset)?r.offset(c):n.specificOffset,u=!b(a.ordinal),d=!b(a.year),f=!b(a.month)||!b(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new Xo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Xo(`Can't mix ordinal dates with month/day`);let ee=m||a.weekday&&!p,te,ne,re=Id(c,l);ee?(te=qd,ne=Wd,re=Nc(re,o,s)):u?(te=Jd,ne=Gd,re=Fc(re)):(te=Kd,ne=Ud);let ie=!1;for(let e of te){let t=a[e];b(t)?a[e]=ie?ne[e]:re[e]:ie=!0}let ae=(ee?Rc(a,o,s):u?zc(a):Bc(a))||Vc(a);if(ae)return e.invalid(ae);let[oe,se]=Ld(ee?Pc(a,o,s):u?Ic(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]=Au(e);return zd(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=ju(e);return zd(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=Mu(e);return zd(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(b(t)||b(n))throw new Qo(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=Dd(ic.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):zd(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]=zu(e);return zd(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Qo(`need to specify a reason the DateTime is invalid`);let r=t instanceof Tc?t:new Tc(t,n);if(wc.throwOnInvalid)throw new qo(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=Od(e,ic.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return wd(zl.parseFormat(e),ic.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){tf=void 0,nf.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?Md(this).weekYear:NaN}get weekNumber(){return this.isValid?Md(this).weekNumber:NaN}get weekday(){return this.isValid?Md(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?Nd(this).weekday:NaN}get localWeekNumber(){return this.isValid?Nd(this).weekNumber:NaN}get localWeekYear(){return this.isValid?Nd(this).weekYear:NaN}get ordinal(){return this.isValid?Fc(this.c).ordinal:NaN}get monthShort(){return this.isValid?nd.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?nd.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?nd.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?nd.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=ll(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=Id(s,a),u=Id(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[Pd(this,{ts:s}),Pd(this,{ts:c})]:[this]}get isInLeapYear(){return ol(this.year)}get daysInMonth(){return cl(this.year,this.month)}get daysInYear(){return this.isValid?sl(this.year):NaN}get weeksInWeekYear(){return this.isValid?dl(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?dl(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=zl.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(oc.instance(e),t)}toLocal(){return this.setZone(wc.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=cc(t,wc.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]=Ld(r,n,t)}return Pd(this,{ts:e,zone:t})}return e.invalid(jd(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return Pd(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=gl(e,Xd),{minDaysInFirstWeek:n,startOfWeek:r}=Lc(t,this.loc),i=!b(t.weekYear)||!b(t.weekNumber)||!b(t.weekday),a=!b(t.ordinal),o=!b(t.year),s=!b(t.month)||!b(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new Xo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Xo(`Can't mix ordinal dates with month/day`);let u;i?u=Pc({...Nc(this.c,n,r),...t},n,r):b(t.ordinal)?(u={...this.toObject(),...t},b(t.day)&&(u.day=Math.min(cl(u.year,u.month),u.day))):u=Ic({...Fc(this.c),...t});let[d,f]=Ld(u,this.o,this.zone);return Pd(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Qu.fromDurationLike(e);return Pd(this,Rd(this,t))}minus(e){if(!this.isValid)return this;let t=Qu.fromDurationLike(e).negate();return Pd(this,Rd(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Qu.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}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?zl.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):kd}toLocaleString(e=ns,t={}){return this.isValid?zl.create(this.loc.clone(t),e).formatDateTime(this):kd}toLocaleParts(e={}){return this.isValid?zl.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=Yd(a);let o=e===`extended`,s=Vd(this,o,a);return Kd.indexOf(a)>=3&&(s+=`T`),s+=Hd(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?Vd(this,e===`extended`,Yd(t)):null}toISOWeekDate(){return Bd(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=Yd(o),(r&&Kd.indexOf(o)>=3?`T`:``)+Hd(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return Bd(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return Bd(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?Vd(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`)),Bd(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():kd}[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 Qu.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Jc(t).map(Qu.normalizeUnit),a=e.valueOf()>this.valueOf(),o=ad(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?td.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),$d(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?$d(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 Qo(`min requires all arguments be DateTimes`);return Yc(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Qo(`max requires all arguments be DateTimes`);return Yc(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return Ed(ic.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 Td(ic.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(b(t)||b(n))throw new Qo(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=ic.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Qo(`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):zd(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return ns}static get DATE_MED(){return rs}static get DATE_MED_WITH_WEEKDAY(){return is}static get DATE_FULL(){return as}static get DATE_HUGE(){return os}static get TIME_SIMPLE(){return ss}static get TIME_WITH_SECONDS(){return cs}static get TIME_WITH_SHORT_OFFSET(){return ls}static get TIME_WITH_LONG_OFFSET(){return us}static get TIME_24_SIMPLE(){return ds}static get TIME_24_WITH_SECONDS(){return fs}static get TIME_24_WITH_SHORT_OFFSET(){return ps}static get TIME_24_WITH_LONG_OFFSET(){return ms}static get DATETIME_SHORT(){return hs}static get DATETIME_SHORT_WITH_SECONDS(){return gs}static get DATETIME_MED(){return _s}static get DATETIME_MED_WITH_SECONDS(){return vs}static get DATETIME_MED_WITH_WEEKDAY(){return ys}static get DATETIME_FULL(){return bs}static get DATETIME_FULL_WITH_SECONDS(){return xs}static get DATETIME_HUGE(){return Ss}static get DATETIME_HUGE_WITH_SECONDS(){return Cs}};function rf(e){if(S.isDateTime(e))return e;if(e&&e.valueOf&&Hc(e.valueOf()))return S.fromJSDate(e);if(e&&typeof e==`object`)return S.fromObject(e);throw new Qo(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function af(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 of=`1`,sf=`0..1`,cf=`*`,lf=`0..*`,uf=new Map([[`-`,[`1`,`1`]],[`<>`,[`*`,`*`]],[`>`,[`*`,`1`]],[`<`,[`1`,`*`]],[`-?`,[`1`,sf]],[`?-`,[sf,`1`]],[`?-?`,[sf,sf]],[`?>`,[lf,`1`]],[`>?`,[`*`,sf]],[`?>?`,[lf,sf]],[`?<`,[sf,`*`]],[`<?`,[`1`,lf]],[`?<?`,[sf,lf]],[`?<>`,[lf,`*`]],[`<>?`,[`*`,lf]],[`?<>?`,[lf,lf]]]),df=new Map([...uf.entries()].map(([e,[t,n]])=>[`${t}-${n}`,e]));function ff(e){return uf.get(e)}function pf(e){return af(e).max===1}function mf(e){return af(e).max===`*`}function hf(e){return af(e).min===0}function gf(e){return af(e).min>=1}function _f(e){return e.replace(/\?/g,``)}function vf(e,t){return df.get(`${e}-${t}`)??`<>`}function yf(e){let{min:t,max:n}=af(e);return t===0?e:n===`*`?lf:sf}function bf(e){let{min:t,max:n}=af(e);return t>=1?e:n===`*`?`*`:`1`}function xf(e){let{min:t,max:n}=af(e);return n===`*`?e:t===0?lf:`*`}var C=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_DEP_CONTEXT=3042]=`INVALID_DEP_CONTEXT`,e[e.INVALID_DEP_FIELD=3043]=`INVALID_DEP_FIELD`,e[e.INVALID_NOTE_CONTEXT=3044]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3045]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3046]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3047]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3048]=`EMPTY_NOTE`,e[e.UNKNOWN_NOTE_SETTING=3049]=`UNKNOWN_NOTE_SETTING`,e[e.DUPLICATE_NOTE_SETTING=3050]=`DUPLICATE_NOTE_SETTING`,e[e.INVALID_NOTE_SETTING_VALUE=3051]=`INVALID_NOTE_SETTING_VALUE`,e[e.INVALID_INDEXES_CONTEXT=3052]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3053]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3054]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3055]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3056]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3057]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3058]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3059]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3060]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3061]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3062]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3063]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3064]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3065]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3066]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3067]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3069]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3070]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3071]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3072]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3073]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3074]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3075]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3076]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3077]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3078]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3079]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3080]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3081]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3082]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3083]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3084]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3085]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3086]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.UNKNOWN_RECORDS_SETTING=3087]=`UNKNOWN_RECORDS_SETTING`,e[e.DUPLICATE_RECORDS_SETTING=3088]=`DUPLICATE_RECORDS_SETTING`,e[e.INVALID_RECORDS_SETTING_VALUE=3089]=`INVALID_RECORDS_SETTING_VALUE`,e[e.INVALID_USE_CONTEXT=3090]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3091]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3092]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3093]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3094]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3095]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3096]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.DEP_SELF_LOOP=5003]=`DEP_SELF_LOOP`,e[e.DEP_MIXED_DOWNSTREAM_TABLES=5004]=`DEP_MIXED_DOWNSTREAM_TABLES`,e[e.DEP_DUPLICATE_DOWNSTREAM_TABLE=5005]=`DEP_DUPLICATE_DOWNSTREAM_TABLE`,e[e.DEP_MIXED_LEVEL=5006]=`DEP_MIXED_LEVEL`,e[e.UNEQUAL_FIELDS_BINARY_REF=5007]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5008]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5009]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e[e.INVALID_METADATA_TARGET_KIND=5010]=`INVALID_METADATA_TARGET_KIND`,e[e.INVALID_METADATA_FIELD=5011]=`INVALID_METADATA_FIELD`,e[e.DUPLICATE_METADATA_FIELD=5012]=`DUPLICATE_METADATA_FIELD`,e}({}),Sf=function(e){return e.RefColumnMismatch=`Mismatched optional ref constraints`,e.RecordValueTypeMismatch=`Record type errors`,e.RecordConstraintViolation=`Record constraint violations`,e.Other=`Other`,e}({}),w=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.details=i,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new Cf(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},Cf=class extends Error{constructor(e,t,n,r){super(t),this.code=e,this.diagnostic=t,this.details=r,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,w.prototype)}get filepath(){return this.nodeOrToken.filepath}},wf=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.details=i,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}get quickFixes(){return this.details?.quickFixes}get filepath(){return this.nodeOrToken.filepath}};function Tf(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Ef(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Df(e){let[t]=e;return Ef(t)||Tf(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Of(e){return Tf(e)||Ef(e)}function kf(e){let t=j(e);return t!==void 0&&t.length>0}function Af(e){return jf(e)}function jf(e){return e instanceof Dm&&e.expression instanceof Em}function Mf(e){return!!e.bodyColon}function Nf(e){return e instanceof B&&e.op?.value===`~`&&D(e.expression)}function Pf(e){return e!==void 0&&uf.has(e)}function Ff(e){return e===`<-`||e===`->`}function If(e){if(!(e instanceof Dm)||!(e.expression instanceof wm)||e.expression.literal?.kind!==_.COLOR_LITERAL)return!1;let t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!==`#`)return!1;for(let e=1;e<t.length;e+=1)if(!Df(t[e]))return!1;return!0}function Lf(e){return If(e)?!0:Kf(e)&&e.expression.variable.value.toLowerCase()===`none`}function Rf(e){if(E(e)||zf(e)||Kf(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof B&&Do.includes(e.op?.value)&&zf(e.expression)||e instanceof ym)return!0;if(!e||!qf(e))return!1;let t=dp(e);return t.length===2||t.length===3}function zf(e){return e instanceof B?Do.includes(e.op.value)?zf(e.expression):!1:e instanceof Dm&&e.expression instanceof wm&&e.expression.literal?.kind===_.NUMERIC_LITERAL}function Bf(e){if(!(e instanceof B)||!Pf(e.op?.value))return!1;let t=j(e.expression);return t!==void 0&&t.length>0}function Vf(e){if(!(e instanceof B)||!Ff(e.op?.value))return!1;let t=j(e.expression);return t!==void 0&&t.length>0}function Hf(e){return e instanceof bm&&e.elementList.every(D)}function Uf(e){if(!(e instanceof Cm||O(e)||e instanceof Dm||e instanceof km))return!1;for(;e instanceof Cm||e instanceof km;)if(e instanceof Cm){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>zf(e)||E(e)||Kf(e)))return!1;e=e.callee}else if(e instanceof km){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&zf(e.name)))return!1;e=e.array}let t=j(e);return t!==void 0&&t.length>0}function Wf(e){return E(e)||If(e)}function T(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof Dm){r.push(new w(C.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=sp(e.name)?.toLowerCase();if(!n)return;let i=t[n];i?i.push(e):t[n]=[e]}),new n(t,r)):new n(t)}function E(e){return e instanceof Dm&&(e.expression instanceof Em&&e.expression.variable instanceof Ha&&e.expression.variable.kind===_.QUOTED_STRING||e.expression instanceof wm&&e.expression.literal?.kind===_.STRING_LITERAL)}function D(e){return e instanceof Dm&&e.expression instanceof Em&&e.expression.variable instanceof Ha}function Gf(e){return e?e instanceof Tm:!1}function Kf(e){return e instanceof Dm&&e.expression instanceof Em&&e.expression.variable?.kind===_.IDENTIFIER}function O(e){return e instanceof V&&e.leftExpression instanceof I&&e.rightExpression instanceof I&&e.op?.value===`.`}function qf(e){return D(e)?!0:O(e)&&D(e.rightExpression)&&qf(e.leftExpression)}function k(e,t){return e instanceof R&&e.isKind(t)}function Jf(e){return e instanceof mm}function Yf(e,t){return e instanceof hm&&(t===void 0||e.isKind(t))}function Xf(e){return e instanceof L}function A(e,...t){return e instanceof H&&e.parent instanceof R&&e.parent.isKind(...t)}function Zf(e,t){let n=e.parent;return n instanceof R&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Qf(e,t){let n=e.parentOfKind(H);if(!n||t<0)return!1;if(t===0)return n.callee?n.callee.containsEq(e):!1;let r=n.args[t-1];return r?r.containsEq(e):!1}function $f(e){return!!e.parentOfKind(W)}function ep(e,t){let n=e.parentOfKind(z);return!n||(n.name instanceof Dm?N(n.name):sp(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function tp(e){return!(e instanceof V)||!Pf(e.op?.value)?!1:fp(e.leftExpression)!==void 0&&fp(e.rightExpression)!==void 0}function np(e){let t=fp(e.leftExpression),n=fp(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function rp(e){return e instanceof Dm&&e.expression instanceof Em||e instanceof ym}function ip(e){if(D(e))return e;if(O(e)){let t=e.rightExpression;if(t&&D(t))return t}}function ap(e){let t=e.parentNode;return!O(t)||t.rightExpression!==e?!1:!(O(t.parentNode)&&t.parentNode.leftExpression===t)}function op(e){if(D(e))return e.expression.variable}function sp(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function cp(e){if(!(e instanceof R))return;let t=j(e?.name);return t===void 0?void 0:t.join(`.`)}function lp(e){return e.elementList.length===0}function up(e){return e?.body?e.body instanceof U?e.body.body:[e.body]:[]}function dp(e){if(!e)return;if(!O(e))return[e];let t=dp(e.leftExpression);if(t)return t.push(e.rightExpression),t}function j(e){if(e===void 0)return;let t=dp(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 fp(e){if(e===void 0)return;let t=dp(e);if(!t||t.length===0)return;let n=[];if(!D(h(t))){let e=t.pop();if(Hf(e))n=e.elementList;else return}let r=t;if(r.every(D))return{variables:r,tupleElements:n}}function pp(e){if(rp(e))return e instanceof ym?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof bm&&e.elementList.every(rp))return{functional:e.elementList.filter(e=>e instanceof ym),nonFunctional:e.elementList.filter(D)}}function M(e){if(E(e))return e.expression instanceof Em?e?.expression?.variable?.value:e.expression.literal.value}function mp(e){return e instanceof Dm&&e.expression instanceof wm&&e.expression.literal?.kind===_.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function hp(e){if(!(e instanceof Cm)||!e.callee)return;let t=dp(e.callee);if(!t||t.length===0||!t.every(D))return;let n=[];return Hf(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function N(e){if(D(e))return e.expression.variable.value}function gp(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function _p(e){if(e.name instanceof _m)return sp(e.name)?.toLowerCase();if(e.name instanceof Dm)return N(e.name)}function vp(e){return Kf(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Om}function yp(e){return M(e)===``}function bp(e){return e instanceof ym}function xp(e){let t=mp(e);if(t!==null)return t;if(zf(e)&&e instanceof B&&e.expression){let t=e.op?.value,n=mp(e.expression);if(n!==null)return t===`-`?-n:n}return null}function Sp(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=xp(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 Cp(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=xp(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 wp=[`true`,`yes`,`y`,`t`,`1`],Tp=[`false`,`no`,`n`,`f`,`0`];function Ep(e){if(e==null)return null;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===0?!1:e===1||null;if(typeof e==`string`){let t=e.toLowerCase();return wp.includes(t)?!0:!Tp.includes(t)&&null}if(Kf(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=mp(e);if(t===0)return!1;if(t===1)return!0;let n=M(e)?.toLowerCase();if(n){if(wp.includes(n))return!0;if(Tp.includes(n))return!1}return null}function Dp(e){if(e==null)return null;if(typeof e==`string`)return e;let t=j(e);return t?h(t):M(e)??null}function Op(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??Sp(e)??Ep(e);return t===null?null:t.toString()}var kp=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Ap=[`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`],jp=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Mp(e){if(e==null)return null;let t=typeof e==`string`?e:M(e)??null;if(t===null)return null;for(let e of jp){let n=S.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of kp){let n=S.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Ap){let n=S.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=S.fromISO(t,{setZone:!0});return n.isValid?n.toISO({suppressMilliseconds:!0,includeOffset:r(n)}):null;function r(e){return e.zone.type!==`system`}}function Np(e){return e instanceof B?`${e.op?.value}${Np(e.expression)}`:e.expression.literal.value}function Pp(e){return e instanceof B?e.op?.value===`-`?-Pp(e.expression):Pp(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 Fp(e){let t=e.split(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(`PASS_THROUGH`),t=Symbol(`UNHANDLED`),n=class e{static create(t,n,r,i){return new e(t,n,r,i)}constructor(e,t,n,r){this.value=e,this.errors=t??[],this.warnings=n,this.infos=r}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings,this.infos):this}hasValue(e){return this.value===e}getFiltered(e){return this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings??[]}getInfos(){return this.infos??[]}chainFiltered(t,n){if(this.value===n)return new e(void 0,this.errors,this.warnings,this.infos);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()],o=[...this.getInfos(),...r.getInfos()];return new e(r.value,i,a,o)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()],a=[...this.getInfos(),...n.getInfos()];return new e(n.value,r,i,a)}mapFiltered(t,n){return this.value===n?new e(void 0,this.errors,this.warnings,this.infos):new e(t(this.value),this.errors,this.warnings,this.infos)}map(t){return new e(t(this.value),this.errors,this.warnings,this.infos)}},r=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Dep=`dep`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e.Metadata=`metadata`,e}({}),i=function(e){return e.Color=`color`,e.HeaderColor=`headercolor`,e.Note=`note`,e.PK=`pk`,e.PrimaryKey=`primary key`,e.Unique=`unique`,e.Ref=`ref`,e.Dep=`dep`,e.NotNull=`not null`,e.Null=`null`,e.Increment=`increment`,e.Default=`default`,e.Name=`name`,e.Type=`type`,e.Check=`check`,e.Update=`update`,e.Delete=`delete`,e.Inactive=`inactive`,e.Example=`example`,e}({}),a=typeof global==`object`&&global&&global.Object===Object&&global,o=typeof self==`object`&&self&&self.Object===Object&&self,s=a||o||Function(`return this`)(),c=s.Symbol,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function p(e){var t=u.call(e,f),n=e[f];try{e[f]=void 0;var r=!0}catch{}var i=d.call(e);return r&&(t?e[f]=n:delete e[f]),i}var m=Object.prototype.toString;function ee(e){return m.call(e)}var te=`[object Null]`,ne=`[object Undefined]`,re=c?c.toStringTag:void 0;function ie(e){return e==null?e===void 0?ne:te:re&&re in Object(e)?p(e):ee(e)}function ae(e){return typeof e==`object`&&!!e}var oe=`[object Symbol]`;function se(e){return typeof e==`symbol`||ae(e)&&ie(e)==oe}function ce(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var le=Array.isArray,ue=1/0,de=c?c.prototype:void 0,fe=de?de.toString:void 0;function pe(e){if(typeof e==`string`)return e;if(le(e))return ce(e,pe)+``;if(se(e))return fe?fe.call(e):``;var t=e+``;return t==`0`&&1/e==-ue?`-0`:t}var me=/\s/;function he(e){for(var t=e.length;t--&&me.test(e.charAt(t)););return t}var ge=/^\s+/;function _e(e){return e&&e.slice(0,he(e)+1).replace(ge,``)}function ve(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var ye=NaN,be=/^[-+]0x[0-9a-f]+$/i,xe=/^0b[01]+$/i,Se=/^0o[0-7]+$/i,Ce=parseInt;function we(e){if(typeof e==`number`)return e;if(se(e))return ye;if(ve(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=ve(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=_e(e);var n=xe.test(e);return n||Se.test(e)?Ce(e.slice(2),n?2:8):be.test(e)?ye:+e}var Te=1/0,Ee=17976931348623157e292;function De(e){return e?(e=we(e),e===Te||e===-Te?(e<0?-1:1)*Ee:e===e?e:0):e===0?e:0}function Oe(e){var t=De(e),n=t%1;return t===t?n?t-n:t:0}function ke(e){return e}var Ae=`[object AsyncFunction]`,je=`[object Function]`,Me=`[object GeneratorFunction]`,Ne=`[object Proxy]`;function Pe(e){if(!ve(e))return!1;var t=ie(e);return t==je||t==Me||t==Ae||t==Ne}var Fe=s[`__core-js_shared__`],Ie=function(){var e=/[^.]+$/.exec(Fe&&Fe.keys&&Fe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Le(e){return!!Ie&&Ie in e}var Re=Function.prototype.toString;function ze(e){if(e!=null){try{return Re.call(e)}catch{}try{return e+``}catch{}}return``}var Be=/[\\^$.*+?()[\]{}|]/g,Ve=/^\[object .+?Constructor\]$/,He=Function.prototype,Ue=Object.prototype,We=He.toString,Ge=Ue.hasOwnProperty,Ke=RegExp(`^`+We.call(Ge).replace(Be,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function qe(e){return!ve(e)||Le(e)?!1:(Pe(e)?Ke:Ve).test(ze(e))}function Je(e,t){return e?.[t]}function Ye(e,t){var n=Je(e,t);return qe(n)?n:void 0}var Xe=Ye(s,`WeakMap`);function Ze(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}function Qe(){}var $e=800,et=16,tt=Date.now;function nt(e){var t=0,n=0;return function(){var r=tt(),i=et-(r-n);if(n=r,i>0){if(++t>=$e)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function rt(e){return function(){return e}}var it=function(){try{var e=Ye(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),at=nt(it?function(e,t){return it(e,`toString`,{configurable:!0,enumerable:!1,value:rt(t),writable:!0})}:ke);function ot(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1}function st(e){return e!==e}function ct(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}function lt(e,t,n){return t===t?ct(e,t,n):ot(e,st,n)}function ut(e,t){return!!(e!=null&&e.length)&&lt(e,t,0)>-1}var dt=9007199254740991,ft=/^(?:0|[1-9]\d*)$/;function pt(e,t){var n=typeof e;return t??=dt,!!t&&(n==`number`||n!=`symbol`&&ft.test(e))&&e>-1&&e%1==0&&e<t}function mt(e,t,n){t==`__proto__`&&it?it(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function ht(e,t){return e===t||e!==e&&t!==t}var gt=Math.max;function _t(e,t,n){return t=gt(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=gt(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Ze(e,this,s)}}function vt(e,t){return at(_t(e,t,ke),e+``)}var yt=9007199254740991;function bt(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=yt}function xt(e){return e!=null&&bt(e.length)&&!Pe(e)}var St=Object.prototype;function Ct(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||St)}function wt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var Tt=`[object Arguments]`;function Et(e){return ae(e)&&ie(e)==Tt}var Dt=Object.prototype,Ot=Dt.hasOwnProperty,kt=Dt.propertyIsEnumerable,At=Et(function(){return arguments}())?Et:function(e){return ae(e)&&Ot.call(e,`callee`)&&!kt.call(e,`callee`)};function jt(){return!1}var Mt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Nt=Mt&&typeof module==`object`&&module&&!module.nodeType&&module,Pt=Nt&&Nt.exports===Mt?s.Buffer:void 0,Ft=(Pt?Pt.isBuffer:void 0)||jt,It=`[object Arguments]`,Lt=`[object Array]`,Rt=`[object Boolean]`,zt=`[object Date]`,Bt=`[object Error]`,Vt=`[object Function]`,Ht=`[object Map]`,Ut=`[object Number]`,Wt=`[object Object]`,Gt=`[object RegExp]`,Kt=`[object Set]`,qt=`[object String]`,Jt=`[object WeakMap]`,Yt=`[object ArrayBuffer]`,Xt=`[object DataView]`,Zt=`[object Float32Array]`,Qt=`[object Float64Array]`,$t=`[object Int8Array]`,en=`[object Int16Array]`,tn=`[object Int32Array]`,nn=`[object Uint8Array]`,rn=`[object Uint8ClampedArray]`,an=`[object Uint16Array]`,on=`[object Uint32Array]`,sn={};sn[Zt]=sn[Qt]=sn[$t]=sn[en]=sn[tn]=sn[nn]=sn[rn]=sn[an]=sn[on]=!0,sn[It]=sn[Lt]=sn[Yt]=sn[Rt]=sn[Xt]=sn[zt]=sn[Bt]=sn[Vt]=sn[Ht]=sn[Ut]=sn[Wt]=sn[Gt]=sn[Kt]=sn[qt]=sn[Jt]=!1;function cn(e){return ae(e)&&bt(e.length)&&!!sn[ie(e)]}function ln(e){return function(t){return e(t)}}var un=typeof exports==`object`&&exports&&!exports.nodeType&&exports,dn=un&&typeof module==`object`&&module&&!module.nodeType&&module,fn=dn&&dn.exports===un&&a.process,pn=function(){try{return dn&&dn.require&&dn.require(`util`).types||fn&&fn.binding&&fn.binding(`util`)}catch{}}(),mn=pn&&pn.isTypedArray,hn=mn?ln(mn):cn,gn=Object.prototype.hasOwnProperty;function _n(e,t){var n=le(e),r=!n&&At(e),i=!n&&!r&&Ft(e),a=!n&&!r&&!i&&hn(e),o=n||r||i||a,s=o?wt(e.length,String):[],c=s.length;for(var l in e)(t||gn.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||pt(l,c)))&&s.push(l);return s}function vn(e,t){return function(n){return e(t(n))}}var yn=vn(Object.keys,Object),bn=Object.prototype.hasOwnProperty;function xn(e){if(!Ct(e))return yn(e);var t=[];for(var n in Object(e))bn.call(e,n)&&n!=`constructor`&&t.push(n);return t}function Sn(e){return xt(e)?_n(e):xn(e)}function Cn(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var wn=Object.prototype.hasOwnProperty;function Tn(e){if(!ve(e))return Cn(e);var t=Ct(e),n=[];for(var r in e)r==`constructor`&&(t||!wn.call(e,r))||n.push(r);return n}function En(e){return xt(e)?_n(e,!0):Tn(e)}var Dn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,On=/^\w*$/;function kn(e,t){if(le(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||se(e)?!0:On.test(e)||!Dn.test(e)||t!=null&&e in Object(t)}var An=Ye(Object,`create`);function jn(){this.__data__=An?An(null):{},this.size=0}function Mn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Nn=`__lodash_hash_undefined__`,Pn=Object.prototype.hasOwnProperty;function Fn(e){var t=this.__data__;if(An){var n=t[e];return n===Nn?void 0:n}return Pn.call(t,e)?t[e]:void 0}var In=Object.prototype.hasOwnProperty;function Ln(e){var t=this.__data__;return An?t[e]!==void 0:In.call(t,e)}var Rn=`__lodash_hash_undefined__`;function zn(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=An&&t===void 0?Rn:t,this}function Bn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Bn.prototype.clear=jn,Bn.prototype.delete=Mn,Bn.prototype.get=Fn,Bn.prototype.has=Ln,Bn.prototype.set=zn;function Vn(){this.__data__=[],this.size=0}function Hn(e,t){for(var n=e.length;n--;)if(ht(e[n][0],t))return n;return-1}var Un=Array.prototype.splice;function Wn(e){var t=this.__data__,n=Hn(t,e);return n<0?!1:(n==t.length-1?t.pop():Un.call(t,n,1),--this.size,!0)}function Gn(e){var t=this.__data__,n=Hn(t,e);return n<0?void 0:t[n][1]}function Kn(e){return Hn(this.__data__,e)>-1}function qn(e,t){var n=this.__data__,r=Hn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function Jn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Jn.prototype.clear=Vn,Jn.prototype.delete=Wn,Jn.prototype.get=Gn,Jn.prototype.has=Kn,Jn.prototype.set=qn;var Yn=Ye(s,`Map`);function Xn(){this.size=0,this.__data__={hash:new Bn,map:new(Yn||Jn),string:new Bn}}function Zn(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Qn(e,t){var n=e.__data__;return Zn(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function $n(e){var t=Qn(this,e).delete(e);return this.size-=+!!t,t}function er(e){return Qn(this,e).get(e)}function tr(e){return Qn(this,e).has(e)}function nr(e,t){var n=Qn(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function rr(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}rr.prototype.clear=Xn,rr.prototype.delete=$n,rr.prototype.get=er,rr.prototype.has=tr,rr.prototype.set=nr;var ir=`Expected a function`;function ar(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(ir);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],a=n.cache;if(a.has(i))return a.get(i);var o=e.apply(this,r);return n.cache=a.set(i,o)||a,o};return n.cache=new(ar.Cache||rr),n}ar.Cache=rr;var or=500;function sr(e){var t=ar(e,function(e){return n.size===or&&n.clear(),e}),n=t.cache;return t}var cr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,lr=/\\(\\)?/g,ur=sr(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(cr,function(e,n,r,i){t.push(r?i.replace(lr,`$1`):n||e)}),t});function dr(e){return e==null?``:pe(e)}function fr(e,t){return le(e)?e:kn(e,t)?[e]:ur(dr(e))}var pr=1/0;function mr(e){if(typeof e==`string`||se(e))return e;var t=e+``;return t==`0`&&1/e==-pr?`-0`:t}function hr(e,t){t=fr(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[mr(t[n++])];return n&&n==r?e:void 0}function gr(e,t,n){var r=e==null?void 0:hr(e,t);return r===void 0?n:r}function _r(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var vr=c?c.isConcatSpreadable:void 0;function yr(e){return le(e)||At(e)||!!(vr&&e&&e[vr])}function br(e,t,n,r,i){var a=-1,o=e.length;for(n||=yr,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?br(s,t-1,n,r,i):_r(i,s):r||(i[i.length]=s)}return i}function xr(e){return e!=null&&e.length?br(e,1):[]}function Sr(){this.__data__=new Jn,this.size=0}function Cr(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function wr(e){return this.__data__.get(e)}function Tr(e){return this.__data__.has(e)}var Er=200;function Dr(e,t){var n=this.__data__;if(n instanceof Jn){var r=n.__data__;if(!Yn||r.length<Er-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new rr(r)}return n.set(e,t),this.size=n.size,this}function Or(e){var t=this.__data__=new Jn(e);this.size=t.size}Or.prototype.clear=Sr,Or.prototype.delete=Cr,Or.prototype.get=wr,Or.prototype.has=Tr,Or.prototype.set=Dr;function kr(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}function Ar(){return[]}var jr=Object.prototype.propertyIsEnumerable,Mr=Object.getOwnPropertySymbols,Nr=Mr?function(e){return e==null?[]:(e=Object(e),kr(Mr(e),function(t){return jr.call(e,t)}))}:Ar;function Pr(e,t,n){var r=t(e);return le(e)?r:_r(r,n(e))}function Fr(e){return Pr(e,Sn,Nr)}var Ir=Ye(s,`DataView`),Lr=Ye(s,`Promise`),Rr=Ye(s,`Set`),zr=`[object Map]`,Br=`[object Object]`,Vr=`[object Promise]`,Hr=`[object Set]`,Ur=`[object WeakMap]`,Wr=`[object DataView]`,Gr=ze(Ir),Kr=ze(Yn),qr=ze(Lr),Jr=ze(Rr),Yr=ze(Xe),Xr=ie;(Ir&&Xr(new Ir(new ArrayBuffer(1)))!=Wr||Yn&&Xr(new Yn)!=zr||Lr&&Xr(Lr.resolve())!=Vr||Rr&&Xr(new Rr)!=Hr||Xe&&Xr(new Xe)!=Ur)&&(Xr=function(e){var t=ie(e),n=t==Br?e.constructor:void 0,r=n?ze(n):``;if(r)switch(r){case Gr:return Wr;case Kr:return zr;case qr:return Vr;case Jr:return Hr;case Yr:return Ur}return t});var Zr=Xr,Qr=s.Uint8Array;function $r(e){for(var t=-1,n=e==null?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i}var ei=`__lodash_hash_undefined__`;function ti(e){return this.__data__.set(e,ei),this}function ni(e){return this.__data__.has(e)}function ri(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new rr;++t<n;)this.add(e[t])}ri.prototype.add=ri.prototype.push=ti,ri.prototype.has=ni;function ii(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function ai(e,t){return e.has(t)}var oi=1,si=2;function ci(e,t,n,r,i,a){var o=n&oi,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,p=n&si?new ri:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],ee=t[d];if(r)var te=o?r(ee,m,d,t,e,a):r(m,ee,d,e,t,a);if(te!==void 0){if(te)continue;f=!1;break}if(p){if(!ii(t,function(e,t){if(!ai(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===ee||i(m,ee,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}function li(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function ui(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var di=1,fi=2,pi=`[object Boolean]`,mi=`[object Date]`,hi=`[object Error]`,gi=`[object Map]`,_i=`[object Number]`,vi=`[object RegExp]`,yi=`[object Set]`,bi=`[object String]`,xi=`[object Symbol]`,Si=`[object ArrayBuffer]`,Ci=`[object DataView]`,wi=c?c.prototype:void 0,Ti=wi?wi.valueOf:void 0;function Ei(e,t,n,r,i,a,o){switch(n){case Ci:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Si:return!(e.byteLength!=t.byteLength||!a(new Qr(e),new Qr(t)));case pi:case mi:case _i:return ht(+e,+t);case hi:return e.name==t.name&&e.message==t.message;case vi:case bi:return e==t+``;case gi:var s=li;case yi:var c=r&di;if(s||=ui,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=fi,o.set(e,t);var u=ci(s(e),s(t),r,i,a,o);return o.delete(e),u;case xi:if(Ti)return Ti.call(e)==Ti.call(t)}return!1}var Di=1,Oi=Object.prototype.hasOwnProperty;function ki(e,t,n,r,i,a){var o=n&Di,s=Fr(e),c=s.length;if(c!=Fr(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Oi.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var ee=e[u],te=t[u];if(r)var ne=o?r(te,ee,u,t,e,a):r(ee,te,u,e,t,a);if(!(ne===void 0?ee===te||i(ee,te,n,r,a):ne)){p=!1;break}m||=u==`constructor`}if(p&&!m){var re=e.constructor,ie=t.constructor;re!=ie&&`constructor`in e&&`constructor`in t&&!(typeof re==`function`&&re instanceof re&&typeof ie==`function`&&ie instanceof ie)&&(p=!1)}return a.delete(e),a.delete(t),p}var Ai=1,ji=`[object Arguments]`,Mi=`[object Array]`,Ni=`[object Object]`,Pi=Object.prototype.hasOwnProperty;function Fi(e,t,n,r,i,a){var o=le(e),s=le(t),c=o?Mi:Zr(e),l=s?Mi:Zr(t);c=c==ji?Ni:c,l=l==ji?Ni:l;var u=c==Ni,d=l==Ni,f=c==l;if(f&&Ft(e)){if(!Ft(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Or,o||hn(e)?ci(e,t,n,r,i,a):Ei(e,t,c,n,r,i,a);if(!(n&Ai)){var p=u&&Pi.call(e,`__wrapped__`),m=d&&Pi.call(t,`__wrapped__`);if(p||m){var ee=p?e.value():e,te=m?t.value():t;return a||=new Or,i(ee,te,n,r,a)}}return f?(a||=new Or,ki(e,t,n,r,i,a)):!1}function Ii(e,t,n,r,i){return e===t?!0:e==null||t==null||!ae(e)&&!ae(t)?e!==e&&t!==t:Fi(e,t,n,r,Ii,i)}var Li=1,Ri=2;function zi(e,t,n,r){var i=n.length,a=i,o=!r;if(e==null)return!a;for(e=Object(e);i--;){var s=n[i];if(o&&s[2]?s[1]!==e[s[0]]:!(s[0]in e))return!1}for(;++i<a;){s=n[i];var c=s[0],l=e[c],u=s[1];if(o&&s[2]){if(l===void 0&&!(c in e))return!1}else{var d=new Or;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Ii(u,l,Li|Ri,r,d):f))return!1}}return!0}function Bi(e){return e===e&&!ve(e)}function Vi(e){for(var t=Sn(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Bi(i)]}return t}function Hi(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function Ui(e){var t=Vi(e);return t.length==1&&t[0][2]?Hi(t[0][0],t[0][1]):function(n){return n===e||zi(n,e,t)}}function Wi(e,t){return e!=null&&t in Object(e)}function Gi(e,t,n){t=fr(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=mr(t[r]);if(!(a=e!=null&&n(e,o)))break;e=e[o]}return a||++r!=i?a:(i=e==null?0:e.length,!!i&&bt(i)&&pt(o,i)&&(le(e)||At(e)))}function Ki(e,t){return e!=null&&Gi(e,t,Wi)}var qi=1,Ji=2;function Yi(e,t){return kn(e)&&Bi(t)?Hi(mr(e),t):function(n){var r=gr(n,e);return r===void 0&&r===t?Ki(n,e):Ii(t,r,qi|Ji)}}function Xi(e){return function(t){return t?.[e]}}function Zi(e){return function(t){return hr(t,e)}}function Qi(e){return kn(e)?Xi(mr(e)):Zi(e)}function $i(e){return typeof e==`function`?e:e==null?ke:typeof e==`object`?le(e)?Yi(e[0],e[1]):Ui(e):Qi(e)}function ea(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}function ta(e){return function(t,n,r){for(var i=-1,a=Object(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}var na=ta();function ra(e,t){return e&&na(e,t,Sn)}function ia(e,t){return function(n,r){if(n==null)return n;if(!xt(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var aa=ia(ra);function oa(e,t,n,r){return aa(e,function(e,i,a){t(r,e,n(e),a)}),r}function sa(e,t){return function(n,r){var i=le(n)?ea:oa,a=t?t():{};return i(n,e,$i(r,2),a)}}function ca(e){return ae(e)&&xt(e)}function la(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}var ua=200;function da(e,t,n,r){var i=-1,a=ut,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ce(t,ln(n))),r?(a=la,o=!1):t.length>=ua&&(a=ai,o=!1,t=new ri(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var fa=vt(function(e,t){return ca(e)?da(e,br(t,1,ca,!0)):[]});function h(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function pa(e){return typeof e==`function`?e:ke}function ma(e,t){var n=[];return aa(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}function ha(e,t){return(le(e)?kr:ma)(e,$i(t,3))}var ga=Math.max,_a=Math.min;function va(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Oe(n),i=n<0?ga(r+i,0):_a(i,r-1)),ot(e,$i(t,3),i,!0)}function ya(e){return e&&e.length?e[0]:void 0}function ba(e,t){var n=-1,r=xt(e)?Array(e.length):[];return aa(e,function(e,i,a){r[++n]=t(e,i,a)}),r}function xa(e,t){return(le(e)?ce:ba)(e,$i(t,3))}function Sa(e,t){return br(xa(e,t),1)}function Ca(e,t){return e==null?e:na(e,pa(t),En)}var wa=Object.prototype.hasOwnProperty,Ta=sa(function(e,t,n){wa.call(e,n)?e[n].push(t):mt(e,n,[t])}),Ea=`[object Map]`,Da=`[object Set]`,Oa=Object.prototype.hasOwnProperty;function ka(e){if(e==null)return!0;if(xt(e)&&(le(e)||typeof e==`string`||typeof e.splice==`function`||Ft(e)||hn(e)||At(e)))return!e.length;var t=Zr(e);if(t==Ea||t==Da)return!e.size;if(Ct(e))return!xn(e).length;for(var n in e)if(Oa.call(e,n))return!1;return!0}var Aa=sa(function(e,t,n){mt(e,n,t)}),g=sa(function(e,t,n){e[+!n].push(t)},function(){return[[],[]]}),ja=Rr&&1/ui(new Rr([,-0]))[1]==1/0?function(e){return new Rr(e)}:Qe,Ma=200;function Na(e,t,n){var r=-1,i=ut,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=la;else if(a>=Ma){var l=t?null:ja(e);if(l)return ui(l);o=!1,i=ai,c=new ri}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}function Pa(e){return e&&e.length?Na(e):[]}function Fa(e,t){return e&&e.length?Na(e,$i(t,2)):[]}var Ia=Math.max;function La(e){if(!(e&&e.length))return[];var t=0;return e=kr(e,function(e){if(ca(e))return t=Ia(e.length,t),!0}),wt(t,function(t){return ce(e,Xi(t))})}var Ra=vt(La),_=function(e){return e.SPACE=`<space>`,e.TAB=`<tab>`,e.NEWLINE=`<newline>`,e.COMMA=`<comma>`,e.LPAREN=`<lparen>`,e.RPAREN=`<rparen>`,e.LBRACE=`<lbrace>`,e.RBRACE=`<rbrace>`,e.LBRACKET=`<lbracket>`,e.RBRACKET=`<rbracket>`,e.LANGLE=`<langle>`,e.RANGLE=`<rangle>`,e.OP=`<op>`,e.EOF=`<eof>`,e.NUMERIC_LITERAL=`<number>`,e.STRING_LITERAL=`<string>`,e.COLOR_LITERAL=`<color>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.QUOTED_STRING=`<variable>`,e.IDENTIFIER=`<identifier>`,e.SEMICOLON=`<semicolon>`,e.COLON=`<colon>`,e.SINGLE_LINE_COMMENT=`<single-line-comment>`,e.MULTILINE_COMMENT=`<multiline-comment>`,e.FRONT_MATTER=`<front-matter>`,e.WILDCARD=`<wildcard>`,e}({});function za(e){switch(e.kind){case`<newline>`:case`<space>`:case`<tab>`:case`<single-line-comment>`:case`<multiline-comment>`:case`<front-matter>`:return!0;default:return!1}}function Ba(e){if(!e)return!1;switch(e){case`+`:case`-`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`?`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function Va(e){return e!==void 0&&e.kind===`<op>`}var Ha=class e{constructor(e,t,n,r,i,a){this.kind=e,this.filepath=t,this.startPos=n,this.endPos=r,this.value=i,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=a,this.start=n.offset,this.end=r.offset}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}};function Ua(e){return e.trailingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0}function Wa(e,t){return t.leadingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0||Ua(e)}function Ga(e){return e.trailingTrivia.find(({kind:e})=>[_.SPACE,_.TAB].includes(e))!==void 0}function Ka(e){return e.trailingTrivia.length===0?e.end:Ka(h(e.trailingTrivia))}function qa(e){return e.leadingTrivia.length===0?e.start:qa(e.leadingTrivia[0])}function Ja(e){return[_.SINGLE_LINE_COMMENT,_.MULTILINE_COMMENT].includes(e.kind)}var Ya=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},Xa=/^[A-Za-z]:\//;function Za(e=``){return e&&e.replace(/\\/g,`/`).replace(Xa,e=>e.toUpperCase())}var Qa=/^[/\\]{2}/,$a=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,eo=/^[A-Za-z]:$/,to=/^\/([A-Za-z]:)?$/,no=/.(\.[^./]+|\.)$/,ro=function(e){if(e.length===0)return`.`;e=Za(e);let t=e.match(Qa),n=co(e),r=e[e.length-1]===`/`;return e=so(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),eo.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!co(e)?`/${e}`:e)},io=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 ro(t)};function ao(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var oo=function(...e){e=e.map(e=>Za(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:ao();!i||i.length===0||(t=`${i}/${t}`,n=co(i))}return t=so(t,!n),n&&!co(t)?`/${t}`:t.length>0?t:`.`};function so(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 co=function(e){return $a.test(e)},lo=function(e){if(e===`..`)return``;let t=no.exec(Za(e));return t&&t[1]||``},uo=function(e,t){let n=oo(e).replace(to,`$1`).split(`/`),r=oo(t).replace(to,`$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(`/`)},fo=function(e){let t=Za(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&eo.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(co(e)?`/`:`.`)},po=function(e,t){let n=Za(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},mo=/^[a-zA-Z]:\//,ho=class e{constructor(e,t={}){e=e.split(`/`).map(go).join(`/`);let n=ro(e);if(!co(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(oo(t,n))}static fromUri(t){try{let n=new URL(t);return new e(ro(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(ro(t))}}get absolute(){return this.path}get fsPath(){return this.path.split(`/`).map(decodeURIComponent).join(`/`)}get dirname(){return fo(this.fsPath)}get basename(){return po(this.fsPath)}get extname(){return lo(this.fsPath)}resolve(t){return new e(oo(this.dirname,t))}join(...t){return new e(io(this.path,...t))}relativeTo(e){let t=uo(e,this.fsPath);return!t.startsWith(`./`)&&!t.startsWith(`../`)&&![`.`,`..`].includes(t)?`./${t}`:t}toKey(){return this.path}equals(e){return this.toKey()===e.toKey()}isParentOf(e){if(this.path===e.path)return!1;let t=this.path.endsWith(`/`)?this.path:`${this.path}/`;return e.path.startsWith(t)}toUri(e={}){let t=e.protocol||this.protocol;if(!t)return this.path;let n=mo.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!co(ro(e))}};function go(e){try{return encodeURIComponent(decodeURIComponent(e))}catch{return encodeURIComponent(e)}}var _o=[`null`,`true`,`false`],vo=`none`,yo=`.dbml`,bo=[`-`,`+`],v=`public`,xo=ho.from(`/main.dbml`),So={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`])},Co={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`])},wo={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},To={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`])},Eo={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`])},Do={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`])},Oo={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function ko(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function Ao(e,t){let n=ko(e);return t?So[t].has(n):Object.values(So).some(e=>e.has(n))}function jo(e,t){let n=ko(e);return t?Co[t].has(n):Object.values(Co).some(e=>e.has(n))}function Mo(e,t){return Ao(e,t)||jo(e,t)}function No(e,t){let n=ko(e);return t?wo[t].has(n):Object.values(wo).some(e=>e.has(n))}function Po(e,t){let n=ko(e);return t?To[t].has(n):Object.values(To).some(e=>e.has(n))}function Fo(e,t){let n=ko(e);return t?Eo[t].has(n):Object.values(Eo).some(e=>e.has(n))}function Io(e,t){let n=ko(e);return t?Do[t].has(n):Object.values(Do).some(e=>e.has(n))}function Lo(e,t){let n=ko(e);return t?Oo[t].has(n):Object.values(Oo).some(e=>e.has(n))}function Ro(e,t){if(t)return`string`;if(Ao(e))return`integer`;if(jo(e))return`real`;if(No(e))return`bool`;if(Po(e))return`string`;let n=ko(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:Io(e)?`datetime`:e}var zo=class extends Error{},Bo=class extends zo{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Vo=class extends zo{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Ho=class extends zo{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Uo=class extends zo{},Wo=class extends zo{constructor(e){super(`Invalid unit ${e}`)}},Go=class extends zo{},Ko=class extends zo{constructor(){super(`Zone is an abstract class`)}},y=`numeric`,qo=`short`,Jo=`long`,Yo={year:y,month:y,day:y},Xo={year:y,month:qo,day:y},Zo={year:y,month:qo,day:y,weekday:qo},Qo={year:y,month:Jo,day:y},$o={year:y,month:Jo,day:y,weekday:Jo},es={hour:y,minute:y},ts={hour:y,minute:y,second:y},ns={hour:y,minute:y,second:y,timeZoneName:qo},rs={hour:y,minute:y,second:y,timeZoneName:Jo},is={hour:y,minute:y,hourCycle:`h23`},as={hour:y,minute:y,second:y,hourCycle:`h23`},os={hour:y,minute:y,second:y,hourCycle:`h23`,timeZoneName:qo},ss={hour:y,minute:y,second:y,hourCycle:`h23`,timeZoneName:Jo},cs={year:y,month:y,day:y,hour:y,minute:y},ls={year:y,month:y,day:y,hour:y,minute:y,second:y},us={year:y,month:qo,day:y,hour:y,minute:y},ds={year:y,month:qo,day:y,hour:y,minute:y,second:y},fs={year:y,month:qo,day:y,weekday:qo,hour:y,minute:y},ps={year:y,month:Jo,day:y,hour:y,minute:y,timeZoneName:qo},ms={year:y,month:Jo,day:y,hour:y,minute:y,second:y,timeZoneName:qo},hs={year:y,month:Jo,day:y,weekday:Jo,hour:y,minute:y,timeZoneName:Jo},gs={year:y,month:Jo,day:y,weekday:Jo,hour:y,minute:y,second:y,timeZoneName:Jo},_s=class{get type(){throw new Ko}get name(){throw new Ko}get ianaName(){return this.name}get isUniversal(){throw new Ko}offsetName(e,t){throw new Ko}formatOffset(e,t){throw new Ko}offset(e){throw new Ko}equals(e){throw new Ko}get isValid(){throw new Ko}},vs=null,ys=class e extends _s{static get instance(){return vs===null&&(vs=new e),vs}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return ol(e,t,n)}formatOffset(e,t){return ul(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},bs=new Map;function xs(e){let t=bs.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`}),bs.set(e,t)),t}var Ss={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function Cs(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 ws(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=Ss[t];t===`era`?r[a]=i:b(a)||(r[a]=parseInt(i,10))}return r}var Ts=new Map,Es=class e extends _s{static create(t){let n=Ts.get(t);return n===void 0&&Ts.set(t,n=new e(t)),n}static resetCache(){Ts.clear(),bs.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 ol(e,t,n,this.name)}formatOffset(e,t){return ul(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=xs(this.name),[r,i,a,o,s,c,l]=n.formatToParts?ws(n,t):Cs(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=nl({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}},Ds={};function Os(e,t={}){let n=JSON.stringify([e,t]),r=Ds[n];return r||(r=new Intl.ListFormat(e,t),Ds[n]=r),r}var ks=new Map;function As(e,t={}){let n=JSON.stringify([e,t]),r=ks.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),ks.set(n,r)),r}var js=new Map;function Ms(e,t={}){let n=JSON.stringify([e,t]),r=js.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),js.set(n,r)),r}var Ns=new Map;function Ps(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=Ns.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),Ns.set(i,a)),a}var Fs=null;function Is(){return Fs||(Fs=new Intl.DateTimeFormat().resolvedOptions().locale,Fs)}var Ls=new Map;function Rs(e){let t=Ls.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Ls.set(e,t)),t}var zs=new Map;function Bs(e){let t=zs.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Xs,...t}),zs.set(e,t)}return t}function Vs(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=As(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=As(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Hs(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Us(e){let t=[];for(let n=1;n<=12;n++){let r=Xd.utc(2009,n,1);t.push(e(r))}return t}function Ws(e){let t=[];for(let n=1;n<=7;n++){let r=Xd.utc(2016,11,13+n);t.push(e(r))}return t}function Gs(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Ks(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||Rs(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=Ms(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return Jc(this.floor?Math.floor(e):Qc(e,3),this.padTo)}},Js=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&&Es.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=As(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()}},Ys=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&zc()&&(this.rtf=Ps(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):kl(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Xs={firstDay:1,minimalDays:4,weekend:[6,7]},Zs=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||_c.defaultLocale;return new e(o||(a?`en-US`:Is()),n||_c.defaultNumberingSystem,r||_c.defaultOutputCalendar,Gc(i)||_c.defaultWeekSettings,o)}static resetCache(){Fs=null,ks.clear(),js.clear(),Ns.clear(),Ls.clear(),zs.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]=Vs(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Hs(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??=Ks(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,Gc(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 Gs(this,e,hl,()=>{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]=Us(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Gs(this,e,yl,()=>{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]=Ws(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Gs(this,void 0,()=>bl,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[Xd.utc(2016,11,13,9),Xd.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Gs(this,e,wl,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[Xd.utc(-40,1,1),Xd.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 Js(e,this.intl,t)}relFormatter(e={}){return new Ys(this.intl,this.isEnglish(),e)}listFormatter(e={}){return Os(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||Rs(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Bc()?Bs(this.locale):Xs}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})`}},Qs=null,$s=class e extends _s{static get utcInstance(){return Qs===null&&(Qs=new e(0)),Qs}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(sl(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${ul(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${ul(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return ul(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}},ec=class extends _s{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 tc(e,t){if(b(e)||e===null)return t;if(e instanceof _s)return e;if(Lc(e)){let n=e.toLowerCase();return n==="default"?t:n===`local`||n===`system`?ys.instance:n===`utc`||n===`gmt`?$s.utcInstance:$s.parseSpecifier(n)||Es.create(e)}else if(Fc(e))return $s.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new ec(e)}var nc={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},rc={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]},ic=nc.hanidec.replace(/[\[|\]]/g,``).split(``);function ac(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(nc.hanidec)!==-1)t+=ic.indexOf(e[n]);else for(let e in rc){let[n,i]=rc[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var oc=new Map;function sc(){oc.clear()}function cc({numberingSystem:e},t=``){let n=e||`latn`,r=oc.get(n);r===void 0&&(r=new Map,oc.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${nc[n]}${t}`),r.set(t,i)),i}var lc=()=>Date.now(),uc=`system`,dc=null,fc=null,pc=null,mc=60,hc,gc=null,_c=class{static get now(){return lc}static set now(e){lc=e}static set defaultZone(e){uc=e}static get defaultZone(){return tc(uc,ys.instance)}static get defaultLocale(){return dc}static set defaultLocale(e){dc=e}static get defaultNumberingSystem(){return fc}static set defaultNumberingSystem(e){fc=e}static get defaultOutputCalendar(){return pc}static set defaultOutputCalendar(e){pc=e}static get defaultWeekSettings(){return gc}static set defaultWeekSettings(e){gc=Gc(e)}static get twoDigitCutoffYear(){return mc}static set twoDigitCutoffYear(e){mc=e%100}static get throwOnInvalid(){return hc}static set throwOnInvalid(e){hc=e}static resetCaches(){Zs.resetCache(),Es.resetCache(),Xd.resetCache(),sc()}},vc=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},yc=[0,31,59,90,120,151,181,212,243,273,304,334],bc=[0,31,60,91,121,152,182,213,244,274,305,335];function xc(e,t){return new vc(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function Sc(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 Cc(e,t,n){return n+($c(e)?bc:yc)[t-1]}function wc(e,t){let n=$c(e)?bc:yc,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function Tc(e,t){return(e-t+7)%7+1}function Ec(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Cc(r,i,a),s=Tc(Sc(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=il(l,t,n)):c>il(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...dl(e)}}function Dc(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=Tc(Sc(r,1,t),n),s=el(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=el(l)):c>s?(l=r+1,c-=el(r)):l=r;let{month:u,day:d}=wc(l,c);return{year:l,month:u,day:d,...dl(e)}}function Oc(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Cc(t,n,r),...dl(e)}}function kc(e){let{year:t,ordinal:n}=e,{month:r,day:i}=wc(t,n);return{year:t,month:r,day:i,...dl(e)}}function Ac(e,t){if(!b(e.localWeekday)||!b(e.localWeekNumber)||!b(e.localWeekYear)){if(!b(e.weekday)||!b(e.weekNumber)||!b(e.weekYear))throw new Uo(`Cannot mix locale-based week fields with ISO-based week fields`);return b(e.localWeekday)||(e.weekday=e.localWeekday),b(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),b(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 jc(e,t=4,n=1){let r=Ic(e.weekYear),i=Kc(e.weekNumber,1,il(e.weekYear,t,n)),a=Kc(e.weekday,1,7);return r?i?a?!1:xc(`weekday`,e.weekday):xc(`week`,e.weekNumber):xc(`weekYear`,e.weekYear)}function Mc(e){let t=Ic(e.year),n=Kc(e.ordinal,1,el(e.year));return t?n?!1:xc(`ordinal`,e.ordinal):xc(`year`,e.year)}function Nc(e){let t=Ic(e.year),n=Kc(e.month,1,12),r=Kc(e.day,1,tl(e.year,e.month));return t?n?r?!1:xc(`day`,e.day):xc(`month`,e.month):xc(`year`,e.year)}function Pc(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Kc(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Kc(n,0,59),s=Kc(r,0,59),c=Kc(i,0,999);return a?o?s?c?!1:xc(`millisecond`,i):xc(`second`,r):xc(`minute`,n):xc(`hour`,t)}function b(e){return e===void 0}function Fc(e){return typeof e==`number`}function Ic(e){return typeof e==`number`&&e%1==0}function Lc(e){return typeof e==`string`}function Rc(e){return Object.prototype.toString.call(e)===`[object Date]`}function zc(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Bc(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Vc(e){return Array.isArray(e)?e:[e]}function Hc(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 Uc(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Wc(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Gc(e){if(e==null)return null;if(typeof e!=`object`)throw new Go(`Week settings must be an object`);if(!Kc(e.firstDay,1,7)||!Kc(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Kc(e,1,7)))throw new Go(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Kc(e,t,n){return Ic(e)&&e>=t&&e<=n}function qc(e,t){return e-t*Math.floor(e/t)}function Jc(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Yc(e){if(!(b(e)||e===null||e===``))return parseInt(e,10)}function Xc(e){if(!(b(e)||e===null||e===``))return parseFloat(e)}function Zc(e){if(!(b(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Qc(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 $c(e){return e%4==0&&(e%100!=0||e%400==0)}function el(e){return $c(e)?366:365}function tl(e,t){let n=qc(t-1,12)+1,r=e+(t-n)/12;return n===2?$c(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function nl(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 rl(e,t,n){return-Tc(Sc(e,1,t),n)+t-1}function il(e,t=4,n=1){let r=rl(e,t,n),i=rl(e+1,t,n);return(el(e)-r+i)/7}function al(e){return e>99?e:e>_c.twoDigitCutoffYear?1900+e:2e3+e}function ol(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 sl(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 cl(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new Go(`Invalid unit value ${e}`);return t}function ll(e,t){let n={};for(let r in e)if(Wc(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=cl(i)}return n}function ul(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}${Jc(n,2)}:${Jc(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${Jc(n,2)}${Jc(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function dl(e){return Uc(e,[`hour`,`minute`,`second`,`millisecond`])}var fl=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],pl=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ml=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function hl(e){switch(e){case`narrow`:return[...ml];case`short`:return[...pl];case`long`:return[...fl];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 gl=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],_l=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],vl=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];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`];default:return null}}var bl=[`AM`,`PM`],xl=[`Before Christ`,`Anno Domini`],Sl=[`BC`,`AD`],Cl=[`B`,`A`];function wl(e){switch(e){case`narrow`:return[...Cl];case`short`:return[...Sl];case`long`:return[...xl];default:return null}}function Tl(e){return bl[e.hour<12?0:1]}function El(e,t){return yl(t)[e.weekday-1]}function Dl(e,t){return hl(t)[e.month-1]}function Ol(e,t){return wl(t)[e.year<0?0:1]}function kl(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 Al(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var jl={D:Yo,DD:Xo,DDD:Qo,DDDD:$o,t:es,tt:ts,ttt:ns,tttt:rs,T:is,TT:as,TTT:os,TTTT:ss,f:cs,ff:us,fff:ps,ffff:hs,F:ls,FF:ds,FFF:ms,FFFF:gs},Ml=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 jl[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 Jc(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?Tl(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?Dl(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?El(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?Ol(t,e):a({era:e},`era`);return Al(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 Al(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Nl=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Pl(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Fl(...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 Il(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 Ll(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Yc(t[n+i]);return[r,null,n+i]}}var Rl=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,zl=`(?:${Rl.source}?(?:\\[(${Nl.source})\\])?)?`,Bl=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Vl=RegExp(`${Bl.source}${zl}`),Hl=RegExp(`(?:[Tt]${Vl.source})?`),Ul=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Wl=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Gl=/(\d{4})-?(\d{3})/,Kl=Ll(`weekYear`,`weekNumber`,`weekDay`),ql=Ll(`year`,`ordinal`),Jl=/(\d{4})-(\d\d)-(\d\d)/,Yl=RegExp(`${Bl.source} ?(?:${Rl.source}|(${Nl.source}))?`),Xl=RegExp(`(?: ${Yl.source})?`);function Zl(e,t,n){let r=e[t];return b(r)?n:Yc(r)}function Ql(e,t){return[{year:Zl(e,t),month:Zl(e,t+1,1),day:Zl(e,t+2,1)},null,t+3]}function $l(e,t){return[{hours:Zl(e,t,0),minutes:Zl(e,t+1,0),seconds:Zl(e,t+2,0),milliseconds:Zc(e[t+3])},null,t+4]}function eu(e,t){let n=!e[t]&&!e[t+1],r=sl(e[t+1],e[t+2]);return[{},n?null:$s.instance(r),t+3]}function tu(e,t){return[{},e[t]?Es.create(e[t]):null,t+1]}var nu=RegExp(`^T?${Bl.source}$`),ru=/^-?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 iu(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(Xc(n)),months:f(Xc(r)),weeks:f(Xc(i)),days:f(Xc(a)),hours:f(Xc(o)),minutes:f(Xc(s)),seconds:f(Xc(c),c===`-0`),milliseconds:f(Zc(l),d)}]}var au={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function ou(e,t,n,r,i,a,o){let s={year:t.length===2?al(Yc(t)):Yc(t),month:pl.indexOf(n)+1,day:Yc(r),hour:Yc(i),minute:Yc(a)};return o&&(s.second=Yc(o)),e&&(s.weekday=e.length>3?gl.indexOf(e)+1:_l.indexOf(e)+1),s}var su=/^(?:(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 cu(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=ou(t,i,r,n,a,o,s),p;return p=c?au[c]:l?0:sl(u,d),[f,new $s(p)]}function lu(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var uu=/^(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$/,du=/^(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$/,fu=/^(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 pu(e){let[,t,n,r,i,a,o,s]=e;return[ou(t,i,r,n,a,o,s),$s.utcInstance]}function mu(e){let[,t,n,r,i,a,o,s]=e;return[ou(t,s,n,r,i,a,o),$s.utcInstance]}var hu=Pl(Ul,Hl),gu=Pl(Wl,Hl),_u=Pl(Gl,Hl),vu=Pl(Vl),yu=Fl(Ql,$l,eu,tu),bu=Fl(Kl,$l,eu,tu),xu=Fl(ql,$l,eu,tu),Su=Fl($l,eu,tu);function Cu(e){return Il(e,[hu,yu],[gu,bu],[_u,xu],[vu,Su])}function wu(e){return Il(lu(e),[su,cu])}function Tu(e){return Il(e,[uu,pu],[du,pu],[fu,mu])}function Eu(e){return Il(e,[ru,iu])}var Du=Fl($l);function Ou(e){return Il(e,[nu,Du])}var ku=Pl(Jl,Xl),Au=Pl(Yl),ju=Fl($l,eu,tu);function Mu(e){return Il(e,[ku,yu],[Au,ju])}var Nu=`Invalid Duration`,Pu={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}},Fu={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},...Pu},Iu=146097/400,Lu=146097/4800,Ru={years:{quarters:4,months:12,weeks:Iu/7,days:Iu,hours:Iu*24,minutes:Iu*24*60,seconds:Iu*24*60*60,milliseconds:Iu*24*60*60*1e3},quarters:{months:3,weeks:Iu/28,days:Iu/4,hours:Iu*24/4,minutes:Iu*24*60/4,seconds:Iu*24*60*60/4,milliseconds:Iu*24*60*60*1e3/4},months:{weeks:Lu/7,days:Lu,hours:Lu*24,minutes:Lu*24*60,seconds:Lu*24*60*60,milliseconds:Lu*24*60*60*1e3},...Pu},zu=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Bu=zu.slice(0).reverse();function Vu(e,t,n=!1){return new Gu({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 Hu(e,t){let n=t.milliseconds??0;for(let r of Bu.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Uu(e,t){let n=Hu(e,t)<0?-1:1;zu.reduceRight((r,i)=>{if(b(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),zu.reduce((n,r)=>{if(b(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Wu(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Gu=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Ru:Fu;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||Zs.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 Go(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:ll(t,e.normalizeUnit),loc:Zs.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(Fc(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new Go(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=Eu(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]=Ou(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 Go(`need to specify a reason the Duration is invalid`);let r=t instanceof vc?t:new vc(t,n);if(_c.throwOnInvalid)throw new Ho(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 Wo(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?Ml.create(this.loc,n).formatDurationFromString(this,e):Nu}toHuman(e={}){if(!this.isValid)return Nu;let t=e.showZeros!==!1,n=zu.map(n=>{let r=this.values[n];return b(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+=Qc(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},Xd.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?Hu(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 zu)(Wc(n.values,e)||Wc(this.values,e))&&(r[e]=n.get(e)+this.get(e));return Vu(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]=cl(e(this.values[n],n));return Vu(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...ll(t,e.normalizeUnit)};return Vu(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 Vu(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Uu(this.matrix,e),Vu(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Wu(this.normalize().shiftToAll().toObject());return Vu(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 zu)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;Fc(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else Fc(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 Uu(this.matrix,n),Vu(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 Vu(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Wu(this.values);return Vu(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 zu)if(!t(this.values[n],e.values[n]))return!1;return!0}},Ku=`Invalid Interval`;function qu(e,t){return!e||!e.isValid?Ju.invalid(`missing or invalid start`):!t||!t.isValid?Ju.invalid(`missing or invalid end`):t<e?Ju.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 Ju=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 Go(`need to specify a reason the Interval is invalid`);let r=t instanceof vc?t:new vc(t,n);if(_c.throwOnInvalid)throw new Vo(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=Zd(t),i=Zd(n);return qu(r,i)??new e({start:r,end:i})}static after(t,n){let r=Gu.fromDurationLike(n),i=Zd(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Gu.fromDurationLike(n),i=Zd(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=Xd.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=Xd.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Gu.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Gu.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(Zd).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=Gu.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()})`:Ku}[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=Yo,t={}){return this.isValid?Ml.create(this.s.loc.clone(t),e).formatInterval(this):Ku}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Ku}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Ku}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Ku}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Ku}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Gu.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Yu=class{static hasDST(e=_c.defaultZone){let t=Xd.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return Es.isValidZone(e)}static normalizeZone(e){return tc(e,_c.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||Zs.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||Zs.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||Zs.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||Zs.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||Zs.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||Zs.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||Zs.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return Zs.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return Zs.create(t,null,`gregory`).eras(e)}static features(){return{relative:zc(),localeWeek:Bc()}}};function Xu(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Gu.fromMillis(r).as(`days`))}function Zu(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=Xu(e,t);return(n-n%7)/7}],[`days`,Xu]],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 Qu(e,t,n,r){let[i,a,o,s]=Zu(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=Gu.fromObject(a,r);return l.length>0?Gu.fromMillis(c,r).shiftTo(...l).plus(u):u}var $u=`missing Intl.DateTimeFormat.formatToParts support`;function x(e,t=e=>e){return{regex:e,deser:([e])=>t(ac(e))}}var ed=`[ \xA0]`,td=new RegExp(ed,`g`);function nd(e){return e.replace(/\./g,`\\.?`).replace(td,ed)}function rd(e){return e.replace(/\./g,``).replace(td,` `).toLowerCase()}function id(e,t){return e===null?null:{regex:RegExp(e.map(nd).join(`|`)),deser:([n])=>e.findIndex(e=>rd(n)===rd(e))+t}}function ad(e,t){return{regex:e,deser:([,e,t])=>sl(e,t),groups:t}}function od(e){return{regex:e,deser:([e])=>e}}function sd(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function cd(e,t){let n=cc(t),r=cc(t,`{2}`),i=cc(t,`{3}`),a=cc(t,`{4}`),o=cc(t,`{6}`),s=cc(t,`{1,2}`),c=cc(t,`{1,3}`),l=cc(t,`{1,6}`),u=cc(t,`{1,9}`),d=cc(t,`{2,4}`),f=cc(t,`{4,6}`),p=e=>({regex:RegExp(sd(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return id(t.eras(`short`),0);case`GG`:return id(t.eras(`long`),0);case`y`:return x(l);case`yy`:return x(d,al);case`yyyy`:return x(a);case`yyyyy`:return x(f);case`yyyyyy`:return x(o);case`M`:return x(s);case`MM`:return x(r);case`MMM`:return id(t.months(`short`,!0),1);case`MMMM`:return id(t.months(`long`,!0),1);case`L`:return x(s);case`LL`:return x(r);case`LLL`:return id(t.months(`short`,!1),1);case`LLLL`:return id(t.months(`long`,!1),1);case`d`:return x(s);case`dd`:return x(r);case`o`:return x(c);case`ooo`:return x(i);case`HH`:return x(r);case`H`:return x(s);case`hh`:return x(r);case`h`:return x(s);case`mm`:return x(r);case`m`:return x(s);case`q`:return x(s);case`qq`:return x(r);case`s`:return x(s);case`ss`:return x(r);case`S`:return x(c);case`SSS`:return x(i);case`u`:return od(u);case`uu`:return od(s);case`uuu`:return x(n);case`a`:return id(t.meridiems(),0);case`kkkk`:return x(a);case`kk`:return x(d,al);case`W`:return x(s);case`WW`:return x(r);case`E`:case`c`:return x(n);case`EEE`:return id(t.weekdays(`short`,!1),1);case`EEEE`:return id(t.weekdays(`long`,!1),1);case`ccc`:return id(t.weekdays(`short`,!0),1);case`cccc`:return id(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return ad(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return ad(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return od(/[a-z_+-/]{1,256}?/i);case` `:return od(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:$u};return m.token=e,m}var ld={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 ud(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=ld[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function dd(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function fd(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Wc(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 pd(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 b(e.z)||(n=Es.create(e.z)),b(e.Z)||(n||=new $s(e.Z),r=e.Z),b(e.q)||(e.M=(e.q-1)*3+1),b(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),b(e.u)||(e.S=Zc(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var md=null;function hd(){return md||=Xd.fromMillis(1555555555555),md}function gd(e,t){if(e.literal)return e;let n=xd(Ml.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function _d(e,t){return Array.prototype.concat(...e.map(e=>gd(e,t)))}var vd=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=_d(Ml.parseFormat(t),e),this.units=this.tokens.map(t=>cd(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=dd(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=fd(e,this.regex,this.handlers),[r,i,a]=n?pd(n):[null,null,void 0];if(Wc(n,`a`)&&Wc(n,`H`))throw new Uo(`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 yd(e,t,n){return new vd(e,n).explainFromTokens(t)}function bd(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=yd(e,t,n);return[r,i,a,o]}function xd(e,t){if(!e)return null;let n=Ml.create(t,e).dtFormatter(hd()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>ud(t,e,i))}var Sd=`Invalid DateTime`,Cd=864e13;function wd(e){return new vc(`unsupported zone`,`the zone "${e.name}" is not supported`)}function Td(e){return e.weekData===null&&(e.weekData=Ec(e.c)),e.weekData}function Ed(e){return e.localWeekData===null&&(e.localWeekData=Ec(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function Dd(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new Xd({...n,...t,old:n})}function Od(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 kd(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 Ad(e,t,n){return Od(nl(e),t,n)}function jd(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,tl(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Gu.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]=Od(nl(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function Md(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=Xd.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return Xd.invalid(new vc(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function Nd(e,t,n=!0){return e.isValid?Ml.create(Zs.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function Pd(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=Jc(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=Jc(e.c.month),n===`month`)return i;i+=`-`}else if(i+=Jc(e.c.month),n===`month`)return i;return i+=Jc(e.c.day),i}function Fd(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+=Jc(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=Jc(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=Jc(e.c.second))}else{if(c+=Jc(e.c.minute),o===`minute`)break;s&&(c+=Jc(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=Jc(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=Jc(Math.trunc(-e.o/60)),c+=`:`,c+=Jc(Math.trunc(-e.o%60))):(c+=`+`,c+=Jc(Math.trunc(e.o/60)),c+=`:`,c+=Jc(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Id={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Ld={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Rd={ordinal:1,hour:0,minute:0,second:0,millisecond:0},zd=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],Bd=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],Vd=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function Hd(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 Wo(e);return t}function Ud(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return Hd(e)}}function Wd(e){if(Jd===void 0&&(Jd=_c.now()),e.type!==`iana`)return e.offset(Jd);let t=e.name,n=Yd.get(t);return n===void 0&&(n=e.offset(Jd),Yd.set(t,n)),n}function Gd(e,t){let n=tc(t.zone,_c.defaultZone);if(!n.isValid)return Xd.invalid(wd(n));let r=Zs.fromObject(t),i,a;if(b(e.year))i=_c.now();else{for(let t of zd)b(e[t])&&(e[t]=Id[t]);let t=Nc(e)||Pc(e);if(t)return Xd.invalid(t);let r=Wd(n);[i,a]=Ad(e,r,n)}return new Xd({ts:i,zone:n,loc:r,o:a})}function Kd(e,t,n){let r=b(n.round)?!0:n.round,i=b(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Qc(e,r||n.calendary?0:2,n.calendary?`round`:i),t.loc.clone(n).relFormatter(n).format(e,a)),o=r=>n.calendary?t.hasSame(e,r)?0:t.startOf(r).diff(e.startOf(r),r).get(r):t.diff(e,r).get(r);if(n.unit)return a(o(n.unit),n.unit);for(let e of n.units){let t=o(e);if(Math.abs(t)>=1)return a(t,e)}return a(e>t?-0:0,n.units[n.units.length-1])}function qd(e){let t={},n;return e.length>0&&typeof e[e.length-1]==`object`?(t=e[e.length-1],n=Array.from(e).slice(0,e.length-1)):n=Array.from(e),[t,n]}var Jd,Yd=new Map,Xd=class e{constructor(e){let t=e.zone||_c.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new vc(`invalid input`):null)||(t.isValid?null:wd(t));this.ts=b(e.ts)?_c.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=Fc(e.o)&&!e.old?e.o:t.offset(this.ts);r=kd(this.ts,a),n=Number.isNaN(r.year)?new vc(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||Zs.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=qd(arguments),[n,r,i,a,o,s,c]=t;return Gd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=qd(arguments),[n,r,i,a,o,s,c]=t;return e.zone=$s.utcInstance,Gd({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Rc(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=tc(n.zone,_c.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:Zs.fromObject(n)}):e.invalid(wd(i))}static fromMillis(t,n={}){if(!Fc(t))throw new Go(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`);return t<-864e13||t>Cd?e.invalid(`Timestamp out of range`):new e({ts:t,zone:tc(n.zone,_c.defaultZone),loc:Zs.fromObject(n)})}static fromSeconds(t,n={}){if(Fc(t))return new e({ts:t*1e3,zone:tc(n.zone,_c.defaultZone),loc:Zs.fromObject(n)});throw new Go(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=tc(n.zone,_c.defaultZone);if(!r.isValid)return e.invalid(wd(r));let i=Zs.fromObject(n),a=ll(t,Ud),{minDaysInFirstWeek:o,startOfWeek:s}=Ac(a,i),c=_c.now(),l=b(n.specificOffset)?r.offset(c):n.specificOffset,u=!b(a.ordinal),d=!b(a.year),f=!b(a.month)||!b(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new Uo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Uo(`Can't mix ordinal dates with month/day`);let ee=m||a.weekday&&!p,te,ne,re=kd(c,l);ee?(te=Bd,ne=Ld,re=Ec(re,o,s)):u?(te=Vd,ne=Rd,re=Oc(re)):(te=zd,ne=Id);let ie=!1;for(let e of te){let t=a[e];b(t)?ie?a[e]=ne[e]:a[e]=re[e]:ie=!0}let ae=(ee?jc(a,o,s):u?Mc(a):Nc(a))||Pc(a);if(ae)return e.invalid(ae);let[oe,se]=Ad(ee?Dc(a,o,s):u?kc(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]=Cu(e);return Md(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=wu(e);return Md(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=Tu(e);return Md(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(b(t)||b(n))throw new Go(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=bd(Zs.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):Md(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]=Mu(e);return Md(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new Go(`need to specify a reason the DateTime is invalid`);let r=t instanceof vc?t:new vc(t,n);if(_c.throwOnInvalid)throw new Bo(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=xd(e,Zs.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return _d(Ml.parseFormat(e),Zs.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){Jd=void 0,Yd.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?Td(this).weekYear:NaN}get weekNumber(){return this.isValid?Td(this).weekNumber:NaN}get weekday(){return this.isValid?Td(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?Ed(this).weekday:NaN}get localWeekNumber(){return this.isValid?Ed(this).weekNumber:NaN}get localWeekYear(){return this.isValid?Ed(this).weekYear:NaN}get ordinal(){return this.isValid?Oc(this.c).ordinal:NaN}get monthShort(){return this.isValid?Yu.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Yu.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Yu.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Yu.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=nl(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=kd(s,a),u=kd(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[Dd(this,{ts:s}),Dd(this,{ts:c})]:[this]}get isInLeapYear(){return $c(this.year)}get daysInMonth(){return tl(this.year,this.month)}get daysInYear(){return this.isValid?el(this.year):NaN}get weeksInWeekYear(){return this.isValid?il(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?il(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=Ml.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone($s.instance(e),t)}toLocal(){return this.setZone(_c.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=tc(t,_c.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]=Ad(r,n,t)}return Dd(this,{ts:e,zone:t})}else return e.invalid(wd(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return Dd(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=ll(e,Ud),{minDaysInFirstWeek:n,startOfWeek:r}=Ac(t,this.loc),i=!b(t.weekYear)||!b(t.weekNumber)||!b(t.weekday),a=!b(t.ordinal),o=!b(t.year),s=!b(t.month)||!b(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new Uo(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Uo(`Can't mix ordinal dates with month/day`);let u;i?u=Dc({...Ec(this.c,n,r),...t},n,r):b(t.ordinal)?(u={...this.toObject(),...t},b(t.day)&&(u.day=Math.min(tl(u.year,u.month),u.day))):u=kc({...Oc(this.c),...t});let[d,f]=Ad(u,this.o,this.zone);return Dd(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Gu.fromDurationLike(e);return Dd(this,jd(this,t))}minus(e){if(!this.isValid)return this;let t=Gu.fromDurationLike(e).negate();return Dd(this,jd(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Gu.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?Ml.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):Sd}toLocaleString(e=Yo,t={}){return this.isValid?Ml.create(this.loc.clone(t),e).formatDateTime(this):Sd}toLocaleParts(e={}){return this.isValid?Ml.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=Hd(a);let o=e===`extended`,s=Pd(this,o,a);return zd.indexOf(a)>=3&&(s+=`T`),s+=Fd(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?Pd(this,e===`extended`,Hd(t)):null}toISOWeekDate(){return Nd(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=Hd(o),(r&&zd.indexOf(o)>=3?`T`:``)+Fd(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return Nd(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return Nd(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?Pd(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`)),Nd(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():Sd}[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 Gu.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Vc(t).map(Gu.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Qu(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?Ju.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),Kd(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?Kd(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 Go(`min requires all arguments be DateTimes`);return Hc(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new Go(`max requires all arguments be DateTimes`);return Hc(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return yd(Zs.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 vd(Zs.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(b(t)||b(n))throw new Go(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=Zs.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new Go(`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):Md(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Yo}static get DATE_MED(){return Xo}static get DATE_MED_WITH_WEEKDAY(){return Zo}static get DATE_FULL(){return Qo}static get DATE_HUGE(){return $o}static get TIME_SIMPLE(){return es}static get TIME_WITH_SECONDS(){return ts}static get TIME_WITH_SHORT_OFFSET(){return ns}static get TIME_WITH_LONG_OFFSET(){return rs}static get TIME_24_SIMPLE(){return is}static get TIME_24_WITH_SECONDS(){return as}static get TIME_24_WITH_SHORT_OFFSET(){return os}static get TIME_24_WITH_LONG_OFFSET(){return ss}static get DATETIME_SHORT(){return cs}static get DATETIME_SHORT_WITH_SECONDS(){return ls}static get DATETIME_MED(){return us}static get DATETIME_MED_WITH_SECONDS(){return ds}static get DATETIME_MED_WITH_WEEKDAY(){return fs}static get DATETIME_FULL(){return ps}static get DATETIME_FULL_WITH_SECONDS(){return ms}static get DATETIME_HUGE(){return hs}static get DATETIME_HUGE_WITH_SECONDS(){return gs}};function Zd(e){if(Xd.isDateTime(e))return e;if(e&&e.valueOf&&Fc(e.valueOf()))return Xd.fromJSDate(e);if(e&&typeof e==`object`)return Xd.fromObject(e);throw new Go(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function Qd(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 $d=`1`,ef=`0..1`,tf=`*`,nf=`0..*`,rf=new Map([[`-`,[`1`,`1`]],[`<>`,[`*`,`*`]],[`>`,[`*`,`1`]],[`<`,[`1`,`*`]],[`-?`,[`1`,ef]],[`?-`,[ef,`1`]],[`?-?`,[ef,ef]],[`?>`,[nf,`1`]],[`>?`,[`*`,ef]],[`?>?`,[nf,ef]],[`?<`,[ef,`*`]],[`<?`,[`1`,nf]],[`?<?`,[ef,nf]],[`?<>`,[nf,`*`]],[`<>?`,[`*`,nf]],[`?<>?`,[nf,nf]]]),af=new Map([...rf.entries()].map(([e,[t,n]])=>[`${t}-${n}`,e]));function of(e){return rf.get(e)}function sf(e){return Qd(e).max===1}function cf(e){return Qd(e).max===`*`}function lf(e){return Qd(e).min===0}function uf(e){return Qd(e).min>=1}function df(e){return e.replace(/\?/g,``)}function ff(e,t){return af.get(`${e}-${t}`)??`<>`}function pf(e){let{min:t,max:n}=Qd(e);return t===0?e:n===`*`?nf:ef}function mf(e){let{min:t,max:n}=Qd(e);return t>=1?e:n===`*`?`*`:`1`}function hf(e){let{min:t,max:n}=Qd(e);return n===`*`?e:t===0?nf:`*`}var S=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_DEP_CONTEXT=3042]=`INVALID_DEP_CONTEXT`,e[e.INVALID_DEP_FIELD=3043]=`INVALID_DEP_FIELD`,e[e.INVALID_NOTE_CONTEXT=3044]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3045]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3046]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3047]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3048]=`EMPTY_NOTE`,e[e.UNKNOWN_NOTE_SETTING=3049]=`UNKNOWN_NOTE_SETTING`,e[e.DUPLICATE_NOTE_SETTING=3050]=`DUPLICATE_NOTE_SETTING`,e[e.INVALID_NOTE_SETTING_VALUE=3051]=`INVALID_NOTE_SETTING_VALUE`,e[e.INVALID_INDEXES_CONTEXT=3052]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3053]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3054]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3055]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3056]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3057]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3058]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3059]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3060]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3061]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3062]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3063]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3064]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3065]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3066]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3067]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3069]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3070]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3071]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3072]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3073]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3074]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3075]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3076]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3077]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3078]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3079]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3080]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3081]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3082]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3083]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3084]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3085]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3086]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.UNKNOWN_RECORDS_SETTING=3087]=`UNKNOWN_RECORDS_SETTING`,e[e.DUPLICATE_RECORDS_SETTING=3088]=`DUPLICATE_RECORDS_SETTING`,e[e.INVALID_RECORDS_SETTING_VALUE=3089]=`INVALID_RECORDS_SETTING_VALUE`,e[e.INVALID_USE_CONTEXT=3090]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3091]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3092]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3093]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3094]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3095]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3096]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.DEP_SELF_LOOP=5003]=`DEP_SELF_LOOP`,e[e.DEP_MIXED_DOWNSTREAM_TABLES=5004]=`DEP_MIXED_DOWNSTREAM_TABLES`,e[e.DEP_DUPLICATE_DOWNSTREAM_TABLE=5005]=`DEP_DUPLICATE_DOWNSTREAM_TABLE`,e[e.DEP_MIXED_LEVEL=5006]=`DEP_MIXED_LEVEL`,e[e.UNEQUAL_FIELDS_BINARY_REF=5007]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5008]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5009]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e[e.INVALID_METADATA_TARGET_KIND=5010]=`INVALID_METADATA_TARGET_KIND`,e[e.INVALID_METADATA_FIELD=5011]=`INVALID_METADATA_FIELD`,e[e.DUPLICATE_METADATA_FIELD=5012]=`DUPLICATE_METADATA_FIELD`,e[e.UNKNOWN_KIND=6e3]=`UNKNOWN_KIND`,e[e.MISSING_NAME=6001]=`MISSING_NAME`,e[e.RESERVED_KIND=6002]=`RESERVED_KIND`,e[e.UNKNOWN_ENDPOINT=6003]=`UNKNOWN_ENDPOINT`,e[e.EMPTY_LINK=6004]=`EMPTY_LINK`,e[e.BAD_LINK=6005]=`BAD_LINK`,e[e.UNKNOWN_METADATA_TARGET=6006]=`UNKNOWN_METADATA_TARGET`,e[e.BAD_PROPERTY=6007]=`BAD_PROPERTY`,e[e.DUPLICATE_PROPERTY=6008]=`DUPLICATE_PROPERTY`,e[e.DIAGRAM_TYPE_NOT_HERE=6009]=`DIAGRAM_TYPE_NOT_HERE`,e[e.METADATA_KIND_MISMATCH=6010]=`METADATA_KIND_MISMATCH`,e[e.UNKNOWN_TYPE=6011]=`UNKNOWN_TYPE`,e[e.UNKNOWN_ICON=6012]=`UNKNOWN_ICON`,e[e.BAD_IMAGE=6013]=`BAD_IMAGE`,e[e.DUPLICATE_LINK=6014]=`DUPLICATE_LINK`,e[e.NESTED_ENDPOINTS=6015]=`NESTED_ENDPOINTS`,e}({}),gf=function(e){return e.RefColumnMismatch=`Mismatched optional ref constraints`,e.RecordValueTypeMismatch=`Record type errors`,e.RecordConstraintViolation=`Record constraint violations`,e.Other=`Other`,e}({}),C=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.details=i,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new _f(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},_f=class extends Error{constructor(e,t,n,r){super(t),this.code=e,this.diagnostic=t,this.details=r,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,C.prototype)}get filepath(){return this.nodeOrToken.filepath}},vf=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.diagnostic=n,this.details=i,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}get quickFixes(){return this.details?.quickFixes}get filepath(){return this.nodeOrToken.filepath}};function yf(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function bf(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function xf(e){let[t]=e;return bf(t)||yf(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Sf(e){return yf(e)||bf(e)}function Cf(e){let t=A(e);return t!==void 0&&t.length>0}function wf(e){return Tf(e)}function Tf(e){return e instanceof km&&e.expression instanceof Om}function Ef(e){return!!e.bodyColon}function Df(e){return e instanceof z&&e.op?.value===`~`&&E(e.expression)}function Of(e){return e!==void 0&&rf.has(e)}function kf(e){return e===`<-`||e===`->`}function Af(e){if(!(e instanceof km)||!(e.expression instanceof Em)||e.expression.literal?.kind!==_.COLOR_LITERAL)return!1;let t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!==`#`)return!1;for(let e=1;e<t.length;e+=1)if(!xf(t[e]))return!1;return!0}function jf(e){return Af(e)?!0:Bf(e)&&e.expression.variable.value.toLowerCase()===`none`}function Mf(e){if(T(e)||Nf(e)||Bf(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof z&&bo.includes(e.op?.value)&&Nf(e.expression)||e instanceof xm)return!0;if(!e||!Vf(e))return!1;let t=ap(e);return t.length===2||t.length===3}function Nf(e){return e instanceof z?bo.includes(e.op.value)?Nf(e.expression):!1:e instanceof km&&e.expression instanceof Em&&e.expression.literal?.kind===_.NUMERIC_LITERAL}function Pf(e){if(!(e instanceof z)||!Of(e.op?.value))return!1;let t=A(e.expression);return t!==void 0&&t.length>0}function Ff(e){if(!(e instanceof z)||!kf(e.op?.value))return!1;let t=A(e.expression);return t!==void 0&&t.length>0}function If(e){return e instanceof Sm&&e.elementList.every(E)}function Lf(e){if(!(e instanceof Tm||D(e)||e instanceof km||e instanceof jm))return!1;for(;e instanceof Tm||e instanceof jm;)if(e instanceof Tm){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Nf(e)||T(e)||Bf(e)))return!1;e=e.callee}else if(e instanceof jm){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Nf(e.name)))return!1;e=e.array}let t=A(e);return t!==void 0&&t.length>0}function Rf(e){return T(e)||Af(e)}function w(e){let t={},r=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof km){r.push(new C(S.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let n=tp(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 T(e){return e instanceof km&&(e.expression instanceof Om&&e.expression.variable instanceof Ha&&e.expression.variable.kind===_.QUOTED_STRING||e.expression instanceof Em&&e.expression.literal?.kind===_.STRING_LITERAL)}function E(e){return e instanceof km&&e.expression instanceof Om&&e.expression.variable instanceof Ha}function zf(e){return e?e instanceof Dm:!1}function Bf(e){return e instanceof km&&e.expression instanceof Om&&e.expression.variable?.kind===_.IDENTIFIER}function D(e){return e instanceof B&&e.leftExpression instanceof F&&e.rightExpression instanceof F&&e.op?.value===`.`}function Vf(e){return E(e)?!0:D(e)&&E(e.rightExpression)&&Vf(e.leftExpression)}function O(e,t){return e instanceof L&&e.isKind(t)}function Hf(e){return e instanceof gm}function Uf(e,t){return e instanceof _m&&(t===void 0||e.isKind(t))}function Wf(e){return e instanceof I}function k(e,...t){return e instanceof V&&e.parent instanceof L&&e.parent.isKind(...t)}function Gf(e,t){let n=e.parent;return n instanceof L&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Kf(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 qf(e){return!!e.parentOfKind(U)}function Jf(e,t){let n=e.parentOfKind(R);return!n||(n.name instanceof km?M(n.name):tp(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function Yf(e){return!(e instanceof B)||!Of(e.op?.value)?!1:op(e.leftExpression)!==void 0&&op(e.rightExpression)!==void 0}function Xf(e){let t=op(e.leftExpression),n=op(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function Zf(e){return e instanceof km&&e.expression instanceof Om||e instanceof xm}function Qf(e){if(E(e))return e;if(D(e)){let t=e.rightExpression;if(t&&E(t))return t}}function $f(e){let t=e.parentNode;return!D(t)||t.rightExpression!==e?!1:!(D(t.parentNode)&&t.parentNode.leftExpression===t)}function ep(e){if(E(e))return e.expression.variable}function tp(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function np(e){if(!(e instanceof L))return;let t=A(e?.name);return t===void 0?void 0:t.join(`.`)}function rp(e){return e.elementList.length===0}function ip(e){return e?.body?e.body instanceof H?e.body.body:[e.body]:[]}function ap(e){if(!e)return;if(!D(e))return[e];let t=ap(e.leftExpression);if(t)return t.push(e.rightExpression),t}function A(e){if(e===void 0)return;let t=ap(e);if(!t)return;let n=[];for(let e of t){let t=M(e);if(typeof t!=`string`)return;n.push(t)}return n}function op(e){if(e===void 0)return;let t=ap(e);if(!t||t.length===0)return;let n=[];if(!E(h(t))){let e=t.pop();if(If(e))n=e.elementList;else return}let r=t;if(r.every(E))return{variables:r,tupleElements:n}}function sp(e){if(Zf(e))return e instanceof xm?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof Sm&&e.elementList.every(Zf))return{functional:e.elementList.filter(e=>e instanceof xm),nonFunctional:e.elementList.filter(E)}}function j(e){if(T(e))return e.expression instanceof Om?e?.expression?.variable?.value:e.expression.literal.value}function cp(e){return e instanceof km&&e.expression instanceof Em&&e.expression.literal?.kind===_.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function lp(e){if(!(e instanceof Tm)||!e.callee)return;let t=ap(e.callee);if(!t||t.length===0||!t.every(E))return;let n=[];return If(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function M(e){if(E(e))return e.expression.variable.value}function up(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function dp(e){if(e.name instanceof ym)return tp(e.name)?.toLowerCase();if(e.name instanceof km)return M(e.name)}function fp(e){return Bf(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Am}function pp(e){return j(e)===``}function mp(e){return e instanceof xm}function hp(e){let t=cp(e);if(t!==null)return t;if(Nf(e)&&e instanceof z&&e.expression){let t=e.op?.value,n=cp(e.expression);if(n!==null)return t===`-`?-n:n}return null}function gp(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=hp(e);if(t!==null)return t;let n=j(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function _p(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=hp(e);if(t!==null)return Number.isInteger(t)?t:null;let n=j(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var vp=[`true`,`yes`,`y`,`t`,`1`],yp=[`false`,`no`,`n`,`f`,`0`];function bp(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 vp.includes(t)?!0:yp.includes(t)?!1:null}if(Bf(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=cp(e);if(t===0)return!1;if(t===1)return!0;let n=j(e)?.toLowerCase();if(n){if(vp.includes(n))return!0;if(yp.includes(n))return!1}return null}function xp(e){if(e==null)return null;if(typeof e==`string`)return e;let t=A(e);return t?h(t):j(e)??null}function Sp(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=j(e)??null??gp(e)??bp(e);return t===null?null:t.toString()}var Cp=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],wp=[`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`],Tp=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function Ep(e){if(e==null)return null;let t=typeof e==`string`?e:j(e)??null;if(t===null)return null;for(let e of Tp){let n=Xd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of Cp){let n=Xd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of wp){let n=Xd.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=Xd.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 Dp(e){return e instanceof z?`${e.op?.value}${Dp(e.expression)}`:e.expression.literal.value}function Op(e){return e instanceof z?e.op?.value===`-`?-Op(e.expression):Op(e.expression):Number.parseFloat(e.expression.literal.value)}function N(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 kp(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 Ip(e){let t=j(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function Lp(e){if(If(e))return e.expression.literal.value;if(Kf(e)&&N(e)?.toLowerCase()===`none`)return Eo}function Rp(e){if(e){if(E(e)){let t=M(e);if(t!==void 0)return{value:t,type:`string`}}if(zf(e))return{type:`number`,value:Pp(e)};if(Kf(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof ym&&e.value)return{value:e.value.value,type:`expression`};if(qf(e)){let t=dp(e)?.at(-1),n=t?N(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function zp(e,t){let r=``,i=null;if(t instanceof Cm){if(i=(t.argumentList?.elementList??[]).map(e=>zf(e)?Np(e):E(e)?M(e):N(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof Cm||t instanceof km;)if(t instanceof Cm){if(r=`(${(t.argumentList?.elementList??[]).map(e=>zf(e)?Np(e):E(e)?M(e):N(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof km){if(r=`${`[${(t.indexer?.elementList??[]).map(e=>e?.name?.expression?.literal?.value??``).join(`,`)}]`}${r}`,!t.array)break;t=t.array}let{name:a,schemaName:o}=Ip(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new w(C.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}function Bp(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=Vp(e.value);a!==void 0&&(r[t]=a)}return r}function Vp(e){if(!e)return;let t=M(e);if(t!==void 0)return t;let n=Lp(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}({}),Hp={Table:`Table`,Enum:`Enum`,TableGroup:`TableGroup`,TablePartial:`TablePartial`,Note:`Note`,Schema:`Schema`},Up=function(e){return e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.Note=`Note`,e}({}),Wp=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},Gp=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()}},Kp=class e extends Gp{constructor({name:e,parent:t},n,r){super({kind:`Schema`},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===v}inNestedSchema(t,n){let r=this.members(t);if(r.some(e=>e.originalSymbol===n.originalSymbol))return!0;for(let i of r)if(i instanceof e&&i.inNestedSchema(t,n))return!0;return!1}},qp=class extends Gp{constructor({declaration:e,name:t},n,r){super({kind:`Enum`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Jp=class extends Gp{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=Fp(M(i));if(a)return{value:a,token:P(r)}}},Yp=class extends Gp{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 dm))}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=Fp(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?Lp(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===Wm.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===Wm.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===Wm.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===Wm.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof H)||!Nf(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===Wm.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===Wm.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=Lp(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=Fp(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}},Xp=class extends Gp{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 dm?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)}isInPkIndex(e){if(!this.declaration||!this.name)return!1;let n=(this instanceof dm?this.injectionDeclaration:this.declaration).parentOfKind(R);if(!n)return!1;let r=e.nodeSymbol(n).getFiltered(t);if(!(r instanceof Yp))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)||Wo(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 Rp(n)}type(e){if(!(this.declaration instanceof H))return;let n=zp(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 qp?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===Wm.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=Fp(M(i));if(a)return{value:a,token:P(r)}}},Zp=class extends Gp{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?Lp(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=Fp(M(i));if(a)return{value:a,token:P(r)}}},Qp=class extends Gp{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}},$p=class extends Gp{constructor({declaration:e,name:t},n,r){super({kind:`Note`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},em=class extends Gp{constructor({declaration:e,name:t},n,r){super({kind:`TablePartial`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},tm=class extends Gp{constructor({declaration:e,name:t},n,r){super({kind:`PartialInjection`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},nm=class extends Gp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},rm=class extends Gp{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}},im=class extends Gp{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}},am=class extends Gp{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}},om=class extends Gp{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}},sm=class extends Gp{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}},cm=class extends Gp{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 Kp&&r.inNestedSchema(e,t))return!0;return!1}},lm=class extends Gp{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}},um=class extends Gp{constructor({kind:e,declaration:t,useSpecifierDeclaration:n,usedSymbol:r,name:i},a,o){super({kind:e,declaration:t,name:i},a,o),this.useSpecifierDeclaration=n,this.usedSymbol=r}get canBeImported(){let e=this.useSpecifierDeclaration?.parentOfKind(mm);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},dm=class extends Xp{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},fm=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},I=class{constructor(e,t,n,r){this.id=e,this.kind=t,this.filepath=n;let i=r.find(e=>e!==void 0&&!Number.isNaN(e.start));i?(this.startPos=i.startPos,this.fullStart=i instanceof Ha?qa(i):i.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let a=[...r].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));a?(this.endPos=a.endPos,this.fullEnd=a instanceof Ha?Ka(a):a.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}intern(){return`node@${this.filepath.intern()}:${this.id}`}get parent(){let e=this.parentNode;for(;e;){if(e instanceof R||e instanceof L)return e;e=e.parentNode}}parentOfKind(e){let t=this;for(;t;){if(t instanceof e)return t;t=t.parentNode}}strictlyContains(e){if(typeof e==`number`)return this.start<e&&this.end>e;let{start:t,end:n}=e,r=this.start<t,i=r||this.start===t,a=this.end>n,o=a||this.end===n;return r&&o||i&&a}containsEq(e){if(typeof e==`number`)return this.start<=e&&this.end>=e;let{start:t,end:n}=e;return this.start<=t&&this.end>=n}},pm=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.USE_DECLARATION=`<use-declaration>`,e.USE_SPECIFIER=`<use-specifier>`,e.USE_SPECIFIER_LIST=`<use-specifier-list>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifier-stream>`,e.LITERAL=`<literal>`,e.VARIABLE=`<variable>`,e.PREFIX_EXPRESSION=`<prefix-expression>`,e.INFIX_EXPRESSION=`<infix-expression>`,e.POSTFIX_EXPRESSION=`<postfix-expression>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.FUNCTION_APPLICATION=`<function-application>`,e.BLOCK_EXPRESSION=`<block-expression>`,e.LIST_EXPRESSION=`<list-expression>`,e.TUPLE_EXPRESSION=`<tuple-expression>`,e.CALL_EXPRESSION=`<call-expression>`,e.PRIMARY_EXPRESSION=`<primary-expression>`,e.GROUP_EXPRESSION=`<group-expression>`,e.COMMA_EXPRESSION=`<comma-expression>`,e.EMPTY=`<dummy>`,e.ARRAY=`<array>`,e.WILDCARD=`<wildcard>`,e}({}),L=class extends I{constructor({body:e=[],eof:t,source:n},r,i){super(r,`<program>`,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===`<element-declaration>`)}get uses(){return this.body.filter(e=>e.kind===`<use-declaration>`)}},mm=class extends I{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,`<use-declaration>`,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return $a(this.useKeyword)}},hm=class extends I{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,`<use-specifier>`,a,[e,t,n,r]),this.importKind=e,this.name=t,this.asKeyword=n,this.alias=r}isKind(...e){return this.importKind?.value!==void 0&&e.map(e=>e.toLowerCase()).includes(this.importKind.value.toLowerCase())}getSymbolKind(){let e=this.importKind?.value?.toLowerCase();if(e!==void 0)return Object.values(F).find(t=>t.toLowerCase()===e)}},gm=class extends I{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,`<use-specifier-list>`,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},R=class e extends I{constructor({type:t,targetKind:n,name:r,as:i,alias:a,attributeList:o,bodyColon:s,body:c},l,u){if(super(l,`<element-declaration>`,u,[t,n,r,i,a,o,s,c]),c&&s&&!(c instanceof H||c instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.targetKind=n,this.name=r,this.as=i,this.alias=a,this.attributeList=o,this.bodyColon=s,this.body=c}isKind(...e){return e.some(e=>this.type?.value.toLowerCase()===e)}getElementKind(){return Object.values(r).find(e=>this.isKind(e))}},_m=class extends I{constructor({identifiers:e=[]},t,n){super(t,`<identifier-stream>`,n,e||[]),this.identifiers=e}},z=class extends I{constructor({name:e,colon:t,value:n},r,i){super(r,`<attribute>`,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},B=class extends I{constructor({op:e,expression:t},n,r){super(n,`<prefix-expression>`,r,[e,t]),this.op=e,this.expression=t}},V=class extends I{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,`<infix-expression>`,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},vm=class extends I{constructor({op:e,expression:t},n,r){super(n,`<postfix-expression>`,r,[t,e]),this.op=e,this.expression=t}},ym=class extends I{constructor({value:e},t,n){super(t,`<function-expression>`,n,[e]),this.value=e}},H=class extends I{constructor({callee:e,args:t=[]},n,r){super(n,`<function-application>`,r,[e,...t]),this.callee=e,this.args=t}},U=class extends I{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,`<block-expression>`,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},W=class extends I{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,`<list-expression>`,a,[e,...Am(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},bm=class extends I{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,`<tuple-expression>`,a,[e,...Am(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},xm=class extends I{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,`<comma-expression>`,r,[...Am(e,t)]),this.elementList=e,this.commaList=t}},Sm=class extends bm{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=`<group-expression>`}},Cm=class extends I{constructor({callee:e,argumentList:t},n,r){super(n,`<call-expression>`,r,[e,t]),this.callee=e,this.argumentList=t}},wm=class extends I{constructor({literal:e},t,n){super(t,`<literal>`,n,[e]),this.literal=e}},Tm=class extends I{constructor({token:e},t,n){super(t,`<wildcard>`,n,[e]),this.token=e}},Em=class extends I{constructor({variable:e},t,n){super(t,`<variable>`,n,[e]),this.variable=e}},Dm=class extends I{constructor({expression:e},t,n){super(t,`<primary-expression>`,n,[e]),this.expression=e}},Om=class extends I{constructor({prevToken:e},t,n){let r=Ha.create(_.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,`<dummy>`,n,[r])}},km=class extends I{constructor({expression:e,indexer:t},n,r){super(n,`<array>`,r,[e,t]),this.array=e,this.indexer=t}};function Am(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];let[n]=e,[r]=t;return(n.start<r.start?xr(Ra(e,t)):xr(Ra(t,e))).filter(e=>e!==null)}var jm=function(e){return e.Table=`table`,e}({});function Mm(e,t,n){let r=t,i=e;if(i instanceof Cm&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Kf(i)||r.length===0)return;let a=[...r],o=op(i),s=a.pop();if(!(s instanceof U))return;let c=h(a)instanceof W?a.pop():void 0;if(a.length===3){let e=op(a[1]);return!e||!Ya(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 Ha?Nm(e):Pm(e))}function Nm(e){e.kind!==_.EOF&&(e.isInvalid=!0)}function Pm(e){if(e instanceof R)G(e.type),G(e.targetKind),G(e.name),G(e.as),G(e.alias),G(e.bodyColon),G(e.attributeList),G(e.body);else if(e instanceof _m)e.identifiers.forEach(G);else if(e instanceof z)G(e.name),G(e.colon),G(e.value);else if(e instanceof B)G(e.op),G(e.expression);else if(e instanceof V)G(e.leftExpression),G(e.op),G(e.rightExpression);else if(e instanceof vm)G(e.op),G(e.expression);else if(e instanceof U)G(e.blockOpenBrace),e.body.forEach(G),G(e.blockCloseBrace);else if(e instanceof W)G(e.listOpenBracket),e.commaList.forEach(G),e.elementList.forEach(G),G(e.listCloseBracket);else if(e instanceof bm)G(e.tupleOpenParen),e.commaList.forEach(G),e.elementList.forEach(G),G(e.tupleCloseParen);else if(e instanceof xm)e.commaList.forEach(G),e.elementList.forEach(G);else if(e instanceof Cm)G(e.callee),G(e.argumentList);else if(e instanceof H)G(e.callee),e.args.forEach(G);else if(e instanceof Dm)G(e.expression);else if(e instanceof ym)G(e.value);else if(e instanceof Em)G(e.variable);else if(e instanceof wm)G(e.literal);else if(e instanceof Sm)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof km)G(e.array),G(e.indexer);else if(e instanceof L)e.body.forEach(G),G(e.eof);else if(!(e instanceof Om)){if(e instanceof mm)G(e.useKeyword),G(e.specifiers),G(e.fromKeyword),G(e.importPath);else if(e instanceof gm)G(e.openBrace),e.specifiers.forEach(G),G(e.closeBrace);else if(e instanceof hm)G(e.importKind),G(e.name),G(e.asKeyword),G(e.alias);else if(e instanceof Tm)G(e.token);else throw Error(`Unreachable case in markInvalidNode`)}}function Fm(...e){return e.filter(e=>e!==void 0)}function Im(e){if(e instanceof L)return Fm(...e.body,e.eof);if(e instanceof R)return Fm(e.type,e.targetKind,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof z)return Fm(e.name,e.colon,e.value);if(e instanceof _m)return e.identifiers;if(e instanceof wm)return e.literal?[e.literal]:[];if(e instanceof Em)return Fm(e.variable);if(e instanceof B)return Fm(e.op,e.expression);if(e instanceof V)return Fm(e.leftExpression,e.op,e.rightExpression);if(e instanceof vm)return Fm(e.expression,e.op);if(e instanceof ym)return Fm(e.value);if(e instanceof H)return Fm(e.callee,...e.args);if(e instanceof U)return Fm(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof W)return Fm(e.listOpenBracket,...Lm(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof bm)return Fm(e.tupleOpenParen,...Lm(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof xm)return Fm(...Lm(e.elementList,e.commaList));if(e instanceof Cm)return Fm(e.callee,e.argumentList);if(e instanceof Dm)return Fm(e.expression);if(e instanceof km)return Fm(e.array,e.indexer);if(e instanceof Om)return[];if(e instanceof mm)return Fm(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof gm)return Fm(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof hm)return Fm(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof Tm)return Fm(e.token);throw e instanceof Sm?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Lm(e,t){let n=[],r=Math.min(e.length,t.length);for(let i=0;i<r;i+=1)n.push(e[i],t[i]);return n.push(...e.slice(r),...t.slice(r)),n}function Rm(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function zm(e){if(!e)return[];if(D(e))return[{variables:[e],tupleElements:[]}];if(e instanceof V){let t=fp(e);return t?[t]:[...zm(e.leftExpression),...zm(e.rightExpression)]}if(e instanceof B||e instanceof vm)return zm(e.expression);if(e instanceof bm){let t=fp(e);return t?[t]:e.elementList.flatMap(zm)}return[]}function Bm(e,n){let r=n.parentNode;if(!r||!O(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;O(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Vm(e,t,r,i){if(!D(r))return new n(void 0);let a=gp(r)??``;if(O(r.parentNode)&&r.parentNode.rightExpression===r&&ap(r)){let t=Bm(e,r);if(!t)return new n(void 0);if(i===F.Column){if(t.isKind(F.Table)){let i=e.lookupMembers(t,F.Column,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${t.name}'`,r)])}return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist`,r)])}if(t.isKind(F.Schema)){let i=e.lookupMembers(t,F.Table,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist`,r)])}let o=Bm(e,r);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,r)])}if(i===F.Column&&o.isKind(F.Table)){let t=e.lookupMembers(o,F.Column,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${o.name}'`,r)])}return new n(void 0)}let s=r.parentNode;if(s.leftExpression===r){if(O(s.parentNode)&&s.parentNode.leftExpression===s||i===F.Table){let i=e.lookupMembers(t,F.Schema,a);return i?n.create(i):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist in Schema 'public'`,r)])}let o=e.lookupMembers(t,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Hm(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Kp&&e.isPublicSchema())}function Um(e,n){let r=e.parseFile(n).getValue().ast;return e.nodeSymbol(r).getFiltered(t)}var Wm=function(e){return e.Ref=`ref`,e.Dep=`dep`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e.MetadataElement=`metadata element`,e}({}),Gm=class e{static{this.id=0}constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}resolveOwnerPrograms(e,t){let n=this.declaration.filepath;return e.reachableFiles().flatMap(t=>Um(e,t)||[]).filter(r=>e.reachableFiles(r.filepath).some(e=>e.equals(n))&&t.every(t=>r.inNestedSchema(e,t)))}},Km=class extends Gm{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=up(this.declaration)[0];if(!(t instanceof H))return[];let n=t.callee;return n instanceof V?eh(e,n.leftExpression):[]}if(this.declaration instanceof z){let n=this.declaration.parentOfKind(H);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}return[]}rightColumns(e){if(this.declaration instanceof R){let t=up(this.declaration)[0];if(!(t instanceof H))return[];let n=t.callee;return n instanceof V?eh(e,n.rightExpression):[]}if(this.declaration instanceof z){let t=this.declaration.value;return t instanceof B?eh(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof R){let t=up(this.declaration)[0];if(!(t instanceof H))return;let n=t.callee;return n instanceof V?th(e,n.leftExpression):void 0}if(this.declaration instanceof z)return this.container(e)}rightTable(e){if(this.declaration instanceof R){let t=up(this.declaration)[0];if(!(t instanceof H))return;let n=t.callee;return n instanceof V?th(e,n.rightExpression):void 0}if(this.declaration instanceof z){let t=this.declaration.value;return t instanceof B?th(e,t.expression)??this.container(e):void 0}}op(e){return this.opToken()?.value}opToken(){if(this.declaration instanceof R){let e=up(this.declaration)[0];if(!(e instanceof H))return;let t=e.callee;return t instanceof V?t.op:void 0}if(this.declaration instanceof z){let e=this.declaration.value;return e instanceof B?e.op:void 0}}cardinalities(e){let t=this.op(e);return t?ff(t):void 0}leftCardinality(e){let t=this.cardinalities(e);return t?af(t[0]):void 0}rightCardinality(e){let t=this.cardinalities(e);return t?af(t[1]):void 0}active(e){if(!(this.declaration instanceof R))return!0;let n=up(this.declaration)[0];return!n||!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length}leftToken(){if(this.declaration instanceof R){let e=up(this.declaration)[0];if(e instanceof H){let t=e.callee;if(t instanceof V&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof z){let e=this.declaration.parentOfKind(H);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof R){let e=up(this.declaration)[0];if(e instanceof H){let t=e.callee;if(t instanceof V&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof z,this.declaration}owners(e){let t=this.leftTable(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},qm=class extends Gm{constructor(e){super(e),this.kind=`dep`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}edgeExpressions(){return this.declaration instanceof R?up(this.declaration).filter(e=>e instanceof H).map(e=>e.callee).filter(e=>e instanceof V):[]}upstreamColumns(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>eh(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=this.hostColumn(e),i=eh(e,t.expression);if(n===`->`)return[r?[r]:[]];if(n===`<-`)return[i]}return[]}downstreamColumns(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>eh(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=this.hostColumn(e),i=eh(e,t.expression);if(n===`->`)return[i];if(n===`<-`)return[r?[r]:[]]}return[]}upstreamTables(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>nh(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=nh(e,t.expression);if(n===`->`)return[this.container(e)];if(n===`<-`)return[r]}return[]}downstreamTables(e){if(this.declaration instanceof R)return this.edgeExpressions().map(t=>nh(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof z){let t=this.declaration.value;if(!(t instanceof B))return[];let n=t.op?.value,r=nh(e,t.expression);if(n===`->`)return[r];if(n===`<-`)return[this.container(e)]}return[]}hostColumn(e){if(!(this.declaration instanceof z))return;let n=this.declaration.parentOfKind(H);if(n)return e.nodeSymbol(n).getFiltered(t)}owners(e){let n=this.upstreamTables(e),r=this.downstreamTables(e),i=[...n,...r].filter(e=>!!e);if(i.length===0)return[];let a=this.declaration.filepath;return e.reachableFiles().flatMap(n=>e.nodeSymbol(e.parseFile(n).getValue().ast).getFiltered(t)||[]).filter(t=>e.reachableFiles(t.filepath).some(e=>e.equals(a))&&i.every(n=>t.inNestedSchema(e,n)))}},Jm=class extends Gm{constructor(e){super(e),this.kind=`partial ref`}container(e){let n=this.declaration.parentOfKind(R);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof z))return[];let n=this.declaration.parentOfKind(H);if(!n)return[];let r=e.nodeSymbol(n).getFiltered(t);return r?[r]:[]}rightColumns(e){if(!(this.declaration instanceof z))return[];let t=this.declaration.value;return t instanceof B?eh(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 th(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?ff(t):void 0}leftToken(){if(this.declaration instanceof z){let e=this.declaration.parentOfKind(H);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof z,this.declaration}owners(e){let t=this.leftTablePartial(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Ym=class extends Gm{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]:[]}},Xm=class extends Gm{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]:[]}},Zm=class extends Gm{constructor(e){super(e),this.kind=`records`}table(e){let n=this.declaration,i=n.parent;if(i instanceof R&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof Cm))return;let o=hp(a);if(!o)return;let s=o.variables.at(-1);if(s)return e.nodeReferee(s).getFiltered(t)?.originalSymbol}example(e){return!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Example]?.length}owners(e){let t=this.table(e);return t?this.resolveOwnerPrograms(e,[t]):[]}},Qm=class extends Gm{constructor(e){super(e),this.kind=`metadata element`}target(e){let n=this.declaration.name;if(!n)return;let r=ip(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])}},$m=class extends Gm{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 eh(e,n){if(!n)return[];let r=fp(n);return r?(r.tupleElements.length>0?r.tupleElements:r.variables.at(-1)?[r.variables.at(-1)]:[]).flatMap(n=>{let r=e.nodeReferee(n).getFiltered(t);return r?.isKind(F.Column)?[r]:[]}):[]}function th(e,n){if(!n)return;let r=fp(n);if(!r)return;let i=r.tupleElements.length>0?r.variables.at(-1):r.variables.at(-2);if(i)return e.nodeReferee(i).getFiltered(t)}function nh(e,n){if(!n)return;let r=fp(n);if(!r)return;if(r.tupleElements.length>0){let n=r.variables.at(-1);return n?e.nodeReferee(n).getFiltered(t):void 0}let i=r.variables.at(-1);if(i){let n=e.nodeReferee(i).getFiltered(t);if(n?.isKind(F.Table))return n}let a=r.variables.at(-2);if(a)return e.nodeReferee(a).getFiltered(t)}var rh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},ih=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof U?new n(e.body.flatMap(e=>{if(!(e instanceof H))return[];let t=P(e),n=e.callee instanceof ym?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof W);return a&&(r=M(T(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}},ah={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 Ym(i))}return n.create(e)},bindNode(t,i){return k(i,r.Checks)?n.create(void 0,new rh(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Wm.TableChecks?r.declaration instanceof R?new ih(t,r.declaration).interpret():n.create(void 0):n.create(e)}},oh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[e.callee,...e.args].flatMap(zm).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors())),n=this.checkColumnSelfLoop(e.callee);return t.concat(n)})}checkColumnSelfLoop(e){if(!(e instanceof V)||this.endpointLevel(e.leftExpression)!==`column`||this.endpointLevel(e.rightExpression)!==`column`)return[];let t=this.endpointSymbol(e.leftExpression),n=this.endpointSymbol(e.rightExpression);return t&&n&&t===n?[new w(C.DEP_SELF_LOOP,`A column cannot depend on itself`,e)]:[]}endpointSymbol(e){if(!e)return;let n=fp(e);if(!n)return;let r=n.variables.at(-1);if(r)return this.compiler.nodeReferee(r).getFiltered(t)}endpointLevel(e){if(!e)return;let n=fp(e);if(!n)return;if(n.tupleElements.length>0)return`column`;let r=n.variables.at(-1);if(!r)return;let i=this.compiler.nodeReferee(r).getFiltered(t);if(i?.isKind(F.Column))return`column`;if(i?.isKind(F.Table))return`table`}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},sh=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.dep={}}interpret(){this.dep.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretEdges(),...this.interpretSettings()];return n.create(this.dep,e)}interpretName(){if(!(this.declarationNode instanceof R))return this.dep.name=null,this.dep.schemaName=null,[];let e=[],t=this.declarationNode.name?j(this.declarationNode.name)??[]:[];return this.dep.name=t.pop()||null,t.length>1&&e.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.dep.schemaName=t.join(`.`)||null,e}interpretEdges(){let e=this.metadata.upstreamColumns(this.compiler),t=this.metadata.downstreamColumns(this.compiler),n=this.metadata.upstreamTables(this.compiler),r=this.metadata.downstreamTables(this.compiler),i=[],a=[],o=Math.max(n.length,r.length);for(let a=0;a<o;a++){let o=n[a],s=r[a],c=e[a]??[],l=t[a]??[],u=o?.interpretedName(this.compiler,this.filepath),d=s?.interpretedName(this.compiler,this.filepath);u?.schema,d?.schema,i.push({upstream:{schemaName:u?.schema??null,tableName:u?.name??``,fieldNames:c.map(e=>e.name??``),token:this.dep.token},downstream:{schemaName:d?.schema??null,tableName:d?.name??``,fieldNames:l.map(e=>e.name??``),token:this.dep.token},token:this.dep.token})}return this.dep.edges=i,a}interpretSettings(){let e={};if(this.declarationNode instanceof R){this.declarationNode.attributeList&&this.consumeSettings(this.declarationNode.attributeList,e);let t=this.declarationNode.body;if(t){let n=t instanceof H?[t]:t.body.filter(e=>e instanceof H);for(let t of n){let n=t.args.find(e=>e instanceof W);n&&this.consumeSettings(n,e)}if(!(t instanceof H)){let n=t.body.filter(e=>e instanceof R);for(let t of n){let n=t.type?.value?.toLowerCase();if(!n)continue;let a=t.body;if(t.isKind(r.Note)&&a instanceof U){let e=a.body[0];if(e instanceof H&&e.callee){let n=this.extractAttrValue(e.callee);n!==void 0&&(this.dep.note={value:Fp(String(n)),token:P(t)})}continue}if(!(a instanceof H))continue;if(n===i.Color){let e=Lp(a.callee);e!==void 0&&(this.dep.color=e);continue}let o=this.extractAttrValue(a.callee);o!==void 0&&(t.isKind(r.Note)?this.dep.note={value:Fp(String(o)),token:P(t)}:e[n]=o)}}}}return Object.keys(e).length>0&&(this.dep.metadata=e),[]}consumeSettings(e,t){let n=T(e).getValue();for(let[e,r]of Object.entries(n)){let n=r[0];if(!n)continue;if(e===i.Color){let e=Lp(n.value);e!==void 0&&(this.dep.color=e);continue}let a=this.extractAttrValue(n.value);a!==void 0&&(e===i.Note?this.dep.note={value:Fp(String(a)),token:P(n)}:t[e]=a)}}extractAttrValue(e){if(e instanceof _m)return sp(e);let t=mp(e);if(t!==null)return t;let n=M(e);return n===void 0?N(e):n}};function ch(e){let t=e.parent;for(;t;){if(t instanceof R&&t.isKind(r.Dep))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var lh={nodeReferee(r,i){if(!D(i)&&!O(i)||!ch(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):uh(r,o,i)},nodeMetadata(t,a){if(k(a,r.Dep)){let t=up(a);return t.length===0||!t.some(e=>e instanceof H&&e.callee instanceof V)?n.create(e):n.create(new qm(a))}return a instanceof z?!(a.name instanceof _m)||sp(a.name)?.toLowerCase()!==i.Dep?n.create(e):n.create(new qm(a)):n.create(e)},bindNode(t,i){return k(i,r.Dep)?n.create(void 0,new oh(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof qm?new sh(t,r,i).interpret():n.create(e)}};function uh(e,r,i){if(!D(i))return new n(void 0);let a=gp(i)??``;if(!O(i.parentNode)){let t=Hm(e,r);if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=i.parentNode;if(o.rightExpression===i){let r=Bm(e,i);if(r?.isKind(F.Schema)){let t=e.lookupMembers(r,F.Table,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema '${r.name}'`,i)])}if(r?.isKind(F.Table)){let o=e.lookupMembers(r,F.Column,a);if(o)return n.create(o);let s=r.declaration?e.nodeFullname(r.declaration).getFiltered(t)?.join(`.`)??r.name:r.name;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${s}'`,i)])}return new n(void 0)}if(o.leftExpression===i){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let t=e.lookupMembers(r,F.Schema,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=e.lookupMembers(r,F.Schema,a);if(t)return n.create(t);let s=Hm(e,r);if(s){let t=e.lookupMembers(s,F.Table,a);if(t)return n.create(t)}let c=e.lookupMembers(r,F.Table,a);return c?n.create(c):new n(void 0,[new w(C.BINDING_ERROR,`Schema or Table '${a}' does not exist`,i)])}return new n(void 0)}var dh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=g(e.body,e=>e instanceof H);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof U)?[]:e.isKind(r.DiagramViewTables)?this.bindTableReferences(e.body):e.isKind(r.DiagramViewNotes)?this.bindNoteReferences(e.body):e.isKind(r.DiagramViewTableGroups)?this.bindTableGroupReferences(e.body):e.isKind(r.DiagramViewSchemas)?this.bindSchemaReferences(e.body):[])}bindTableReferences(e){let[t]=g(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Gf(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]=g(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Gf(e.callee)?[]:zm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=g(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Gf(e.callee)?[]:zm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=g(e.body,e=>e instanceof H);return t.flatMap(e=>!e.callee||Gf(e.callee)?[]:zm(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},fh=class{constructor(e,t,n,r){this.diagramViewWildcards=new Set,this.diagramViewExplicitlySet=new Set,this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r??t.filepath,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null}}}interpret(){let e=[];this.diagramView.token=this.symbol.token;let{name:t,schema:r}=this.symbol.interpretedName(this.compiler,this.filepath);return this.diagramView.name=t,this.diagramView.schemaName=r,this.declarationNode.body instanceof U&&e.push(...this.interpretBody(this.declarationNode.body)),this.expandDiagramViewWildcards(),new n(this.diagramView,e)}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof H&&Gf(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramViewWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramViewExplicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=g(e.body,e=>e instanceof R),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof U&&this.interpretSubBlock(e.body,t)}let i=this.diagramView.visibleEntities;return(n.has(`tables`)&&i.tables!==null||n.has(`tablegroups`)&&i.tableGroups!==null||n.has(`schemas`)&&i.schemas!==null)&&(n.has(`tables`)||(i.tables=[]),n.has(`tablegroups`)||(i.tableGroups=[]),n.has(`schemas`)||(i.schemas=[])),n.has(r.DiagramViewTables)&&this.diagramViewExplicitlySet.add(`tables`),n.has(r.DiagramViewTableGroups)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(r.DiagramViewSchemas)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(r.DiagramViewNotes)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,n){if(!n)return;if(e.body.some(e=>e instanceof H&&Gf(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`)}return}if(e.body.length===0)return;let i=[];for(let n of e.body){if(!(n instanceof H))continue;let e=n.callee&&ip(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(`.`):v;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]:v;i.push({name:o,schemaName:s})}switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=i.length>0?i:null;break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=i.length>0?i.map(e=>({name:e.name})):null}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;t&&e&&(t.has(`tables`)||t.has(`schemas`)?(e.tables=[],e.tableGroups=[],e.schemas=[]):t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames()))}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n)return[];let r=this.compiler.symbolMembers(n).getFiltered(t);return r?Fa(r.filter(e=>e.isKind(F.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function ph(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var mh={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new w(C.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},hh={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.DiagramView)?new n(i.symbolFactory.create(nm,{declaration:a,name:o},a.filepath)):A(a,r.DiagramView)&&a instanceof Tm?new n(i.symbolFactory.create(rm,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(om,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewTables)?new n(i.symbolFactory.create(im,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(am,{declaration:a,name:o},a.filepath)):A(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(sm,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&$f(a))return n.create(e);let o=gh(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)?_h(i,c,a):o.isKind(r.DiagramViewNotes)?vh(i,c,a,F.StickyNote):o.isKind(r.DiagramViewTableGroups)?vh(i,c,a,F.TableGroup):o.isKind(r.DiagramViewSchemas)?yh(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 up(o))if(e instanceof H){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof R&&c.push(...up(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(z_).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(mh.getFieldDuplicateError(n,e.kind,i)),s.push(mh.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 dh(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 nm?r.declaration instanceof R?new fh(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function gh(e){let t=e.parentOfKind(H);if(!t)return;let n=t.parentNode;if(!(n instanceof U))return;let i=n.parentNode;if(!(i instanceof R)||!i.isKind(r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewTableGroups,r.DiagramViewSchemas))return;let a=i.parentNode;if(!(a instanceof U))return;let o=a.parentNode;if(o instanceof R&&o.isKind(r.DiagramView))return i}function _h(e,r,i){let a=gp(i);if(a===void 0)return n.create(void 0);if(O(i.parentNode)){let t=Bm(e,i);if(t){if(t.isKind(F.Schema)){let r=ap(i),o=e.lookupMembers(t,r?F.Table:F.Schema,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,F.Schema,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find schema '${a}'`,i)])}let o=e.symbolMembers(r).getFiltered(t)||[];for(let e of o){let t=e.name;if(e.isKind(F.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,F.Table,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Could not find table '${a}'`,i)])}function vh(e,t,r,i){let a=gp(r);if(a===void 0)return n.create(void 0);let o=e.lookupMembers(t,i,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${i===F.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function yh(e,t,r){let i=gp(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var bh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof H)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},xh=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.enum={values:[]}}interpret(){this.enum.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody(this.declarationNode.body)];return n.create(this.enum,e)}interpretName(){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);return this.enum.name=e,this.enum.schemaName=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=P(t),n.name=N(t.callee);let r=T(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Fp(M(r.value)),token:P(r)},this.enum.values.push(n),[]})}},Sh={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new w(C.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},Ch={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.Enum)?new n(i.symbolFactory.create(qp,{declaration:a,name:o},a.filepath)):A(a,r.Enum)?new n(i.symbolFactory.create(Jp,{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=up(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(Sh.getFieldDuplicateError(t,r)),c.push(Sh.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 bh(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof qp?new xh(t,r,i).interpret():n.create(e)}},wh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof R)||!this.declarationNode.parent.isKind(r.Table)&&!this.declarationNode.parent.isKind(r.TablePartial)||!(this.declarationNode.body instanceof U)?[]:this.bindBody(this.declarationNode.body)}get ownerContainerKind(){return this.declarationNode.parent.isKind(r.TablePartial)?`TablePartial`:`Table`}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let n=j(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(zm).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=gp(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new w(C.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Th=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof U?new n(e.body.flatMap(e=>{if(!(e instanceof H)||!e.callee)return[];let n=[],r=P(e),a=[e.callee,...e.args],o,s,c,l,u;h(a)instanceof W&&a.pop();let d=this.compiler.nodeSettings(e).getFiltered(t);if(d){o=!!d[i.PK]?.length||void 0,s=!!d[i.Unique]?.length||void 0,c=M(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=M(e.value);t!==void 0&&(l={value:t,token:P(e)})}u=N(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof Cm))return e;let t=[],n=e;for(;n instanceof Cm&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=pp(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:gp(e)??``,type:`column`,token:P(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}},Eh={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 Xm(i))},nodeReferee(i,a){if(!D(a)||$f(a))return n.create(e);let o=a;for(;o&&!k(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!k(s,r.Table)&&!k(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=D(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,F.Column,l);if(u)return n.create(u);let d=k(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return k(i,r.Indexes)?n.create(void 0,new wh(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Wm.Indexes?r.declaration instanceof R?new Th(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function Dh(e,n){let r=dp(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof bm){let n=[];for(let r of i.elementList){let i=e.nodeReferee(r).getFiltered(t);if(!i)return;n.push(i.originalSymbol)}return n}let a=r[r.length-1];if(!a||a instanceof bm)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function Oh(e,t,n,r){let i=e.map(e=>e.intern()).sort().join(`,`),a=t.map(e=>e.intern()).sort().join(`,`);if(i===a)return[new w(C.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new w(C.CIRCULAR_REF,`References with same endpoints exist`,n),new w(C.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var kh=class{constructor(e,t){this.compiler=t,this.ast=e}resolve(){let e=[],i=this.compiler.reachableFiles(this.ast.filepath);for(let n of i){let{ast:i}=this.compiler.parseFile(n).getFiltered(t)||{ast:void 0};if(!i)continue;let a=i.body.filter(e=>e instanceof R&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new w(C.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof R&&t.type){let n=t;e.push(...this.compiler.bindNode(n).getErrors())}else e.push(...this.compiler.bindNode(t).getErrors())}let a=this.compiler.nodeSymbol(this.ast).getFiltered(t);return a&&e.push(...Ah(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 up(e)){if(!(r instanceof H)||!r.callee||!tp(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=Dh(this.compiler,i.leftExpression),o=Dh(this.compiler,i.rightExpression);a&&o&&n.push(...Oh(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of up(e)){if(!(a instanceof H)||!a.callee)continue;let e=this.compiler.nodeSymbol(a).getFiltered(t);if(!e)continue;let o=this.compiler.nodeSettings(a).getFiltered(t);if(!o)continue;let s=o[i.Ref];if(s&&s.length!==0)for(let t of s){let i=t.value;if(!(i instanceof B)||!i.op||!Pf(i.op.value)||!i.expression)continue;let a=Dh(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...Oh(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of up(e)){if(!(r instanceof H)||!r.callee)continue;let e=N(r.callee);if(!e)continue;let a=this.compiler.nodeSettings(r).getFiltered(t);if(!a)continue;let o=a[i.Ref];if(o&&o.length!==0)for(let t of o){let r=t.value;r instanceof B&&r.op&&Pf(r.op.value)&&r.expression&&D(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new w(C.SAME_ENDPOINT,`Two endpoints are the same`,t))}}return n}checkTableGroups(){let e=[],n=new Map,i=this.compiler.reachableFiles(this.ast.filepath);for(let a of i){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=up(a);for(let r of c){if(!(r instanceof H)||!r.callee)continue;let i=dp(r.callee);if(!i||i.length===0)continue;let a=i[i.length-1],o=this.compiler.nodeReferee(a).getFiltered(t)?.originalSymbol;if(!o)continue;let c=n.get(o.id);if(c){let t=j(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new w(C.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${n}" already appears in group "${c.groupName}"`,r))}else n.set(o.id,{groupName:s,node:r})}}}return e}};function Ah(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 Kp&&a.push(...Ah(e,t,r));return a}function jh(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 Mh(e,t){return e>=t.start&&e<t.end}function Nh(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 Ph(e,t){let n=e.getSource(t.filepath);if(n)return n.slice(t.start,t.end).trim()}function Fh(e,t){return t.map(t=>t.qualifiedName(e).join(`.`)).join(`, `)}function Ih(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Fh(e,i),c=i.length>1?`Columns (\`${s}\`) are all nullable but operator \`${r}\` requires at least one to be NOT NULL`:`Column \`${s}\` is nullable but operator \`${r}\` requires it to be NOT NULL`,l=Ph(e,a),u=i[0]?.declaration,d=u&&Ph(e,u),f=[`- In ref definition \`${l??r}\`, the operator \`${r}\` requires \`${s}\` to reference an existing row.`,d?`- In column definition \`${d}\`, the column is nullable, which allows rows with no parent.`:`- A nullable column allows rows with no parent.`].join(`
5
- `);return new wf(C.INVALID_REF_RELATIONSHIP,c,t,{category:Sf.RefColumnMismatch,explanation:f,quickFixes:o})}function Lh(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Fh(e,i),c=i.length>1?`Columns (\`${s}\`) are NOT NULL but operator \`${r}\` allows them to be optional`:`Column \`${s}\` is NOT NULL but operator \`${r}\` allows it to be optional`,l=Ph(e,a),u=i[0]?.declaration,d=u&&Ph(e,u),f=[`- In ref definition \`${l??r}\`, the operator \`${r}\` marks \`${s}\` as optional.`,d?`- In column definition \`${d}\`, the column is NOT NULL.`:`- The column is NOT NULL.`].join(`
6
- `);return new wf(C.INVALID_REF_RELATIONSHIP,c,t,{category:Sf.RefColumnMismatch,explanation:f,quickFixes:o})}function Rh(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Fh(e,i),c=i.length>1?`Columns (\`${s}\`) have a unique index but operator \`${r}\` allows many`:`Column \`${s}\` is unique but operator \`${r}\` allows many`,l=[`- In ref definition \`${Ph(e,a)??r}\`, the operator \`${r}\` allows many.`,`- \`${s}\` has a unique constraint, so each value can appear at most once.`].join(`
7
- `);return new wf(C.INVALID_REF_RELATIONSHIP,c,t,{category:Sf.RefColumnMismatch,explanation:l,quickFixes:o})}function zh(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Fh(e,i),c=i.length>1?`Columns (\`${s}\`) should have a composite unique index for operator \`${r}\``:`Column \`${s}\` should be unique or primary key for operator \`${r}\``,l=[`- In ref definition \`${Ph(e,a)??r}\`, the operator \`${r}\` implies \`${s}\` has at most one row.`,`- \`${s}\` has no unique or primary key constraint.`].join(`
8
- `);return new wf(C.INVALID_REF_RELATIONSHIP,c,t,{category:Sf.RefColumnMismatch,explanation:l,quickFixes:o})}function Bh(e,t,n,r){let{schema:i,name:a}=r?t.interpretedName(e,r):{schema:t.schema(e),name:t.name??``},o=n.map(e=>{let t=e.name??``;return i?`${i}.${a}.${t}`:`${a}.${t}`});return o.length===1?o[0]:`(${o.join(`, `)})`}function Vh(e,t){return e.length>1?`Composite ${t}`:t}function Hh(e,t){let{colName:n}=t;return new wf(C.INVALID_RECORDS_FIELD,`NULL not allowed for NOT NULL column \`${n}\` without a default value or auto-increment`,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` is marked NOT NULL and has no default value or auto-increment.`})}function Uh(e,t){let{colName:n}=t;return new wf(C.INVALID_RECORDS_FIELD,`Invalid enum value for column \`${n}\``,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` uses an enum type. The value must match one of the defined enum members.`})}function Wh(e,t){let{colName:n,typeName:r}=t;return new wf(C.INVALID_RECORDS_FIELD,`Invalid numeric value for column \`${n}\``,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` has type \`${r}\` which expects a numeric value. Provide a valid integer or decimal.`})}function Gh(e,t){let{colName:n,value:r}=t;return new wf(C.INVALID_RECORDS_FIELD,`Invalid integer value \`${r}\` for column \`${n}\`: expected integer, got decimal`,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` is an integer column and cannot store decimal values.`})}function Kh(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,totalDigits:s}=t;return new wf(C.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds precision: expected at most ${a} total digits, got ${s}`,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${a} total digits. The value \`${i}\` has ${s}.`})}function qh(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,decimalDigits:s}=t;return new wf(C.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds scale: expected at most ${o} decimal digits, got ${s}`,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${o} decimal places. The value \`${i}\` has ${s}.`})}function Jh(e,t){let{colName:n}=t;return new wf(C.INVALID_RECORDS_FIELD,`Invalid boolean value for column \`${n}\``,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` is a boolean column. Use \`true\`/\`false\`, \`1\`/\`0\`, or \`'yes'\`/\`'no'\`.`})}function Yh(e,t){let{colName:n}=t;return new wf(C.INVALID_RECORDS_FIELD,`Invalid datetime value for column \`${n}\``,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` expects a date or time value. Supported formats include \`'YYYY-MM-DD'\`, \`'HH:MM:SS'\`, \`'YYYY-MM-DD HH:MM:SS'\`, \`'MM/DD/YYYY'\`, \`'D MMM YYYY'\`, or \`'MMM D, YYYY'\`.`})}function Xh(e,t){let{colName:n}=t;return new wf(C.INVALID_RECORDS_FIELD,`Invalid string value for column \`${n}\``,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` is a string column. Values must be wrapped in quotes.`})}function Zh(e,t){let{colName:n,typeName:r,typeArg:i,maxLength:a,actualLength:o}=t;return new wf(C.INVALID_RECORDS_FIELD,`String value for column \`${n}\` exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e,{category:Sf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${i})\`, limiting values to ${a} bytes in UTF-8 encoding. The provided value uses ${o} bytes.`})}function Qh(e,t,n){let{table:r,columns:i}=n,a=Bh(e,r,i),o=Vh(i,`PK`);return new wf(C.INVALID_RECORDS_FIELD,`NULL in ${o}: \`${a}\` cannot be NULL`,t,{category:Sf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key and cannot be NULL.`})}function $h(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=Bh(e,r,i),s=Vh(i,`PK`);return new wf(C.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:Sf.RecordConstraintViolation,explanation:`\`${o}\` is a primary key and must be unique across all rows.`})}function eg(e,t,n){let{table:r,columns:i}=n,a=Bh(e,r,i),o=Vh(i,`PK`);return new wf(C.INVALID_RECORDS_FIELD,`${o}: Column \`${a}\` is missing from record and has no default value`,t,{category:Sf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key with no default or auto-increment, so it must be specified in the records block.`})}function tg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=Bh(e,r,i,s),u=Bh(e,a,o,s);return new wf(C.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` must not be NULL`,t,{category:Sf.RecordConstraintViolation,explanation:`\`${l}\` references \`${u}\`, so every row must have a non-null value.`})}function ng(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=Bh(e,r,i,s),u=Bh(e,a,o,s);return new wf(C.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` does not exist in \`${u}\``,t,{category:Sf.RecordConstraintViolation,explanation:`\`${l}\` is a foreign key referencing \`${u}\`. Every non-null value in an FK must match an existing row in the referenced column.`})}function rg(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=Bh(e,r,i),s=Vh(i,`UNIQUE`);return new wf(C.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:Sf.RecordConstraintViolation,explanation:`\`${o}\` has a unique constraint, so no two rows can have the same value.`})}function ig(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function ag(e,t){return e?`${e}.${t}`:`${v}.${t}`}function og(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 sg(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function cg(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 lg(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function ug(e,t){let{token:n}=t;return e.nodeAtPosition(n.filepath,n.start.offset)??e.parse.ast(n.filepath)}function dg(e,t,n,r){return ka(r.values)?[]:Sa(gg(t,e),i=>fg(e,t,n,i,r))}function fg(e,t,n,r,i){let a=ig(i),o=hg(e,t,n,r,i);if(!ka(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=g(a,t=>sg(e,t,s)),u=pg(e,t,s,c),d=r.some(t=>t.increment(e))?[]:mg(e,t,r,l);return[...u,...d]}function pg(e,t,n,r){if(ka(r))return[];let i=n.map(e=>e.name??``);return Sa(r,r=>lg(r,i).map(r=>Qh(e,ug(e,r),{table:t,columns:n})))}function mg(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r,t=>og(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=cg(e,r,n);return lg(r,i).map(r=>$h(e,ug(e,r),{table:t,columns:n,valueStr:a}))}))}function hg(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=fa(a,Array.from(o));if(ka(s))return[];let c=new Set(s),l=r.filter(e=>c.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e));return ka(l)?[]:i.values.map(()=>eg(e,n,{table:t,columns:l}))}function gg(e,t){let n=e.mergedColumns(t),r=Aa(n,e=>e.name??``);return[...n.filter(e=>e.pk(t)).map(e=>[e]),...e.mergedIndexes(t).flatMap(e=>{let n=t.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.pk).map(e=>$r(e.columns.map(e=>r[e.value]))):[]})]}function _g(e,t,n){if(ka(n.values))return[];let r=ig(n);return Sa(vg(e,t),n=>yg(e,t,n,r))}function vg(e,t){let n=t.mergedColumns(e),r=Aa(n,e=>e.name??``);return[...n.filter(t=>t.isUniqueSet(e)).map(e=>[e]),...t.mergedIndexes(e).flatMap(t=>{let n=e.interpretMetadata(t,t.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.unique).map(e=>$r(e.columns.map(e=>r[e.value]))):[]})]}function yg(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r.filter(t=>!sg(e,t,n)),t=>og(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=cg(e,r,n);return lg(r,i).map(r=>rg(e,ug(e,r),{table:t,columns:n,valueStr:a}))}))}function bg(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(ag(a,e),i)}return r}function xg(e,t,n,r){let i=bg(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!ka(t.record.values)&&a.add(e);return Sa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(ag(e.schemaName,e.tableName))):!1),t=>Sg(e,t,i,r))}function Sg(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(ag(i.schemaName,i.tableName)),s=n.get(ag(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=$r(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=$r(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=af(i.relation),{min:m,max:ee}=af(a.relation),te=p===1&&m===0||p!==`*`&&ee!==`*`,ne=ee===1&&f===0;return[...te?[]:Cg(e,o,u,s,d,i.relation,a.relation,r),...ne?[]:Cg(e,s,d,o,u,a.relation,i.relation,r)]}function Cg(e,t,n,r,i,a,o,s){if(!t.record||ka(t.record.values))return[];let{min:c,max:l}=af(a),{min:u,max:d}=af(o),f=$r(n.map(e=>e.name));$r(i.map(e=>e.name));let p=u===0,m=ig(t.record),ee=r.record?ig(r.record):[],te=new Set(ee.map(t=>og(e,t,i))),ne={leftTable:t.tableSymbol,leftColumns:n,rightTable:r.tableSymbol,rightColumns:i,filepath:s};return Sa(m,t=>{if(sg(e,t,n)){if(p)return[];let r=cg(e,t,n);return lg(t,f).map(t=>tg(e,ug(e,t),{...ne,valueStr:r}))}if(d===`*`&&c===0&&l===`*`)return[];let r=og(e,t,n);if(te.has(r))return[];let i=cg(e,t,n);return lg(t,f).map(t=>ng(e,ug(e,t),{...ne,valueStr:i}))})}function wg(e){return e instanceof qm&&e.declaration instanceof R&&e.declaration.body instanceof U}function Tg(e,t){let n=e.edges??[];if(n.length===0||!wg(t))return[];let r=[],i=ag(n[0].downstream.schemaName,n[0].downstream.tableName);for(let e=1;e<n.length;e++){let a=ag(n[e].downstream.schemaName,n[e].downstream.tableName);if(a!==i){r.push(new w(C.DEP_MIXED_DOWNSTREAM_TABLES,`All edges in a Dep block must target the same downstream table, but found '${i}' and '${a}'`,t.declaration));break}}let a=e=>e.upstream.fieldNames.length>0||e.downstream.fieldNames.length>0,o=a(n[0]);for(let e=1;e<n.length;e++)if(a(n[e])!==o){r.push(new w(C.DEP_MIXED_LEVEL,`All edges in a Dep block must be at the same level (all table-level or all column-level)`,t.declaration));break}return r}function Eg(e,t){let n=Ag(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof z&&_p(e)?.toLowerCase()===t.toLowerCase());if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof R){let n=jg(e,t);if(n)return{kind:`body`,declaration:n}}}function Dg(e,t){let n=Ag(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof R){let n=e.body;if(n&&!(n instanceof H))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function Og(e,t,n,r){if(n===null)return kg(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=Eg(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return Dg(e,i)}function kg(e,t,n){let r=Eg(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function Ag(e){if(e instanceof H)return e.args.find(e=>e instanceof W);if(e instanceof R){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof H)return t.args.find(e=>e instanceof W)}}function jg(e,t){let n=e.body;if(!(!n||Mf(e)||n instanceof H)){for(let e of n.body)if(e instanceof R&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function Mg(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=af(l),d=n===`left`?c[1]:c[0],f=af(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),ee=n===`left`?t.leftToken():t.rightToken(),te=n===`left`?t.rightToken():t.leftToken(),ne=[];function re(e,t,n){ne.push(n(e));for(let r of t)r.declaration&&r.declaration!==e&&ne.push(n(r.declaration))}let ie=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&ie&&m.length>0&&m.every(t=>t.nullable(e))){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Pg(s,yf(l),d,n,`Make '${r}' optional in the ref`),...i?m.map(t=>Fg(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Ih(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.min===0&&ie&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Pg(s,bf(l),d,n,`Make '${r}' required in the ref`),...i?m.map(t=>Ig(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Lh(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.max===`*`&&Lg(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Pg(s,`1`,d,n,`Make '${r}' one in the ref`)].filter(e=>!!e);re(ee,p,n=>Rh(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}if(u.max===1&&!Lg(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Pg(s,xf(l),d,n,`Make '${r}' many in the ref`),a&&p.length===1&&Rg(p[0],e)].filter(e=>!!e);re(ee,p,n=>zh(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}return ne}function Ng(e,t){return[...Mg(e,t,`right`,{allowOtherColFix:!1}),...Mg(e,t,`left`,{allowOwnColFix:!1})]}function Pg(e,t,n,r,i){let a=vf(r===`left`?t:n,r===`right`?t:n);return{title:`${i} (change operator to '${a}')`,shortTitle:`Change to ${a}`,filepath:e.filepath,edits:[{start:e.start,end:e.end,newText:a}],isPreferred:!0}}function Fg(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=kg(e.declaration,`null`,n);if(i)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[i]};let a=Dg(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[a]}}function Ig(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=kg(e.declaration,`not null`,n);if(r)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as NULL`,shortTitle:`Make nullable`,filepath:e.declaration.filepath,edits:[r]}}function Lg(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 dm?r.injectionDeclaration:r.declaration)?.parentOfKind(R);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof Yp))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 Rg(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=Dg(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,shortTitle:`Add unique`,filepath:e.declaration.filepath,edits:[n]}}var zg=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],deps:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:P(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.infos.push(...this.validateRecords()),new n(this.db,this.errors,this.warnings,this.infos)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof um)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 Kp);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Kp){n.push(t);continue}if(!(t instanceof um))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 Yp?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Yp?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}]};jh(this.db,e,o)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],n=new Set,r=new Set,i=new Map;for(let t of e){if(!(t instanceof Zm))continue;let e=t.table(this.compiler);if(!e)continue;let n=e.originalSymbol.intern(),r=i.get(n);r?r.count++:i.set(n,{count:1,tableName:e.name??``})}for(let a of e){let e=this.compiler.interpretMetadata(a,this.filepath);if(e.hasValue(t))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings()),this.infos.push(...e.getInfos());let o=e.getValue();if(o!==void 0)switch(a.kind){case Wm.Ref:{let e=o,[t,r]=e.endpoints??[];if(t&&r){let e=[t.schemaName,t.tableName,t.fieldNames.join(`,`),r.schemaName,r.tableName,r.fieldNames.join(`,`)].join(`|`),i=[r.schemaName,r.tableName,r.fieldNames.join(`,`),t.schemaName,t.tableName,t.fieldNames.join(`,`)].join(`|`);if(n.has(e)||n.has(i)){this.errors.push(new w(C.SAME_ENDPOINT,`Ref with same endpoints already exists`,a.declaration));break}n.add(e)}this.db.refs.push(e);break}case Wm.Dep:{let e=o,t=a instanceof qm?a.edgeExpressions():[],n=-1;if((e.edges??[]).some((e,t)=>{let{upstream:i,downstream:a}=e,o=[i.schemaName,i.tableName,i.fieldNames.join(`,`),a.schemaName,a.tableName,a.fieldNames.join(`,`)].join(`|`);return r.has(o)?(n=t,!0):(r.add(o),!1)}),n>=0){let e=t[n]??a.declaration;this.errors.push(new w(C.SAME_ENDPOINT,`Dep with same endpoints already exists`,e));break}let i=Tg(e,a);if(i.length>0){this.errors.push(...i);break}this.db.deps.push(e);break}case Wm.Records:if(a instanceof Zm){let e=a.table(this.compiler)?.originalSymbol.intern()??``,t=e?i.get(e):void 0;if(t&&t.count>1){this.errors.push(new w(C.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,a.declaration));break}}this.db.records.push(o);break;case Wm.Project:this.db.project=o;break;case Wm.MetadataElement:}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof lm)||!t.isKind(F.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:jm.Table,value:{tableName:e,schemaName:n}};this.db.aliases.push(r)}}validateRecords(){let e=[],n=new Map,r=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let e of r){if(!(e instanceof Kp))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 Yp))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 Zm))continue;let i=r.table(this.compiler);if(!(i instanceof Yp))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...dg(this.compiler,i,r.declaration,o)),e.push(..._g(this.compiler,i,o));let s=i.originalSymbol.intern(),c=n.get(s);c?c.record=o:n.set(s,{tableSymbol:i,record:o,recordBlock:r.declaration})}let a=this.collectPartialRefs(n);return e.push(...xg(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Jm);for(let t of e)this.infos.push(...Ng(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Jm),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 dm&&t.declaration===e.declaration)))continue;let l=ff(s);if(!l)continue;let u=a instanceof em&&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)}}},Bg={nodeSymbol(t,r){return Xf(r)?n.create(t.symbolFactory.create(cm,{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(v);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 Xf(r)?new kh(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof cm))return n.create(e);if(!(r.declaration instanceof L))return n.create(void 0);if(!Rm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new zg(t,r,i).interpret()}},Vg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof H)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Hg=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}=Ip(e);return this.project.name=t,[]}interpretSubElement(e){let r=this.compiler.nodeSymbol(e).getFiltered(t);if(r){let e=this.compiler.interpretSymbol(r,this.filepath);if(!e.hasValue(t))return e}return n.create(void 0)}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.getElementKind()){case r.Table:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tables?.push(e.getValue()),e.getErrors()}case r.TableGroup:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tableGroups?.push(e.getValue()),e.getErrors()}case r.Enum:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.enums?.push(e.getValue()),e.getErrors()}case r.Note:{let e=t.body instanceof U?t.body.body[0]?.callee:t.body?.callee,n=e?M(e):void 0;return n&&(this.project.note={value:Fp(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),[]}})}},Ug={nodeMetadata(t,i){return k(i,r.Project)?n.create(new $m(i)):n.create(e)},bindNode(t,i){return k(i,r.Project)?n.create(void 0,new Vg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof $m)||!(r.declaration instanceof R)?n.create(e):new Hg(t,r.declaration,i).interpret()}},Wg=class{constructor(e,t){this.compiler=e,this.declarationNode=t,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof U&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof L?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=hp(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=cp(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=gp(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new w(C.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new w(C.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new w(C.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,e))),this.boundColumns.set(r,e)}return c}bindInsideTableName(e){let n=this.declarationNode.parent;if(!(n instanceof R)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Hf(e))return[];let i=cp(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=gp(n)??`<unnamed>`;this.compiler.nodeReferee(n).getFiltered(t)||a.push(new w(C.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n))}return a}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof H),n=e.body.filter(e=>e instanceof R);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof xm?e.callee.elementList:[e.callee]).flatMap(zm).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();return!t||!n?[]:[...e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors()),...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}):[]}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Gg=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Kg(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=qg(n,r.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getInfos());let o=a.getValue();o.row&&i.push(o.row)}let a=P(this.element),o=this.metadata.example(this.compiler)||void 0;return new n({schemaName:r.schemaName,tableName:r.tableName,columns:r.columns.map(e=>e.name??``),values:i,example:o,token:a},e,[],t)}};function Kg(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 Yp))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=hp(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 Yp))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 qg(e,t,r){let i=[],a=[],o={},s=e.callee instanceof xm?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new w(C.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new n({row:null,columnNodes:{}},i,[],a);let c=[];for(let e=0;e<t.length;e++){let n=s[e],l=t[e];o[l.name??``]=n;let u=Yg(n,l,r);i.push(...u.getErrors()),a.push(...u.getInfos());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:P(n)})}return new n({row:c,columnNodes:o},i,[],a)}function Jg(e){return e instanceof ym&&e.value?.value||``}function Yg(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=Go(o,s),p=Op(e),m=p===null?Jg(e):p,ee=p===null?`expression`:f;if(e instanceof ym)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(vp(e)||yp(e)&&!Vo(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Wo(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[],[Hh(e,{colName:d})]):new n({value:null,type:f,token:i},[],[])}if(s){let a=t.type(r)?.enumSymbol,o=a?a.members(r).filter(e=>e.isKind(F.EnumField)).map(e=>e.name).filter(Boolean):[],s=M(e);return s===void 0&&(s=D(e)?e.expression.variable.value:void 0),o.includes(s)?new n({value:s,type:f,token:i},[],[]):new n({value:s,type:f,token:i},[],[],[Uh(e,{colName:d})])}if(Lo(o)||Ro(o)||Wo(o)){let t=xp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Wh(e,{colName:d,typeName:o})]);if(Lo(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[],[Gh(e,{colName:d,value:t})]);let r=Ro(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Ro(o)&&r){let{precision:a,scale:s}=r,c=t.toString().split(`.`),l=c[0].replace(/^-/,``),u=c[1]||``,p=l.length+u.length,m=u.length;if(p>a)return new n({value:t,type:f,token:i},[],[],[Kh(e,{colName:d,typeName:o,value:t,precision:a,scale:s,totalDigits:p})]);if(m>s)return new n({value:t,type:f,token:i},[],[],[qh(e,{colName:d,typeName:o,value:t,precision:a,scale:s,decimalDigits:m})])}return new n({value:t,type:f,token:i},[],[])}if(Bo(o)){let t=Ep(e);return t===null?new n({value:m,type:ee,token:i},[],[],[Jh(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Uo(o)){let t=Mp(e);return t===null?new n({value:m,type:ee,token:i},[],[],[Yh(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Vo(o)){let t=Op(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Xh(e,{colName:d})]);let r=a?.args?.length?Number(a.args[0]):void 0;if(r&&!Number.isNaN(r)){let s=r,c=new TextEncoder().encode(t).length;if(c>s)return new n({value:t,type:f,token:i},[],[],[Zh(e,{colName:d,typeName:o,typeArg:String(a.args[0]),maxLength:s,actualLength:c})])}return new n({value:t,type:`string`,token:i},[],[])}return new n({value:m,type:ee,token:i},[],[])}var Xg={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 Zm(i));let o=i.name;return o instanceof Cm&&o.callee?n.create(new Zm(i)):n.create(e)},nodeReferee(i,a){if(!D(a))return n.create(e);let o=a.parentOfKind(R);if(!o?.isKind(r.Records))return n.create(e);let s=i.parseFile(a.filepath).getValue().ast,c=i.nodeSymbol(s).getFiltered(t);if(!c)return n.create(void 0);let l=a.parentOfKind(bm);if(l?.parentNode===o)return Zg(i,o,a);let u=a.parentOfKind(Cm);return u?.parentNode===o&&l?.parentNode===u?Qg(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?$g(i,c,a):t_(i,c,a)},bindNode(t,i){return k(i,r.Records)?n.create(void 0,new Wg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Zm?r.declaration instanceof R?new Gg(t,r,i).interpret():n.create(void 0):n.create(e)}};function Zg(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 e_(e,n,a)}return new n(void 0)}function Qg(e,r,i){if(r.callee){let n;if(D(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=dp(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return e_(e,n,i)}return new n(void 0)}function $g(e,t,r){if(!D(r))return new n(void 0);let i=gp(r)??``;if(!O(r.parentNode)){let a=e.lookupMembers(t,[F.Table,F.Schema],i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Bm(e,r);if(!a){let a=e.lookupMembers(t,[F.Table,F.Schema],i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Table,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function e_(e,t,r){if(!D(r))return new n(void 0);let i=gp(r)??``,a=e.lookupMembers(t,F.Column,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function t_(e,t,r){if(!D(r))return new n(void 0);let i=gp(r)??``;if(!O(r.parentNode))return new n(void 0);let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var n_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(zm).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();return!t||!n?[]:(Array.isArray(t)||(t=[t]),[...e.variables,n,...t].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},r_=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=P(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()],{infos:t}=this.validateRefConstraints();return n.create(this.ref,e,void 0,t)}interpretName(){if(!(this.declarationNode instanceof R))return[];let e=[],t=j(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if(Ra(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new w(C.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=ff(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=up(this.declarationNode)[0];if(u.args[0]){let e=T(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof _m?sp(t):N(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof _m?sp(n):N(n),this.ref.color=e.color?.length?Lp(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:[...Mg(this.compiler,this.metadata,`right`),...Mg(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function i_(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 a_={nodeReferee(r,i){if(!D(i)&&!O(i)||!i_(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):o_(r,o,i)},nodeMetadata(t,a){if(k(a,r.Ref)){let t=up(a)[0];if(!(t instanceof H)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof V)||!r.op?n.create(e):n.create(new Km(a))}if(a instanceof z){if(!(a.name instanceof _m)||sp(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof R&&t.isKind(r.TablePartial)?n.create(new Jm(a)):n.create(new Km(a))}return n.create(e)},bindNode(t,i){return k(i,r.Ref)?n.create(void 0,new n_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Km?new r_(t,r,i).interpret():n.create(e)}};function o_(e,r,i){if(!D(i))return new n(void 0);let a=gp(i)??``;if(!O(i.parentNode)){let r=i.parentNode;if(r&&O(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=O(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(F.Table)){let r=e.lookupMembers(c,F.Column,a);if(r)return n.create(r);let o=c.declaration?e.nodeFullname(c.declaration).getFiltered(t)?.join(`.`)??c.name:c.name;return new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Bm(e,i);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(F.Table)){let r=e.lookupMembers(o,F.Column,a);return r?n.create(r):new n(void 0,[new w(C.BINDING_ERROR,`Column '${a}' does not exist in Table '${o.declaration?e.nodeFullname(o.declaration).getFiltered(t)?.join(`.`)??o.name:o.name}'`,i)])}return new n(void 0)}let s=i.parentNode;if(s.leftExpression===i){if(O(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,F.Schema,a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Hm(e,r);if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,F.Table,a);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var s_={visibleName(e,n){let r=n instanceof I?n:n.useSpecifierDeclaration instanceof hm?n.useSpecifierDeclaration:n.declaration;if(r instanceof hm&&n instanceof Gp&&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]}},c_={nodeSymbol(r,i){if(!Yf(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(um,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:s_.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new w(C.BINDING_ERROR,`Failed to resolve the import of ${a} '${(j(i.name)||[]).map(z_).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof um))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)&&!qf(i))return n.create(e);let a=i.parentOfKind(hm);if(!a)return n.create(e);let o=a.name===i||O(a.name)&&a.name.rightExpression===i?a.getSymbolKind():F.Schema;if(o===void 0)return n.create(void 0);let s=j(i.parentOfKind(V)),c=N(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(mm);if(l?.importPath?.value===void 0)return n.create(void 0);let u=r.layout.resolveFileSpecifier(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new w(C.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new w(C.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toKey()}. Does the file exist?`,i)]);let d=i.parentOfKind(V)?.leftExpression;if(d&&d!==i){let e=r.nodeReferee(d).getFiltered(t);if(!e)return n.create(void 0);let a=r.lookupMembers(e,o,c);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=l_(r,u,c,o);return f?n.create(f):n.create(void 0,[new w(C.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toKey()}`,i)])},bindNode(t,r){if(Jf(r)){let e=[];if(r.importPath?.value){let n=t.layout.resolveFileSpecifier(r.filepath,r.importPath.value);(!n||!t.layout.exists(n))&&e.push(new w(C.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath))}if(r.specifiers){let n=t.bindNode(r.specifiers);e.push(...n.getErrors())}return new n(void 0,e)}return r instanceof gm?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):Yf(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 um))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 l_(e,n,r,i,a=new Set){if(!n||a.has(n.intern()))return;a.add(n.intern());let o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.nonSchemaMembers.find(e=>e.name===r&&e.isKind(i));if(s)return s;let c=o.schemaMembers.find(e=>e.name===r);if(c?.isKind(F.Schema))return c;for(let t of o.reuses.selective)if(j(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(mm);if(o?.importPath?.value){let s=l_(e,e.layout.resolveFileSpecifier(n,o.importPath.value),j(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=l_(e,t,r,i,a);if(n)return n}}function u_(e){if(e instanceof So){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=f_(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof cm?p_(this,e,i):m_(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 d_(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof hm?s_.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof hm&&r.getSymbolKind()===F.Schema?a:a.length<=1?[v]:a.slice(0,-1);return o.length<i.length||!i.every((e,t)=>e===o[t])?{kind:`none`}:o.length===i.length?{kind:`direct`}:{kind:`child`,schemaName:o[i.length]}}function f_(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let n of r.body){if(!(n instanceof mm)||!n.specifiers||!n.importPath)continue;let r=e.layout.resolveFileSpecifier(t,n.importPath.value);r&&(n.isReuse?n.specifiers instanceof Tm?i.push({importPath:r,node:n.specifiers}):a.push(...n.specifiers.specifiers):n.specifiers instanceof Tm?o.push({importPath:r,node:n.specifiers}):s.push(...n.specifiers.specifiers))}return{ast:r,parseResult:n,selectiveReuses:a,wildcardReuses:i,selectiveUses:s,wildcardUses:o}}function p_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[v,e.symbolFactory.create(Kp,{name:v},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?v:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Kp,{name:i},s))}h_(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of __(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Kp,{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 m_(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=d_(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(lm,{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(Kp,{name:i.schemaName,parent:n},n.filepath))}}g_(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of v_(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Kp,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function h_(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==F.Schema)continue;let t=s_.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Kp,{name:t},r))}}function g_(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==F.Schema)continue;let t=s_.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(Kp,{name:o,parent:n},n.filepath))}}function __(e,n){let{ast:r}=e.parseFile(n).getValue(),i=[];for(let n of r.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],a=r.length<=1?v:r[0];i.push(a)}let a=f_(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==F.Schema)continue;let n=s_.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function v_(e,n,r){let{ast:i}=e.parseFile(n).getValue(),a=[];for(let n of i.declarations){let i=e.nodeFullname(n).getFiltered(t)||[],o=i.length<=1?[v]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=f_(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==F.Schema)continue;let n=s_.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var y_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){let e=[];return this.declarationNode.attributeList&&e.push(...this.bindHeaderSettings(this.declarationNode.attributeList)),this.declarationNode.body instanceof U&&e.push(...this.bindBody(this.declarationNode.body)),e}bindHeaderSettings(e){return T(e).getValue().dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])??[]}bindInlineDepValue(e){return zm(e).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return(e=>e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(h(n)instanceof W){let e=T(h(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!Nf(e.callee)))}tryToBindColumnType(e){let t=fp(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(E(e))return[];if(D(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&To.includes(t))return[]}let t=fp(e);if(!t){if(O(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return zm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}};function b_(e){let t=e.targetKind?.value?.toLowerCase();return Object.values(Up).find(e=>e.toLowerCase()===t)}function x_(e,t,n){let r=[];return t.length>1&&r.push(...t.map(t=>new w(n.duplicate,`'${e}' can only appear once`,t))),t.forEach(t=>{Wf(t.value)||r.push(new w(n.invalidValue,`Custom setting '${e}' must be a string or a color literal`,t.value||t.name||t))}),r}function S_(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?S_(e,a,n.slice(1)):a}function C_(e,t){if(e.length===0)return[];let n;switch(t){case Up.Table:n=[...Array(e.length-1).fill(F.Schema),F.Table];break;case Up.Column:n=e.length===1?[F.Column]:[...Array(e.length-2).fill(F.Schema),F.Table,F.Column];break;case Up.TableGroup:n=[...Array(e.length-1).fill(F.Schema),F.TableGroup];break;case Up.Note:n=[...Array(e.length-1).fill(F.Schema),F.StickyNote]}return e.map((e,t)=>({name:e,symbolKind:n[t]}))}function w_(e,t){let n=Um(e,t.filepath);if(!n)return;let r=b_(t),i=j(t.name);if(!i?.length||!r)return;let a=C_(i,r),{name:o,symbolKind:s}=a[0];if(o===`public`&&s===F.Schema){let t=Hm(e,n);if(t)return S_(e,t,a.slice(1))}return S_(e,n,a)}function T_(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 E_(e,n,r,i,a){let o=Um(e,a);if(!o)return;let s=e.symbolMetadata(r).filter(t=>t.owners(e).includes(o));if(!s.length)return;let c=T_(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 D_=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;E_(this.compiler,this.table,this.symbol,k_,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&&E_(this.compiler,e,t,A_,this.filepath)}}interpretName(e){let{name:t,schemaName:n}=Ip(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new w(C.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.table.name=t,this.table.schemaName=n.length?n[0]:null,[])}interpretAlias(e){if(!e)return[];let t=gp(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=T(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Lp(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Fp(M(n?.value)),token:P(n)},this.table.metadata=Bp(t,Object.keys(k_)),[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof H);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:Fp(M(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:P(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);case r.Records:return[];default:return[]}})}interpretInjection(e,n){let r=[],i={order:n,token:P(e)};i.name=N(e.expression)||``;let a=e.expression?this.compiler.nodeReferee(e.expression).getFiltered(t):void 0,o=this.compiler.parseFile(this.filepath).getValue().ast,s=this.compiler.nodeSymbol(o).getFiltered(t);if(a&&!s.inNestedSchema(this.compiler,a)){let n=this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),o=n?(this.compiler.symbolUses(n).getFiltered(t)??[]).find(e=>e.filepath.equals(this.filepath)):void 0;r.push(new w(C.UNSUPPORTED,`TablePartial ${i.name} from '${a.filepath}' should be imported. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,o?.useSpecifierDeclaration??e))}return this.table.partials.push(i),r}interpretFields(e){let n=this.symbol??this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),r=(n?this.compiler.symbolMembers(n).getFiltered(t)??[]:[]).filter(e=>e.isKind(F.Column)).length?[]:[new w(C.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Nf(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=gp(e.callee),r.token=P(e);let o=zp(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=Bp(s,O_);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.endpoints?.[0])return[];let s=o.endpoints[0],c=r.op(this.compiler);return c?{schemaName:s.schemaName,tableName:s.tableName,fieldNames:s.fieldNames,relation:c,token:s.token}:[]}),r.inline_deps=(s[i.Dep]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.edges?.[0])return[];let s=e.value;if(!(s instanceof B))return[];let c=s.op?.value;if(c!==`->`&&c!==`<-`)return[];let u=o.edges[0],d=c===`->`?u.downstream:u.upstream;return{schemaName:d.schemaName,tableName:d.tableName,fieldNames:d.fieldNames,direction:c,token:d.token}}),r.checks=(s[i.Check]||[]).map(e=>({token:P(e),expression:e.value.value.value})),this.table.fields.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.indexes.push(...i):i&&this.table.indexes.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.checks.push(...i):i&&this.table.checks.push(i),r.getErrors()}},O_=[i.Note,i.Ref,i.PrimaryKey,i.PK,i.NotNull,i.Null,i.Unique,i.Increment,i.Default,i.Check],k_={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.HeaderColor]:{isValidBuiltinFieldValue:If,message:`'headercolor' must be a color literal`,assignBuiltinField(e,t){e.headerColor=t}}},A_={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a quoted string`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}}},j_={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new w(C.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new w(C.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},M_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.Table)?new n(i.symbolFactory.create(Yp,{declaration:a,name:o},a.filepath)):A(a,r.Table)?Nf(a.callee)?new n(i.symbolFactory.create(tm,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Xp,{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=up(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(j_.getColumnDuplicateError(e.name,r)),c.push(j_.getColumnDuplicateError(e.name,n))):(c.push(j_.getPartialInjectionDuplicateError(e.name,r)),c.push(j_.getPartialInjectionDuplicateError(e.name,n))):l.set(t,n)}}let u=[];for(let e=0;e<s.length;e++){let n=s[e];if(!(n.declaration instanceof H)||!Nf(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=N(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new w(C.BINDING_ERROR,`TablePartial '${o}' does not exist in Schema 'public'`,i||a));continue}let d=r.symbolMembers(l).getFiltered(t);if(d){let t=d.flatMap(e=>{if(!e.declaration)return[];let t=e.name;return t===void 0?e:r.symbolFactory.create(dm,{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 dm)).map(e=>e.name));return new n(Fa([...s.filter(e=>!(e instanceof dm&&d.has(e.name)))].reverse(),e=>e.isKind(F.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(ep(o,i.Dep)&&o.parent instanceof R&&o.parent.isKind(r.Table)&&!Zf(o,r.Table)){let e=a.parseFile(o.filepath).getValue().ast,r=a.nodeSymbol(e).getValue();return r===t?n.create(void 0):I_(a,r,o)}if(!Zf(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===`~`?N_(a,c,o):Qf(o,1)?P_(a,c,o):ep(o,i.Ref)?F_(a,c,o):ep(o,i.Dep)?I_(a,c,o):Qf(o,0)?n.create(e):L_(a,c,o)},bindNode(i,a){if(!k(a,r.Table))return n.create(e);let o=new y_(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.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function N_(e,r,i){let a=N(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Kp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,F.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,F.TablePartial,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function P_(e,t,r){if(!D(r))return new n(void 0);let i=gp(r)??``;if(!O(r.parentNode))return n.create(e.lookupMembers(t,F.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=ap(r),o=e.lookupMembers(a,t?F.Enum:F.Schema,i);return o?n.create(o):new n(void 0,[new w(C.BINDING_ERROR,t?`Enum '${i}' does not exist in Schema 'public'`:`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function F_(e,i,a){if(!D(a))return new n(void 0);let o=gp(a)??``;if(!O(a.parentNode)){let s=a.parent,c=s instanceof R&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,F.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,F.Column,o);return l?n.create(l):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}return Vm(e,i,a,F.Column)}function I_(e,i,a){if(!D(a))return new n(void 0);let o=Zf(a,r.Table),s=gp(a)??``;if(!O(a.parentNode)){if(o){let o=a.parent,c=o instanceof R&&o.isKind(r.Table)?e.nodeSymbol(o).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,F.Column,s);if(t)return n.create(t)}let l=e.lookupMembers(i,F.Column,s);return l?n.create(l):new n(void 0,[new w(C.BINDING_ERROR,`Column '${s}' does not exist in Table 'public.${c?.name??``}'`,a)])}{let t=e.lookupMembers(i,F.Table,s);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${s}' does not exist in Schema 'public'`,a)])}}return Vm(e,i,a,o?F.Column:F.Table)}function L_(e,t,r){if(!D(r))return new n(void 0);let i=gp(r)??``;if(!O(r.parentNode))return To.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,F.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function R_(e){return e?e.split(``).every(e=>Tf(e)||Ef(e))&&!Ef(e[0]):!1}function z_(e){return R_(e)?e:`"${H_(e)}"`}function B_(...e){return e.map(z_).join(`.`)}function V_(e){let t=``,n=0,r={n:`
9
- `,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function H_(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
10
- `: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 U_(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`'${H_(e)}'`;let{value:t,type:n}=e;if(t==null||Bo(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(Bo(n)){let e=Ep(t);return e===null?`\`${t}\``:e?`true`:`false`}if(zo(n)){let e=Sp(t);return e===null?`\`${t}\``:String(e)}if(Uo(n)){let e=Mp(t);return e===null?`\`${t}\``:`'${H_(e)}'`}let r=Op(t);return r===null?`\`${t}\``:`'${H_(r)}'`}function W_(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?V_(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function G_(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 K_(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 Kp&&n.isKind(F.Schema)){let o=e.symbolMembers(n);i.push(...o.getErrors()),a.push(...o.getWarnings()),r.push(...o.getFiltered(t)??[])}}return new n(r,i,a)}function q_(e){return e.includes(`
11
- `)?`'''\n${e}\n'''`:`'${H_(e)}'`}var J_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(zm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof um?[...r.getErrors(),new w(C.BINDING_ERROR,`TableGroup cannot reference imported table '${i.name}'`,n)]:r.getErrors()}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Y_={[i.Note]:{isValidBuiltinFieldValue:E,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.Color]:{isValidBuiltinFieldValue:If,message:`'color' must be a color literal`,assignBuiltinField(e,t){e.color=t}}},X_=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)),E_(this.compiler,this.tableGroup,this.symbol,Y_,this.filepath),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=Ip(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name))),this.tableGroup.name=n,this.tableGroup.schemaName=r[0]||null,t}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof H);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:Fp(M(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:P(e)}}return[]})}interpretFields(e){let n=[];return this.tableGroup.tables=e.map(e=>{let r=e.callee?this.compiler.nodeReferee(e.callee).getFiltered(t):void 0;if(r?.isKind(F.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=j(e.callee);return i.length>2&&n.push(new w(C.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=T(e).getValue();this.tableGroup.color=t.color?.length?Lp(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Fp(M(n?.value)),token:P(n)},this.tableGroup.metadata=Bp(t,Object.keys(Y_)),[]}},Z_={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new w(C.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Q_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return k(a,r.TableGroup)?new n(i.symbolFactory.create(Zp,{declaration:a,name:s},a.filepath)):A(a,r.TableGroup)?new n(i.symbolFactory.create(Qp,{declaration:a,name:o?.map(z_).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=up(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(Z_.getFieldDuplicateError(e.name,r)),s.push(Z_.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)||!Zf(a,r.TableGroup)||a.parent&&$f(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):$_(i,s,a)},bindNode(i,a){if(!k(a,r.TableGroup))return n.create(e);let o=new J_(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 Zp)?n.create(e):Rm(t,o)?new X_(t,i,a).interpret():n.create(void 0)}};function $_(e,r,i){let a=gp(i)??``;if(!O(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Kp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,F.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,F.Table,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Bm(e,i);if(o){if(o.isKind(F.Schema)){let t=e.lookupMembers(o,[F.Table,F.Schema],a);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,F.Schema,a);return s?n.create(s):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var ev=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof U?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof H)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(h(n)instanceof W){let e=T(h(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t})}tryToBindColumnType(e){let t=fp(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():[])}},tv=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}=Ip(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=T(e).getValue(),n=ya(t[i.HeaderColor]);this.tablePartial.headerColor=n?Lp(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Fp(M(r?.value)),token:P(r)},[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof H);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:Fp(M(e.body instanceof U?e.body.body[0].callee:e.body.callee)),token:P(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let n=[],r={},a=this.compiler.nodeSymbol(e).getFiltered(t);r.name=gp(e.callee)??``,r.token=P(e);let o=zp(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=Bp(s,O_);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 Jm))return[];let r=n.owners(this.compiler);if(l&&r.length>0&&!r.some(e=>e===l))return[];let i=n.op(this.compiler);if(!i)return[];let a=n.rightTable(this.compiler),o=n.rightColumns(this.compiler);if(!a||o.length===0)return[];let s=a.interpretedName(this.compiler,this.filepath);return{schemaName:s.schema,tableName:s.name,fieldNames:o.map(e=>e.name??``),relation:i,token:P(n.rightToken())}}),r.inline_deps=[],r.checks=(s[i.Check]||[]).map(e=>({token:P(e),expression:e.value.value.value})),this.tablePartial.fields?.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.indexes?.push(...i):i&&this.tablePartial.indexes?.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.checks?.push(...i):i&&this.tablePartial.checks?.push(i),r.getErrors()}},nv={getDuplicateError(e,t,n){return new w(C.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},rv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return k(a,r.TablePartial)?new n(i.symbolFactory.create(em,{declaration:a,name:o},a.filepath)):A(a,r.TablePartial)?new n(i.symbolFactory.create(Xp,{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=up(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(j_.getColumnDuplicateError(t,r)),s.push(j_.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)||!Zf(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):Qf(o,1)?iv(a,c,o):ep(o,i.Ref)?av(a,c,o):ov(a,c,o)},bindNode(i,a){if(!k(a,r.TablePartial))return n.create(e);let o=new ev(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof em?r.declaration instanceof R?new tv(t,r,i).interpret():n.create(void 0):n.create(e)}};function iv(e,t,r){if(!D(r))return new n(void 0);let i=gp(r)??``;if(!O(r.parentNode))return n.create(e.lookupMembers(t,F.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function av(e,i,a){if(!D(a))return new n(void 0);let o=gp(a)??``;if(!O(a.parentNode)){let s=a.parent;if(s instanceof R&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,F.Column,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,F.Column,o);return c?n.create(c):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Bm(e,a);if(s){if(s.isKind(F.Schema)){let t=e.lookupMembers(s,[F.Table,F.Schema],o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(F.Table)){let t=e.lookupMembers(s,F.Column,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${s.name}'`,a)])}return new n(void 0)}let c=a.parentNode;if(c.leftExpression===a){if(O(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,F.Schema,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,F.Table,o);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function ov(e,t,r){if(!D(r))return new n(void 0);let i=gp(r)??``;if(!O(r.parentNode))return To.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,F.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(F.Schema)){let t=e.lookupMembers(a,[F.Enum,F.Schema],i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(F.Enum)){let t=e.lookupMembers(a,F.EnumField,i);return t?n.create(t):new n(void 0,[new w(C.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(O(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,F.Schema,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,F.Enum,i);return a?n.create(a):new n(void 0,[new w(C.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var sv={symbolMembers(r,i){if(!i.isKind(F.Schema)||!(i instanceof Kp))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=lv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...uv(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...fv(r,i,e,t,c));for(let e of o.uses.selective){let n=lv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...uv(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...fv(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(...mv(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof um&&e.isKind(F.Schema))return!1;let t=`${e.originalSymbol.intern()}:${e.name??``}`;return!d.has(t)&&(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 um?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(cv(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function cv(e,t,n,r){switch(e){case F.Table:return j_.getDuplicateError(t,n,r);case F.Enum:return Sh.getDuplicateError(t,n,r);case F.TablePartial:return nv.getDuplicateError(t,n,r);case F.TableGroup:return Z_.getDuplicateError(t,n,r);case F.DiagramView:return mh.getDuplicateError(t,n,r);default:return new w(C.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function lv(e,r,i,a){let o=d_(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(Kp,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function uv(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=s_.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:dv(e,n,r,a,i)}function dv(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(um,{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(...mv(e,n,t));for(let i of s.reuses.selective)if(c.push(...uv(e,n,i,a)),d_(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(um,{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=pv(e,t,n.qualifiedName);i&&c.push(...dv(e,n,r,i,a))}return c}function fv(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=pv(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(um,{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(Kp,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=lv(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...uv(e,n,r))}for(let{importPath:t}of d)l.push(...fv(e,n,t,i,a,o));return l}function pv(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 mv(e,n,r){if(!r.isKind(F.TableGroup)||!(r instanceof um))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?[v]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=hv(e,c,i);l&&s.push(e.symbolFactory.create(um,{kind:F.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function hv(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 gv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof H)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},_v={[i.Color]:{isValidBuiltinFieldValue:Lf,message:`'color' must be a color literal or 'none'`,assignBuiltinField(e,t){e.color=t}}},vv=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 E_(this.compiler,this.note,this.symbol,_v,this.filepath),n.create(this.note,e)}interpretName(){let{name:e}=this.symbol.interpretedName(this.compiler,this.filepath);return this.note.name=e,[]}interpretSettingList(e){let t=T(e).getValue();return t.color?.length&&(this.note.color=Lp(t.color.at(0)?.value)),this.note.metadata=Bp(t,Object.keys(_v)),[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof H);return t.length!==1||n.length>0?[new w(C.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=M(e.callee)??``;return this.note.content=Fp(t),[]}},yv={nodeSymbol(i,a){return!k(a,r.Note)||!(a.parentNode instanceof L)?n.create(e):new n(i.symbolFactory.create($p,{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 gv(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof $p?r.declaration instanceof R?new vv(t,r,i).interpret():n.create(void 0):n.create(e)}},bv=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=b_(this.declarationNode);return!j(e)?.length||!t||w_(this.compiler,this.declarationNode)?[]:[new w(C.BINDING_ERROR,`cannot find metadata target element`,e??this.declarationNode)]}bindBody(e){return e instanceof U?e.body.filter(e=>e instanceof R).flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[]):[]}},xv=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.filepath=n,this.values={}}interpret(){let e=this.interpretValues(this.declarationNode.body);return new n(this.values,e)}interpretValues(e){if(!(e instanceof U))return[];for(let t of e.body){if(!(t instanceof R))continue;let e=t.type?.value;if(!e)continue;let n=Vp(t.body instanceof H?t.body.callee:void 0);n&&(this.values[e]={value:e===`note`?Fp(n):n,token:P(t)})}return[]}},Sv=[c_,M_,Ch,Xg,Eh,ah,a_,lh,Ug,Q_,rv,yv,{nodeMetadata(t,i){return k(i,r.Metadata)?new n(new Qm(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)||!b_(a)?new n(void 0):new n(w_(t,a))},bindNode(t,i){return k(i,r.Metadata)?new n(void 0,new bv(t,i).bind()):new n(e)},interpretMetadata(t,i,a){return i instanceof Qm?k(i.declaration,r.Metadata)?new xv(t,i,a).interpret():new n(void 0):new n(e)}},sv,hh,Bg];function Cv(t,...r){for(let i of Sv){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function wv(r){let i=Cv(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Tv(r){let i=Cv(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Ev(r){let i=Cv(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Dv(r){let i=Cv(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function Ov(r){let i=Cv(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function kv(r,i){let a=Cv(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function Av(r,i){let a=Cv(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var jv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new w(C.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return h(n)instanceof W&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof ym))&&t.push(new w(C.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`name`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||n.push(new w(C.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Mv={validateNode(t,i){if(!k(i,r.Checks))return n.create(e);let a=new jv(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return k(i,r.Checks)?i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Checks)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Checks)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},Nv=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Project,r.Dep)?[]:[new w(C.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project or a Dep`,this.declarationNode)]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof U)return[new w(C.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return!(this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Dep))&&!E(e.callee)&&t.push(new w(C.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e)),e.args.length>0&&t.push(...e.args.map(e=>new w(C.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function Pv(e){return e instanceof R&&!!e.type?.value}var Fv={validateNode(t,r){if(!Pv(r))return n.create(e);let i=new Nv(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return Pv(r)?r.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return Pv(r)?r.alias?new n(void 0,[new w(C.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return Pv(r)?r.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},Iv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettings(),...this.validateBody(this.declarationNode.body)]}validateSettings(){let e=[];this.declarationNode.attributeList&&e.push(...Lv(this.declarationNode.attributeList).getErrors());let t=this.declarationNode.body;if(t instanceof H){let n=t.args.find(e=>e instanceof W);n&&e.push(...Lv(n).getErrors())}return e}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_DEP_CONTEXT,`A Dep must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Dep name`,e)]:jf(e)?[]:[new w(C.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.forEach(e=>{if(!e.callee){t.push(new w(C.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e));return}if(!(e.callee instanceof V)){t.push(new w(C.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e.callee));return}let n=e.callee;n.op?.value!==`->`&&n.op?.value!==`<-`&&t.push(new w(C.INVALID_DEP_FIELD,`Dep edges must use the '->' or '<-' operator`,e.callee));let r=fp(n.leftExpression)??{variables:[],tupleElements:[]},i=fp(n.rightExpression)??{variables:[],tupleElements:[]};r.variables.length===0&&r.tupleElements.length===0&&t.push(new w(C.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.leftExpression||e.callee)),i.variables.length===0&&i.tupleElements.length===0&&t.push(new w(C.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.rightExpression||e.callee));let a=[...e.args];h(a)instanceof W?a.pop():a[0]instanceof W&&a.shift(),a.length>0&&t.push(...a.map(e=>new w(C.INVALID_DEP_FIELD,`A Dep field should only have a single binary relationship`,e)))}),t}validateSubElements(e){return e.flatMap(e=>{if(!e.type)return[];let t=e.type.value?.toLowerCase(),n=e.body;if(!t)return[];switch(t){case i.Color:return e.name||!(n instanceof H)||!n.callee||!If(n.callee)?[new w(C.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,e)]:[];case i.Note:{let t;return n instanceof H?t=n.callee:n instanceof U&&n.body[0]instanceof H&&(t=n.body[0].callee),!t||!E(t)?[new w(C.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,e)]:[]}default:return e.name||n instanceof U?[new w(C.INVALID_SETTINGS,`'${t}' must be a simple field (e.g. ${t}: value). Block syntax is not allowed`,e)]:!(n instanceof H)||!n.callee?[]:!E(n.callee)&&!If(n.callee)&&!zf(n.callee)&&!jf(n.callee)?[new w(C.INVALID_SETTINGS,`Invalid value for '${t}'. Expected a string, number, color, or identifier`,e)]:[]}})}};function Lv(e){let t=T(e),r=[...t.getErrors()],a=t.getValue();for(let[e,t]of Object.entries(a))for(let n of t)switch(e){case i.Color:If(n.value)||r.push(new w(C.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,n));break;case i.Note:E(n.value)||r.push(new w(C.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,n));break;default:n.value&&!E(n.value)&&!If(n.value)&&!zf(n.value)&&!jf(n.value)&&r.push(new w(C.INVALID_SETTINGS,`Invalid value for setting '${e}'. Expected a string, number, color, or identifier`,n))}return new n(a,r)}var Rv={validateNode(t,i){return k(i,r.Dep)?n.create(void 0,new Iv(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Dep)?i.name?jf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,i.name)]):new n(void 0):A(i,r.Dep)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Dep)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Dep)?new n(void 0):n.create(e)},nodeSettings(t,i){if(k(i,r.Dep))return i.attributeList?Lv(i.attributeList):new n({});if(A(i,r.Dep)){let e=[...i.args],t;return h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),t?Lv(t):new n({})}return n.create(e)}},zv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList)],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?jf(e)?[]:[new w(C.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new w(C.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof H)return{errors:[new w(C.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=g(e.body,e=>e instanceof H),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Gf(e.callee)?e.args.length>0?e.args.map(e=>new w(C.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new w(C.INVALID_DIAGRAMVIEW_FIELD,`Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.`,e)])}validateSubElements(e){let t=[],n=[],r=[`tables`,`notes`,`tablegroups`,`schemas`];for(let i of e){if(!i.type)continue;let e=i.type.value.toLowerCase();if(!r.includes(e)){t.push(new w(C.INVALID_DIAGRAMVIEW_FIELD,`Unknown block type "${i.type.value}" in DiagramView. Allowed: Tables, Notes, TableGroups, Schemas`,i));continue}let a=this.validateSubBlock(i);t.push(...a.errors),n.push(...a.warnings)}return{errors:t,warnings:n}}validateSubBlock(e){let t=[],n=[];if(Mf(e))return t.push(new w(C.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof U))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof H&&Gf(e.callee)),a=r.body.some(e=>e instanceof H&&!Gf(e.callee));return i&&a&&n.push(new Cf(C.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t.push(...this.validateSubBlockFields(e)),{errors:t,warnings:n}}validateSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof U))return t;let n=e.body.body.filter(e=>e instanceof H);for(let e of n)Gf(e.callee)||(e.args.length>0||!j(e.callee))&&t.push(...e.args.map(e=>new w(C.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},Bv={validateNode(t,i){if(!k(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new zv(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(k(i,r.DiagramView)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=j(i.name);return e?new n(e):new n(void 0)}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(v),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)}},Vv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:kf(e)?[]:[new w(C.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new w(C.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new w(C.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!D(n.callee)&&t.push(new w(C.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];h(e)instanceof W?(t.push(...this.validateFieldSettings(h(e))),e.pop()):e[0]instanceof W&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new w(C.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];if(t)switch(e){case i.Note:t.length>1&&t.forEach(e=>n.push(new w(C.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{E(e.value)||n.push(new w(C.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Hv={validateNode(t,i){return k(i,r.Enum)?n.create(void 0,new Vv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.Enum)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!kf(i.name))return new n(void 0,[new w(C.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=j(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(A(i,r.Enum)){let e=N(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return k(i,r.Enum)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(k(a,r.Enum))return a.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(A(a,r.Enum)){let e=[...a.args],t;if(h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),!t)return new n({});let r=T(t),o=r.getErrors(),s=r.getValue(),c={};for(let[e,t]of Object.entries(s))switch(e){case i.Note:t.length>1&&t.forEach(e=>o.push(new w(C.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{E(e.value)||o.push(new w(C.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new w(C.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Uv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new w(C.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new w(C.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return h(n)instanceof W&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof Cm;)e.argumentList&&pp(e.argumentList)===void 0&&t.push(new w(C.INVALID_INDEXES_FIELD,`An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such`,e.argumentList)),e=e.callee;pp(e)===void 0&&t.push(new w(C.INVALID_INDEXES_FIELD,`An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such`,e))}),t})}validateFieldSetting(e){let t=T(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`note`:case`name`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new w(C.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{D(e.value)||n.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new w(C.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Wv={validateNode(t,i){return k(i,r.Indexes)?n.create(void 0,new Uv(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Indexes)?i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):A(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Indexes)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(k(a,r.Indexes))return a.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(A(a,r.Indexes)){let e=[a.callee,...a.args],t;if(h(e)instanceof W&&(t=h(e)),!t)return new n({});let r=T(t),o=r.getErrors(),s=r.getValue(),c={};for(let[e,t]of Object.entries(s))switch(e){case i.Note:case i.Name:t.length>1&&t.forEach(t=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{E(t.value)||o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))}),c[e]=t;break;case i.Unique:case i.PK:t.length>1&&t.forEach(t=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))}),c[e]=t;break;case i.Type:t.length>1&&t.forEach(e=>o.push(new w(C.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{D(e.value)||o.push(new w(C.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new w(C.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Gv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return!(e instanceof L)&&!(e instanceof R&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project,r.Dep))?[new w(C.INVALID_NOTE_CONTEXT,`A Note can only appear inside a Table, a TableGroup, a TablePartial or a Project. Sticky note can only appear at the global scope.`,this.declarationNode)]:[]}validateName(e){return this.compiler.nodeFullname(this.declarationNode).getErrors()}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof L}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new w(C.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=T(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.Color:{let t=_v[i.Color];e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{t.isValidBuiltinFieldValue(e.value)||n.push(new w(C.INVALID_NOTE_SETTING_VALUE,t.message,e.value||e.name))});break}default:n.push(...x_(t,e,{duplicate:C.DUPLICATE_NOTE_SETTING,invalidValue:C.INVALID_NOTE_SETTING_VALUE}))}}),n}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new w(C.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new w(C.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),E(e[0].callee)||t.push(new w(C.INVALID_NOTE,`A Note content must be a quoted string`,e[0])),e[0].args.length>0&&t.push(...e[0].args.map(e=>new w(C.INVALID_NOTE,`A Note can only contain one quoted string`,e))),t)}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Kv={validateNode(t,i){return k(i,r.Note)?n.create(void 0,new Gv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!k(i,r.Note))return n.create(e);if(!(i.parent instanceof L))return i.name?new n(void 0,[new w(C.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new w(C.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof Tm)return new n(void 0,[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=j(i.name);return a===void 0?new n(void 0,[new w(C.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return k(i,r.Note)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Note)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},qv={[Up.Table]:k_,[Up.Column]:A_,[Up.TableGroup]:Y_,[Up.Note]:_v},Jv=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 b_(this.declarationNode)?[]:[new w(C.INVALID_METADATA_TARGET_KIND,`A Metadata target kind must be one of: ${Object.values(Up).join(`, `)}`,this.declarationNode.targetKind??this.declarationNode)]}validateTargetName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Metadata target's name`,e)]:kf(e)?[]:[new w(C.INVALID_NAME,`A Metadata target's name must be of the form <schema>.<table>, <table>.<column>, <schema>.<table>.<column> or a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A Metadata target must have a name`,this.declarationNode)]}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Metadata's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.map(e=>new w(C.INVALID_METADATA_FIELD,`A Metadata field must use the 'key: value' syntax`,e))}validateSubElements(e){let t={},n=b_(this.declarationNode),r=e.flatMap(e=>{if(!e.type)return[];if(e.body instanceof U)return[new w(C.UNEXPECTED_COMPLEX_BODY,`A Metadata field can only have an inline value`,e.body)];let r=e.type.value.toLowerCase();t[r]||(t[r]=[]),t[r].push(e);let i=n?qv[n][r]:void 0;return i?i.isValidBuiltinFieldValue(e.body?.callee)?[]:[new w(C.INVALID_METADATA_FIELD,i.message,e)]:Wf(e.body?.callee)?[]:[new w(C.INVALID_METADATA_FIELD,`A Metadata field value must be a string or a color literal`,e.body??e)]});return r.push(...Object.values(t).flatMap(e=>e.length<=1?[]:e.map(e=>new w(C.DUPLICATE_METADATA_FIELD,`Duplicate Metadata fields are defined`,e)))),r}},Yv={validateNode(t,i){return k(i,r.Metadata)?new n(void 0,new Jv(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)}},Xv=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)}},Zv={validateNode(t,r){return Xf(r)?n.create(void 0,new Xv(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Xf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Xf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Xf(r)?new n({}):n.create(e)}},Qv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name).getErrors(),...this.validateAlias(this.declarationNode.alias).getErrors(),...this.validateSettingList(this.declarationNode.attributeList).getErrors(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?jf(e)?new n(j(e)):new n(void 0,[new w(C.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]):new n(void 0)}validateAlias(e){return e?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...t.map(e=>new w(C.INVALID_PROJECT_FIELD,`A Project can not have inline fields`,e)),...this.validateSubElements(n)]}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},$v={validateNode(t,i){return k(i,r.Project)?n.create(void 0,new Qv(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Project)?i.name?jf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):A(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Project)&&i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):A(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Project)?i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):A(i,r.Project)?new n({}):n.create(e)}},ey=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return e instanceof L||e instanceof R&&e.isKind(r.Table)?[]:[new w(C.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof L?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof Cm))return[new w(C.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,e||this.declarationNode.type||this.declarationNode)];let t=[];return(!e.callee||!kf(e.callee))&&t.push(new w(C.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Hf(e.argumentList))&&t.push(new w(C.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Hf(e)?[new w(C.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return ty(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateDataRow(e);let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateDataRows(t),...this.validateSubElements(n)]}validateDataRows(e){return e.flatMap(e=>this.validateDataRow(e))}validateDataRow(e){let t=[];if(!e.callee||e.args.length>0)return t.push(new w(C.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof xm)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new w(C.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,n));else this.isValidRecordValue(e.callee)||t.push(new w(C.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,e.callee));return t}isValidRecordValue(e){if(e instanceof Om||zf(e)||E(e)||e instanceof ym)return!0;if(D(e)){let t=e.expression.variable.value.toLowerCase();return To.includes(t)}if(O(e)){let t=j(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function ty(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.Example:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_RECORDS_SETTING,`'example' can only appear once`,e))),e.forEach(e=>{e.value&&r.push(new w(C.INVALID_RECORDS_SETTING_VALUE,`'example' cannot have a value`,e))});break;default:r.push(...e.map(e=>new w(C.UNKNOWN_RECORDS_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}var ny={validateNode(t,i){return k(i,r.Records)?n.create(void 0,new ey(t,i).validate()):n.create(e)},nodeFullname(i,a){if(k(a,r.Records)){if(a.name instanceof Tm)return new n(void 0,[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof L){if(!(a.name instanceof Cm))return new n(void 0,[new w(C.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,a.name||a.type||a)]);let e=[];(!a.name.callee||!kf(a.name.callee))&&e.push(new w(C.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Hf(a.name.argumentList))&&e.push(new w(C.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=j(a.name.callee);return t?.length===1&&t.unshift(v),new n(t,e)}{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Hf(a.name)?new n(e,[new w(C.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return A(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Records)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):A(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Records)?i.attributeList?ty(i.attributeList):new n({}):A(i,r.Records)?new n({}):n.create(e)}},ry=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:jf(e)?[]:[new w(C.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new w(C.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new w(C.EMPTY_REF,`A Ref must have at least one field`,this.declarationNode)];let t=[];return e.length>1&&t.push(...e.slice(1).map(e=>new w(C.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!tp(e.callee)&&t.push(new w(C.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&tp(e.callee)){let n=fp(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=fp(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new w(C.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new w(C.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!np(e.callee)&&t.push(new w(C.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(h(n)instanceof W){let e=this.validateFieldSettings(h(n));t.push(...e),n.pop()}else n[0]instanceof W&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new w(C.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return ay(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function iy(e){if(!(D(e)&&e.expression.variable.kind!==_.QUOTED_STRING)&&!(e instanceof _m))return!1;let t;if(t=e instanceof _m?sp(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 ay(e){let t=T(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Delete:case i.Update:t.length>1&&t.forEach(t=>r.push(new w(C.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{iy(t.value)||r.push(new w(C.INVALID_REF_SETTING_VALUE,`'${e}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,t))}),o[e]=t;break;case i.Color:t.length>1&&r.push(...t.map(e=>new w(C.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{If(e.value)||r.push(new w(C.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),o[e]=t;break;case i.Inactive:t.length>1&&r.push(...t.map(e=>new w(C.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new w(C.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new w(C.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var oy={validateNode(t,i){return k(i,r.Ref)?n.create(void 0,new ry(t,i).validate()):n.create(e)},nodeFullname(t,i){return k(i,r.Ref)?i.name?jf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):A(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return k(i,r.Ref)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(k(i,r.Ref))return i.attributeList?new n({},[new w(C.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(A(i,r.Ref)){let e=[...i.args],t;return h(e)instanceof W?t=h(e):e[0]instanceof W&&(t=e[0]),t?ay(t):new n({})}return n.create(e)}},sy=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof km?[new w(C.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:kf(e)?[]:[new w(C.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new w(C.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Af(e)?[]:[new w(C.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){return cy(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=e=>{let t=[];if(!e.callee)return[];e.args.length===0&&t.push(new w(C.INVALID_COLUMN,`A column must have a type`,e.callee)),D(e.callee)||t.push(new w(C.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Uf(e.args[0])&&t.push(new w(C.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t},n=e=>{let t=[];return e.callee?(Nf(e.callee)||t.push(new w(C.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee)),e.args.length&&t.push(...e.args.map(e=>new w(C.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof B&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){return ly(e).getErrors()}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function cy(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{let t=k_[i.HeaderColor];t.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{let t=k_[i.Note];t.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Vf(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,"'dep' must be `-> target` or `<- source`",e.value||e.name))});break;default:r.push(...x_(t,e,{duplicate:C.DUPLICATE_TABLE_SETTING,invalidValue:C.INVALID_TABLE_SETTING_VALUE}))}}),new n(a,r)}function ly(e){if(!e.slice(0,-1).every(Kf)||!e.slice(-1).every(e=>Kf(e)||e instanceof W))return new n({},e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let t;h(e)instanceof W&&(t=e.pop());let r=T(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();t!==i.PK&&t!==i.Unique?a.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e)):o[t]===void 0?o[t]=[e]:o[t].push(e)});let s=o[i.PK]||[],c=o[i.PrimaryKey]||[];return s.length>=1&&c.length>=1&&a.push(...[...s,...c].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{let t=A_[i.Note];t.isValidBuiltinFieldValue(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Bf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=o[i.Null]||[];e.length>=1&&t.length>=1&&a.push(...[...e,...t].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Rf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'default' must be an enum value, a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof ym||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Vf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'dep' must be a valid unary relationship`,e.value||e.name))});break;default:a.push(...x_(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),new n(o,a)}var uy={validateNode(t,i){return k(i,r.Table)?n.create(void 0,new sy(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.Table)){if(!i.name)return new n(void 0,[new w(C.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof km)return new n(void 0,[new w(C.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,i.name)]);let e=j(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(A(i,r.Table)){if(Nf(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?Af(i.alias)?new n(N(i.alias)):new n(void 0,[new w(C.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):A(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.Table)?i.attributeList?cy(i.attributeList):new n({}):A(i,r.Table)?ly(i.args.slice(1)):n.create(e)}},dy=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:jf(e)?[]:[new w(C.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new w(C.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){return fy(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&j(e.callee)===void 0&&t.push(new w(C.INVALID_TABLEGROUP_FIELD,`A TableGroup field must be of the form <table> or <schema>.<table>`,e.callee)),e.args.length>0&&t.push(...e.args.map(e=>new w(C.INVALID_TABLEGROUP_FIELD,`A TableGroup field should only have a single Table name`,e))),t})}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function fy(e){let t=T(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Color:case i.Note:{let n=Y_[e];t.length>1&&r.push(...t.map(t=>new w(C.DUPLICATE_TABLE_SETTING,`'${e}' can only appear once`,t))),t.forEach(e=>{n.isValidBuiltinFieldValue(e.value)||r.push(new w(C.INVALID_TABLE_SETTING_VALUE,n.message,e.value||e.name))}),o[e]=t;break}default:r.push(...x_(e,t,{duplicate:C.DUPLICATE_TABLE_SETTING,invalidValue:C.INVALID_TABLE_SETTING_VALUE})),o[e]=t}return new n(o,r)}var py={validateNode(t,i){return k(i,r.TableGroup)?n.create(void 0,new dy(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.TableGroup))return i.name?jf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new w(C.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(A(i,r.TableGroup)){let e=j(i.callee);return e?.length===1&&e.unshift(v),new n(e)}return n.create(e)},nodeAlias(t,i){return k(i,r.TableGroup)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):A(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.TableGroup)?fy(i.attributeList):A(i,r.TableGroup)?new n({}):n.create(e)}},my=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new w(C.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new w(C.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:jf(e)?[]:[new w(C.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new w(C.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new w(C.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=T(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{If(e.value)||n.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&n.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||n.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new w(C.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof H)return[new w(C.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof H);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[];e.args.length===0&&t.push(new w(C.INVALID_COLUMN,`A column must have a type`,e.callee)),D(e.callee)||t.push(new w(C.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Uf(e.args[0])&&t.push(new w(C.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t})}validateFieldSetting(e){let t=h(e);if(!e.slice(0,-1).every(Kf)||!(Kf(t)||t instanceof W))return e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;h(e)instanceof W&&(n=e.pop());let r=T(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();t!==i.PK&&t!==i.Unique?a.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e)):o[t]===void 0?o[t]=[e]:o[t].push(e)});let s=o[i.PK]||[],c=o[i.PrimaryKey]||[];return s.length>=1&&c.length>=1&&a.push(...[...s,...c].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Bf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=o[i.Null]||[];e.length>=1&&n.length>=1&&a.push(...[...e,...n].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&a.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Rf(e.value)||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof ym||a.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...x_(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),a}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new w(C.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function hy(e){let t=T(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{If(e.value)||r.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new w(C.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||r.push(new w(C.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new w(C.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function gy(e){let t=h(e);if(e.length>0&&(!e.slice(0,-1).every(Kf)||!(Kf(t)||t instanceof W)))return new n({},e.map(e=>new w(C.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let r;h(e)instanceof W&&(r=e.pop());let a=T(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(N(e)??``).toLowerCase();t!==i.PK&&t!==i.Unique?o.push(new w(C.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e)):s[t]===void 0?s[t]=[e]:s[t].push(e)});let c=s[i.PK]||[],l=s[i.PrimaryKey]||[];return c.length>=1&&l.length>=1&&o.push(...[...c,...l].map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{E(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Bf(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=s[i.Null]||[];e.length>=1&&n.length>=1&&o.push(...[...e,...n].map(e=>new w(C.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&o.push(...e.map(e=>new w(C.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Rf(e.value)||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof ym||o.push(new w(C.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:o.push(...x_(t,e,{duplicate:C.DUPLICATE_COLUMN_SETTING,invalidValue:C.INVALID_COLUMN_SETTING_VALUE}))}}),new n(s,o)}var _y={validateNode(t,i){return k(i,r.TablePartial)?n.create(void 0,new my(t,i).validate()):n.create(e)},nodeFullname(t,i){if(k(i,r.TablePartial))return i.name?jf(i.name)?new n(j(i.name)):new n(void 0,[new w(C.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new w(C.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(A(i,r.TablePartial)){let e=N(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return k(i,r.TablePartial)?i.alias?new n(void 0,[new w(C.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(N(i.alias)):A(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return k(i,r.TablePartial)?hy(i.attributeList):A(i,r.TablePartial)?gy(i.args.slice(1)):n.create(e)}},vy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new w(C.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.specifiers instanceof Tm)return[];for(let t of this.declarationNode.specifiers?.specifiers||[])e.push(...this.validateSpecifier(t));return e}validateSpecifier(e){let t=[];return e.importKind===void 0?t.push(new w(C.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Hp))||t.push(new w(C.INVALID_USE_SPECIFIER_KIND,`'${e.importKind.value}' is not a valid specifier type`,e.importKind)),[...t,...this.compiler.nodeFullname(e).getErrors(),...this.compiler.nodeAlias(e).getErrors()]}},yy=[uy,Hv,ny,Wv,Mv,oy,Rv,$v,py,_y,Kv,Yv,Bv,Zv,{validateNode(t,r){return r instanceof mm?n.create(void 0,new vy(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!Yf(r))return n.create(e);let i=j(r.name);return!i||i.length===0?n.create(void 0,[new w(C.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Hp.TableGroup)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Hp.TablePartial)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Hp.Note)&&i.length>1?n.create(i,[new w(C.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Hp.Schema)&&i.unshift(v),new n(i))},nodeAlias(t,r){return Yf(r)?r.alias?Af(r.alias)?new n(N(r.alias)):new n(void 0,[new w(C.INVALID_ALIAS,`Use aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return r instanceof mm?n.create({}):n.create(e)}},Fv];function by(t,...r){for(let n of yy){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function xy(r){let i=by(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function Sy(r){let i=by(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function Cy(r){let i=by(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function wy(r){let i=by(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var Ty=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Ey(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}),Ty&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function Dy(e,t,...n){return Ey(t,n)}var Oy=!1,ky=!1,Ay=!1,jy=!1,My=void 0,Ny=typeof self==`object`?self:typeof global==`object`?global:{},Py=void 0;Ny.vscode!==void 0&&Ny.vscode.process!==void 0?Py=Ny.vscode.process:typeof process<`u`&&(Py=process);var Fy=typeof Py?.versions?.electron==`string`&&Py?.type===`renderer`;if(typeof navigator==`object`&&!Fy)My=navigator.userAgent,Oy=My.indexOf(`Windows`)>=0,ky=My.indexOf(`Macintosh`)>=0,(My.indexOf(`Macintosh`)>=0||My.indexOf(`iPad`)>=0||My.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,Ay=My.indexOf(`Linux`)>=0,My?.indexOf(`Mobi`),jy=!0,Dy({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof Py==`object`){Oy=Py.platform===`win32`,ky=Py.platform===`darwin`,Ay=Py.platform===`linux`,Ay&&Py.env.SNAP&&Py.env.SNAP_REVISION,Py.env.CI||Py.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=Py.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 Iy=Oy,Ly=ky;jy&&Ny.importScripts;var Ry=My,zy=typeof Ny.postMessage==`function`&&!Ny.importScripts;(()=>{if(zy){let e=[];Ny.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}),Ny.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var By=!!(Ry&&Ry.indexOf(`Chrome`)>=0);Ry&&Ry.indexOf(`Firefox`),!By&&Ry&&Ry.indexOf(`Safari`),Ry&&Ry.indexOf(`Edg/`),Ry&&Ry.indexOf(`Android`);var Vy;if(Ny.vscode!==void 0&&Ny.vscode.process!==void 0){let e=Ny.vscode.process;Vy={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else Vy=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 Iy?`win32`:Ly?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var Hy=Vy.cwd,Uy=Vy.env,Wy=Vy.platform,Gy=65,Ky=97,qy=90,Jy=122,Yy=46,Xy=47,Zy=92,Qy=58,$y=63,eb=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 tb(e,t){if(typeof e!=`object`||!e)throw new eb(t,`Object`,e)}function nb(e,t){if(typeof e!=`string`)throw new eb(t,`string`,e)}var rb=Wy===`win32`;function K(e){return e===Xy||e===Zy}function ib(e){return e===Xy}function ab(e){return e>=Gy&&e<=qy||e>=Ky&&e<=Jy}function ob(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=Xy;if(r(c)){if(o!==l-1&&s!==1){if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==Yy||i.charCodeAt(i.length-2)!==Yy){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}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===Yy&&s!==-1?++s:s=-1}return i}function sb(e,t){tb(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 cb={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],nb(a,`path`),a.length===0)continue}else t.length===0?a=Hy():(a=Uy[`=${t}`]||Hy(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Zy)&&(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 ab(u)&&a.charCodeAt(1)===Qy&&(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=ob(n,!r,`\\`,K),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){nb(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return ib(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 ab(a)&&e.charCodeAt(1)===Qy&&(r=e.slice(0,2),n=2,t>2&&K(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?ob(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){nb(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return K(n)||t>2&&ab(n)&&e.charCodeAt(1)===Qy&&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];nb(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 cb.normalize(t)},relative(e,t){if(nb(e,`from`),nb(t,`to`),e===t)return``;let n=cb.resolve(e),r=cb.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Zy;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Zy;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Zy;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Zy;)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===Zy&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Zy)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Zy?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)===Zy)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Zy&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=cb.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Zy){if(t.charCodeAt(1)===Zy){let e=t.charCodeAt(2);if(e!==$y&&e!==Yy)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(ab(t.charCodeAt(0))&&t.charCodeAt(1)===Qy&&t.charCodeAt(2)===Zy)return`\\\\?\\${t}`;return e},dirname(e){nb(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 ab(i)&&e.charCodeAt(1)===Qy&&(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&&nb(t,`ext`),nb(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&ab(e.charCodeAt(0))&&e.charCodeAt(1)===Qy&&(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){nb(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Qy&&ab(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}}else i===-1&&(a=!1,i=s+1),t===Yy?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:sb.bind(null,`\\`),parse(e){nb(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(ab(i)&&e.charCodeAt(1)===Qy){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}}else s===-1&&(c=!1,s=l+1),i===Yy?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))),t.dir=o>0&&o!==r?e.slice(0,o-1):t.root,t},sep:`\\`,delimiter:`;`,win32:null,posix:null},lb=(()=>{if(rb){let e=/\\/g;return()=>{let t=Hy().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Hy()})(),ub={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:lb();nb(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Xy)}return t=ob(t,!n,`/`,ib),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(nb(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Xy,n=e.charCodeAt(e.length-1)===Xy;return e=ob(e,!t,`/`,ib),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return nb(e,`path`),e.length>0&&e.charCodeAt(0)===Xy},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];nb(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:ub.normalize(t)},relative(e,t){if(nb(e,`from`),nb(t,`to`),e===t||(e=ub.resolve(e),t=ub.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===Xy&&(o=s)}if(s===a){if(i>a){if(t.charCodeAt(1+s)===Xy)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Xy?o=s:s===0&&(o=0))}let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Xy)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(nb(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Xy,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Xy){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&&nb(t,`ext`),nb(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===Xy){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)===Xy){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){nb(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===Xy){if(!i){n=o+1;break}}else r===-1&&(i=!1,r=o+1),s===Yy?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:sb.bind(null,`/`),parse(e){nb(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Xy,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===Xy){if(!s){a=c+1;break}}else o===-1&&(s=!1,o=c+1),t===Yy?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};ub.win32=cb.win32=cb,ub.posix=cb.posix=ub,rb?cb.normalize:ub.normalize,rb?cb.resolve:ub.resolve,rb?cb.relative:ub.relative,rb?cb.dirname:ub.dirname,rb?cb.basename:ub.basename,rb?cb.extname:ub.extname,rb?cb.sep:ub.sep;var db=/^\w[\w\d+.-]*$/,fb=/^\//,pb=/^\/\//;function mb(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&&!db.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!fb.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(pb.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 hb(e,t){return!e&&!t?`file`:e}function gb(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==_b&&(t=_b+t):t=_b}return t}var q=``,_b=`/`,vb=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,yb=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=hb(e,a),this.authority=t||q,this.path=gb(this.scheme,n||q),this.query=r||q,this.fragment=i||q,mb(this,a))}get fsPath(){return Tb(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 xb(t,n,r,i,a)}static parse(e,t=!1){let n=vb.exec(e);return n?new xb(n[2]||q,kb(n[4]||q),kb(n[5]||q),kb(n[7]||q),kb(n[9]||q),t):new xb(q,q,q,q,q)}static file(e){let t=q;if(Iy&&(e=e.replace(/\\/g,_b)),e[0]===_b&&e[1]===_b){let n=e.indexOf(_b,2);n===-1?(t=e.substring(2),e=_b):(t=e.substring(2,n),e=e.substring(n)||_b)}return new xb(`file`,t,e,q,q)}static from(e,t){return new xb(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=Iy&&t.scheme===`file`?e.file(cb.join(Tb(t,!0),...n)).path:ub.join(t.path,...n),t.with({path:r})}toString(e=!1){return Eb(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new xb(t);return e._formatted=t.external??null,e._fsPath=t._sep===bb?t.fsPath??null:null,e}}},bb=Iy?1:void 0,xb=class extends yb{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=Tb(this,!1),this._fsPath}toString(e=!1){return e?Eb(this,!0):(this._formatted||=Eb(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=bb),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}},Sb={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 Cb(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=Sb[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 wb(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+=Sb[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function Tb(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,Iy&&(n=n.replace(/\//g,`\\`)),n}function Eb(e,t){let n=t?wb:Cb,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=_b,r+=_b),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:Cb(c,!1,!1)),r}function Db(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+Db(e.substr(3)):e}}var Ob=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function kb(e){return e.match(Ob)?e.replace(Ob,e=>Db(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}({}),Ab=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 jb(e,t){return e.getOffsetAt(t)}function Mb(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 Nb=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=So.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=Mb(e,n.nodeOrToken);if(r.startLineNumber===t.startLineNumber&&r.startColumn===t.startColumn&&r.endLineNumber===t.endLineNumber&&r.endColumn===t.endColumn)for(let r of n.quickFixes??[]){let n=this.quickFixToCodeAction(r,e,t);n&&o.push(n)}}let s=Fa(o,e=>{let t=e.diagnostics?.[0];return`${e.title}@${t?.startLineNumber}:${t?.startColumn}`});if(s.length)return{actions:s,dispose(){}}}quickFixToCodeAction(e,t,n){let r=So.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=yb.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]}}},Pb=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=So.fromUri(String(e.uri)),a=jb(e,n),o=this.resolveImportPath(i,a,r);if(o)return o;let s=[...this.compiler.container.stack(i,a)];for(;s.length!==0;){let e=s.pop();if(!e)continue;let n=this.compiler.nodeReferee(e).getFiltered(t);if(!n)continue;let i;if(n.declaration&&[pm.PRIMARY_EXPRESSION,pm.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=yb.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[]}resolveImportPath(e,t,n){let r=this.compiler.parse.ast(e);for(let i of r.body){if(!(i instanceof mm)||!i.importPath||!Mh(t,i.importPath))continue;let r=i.importPath.value;if(!r)continue;let a=this.compiler.layout.resolveFileSpecifier(e,r);if(a&&this.compiler.layout.exists(a))return[{range:{startColumn:1,startLineNumber:1,endColumn:1,endLineNumber:1},uri:n&&yb.parse(a.toUri({protocol:n.scheme}))}]}}},Fb=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e),...this.provideInfos(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideInfos(e){return e?this.compiler.interpretFile(e).getInfos().map(e=>this.createDiagnostic(e,`info`)):this.compiler.interpretProject().getInfos().map(e=>this.createDiagnostic(e,`info`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos,a=e.details,o=a?.quickFixes?.filter(e=>e.edits.length>0).map(e=>({title:e.title,shortTitle:e.shortTitle,edits:e.edits.map(e=>({start:e.start,end:e.end,newText:e.newText})),isPreferred:e.isPreferred}));return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code,category:a?.category,explanation:a?.explanation,filepath:e.filepath,quickFixes:o}}getSeverityValue(e){return e===`error`?Ab.Error:e===`warning`?Ab.Warning:Ab.Info}},Ib=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=So.fromUri(String(r)),a=jb(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[pm.ELEMENT_DECLARATION,pm.FUNCTION_APPLICATION,pm.PRIMARY_EXPRESSION].includes(e?.kind)){let n=this.compiler.nodeSymbol(e).getFiltered(t)??this.compiler.nodeReferee(e).getFiltered(t),i=n?this.compiler.symbolReferences(n):void 0;if(i&&i.length>0)return i.map(e=>{let t=r;return r&&e.filepath&&(t=yb.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 Lb(e,t){let n=[],r=e.parseFile(t).getValue()?.ast;if(!r)return n;for(let e of r.uses){let t=e.importPath?.value??``,r=[];if(e.specifiers instanceof gm)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=N(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?N(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof Tm&&r.push({name:`*`});(r.length!==0||e.specifiers instanceof Tm)&&n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function Rb(e,t,n,r,i,a){let o=Lb(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:zb(Pa([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
12
- `),removeRange:Bb(a,e.startOffset,e.endOffset)}}return{topInsert:zb([l],s,`
13
- `)}}function zb(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function Bb(e,t,n){let r=e.lastIndexOf(`
14
- `,t-1)+1,i=n;for(;i<e.length&&(e[i]===` `||e[i]===` `);)i++;return i<e.length&&e[i]===`\r`&&i++,i<e.length&&e[i]===`
15
- `&&i++,{startOffset:r,endOffset:i}}function Vb(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 Hb(e,t){if(!e||Ga(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===_.NEWLINE&&n.end<=t)return!1}return!0}function X(){return{suggestions:[]}}function Ub(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function Wb(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:z_(e.insertText??``),quoted:!0}))}}function Gb(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 Kb(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(qb(e,c,t.kind,s,r,o)))}}return i}function qb(e,t,n,r,i,a){let o=Rb(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=Jb(a,o.removeRange.startOffset),t=Jb(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:Vb(n),detail:`from ${e.layout.getFileSpecifierInfo(i,r)?.label??r.basename}`,sortText:`zzz_${Vb(n).toString().padStart(2,`0`)}_${t}`,range:void 0,additionalTextEdits:s}}function Jb(e,t){let n=1,r=1;for(let i=0;i<t&&i<e.length;i++)e[i]===`
16
- `?(n++,r=1):r++;return{line:n,column:r}}function Yb(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof R)||!o.isKind(r.Records)||!(o.body instanceof U)||!o.body||!Mh(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof L?Xb(e,o):Zb(e,o)}function Xb(e,n){if(!(n.name instanceof Cm))return X();let r=n.name.argumentList?.elementList||[],i=r.map(n=>e.nodeReferee(n).getFiltered(t));if(!i||i.length===0)return X();let a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Xp||r instanceof dm))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 Zb(e,n){let r=n.parent;if(!(r instanceof R))return X();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof Yp))return X();let a;if(n.name instanceof bm){let r=n.name.elementList,i=r.map(n=>e.nodeReferee(n).getFiltered(t)).filter(e=>e!==void 0);a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Xp||r instanceof dm))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 Qb(e,t,n,r,i,a={}){let o=e.parse.ast(t);for(let s of o.body)if(s instanceof mm&&n>=s.start&&n<=s.fullEnd)return $b(e,t,n,s,i,r,a);return null}function $b(e,t,n,r,i,a,o){if(r.importPath&&Mh(n,r.importPath))return ix(e,t,r.importPath,i,r,o);if(r.importPath&&n>=r.importPath.end)return X();if(r.fromKeyword&&n>r.fromKeyword.end)return ix(e,t,void 0,i,r,o);if(r.specifiers instanceof gm){if(!r.specifiers.openBrace){let e=rx();return Hb(r.useKeyword,n)?Ub(e):e}return ex(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof Tm)return X();let s=rx();return Hb(r.useKeyword,n)?Ub(s):s}function ex(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 nx(e,t,i,n)}return tx()}}return tx()}function tx(){return{suggestions:Object.keys(Hp).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function nx(e,n,r,i){if(!r)return X();let a=e.layout.resolveFileSpecifier(n,r.value);if(!a)return X();let o=e.usableMembers(a).getFiltered(t);if(!o)return X();let s=new Set;for(let n of o.schemaMembers){let r=e.symbolMembers(n).getFiltered(t)??[];for(let e of r){if(e.kind!==i||e instanceof um&&!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:Vb(i),range:void 0}))}}function rx(){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 ix(e,t,n,r,i,{fileListDepth:a=2}){let o=n?n.value:``,s=n===void 0,c;if(n){let e=Mb(r,n);c={startLineNumber:e.startLineNumber,startColumn:e.startColumn+1,endLineNumber:e.endLineNumber,endColumn:e.endColumn-1}}let l=sx(i),u=new Map,d=new Set;if(o.startsWith(`/`)||o.startsWith(`./`)||o.startsWith(`../`))for(let{label:n,entry:r}of ax(e,t,o)){let i=e.layout.isDirectory(r),a=i?void 0:e.layout.getFileSpecifierInfo(t,r);if(!i&&a===void 0)continue;!i&&cx(e,r,l)&&d.add(n);let o=a?.specifier??n;u.set(n,{label:a?.label??n,detail:a?.detail,insertText:s?`'${o}'`:o,insertTextRules:Y.KeepWhitespace,kind:i?J.Folder:J.File,sortText:`${i?`2`:`3`}${n}`,range:c})}else{let n=ox(e.layout,So.from(`/`),a);for(let r of n){if(r.equals(t))continue;let n=e.layout.getFileSpecifierInfo(t,r);if(n===void 0||!n.specifier.startsWith(o))continue;let{specifier:i,label:a,detail:f}=n;if(cx(e,r,l)&&d.add(i),u.has(i))continue;let p=s?`'${i}'`:i;u.set(i,{label:a??i,detail:f,insertText:p,insertTextRules:Y.KeepWhitespace,kind:J.File,sortText:`3${i}`,range:c})}}for(let[e,t]of u)d.has(e)&&(t.sortText=`${t.kind===J.File?`0`:`1`}${e}`,t.detail=t.detail?`${t.detail} · best match`:`best match`);return{suggestions:[...u.values()]}}function ax(e,t,n){let r;n.startsWith(`/`)?r=n:(r=So.resolve(t.dirname,n).fsPath,n.endsWith(`/`)&&!r.endsWith(`/`)&&(r+=`/`));let i=r.endsWith(`/`)?r:So.from(r).dirname,a=[];for(let o of e.layout.listDirectory(So.from(i))){if(o.equals(t)||!o.fsPath.startsWith(r))continue;let i=o.fsPath.slice(r.length),s=e.layout.isDirectory(o)?`${n}${i}/`:`${n}${i}`;a.push({label:s,entry:o})}return a}function ox(e,t,n){if(n<=0)return[];let r=[];for(let i of e.listDirectory(t))e.isFile(i)?r.push(i):e.isDirectory(i)&&r.push(...ox(e,i,n-1));return r}function sx(e){let t=e.specifiers;return t instanceof gm?t.specifiers.flatMap(e=>{let t=N(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function cx(e,n,r){if(r.length===0)return!1;let i=e.usableMembers(n).getFiltered(t);return i?r.every(({name:e,kind:t})=>i.nonSchemaMembers.some(n=>n.kind===t&&n.name===e)):!1}var Z={Table:`Table`,TableGroup:`TableGroup`,Enum:`Enum`,Project:`Project`,Ref:`Ref`,Dep:`Dep`,TablePartial:`TablePartial`,Records:`Records`,DiagramView:`DiagramView`,Note:`Note`,Metadata:`Metadata`,Indexes:`indexes`,Checks:`checks`,Tables:`Tables`,TableGroups:`TableGroups`,Notes:`Notes`,Schemas:`Schemas`,Column:`Column`},lx=`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(`.`),ux=[i.HeaderColor,i.Note];ux.map(e=>`${e}: `);var dx=[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique],fx=[i.Ref,i.Dep,i.Default,i.Note,i.Check],px=[...dx,...fx],mx=[...dx,...fx.map(e=>`${e}: `)],hx=[i.Unique,i.PK],gx=[i.Note,i.Name,i.Type],_x=[...hx,...gx],vx=[...hx,...gx.map(e=>`${e}: `)],yx=[i.Inactive],bx=[i.Update,i.Delete,i.Color],xx=[...yx,...bx],Sx=[...yx,...bx.map(e=>`${e}: `)],Cx=[i.Note],wx=Cx.map(e=>`${e}: `),Tx=[i.Name],Ex=Tx.map(e=>`${e}: `),Dx=[`cascade`,`set default`,`set null`,`restrict`],Ox=[`btree`,`hash`],kx=[Z.Note,Z.Indexes,Z.Checks,Z.Records],Ax=[Z.Table,Z.TableGroup,Z.Enum,Z.Note,Z.Ref,Z.Dep,Z.TablePartial],jx=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[],this.fileListDepth=t.fileListDepth??2}provideCompletionItems(e,t){let n=So.fromUri(String(e.uri)),i=jb(e,t),a=Yb(this.compiler,e,t,n,i);if(a!==null)return a;let o=this.compiler.token.flatStream(n),{token:s,index:c}=this.compiler.container.token(n,i),l=c===void 0?o[0]:o[c+1];if([...s?.trailingTrivia||[],...s?.leadingTrivia||[],...l?.leadingTrivia||[]].find(e=>Ja(e)&&Mh(i,e)))return X();if(c===void 0)return Kx();let u=Qb(this.compiler,n,i,s,e,{fileListDepth:this.fileListDepth});if(u!==null)return u;if([_.STRING_LITERAL,_.QUOTED_STRING].includes(s.kind)&&Mh(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 Kx();let f=[...this.compiler.container.stack(n,i)].reverse();for(let e of f)if(e instanceof B)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return Nx(this.compiler,n,i,e);case`~`:return Mx(this.compiler,n,i)}else if(e instanceof V)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return Nx(this.compiler,n,i,e);case`.`:return Ux(this.compiler,n,i,e)}else if(e instanceof z)return Rx(this.compiler,n,i,e);else if(e instanceof W)return Rx(this.compiler,n,i,e);else if(e instanceof bm)return Ix(this.compiler,n,i,e);else if(e instanceof xm)return Lx(this.compiler,n,i);else if(e instanceof Cm)return nS(this.compiler,n,i,e);else if(e instanceof H)return Wx(this.compiler,n,i,e);else if(e instanceof R){if(Nh(i,e))return k(e,r.Metadata)?eS(this.compiler,n,i,e):tS(this.compiler,n,i,e);if(e.bodyColon&&i>=e.bodyColon.end||e.body&&Mh(i,e.body))return Wx(this.compiler,n,i,void 0)}return X()}};function Mx(e,t,n){return Fx(e,t,n,e.parse.ast(t),[F.TablePartial])}function Nx(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.DEP,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=Fx(e,t,n,e.container.element(t,n),[F.Table,F.Schema,F.Column]);return Hb(r.op,n)?Ub(i):i}return X()}function Px(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?Wb({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof Kp&&e.isPublicSchema())).flatMap(t=>{let r=t.name;if(r===void 0)return[];let i=t.originalFilepath,a=i&&!i.equals(n.filepath)?`from ${e.layout.getFileSpecifierInfo(n.filepath,i)?.label??i.basename}`:`this file`;return{label:r,insertText:r,insertTextRules:Y.KeepWhitespace,kind:Vb(t.kind),sortText:Vb(t.kind).toString().padStart(2,`0`),detail:a,range:void 0}}).filter(e=>e.label!==``)}):X()}function Fx(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=Px(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 Kb(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 Wb(s)}function Ix(e,n,i,a){let o=e.container.scopeKind(n,i),s=e.container.element(n,i),c=[...e.container.stack(n,i)];for(let t of c)if(t instanceof Cm&&t.argumentList===a)return nS(e,n,i,t);if(s instanceof R&&s.isKind(r.Records)&&!(s.name instanceof Cm)&&Nh(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=Px(e,i,[F.Column]);return lp(a)?Gb(t):t}}switch(o){case Q.INDEXES:return oS(e,n,i);case Q.REF:case Q.DEP:for(;c.length>0;){let t=c.pop();if(t instanceof V&&t.op?.value===`.`)return Ux(e,n,i,t)}return Xx(e,n,i)}return X()}function Lx(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?Fx(e,t,n,e.container.element(t,n),[F.Schema,F.Enum,F.EnumField]):X()}function Rx(e,t,n,r){let{token:i}=e.container.token(t,n);if([_.COMMA,_.LBRACKET].includes(i?.kind)){let r=zx(e,t,n);return i?.kind===_.COMMA&&Hb(i,n)?Ub(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return zx(e,t,n);if(r.name instanceof _m){let a=Vx(e,t,n,sp(r.name)??``);return i?.kind===_.COLON&&Hb(i,n)?Ub(a):a}return X()}function zx(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&&!Mh(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=ux;break;case Q.TABLEGROUP:e=[i.Color,i.Note];break;case Q.RECORDS:return{suggestions:[{label:i.Example,insertText:i.Example,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}]};case Q.NOTE:e=[i.Color];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}))}}switch(a){case Q.TABLE:case Q.TABLEPARTIAL:return{suggestions:Bx(px,mx)};case Q.ENUM:return{suggestions:Bx(Cx,wx)};case Q.INDEXES:return{suggestions:Bx(_x,vx)};case Q.REF:return{suggestions:Bx(xx,Sx)};case Q.DEP:return{suggestions:[i.Note,i.Color].map(e=>({label:e,insertText:`${e}: `,kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))};case Q.CHECKS:return{suggestions:Bx(Tx,Ex)}}return X()}function Bx(e,t){return e.map((e,n)=>({label:e,insertText:t[n],kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))}function Vx(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:Dx.map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:Ox.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:[Eo].map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};break;case`default`:return Fx(e,t,n,e.container.element(t,n),[F.Schema,F.Enum])}return X()}function Hx(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 Ux(e,n,r,i){let a=dp(i)??[];return a.pop(),a.some(e=>!D(e))?X():Wb({suggestions:Hx(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:Vb(e.kind),range:void 0}})})}function Wx(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return Jx(e,t,n,i);case Q.PROJECT:return Yx(e,t,n,i);case Q.INDEXES:return iS(e,t,n);case Q.ENUM:return qx(e,t,n,i);case Q.REF:case Q.DEP:{let r=Xx(e,t,n);return e.container.token(t,n).token?.kind===_.COLON&&Hb(e.container.token(t,n).token,n)?Ub(r):r}case Q.TABLEGROUP:return rS(e,t);case Q.DIAGRAMVIEW:return lS();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof R){let a=i.parentNode,o=a instanceof U?a.parentNode:void 0;if(o instanceof R&&o.isKind(r.DiagramView))return uS(e,t,n,i)}return X()}default:return X()}}var Gx=[Z.Table,Z.TableGroup,Z.Enum,Z.Project,Z.Ref,Z.Dep,Z.TablePartial,Z.Records,Z.DiagramView,Z.Note,Z.Metadata];function Kx(){return{suggestions:Gx.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function qx(e,t,n,r){return r?.callee&&sS(n,r)===1?Fx(e,t,n,e.container.element(t,n),[F.Schema,F.Table,F.Column]):X()}function Jx(e,t,n,r){let i=kx;if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))};let a=sS(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:a===1?aS(e,t,n):X()}function Yx(e,t,n,r){let i=Ax;return!r?.callee||sS(n,r)===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:X()}function Xx(e,t,n){return Fx(e,t,n,e.container.element(t,n),[F.Schema,F.Table,F.Column])}var Zx={[Up.Table]:[F.Schema,F.Table],[Up.Column]:[F.Schema,F.Table,F.Column],[Up.TableGroup]:[F.TableGroup],[Up.Note]:[F.StickyNote]},Qx={[Up.Table]:Z.Table,[Up.Column]:Z.Column,[Up.TableGroup]:Z.TableGroup,[Up.Note]:Z.Note};function $x(){return{suggestions:Object.values(Up).map(e=>{let t=Qx[e];return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}})}}function eS(e,t,n,r){let i=b_(r);if(!i||n<=r.targetKind.end&&n>=r.targetKind.start)return $x();let a=Zx[i];return a?Fx(e,t,n,r.parent,a):X()}function tS(e,t,n,i){return i.isKind(r.Records)?Fx(e,t,n,i.parent,[F.Schema,F.Table]):X()}function nS(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&Mh(i,a.callee),c=a.argumentList&&Mh(i,a.argumentList);if(o instanceof R&&o.isKind(r.Records)&&Nh(i,o)){if(s)return Fx(e,n,i,o.parent,[F.Schema,F.Table]);if(!c)return X();let r=a.callee;if(!r)return X();let l=dp(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return X();let f=Px(e,d,[F.Column]),{argumentList:p}=a;return!p||!lp(p)?f:Gb(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof H)||o.callee!==a||(N(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return X();let l=Px(e,s,[F.Column]),{argumentList:u}=a;return!u||!lp(u)?l:Gb(l)}return X()}function rS(e,t){return{suggestions:[...Wb({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 Kp&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:Vb(e.kind),range:void 0}})}).suggestions,...[Z.Note].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))]}}function iS(e,t,n){return oS(e,t,n)}function aS(e,t,n){return{suggestions:[...lx.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.TypeParameter,sortText:J.TypeParameter.toString().padStart(2,`0`),range:void 0})),...Fx(e,t,n,e.container.element(t,n),[F.Enum,F.Schema]).suggestions]}}function oS(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?Wb({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:Vb(F.Column),range:void 0}:[]})}):X()}function sS(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 cS={label:`*`,insertText:`*`,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0};function lS(){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})),cS]}}function uS(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[cS,...Fx(e,t,n,e.parse.ast(t),[F.Table,F.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[cS,...Fx(e,t,n,e.parse.ast(t),[F.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[cS,{label:v,insertText:v,insertTextRules:Y.KeepWhitespace,kind:J.Module,range:void 0},...Fx(e,t,n,e.parse.ast(t),[F.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[cS,...Fx(e,t,n,e.parse.ast(t),[F.StickyNote]).suggestions]};default:return X()}}var dS={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*[}\]].*)$/}},fS={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`dep`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`,`metadata`],metadataTarget:[`table`,`tablegroup`,`schema`,`column`,`note`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`dep`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`none`,`check`,`tables`,`tablegroups`,`notes`,`schemas`,`inactive`,`example`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>~-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":{cases:{"$3@metadataTarget":[`keyword`,``,`keyword`,``,`identifier`],"@default":[`keyword`,``,`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`identifier`,``,`identifier`]}}],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@metadataTarget":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}};function pS(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:va(n,e=>!e.isInvalid,r);if(a===-1)return[this.parse.ast(e)];let o=n[a].start,s=this.parse.ast(e),c=[s];for(;;){let e=Im(s).find(e=>Mh(o,e));if(e===void 0||e instanceof Ha)break;c.push(e),s=e}if(i?.kind===_.COLON)return c;for(;c.length>0;){let n=!1,r=h(c);if(r instanceof H){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
17
- `&&(c.pop(),n=!0)}else r instanceof B||r instanceof V?this.container.token(e,t).token!==r.op&&(c.pop(),n=!0):r instanceof W?r.listCloseBracket&&r.end<=t&&(c.pop(),n=!0):r instanceof bm?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof xm?r.end<=t&&(c.pop(),n=!0):r instanceof U?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof _m||r.end<t&&(c.pop(),n=!0);if(n){let e=h(c);e instanceof R&&e.end<=t&&c.pop()}if(!n)break}return c}function mS(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 hS(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 gS(e,n){let r=this.container.element(e,n);if(!r)return;let i=this.nodeSymbol(r);if(i.hasValue(t))return;let a=this.symbolMembers(i.getValue());if(!a.hasValue(t))return a.getValue()}var Q=function(e){return e[e.TABLE=0]=`TABLE`,e[e.ENUM=1]=`ENUM`,e[e.TABLEGROUP=2]=`TABLEGROUP`,e[e.INDEXES=3]=`INDEXES`,e[e.NOTE=4]=`NOTE`,e[e.REF=5]=`REF`,e[e.DEP=6]=`DEP`,e[e.PROJECT=7]=`PROJECT`,e[e.CUSTOM=8]=`CUSTOM`,e[e.TOPLEVEL=9]=`TOPLEVEL`,e[e.TABLEPARTIAL=10]=`TABLEPARTIAL`,e[e.CHECKS=11]=`CHECKS`,e[e.RECORDS=12]=`RECORDS`,e[e.DIAGRAMVIEW=13]=`DIAGRAMVIEW`,e[e.METADATA=14]=`METADATA`,e}({});function _S(e,t){let n=this.container.element(e,t);if(n instanceof L)return Q.TOPLEVEL;switch(n.type?.value.toLowerCase()){case`table`:return Q.TABLE;case`enum`:return Q.ENUM;case`ref`:return Q.REF;case`dep`:return Q.DEP;case`tablegroup`:return Q.TABLEGROUP;case`indexes`:return Q.INDEXES;case`note`:return Q.NOTE;case`project`:return Q.PROJECT;case`tablepartial`:return Q.TABLEPARTIAL;case`checks`:return Q.CHECKS;case`records`:return Q.RECORDS;case`diagramview`:return Q.DIAGRAMVIEW;case`metadata`:return Q.METADATA;default:return Q.CUSTOM}}function vS(e,t){let r=t.originalSymbol;if(r.filepath.equals(e))return n.create(bS(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=yS(this,e);if(i.length>0)return n.create({schema:i.join(`.`),name:t});let a=bS(this,r);return a?n.create({...a,name:t}):n.create({schema:v,name:t})}return n.create(bS(this,r))}function yS(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof Kp&&e.isKind(F.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function bS(e,n){if(!n.declaration)return n.name?{schema:v,name:n.name}:void 0;let r=e.nodeFullname(n.declaration).getFiltered(t);if(!r||r.length===0)return n.name?{schema:v,name:n.name}:void 0;let i=r[r.length-1];return{schema:r.length>1?r.slice(0,-1).join(`.`):v,name:i}}function xS(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof mm)||!i.importPath)continue;let t=this.layout.resolveFileSpecifier(e,i.importPath.value);t&&!r.has(t.absolute)&&(r.add(t.absolute),n.push(t))}return n}function SS(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 CS(e){return SS(this,e?[e]:this.layout.getEntrypoints())}function wS(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function TS(e){return this.interpretFile(e).getErrors()}function ES(e){return this.interpretFile(e).getWarnings()}function DS(e){return this.parseFile(e).getValue().tokens}function OS(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.interpretSymbol(r,e).getFiltered(t)}function kS(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.symbolMembers(r).getFiltered(t)}function AS(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function jS(e){return this.parseFile(e).getValue().tokens.filter(eo)}function MS(e,t){let n=this.parse.ast(e);for(;;){let e=Im(n).find(e=>Mh(t,e));if(e===void 0)return n;if(e instanceof Ha)return e;n=e}}function NS(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 PS(){let e=G_(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 FS(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 IS(){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 LS(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var RS=class{constructor(e,t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
18
- `?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,e}peek(e=0){if(!(this.current.offset+e>=this.text.length))return this.text[this.current.offset+e]}check(e){for(let t=0;t<e.length;t+=1)if(e[t]!==this.peek(t))return!1;return!0}match(e){return this.check(e)?(e.split(``).forEach(()=>this.advance()),!0):!1}addToken(e,t=!1){this.tokens.push(this.createToken(e,t))}createToken(e,t=!1){return Ha.create(e,this.filepath,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),t)}lex(){return this.scanTokens(),this.tokens.push(Ha.create(_.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new n(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(_.SPACE);break;case`\r`:break;case`
19
- `:this.addToken(_.NEWLINE);break;case` `:this.addToken(_.TAB);break;case`,`:this.addToken(_.COMMA);break;case`(`:this.addToken(_.LPAREN);break;case`)`:this.addToken(_.RPAREN);break;case`[`:this.addToken(_.LBRACKET);break;case`]`:this.addToken(_.RBRACKET);break;case`{`:this.addToken(_.LBRACE);break;case`}`:this.addToken(_.RBRACE);break;case`;`:this.addToken(_.SEMICOLON);break;case`:`:this.addToken(_.COLON);break;case`'`:this.match(`''`)?this.multilineStringLiteral():this.singleLineStringLiteral();break;case`"`:this.quotedVariable();break;case"`":this.functionExpression();break;case`#`:this.colorLiteral();break;case`/`:this.match(`/`)?this.singleLineComment():this.match(`*`)?this.multilineComment():this.operator(e);break;case`*`:this.addToken(_.WILDCARD);break;default:if(Ba(e)){this.operator(e);break}if(Tf(e)){this.identifier();break}if(Ef(e)){this.numericLiteralOrIdentifier();break}this.addToken(_.OP,!0),this.errors.push(new w(C.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(_.OP,!0)))}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)za(i)?(t.push(i),i.kind===_.NEWLINE&&n&&(n.trailingTrivia=t,e=!0,n=void 0,t=[])):(e?i.leadingTrivia=t:n.trailingTrivia=t,r.push(i),t=[],n=i,e=!1);this.tokens=r}gatherInvalid(){let e,t=[],n=[];for(e=0;e<this.tokens.length&&eo(this.tokens[e]);e+=1)n.push(this.tokens[e]);let r=this.tokens[e];for(r.leadingInvalid=[...n,...r.leadingInvalid];e<this.tokens.length;e+=1){let n=this.tokens[e];eo(n)?r.trailingInvalid.push(n):(r=n,t.push(n))}this.tokens=t}consumeUntil(e,t,{allowNewline:n,allowEof:r,raw:i,consumeStopSequence:a=!0}){let o=``;for(;!this.isAtEnd()&&(n||!this.check(`
20
- `))&&!this.check(t);)this.peek()===`\\`&&!i?(this.advance(),o+=this.escapedString()):o+=this.advance();if(this.isAtEnd()&&!r){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new w(C.UNEXPECTED_EOF,`EOF reached while parsing`,t))}else if(this.check(`
21
- `)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new w(C.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t))}else a&&this.match(t),this.tokens.push(Ha.create(e,this.filepath,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(_.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(_.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(_.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(_.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(_.SINGLE_LINE_COMMENT,`
22
- `,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(_.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Of(this.peek());)this.advance();this.addToken(_.IDENTIFIER)}operator(e){switch(e){case`<`:this.peek()===`=`?this.advance():this.peek()===`>`?(this.advance(),this.peek()===`?`&&this.advance()):(this.peek()===`?`||this.peek()===`-`)&&this.advance();break;case`>`:(this.peek()===`=`||this.peek()===`?`)&&this.advance();break;case`-`:(this.peek()===`>`||this.peek()===`?`)&&this.advance();break;case`?`:this.peek()===`-`?(this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`<`?(this.advance(),this.peek()===`>`&&this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`>`&&(this.advance(),this.peek()===`?`&&this.advance());break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance()}this.addToken(_.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(_.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&&Ef(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Ef(this.peek());)this.advance();if(this.isAtEnd()||!Of(this.peek()))return this.addToken(_.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(_.NUMERIC_LITERAL);if(!t&&!Of(this.peek()))return this.addToken(_.NUMERIC_LITERAL);if(!t&&!Ef(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||Of(this.peek()));)this.advance();let e=this.createToken(_.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new w(C.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&Of(this.peek());)this.advance();let e=this.createToken(_.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&Of(this.peek());)this.advance();this.addToken(_.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(`
4
+ `)}function Ap(e){let t=A(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function jp(e){if(Af(e))return e.expression.literal.value;if(Bf(e)&&M(e)?.toLowerCase()===`none`)return vo}function Mp(e){if(e){if(T(e)){let t=j(e);if(t!==void 0)return{value:t,type:`string`}}if(Nf(e))return{type:`number`,value:Op(e)};if(Bf(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof xm&&e.value)return{value:e.value.value,type:`expression`};if(Vf(e)){let t=ap(e)?.at(-1),n=t?M(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function Np(e,t){let r=``,i=null;if(t instanceof Tm){if(i=(t.argumentList?.elementList??[]).map(e=>Nf(e)?Dp(e):T(e)?j(e):M(e)).join(`,`),r=`(${i})`,!t.callee)return new n({schemaName:null,type_name:``,args:i});t=t.callee}for(;t instanceof Tm||t instanceof jm;)if(t instanceof Tm){if(r=`(${(t.argumentList?.elementList??[]).map(e=>Nf(e)?Dp(e):T(e)?j(e):M(e)).join(`,`)})${r}`,!t.callee)break;t=t.callee}else if(t instanceof jm){if(r=`${`[${(t.indexer?.elementList??[]).map(e=>e?.name?.expression?.literal?.value??``).join(`,`)}]`}${r}`,!t.array)break;t=t.array}let{name:a,schemaName:o}=Ap(t);return o.length>1?new n({schemaName:o[0]??null,type_name:`${a}${r}`,args:i},[new C(S.UNSUPPORTED,`Nested schema is not supported`,t)]):new n({schemaName:o.length===0?null:o[0],type_name:`${a}${r}`,args:i})}function Pp(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=Fp(e.value);a!==void 0&&(r[t]=a)}return r}function Fp(e){if(!e)return;let t=j(e);if(t!==void 0)return t;let n=jp(e);if(n!==void 0)return n}var P=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.StickyNote=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewTopLevelWildcard=`DiagramView top-level wildcard`,e.DiagramViewTable=`DiagramView table`,e.DiagramViewTableGroup=`DiagramView tablegroup`,e.DiagramViewNote=`DiagramView note`,e.DiagramViewSchema=`DiagramView schema`,e.Metadata=`Metadata`,e.Element=`Element`,e.Kind=`Kind`,e.Program=`Program`,e}({}),Ip={Table:`Table`,Enum:`Enum`,TableGroup:`TableGroup`,TablePartial:`TablePartial`,Note:`Note`,Schema:`Schema`},Lp=function(e){return e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.Note=`Note`,e}({}),Rp=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},zp=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 N(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()}},Bp=class e extends zp{constructor({name:e,parent:t},n,r){super({kind:`Schema`},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===v}inNestedSchema(t,n){let r=this.members(t);if(r.some(e=>e.originalSymbol===n.originalSymbol))return!0;for(let i of r)if(i instanceof e&&i.inNestedSchema(t,n))return!0;return!1}},Vp=class extends zp{constructor({declaration:e,name:t},n,r){super({kind:`Enum`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Hp=class extends zp{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=kp(j(i));if(a)return{value:a,token:N(r)}}},Up=class extends zp{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 sm))}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=kp(j(i));if(a)return{value:a,token:N(r)}}headercolor(e){if(!this.declaration)return;let n=e.nodeSettings(this.declaration).getFiltered(t);return n?.[i.HeaderColor]?.length?jp(n[i.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===Ph.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===Ph.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===Ph.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===Ph.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(n=>{if(!(n.declaration instanceof V)||!Df(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===Ph.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===Ph.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=jp(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=kp(j(a));if(o)return{value:o,token:N(i)}},r=n(this);for(let t of this.resolvedPartials(e)){let e=n(t);e&&(r=e)}return r}},Wp=class extends zp{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 sm?this.injectionDeclaration:this.declaration)?.parentOfKind(L);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 sm?this.injectionDeclaration:this.declaration).parentOfKind(L);if(!n)return!1;let r=e.nodeSymbol(n).getFiltered(t);if(!(r instanceof Up))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)||Lo(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 Mp(n)}type(e){if(!(this.declaration instanceof V))return;let n=Np(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 Vp?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===Ph.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=kp(j(i));if(a)return{value:a,token:N(r)}}},Gp=class extends zp{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?jp(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=kp(j(i));if(a)return{value:a,token:N(r)}}},Kp=class extends zp{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}},qp=class extends zp{constructor({declaration:e,name:t},n,r){super({kind:`Element`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Jp=class extends zp{constructor({declaration:e,name:t},n,r){super({kind:`Kind`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Yp=class extends zp{constructor({declaration:e,name:t},n,r){super({kind:`Note`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Xp=class extends zp{constructor({declaration:e,name:t},n,r){super({kind:`TablePartial`,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Zp=class extends zp{constructor({declaration:e,name:t},n,r){super({kind:`PartialInjection`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Qp=class extends zp{constructor({declaration:e,name:t},n,r){super({kind:`DiagramView`,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},$p=class extends zp{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}},em=class extends zp{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}},tm=class extends zp{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}},nm=class extends zp{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}},rm=class extends zp{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}},im=class extends zp{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 Bp&&r.inNestedSchema(e,t))return!0;return!1}},am=class extends zp{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}},om=class extends zp{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(gm);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},sm=class extends Wp{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}};function cm(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`as`}function lm(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`use`}function um(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`metadata`}function dm(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`from`}function fm(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function pm(e){return!!e?.isInvalid}var mm=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},F=class{constructor(e,t,n,r){this.id=e,this.kind=t,this.filepath=n;let i=r.find(e=>e!==void 0&&!Number.isNaN(e.start));i?(this.startPos=i.startPos,this.fullStart=i instanceof Ha?qa(i):i.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let a=[...r].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));a?(this.endPos=a.endPos,this.fullEnd=a instanceof Ha?Ka(a):a.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}intern(){return`node@${this.filepath.intern()}:${this.id}`}get parent(){let e=this.parentNode;for(;e;){if(e instanceof L||e instanceof I)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}},hm=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}({}),I=class extends F{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>`)}},gm=class extends F{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 fm(this.useKeyword)}},_m=class extends F{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,`<use-specifier>`,a,[e,t,n,r]),this.importKind=e,this.name=t,this.asKeyword=n,this.alias=r}isKind(...e){return this.importKind?.value!==void 0&&e.map(e=>e.toLowerCase()).includes(this.importKind.value.toLowerCase())}getSymbolKind(){let e=this.importKind?.value?.toLowerCase();if(e!==void 0)return this.archImport?e===`kind`?P.Kind:e===`note`?P.Element:Object.values(Ip).find(t=>t.toLowerCase()===e)??P.Element:Object.values(P).find(t=>t.toLowerCase()===e)}},vm=class extends F{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}},L=class e extends F{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))}},ym=class extends F{constructor({identifiers:e=[]},t,n){super(t,`<identifier-stream>`,n,e||[]),this.identifiers=e}},R=class extends F{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}},z=class extends F{constructor({op:e,expression:t},n,r){super(n,`<prefix-expression>`,r,[e,t]),this.op=e,this.expression=t}},B=class extends F{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,`<infix-expression>`,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},bm=class extends F{constructor({op:e,expression:t},n,r){super(n,`<postfix-expression>`,r,[t,e]),this.op=e,this.expression=t}},xm=class extends F{constructor({value:e},t,n){super(t,`<function-expression>`,n,[e]),this.value=e}},V=class extends F{constructor({callee:e,args:t=[]},n,r){super(n,`<function-application>`,r,[e,...t]),this.callee=e,this.args=t}},H=class extends F{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 F{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,`<list-expression>`,a,[e,...Mm(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},Sm=class extends F{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,`<tuple-expression>`,a,[e,...Mm(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},Cm=class extends F{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,`<comma-expression>`,r,[...Mm(e,t)]),this.elementList=e,this.commaList=t}},wm=class extends Sm{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=`<group-expression>`}},Tm=class extends F{constructor({callee:e,argumentList:t},n,r){super(n,`<call-expression>`,r,[e,t]),this.callee=e,this.argumentList=t}},Em=class extends F{constructor({literal:e},t,n){super(t,`<literal>`,n,[e]),this.literal=e}},Dm=class extends F{constructor({token:e},t,n){super(t,`<wildcard>`,n,[e]),this.token=e}},Om=class extends F{constructor({variable:e},t,n){super(t,`<variable>`,n,[e]),this.variable=e}},km=class extends F{constructor({expression:e},t,n){super(t,`<primary-expression>`,n,[e]),this.expression=e}},Am=class extends F{constructor({prevToken:e},t,n){let r=Ha.create(_.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,`<dummy>`,n,[r])}},jm=class extends F{constructor({expression:e,indexer:t},n,r){super(n,`<array>`,r,[e,t]),this.array=e,this.indexer=t}};function Mm(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];let[n]=e,[r]=t;return(n.start<r.start?xr(Ra(e,t)):xr(Ra(t,e))).filter(e=>e!==null)}var Nm=function(e){return e.Table=`table`,e}({});function Pm(e,t,n){let r=t,i=e;if(i instanceof Tm&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Bf(i)||r.length===0)return;let a=[...r],o=ep(i),s=a.pop();if(!(s instanceof H))return;let c=h(a)instanceof U?a.pop():void 0;if(a.length===3){let e=ep(a[1]);return!e||!cm(e)?void 0:n.create(L,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(L,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(L,{type:o,attributeList:c,body:s})}function W(e){e&&(e instanceof Ha?Fm(e):Im(e))}function Fm(e){e.kind!==_.EOF&&(e.isInvalid=!0)}function Im(e){if(e instanceof L)W(e.type),W(e.targetKind),W(e.name),W(e.as),W(e.alias),W(e.bodyColon),W(e.attributeList),W(e.body);else if(e instanceof ym)e.identifiers.forEach(W);else if(e instanceof R)W(e.name),W(e.colon),W(e.value);else if(e instanceof z)W(e.op),W(e.expression);else if(e instanceof B)W(e.leftExpression),W(e.op),W(e.rightExpression);else if(e instanceof bm)W(e.op),W(e.expression);else if(e instanceof H)W(e.blockOpenBrace),e.body.forEach(W),W(e.blockCloseBrace);else if(e instanceof U)W(e.listOpenBracket),e.commaList.forEach(W),e.elementList.forEach(W),W(e.listCloseBracket);else if(e instanceof Sm)W(e.tupleOpenParen),e.commaList.forEach(W),e.elementList.forEach(W),W(e.tupleCloseParen);else if(e instanceof Cm)e.commaList.forEach(W),e.elementList.forEach(W);else if(e instanceof Tm)W(e.callee),W(e.argumentList);else if(e instanceof V)W(e.callee),e.args.forEach(W);else if(e instanceof km)W(e.expression);else if(e instanceof xm)W(e.value);else if(e instanceof Om)W(e.variable);else if(e instanceof Em)W(e.literal);else if(e instanceof wm)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof jm)W(e.array),W(e.indexer);else if(e instanceof I)e.body.forEach(W),W(e.eof);else if(!(e instanceof Am))if(e instanceof gm)W(e.useKeyword),W(e.specifiers),W(e.fromKeyword),W(e.importPath);else if(e instanceof vm)W(e.openBrace),e.specifiers.forEach(W),W(e.closeBrace);else if(e instanceof _m)W(e.importKind),W(e.name),W(e.asKeyword),W(e.alias);else if(e instanceof Dm)W(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function Lm(...e){return e.filter(e=>e!==void 0)}function Rm(e){if(e instanceof I)return Lm(...e.body,e.eof);if(e instanceof L)return Lm(e.type,e.targetKind,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof R)return Lm(e.name,e.colon,e.value);if(e instanceof ym)return e.identifiers;if(e instanceof Em)return e.literal?[e.literal]:[];if(e instanceof Om)return Lm(e.variable);if(e instanceof z)return Lm(e.op,e.expression);if(e instanceof B)return Lm(e.leftExpression,e.op,e.rightExpression);if(e instanceof bm)return Lm(e.expression,e.op);if(e instanceof xm)return Lm(e.value);if(e instanceof V)return Lm(e.callee,...e.args);if(e instanceof H)return Lm(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof U)return Lm(e.listOpenBracket,...zm(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof Sm)return Lm(e.tupleOpenParen,...zm(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof Cm)return Lm(...zm(e.elementList,e.commaList));if(e instanceof Tm)return Lm(e.callee,e.argumentList);if(e instanceof km)return Lm(e.expression);if(e instanceof jm)return Lm(e.array,e.indexer);if(e instanceof Am)return[];if(e instanceof gm)return Lm(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof vm)return Lm(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof _m)return Lm(e.importKind,e.name,e.asKeyword,e.alias);if(e instanceof Dm)return Lm(e.token);throw e instanceof wm?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function zm(e,t){let n=[],r=Math.min(e.length,t.length);for(let i=0;i<r;i+=1)n.push(e[i],t[i]);return n.push(...e.slice(r),...t.slice(r)),n}function Bm(e,t){return e.reachableFiles(t.filepath).every(t=>e.bindFile(t).getErrors().length===0)}function Vm(e){if(!e)return[];if(E(e))return[{variables:[e],tupleElements:[]}];if(e instanceof B){let t=op(e);return t?[t]:[...Vm(e.leftExpression),...Vm(e.rightExpression)]}if(e instanceof z||e instanceof bm)return Vm(e.expression);if(e instanceof Sm){let t=op(e);return t?[t]:e.elementList.flatMap(Vm)}return[]}function Hm(e,n){let r=n.parentNode;if(!r||!D(r)||r.rightExpression!==n)return;let i=r.leftExpression;for(;D(i);)i=i.rightExpression;return e.nodeReferee(i).getFiltered(t)??void 0}function Um(e,t,r,i){if(!E(r))return new n(void 0);let a=up(r)??``;if(D(r.parentNode)&&r.parentNode.rightExpression===r&&$f(r)){let t=Hm(e,r);if(!t)return new n(void 0);if(i===P.Column){if(t.isKind(P.Table)){let i=e.lookupMembers(t,P.Column,a);return i?n.create(i):new n(void 0,[new C(S.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${t.name}'`,r)])}return new n(void 0,[new C(S.BINDING_ERROR,`Column '${a}' does not exist`,r)])}else{if(t.isKind(P.Schema)){let i=e.lookupMembers(t,P.Table,a);return i?n.create(i):new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist`,r)])}}let o=Hm(e,r);if(o){if(o.isKind(P.Schema)){let t=e.lookupMembers(o,[P.Table,P.Schema],a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${a}' does not exist`,r)])}if(i===P.Column&&o.isKind(P.Table)){let t=e.lookupMembers(o,P.Column,a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Column '${a}' does not exist in Table 'public.${o.name}'`,r)])}return new n(void 0)}let s=r.parentNode;if(s.leftExpression===r){if(D(s.parentNode)&&s.parentNode.leftExpression===s||i===P.Table){let i=e.lookupMembers(t,P.Schema,a);return i?n.create(i):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${a}' does not exist in Schema 'public'`,r)])}let o=e.lookupMembers(t,P.Table,a);return o?n.create(o):new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Wm(e,n){let r=e.symbolMembers(n).getFiltered(t);if(r)return r.find(e=>e instanceof Bp&&e.isPublicSchema())}function Gm(e,n){let r=e.parseFile(n).getValue().ast;return e.nodeSymbol(r).getFiltered(t)}var Km=`server.function.container.database.cache.queue.disk.bucket.balancer.proxy.lock.key.gateway.globe.cloud.firewall.shield.router.switch.pipeline.chip.box.person.users.browser.mobile.laptop.desktop.terminal.mail.pulse.chart.clock.bell.search.settings.file.folder.tag.warning.check.rocket.webhook.stream.graph.robot.aws.gcp.azure.cloudflare.vercel.digitalocean.docker.kubernetes.nodejs.python.golang.java.nginx.postgres.mysql.mongodb.redis.elastic.kafka.rabbitmq.bigquery.snowflake.grafana.prometheus.github.gitlab.terraform.jenkins.stripe.firebase.supabase.sentry.datadog.slack.linux.apple.windows.haproxy`.split(`.`),qm={k8s:`kubernetes`,k9s:`kubernetes`,postgresql:`postgres`,pg:`postgres`,mongo:`mongodb`,node:`nodejs`,go:`golang`,elasticsearch:`elastic`,mq:`rabbitmq`,amqp:`rabbitmq`,do:`digitalocean`,google:`gcp`,gcloud:`gcp`,amazon:`aws`,s3:`bucket`,lambda:`function`,ec2:`server`,rds:`database`,sqs:`queue`,cdn:`globe`,internet:`cloud`,user:`person`,team:`users`,vpn:`lock`,monitor:`pulse`,metrics:`chart`,log:`file`,ci:`pipeline`,cron:`clock`,ai:`chip`,ml:`chip`},Jm=e=>qm[e]??e,Ym=new Set(Km),Xm=e=>Ym.has(Jm(e)),Zm={Server:{icon:`server`,category:`compute`},Function:{icon:`function`,category:`compute`},Container:{icon:`container`,category:`compute`},Service:{icon:`chip`,category:`compute`},Registry:{icon:`container`,category:`compute`},Database:{icon:`database`,category:`data`},Cache:{icon:`cache`,category:`data`},Queue:{icon:`queue`,category:`data`},Topic:{icon:`stream`,category:`data`},Storage:{icon:`disk`,category:`data`},Bucket:{icon:`bucket`,category:`data`},Warehouse:{icon:`graph`,category:`data`},Search:{icon:`search`,category:`data`},LoadBalancer:{icon:`balancer`,category:`net`},Proxy:{icon:`proxy`,category:`net`},VPN:{icon:`lock`,category:`net`},Gateway:{icon:`gateway`,category:`net`},Firewall:{icon:`firewall`,category:`net`},Router:{icon:`router`,category:`net`},Secret:{icon:`key`,category:`net`},CDN:{icon:`globe`,category:`edge`},Internet:{icon:`cloud`,category:`edge`},Client:{icon:`person`,category:`people`},Browser:{icon:`browser`,category:`people`},Mobile:{icon:`mobile`,category:`people`},Team:{icon:`users`,category:`people`},Monitoring:{icon:`pulse`,category:`ops`},Logging:{icon:`file`,category:`ops`},Alerting:{icon:`bell`,category:`ops`},Scheduler:{icon:`clock`,category:`ops`},Pipeline:{icon:`pipeline`,category:`ops`}},Qm=new Map(Object.keys(Zm).map(e=>[e.toLowerCase(),e])),$m=e=>Qm.get(e.toLowerCase());function eh(e){let t=e.toLowerCase();if(Xm(t))return`${e} is a brand, and a brand is a setting: Database name [type: '${t}']`;let n=Object.keys(Zm).filter(e=>{let n=e.toLowerCase();return n.startsWith(t)||t.startsWith(n)||n.includes(t)?!0:th(n,t,2)}).slice(0,6);return n.length?`Did you mean: ${n.join(`, `)}?`:`Declare it: Kind ${e} [icon: box]`}function th(e,t,n){if(Math.abs(e.length-t.length)>n)return!1;let r=Array.from({length:t.length+1},(e,t)=>t);for(let i=1;i<=e.length;i+=1){let a=[i],o=i;for(let n=1;n<=t.length;n+=1)a[n]=e[i-1]===t[n-1]?r[n-1]:1+Math.min(r[n-1],r[n],a[n-1]),o=Math.min(o,a[n]);if(o>n)return!1;r=a}return r[t.length]<=n}var nh=new Set([`Kind`,`Group`,`Note`,`Metadata`,`Link`,`Ref`,`use`,`Project`]),rh=new Set([...nh].map(e=>e.toLowerCase())),ih=e=>rh.has(e.toLowerCase());function ah(e){let t=e.toLowerCase(),n=[...Km,...Object.keys(qm)].filter(e=>e.startsWith(t)||t.startsWith(e)||e.includes(t)).slice(0,6);return n.length?`Did you mean: ${n.join(`, `)}?`:`The pack has ${Km.length} marks; draw your own with [glyph: 'M...'].`}var oh={group:`group`,note:`note`,kind:`kind`,link:`link`,ref:`link`,metadata:`metadata`,project:`project`},sh=e=>e.type?.value;function ch(e){return e instanceof L&&e.parentNode instanceof I&&!!e.type}function lh(e){if(ch(e))return oh[e.type.value.toLowerCase()]??`node`}function uh(e){let t=e;for(;t;){if(ch(t))return t;t=t.parentNode}}function G(e){if(e){if(e instanceof km){if(e.expression instanceof Om)return e.expression.variable?.value;if(e.expression instanceof Em)return String(e.expression.literal?.value)}if(e instanceof ym)return e.identifiers?.map(e=>e.value).join(` `)}}var dh=e=>G(e.alias)??G(e.name);function fh(e){if(!(e instanceof km)||!(e.expression instanceof Em))return null;let t=e.expression.literal;if(t?.kind!==_.NUMERIC_LITERAL)return null;let n=Number(t.value);return Number.isFinite(n)?n:null}function ph(e){let t=fh(e);if(t!==null)return t;let n=G(e);if(n!==void 0)return n===`true`?!0:n===`false`?!1:n}function mh(e){let t={};for(let n of e?.elementList??[]){if(!(n instanceof R))continue;let e=G(n.name)?.toLowerCase();e&&(t[e]=n.value===void 0?!0:ph(n.value)??!0)}return t}function hh(e){return e.body?e.body instanceof H?[...e.body.body]:[e.body]:[]}function gh(e){if(!(e instanceof V))return;let t=[...e.args??[]],n=t[t.length-1]instanceof U?t.pop():void 0;return{callee:e.callee,args:t,settings:n}}function _h(e){if(!(e instanceof B))return;let t=e.op?.value;if(!(!t||!e.leftExpression||!e.rightExpression))return{left:e.leftExpression,op:t,right:e.rightExpression}}function vh(e){let t=_h(e);return t&&t.op===`.`?t.left:e}var yh=new Set([`>`,`<`,`<>`,`-`]);function bh(e){let[t]=hh(e);if(!t)return;let n=gh(t),r=_h(n?.callee??t);if(!(!r||!yh.has(r.op)))return{row:n,infix:r}}function xh(e){if(e instanceof L){let t=sh(e);if(!t)return;let[n]=hh(e);if(!n)return{key:t,value:void 0};let r=gh(n);return{key:t,value:ph(r?r.callee??n:n)}}let t=gh(e),n=G(t?.callee);if(!n)return;let[r]=t?.args??[];return{key:n,value:r===void 0?void 0:ph(r)}}var Sh=e=>e instanceof L&&e.type?.value.toLowerCase()===`note`;function Ch(e){return hh(e).find(Sh)}function wh(e){return Eh(hh(e).map(e=>G(gh(e)?.callee)??``).join(` `))}function Th(e){return hh(e).map(e=>G(gh(e)?.callee)??``).join(` `).trim()}function Eh(e){let t=e.split(`
5
+ `),n=t.filter(e=>e.trim()).map(e=>e.length-e.trimStart().length),r=n.length?Math.min(...n):0;return t.map(e=>e.slice(r)).join(`
6
+ `).trim()}var Dh=/^(https:\/\/|data:image\/)/i,Oh=`A picture must be an https: URL or a data:image/ URI.`;function kh(e,t,n){let r={settings:t,problems:[]},i=new Set;for(let a of hh(e)){if(!(a instanceof L)){if(!n)continue;let e=gh(a);if(!e)continue;for(let n of[e.callee,...e.args]){let e=G(n);if(e){if(i.has(e)){r.problems.push({code:`duplicate`,message:`${e} is set twice`,node:a});continue}i.add(e),t[e]=!0}}continue}let e=sh(a);if(!e||e.toLowerCase()===`note`)continue;let o=xh(a);if(!o||o.value===void 0){r.problems.push({code:`bad`,message:`A property reads ${e}: 'value'`,node:a});continue}if(i.has(o.key)){r.problems.push({code:`duplicate`,message:`${o.key} is set twice`,node:a});continue}i.add(o.key),t[o.key]=o.value}return r}function Ah(e,t,n,r){let i=Gm(e,t);if(!i)return;let a=Wm(e,i);return(a&&e.lookupMembers(a,n,r))??e.lookupMembers(i,n,r)}function jh(e,n){let r=new Map,i=Gm(e,n);if(!i)return r;let a=Wm(e,i);if(!a)return r;let o=(e.symbolMembers(a).getFiltered(t)??[]).filter(e=>e.isKind(P.Kind)&&e.name!==void 0&&!ih(e.name));for(let e of[...o.filter(e=>e instanceof om),...o.filter(e=>!(e instanceof om))])r.set(e.name.toLowerCase(),e);return r}function Mh(e,t,n){let r=jh(e,t).get(n.toLowerCase());return r?r.originalSymbol.name:$m(n)}function Nh(e){let t=e.originalSymbol.declaration;return t instanceof L?dh(t):void 0}var Ph=function(e){return e.Ref=`ref`,e.Dep=`dep`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e.MetadataElement=`metadata element`,e.Link=`link`,e}({}),Fh=class e{static{this.id=0}constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}resolveOwnerPrograms(e,t){let n=this.declaration.filepath;return e.reachableFiles().flatMap(t=>Gm(e,t)||[]).filter(r=>e.reachableFiles(r.filepath).some(e=>e.equals(n))&&t.every(t=>r.inNestedSchema(e,t)))}},Ih=class extends Fh{constructor(e){super(e),this.kind=`ref`}container(e){let n=this.declaration.parentOfKind(L);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(this.declaration instanceof L){let t=ip(this.declaration)[0];if(!(t instanceof V))return[];let n=t.callee;return n instanceof B?Kh(e,n.leftExpression):[]}if(this.declaration instanceof R){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 L){let t=ip(this.declaration)[0];if(!(t instanceof V))return[];let n=t.callee;return n instanceof B?Kh(e,n.rightExpression):[]}if(this.declaration instanceof R){let t=this.declaration.value;return t instanceof z?Kh(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof L){let t=ip(this.declaration)[0];if(!(t instanceof V))return;let n=t.callee;return n instanceof B?qh(e,n.leftExpression):void 0}if(this.declaration instanceof R)return this.container(e)}rightTable(e){if(this.declaration instanceof L){let t=ip(this.declaration)[0];if(!(t instanceof V))return;let n=t.callee;return n instanceof B?qh(e,n.rightExpression):void 0}if(this.declaration instanceof R){let t=this.declaration.value;return t instanceof z?qh(e,t.expression)??this.container(e):void 0}}op(e){return this.opToken()?.value}opToken(){if(this.declaration instanceof L){let e=ip(this.declaration)[0];if(!(e instanceof V))return;let t=e.callee;return t instanceof B?t.op:void 0}if(this.declaration instanceof R){let e=this.declaration.value;return e instanceof z?e.op:void 0}}cardinalities(e){let t=this.op(e);return t?of(t):void 0}leftCardinality(e){let t=this.cardinalities(e);return t?Qd(t[0]):void 0}rightCardinality(e){let t=this.cardinalities(e);return t?Qd(t[1]):void 0}active(e){if(!(this.declaration instanceof L))return!0;let n=ip(this.declaration)[0];return n?!e.nodeSettings(n).getFiltered(t)?.[i.Inactive]?.length:!0}leftToken(){if(this.declaration instanceof L){let e=ip(this.declaration)[0];if(e instanceof V){let t=e.callee;if(t instanceof B&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof R){let e=this.declaration.parentOfKind(V);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof L){let e=ip(this.declaration)[0];if(e instanceof V){let t=e.callee;if(t instanceof B&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof R,this.declaration}owners(e){let t=this.leftTable(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Lh=class extends Fh{constructor(e){super(e),this.kind=`dep`}container(e){let n=this.declaration.parentOfKind(L);if(n?.isKind(r.Table))return e.nodeSymbol(n).getFiltered(t)}edgeExpressions(){return this.declaration instanceof L?ip(this.declaration).filter(e=>e instanceof V).map(e=>e.callee).filter(e=>e instanceof B):[]}upstreamColumns(e){if(this.declaration instanceof L)return this.edgeExpressions().map(t=>Kh(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof R){let t=this.declaration.value;if(!(t instanceof z))return[];let n=t.op?.value,r=this.hostColumn(e),i=Kh(e,t.expression);if(n===`->`)return[r?[r]:[]];if(n===`<-`)return[i]}return[]}downstreamColumns(e){if(this.declaration instanceof L)return this.edgeExpressions().map(t=>Kh(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof R){let t=this.declaration.value;if(!(t instanceof z))return[];let n=t.op?.value,r=this.hostColumn(e),i=Kh(e,t.expression);if(n===`->`)return[i];if(n===`<-`)return[r?[r]:[]]}return[]}upstreamTables(e){if(this.declaration instanceof L)return this.edgeExpressions().map(t=>Jh(e,t.op?.value===`<-`?t.rightExpression:t.leftExpression));if(this.declaration instanceof R){let t=this.declaration.value;if(!(t instanceof z))return[];let n=t.op?.value,r=Jh(e,t.expression);if(n===`->`)return[this.container(e)];if(n===`<-`)return[r]}return[]}downstreamTables(e){if(this.declaration instanceof L)return this.edgeExpressions().map(t=>Jh(e,t.op?.value===`<-`?t.leftExpression:t.rightExpression));if(this.declaration instanceof R){let t=this.declaration.value;if(!(t instanceof z))return[];let n=t.op?.value,r=Jh(e,t.expression);if(n===`->`)return[r];if(n===`<-`)return[this.container(e)]}return[]}hostColumn(e){if(!(this.declaration instanceof R))return;let n=this.declaration.parentOfKind(V);if(n)return e.nodeSymbol(n).getFiltered(t)}owners(e){let n=this.upstreamTables(e),r=this.downstreamTables(e),i=[...n,...r].filter(e=>!!e);if(i.length===0)return[];let a=this.declaration.filepath;return e.reachableFiles().flatMap(n=>e.nodeSymbol(e.parseFile(n).getValue().ast).getFiltered(t)||[]).filter(t=>e.reachableFiles(t.filepath).some(e=>e.equals(a))&&i.every(n=>t.inNestedSchema(e,n)))}},Rh=class extends Fh{constructor(e){super(e),this.kind=`partial ref`}container(e){let n=this.declaration.parentOfKind(L);if(n?.isKind(r.TablePartial))return e.nodeSymbol(n).getFiltered(t)}leftColumns(e){if(!(this.declaration instanceof R))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 R))return[];let t=this.declaration.value;return t instanceof z?Kh(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof R)return this.container(e)}rightTable(e){if(!(this.declaration instanceof R))return;let t=this.declaration.value;if(t instanceof z)return qh(e,t.expression)??this.container(e)}op(e){return this.opToken()?.value}opToken(){if(!(this.declaration instanceof R))return;let e=this.declaration.value;if(e instanceof z)return e.op}cardinalities(e){let t=this.op(e);return t?of(t):void 0}leftToken(){if(this.declaration instanceof R){let e=this.declaration.parentOfKind(V);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof R,this.declaration}owners(e){let t=this.leftTablePartial(e),n=this.rightTable(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},zh=class extends Fh{constructor(e){super(e),this.kind=`table checks`,this.ownerTable=e.parentNode?.parentOfKind(L)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Bh=class extends Fh{constructor(e){super(e),this.kind=`indexes`,this.ownerTable=e.parentNode?.parentOfKind(L)}owners(e){if(!this.ownerTable)return[];let n=e.nodeSymbol(this.ownerTable).getFiltered(t);return n?[n.originalSymbol]:[]}},Vh=class extends Fh{constructor(e){super(e),this.kind=`records`}table(e){let n=this.declaration,i=n.parent;if(i instanceof L&&i.isKind(r.Table))return e.nodeSymbol(i).getFiltered(t);let a=n.name;if(!(a instanceof Tm))return;let o=lp(a);if(!o)return;let s=o.variables.at(-1);if(s)return e.nodeReferee(s).getFiltered(t)?.originalSymbol}example(e){return!!e.nodeSettings(this.declaration).getFiltered(t)?.[i.Example]?.length}owners(e){let t=this.table(e);return t?this.resolveOwnerPrograms(e,[t]):[]}},Hh=class extends Fh{constructor(e){super(e),this.kind=`metadata element`}target(e){let n=this.declaration.name;if(!n)return;let r=Qf(n)??n;return e.nodeReferee(r).getFiltered(t)?.originalSymbol}owners(e){let n=this.target(e);if(!n)return[];if(n.kind===P.Column){let r=n.declaration?.parentOfKind(L),i=r?e.nodeSymbol(r).getFiltered(t)?.originalSymbol:void 0;if(!i)return[];n=i}return this.resolveOwnerPrograms(e,[n])}},Uh=class extends Fh{constructor(e){super(e),this.kind=`link`}endpoints(e){let n=bh(this.declaration);if(!n)return[void 0,void 0];let r=n=>{let r=vh(n);return E(r)?e.nodeReferee(r).getFiltered(t)?.originalSymbol:void 0};return[r(n.infix.left),r(n.infix.right)]}owners(e){let[t,n]=this.endpoints(e);return!t||!n?[]:this.resolveOwnerPrograms(e,[t,n])}},Wh=class extends Hh{target(e){if(this.declaration.name)return super.target(e);let t=this.declaration.targetKind?.value;if(t)return Ah(e,this.declaration.filepath,P.Element,t)?.originalSymbol}},Gh=class extends Fh{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 Kh(e,n){if(!n)return[];let r=op(n);return r?(r.tupleElements.length>0?r.tupleElements:r.variables.at(-1)?[r.variables.at(-1)]:[]).flatMap(n=>{let r=e.nodeReferee(n).getFiltered(t);return r?.isKind(P.Column)?[r]:[]}):[]}function qh(e,n){if(!n)return;let r=op(n);if(!r)return;let i=r.tupleElements.length>0?r.variables.at(-1):r.variables.at(-2);if(i)return e.nodeReferee(i).getFiltered(t)}function Jh(e,n){if(!n)return;let r=op(n);if(!r)return;if(r.tupleElements.length>0){let n=r.variables.at(-1);return n?e.nodeReferee(n).getFiltered(t):void 0}let i=r.variables.at(-1);if(i){let n=e.nodeReferee(i).getFiltered(t);if(n?.isKind(P.Table))return n}let a=r.variables.at(-2);if(a)return e.nodeReferee(a).getFiltered(t)}var Yh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},Xh=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=N(e),n=e.callee instanceof xm?e.callee.value?.value??``:``,r,a=e.args.find(e=>e instanceof U);return a&&(r=j(w(a).getValue()[i.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new n([])}},Zh={nodeMetadata(t,i){if(O(i,r.Checks)){let t=i.parent;return!t||!O(t,r.Table)&&!O(t,r.TablePartial)?n.create(e):n.create(new zh(i))}return n.create(e)},bindNode(t,i){return O(i,r.Checks)?n.create(void 0,new Yh(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Ph.TableChecks?r.declaration instanceof L?new Xh(t,r.declaration).interpret():n.create(void 0):n.create(e)}},Qh=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof I)&&!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]=g(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[e.callee,...e.args].flatMap(Vm).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors())),n=this.checkColumnSelfLoop(e.callee);return t.concat(n)})}checkColumnSelfLoop(e){if(!(e instanceof B)||this.endpointLevel(e.leftExpression)!==`column`||this.endpointLevel(e.rightExpression)!==`column`)return[];let t=this.endpointSymbol(e.leftExpression),n=this.endpointSymbol(e.rightExpression);return t&&n&&t===n?[new C(S.DEP_SELF_LOOP,`A column cannot depend on itself`,e)]:[]}endpointSymbol(e){if(!e)return;let n=op(e);if(!n)return;let r=n.variables.at(-1);if(r)return this.compiler.nodeReferee(r).getFiltered(t)}endpointLevel(e){if(!e)return;let n=op(e);if(!n)return;if(n.tupleElements.length>0)return`column`;let r=n.variables.at(-1);if(!r)return;let i=this.compiler.nodeReferee(r).getFiltered(t);if(i?.isKind(P.Column))return`column`;if(i?.isKind(P.Table))return`table`}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},$h=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.dep={}}interpret(){this.dep.token=N(this.declarationNode);let e=[...this.interpretName(),...this.interpretEdges(),...this.interpretSettings()];return n.create(this.dep,e)}interpretName(){if(!(this.declarationNode instanceof L))return this.dep.name=null,this.dep.schemaName=null,[];let e=[],t=this.declarationNode.name?A(this.declarationNode.name)??[]:[];return this.dep.name=t.pop()||null,t.length>1&&e.push(new C(S.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.dep.schemaName=t.join(`.`)||null,e}interpretEdges(){let e=this.metadata.upstreamColumns(this.compiler),t=this.metadata.downstreamColumns(this.compiler),n=this.metadata.upstreamTables(this.compiler),r=this.metadata.downstreamTables(this.compiler),i=[],a=[],o=Math.max(n.length,r.length);for(let a=0;a<o;a++){let o=n[a],s=r[a],c=e[a]??[],l=t[a]??[],u=o?.interpretedName(this.compiler,this.filepath),d=s?.interpretedName(this.compiler,this.filepath);u?.schema,d?.schema,i.push({upstream:{schemaName:u?.schema??null,tableName:u?.name??``,fieldNames:c.map(e=>e.name??``),token:this.dep.token},downstream:{schemaName:d?.schema??null,tableName:d?.name??``,fieldNames:l.map(e=>e.name??``),token:this.dep.token},token:this.dep.token})}return this.dep.edges=i,a}interpretSettings(){let e={};if(this.declarationNode instanceof L){this.declarationNode.attributeList&&this.consumeSettings(this.declarationNode.attributeList,e);let t=this.declarationNode.body;if(t){let n=t instanceof V?[t]:t.body.filter(e=>e instanceof V);for(let t of n){let n=t.args.find(e=>e instanceof U);n&&this.consumeSettings(n,e)}if(!(t instanceof V)){let n=t.body.filter(e=>e instanceof L);for(let t of n){let n=t.type?.value?.toLowerCase();if(!n)continue;let a=t.body;if(t.isKind(r.Note)&&a instanceof H){let e=a.body[0];if(e instanceof V&&e.callee){let n=this.extractAttrValue(e.callee);n!==void 0&&(this.dep.note={value:kp(String(n)),token:N(t)})}continue}if(!(a instanceof V))continue;if(n===i.Color){let e=jp(a.callee);e!==void 0&&(this.dep.color=e);continue}let o=this.extractAttrValue(a.callee);o!==void 0&&(t.isKind(r.Note)?this.dep.note={value:kp(String(o)),token:N(t)}:e[n]=o)}}}}return Object.keys(e).length>0&&(this.dep.metadata=e),[]}consumeSettings(e,t){let n=w(e).getValue();for(let[e,r]of Object.entries(n)){let n=r[0];if(!n)continue;if(e===i.Color){let e=jp(n.value);e!==void 0&&(this.dep.color=e);continue}let a=this.extractAttrValue(n.value);a!==void 0&&(e===i.Note?this.dep.note={value:kp(String(a)),token:N(n)}:t[e]=a)}}extractAttrValue(e){if(e instanceof ym)return tp(e);let t=cp(e);if(t!==null)return t;let n=j(e);return n===void 0?M(e):n}};function eg(e){let t=e.parent;for(;t;){if(t instanceof L&&t.isKind(r.Dep))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var tg={nodeReferee(r,i){if(!E(i)&&!D(i)||!eg(i)||i.parentOfKind(R))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):ng(r,o,i)},nodeMetadata(t,a){if(O(a,r.Dep)){let t=ip(a);return t.length===0||!t.some(e=>e instanceof V&&e.callee instanceof B)?n.create(e):n.create(new Lh(a))}return a instanceof R?!(a.name instanceof ym)||tp(a.name)?.toLowerCase()!==i.Dep?n.create(e):n.create(new Lh(a)):n.create(e)},bindNode(t,i){return O(i,r.Dep)?n.create(void 0,new Qh(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Lh?new $h(t,r,i).interpret():n.create(e)}};function ng(e,r,i){if(!E(i))return new n(void 0);let a=up(i)??``;if(!D(i.parentNode)){let t=Wm(e,r);if(t){let r=e.lookupMembers(t,P.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,P.Table,a);return o?n.create(o):new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=i.parentNode;if(o.rightExpression===i){let r=Hm(e,i);if(r?.isKind(P.Schema)){let t=e.lookupMembers(r,P.Table,a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist in Schema '${r.name}'`,i)])}if(r?.isKind(P.Table)){let o=e.lookupMembers(r,P.Column,a);if(o)return n.create(o);let s=r.declaration?e.nodeFullname(r.declaration).getFiltered(t)?.join(`.`)??r.name:r.name;return new n(void 0,[new C(S.BINDING_ERROR,`Column '${a}' does not exist in Table '${s}'`,i)])}return new n(void 0)}if(o.leftExpression===i){if(D(o.parentNode)&&o.parentNode.leftExpression===o){let t=e.lookupMembers(r,P.Schema,a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=e.lookupMembers(r,P.Schema,a);if(t)return n.create(t);let s=Wm(e,r);if(s){let t=e.lookupMembers(s,P.Table,a);if(t)return n.create(t)}let c=e.lookupMembers(r,P.Table,a);return c?n.create(c):new n(void 0,[new C(S.BINDING_ERROR,`Schema or Table '${a}' does not exist`,i)])}return new n(void 0)}var rg=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]=g(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]=g(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||zf(e.callee)?[]:[e.callee,...e.args].flatMap(Vm).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables.pop();return[...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}))}bindNoteReferences(e){let[t]=g(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||zf(e.callee)?[]:Vm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=g(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||zf(e.callee)?[]:Vm(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=g(e.body,e=>e instanceof V);return t.flatMap(e=>!e.callee||zf(e.callee)?[]:Vm(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},ig=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&&zf(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramViewWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramViewExplicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=g(e.body,e=>e instanceof L),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&&zf(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&&Qf(n.callee),r=e&&this.compiler.nodeReferee(e).getFiltered(t);if(r?.declaration instanceof L){let e=A(r.declaration.name)??[];if(e.length>0){let t=e[e.length-1],n=e.length>1?e.slice(0,-1).join(`.`):v;i.push({name:t,schemaName:n});continue}}let a=A(n.callee)??[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[0]:v;i.push({name:o,schemaName:s})}switch(n){case r.DiagramViewTables:this.diagramView.visibleEntities.tables=i.length>0?i:null;break;case r.DiagramViewNotes:this.diagramView.visibleEntities.stickyNotes=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewTableGroups:this.diagramView.visibleEntities.tableGroups=i.length>0?i.map(e=>({name:e.name})):null;break;case r.DiagramViewSchemas:this.diagramView.visibleEntities.schemas=i.length>0?i.map(e=>({name:e.name})):null;break}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;if(!(!t||!e)){if(t.has(`tables`)||t.has(`schemas`)){e.tables=[],e.tableGroups=[],e.schemas=[];return}t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames())}}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n)return[];let r=this.compiler.symbolMembers(n).getFiltered(t);return r?Fa(r.filter(e=>e.isKind(P.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function ag(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var og={getDuplicateError(e,t,n){return new C(S.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new C(S.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},sg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return O(a,r.DiagramView)?new n(i.symbolFactory.create(Qp,{declaration:a,name:o},a.filepath)):k(a,r.DiagramView)&&a instanceof Dm?new n(i.symbolFactory.create($p,{declaration:a,name:o},a.filepath)):k(a,r.DiagramViewNotes)?new n(i.symbolFactory.create(nm,{declaration:a,name:o},a.filepath)):k(a,r.DiagramViewTables)?new n(i.symbolFactory.create(em,{declaration:a,name:o},a.filepath)):k(a,r.DiagramViewTableGroups)?new n(i.symbolFactory.create(tm,{declaration:a,name:o},a.filepath)):k(a,r.DiagramViewSchemas)?new n(i.symbolFactory.create(rm,{declaration:a,name:o},a.filepath)):n.create(e)},nodeReferee(i,a){if(a.parent&&qf(a))return n.create(e);let o=cg(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)?lg(i,c,a):o.isKind(r.DiagramViewNotes)?ug(i,c,a,P.StickyNote):o.isKind(r.DiagramViewTableGroups)?ug(i,c,a,P.TableGroup):o.isKind(r.DiagramViewSchemas)?dg(i,c,a):n.create(e):n.create(void 0)},symbolMembers(i,a){if(!a.isKind(P.DiagramView))return n.create(e);if(!a.declaration)return n.create([]);let o=a.declaration;if(!O(o,r.DiagramView))return n.create([]);let s=[],c=[];for(let e of ip(o))if(e instanceof V){let n=i.nodeSymbol(e).getFiltered(t);n&&c.push(n)}else e instanceof L&&c.push(...ip(e).flatMap(e=>i.nodeSymbol(e).getFiltered(t)??[]));let l=new Map;for(let e of c){if(!e.isKind(P.DiagramViewSchema,P.DiagramViewTableGroup,P.DiagramViewTable,P.DiagramViewNote)||!e.declaration)continue;let n=(i.nodeFullname(e.declaration).getFiltered(t)||[]).map(Vv).join(`.`),r=`${e.kind}:${n}`;if(n!==void 0){let t=e.declaration,i=l.get(r);i?(s.push(og.getFieldDuplicateError(n,e.kind,i)),s.push(og.getFieldDuplicateError(n,e.kind,t))):l.set(r,t)}}return n.create(c,s)},bindNode(i,a){if(!O(a,r.DiagramView))return n.create(e);let o=new rg(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Qp?r.declaration instanceof L?new ig(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function cg(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 L)||!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 L)||!o.isKind(r.DiagramView)))return i}function lg(e,r,i){let a=up(i);if(a===void 0)return n.create(void 0);if(D(i.parentNode)){let t=Hm(e,i);if(t){if(t.isKind(P.Schema)){let r=$f(i),o=e.lookupMembers(t,r?P.Table:P.Schema,a);return o?n.create(o):new n(void 0,[new C(S.BINDING_ERROR,`Could not find ${r?`table`:`schema`} '${a}'`,i)])}return new n(void 0)}let o=e.lookupMembers(r,P.Schema,a);return o?n.create(o):new n(void 0,[new C(S.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(P.Table)&&a===t)return n.create(e)}let s=e.lookupMembers(r,P.Table,a);return s?n.create(s):new n(void 0,[new C(S.BINDING_ERROR,`Could not find table '${a}'`,i)])}function ug(e,t,r,i){let a=up(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 C(S.BINDING_ERROR,`Could not find ${i===P.StickyNote?`note`:`tablegroup`} '${a}'`,r)])}function dg(e,t,r){let i=up(r);if(i===void 0)return n.create(void 0);let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Could not find schema '${i}'`,r)])}var fg=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 L);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},pg=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=N(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=N(t),n.name=M(t.callee);let r=w(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:kp(j(r.value)),token:N(r)},this.enum.values.push(n),[]})}},mg={getDuplicateError(e,t,n){return new C(S.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new C(S.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},hg={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return O(a,r.Enum)?new n(i.symbolFactory.create(Vp,{declaration:a,name:o},a.filepath)):k(a,r.Enum)?new n(i.symbolFactory.create(Hp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(P.Enum))return n.create(e);let a=i.declaration;if(!(a instanceof L))return new n([]);let o=ip(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(P.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=l.get(t);r?(c.push(mg.getFieldDuplicateError(t,r)),c.push(mg.getFieldDuplicateError(t,n))):l.set(t,n)}}return new n(s,c)},bindNode(i,a){if(!O(a,r.Enum))return n.create(e);let o=new fg(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?new pg(t,r,i).interpret():n.create(e)}},gg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)||!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]=g(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=A(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(Vm).flatMap(e=>e.variables.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=up(e);if(r===void 0)return[];let i=this.compiler.nodeReferee(e);return!i.getValue()||i.hasValue(t)?new C(S.BINDING_ERROR,`No column named '${r}' inside ${this.ownerContainerKind} '${n}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},_g=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=N(e),a=[e.callee,...e.args],o,s,c,l,u;h(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=j(d[i.Name]?.at(0)?.value);let e=d[i.Note]?.at(0);if(e){let t=j(e.value);t!==void 0&&(l={value:t,token:N(e)})}u=M(d[i.Type]?.at(0)?.value)}let f=a.flatMap(e=>{if(!(e instanceof Tm))return e;let t=[],n=e;for(;n instanceof Tm&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of f){let t=sp(e);if(t){for(let e of t.functional)n.push({value:e.value?.value??``,type:`expression`,token:N(e)});for(let e of t.nonFunctional)n.push({value:up(e)??``,type:`column`,token:N(e)})}}return[{columns:n,pk:o,unique:s,name:c,note:l,type:u,token:r}]})):new n([])}},vg={nodeMetadata(t,i){if(!O(i,r.Indexes))return n.create(e);let a=i.parent;return!a||!O(a,r.Table)&&!O(a,r.TablePartial)?n.create(e):n.create(new Bh(i))},nodeReferee(i,a){if(!E(a)||qf(a))return n.create(e);let o=a;for(;o&&!O(o,r.Indexes);)o=o.parent;if(!o)return n.create(e);let s=o.parent;if(!s||!O(s,r.Table)&&!O(s,r.TablePartial))return n.create(e);let c=i.nodeSymbol(s).getFiltered(t);if(!c)return new n(void 0);let l=E(a)?a.expression.variable?.value??``:``,u=i.lookupMembers(c,P.Column,l);if(u)return n.create(u);let d=O(s,r.TablePartial)?`TablePartial`:`Table`;return new n(void 0,[new C(S.BINDING_ERROR,`Column '${l}' does not exist in ${d} 'public.${c.name}'`,a)])},bindNode(t,i){return O(i,r.Indexes)?n.create(void 0,new gg(t,i).bind()):n.create(e)},interpretMetadata(t,r){return r.kind===Ph.Indexes?r.declaration instanceof L?new _g(t,r.declaration).interpret():n.create(void 0):n.create(e)}};function yg(e,n){let r=ap(n);if(!r||r.length===0)return;let i=r[r.length-1];if(i instanceof Sm){let n=[];for(let r of i.elementList){let i=e.nodeReferee(r).getFiltered(t);if(!i)return;n.push(i.originalSymbol)}return n}let a=r[r.length-1];if(!a||a instanceof Sm)return;let o=e.nodeReferee(a).getFiltered(t);if(o)return[o.originalSymbol]}function bg(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 C(S.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new C(S.CIRCULAR_REF,`References with same endpoints exist`,n),new C(S.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var xg=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 L&&e.isKind(r.Project));a.length>1&&a.forEach(t=>e.push(new C(S.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let t of i.body)if(t instanceof L&&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(...Sg(this.compiler,a)),e.push(...this.checkDuplicateRefs()),e.push(...this.checkTableGroups()),new n(void 0,e)}isArchFile(e){return!this.compiler.explicitModules&&this.compiler.parsedFileKind(e)===`arch`}checkDuplicateRefs(){let e=[],n=new Map,i=this.compiler.reachableFiles(this.ast.filepath);for(let a of i){if(this.isArchFile(a))continue;let i=this.compiler.parseFile(a).getFiltered(t);if(!i)continue;let{ast:o}=i;for(let t of o.body){if(!(t instanceof L)||!t.type)continue;let i=t;O(i,r.Ref)&&e.push(...this.checkStandaloneRefs(i,n)),O(i,r.Table)&&e.push(...this.checkInlineRefs(i,n)),O(i,r.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(i))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of ip(e)){if(!(r instanceof V)||!r.callee||!Yf(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=yg(this.compiler,i.leftExpression),o=yg(this.compiler,i.rightExpression);!a||!o||n.push(...bg(a,o,e,t))}return n}checkInlineRefs(e,n){let r=[];for(let a of ip(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 z)||!i.op||!Of(i.op.value)||!i.expression)continue;let a=yg(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];r.push(...bg(o,a,t,n))}}return r}checkTablePartialSelfRefs(e){let n=[];for(let r of ip(e)){if(!(r instanceof V)||!r.callee)continue;let e=M(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 z&&(!r.op||!Of(r.op.value)||r.expression&&E(r.expression)&&r.expression.expression.variable?.value===e&&n.push(new C(S.SAME_ENDPOINT,`Two endpoints are the same`,t)))}}return n}checkTableGroups(){let e=[],n=new Map,i=this.compiler.reachableFiles(this.ast.filepath);for(let a of i){if(this.isArchFile(a))continue;let i=this.compiler.parseFile(a).getFiltered(t);if(!i)continue;let{ast:o}=i;for(let i of o.body){if(!(i instanceof L)||!i.type)continue;let a=i;if(!O(a,r.TableGroup))continue;let o=a.name?A(a.name):void 0,s=o?o.join(`.`):`<unknown>`,c=ip(a);for(let r of c){if(!(r instanceof V)||!r.callee)continue;let i=ap(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=A(r.callee),n=t?t.join(`.`):`<unknown>`;e.push(new C(S.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 Sg(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 Bp&&a.push(...Sg(e,t,r));return a}function Cg(e,t,n){if(t.isKind(P.Table))e.externals.tables.push(n);else if(t.isKind(P.Enum))e.externals.enums.push(n);else if(t.isKind(P.TableGroup))e.externals.tableGroups.push(n);else if(t.isKind(P.TablePartial))e.externals.tablePartials.push(n);else if(t.isKind(P.StickyNote))e.externals.notes.push(n);else if(t.isKind(P.Kind))(e.externals.kinds??=[]).push(n);else if(t.isKind(P.Element)){let r=lh(t.originalSymbol.declaration);r===`group`?(e.externals.groups??=[]).push(n):r===`note`?(e.externals.noteBoxes??=[]).push(n):(e.externals.nodes??=[]).push(n)}}function wg(e,t){return e>=t.start&&e<t.end}function Tg(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 Eg(e,t){let n=e.getSource(t.filepath);if(n)return n.slice(t.start,t.end).trim()}function Dg(e,t){return t.map(t=>t.qualifiedName(e).join(`.`)).join(`, `)}function Og(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Dg(e,i),c=i.length>1?`Columns (\`${s}\`) are all nullable but operator \`${r}\` requires at least one to be NOT NULL`:`Column \`${s}\` is nullable but operator \`${r}\` requires it to be NOT NULL`,l=Eg(e,a),u=i[0]?.declaration,d=u&&Eg(e,u),f=[`- In ref definition \`${l??r}\`, the operator \`${r}\` requires \`${s}\` to reference an existing row.`,d?`- In column definition \`${d}\`, the column is nullable, which allows rows with no parent.`:`- A nullable column allows rows with no parent.`].join(`
7
+ `);return new vf(S.INVALID_REF_RELATIONSHIP,c,t,{category:gf.RefColumnMismatch,explanation:f,quickFixes:o})}function kg(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Dg(e,i),c=i.length>1?`Columns (\`${s}\`) are NOT NULL but operator \`${r}\` allows them to be optional`:`Column \`${s}\` is NOT NULL but operator \`${r}\` allows it to be optional`,l=Eg(e,a),u=i[0]?.declaration,d=u&&Eg(e,u),f=[`- In ref definition \`${l??r}\`, the operator \`${r}\` marks \`${s}\` as optional.`,d?`- In column definition \`${d}\`, the column is NOT NULL.`:`- The column is NOT NULL.`].join(`
8
+ `);return new vf(S.INVALID_REF_RELATIONSHIP,c,t,{category:gf.RefColumnMismatch,explanation:f,quickFixes:o})}function Ag(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Dg(e,i),c=i.length>1?`Columns (\`${s}\`) have a unique index but operator \`${r}\` allows many`:`Column \`${s}\` is unique but operator \`${r}\` allows many`,l=[`- In ref definition \`${Eg(e,a)??r}\`, the operator \`${r}\` allows many.`,`- \`${s}\` has a unique constraint, so each value can appear at most once.`].join(`
9
+ `);return new vf(S.INVALID_REF_RELATIONSHIP,c,t,{category:gf.RefColumnMismatch,explanation:l,quickFixes:o})}function jg(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Dg(e,i),c=i.length>1?`Columns (\`${s}\`) should have a composite unique index for operator \`${r}\``:`Column \`${s}\` should be unique or primary key for operator \`${r}\``,l=[`- In ref definition \`${Eg(e,a)??r}\`, the operator \`${r}\` implies \`${s}\` has at most one row.`,`- \`${s}\` has no unique or primary key constraint.`].join(`
10
+ `);return new vf(S.INVALID_REF_RELATIONSHIP,c,t,{category:gf.RefColumnMismatch,explanation:l,quickFixes:o})}function Mg(e,t,n,r){let{schema:i,name:a}=r?t.interpretedName(e,r):{schema:t.schema(e),name:t.name??``},o=n.map(e=>{let t=e.name??``;return i?`${i}.${a}.${t}`:`${a}.${t}`});return o.length===1?o[0]:`(${o.join(`, `)})`}function Ng(e,t){return e.length>1?`Composite ${t}`:t}function Pg(e,t){let{colName:n}=t;return new vf(S.INVALID_RECORDS_FIELD,`NULL not allowed for NOT NULL column \`${n}\` without a default value or auto-increment`,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` is marked NOT NULL and has no default value or auto-increment.`})}function Fg(e,t){let{colName:n}=t;return new vf(S.INVALID_RECORDS_FIELD,`Invalid enum value for column \`${n}\``,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` uses an enum type. The value must match one of the defined enum members.`})}function Ig(e,t){let{colName:n,typeName:r}=t;return new vf(S.INVALID_RECORDS_FIELD,`Invalid numeric value for column \`${n}\``,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` has type \`${r}\` which expects a numeric value. Provide a valid integer or decimal.`})}function Lg(e,t){let{colName:n,value:r}=t;return new vf(S.INVALID_RECORDS_FIELD,`Invalid integer value \`${r}\` for column \`${n}\`: expected integer, got decimal`,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` is an integer column and cannot store decimal values.`})}function Rg(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,totalDigits:s}=t;return new vf(S.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds precision: expected at most ${a} total digits, got ${s}`,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${a} total digits. The value \`${i}\` has ${s}.`})}function zg(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,decimalDigits:s}=t;return new vf(S.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds scale: expected at most ${o} decimal digits, got ${s}`,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${o} decimal places. The value \`${i}\` has ${s}.`})}function Bg(e,t){let{colName:n}=t;return new vf(S.INVALID_RECORDS_FIELD,`Invalid boolean value for column \`${n}\``,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` is a boolean column. Use \`true\`/\`false\`, \`1\`/\`0\`, or \`'yes'\`/\`'no'\`.`})}function Vg(e,t){let{colName:n}=t;return new vf(S.INVALID_RECORDS_FIELD,`Invalid datetime value for column \`${n}\``,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` expects a date or time value. Supported formats include \`'YYYY-MM-DD'\`, \`'HH:MM:SS'\`, \`'YYYY-MM-DD HH:MM:SS'\`, \`'MM/DD/YYYY'\`, \`'D MMM YYYY'\`, or \`'MMM D, YYYY'\`.`})}function Hg(e,t){let{colName:n}=t;return new vf(S.INVALID_RECORDS_FIELD,`Invalid string value for column \`${n}\``,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` is a string column. Values must be wrapped in quotes.`})}function Ug(e,t){let{colName:n,typeName:r,typeArg:i,maxLength:a,actualLength:o}=t;return new vf(S.INVALID_RECORDS_FIELD,`String value for column \`${n}\` exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e,{category:gf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${i})\`, limiting values to ${a} bytes in UTF-8 encoding. The provided value uses ${o} bytes.`})}function Wg(e,t,n){let{table:r,columns:i}=n,a=Mg(e,r,i),o=Ng(i,`PK`);return new vf(S.INVALID_RECORDS_FIELD,`NULL in ${o}: \`${a}\` cannot be NULL`,t,{category:gf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key and cannot be NULL.`})}function Gg(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=Mg(e,r,i),s=Ng(i,`PK`);return new vf(S.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:gf.RecordConstraintViolation,explanation:`\`${o}\` is a primary key and must be unique across all rows.`})}function Kg(e,t,n){let{table:r,columns:i}=n,a=Mg(e,r,i),o=Ng(i,`PK`);return new vf(S.INVALID_RECORDS_FIELD,`${o}: Column \`${a}\` is missing from record and has no default value`,t,{category:gf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key with no default or auto-increment, so it must be specified in the records block.`})}function qg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=Mg(e,r,i,s),u=Mg(e,a,o,s);return new vf(S.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` must not be NULL`,t,{category:gf.RecordConstraintViolation,explanation:`\`${l}\` references \`${u}\`, so every row must have a non-null value.`})}function Jg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=Mg(e,r,i,s),u=Mg(e,a,o,s);return new vf(S.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` does not exist in \`${u}\``,t,{category:gf.RecordConstraintViolation,explanation:`\`${l}\` is a foreign key referencing \`${u}\`. Every non-null value in an FK must match an existing row in the referenced column.`})}function Yg(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=Mg(e,r,i),s=Ng(i,`UNIQUE`);return new vf(S.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:gf.RecordConstraintViolation,explanation:`\`${o}\` has a unique constraint, so no two rows can have the same value.`})}function Xg(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function Zg(e,t){return e?`${e}.${t}`:`${v}.${t}`}function Qg(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 $g(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function e_(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 t_(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function n_(e,t){let{token:n}=t;return e.nodeAtPosition(n.filepath,n.start.offset)??e.parse.ast(n.filepath)}function r_(e,t,n,r){return ka(r.values)?[]:Sa(c_(t,e),i=>i_(e,t,n,i,r))}function i_(e,t,n,r,i){let a=Xg(i),o=s_(e,t,n,r,i);if(!ka(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=g(a,t=>$g(e,t,s)),u=a_(e,t,s,c),d=r.some(t=>t.increment(e))?[]:o_(e,t,r,l);return[...u,...d]}function a_(e,t,n,r){if(ka(r))return[];let i=n.map(e=>e.name??``);return Sa(r,r=>t_(r,i).map(r=>Wg(e,n_(e,r),{table:t,columns:n})))}function o_(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r,t=>Qg(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=e_(e,r,n);return t_(r,i).map(r=>Gg(e,n_(e,r),{table:t,columns:n,valueStr:a}))}))}function s_(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=fa(a,Array.from(o));if(ka(s))return[];let c=new Set(s),l=r.filter(e=>c.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e));return ka(l)?[]:i.values.map(()=>Kg(e,n,{table:t,columns:l}))}function c_(e,t){let n=e.mergedColumns(t),r=Aa(n,e=>e.name??``);return[...n.filter(e=>e.pk(t)).map(e=>[e]),...e.mergedIndexes(t).flatMap(e=>{let n=t.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.pk).map(e=>$r(e.columns.map(e=>r[e.value]))):[]})]}function l_(e,t,n){if(ka(n.values))return[];let r=Xg(n);return Sa(u_(e,t),n=>d_(e,t,n,r))}function u_(e,t){let n=t.mergedColumns(e),r=Aa(n,e=>e.name??``);return[...n.filter(t=>t.isUniqueSet(e)).map(e=>[e]),...t.mergedIndexes(e).flatMap(t=>{let n=e.interpretMetadata(t,t.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.unique).map(e=>$r(e.columns.map(e=>r[e.value]))):[]})]}function d_(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r.filter(t=>!$g(e,t,n)),t=>Qg(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=e_(e,r,n);return t_(r,i).map(r=>Yg(e,n_(e,r),{table:t,columns:n,valueStr:a}))}))}function f_(e,t,n){let r=new Map;for(let i of e.values()){let{name:e,schema:a}=i.tableSymbol.interpretedName(t,n);r.set(Zg(a,e),i)}return r}function p_(e,t,n,r){let i=f_(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!ka(t.record.values)&&a.add(e);return Sa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(Zg(e.schemaName,e.tableName))):!1),t=>m_(e,t,i,r))}function m_(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(Zg(i.schemaName,i.tableName)),s=n.get(Zg(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=$r(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=$r(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=Qd(i.relation),{min:m,max:ee}=Qd(a.relation),te=p===1&&m===0||p!==`*`&&ee!==`*`,ne=ee===1&&f===0;return[...te?[]:h_(e,o,u,s,d,i.relation,a.relation,r),...ne?[]:h_(e,s,d,o,u,a.relation,i.relation,r)]}function h_(e,t,n,r,i,a,o,s){if(!t.record||ka(t.record.values))return[];let{min:c,max:l}=Qd(a),{min:u,max:d}=Qd(o),f=$r(n.map(e=>e.name));$r(i.map(e=>e.name));let p=u===0,m=Xg(t.record),ee=r.record?Xg(r.record):[],te=new Set(ee.map(t=>Qg(e,t,i))),ne={leftTable:t.tableSymbol,leftColumns:n,rightTable:r.tableSymbol,rightColumns:i,filepath:s};return Sa(m,t=>{if($g(e,t,n)){if(p)return[];let r=e_(e,t,n);return t_(t,f).map(t=>qg(e,n_(e,t),{...ne,valueStr:r}))}if(d===`*`&&c===0&&l===`*`)return[];let r=Qg(e,t,n);if(te.has(r))return[];let i=e_(e,t,n);return t_(t,f).map(t=>Jg(e,n_(e,t),{...ne,valueStr:i}))})}function g_(e){return e instanceof Lh&&e.declaration instanceof L&&e.declaration.body instanceof H}function __(e,t){let n=e.edges??[];if(n.length===0||!g_(t))return[];let r=[],i=Zg(n[0].downstream.schemaName,n[0].downstream.tableName);for(let e=1;e<n.length;e++){let a=Zg(n[e].downstream.schemaName,n[e].downstream.tableName);if(a!==i){r.push(new C(S.DEP_MIXED_DOWNSTREAM_TABLES,`All edges in a Dep block must target the same downstream table, but found '${i}' and '${a}'`,t.declaration));break}}let a=e=>e.upstream.fieldNames.length>0||e.downstream.fieldNames.length>0,o=a(n[0]);for(let e=1;e<n.length;e++)if(a(n[e])!==o){r.push(new C(S.DEP_MIXED_LEVEL,`All edges in a Dep block must be at the same level (all table-level or all column-level)`,t.declaration));break}return r}function v_(e){let t=e.targetKind?.value?.toLowerCase();return Object.values(Lp).find(e=>e.toLowerCase()===t)}function y_(e,t,n){let r=[];return t.length>1&&r.push(...t.map(t=>new C(n.duplicate,`'${e}' can only appear once`,t))),t.forEach(t=>{Rf(t.value)||r.push(new C(n.invalidValue,`Custom setting '${e}' must be a string or a color literal`,t.value||t.name||t))}),r}function b_(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?b_(e,a,n.slice(1)):a}function x_(e,t){if(e.length===0)return[];let n;switch(t){case Lp.Table:n=[...Array(e.length-1).fill(P.Schema),P.Table];break;case Lp.Column:n=e.length===1?[P.Column]:[...Array(e.length-2).fill(P.Schema),P.Table,P.Column];break;case Lp.TableGroup:n=[...Array(e.length-1).fill(P.Schema),P.TableGroup];break;case Lp.Note:n=[...Array(e.length-1).fill(P.Schema),P.StickyNote];break;default:break}return e.map((e,t)=>({name:e,symbolKind:n[t]}))}function S_(e,t){let n=Gm(e,t.filepath);if(!n)return;let r=v_(t),i=A(t.name);if(!i?.length||!r)return;let a=x_(i,r),{name:o,symbolKind:s}=a[0];if(o===`public`&&s===P.Schema){let t=Wm(e,n);if(t)return b_(e,t,a.slice(1))}return b_(e,n,a)}function C_(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 w_(e,n,r,i,a){let o=Gm(e,a);if(!o)return;let s=e.symbolMetadata(r).filter(t=>t.owners(e).includes(o));if(!s.length)return;let c=C_(e,a),l=[...s].sort((e,t)=>{let n=c.get(e.declaration.filepath.intern())??-1,r=c.get(t.declaration.filepath.intern())??-1;return n===r?e.declaration.start-t.declaration.start:n-r}).map(n=>e.interpretMetadata(n,a).getFiltered(t)).filter(e=>!!e);if(!l.length)return;let u={};for(let e of l)for(let[t,{value:n,token:r}]of Object.entries(e))u[t.toLowerCase()]={originalKey:t,value:n,token:r};let d=n.metadata?Object.fromEntries(Object.entries(n.metadata).map(([e,t])=>[e.toLowerCase(),{originalKey:e,value:t}])):{};Object.entries(u).forEach(([e,t])=>{let{originalKey:r,value:a,token:o}=t;i[e]?i[e].assignBuiltinField(n,a,o):d[e]={originalKey:r,value:a}}),n.metadata=Object.fromEntries(Object.values(d).map(e=>[e.originalKey,e.value]))}function T_(e,t,n,r,i){let a=[],o=Gm(e,n);if(!o)return a;let s=C_(e,n),c=e.symbolMetadata(t).filter(t=>t instanceof Wh&&t.owners(e).includes(o)).sort((e,t)=>{let n=s.get(e.declaration.filepath.intern())??-1,r=s.get(t.declaration.filepath.intern())??-1;return n===r?e.declaration.start-t.declaration.start:n-r});for(let e of c){Object.assign(r,N_(e).getValue());let t=e.declaration.name?e.declaration.targetKind?.value:void 0;i&&t&&i.toLowerCase()!==t.toLowerCase()&&a.push(new _f(S.METADATA_KIND_MISMATCH,`${G(e.declaration.name)} is a ${i}, not a ${t}`,e.declaration))}return a}function E_(e){let t=Ch(e);if(!t)return null;let n=wh(t);return n?{value:n,token:N(t)}:null}function D_(e,r,i){let a=r.declaration;if(!(a instanceof L))return new n(void 0);let o=lh(a),s=G(a.name)??``,c=N(a);if(o===`note`)return new n({name:s,alias:null,content:Th(a),token:c});let l=G(a.alias)??null,u=mh(a.attributeList);if(kh(a,u,o===`node`),o===`group`){let o=[];for(let n of hh(a))if(n instanceof V)for(let r of[n.callee,...n.args]){if(!E(r))continue;let n=e.nodeReferee(r).getFiltered(t),i=n&&Nh(n);i!==void 0&&!o.includes(i)&&o.push(i)}let d=T_(e,r,i,u);return new n({name:s,alias:l,children:o,settings:u,note:E_(a),token:c},[],d)}let{type:d,image:f}=O_(u.type),p=k_(u.type,a),m=sh(a),ee=Mh(e,a.filepath,m)??m;return p.push(...T_(e,r,i,u,ee)),new n({name:s,alias:l,kind:ee,type:d,image:f,settings:u,note:E_(a),token:c},[],p)}function O_(e){let t=typeof e==`string`?e.trim():``;return t?Dh.test(t)?{type:null,image:t}:{type:Xm(t)?Jm(t):null,image:null}:{type:null,image:null}}function k_(e,t){let n=typeof e==`string`?e.trim():``;return!n||Dh.test(n)||Xm(n)?[]:/^[a-z]+:/i.test(n)?[new _f(S.BAD_IMAGE,`${Oh} Got: ${n}`,t)]:[new _f(S.UNKNOWN_TYPE,`There is no type called ${n}. ${ah(n)}`,t)]}function A_(e){let t=e.declaration;if(!(t instanceof L))return new n(void 0);let r=mh(t.attributeList),i=typeof r.icon==`string`?r.icon:`box`,a=Dh.test(i)?i:null,o=typeof r.glyph==`string`?r.glyph.split(`;`).map(e=>e.trim()).filter(Boolean):null,s=[];if(typeof r.icon==`string`&&!a&&!Xm(i)){let e=/^[a-z][a-z0-9+.-]*:/i.test(i);s.push(new _f(e?S.BAD_IMAGE:S.UNKNOWN_ICON,e?`${Oh} Got: ${i}`:`There is no icon called ${i}. ${ah(i)}`,t))}return new n({name:G(t.name)??``,icon:!a&&Xm(i)?Jm(i):`box`,glyph:o?.length?o:null,image:a,category:`custom`,color:typeof r.color==`string`?r.color:null,builtin:!1,token:N(t)},[],s)}function j_(){return Object.entries(Zm).map(([e,t])=>({name:e,icon:t.icon,glyph:null,image:null,category:t.category,color:null,builtin:!0,token:null}))}function M_(e,t){let r=bh(t.declaration),[i,a]=t.endpoints(e),o=i&&Nh(i),s=a&&Nh(a);return!r||o===void 0||s===void 0?new n(void 0):new n({from:o,to:s,op:r.infix.op,settings:mh(r.row?.settings??t.declaration.attributeList),token:N(t.declaration)})}function N_(e){let t={},r=new Set;for(let n of hh(e.declaration)){let e=n instanceof L?xh(n):void 0;!e||e.value===void 0||r.has(e.key)||(r.add(e.key),t[e.key]=e.value)}return new n(t)}function P_(e,t){let n=R_(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof R?dp(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof L){let n=z_(e,t);if(n)return{kind:`body`,declaration:n}}}function F_(e,t){let n=R_(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof L){let n=e.body;if(n&&!(n instanceof V))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function I_(e,t,n,r){if(n===null)return L_(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=P_(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return F_(e,i)}function L_(e,t,n){let r=P_(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function R_(e){if(e instanceof V)return e.args.find(e=>e instanceof U);if(e instanceof L){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof V)return t.args.find(e=>e instanceof U)}}function z_(e,t){let n=e.body;if(!(!n||Ef(e)||n instanceof V)){for(let e of n.body)if(e instanceof L&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function B_(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=Qd(l),d=n===`left`?c[1]:c[0],f=Qd(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),ee=n===`left`?t.leftToken():t.rightToken(),te=n===`left`?t.rightToken():t.leftToken(),ne=[];function re(e,t,n){ne.push(n(e));for(let r of t)r.declaration&&r.declaration!==e&&ne.push(n(r.declaration))}let ie=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&ie&&m.length>0&&m.every(t=>t.nullable(e))){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&H_(s,pf(l),d,n,`Make '${r}' optional in the ref`),...i?m.map(t=>U_(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Og(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.min===0&&ie&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&H_(s,mf(l),d,n,`Make '${r}' required in the ref`),...i?m.map(t=>W_(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>kg(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.max===`*`&&G_(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&H_(s,`1`,d,n,`Make '${r}' one in the ref`)].filter(e=>!!e);re(ee,p,n=>Ag(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}if(u.max===1&&!G_(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&H_(s,hf(l),d,n,`Make '${r}' many in the ref`),a&&p.length===1&&K_(p[0],e)].filter(e=>!!e);re(ee,p,n=>jg(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}return ne}function V_(e,t){return[...B_(e,t,`right`,{allowOtherColFix:!1}),...B_(e,t,`left`,{allowOwnColFix:!1})]}function H_(e,t,n,r,i){let a=ff(r===`left`?t:n,r===`right`?t:n);return{title:`${i} (change operator to '${a}')`,shortTitle:`Change to ${a}`,filepath:e.filepath,edits:[{start:e.start,end:e.end,newText:a}],isPreferred:!0}}function U_(e,t){if(!e.declaration||e.pk(t)||e.increment(t)||e.isNotNullSet(t))return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=e.qualifiedName(t).join(`.`),i=L_(e.declaration,`null`,n);if(i)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[i]};let a=F_(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[a]}}function W_(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=L_(e.declaration,`not null`,n);if(r)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as NULL`,shortTitle:`Make nullable`,filepath:e.declaration.filepath,edits:[r]}}function G_(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 sm?r.injectionDeclaration:r.declaration)?.parentOfKind(L);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof Up))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 K_(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=F_(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,shortTitle:`Add unique`,filepath:e.declaration.filepath,edits:[n]}}var q_=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],this.arch={nodes:[],groups:[],noteBoxes:[],links:[],kinds:[],importedKinds:[]},this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],deps:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:N(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.infos.push(...this.validateRecords()),this.finishArch(),new n(this.db,this.errors,this.warnings,this.infos)}finishArch(){let e=this.compiler.parsedFileKind(this.filepath)===`arch`,t=new Map;for(let e of this.arch.kinds)t.set(e.name.toLowerCase(),e);for(let e of this.arch.importedKinds)t.has(e.name.toLowerCase())||t.set(e.name.toLowerCase(),e);if(e||this.arch.nodes.length)for(let e of j_())t.has(e.name.toLowerCase())||t.set(e.name.toLowerCase(),e);let n=new Set([...this.arch.nodes,...this.arch.groups,...this.arch.noteBoxes].map(e=>e.alias??e.name)),r=new Map;for(let e of this.arch.groups){let t=e.alias??e.name;for(let i of e.children)n.has(i)&&!r.has(i)&&r.set(i,t)}for(let e of this.arch.groups){let t=e.alias??e.name;e.children=e.children.filter(e=>r.get(e)===t)}let i=new Set;for(let{link:e,declaration:t}of this.arch.links){let n=[e.from,e.to].sort().join(`\0`);i.has(n)&&this.warnings.push(new _f(S.DUPLICATE_LINK,`${e.from} and ${e.to} are already connected`,t)),i.add(n),(r.get(e.from)===e.to||r.get(e.to)===e.from)&&this.warnings.push(new _f(S.NESTED_ENDPOINTS,`${e.from} is already inside ${e.to}`,t))}let a={nodes:this.arch.nodes,groups:this.arch.groups,noteBoxes:this.arch.noteBoxes,links:this.arch.links.map(({link:e})=>e),kinds:[...t.values()]};for(let[t,n]of Object.entries(a))(e||n.length)&&(this.db[t]=n);let o={...this.compiler.scanFile(this.filepath).frontMatter,...e?J_(this.programNode):{}};Object.keys(o).length&&(this.db.frontMatter=o),e&&(this.db.diagramType=`arch`)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof om)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 Bp);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Bp){n.push(t);continue}if(!(t instanceof om))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 Up?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Up?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}]};Cg(this.db,e,o)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],n=new Set,r=new Set,i=new Map;for(let t of e){if(!(t instanceof Vh))continue;let e=t.table(this.compiler);if(!e)continue;let n=e.originalSymbol.intern(),r=i.get(n);r?r.count++:i.set(n,{count:1,tableName:e.name??``})}for(let a of e){let e=this.compiler.interpretMetadata(a,this.filepath);if(e.hasValue(t))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings()),this.infos.push(...e.getInfos());let o=e.getValue();if(o!==void 0)switch(a.kind){case Ph.Ref:{let e=o,[t,r]=e.endpoints??[];if(t&&r){let e=[t.schemaName,t.tableName,t.fieldNames.join(`,`),r.schemaName,r.tableName,r.fieldNames.join(`,`)].join(`|`),i=[r.schemaName,r.tableName,r.fieldNames.join(`,`),t.schemaName,t.tableName,t.fieldNames.join(`,`)].join(`|`);if(n.has(e)||n.has(i)){this.errors.push(new C(S.SAME_ENDPOINT,`Ref with same endpoints already exists`,a.declaration));break}n.add(e)}this.db.refs.push(e);break}case Ph.Dep:{let e=o,t=a instanceof Lh?a.edgeExpressions():[],n=-1;if((e.edges??[]).some((e,t)=>{let{upstream:i,downstream:a}=e,o=[i.schemaName,i.tableName,i.fieldNames.join(`,`),a.schemaName,a.tableName,a.fieldNames.join(`,`)].join(`|`);return r.has(o)?(n=t,!0):(r.add(o),!1)}),n>=0){let e=t[n]??a.declaration;this.errors.push(new C(S.SAME_ENDPOINT,`Dep with same endpoints already exists`,e));break}let i=__(e,a);if(i.length>0){this.errors.push(...i);break}this.db.deps.push(e);break}case Ph.Records:if(a instanceof Vh){let e=a.table(this.compiler)?.originalSymbol.intern()??``,t=e?i.get(e):void 0;if(t&&t.count>1){this.errors.push(new C(S.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,a.declaration));break}}this.db.records.push(o);break;case Ph.Project:this.db.project=o;break;case Ph.Link:this.arch.links.push({link:o,declaration:a.declaration});break;case Ph.MetadataElement:default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof am)||!t.isKind(P.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:Nm.Table,value:{tableName:e,schemaName:n}};this.db.aliases.push(r)}}validateRecords(){let e=[],n=new Map,r=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let e of r){if(!(e instanceof Bp))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(P.Table))continue;let t=e.originalSymbol;if(!(t instanceof Up))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 Vh))continue;let i=r.table(this.compiler);if(!(i instanceof Up))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...r_(this.compiler,i,r.declaration,o)),e.push(...l_(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(...p_(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Rh);for(let t of e)this.infos.push(...V_(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Rh),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 sm&&t.declaration===e.declaration)))continue;let l=of(s);if(!l)continue;let u=a instanceof Xp&&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:N(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:N(i.rightToken())};n.push({token:N(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case P.Element:{let n=lh(e.originalSymbol.declaration);n===`group`?this.arch.groups.push(t):n===`note`?this.arch.noteBoxes.push(t):this.arch.nodes.push(t);break}case P.Kind:e instanceof om?this.arch.importedKinds.push(t):this.arch.kinds.push(t);break;case P.Table:this.db.tables.push(t);break;case P.Enum:this.db.enums.push(t);break;case P.TableGroup:this.db.tableGroups.push(t);break;case P.TablePartial:this.db.tablePartials.push(t);break;case P.StickyNote:this.db.notes.push(t);break;case P.DiagramView:this.db.diagramViews.push(t);break;default:break}}};function J_(e){let t={};for(let n of e.body)if(!(!ch(n)||lh(n)!==`project`))for(let e of hh(n)){let n,r;if(e instanceof L)n=sh(e)?.toLowerCase(),r=G(gh(hh(e)[0])?.callee);else{let t=gh(e);n=G(t?.callee)?.toLowerCase(),r=G(t?.args[0])}!n||n===`diagram_type`||r===void 0||(t[n]=r)}return t}var Y_={nodeSymbol(t,r){return Wf(r)?n.create(t.symbolFactory.create(im,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(P.Program))return n.create(e);if(!(i.declaration instanceof I))return n.create([]);let a=new Map;for(let e of r.reachableFiles(i.filepath)){let{schemaMembers:t}=r.usableMembers(e).getValue();for(let e of t)a.has(e.name)||a.set(e.name,e)}let o=a.get(v);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(P.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Wf(r)?new xg(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof im))return n.create(e);if(!(r.declaration instanceof I))return n.create(void 0);if(!Bm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new q_(t,r,i).interpret()}},X_=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 L);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Z_=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=N(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}=Ap(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?j(e):void 0;return n&&(this.project.note={value:kp(n),token:N(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()]=j(t.body.callee),[]}})}},Q_={nodeMetadata(t,i){return O(i,r.Project)?n.create(new Gh(i)):n.create(e)},bindNode(t,i){return O(i,r.Project)?n.create(void 0,new X_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof Gh)||!(r.declaration instanceof L)?n.create(e):new Z_(t,r.declaration,i).interpret()}},$_=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 I?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=lp(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=np(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=up(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new C(S.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new C(S.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new C(S.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 L)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!If(e))return[];let i=np(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=up(n)??`<unnamed>`;if(!this.compiler.nodeReferee(n).getFiltered(t)){a.push(new C(S.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 L);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof Cm?e.callee.elementList:[e.callee]).flatMap(Vm).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();return!t||!n?[]:[...e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors()),...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}):[]}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},ev=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=tv(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=nv(n,r.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getInfos());let o=a.getValue();o.row&&i.push(o.row)}let a=N(this.element),o=this.metadata.example(this.compiler)||void 0;return new n({schemaName:r.schemaName,tableName:r.tableName,columns:r.columns.map(e=>e.name??``),values:i,example:o,token:a},e,[],t)}};function tv(e,n,i){let a=e.name,o=e.parent;if(o instanceof L&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Up))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===M(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=lp(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,P.Schema,u);e&&(p=n.lookupMembers(e,P.Table,l))}if(p||=n.lookupMembers(f,P.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Up))return;let ee=m.mergedColumns(n),te=s.args.map(e=>ee.find(t=>t.name===M(e))).filter(Boolean),ne=m.interpretedName(n,i);return{schemaName:ne.schema,tableName:ne.name,columns:te}}function nv(e,t,r){let i=[],a=[],o={},s=e.callee instanceof Cm?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new C(S.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new n({row:null,columnNodes:{}},i,[],a);let c=[];for(let e=0;e<t.length;e++){let n=s[e],l=t[e];o[l.name??``]=n;let u=iv(n,l,r);i.push(...u.getErrors()),a.push(...u.getInfos());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:N(n)})}return new n({row:c,columnNodes:o},i,[],a)}function rv(e){return e instanceof xm&&e.value?.value||``}function iv(e,t,r){let i=N(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=Ro(o,s),p=Sp(e),m=p===null?rv(e):p,ee=p===null?`expression`:f;if(e instanceof xm)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(fp(e)||pp(e)&&!Po(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Lo(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[],[Pg(e,{colName:d})]):new n({value:null,type:f,token:i},[],[])}if(s){let a=t.type(r)?.enumSymbol,o=a?a.members(r).filter(e=>e.isKind(P.EnumField)).map(e=>e.name).filter(Boolean):[],s=j(e);return s===void 0&&(s=E(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},[],[],[Fg(e,{colName:d})])}if(Ao(o)||jo(o)||Lo(o)){let t=hp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Ig(e,{colName:d,typeName:o})]);if(Ao(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[],[Lg(e,{colName:d,value:t})]);let r=jo(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(jo(o)&&r){let{precision:a,scale:s}=r,c=t.toString().split(`.`),l=c[0].replace(/^-/,``),u=c[1]||``,p=l.length+u.length,m=u.length;if(p>a)return new n({value:t,type:f,token:i},[],[],[Rg(e,{colName:d,typeName:o,value:t,precision:a,scale:s,totalDigits:p})]);if(m>s)return new n({value:t,type:f,token:i},[],[],[zg(e,{colName:d,typeName:o,value:t,precision:a,scale:s,decimalDigits:m})])}return new n({value:t,type:f,token:i},[],[])}if(No(o)){let t=bp(e);return t===null?new n({value:m,type:ee,token:i},[],[],[Bg(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Io(o)){let t=Ep(e);return t===null?new n({value:m,type:ee,token:i},[],[],[Vg(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Po(o)){let t=Sp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Hg(e,{colName:d})]);let r=a?.args?.length?Number(a.args[0]):void 0;if(r&&!Number.isNaN(r)){let s=r,c=new TextEncoder().encode(t).length;if(c>s)return new n({value:t,type:f,token:i},[],[],[Ug(e,{colName:d,typeName:o,typeArg:String(a.args[0]),maxLength:s,actualLength:c})])}return new n({value:t,type:`string`,token:i},[],[])}return new n({value:m,type:ee,token:i},[],[])}var av={nodeMetadata(t,i){if(!O(i,r.Records))return n.create(e);let a=i.parent;if(a&&O(a,r.Table))return n.create(new Vh(i));let o=i.name;return o instanceof Tm&&o.callee?n.create(new Vh(i)):n.create(e)},nodeReferee(i,a){if(!E(a))return n.create(e);let o=a.parentOfKind(L);if(!o?.isKind(r.Records))return n.create(e);let s=i.parseFile(a.filepath).getValue().ast,c=i.nodeSymbol(s).getFiltered(t);if(!c)return n.create(void 0);let l=a.parentOfKind(Sm);if(l?.parentNode===o)return ov(i,o,a);let u=a.parentOfKind(Tm);return u?.parentNode===o&&l?.parentNode===u?sv(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?cv(i,c,a):uv(i,c,a)},bindNode(t,i){return O(i,r.Records)?n.create(void 0,new $_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Vh?r.declaration instanceof L?new ev(t,r,i).interpret():n.create(void 0):n.create(e)}};function ov(e,i,a){let o=i.parent;if(o instanceof L&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return lv(e,n,a)}return new n(void 0)}function sv(e,r,i){if(r.callee){let n;if(E(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=ap(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return lv(e,n,i)}return new n(void 0)}function cv(e,t,r){if(!E(r))return new n(void 0);let i=up(r)??``;if(!D(r.parentNode)){let a=e.lookupMembers(t,[P.Table,P.Schema],i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Hm(e,r);if(!a){let a=e.lookupMembers(t,[P.Table,P.Schema],i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Table,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function lv(e,t,r){if(!E(r))return new n(void 0);let i=up(r)??``,a=e.lookupMembers(t,P.Column,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function uv(e,t,r){if(!E(r))return new n(void 0);let i=up(r)??``;if(!D(r.parentNode))return new n(void 0);let a=Hm(e,r);if(a){if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Enum,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(P.Enum)){let t=e.lookupMembers(a,P.EnumField,i);return t?n.create(t):new n(void 0,[new C(S.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(D(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,P.Enum,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var dv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof I)&&!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]=g(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Vm).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();return!t||!n?[]:(Array.isArray(t)||(t=[t]),[...e.variables,n,...t].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},fv=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=N(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 L))return[];let e=[],t=A(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new C(S.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if(Ra(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new C(S.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=of(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=N(this.metadata.leftToken()),l=N(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof L?[{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 L))return[];let u=ip(this.declarationNode)[0];if(u.args[0]){let e=w(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof ym?tp(t):M(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof ym?tp(n):M(n),this.ref.color=e.color?.length?jp(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:[...B_(this.compiler,this.metadata,`right`),...B_(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function pv(e){let t=e.parent;for(;t;){if(t instanceof L&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var mv={nodeReferee(r,i){if(!E(i)&&!D(i)||!pv(i)||i.parentOfKind(R))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):hv(r,o,i)},nodeMetadata(t,a){if(O(a,r.Ref)){let t=ip(a)[0];if(!(t instanceof V)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof B)||!r.op?n.create(e):n.create(new Ih(a))}if(a instanceof R){if(!(a.name instanceof ym)||tp(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof L&&t.isKind(r.TablePartial)?n.create(new Rh(a)):n.create(new Ih(a))}return n.create(e)},bindNode(t,i){return O(i,r.Ref)?n.create(void 0,new dv(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Ih?new fv(t,r,i).interpret():n.create(e)}};function hv(e,r,i){if(!E(i))return new n(void 0);let a=up(i)??``;if(!D(i.parentNode)){let r=i.parentNode;if(r&&D(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=D(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(P.Table)){let r=e.lookupMembers(c,P.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 C(S.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Hm(e,i);if(o){if(o.isKind(P.Schema)){let t=e.lookupMembers(o,[P.Table,P.Schema],a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(P.Table)){let r=e.lookupMembers(o,P.Column,a);return r?n.create(r):new n(void 0,[new C(S.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(D(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,P.Schema,a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Wm(e,r);if(t){let r=e.lookupMembers(t,P.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,P.Table,a);return o?n.create(o):new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var gv={visibleName(e,n){let r=n instanceof F?n:n.useSpecifierDeclaration instanceof _m?n.useSpecifierDeclaration:n.declaration;if(r instanceof _m&&n instanceof zp&&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]}},_v={nodeSymbol(r,i){if(!Uf(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===P.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(om,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:gv.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new C(S.BINDING_ERROR,`Failed to resolve the import of ${a} '${(A(i.name)||[]).map(Vv).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof om))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(!E(i)&&!Vf(i))return n.create(e);let a=i.parentOfKind(_m);if(!a)return n.create(e);let o=a.name===i||D(a.name)&&a.name.rightExpression===i?a.getSymbolKind():P.Schema;if(o===void 0)return n.create(void 0);let s=A(i.parentOfKind(B)),c=M(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(gm);if(l?.importPath?.value===void 0)return n.create(void 0);let u=r.layout.resolveFileSpecifier(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new C(S.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new C(S.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toKey()}. Does the file exist?`,i)]);let d=i.parentOfKind(B)?.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 C(S.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=vv(r,u,c,o);return f?n.create(f):n.create(void 0,[new C(S.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toKey()}`,i)])},bindNode(t,r){if(Hf(r)){let e=[];if(r.importPath?.value){let n=t.layout.resolveFileSpecifier(r.filepath,r.importPath.value);(!n||!t.layout.exists(n))&&e.push(new C(S.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath))}if(r.specifiers){let n=t.bindNode(r.specifiers);e.push(...n.getErrors())}return new n(void 0,e)}return r instanceof vm?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):Uf(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 om))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 vv(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(P.Schema))return c;for(let t of o.reuses.selective)if(A(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(gm);if(o?.importPath?.value){let s=vv(e,e.layout.resolveFileSpecifier(n,o.importPath.value),A(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=vv(e,t,r,i,a);if(n)return n}}function yv(e){if(e instanceof ho){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=xv(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof im?Sv(this,e,i):Cv(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 bv(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof _m?gv.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof _m&&r.getSymbolKind()===P.Schema?a:a.length<=1?[v]:a.slice(0,-1);return o.length<i.length||!i.every((e,t)=>e===o[t])?{kind:`none`}:o.length===i.length?{kind:`direct`}:{kind:`child`,schemaName:o[i.length]}}function xv(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let n of r.body){if(!(n instanceof gm)||!n.specifiers||!n.importPath)continue;let r=e.layout.resolveFileSpecifier(t,n.importPath.value);r&&(n.isReuse?n.specifiers instanceof Dm?i.push({importPath:r,node:n.specifiers}):a.push(...n.specifiers.specifiers):n.specifiers instanceof Dm?o.push({importPath:r,node:n.specifiers}):s.push(...n.specifiers.specifiers))}return{ast:r,parseResult:n,selectiveReuses:a,wildcardReuses:i,selectiveUses:s,wildcardUses:o}}function Sv(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[v,e.symbolFactory.create(Bp,{name:v},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?v:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Bp,{name:i},s))}wv(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of Ev(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Bp,{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 Cv(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof L))continue;let i=bv(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(am,{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(Bp,{name:i.schemaName,parent:n},n.filepath))}Tv(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of Dv(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Bp,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function wv(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==P.Schema)continue;let t=gv.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Bp,{name:t},r))}}function Tv(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==P.Schema)continue;let t=gv.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(Bp,{name:o,parent:n},n.filepath))}}function Ev(e,n){let{ast:r}=e.parseFile(n).getValue(),i=[];for(let n of r.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],a=r.length<=1?v:r[0];i.push(a)}let a=xv(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==P.Schema)continue;let n=gv.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function Dv(e,n,r){let{ast:i}=e.parseFile(n).getValue(),a=[];for(let n of i.declarations){let i=e.nodeFullname(n).getFiltered(t)||[],o=i.length<=1?[v]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=xv(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==P.Schema)continue;let n=gv.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var Ov=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){let e=[];return this.declarationNode.attributeList&&e.push(...this.bindHeaderSettings(this.declarationNode.attributeList)),this.declarationNode.body instanceof H&&e.push(...this.bindBody(this.declarationNode.body)),e}bindHeaderSettings(e){return w(e).getValue().dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])??[]}bindInlineDepValue(e){return Vm(e).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=g(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(h(n)instanceof U){let e=w(h(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!Df(e.callee)))}tryToBindColumnType(e){let t=op(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(T(e))return[];if(E(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&_o.includes(t))return[]}let t=op(e);if(!t){if(D(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return Vm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},kv=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??N(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;w_(this.compiler,this.table,this.symbol,jv,this.filepath);let e=this.compiler.symbolMembers(this.symbol).getFiltered(t)??[];for(let t of e){if(!t.isKind(P.Column))continue;let e=this.table.fields.find(e=>e.name===t.name);e&&w_(this.compiler,e,t,Mv,this.filepath)}}interpretName(e){let{name:t,schemaName:n}=Ap(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new C(S.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=up(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=w(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?jp(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:kp(j(n?.value)),token:N(n)},this.table.metadata=Pp(t,Object.keys(jv)),[]}interpretBody(e){let[t,n]=g(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:kp(j(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:N(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:N(e)};i.name=M(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 C(S.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(P.Column)).length?[]:[new C(S.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Df(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=up(e.callee),r.token=N(e);let o=Np(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=Pp(s,Av);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.endpoints?.[0])return[];let s=o.endpoints[0],c=r.op(this.compiler);return c?{schemaName:s.schemaName,tableName:s.tableName,fieldNames:s.fieldNames,relation:c,token:s.token}:[]}),r.inline_deps=(s[i.Dep]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.edges?.[0])return[];let s=e.value;if(!(s instanceof z))return[];let c=s.op?.value;if(c!==`->`&&c!==`<-`)return[];let u=o.edges[0],d=c===`->`?u.downstream:u.upstream;return{schemaName:d.schemaName,tableName:d.tableName,fieldNames:d.fieldNames,direction:c,token:d.token}}),r.checks=(s[i.Check]||[]).map(e=>({token:N(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()}},Av=[i.Note,i.Ref,i.PrimaryKey,i.PK,i.NotNull,i.Null,i.Unique,i.Increment,i.Default,i.Check],jv={[i.Note]:{isValidBuiltinFieldValue:T,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.HeaderColor]:{isValidBuiltinFieldValue:Af,message:`'headercolor' must be a color literal`,assignBuiltinField(e,t){e.headerColor=t}}},Mv={[i.Note]:{isValidBuiltinFieldValue:T,message:`'note' must be a quoted string`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}}},Nv={getDuplicateError(e,t,n){return new C(S.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new C(S.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new C(S.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},Pv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return O(a,r.Table)?new n(i.symbolFactory.create(Up,{declaration:a,name:o},a.filepath)):k(a,r.Table)?Df(a.callee)?new n(i.symbolFactory.create(Zp,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Wp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(P.Table))return n.create(e);let a=i.declaration;if(!(a instanceof L))return new n([]);let o=ip(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(P.Column,P.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof L&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(P.Column)?(c.push(Nv.getColumnDuplicateError(e.name,r)),c.push(Nv.getColumnDuplicateError(e.name,n))):(c.push(Nv.getPartialInjectionDuplicateError(e.name,r)),c.push(Nv.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)||!Df(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=M(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new C(S.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(sm,{kind:P.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(P.Column)&&!(e instanceof sm)).map(e=>e.name));return new n(Fa([...s.filter(e=>!(e instanceof sm&&d.has(e.name)))].reverse(),e=>e.isKind(P.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(Jf(o,i.Dep)&&o.parent instanceof L&&o.parent.isKind(r.Table)&&!Gf(o,r.Table)){let e=a.parseFile(o.filepath).getValue().ast,r=a.nodeSymbol(e).getValue();return r===t?n.create(void 0):Rv(a,r,o)}if(!Gf(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):E(o)&&o.parentNode instanceof z&&o.parentNode.op?.value===`~`?Fv(a,c,o):Kf(o,1)?Iv(a,c,o):Jf(o,i.Ref)?Lv(a,c,o):Jf(o,i.Dep)?Rv(a,c,o):Kf(o,0)?n.create(e):zv(a,c,o)},bindNode(i,a){if(!O(a,r.Table))return n.create(e);let o=new Ov(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 L?new kv(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function Fv(e,r,i){let a=M(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Bp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,P.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,P.TablePartial,a);return s?n.create(s):new n(void 0,[new C(S.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function Iv(e,t,r){if(!E(r))return new n(void 0);let i=up(r)??``;if(!D(r.parentNode))return n.create(e.lookupMembers(t,P.Enum,i));let a=Hm(e,r);if(a){if(a.isKind(P.Schema)){let t=$f(r),o=e.lookupMembers(a,t?P.Enum:P.Schema,i);return o?n.create(o):new n(void 0,[new C(S.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,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Lv(e,i,a){if(!E(a))return new n(void 0);let o=up(a)??``;if(!D(a.parentNode)){let s=a.parent,c=s instanceof L&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,P.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,P.Column,o);return l?n.create(l):new n(void 0,[new C(S.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}return Um(e,i,a,P.Column)}function Rv(e,i,a){if(!E(a))return new n(void 0);let o=Gf(a,r.Table),s=up(a)??``;if(!D(a.parentNode))if(o){let o=a.parent,c=o instanceof L&&o.isKind(r.Table)?e.nodeSymbol(o).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,P.Column,s);if(t)return n.create(t)}let l=e.lookupMembers(i,P.Column,s);return l?n.create(l):new n(void 0,[new C(S.BINDING_ERROR,`Column '${s}' does not exist in Table 'public.${c?.name??``}'`,a)])}else{let t=e.lookupMembers(i,P.Table,s);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table '${s}' does not exist in Schema 'public'`,a)])}return Um(e,i,a,o?P.Column:P.Table)}function zv(e,t,r){if(!E(r))return new n(void 0);let i=up(r)??``;if(!D(r.parentNode))return _o.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,P.Enum,i));let a=Hm(e,r);if(a){if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Enum,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(P.Enum)){let t=e.lookupMembers(a,P.EnumField,i);return t?n.create(t):new n(void 0,[new C(S.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(D(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,P.Enum,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function Bv(e){return e?e.split(``).every(e=>yf(e)||bf(e))&&!bf(e[0]):!1}function Vv(e){return Bv(e)?e:`"${Wv(e)}"`}function Hv(...e){return e.map(Vv).join(`.`)}function Uv(e){let t=``,n=0,r={n:`
11
+ `,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function Wv(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
12
+ `:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function Gv(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`'${Wv(e)}'`;let{value:t,type:n}=e;if(t==null||No(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(No(n)){let e=bp(t);return e===null?`\`${t}\``:e?`true`:`false`}if(Mo(n)){let e=gp(t);return e===null?`\`${t}\``:String(e)}if(Io(n)){let e=Ep(t);return e===null?`\`${t}\``:`'${Wv(e)}'`}let r=Sp(t);return r===null?`\`${t}\``:`'${Wv(r)}'`}function Kv(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?Uv(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function qv(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 Jv(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 Bp&&n.isKind(P.Schema)){let o=e.symbolMembers(n);i.push(...o.getErrors()),a.push(...o.getWarnings()),r.push(...o.getFiltered(t)??[])}}return new n(r,i,a)}function Yv(e){return e.includes(`
13
+ `)?`'''\n${e}\n'''`:`'${Wv(e)}'`}var Xv=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]=g(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Vm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof om?[...r.getErrors(),new C(S.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():[])}},Zv={[i.Note]:{isValidBuiltinFieldValue:T,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.Color]:{isValidBuiltinFieldValue:Af,message:`'color' must be a color literal`,assignBuiltinField(e,t){e.color=t}}},Qv=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=N(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),w_(this.compiler,this.tableGroup,this.symbol,Zv,this.filepath),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=Ap(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new C(S.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name))),this.tableGroup.name=n,this.tableGroup.schemaName=r[0]||null,t}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:kp(j(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:N(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(P.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=A(e.callee);return i.length>2&&n.push(new C(S.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=w(e).getValue();this.tableGroup.color=t.color?.length?jp(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:kp(j(n?.value)),token:N(n)},this.tableGroup.metadata=Pp(t,Object.keys(Zv)),[]}},$v={getDuplicateError(e,t,n){return new C(S.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new C(S.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},ey={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return O(a,r.TableGroup)?new n(i.symbolFactory.create(Gp,{declaration:a,name:s},a.filepath)):k(a,r.TableGroup)?new n(i.symbolFactory.create(Kp,{declaration:a,name:o?.map(Vv).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(P.TableGroup)){let e=i.declaration;if(!(e instanceof L))return new n([]);let a=ip(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(P.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof L&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push($v.getFieldDuplicateError(e.name,r)),s.push($v.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(P.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!E(a)||!Gf(a,r.TableGroup)||a.parent&&qf(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):ty(i,s,a)},bindNode(i,a){if(!O(a,r.TableGroup))return n.create(e);let o=new Xv(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!O(o,r.TableGroup)||!(i instanceof Gp)?n.create(e):Bm(t,o)?new Qv(t,i,a).interpret():n.create(void 0)}};function ty(e,r,i){let a=up(i)??``;if(!D(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Bp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,P.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,P.Table,a);return s?n.create(s):new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Hm(e,i);if(o){if(o.isKind(P.Schema)){let t=e.lookupMembers(o,[P.Table,P.Schema],a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,P.Schema,a);return s?n.create(s):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var ny=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]=g(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(h(n)instanceof U){let e=w(h(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t})}tryToBindColumnType(e){let t=op(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return Vm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];if(n){let r=[],i=e.variables;for(let e of i)r.push(...this.compiler.nodeReferee(e).getErrors());let a=this.compiler.nodeReferee(n);return r.push(...a.getErrors()),a.getValue()&&r.push(...this.compiler.nodeReferee(t).getErrors()),r}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},ry=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??N(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}=Ap(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=w(e).getValue(),n=ya(t[i.HeaderColor]);this.tablePartial.headerColor=n?jp(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:kp(j(r?.value)),token:N(r)},[]}interpretBody(e){let[t,n]=g(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:kp(j(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:N(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=up(e.callee)??``,r.token=N(e);let o=Np(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=Pp(s,Av);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 Rh))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:N(n.rightToken())}}),r.inline_deps=[],r.checks=(s[i.Check]||[]).map(e=>({token:N(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()}},iy={getDuplicateError(e,t,n){return new C(S.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},ay={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return O(a,r.TablePartial)?new n(i.symbolFactory.create(Xp,{declaration:a,name:o},a.filepath)):k(a,r.TablePartial)?new n(i.symbolFactory.create(Wp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(P.TablePartial)){let e=a.declaration;if(!(e instanceof L))return new n([]);let r=ip(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(P.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof L&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Nv.getColumnDuplicateError(t,r)),s.push(Nv.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(P.Column)&&O(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!E(o)&&!D(o)||!Gf(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):Kf(o,1)?oy(a,c,o):Jf(o,i.Ref)?sy(a,c,o):cy(a,c,o)},bindNode(i,a){if(!O(a,r.TablePartial))return n.create(e);let o=new ny(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Xp?r.declaration instanceof L?new ry(t,r,i).interpret():n.create(void 0):n.create(e)}};function oy(e,t,r){if(!E(r))return new n(void 0);let i=up(r)??``;if(!D(r.parentNode))return n.create(e.lookupMembers(t,P.Enum,i));let a=Hm(e,r);if(a){if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Enum,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.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,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function sy(e,i,a){if(!E(a))return new n(void 0);let o=up(a)??``;if(!D(a.parentNode)){let s=a.parent;if(s instanceof L&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,P.Column,o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,P.Column,o);return c?n.create(c):new n(void 0,[new C(S.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Hm(e,a);if(s){if(s.isKind(P.Schema)){let t=e.lookupMembers(s,[P.Table,P.Schema],o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(P.Table)){let t=e.lookupMembers(s,P.Column,o);return t?n.create(t):new n(void 0,[new C(S.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(D(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,P.Schema,o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,P.Table,o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function cy(e,t,r){if(!E(r))return new n(void 0);let i=up(r)??``;if(!D(r.parentNode))return _o.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,P.Enum,i));let a=Hm(e,r);if(a){if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Enum,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(P.Enum)){let t=e.lookupMembers(a,P.EnumField,i);return t?n.create(t):new n(void 0,[new C(S.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(D(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,P.Enum,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var ly={symbolMembers(r,i){if(!i.isKind(P.Schema)||!(i instanceof Bp))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=dy(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...fy(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...my(r,i,e,t,c));for(let e of o.uses.selective){let n=dy(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...fy(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...my(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(P.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(P.TableGroup)))}}for(let t of e)u.push(...gy(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof om&&e.isKind(P.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(P.Schema)||e.isKind(P.Kind))continue;let t=e instanceof om?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof L&&e.declaration.name&&!e.isKind(P.Element)?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(uy(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function uy(e,t,n,r){switch(e){case P.Table:return Nv.getDuplicateError(t,n,r);case P.Enum:return mg.getDuplicateError(t,n,r);case P.TablePartial:return iy.getDuplicateError(t,n,r);case P.TableGroup:return $v.getDuplicateError(t,n,r);case P.DiagramView:return og.getDuplicateError(t,n,r);case P.Element:return new C(S.DUPLICATE_NAME,`${t} is already declared`,r);default:return new C(S.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function dy(e,r,i,a){let o=bv(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(Bp,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function fy(e,n,r,i=new Set){if(r.getSymbolKind()!==P.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(P.Schema))return[];let o=gv.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:py(e,n,r,a,i)}function py(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(om,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(P.TableGroup)&&c.push(...gy(e,n,t));for(let i of s.reuses.selective)if(c.push(...fy(e,n,i,a)),bv(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(om,{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=hy(e,t,n.qualifiedName);i&&c.push(...py(e,n,r,i,a))}return c}function my(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=hy(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(om,{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(Bp,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=dy(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...fy(e,n,r))}for(let{importPath:t}of d)l.push(...my(e,n,t,i,a,o));return l}function hy(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 gy(e,n,r){if(!r.isKind(P.TableGroup)||!(r instanceof om))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(P.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=A(n);if(!i||i.length===0)continue;let a=i.length<=1?[v]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=_y(e,c,i);l&&s.push(e.symbolFactory.create(om,{kind:P.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function _y(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(P.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(P.Table)&&e.name===a)}var vy=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 L);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},yy={[i.Color]:{isValidBuiltinFieldValue:jf,message:`'color' must be a color literal or 'none'`,assignBuiltinField(e,t){e.color=t}}},by=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=N(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return w_(this.compiler,this.note,this.symbol,yy,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=w(e).getValue();return t.color?.length&&(this.note.color=jp(t.color.at(0)?.value)),this.note.metadata=Pp(t,Object.keys(yy)),[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof V);return t.length!==1||n.length>0?[new C(S.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=j(e.callee)??``;return this.note.content=kp(t),[]}},xy={nodeSymbol(i,a){return!O(a,r.Note)||!(a.parentNode instanceof I)?n.create(e):new n(i.symbolFactory.create(Yp,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(P.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return O(i,r.Note)?n.create(void 0,new vy(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof Yp?r.declaration instanceof L?new by(t,r,i).interpret():n.create(void 0):n.create(e)}},Sy=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=v_(this.declarationNode);return!A(e)?.length||!t||S_(this.compiler,this.declarationNode)?[]:[new C(S.BINDING_ERROR,`cannot find metadata target element`,e??this.declarationNode)]}bindBody(e){return e instanceof H?e.body.filter(e=>e instanceof L).flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[]):[]}},Cy=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 L))continue;let e=t.type?.value;if(!e)continue;let n=Fp(t.body instanceof V?t.body.callee:void 0);n&&(this.values[e]={value:e===`note`?kp(n):n,token:N(t)})}return[]}},wy={nodeMetadata(t,i){return O(i,r.Metadata)?new n(new Hh(i)):new n(e)},nodeReferee(t,i){if(!E(i))return new n(e);let a=i.parentOfKind(L);return!a||!O(a,r.Metadata)||!a.name?.containsEq(i)?new n(e):!A(a.name)||!v_(a)?new n(void 0):new n(S_(t,a))},bindNode(t,i){return O(i,r.Metadata)?new n(void 0,new Sy(t,i).bind()):new n(e)},interpretMetadata(t,i,a){return i instanceof Hh?O(i.declaration,r.Metadata)?new Cy(t,i,a).interpret():new n(void 0):new n(e)}};function Ty(e,t){let n=e.parentNode;return!(n instanceof V)||!(t.body instanceof H)||n.parentNode!==t.body?!1:n.callee===e||n.args.includes(e)}function Ey(e,t){let n=bh(t);return!!n&&(vh(n.infix.left)===e||vh(n.infix.right)===e)}var Dy=(e,t,n)=>new C(e,`${t} is not declared anywhere`,n);function Oy(e,t,n,r){if(Ah(e,t.filepath,P.Table,n))return new C(S.BINDING_ERROR,`${n} is a table; ${r}`,t)}function ky(e,t,r){let i=G(t);if(i===void 0)return new n(void 0);switch(lh(r)){case`group`:{if(!Ty(t,r))return new n(void 0);let a=Ah(e,t.filepath,P.Element,i),o=a?void 0:Oy(e,t,i,`a group lists elements and groups`);return new n(a,o?[o]:[])}case`link`:{if(!Ey(t,r))return new n(void 0);let a=Ah(e,t.filepath,P.Element,i);return a?new n(a):new n(void 0,[Oy(e,t,i,`a link joins elements`)??Dy(S.UNKNOWN_ENDPOINT,i,r)])}case`metadata`:{if(!r.name?.containsEq(t))return new n(void 0);let a=Ah(e,t.filepath,P.Element,i);return a?new n(a):new n(void 0,[Dy(S.UNKNOWN_METADATA_TARGET,i,r)])}default:return new n(void 0)}}function Ay(e,t){let r=[],i=sh(t);switch(lh(t)){case`node`:G(t.name)!==void 0&&!Mh(e,t.filepath,i)&&r.push(new C(S.UNKNOWN_KIND,`${i} is not a kind. ${eh(i)}`,t));break;case`group`:for(let n of hh(t))if(n instanceof V)for(let t of[n.callee,...n.args])E(t)&&r.push(...e.nodeReferee(t).getErrors());break;case`link`:{let n=bh(t);if(!n)break;for(let t of[n.infix.left,n.infix.right]){let n=vh(t);E(n)&&r.push(...e.nodeReferee(n).getErrors())}break}case`metadata`:if(E(t.name)&&r.push(...e.nodeReferee(t.name).getErrors()),!new Wh(t).target(e)&&!r.length){let e=G(t.name)??t.targetKind?.value??`that`;r.push(Dy(S.UNKNOWN_METADATA_TARGET,e,t))}break;default:break}return new n(void 0,r)}function jy(e,r){if(!r.name)return new n(void 0);let i=e.nodeReferee(r.name),a=[...i.getErrors()],o=i.getFiltered(t)?.originalSymbol,s=r.importKind?.value,c=o?.declaration;if(s&&o?.isKind(P.Element)&&c instanceof L){let t=sh(c),n=lh(c)===`node`?Mh(e,c.filepath,t)??t:t;n.toLowerCase()!==s.toLowerCase()&&a.push(new C(S.BINDING_ERROR,`${dh(c)} is a ${n}, not a ${s}`,r.importKind))}return new n(void 0,a)}var My={nodeSymbol(t,r){if(!ch(r))return n.create(e);switch(lh(r)){case`node`:case`group`:case`note`:return new n(t.symbolFactory.create(qp,{declaration:r,name:dh(r)},r.filepath));case`kind`:return new n(t.symbolFactory.create(Jp,{declaration:r,name:G(r.name)},r.filepath));default:return n.create(e)}},symbolMembers(t,r){return r instanceof qp||r instanceof Jp?new n([]):n.create(e)},nodeReferee(t,r){if(!E(r)||r.parentOfKind(_m))return n.create(e);let i=uh(r);return i?ky(t,r,i):n.create(e)},bindNode(t,r){return r instanceof _m&&r.archImport?jy(t,r):ch(r)?Ay(t,r):n.create(e)},nodeMetadata(t,r){if(!ch(r))return n.create(e);switch(lh(r)){case`link`:return new n(new Uh(r));case`metadata`:return new n(new Wh(r));default:return n.create(e)}},interpretSymbol(t,r,i){return r instanceof qp?D_(t,r,i):r instanceof Jp?A_(r):n.create(e)},interpretMetadata(t,r){return r instanceof Uh?M_(t,r):r instanceof Wh?N_(r):n.create(e)}},Ny=[_v,Pv,hg,av,vg,Zh,mv,tg,Q_,ey,ay,xy,wy,ly,sg,Y_],Py=[My,_v,ly,Y_];function Fy(e,t){if(e.explicitModules)return e.explicitModules;let n=t.filepath??t.declaration?.filepath;return n&&e.parsedFileKind(n)===`arch`?Py:Ny}function Iy(t,r,...i){for(let a of Fy(t,i[1])){let t=a[r];if(t){let r=t(...i);if(r instanceof n&&!r.hasValue(e))return r}}return n.create(e)}function Ly(r){let i=Iy(this,`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Ry(r){let i=Iy(this,`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function zy(r){let i=Iy(this,`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function By(r){let i=Iy(this,`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function Vy(r){let i=Iy(this,`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function Hy(r,i){let a=Iy(this,`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function Uy(r,i){let a=Iy(this,`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var Wy=class{constructor(e,t,n={}){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t,this.options=n}scanFrontMatter(){if(!this.options.allowFrontMatter||!this.text.startsWith(`---`))return;let e=this.text[3];if(e!==`
14
+ `&&e!==`\r`)return;let t=this.text.indexOf(`
15
+ ---`,3);if(t===-1)return;let n=this.text.indexOf(`
16
+ `,t+1);for(n===-1&&(n=this.text.length);this.current.offset<n;)this.advance();this.addToken(_.FRONT_MATTER)}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
17
+ `?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,e}peek(e=0){if(!(this.current.offset+e>=this.text.length))return this.text[this.current.offset+e]}check(e){for(let t=0;t<e.length;t+=1)if(e[t]!==this.peek(t))return!1;return!0}match(e){return this.check(e)?(e.split(``).forEach(()=>this.advance()),!0):!1}addToken(e,t=!1){this.tokens.push(this.createToken(e,t))}createToken(e,t=!1){return Ha.create(e,this.filepath,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),t)}lex(){return this.scanTokens(),this.tokens.push(Ha.create(_.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new n(this.tokens,this.errors)}scanTokens(){for(this.scanFrontMatter();!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(_.SPACE);break;case`\r`:break;case`
18
+ `:this.addToken(_.NEWLINE);break;case` `:this.addToken(_.TAB);break;case`,`:this.addToken(_.COMMA);break;case`(`:this.addToken(_.LPAREN);break;case`)`:this.addToken(_.RPAREN);break;case`[`:this.addToken(_.LBRACKET);break;case`]`:this.addToken(_.RBRACKET);break;case`{`:this.addToken(_.LBRACE);break;case`}`:this.addToken(_.RBRACE);break;case`;`:this.addToken(_.SEMICOLON);break;case`:`:this.addToken(_.COLON);break;case`'`:this.match(`''`)?this.multilineStringLiteral():this.singleLineStringLiteral();break;case`"`:this.quotedVariable();break;case"`":this.functionExpression();break;case`#`:this.colorLiteral();break;case`/`:this.match(`/`)?this.singleLineComment():this.match(`*`)?this.multilineComment():this.operator(e);break;case`*`:this.addToken(_.WILDCARD);break;default:if(Ba(e)){this.operator(e);break}if(yf(e)){this.identifier();break}if(bf(e)){this.numericLiteralOrIdentifier();break}this.addToken(_.OP,!0),this.errors.push(new C(S.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(_.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)za(i)?(t.push(i),i.kind===_.NEWLINE&&n&&(n.trailingTrivia=t,e=!0,n=void 0,t=[])):(e?i.leadingTrivia=t:n.trailingTrivia=t,r.push(i),t=[],n=i,e=!1);this.tokens=r}gatherInvalid(){let e,t=[],n=[];for(e=0;e<this.tokens.length&&pm(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];pm(n)?r.trailingInvalid.push(n):(r=n,t.push(n))}this.tokens=t}consumeUntil(e,t,{allowNewline:n,allowEof:r,raw:i,consumeStopSequence:a=!0}){let o=``;for(;!this.isAtEnd()&&(n||!this.check(`
19
+ `))&&!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 C(S.UNEXPECTED_EOF,`EOF reached while parsing`,t));return}if(this.check(`
20
+ `)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new C(S.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(Ha.create(e,this.filepath,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(_.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(_.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(_.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(_.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(_.SINGLE_LINE_COMMENT,`
21
+ `,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(_.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Sf(this.peek());)this.advance();this.addToken(_.IDENTIFIER)}operator(e){switch(e){case`<`:this.peek()===`=`?this.advance():this.peek()===`>`?(this.advance(),this.peek()===`?`&&this.advance()):(this.peek()===`?`||this.peek()===`-`)&&this.advance();break;case`>`:(this.peek()===`=`||this.peek()===`?`)&&this.advance();break;case`-`:(this.peek()===`>`||this.peek()===`?`)&&this.advance();break;case`?`:this.peek()===`-`?(this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`<`?(this.advance(),this.peek()===`>`&&this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`>`&&(this.advance(),this.peek()===`?`&&this.advance());break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(_.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(_.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&&bf(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&bf(this.peek());)this.advance();if(this.isAtEnd()||!Sf(this.peek()))return this.addToken(_.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1&&bf(this.peek()))return this.advance(),this.addToken(_.NUMERIC_LITERAL);if(!t&&!Sf(this.peek()))return this.addToken(_.NUMERIC_LITERAL);if(!t&&!bf(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||Sf(this.peek()));)this.advance();let e=this.createToken(_.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new C(S.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&Sf(this.peek());)this.advance();let e=this.createToken(_.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&Sf(this.peek());)this.advance();this.addToken(_.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(`
23
22
  `)&&this.advance(),``;case`
24
23
  `:return``;case`t`:return` `;case`n`:return`
25
- `;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()||!Of(this.peek()))return this.errors.push(new w(C.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Ha.create(_.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},zS=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),BS=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 h(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case _.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case _.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case _.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case _.RBRACKET:if(this.isWithinListExpressionContext())return 0}}},VS=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}},HS=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new BS,this.useSpecifierList=this.contextStack.withContextDo(zS.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(gm,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof hm&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(_.IDENTIFIER)&&Qa(this.peek()))break;!Ua(this.previous())&&!this.check(_.RBRACE)&&this.logError(this.peek(),C.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(_.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||this.check(_.STRING_LITERAL)||this.check(_.IDENTIFIER)&&Qa(e)||Wa(this.previous(),e))break;G(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===_.EOF?this.logError(e,C.UNEXPECTED_EOF,`Unexpected EOF`):G(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ya(e)||this.check(_.COLON,_.LBRACE,_.LBRACKET))break;G(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COLON,_.LBRACE,_.LBRACKET))break;G(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(zS.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(U,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(_.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||Wa(this.previous(),e))break;G(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(zS.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(Sm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(bm,e);try{this.consume(`Expect an opening parenthesis '('`,_.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(_.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(_.RPAREN);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof 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 ')'`,_.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.RPAREN,_.COMMA))break;G(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(zS.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(W,e);try{this.consume(`Expect an opening bracket '['`,_.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(_.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(_.RBRACKET);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof 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 ']'`,_.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;G(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET,_.COLON))break;G(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;G(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new VS(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===_.EOF}advance(){return this.isAtEnd()?h(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?h(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),C.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(G(this.peek()),this.logError(this.advance(),C.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)G(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(L,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Im(e).forEach(t=>{t instanceof I&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Xa(this.peek())||$a(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof mm&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(mm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===_.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(Tm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof gm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof Tm?`'*'`:`specifier list`;return Qa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(_.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(hm,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,_.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(_.IDENTIFIER,_.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof I&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an element name`);if(Ya(this.peek())){e.asKeyword=this.advance();try{if(!this.check(_.IDENTIFIER,_.QUOTED_STRING))throw this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(Za(e.type))try{this.consume(`Expect a metadata target kind`,_.IDENTIFIER),e.targetKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(_.COLON,_.LBRACE,_.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ya(this.peek())){if(e.as=this.advance(),this.check(_.COLON,_.LBRACE,_.LBRACKET))this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}}try{e.attributeList=this.check(_.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,_.LBRACE,_.COLON))return t();try{if(this.match(_.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof R?(G(t),this.logError(t,C.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,_.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof R?this.errors.push(new w(C.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}expression(){let e={args:[]},t=()=>Mm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(H,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Ga(this.previous())||this.logError(n,C.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ua(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.RBRACKET,_.RPAREN,_.COMMA,_.COLON].includes(e)}commaExpression(){let e=this.check(_.COMMA)?this.nodeFactory.create(Om,{prevToken:this.previous()}):this.normalExpression();if(!this.check(_.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(Om,{prevToken:this.previous()}));break}if(this.check(_.COMMA))t.elementList.push(this.nodeFactory.create(Om,{prevToken:this.previous()}));else try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(xm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(_.COMMA));return this.nodeFactory.create(xm,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ua(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.LBRACE,_.RBRACKET,_.LBRACKET,_.RPAREN,_.LPAREN,_.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===_.LPAREN){let{left:r}=QS(n);if(r<e||Wa(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(Cm,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Cm,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===_.LBRACKET){if(Ga(this.previous()))break;try{t=this.nodeFactory.create(km,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(km,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Va(n)){let r=n,i=QS(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(vm,{expression:t,op:r})}else{let n=JS(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(V,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(V,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Va(this.peek())){let t={};t.op=this.peek();let n=XS(t.op);if(n.right===null)throw this.logError(t.op,C.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Om,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(B,t),e.handlerContext)):e}e=this.nodeFactory.create(B,t)}else if(e=this.extractOperand(),e instanceof Om)throw new $(this.peek(),this.nodeFactory.create(Om,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(_.WILDCARD)?this.wildcardExpression():this.check(_.NUMERIC_LITERAL,_.STRING_LITERAL,_.COLOR_LITERAL,_.QUOTED_STRING,_.IDENTIFIER)?this.primaryExpression():this.check(_.FUNCTION_EXPRESSION)?this.functionExpression():this.check(_.LBRACKET)?this.listExpression():this.check(_.LBRACE)?this.blockExpression():this.check(_.LPAREN)?this.tupleExpression():(this.peek().kind===_.EOF?this.logError(this.peek(),C.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),C.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Om,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,_.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(ym,e),t.handlerContext):t}return this.nodeFactory.create(ym,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(Tm,{token:this.previous()})}canBeField(){return this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.COLON}primaryExpression(){if(this.match(_.COLOR_LITERAL,_.STRING_LITERAL,_.NUMERIC_LITERAL))return this.nodeFactory.create(Dm,{expression:this.nodeFactory.create(wm,{literal:this.previous()})});if(this.match(_.QUOTED_STRING,_.IDENTIFIER))return this.nodeFactory.create(Dm,{expression:this.nodeFactory.create(Em,{variable:this.previous()})});throw this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(_.COLON,_.RBRACKET,_.COMMA)){let t=this.peek();this.logError(t,C.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(_m,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(z,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(_.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(z,e)}attributeValue(){let e;try{e=this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==_.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(_.COLON,_.COMMA,_.RBRACKET);)try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(_m,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(_m,{identifiers:e})}logError(e,t,n){this.errors.push(new w(t,n,e))}},US=e=>({left:e,right:e+1}),WS=e=>({left:null,right:e}),GS=e=>({left:e,right:null}),KS={left:null,right:null},qS={".":US(16),"/":US(11),"%":US(11),"+":US(9),"=":US(2),"==":US(4),"!=":US(4),"-":US(9),"-?":US(9),"?-":US(9),"?-?":US(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`].map(e=>[e,US(7)]))};function JS(e){return qS[e.value]??KS}var YS=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`,`!`,`~`].map(e=>[e,WS(15)]));function XS(e){return YS[e.value]??KS}var ZS={"(":GS(14)};function QS(e){return ZS[e.value]??KS}function $S(e){let t=this.getSource(e);return new RS(t??``,e).lex().chain(n=>new HS(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function eC(){let e=G_(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 tC(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof um?s_.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 nC(e,n,r){let i;if(e instanceof Gp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Gp))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 rC(e){let t=e.originalSymbol;return K_(this).map(n=>n.filter(n=>n instanceof lm&&n.originalSymbol===t&&n!==e))}function iC(){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 Qm){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)}else for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(D(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof bm&&O(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ip(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Im(e))t instanceof I&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Kp&&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 aC(e){return this.resolutionIndex().parents.get(e.intern())??[]}function oC(e){return this.resolutionIndex().references.get(e.intern())??[]}function sC(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function cC(e){let t=e.originalSymbol;return K_(this).map(n=>n.filter(n=>n instanceof um&&n.originalSymbol===t&&n!==e))}function lC(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 uC(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=e.getSource(n)??``;for(let t of e.symbolMetadata(o))if(t instanceof Km&&fC(e,t,r)){if(t.declaration instanceof z){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(H);if(!r)continue;let a=kg(r,i.Ref,s);if(!a)continue;return{kind:`inline`,op:n,fullStart:a.start,fullEnd:a.end}}if(t.declaration instanceof R){let e=up(t.declaration)[0];if(e instanceof H)return{kind:`standalone`,node:e}}}}function dC(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0||t.length===r.length&&t.every((e,t)=>e.name===r[t])}function fC(e,t,n){let r=t.leftTable(e),i=t.leftColumns(e),a=t.rightTable(e),o=t.rightColumns(e),[s,c]=n.endpoints;return dC(r,i,s)&&dC(a,o,c)||dC(r,i,c)&&dC(a,o,s)}function pC(e,t,n){let r=yC(e,t,_C(n.schemaName),n.tableName,F.Table);return{table:r,columns:(n.fieldNames??[]).map(t=>r?e.lookupMembers(r,F.Column,t):void 0)}}function mC(e,t){let n=e?.originalSymbol.declaration;return!!n&&n===t?.originalSymbol.declaration}function hC(e,t,n){return!mC(e,n.table)||t.length!==n.columns.length?!1:t.every((e,t)=>mC(e,n.columns[t]))}function gC(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=pC(e,n,r.upstream),c=pC(e,n,r.downstream);if(!s.table||!c.table)return;let l=e.getSource(n)??``;for(let t of e.symbolMetadata(o)){if(!(t instanceof qm))continue;let n=t.upstreamTables(e),r=t.upstreamColumns(e),a=t.downstreamTables(e),o=t.downstreamColumns(e);if(!n.some((e,t)=>hC(n[t],r[t]??[],s)&&hC(a[t],o[t]??[],c)))continue;if(t.declaration instanceof R)return{kind:`block`,declaration:t.declaration};let u=t.declaration.parentOfKind(H);if(!u)continue;let d=kg(u,i.Dep,l);if(!d)continue;let f=t.declaration.value;if(!(f instanceof B))continue;let p=f.op?.value;if(p)return{kind:`inline`,op:p,fullStart:d.start,fullEnd:d.end}}}function _C(e){return e&&e.length>0?e:v}function vC(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=W_(e);if(t.length===0)return{schema:v,table:``};if(t.length===1)return{schema:v,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function yC(e,n,r,i,a=F.Table){let o=e.parseFile(n).getValue().ast,s=e.nodeSymbol(o).getFiltered(t);if(!s)return;if(r===`public`)return e.lookupMembers(s,a,i)??void 0;let c=e.lookupMembers(s,F.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function bC(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function xC(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(z_(e.schemaName)),t.push(z_(e.tableName));for(let n of e.fieldNames??[])t.push(z_(n));return t.join(`.`)}function SC(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function CC(e,t){if(!e||!(e instanceof R))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function wC(e,t,n){let r=!R_(t),i=!R_(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 TC(e,t,n,r,i,a){return n===i&&r===a?!1:yC(e,t,i,a)!==void 0}function EC(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 bC(n.substring(i,a))===t?{start:i,end:e.end}:null}function DC(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function OC(e,t,n,r,i){let a=[],o=new Set,s=DC(r);for(let r of e){if(bC(i.substring(r.start,r.end))!==n)continue;let e=EC(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 kC(e,n,r){let i=vC(n),a=vC(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=yC(this,e,o,s);if(!u||u instanceof lm||TC(this,e,o,s,c,l))return new Map;if(u instanceof um&&u.useSpecifierDeclaration instanceof hm&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return AC(this,e,n,u,c,l)}return jC(this,u,o,s,c,l)}function AC(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=wC(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,lC(o,c)]])}function jC(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=wC(i,a,CC(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:DC(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 OC([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,lC(r,n))}return m}function MC(e,t,n,r){if(t.kind===`dep`)return FC(this,e,t,n,r);if(t.kind===`ref`)return IC(this,e,t,n,r);let i=PC(this,e,t);if(!i)return[];let a=Og(i,n,r,this.getSource(e)??``);return a?[a]:[]}function NC(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:lC(i,a)}function PC(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case F.Column:{let i=yC(e,t,r,n.table,F.Table);return i?e.lookupMembers(i,F.Column,n.column)?.declaration:void 0}case F.Table:return yC(e,t,r,n.table)?.declaration;case F.Enum:case F.StickyNote:case F.TableGroup:return yC(e,t,r,n.name,n.kind)?.declaration;case F.Schema:return yC(e,t,n.schema,``,F.Schema)?.declaration;default:return}}function FC(e,t,n,r,i){let a=e.getSource(t)??``,o=gC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=xC(n.upstream),t=xC(n.downstream),s=SC(r,i),c=s?`Dep [${s}] {\n ${e} -> ${t}\n}`:`Dep {\n ${e} -> ${t}\n}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
24
+ `;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!Sf(this.peek()))return this.errors.push(new C(S.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`,Ha.create(_.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},Gy=new Set([`arch`,`architecture`]),Ky=e=>!!e&&Gy.has(e.toLowerCase());function qy(e){let t={};for(let n of e.split(`
25
+ `)){let e=n.trim();if(!e||e===`---`)continue;let r=e.indexOf(`:`);if(r<=0)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim().replace(/^['"]|['"]$/g,``);i&&(t[i]=a)}return t}function Jy(e){return e[0]?.leadingTrivia.find(e=>e.kind===_.FRONT_MATTER)}var Yy=new Set([_.LBRACE,_.LBRACKET,_.LPAREN]),Xy=new Set([_.RBRACE,_.RBRACKET,_.RPAREN]);function Zy(e){let t=Jy(e),n={frontMatter:t?qy(t.value):{},topWords:[],kindNames:[],usePaths:[]},r=0,i=-1;for(let t=0;t<e.length;t+=1){let a=e[t];if(a.kind===_.EOF)break;let o=a.startPos.line>i;if(i=a.endPos.line,Yy.has(a.kind)?r+=1:Xy.has(a.kind)&&(r=Math.max(0,r-1)),r!==0||!o||a.kind!==_.IDENTIFIER)continue;let s=a.value.toLowerCase();if(n.topWords.push(s),s===`kind`){let r=e[t+1];(r?.kind===_.IDENTIFIER||r?.kind===_.QUOTED_STRING)&&n.kindNames.push(r.value.toLowerCase())}if(s===`use`||s===`reuse`){let r=0;for(let i=t+1;i<e.length;i+=1){let t=e[i];if(t.kind===_.EOF)break;if(Yy.has(t.kind))r+=1;else if(Xy.has(t.kind))--r;else if(r===0&&t.kind===_.IDENTIFIER&&t.value===`from`){let t=e[i+1];t?.kind===_.STRING_LITERAL&&n.usePaths.push(t.value);break}}}}return n}function Qy(e,t){if(e.frontMatter.diagram_type!==void 0)return{kind:Ky(e.frontMatter.diagram_type)?`arch`:`dbml`,dependsOnImports:!1};if(e.topWords.some(e=>e===`group`||e===`kind`||$m(e)!==void 0))return{kind:`arch`,dependsOnImports:!1};if(e.usePaths.length===0)return{kind:`dbml`,dependsOnImports:!1};let n=new Set(t().flatMap(e=>e.kindNames));return{kind:e.topWords.some(e=>n.has(e))?`arch`:`dbml`,dependsOnImports:!0}}var $y=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 C(S.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof I?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new C(S.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=g(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 h(n)instanceof U&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof xm))&&t.push(new C(S.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=w(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 C(S.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{T(t.value)||n.push(new C(S.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new C(S.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},eb={validateNode(t,i){if(!O(i,r.Checks))return n.create(e);let a=new $y(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return O(i,r.Checks)?i.name?new n(void 0,[new C(S.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Checks)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Checks)?i.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},tb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L&&this.declarationNode.parent.isKind(r.Project,r.Dep)?[]:[new C(S.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project or a Dep`,this.declarationNode)]}validateName(e){return e?[new C(S.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new C(S.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return!(this.declarationNode.parent instanceof L&&this.declarationNode.parent.isKind(r.Dep))&&!T(e.callee)&&t.push(new C(S.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 C(S.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function nb(e){return e instanceof L&&!!e.type?.value}var rb={validateNode(t,r){if(!nb(r))return n.create(e);let i=new tb(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return nb(r)?r.name?new n(void 0,[new C(S.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return nb(r)?r.alias?new n(void 0,[new C(S.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return nb(r)?r.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},ib=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettings(),...this.validateBody(this.declarationNode.body)]}validateSettings(){let e=[];this.declarationNode.attributeList&&e.push(...ab(this.declarationNode.attributeList).getErrors());let t=this.declarationNode.body;if(t instanceof V){let n=t.args.find(e=>e instanceof U);n&&e.push(...ab(n).getErrors())}return e}validateContext(){return this.declarationNode.parent instanceof I?[]:[new C(S.INVALID_DEP_CONTEXT,`A Dep must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Dm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Dep name`,e)]:Tf(e)?[]:[new C(S.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.forEach(e=>{if(!e.callee){t.push(new C(S.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e));return}if(!(e.callee instanceof B)){t.push(new C(S.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e.callee));return}let n=e.callee;n.op?.value!==`->`&&n.op?.value!==`<-`&&t.push(new C(S.INVALID_DEP_FIELD,`Dep edges must use the '->' or '<-' operator`,e.callee));let r=op(n.leftExpression)??{variables:[],tupleElements:[]},i=op(n.rightExpression)??{variables:[],tupleElements:[]};r.variables.length===0&&r.tupleElements.length===0&&t.push(new C(S.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.leftExpression||e.callee)),i.variables.length===0&&i.tupleElements.length===0&&t.push(new C(S.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.rightExpression||e.callee));let a=[...e.args];h(a)instanceof U?a.pop():a[0]instanceof U&&a.shift(),a.length>0&&t.push(...a.map(e=>new C(S.INVALID_DEP_FIELD,`A Dep field should only have a single binary relationship`,e)))}),t}validateSubElements(e){return e.flatMap(e=>{if(!e.type)return[];let t=e.type.value?.toLowerCase(),n=e.body;if(!t)return[];switch(t){case i.Color:return e.name||!(n instanceof V)||!n.callee||!Af(n.callee)?[new C(S.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,e)]:[];case i.Note:{let t;return n instanceof V?t=n.callee:n instanceof H&&n.body[0]instanceof V&&(t=n.body[0].callee),!t||!T(t)?[new C(S.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,e)]:[]}default:return e.name||n instanceof H?[new C(S.INVALID_SETTINGS,`'${t}' must be a simple field (e.g. ${t}: value). Block syntax is not allowed`,e)]:!(n instanceof V)||!n.callee?[]:!T(n.callee)&&!Af(n.callee)&&!Nf(n.callee)&&!Tf(n.callee)?[new C(S.INVALID_SETTINGS,`Invalid value for '${t}'. Expected a string, number, color, or identifier`,e)]:[]}})}};function ab(e){let t=w(e),r=[...t.getErrors()],a=t.getValue();for(let[e,t]of Object.entries(a))for(let n of t)switch(e){case i.Color:Af(n.value)||r.push(new C(S.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,n));break;case i.Note:T(n.value)||r.push(new C(S.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,n));break;default:n.value&&!T(n.value)&&!Af(n.value)&&!Nf(n.value)&&!Tf(n.value)&&r.push(new C(S.INVALID_SETTINGS,`Invalid value for setting '${e}'. Expected a string, number, color, or identifier`,n));break}return new n(a,r)}var ob={validateNode(t,i){return O(i,r.Dep)?n.create(void 0,new ib(t,i).validate()):n.create(e)},nodeFullname(t,i){return O(i,r.Dep)?i.name?Tf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,i.name)]):new n(void 0):k(i,r.Dep)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Dep)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.Dep)?new n(void 0):n.create(e)},nodeSettings(t,i){if(O(i,r.Dep))return i.attributeList?ab(i.attributeList):new n({});if(k(i,r.Dep)){let e=[...i.args],t;return h(e)instanceof U?t=h(e):e[0]instanceof U&&(t=e[0]),t?ab(t):new n({})}return n.create(e)}},sb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList)],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof L?[new C(S.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Tf(e)?[]:[new C(S.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new C(S.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=w(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new C(S.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof V)return{errors:[new C(S.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=g(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=>zf(e.callee)?e.args.length>0?e.args.map(e=>new C(S.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new C(S.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 C(S.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(Ef(e))return t.push(new C(S.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&&zf(e.callee)),a=r.body.some(e=>e instanceof V&&!zf(e.callee));return i&&a&&n.push(new _f(S.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)zf(e.callee)||(e.args.length>0||!A(e.callee))&&t.push(...e.args.map(e=>new C(S.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},cb={validateNode(t,i){if(!O(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new sb(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(O(i,r.DiagramView)){if(!i.name)return new n(void 0,[new C(S.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=A(i.name);return e?new n(e):new n(void 0)}else if(k(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=A(i.callee);return e?(e.length===1&&k(i,r.DiagramViewTables)&&e.unshift(v),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return O(i,r.DiagramView)?new n(void 0):n.create(e)}},lb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L?[new C(S.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Dm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Cf(e)?[]:[new C(S.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new C(S.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.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]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new C(S.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!E(n.callee)&&t.push(new C(S.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];h(e)instanceof U?(t.push(...this.validateFieldSettings(h(e))),e.pop()):e[0]instanceof U&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new C(S.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=w(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 C(S.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{T(e.value)||n.push(new C(S.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new C(S.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():[])}},ub={validateNode(t,i){return O(i,r.Enum)?n.create(void 0,new lb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(O(i,r.Enum)){if(!i.name)return new n(void 0,[new C(S.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Cf(i.name))return new n(void 0,[new C(S.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=A(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(k(i,r.Enum)){let e=M(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return O(i,r.Enum)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(O(a,r.Enum))return a.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(k(a,r.Enum)){let e=[...a.args],t;if(h(e)instanceof U?t=h(e):e[0]instanceof U&&(t=e[0]),!t)return new n({});let r=w(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 C(S.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{T(e.value)||o.push(new C(S.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new C(S.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},db=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new C(S.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof I?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new C(S.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=g(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 h(n)instanceof U&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof Tm;)e.argumentList&&sp(e.argumentList)===void 0&&t.push(new C(S.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;sp(e)===void 0&&t.push(new C(S.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=w(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 C(S.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{T(t.value)||n.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new C(S.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new C(S.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{E(e.value)||n.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new C(S.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},fb={validateNode(t,i){return O(i,r.Indexes)?n.create(void 0,new db(t,i).validate()):n.create(e)},nodeFullname(t,i){return O(i,r.Indexes)?i.name?new n(void 0,[new C(S.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):k(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Indexes)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(O(a,r.Indexes))return a.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(k(a,r.Indexes)){let e=[a.callee,...a.args],t;if(h(e)instanceof U&&(t=h(e)),!t)return new n({});let r=w(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 C(S.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{T(t.value)||o.push(new C(S.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 C(S.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new C(S.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 C(S.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{E(e.value)||o.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new C(S.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},pb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return!(e instanceof I)&&!(e instanceof L&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project,r.Dep))?[new C(S.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 C(S.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof I}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new C(S.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=w(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.Color:{let t=yy[i.Color];e.length>1&&n.push(...e.map(e=>new C(S.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{t.isValidBuiltinFieldValue(e.value)||n.push(new C(S.INVALID_NOTE_SETTING_VALUE,t.message,e.value||e.name))});break}default:n.push(...y_(t,e,{duplicate:S.DUPLICATE_NOTE_SETTING,invalidValue:S.INVALID_NOTE_SETTING_VALUE}))}}),n}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new C(S.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new C(S.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),T(e[0].callee)||t.push(new C(S.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 C(S.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():[])}},mb={validateNode(t,i){return O(i,r.Note)?n.create(void 0,new pb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!O(i,r.Note))return n.create(e);if(!(i.parent instanceof I))return i.name?new n(void 0,[new C(S.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new C(S.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof Dm)return new n(void 0,[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=A(i.name);return a===void 0?new n(void 0,[new C(S.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return O(i,r.Note)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Note)?i.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},hb={[Lp.Table]:jv,[Lp.Column]:Mv,[Lp.TableGroup]:Zv,[Lp.Note]:yy},gb=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 v_(this.declarationNode)?[]:[new C(S.INVALID_METADATA_TARGET_KIND,`A Metadata target kind must be one of: ${Object.values(Lp).join(`, `)}`,this.declarationNode.targetKind??this.declarationNode)]}validateTargetName(e){return e?e instanceof Dm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Metadata target's name`,e)]:Cf(e)?[]:[new C(S.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 C(S.NAME_NOT_FOUND,`A Metadata target must have a name`,this.declarationNode)]}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A Metadata's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.map(e=>new C(S.INVALID_METADATA_FIELD,`A Metadata field must use the 'key: value' syntax`,e))}validateSubElements(e){let t={},n=v_(this.declarationNode),r=e.flatMap(e=>{if(!e.type)return[];if(e.body instanceof H)return[new C(S.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?hb[n][r]:void 0;return i?i.isValidBuiltinFieldValue(e.body?.callee)?[]:[new C(S.INVALID_METADATA_FIELD,i.message,e)]:Rf(e.body?.callee)?[]:[new C(S.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 C(S.DUPLICATE_METADATA_FIELD,`Duplicate Metadata fields are defined`,e)))),r}},_b={validateNode(t,i){return O(i,r.Metadata)?new n(void 0,new gb(t,i).validate()):new n(e)},nodeFullname(t,i){return O(i,r.Metadata)?new n(void 0):new n(e)},nodeAlias(t,i){return O(i,r.Metadata)?new n(void 0):new n(e)},nodeSettings(t,i){return O(i,r.Metadata)?new n({}):new n(e)}},vb=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)}},yb={validateNode(t,r){return Wf(r)?n.create(void 0,new vb(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Wf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Wf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Wf(r)?new n({}):n.create(e)}},bb=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 L?[new C(S.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Tf(e)?new n(A(e)):new n(void 0,[new C(S.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 C(S.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...t.map(e=>new C(S.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():[])}},xb={validateNode(t,i){return O(i,r.Project)?n.create(void 0,new bb(t,i).validate()):n.create(e)},nodeFullname(t,i){return O(i,r.Project)?i.name?Tf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):k(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Project)&&i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):k(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Project)?i.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):k(i,r.Project)?new n({}):n.create(e)}},Sb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return e instanceof I||e instanceof L&&e.isKind(r.Table)?[]:[new C(S.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof Dm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof I?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof Tm))return[new C(S.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||!Cf(e.callee))&&t.push(new C(S.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!If(e.argumentList))&&t.push(new C(S.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!If(e)?[new C(S.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return Cb(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateDataRow(e);let[t,n]=g(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 C(S.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof Cm)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new C(S.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 C(S.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,e.callee));return t}isValidRecordValue(e){if(e instanceof Am||Nf(e)||T(e)||e instanceof xm)return!0;if(E(e)){let t=e.expression.variable.value.toLowerCase();return _o.includes(t)}if(D(e)){let t=A(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function Cb(e){let t=w(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.Example:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_RECORDS_SETTING,`'example' can only appear once`,e))),e.forEach(e=>{e.value&&r.push(new C(S.INVALID_RECORDS_SETTING_VALUE,`'example' cannot have a value`,e))});break;default:r.push(...e.map(e=>new C(S.UNKNOWN_RECORDS_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}var wb={validateNode(t,i){return O(i,r.Records)?n.create(void 0,new Sb(t,i).validate()):n.create(e)},nodeFullname(i,a){if(O(a,r.Records)){if(a.name instanceof Dm)return new n(void 0,[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof I){if(!(a.name instanceof Tm))return new n(void 0,[new C(S.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||!Cf(a.name.callee))&&e.push(new C(S.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 C(S.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=A(a.name.callee);return t?.length===1&&t.unshift(v),new n(t,e)}else{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!If(a.name)?new n(e,[new C(S.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return k(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Records)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):k(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Records)?i.attributeList?Cb(i.attributeList):new n({}):k(i,r.Records)?new n({}):n.create(e)}},Tb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof I?[]:[new C(S.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Dm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:Tf(e)?[]:[new C(S.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.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]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new C(S.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 C(S.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Yf(e.callee)&&t.push(new C(S.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Yf(e.callee)){let n=op(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=op(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new C(S.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new C(S.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Xf(e.callee)&&t.push(new C(S.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(h(n)instanceof U){let e=this.validateFieldSettings(h(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 C(S.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return Db(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function Eb(e){if(!(E(e)&&e.expression.variable.kind!==_.QUOTED_STRING)&&!(e instanceof ym))return!1;let t;if(t=e instanceof ym?tp(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 Db(e){let t=w(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 C(S.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Eb(t.value)||r.push(new C(S.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 C(S.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Af(e.value)||r.push(new C(S.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 C(S.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new C(S.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new C(S.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var Ob={validateNode(t,i){return O(i,r.Ref)?n.create(void 0,new Tb(t,i).validate()):n.create(e)},nodeFullname(t,i){return O(i,r.Ref)?i.name?Tf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):k(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Ref)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(O(i,r.Ref))return i.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(k(i,r.Ref)){let e=[...i.args],t;return h(e)instanceof U?t=h(e):e[0]instanceof U&&(t=e[0]),t?Db(t):new n({})}return n.create(e)}},kb=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L?[new C(S.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof jm?[new C(S.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof Dm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Cf(e)?[]:[new C(S.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new C(S.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?wf(e)?[]:[new C(S.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){return Ab(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=g(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 C(S.INVALID_COLUMN,`A column must have a type`,e.callee)),E(e.callee)||t.push(new C(S.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 C(S.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?(Df(e.callee)||t.push(new C(S.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 C(S.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof z&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){return jb(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 C(S.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Ab(e){let t=w(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{let t=jv[i.HeaderColor];t.isValidBuiltinFieldValue(e.value)||r.push(new C(S.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{let t=jv[i.Note];t.isValidBuiltinFieldValue(e.value)||r.push(new C(S.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Ff(e.value)||r.push(new C(S.INVALID_TABLE_SETTING_VALUE,"'dep' must be `-> target` or `<- source`",e.value||e.name))});break;default:r.push(...y_(t,e,{duplicate:S.DUPLICATE_TABLE_SETTING,invalidValue:S.INVALID_TABLE_SETTING_VALUE}))}}),new n(a,r)}function jb(e){if(!e.slice(0,-1).every(Bf)||!e.slice(-1).every(e=>Bf(e)||e instanceof U))return new n({},e.map(e=>new C(S.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let t;h(e)instanceof U&&(t=e.pop());let r=w(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(M(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{let t=Mv[i.Note];t.isValidBuiltinFieldValue(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Pf(e.value)||a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&a.push(new C(S.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 C(S.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 C(S.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 C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Mf(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'default' must be an enum value, a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof xm||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Ff(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'dep' must be a valid unary relationship`,e.value||e.name))});break;default:a.push(...y_(t,e,{duplicate:S.DUPLICATE_COLUMN_SETTING,invalidValue:S.INVALID_COLUMN_SETTING_VALUE}))}}),new n(o,a)}var Mb={validateNode(t,i){return O(i,r.Table)?n.create(void 0,new kb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(O(i,r.Table)){if(!i.name)return new n(void 0,[new C(S.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof jm)return new n(void 0,[new C(S.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=A(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(k(i,r.Table)){if(Df(i.callee)){let e=M(i.callee.expression);return new n(e?[e]:void 0)}let e=M(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return O(i,r.Table)?i.alias?wf(i.alias)?new n(M(i.alias)):new n(void 0,[new C(S.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):k(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Table)?i.attributeList?Ab(i.attributeList):new n({}):k(i,r.Table)?jb(i.args.slice(1)):n.create(e)}},Nb=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 L?[new C(S.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Dm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:Tf(e)?[]:[new C(S.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new C(S.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){return Pb(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&A(e.callee)===void 0&&t.push(new C(S.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 C(S.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 C(S.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Pb(e){let t=w(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=Zv[e];t.length>1&&r.push(...t.map(t=>new C(S.DUPLICATE_TABLE_SETTING,`'${e}' can only appear once`,t))),t.forEach(e=>{n.isValidBuiltinFieldValue(e.value)||r.push(new C(S.INVALID_TABLE_SETTING_VALUE,n.message,e.value||e.name))}),o[e]=t;break}default:r.push(...y_(e,t,{duplicate:S.DUPLICATE_TABLE_SETTING,invalidValue:S.INVALID_TABLE_SETTING_VALUE})),o[e]=t;break}return new n(o,r)}var Fb={validateNode(t,i){return O(i,r.TableGroup)?n.create(void 0,new Nb(t,i).validate()):n.create(e)},nodeFullname(t,i){if(O(i,r.TableGroup))return i.name?Tf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new C(S.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(k(i,r.TableGroup)){let e=A(i.callee);return e?.length===1&&e.unshift(v),new n(e)}return n.create(e)},nodeAlias(t,i){return O(i,r.TableGroup)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.TableGroup)?Pb(i.attributeList):k(i,r.TableGroup)?new n({}):n.create(e)}},Ib=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L?[new C(S.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Dm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:Tf(e)?[]:[new C(S.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new C(S.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=w(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new C(S.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Af(e.value)||n.push(new C(S.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 C(S.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{T(e.value)||n.push(new C(S.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new C(S.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=g(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 C(S.INVALID_COLUMN,`A column must have a type`,e.callee)),E(e.callee)||t.push(new C(S.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 C(S.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t})}validateFieldSetting(e){let t=h(e);if(!e.slice(0,-1).every(Bf)||!(Bf(t)||t instanceof U))return e.map(e=>new C(S.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;h(e)instanceof U&&(n=e.pop());let r=w(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(M(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{T(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Pf(e.value)||a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&a.push(new C(S.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 C(S.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 C(S.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 C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&a.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Mf(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof xm||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...y_(t,e,{duplicate:S.DUPLICATE_COLUMN_SETTING,invalidValue:S.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 C(S.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Lb(e){let t=w(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Af(e.value)||r.push(new C(S.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 C(S.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{T(e.value)||r.push(new C(S.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new C(S.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function Rb(e){let t=h(e);if(e.length>0&&(!e.slice(0,-1).every(Bf)||!(Bf(t)||t instanceof U)))return new n({},e.map(e=>new C(S.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let r;h(e)instanceof U&&(r=e.pop());let a=w(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(M(e)??``).toLowerCase();if(t!==i.PK&&t!==i.Unique){o.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{T(e.value)||o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Pf(e.value)||o.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&o.push(new C(S.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 C(S.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 C(S.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 C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&o.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof R&&e.value!==void 0&&o.push(new C(S.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 C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Mf(e.value)||o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof xm||o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:o.push(...y_(t,e,{duplicate:S.DUPLICATE_COLUMN_SETTING,invalidValue:S.INVALID_COLUMN_SETTING_VALUE}))}}),new n(s,o)}var zb={validateNode(t,i){return O(i,r.TablePartial)?n.create(void 0,new Ib(t,i).validate()):n.create(e)},nodeFullname(t,i){if(O(i,r.TablePartial))return i.name?Tf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new C(S.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(k(i,r.TablePartial)){let e=M(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return O(i,r.TablePartial)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(M(i.alias)):k(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.TablePartial)?Lb(i.attributeList):k(i,r.TablePartial)?Rb(i.args.slice(1)):n.create(e)}},Bb=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof I?[]:[new C(S.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.specifiers instanceof Dm)return[];for(let t of this.declarationNode.specifiers?.specifiers||[])e.push(...this.validateSpecifier(t));return e}validateSpecifier(e){let t=[];return e.importKind===void 0?t.push(new C(S.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):!e.archImport&&!e.isKind(...Object.values(Ip))&&t.push(new C(S.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()]}},Vb={validateNode(t,r){return r instanceof gm?n.create(void 0,new Bb(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!Uf(r))return n.create(e);let i=A(r.name);return!i||i.length===0?n.create(void 0,[new C(S.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Ip.TableGroup)&&i.length>1?n.create(i,[new C(S.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Ip.TablePartial)&&i.length>1?n.create(i,[new C(S.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Ip.Note)&&i.length>1?n.create(i,[new C(S.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Ip.Schema)&&i.unshift(v),new n(i))},nodeAlias(t,r){return Uf(r)?r.alias?wf(r.alias)?new n(M(r.alias)):new n(void 0,[new C(S.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 gm?n.create({}):n.create(e)}};function Hb(e){let t=[],r=sh(e),i=lh(e);switch(i){case`node`:case`group`:case`note`:if(!G(e.name)){t.push(new C(S.MISSING_NAME,`A ${r} needs a name`,e));break}if(i===`note`)break;for(let n of kh(e,mh(e.attributeList),i===`node`).problems)t.push(new C(n.code===`bad`?S.BAD_PROPERTY:S.DUPLICATE_PROPERTY,n.message,n.node));break;case`kind`:{let n=G(e.name);n&&ih(n)&&t.push(new C(S.RESERVED_KIND,`${n} opens a declaration, so it cannot also be the name of a kind`,e));break}case`link`:{if(!hh(e)[0]){t.push(new C(S.EMPTY_LINK,`A Link needs two endpoints: Link: a > b`,e));break}let n=bh(e);(!n||!G(vh(n.infix.left))||!G(vh(n.infix.right)))&&t.push(new C(S.BAD_LINK,`A Link reads a > b, a < b, a <> b or a - b`,e));break}case`metadata`:{let n=new Set;for(let r of hh(e)){let e=r instanceof L?xh(r):void 0;if(!e||e.value===void 0){t.push(new C(S.BAD_PROPERTY,`A Metadata field must use the 'key: value' syntax`,r));continue}if(n.has(e.key)){t.push(new C(S.DUPLICATE_PROPERTY,`Duplicate Metadata fields are defined`,r));continue}n.add(e.key)}break}case`project`:for(let n of hh(e))(n instanceof L?sh(n):G(gh(n)?.callee))?.toLowerCase()===`diagram_type`&&t.push(new C(S.DIAGRAM_TYPE_NOT_HERE,`diagram_type has no effect inside Project. It says what the DOCUMENT is, and a host reads it before parsing, so it has to be in front matter:
26
+
27
+ ---
28
+ diagram_type: arch
29
+ ---`,n));break;default:break}return new n(void 0,t)}var Ub={validateNode(t,r){return ch(r)?Hb(r):n.create(e)},nodeFullname(t,r){if(!ch(r))return n.create(e);let i=lh(r),a=i===`kind`?G(r.name):i===`node`||i===`group`||i===`note`?dh(r):void 0;return new n(a===void 0?void 0:[a])},nodeAlias(t,r){return ch(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return ch(r)?new n({}):n.create(e)}},Wb=[Mb,ub,wb,fb,eb,Ob,ob,xb,Fb,zb,mb,_b,cb,yb,Vb,rb],Gb=[Ub,yb,Vb];function Kb(t,...r){let[i,a]=r,o=!i.explicitModules&&i.parsedFileKind(a.filepath)===`arch`?Gb:Wb;for(let n of o){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function qb(r){let i=Kb(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function Jb(r){let i=Kb(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function Yb(r){let i=Kb(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function Xb(r){let i=Kb(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var Zb=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Qb(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}),Zb&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function $b(e,t,...n){return Qb(t,n)}var ex=!1,tx=!1,nx=!1,rx=!1,ix=void 0,ax=typeof self==`object`?self:typeof global==`object`?global:{},ox=void 0;ax.vscode!==void 0&&ax.vscode.process!==void 0?ox=ax.vscode.process:typeof process<`u`&&(ox=process);var sx=typeof ox?.versions?.electron==`string`&&ox?.type===`renderer`;if(typeof navigator==`object`&&!sx)ix=navigator.userAgent,ex=ix.indexOf(`Windows`)>=0,tx=ix.indexOf(`Macintosh`)>=0,(ix.indexOf(`Macintosh`)>=0||ix.indexOf(`iPad`)>=0||ix.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,nx=ix.indexOf(`Linux`)>=0,ix?.indexOf(`Mobi`),rx=!0,$b({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof ox==`object`){ex=ox.platform===`win32`,tx=ox.platform===`darwin`,nx=ox.platform===`linux`,nx&&ox.env.SNAP&&ox.env.SNAP_REVISION,ox.env.CI||ox.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=ox.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 cx=ex,lx=tx;rx&&ax.importScripts;var ux=ix,dx=typeof ax.postMessage==`function`&&!ax.importScripts;(()=>{if(dx){let e=[];ax.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}),ax.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var fx=!!(ux&&ux.indexOf(`Chrome`)>=0);ux&&ux.indexOf(`Firefox`),!fx&&ux&&ux.indexOf(`Safari`),ux&&ux.indexOf(`Edg/`),ux&&ux.indexOf(`Android`);var px;if(ax.vscode!==void 0&&ax.vscode.process!==void 0){let e=ax.vscode.process;px={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else px=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 cx?`win32`:lx?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var mx=px.cwd,hx=px.env,gx=px.platform,_x=65,vx=97,yx=90,bx=122,xx=46,Sx=47,Cx=92,wx=58,Tx=63,Ex=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 Dx(e,t){if(typeof e!=`object`||!e)throw new Ex(t,`Object`,e)}function Ox(e,t){if(typeof e!=`string`)throw new Ex(t,`string`,e)}var kx=gx===`win32`;function K(e){return e===Sx||e===Cx}function Ax(e){return e===Sx}function jx(e){return e>=_x&&e<=yx||e>=vx&&e<=bx}function Mx(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=Sx;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==xx||i.charCodeAt(i.length-2)!==xx){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===xx&&s!==-1?++s:s=-1}return i}function Nx(e,t){Dx(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 Px={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],Ox(a,`path`),a.length===0)continue}else t.length===0?a=mx():(a=hx[`=${t}`]||mx(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Cx)&&(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 jx(u)&&a.charCodeAt(1)===wx&&(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=Mx(n,!r,`\\`,K),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){Ox(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return Ax(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 jx(a)&&e.charCodeAt(1)===wx&&(r=e.slice(0,2),n=2,t>2&&K(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?Mx(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){Ox(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return K(n)||t>2&&jx(n)&&e.charCodeAt(1)===wx&&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];Ox(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 Px.normalize(t)},relative(e,t){if(Ox(e,`from`),Ox(t,`to`),e===t)return``;let n=Px.resolve(e),r=Px.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Cx;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Cx;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Cx;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Cx;)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===Cx&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Cx)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Cx?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)===Cx)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Cx&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=Px.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Cx){if(t.charCodeAt(1)===Cx){let e=t.charCodeAt(2);if(e!==Tx&&e!==xx)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(jx(t.charCodeAt(0))&&t.charCodeAt(1)===wx&&t.charCodeAt(2)===Cx)return`\\\\?\\${t}`;return e},dirname(e){Ox(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 jx(i)&&e.charCodeAt(1)===wx&&(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&&Ox(t,`ext`),Ox(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&jx(e.charCodeAt(0))&&e.charCodeAt(1)===wx&&(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){Ox(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===wx&&jx(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===xx?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:Nx.bind(null,`\\`),parse(e){Ox(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(jx(i)&&e.charCodeAt(1)===wx){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===xx?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},Fx=(()=>{if(kx){let e=/\\/g;return()=>{let t=mx().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>mx()})(),Ix={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:Fx();Ox(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Sx)}return t=Mx(t,!n,`/`,Ax),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(Ox(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Sx,n=e.charCodeAt(e.length-1)===Sx;return e=Mx(e,!t,`/`,Ax),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return Ox(e,`path`),e.length>0&&e.charCodeAt(0)===Sx},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];Ox(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:Ix.normalize(t)},relative(e,t){if(Ox(e,`from`),Ox(t,`to`),e===t||(e=Ix.resolve(e),t=Ix.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===Sx&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===Sx)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Sx?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Sx)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(Ox(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Sx,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Sx){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&&Ox(t,`ext`),Ox(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===Sx){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)===Sx){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Ox(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===Sx){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===xx?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:Nx.bind(null,`/`),parse(e){Ox(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Sx,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===Sx){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===xx?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};Ix.win32=Px.win32=Px,Ix.posix=Px.posix=Ix,kx?Px.normalize:Ix.normalize,kx?Px.resolve:Ix.resolve,kx?Px.relative:Ix.relative,kx?Px.dirname:Ix.dirname,kx?Px.basename:Ix.basename,kx?Px.extname:Ix.extname,kx?Px.sep:Ix.sep;var Lx=/^\w[\w\d+.-]*$/,Rx=/^\//,zx=/^\/\//;function Bx(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&&!Lx.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!Rx.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(zx.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 Vx(e,t){return!e&&!t?`file`:e}function Hx(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==Ux&&(t=Ux+t):t=Ux;break}return t}var q=``,Ux=`/`,Wx=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,Gx=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=Vx(e,a),this.authority=t||q,this.path=Hx(this.scheme,n||q),this.query=r||q,this.fragment=i||q,Bx(this,a))}get fsPath(){return Zx(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 qx(t,n,r,i,a)}static parse(e,t=!1){let n=Wx.exec(e);return n?new qx(n[2]||q,tS(n[4]||q),tS(n[5]||q),tS(n[7]||q),tS(n[9]||q),t):new qx(q,q,q,q,q)}static file(e){let t=q;if(cx&&(e=e.replace(/\\/g,Ux)),e[0]===Ux&&e[1]===Ux){let n=e.indexOf(Ux,2);n===-1?(t=e.substring(2),e=Ux):(t=e.substring(2,n),e=e.substring(n)||Ux)}return new qx(`file`,t,e,q,q)}static from(e,t){return new qx(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=cx&&t.scheme===`file`?e.file(Px.join(Zx(t,!0),...n)).path:Ix.join(t.path,...n),t.with({path:r})}toString(e=!1){return Qx(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new qx(t);return e._formatted=t.external??null,e._fsPath=t._sep===Kx?t.fsPath??null:null,e}}},Kx=cx?1:void 0,qx=class extends Gx{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=Zx(this,!1),this._fsPath}toString(e=!1){return e?Qx(this,!0):(this._formatted||=Qx(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=Kx),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}},Jx={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 Yx(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=Jx[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 Xx(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+=Jx[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function Zx(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,cx&&(n=n.replace(/\//g,`\\`)),n}function Qx(e,t){let n=t?Xx:Yx,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=Ux,r+=Ux),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:Yx(c,!1,!1)),r}function $x(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+$x(e.substr(3)):e}}var eS=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function tS(e){return e.match(eS)?e.replace(eS,e=>$x(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}({}),nS=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 rS(e,t){return e.getOffsetAt(t)}function iS(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 aS=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=ho.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=iS(e,n.nodeOrToken);if(!(r.startLineNumber!==t.startLineNumber||r.startColumn!==t.startColumn||r.endLineNumber!==t.endLineNumber||r.endColumn!==t.endColumn))for(let r of n.quickFixes??[]){let n=this.quickFixToCodeAction(r,e,t);n&&o.push(n)}}let s=Fa(o,e=>{let t=e.diagnostics?.[0];return`${e.title}@${t?.startLineNumber}:${t?.startColumn}`});if(s.length)return{actions:s,dispose(){}}}quickFixToCodeAction(e,t,n){let r=ho.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=Gx.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]}}},oS=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=ho.fromUri(String(e.uri)),a=rS(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&&[hm.PRIMARY_EXPRESSION,hm.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=Gx.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[]}},sS=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e),...this.provideInfos(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideInfos(e){return e?this.compiler.interpretFile(e).getInfos().map(e=>this.createDiagnostic(e,`info`)):this.compiler.interpretProject().getInfos().map(e=>this.createDiagnostic(e,`info`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos,a=e.details,o=a?.quickFixes?.filter(e=>e.edits.length>0).map(e=>({title:e.title,shortTitle:e.shortTitle,edits:e.edits.map(e=>({start:e.start,end:e.end,newText:e.newText})),isPreferred:e.isPreferred}));return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code,category:a?.category,explanation:a?.explanation,filepath:e.filepath,quickFixes:o}}getSeverityValue(e){return e===`error`?nS.Error:e===`warning`?nS.Warning:nS.Info}},cS=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=ho.fromUri(String(r)),a=rS(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[hm.ELEMENT_DECLARATION,hm.FUNCTION_APPLICATION,hm.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=Gx.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 lS(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 vm)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=M(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?M(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof Dm&&r.push({name:`*`});r.length===0&&!(e.specifiers instanceof Dm)||n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function uS(e,t,n,r,i,a){let o=lS(e,i),s=r.relativeTo(i.dirname).replace(/\.dbml$/,``),c=o.findIndex(e=>e.sourceFile===s),l=`${n} ${t}`;if(c!==-1){let e=o[c];return e.specifiers.some(e=>e.name===t)?{topInsert:``}:{topInsert:dS(Pa([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
30
+ `),removeRange:fS(a,e.startOffset,e.endOffset)}}return{topInsert:dS([l],s,`
31
+ `)}}function dS(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function fS(e,t,n){let r=e.lastIndexOf(`
32
+ `,t-1)+1,i=n;for(;i<e.length&&(e[i]===` `||e[i]===` `);)i++;return i<e.length&&e[i]===`\r`&&i++,i<e.length&&e[i]===`
33
+ `&&i++,{startOffset:r,endOffset:i}}function pS(e){switch(e){case P.Schema:return J.Module;case P.Table:case P.TablePartial:case P.Metadata:return J.Class;case P.Column:case P.TableGroupField:return J.Field;case P.Enum:return J.Enum;case P.EnumField:return J.EnumMember;case P.TableGroup:return J.Struct;default:return J.Text}}function mS(e,t){if(!e||Ga(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===_.NEWLINE&&n.end<=t)return!1}return!0}function X(){return{suggestions:[]}}function hS(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function gS(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:Vv(e.insertText??``),quoted:!0}))}}function _S(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 vS(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(yS(e,c,t.kind,s,r,o)))}}return i}function yS(e,t,n,r,i,a){let o=uS(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=bS(a,o.removeRange.startOffset),t=bS(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:pS(n),detail:`from ${r.basename}`,sortText:`zzz_${pS(n).toString().padStart(2,`0`)}_${t}`,range:void 0,additionalTextEdits:s}}function bS(e,t){let n=1,r=1;for(let i=0;i<t&&i<e.length;i++)e[i]===`
34
+ `?(n++,r=1):r++;return{line:n,column:r}}function xS(e,t,n,i,a){let o=e.container.element(i,a);return!(o instanceof L)||!o.isKind(r.Records)||!(o.body instanceof H)||!o.body||!wg(a,o.body)||t.getLineContent(n.lineNumber).trim()!==``?null:o.parent instanceof I?SS(e,o):CS(e,o)}function SS(e,n){if(!(n.name instanceof Tm))return X();let r=n.name.argumentList?.elementList||[],i=r.map(n=>e.nodeReferee(n).getFiltered(t));if(!i||i.length===0)return X();let a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Wp||r instanceof sm))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 CS(e,n){let r=n.parent;if(!(r instanceof L))return X();let i=e.nodeSymbol(r).getFiltered(t);if(!(i instanceof Up))return X();let a;if(n.name instanceof Sm){let r=n.name.elementList,i=r.map(n=>e.nodeReferee(n).getFiltered(t)).filter(e=>e!==void 0);a=r.flatMap((t,n)=>{let r=i[n];if(!(r instanceof Wp||r instanceof sm))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 wS(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof gm&&n>=o.start&&n<=o.fullEnd)return TS(e,t,n,o,i,r);return null}function TS(e,t,n,r,i,a){if(r.importPath&&wg(n,r.importPath))return AS(e,t,r.importPath,i,r);if(r.importPath&&n>=r.importPath.end)return X();if(r.fromKeyword&&n>r.fromKeyword.end)return AS(e,t,void 0,i,r);if(r.specifiers instanceof vm){if(!r.specifiers.openBrace){let e=kS();return mS(r.useKeyword,n)?hS(e):e}return ES(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof Dm)return X();let o=kS();return mS(r.useKeyword,n)?hS(o):o}function ES(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!==P.Schema)return OS(e,t,i,n)}return DS()}}return DS()}function DS(){return{suggestions:Object.keys(Ip).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function OS(e,n,r,i){if(!r)return X();let a=e.layout.resolveFileSpecifier(n,r.value);if(!a)return X();let o=e.usableMembers(a).getFiltered(t);if(!o)return X();let s=new Set;for(let n of o.schemaMembers){let r=e.symbolMembers(n).getFiltered(t)??[];for(let e of r){if(e.kind!==i||e instanceof om&&!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:pS(i),range:void 0}))}}function kS(){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 AS(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=iS(r,n);c={startLineNumber:e.startLineNumber,startColumn:e.startColumn+1,endLineNumber:e.endLineNumber,endColumn:e.endColumn-1}}let l=new Map,u=new Map,d=Fa(e.layout.getEntrypoints().flatMap(t=>[...e.reachableFiles(t)]),e=>e.intern());for(let n of d){if(n.equals(t))continue;let r=n.relativeTo(a);if(r.endsWith(`.dbml`)&&(r=r.slice(0,-yo.length)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=ho.resolve(a,d),p=e.layout.isDirectory(f);if(MS(e,n,jS(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 jS(e){let t=e.specifiers;return t instanceof vm?t.specifiers.flatMap(e=>{let t=M(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function MS(e,n,r){if(r.length===0)return!1;let i=e.usableMembers(n).getFiltered(t);return i?r.every(({name:e,kind:t})=>i.nonSchemaMembers.some(n=>n.kind===t&&n.name===e)):!1}var Z={Table:`Table`,TableGroup:`TableGroup`,Enum:`Enum`,Project:`Project`,Ref:`Ref`,Dep:`Dep`,TablePartial:`TablePartial`,Records:`Records`,DiagramView:`DiagramView`,Note:`Note`,Metadata:`Metadata`,Indexes:`indexes`,Checks:`checks`,Tables:`Tables`,TableGroups:`TableGroups`,Notes:`Notes`,Schemas:`Schemas`,Column:`Column`},NS=`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(`.`),PS=[i.HeaderColor,i.Note];PS.map(e=>`${e}: `);var FS=[i.PK,i.PrimaryKey,i.Null,i.NotNull,i.Increment,i.Unique],IS=[i.Ref,i.Dep,i.Default,i.Note,i.Check],LS=[...FS,...IS],RS=[...FS,...IS.map(e=>`${e}: `)],zS=[i.Unique,i.PK],BS=[i.Note,i.Name,i.Type],VS=[...zS,...BS],HS=[...zS,...BS.map(e=>`${e}: `)],US=[i.Inactive],WS=[i.Update,i.Delete,i.Color],GS=[...US,...WS],KS=[...US,...WS.map(e=>`${e}: `)],qS=[i.Note],JS=qS.map(e=>`${e}: `),YS=[i.Name],XS=YS.map(e=>`${e}: `),ZS=[`cascade`,`set default`,`set null`,`restrict`],QS=[`btree`,`hash`],$S=[Z.Note,Z.Indexes,Z.Checks,Z.Records],eC=[Z.Table,Z.TableGroup,Z.Enum,Z.Note,Z.Ref,Z.Dep,Z.TablePartial],tC=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=ho.fromUri(String(e.uri)),i=rS(e,t),a=xS(this.compiler,e,t,n,i);if(a!==null)return a;let o=this.compiler.token.flatStream(n),{token:s,index:c}=this.compiler.container.token(n,i),l=c===void 0?o[0]:o[c+1];if([...s?.trailingTrivia||[],...s?.leadingTrivia||[],...l?.leadingTrivia||[]].find(e=>Ja(e)&&wg(i,e)))return X();if(c===void 0)return gC();let u=wS(this.compiler,n,i,s,e);if(u!==null)return u;if([_.STRING_LITERAL,_.QUOTED_STRING].includes(s.kind)&&wg(i,s))return X();let d=this.compiler.container.element(n,i);if(this.compiler.container.scopeKind(n,i)===Q.TOPLEVEL||d instanceof L&&d.type&&d.type.start<=i&&d.type.end>=i)return gC();let f=[...this.compiler.container.stack(n,i)].reverse();for(let e of f)if(e instanceof z)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return rC(this.compiler,n,i,e);case`~`:return nC(this.compiler,n,i);default:}else if(e instanceof B)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:case`->`:case`<-`:return rC(this.compiler,n,i,e);case`.`:return pC(this.compiler,n,i,e);default:}else if(e instanceof R)return cC(this.compiler,n,i,e);else if(e instanceof U)return cC(this.compiler,n,i,e);else if(e instanceof Sm)return oC(this.compiler,n,i,e);else if(e instanceof Cm)return sC(this.compiler,n,i);else if(e instanceof Tm)return EC(this.compiler,n,i,e);else if(e instanceof V)return mC(this.compiler,n,i,e);else if(e instanceof L){if(Tg(i,e))return O(e,r.Metadata)?wC(this.compiler,n,i,e):TC(this.compiler,n,i,e);if(e.bodyColon&&i>=e.bodyColon.end||e.body&&wg(i,e.body))return mC(this.compiler,n,i,void 0)}return X()}};function nC(e,t,n){return aC(e,t,n,e.parse.ast(t),[P.TablePartial])}function rC(e,t,n,r){let i=e.container.scopeKind(t,n);if([Q.REF,Q.DEP,Q.TABLE,Q.TABLEPARTIAL].includes(i)){let i=aC(e,t,n,e.container.element(t,n),[P.Table,P.Schema,P.Column]);return mS(r.op,n)?hS(i):i}return X()}function iC(e,n,r){let i=e.symbolMembers(n).getFiltered(t);return i?gS({suggestions:i.filter(e=>r.includes(e.kind)).filter(e=>!(e instanceof Bp&&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:pS(e.kind),sortText:pS(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):X()}function aC(e,n,r,i,a){if(i===void 0)return X();let o=i,s={suggestions:[]},c;for(;o;){o instanceof I&&(c=o);let n=e.nodeSymbol(o).getFiltered(t);if(n){let t=iC(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 L?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 vS(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 gS(s)}function oC(e,n,i,a){let o=e.container.scopeKind(n,i),s=e.container.element(n,i),c=[...e.container.stack(n,i)];for(let t of c)if(t instanceof Tm&&t.argumentList===a)return EC(e,n,i,t);if(s instanceof L&&s.isKind(r.Records)&&!(s.name instanceof Tm)&&Tg(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=iC(e,i,[P.Column]);return rp(a)?_S(t):t}}switch(o){case Q.INDEXES:return AC(e,n,i);case Q.REF:case Q.DEP:for(;c.length>0;){let t=c.pop();if(t instanceof B&&t.op?.value===`.`)return pC(e,n,i,t)}return bC(e,n,i);default:break}return X()}function sC(e,t,n){return e.container.scopeKind(t,n)===Q.RECORDS?aC(e,t,n,e.container.element(t,n),[P.Schema,P.Enum,P.EnumField]):X()}function cC(e,t,n,r){let{token:i}=e.container.token(t,n);if([_.COMMA,_.LBRACKET].includes(i?.kind)){let r=lC(e,t,n);return i?.kind===_.COMMA&&mS(i,n)?hS(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return lC(e,t,n);if(r.name instanceof ym){let a=dC(e,t,n,tp(r.name)??``);return i?.kind===_.COLON&&mS(i,n)?hS(a):a}return X()}function lC(e,t,n){let r=e.container.element(t,n);if(r instanceof I)return X();let a=e.container.scopeKind(t,n);if(r.body&&!wg(n,r.body)){let e;switch(a){case Q.TABLE:case Q.TABLEPARTIAL:e=PS;break;case Q.TABLEGROUP:e=[i.Color,i.Note];break;case Q.RECORDS:return{suggestions:[{label:i.Example,insertText:i.Example,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}]};case Q.NOTE:e=[i.Color];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:J.Field,insertTextRules:Y.KeepWhitespace,range:void 0}))}}switch(a){case Q.TABLE:case Q.TABLEPARTIAL:return{suggestions:uC(LS,RS)};case Q.ENUM:return{suggestions:uC(qS,JS)};case Q.INDEXES:return{suggestions:uC(VS,HS)};case Q.REF:return{suggestions:uC(GS,KS)};case Q.DEP:return{suggestions:[i.Note,i.Color].map(e=>({label:e,insertText:`${e}: `,kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))};case Q.CHECKS:return{suggestions:uC(YS,XS)};default:break}return X()}function uC(e,t){return e.map((e,n)=>({label:e,insertText:t[n],kind:J.Property,insertTextRules:Y.KeepWhitespace,range:void 0}))}function dC(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:ZS.map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:QS.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:[vo].map(e=>({label:e,insertText:e,kind:J.Value,insertTextRules:Y.KeepWhitespace,range:void 0}))};break;case`default`:return aC(e,t,n,e.container.element(t,n),[P.Schema,P.Enum]);default:break}return X()}function fC(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 L?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 pC(e,n,r,i){let a=ap(i)??[];return a.pop(),a.some(e=>!E(e))?X():gS({suggestions:fC(e,a.map(e=>M(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:pS(e.kind),range:void 0}})})}function mC(e,t,n,i){switch(e.container.scopeKind(t,n)){case Q.TABLE:case Q.TABLEPARTIAL:return vC(e,t,n,i);case Q.PROJECT:return yC(e,t,n,i);case Q.INDEXES:return OC(e,t,n);case Q.ENUM:return _C(e,t,n,i);case Q.REF:case Q.DEP:{let r=bC(e,t,n);return e.container.token(t,n).token?.kind===_.COLON&&mS(e.container.token(t,n).token,n)?hS(r):r}case Q.TABLEGROUP:return DC(e,t);case Q.DIAGRAMVIEW:return NC();case Q.CUSTOM:{let i=e.container.element(t,n);if(i instanceof L){let a=i.parentNode,o=a instanceof H?a.parentNode:void 0;if(o instanceof L&&o.isKind(r.DiagramView))return PC(e,t,n,i)}return X()}default:return X()}}var hC=[Z.Table,Z.TableGroup,Z.Enum,Z.Project,Z.Ref,Z.Dep,Z.TablePartial,Z.Records,Z.DiagramView,Z.Note,Z.Metadata];function gC(){return{suggestions:hC.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}}function _C(e,t,n,r){return r?.callee&&jC(n,r)===1?aC(e,t,n,e.container.element(t,n),[P.Schema,P.Table,P.Column]):X()}function vC(e,t,n,r){let i=$S;if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))};let a=jC(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:a===1?kC(e,t,n):X()}function yC(e,t,n,r){let i=eC;return!r?.callee||jC(n,r)===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))}:X()}function bC(e,t,n){return aC(e,t,n,e.container.element(t,n),[P.Schema,P.Table,P.Column])}var xC={[Lp.Table]:[P.Schema,P.Table],[Lp.Column]:[P.Schema,P.Table,P.Column],[Lp.TableGroup]:[P.TableGroup],[Lp.Note]:[P.StickyNote]},SC={[Lp.Table]:Z.Table,[Lp.Column]:Z.Column,[Lp.TableGroup]:Z.TableGroup,[Lp.Note]:Z.Note};function CC(){return{suggestions:Object.values(Lp).map(e=>{let t=SC[e];return{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}})}}function wC(e,t,n,r){let i=v_(r);if(!i||n<=r.targetKind.end&&n>=r.targetKind.start)return CC();let a=xC[i];return a?aC(e,t,n,r.parent,a):X()}function TC(e,t,n,i){return i.isKind(r.Records)?aC(e,t,n,i.parent,[P.Schema,P.Table]):X()}function EC(e,n,i,a){let o=e.container.element(n,i),s=a.callee&&wg(i,a.callee),c=a.argumentList&&wg(i,a.argumentList);if(o instanceof L&&o.isKind(r.Records)&&Tg(i,o)){if(s)return aC(e,n,i,o.parent,[P.Schema,P.Table]);if(!c)return X();let r=a.callee;if(!r)return X();let l=ap(r)??[r],u=l[l.length-1],d=u?e.nodeReferee(u).getFiltered(t):void 0;if(!d)return X();let f=iC(e,d,[P.Column]),{argumentList:p}=a;return!p||!rp(p)?f:_S(f)}let l=[...e.container.stack(n,i)];for(let o of l){if(!c||!(o instanceof V)||o.callee!==a||(M(a.callee)??``).toLowerCase()!==r.Records)continue;let s=e.nodeSymbol(e.container.element(n,i)).getFiltered(t);if(!s)return X();let l=iC(e,s,[P.Column]),{argumentList:u}=a;return!u||!rp(u)?l:_S(l)}return X()}function DC(e,t){return{suggestions:[...gS({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==P.Table&&e.kind!==P.Schema)return[];let t=e.name;return t===void 0||e instanceof Bp&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:Y.KeepWhitespace,kind:pS(e.kind),range:void 0}})}).suggestions,...[Z.Note].map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0}))]}}function OC(e,t,n){return AC(e,t,n)}function kC(e,t,n){return{suggestions:[...NS.map(e=>({label:e,insertText:e,insertTextRules:Y.KeepWhitespace,kind:J.TypeParameter,sortText:J.TypeParameter.toString().padStart(2,`0`),range:void 0})),...aC(e,t,n,e.container.element(t,n),[P.Enum,P.Schema]).suggestions]}}function AC(e,n,r){let i=e.container.element(n,r)?.parent,a=i?e.nodeSymbol(i).getFiltered(t):void 0;if(!a||!a?.isKind(P.Table))return X();let o=e.symbolMembers(a).getFiltered(t);return o?gS({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:pS(P.Column),range:void 0}:[]})}):X()}function jC(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 MC={label:`*`,insertText:`*`,insertTextRules:Y.KeepWhitespace,kind:J.Keyword,range:void 0};function NC(){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})),MC]}}function PC(e,t,n,i){switch(i.getElementKind()){case r.DiagramViewTables:return{suggestions:[MC,...aC(e,t,n,e.parse.ast(t),[P.Table,P.Schema]).suggestions]};case r.DiagramViewTableGroups:return{suggestions:[MC,...aC(e,t,n,e.parse.ast(t),[P.TableGroup]).suggestions]};case r.DiagramViewSchemas:return{suggestions:[MC,{label:v,insertText:v,insertTextRules:Y.KeepWhitespace,kind:J.Module,range:void 0},...aC(e,t,n,e.parse.ast(t),[P.Schema]).suggestions]};case r.DiagramViewNotes:return{suggestions:[MC,...aC(e,t,n,e.parse.ast(t),[P.StickyNote]).suggestions]};default:return X()}}var FC={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*[}\]].*)$/}},IC={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`dep`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`,`metadata`],metadataTarget:[`table`,`tablegroup`,`schema`,`column`,`note`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`dep`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`none`,`check`,`tables`,`tablegroups`,`notes`,`schemas`,`inactive`,`example`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>~-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":{cases:{"$3@metadataTarget":[`keyword`,``,`keyword`,``,`identifier`],"@default":[`keyword`,``,`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`identifier`,``,`identifier`]}}],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@metadataTarget":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}};function LC(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:va(n,e=>!e.isInvalid,r);if(a===-1)return[this.parse.ast(e)];let o=n[a].start,s=this.parse.ast(e),c=[s];for(;;){let e=Rm(s).find(e=>wg(o,e));if(e===void 0||e instanceof Ha)break;c.push(e),s=e}if(i?.kind===_.COLON)return c;for(;c.length>0;){let n=!1,r=h(c);if(r instanceof V){let i=this.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
35
+ `&&(c.pop(),n=!0)}else r instanceof z||r instanceof B?this.container.token(e,t).token!==r.op&&(c.pop(),n=!0):r instanceof U?r.listCloseBracket&&r.end<=t&&(c.pop(),n=!0):r instanceof Sm?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof Cm?r.end<=t&&(c.pop(),n=!0):r instanceof H?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof ym||r.end<t&&(c.pop(),n=!0);if(n){let e=h(c);e instanceof L&&e.end<=t&&c.pop()}if(!n)break}return c}function RC(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 zC(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof L)return n[e];return this.parse.ast(e)}function BC(e,n){let r=this.container.element(e,n);if(!r)return;let i=this.nodeSymbol(r);if(i.hasValue(t))return;let a=this.symbolMembers(i.getValue());if(!a.hasValue(t))return a.getValue()}var Q=function(e){return e[e.TABLE=0]=`TABLE`,e[e.ENUM=1]=`ENUM`,e[e.TABLEGROUP=2]=`TABLEGROUP`,e[e.INDEXES=3]=`INDEXES`,e[e.NOTE=4]=`NOTE`,e[e.REF=5]=`REF`,e[e.DEP=6]=`DEP`,e[e.PROJECT=7]=`PROJECT`,e[e.CUSTOM=8]=`CUSTOM`,e[e.TOPLEVEL=9]=`TOPLEVEL`,e[e.TABLEPARTIAL=10]=`TABLEPARTIAL`,e[e.CHECKS=11]=`CHECKS`,e[e.RECORDS=12]=`RECORDS`,e[e.DIAGRAMVIEW=13]=`DIAGRAMVIEW`,e[e.METADATA=14]=`METADATA`,e}({});function VC(e,t){let n=this.container.element(e,t);if(n instanceof I)return Q.TOPLEVEL;switch(n.type?.value.toLowerCase()){case`table`:return Q.TABLE;case`enum`:return Q.ENUM;case`ref`:return Q.REF;case`dep`:return Q.DEP;case`tablegroup`:return Q.TABLEGROUP;case`indexes`:return Q.INDEXES;case`note`:return Q.NOTE;case`project`:return Q.PROJECT;case`tablepartial`:return Q.TABLEPARTIAL;case`checks`:return Q.CHECKS;case`records`:return Q.RECORDS;case`diagramview`:return Q.DIAGRAMVIEW;case`metadata`:return Q.METADATA;default:return Q.CUSTOM}}function HC(e,t){let r=t.originalSymbol;if(r.filepath.equals(e))return n.create(WC(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=UC(this,e);if(i.length>0)return n.create({schema:i.join(`.`),name:t});let a=WC(this,r);return a?n.create({...a,name:t}):n.create({schema:v,name:t})}return n.create(WC(this,r))}function UC(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof Bp&&e.isKind(P.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function WC(e,n){if(!n.declaration)return n.name?{schema:v,name:n.name}:void 0;let r=e.nodeFullname(n.declaration).getFiltered(t);if(!r||r.length===0)return n.name?{schema:v,name:n.name}:void 0;let i=r[r.length-1];return{schema:r.length>1?r.slice(0,-1).join(`.`):v,name:i}}function GC(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof gm)||!i.importPath)continue;let t=this.layout.resolveFileSpecifier(e,i.importPath.value);!t||r.has(t.absolute)||(r.add(t.absolute),n.push(t))}return n}function KC(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 qC(e){return KC(this,e?[e]:this.layout.getEntrypoints())}function JC(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function YC(e){return this.interpretFile(e).getErrors()}function XC(e){return this.interpretFile(e).getWarnings()}function ZC(e){return this.parseFile(e).getValue().tokens}function QC(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.interpretSymbol(r,e).getFiltered(t)}function $C(e){let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(t);if(r)return this.symbolMembers(r).getFiltered(t)}function ew(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function tw(e){return this.parseFile(e).getValue().tokens.filter(pm)}function nw(e,t){let n=this.parse.ast(e);for(;;){let e=Rm(n).find(e=>wg(t,e));if(e===void 0)return n;if(e instanceof Ha)return e;n=e}}function rw(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 iw(){let e=qv(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 aw(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 ow(){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 sw(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var cw=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),lw=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 h(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case _.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case _.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case _.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case _.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},uw=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}},dw=class{constructor(e,t,n,r,i={}){this.current=0,this.errors=[],this.contextStack=new lw,this.useSpecifierList=this.contextStack.withContextDo(cw.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(vm,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof _m&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(_.IDENTIFIER)&&dm(this.peek()))break;!Ua(this.previous())&&!this.check(_.RBRACE)&&this.logError(this.peek(),S.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(_.RBRACE))for(W(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||this.check(_.STRING_LITERAL)||this.check(_.IDENTIFIER)&&dm(e)||Wa(this.previous(),e))break;W(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===_.EOF?this.logError(e,S.UNEXPECTED_EOF,`Unexpected EOF`):W(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(cm(e)||this.check(_.COLON,_.LBRACE,_.LBRACKET))break;W(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COLON,_.LBRACE,_.LBRACKET))break;W(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(cw.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(H,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(_.RBRACE))for(W(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||Wa(this.previous(),e))break;W(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(cw.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(wm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(Sm,e);try{this.consume(`Expect an opening parenthesis '('`,_.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(_.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(_.RPAREN);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof F&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,_.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.RPAREN,_.COMMA))break;W(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(cw.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(U,e);try{this.consume(`Expect an opening bracket '['`,_.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(_.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(_.RBRACKET);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof F&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,_.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;W(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET,_.COLON))break;W(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;W(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new uw(n,r),this.filepath=r,this.options=i}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===_.EOF}advance(){return this.isAtEnd()?h(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?h(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),S.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(W(this.peek()),this.logError(this.advance(),S.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)W(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(I,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Rm(e).forEach(t=>{t instanceof F&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(lm(this.peek())||fm(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof gm&&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(gm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===_.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(Dm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof vm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof Dm?`'*'`:`specifier list`;return dm(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(_.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(_m,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,_.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(_.IDENTIFIER,_.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof F&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect an element name`);if(cm(this.peek())){e.asKeyword=this.advance();try{if(!this.check(_.IDENTIFIER,_.QUOTED_STRING))throw this.logError(this.peek(),S.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(L,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(um(e.type))try{this.consume(`Expect a metadata target kind`,_.IDENTIFIER),e.targetKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(_.COLON,_.LBRACE,_.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(cm(this.peek()))if(e.as=this.advance(),this.check(_.COLON,_.LBRACE,_.LBRACKET))this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(_.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.options.allowBodylessElement&&!this.check(_.LBRACE,_.COLON)||!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,_.LBRACE,_.COLON))return t();try{if(this.match(_.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof L?(W(t),this.logError(t,S.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(L,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(L,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,_.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof L?this.errors.push(new C(S.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(L,e)}expression(){let e={args:[]},t=()=>Pm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(V,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Ga(this.previous())||this.logError(n,S.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()||Ua(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.RBRACKET,_.RPAREN,_.COMMA,_.COLON].includes(e)}commaExpression(){let e=this.check(_.COMMA)?this.nodeFactory.create(Am,{prevToken:this.previous()}):this.normalExpression();if(!this.check(_.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(Am,{prevToken:this.previous()}));break}if(this.check(_.COMMA)){t.elementList.push(this.nodeFactory.create(Am,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(Cm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(_.COMMA));return this.nodeFactory.create(Cm,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ua(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.LBRACE,_.RBRACKET,_.LBRACKET,_.RPAREN,_.LPAREN,_.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===_.LPAREN){let{left:r}=xw(n);if(r<e||Wa(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(Tm,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Tm,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===_.LBRACKET){if(Ga(this.previous()))break;try{t=this.nodeFactory.create(jm,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(jm,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Va(n)){let r=n,i=xw(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(bm,{expression:t,op:r})}else{let n=_w(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(B,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(B,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Va(this.peek())){let t={};t.op=this.peek();let n=yw(t.op);if(n.right===null)throw this.logError(t.op,S.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Am,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(z,t),e.handlerContext)):e}e=this.nodeFactory.create(z,t)}else if(e=this.extractOperand(),e instanceof Am)throw new $(this.peek(),this.nodeFactory.create(Am,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(_.WILDCARD)?this.wildcardExpression():this.check(_.NUMERIC_LITERAL,_.STRING_LITERAL,_.COLOR_LITERAL,_.QUOTED_STRING,_.IDENTIFIER)?this.primaryExpression():this.check(_.FUNCTION_EXPRESSION)?this.functionExpression():this.check(_.LBRACKET)?this.listExpression():this.check(_.LBRACE)?this.blockExpression():this.check(_.LPAREN)?this.tupleExpression():(this.peek().kind===_.EOF?this.logError(this.peek(),S.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),S.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Am,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,_.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(xm,e),t.handlerContext):t}return this.nodeFactory.create(xm,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(Dm,{token:this.previous()})}canBeField(){return this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.COLON}primaryExpression(){if(this.match(_.COLOR_LITERAL,_.STRING_LITERAL,_.NUMERIC_LITERAL))return this.nodeFactory.create(km,{expression:this.nodeFactory.create(Em,{literal:this.previous()})});if(this.match(_.QUOTED_STRING,_.IDENTIFIER))return this.nodeFactory.create(km,{expression:this.nodeFactory.create(Om,{variable:this.previous()})});throw this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(_.COLON,_.RBRACKET,_.COMMA)){let t=this.peek();this.logError(t,S.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(ym,{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(R,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(_.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(R,e)}attributeValue(){let e;try{e=this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==_.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(_.COLON,_.COMMA,_.RBRACKET);)try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(ym,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(ym,{identifiers:e})}logError(e,t,n){this.errors.push(new C(t,n,e))}},fw=e=>({left:e,right:e+1}),pw=e=>({left:null,right:e}),mw=e=>({left:e,right:null}),hw={left:null,right:null},gw={".":fw(16),"/":fw(11),"%":fw(11),"+":fw(9),"=":fw(2),"==":fw(4),"!=":fw(4),"-":fw(9),"-?":fw(9),"?-":fw(9),"?-?":fw(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`].map(e=>[e,fw(7)]))};function _w(e){return gw[e.value]??hw}var vw=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`,`!`,`~`].map(e=>[e,pw(15)]));function yw(e){return vw[e.value]??hw}var bw={"(":mw(14)};function xw(e){return bw[e.value]??hw}function Sw(e){let t=this.getSource(e)??``,n=this.lexerOptions();return new Wy(t,e,n).lex().chain(r=>{let i=this.fileKindForParse(e,n.allowFrontMatter?r:void 0);return new dw(t,r,this.nodeIdGenerator,e,this.parserOptions(i)).parse().map(e=>(i===`arch`&&!this.explicitModules&&Cw(e.ast),e))}).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function Cw(e){for(let t of e.body)if(!(!(t instanceof gm)||!(t.specifiers instanceof vm)))for(let e of t.specifiers.specifiers)e.archImport=!0}function ww(){let e=qv(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 Tw(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof om?gv.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 Ew(e,n,r){let i;if(e instanceof zp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof zp))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 Dw(e){let t=e.originalSymbol;return Jv(this).map(n=>n.filter(n=>n instanceof am&&n.originalSymbol===t&&n!==e))}function Ow(){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 Hh){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(E(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof Sm&&D(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=Qf(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Rm(e))t instanceof F&&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 Bp&&t.isKind(P.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 kw(e){return this.resolutionIndex().parents.get(e.intern())??[]}function Aw(e){return this.resolutionIndex().references.get(e.intern())??[]}function jw(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function Mw(e){let t=e.originalSymbol;return Jv(this).map(n=>n.filter(n=>n instanceof om&&n.originalSymbol===t&&n!==e))}function Nw(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 Pw(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=e.getSource(n)??``;for(let t of e.symbolMetadata(o))if(t instanceof Ih&&Iw(e,t,r)){if(t.declaration instanceof R){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(V);if(!r)continue;let a=L_(r,i.Ref,s);if(!a)continue;return{kind:`inline`,op:n,fullStart:a.start,fullEnd:a.end}}if(t.declaration instanceof L){let e=ip(t.declaration)[0];if(e instanceof V)return{kind:`standalone`,node:e}}}}function Fw(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0?!0:t.length===r.length?t.every((e,t)=>e.name===r[t]):!1}function Iw(e,t,n){let r=t.leftTable(e),i=t.leftColumns(e),a=t.rightTable(e),o=t.rightColumns(e),[s,c]=n.endpoints;return Fw(r,i,s)&&Fw(a,o,c)||Fw(r,i,c)&&Fw(a,o,s)}function Lw(e,t,n){let r=Uw(e,t,Vw(n.schemaName),n.tableName,P.Table);return{table:r,columns:(n.fieldNames??[]).map(t=>r?e.lookupMembers(r,P.Column,t):void 0)}}function Rw(e,t){let n=e?.originalSymbol.declaration;return!!n&&n===t?.originalSymbol.declaration}function zw(e,t,n){return!Rw(e,n.table)||t.length!==n.columns.length?!1:t.every((e,t)=>Rw(e,n.columns[t]))}function Bw(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=Lw(e,n,r.upstream),c=Lw(e,n,r.downstream);if(!s.table||!c.table)return;let l=e.getSource(n)??``;for(let t of e.symbolMetadata(o)){if(!(t instanceof Lh))continue;let n=t.upstreamTables(e),r=t.upstreamColumns(e),a=t.downstreamTables(e),o=t.downstreamColumns(e);if(!n.some((e,t)=>zw(n[t],r[t]??[],s)&&zw(a[t],o[t]??[],c)))continue;if(t.declaration instanceof L)return{kind:`block`,declaration:t.declaration};let u=t.declaration.parentOfKind(V);if(!u)continue;let d=L_(u,i.Dep,l);if(!d)continue;let f=t.declaration.value;if(!(f instanceof z))continue;let p=f.op?.value;if(p)return{kind:`inline`,op:p,fullStart:d.start,fullEnd:d.end}}}function Vw(e){return e&&e.length>0?e:v}function Hw(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=Kv(e);if(t.length===0)return{schema:v,table:``};if(t.length===1)return{schema:v,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function Uw(e,n,r,i,a=P.Table){let o=e.parseFile(n).getValue().ast,s=e.nodeSymbol(o).getFiltered(t);if(!s)return;if(r===`public`)return e.lookupMembers(s,a,i)??void 0;let c=e.lookupMembers(s,P.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function Ww(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function Gw(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(Vv(e.schemaName)),t.push(Vv(e.tableName));for(let n of e.fieldNames??[])t.push(Vv(n));return t.join(`.`)}function Kw(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function qw(e,t){if(!e||!(e instanceof L))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function Jw(e,t,n){let r=!Bv(t),i=!Bv(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 Yw(e,t,n,r,i,a){return n===i&&r===a?!1:Uw(e,t,i,a)!==void 0}function Xw(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 Ww(n.substring(i,a))===t?{start:i,end:e.end}:null}function Zw(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function Qw(e,t,n,r,i){let a=[],o=new Set,s=Zw(r);for(let r of e){if(Ww(i.substring(r.start,r.end))!==n)continue;let e=Xw(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 $w(e,n,r){let i=Hw(n),a=Hw(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=Uw(this,e,o,s);if(!u||u instanceof am||Yw(this,e,o,s,c,l))return new Map;if(u instanceof om&&u.useSpecifierDeclaration instanceof _m&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return eT(this,e,n,u,c,l)}return tT(this,u,o,s,c,l)}function eT(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=Jw(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,Nw(o,c)]])}function tT(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof L))return new Map;let c=s.filepath;if(!c)return new Map;let l=Jw(i,a,qw(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:Zw(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 Qw([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,Nw(r,n))}return m}function nT(e,t){let n=e.parseFile(t).getValue().ast;return e.parsedFileKind(t)===`arch`?n.body.filter(ch):[]}var rT=e=>{let t=lh(e);return t===`node`||t===`group`||t===`note`};function iT(e,t,n){return nT(e,t).find(e=>rT(e)&&dh(e)===n)}function aT(e,t,n,r){return nT(e,t).find(e=>{if(lh(e)!==`link`)return!1;let t=bh(e);if(!t)return!1;let i=G(vh(t.infix.left)),a=G(vh(t.infix.right));return i===n&&a===r||i===r&&a===n})}function oT(e,t,n){let r=iT(this,e,t);if(!r?.name)return new Map;let i=!r.alias;if(i&&n!==t&&Ah(this,e,P.Element,n))return new Map;let a=this.getSource(e)??``,o=a.substring(r.name.start,r.name.end).includes(`"`)||!Bv(n)?`"${n}"`:n,s=[{start:r.name.start,end:r.name.end,newText:o}];if(i){let i=Bv(n)?n:`${sh(r)} ${o}`;for(let n of sT(nT(this,e),t))s.push({start:n.start,end:n.end,newText:n instanceof Ha?i:o})}return new Map([[e.absolute,Nw(a,s)]])}function sT(e,t){let n=e=>E(e)&&G(e)===t,r=[];for(let i of e)switch(lh(i)){case`link`:{let e=bh(i);if(!e)break;r.push(...[vh(e.infix.left),vh(e.infix.right)].filter(n));break}case`group`:for(let e of hh(i))e instanceof V&&r.push(...[e.callee,...e.args].filter(n));break;case`metadata`:i.name?n(i.name)&&r.push(i.name):i.targetKind?.value===t&&r.push(i.targetKind);break;default:break}return r}function cT(e,t,n,r){if(t.kind===`dep`)return dT(this,e,t,n,r);if(t.kind===`ref`)return fT(this,e,t,n,r);if(t.kind===P.Element)return pT(this,e,t,n,r);if(t.kind===`Link`)return mT(this,e,t,n,r);let i=uT(this,e,t);if(!i)return[];let a=I_(i,n,r,this.getSource(e)??``);return a?[a]:[]}function lT(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:Nw(i,a)}function uT(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case P.Column:{let i=Uw(e,t,r,n.table,P.Table);return i?e.lookupMembers(i,P.Column,n.column)?.declaration:void 0}case P.Table:return Uw(e,t,r,n.table)?.declaration;case P.Enum:case P.StickyNote:case P.TableGroup:return Uw(e,t,r,n.name,n.kind)?.declaration;case P.Schema:return Uw(e,t,n.schema,``,P.Schema)?.declaration;default:return}}function dT(e,t,n,r,i){let a=e.getSource(t)??``,o=Bw(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=Gw(n.upstream),t=Gw(n.downstream),s=Kw(r,i),c=s?`Dep [${s}] {\n ${e} -> ${t}\n}`:`Dep {\n ${e} -> ${t}\n}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
26
36
 
27
37
  `+c+`
28
- `}]}let{declaration:s}=o,{body:c}=s;if(c instanceof H){let e=Og(s,r,i,a);if(e)return[e];let t=Og(c,r,i,a);return t?[t]:[]}let l=Og(s,r,i,a);return l?[l]:[]}function IC(e,t,n,r,i){let a=e.getSource(t)??``,o=uC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=xC(n.endpoints[0]),t=xC(n.endpoints[1]),s=SC(r,i),c=s?`Ref: ${e} ${o.op} ${t} [${s}]`:`Ref: ${e} ${o.op} ${t}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
38
+ `}]}let{declaration:s}=o,{body:c}=s;if(c instanceof V){let e=I_(s,r,i,a);if(e)return[e];let t=I_(c,r,i,a);return t?[t]:[]}let l=I_(s,r,i,a);return l?[l]:[]}function fT(e,t,n,r,i){let a=e.getSource(t)??``,o=Pw(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=Gw(n.endpoints[0]),t=Gw(n.endpoints[1]),s=Kw(r,i),c=s?`Ref: ${e} ${o.op} ${t} [${s}]`:`Ref: ${e} ${o.op} ${t}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
29
39
 
30
40
  `+c+`
31
- `}]}let s=Og(o.node,r,i,a);return s?[s]:[]}function LC(e){let t=[],n=new RS(e,Oo).lex();if(n.getErrors().length>0)return t;let i=new HS(e,n.getValue(),new fm,Oo).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 RC(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function zC(e,t){e.push(` ${t} { * }`)}function BC(e){return e==null?`null`:e.length===0?`empty`:`items`}function VC(e,t){let n=`DiagramView ${z_(e)} {`,r=e=>z_(e.name),i=t?.tables?.map(e=>{let t=z_(e.name);return e.schemaName===`public`?t:`${z_(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:BC(t.tables),tableGroups:BC(t.tableGroups),schemas:BC(t.schemas),stickyNotes:BC(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`&&RC(d,`Tables`,i),c.tableGroups===`items`&&RC(d,`TableGroups`,a),c.schemas===`items`&&RC(d,`Schemas`,o)):u&&zC(d,`Tables`),c.stickyNotes===`items`?RC(d,`Notes`,s):c.stickyNotes===`empty`&&zC(d,`Notes`),d.push(`}`),d.join(`
32
- `)}function HC(e,t,n){let r=this.getSource(e)??``,i=n??LC(r),a=[];for(let e of t){let t=UC(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:lC(r,a,!0),edits:a}}function UC(e,t,n){switch(t.operation){case`create`:return WC(e,t,n);case`update`:return GC(e,t,n);case`delete`:return KC(e,t,n);default:return[]}}function WC(e,t,n){if(n.find(e=>e.name===t.name))return GC(e,t,n);let r=`
41
+ `}]}let s=I_(o.node,r,i,a);return s?[s]:[]}function pT(e,t,n,r,i){let a=iT(e,t,n.name);if(!a)return[];let o=I_(a,r,i,e.getSource(t)??``);return o?[o]:[]}function mT(e,t,n,r,i){let a=aT(e,t,n.from,n.to);if(!a)return[];let o=I_(!bh(a)?.row?.settings&&a.attributeList?a:hh(a)[0],r,i,e.getSource(t)??``);return o?[o]:[]}function hT(e){let t=[],n=new Wy(e,xo).lex();if(n.getErrors().length>0)return t;let i=new dw(e,n.getValue(),new mm,xo).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?A(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function gT(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function _T(e,t){e.push(` ${t} { * }`)}function vT(e){return e==null?`null`:e.length===0?`empty`:`items`}function yT(e,t){let n=`DiagramView ${Vv(e)} {`,r=e=>Vv(e.name),i=t?.tables?.map(e=>{let t=Vv(e.name);return e.schemaName===`public`?t:`${Vv(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:vT(t.tables),tableGroups:vT(t.tableGroups),schemas:vT(t.schemas),stickyNotes:vT(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`&&gT(d,`Tables`,i),c.tableGroups===`items`&&gT(d,`TableGroups`,a),c.schemas===`items`&&gT(d,`Schemas`,o)):u&&_T(d,`Tables`),c.stickyNotes===`items`?gT(d,`Notes`,s):c.stickyNotes===`empty`&&_T(d,`Notes`),d.push(`}`),d.join(`
42
+ `)}function bT(e,t,n){let r=this.getSource(e)??``,i=n??hT(r),a=[];for(let e of t){let t=xT(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:Nw(r,a,!0),edits:a}}function xT(e,t,n){switch(t.operation){case`create`:return ST(e,t,n);case`update`:return CT(e,t,n);case`delete`:return wT(e,t,n);default:return[]}}function ST(e,t,n){if(n.find(e=>e.name===t.name))return CT(e,t,n);let r=`
33
43
 
34
- `+VC(t.name,t.visibleEntities)+`
35
- `;return[{start:e.length,end:e.length,newText:r}]}function GC(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=VC(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function KC(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
44
+ `+yT(t.name,t.visibleEntities)+`
45
+ `;return[{start:e.length,end:e.length,newText:r}]}function CT(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=yT(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function wT(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]===`
36
46
  `;){i--,i>0&&e[i-1]===`\r`&&i--;let t=e.lastIndexOf(`
37
47
  `,i-1)+1;if(e.substring(t,i).trim()!==``){i=r.startIndex,i>0&&e[i-1]===`
38
48
  `&&(i--,i>0&&e[i-1]===`\r`&&i--);break}}return a<e.length&&e[a]===`\r`&&a++,a<e.length&&e[a]===`
39
- `&&a++,[{start:i,end:a,newText:``}]}function qC(e,t){let n=XC(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:q_(t)}}function JC(e){let t=XC(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function YC(e,t){if(XC(e)||!(e instanceof R))return;let n=ZC(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${q_(t)}\n`};let r=e.body;if(r instanceof H){let n=r.args.find(e=>e instanceof W);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${q_(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${q_(t)}]`}}}function XC(e){if(!(e instanceof R))return;let t=e.body;if(t&&!(t instanceof H))for(let e of t.body){if(!(e instanceof R)||!e.isKind(r.Note))continue;let t=QC(e);if(t)return{kind:pm.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof H?t.args.find(e=>e instanceof W):void 0);if(n)return $C(n)}function ZC(e){let t=e.body;if(!(!t||t instanceof H)&&t.blockCloseBrace)return t.blockCloseBrace.start}function QC(e){let t=e.body;if(t instanceof H)return t.callee??void 0;if(t instanceof U&&t.body[0]instanceof H)return t.body[0].callee??void 0}function $C(e){let t=T(e).getValue()[i.Note];if(!t?.length)return;let n=t[0];if(!n.value)return;let r=e.elementList,a=r.indexOf(n),o=n.start,s=n.end;return r.length===1?(o=e.start,s=e.end):a<r.length-1?s=r[a+1].start:o=r[a-1].end,{kind:pm.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function ew(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...nw(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:lC(n,r,!0),edits:r}}function tw(e,t){return`Dep [color: ${t}] {\n ${xC(e.upstream)} -> ${xC(e.downstream)}\n}`}function nw(e,t,n,r){let i=gC(e,t,r.edge);switch(r.operation){case`create`:return iw(n,r,i);case`update`:return i?.kind===`block`?rw(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?rw({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function rw(e,t,n){let r=[];if(e.color!==void 0){let a=Og(t,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=JC(t);e&&r.push(e)}else if(e.note!==void 0){let n=qC(t,e.note)??YC(t,e.note);n&&r.push(n)}return r}function iw(e,t,n){if(n?.kind===`block`)return rw(t,n.declaration,e);let r=tw(t.edge,t.color??``),i={start:e.length,end:e.length,newText:`
49
+ `&&a++,[{start:i,end:a,newText:``}]}function TT(e,t){let n=OT(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:Yv(t)}}function ET(e){let t=OT(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function DT(e,t){if(OT(e)||!(e instanceof L))return;let n=kT(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${Yv(t)}\n`};let r=e.body;if(r instanceof V){let n=r.args.find(e=>e instanceof U);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${Yv(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${Yv(t)}]`}}}function OT(e){if(!(e instanceof L))return;let t=e.body;if(t&&!(t instanceof V))for(let e of t.body){if(!(e instanceof L)||!e.isKind(r.Note))continue;let t=AT(e);if(t)return{kind:hm.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof V?t.args.find(e=>e instanceof U):void 0);if(n)return jT(n)}function kT(e){let t=e.body;if(!(!t||t instanceof V)&&t.blockCloseBrace)return t.blockCloseBrace.start}function AT(e){let t=e.body;if(t instanceof V)return t.callee??void 0;if(t instanceof H&&t.body[0]instanceof V)return t.body[0].callee??void 0}function jT(e){let t=w(e).getValue()[i.Note];if(!t?.length)return;let n=t[0];if(!n.value)return;let r=e.elementList,a=r.indexOf(n),o=n.start,s=n.end;return r.length===1?(o=e.start,s=e.end):a<r.length-1?s=r[a+1].start:o=r[a-1].end,{kind:hm.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function MT(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...PT(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:Nw(n,r,!0),edits:r}}function NT(e,t){return`Dep [color: ${t}] {\n ${Gw(e.upstream)} -> ${Gw(e.downstream)}\n}`}function PT(e,t,n,r){let i=Bw(e,t,r.edge);switch(r.operation){case`create`:return IT(n,r,i);case`update`:return i?.kind===`block`?FT(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?FT({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function FT(e,t,n){let r=[];if(e.color!==void 0){let a=I_(t,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=ET(t);e&&r.push(e)}else if(e.note!==void 0){let n=TT(t,e.note)??DT(t,e.note);n&&r.push(n)}return r}function IT(e,t,n){if(n?.kind===`block`)return FT(t,n.declaration,e);let r=NT(t.edge,t.color??``),i={start:e.length,end:e.length,newText:`
40
50
 
41
51
  `+r+`
42
- `};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var aw=Symbol(`COMPUTING`),ow=class{constructor(e){this.layout=e,this.nodeIdGenerator=new fm,this.symbolIdGenerator=new Wp,this.symbolFactory=new to(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery($S),this.parseProject=this.globalQuery(eC),this.validateNode=this.localQuery(xy),this.validateFile=this.localQuery(LS),this.nodeFullname=this.localQuery(Cy),this.nodeAlias=this.localQuery(wy),this.nodeSettings=this.localQuery(Sy),this.canonicalName=this.globalQuery(vS),this.bindNode=this.globalQuery(Dv),this.bindFile=this.globalQuery(NS),this.bindProject=this.globalQuery(PS),this.interpretSymbol=this.globalQuery(kv),this.interpretMetadata=this.globalQuery(Av),this.interpretFile=this.globalQuery(FS),this.interpretProject=this.globalQuery(IS),this.nodeSymbol=this.globalQuery(wv),this.nodeMetadata=this.globalQuery(Ov),this.symbolMembers=this.globalQuery(Tv),this.symbolMembersLookupMap=this.globalQuery(tC),this.lookupMembers=this.globalQuery(nC),this.nodeReferee=this.globalQuery(Ev),this.resolutionIndex=this.globalQuery(iC),this.symbolReferences=this.globalQuery(oC),this.symbolParent=this.globalQuery(aC),this.symbolMetadata=this.globalQuery(sC),this.symbolAliases=this.globalQuery(rC),this.symbolUses=this.globalQuery(cC),this.fileDependencies=this.localQuery(xS),this.reachableFiles=this.globalQuery(CS),this.usableMembers=this.globalQuery(u_),this.nodeAtPosition=this.localQuery(MS),this.renameTable=kC.bind(this),this.updateElementSetting=NC.bind(this),this.updateElementSettingEdit=MC.bind(this),this.syncDiagramView=HC.bind(this),this.syncDep=ew.bind(this),this.token={invalidStream:this.localQuery(jS),flatStream:this.localQuery(AS)},this.parse={source:e=>this.getSource(e)||``,ast:(e=Oo)=>wS.call(this,e),errors:(e=Oo)=>TS.call(this,e),warnings:(e=Oo)=>ES.call(this,e),tokens:(e=Oo)=>DS.call(this,e),rawDb:(e=Oo)=>OS.call(this,e),publicSymbolTable:(e=Oo)=>kS.call(this,e)},this.container={stack:this.localQuery(pS),token:this.localQuery(mS),element:this.localQuery(hS),scope:this.localQuery(gS),scopeKind:this.localQuery(_S)}}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 SS(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?ph(n[0]):n.map(e=>ph(e)).join(`\0`),a=r.get(i);if(a){if(a===aw)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,aw);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?ph(n[0]):n.map(e=>ph(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===aw)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,aw);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}initMonacoServices(e){let{triggerCharacters:t=[],fileListDepth:n}=e?.autocompletion??{};return{definitionProvider:new Pb(this),referenceProvider:new Ib(this),autocompletionProvider:new jx(this,{triggerCharacters:t,fileListDepth:n}),diagnosticsProvider:new Fb(this),codeActionProvider:new Nb(this)}}},sw=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}resolveFileSpecifier(e,t){if(!So.isRelative(t))return;let n=So.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:So.from(n.absolute+`.dbml`)}getFileSpecifierInfo(e,t){let n=t.relativeTo(e.dirname);return n.endsWith(`.dbml`)&&(n=n.slice(0,-5)),{specifier:n}}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(So.from)}getEntrypoints(){return[...this.files.keys()].map(So.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=km,exports.AttributeNode=z,exports.BlockExpressionNode=U,exports.CARDINALITY_MANY=lf,exports.CARDINALITY_MAYBE=sf,exports.CARDINALITY_ONE=of,exports.CARDINALITY_SOME=cf,exports.CallExpressionNode=Cm,exports.CommaExpressionNode=xm,exports.CompileError=w,exports.CompileErrorCode=C,exports.CompileInfo=wf,exports.CompileWarning=Cf,exports.Compiler=ow,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=Nb,exports.DBMLCompletionItemProvider=jx,exports.DBMLDefinitionProvider=Pb,exports.DBMLDiagnosticsProvider=Fb,exports.DBMLReferencesProvider=Ib,exports.DEFAULT_ENTRY=Oo,exports.ElementDeclarationNode=R,exports.ElementKind=r,exports.EmptyNode=Om,exports.FALSY_VALUES=Tp,exports.Filepath=So,exports.FunctionApplicationNode=H,exports.FunctionExpressionNode=ym,exports.GroupExpressionNode=Sm,exports.IdentifierStreamNode=_m,exports.InfixExpressionNode=V,exports.ListExpressionNode=W,exports.LiteralNode=wm,exports.MarkerSeverity=Ab,exports.MemoryProjectLayout=sw,exports.MetadataKind=Wm,exports.PostfixExpressionNode=vm,exports.PrefixExpressionNode=B,exports.PrimaryExpressionNode=Dm,exports.ProgramNode=L,exports.ScopeKind=Q,exports.SymbolKind=F,exports.SyntaxNode=I,exports.SyntaxNodeIdGenerator=fm,exports.SyntaxNodeKind=pm,exports.SyntaxToken=Ha,exports.SyntaxTokenKind=_,exports.TRUTHY_VALUES=wp,exports.TupleExpressionNode=bm,exports.UNHANDLED=t,exports.Uri=yb,exports.UseDeclarationNode=mm,exports.UseSpecifierListNode=gm,exports.UseSpecifierNode=hm,exports.VariableNode=Em,exports.WildcardNode=Tm,exports.addDoubleQuoteIfNeeded=z_,exports.dbmlLanguageConfig=dS,exports.dbmlMonarchTokensProvider=fS,exports.escapeString=H_,exports.extractNumericLiteral=mp,exports.extractSignedNumber=xp,exports.findDiagramViewBlocks=LC,exports.formatRecordValue=U_,exports.getMultiplicities=ff,exports.getRecordValueType=Go,exports.getRelationshipOp=vf,exports.isBinaryType=Ho,exports.isBooleanType=Bo,exports.isDateTimeType=Uo,exports.isEmptyStringLiteral=yp,exports.isEndpointManySide=mf,exports.isEndpointOneSide=pf,exports.isEndpointOptional=hf,exports.isEndpointRequired=gf,exports.isFloatType=Ro,exports.isFunctionExpression=bp,exports.isIntegerType=Lo,exports.isNullish=vp,exports.isNumericType=zo,exports.isOp=Ba,exports.isOpToken=Va,exports.isSerialType=Wo,exports.isStringType=Vo,exports.isTriviaToken=za,exports.isValidIdentifier=R_,exports.makeCardinalityOptional=yf,exports.makeCardinalityRequired=bf,exports.makeRelationshipRequired=_f,exports.normalizeQualifiedName=B_,exports.normalizeTypeName=Io,exports.parseCardinality=af,exports.splitQualifiedIdentifier=W_,exports.tryExtractBoolean=Ep,exports.tryExtractDateTime=Mp,exports.tryExtractEnum=Dp,exports.tryExtractInteger=Cp,exports.tryExtractNumeric=Sp,exports.tryExtractString=Op,exports.unescapeString=V_,exports.validateForeignKeys=xg,exports.validatePrimaryKey=dg,exports.validateUnique=_g;
52
+ `};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var LT={allowFrontMatter:!0},RT=Symbol(`COMPUTING`),zT=class{constructor(e,t,n){this.layout=e,this.nodeIdGenerator=new mm,this.symbolIdGenerator=new Rp,this.symbolFactory=new Ya(this.symbolIdGenerator),this.fileScans=new Map,this.fileKinds=new Map,this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(Sw),this.parseProject=this.globalQuery(ww),this.validateNode=this.localQuery(qb),this.validateFile=this.localQuery(sw),this.nodeFullname=this.localQuery(Yb),this.nodeAlias=this.localQuery(Xb),this.nodeSettings=this.localQuery(Jb),this.canonicalName=this.globalQuery(HC),this.bindNode=this.globalQuery(By),this.bindFile=this.globalQuery(rw),this.bindProject=this.globalQuery(iw),this.interpretSymbol=this.globalQuery(Hy),this.interpretMetadata=this.globalQuery(Uy),this.interpretFile=this.globalQuery(aw),this.interpretProject=this.globalQuery(ow),this.nodeSymbol=this.globalQuery(Ly),this.nodeMetadata=this.globalQuery(Vy),this.symbolMembers=this.globalQuery(Ry),this.symbolMembersLookupMap=this.globalQuery(Tw),this.lookupMembers=this.globalQuery(Ew),this.nodeReferee=this.globalQuery(zy),this.resolutionIndex=this.globalQuery(Ow),this.symbolReferences=this.globalQuery(Aw),this.symbolParent=this.globalQuery(kw),this.symbolMetadata=this.globalQuery(jw),this.symbolAliases=this.globalQuery(Dw),this.symbolUses=this.globalQuery(Mw),this.fileDependencies=this.localQuery(GC),this.reachableFiles=this.globalQuery(qC),this.usableMembers=this.globalQuery(yv),this.nodeAtPosition=this.localQuery(nw),this.renameTable=$w.bind(this),this.renameElement=oT.bind(this),this.updateElementSetting=lT.bind(this),this.updateElementSettingEdit=cT.bind(this),this.syncDiagramView=bT.bind(this),this.syncDep=MT.bind(this),this.token={invalidStream:this.localQuery(tw),flatStream:this.localQuery(ew)},this.parse={source:e=>this.getSource(e)||``,ast:(e=xo)=>JC.call(this,e),errors:(e=xo)=>YC.call(this,e),warnings:(e=xo)=>XC.call(this,e),tokens:(e=xo)=>ZC.call(this,e),rawDb:(e=xo)=>QC.call(this,e),publicSymbolTable:(e=xo)=>$C.call(this,e)},this.container={stack:this.localQuery(LC),token:this.localQuery(RC),element:this.localQuery(zC),scope:this.localQuery(BC),scopeKind:this.localQuery(VC)},this.explicitModules=t,this.explicitDialect=n,this.dialect=n??{}}getSource(e){return this.layout.getSource(e)}lexerOptions(){return this.explicitDialect?this.explicitDialect.lexer??{}:LT}parserOptions(e){return this.explicitDialect?this.explicitDialect.parser??{}:{allowBodylessElement:e===`arch`}}scanFile(e,t){let n=this.layout.getSource(e)??``,r=e.intern(),i=this.fileScans.get(r);if(i&&i.source===n)return i.scan;let a=Zy(t??new Wy(n,e,LT).lex().getValue());return this.fileScans.set(r,{source:n,scan:a}),a}fileKind(e){return this.decideKind(e).kind}fileKindForParse(e,t){let n=this.decideKind(e,t);return this.fileKinds.set(e.intern(),{filepath:e,...n}),n.kind}parsedFileKind(e){return this.fileKinds.get(e.intern())?.kind??this.fileKind(e)}decideKind(e,t){let n=this.scanFile(e,t);return Qy(n,()=>n.usePaths.flatMap(t=>{let n=this.layout.resolveFileSpecifier(e,t);return n?[this.scanFile(n)]:[]}))}refreshFileKind(e){let t=e.intern(),n=this.fileKinds.get(t);if(!n)return;let r=this.decideKind(e);r.kind!==n.kind&&(this.localCache.delete(t),this.globalCache.clear(),this.fileKinds.set(t,{filepath:e,...r}))}cleanStaleLocalCache(e){let t=this.layout.getSource(e),n=e.absolute,r=this.sourceSnapshot.get(n);if(r!==void 0)if(r!==t){this.localCache.delete(e.intern()),this.globalCache.clear(),this.sourceSnapshot.set(n,t);for(let{filepath:e}of[...this.fileKinds.values()])this.refreshFileKind(e)}else this.fileKinds.get(e.intern())?.dependsOnImports&&this.refreshFileKind(e);else this.sourceSnapshot.set(n,t)}cleanStaleGlobalCache(){let e=this.layout.getEntrypoints(),t=!1;this.entrypointsSnapshot!==void 0&&(this.entrypointsSnapshot.length!==e.length||this.entrypointsSnapshot.some((t,n)=>t.absolute!==e[n].absolute))&&(t=!0),this.entrypointsSnapshot=e;for(let t of KC(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?ag(n[0]):n.map(e=>ag(e)).join(`\0`),a=r.get(i);if(a){if(a===RT)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,RT);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 F?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?ag(n[0]):n.map(e=>ag(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===RT)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,RT);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}initMonacoServices(e){let t=e?.autocompletion?.triggerCharacters??[];return{definitionProvider:new oS(this),referenceProvider:new cS(this),autocompletionProvider:new tC(this,{triggerCharacters:t}),diagnosticsProvider:new sS(this),codeActionProvider:new aS(this)}}},BT=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}resolveFileSpecifier(e,t){if(!ho.isRelative(t))return;let n=ho.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:ho.from(n.absolute+`.dbml`)}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(ho.from)}getEntrypoints(){return[...this.files.keys()].map(ho.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ARCH_DIAGRAM_TYPES=Gy,exports.ArrayNode=jm,exports.AttributeNode=R,exports.BUILTIN_KINDS=Zm,exports.BlockExpressionNode=H,exports.CARDINALITY_MANY=nf,exports.CARDINALITY_MAYBE=ef,exports.CARDINALITY_ONE=$d,exports.CARDINALITY_SOME=tf,exports.CallExpressionNode=Tm,exports.CommaExpressionNode=Cm,exports.CompileError=C,exports.CompileErrorCode=S,exports.Compiler=zT,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=aS,exports.DBMLCompletionItemProvider=tC,exports.DBMLDefinitionProvider=oS,exports.DBMLDiagnosticsProvider=sS,exports.DBMLReferencesProvider=cS,exports.DEFAULT_ENTRY=xo,exports.ElementDeclarationNode=L,exports.ElementKind=r,exports.EmptyNode=Am,exports.FALSY_VALUES=yp,exports.Filepath=ho,exports.FunctionApplicationNode=V,exports.FunctionExpressionNode=xm,exports.GroupExpressionNode=wm,exports.ICON_ALIAS=qm,exports.ICON_NAMES=Km,exports.IdentifierStreamNode=ym,exports.InfixExpressionNode=B,exports.ListExpressionNode=U,exports.LiteralNode=Em,exports.MarkerSeverity=nS,exports.MemoryProjectLayout=BT,exports.MetadataKind=Ph,exports.PostfixExpressionNode=bm,exports.PrefixExpressionNode=z,exports.PrimaryExpressionNode=km,exports.ProgramNode=I,exports.RESERVED=nh,exports.ScopeKind=Q,exports.SymbolKind=P,exports.SyntaxNode=F,exports.SyntaxNodeIdGenerator=mm,exports.SyntaxNodeKind=hm,exports.SyntaxToken=Ha,exports.SyntaxTokenKind=_,exports.TRUTHY_VALUES=vp,exports.TupleExpressionNode=Sm,exports.UNHANDLED=t,exports.Uri=Gx,exports.UseDeclarationNode=gm,exports.UseSpecifierListNode=vm,exports.UseSpecifierNode=_m,exports.VariableNode=Om,exports.WildcardNode=Dm,exports.addDoubleQuoteIfNeeded=Vv,exports.dbmlLanguageConfig=FC,exports.dbmlModules=Ny,exports.dbmlMonarchTokensProvider=IC,exports.escapeString=Wv,exports.extractNumericLiteral=cp,exports.extractSignedNumber=hp,exports.findDiagramViewBlocks=hT,exports.formatRecordValue=Gv,exports.getMultiplicities=of,exports.getRecordValueType=Ro,exports.getRelationshipOp=ff,exports.isArchDiagramType=Ky,exports.isBinaryType=Fo,exports.isBooleanType=No,exports.isDateTimeType=Io,exports.isEmptyStringLiteral=pp,exports.isEndpointManySide=cf,exports.isEndpointOneSide=sf,exports.isEndpointOptional=lf,exports.isEndpointRequired=uf,exports.isFloatType=jo,exports.isFunctionExpression=mp,exports.isIconName=Xm,exports.isIntegerType=Ao,exports.isNullish=fp,exports.isNumericType=Mo,exports.isOp=Ba,exports.isOpToken=Va,exports.isReserved=ih,exports.isSerialType=Lo,exports.isStringType=Po,exports.isTriviaToken=za,exports.isValidIdentifier=Bv,exports.makeCardinalityOptional=pf,exports.makeCardinalityRequired=mf,exports.makeRelationshipRequired=df,exports.normalizeQualifiedName=Hv,exports.normalizeTypeName=ko,exports.parseCardinality=Qd,exports.resolveIcon=Jm,exports.splitQualifiedIdentifier=Kv,exports.suggestIcon=ah,exports.suggestKind=eh,exports.tryExtractBoolean=bp,exports.tryExtractDateTime=Ep,exports.tryExtractEnum=xp,exports.tryExtractInteger=_p,exports.tryExtractNumeric=gp,exports.tryExtractString=Sp,exports.unescapeString=Uv,exports.validateForeignKeys=p_,exports.validatePrimaryKey=r_,exports.validateUnique=l_;