@dbml/parse 6.4.0 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/dist/__tests__/examples/binder/binder.test.d.ts +0 -0
- package/dist/__tests__/examples/binder/records.test.d.ts +0 -0
- package/dist/__tests__/examples/compiler/applyTextEdits.test.d.ts +0 -0
- package/dist/__tests__/examples/compiler/identifierUtils.test.d.ts +0 -0
- package/dist/__tests__/examples/compiler/renameTable.test.d.ts +0 -0
- package/dist/__tests__/examples/compiler/splitQualifiedIdentifier.test.d.ts +0 -0
- package/dist/__tests__/examples/compiler/stringUtils.test.d.ts +0 -0
- package/dist/__tests__/examples/compiler/syncDiagramView.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/interpreter.test.d.ts +0 -0
- package/dist/__tests__/examples/interpreter/record/data.test.d.ts +0 -0
- package/dist/__tests__/examples/interpreter/record/fk.test.d.ts +0 -0
- package/dist/__tests__/examples/interpreter/record/increment.test.d.ts +0 -0
- package/dist/__tests__/examples/interpreter/record/multi_records.test.d.ts +0 -0
- package/dist/__tests__/examples/interpreter/record/pk.test.d.ts +0 -0
- package/dist/__tests__/examples/interpreter/record/table_partial.test.d.ts +0 -0
- package/dist/__tests__/examples/interpreter/record/type_compatibility.test.d.ts +0 -0
- package/dist/__tests__/examples/interpreter/record/unique.test.d.ts +0 -0
- package/dist/__tests__/examples/lexer/lexer.test.d.ts +0 -0
- package/dist/__tests__/examples/lexer/scientific-notation.test.d.ts +0 -0
- package/dist/__tests__/examples/parser/parser.test.d.ts +0 -0
- package/dist/__tests__/examples/services/definition/general.test.d.ts +0 -0
- package/dist/__tests__/examples/services/definition/records.test.d.ts +0 -0
- package/dist/__tests__/examples/services/references/general.test.d.ts +0 -0
- package/dist/__tests__/examples/services/references/records.test.d.ts +0 -0
- package/dist/__tests__/examples/services/service_utils.test.d.ts +0 -0
- package/dist/__tests__/examples/services/suggestions/general.test.d.ts +0 -0
- package/dist/__tests__/examples/services/suggestions/suggestions_diagramview.test.d.ts +1 -0
- package/dist/__tests__/examples/services/suggestions/suggestions_records.test.d.ts +0 -0
- package/dist/__tests__/examples/validator/records.test.d.ts +0 -0
- package/dist/__tests__/examples/validator/validator.test.d.ts +0 -0
- package/dist/__tests__/fuzz/interpreter.test.d.ts +0 -0
- package/dist/__tests__/fuzz/parser.test.d.ts +0 -0
- package/dist/__tests__/fuzz/services.test.d.ts +0 -0
- package/dist/__tests__/properties/lexer.test.d.ts +0 -0
- package/dist/__tests__/properties/parser.test.d.ts +0 -0
- package/dist/__tests__/snapshots/binder/binder.test.d.ts +0 -0
- package/dist/__tests__/snapshots/interpreter/interpreter.test.d.ts +0 -0
- package/dist/__tests__/snapshots/lexer/lexer.test.d.ts +0 -0
- package/dist/__tests__/snapshots/nan/nan.test.d.ts +0 -0
- package/dist/__tests__/snapshots/parser/parser.test.d.ts +0 -0
- package/dist/__tests__/snapshots/validator/validator.test.d.ts +0 -0
- package/dist/__tests__/utils/arbitraries/grammars.d.ts +1 -1
- package/dist/__tests__/utils/arbitraries/index.d.ts +0 -0
- package/dist/__tests__/utils/arbitraries/tokens.d.ts +0 -0
- package/dist/__tests__/utils/arbitraries/utils.d.ts +0 -0
- package/dist/__tests__/utils/compiler.d.ts +0 -0
- package/dist/__tests__/utils/index.d.ts +0 -0
- package/dist/__tests__/utils/mocks.d.ts +0 -0
- package/dist/__tests__/utils/testHelpers.d.ts +0 -0
- package/dist/dbml-parse.js +17 -11
- package/dist/dbml-parse.mjs +706 -13
- package/dist/index.d.ts +0 -0
- package/dist/src/compiler/index.d.ts +0 -0
- package/dist/src/compiler/queries/container/element.d.ts +0 -0
- package/dist/src/compiler/queries/container/index.d.ts +0 -0
- package/dist/src/compiler/queries/container/scope.d.ts +0 -0
- package/dist/src/compiler/queries/container/scopeKind.d.ts +0 -0
- package/dist/src/compiler/queries/container/stack.d.ts +0 -0
- package/dist/src/compiler/queries/container/token.d.ts +0 -0
- package/dist/src/compiler/queries/parse.d.ts +0 -0
- package/dist/src/compiler/queries/symbol.d.ts +0 -0
- package/dist/src/compiler/queries/token.d.ts +0 -0
- package/dist/src/compiler/queries/transform/applyTextEdits.d.ts +0 -0
- package/dist/src/compiler/queries/transform/index.d.ts +0 -0
- package/dist/src/compiler/queries/transform/renameTable.d.ts +0 -0
- package/dist/src/compiler/queries/transform/syncDiagramView.d.ts +30 -0
- package/dist/src/compiler/queries/transform/utils.d.ts +0 -0
- package/dist/src/compiler/queries/utils.d.ts +0 -0
- package/dist/src/compiler/types.d.ts +2 -1
- package/dist/src/constants.d.ts +0 -0
- package/dist/src/core/analyzer/analyzer.d.ts +0 -0
- package/dist/src/core/analyzer/binder/binder.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/checks.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/custom.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/diagramView.d.ts +20 -0
- package/dist/src/core/analyzer/binder/elementBinder/enum.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/indexes.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/note.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/project.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/records.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/ref.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/table.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/tableGroup.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/tablePartial.d.ts +0 -0
- package/dist/src/core/analyzer/binder/types.d.ts +0 -0
- package/dist/src/core/analyzer/binder/utils.d.ts +2 -1
- package/dist/src/core/analyzer/symbol/factory.d.ts +0 -0
- package/dist/src/core/analyzer/symbol/symbolIndex.d.ts +5 -1
- package/dist/src/core/analyzer/symbol/symbolTable.d.ts +0 -0
- package/dist/src/core/analyzer/symbol/symbols.d.ts +26 -0
- package/dist/src/core/analyzer/symbol/utils.d.ts +0 -0
- package/dist/src/core/analyzer/types.d.ts +2 -1
- package/dist/src/core/analyzer/utils.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/checks.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/custom.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/diagramView.d.ts +25 -0
- package/dist/src/core/analyzer/validator/elementValidators/enum.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/indexes.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/note.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/project.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/records.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/ref.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/table.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/tableGroup.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/tablePartial.d.ts +0 -0
- package/dist/src/core/analyzer/validator/types.d.ts +0 -0
- package/dist/src/core/analyzer/validator/utils.d.ts +2 -1
- package/dist/src/core/analyzer/validator/validator.d.ts +0 -0
- package/dist/src/core/errors.d.ts +4 -0
- package/dist/src/core/interpreter/elementInterpreter/diagramView.d.ts +13 -0
- package/dist/src/core/interpreter/elementInterpreter/enum.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/project.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/ref.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/sticky_note.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/table.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/tableGroup.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/tablePartial.d.ts +0 -0
- package/dist/src/core/interpreter/interpreter.d.ts +0 -0
- package/dist/src/core/interpreter/records/index.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/constraints/fk.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/constraints/helper.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/constraints/index.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/constraints/pk.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/constraints/unique.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/data/index.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/data/sqlTypes.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/data/values.d.ts +0 -0
- package/dist/src/core/interpreter/records/utils/index.d.ts +0 -0
- package/dist/src/core/interpreter/types.d.ts +33 -0
- package/dist/src/core/interpreter/utils.d.ts +0 -0
- package/dist/src/core/lexer/lexer.d.ts +0 -0
- package/dist/src/core/lexer/tokens.d.ts +0 -0
- package/dist/src/core/lexer/utils.d.ts +0 -0
- package/dist/src/core/option.d.ts +0 -0
- package/dist/src/core/parser/contextStack.d.ts +0 -0
- package/dist/src/core/parser/factory.d.ts +0 -0
- package/dist/src/core/parser/nodes.d.ts +0 -0
- package/dist/src/core/parser/parser.d.ts +0 -0
- package/dist/src/core/parser/utils.d.ts +0 -0
- package/dist/src/core/report.d.ts +0 -0
- package/dist/src/core/types.d.ts +0 -0
- package/dist/src/core/utils.d.ts +0 -0
- package/dist/src/index.d.ts +4 -1
- package/dist/src/services/definition/provider.d.ts +0 -0
- package/dist/src/services/diagnostics/provider.d.ts +0 -0
- package/dist/src/services/index.d.ts +1 -0
- package/dist/src/services/monarch.d.ts +3 -0
- package/dist/src/services/references/provider.d.ts +0 -0
- package/dist/src/services/suggestions/provider.d.ts +0 -0
- package/dist/src/services/suggestions/recordRowSnippet.d.ts +0 -0
- package/dist/src/services/suggestions/utils.d.ts +0 -0
- package/dist/src/services/types.d.ts +0 -0
- package/dist/src/services/utils.d.ts +0 -0
- package/package.json +2 -3
package/dist/dbml-parse.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&&e(r,Symbol.toStringTag,{value:`Module`}),r},n=typeof global==`object`&&global&&global.Object===Object&&global,r=n,i=typeof self==`object`&&self&&self.Object===Object&&self,a=r||i||Function(`return this`)(),o=a,s=o.Symbol,c=s,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function ee(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 p=ee,te=Object.prototype.toString;function ne(e){return te.call(e)}var re=ne,ie=`[object Null]`,ae=`[object Undefined]`,oe=c?c.toStringTag:void 0;function se(e){return e==null?e===void 0?ae:ie:oe&&oe in Object(e)?p(e):re(e)}var ce=se;function le(e){return typeof e==`object`&&!!e}var ue=le,de=`[object Symbol]`;function fe(e){return typeof e==`symbol`||ue(e)&&ce(e)==de}var pe=fe;function me(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 he=me,ge=Array.isArray,_e=ge,ve=1/0,ye=c?c.prototype:void 0,be=ye?ye.toString:void 0;function xe(e){if(typeof e==`string`)return e;if(_e(e))return he(e,xe)+``;if(pe(e))return be?be.call(e):``;var t=e+``;return t==`0`&&1/e==-ve?`-0`:t}var Se=xe,Ce=/\s/;function we(e){for(var t=e.length;t--&&Ce.test(e.charAt(t)););return t}var Te=we,Ee=/^\s+/;function De(e){return e&&e.slice(0,Te(e)+1).replace(Ee,``)}var Oe=De;function ke(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var Ae=ke,je=NaN,Me=/^[-+]0x[0-9a-f]+$/i,Ne=/^0b[01]+$/i,Pe=/^0o[0-7]+$/i,Fe=parseInt;function Ie(e){if(typeof e==`number`)return e;if(pe(e))return je;if(Ae(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=Ae(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Oe(e);var n=Ne.test(e);return n||Pe.test(e)?Fe(e.slice(2),n?2:8):Me.test(e)?je:+e}var Le=Ie,Re=1/0,ze=17976931348623157e292;function Be(e){return e?(e=Le(e),e===Re||e===-Re?(e<0?-1:1)*ze:e===e?e:0):e===0?e:0}var Ve=Be;function He(e){var t=Ve(e),n=t%1;return t===t?n?t-n:t:0}var Ue=He;function We(e){return e}var Ge=We,Ke=`[object AsyncFunction]`,qe=`[object Function]`,Je=`[object GeneratorFunction]`,Ye=`[object Proxy]`;function Xe(e){if(!Ae(e))return!1;var t=ce(e);return t==qe||t==Je||t==Ke||t==Ye}var Ze=Xe,Qe=o[`__core-js_shared__`],$e=Qe,et=function(){var e=/[^.]+$/.exec($e&&$e.keys&&$e.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function tt(e){return!!et&&et in e}var nt=tt,rt=Function.prototype.toString;function it(e){if(e!=null){try{return rt.call(e)}catch{}try{return e+``}catch{}}return``}var at=it,ot=/[\\^$.*+?()[\]{}|]/g,st=/^\[object .+?Constructor\]$/,ct=Function.prototype,lt=Object.prototype,ut=ct.toString,dt=lt.hasOwnProperty,ft=RegExp(`^`+ut.call(dt).replace(ot,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function pt(e){return!Ae(e)||nt(e)?!1:(Ze(e)?ft:st).test(at(e))}var mt=pt;function ht(e,t){return e?.[t]}var gt=ht;function _t(e,t){var n=gt(e,t);return mt(n)?n:void 0}var vt=_t,yt=vt(o,`WeakMap`),bt=yt;function xt(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var St=xt;function Ct(){}var wt=Ct,Tt=800,Et=16,Dt=Date.now;function Ot(e){var t=0,n=0;return function(){var r=Dt(),i=Et-(r-n);if(n=r,i>0){if(++t>=Tt)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var kt=Ot;function At(e){return function(){return e}}var jt=At,Mt=function(){try{var e=vt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Nt=Mt,Pt=Nt?function(e,t){return Nt(e,`toString`,{configurable:!0,enumerable:!1,value:jt(t),writable:!0})}:Ge,Ft=Pt,It=kt(Ft),Lt=It;function Rt(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1}var zt=Rt;function Bt(e){return e!==e}var Vt=Bt;function Ht(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}var Ut=Ht;function Wt(e,t,n){return t===t?Ut(e,t,n):zt(e,Vt,n)}var Gt=Wt;function Kt(e,t){return!!(e!=null&&e.length)&&Gt(e,t,0)>-1}var qt=Kt,Jt=9007199254740991,Yt=/^(?:0|[1-9]\d*)$/;function Xt(e,t){var n=typeof e;return t??=Jt,!!t&&(n==`number`||n!=`symbol`&&Yt.test(e))&&e>-1&&e%1==0&&e<t}var Zt=Xt;function Qt(e,t,n){t==`__proto__`&&Nt?Nt(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var $t=Qt;function en(e,t){return e===t||e!==e&&t!==t}var tn=en,nn=Math.max;function rn(e,t,n){return t=nn(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=nn(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),St(e,this,s)}}var an=rn;function on(e,t){return Lt(an(e,t,Ge),e+``)}var sn=on,cn=9007199254740991;function ln(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=cn}var un=ln;function dn(e){return e!=null&&un(e.length)&&!Ze(e)}var fn=dn,pn=Object.prototype;function mn(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||pn)}var hn=mn;function gn(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var _n=gn,vn=`[object Arguments]`;function yn(e){return ue(e)&&ce(e)==vn}var bn=yn,xn=Object.prototype,Sn=xn.hasOwnProperty,Cn=xn.propertyIsEnumerable,wn=bn(function(){return arguments}())?bn:function(e){return ue(e)&&Sn.call(e,`callee`)&&!Cn.call(e,`callee`)},Tn=wn;function En(){return!1}var Dn=En,On=typeof exports==`object`&&exports&&!exports.nodeType&&exports,kn=On&&typeof module==`object`&&module&&!module.nodeType&&module,An=kn&&kn.exports===On?o.Buffer:void 0,jn=(An?An.isBuffer:void 0)||Dn,Mn=jn,Nn=`[object Arguments]`,Pn=`[object Array]`,Fn=`[object Boolean]`,In=`[object Date]`,Ln=`[object Error]`,Rn=`[object Function]`,zn=`[object Map]`,Bn=`[object Number]`,Vn=`[object Object]`,Hn=`[object RegExp]`,Un=`[object Set]`,Wn=`[object String]`,Gn=`[object WeakMap]`,Kn=`[object ArrayBuffer]`,qn=`[object DataView]`,Jn=`[object Float32Array]`,Yn=`[object Float64Array]`,Xn=`[object Int8Array]`,Zn=`[object Int16Array]`,Qn=`[object Int32Array]`,$n=`[object Uint8Array]`,er=`[object Uint8ClampedArray]`,tr=`[object Uint16Array]`,nr=`[object Uint32Array]`,m={};m[Jn]=m[Yn]=m[Xn]=m[Zn]=m[Qn]=m[$n]=m[er]=m[tr]=m[nr]=!0,m[Nn]=m[Pn]=m[Kn]=m[Fn]=m[qn]=m[In]=m[Ln]=m[Rn]=m[zn]=m[Bn]=m[Vn]=m[Hn]=m[Un]=m[Wn]=m[Gn]=!1;function rr(e){return ue(e)&&un(e.length)&&!!m[ce(e)]}var ir=rr;function ar(e){return function(t){return e(t)}}var or=ar,sr=typeof exports==`object`&&exports&&!exports.nodeType&&exports,cr=sr&&typeof module==`object`&&module&&!module.nodeType&&module,lr=cr&&cr.exports===sr&&r.process,ur=function(){try{return cr&&cr.require&&cr.require(`util`).types||lr&&lr.binding&&lr.binding(`util`)}catch{}}(),dr=ur,fr=dr&&dr.isTypedArray,pr=fr?or(fr):ir,mr=pr,hr=Object.prototype.hasOwnProperty;function gr(e,t){var n=_e(e),r=!n&&Tn(e),i=!n&&!r&&Mn(e),a=!n&&!r&&!i&&mr(e),o=n||r||i||a,s=o?_n(e.length,String):[],c=s.length;for(var l in e)(t||hr.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||Zt(l,c)))&&s.push(l);return s}var _r=gr;function vr(e,t){return function(n){return e(t(n))}}var yr=vr,br=yr(Object.keys,Object),xr=br,Sr=Object.prototype.hasOwnProperty;function Cr(e){if(!hn(e))return xr(e);var t=[];for(var n in Object(e))Sr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var wr=Cr;function Tr(e){return fn(e)?_r(e):wr(e)}var Er=Tr;function Dr(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Or=Dr,kr=Object.prototype.hasOwnProperty;function Ar(e){if(!Ae(e))return Or(e);var t=hn(e),n=[];for(var r in e)r==`constructor`&&(t||!kr.call(e,r))||n.push(r);return n}var jr=Ar;function Mr(e){return fn(e)?_r(e,!0):jr(e)}var Nr=Mr,Pr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Fr=/^\w*$/;function Ir(e,t){if(_e(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||pe(e)?!0:Fr.test(e)||!Pr.test(e)||t!=null&&e in Object(t)}var Lr=Ir,Rr=vt(Object,`create`),zr=Rr;function Br(){this.__data__=zr?zr(null):{},this.size=0}var Vr=Br;function Hr(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Ur=Hr,Wr=`__lodash_hash_undefined__`,Gr=Object.prototype.hasOwnProperty;function Kr(e){var t=this.__data__;if(zr){var n=t[e];return n===Wr?void 0:n}return Gr.call(t,e)?t[e]:void 0}var qr=Kr,Jr=Object.prototype.hasOwnProperty;function Yr(e){var t=this.__data__;return zr?t[e]!==void 0:Jr.call(t,e)}var Xr=Yr,Zr=`__lodash_hash_undefined__`;function Qr(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=zr&&t===void 0?Zr:t,this}var $r=Qr;function ei(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])}}ei.prototype.clear=Vr,ei.prototype.delete=Ur,ei.prototype.get=qr,ei.prototype.has=Xr,ei.prototype.set=$r;var ti=ei;function ni(){this.__data__=[],this.size=0}var ri=ni;function ii(e,t){for(var n=e.length;n--;)if(tn(e[n][0],t))return n;return-1}var ai=ii,oi=Array.prototype.splice;function si(e){var t=this.__data__,n=ai(t,e);return n<0?!1:(n==t.length-1?t.pop():oi.call(t,n,1),--this.size,!0)}var ci=si;function li(e){var t=this.__data__,n=ai(t,e);return n<0?void 0:t[n][1]}var ui=li;function di(e){return ai(this.__data__,e)>-1}var fi=di;function pi(e,t){var n=this.__data__,r=ai(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var mi=pi;function hi(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])}}hi.prototype.clear=ri,hi.prototype.delete=ci,hi.prototype.get=ui,hi.prototype.has=fi,hi.prototype.set=mi;var gi=hi,_i=vt(o,`Map`),vi=_i;function yi(){this.size=0,this.__data__={hash:new ti,map:new(vi||gi),string:new ti}}var bi=yi;function xi(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var Si=xi;function Ci(e,t){var n=e.__data__;return Si(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var wi=Ci;function Ti(e){var t=wi(this,e).delete(e);return this.size-=t?1:0,t}var Ei=Ti;function Di(e){return wi(this,e).get(e)}var Oi=Di;function ki(e){return wi(this,e).has(e)}var Ai=ki;function ji(e,t){var n=wi(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var Mi=ji;function Ni(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])}}Ni.prototype.clear=bi,Ni.prototype.delete=Ei,Ni.prototype.get=Oi,Ni.prototype.has=Ai,Ni.prototype.set=Mi;var Pi=Ni,Fi=`Expected a function`;function Ii(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(Fi);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(Ii.Cache||Pi),n}Ii.Cache=Pi;var Li=Ii,Ri=500;function zi(e){var t=Li(e,function(e){return n.size===Ri&&n.clear(),e}),n=t.cache;return t}var Bi=zi,Vi=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Hi=/\\(\\)?/g,Ui=Bi(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(Vi,function(e,n,r,i){t.push(r?i.replace(Hi,`$1`):n||e)}),t}),Wi=Ui;function Gi(e){return e==null?``:Se(e)}var Ki=Gi;function qi(e,t){return _e(e)?e:Lr(e,t)?[e]:Wi(Ki(e))}var Ji=qi,Yi=1/0;function Xi(e){if(typeof e==`string`||pe(e))return e;var t=e+``;return t==`0`&&1/e==-Yi?`-0`:t}var Zi=Xi;function Qi(e,t){t=Ji(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[Zi(t[n++])];return n&&n==r?e:void 0}var $i=Qi;function ea(e,t,n){var r=e==null?void 0:$i(e,t);return r===void 0?n:r}var ta=ea;function na(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var ra=na,ia=c?c.isConcatSpreadable:void 0;function aa(e){return _e(e)||Tn(e)||!!(ia&&e&&e[ia])}var oa=aa;function sa(e,t,n,r,i){var a=-1,o=e.length;for(n||=oa,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?sa(s,t-1,n,r,i):ra(i,s):r||(i[i.length]=s)}return i}var ca=sa;function la(e){return e!=null&&e.length?ca(e,1):[]}var ua=la;function da(){this.__data__=new gi,this.size=0}var fa=da;function pa(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var ma=pa;function ha(e){return this.__data__.get(e)}var ga=ha;function _a(e){return this.__data__.has(e)}var va=_a,ya=200;function ba(e,t){var n=this.__data__;if(n instanceof gi){var r=n.__data__;if(!vi||r.length<ya-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Pi(r)}return n.set(e,t),this.size=n.size,this}var xa=ba;function Sa(e){this.size=(this.__data__=new gi(e)).size}Sa.prototype.clear=fa,Sa.prototype.delete=ma,Sa.prototype.get=ga,Sa.prototype.has=va,Sa.prototype.set=xa;var Ca=Sa;function wa(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}var Ta=wa;function Ea(){return[]}var Da=Ea,Oa=Object.prototype.propertyIsEnumerable,ka=Object.getOwnPropertySymbols,Aa=ka?function(e){return e==null?[]:(e=Object(e),Ta(ka(e),function(t){return Oa.call(e,t)}))}:Da,ja=Aa;function Ma(e,t,n){var r=t(e);return _e(e)?r:ra(r,n(e))}var Na=Ma;function Pa(e){return Na(e,Er,ja)}var Fa=Pa,Ia=vt(o,`DataView`),La=Ia,Ra=vt(o,`Promise`),za=Ra,Ba=vt(o,`Set`),Va=Ba,Ha=`[object Map]`,Ua=`[object Object]`,Wa=`[object Promise]`,Ga=`[object Set]`,Ka=`[object WeakMap]`,qa=`[object DataView]`,Ja=at(La),Ya=at(vi),Xa=at(za),Za=at(Va),Qa=at(bt),$a=ce;(La&&$a(new La(new ArrayBuffer(1)))!=qa||vi&&$a(new vi)!=Ha||za&&$a(za.resolve())!=Wa||Va&&$a(new Va)!=Ga||bt&&$a(new bt)!=Ka)&&($a=function(e){var t=ce(e),n=t==Ua?e.constructor:void 0,r=n?at(n):``;if(r)switch(r){case Ja:return qa;case Ya:return Ha;case Xa:return Wa;case Za:return Ga;case Qa:return Ka}return t});var eo=$a,to=o.Uint8Array,no=to;function ro(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 io=ro,ao=`__lodash_hash_undefined__`;function oo(e){return this.__data__.set(e,ao),this}var so=oo;function co(e){return this.__data__.has(e)}var lo=co;function uo(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Pi;++t<n;)this.add(e[t])}uo.prototype.add=uo.prototype.push=so,uo.prototype.has=lo;var fo=uo;function po(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}var mo=po;function ho(e,t){return e.has(t)}var go=ho,_o=1,vo=2;function yo(e,t,n,r,i,a){var o=n&_o,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,ee=n&vo?new fo:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var p=e[d],te=t[d];if(r)var ne=o?r(te,p,d,t,e,a):r(p,te,d,e,t,a);if(ne!==void 0){if(ne)continue;f=!1;break}if(ee){if(!mo(t,function(e,t){if(!go(ee,t)&&(p===e||i(p,e,n,r,a)))return ee.push(t)})){f=!1;break}}else if(!(p===te||i(p,te,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var bo=yo;function xo(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var So=xo;function Co(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var wo=Co,To=1,Eo=2,Do=`[object Boolean]`,Oo=`[object Date]`,ko=`[object Error]`,Ao=`[object Map]`,jo=`[object Number]`,Mo=`[object RegExp]`,No=`[object Set]`,Po=`[object String]`,Fo=`[object Symbol]`,Io=`[object ArrayBuffer]`,Lo=`[object DataView]`,Ro=c?c.prototype:void 0,zo=Ro?Ro.valueOf:void 0;function Bo(e,t,n,r,i,a,o){switch(n){case Lo:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Io:return!(e.byteLength!=t.byteLength||!a(new no(e),new no(t)));case Do:case Oo:case jo:return tn(+e,+t);case ko:return e.name==t.name&&e.message==t.message;case Mo:case Po:return e==t+``;case Ao:var s=So;case No:var c=r&To;if(s||=wo,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Eo,o.set(e,t);var u=bo(s(e),s(t),r,i,a,o);return o.delete(e),u;case Fo:if(zo)return zo.call(e)==zo.call(t)}return!1}var Vo=Bo,Ho=1,Uo=Object.prototype.hasOwnProperty;function Wo(e,t,n,r,i,a){var o=n&Ho,s=Fa(e),c=s.length;if(c!=Fa(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Uo.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var ee=!0;a.set(e,t),a.set(t,e);for(var p=o;++l<c;){u=s[l];var te=e[u],ne=t[u];if(r)var re=o?r(ne,te,u,t,e,a):r(te,ne,u,e,t,a);if(!(re===void 0?te===ne||i(te,ne,n,r,a):re)){ee=!1;break}p||=u==`constructor`}if(ee&&!p){var ie=e.constructor,ae=t.constructor;ie!=ae&&`constructor`in e&&`constructor`in t&&!(typeof ie==`function`&&ie instanceof ie&&typeof ae==`function`&&ae instanceof ae)&&(ee=!1)}return a.delete(e),a.delete(t),ee}var Go=Wo,Ko=1,qo=`[object Arguments]`,Jo=`[object Array]`,Yo=`[object Object]`,Xo=Object.prototype.hasOwnProperty;function Zo(e,t,n,r,i,a){var o=_e(e),s=_e(t),c=o?Jo:eo(e),l=s?Jo:eo(t);c=c==qo?Yo:c,l=l==qo?Yo:l;var u=c==Yo,d=l==Yo,f=c==l;if(f&&Mn(e)){if(!Mn(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Ca,o||mr(e)?bo(e,t,n,r,i,a):Vo(e,t,c,n,r,i,a);if(!(n&Ko)){var ee=u&&Xo.call(e,`__wrapped__`),p=d&&Xo.call(t,`__wrapped__`);if(ee||p){var te=ee?e.value():e,ne=p?t.value():t;return a||=new Ca,i(te,ne,n,r,a)}}return f?(a||=new Ca,Go(e,t,n,r,i,a)):!1}var Qo=Zo;function $o(e,t,n,r,i){return e===t?!0:e==null||t==null||!ue(e)&&!ue(t)?e!==e&&t!==t:Qo(e,t,n,r,$o,i)}var es=$o,ts=1,ns=2;function rs(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 Ca;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?es(u,l,ts|ns,r,d):f))return!1}}return!0}var is=rs;function as(e){return e===e&&!Ae(e)}var os=as;function ss(e){for(var t=Er(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,os(i)]}return t}var cs=ss;function ls(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var us=ls;function ds(e){var t=cs(e);return t.length==1&&t[0][2]?us(t[0][0],t[0][1]):function(n){return n===e||is(n,e,t)}}var fs=ds;function ps(e,t){return e!=null&&t in Object(e)}var ms=ps;function hs(e,t,n){t=Ji(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=Zi(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&&un(i)&&Zt(o,i)&&(_e(e)||Tn(e)))}var gs=hs;function _s(e,t){return e!=null&&gs(e,t,ms)}var vs=_s,ys=1,bs=2;function xs(e,t){return Lr(e)&&os(t)?us(Zi(e),t):function(n){var r=ta(n,e);return r===void 0&&r===t?vs(n,e):es(t,r,ys|bs)}}var Ss=xs;function Cs(e){return function(t){return t?.[e]}}var ws=Cs;function Ts(e){return function(t){return $i(t,e)}}var Es=Ts;function Ds(e){return Lr(e)?ws(Zi(e)):Es(e)}var Os=Ds;function ks(e){return typeof e==`function`?e:e==null?Ge:typeof e==`object`?_e(e)?Ss(e[0],e[1]):fs(e):Os(e)}var As=ks;function js(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}var Ms=js;function Ns(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 Ps=Ns,Fs=Ps(),Is=Fs;function Ls(e,t){return e&&Is(e,t,Er)}var Rs=Ls;function zs(e,t){return function(n,r){if(n==null)return n;if(!fn(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 Bs=zs,Vs=Bs(Rs),Hs=Vs;function Us(e,t,n,r){return Hs(e,function(e,i,a){t(r,e,n(e),a)}),r}var Ws=Us;function Gs(e,t){return function(n,r){var i=_e(n)?Ms:Ws,a=t?t():{};return i(n,e,As(r,2),a)}}var Ks=Gs;function qs(e){return ue(e)&&fn(e)}var Js=qs;function Ys(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 Xs=Ys,Zs=200;function Qs(e,t,n,r){var i=-1,a=qt,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=he(t,or(n))),r?(a=Xs,o=!1):t.length>=Zs&&(a=go,o=!1,t=new fo(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 $s=Qs,ec=sn(function(e,t){return Js(e)?$s(e,ca(t,1,Js,!0)):[]}),tc=ec;function nc(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var h=nc;function rc(e){return typeof e==`function`?e:Ge}var ic=rc;function ac(e,t){var n=[];return Hs(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}var oc=ac;function sc(e,t){return(_e(e)?Ta:oc)(e,As(t,3))}var cc=sc,lc=Math.max,uc=Math.min;function dc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=Ue(n),i=n<0?lc(r+i,0):uc(i,r-1)),zt(e,As(t,3),i,!0)}var fc=dc;function pc(e){return e&&e.length?e[0]:void 0}var mc=pc;function hc(e,t){var n=-1,r=fn(e)?Array(e.length):[];return Hs(e,function(e,i,a){r[++n]=t(e,i,a)}),r}var gc=hc;function _c(e,t){return(_e(e)?he:gc)(e,As(t,3))}var vc=_c;function yc(e,t){return ca(vc(e,t),1)}var bc=yc;function xc(e,t){return e==null?e:Is(e,ic(t),Nr)}var Sc=xc,Cc=Object.prototype.hasOwnProperty,wc=Ks(function(e,t,n){Cc.call(e,n)?e[n].push(t):$t(e,n,[t])}),Tc=wc,Ec=`[object Map]`,Dc=`[object Set]`,Oc=Object.prototype.hasOwnProperty;function kc(e){if(e==null)return!0;if(fn(e)&&(_e(e)||typeof e==`string`||typeof e.splice==`function`||Mn(e)||mr(e)||Tn(e)))return!e.length;var t=eo(e);if(t==Ec||t==Dc)return!e.size;if(hn(e))return!wr(e).length;for(var n in e)if(Oc.call(e,n))return!1;return!0}var Ac=kc,jc=Ks(function(e,t,n){$t(e,n,t)}),Mc=jc,Nc=Ks(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),g=Nc,Pc=Va&&1/wo(new Va([,-0]))[1]==1/0?function(e){return new Va(e)}:wt,Fc=Pc,Ic=200;function Lc(e,t,n){var r=-1,i=qt,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=Xs;else if(a>=Ic){var l=t?null:Fc(e);if(l)return wo(l);o=!1,i=go,c=new fo}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}var Rc=Lc;function zc(e,t){return e&&e.length?Rc(e,As(t,2)):[]}var Bc=zc,Vc=Math.max;function Hc(e){if(!(e&&e.length))return[];var t=0;return e=Ta(e,function(e){if(Js(e))return t=Vc(e.length,t),!0}),_n(t,function(t){return he(e,ws(t))})}var Uc=Hc,Wc=sn(Uc),Gc=Wc;let _=function(e){return e.SPACE=`<space>`,e.TAB=`<tab>`,e.NEWLINE=`<newline>`,e.COMMA=`<comma>`,e.LPAREN=`<lparen>`,e.RPAREN=`<rparen>`,e.LBRACE=`<lbrace>`,e.RBRACE=`<rbrace>`,e.LBRACKET=`<lbracket>`,e.RBRACKET=`<rbracket>`,e.LANGLE=`<langle>`,e.RANGLE=`<rangle>`,e.OP=`<op>`,e.EOF=`<eof>`,e.NUMERIC_LITERAL=`<number>`,e.STRING_LITERAL=`<string>`,e.COLOR_LITERAL=`<color>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.QUOTED_STRING=`<variable>`,e.IDENTIFIER=`<identifier>`,e.SEMICOLON=`<semicolon>`,e.COLON=`<colon>`,e.SINGLE_LINE_COMMENT=`<single-line-comment>`,e.MULTILINE_COMMENT=`<multiline-comment>`,e}({});function Kc(e){switch(e.kind){case _.NEWLINE:case _.SPACE:case _.TAB:case _.SINGLE_LINE_COMMENT:case _.MULTILINE_COMMENT:return!0;default:return!1}}function qc(e){if(!e)return!1;switch(e){case`+`:case`-`:case`*`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function Jc(e){return e!==void 0&&e.kind===_.OP}var Yc=class e{constructor(e,t,n,r,i){this.kind=e,this.startPos=t,this.endPos=n,this.value=r,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=i,this.start=t.offset,this.end=n.offset}static create(t,n,r,i,a){return new e(t,n,r,i,a)}};function Xc(e){return e.trailingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0}function Zc(e,t){return t.leadingTrivia.find(({kind:e})=>e===_.NEWLINE)!==void 0||Xc(e)}function Qc(e){return e.trailingTrivia.find(({kind:e})=>[_.SPACE,_.TAB].includes(e))!==void 0}function $c(e){return e.trailingTrivia.length===0?e.end:$c(h(e.trailingTrivia))}function el(e){return e.leadingTrivia.length===0?e.start:el(e.leadingTrivia[0])}function tl(e){return[_.SINGLE_LINE_COMMENT,_.MULTILINE_COMMENT].includes(e.kind)}var nl=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},v=class{constructor(e,t,n){this.id=e,this.kind=t;let r=n.find(e=>e!==void 0&&!Number.isNaN(e.start));r?(this.startPos=r.startPos,this.fullStart=r instanceof Yc?el(r):r.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let i=[...n].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));i?(this.endPos=i.endPos,this.fullEnd=i instanceof Yc?$c(i):i.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}};let y=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifer-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}({});var b=class extends v{constructor({body:e=[],eof:t,source:n},r){super(r,y.PROGRAM,[...e,t]),this.source=n,this.body=e,this.eof=t}},x=class e extends v{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c){if(super(c,y.ELEMENT_DECLARATION,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof S||s instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.name=n,this.as=r,this.alias=i,this.attributeList=a,this.bodyColon=o,this.body=s}},rl=class extends v{constructor({identifiers:e=[]},t){super(t,y.IDENTIFIER_STREAM,e||[]),this.identifiers=e}},il=class extends v{constructor({name:e,colon:t,value:n},r){super(r,y.ATTRIBUTE,[e,t,n]),this.name=e,this.value=n,this.colon=t}},al=class extends v{constructor({op:e,expression:t},n){super(n,y.PREFIX_EXPRESSION,[e,t]),this.op=e,this.expression=t}},ol=class extends v{constructor({op:e,leftExpression:t,rightExpression:n},r){super(r,y.INFIX_EXPRESSION,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},sl=class extends v{constructor({op:e,expression:t},n){super(n,y.POSTFIX_EXPRESSION,[t,e]),this.op=e,this.expression=t}},cl=class extends v{constructor({value:e},t){super(t,y.FUNCTION_EXPRESSION,[e]),this.value=e}},S=class extends v{constructor({callee:e,args:t=[]},n){super(n,y.FUNCTION_APPLICATION,[e,...t]),this.callee=e,this.args=t}},C=class extends v{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r){super(r,y.BLOCK_EXPRESSION,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},w=class extends v{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i){super(i,y.LIST_EXPRESSION,[e,..._l(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},ll=class extends v{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i){super(i,y.TUPLE_EXPRESSION,[e,..._l(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},ul=class extends v{constructor({elementList:e=[],commaList:t=[]},n){super(n,y.COMMA_EXPRESSION,[..._l(e,t)]),this.elementList=e,this.commaList=t}},dl=class extends ll{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r),this.kind=y.GROUP_EXPRESSION}},T=class extends v{constructor({callee:e,argumentList:t},n){super(n,y.CALL_EXPRESSION,[e,t]),this.callee=e,this.argumentList=t}},fl=class extends v{constructor({literal:e},t){super(t,y.LITERAL,[e]),this.literal=e}},pl=class extends v{constructor({variable:e},t){super(t,y.VARIABLE,[e]),this.variable=e}},ml=class extends v{constructor({expression:e},t){super(t,y.PRIMARY_EXPRESSION,[e]),this.expression=e}},hl=class extends v{constructor({prevToken:e},t){let n=Yc.create(_.SPACE,e.endPos,e.endPos,` `,!1);super(t,y.EMPTY,[n])}},gl=class extends v{constructor({expression:e,indexer:t},n){super(n,y.ARRAY,[e,t]),this.array=e,this.indexer=t}};function _l(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?ua(Gc(e,t)):ua(Gc(t,e))).filter(e=>e!==null)}var vl=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},yl=class{constructor({symbolTable:e},t){this.references=[],this.id=t,this.symbolTable=e}},bl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},xl=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},Sl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Cl=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},wl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Tl=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},El=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Dl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Ol=class{constructor({declaration:e,tablePartialSymbol:t},n){this.references=[],this.id=n,this.declaration=e,this.tablePartialSymbol=t}};let E=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.INVALID_INDEXES_CONTEXT=3047]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3048]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3049]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3050]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3051]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3052]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3053]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3054]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3055]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3056]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3057]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3058]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3059]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3060]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3061]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3062]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3063]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3064]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3065]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3066]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3067]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3069]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3070]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3071]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3072]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3073]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3074]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3075]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3076]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3077]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3078]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3079]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3080]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3081]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.UNEQUAL_FIELDS_BINARY_REF=5003]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5004]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e}({});var D=class e extends Error{constructor(t,n,r){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new kl(this.code,this.message,this.nodeOrToken)}},kl=class extends Error{constructor(e,t,n){super(t),this.code=e,this.diagnostic=t,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,D.prototype)}},O=class e{constructor(e,t,n){this.value=e,this.errors=t===void 0?[]:t,n?.length&&(this.warnings=n)}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings||[]}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()];return new e(n.value,r,i)}map(t){return new e(t(this.value),this.errors,this.warnings)}};function Al(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function jl(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Ml(e){let[t]=e;return jl(t)||Al(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Nl(e){return Al(e)||jl(e)}function Pl(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 Fl(e,t){return e>=t.start&&e<t.end}function Il(e){return e instanceof al?`${e.op?.value}${Il(e.expression)}`:e.expression.literal.value}function Ll(e){return e instanceof al?e.op?.value===`-`?-Ll(e.expression):Ll(e.expression):Number.parseFloat(e.expression.literal.value)}var k=class e{constructor(e){this.value=e}unwrap(){return this.value}unwrap_or(e){return this.value}and_then(e){return e(this.value)}map(t){return new e(t(this.value))}isOk(){return!0}},A=class e{constructor(){this.value=void 0}unwrap(){throw Error(`Trying to unwrap a None value`)}unwrap_or(e){return e}and_then(t){return new e}map(t){return new e}isOk(){return!1}};const Rl=[`null`,`true`,`false`],zl=[`-`,`+`],Bl=`public`;let j=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Check=`checks`,e.Records=`records`,e}({}),M=function(e){return e.Color=`color`,e.HeaderColor=`headercolor`,e.Note=`note`,e.PK=`pk`,e.PrimaryKey=`primary key`,e.Unique=`unique`,e.Ref=`ref`,e.NotNull=`not null`,e.Null=`null`,e.Increment=`increment`,e.Default=`default`,e.Name=`name`,e.Type=`type`,e.Check=`check`,e.Update=`update`,e.Delete=`delete`,e}({});var Vl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b||Du(this.declarationNode.parent).unwrap_or(void 0)!==j.Project?[new D(E.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]:[]}validateName(e){return e?[new D(E.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new D(E.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new D(E.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof C)return[new D(E.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return Gu(e.callee)||t.push(new D(E.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 D(E.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};let N=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.Note=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e}({});function Hl(e){return`${N.Schema}:${e}`}function Ul(e){return`${N.Table}:${e}`}function Wl(e){return`${N.Column}:${e}`}function Gl(e){return`${N.Enum}:${e}`}function Kl(e){return`${N.EnumField}:${e}`}function ql(e){return`${N.TableGroup}:${e}`}function Jl(e){return`${N.TableGroupField}:${e}`}function Yl(e){return`${N.Note}:${e}`}function Xl(e){return`${N.TablePartial}:${e}`}function Zl(e){return`${N.PartialInjection}:${e}`}function Ql(e,t){switch(t){case N.Column:return Wl(e);case N.Enum:return Gl(e);case N.EnumField:return Kl(e);case N.Schema:return Hl(e);case N.Table:return Ul(e);case N.TableGroup:return ql(e);case N.TableGroupField:return Jl(e);case N.TablePartial:return Xl(e);case N.PartialInjection:return Zl(e);default:throw Error(`Unreachable`)}}function $l(e){let[t,n]=e.split(`:`);return Object.values(N).includes(t)?new k({name:n,kind:t}):new A}var eu=class{constructor(){this.table=new Map}has(e){return this.table.has(e)}set(e,t){this.table.set(e,t)}get(e,t){return this.table.get(e)||t!==void 0&&this.set(e,t)||t}entries(){return this.table.entries()}forEach(e){return this.table.forEach(e)}},tu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new D(E.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?mu(e)?[]:[new D(E.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new D(E.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(bl,{declaration:this.declarationNode,symbolTable:new eu});let{name:t}=this.declarationNode,n=F(t);if(n.isOk()){let r=n.unwrap(),i=r.pop(),a=vu(r,this.publicSymbolTable,this.symbolFactory),o=Gl(i);a.has(o)&&e.push(new D(E.DUPLICATE_NAME,`Enum name ${i} already exists in schema '${r.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}return e}validateSettingList(e){return e?[new D(E.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof S)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof S);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.length===0?[new D(E.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)]:e.flatMap(e=>{let t=[];e.callee&&!B(e.callee)&&t.push(new D(E.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,e.callee));let n=[...e.args];return h(n)instanceof w?(t.push(...this.validateFieldSettings(h(n))),n.pop()):n[0]instanceof w&&(t.push(...this.validateFieldSettings(n[0])),n.shift()),n.length>0&&t.push(...n.map(e=>new D(E.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e))),t.push(...this.registerField(e)),t})}validateFieldSettings(e){let t=P(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`note`:t.length>1&&t.forEach(e=>n.push(new D(E.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{Gu(e.value)||n.push(new D(E.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new D(E.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}registerField(e){if(e.callee&&B(e.callee)){let t=L(e.callee).unwrap(),n=Kl(t),r=this.symbolFactory.create(xl,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new D(E.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,e),new D(E.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,r.declaration)]}i.set(n,r)}return[]}},nu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}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 D(E.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof b)return[e];let t=Du(this.declarationNode.parent).unwrap_or(void 0);return t&&[j.Table,j.TablePartial].includes(t)?[]:[e]}validateName(e){return e?[new D(E.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new D(E.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof S)return[new D(E.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=g(e.body,e=>e instanceof S);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 T;)e.argumentList&&!Au(e.argumentList).isOk()&&t.push(new D(E.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;Au(e).isOk()||t.push(new D(E.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=P(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`note`:case`name`:t.length>1&&t.forEach(t=>n.push(new D(E.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Gu(t.value)||n.push(new D(E.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new D(E.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{xu(t.value)||n.push(new D(E.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new D(E.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{B(e.value)||n.push(new D(E.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new D(E.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},ru=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return!(this.declarationNode.parent instanceof b)&&![j.Table,j.TableGroup,j.TablePartial,j.Project].includes(Du(this.declarationNode.parent).unwrap_or(void 0))?[new D(E.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){if(!(this.declarationNode.parent instanceof b))return e?[new D(E.UNEXPECTED_NAME,`A Note shouldn't have a name`,e)]:[];if(!e)return[new D(E.INVALID_NAME,`Sticky note must have a name`,this.declarationNode)];let t=F(e);if(!t.isOk())return[new D(E.INVALID_NAME,`Invalid name for sticky note `,this.declarationNode)];let n=t.unwrap().join(`.`),r=Yl(n);return this.publicSymbolTable.has(r)?[new D(E.DUPLICATE_NAME,`Sticky note "${n}" has already been defined`,e)]:(this.publicSymbolTable.set(r,this.declarationNode.symbol),[])}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new D(E.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof S)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof S);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new D(E.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new D(E.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),Gu(e[0].callee)||t.push(new D(E.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 D(E.INVALID_NOTE,`A Note can only contain one quoted string`,e))),t)}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},iu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}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 x?[new D(E.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?gu(e)?[]:[new D(E.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new D(E.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof S)return[new D(E.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof S);return[...t.map(e=>new D(E.INVALID_PROJECT_FIELD,`A Project can not have inline fields`,e)),...this.validateSubElements(n)]}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},au=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b?[]:[new D(E.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?gu(e)?[]:[new D(E.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new D(E.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof S)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof S);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new D(E.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 D(E.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Nu(e.callee)&&t.push(new D(E.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Nu(e.callee)){let n=ku(e.callee.leftExpression).unwrap_or({variables:[],tupleElements:[]}),r=n.variables.length+Math.min(n.tupleElements.length,1),i=ku(e.callee.rightExpression).unwrap_or({variables:[],tupleElements:[]}),a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new D(E.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new D(E.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Pu(e.callee)&&t.push(new D(E.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 D(E.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){let t=P(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`delete`:case`update`:t.length>1&&t.forEach(t=>n.push(new D(E.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{ou(t.value)||n.push(new D(E.INVALID_REF_SETTING_VALUE,`'${e}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,t))});break;case`color`:t.length>1&&n.push(...t.map(e=>new D(E.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{bu(e.value)||n.push(new D(E.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))});break;default:t.forEach(t=>n.push(new D(E.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}};function ou(e){if(!(B(e)&&e.expression.variable.kind!==_.QUOTED_STRING)&&!(e instanceof rl))return!1;let t;if(t=e instanceof rl?Yu(e).unwrap_or(``):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}var su=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new D(E.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof gl?[new D(E.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:mu(e)?[]:[new D(E.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new D(E.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?hu(e)?[]:[new D(E.INVALID_ALIAS,`Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=P(e),n=t.getErrors();return Sc(t.getValue(),(e,t)=>{switch(t){case M.HeaderColor:e.length>1&&n.push(...e.map(e=>new D(E.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{bu(e.value)||n.push(new D(E.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case M.Note:e.length>1&&n.push(...e.map(e=>new D(E.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{Gu(e.value)||n.push(new D(E.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new D(E.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(Sl,{declaration:this.declarationNode,symbolTable:new eu});let{name:t,alias:n}=this.declarationNode,r=F(t);if(r.isOk()){let n=[...r.unwrap()],i=n.pop(),a=vu(n,this.publicSymbolTable,this.symbolFactory),o=Ul(i);a.has(o)&&e.push(new D(E.DUPLICATE_NAME,`Table name '${i}' already exists in schema '${n.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}if(n&&gu(n)&&!cu(n.expression.variable.value,r.unwrap_or([]))){let r=L(n).unwrap(),i=Ul(r);this.publicSymbolTable.has(i)&&e.push(new D(E.DUPLICATE_NAME,`Table name '${r}' already exists`,t)),this.publicSymbolTable.set(i,this.declarationNode.symbol)}return e}validateBody(e){if(!e)return[];if(e instanceof S)return[new D(E.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof S);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 D(E.INVALID_COLUMN,`A column must have a type`,e.callee)),B(e.callee)||t.push(new D(E.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Eu(e.args[0])&&t.push(new D(E.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t.push(...this.registerField(e)),t},n=e=>{let t=[];if(!e.callee)return[];if(!_u(e.callee))t.push(new D(E.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee));else{let t=I(e.callee.expression).unwrap_or(``),n=this.symbolFactory.create(Dl,{symbolTable:new eu,declaration:e}),r=Zl(t),i=this.declarationNode.symbol.symbolTable;if(i.has(r)){let n=i.get(r);return[new D(E.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,e),new D(E.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,n.declaration)]}i.set(r,n)}return e.args.length&&t.push(...e.args.map(e=>new D(E.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t};return e.flatMap(e=>e.callee instanceof al&&e.callee.op?.value===`~`?n(e):t(e))}registerField(e){if(e.callee&&B(e.callee)){let t=L(e.callee).unwrap(),n=Wl(t),r=this.symbolFactory.create(Cl,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new D(E.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new D(E.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}i.set(n,r)}return[]}validateFieldSetting(e){if(!e.slice(0,-1).every(Ku)||!e.slice(-1).every(e=>Ku(e)||e instanceof w))return[...e.map(e=>new D(E.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e))];if(e.length===0)return[];let t;h(e)instanceof w&&(t=e.pop());let n=P(t),r=n.getErrors(),i=n.getValue();e.forEach(e=>{let t=L(e).unwrap_or(``).toLowerCase();if(t!==`pk`&&t!==`unique`){r.push(new D(E.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}i[t]===void 0?i[t]=[e]:i[t].push(e)});let a=i[M.PK]||[],o=i[M.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sc(i,(e,t)=>{switch(t){case M.Note:e.length>1&&r.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{Gu(e.value)||r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case M.Ref:e.forEach(e=>{wu(e.value)||r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case M.PrimaryKey:e.length>1&&r.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{xu(e.value)||r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case M.PK:e.length>1&&r.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof il&&!xu(e.value)&&r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case M.NotNull:{e.length>1&&r.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=i[M.Null]||[];e.length>=1&&t.length>=1&&r.push(...[...e,...t].map(e=>new D(E.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{xu(e.value)||r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case M.Null:e.length>1&&r.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{xu(e.value)||r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case M.Unique:e.length>1&&r.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof il&&!xu(e.value)&&r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case M.Increment:e.length>1&&r.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof il&&!xu(e.value)&&r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case M.Default:e.length>1&&r.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Su(e.value)||r.push(new D(E.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 M.Check:e.forEach(e=>{e.value instanceof cl||r.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new D(E.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),r}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===`note`);return n.length>1&&t.push(...n.map(e=>new D(E.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function cu(e,t){return t.length===1&&e===t[0]}var lu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new D(E.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?gu(e)?[]:[new D(E.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new D(E.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(wl,{declaration:this.declarationNode,symbolTable:new eu});let t=F(e);if(t.isOk()){let n=t.unwrap(),r=n.pop(),i=vu(n,this.publicSymbolTable,this.symbolFactory),a=ql(r);if(i.has(a))return[new D(E.DUPLICATE_NAME,`TableGroup name '${r}' already exists`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=P(e),n=t.getErrors();return Sc(t.getValue(),(e,t)=>{switch(t){case`color`:e.length>1&&n.push(...e.map(e=>new D(E.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{bu(e.value)||n.push(new D(E.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))});break;case`note`:e.length>1&&n.push(...e.map(e=>new D(E.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.filter(e=>!Gu(e.value)).forEach(e=>{n.push(new D(E.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new D(E.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)));break}}),n}validateBody(e){if(!e)return[];if(e instanceof S)return[new D(E.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof S);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&!F(e.callee).isOk()&&t.push(new D(E.INVALID_TABLEGROUP_FIELD,`A TableGroup field must be of the form <table> or <schema>.<table>`,e.callee)),this.registerField(e),e.args.length>0&&t.push(...e.args.map(e=>new D(E.INVALID_TABLEGROUP_FIELD,`A TableGroup field should only have a single Table name`,e))),t})}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===`note`);return n.length>1&&t.push(...n.map(e=>new D(E.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}registerField(e){if(e.callee&&B(e.callee)){let t=L(e.callee).unwrap(),n=Jl(t),r=this.symbolFactory.create(Tl,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new D(E.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,e),new D(E.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,r.declaration)]}i.set(n,r)}return[]}},uu=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof x?[new D(E.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?gu(e)?[]:[new D(E.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new D(E.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=P(e),n=t.getErrors();return Sc(t.getValue(),(e,t)=>{switch(t){case M.HeaderColor:e.length>1&&n.push(...e.map(e=>new D(E.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{bu(e.value)||n.push(new D(E.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case M.Note:e.length>1&&n.push(...e.map(e=>new D(E.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Gu(e.value)||n.push(new D(E.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new D(E.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(El,{declaration:this.declarationNode,symbolTable:new eu});let t=F(e);if(!t.isOk())return[];let n=t.unwrap(),r=n.pop(),i=vu(n,this.publicSymbolTable,this.symbolFactory),a=Xl(r);return i.has(a)?[new D(E.DUPLICATE_NAME,`TablePartial name '${r}' already exists`,e)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(e){if(!e)return[];if(e instanceof S)return[new D(E.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof S);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 D(E.INVALID_COLUMN,`A column must have a type`,e.callee)),B(e.callee)||t.push(new D(E.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Eu(e.args[0])&&t.push(new D(E.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n),...this.registerField(e)),t})}registerField(e){if(!e.callee||!B(e.callee))return[];let t=L(e.callee).unwrap(),n=Wl(t),r=this.symbolFactory.create(Cl,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new D(E.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new D(E.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}return i.set(n,r),[]}validateFieldSetting(e){let t=h(e);if(!e.slice(0,-1).every(Ku)||!(Ku(t)||t instanceof w))return[...e.map(e=>new D(E.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=P(n),i=r.getErrors(),a=r.getValue();e.forEach(e=>{let t=L(e).unwrap_or(``).toLowerCase();if(t!==M.PK&&t!==M.Unique){i.push(new D(E.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}a[t]===void 0?a[t]=[e]:a[t].push(e)});let o=a[M.PK]||[],s=a[M.PrimaryKey]||[];return o.length>=1&&s.length>=1&&i.push(...[...o,...s].map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Sc(a,(e,t)=>{switch(t){case M.Note:e.length>1&&i.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Gu(e.value)||i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case M.Ref:e.forEach(e=>{wu(e.value)||i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case M.PrimaryKey:e.length>1&&i.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{xu(e.value)||i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case M.PK:e.length>1&&i.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof il&&!xu(e.value)&&i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case M.NotNull:{e.length>1&&i.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=a[M.Null]||[];e.length>=1&&n.length>=1&&i.push(...[...e,...n].map(e=>new D(E.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{xu(e.value)||i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case M.Null:e.length>1&&i.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{xu(e.value)||i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case M.Unique:e.length>1&&i.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof il&&!xu(e.value)&&i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case M.Increment:e.length>1&&i.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof il&&!xu(e.value)&&i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case M.Default:e.length>1&&i.push(...e.map(e=>new D(E.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Su(e.value)||i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case M.Check:e.forEach(e=>{e.value instanceof cl||i.push(new D(E.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>i.push(new D(E.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),i}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===j.Note);return n.length>1&&t.push(...n.map(e=>new D(E.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}},du=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}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 D(E.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof b)return[e];let t=Du(this.declarationNode.parent).unwrap_or(void 0);return t&&[j.Table,j.TablePartial].includes(t)?[]:[e]}validateName(e){return e?[new D(E.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new D(E.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof S)return[new D(E.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=g(e.body,e=>e instanceof S);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 cl))&&t.push(new D(E.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=P(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`name`:t.length>1&&t.forEach(t=>n.push(new D(E.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Gu(t.value)||n.push(new D(E.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new D(E.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},fu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}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 b||e instanceof x&&Du(e).unwrap_or(void 0)===j.Table?[]:[new D(E.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return this.declarationNode.parent instanceof b?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof T))return[new D(E.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)];let t=[];return(!e.callee||!mu(e.callee))&&t.push(new D(E.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Tu(e.argumentList))&&t.push(new D(E.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Tu(e)?[new D(E.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new D(E.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new D(E.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof S)return this.validateDataRow(e);let[t,n]=g(e.body,e=>e instanceof S);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 D(E.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof ul)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new D(E.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 D(E.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 hl||Cu(e)||Gu(e)||e instanceof cl)return!0;if(B(e)){let t=e.expression.variable.value.toLowerCase();return Rl.includes(t)}if(qu(e)){let t=F(e).unwrap_or(void 0);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(pu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}};function pu(e){switch(e.type.value.toLowerCase()){case j.Enum:return tu;case j.Table:return su;case j.TableGroup:return lu;case j.Project:return iu;case j.Ref:return au;case j.Note:return ru;case j.Indexes:return nu;case j.TablePartial:return uu;case j.Check:return du;case j.Records:return fu;default:return Vl}}function mu(e){return!!F(e).unwrap_or(!1)}function hu(e){return gu(e)}function gu(e){return e instanceof ml&&e.expression instanceof pl}function _u(e){return e instanceof al&&e.op?.value===`~`&&B(e.expression)}function vu(e,t,n){e[0]===`public`&&(e=e.slice(1));let r=t;for(let t of e){let e,i=Hl(t);if(r.has(i)){if(e=r.get(i)?.symbolTable,!e)throw Error(`Expect a symbol table in a schema symbol`)}else{e=new eu;let t=n.create(yl,{symbolTable:e});r.set(i,t)}r=e}return r}function yu(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function bu(e){if(!(e instanceof ml)||!(e.expression instanceof fl)||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(!Ml(t[e]))return!1;return!0}function xu(e){return e===void 0}function Su(e){if(Gu(e)||Cu(e)||Ku(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof al&&zl.includes(e.op?.value)&&Cu(e.expression)||e instanceof cl)return!0;if(!e||!Ju(e))return!1;let t=Ou(e).unwrap();return t.length===2||t.length===3}function Cu(e){return e instanceof al?zl.includes(e.op.value)?Cu(e.expression):!1:e instanceof ml&&e.expression instanceof fl&&e.expression.literal?.kind===_.NUMERIC_LITERAL}function wu(e){if(!(e instanceof al)||!yu(e.op?.value))return!1;let t=F(e.expression).unwrap_or(void 0);return t!==void 0&&t.length>0}function Tu(e){return e instanceof ll&&e.elementList.every(B)}function Eu(e){if(!(e instanceof T||qu(e)||e instanceof ml||e instanceof gl))return!1;for(;e instanceof T||e instanceof gl;)if(e instanceof T){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Cu(e)||Gu(e)||Ku(e)))return!1;e=e.callee}else if(e instanceof gl){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Cu(e.name)))return!1;e=e.array}let t=F(e).unwrap_or(void 0);return t!==void 0&&t.length>0}function P(e){let t={},n=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof ml){n.push(new D(E.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let r=Yu(e.name).unwrap_or(void 0)?.toLowerCase();r&&(t[r]===void 0?t[r]=[e]:t[r].push(e))}),new O(t,n)):new O({})}function Du(e){let t=e?.type?.value.toLowerCase();switch(t){case j.Enum:case j.Table:case j.Indexes:case j.Note:case j.Project:case j.Ref:case j.TableGroup:case j.TablePartial:case j.Check:case j.Records:return new k(t);default:return new A}}function Ou(e){if(!e)return new A;if(!qu(e))return new k([e]);let t=Ou(e.leftExpression).unwrap_or(void 0);return t?(t.push(e.rightExpression),new k(t)):new A}function F(e){if(e===void 0)return new A;let t=Ou(e).unwrap_or(void 0);if(!t)return new A;let n=[];for(let e of t){let t=I(e).unwrap_or(void 0);if(typeof t!=`string`)return new A;n.push(t)}return new k(n)}function ku(e){if(e===void 0)return new A;let t=Ou(e).unwrap_or(void 0);if(!t||t.length===0)return new A;let n=[];if(!B(h(t))){let e=t.pop();if(Tu(e))n=e.elementList;else return new A}let r=t;return r.every(B)?new k({variables:r,tupleElements:n}):new A}function I(e){return B(e)?new k(e.expression.variable.value):new A}function Au(e){return Fu(e)?e instanceof cl?new k({functional:[e],nonFunctional:[]}):new k({functional:[],nonFunctional:[e]}):e instanceof ll&&e.elementList.every(Fu)?new k({functional:e.elementList.filter(e=>e instanceof cl),nonFunctional:e.elementList.filter(B)}):new A}function L(e){let t=e?.expression.variable?.value;return t===void 0?new A:new k(t)}function R(e){return Gu(e)?e.expression instanceof pl?new k(e.expression.variable.value):new k(e.expression.literal.value):new A}function ju(e){return e instanceof ml&&e.expression instanceof fl&&e.expression.literal?.kind===_.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function Mu(e){if(e)return B(e)?e.referee:e instanceof ol&&e.op?.value===`.`?Mu(e.rightExpression):e.referee}function Nu(e){return!(e instanceof ol)||!yu(e.op?.value)?!1:ku(e.leftExpression).and_then(()=>ku(e.rightExpression)).unwrap_or(void 0)!==void 0}function Pu(e){let t=ku(e.leftExpression),n=ku(e.rightExpression);if(!t.isOk()||!n.isOk())return!1;let{tupleElements:r}=t.unwrap(),{tupleElements:i}=n.unwrap();return r?.length===i?.length}function Fu(e){return e instanceof ml&&e.expression instanceof pl||e instanceof cl}function Iu(e){if(!(e instanceof T)||!e.callee)return new A;let t=Ou(e.callee).unwrap_or(void 0);if(!t||t.length===0||!t.every(B))return new A;let n=[];return Tu(e.argumentList)&&(n=[...e.argumentList.elementList]),new k({variables:t,args:n})}function Lu(e,t,n){let r=t,i=e;if(i instanceof T&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Ku(i)||r.length===0)return new A;let a=[...r],o=Wu(i).unwrap(),s=a.pop();if(!(s instanceof C))return new A;let c=h(a)instanceof w?a.pop():void 0;if(a.length===3){let e=Wu(a[1]).value;return!e||!Ru(e)?new A:new k(n.create(x,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s}))}return a.length===1?new k(n.create(x,{type:o,name:a[0],attributeList:c,body:s})):a.length===0?new k(n.create(x,{type:o,attributeList:c,body:s})):new A}function Ru(e){return e?.kind===_.IDENTIFIER&&e.value.toLowerCase()===`as`}function z(e){e&&(e instanceof Yc?zu(e):Bu(e))}function zu(e){e.kind!==_.EOF&&(e.isInvalid=!0)}function Bu(e){if(e instanceof x)z(e.type),z(e.name),z(e.as),z(e.alias),z(e.bodyColon),z(e.attributeList),z(e.body);else if(e instanceof rl)e.identifiers.forEach(z);else if(e instanceof il)z(e.name),z(e.colon),z(e.value);else if(e instanceof al)z(e.op),z(e.expression);else if(e instanceof ol)z(e.leftExpression),z(e.op),z(e.rightExpression);else if(e instanceof sl)z(e.op),z(e.expression);else if(e instanceof C)z(e.blockOpenBrace),e.body.forEach(z),z(e.blockCloseBrace);else if(e instanceof w)z(e.listOpenBracket),e.commaList.forEach(z),e.elementList.forEach(z),z(e.listCloseBracket);else if(e instanceof ll)z(e.tupleOpenParen),e.commaList.forEach(z),e.elementList.forEach(z),z(e.tupleCloseParen);else if(e instanceof ul)e.commaList.forEach(z),e.elementList.forEach(z);else if(e instanceof T)z(e.callee),z(e.argumentList);else if(e instanceof S)z(e.callee),e.args.forEach(z);else if(e instanceof ml)z(e.expression);else if(e instanceof cl)z(e.value);else if(e instanceof pl)z(e.variable);else if(e instanceof fl)z(e.literal);else if(e instanceof dl)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof gl)z(e.array),z(e.indexer);else if(e instanceof b)e.body.forEach(z),z(e.eof);else if(!(e instanceof hl))throw Error(`Unreachable case in markInvalidNode`)}function Vu(e){return!!e?.isInvalid}function Hu(...e){return e.filter(e=>e!==void 0)}function Uu(e){if(e instanceof b)return Hu(...e.body,e.eof);if(e instanceof x)return Hu(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof il)return Hu(e.name,e.colon,e.value);if(e instanceof rl)return e.identifiers;if(e instanceof fl)return e.literal?[e.literal]:[];if(e instanceof pl)return Hu(e.variable);if(e instanceof al)return Hu(e.op,e.expression);if(e instanceof ol)return Hu(e.leftExpression,e.op,e.rightExpression);if(e instanceof sl)return Hu(e.expression,e.op);if(e instanceof cl)return Hu(e.value);if(e instanceof S)return Hu(e.callee,...e.args);if(e instanceof C)return Hu(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof w)return Hu(e.listOpenBracket,...Pl(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof ll)return Hu(e.tupleOpenParen,...Pl(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof ul)return Hu(...Pl(e.elementList,e.commaList));if(e instanceof T)return Hu(e.callee,e.argumentList);if(e instanceof ml)return Hu(e.expression);if(e instanceof gl)return Hu(e.array,e.indexer);throw e instanceof dl?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Wu(e){return B(e)?new k(e.expression.variable):new A}function Gu(e){return e instanceof ml&&(e.expression instanceof pl&&e.expression.variable instanceof Yc&&e.expression.variable.kind===_.QUOTED_STRING||e.expression instanceof fl&&e.expression.literal?.kind===_.STRING_LITERAL)}function B(e){return e instanceof ml&&e.expression instanceof pl&&e.expression.variable instanceof Yc}function Ku(e){return e instanceof ml&&e.expression instanceof pl&&e.expression.variable?.kind===_.IDENTIFIER}function qu(e){return e instanceof ol&&e.leftExpression instanceof v&&e.rightExpression instanceof v&&e.op?.value===`.`}function Ju(e){return B(e)?!0:qu(e)&&B(e.rightExpression)&&Ju(e.leftExpression)}function Yu(e){if(e===void 0)return new A;let t=e.identifiers.map(e=>e.value).join(` `);return t===``?new A:new k(t)}function Xu(e){return F(e?.name).map(e=>e.join(`.`))}var Zu=class{constructor(e){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
|
|
2
|
-
`?(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
|
|
3
|
-
`:this.addToken(
|
|
4
|
-
`))&&!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
|
|
5
|
-
`)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new
|
|
6
|
-
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&&e(r,Symbol.toStringTag,{value:`Module`}),r},n=typeof global==`object`&&global&&global.Object===Object&&global,r=n,i=typeof self==`object`&&self&&self.Object===Object&&self,a=r||i||Function(`return this`)(),o=a,s=o.Symbol,c=s,l=Object.prototype,u=l.hasOwnProperty,d=l.toString,f=c?c.toStringTag:void 0;function ee(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 te=ee,ne=Object.prototype.toString;function re(e){return ne.call(e)}var ie=re,ae=`[object Null]`,oe=`[object Undefined]`,se=c?c.toStringTag:void 0;function ce(e){return e==null?e===void 0?oe:ae:se&&se in Object(e)?te(e):ie(e)}var le=ce;function ue(e){return typeof e==`object`&&!!e}var de=ue,fe=`[object Symbol]`;function pe(e){return typeof e==`symbol`||de(e)&&le(e)==fe}var me=pe;function he(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var ge=he,_e=Array.isArray,ve=_e,ye=1/0,be=c?c.prototype:void 0,xe=be?be.toString:void 0;function Se(e){if(typeof e==`string`)return e;if(ve(e))return ge(e,Se)+``;if(me(e))return xe?xe.call(e):``;var t=e+``;return t==`0`&&1/e==-ye?`-0`:t}var Ce=Se,we=/\s/;function Te(e){for(var t=e.length;t--&&we.test(e.charAt(t)););return t}var Ee=Te,De=/^\s+/;function Oe(e){return e&&e.slice(0,Ee(e)+1).replace(De,``)}var ke=Oe;function Ae(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var je=Ae,Me=NaN,Ne=/^[-+]0x[0-9a-f]+$/i,Pe=/^0b[01]+$/i,Fe=/^0o[0-7]+$/i,Ie=parseInt;function Le(e){if(typeof e==`number`)return e;if(me(e))return Me;if(je(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=je(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=ke(e);var n=Pe.test(e);return n||Fe.test(e)?Ie(e.slice(2),n?2:8):Ne.test(e)?Me:+e}var Re=Le,ze=1/0,Be=17976931348623157e292;function Ve(e){return e?(e=Re(e),e===ze||e===-ze?(e<0?-1:1)*Be:e===e?e:0):e===0?e:0}var He=Ve;function Ue(e){var t=He(e),n=t%1;return t===t?n?t-n:t:0}var We=Ue;function Ge(e){return e}var Ke=Ge,qe=`[object AsyncFunction]`,Je=`[object Function]`,Ye=`[object GeneratorFunction]`,Xe=`[object Proxy]`;function Ze(e){if(!je(e))return!1;var t=le(e);return t==Je||t==Ye||t==qe||t==Xe}var Qe=Ze,$e=o[`__core-js_shared__`],et=$e,tt=function(){var e=/[^.]+$/.exec(et&&et.keys&&et.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function nt(e){return!!tt&&tt in e}var rt=nt,it=Function.prototype.toString;function at(e){if(e!=null){try{return it.call(e)}catch{}try{return e+``}catch{}}return``}var ot=at,st=/[\\^$.*+?()[\]{}|]/g,ct=/^\[object .+?Constructor\]$/,lt=Function.prototype,ut=Object.prototype,dt=lt.toString,ft=ut.hasOwnProperty,pt=RegExp(`^`+dt.call(ft).replace(st,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function mt(e){return!je(e)||rt(e)?!1:(Qe(e)?pt:ct).test(ot(e))}var ht=mt;function gt(e,t){return e?.[t]}var _t=gt;function vt(e,t){var n=_t(e,t);return ht(n)?n:void 0}var yt=vt,bt=yt(o,`WeakMap`),xt=bt;function St(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var Ct=St;function wt(){}var Tt=wt,Et=800,Dt=16,Ot=Date.now;function kt(e){var t=0,n=0;return function(){var r=Ot(),i=Dt-(r-n);if(n=r,i>0){if(++t>=Et)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var At=kt;function jt(e){return function(){return e}}var Mt=jt,Nt=function(){try{var e=yt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Pt=Nt,Ft=Pt?function(e,t){return Pt(e,`toString`,{configurable:!0,enumerable:!1,value:Mt(t),writable:!0})}:Ke,It=Ft,Lt=At(It),Rt=Lt;function zt(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1}var Bt=zt;function Vt(e){return e!==e}var Ht=Vt;function Ut(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}var Wt=Ut;function Gt(e,t,n){return t===t?Wt(e,t,n):Bt(e,Ht,n)}var Kt=Gt;function qt(e,t){return!!(e!=null&&e.length)&&Kt(e,t,0)>-1}var Jt=qt,Yt=9007199254740991,Xt=/^(?:0|[1-9]\d*)$/;function Zt(e,t){var n=typeof e;return t??=Yt,!!t&&(n==`number`||n!=`symbol`&&Xt.test(e))&&e>-1&&e%1==0&&e<t}var Qt=Zt;function $t(e,t,n){t==`__proto__`&&Pt?Pt(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var en=$t;function tn(e,t){return e===t||e!==e&&t!==t}var nn=tn,rn=Math.max;function an(e,t,n){return t=rn(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=rn(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Ct(e,this,s)}}var on=an;function sn(e,t){return Rt(on(e,t,Ke),e+``)}var cn=sn,ln=9007199254740991;function un(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=ln}var dn=un;function fn(e){return e!=null&&dn(e.length)&&!Qe(e)}var pn=fn,mn=Object.prototype;function hn(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||mn)}var gn=hn;function _n(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var vn=_n,yn=`[object Arguments]`;function bn(e){return de(e)&&le(e)==yn}var xn=bn,Sn=Object.prototype,Cn=Sn.hasOwnProperty,wn=Sn.propertyIsEnumerable,Tn=xn(function(){return arguments}())?xn:function(e){return de(e)&&Cn.call(e,`callee`)&&!wn.call(e,`callee`)},En=Tn;function Dn(){return!1}var On=Dn,kn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,An=kn&&typeof module==`object`&&module&&!module.nodeType&&module,jn=An&&An.exports===kn?o.Buffer:void 0,Mn=(jn?jn.isBuffer:void 0)||On,Nn=Mn,Pn=`[object Arguments]`,Fn=`[object Array]`,In=`[object Boolean]`,Ln=`[object Date]`,Rn=`[object Error]`,zn=`[object Function]`,Bn=`[object Map]`,Vn=`[object Number]`,Hn=`[object Object]`,Un=`[object RegExp]`,Wn=`[object Set]`,Gn=`[object String]`,Kn=`[object WeakMap]`,qn=`[object ArrayBuffer]`,Jn=`[object DataView]`,Yn=`[object Float32Array]`,Xn=`[object Float64Array]`,Zn=`[object Int8Array]`,Qn=`[object Int16Array]`,$n=`[object Int32Array]`,er=`[object Uint8Array]`,tr=`[object Uint8ClampedArray]`,nr=`[object Uint16Array]`,rr=`[object Uint32Array]`,p={};p[Yn]=p[Xn]=p[Zn]=p[Qn]=p[$n]=p[er]=p[tr]=p[nr]=p[rr]=!0,p[Pn]=p[Fn]=p[qn]=p[In]=p[Jn]=p[Ln]=p[Rn]=p[zn]=p[Bn]=p[Vn]=p[Hn]=p[Un]=p[Wn]=p[Gn]=p[Kn]=!1;function ir(e){return de(e)&&dn(e.length)&&!!p[le(e)]}var ar=ir;function or(e){return function(t){return e(t)}}var sr=or,cr=typeof exports==`object`&&exports&&!exports.nodeType&&exports,lr=cr&&typeof module==`object`&&module&&!module.nodeType&&module,ur=lr&&lr.exports===cr&&r.process,dr=function(){try{return lr&&lr.require&&lr.require(`util`).types||ur&&ur.binding&&ur.binding(`util`)}catch{}}(),fr=dr,pr=fr&&fr.isTypedArray,mr=pr?sr(pr):ar,hr=mr,gr=Object.prototype.hasOwnProperty;function _r(e,t){var n=ve(e),r=!n&&En(e),i=!n&&!r&&Nn(e),a=!n&&!r&&!i&&hr(e),o=n||r||i||a,s=o?vn(e.length,String):[],c=s.length;for(var l in e)(t||gr.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||Qt(l,c)))&&s.push(l);return s}var vr=_r;function yr(e,t){return function(n){return e(t(n))}}var br=yr,xr=br(Object.keys,Object),Sr=xr,Cr=Object.prototype.hasOwnProperty;function wr(e){if(!gn(e))return Sr(e);var t=[];for(var n in Object(e))Cr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var Tr=wr;function Er(e){return pn(e)?vr(e):Tr(e)}var Dr=Er;function Or(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var kr=Or,Ar=Object.prototype.hasOwnProperty;function jr(e){if(!je(e))return kr(e);var t=gn(e),n=[];for(var r in e)r==`constructor`&&(t||!Ar.call(e,r))||n.push(r);return n}var Mr=jr;function Nr(e){return pn(e)?vr(e,!0):Mr(e)}var Pr=Nr,Fr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ir=/^\w*$/;function Lr(e,t){if(ve(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||me(e)?!0:Ir.test(e)||!Fr.test(e)||t!=null&&e in Object(t)}var Rr=Lr,zr=yt(Object,`create`),Br=zr;function Vr(){this.__data__=Br?Br(null):{},this.size=0}var Hr=Vr;function Ur(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Wr=Ur,Gr=`__lodash_hash_undefined__`,Kr=Object.prototype.hasOwnProperty;function qr(e){var t=this.__data__;if(Br){var n=t[e];return n===Gr?void 0:n}return Kr.call(t,e)?t[e]:void 0}var Jr=qr,Yr=Object.prototype.hasOwnProperty;function Xr(e){var t=this.__data__;return Br?t[e]!==void 0:Yr.call(t,e)}var Zr=Xr,Qr=`__lodash_hash_undefined__`;function $r(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Br&&t===void 0?Qr:t,this}var ei=$r;function ti(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ti.prototype.clear=Hr,ti.prototype.delete=Wr,ti.prototype.get=Jr,ti.prototype.has=Zr,ti.prototype.set=ei;var ni=ti;function ri(){this.__data__=[],this.size=0}var ii=ri;function ai(e,t){for(var n=e.length;n--;)if(nn(e[n][0],t))return n;return-1}var oi=ai,si=Array.prototype.splice;function ci(e){var t=this.__data__,n=oi(t,e);return n<0?!1:(n==t.length-1?t.pop():si.call(t,n,1),--this.size,!0)}var li=ci;function ui(e){var t=this.__data__,n=oi(t,e);return n<0?void 0:t[n][1]}var di=ui;function fi(e){return oi(this.__data__,e)>-1}var pi=fi;function mi(e,t){var n=this.__data__,r=oi(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var hi=mi;function gi(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}gi.prototype.clear=ii,gi.prototype.delete=li,gi.prototype.get=di,gi.prototype.has=pi,gi.prototype.set=hi;var _i=gi,vi=yt(o,`Map`),yi=vi;function bi(){this.size=0,this.__data__={hash:new ni,map:new(yi||_i),string:new ni}}var xi=bi;function Si(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var Ci=Si;function wi(e,t){var n=e.__data__;return Ci(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var Ti=wi;function Ei(e){var t=Ti(this,e).delete(e);return this.size-=t?1:0,t}var Di=Ei;function Oi(e){return Ti(this,e).get(e)}var ki=Oi;function Ai(e){return Ti(this,e).has(e)}var ji=Ai;function Mi(e,t){var n=Ti(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var Ni=Mi;function Pi(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Pi.prototype.clear=xi,Pi.prototype.delete=Di,Pi.prototype.get=ki,Pi.prototype.has=ji,Pi.prototype.set=Ni;var Fi=Pi,Ii=`Expected a function`;function Li(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(Ii);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],a=n.cache;if(a.has(i))return a.get(i);var o=e.apply(this,r);return n.cache=a.set(i,o)||a,o};return n.cache=new(Li.Cache||Fi),n}Li.Cache=Fi;var Ri=Li,zi=500;function Bi(e){var t=Ri(e,function(e){return n.size===zi&&n.clear(),e}),n=t.cache;return t}var Vi=Bi,Hi=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ui=/\\(\\)?/g,Wi=Vi(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(Hi,function(e,n,r,i){t.push(r?i.replace(Ui,`$1`):n||e)}),t}),Gi=Wi;function Ki(e){return e==null?``:Ce(e)}var qi=Ki;function Ji(e,t){return ve(e)?e:Rr(e,t)?[e]:Gi(qi(e))}var Yi=Ji,Xi=1/0;function Zi(e){if(typeof e==`string`||me(e))return e;var t=e+``;return t==`0`&&1/e==-Xi?`-0`:t}var Qi=Zi;function $i(e,t){t=Yi(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[Qi(t[n++])];return n&&n==r?e:void 0}var ea=$i;function ta(e,t,n){var r=e==null?void 0:ea(e,t);return r===void 0?n:r}var na=ta;function ra(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var ia=ra,aa=c?c.isConcatSpreadable:void 0;function oa(e){return ve(e)||En(e)||!!(aa&&e&&e[aa])}var sa=oa;function ca(e,t,n,r,i){var a=-1,o=e.length;for(n||=sa,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?ca(s,t-1,n,r,i):ia(i,s):r||(i[i.length]=s)}return i}var la=ca;function ua(e){return e!=null&&e.length?la(e,1):[]}var da=ua;function fa(){this.__data__=new _i,this.size=0}var pa=fa;function ma(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var ha=ma;function ga(e){return this.__data__.get(e)}var _a=ga;function va(e){return this.__data__.has(e)}var ya=va,ba=200;function xa(e,t){var n=this.__data__;if(n instanceof _i){var r=n.__data__;if(!yi||r.length<ba-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Fi(r)}return n.set(e,t),this.size=n.size,this}var Sa=xa;function Ca(e){this.size=(this.__data__=new _i(e)).size}Ca.prototype.clear=pa,Ca.prototype.delete=ha,Ca.prototype.get=_a,Ca.prototype.has=ya,Ca.prototype.set=Sa;var wa=Ca;function Ta(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}var Ea=Ta;function Da(){return[]}var Oa=Da,ka=Object.prototype.propertyIsEnumerable,Aa=Object.getOwnPropertySymbols,ja=Aa?function(e){return e==null?[]:(e=Object(e),Ea(Aa(e),function(t){return ka.call(e,t)}))}:Oa,Ma=ja;function Na(e,t,n){var r=t(e);return ve(e)?r:ia(r,n(e))}var Pa=Na;function Fa(e){return Pa(e,Dr,Ma)}var Ia=Fa,La=yt(o,`DataView`),Ra=La,za=yt(o,`Promise`),Ba=za,Va=yt(o,`Set`),Ha=Va,Ua=`[object Map]`,Wa=`[object Object]`,Ga=`[object Promise]`,Ka=`[object Set]`,qa=`[object WeakMap]`,Ja=`[object DataView]`,Ya=ot(Ra),Xa=ot(yi),Za=ot(Ba),Qa=ot(Ha),$a=ot(xt),eo=le;(Ra&&eo(new Ra(new ArrayBuffer(1)))!=Ja||yi&&eo(new yi)!=Ua||Ba&&eo(Ba.resolve())!=Ga||Ha&&eo(new Ha)!=Ka||xt&&eo(new xt)!=qa)&&(eo=function(e){var t=le(e),n=t==Wa?e.constructor:void 0,r=n?ot(n):``;if(r)switch(r){case Ya:return Ja;case Xa:return Ua;case Za:return Ga;case Qa:return Ka;case $a:return qa}return t});var to=eo,no=o.Uint8Array,ro=no;function io(e){for(var t=-1,n=e==null?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i}var ao=io,oo=`__lodash_hash_undefined__`;function so(e){return this.__data__.set(e,oo),this}var co=so;function lo(e){return this.__data__.has(e)}var uo=lo;function fo(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Fi;++t<n;)this.add(e[t])}fo.prototype.add=fo.prototype.push=co,fo.prototype.has=uo;var po=fo;function mo(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}var ho=mo;function go(e,t){return e.has(t)}var _o=go,vo=1,yo=2;function bo(e,t,n,r,i,a){var o=n&vo,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,ee=n&yo?new po:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var te=e[d],ne=t[d];if(r)var re=o?r(ne,te,d,t,e,a):r(te,ne,d,e,t,a);if(re!==void 0){if(re)continue;f=!1;break}if(ee){if(!ho(t,function(e,t){if(!_o(ee,t)&&(te===e||i(te,e,n,r,a)))return ee.push(t)})){f=!1;break}}else if(!(te===ne||i(te,ne,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var xo=bo;function So(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var Co=So;function wo(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var To=wo,Eo=1,Do=2,Oo=`[object Boolean]`,ko=`[object Date]`,Ao=`[object Error]`,jo=`[object Map]`,Mo=`[object Number]`,No=`[object RegExp]`,Po=`[object Set]`,Fo=`[object String]`,Io=`[object Symbol]`,Lo=`[object ArrayBuffer]`,Ro=`[object DataView]`,zo=c?c.prototype:void 0,Bo=zo?zo.valueOf:void 0;function Vo(e,t,n,r,i,a,o){switch(n){case Ro:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Lo:return!(e.byteLength!=t.byteLength||!a(new ro(e),new ro(t)));case Oo:case ko:case Mo:return nn(+e,+t);case Ao:return e.name==t.name&&e.message==t.message;case No:case Fo:return e==t+``;case jo:var s=Co;case Po:var c=r&Eo;if(s||=To,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Do,o.set(e,t);var u=xo(s(e),s(t),r,i,a,o);return o.delete(e),u;case Io:if(Bo)return Bo.call(e)==Bo.call(t)}return!1}var Ho=Vo,Uo=1,Wo=Object.prototype.hasOwnProperty;function Go(e,t,n,r,i,a){var o=n&Uo,s=Ia(e),c=s.length;if(c!=Ia(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:Wo.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var ee=!0;a.set(e,t),a.set(t,e);for(var te=o;++l<c;){u=s[l];var ne=e[u],re=t[u];if(r)var ie=o?r(re,ne,u,t,e,a):r(ne,re,u,e,t,a);if(!(ie===void 0?ne===re||i(ne,re,n,r,a):ie)){ee=!1;break}te||=u==`constructor`}if(ee&&!te){var ae=e.constructor,oe=t.constructor;ae!=oe&&`constructor`in e&&`constructor`in t&&!(typeof ae==`function`&&ae instanceof ae&&typeof oe==`function`&&oe instanceof oe)&&(ee=!1)}return a.delete(e),a.delete(t),ee}var Ko=Go,qo=1,Jo=`[object Arguments]`,Yo=`[object Array]`,Xo=`[object Object]`,Zo=Object.prototype.hasOwnProperty;function Qo(e,t,n,r,i,a){var o=ve(e),s=ve(t),c=o?Yo:to(e),l=s?Yo:to(t);c=c==Jo?Xo:c,l=l==Jo?Xo:l;var u=c==Xo,d=l==Xo,f=c==l;if(f&&Nn(e)){if(!Nn(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new wa,o||hr(e)?xo(e,t,n,r,i,a):Ho(e,t,c,n,r,i,a);if(!(n&qo)){var ee=u&&Zo.call(e,`__wrapped__`),te=d&&Zo.call(t,`__wrapped__`);if(ee||te){var ne=ee?e.value():e,re=te?t.value():t;return a||=new wa,i(ne,re,n,r,a)}}return f?(a||=new wa,Ko(e,t,n,r,i,a)):!1}var $o=Qo;function es(e,t,n,r,i){return e===t?!0:e==null||t==null||!de(e)&&!de(t)?e!==e&&t!==t:$o(e,t,n,r,es,i)}var ts=es,ns=1,rs=2;function is(e,t,n,r){var i=n.length,a=i,o=!r;if(e==null)return!a;for(e=Object(e);i--;){var s=n[i];if(o&&s[2]?s[1]!==e[s[0]]:!(s[0]in e))return!1}for(;++i<a;){s=n[i];var c=s[0],l=e[c],u=s[1];if(o&&s[2]){if(l===void 0&&!(c in e))return!1}else{var d=new wa;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?ts(u,l,ns|rs,r,d):f))return!1}}return!0}var as=is;function os(e){return e===e&&!je(e)}var ss=os;function cs(e){for(var t=Dr(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,ss(i)]}return t}var ls=cs;function us(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var ds=us;function fs(e){var t=ls(e);return t.length==1&&t[0][2]?ds(t[0][0],t[0][1]):function(n){return n===e||as(n,e,t)}}var ps=fs;function ms(e,t){return e!=null&&t in Object(e)}var hs=ms;function gs(e,t,n){t=Yi(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=Qi(t[r]);if(!(a=e!=null&&n(e,o)))break;e=e[o]}return a||++r!=i?a:(i=e==null?0:e.length,!!i&&dn(i)&&Qt(o,i)&&(ve(e)||En(e)))}var _s=gs;function vs(e,t){return e!=null&&_s(e,t,hs)}var ys=vs,bs=1,xs=2;function Ss(e,t){return Rr(e)&&ss(t)?ds(Qi(e),t):function(n){var r=na(n,e);return r===void 0&&r===t?ys(n,e):ts(t,r,bs|xs)}}var Cs=Ss;function ws(e){return function(t){return t?.[e]}}var Ts=ws;function Es(e){return function(t){return ea(t,e)}}var Ds=Es;function Os(e){return Rr(e)?Ts(Qi(e)):Ds(e)}var ks=Os;function As(e){return typeof e==`function`?e:e==null?Ke:typeof e==`object`?ve(e)?Cs(e[0],e[1]):ps(e):ks(e)}var js=As;function Ms(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}var Ns=Ms;function Ps(e){return function(t,n,r){for(var i=-1,a=Object(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}var Fs=Ps,Is=Fs(),Ls=Is;function Rs(e,t){return e&&Ls(e,t,Dr)}var zs=Rs;function Bs(e,t){return function(n,r){if(n==null)return n;if(!pn(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var Vs=Bs,Hs=Vs(zs),Us=Hs;function Ws(e,t,n,r){return Us(e,function(e,i,a){t(r,e,n(e),a)}),r}var Gs=Ws;function Ks(e,t){return function(n,r){var i=ve(n)?Ns:Gs,a=t?t():{};return i(n,e,js(r,2),a)}}var qs=Ks;function Js(e){return de(e)&&pn(e)}var Ys=Js;function Xs(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}var Zs=Xs,Qs=200;function $s(e,t,n,r){var i=-1,a=Jt,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=ge(t,sr(n))),r?(a=Zs,o=!1):t.length>=Qs&&(a=_o,o=!1,t=new po(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var ec=$s,tc=cn(function(e,t){return Ys(e)?ec(e,la(t,1,Ys,!0)):[]}),nc=tc;function rc(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var m=rc;function ic(e){return typeof e==`function`?e:Ke}var ac=ic;function oc(e,t){var n=[];return Us(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}var sc=oc;function cc(e,t){return(ve(e)?Ea:sc)(e,js(t,3))}var lc=cc,uc=Math.max,dc=Math.min;function fc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=We(n),i=n<0?uc(r+i,0):dc(i,r-1)),Bt(e,js(t,3),i,!0)}var pc=fc;function mc(e){return e&&e.length?e[0]:void 0}var hc=mc;function gc(e,t){var n=-1,r=pn(e)?Array(e.length):[];return Us(e,function(e,i,a){r[++n]=t(e,i,a)}),r}var _c=gc;function vc(e,t){return(ve(e)?ge:_c)(e,js(t,3))}var yc=vc;function bc(e,t){return la(yc(e,t),1)}var xc=bc;function Sc(e,t){return e==null?e:Ls(e,ac(t),Pr)}var Cc=Sc,wc=Object.prototype.hasOwnProperty,Tc=qs(function(e,t,n){wc.call(e,n)?e[n].push(t):en(e,n,[t])}),Ec=Tc,Dc=`[object Map]`,Oc=`[object Set]`,kc=Object.prototype.hasOwnProperty;function Ac(e){if(e==null)return!0;if(pn(e)&&(ve(e)||typeof e==`string`||typeof e.splice==`function`||Nn(e)||hr(e)||En(e)))return!e.length;var t=to(e);if(t==Dc||t==Oc)return!e.size;if(gn(e))return!Tr(e).length;for(var n in e)if(kc.call(e,n))return!1;return!0}var jc=Ac,Mc=qs(function(e,t,n){en(e,n,t)}),Nc=Mc,Pc=qs(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),h=Pc,Fc=Ha&&1/To(new Ha([,-0]))[1]==1/0?function(e){return new Ha(e)}:Tt,Ic=Fc,Lc=200;function Rc(e,t,n){var r=-1,i=Jt,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=Zs;else if(a>=Lc){var l=t?null:Ic(e);if(l)return To(l);o=!1,i=_o,c=new po}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}var zc=Rc;function Bc(e,t){return e&&e.length?zc(e,js(t,2)):[]}var Vc=Bc,Hc=Math.max;function Uc(e){if(!(e&&e.length))return[];var t=0;return e=Ea(e,function(e){if(Ys(e))return t=Hc(e.length,t),!0}),vn(t,function(t){return ge(e,Ts(t))})}var Wc=Uc,Gc=cn(Wc),Kc=Gc;let g=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}({});function qc(e){switch(e.kind){case g.NEWLINE:case g.SPACE:case g.TAB:case g.SINGLE_LINE_COMMENT:case g.MULTILINE_COMMENT:return!0;default:return!1}}function Jc(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 Yc(e){return e!==void 0&&e.kind===g.OP}var Xc=class e{constructor(e,t,n,r,i){this.kind=e,this.startPos=t,this.endPos=n,this.value=r,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=i,this.start=t.offset,this.end=n.offset}static create(t,n,r,i,a){return new e(t,n,r,i,a)}};function Zc(e){return e.trailingTrivia.find(({kind:e})=>e===g.NEWLINE)!==void 0}function Qc(e,t){return t.leadingTrivia.find(({kind:e})=>e===g.NEWLINE)!==void 0||Zc(e)}function $c(e){return e.trailingTrivia.find(({kind:e})=>[g.SPACE,g.TAB].includes(e))!==void 0}function el(e){return e.trailingTrivia.length===0?e.end:el(m(e.trailingTrivia))}function tl(e){return e.leadingTrivia.length===0?e.start:tl(e.leadingTrivia[0])}function nl(e){return[g.SINGLE_LINE_COMMENT,g.MULTILINE_COMMENT].includes(e.kind)}var rl=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},_=class{constructor(e,t,n){this.id=e,this.kind=t;let r=n.find(e=>e!==void 0&&!Number.isNaN(e.start));r?(this.startPos=r.startPos,this.fullStart=r instanceof Xc?tl(r):r.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let i=[...n].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));i?(this.endPos=i.endPos,this.fullEnd=i instanceof Xc?el(i):i.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}};let v=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifer-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}({});var y=class extends _{constructor({body:e=[],eof:t,source:n},r){super(r,v.PROGRAM,[...e,t]),this.source=n,this.body=e,this.eof=t}},b=class e extends _{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c){if(super(c,v.ELEMENT_DECLARATION,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof x||s instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.name=n,this.as=r,this.alias=i,this.attributeList=a,this.bodyColon=o,this.body=s}},il=class extends _{constructor({identifiers:e=[]},t){super(t,v.IDENTIFIER_STREAM,e||[]),this.identifiers=e}},al=class extends _{constructor({name:e,colon:t,value:n},r){super(r,v.ATTRIBUTE,[e,t,n]),this.name=e,this.value=n,this.colon=t}},ol=class extends _{constructor({op:e,expression:t},n){super(n,v.PREFIX_EXPRESSION,[e,t]),this.op=e,this.expression=t}},sl=class extends _{constructor({op:e,leftExpression:t,rightExpression:n},r){super(r,v.INFIX_EXPRESSION,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},cl=class extends _{constructor({op:e,expression:t},n){super(n,v.POSTFIX_EXPRESSION,[t,e]),this.op=e,this.expression=t}},ll=class extends _{constructor({value:e},t){super(t,v.FUNCTION_EXPRESSION,[e]),this.value=e}},x=class extends _{constructor({callee:e,args:t=[]},n){super(n,v.FUNCTION_APPLICATION,[e,...t]),this.callee=e,this.args=t}},S=class extends _{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r){super(r,v.BLOCK_EXPRESSION,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},C=class extends _{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i){super(i,v.LIST_EXPRESSION,[e,...vl(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},ul=class extends _{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i){super(i,v.TUPLE_EXPRESSION,[e,...vl(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},dl=class extends _{constructor({elementList:e=[],commaList:t=[]},n){super(n,v.COMMA_EXPRESSION,[...vl(e,t)]),this.elementList=e,this.commaList=t}},fl=class extends ul{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r),this.kind=v.GROUP_EXPRESSION}},w=class extends _{constructor({callee:e,argumentList:t},n){super(n,v.CALL_EXPRESSION,[e,t]),this.callee=e,this.argumentList=t}},pl=class extends _{constructor({literal:e},t){super(t,v.LITERAL,[e]),this.literal=e}},ml=class extends _{constructor({variable:e},t){super(t,v.VARIABLE,[e]),this.variable=e}},hl=class extends _{constructor({expression:e},t){super(t,v.PRIMARY_EXPRESSION,[e]),this.expression=e}},gl=class extends _{constructor({prevToken:e},t){let n=Xc.create(g.SPACE,e.endPos,e.endPos,` `,!1);super(t,v.EMPTY,[n])}},_l=class extends _{constructor({expression:e,indexer:t},n){super(n,v.ARRAY,[e,t]),this.array=e,this.indexer=t}};function vl(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];let[n]=e,[r]=t;return(n.start<r.start?da(Kc(e,t)):da(Kc(t,e))).filter(e=>e!==null)}var yl=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},bl=class{constructor({symbolTable:e},t){this.references=[],this.id=t,this.symbolTable=e}},xl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Sl=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},Cl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},wl=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},Tl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},El=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},Dl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Ol=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},kl=class{constructor({declaration:e},t){this.references=[],this.id=t,this.declaration=e}},Al=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},jl=class{constructor({symbolTable:e,declaration:t},n){this.references=[],this.id=n,this.symbolTable=e,this.declaration=t}},Ml=class{constructor({declaration:e,tablePartialSymbol:t},n){this.references=[],this.id=n,this.declaration=e,this.tablePartialSymbol=t}};let T=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.INVALID_INDEXES_CONTEXT=3047]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3048]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3049]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3050]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3051]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3052]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3053]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3054]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3055]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3056]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3057]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3058]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3059]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3060]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3061]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3062]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3063]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3064]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3065]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3066]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3067]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3069]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3070]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3071]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3072]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3073]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3074]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3075]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3076]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3077]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3078]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3079]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3080]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3081]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3082]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3083]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3084]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3085]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.UNEQUAL_FIELDS_BINARY_REF=5003]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5004]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e}({});var E=class e extends Error{constructor(t,n,r){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new Nl(this.code,this.message,this.nodeOrToken)}},Nl=class extends Error{constructor(e,t,n){super(t),this.code=e,this.diagnostic=t,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,E.prototype)}},D=class e{constructor(e,t,n){this.value=e,this.errors=t===void 0?[]:t,n?.length&&(this.warnings=n)}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings||[]}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()];return new e(n.value,r,i)}map(t){return new e(t(this.value),this.errors,this.warnings)}};function Pl(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Fl(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Il(e){let[t]=e;return Fl(t)||Pl(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function Ll(e){return Pl(e)||Fl(e)}function Rl(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 zl(e,t){return e>=t.start&&e<t.end}function Bl(e){return e instanceof ol?`${e.op?.value}${Bl(e.expression)}`:e.expression.literal.value}function Vl(e){return e instanceof ol?e.op?.value===`-`?-Vl(e.expression):Vl(e.expression):Number.parseFloat(e.expression.literal.value)}var O=class e{constructor(e){this.value=e}unwrap(){return this.value}unwrap_or(e){return this.value}and_then(e){return e(this.value)}map(t){return new e(t(this.value))}isOk(){return!0}},k=class e{constructor(){this.value=void 0}unwrap(){throw Error(`Trying to unwrap a None value`)}unwrap_or(e){return e}and_then(t){return new e}map(t){return new e}isOk(){return!1}};const Hl=[`null`,`true`,`false`],Ul=[`-`,`+`],Wl=`public`;let A=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Check=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e}({}),j=function(e){return e.Color=`color`,e.HeaderColor=`headercolor`,e.Note=`note`,e.PK=`pk`,e.PrimaryKey=`primary key`,e.Unique=`unique`,e.Ref=`ref`,e.NotNull=`not null`,e.Null=`null`,e.Increment=`increment`,e.Default=`default`,e.Name=`name`,e.Type=`type`,e.Check=`check`,e.Update=`update`,e.Delete=`delete`,e}({});var Gl=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}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 y||Fu(this.declarationNode.parent).unwrap_or(void 0)!==A.Project?[new E(T.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]:[]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof S)return[new E(T.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return z(e.callee)||t.push(new E(T.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e)),e.args.length>0&&t.push(...e.args.map(e=>new E(T.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};let M=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.Note=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewField=`DiagramView field`,e}({});function Kl(e){return`${M.Schema}:${e}`}function ql(e){return`${M.Table}:${e}`}function Jl(e){return`${M.Column}:${e}`}function Yl(e){return`${M.Enum}:${e}`}function Xl(e){return`${M.EnumField}:${e}`}function Zl(e){return`${M.TableGroup}:${e}`}function Ql(e){return`${M.TableGroupField}:${e}`}function $l(e){return`${M.Note}:${e}`}function eu(e){return`${M.TablePartial}:${e}`}function tu(e){return`${M.PartialInjection}:${e}`}function nu(e){return`${M.DiagramView}:${e}`}function ru(e){return`${M.DiagramViewField}:${e}`}function iu(e,t){switch(t){case M.Column:return Jl(e);case M.Enum:return Yl(e);case M.EnumField:return Xl(e);case M.Schema:return Kl(e);case M.Table:return ql(e);case M.TableGroup:return Zl(e);case M.TableGroupField:return Ql(e);case M.Note:return $l(e);case M.TablePartial:return eu(e);case M.PartialInjection:return tu(e);case M.DiagramView:return nu(e);case M.DiagramViewField:return ru(e);default:throw Error(`Unreachable`)}}function au(e){let[t,n]=e.split(`:`);return Object.values(M).includes(t)?new O({name:n,kind:t}):new k}var ou=class{constructor(){this.table=new Map}has(e){return this.table.has(e)}set(e,t){this.table.set(e,t)}get(e,t){return this.table.get(e)||t!==void 0&&this.set(e,t)||t}entries(){return this.table.entries()}forEach(e){return this.table.forEach(e)}},su=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b?[new E(T.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Su(e)?[]:[new E(T.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new E(T.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(xl,{declaration:this.declarationNode,symbolTable:new ou});let{name:t}=this.declarationNode,n=P(t);if(n.isOk()){let r=n.unwrap(),i=r.pop(),a=Eu(r,this.publicSymbolTable,this.symbolFactory),o=Yl(i);a.has(o)&&e.push(new E(T.DUPLICATE_NAME,`Enum name ${i} already exists in schema '${r.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}return e}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof x)return this.validateFields([e]);let[t,n]=h(e.body,e=>e instanceof x);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.length===0?[new E(T.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)]:e.flatMap(e=>{let t=[];e.callee&&!B(e.callee)&&t.push(new E(T.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,e.callee));let n=[...e.args];return m(n)instanceof C?(t.push(...this.validateFieldSettings(m(n))),n.pop()):n[0]instanceof C&&(t.push(...this.validateFieldSettings(n[0])),n.shift()),n.length>0&&t.push(...n.map(e=>new E(T.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e))),t.push(...this.registerField(e)),t})}validateFieldSettings(e){let t=N(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`note`:t.length>1&&t.forEach(e=>n.push(new E(T.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{z(e.value)||n.push(new E(T.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}registerField(e){if(e.callee&&B(e.callee)){let t=I(e.callee).unwrap(),n=Xl(t),r=this.symbolFactory.create(Sl,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new E(T.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,e),new E(T.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,r.declaration)]}i.set(n,r)}return[]}},cu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new E(T.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof y)return[e];let t=Fu(this.declarationNode.parent).unwrap_or(void 0);return t&&[A.Table,A.TablePartial].includes(t)?[]:[e]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof x)return[new E(T.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=h(e.body,e=>e instanceof x);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 m(n)instanceof C&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof w;)e.argumentList&&!Ru(e.argumentList).isOk()&&t.push(new E(T.INVALID_INDEXES_FIELD,`An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such`,e.argumentList)),e=e.callee;Ru(e).isOk()||t.push(new E(T.INVALID_INDEXES_FIELD,`An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such`,e))}),t})}validateFieldSetting(e){let t=N(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`note`:case`name`:t.length>1&&t.forEach(t=>n.push(new E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{z(t.value)||n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new E(T.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{ku(t.value)||n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new E(T.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{B(e.value)||n.push(new E(T.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},lu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}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 y)&&![A.Table,A.TableGroup,A.TablePartial,A.Project].includes(Fu(this.declarationNode.parent).unwrap_or(void 0))?[new E(T.INVALID_NOTE_CONTEXT,`A Note can only appear inside a Table, a TableGroup, a TablePartial or a Project. Sticky note can only appear at the global scope.`,this.declarationNode)]:[]}validateName(e){if(!(this.declarationNode.parent instanceof y))return e?[new E(T.UNEXPECTED_NAME,`A Note shouldn't have a name`,e)]:[];if(!e)return[new E(T.INVALID_NAME,`Sticky note must have a name`,this.declarationNode)];let t=P(e);if(!t.isOk())return[new E(T.INVALID_NAME,`Invalid name for sticky note `,this.declarationNode)];let n=t.unwrap().join(`.`),r=$l(n);return this.publicSymbolTable.has(r)?[new E(T.DUPLICATE_NAME,`Sticky note "${n}" has already been defined`,e)]:(this.declarationNode.symbol=this.symbolFactory.create(kl,{declaration:this.declarationNode}),this.publicSymbolTable.set(r,this.declarationNode.symbol),[])}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof x)return this.validateFields([e]);let[t,n]=h(e.body,e=>e instanceof x);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new E(T.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new E(T.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),z(e[0].callee)||t.push(new E(T.INVALID_NOTE,`A Note content must be a quoted string`,e[0])),e[0].args.length>0&&t.push(...e[0].args.map(e=>new E(T.INVALID_NOTE,`A Note can only contain one quoted string`,e))),t)}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},uu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b?[new E(T.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?wu(e)?[]:[new E(T.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof x)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof x);return[...t.map(e=>new E(T.INVALID_PROJECT_FIELD,`A Project can not have inline fields`,e)),...this.validateSubElements(n)]}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},du=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}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 y?[]:[new E(T.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?wu(e)?[]:[new E(T.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof x)return this.validateFields([e]);let[t,n]=h(e.body,e=>e instanceof x);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new E(T.EMPTY_REF,`A Ref must have at least one field`,this.declarationNode)];let t=[];return e.length>1&&t.push(...e.slice(1).map(e=>new E(T.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Vu(e.callee)&&t.push(new E(T.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Vu(e.callee)){let n=Lu(e.callee.leftExpression).unwrap_or({variables:[],tupleElements:[]}),r=n.variables.length+Math.min(n.tupleElements.length,1),i=Lu(e.callee.rightExpression).unwrap_or({variables:[],tupleElements:[]}),a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new E(T.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new E(T.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Hu(e.callee)&&t.push(new E(T.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(m(n)instanceof C){let e=this.validateFieldSettings(m(n));t.push(...e),n.pop()}else n[0]instanceof C&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new E(T.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){let t=N(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`delete`:case`update`:t.length>1&&t.forEach(t=>n.push(new E(T.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{fu(t.value)||n.push(new E(T.INVALID_REF_SETTING_VALUE,`'${e}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,t))});break;case`color`:t.length>1&&n.push(...t.map(e=>new E(T.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Ou(e.value)||n.push(new E(T.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}};function fu(e){if(!(B(e)&&e.expression.variable.kind!==g.QUOTED_STRING)&&!(e instanceof il))return!1;let t;if(t=e instanceof il?nd(e).unwrap_or(``):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}var pu=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b?[new E(T.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof _l?[new E(T.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:Su(e)?[]:[new E(T.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new E(T.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?Cu(e)?[]:[new E(T.INVALID_ALIAS,`Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=N(e),n=t.getErrors();return Cc(t.getValue(),(e,t)=>{switch(t){case j.HeaderColor:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{Ou(e.value)||n.push(new E(T.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case j.Note:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{z(e.value)||n.push(new E(T.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new E(T.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(Cl,{declaration:this.declarationNode,symbolTable:new ou});let{name:t,alias:n}=this.declarationNode,r=P(t);if(r.isOk()){let n=[...r.unwrap()],i=n.pop(),a=Eu(n,this.publicSymbolTable,this.symbolFactory),o=ql(i);a.has(o)&&e.push(new E(T.DUPLICATE_NAME,`Table name '${i}' already exists in schema '${n.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}if(n&&wu(n)&&!mu(n.expression.variable.value,r.unwrap_or([]))){let r=I(n).unwrap(),i=ql(r);this.publicSymbolTable.has(i)&&e.push(new E(T.DUPLICATE_NAME,`Table name '${r}' already exists`,t)),this.publicSymbolTable.set(i,this.declarationNode.symbol)}return e}validateBody(e){if(!e)return[];if(e instanceof x)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof x);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=e=>{let t=[];if(!e.callee)return[];e.args.length===0&&t.push(new E(T.INVALID_COLUMN,`A column must have a type`,e.callee)),B(e.callee)||t.push(new E(T.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Pu(e.args[0])&&t.push(new E(T.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t.push(...this.registerField(e)),t},n=e=>{let t=[];if(!e.callee)return[];if(!Tu(e.callee))t.push(new E(T.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee));else{let t=F(e.callee.expression).unwrap_or(``),n=this.symbolFactory.create(jl,{symbolTable:new ou,declaration:e}),r=tu(t),i=this.declarationNode.symbol.symbolTable;if(i.has(r)){let n=i.get(r);return[new E(T.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,e),new E(T.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,n.declaration)]}i.set(r,n)}return e.args.length&&t.push(...e.args.map(e=>new E(T.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t};return e.flatMap(e=>e.callee instanceof ol&&e.callee.op?.value===`~`?n(e):t(e))}registerField(e){if(e.callee&&B(e.callee)){let t=I(e.callee).unwrap(),n=Jl(t),r=this.symbolFactory.create(wl,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new E(T.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new E(T.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}i.set(n,r)}return[]}validateFieldSetting(e){if(!e.slice(0,-1).every($u)||!e.slice(-1).every(e=>$u(e)||e instanceof C))return[...e.map(e=>new E(T.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e))];if(e.length===0)return[];let t;m(e)instanceof C&&(t=e.pop());let n=N(t),r=n.getErrors(),i=n.getValue();e.forEach(e=>{let t=I(e).unwrap_or(``).toLowerCase();if(t!==`pk`&&t!==`unique`){r.push(new E(T.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}i[t]===void 0?i[t]=[e]:i[t].push(e)});let a=i[j.PK]||[],o=i[j.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(i,(e,t)=>{switch(t){case j.Note:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{z(e.value)||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case j.Ref:e.forEach(e=>{Mu(e.value)||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case j.PrimaryKey:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{ku(e.value)||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case j.PK:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof al&&!ku(e.value)&&r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case j.NotNull:{e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=i[j.Null]||[];e.length>=1&&t.length>=1&&r.push(...[...e,...t].map(e=>new E(T.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{ku(e.value)||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case j.Null:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{ku(e.value)||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case j.Unique:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof al&&!ku(e.value)&&r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case j.Increment:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof al&&!ku(e.value)&&r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case j.Default:e.length>1&&r.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Au(e.value)||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'default' must be an enum value, a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case j.Check:e.forEach(e=>{e.value instanceof ll||r.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new E(T.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),r}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===`note`);return n.length>1&&t.push(...n.map(e=>new E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function mu(e,t){return t.length===1&&e===t[0]}var hu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b?[new E(T.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?wu(e)?[]:[new E(T.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new E(T.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Tl,{declaration:this.declarationNode,symbolTable:new ou});let t=P(e);if(t.isOk()){let n=t.unwrap(),r=n.pop(),i=Eu(n,this.publicSymbolTable,this.symbolFactory),a=Zl(r);if(i.has(a))return[new E(T.DUPLICATE_NAME,`TableGroup name '${r}' already exists`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=N(e),n=t.getErrors();return Cc(t.getValue(),(e,t)=>{switch(t){case`color`:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{Ou(e.value)||n.push(new E(T.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))});break;case`note`:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.filter(e=>!z(e.value)).forEach(e=>{n.push(new E(T.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new E(T.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)));break}}),n}validateBody(e){if(!e)return[];if(e instanceof x)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof x);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&!P(e.callee).isOk()&&t.push(new E(T.INVALID_TABLEGROUP_FIELD,`A TableGroup field must be of the form <table> or <schema>.<table>`,e.callee)),this.registerField(e),e.args.length>0&&t.push(...e.args.map(e=>new E(T.INVALID_TABLEGROUP_FIELD,`A TableGroup field should only have a single Table name`,e))),t})}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===`note`);return n.length>1&&t.push(...n.map(e=>new E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}registerField(e){if(e.callee&&B(e.callee)){let t=I(e.callee).unwrap(),n=Ql(t),r=this.symbolFactory.create(El,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new E(T.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,e),new E(T.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,r.declaration)]}i.set(n,r)}return[]}},gu=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b?[new E(T.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?wu(e)?[]:[new E(T.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new E(T.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=N(e),n=t.getErrors();return Cc(t.getValue(),(e,t)=>{switch(t){case j.HeaderColor:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Ou(e.value)||n.push(new E(T.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case j.Note:e.length>1&&n.push(...e.map(e=>new E(T.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{z(e.value)||n.push(new E(T.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new E(T.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Al,{declaration:this.declarationNode,symbolTable:new ou});let t=P(e);if(!t.isOk())return[];let n=t.unwrap(),r=n.pop(),i=Eu(n,this.publicSymbolTable,this.symbolFactory),a=eu(r);return i.has(a)?[new E(T.DUPLICATE_NAME,`TablePartial name '${r}' already exists`,e)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(e){if(!e)return[];if(e instanceof x)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof x);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[];e.args.length===0&&t.push(new E(T.INVALID_COLUMN,`A column must have a type`,e.callee)),B(e.callee)||t.push(new E(T.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Pu(e.args[0])&&t.push(new E(T.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n),...this.registerField(e)),t})}registerField(e){if(!e.callee||!B(e.callee))return[];let t=I(e.callee).unwrap(),n=Jl(t),r=this.symbolFactory.create(wl,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new E(T.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new E(T.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}return i.set(n,r),[]}validateFieldSetting(e){let t=m(e);if(!e.slice(0,-1).every($u)||!($u(t)||t instanceof C))return[...e.map(e=>new E(T.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e))];if(e.length===0)return[];let n;m(e)instanceof C&&(n=e.pop());let r=N(n),i=r.getErrors(),a=r.getValue();e.forEach(e=>{let t=I(e).unwrap_or(``).toLowerCase();if(t!==j.PK&&t!==j.Unique){i.push(new E(T.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}a[t]===void 0?a[t]=[e]:a[t].push(e)});let o=a[j.PK]||[],s=a[j.PrimaryKey]||[];return o.length>=1&&s.length>=1&&i.push(...[...o,...s].map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Cc(a,(e,t)=>{switch(t){case j.Note:e.length>1&&i.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{z(e.value)||i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case j.Ref:e.forEach(e=>{Mu(e.value)||i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case j.PrimaryKey:e.length>1&&i.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{ku(e.value)||i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case j.PK:e.length>1&&i.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof al&&!ku(e.value)&&i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case j.NotNull:{e.length>1&&i.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=a[j.Null]||[];e.length>=1&&n.length>=1&&i.push(...[...e,...n].map(e=>new E(T.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{ku(e.value)||i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case j.Null:e.length>1&&i.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{ku(e.value)||i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case j.Unique:e.length>1&&i.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof al&&!ku(e.value)&&i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case j.Increment:e.length>1&&i.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof al&&!ku(e.value)&&i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case j.Default:e.length>1&&i.push(...e.map(e=>new E(T.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Au(e.value)||i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case j.Check:e.forEach(e=>{e.value instanceof ll||i.push(new E(T.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>i.push(new E(T.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),i}validateSubElements(e){let t=e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[])),n=e.filter(e=>e.type?.value.toLowerCase()===A.Note);return n.length>1&&t.push(...n.map(e=>new E(T.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}},_u=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new E(T.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof y)return[e];let t=Fu(this.declarationNode.parent).unwrap_or(void 0);return t&&[A.Table,A.TablePartial].includes(t)?[]:[e]}validateName(e){return e?[new E(T.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof x)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=h(e.body,e=>e instanceof x);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 m(n)instanceof C&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof ll))&&t.push(new E(T.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=N(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`name`:t.length>1&&t.forEach(t=>n.push(new E(T.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{z(t.value)||n.push(new E(T.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new E(T.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}},vu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}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 y||e instanceof b&&Fu(e).unwrap_or(void 0)===A.Table?[]:[new E(T.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return this.declarationNode.parent instanceof y?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof w))return[new E(T.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,e||this.declarationNode.type)];let t=[];return(!e.callee||!Su(e.callee))&&t.push(new E(T.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Nu(e.argumentList))&&t.push(new E(T.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Nu(e)?[new E(T.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new E(T.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof x)return this.validateDataRow(e);let[t,n]=h(e.body,e=>e instanceof x);return[...this.validateDataRows(t),...this.validateSubElements(n)]}validateDataRows(e){return e.flatMap(e=>this.validateDataRow(e))}validateDataRow(e){let t=[];if(!e.callee||e.args.length>0)return t.push(new E(T.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof dl)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new E(T.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,n));else this.isValidRecordValue(e.callee)||t.push(new E(T.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,e.callee));return t}isValidRecordValue(e){if(e instanceof gl||ju(e)||z(e)||e instanceof ll)return!0;if(B(e)){let t=e.expression.variable.value.toLowerCase();return Hl.includes(t)}if(ed(e)){let t=P(e).unwrap_or(void 0);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(xu(e))(e,this.publicSymbolTable,this.symbolFactory).validate():[]))}};function yu(e){return e&&e instanceof hl&&e.expression instanceof ml?e.expression.variable?.value===`*`:!1}var bu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof b?[new E(T.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?wu(e)?[]:[new E(T.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new E(T.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new E(T.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Dl,{declaration:this.declarationNode,symbolTable:new ou});let t=P(e);if(t.isOk()){let n=t.unwrap(),r=n.pop(),i=Eu(n,this.publicSymbolTable,this.symbolFactory),a=nu(r);if(i.has(a))return[new E(T.DUPLICATE_DIAGRAMVIEW_NAME,`DiagramView name '${r}' already exists`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=N(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new E(T.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return[];if(e instanceof x)return[new E(T.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)];let[t,n]=h(e.body,e=>e instanceof x);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(yu(e.callee))return[];let t=[];return t.push(new E(T.INVALID_DIAGRAMVIEW_FIELD,`Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.`,e)),t})}validateSubElements(e){let t=[],n=[`tables`,`notes`,`tablegroups`,`schemas`];for(let r of e){if(r.parent=this.declarationNode,!r.type)continue;let e=r.type.value.toLowerCase();if(!n.includes(e)){t.push(new E(T.INVALID_DIAGRAMVIEW_FIELD,`Unknown block type "${r.type.value}" in DiagramView. Allowed: Tables, Notes, TableGroups, Schemas`,r));continue}t.push(...this.validateSubBlock(r)),t.push(...this.registerSubBlockFields(r))}return t}validateSubBlock(e){let t=[];if(!e.body||!(e.body instanceof S))return t;let n=e.body,r=n.body.some(e=>e instanceof x&&yu(e.callee)),i=n.body.some(e=>e instanceof x&&!yu(e.callee));return r&&i&&t.push(new Nl(T.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t}registerSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof S))return t;let n=e.body.body.filter(e=>e instanceof x);for(let e of n){if(e.callee&&B(e.callee)){if(yu(e.callee))continue;let n=I(e.callee).unwrap(),r=ru(n),i=this.symbolFactory.create(Ol,{declaration:e});e.symbol=i;let a=this.declarationNode.symbol.symbolTable;if(a.has(r)){let i=a.get(r);t.push(new E(T.DUPLICATE_DIAGRAMVIEW_FIELD,`${n} already exists in DiagramView`,e),new E(T.DUPLICATE_DIAGRAMVIEW_FIELD,`${n} already exists in DiagramView`,i.declaration))}else a.set(r,i)}e.args.length>0&&t.push(...e.args.map(e=>new E(T.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)))}return t}};function xu(e){switch(e.type.value.toLowerCase()){case A.Enum:return su;case A.Table:return pu;case A.TableGroup:return hu;case A.Project:return uu;case A.Ref:return du;case A.Note:return lu;case A.Indexes:return cu;case A.TablePartial:return gu;case A.Check:return _u;case A.Records:return vu;case A.DiagramView:return bu;default:return Gl}}function Su(e){return!!P(e).unwrap_or(!1)}function Cu(e){return wu(e)}function wu(e){return e instanceof hl&&e.expression instanceof ml}function Tu(e){return e instanceof ol&&e.op?.value===`~`&&B(e.expression)}function Eu(e,t,n){e[0]===`public`&&(e=e.slice(1));let r=t;for(let t of e){let e,i=Kl(t);if(r.has(i)){if(e=r.get(i)?.symbolTable,!e)throw Error(`Expect a symbol table in a schema symbol`)}else{e=new ou;let t=n.create(bl,{symbolTable:e});r.set(i,t)}r=e}return r}function Du(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function Ou(e){if(!(e instanceof hl)||!(e.expression instanceof pl)||e.expression.literal?.kind!==g.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(!Il(t[e]))return!1;return!0}function ku(e){return e===void 0}function Au(e){if(z(e)||ju(e)||$u(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof ol&&Ul.includes(e.op?.value)&&ju(e.expression)||e instanceof ll)return!0;if(!e||!td(e))return!1;let t=Iu(e).unwrap();return t.length===2||t.length===3}function ju(e){return e instanceof ol?Ul.includes(e.op.value)?ju(e.expression):!1:e instanceof hl&&e.expression instanceof pl&&e.expression.literal?.kind===g.NUMERIC_LITERAL}function Mu(e){if(!(e instanceof ol)||!Du(e.op?.value))return!1;let t=P(e.expression).unwrap_or(void 0);return t!==void 0&&t.length>0}function Nu(e){return e instanceof ul&&e.elementList.every(B)}function Pu(e){if(!(e instanceof w||ed(e)||e instanceof hl||e instanceof _l))return!1;for(;e instanceof w||e instanceof _l;)if(e instanceof w){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>ju(e)||z(e)||$u(e)))return!1;e=e.callee}else if(e instanceof _l){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&ju(e.name)))return!1;e=e.array}let t=P(e).unwrap_or(void 0);return t!==void 0&&t.length>0}function N(e){let t={},n=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof hl){n.push(new E(T.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let r=nd(e.name).unwrap_or(void 0)?.toLowerCase();r&&(t[r]===void 0?t[r]=[e]:t[r].push(e))}),new D(t,n)):new D({})}function Fu(e){let t=e?.type?.value.toLowerCase();switch(t){case A.Enum:case A.Table:case A.Indexes:case A.Note:case A.Project:case A.Ref:case A.TableGroup:case A.TablePartial:case A.Check:case A.Records:case A.DiagramView:return new O(t);default:return new k}}function Iu(e){if(!e)return new k;if(!ed(e))return new O([e]);let t=Iu(e.leftExpression).unwrap_or(void 0);return t?(t.push(e.rightExpression),new O(t)):new k}function P(e){if(e===void 0)return new k;let t=Iu(e).unwrap_or(void 0);if(!t)return new k;let n=[];for(let e of t){let t=F(e).unwrap_or(void 0);if(typeof t!=`string`)return new k;n.push(t)}return new O(n)}function Lu(e){if(e===void 0)return new k;let t=Iu(e).unwrap_or(void 0);if(!t||t.length===0)return new k;let n=[];if(!B(m(t))){let e=t.pop();if(Nu(e))n=e.elementList;else return new k}let r=t;return r.every(B)?new O({variables:r,tupleElements:n}):new k}function F(e){return B(e)?new O(e.expression.variable.value):new k}function Ru(e){return Uu(e)?e instanceof ll?new O({functional:[e],nonFunctional:[]}):new O({functional:[],nonFunctional:[e]}):e instanceof ul&&e.elementList.every(Uu)?new O({functional:e.elementList.filter(e=>e instanceof ll),nonFunctional:e.elementList.filter(B)}):new k}function I(e){let t=e?.expression.variable?.value;return t===void 0?new k:new O(t)}function L(e){return z(e)?e.expression instanceof ml?new O(e.expression.variable.value):new O(e.expression.literal.value):new k}function zu(e){return e instanceof hl&&e.expression instanceof pl&&e.expression.literal?.kind===g.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function Bu(e){if(e)return B(e)?e.referee:e instanceof sl&&e.op?.value===`.`?Bu(e.rightExpression):e.referee}function Vu(e){return!(e instanceof sl)||!Du(e.op?.value)?!1:Lu(e.leftExpression).and_then(()=>Lu(e.rightExpression)).unwrap_or(void 0)!==void 0}function Hu(e){let t=Lu(e.leftExpression),n=Lu(e.rightExpression);if(!t.isOk()||!n.isOk())return!1;let{tupleElements:r}=t.unwrap(),{tupleElements:i}=n.unwrap();return r?.length===i?.length}function Uu(e){return e instanceof hl&&e.expression instanceof ml||e instanceof ll}function Wu(e){if(!(e instanceof w)||!e.callee)return new k;let t=Iu(e.callee).unwrap_or(void 0);if(!t||t.length===0||!t.every(B))return new k;let n=[];return Nu(e.argumentList)&&(n=[...e.argumentList.elementList]),new O({variables:t,args:n})}function Gu(e,t,n){let r=t,i=e;if(i instanceof w&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!$u(i)||r.length===0)return new k;let a=[...r],o=Qu(i).unwrap(),s=a.pop();if(!(s instanceof S))return new k;let c=m(a)instanceof C?a.pop():void 0;if(a.length===3){let e=Qu(a[1]).value;return!e||!Ku(e)?new k:new O(n.create(b,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s}))}return a.length===1?new O(n.create(b,{type:o,name:a[0],attributeList:c,body:s})):a.length===0?new O(n.create(b,{type:o,attributeList:c,body:s})):new k}function Ku(e){return e?.kind===g.IDENTIFIER&&e.value.toLowerCase()===`as`}function R(e){e&&(e instanceof Xc?qu(e):Ju(e))}function qu(e){e.kind!==g.EOF&&(e.isInvalid=!0)}function Ju(e){if(e instanceof b)R(e.type),R(e.name),R(e.as),R(e.alias),R(e.bodyColon),R(e.attributeList),R(e.body);else if(e instanceof il)e.identifiers.forEach(R);else if(e instanceof al)R(e.name),R(e.colon),R(e.value);else if(e instanceof ol)R(e.op),R(e.expression);else if(e instanceof sl)R(e.leftExpression),R(e.op),R(e.rightExpression);else if(e instanceof cl)R(e.op),R(e.expression);else if(e instanceof S)R(e.blockOpenBrace),e.body.forEach(R),R(e.blockCloseBrace);else if(e instanceof C)R(e.listOpenBracket),e.commaList.forEach(R),e.elementList.forEach(R),R(e.listCloseBracket);else if(e instanceof ul)R(e.tupleOpenParen),e.commaList.forEach(R),e.elementList.forEach(R),R(e.tupleCloseParen);else if(e instanceof dl)e.commaList.forEach(R),e.elementList.forEach(R);else if(e instanceof w)R(e.callee),R(e.argumentList);else if(e instanceof x)R(e.callee),e.args.forEach(R);else if(e instanceof hl)R(e.expression);else if(e instanceof ll)R(e.value);else if(e instanceof ml)R(e.variable);else if(e instanceof pl)R(e.literal);else if(e instanceof fl)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof _l)R(e.array),R(e.indexer);else if(e instanceof y)e.body.forEach(R),R(e.eof);else if(!(e instanceof gl))throw Error(`Unreachable case in markInvalidNode`)}function Yu(e){return!!e?.isInvalid}function Xu(...e){return e.filter(e=>e!==void 0)}function Zu(e){if(e instanceof y)return Xu(...e.body,e.eof);if(e instanceof b)return Xu(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof al)return Xu(e.name,e.colon,e.value);if(e instanceof il)return e.identifiers;if(e instanceof pl)return e.literal?[e.literal]:[];if(e instanceof ml)return Xu(e.variable);if(e instanceof ol)return Xu(e.op,e.expression);if(e instanceof sl)return Xu(e.leftExpression,e.op,e.rightExpression);if(e instanceof cl)return Xu(e.expression,e.op);if(e instanceof ll)return Xu(e.value);if(e instanceof x)return Xu(e.callee,...e.args);if(e instanceof S)return Xu(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof C)return Xu(e.listOpenBracket,...Rl(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof ul)return Xu(e.tupleOpenParen,...Rl(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof dl)return Xu(...Rl(e.elementList,e.commaList));if(e instanceof w)return Xu(e.callee,e.argumentList);if(e instanceof hl)return Xu(e.expression);if(e instanceof _l)return Xu(e.array,e.indexer);throw e instanceof fl?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Qu(e){return B(e)?new O(e.expression.variable):new k}function z(e){return e instanceof hl&&(e.expression instanceof ml&&e.expression.variable instanceof Xc&&e.expression.variable.kind===g.QUOTED_STRING||e.expression instanceof pl&&e.expression.literal?.kind===g.STRING_LITERAL)}function B(e){return e instanceof hl&&e.expression instanceof ml&&e.expression.variable instanceof Xc}function $u(e){return e instanceof hl&&e.expression instanceof ml&&e.expression.variable?.kind===g.IDENTIFIER}function ed(e){return e instanceof sl&&e.leftExpression instanceof _&&e.rightExpression instanceof _&&e.op?.value===`.`}function td(e){return B(e)?!0:ed(e)&&B(e.rightExpression)&&td(e.leftExpression)}function nd(e){if(e===void 0)return new k;let t=e.identifiers.map(e=>e.value).join(` `);return t===``?new k:new O(t)}function rd(e){return P(e?.name).map(e=>e.join(`.`))}var id=class{constructor(e){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
|
|
2
|
+
`?(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 Xc.create(e,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),t)}lex(){return this.scanTokens(),this.tokens.push(Xc.create(g.EOF,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new D(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(g.SPACE);break;case`\r`:break;case`
|
|
3
|
+
`:this.addToken(g.NEWLINE);break;case` `:this.addToken(g.TAB);break;case`,`:this.addToken(g.COMMA);break;case`(`:this.addToken(g.LPAREN);break;case`)`:this.addToken(g.RPAREN);break;case`[`:this.addToken(g.LBRACKET);break;case`]`:this.addToken(g.RBRACKET);break;case`{`:this.addToken(g.LBRACE);break;case`}`:this.addToken(g.RBRACE);break;case`;`:this.addToken(g.SEMICOLON);break;case`:`:this.addToken(g.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;default:if(Jc(e)){this.operator(e);break}if(Pl(e)){this.identifier();break}if(Fl(e)){this.numericLiteralOrIdentifier();break}this.addToken(g.OP,!0),this.errors.push(new E(T.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(g.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)qc(i)?(t.push(i),i.kind===g.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&&Yu(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];Yu(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(`
|
|
4
|
+
`))&&!this.check(t);)this.peek()===`\\`&&!i?(this.advance(),o+=this.escapedString()):o+=this.advance();if(this.isAtEnd()&&!r){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new E(T.UNEXPECTED_EOF,`EOF reached while parsing`,t));return}if(this.check(`
|
|
5
|
+
`)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new E(T.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(Xc.create(e,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(g.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(g.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(g.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(g.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(g.SINGLE_LINE_COMMENT,`
|
|
6
|
+
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(g.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Ll(this.peek());)this.advance();this.addToken(g.IDENTIFIER)}operator(e){switch(e){case`<`:[`>`,`=`].includes(this.peek())&&this.advance();break;case`>`:this.peek()===`=`&&this.advance();break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(g.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(g.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=t?1:0,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&&Fl(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Fl(this.peek());)this.advance();if(this.isAtEnd()||!Ll(this.peek()))return this.addToken(g.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(g.NUMERIC_LITERAL);if(!t&&!Ll(this.peek()))return this.addToken(g.NUMERIC_LITERAL);if(!t&&!Fl(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||Ll(this.peek()));)this.advance();let e=this.createToken(g.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new E(T.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&Ll(this.peek());)this.advance();let e=this.createToken(g.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&Ll(this.peek());)this.advance();this.addToken(g.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(`
|
|
7
7
|
`)&&this.advance(),``;case`
|
|
8
8
|
`:return``;case`t`:return` `;case`n`:return`
|
|
9
|
-
`;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()||!Nl(this.peek()))return this.errors.push(new D(E.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`,Yc.create(_.STRING_LITERAL,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}};let Qu=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({});var $u=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===Qu.ListExpression&&(this.numberOfNestedLBrackets+=1),e===Qu.GroupExpression&&(this.numberOfNestedLParens+=1),e===Qu.BlockExpression&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===Qu.ListExpression&&--this.numberOfNestedLBrackets,e===Qu.GroupExpression&&--this.numberOfNestedLParens,e===Qu.BlockExpression&&--this.numberOfNestedLBraces,e}top(){return h(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case _.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[Qu.GroupExpression,Qu.ListExpression].includes(e));break;case _.RPAREN:if(this.isWithinGroupExpressionContext())return Qu.GroupExpression;break;case _.RBRACE:if(this.isWithinBlockExpressionContext())return Qu.BlockExpression;break;case _.RBRACKET:if(this.isWithinListExpressionContext())return Qu.ListExpression;break;default:break}}},ed=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}},V=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},td=class{constructor(e,t,n){this.current=0,this.errors=[],this.contextStack=new $u,this.synchronizeProgram=()=>{let e=this.peek();e.kind===_.EOF?this.logError(e,E.UNEXPECTED_EOF,`Unexpected EOF`):z(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ru(e)||this.check(_.COLON,_.LBRACE,_.LBRACKET))break;z(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COLON,_.LBRACE,_.LBRACKET))break;z(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Qu.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(C,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(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 V))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(_.RBRACE))for(z(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||Zc(this.previous(),e))break;z(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Qu.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(dl,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ll,e);try{this.consume(`Expect an opening parenthesis '('`,_.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(_.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof V))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new V(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 V))throw t;if(t.partialNode instanceof v&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new V(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,_.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(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;z(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Qu.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 V))throw e;if(!this.canHandle(e))throw new V(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(_.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof V))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new V(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 V))throw n;if(n.partialNode instanceof v&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,_.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;z(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET,_.COLON))break;z(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;z(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new ed(n)}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(),E.UNEXPECTED_TOKEN,e),new V(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(z(this.peek()),this.logError(this.advance(),E.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)z(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(),n=this.nodeFactory.create(b,{body:e,eof:t,source:this.source});return this.gatherInvalid(),new O({ast:n,tokens:this.tokens},this.errors)}program(){let e=[];for(;!this.isAtEnd();)try{let t=this.elementDeclaration();e.push(t)}catch(t){if(!(t instanceof V))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(x,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof V?new V(e.token,t(),e.handlerContext):e}if(!this.check(_.COLON,_.LBRACE,_.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof V))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ru(this.peek()))if(e.as=this.advance(),this.check(_.COLON,_.LBRACE,_.LBRACKET))this.logError(this.peek(),E.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof V))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(_.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof V?(e.attributeList=n.partialNode,new V(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 x?(z(t),this.logError(t,E.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 V?(e.body=n.partialNode,new V(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(x,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(x,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof V?(e.type=n.partialNode,new V(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,_.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof V?(e.bodyColon=n.partialNode,new V(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof x?this.errors.push(new D(E.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof V?(e.body=n.partialNode,new V(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(x,e)}expression(){let e={args:[]},t=()=>Lu(e.callee,e.args,this.nodeFactory).unwrap_or(this.nodeFactory.create(S,e));try{e.callee=this.commaExpression()}catch(n){throw n instanceof V?(e.callee=n.partialNode,new V(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Qc(this.previous())||this.logError(n,E.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof V?(n=r.partialNode,e.args.push(n),new V(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Xc(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(hl,{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(hl,{prevToken:this.previous()}));break}if(this.check(_.COMMA)){t.elementList.push(this.nodeFactory.create(hl,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof V?(e.partialNode&&t.elementList.push(e.partialNode),new V(e.token,this.nodeFactory.create(ul,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(_.COMMA));return this.nodeFactory.create(ul,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Xc(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}=sd(n);if(r<e||Zc(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(T,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof V?(t=this.nodeFactory.create(T,{callee:t,argumentList:e.partialNode}),new V(e.token,t,e.handlerContext)):e}}else if(n.kind===_.LBRACKET){if(Qc(this.previous()))break;try{t=this.nodeFactory.create(gl,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof V?(t=this.nodeFactory.create(gl,{expression:t,indexer:e.partialNode}),new V(e.token,t,e.handlerContext)):e}}else if(Jc(n)){let r=n,i=sd(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(sl,{expression:t,op:r})}else{let n=rd(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(ol,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof V?(t=this.nodeFactory.create(ol,{leftExpression:t,op:r,rightExpression:e.partialNode}),new V(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Jc(this.peek())){let t={};t.op=this.peek();let n=ad(t.op);if(n.right===null)throw this.logError(t.op,E.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new V(t.op,this.nodeFactory.create(hl,{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 V?(t.expression=e.partialNode,new V(e.token,this.nodeFactory.create(al,t),e.handlerContext)):e}e=this.nodeFactory.create(al,t)}else if(e=this.extractOperand(),e instanceof hl)throw new V(this.peek(),this.nodeFactory.create(hl,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return 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(),E.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),E.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(hl,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,_.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof V?new V(t.token,this.nodeFactory.create(cl,e),t.handlerContext):t}return this.nodeFactory.create(cl,e)}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(ml,{expression:this.nodeFactory.create(fl,{literal:this.previous()})});if(this.match(_.QUOTED_STRING,_.IDENTIFIER))return this.nodeFactory.create(ml,{expression:this.nodeFactory.create(pl,{variable:this.previous()})});throw this.logError(this.peek(),E.UNEXPECTED_TOKEN,`Expect a variable or literal`),new V(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,E.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(rl,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof V))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new V(t.token,this.nodeFactory.create(il,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(_.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(il,e)}attributeValue(){let e;try{e=this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof V)||!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 V?new V(t.token,this.nodeFactory.create(rl,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(rl,{identifiers:e})}logError(e,t,n){this.errors.push(new D(t,n,e))}},nd={"+":{left:9,right:10},"*":{left:11,right:12},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function rd(e){return nd[e.value]||{left:null,right:null}}var id={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function ad(e){return id[e.value]||{left:null,right:null}}var od={"(":{left:14,right:null}};function sd(e){return od[e.value]||{left:null,right:null}}var cd=class{constructor(e,t){this.ast=e,this.symbolFactory=t,this.publicSchemaSymbol=this.symbolFactory.create(yl,{symbolTable:new eu}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){let e=[];this.ast.body.forEach(t=>{if(t.parent=this.ast,t.type===void 0)return;let n=new(pu(t))(t,this.publicSchemaSymbol.symbolTable,this.symbolFactory);e.push(...n.validate())});let t=this.ast.body.filter(e=>Du(e).unwrap_or(void 0)===j.Project);return t.length>1&&t.forEach(t=>e.push(new D(E.PROJECT_REDEFINED,`Only one project can exist`,t))),new O(this.ast,e)}},ld=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return[]}},ud=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof S)return[];let t=e.body.filter(e=>e instanceof x);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}},dd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof C?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof S)return[];let t=e.body.filter(e=>e instanceof S);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}},fd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof x)||Du(this.declarationNode.parent).unwrap_or(void 0)!==j.Table||!(this.declarationNode.body instanceof C)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof S)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof S);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=F(this.declarationNode.parent.name).map(e=>e.join(`.`)).unwrap_or(`<unnamed>`),n=this.declarationNode.parent.symbol.symbolTable;return[e.callee,...e.args].flatMap(Cd).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=L(e).unwrap_or(void 0);if(r===void 0)return[];let i=Wl(r),a=n.get(i);return a?(e.referee=a,a.references.push(e),[]):new D(E.BINDING_ERROR,`No column named '${r}' inside Table '${t}'`,e)})})}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}},pd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof S)return[];let t=e.body.filter(e=>e instanceof x);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}},md=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof C?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof S)return[];let t=e.body.filter(e=>e instanceof x);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}},hd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof b)&&Du(this.declarationNode.parent).unwrap_or(void 0)!==j.Project?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof S)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof S);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Cd).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();if(!t||!n)return[];Array.isArray(t)||(t=[t]);let r=e.variables;return t.flatMap(e=>wd(this.ast,[...r.map(e=>({node:e,kind:N.Schema})),{node:n,kind:N.Table},{node:e,kind:N.Column}]))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}},gd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof C?this.bindBody(this.declarationNode.body):[]}resolvePartialInjections(){let{body:e}=this.declarationNode;return(e?e instanceof C?e.body:[e]:[]).filter(e=>e instanceof S&&_u(e.callee)).reverse().flatMap(e=>{let t=ku(e.callee.expression).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=wd(this.ast,[...r.map(e=>({node:e,kind:N.Schema})),{node:n,kind:N.TablePartial}]);return i.length?i:(n.referee?.symbolTable?.forEach(t=>{let r=I(t.declaration.callee).unwrap_or(void 0);if(r===void 0)return;let i=this.symbolFactory.create(Ol,{declaration:e,tablePartialSymbol:n.referee}),a=Wl(r),o=this.declarationNode.symbol?.symbolTable;o?.has(a)||o?.set(a,i)}),[])})}bindBody(e){if(!e)return[];if(e instanceof S)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof S);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=P(h(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!_u(e.callee)))}tryToBindColumnType(e){let t=ku(e).unwrap_or(void 0);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&wd(this.ast,[...r.map(e=>({node:e,kind:N.Schema})),{node:n,kind:N.Enum}])}tryToBindEnumFieldRef(e){if(Gu(e))return[];if(B(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&Rl.includes(t))return[]}let t=ku(e).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=t.variables;return wd(this.ast,[...i.map(e=>({node:e,kind:N.Schema})),{node:r,kind:N.Enum},{node:n,kind:N.EnumField}])}bindInlineRef(e){return Cd(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?wd(this.ast,[...r.map(e=>({node:e,kind:N.Schema})),{node:n,kind:N.Table},{node:t,kind:N.Column}]):wd(this.declarationNode,[{node:t,kind:N.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}},_d=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof C?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof S)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof S);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Cd).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return wd(this.ast,[...n.map(e=>({node:e,kind:N.Schema})),{node:t,kind:N.Table}])}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}},vd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof C?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof S)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof S);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=P(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=ku(e).unwrap_or(void 0);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&wd(this.ast,[...r.map(e=>({node:e,kind:N.Schema})),{node:n,kind:N.Enum}])}bindInlineRef(e){return Cd(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?wd(this.ast,[...r.map(e=>({node:e,kind:N.Schema})),{node:n,kind:N.Table},{node:t,kind:N.Column}]):wd(this.declarationNode,[{node:t,kind:N.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}};function yd(e){return[Hl,Ul,Gl,ql,Wl,Kl,Jl,Xl,Zl].map(t=>t(e))}function bd(e){if(e instanceof yl)return N.Schema;if(e instanceof Sl)return N.Table;if(e instanceof Cl)return N.Column;if(e instanceof bl)return N.Enum;if(e instanceof xl)return N.EnumField;if(e instanceof wl)return N.TableGroup;if(e instanceof Tl)return N.TableGroupField;if(e instanceof El)return N.TablePartial;if(e instanceof Ol)return N.Column;if(e instanceof Dl)return N.PartialInjection;throw Error(`No other possible symbol kind in getSymbolKind`)}var xd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof C&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof b?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let t=Iu(e).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=wd(this.ast,[...r.map(e=>({node:e,kind:N.Schema})),{node:n,kind:N.Table}]);if(i.length>0)return i;let a=n.referee;if(!a?.symbolTable)return[];let o=Xu(n.referee?.declaration).unwrap_or(`<invalid name>`),s=[];for(let e of t.args){let t=L(e).unwrap_or(`<unnamed>`),n=Wl(t),r=a.symbolTable.get(n);if(!r){s.push(new D(E.BINDING_ERROR,`Column '${t}' does not exist in Table '${o}'`,e));continue}e.referee=r,r.references.push(e);let i=this.boundColumns.get(r);i&&(s.push(new D(E.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,i)),s.push(new D(E.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,e))),this.boundColumns.set(r,e)}return s}bindInsideTableName(e){let t=this.declarationNode.parent;if(!(t instanceof x)||Du(t).unwrap_or(void 0)!==j.Table)return[];let n=t.symbol?.symbolTable;if(!n||!Tu(e))return[];let r=Xu(t).unwrap_or(`<invalid name>`),i=[];for(let t of e.elementList){let e=L(t).unwrap_or(`<unnamed>`),a=Wl(e),o=n.get(a);if(!o){i.push(new D(E.BINDING_ERROR,`Column '${e}' does not exist in Table '${r}'`,t));continue}t.referee=o,o.references.push(t)}return i}bindBody(e){if(!e)return[];if(e instanceof S)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof S),n=e.body.filter(e=>e instanceof x);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof ul?e.callee.elementList:[e.callee]).flatMap(Cd).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t||!n)return[];let r=e.variables;return wd(this.ast,[...r.map(e=>({node:e,kind:N.Schema})),{node:n,kind:N.Enum},{node:t,kind:N.EnumField}])}):[]}bindSubElements(e){return e.flatMap(e=>e.type?new(Sd(e))(e,this.ast,this.symbolFactory).bind():[])}};function Sd(e){switch(e.type.value.toLowerCase()){case j.Enum:return dd;case j.Table:return gd;case j.TableGroup:return _d;case j.Project:return md;case j.Ref:return hd;case j.Note:return pd;case j.Indexes:return fd;case j.TablePartial:return vd;case j.Check:return ld;case j.Records:return xd;default:return ud}}function Cd(e){if(!e)return[];if(B(e))return[{variables:[e],tupleElements:[]}];if(e instanceof ol){let t=ku(e).unwrap_or(void 0);return t?[t]:[...Cd(e.leftExpression),...Cd(e.rightExpression)]}if(e instanceof al||e instanceof sl)return Cd(e.expression);if(e instanceof ll){let t=ku(e).unwrap_or(void 0);return t?[t]:e.elementList.flatMap(Cd)}return[]}function wd(e,t){if(!e.symbol?.symbolTable)throw Error(`lookupAndBindInScope should only be called with initial scope having a symbol table`);let n=e.symbol.symbolTable,r=bd(e.symbol),i=e instanceof x?Xu(e).unwrap_or(`<invalid name>`):Bl;if(e instanceof b&&t.length){let{node:e,kind:n}=t[0];L(e).unwrap_or(`<unnamed>`)===`public`&&n===N.Schema&&t.shift()}for(let e of t){let{node:t,kind:a}=e,o=L(t).unwrap_or(`<unnamed>`),s=Ql(o,a),c=n.get(s);if(!c)return[new D(E.BINDING_ERROR,`${a} '${o}' does not exist in ${i===void 0?`global scope`:`${r} '${i}'`}`,t)];if(t.referee=c,c.references.push(t),i=o,r=a,!c.symbolTable)return[];n=c.symbolTable}return[]}var Td=class{constructor(e,t){this.ast=e,this.symbolFactory=t}resolvePartialInjections(){return this.ast.body.filter(e=>Du(e).unwrap_or(``)===j.Table).flatMap(e=>new gd(e,this.ast,this.symbolFactory).resolvePartialInjections())}resolve(){let e=[];e.push(...this.resolvePartialInjections());for(let t of this.ast.body)if(t.type){let n=new(Sd(t))(t,this.ast,this.symbolFactory);e.push(...n.bind())}return new O(this.ast,e)}},Ed=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}},Dd=class{constructor(e,t){this.ast=e,this.symbolFactory=new Ed(t)}analyze(){return new cd(this.ast,this.symbolFactory).validate().chain(e=>new Td(e,this.symbolFactory).resolve())}validate(){return new cd(this.ast,this.symbolFactory).validate().chain(e=>new O(e,[]))}};function Od(e,t){let{variables:n,tupleElements:r}=ku(e).unwrap(),i=r.map(e=>L(e).unwrap()),a=n.map(e=>L(e).unwrap());return r.length?n.length===0?{schemaName:t.schemaName,tableName:t.name,fieldNames:i}:{tableName:a.pop(),schemaName:a.pop()||null,fieldNames:i}:n.length===1?{schemaName:t.schemaName,tableName:t.name,fieldNames:[a[0]]}:{fieldNames:[a.pop()],tableName:a.pop(),schemaName:a.pop()||null}}function kd(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:throw Error(`Invalid relation op`)}}function H(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}}}function Ad(e){let t=Ou(e).unwrap_or(void 0)?.pop();return t instanceof ll?t.elementList.map(e=>e.referee):[t.referee]}function jd(e){let t=F(e).unwrap();return{name:t.pop(),schemaName:t}}function Md(e){return e.expression.literal.value}function Nd(e,t){if(Array.isArray(e)){let n=e.map(({id:e})=>e).sort().join(`,`),r=t.map(({id:e})=>e).sort().join(`,`);return n<r?`${n}-${r}`:`${r}-${n}`}let n=e.id.toString(),r=t.id.toString();return n<r?`${n}-${r}`:`${r}-${n}`}function Pd(e,t){return Array.isArray(e)?Gc(e.map(({id:e})=>e).sort(),t.map(({id:e})=>e).sort()).every(([e,t])=>e===t):e.id===t.id}function Fd(e){let t=e.split(`
|
|
9
|
+
`;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()||!Ll(this.peek()))return this.errors.push(new E(T.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Xc.create(g.STRING_LITERAL,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}};let ad=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({});var od=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===ad.ListExpression&&(this.numberOfNestedLBrackets+=1),e===ad.GroupExpression&&(this.numberOfNestedLParens+=1),e===ad.BlockExpression&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===ad.ListExpression&&--this.numberOfNestedLBrackets,e===ad.GroupExpression&&--this.numberOfNestedLParens,e===ad.BlockExpression&&--this.numberOfNestedLBraces,e}top(){return m(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 g.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[ad.GroupExpression,ad.ListExpression].includes(e));break;case g.RPAREN:if(this.isWithinGroupExpressionContext())return ad.GroupExpression;break;case g.RBRACE:if(this.isWithinBlockExpressionContext())return ad.BlockExpression;break;case g.RBRACKET:if(this.isWithinListExpressionContext())return ad.ListExpression;break;default:break}}},sd=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}},V=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},cd=class{constructor(e,t,n){this.current=0,this.errors=[],this.contextStack=new od,this.synchronizeProgram=()=>{let e=this.peek();e.kind===g.EOF?this.logError(e,T.UNEXPECTED_EOF,`Unexpected EOF`):R(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ku(e)||this.check(g.COLON,g.LBRACE,g.LBRACKET))break;R(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(g.COLON,g.LBRACE,g.LBRACKET))break;R(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(ad.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(S,e);try{this.consume(`Expect an opening brace '{'`,g.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(g.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof V))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,g.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(g.RBRACE))for(R(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(g.RBRACE)||Qc(this.previous(),e))break;R(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(ad.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(fl,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ul,e);try{this.consume(`Expect an opening parenthesis '('`,g.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(g.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof V))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(g.RPAREN);)try{this.consume(`Expect a comma ','`,g.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof V))throw t;if(t.partialNode instanceof _&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new V(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,g.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(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(g.RPAREN,g.COMMA))break;R(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(ad.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(C,e);try{this.consume(`Expect an opening bracket '['`,g.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(g.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof V))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(g.RBRACKET);)try{this.consume(`Expect a comma ','`,g.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof V))throw n;if(n.partialNode instanceof _&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,g.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof V))throw e;if(!this.canHandle(e))throw new V(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(g.COMMA,g.RBRACKET))break;R(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(g.COMMA,g.RBRACKET,g.COLON))break;R(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(g.COMMA,g.RBRACKET))break;R(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new sd(n)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===g.EOF}advance(){return this.isAtEnd()?m(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?m(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),T.UNEXPECTED_TOKEN,e),new V(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(R(this.peek()),this.logError(this.advance(),T.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)R(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(),n=this.nodeFactory.create(y,{body:e,eof:t,source:this.source});return this.gatherInvalid(),new D({ast:n,tokens:this.tokens},this.errors)}program(){let e=[];for(;!this.isAtEnd();)try{let t=this.elementDeclaration();e.push(t)}catch(t){if(!(t instanceof V))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(b,e);try{this.consume(`Expect an identifier`,g.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof V?new V(e.token,t(),e.handlerContext):e}if(!this.check(g.COLON,g.LBRACE,g.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof V))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ku(this.peek()))if(e.as=this.advance(),this.check(g.COLON,g.LBRACE,g.LBRACKET))this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof V))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new V(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(g.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof V?(e.attributeList=n.partialNode,new V(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,g.LBRACE,g.COLON))return t();try{if(this.match(g.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof b?(R(t),this.logError(t,T.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof V?(e.body=n.partialNode,new V(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(b,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(b,e);try{this.consume(`Expect an identifier`,g.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof V?(e.type=n.partialNode,new V(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,g.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof V?(e.bodyColon=n.partialNode,new V(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof b?this.errors.push(new E(T.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof V?(e.body=n.partialNode,new V(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(b,e)}expression(){let e={args:[]},t=()=>Gu(e.callee,e.args,this.nodeFactory).unwrap_or(this.nodeFactory.create(x,e));try{e.callee=this.commaExpression()}catch(n){throw n instanceof V?(e.callee=n.partialNode,new V(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){$c(this.previous())||this.logError(n,T.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof V?(n=r.partialNode,e.args.push(n),new V(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Zc(this.previous()))return!0;let e=this.peek().kind;return[g.RBRACE,g.RBRACKET,g.RPAREN,g.COMMA,g.COLON].includes(e)}commaExpression(){let e=this.check(g.COMMA)?this.nodeFactory.create(gl,{prevToken:this.previous()}):this.normalExpression();if(!this.check(g.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(gl,{prevToken:this.previous()}));break}if(this.check(g.COMMA)){t.elementList.push(this.nodeFactory.create(gl,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof V?(e.partialNode&&t.elementList.push(e.partialNode),new V(e.token,this.nodeFactory.create(dl,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(g.COMMA));return this.nodeFactory.create(dl,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Zc(this.previous()))return!0;let e=this.peek().kind;return[g.RBRACE,g.LBRACE,g.RBRACKET,g.LBRACKET,g.RPAREN,g.LPAREN,g.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===g.LPAREN){let{left:r}=md(n);if(r<e||Qc(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(w,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof V?(t=this.nodeFactory.create(w,{callee:t,argumentList:e.partialNode}),new V(e.token,t,e.handlerContext)):e}}else if(n.kind===g.LBRACKET){if($c(this.previous()))break;try{t=this.nodeFactory.create(_l,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof V?(t=this.nodeFactory.create(_l,{expression:t,indexer:e.partialNode}),new V(e.token,t,e.handlerContext)):e}}else if(Yc(n)){let r=n,i=md(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(cl,{expression:t,op:r})}else{let n=ud(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(sl,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof V?(t=this.nodeFactory.create(sl,{leftExpression:t,op:r,rightExpression:e.partialNode}),new V(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(this.check(g.OP)&&this.peek().value===`*`)this.advance(),e=this.nodeFactory.create(hl,{expression:this.nodeFactory.create(ml,{variable:this.previous()})});else if(Yc(this.peek())){let t={};t.op=this.peek();let n=fd(t.op);if(n.right===null)throw this.logError(t.op,T.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new V(t.op,this.nodeFactory.create(gl,{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 V?(t.expression=e.partialNode,new V(e.token,this.nodeFactory.create(ol,t),e.handlerContext)):e}e=this.nodeFactory.create(ol,t)}else if(e=this.extractOperand(),e instanceof gl)throw new V(this.peek(),this.nodeFactory.create(gl,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(g.NUMERIC_LITERAL,g.STRING_LITERAL,g.COLOR_LITERAL,g.QUOTED_STRING,g.IDENTIFIER)?this.primaryExpression():this.check(g.FUNCTION_EXPRESSION)?this.functionExpression():this.check(g.LBRACKET)?this.listExpression():this.check(g.LBRACE)?this.blockExpression():this.check(g.LPAREN)?this.tupleExpression():(this.peek().kind===g.EOF?this.logError(this.peek(),T.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),T.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(gl,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,g.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof V?new V(t.token,this.nodeFactory.create(ll,e),t.handlerContext):t}return this.nodeFactory.create(ll,e)}canBeField(){return this.peek().kind===g.IDENTIFIER&&this.peek(1).kind===g.COLON}primaryExpression(){if(this.match(g.COLOR_LITERAL,g.STRING_LITERAL,g.NUMERIC_LITERAL))return this.nodeFactory.create(hl,{expression:this.nodeFactory.create(pl,{literal:this.previous()})});if(this.match(g.QUOTED_STRING,g.IDENTIFIER))return this.nodeFactory.create(hl,{expression:this.nodeFactory.create(ml,{variable:this.previous()})});throw this.logError(this.peek(),T.UNEXPECTED_TOKEN,`Expect a variable or literal`),new V(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(g.COLON,g.RBRACKET,g.COMMA)){let t=this.peek();this.logError(t,T.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(il,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof V))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new V(t.token,this.nodeFactory.create(al,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(g.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(al,e)}attributeValue(){let e;try{e=this.peek().kind===g.IDENTIFIER&&this.peek(1).kind===g.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof V)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==g.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(g.COLON,g.COMMA,g.RBRACKET);)try{this.consume(`Expect an identifier`,g.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof V?new V(t.token,this.nodeFactory.create(il,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(il,{identifiers:e})}logError(e,t,n){this.errors.push(new E(t,n,e))}},ld={"+":{left:9,right:10},"*":{left:11,right:12},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function ud(e){return ld[e.value]||{left:null,right:null}}var dd={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function fd(e){return dd[e.value]||{left:null,right:null}}var pd={"(":{left:14,right:null}};function md(e){return pd[e.value]||{left:null,right:null}}var hd=class{constructor(e,t){this.ast=e,this.symbolFactory=t,this.publicSchemaSymbol=this.symbolFactory.create(bl,{symbolTable:new ou}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){let e=[];this.ast.body.forEach(t=>{if(t.parent=this.ast,t.type===void 0)return;let n=new(xu(t))(t,this.publicSchemaSymbol.symbolTable,this.symbolFactory);e.push(...n.validate())});let t=this.ast.body.filter(e=>Fu(e).unwrap_or(void 0)===A.Project);return t.length>1&&t.forEach(t=>e.push(new E(T.PROJECT_REDEFINED,`Only one project can exist`,t))),new D(this.ast,e)}},gd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return[]}},_d=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof x)return[];let t=e.body.filter(e=>e instanceof b);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}};function vd(e){return e&&e instanceof hl&&e.expression instanceof ml?e.expression.variable?.value===`*`:!1}var yd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof S?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=h(e.body,e=>e instanceof x);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>{if(!e.type)return[];let t=e.type.value.toLowerCase();if(!(e.body instanceof S))return[];let n=[];switch(t){case`tables`:n.push(...this.bindTableReferences(e.body));break;case`notes`:n.push(...this.bindNoteReferences(e.body));break;case`tablegroups`:n.push(...this.bindTableGroupReferences(e.body));break;case`schemas`:n.push(...this.bindSchemaReferences(e.body));break;default:break}return n})}bindTableReferences(e){let[t]=h(e.body,e=>e instanceof x);return t.flatMap(e=>!e.callee||vd(e.callee)?[]:[e.callee,...e.args].flatMap(Md).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Nd(this.ast,[...n.map(e=>({node:e,kind:M.Schema})),{node:t,kind:M.Table}])}))}bindNoteReferences(e){let[t]=h(e.body,e=>e instanceof x);return t.flatMap(e=>!e.callee||vd(e.callee)?[]:Md(e.callee).flatMap(e=>{let t=e.variables.pop();return t?Nd(this.ast,[{node:t,kind:M.Note}]):[]}))}bindTableGroupReferences(e){let[t]=h(e.body,e=>e instanceof x);return t.flatMap(e=>!e.callee||vd(e.callee)?[]:Md(e.callee).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Nd(this.ast,[...n.map(e=>({node:e,kind:M.Schema})),{node:t,kind:M.TableGroup}])}))}bindSchemaReferences(e){let[t]=h(e.body,e=>e instanceof x);return t.flatMap(e=>!e.callee||vd(e.callee)?[]:Md(e.callee).flatMap(e=>{let t=e.variables.pop();return t?Nd(this.ast,[{node:t,kind:M.Schema}]):[]}))}},bd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof S?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof x)return[];let t=e.body.filter(e=>e instanceof x);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}},xd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof b)||Fu(this.declarationNode.parent).unwrap_or(void 0)!==A.Table||!(this.declarationNode.body instanceof S)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof x)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof x);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=P(this.declarationNode.parent.name).map(e=>e.join(`.`)).unwrap_or(`<unnamed>`),n=this.declarationNode.parent.symbol.symbolTable;return[e.callee,...e.args].flatMap(Md).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=I(e).unwrap_or(void 0);if(r===void 0)return[];let i=Jl(r),a=n.get(i);return a?(e.referee=a,a.references.push(e),[]):new E(T.BINDING_ERROR,`No column named '${r}' inside Table '${t}'`,e)})})}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}},Sd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof x)return[];let t=e.body.filter(e=>e instanceof b);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}},Cd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof S?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof x)return[];let t=e.body.filter(e=>e instanceof b);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}},wd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof y)&&Fu(this.declarationNode.parent).unwrap_or(void 0)!==A.Project?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof x)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof x);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Md).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();if(!t||!n)return[];Array.isArray(t)||(t=[t]);let r=e.variables;return t.flatMap(e=>Nd(this.ast,[...r.map(e=>({node:e,kind:M.Schema})),{node:n,kind:M.Table},{node:e,kind:M.Column}]))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}},Td=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof S?this.bindBody(this.declarationNode.body):[]}resolvePartialInjections(){let{body:e}=this.declarationNode;return(e?e instanceof S?e.body:[e]:[]).filter(e=>e instanceof x&&Tu(e.callee)).reverse().flatMap(e=>{let t=Lu(e.callee.expression).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=Nd(this.ast,[...r.map(e=>({node:e,kind:M.Schema})),{node:n,kind:M.TablePartial}]);return i.length?i:(n.referee?.symbolTable?.forEach(t=>{let r=F(t.declaration.callee).unwrap_or(void 0);if(r===void 0)return;let i=this.symbolFactory.create(Ml,{declaration:e,tablePartialSymbol:n.referee}),a=Jl(r),o=this.declarationNode.symbol?.symbolTable;o?.has(a)||o?.set(a,i)}),[])})}bindBody(e){if(!e)return[];if(e instanceof x)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof x);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(m(n)instanceof C){let e=N(m(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!Tu(e.callee)))}tryToBindColumnType(e){let t=Lu(e).unwrap_or(void 0);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&Nd(this.ast,[...r.map(e=>({node:e,kind:M.Schema})),{node:n,kind:M.Enum}])}tryToBindEnumFieldRef(e){if(z(e))return[];if(B(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&Hl.includes(t))return[]}let t=Lu(e).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=t.variables;return Nd(this.ast,[...i.map(e=>({node:e,kind:M.Schema})),{node:r,kind:M.Enum},{node:n,kind:M.EnumField}])}bindInlineRef(e){return Md(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?Nd(this.ast,[...r.map(e=>({node:e,kind:M.Schema})),{node:n,kind:M.Table},{node:t,kind:M.Column}]):Nd(this.declarationNode,[{node:t,kind:M.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}},Ed=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof S?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof x)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof x);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Md).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Nd(this.ast,[...n.map(e=>({node:e,kind:M.Schema})),{node:t,kind:M.Table}])}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}},Dd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof S?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof x)return this.bindFields([e]);let[t,n]=h(e.body,e=>e instanceof x);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(m(n)instanceof C){let e=N(m(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=Lu(e).unwrap_or(void 0);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&Nd(this.ast,[...r.map(e=>({node:e,kind:M.Schema})),{node:n,kind:M.Enum}])}bindInlineRef(e){return Md(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?Nd(this.ast,[...r.map(e=>({node:e,kind:M.Schema})),{node:n,kind:M.Table},{node:t,kind:M.Column}]):Nd(this.declarationNode,[{node:t,kind:M.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}};function Od(e){return[Kl,ql,Yl,Zl,Jl,Xl,Ql,eu,tu].map(t=>t(e))}function kd(e){if(e instanceof bl)return M.Schema;if(e instanceof Cl)return M.Table;if(e instanceof wl)return M.Column;if(e instanceof xl)return M.Enum;if(e instanceof Sl)return M.EnumField;if(e instanceof Tl)return M.TableGroup;if(e instanceof El)return M.TableGroupField;if(e instanceof Al)return M.TablePartial;if(e instanceof Ml)return M.Column;if(e instanceof jl)return M.PartialInjection;if(e instanceof kl)return M.Note;throw Error(`No other possible symbol kind in getSymbolKind`)}var Ad=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof S&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof y?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let t=Wu(e).unwrap_or(void 0);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=Nd(this.ast,[...r.map(e=>({node:e,kind:M.Schema})),{node:n,kind:M.Table}]);if(i.length>0)return i;let a=n.referee;if(!a?.symbolTable)return[];let o=rd(n.referee?.declaration).unwrap_or(`<invalid name>`),s=[];for(let e of t.args){let t=I(e).unwrap_or(`<unnamed>`),n=Jl(t),r=a.symbolTable.get(n);if(!r){s.push(new E(T.BINDING_ERROR,`Column '${t}' does not exist in Table '${o}'`,e));continue}e.referee=r,r.references.push(e);let i=this.boundColumns.get(r);i&&(s.push(new E(T.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,i)),s.push(new E(T.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,e))),this.boundColumns.set(r,e)}return s}bindInsideTableName(e){let t=this.declarationNode.parent;if(!(t instanceof b)||Fu(t).unwrap_or(void 0)!==A.Table)return[];let n=t.symbol?.symbolTable;if(!n||!Nu(e))return[];let r=rd(t).unwrap_or(`<invalid name>`),i=[];for(let t of e.elementList){let e=I(t).unwrap_or(`<unnamed>`),a=Jl(e),o=n.get(a);if(!o){i.push(new E(T.BINDING_ERROR,`Column '${e}' does not exist in Table '${r}'`,t));continue}t.referee=o,o.references.push(t)}return i}bindBody(e){if(!e)return[];if(e instanceof x)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof x),n=e.body.filter(e=>e instanceof b);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof dl?e.callee.elementList:[e.callee]).flatMap(Md).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t||!n)return[];let r=e.variables;return Nd(this.ast,[...r.map(e=>({node:e,kind:M.Schema})),{node:n,kind:M.Enum},{node:t,kind:M.EnumField}])}):[]}bindSubElements(e){return e.flatMap(e=>e.type?new(jd(e))(e,this.ast,this.symbolFactory).bind():[])}};function jd(e){switch(e.type.value.toLowerCase()){case A.Enum:return bd;case A.Table:return Td;case A.TableGroup:return Ed;case A.Project:return Cd;case A.Ref:return wd;case A.Note:return Sd;case A.Indexes:return xd;case A.TablePartial:return Dd;case A.Check:return gd;case A.Records:return Ad;case A.DiagramView:return yd;default:return _d}}function Md(e){if(!e)return[];if(B(e))return[{variables:[e],tupleElements:[]}];if(e instanceof sl){let t=Lu(e).unwrap_or(void 0);return t?[t]:[...Md(e.leftExpression),...Md(e.rightExpression)]}if(e instanceof ol||e instanceof cl)return Md(e.expression);if(e instanceof ul){let t=Lu(e).unwrap_or(void 0);return t?[t]:e.elementList.flatMap(Md)}return[]}function Nd(e,t){if(!e.symbol?.symbolTable)throw Error(`lookupAndBindInScope should only be called with initial scope having a symbol table`);let n=e.symbol.symbolTable,r=kd(e.symbol),i=e instanceof b?rd(e).unwrap_or(`<invalid name>`):Wl;if(e instanceof y&&t.length){let{node:e,kind:n}=t[0];I(e).unwrap_or(`<unnamed>`)===`public`&&n===M.Schema&&t.shift()}for(let e of t){let{node:t,kind:a}=e,o=I(t).unwrap_or(`<unnamed>`),s=iu(o,a),c=n.get(s);if(!c)return[new E(T.BINDING_ERROR,`${a} '${o}' does not exist in ${i===void 0?`global scope`:`${r} '${i}'`}`,t)];if(t.referee=c,c.references.push(t),i=o,r=a,!c.symbolTable)return[];n=c.symbolTable}return[]}var Pd=class{constructor(e,t){this.ast=e,this.symbolFactory=t}resolvePartialInjections(){return this.ast.body.filter(e=>Fu(e).unwrap_or(``)===A.Table).flatMap(e=>new Td(e,this.ast,this.symbolFactory).resolvePartialInjections())}resolve(){let e=[];e.push(...this.resolvePartialInjections());for(let t of this.ast.body)if(t.type){let n=new(jd(t))(t,this.ast,this.symbolFactory);e.push(...n.bind())}return new D(this.ast,e)}},Fd=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}},Id=class{constructor(e,t){this.ast=e,this.symbolFactory=new Fd(t)}analyze(){return new hd(this.ast,this.symbolFactory).validate().chain(e=>new Pd(e,this.symbolFactory).resolve())}validate(){return new hd(this.ast,this.symbolFactory).validate().chain(e=>new D(e,[]))}};function Ld(e,t){let{variables:n,tupleElements:r}=Lu(e).unwrap(),i=r.map(e=>I(e).unwrap()),a=n.map(e=>I(e).unwrap());return r.length?n.length===0?{schemaName:t.schemaName,tableName:t.name,fieldNames:i}:{tableName:a.pop(),schemaName:a.pop()||null,fieldNames:i}:n.length===1?{schemaName:t.schemaName,tableName:t.name,fieldNames:[a[0]]}:{fieldNames:[a.pop()],tableName:a.pop(),schemaName:a.pop()||null}}function Rd(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:throw Error(`Invalid relation op`)}}function H(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}}}function zd(e){let t=Iu(e).unwrap_or(void 0)?.pop();return t instanceof ul?t.elementList.map(e=>e.referee):[t.referee]}function Bd(e){let t=P(e).unwrap();return{name:t.pop(),schemaName:t}}function Vd(e){return e.expression.literal.value}function Hd(e,t){if(Array.isArray(e)){let n=e.map(({id:e})=>e).sort().join(`,`),r=t.map(({id:e})=>e).sort().join(`,`);return n<r?`${n}-${r}`:`${r}-${n}`}let n=e.id.toString(),r=t.id.toString();return n<r?`${n}-${r}`:`${r}-${n}`}function Ud(e,t){return Array.isArray(e)?Kc(e.map(({id:e})=>e).sort(),t.map(({id:e})=>e).sort()).every(([e,t])=>e===t):e.id===t.id}function Wd(e){let t=e.split(`
|
|
10
10
|
`),n=t.slice(t.findIndex(e=>e.trimStart()!==``)),r=n.filter(e=>e.trimStart()),i=Math.min(...r.map(e=>e.length-e.trimStart().length));return n.map(e=>e.slice(i)).join(`
|
|
11
|
-
`)}function Id(e){if(e){if(Gu(e))return{value:R(e).unwrap(),type:`string`};if(Cu(e))return{type:`number`,value:Ll(e)};if(Ku(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof cl&&e.value)return{value:e.value.value,type:`expression`};if(Ju(e))return{value:Ou(e).map(h).and_then(I).unwrap(),type:`string`};throw Error(`Unreachable`)}}function Ld(e,t){let n=``,r=null,i,a;if(e instanceof T){let t=e.argumentList.elementList;if(r=t.map(e=>Cu(e)?Il(e):Gu(e)?R(e).unwrap():I(e).unwrap()).join(`,`),n=`(${r})`,t.length===2&&Cu(t[0])&&Cu(t[1])){let e=Ll(t[0]),n=Ll(t[1]);!isNaN(e)&&!isNaN(n)&&(i={precision:Math.trunc(e),scale:Math.trunc(n)})}else if(t.length===1&&Cu(t[0])){let e=Ll(t[0]);isNaN(e)||(a={length:Math.trunc(e)})}e=e.callee}for(;e instanceof T||e instanceof gl;)e instanceof T?(n=`(${e.argumentList.elementList.map(e=>Cu(e)?Il(e):Gu(e)?R(e).unwrap():I(e).unwrap()).join(`,`)})${n}`,e=e.callee):e instanceof gl&&(n=`${`[${e.indexer.elementList.map(e=>e.name.expression.literal.value).join(`,`)}]`}${n}`,e=e.array);let{name:o,schemaName:s}=jd(e),c=s.length===0?null:s[0],l=!![...t.enums.values()].find(e=>e.name===o&&e.schemaName===c);return s.length>1?new O({schemaName:s.length===0?null:s[0],type_name:`${o}${n}`,args:r,numericParams:i,lengthParam:a,isEnum:l},[new D(E.UNSUPPORTED,`Nested schema is not supported`,e)]):new O({schemaName:s.length===0?null:s[0],type_name:`${o}${n}`,args:r,numericParams:i,lengthParam:a,isEnum:l})}function Rd(e,t){let n=[...t.tables.entries()].find(([,t])=>t===e)?.[0];if(!n)throw Error(`mergeTableAndPartials should be called after all tables are interpreted`);if(!(n.body instanceof C))throw Error(`Table element should have a block body`);let r=[...e.indexes],i=[...e.checks],a=e.headerColor,o=e.note,s=[...t.tablePartials.values()];for(let t of[...e.partials].reverse()){let{name:e}=t,n=s.find(t=>t.name===e);n&&(r.push(...n.indexes),i.push(...n.checks),n.headerColor!==void 0&&(a=n.headerColor),n.note!==void 0&&(o=n.note))}let c=new Map(e.fields.map(e=>[e.name,e])),l=new Set(c.keys()),u=new Map(s.map(e=>[e.name,e])),d=[];for(let e of n.body.body)if(e instanceof S)if(_u(e.callee)){let t=I(e.callee.expression).unwrap_or(void 0),n=u.get(t);if(!n)continue;for(let e of n.fields)l.has(e.name)||d.push(e)}else{let t=I(e.callee).unwrap(),n=c.get(t);if(!n)continue;d.push(n)}let f=Bc([...d].reverse(),`name`).reverse();return{...e,fields:f,indexes:r,checks:i,headerColor:a,note:o}}function zd(e,t){let n=[],r=[...t.tablePartials.values()],i=new Set(e.fields.map(e=>e.name));for(let t of[...e.partials].reverse()){let{name:a}=t,o=r.find(e=>e.name===a);if(o){for(let t of o.fields)if(!i.has(t.name))for(let r of t.inline_refs){let i=kd(r.relation);n.push({name:null,schemaName:null,token:r.token,endpoints:[{schemaName:r.schemaName,tableName:r.tableName,fieldNames:r.fieldNames,token:r.token,relation:i[1]},{schemaName:e.schemaName,tableName:e.name,fieldNames:[t.name],token:t.token,relation:i[0]}]})}}}return n}var Bd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=H(this.declarationNode),this.env.tables.set(this.declarationNode,this.table);let e=[...this.interpretName(this.declarationNode.name),...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}},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),e}interpretName(e){let{name:t,schemaName:n}=jd(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new D(E.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=L(e).unwrap_or(null);return t&&(this.env.aliases.push({name:t,kind:`table`,value:{tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=t),[]}interpretSettingList(e){let t=P(e).getValue();this.table.headerColor=t[M.HeaderColor]?.length?Md(t[M.HeaderColor]?.at(0)?.value):void 0;let[n]=t[M.Note]||[];return this.table.note=n&&{value:R(n?.value).map(Fd).unwrap(),token:H(n)},[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof S);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case j.Note:return this.table.note={value:R(e.body instanceof C?e.body.body[0].callee:e.body.callee).map(Fd).unwrap(),token:H(e)},[];case j.Indexes:return this.interpretIndexes(e);case j.Check:return this.interpretChecks(e);case j.Records:return this.env.recordsElements.push(e),[];default:return[]}})}interpretInjection(e,t){let n={order:t,token:H(e)};return n.name=I(e.expression).unwrap_or(``),this.table.partials.push(n),[]}interpretFields(e){let t=(this.declarationNode.symbol?.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([e])=>$l(e).unwrap_or(null)?.kind===N.Column).length?[]:[new D(E.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],n=e.flatMap((e,t)=>_u(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...t,...n]}interpretColumn(e){let t=[],n={};n.name=L(e.callee).unwrap();let r=Ld(e.args[0],this.env);n.type=r.getValue(),t.push(...r.getErrors()),n.token=H(e),n.inline_refs=[];let i=e.args.slice(1);if(h(i)instanceof w){let r=P(i.pop()).getValue();n.pk=!!r[M.PK]?.length||!!r[M.PrimaryKey]?.length,n.increment=!!r[M.Increment]?.length,n.unique=!!r[M.Unique]?.length,n.not_null=r[M.NotNull]?.length?!0:r[M.Null]?.length?!1:void 0,n.dbdefault=Id(r[M.Default]?.at(0)?.value);let a=r[M.Note]?.at(0);n.note=a&&{value:R(a.value).map(Fd).unwrap(),token:H(a)},n.inline_refs=(r[M.Ref]||[]).flatMap(n=>{let[r]=Ad(n.value.expression);if(Pd(r,e.symbol))return t.push(new D(E.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=F(n.value.expression).unwrap(),o;if(a.length===1){let[e]=a;o={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[e],relation:i.value,token:H(n)}}else if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:H(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:H(n)}}else{t.push(new D(E.UNSUPPORTED,`Nested schema is not supported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:H(n)}}let s=this.registerInlineRefToEnv(e,r,o,n);return t.push(...s),s.length===0?o:[]}),n.checks=(r[M.Check]||[]).map(e=>({token:H(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>I(e).unwrap().toLowerCase()===`pk`),n.unique||=i.some(e=>I(e).unwrap().toLowerCase()===`unique`),this.table.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){return this.table.indexes.push(...e.body.body.map(e=>{let t={columns:[]},n=e;t.token=H(n);let r=[n.callee,...n.args];if(h(r)instanceof w){let e=P(r.pop()).getValue();t.pk=!!e[M.PK]?.length,t.unique=!!e[M.Unique]?.length,t.name=R(e[M.Name]?.at(0)?.value).unwrap_or(void 0);let n=e[M.Note]?.at(0);t.note=n&&{value:R(n.value).unwrap(),token:H(n)},t.type=I(e[M.Type]?.at(0)?.value).unwrap_or(void 0)}return r.flatMap(e=>{if(!(e instanceof T))return e;let t=[];for(;e instanceof T;)t.push(e.argumentList),e=e.callee;return t.push(e),t}).forEach(e=>{let{functional:n,nonFunctional:r}=Au(e).unwrap();t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:H(e)})),...r.map(e=>({value:L(e).unwrap(),type:`column`,token:H(e)})))}),t})),[]}interpretChecks(e){return this.table.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=H(n),n.args[0]instanceof w&&(t.name=R(P(n.args[0]).getValue()[M.Name]?.at(0)?.value).unwrap_or(void 0)),t.expression=n.callee.value.value,t})),[]}registerInlineRefToEnv(e,t,n,r){let i=Nd(e.symbol,t);if(this.env.refIds[i])return[new D(E.CIRCULAR_REF,`References with same endpoints exist`,r),new D(E.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[i])];let a=kd(n.relation);return this.env.refIds[i]=r,this.env.ref.set(r,{name:null,schemaName:null,token:n.token,endpoints:[{...n,relation:a[1]},{schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[I(e.callee).unwrap()],token:H(e),relation:a[0]}]}),[]}},Vd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.note={name:void 0,content:void 0,token:void 0}}interpret(){return this.note.token=H(this.declarationNode),this.env.notes.set(this.declarationNode,this.note),[...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let{name:t}=jd(e);return this.note.name=t,[]}interpretSettingList(e){let t=P(e).getValue();return this.note.headerColor=t.headercolor?.length?Md(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof S);return t.length!==1||n.length>0?[new D(E.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=ta(e,`callee.expression.literal.value`,``);return this.note.content=Fd(t),[]}},Hd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.container=this.declarationNode.parent instanceof x?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=H(this.declarationNode),this.env.ref.set(this.declarationNode,this.ref),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let t=[],n=F(this.declarationNode.name).unwrap_or([]);return this.ref.name=n.pop()||null,n.length>1&&t.push(new D(E.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=n.join(`.`)||null,t}interpretBody(e){return e instanceof S?this.interpretField(e):this.interpretField(e.body[0])}interpretField(e){let t=e.callee.op.value,{leftExpression:n,rightExpression:r}=e.callee,i=Ad(n),a=Ad(r);if(Pd(i,a))return[new D(E.SAME_ENDPOINT,`Two endpoints are the same`,e)];let o=Nd(i,a);if(this.env.refIds[o])return[new D(E.CIRCULAR_REF,`References with same endpoints exist`,this.declarationNode),new D(E.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[o])];if(e.args[0]){let t=P(e.args[0]).getValue(),n=t.delete?.at(0)?.value;this.ref.onDelete=n instanceof rl?Yu(n).unwrap_or(void 0):I(n).unwrap_or(void 0);let r=t.update?.at(0)?.value;this.ref.onUpdate=r instanceof rl?Yu(r).unwrap_or(void 0):I(r).unwrap_or(void 0),this.ref.color=t.color?.length?Md(t.color?.at(0)?.value):void 0}let s=kd(t);return this.ref.endpoints=[{...Od(n,this.container),relation:s[0],token:H(n)},{...Od(r,this.container),relation:s[1],token:H(r)}],this.env.refIds[o]=this.declarationNode,[]}},Ud=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=H(this.declarationNode),this.env.tableGroups.set(this.declarationNode,this.tableGroup),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),e}interpretName(e){let t=[],{name:n,schemaName:r}=jd(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new D(E.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 S);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case`note`:this.tableGroup.note={value:R(e.body instanceof C?e.body.body[0].callee:e.body.callee).map(Fd).unwrap(),token:H(e)};break;default:break}return[]})}interpretFields(e){let t=[];return this.tableGroup.tables=e.map(e=>{let n=F(e.callee).unwrap();n.length>2&&t.push(new D(E.UNSUPPORTED,`Nested schema is not supported`,e));let r=Ou(e.callee).unwrap().pop().referee.id;if(this.env.tableOwnerGroup[r]){let i=this.env.tableOwnerGroup[r],{schemaName:a,name:o}=this.env.tableGroups.get(i),s=a?`${a}.${o}`:o;t.push(new D(E.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${n.join(`.`)}" already appears in group "${s}"`,e))}else this.env.tableOwnerGroup[r]=this.declarationNode;return{name:n.pop(),schemaName:n.join(`.`)}}),t}interpretSettingList(e){let t=P(e).getValue();this.tableGroup.color=t.color?.length?Md(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:R(n?.value).map(Fd).unwrap(),token:H(n)},[]}},Wd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.enum={values:[]}}interpret(){return this.enum.token=H(this.declarationNode),this.env.enums.set(this.declarationNode,this.enum),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let{name:t,schemaName:n}=jd(e);return n.length>1?(this.enum.name=t,this.enum.schemaName=n.join(`.`),[new D(E.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.enum.name=t,this.enum.schemaName=n.length?n[0]:null,[])}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=H(t),n.name=I(t.callee).unwrap();let r=P(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:R(r.value).map(Fd).unwrap(),token:H(r)},this.enum.values.push(n),[]})}},Gd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=H(this.declarationNode),this.env.tablePartials.set(this.declarationNode,this.tablePartial);let e=[...this.interpretName(this.declarationNode.name),...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})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),e}interpretName(e){let{name:t}=jd(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=P(e).getValue(),n=mc(t[M.HeaderColor]);this.tablePartial.headerColor=n?Md(n.value):void 0;let[r]=t[M.Note]||[];return this.tablePartial.note=r&&{value:R(r?.value).map(Fd).unwrap(),token:H(r)},[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof S);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case j.Note:return this.tablePartial.note={value:R(e.body instanceof C?e.body.body[0].callee:e.body.callee).map(Fd).unwrap(),token:H(e)},[];case j.Indexes:return this.interpretIndexes(e);case j.Check:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let t=[],n={};n.name=L(e.callee).unwrap();let r=Ld(e.args[0],this.env);n.type=r.getValue(),t.push(...r.getErrors()),n.token=H(e),n.inline_refs=[];let i=e.args.slice(1);if(h(i)instanceof w){let r=P(i.pop()).getValue();n.pk=!!r[M.PK]?.length||!!r[M.PrimaryKey]?.length,n.increment=!!r[M.Increment]?.length,n.unique=!!r[M.Unique]?.length,n.not_null=r[M.NotNull]?.length?!0:r[M.Null]?.length?!1:void 0,n.dbdefault=Id(r[M.Default]?.at(0)?.value);let a=r[M.Note]?.at(0);n.note=a&&{value:R(a.value).map(Fd).unwrap(),token:H(a)},n.inline_refs=(r[M.Ref]||[]).flatMap(n=>{let[r]=Ad(n.value.expression);if(Pd(r,e.symbol))return t.push(new D(E.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=F(n.value.expression).unwrap(),o;if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:H(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:H(n)}}else{t.push(new D(E.UNSUPPORTED,`Unsupported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:H(n)}}return o}),n.checks=(r[M.Check]||[]).map(e=>({token:H(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>I(e).unwrap().toLowerCase()===`pk`),n.unique||=i.some(e=>I(e).unwrap().toLowerCase()===`unique`),this.tablePartial.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){return this.tablePartial.indexes.push(...e.body.body.map(e=>{let t={columns:[]},n=e;t.token=H(n);let r=[n.callee,...n.args];if(h(r)instanceof w){let e=P(r.pop()).getValue();t.pk=!!e[M.PK]?.length,t.unique=!!e[M.Unique]?.length,t.name=R(e[M.Name]?.at(0)?.value).unwrap_or(void 0);let n=e[M.Note]?.at(0);t.note=n&&{value:R(n.value).unwrap(),token:H(n)},t.type=I(e[M.Type]?.at(0)?.value).unwrap_or(void 0)}return r.flatMap(e=>{if(!(e instanceof T))return e;let t=[],n=e;for(;n instanceof T;)t.push(n.argumentList),n=n.callee;return t.push(n),t}).forEach(e=>{let{functional:n,nonFunctional:r}=Au(e).unwrap();t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:H(e)})),...r.map(e=>({value:L(e).unwrap(),type:`column`,token:H(e)})))}),t})),[]}interpretChecks(e){return this.tablePartial.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=H(n),n.args[0]instanceof w&&(t.name=R(P(n.args[0]).getValue()[M.Name]?.at(0)?.value).unwrap_or(void 0)),t.expression=n.callee.value.value,t})),[]}},Kd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){return this.env.project.set(this.declarationNode,this.project),this.project.token=H(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=jd(e);return this.project.name=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.type?.value.toLowerCase()){case`table`:{let e=new Bd(t,this.env).interpret();return this.project.tables.push(this.env.tables.get(t)),e}case`ref`:{let e=new Hd(t,this.env).interpret();return this.project.refs.push(this.env.ref.get(t)),e}case`tablegroup`:{let e=new Ud(t,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(t)),e}case`enum`:{let e=new Wd(t,this.env).interpret();return this.project.enums.push(this.env.enums.get(t)),e}case`note`:return this.project.note={value:R(t.body instanceof C?t.body.body[0].callee:t.body.callee).map(Fd).unwrap(),token:H(t)},[];case`tablepartial`:{let e=new Gd(t,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(t)),e}default:return this.project[t.type.value.toLowerCase()]=R(t.body.callee).unwrap(),[]}})}},qd={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`])},Jd={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`])},Yd={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},Xd={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`])},Zd={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`])},Qd={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`])},$d={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function ef(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function tf(e,t){let n=ef(e);return t?qd[t].has(n):Object.values(qd).some(e=>e.has(n))}function nf(e,t){let n=ef(e);return t?Jd[t].has(n):Object.values(Jd).some(e=>e.has(n))}function rf(e,t){return tf(e,t)||nf(e,t)}function af(e,t){let n=ef(e);return t?Yd[t].has(n):Object.values(Yd).some(e=>e.has(n))}function of(e,t){let n=ef(e);return t?Xd[t].has(n):Object.values(Xd).some(e=>e.has(n))}function sf(e,t){let n=ef(e);return t?Zd[t].has(n):Object.values(Zd).some(e=>e.has(n))}function cf(e,t){let n=ef(e);return t?Qd[t].has(n):Object.values(Qd).some(e=>e.has(n))}function lf(e,t){let n=ef(e);return t?$d[t].has(n):Object.values($d).some(e=>e.has(n))}function uf(e){let t=e.declaration;return t instanceof S&&t.args[0]||null}function df(e){let t=uf(e);if(!(t instanceof T)||!t.argumentList||t.argumentList.elementList.length!==2)return{};let n=ju(t.argumentList.elementList[0]),r=ju(t.argumentList.elementList[1]);return n===null||r===null?{}:{precision:Math.trunc(n),scale:Math.trunc(r)}}function ff(e){let t=uf(e);if(!(t instanceof T)||!t.argumentList||t.argumentList.elementList.length!==1)return{};let n=ju(t.argumentList.elementList[0]);return n===null?{}:{length:Math.trunc(n)}}function pf(e,t){if(t)return`string`;if(tf(e))return`integer`;if(nf(e))return`real`;if(af(e))return`bool`;if(of(e))return`string`;let n=ef(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:cf(e)?`datetime`:e}var mf=class extends Error{},hf=class extends mf{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},gf=class extends mf{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},_f=class extends mf{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},vf=class extends mf{},yf=class extends mf{constructor(e){super(`Invalid unit ${e}`)}},bf=class extends mf{},xf=class extends mf{constructor(){super(`Zone is an abstract class`)}},U=`numeric`,Sf=`short`,Cf=`long`,wf={year:U,month:U,day:U},Tf={year:U,month:Sf,day:U},Ef={year:U,month:Sf,day:U,weekday:Sf},Df={year:U,month:Cf,day:U},Of={year:U,month:Cf,day:U,weekday:Cf},kf={hour:U,minute:U},Af={hour:U,minute:U,second:U},jf={hour:U,minute:U,second:U,timeZoneName:Sf},Mf={hour:U,minute:U,second:U,timeZoneName:Cf},Nf={hour:U,minute:U,hourCycle:`h23`},Pf={hour:U,minute:U,second:U,hourCycle:`h23`},Ff={hour:U,minute:U,second:U,hourCycle:`h23`,timeZoneName:Sf},If={hour:U,minute:U,second:U,hourCycle:`h23`,timeZoneName:Cf},Lf={year:U,month:U,day:U,hour:U,minute:U},Rf={year:U,month:U,day:U,hour:U,minute:U,second:U},zf={year:U,month:Sf,day:U,hour:U,minute:U},Bf={year:U,month:Sf,day:U,hour:U,minute:U,second:U},Vf={year:U,month:Sf,day:U,weekday:Sf,hour:U,minute:U},Hf={year:U,month:Cf,day:U,hour:U,minute:U,timeZoneName:Sf},Uf={year:U,month:Cf,day:U,hour:U,minute:U,second:U,timeZoneName:Sf},Wf={year:U,month:Cf,day:U,weekday:Cf,hour:U,minute:U,timeZoneName:Cf},Gf={year:U,month:Cf,day:U,weekday:Cf,hour:U,minute:U,second:U,timeZoneName:Cf},Kf=class{get type(){throw new xf}get name(){throw new xf}get ianaName(){return this.name}get isUniversal(){throw new xf}offsetName(e,t){throw new xf}formatOffset(e,t){throw new xf}offset(e){throw new xf}equals(e){throw new xf}get isValid(){throw new xf}},qf=null,Jf=class e extends Kf{static get instance(){return qf===null&&(qf=new e),qf}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Mm(e,t,n)}formatOffset(e,t){return Im(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},Yf=new Map;function Xf(e){let t=Yf.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`}),Yf.set(e,t)),t}var Zf={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function Qf(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 $f(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=Zf[t];t===`era`?r[a]=i:K(a)||(r[a]=parseInt(i,10))}return r}var ep=new Map,tp=class e extends Kf{static create(t){let n=ep.get(t);return n===void 0&&ep.set(t,n=new e(t)),n}static resetCache(){ep.clear(),Yf.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 Mm(e,t,n,this.name)}formatOffset(e,t){return Im(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=Xf(this.name),[r,i,a,o,s,c,l]=n.formatToParts?$f(n,t):Qf(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=Om({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}},np={};function rp(e,t={}){let n=JSON.stringify([e,t]),r=np[n];return r||(r=new Intl.ListFormat(e,t),np[n]=r),r}var ip=new Map;function ap(e,t={}){let n=JSON.stringify([e,t]),r=ip.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),ip.set(n,r)),r}var op=new Map;function sp(e,t={}){let n=JSON.stringify([e,t]),r=op.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),op.set(n,r)),r}var cp=new Map;function lp(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=cp.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),cp.set(i,a)),a}var up=null;function dp(){return up||(up=new Intl.DateTimeFormat().resolvedOptions().locale,up)}var fp=new Map;function pp(e){let t=fp.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),fp.set(e,t)),t}var mp=new Map;function hp(e){let t=mp.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Tp,...t}),mp.set(e,t)}return t}function gp(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=ap(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=ap(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function _p(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function vp(e){let t=[];for(let n=1;n<=12;n++){let r=Y.utc(2009,n,1);t.push(e(r))}return t}function yp(e){let t=[];for(let n=1;n<=7;n++){let r=Y.utc(2016,11,13+n);t.push(e(r))}return t}function bp(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function xp(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||pp(e.locale).numberingSystem===`latn`}var Sp=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=sp(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return q(this.floor?Math.floor(e):wm(e,3),this.padTo)}},Cp=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&&tp.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=ap(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()}},wp=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&fm()&&(this.rtf=lp(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):th(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Tp={firstDay:1,minimalDays:4,weekend:[6,7]},W=class e{static fromOpts(t){return e.create(t.locale,t.numberingSystem,t.outputCalendar,t.weekSettings,t.defaultToEN)}static create(t,n,r,i,a=!1){let o=t||G.defaultLocale;return new e(o||(a?`en-US`:dp()),n||G.defaultNumberingSystem,r||G.defaultOutputCalendar,vm(i)||G.defaultWeekSettings,o)}static resetCache(){up=null,ip.clear(),op.clear(),cp.clear(),fp.clear(),mp.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]=gp(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=_p(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??=xp(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,vm(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 bp(this,e,Vm,()=>{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]=vp(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return bp(this,e,Gm,()=>{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]=yp(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return bp(this,void 0,()=>Km,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[Y.utc(2016,11,13,9),Y.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return bp(this,e,Xm,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[Y.utc(-40,1,1),Y.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 Sp(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new Cp(e,this.intl,t)}relFormatter(e={}){return new wp(this.intl,this.isEnglish(),e)}listFormatter(e={}){return rp(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||pp(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:pm()?hp(this.locale):Tp}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})`}},Ep=null,Dp=class e extends Kf{static get utcInstance(){return Ep===null&&(Ep=new e(0)),Ep}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(Nm(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${Im(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${Im(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return Im(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}},Op=class extends Kf{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 kp(e,t){if(K(e)||e===null)return t;if(e instanceof Kf)return e;if(um(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?Jf.instance:n===`utc`||n===`gmt`?Dp.utcInstance:Dp.parseSpecifier(n)||tp.create(e)}else if(cm(e))return Dp.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new Op(e)}var Ap={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},jp={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]},Mp=Ap.hanidec.replace(/[\[|\]]/g,``).split(``);function Np(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(Ap.hanidec)!==-1)t+=Mp.indexOf(e[n]);else for(let e in jp){let[n,i]=jp[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Pp=new Map;function Fp(){Pp.clear()}function Ip({numberingSystem:e},t=``){let n=e||`latn`,r=Pp.get(n);r===void 0&&(r=new Map,Pp.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Ap[n]}${t}`),r.set(t,i)),i}var Lp=()=>Date.now(),Rp=`system`,zp=null,Bp=null,Vp=null,Hp=60,Up,Wp=null,G=class{static get now(){return Lp}static set now(e){Lp=e}static set defaultZone(e){Rp=e}static get defaultZone(){return kp(Rp,Jf.instance)}static get defaultLocale(){return zp}static set defaultLocale(e){zp=e}static get defaultNumberingSystem(){return Bp}static set defaultNumberingSystem(e){Bp=e}static get defaultOutputCalendar(){return Vp}static set defaultOutputCalendar(e){Vp=e}static get defaultWeekSettings(){return Wp}static set defaultWeekSettings(e){Wp=vm(e)}static get twoDigitCutoffYear(){return Hp}static set twoDigitCutoffYear(e){Hp=e%100}static get throwOnInvalid(){return Up}static set throwOnInvalid(e){Up=e}static resetCaches(){W.resetCache(),tp.resetCache(),Y.resetCache(),Fp()}},Gp=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},Kp=[0,31,59,90,120,151,181,212,243,273,304,334],qp=[0,31,60,91,121,152,182,213,244,274,305,335];function Jp(e,t){return new Gp(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function Yp(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 Xp(e,t,n){return n+(Tm(e)?qp:Kp)[t-1]}function Zp(e,t){let n=Tm(e)?qp:Kp,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function Qp(e,t){return(e-t+7)%7+1}function $p(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Xp(r,i,a),s=Qp(Yp(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=Am(l,t,n)):c>Am(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...Lm(e)}}function em(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=Qp(Yp(r,1,t),n),s=Em(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=Em(l)):c>s?(l=r+1,c-=Em(r)):l=r;let{month:u,day:d}=Zp(l,c);return{year:l,month:u,day:d,...Lm(e)}}function tm(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Xp(t,n,r),...Lm(e)}}function nm(e){let{year:t,ordinal:n}=e,{month:r,day:i}=Zp(t,n);return{year:t,month:r,day:i,...Lm(e)}}function rm(e,t){if(!K(e.localWeekday)||!K(e.localWeekNumber)||!K(e.localWeekYear)){if(!K(e.weekday)||!K(e.weekNumber)||!K(e.weekYear))throw new vf(`Cannot mix locale-based week fields with ISO-based week fields`);return K(e.localWeekday)||(e.weekday=e.localWeekday),K(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),K(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 im(e,t=4,n=1){let r=lm(e.weekYear),i=ym(e.weekNumber,1,Am(e.weekYear,t,n)),a=ym(e.weekday,1,7);return r?i?a?!1:Jp(`weekday`,e.weekday):Jp(`week`,e.weekNumber):Jp(`weekYear`,e.weekYear)}function am(e){let t=lm(e.year),n=ym(e.ordinal,1,Em(e.year));return t?n?!1:Jp(`ordinal`,e.ordinal):Jp(`year`,e.year)}function om(e){let t=lm(e.year),n=ym(e.month,1,12),r=ym(e.day,1,Dm(e.year,e.month));return t?n?r?!1:Jp(`day`,e.day):Jp(`month`,e.month):Jp(`year`,e.year)}function sm(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=ym(t,0,23)||t===24&&n===0&&r===0&&i===0,o=ym(n,0,59),s=ym(r,0,59),c=ym(i,0,999);return a?o?s?c?!1:Jp(`millisecond`,i):Jp(`second`,r):Jp(`minute`,n):Jp(`hour`,t)}function K(e){return e===void 0}function cm(e){return typeof e==`number`}function lm(e){return typeof e==`number`&&e%1==0}function um(e){return typeof e==`string`}function dm(e){return Object.prototype.toString.call(e)===`[object Date]`}function fm(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function pm(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function mm(e){return Array.isArray(e)?e:[e]}function hm(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 gm(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function _m(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function vm(e){if(e==null)return null;if(typeof e!=`object`)throw new bf(`Week settings must be an object`);if(!ym(e.firstDay,1,7)||!ym(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!ym(e,1,7)))throw new bf(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function ym(e,t,n){return lm(e)&&e>=t&&e<=n}function bm(e,t){return e-t*Math.floor(e/t)}function q(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function xm(e){if(!(K(e)||e===null||e===``))return parseInt(e,10)}function Sm(e){if(!(K(e)||e===null||e===``))return parseFloat(e)}function Cm(e){if(!(K(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function wm(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 Tm(e){return e%4==0&&(e%100!=0||e%400==0)}function Em(e){return Tm(e)?366:365}function Dm(e,t){let n=bm(t-1,12)+1,r=e+(t-n)/12;return n===2?Tm(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function Om(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 km(e,t,n){return-Qp(Yp(e,1,t),n)+t-1}function Am(e,t=4,n=1){let r=km(e,t,n),i=km(e+1,t,n);return(Em(e)-r+i)/7}function jm(e){return e>99?e:e>G.twoDigitCutoffYear?1900+e:2e3+e}function Mm(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 Nm(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 Pm(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new bf(`Invalid unit value ${e}`);return t}function Fm(e,t){let n={};for(let r in e)if(_m(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=Pm(i)}return n}function Im(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}${q(n,2)}:${q(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${q(n,2)}${q(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function Lm(e){return gm(e,[`hour`,`minute`,`second`,`millisecond`])}var Rm=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],zm=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Bm=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function Vm(e){switch(e){case`narrow`:return[...Bm];case`short`:return[...zm];case`long`:return[...Rm];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 Hm=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],Um=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Wm=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function Gm(e){switch(e){case`narrow`:return[...Wm];case`short`:return[...Um];case`long`:return[...Hm];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var Km=[`AM`,`PM`],qm=[`Before Christ`,`Anno Domini`],Jm=[`BC`,`AD`],Ym=[`B`,`A`];function Xm(e){switch(e){case`narrow`:return[...Ym];case`short`:return[...Jm];case`long`:return[...qm];default:return null}}function Zm(e){return Km[e.hour<12?0:1]}function Qm(e,t){return Gm(t)[e.weekday-1]}function $m(e,t){return Vm(t)[e.month-1]}function eh(e,t){return Xm(t)[e.year<0?0:1]}function th(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 nh(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var rh={D:wf,DD:Tf,DDD:Df,DDDD:Of,t:kf,tt:Af,ttt:jf,tttt:Mf,T:Nf,TT:Pf,TTT:Ff,TTTT:If,f:Lf,ff:zf,fff:Hf,ffff:Wf,F:Rf,FF:Bf,FFF:Uf,FFFF:Gf},ih=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 rh[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 q(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?Zm(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?$m(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?Qm(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?eh(t,e):a({era:e},`era`);return nh(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 nh(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},ah=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function oh(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function sh(...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 ch(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 lh(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=xm(t[n+i]);return[r,null,n+i]}}var uh=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,dh=`(?:${uh.source}?(?:\\[(${ah.source})\\])?)?`,fh=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,ph=RegExp(`${fh.source}${dh}`),mh=RegExp(`(?:[Tt]${ph.source})?`),hh=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,gh=/(\d{4})-?W(\d\d)(?:-?(\d))?/,_h=/(\d{4})-?(\d{3})/,vh=lh(`weekYear`,`weekNumber`,`weekDay`),yh=lh(`year`,`ordinal`),bh=/(\d{4})-(\d\d)-(\d\d)/,xh=RegExp(`${fh.source} ?(?:${uh.source}|(${ah.source}))?`),Sh=RegExp(`(?: ${xh.source})?`);function Ch(e,t,n){let r=e[t];return K(r)?n:xm(r)}function wh(e,t){return[{year:Ch(e,t),month:Ch(e,t+1,1),day:Ch(e,t+2,1)},null,t+3]}function Th(e,t){return[{hours:Ch(e,t,0),minutes:Ch(e,t+1,0),seconds:Ch(e,t+2,0),milliseconds:Cm(e[t+3])},null,t+4]}function Eh(e,t){let n=!e[t]&&!e[t+1],r=Nm(e[t+1],e[t+2]);return[{},n?null:Dp.instance(r),t+3]}function Dh(e,t){return[{},e[t]?tp.create(e[t]):null,t+1]}var Oh=RegExp(`^T?${fh.source}$`),kh=/^-?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 Ah(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(Sm(n)),months:f(Sm(r)),weeks:f(Sm(i)),days:f(Sm(a)),hours:f(Sm(o)),minutes:f(Sm(s)),seconds:f(Sm(c),c===`-0`),milliseconds:f(Cm(l),d)}]}var jh={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Mh(e,t,n,r,i,a,o){let s={year:t.length===2?jm(xm(t)):xm(t),month:zm.indexOf(n)+1,day:xm(r),hour:xm(i),minute:xm(a)};return o&&(s.second=xm(o)),e&&(s.weekday=e.length>3?Hm.indexOf(e)+1:Um.indexOf(e)+1),s}var Nh=/^(?:(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 Ph(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=Mh(t,i,r,n,a,o,s),ee;return ee=c?jh[c]:l?0:Nm(u,d),[f,new Dp(ee)]}function Fh(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var Ih=/^(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$/,Lh=/^(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$/,Rh=/^(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 zh(e){let[,t,n,r,i,a,o,s]=e;return[Mh(t,i,r,n,a,o,s),Dp.utcInstance]}function Bh(e){let[,t,n,r,i,a,o,s]=e;return[Mh(t,s,n,r,i,a,o),Dp.utcInstance]}var Vh=oh(hh,mh),Hh=oh(gh,mh),Uh=oh(_h,mh),Wh=oh(ph),Gh=sh(wh,Th,Eh,Dh),Kh=sh(vh,Th,Eh,Dh),qh=sh(yh,Th,Eh,Dh),Jh=sh(Th,Eh,Dh);function Yh(e){return ch(e,[Vh,Gh],[Hh,Kh],[Uh,qh],[Wh,Jh])}function Xh(e){return ch(Fh(e),[Nh,Ph])}function Zh(e){return ch(e,[Ih,zh],[Lh,zh],[Rh,Bh])}function Qh(e){return ch(e,[kh,Ah])}var $h=sh(Th);function eg(e){return ch(e,[Oh,$h])}var tg=oh(bh,Sh),ng=oh(xh),rg=sh(Th,Eh,Dh);function ig(e){return ch(e,[tg,Gh],[ng,rg])}var ag=`Invalid Duration`,og={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}},sg={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},...og},cg=146097/400,lg=146097/4800,ug={years:{quarters:4,months:12,weeks:cg/7,days:cg,hours:cg*24,minutes:cg*24*60,seconds:cg*24*60*60,milliseconds:cg*24*60*60*1e3},quarters:{months:3,weeks:cg/28,days:cg/4,hours:cg*24/4,minutes:cg*24*60/4,seconds:cg*24*60*60/4,milliseconds:cg*24*60*60*1e3/4},months:{weeks:lg/7,days:lg,hours:lg*24,minutes:lg*24*60,seconds:lg*24*60*60,milliseconds:lg*24*60*60*1e3},...og},dg=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],fg=dg.slice(0).reverse();function pg(e,t,n=!1){return new _g({values:n?t.values:{...e.values,...t.values||{}},loc:e.loc.clone(t.loc),conversionAccuracy:t.conversionAccuracy||e.conversionAccuracy,matrix:t.matrix||e.matrix})}function mg(e,t){let n=t.milliseconds??0;for(let r of fg.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function hg(e,t){let n=mg(e,t)<0?-1:1;dg.reduceRight((r,i)=>{if(K(t[i]))return r;if(r){let a=t[r]*n,o=e[i][r],s=Math.floor(a/o);t[i]+=s*n,t[r]-=s*o*n}return i},null),dg.reduce((n,r)=>{if(K(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function gg(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var _g=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?ug:sg;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||W.create(),this.conversionAccuracy=t?`longterm`:`casual`,this.invalid=e.invalid||null,this.matrix=n,this.isLuxonDuration=!0}static fromMillis(t,n){return e.fromObject({milliseconds:t},n)}static fromObject(t,n={}){if(typeof t!=`object`||!t)throw new bf(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:Fm(t,e.normalizeUnit),loc:W.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(cm(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new bf(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=Qh(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]=eg(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 bf(`need to specify a reason the Duration is invalid`);let r=t instanceof Gp?t:new Gp(t,n);if(G.throwOnInvalid)throw new _f(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 yf(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?ih.create(this.loc,n).formatDurationFromString(this,e):ag}toHuman(e={}){if(!this.isValid)return ag;let t=e.showZeros!==!1,n=dg.map(n=>{let r=this.values[n];return K(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+=wm(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},Y.fromMillis(t,{zone:`UTC`}).toISOTime(e))}toJSON(){return this.toISO()}toString(){return this.toISO()}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Duration { values: ${JSON.stringify(this.values)} }`:`Duration { Invalid, reason: ${this.invalidReason} }`}toMillis(){return this.isValid?mg(this.matrix,this.values):NaN}valueOf(){return this.toMillis()}plus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t),r={};for(let e of dg)(_m(n.values,e)||_m(this.values,e))&&(r[e]=n.get(e)+this.get(e));return pg(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]=Pm(e(this.values[n],n));return pg(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...Fm(t,e.normalizeUnit)};return pg(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 pg(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return hg(this.matrix,e),pg(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=gg(this.normalize().shiftToAll().toObject());return pg(this,{values:e},!0)}shiftTo(...t){if(!this.isValid||t.length===0)return this;t=t.map(t=>e.normalizeUnit(t));let n={},r={},i=this.toObject(),a;for(let e of dg)if(t.indexOf(e)>=0){a=e;let t=0;for(let n in r)t+=this.matrix[n][e]*r[n],r[n]=0;cm(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else cm(i[e])&&(r[e]=i[e]);for(let e in r)r[e]!==0&&(n[a]+=e===a?r[e]:r[e]/this.matrix[a][e]);return hg(this.matrix,n),pg(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 pg(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=gg(this.values);return pg(this,{values:e},!0)}get years(){return this.isValid?this.values.years||0:NaN}get quarters(){return this.isValid?this.values.quarters||0:NaN}get months(){return this.isValid?this.values.months||0:NaN}get weeks(){return this.isValid?this.values.weeks||0:NaN}get days(){return this.isValid?this.values.days||0:NaN}get hours(){return this.isValid?this.values.hours||0:NaN}get minutes(){return this.isValid?this.values.minutes||0:NaN}get seconds(){return this.isValid?this.values.seconds||0:NaN}get milliseconds(){return this.isValid?this.values.milliseconds||0:NaN}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}equals(e){if(!this.isValid||!e.isValid||!this.loc.equals(e.loc))return!1;function t(e,t){return e===void 0||e===0?t===void 0||t===0:e===t}for(let n of dg)if(!t(this.values[n],e.values[n]))return!1;return!0}},vg=`Invalid Interval`;function yg(e,t){return!e||!e.isValid?bg.invalid(`missing or invalid start`):!t||!t.isValid?bg.invalid(`missing or invalid end`):t<e?bg.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 bg=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 bf(`need to specify a reason the Interval is invalid`);let r=t instanceof Gp?t:new Gp(t,n);if(G.throwOnInvalid)throw new gf(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=S_(t),i=S_(n);return yg(r,i)??new e({start:r,end:i})}static after(t,n){let r=_g.fromDurationLike(n),i=S_(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=_g.fromDurationLike(n),i=S_(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=Y.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=Y.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=_g.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=_g.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(S_).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=_g.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()})`:vg}[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=wf,t={}){return this.isValid?ih.create(this.s.loc.clone(t),e).formatInterval(this):vg}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:vg}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:vg}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:vg}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:vg}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):_g.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},xg=class{static hasDST(e=G.defaultZone){let t=Y.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return tp.isValidZone(e)}static normalizeZone(e){return kp(e,G.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||W.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||W.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||W.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||W.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return W.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return W.create(t,null,`gregory`).eras(e)}static features(){return{relative:fm(),localeWeek:pm()}}};function Sg(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(_g.fromMillis(r).as(`days`))}function Cg(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=Sg(e,t);return(n-n%7)/7}],[`days`,Sg]],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 wg(e,t,n,r){let[i,a,o,s]=Cg(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=_g.fromObject(a,r);return l.length>0?_g.fromMillis(c,r).shiftTo(...l).plus(u):u}var Tg=`missing Intl.DateTimeFormat.formatToParts support`;function J(e,t=e=>e){return{regex:e,deser:([e])=>t(Np(e))}}var Eg=`[ \xA0]`,Dg=new RegExp(Eg,`g`);function Og(e){return e.replace(/\./g,`\\.?`).replace(Dg,Eg)}function kg(e){return e.replace(/\./g,``).replace(Dg,` `).toLowerCase()}function Ag(e,t){return e===null?null:{regex:RegExp(e.map(Og).join(`|`)),deser:([n])=>e.findIndex(e=>kg(n)===kg(e))+t}}function jg(e,t){return{regex:e,deser:([,e,t])=>Nm(e,t),groups:t}}function Mg(e){return{regex:e,deser:([e])=>e}}function Ng(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function Pg(e,t){let n=Ip(t),r=Ip(t,`{2}`),i=Ip(t,`{3}`),a=Ip(t,`{4}`),o=Ip(t,`{6}`),s=Ip(t,`{1,2}`),c=Ip(t,`{1,3}`),l=Ip(t,`{1,6}`),u=Ip(t,`{1,9}`),d=Ip(t,`{2,4}`),f=Ip(t,`{4,6}`),ee=e=>({regex:RegExp(Ng(e.val)),deser:([e])=>e,literal:!0}),p=(p=>{if(e.literal)return ee(p);switch(p.val){case`G`:return Ag(t.eras(`short`),0);case`GG`:return Ag(t.eras(`long`),0);case`y`:return J(l);case`yy`:return J(d,jm);case`yyyy`:return J(a);case`yyyyy`:return J(f);case`yyyyyy`:return J(o);case`M`:return J(s);case`MM`:return J(r);case`MMM`:return Ag(t.months(`short`,!0),1);case`MMMM`:return Ag(t.months(`long`,!0),1);case`L`:return J(s);case`LL`:return J(r);case`LLL`:return Ag(t.months(`short`,!1),1);case`LLLL`:return Ag(t.months(`long`,!1),1);case`d`:return J(s);case`dd`:return J(r);case`o`:return J(c);case`ooo`:return J(i);case`HH`:return J(r);case`H`:return J(s);case`hh`:return J(r);case`h`:return J(s);case`mm`:return J(r);case`m`:return J(s);case`q`:return J(s);case`qq`:return J(r);case`s`:return J(s);case`ss`:return J(r);case`S`:return J(c);case`SSS`:return J(i);case`u`:return Mg(u);case`uu`:return Mg(s);case`uuu`:return J(n);case`a`:return Ag(t.meridiems(),0);case`kkkk`:return J(a);case`kk`:return J(d,jm);case`W`:return J(s);case`WW`:return J(r);case`E`:case`c`:return J(n);case`EEE`:return Ag(t.weekdays(`short`,!1),1);case`EEEE`:return Ag(t.weekdays(`long`,!1),1);case`ccc`:return Ag(t.weekdays(`short`,!0),1);case`cccc`:return Ag(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return jg(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return jg(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return Mg(/[a-z_+-/]{1,256}?/i);case` `:return Mg(/[^\S\n\r]/);default:return ee(p)}})(e)||{invalidReason:Tg};return p.token=e,p}var Fg={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 Ig(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=Fg[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function Lg(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function Rg(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(_m(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 zg(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 K(e.z)||(n=tp.create(e.z)),K(e.Z)||(n||=new Dp(e.Z),r=e.Z),K(e.q)||(e.M=(e.q-1)*3+1),K(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),K(e.u)||(e.S=Cm(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var Bg=null;function Vg(){return Bg||=Y.fromMillis(1555555555555),Bg}function Hg(e,t){if(e.literal)return e;let n=qg(ih.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function Ug(e,t){return Array.prototype.concat(...e.map(e=>Hg(e,t)))}var Wg=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=Ug(ih.parseFormat(t),e),this.units=this.tokens.map(t=>Pg(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=Lg(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=Rg(e,this.regex,this.handlers),[r,i,a]=n?zg(n):[null,null,void 0];if(_m(n,`a`)&&_m(n,`H`))throw new vf(`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 Gg(e,t,n){return new Wg(e,n).explainFromTokens(t)}function Kg(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=Gg(e,t,n);return[r,i,a,o]}function qg(e,t){if(!e)return null;let n=ih.create(t,e).dtFormatter(Vg()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>Ig(t,e,i))}var Jg=`Invalid DateTime`,Yg=864e13;function Xg(e){return new Gp(`unsupported zone`,`the zone "${e.name}" is not supported`)}function Zg(e){return e.weekData===null&&(e.weekData=$p(e.c)),e.weekData}function Qg(e){return e.localWeekData===null&&(e.localWeekData=$p(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function $g(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new Y({...n,...t,old:n})}function e_(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 t_(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 n_(e,t,n){return e_(Om(e),t,n)}function r_(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,Dm(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=_g.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]=e_(Om(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function i_(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=Y.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return Y.invalid(new Gp(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function a_(e,t,n=!0){return e.isValid?ih.create(W.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function o_(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=q(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=q(e.c.month),n===`month`)return i;i+=`-`}else if(i+=q(e.c.month),n===`month`)return i;return i+=q(e.c.day),i}function s_(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+=q(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=q(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=q(e.c.second))}else{if(c+=q(e.c.minute),o===`minute`)break;s&&(c+=q(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=q(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=q(Math.trunc(-e.o/60)),c+=`:`,c+=q(Math.trunc(-e.o%60))):(c+=`+`,c+=q(Math.trunc(e.o/60)),c+=`:`,c+=q(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var c_={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},l_={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},u_={ordinal:1,hour:0,minute:0,second:0,millisecond:0},d_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],f_=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],p_=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function m_(e){let t={year:`year`,years:`year`,month:`month`,months:`month`,day:`day`,days:`day`,hour:`hour`,hours:`hour`,minute:`minute`,minutes:`minute`,quarter:`quarter`,quarters:`quarter`,second:`second`,seconds:`second`,millisecond:`millisecond`,milliseconds:`millisecond`,weekday:`weekday`,weekdays:`weekday`,weeknumber:`weekNumber`,weeksnumber:`weekNumber`,weeknumbers:`weekNumber`,weekyear:`weekYear`,weekyears:`weekYear`,ordinal:`ordinal`}[e.toLowerCase()];if(!t)throw new yf(e);return t}function h_(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return m_(e)}}function g_(e){if(b_===void 0&&(b_=G.now()),e.type!==`iana`)return e.offset(b_);let t=e.name,n=x_.get(t);return n===void 0&&(n=e.offset(b_),x_.set(t,n)),n}function __(e,t){let n=kp(t.zone,G.defaultZone);if(!n.isValid)return Y.invalid(Xg(n));let r=W.fromObject(t),i,a;if(K(e.year))i=G.now();else{for(let t of d_)K(e[t])&&(e[t]=c_[t]);let t=om(e)||sm(e);if(t)return Y.invalid(t);let r=g_(n);[i,a]=n_(e,r,n)}return new Y({ts:i,zone:n,loc:r,o:a})}function v_(e,t,n){let r=K(n.round)?!0:n.round,i=K(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=wm(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 y_(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 b_,x_=new Map,Y=class e{constructor(e){let t=e.zone||G.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new Gp(`invalid input`):null)||(t.isValid?null:Xg(t));this.ts=K(e.ts)?G.now():e.ts;let r=null,i=null;if(!n)if(e.old&&e.old.ts===this.ts&&e.old.zone.equals(t))[r,i]=[e.old.c,e.old.o];else{let a=cm(e.o)&&!e.old?e.o:t.offset(this.ts);r=t_(this.ts,a),n=Number.isNaN(r.year)?new Gp(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||W.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=y_(arguments),[n,r,i,a,o,s,c]=t;return __({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=y_(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Dp.utcInstance,__({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=dm(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=kp(n.zone,G.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:W.fromObject(n)}):e.invalid(Xg(i))}static fromMillis(t,n={}){if(cm(t))return t<-Yg||t>Yg?e.invalid(`Timestamp out of range`):new e({ts:t,zone:kp(n.zone,G.defaultZone),loc:W.fromObject(n)});throw new bf(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(cm(t))return new e({ts:t*1e3,zone:kp(n.zone,G.defaultZone),loc:W.fromObject(n)});throw new bf(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=kp(n.zone,G.defaultZone);if(!r.isValid)return e.invalid(Xg(r));let i=W.fromObject(n),a=Fm(t,h_),{minDaysInFirstWeek:o,startOfWeek:s}=rm(a,i),c=G.now(),l=K(n.specificOffset)?r.offset(c):n.specificOffset,u=!K(a.ordinal),d=!K(a.year),f=!K(a.month)||!K(a.day),ee=d||f,p=a.weekYear||a.weekNumber;if((ee||u)&&p)throw new vf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new vf(`Can't mix ordinal dates with month/day`);let te=p||a.weekday&&!ee,ne,re,ie=t_(c,l);te?(ne=f_,re=l_,ie=$p(ie,o,s)):u?(ne=p_,re=u_,ie=tm(ie)):(ne=d_,re=c_);let ae=!1;for(let e of ne){let t=a[e];K(t)?ae?a[e]=re[e]:a[e]=ie[e]:ae=!0}let oe=(te?im(a,o,s):u?am(a):om(a))||sm(a);if(oe)return e.invalid(oe);let[se,ce]=n_(te?em(a,o,s):u?nm(a):a,l,r),le=new e({ts:se,zone:r,o:ce,loc:i});return a.weekday&&ee&&t.weekday!==le.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${le.toISO()}`):le.isValid?le:e.invalid(le.invalid)}static fromISO(e,t={}){let[n,r]=Yh(e);return i_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=Xh(e);return i_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=Zh(e);return i_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(K(t)||K(n))throw new bf(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=Kg(W.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):i_(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]=ig(e);return i_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new bf(`need to specify a reason the DateTime is invalid`);let r=t instanceof Gp?t:new Gp(t,n);if(G.throwOnInvalid)throw new hf(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=qg(e,W.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return Ug(ih.parseFormat(e),W.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){b_=void 0,x_.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?Zg(this).weekYear:NaN}get weekNumber(){return this.isValid?Zg(this).weekNumber:NaN}get weekday(){return this.isValid?Zg(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?Qg(this).weekday:NaN}get localWeekNumber(){return this.isValid?Qg(this).weekNumber:NaN}get localWeekYear(){return this.isValid?Qg(this).weekYear:NaN}get ordinal(){return this.isValid?tm(this.c).ordinal:NaN}get monthShort(){return this.isValid?xg.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?xg.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?xg.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?xg.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=Om(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=t_(s,a),u=t_(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[$g(this,{ts:s}),$g(this,{ts:c})]:[this]}get isInLeapYear(){return Tm(this.year)}get daysInMonth(){return Dm(this.year,this.month)}get daysInYear(){return this.isValid?Em(this.year):NaN}get weeksInWeekYear(){return this.isValid?Am(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?Am(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=ih.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Dp.instance(e),t)}toLocal(){return this.setZone(G.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=kp(t,G.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]=n_(r,n,t)}return $g(this,{ts:e,zone:t})}else return e.invalid(Xg(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return $g(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=Fm(e,h_),{minDaysInFirstWeek:n,startOfWeek:r}=rm(t,this.loc),i=!K(t.weekYear)||!K(t.weekNumber)||!K(t.weekday),a=!K(t.ordinal),o=!K(t.year),s=!K(t.month)||!K(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new vf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new vf(`Can't mix ordinal dates with month/day`);let u;i?u=em({...$p(this.c,n,r),...t},n,r):K(t.ordinal)?(u={...this.toObject(),...t},K(t.day)&&(u.day=Math.min(Dm(u.year,u.month),u.day))):u=nm({...tm(this.c),...t});let[d,f]=n_(u,this.o,this.zone);return $g(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=_g.fromDurationLike(e);return $g(this,r_(this,t))}minus(e){if(!this.isValid)return this;let t=_g.fromDurationLike(e).negate();return $g(this,r_(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=_g.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?ih.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):Jg}toLocaleString(e=wf,t={}){return this.isValid?ih.create(this.loc.clone(t),e).formatDateTime(this):Jg}toLocaleParts(e={}){return this.isValid?ih.create(this.loc.clone(e),e).formatDateTimeParts(this):[]}toISO({format:e=`extended`,suppressSeconds:t=!1,suppressMilliseconds:n=!1,includeOffset:r=!0,extendedZone:i=!1,precision:a=`milliseconds`}={}){if(!this.isValid)return null;a=m_(a);let o=e===`extended`,s=o_(this,o,a);return d_.indexOf(a)>=3&&(s+=`T`),s+=s_(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?o_(this,e===`extended`,m_(t)):null}toISOWeekDate(){return a_(this,`kkkk-'W'WW-c`)}toISOTime({suppressMilliseconds:e=!1,suppressSeconds:t=!1,includeOffset:n=!0,includePrefix:r=!1,extendedZone:i=!1,format:a=`extended`,precision:o=`milliseconds`}={}){return this.isValid?(o=m_(o),(r&&d_.indexOf(o)>=3?`T`:``)+s_(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return a_(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return a_(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?o_(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`)),a_(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():Jg}[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 _g.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=mm(t).map(_g.normalizeUnit),a=e.valueOf()>this.valueOf(),o=wg(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?bg.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),v_(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?v_(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 bf(`min requires all arguments be DateTimes`);return hm(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new bf(`max requires all arguments be DateTimes`);return hm(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return Gg(W.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new Wg(W.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(K(t)||K(n))throw new bf(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=W.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new bf(`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):i_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return wf}static get DATE_MED(){return Tf}static get DATE_MED_WITH_WEEKDAY(){return Ef}static get DATE_FULL(){return Df}static get DATE_HUGE(){return Of}static get TIME_SIMPLE(){return kf}static get TIME_WITH_SECONDS(){return Af}static get TIME_WITH_SHORT_OFFSET(){return jf}static get TIME_WITH_LONG_OFFSET(){return Mf}static get TIME_24_SIMPLE(){return Nf}static get TIME_24_WITH_SECONDS(){return Pf}static get TIME_24_WITH_SHORT_OFFSET(){return Ff}static get TIME_24_WITH_LONG_OFFSET(){return If}static get DATETIME_SHORT(){return Lf}static get DATETIME_SHORT_WITH_SECONDS(){return Rf}static get DATETIME_MED(){return zf}static get DATETIME_MED_WITH_SECONDS(){return Bf}static get DATETIME_MED_WITH_WEEKDAY(){return Vf}static get DATETIME_FULL(){return Hf}static get DATETIME_FULL_WITH_SECONDS(){return Uf}static get DATETIME_HUGE(){return Wf}static get DATETIME_HUGE_WITH_SECONDS(){return Gf}};function S_(e){if(Y.isDateTime(e))return e;if(e&&e.valueOf&&cm(e.valueOf()))return Y.fromJSDate(e);if(e&&typeof e==`object`)return Y.fromObject(e);throw new bf(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function C_(e){return Ku(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof hl}function w_(e){return R(e).unwrap_or(void 0)===``}function T_(e){return e instanceof cl}function E_(e){let t=ju(e);if(t!==null)return t;if(Cu(e)&&e instanceof al&&e.expression){let t=e.op?.value,n=ju(e.expression);if(n!==null)return t===`-`?-n:n}return null}function D_(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=E_(e);if(t!==null)return t;let n=R(e).unwrap_or(void 0);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function O_(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=E_(e);if(t!==null)return Number.isInteger(t)?t:null;let n=R(e).unwrap_or(void 0);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}const k_=[`true`,`yes`,`y`,`t`,`1`],A_=[`false`,`no`,`n`,`f`,`0`];function j_(e){if(e==null)return null;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===0?!1:e===1?!0:null;if(typeof e==`string`){let t=e.toLowerCase();return k_.includes(t)?!0:A_.includes(t)?!1:null}if(Ku(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=ju(e);if(t===0)return!1;if(t===1)return!0;let n=R(e)?.unwrap_or(``).toLowerCase();if(n){if(k_.includes(n))return!0;if(A_.includes(n))return!1}return null}function M_(e){if(e==null)return null;if(typeof e==`string`)return e;let t=F(e).unwrap_or(void 0);return t?h(t):R(e).unwrap_or(null)}function N_(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=R(e).unwrap_or(null)??D_(e)??j_(e);return t===null?null:t.toString()}var P_=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],F_=[`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`],I_=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function L_(e){if(e==null)return null;let t=typeof e==`string`?e:R(e).unwrap_or(null);if(t===null)return null;for(let e of I_){let n=Y.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of P_){let n=Y.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of F_){let n=Y.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=Y.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 R_(e,t,n){return t.map((t,r)=>{let i=e[t]?.value;if(i==null&&n&&n[r]){let e=n[r];if(e?.dbdefault)return JSON.stringify(e.dbdefault.value)}return JSON.stringify(i)}).join(`|`)}function z_(e,t,n){return t.some((t,r)=>{let i=e[t]?.value;return i==null&&n&&n[r]&&n[r]?.dbdefault?!1:i==null})}function B_(e){return e.increment||lf(e.type.type_name)}function V_(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function H_(e,t,n){return n.length===1?V_(e,t,n[0]):`(${n.map(n=>V_(e,t,n)).join(`, `)})`}function U_(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function W_(e,t,n){let r=t.map(t=>e.columnNodes[t]).filter(Boolean);return r.length>0?r.map(e=>new D(E.INVALID_RECORDS_FIELD,n,e)):[new D(E.INVALID_RECORDS_FIELD,n,e.node)]}var G_=e=>e>1?`Composite PK`:`PK`;function K_(e){return bc(Array.from(e.records),([t,n])=>{if(Ac(n))return[];e.cachedMergedTables.has(t)||e.cachedMergedTables.set(t,Rd(t,e));let r=e.cachedMergedTables.get(t),i=X_(r),a=Z_(n),o=Mc(r.fields,`name`);return bc(i,e=>q_(e,n,a,o,r))})}function q_(e,t,n,r,i){let a=Q_(e,n,r,i,t);if(!Ac(a))return a;let o=io(e.map(e=>r[e])),s=o.every(e=>e&&B_(e)),[c,l]=g(t,t=>z_(t.values,e,o)),u=s?[]:J_(c,e,i),d=Y_(l,e,o,i);return[...u,...d]}function J_(e,t,n){if(Ac(e))return[];let r=`NULL in ${G_(t.length)}: ${H_(n.schemaName,n.name,t)} cannot be NULL`;return bc(e,e=>W_(e,t,r))}function Y_(e,t,n,r){return bc(cc(Tc(e,e=>R_(e.values,t,n)),e=>e.length>1),e=>{let n=G_(t.length),i=H_(r.schemaName,r.name,t);return bc(e.slice(1),e=>W_(e,t,`Duplicate ${n}: ${i} = ${U_(e.values,t)}`))})}function X_(e){return[...e.fields.filter(e=>e.pk).map(e=>[e.name]),...e.indexes.filter(e=>e.pk).map(e=>e.columns.map(e=>e.value))]}function Z_(e){return new Set(e.flatMap(e=>Object.keys(e.values)))}function Q_(e,t,n,r,i){let a=tc(e,Array.from(t));if(Ac(a))return[];let o=a.filter(e=>{let t=n[e];return t&&!t.increment&&!lf(t.type.type_name)&&!t.dbdefault});if(Ac(o))return[];let s=`${G_(o.length)}: Column ${H_(r.schemaName,r.name,o)} is missing from record and has no default value`;return i.map(e=>new D(E.INVALID_RECORDS_FIELD,s,e.node))}var $_=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function ev(e){return bc(Array.from(e.records),([t,n])=>{e.cachedMergedTables.has(t)||e.cachedMergedTables.set(t,Rd(t,e));let r=e.cachedMergedTables.get(t);if(Ac(n))return[];let i=tv(r),a=Mc(r.fields,`name`);return bc(i,e=>nv(n,e,io(e.map(e=>a[e])),r))})}function tv(e){return[...e.fields.filter(e=>e.unique).map(e=>[e.name]),...e.indexes.filter(e=>e.unique).map(e=>e.columns.map(e=>e.value))]}function nv(e,t,n,r){return bc(cc(Tc(e.filter(e=>!z_(e.values,t,n)),e=>R_(e.values,t,n)),e=>e.length>1),e=>{let n=$_(t.length),i=H_(r.schemaName,r.name,t);return bc(e.slice(1),e=>W_(e,t,`Duplicate ${n}: ${i} = ${U_(e.values,t)}`))})}function rv(e){let t=[...e.ref.values(),...bc(Array.from(e.tables.values()),t=>zd(t,e))],n=iv(e);return bc(t,e=>sv(e,n))}function iv(e){let t=new Map;for(let n of e.tables.values()){let r=av(n.schemaName,n.name),i=e.records.get(n)||[];e.cachedMergedTables.has(n)||e.cachedMergedTables.set(n,Rd(n,e));let a=e.cachedMergedTables.get(n);t.set(r,{mergedTable:a,rows:i})}return t}function av(e,t){return e?`${e}.${t}`:`${Bl}.${t}`}function ov(e,t,n,r){if(Ac(e.rows))return[];let i=new Set(t.rows.map(e=>R_(e.values,r.fieldNames)));return bc(e.rows.filter(e=>!z_(e.values,n.fieldNames)).filter(e=>{let t=R_(e.values,n.fieldNames);return!i.has(t)}),i=>{let a=H_(e.mergedTable.schemaName,e.mergedTable.name,n.fieldNames),o=H_(t.mergedTable.schemaName,t.mergedTable.name,r.fieldNames),s=`FK violation: ${a} = ${U_(i.values,n.fieldNames)} does not exist in ${o}`;return W_(i,n.fieldNames,s)})}function sv(e,t){if(!e.endpoints)return[];let[n,r]=e.endpoints,i=t.get(av(n.schemaName,n.tableName)),a=t.get(av(r.schemaName,r.tableName));return!i||!a?[]:cv(i,a,n,r)}function cv(e,t,n,r){let i=n.relation,a=r.relation;return i===`1`&&a===`1`||i===`*`&&a===`*`?[...ov(e,t,n,r),...ov(t,e,r,n)]:i===`*`&&a===`1`?ov(e,t,n,r):i===`1`&&a===`*`?ov(t,e,r,n):[]}var lv=class{constructor(e){this.env=e,this.tableToRecordMap=new Map}interpret(e){let t=[],n=[];for(let r of e){let{table:e,mergedColumns:i}=uv(r,this.env),a=this.tableToRecordMap.get(e);if(a){t.push(new D(E.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${e.name}' - A Table can only have one Records block`,a)),t.push(new D(E.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${e.name}' - A Table can only have one Records block`,r));continue}this.tableToRecordMap.set(e,r);for(let a of r.body.body){let r=a,o=dv(r,i,this.env);t.push(...o.getErrors()),n.push(...o.getWarnings());let s=o.getValue();s.row&&(this.env.records.has(e)||this.env.records.set(e,[]),this.env.records.get(e).push({values:s.row,node:r,columnNodes:s.columnNodes}))}}let r=this.validateConstraints();return n.push(...r),new O(void 0,t,n)}validateConstraints(){let e=[];return e.push(...K_(this.env).map(e=>e.toWarning())),e.push(...ev(this.env).map(e=>e.toWarning())),e.push(...rv(this.env).map(e=>e.toWarning())),e}};function uv(e,t){let n=e.name,r=e.parent;if(r instanceof x){let e=t.tables.get(r),i=Rd(e,t);return n?{table:e,mergedTable:i,mergedColumns:n.elementList.map(e=>i.fields.find(t=>t.name===I(e).unwrap()))}:{table:e,mergedTable:i,mergedColumns:i.fields}}let i=Iu(n).unwrap(),a=h(i.variables).referee.declaration,o=t.tables.get(a),s=Rd(o,t);return{table:o,mergedTable:s,mergedColumns:i.args.map(e=>s.fields.find(t=>t.name===I(e).unwrap()))}}function dv(e,t,n){let r=[],i=[],a={},o={},s=e.callee instanceof ul?e.callee.elementList:[e.callee];if(s.length!==t.length)return r.push(new D(E.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new O({row:null,columnNodes:{}},r,i);for(let e=0;e<t.length;e++){let c=s[e],l=t[e];o[l.name]=c;let u=pv(c,l,n);r.push(...u.getErrors()),i.push(...u.getWarnings());let d=u.getValue();d!==null&&(a[l.name]=d)}return new O({row:a,columnNodes:o},r,i)}function fv(e,t){return e instanceof cl?e.value?.value||``:!isNaN(e.start)&&!isNaN(e.end)?t.slice(e.start,e.end):``}function pv(e,t,n){let r=t.type.type_name.split(`(`)[0],{increment:i,not_null:a,dbdefault:o}=t,s=t.type.isEnum||!1,c=pf(r,s),l=N_(e),u=l===null?fv(e,n.source):l,d=l===null?`expression`:c;if(e instanceof cl)return new O({value:e.value?.value||``,type:`expression`},[],[]);if(C_(e)||w_(e)&&!of(r)){let n=o&&o.value.toString().toLowerCase()!==`null`,s=lf(r);return a&&!n&&!i&&!s?new O({value:null,type:c},[],[new kl(E.INVALID_RECORDS_FIELD,`NULL not allowed for non-nullable column '${t.name}' without default and increment`,e)]):new O({value:null,type:c},[],[])}if(s){let r=([...n.enums.values()].find(e=>e.schemaName===t.type.schemaName&&e.name===t.type.type_name)?.values||[]).map(e=>e.name),i=R(e).unwrap_or(void 0);return i===void 0&&(i=F(e).unwrap_or([]).pop()),r.includes(i)?new O({value:i,type:c},[],[]):new O({value:i,type:c},[],[new kl(E.INVALID_RECORDS_FIELD,`Invalid enum value for column '${t.name}'`,e)])}if(rf(r)){let n=D_(e);if(n===null)return new O({value:u,type:d},[],[new kl(E.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${t.name}'`,e)]);if(tf(r)&&!Number.isInteger(n))return new O({value:Math.floor(n),type:c},[],[new kl(E.INVALID_RECORDS_FIELD,`Invalid integer value ${n} for column '${t.name}': expected integer, got decimal`,e)]);if(nf(r)&&t.type.numericParams){let{precision:r,scale:i}=t.type.numericParams,a=n.toString().split(`.`),o=a[0].replace(/^-/,``),s=a[1]||``,l=o.length+s.length,u=s.length;if(l>r)return new O({value:n,type:c},[],[new kl(E.INVALID_RECORDS_FIELD,`Numeric value ${n} for column '${t.name}' exceeds precision: expected at most ${r} total digits, got ${l}`,e)]);if(u>i)return new O({value:n,type:c},[],[new kl(E.INVALID_RECORDS_FIELD,`Numeric value ${n} for column '${t.name}' exceeds scale: expected at most ${i} decimal digits, got ${u}`,e)])}return new O({value:n,type:c},[],[])}if(af(r)){let n=j_(e);return n===null?new O({value:u,type:d},[],[new kl(E.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${t.name}'`,e)]):new O({value:n,type:c},[],[])}if(cf(r)){let n=L_(e);return n===null?new O({value:u,type:d},[],[new kl(E.INVALID_RECORDS_FIELD,`Invalid datetime value for column '${t.name}', expected valid datetime format (e.g., 'YYYY-MM-DD', 'HH:MM:SS', 'YYYY-MM-DD HH:MM:SS', 'MM/DD/YYYY', 'D MMM YYYY', or 'MMM D, YYYY')`,e)]):new O({value:n,type:c},[],[])}if(of(r)){let n=N_(e);if(n===null)return new O({value:u,type:d},[],[new kl(E.INVALID_RECORDS_FIELD,`Invalid string value for column '${t.name}'`,e)]);if(t.type.lengthParam){let{length:r}=t.type.lengthParam,i=new TextEncoder().encode(n).length;if(i>r)return new O({value:n,type:c},[],[new kl(E.INVALID_RECORDS_FIELD,`String value for column '${t.name}' exceeds maximum length: expected at most ${r} bytes (UTF-8), got ${i} bytes`,e)])}return new O({value:n,type:`string`},[],[])}return new O({value:u,type:d},[],[])}function mv(e){return{...e,fields:e.fields.map(e=>({...e,type:{...e.type,isEnum:void 0,lengthParam:void 0,numericParams:void 0}}))}}function hv(e){let t=[];for(let[n,r]of e.records){if(!r.length)continue;let e=Object.keys(r[0].columnNodes);t.push({schemaName:n.schemaName||void 0,tableName:n.name,columns:e,values:r.map(t=>e.map(e=>{let n=t.values[e];return n?{value:n.value,type:n.type}:{value:null,type:`expression`}}))})}return{schemas:[],tables:Array.from(e.tables.values()).map(mv),notes:Array.from(e.notes.values()),refs:Array.from(e.ref.values()),enums:Array.from(e.enums.values()),tableGroups:Array.from(e.tableGroups.values()),aliases:e.aliases,project:Array.from(e.project.values())[0]||{},tablePartials:Array.from(e.tablePartials.values()).map(mv),records:t}}var gv=class{constructor(e){this.ast=e,this.env={schema:[],tables:new Map,notes:new Map,refIds:{},ref:new Map,enums:new Map,tableOwnerGroup:{},tableGroups:new Map,aliases:[],project:new Map,tablePartials:new Map,records:new Map,recordsElements:[],cachedMergedTables:new Map,source:e.source}}interpret(){let e=this.ast.body.flatMap(e=>{switch(Du(e).unwrap_or(void 0)){case j.Table:return new Bd(e,this.env).interpret();case j.Note:return new Vd(e,this.env).interpret();case j.Ref:return new Hd(e,this.env).interpret();case j.TableGroup:return new Ud(e,this.env).interpret();case j.TablePartial:return new Gd(e,this.env).interpret();case j.Enum:return new Wd(e,this.env).interpret();case j.Project:return new Kd(e,this.env).interpret();case j.Records:return this.env.recordsElements.push(e),[];default:return[]}}),t=[];if(this.env.recordsElements.length){let n=new lv(this.env).interpret(this.env.recordsElements);e.push(...n.getErrors()),t.push(...n.getWarnings())}return new O(hv(this.env),e,t)}};let X=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}({}),Z=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),_v=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 vv(e){return e?e.split(``).every(e=>Al(e)||jl(e))&&!jl(e[0]):!1}function yv(e){return vv(e)?e:`"${xv(e)}"`}function bv(e){let t=``,n=0,r={n:`
|
|
12
|
-
`,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
|
|
13
|
-
`: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 Sv(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`'${xv(e)}'`;let{value:t,type:n}=e;if(t==null||af(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(af(n)){let e=j_(t);return e===null?`\`${t}\``:e?`true`:`false`}if(rf(n)){let e=D_(t);return e===null?`\`${t}\``:String(e)}if(cf(n)){let e=L_(t);return e===null?`\`${t}\``:`'${xv(e)}'`}let r=N_(t);return r===null?`\`${t}\``:`'${xv(r)}'`}function Cv(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?bv(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function wv(e){switch(e){case N.Schema:return X.Module;case N.Table:case N.TablePartial:return X.Class;case N.Column:case N.TableGroupField:return X.Field;case N.Enum:return X.Enum;case N.EnumField:return X.EnumMember;case N.TableGroup:return X.Struct;default:return X.Text}}function Tv(e,t){if(!e||Qc(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 Q(){return{suggestions:[]}}function Ev(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function Dv(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:yv(e.insertText??``),quoted:!0}))}}function Ov(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:Z.KeepWhitespace,kind:X.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function kv(e,t){return e<t.start||e>t.end?!1:t.body?e<t.body.start||e>t.body.end:!0}function Av(e){return e.commaList.length+e.elementList.length===0}function jv(e){let t=[];for(let[n,r]of e.symbolTable.entries()){let e=$l(n).unwrap_or(void 0);if(e===void 0||e.kind!==N.Column||!(r instanceof Cl||r instanceof Ol))continue;let i=Mv(r,e.name);i&&t.push(i)}return t}function Mv(e,t){let n=Wl(t),r=e instanceof Ol?e.tablePartialSymbol.symbolTable.get(n)?.declaration:e.declaration;if(!(r instanceof S))return null;let i=I(r.callee).unwrap_or(null),a=I(r.args[0]).unwrap_or(null);return i===null||a===null?null:{name:i,type:a}}function Nv(e,t,n,r){let i=e.container.element(r);return!(i instanceof x)||Du(i).unwrap_or(void 0)!==j.Records||!(i.body instanceof C)||!i.body||!Fl(r,i.body)||t.getLineContent(n.lineNumber).trim()!==``?null:i.parent instanceof b?Pv(e,i):Fv(e,i)}function Pv(e,t){if(!(t.name instanceof T))return Q();let n=t.name.argumentList?.elementList||[],r=n.map(e=>Mu(e));if(!r||r.length===0)return Q();let i=n.map((e,t)=>{let n=r[t];if(!n||!(n instanceof Cl||n instanceof Ol))return null;let i=I(e).unwrap_or(void 0);return i?Mv(n,i):null}).filter(e=>e!==null);return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}function Fv(e,t){let n=t.parent;if(!(n instanceof x))return Q();let r=n.symbol;if(!(r instanceof Sl))return Q();let i;if(t.name instanceof ll){let e=t.name.elementList,n=e.map(e=>Mu(e)).filter(e=>e!==void 0);i=e.map((e,t)=>{let r=n[t];if(!r||!(r instanceof Cl||r instanceof Ol))return null;let i=I(e).unwrap_or(void 0);return i===void 0?null:Mv(r,i)}).filter(e=>e!==null)}else{let e=jv(r);if(!e)return Q();i=e}return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}function Iv(e,t){return e.getOffsetAt(t)}var Lv=class{constructor(e,t=[]){this.compiler=e,this.triggerCharacters=t}provideCompletionItems(e,t){let n=Iv(e,t),r=Nv(this.compiler,e,t,n);if(r!==null)return r;let i=this.compiler.token.flatStream(),{token:a,index:o}=this.compiler.container.token(n),s=o===void 0?i[0]:i[o+1];if([...a?.trailingTrivia||[],...a?.leadingTrivia||[],...s?.leadingTrivia||[]].find(e=>tl(e)&&Fl(n,e)))return Q();if(o===void 0)return Yv();if([_.STRING_LITERAL,_.QUOTED_STRING].includes(a.kind)&&Fl(n,a))return Q();let c=this.compiler.container.element(n);if(this.compiler.container.scopeKind(n)===$.TOPLEVEL||c instanceof x&&c.type&&c.type.start<=n&&c.type.end>=n)return Yv();let l=[...this.compiler.container.stack(n)].reverse();for(let e of l)if(e instanceof al)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return zv(this.compiler,n,e);case`~`:return Rv(this.compiler,n);default:}else if(e instanceof ol)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return zv(this.compiler,n,e);case`.`:return qv(this.compiler,n,e);default:}else if(e instanceof il)return Wv(this.compiler,n,e);else if(e instanceof w)return Wv(this.compiler,n,e);else if(e instanceof ll)return Hv(this.compiler,n,e);else if(e instanceof ul)return Uv(this.compiler,n);else if(e instanceof T)return ty(this.compiler,n,e);else if(e instanceof S)return Jv(this.compiler,n,e);else if(e instanceof x){if(kv(n,e))return ey(this.compiler,n,e);if(e.bodyColon&&n>=e.bodyColon.end||e.body&&Fl(n,e.body))return Jv(this.compiler,n,void 0)}return Q()}};function Rv(e,t){return Vv(e,t,e.parse.ast(),[N.TablePartial])}function zv(e,t,n){let r=e.container.scopeKind(t);if([$.REF,$.TABLE,$.TABLEPARTIAL].includes(r)){let r=Vv(e,t,e.container.element(t),[N.Table,N.Schema,N.Column]);return Tv(n.op,t)?Ev(r):r}return Q()}function Bv(e,t,n){return Dv({suggestions:e.symbol.members(t).filter(({kind:e})=>n.includes(e)).map(({name:e,kind:t})=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:wv(t),sortText:wv(t).toString().padStart(2,`0`),range:void 0}))})}function Vv(e,t,n,r){if(n===void 0)return Q();let i=n,a={suggestions:[]};for(;i;){if(i?.symbol?.symbolTable){let{symbol:t}=i;a.suggestions.push(...Bv(e,t,r).suggestions)}i=i instanceof x?i.parent:void 0}return Dv(a)}function Hv(e,t,n){let r=e.container.scopeKind(t),i=e.container.element(t),a=[...e.container.stack(t)];for(let r of a)if(r instanceof T&&r.argumentList===n)return ty(e,t,r);if(i instanceof x&&Du(i).unwrap_or(void 0)===j.Records&&!(i.name instanceof T)&&kv(t,i)){let t=i.parent?.symbol||i.name?.referee;if(t){let r=Bv(e,t,[N.Column]);return Av(n)?Ov(r):r}}switch(r){case $.INDEXES:return ay(e,t);case $.REF:for(;a.length>0;){let n=a.pop();if(n instanceof ol&&n.op?.value===`.`)return qv(e,t,n)}return $v(e,t);default:break}return Q()}function Uv(e,t){return e.container.scopeKind(t)===$.RECORDS?Vv(e,t,e.container.element(t),[N.Schema,N.Enum,N.EnumField]):Q()}function Wv(e,t,n){let{token:r}=e.container.token(t);if([_.COMMA,_.LBRACKET].includes(r?.kind)){let n=Gv(e,t);return r?.kind===_.COMMA&&Tv(r,t)?Ev(n):n}if(n.name&&n.name.start<=t&&n.name.end>=t)return Gv(e,t);if(n.name instanceof rl){let i=Kv(e,t,Yu(n.name).unwrap_or(``));return r?.kind===_.COLON&&Tv(r,t)?Ev(i):i}return Q()}function Gv(e,t){let n=e.container.element(t);if(n instanceof b)return Q();let r=e.container.scopeKind(t);if(n.body&&!Fl(t,n.body)){let e;switch(r){case $.TABLE:case $.TABLEPARTIAL:e=[M.HeaderColor,M.Note];break;case $.TABLEGROUP:e=[M.Color,M.Note];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:X.Field,insertTextRules:Z.KeepWhitespace,range:void 0}))}}switch(r){case $.TABLE:case $.TABLEPARTIAL:return{suggestions:[...[M.PK,M.PrimaryKey,M.Null,M.NotNull,M.Increment,M.Unique].map(e=>({label:e,insertText:e,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0})),...[M.Ref,M.Default,M.Note,M.Check].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.ENUM:return{suggestions:[...[M.Note].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.INDEXES:return{suggestions:[...[M.Unique,M.PK].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Property,range:void 0})),...[M.Note,M.Name,M.Type].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.REF:return{suggestions:[M.Update,M.Delete,M.Color].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};case $.CHECKS:return{suggestions:[M.Name].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};default:break}return Q()}function Kv(e,t,n){switch(n?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`default`:return Vv(e,t,e.container.element(t),[N.Schema,N.Enum]);default:break}return Q()}function qv(e,t,n){let r=Ou(n).unwrap_or([]);if(r.pop(),r.some(e=>!B(e)))return Q();let i=r.map(e=>I(e).unwrap());return Dv({suggestions:e.symbol.ofName(i,e.container.element(t)).flatMap(({symbol:t})=>e.symbol.members(t)).map(({kind:e,name:t})=>({label:t,insertText:t,kind:wv(e),range:void 0}))})}function Jv(e,t,n){switch(e.container.scopeKind(t)){case $.TABLE:case $.TABLEPARTIAL:return Zv(e,t,n);case $.PROJECT:return Qv(e,t,n);case $.INDEXES:return ry(e,t);case $.ENUM:return Xv(e,t,n);case $.REF:{let n=$v(e,t);return e.container.token(t).token?.kind===_.COLON&&Tv(e.container.token(t).token,t)?Ev(n):n}case $.TABLEGROUP:return ny(e);default:return Q()}}function Yv(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}}function Xv(e,t,n){return n?.callee&&oy(t,n)===1?Vv(e,t,e.container.element(t),[N.Schema,N.Table,N.Column]):Q()}function Zv(e,t,n){let r=[`Note`,`indexes`,`checks`,`Records`];if(!n?.callee)return{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))};let i=oy(t,n);return i===0?{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:i===1?iy(e,t):Q()}function Qv(e,t,n){return!n?.callee||oy(t,n)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:Q()}function $v(e,t){return Vv(e,t,e.container.element(t),[N.Schema,N.Table,N.Column])}function ey(e,t,n){return Du(n).unwrap_or(void 0)===j.Records?Vv(e,t,n.parent,[N.Schema,N.Table]):Q()}function ty(e,t,n){let r=e.container.element(t),i=n.callee&&Fl(t,n.callee),a=n.argumentList&&Fl(t,n.argumentList);if(r instanceof x&&Du(r).unwrap_or(void 0)===j.Records&&kv(t,r)){if(i)return Vv(e,t,r.parent,[N.Schema,N.Table]);if(!a)return Q();let o=n.callee;if(!o)return Q();let s=Ou(o).unwrap_or([o]),c=s[s.length-1]?.referee;if(!c)return Q();let l=Bv(e,c,[N.Column]),{argumentList:u}=n;return!u||!Av(u)?l:Ov(l)}let o=[...e.container.stack(t)];for(let r of o){if(!a||!(r instanceof S)||r.callee!==n||I(n.callee).unwrap_or(``).toLowerCase()!==j.Records)continue;let i=e.container.element(t).symbol;if(!i)return Q();let o=Bv(e,i,[N.Column]),{argumentList:s}=n;return!s||!Av(s)?o:Ov(o)}return Q()}function ny(e){return{suggestions:[...Dv({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=$l(e).unwrap_or(void 0);if(t===void 0)return[];let{kind:n,name:r}=t;return n!==N.Table&&n!==N.Schema?[]:{label:r,insertText:r,insertTextRules:Z.KeepWhitespace,kind:wv(n),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))]}}function ry(e,t){return ay(e,t)}function iy(e,t){return{suggestions:[...`integer.int.tinyint.smallint.mediumint.bigint.bit.bool.binary.varbinary.logical.char.nchar.varchar.varchar2.nvarchar.nvarchar2.binary_float.binary_double.float.double.decimal.dec.real.money.smallmoney.enum.tinyblob.tinytext.blob.text.mediumblob.mediumtext.longblob.longtext.ntext.set.inet6.uuid.image.date.time.datetime.datetime2.timestamp.year.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`).map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.TypeParameter,sortText:X.TypeParameter.toString().padStart(2,`0`),range:void 0})),...Vv(e,t,e.container.element(t),[N.Enum,N.Schema]).suggestions]}}function ay(e,t){let n=e.container.element(t)?.parent;if(!(n?.symbol instanceof Sl))return Q();let{symbolTable:r}=n.symbol;return Dv({suggestions:[...r.entries()].flatMap(([e])=>{let t=$l(e).unwrap_or(void 0);if(t===void 0)return[];let{name:n}=t;return{label:n,insertText:n,insertTextRules:Z.KeepWhitespace,kind:wv(N.Column),range:void 0}})})}function oy(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 sy=class{constructor(e){this.compiler=e}provideDefinition(e,t){let{uri:n}=e,r=Iv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(!e?.referee)continue;let t;if(e.referee?.declaration&&[y.PRIMARY_EXPRESSION,y.VARIABLE].includes(e?.kind)&&({declaration:t}=e.referee),t){let{startPos:e,endPos:r}=t;return[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:r.column+1,endLineNumber:r.line+1},uri:n}]}}return[]}},cy=class{constructor(e){this.compiler=e}provideReferences(e,t){let{uri:n}=e,r=Iv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(e&&[y.ELEMENT_DECLARATION,y.FUNCTION_APPLICATION,y.PRIMARY_EXPRESSION].includes(e?.kind)){let{symbol:t}=e;if(t?.references.length)return t.references.map(({startPos:e,endPos:t})=>({range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}))}}return[]}},ly=class{constructor(e){this.compiler=e}provideDiagnostics(){let e=[],t=this.compiler.parse._(),n=t.getErrors();for(let t of n)e.push(this.createDiagnostic(t,`error`));let r=t.getWarnings();for(let t of r)e.push(this.createDiagnostic(t,`warning`));return e}provideErrors(){return this.compiler.parse._().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(){return this.compiler.parse._().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideMarkers(){return this.provideDiagnostics().map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos;return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code}}getSeverityValue(e){return e===`error`?_v.Error:_v.Warning}},uy=t({CompletionItemInsertTextRule:()=>Z,CompletionItemKind:()=>X,DBMLCompletionItemProvider:()=>Lv,DBMLDefinitionProvider:()=>sy,DBMLDiagnosticsProvider:()=>ly,DBMLReferencesProvider:()=>cy,MarkerSeverity:()=>_v},1);function dy(){return this.parse._().getValue().ast}function fy(){return this.parse._().getErrors()}function py(){return this.parse._().getWarnings()}function my(){return this.parse._().getValue().tokens}function hy(){return this.parse._().getValue().rawDb}function gy(){return this.parse._().getValue().ast.symbol.symbolTable}function _y(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function vy(){return this.parse.tokens().filter(Vu)}function yy(e){return e.symbolTable?[...e.symbolTable.entries()].map(([e,t])=>({...$l(e).unwrap(),symbol:t})):[]}function by(e,t){if(e.length===0)return[];let n=[];for(let r=t;r;r=r instanceof x?r.parent:void 0){if(!r.symbol?.symbolTable)continue;let{symbolTable:t}=r.symbol,i=[t],a=[];for(let t of e)a=i.flatMap(e=>yd(t).flatMap(t=>{let n=e.get(t),r=$l(t).unwrap_or(void 0);return!n||!r?[]:{...r,symbol:n}})),i=a.flatMap(e=>e.symbol.symbolTable?e.symbol.symbolTable:[]);n.push(...a)}return n}function xy(e,t){return`${e.join(`.`)}@${t.id}`}function Sy(e){let t=this.token.flatStream(),{index:n,token:r}=this.container.token(e),i=n===void 0?-1:fc(t,e=>!e.isInvalid,n);if(i===-1)return[this.parse.ast()];let a=t[i].start,o=this.parse.ast(),s=[o];for(;;){let e=Uu(o).find(e=>Fl(a,e));if(e===void 0||e instanceof Yc)break;s.push(e),o=e}if(r?.kind===_.COLON)return s;for(;s.length>0;){let t=!1,n=h(s);if(n instanceof S){let r=this.parse.source();for(let i=n.end;i<e;i+=1)r[i]===`
|
|
14
|
-
`&&(s.pop(),t=!0)}else n instanceof
|
|
11
|
+
`)}function Gd(e){if(e){if(z(e))return{value:L(e).unwrap(),type:`string`};if(ju(e))return{type:`number`,value:Vl(e)};if($u(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof ll&&e.value)return{value:e.value.value,type:`expression`};if(td(e))return{value:Iu(e).map(m).and_then(F).unwrap(),type:`string`};throw Error(`Unreachable`)}}function Kd(e,t){let n=``,r=null,i,a;if(e instanceof w){let t=e.argumentList.elementList;if(r=t.map(e=>ju(e)?Bl(e):z(e)?L(e).unwrap():F(e).unwrap()).join(`,`),n=`(${r})`,t.length===2&&ju(t[0])&&ju(t[1])){let e=Vl(t[0]),n=Vl(t[1]);!isNaN(e)&&!isNaN(n)&&(i={precision:Math.trunc(e),scale:Math.trunc(n)})}else if(t.length===1&&ju(t[0])){let e=Vl(t[0]);isNaN(e)||(a={length:Math.trunc(e)})}e=e.callee}for(;e instanceof w||e instanceof _l;)e instanceof w?(n=`(${e.argumentList.elementList.map(e=>ju(e)?Bl(e):z(e)?L(e).unwrap():F(e).unwrap()).join(`,`)})${n}`,e=e.callee):e instanceof _l&&(n=`${`[${e.indexer.elementList.map(e=>e.name.expression.literal.value).join(`,`)}]`}${n}`,e=e.array);let{name:o,schemaName:s}=Bd(e),c=s.length===0?null:s[0],l=!![...t.enums.values()].find(e=>e.name===o&&e.schemaName===c);return s.length>1?new D({schemaName:s.length===0?null:s[0],type_name:`${o}${n}`,args:r,numericParams:i,lengthParam:a,isEnum:l},[new E(T.UNSUPPORTED,`Nested schema is not supported`,e)]):new D({schemaName:s.length===0?null:s[0],type_name:`${o}${n}`,args:r,numericParams:i,lengthParam:a,isEnum:l})}function qd(e,t){let n=[...t.tables.entries()].find(([,t])=>t===e)?.[0];if(!n)throw Error(`mergeTableAndPartials should be called after all tables are interpreted`);if(!(n.body instanceof S))throw Error(`Table element should have a block body`);let r=[...e.indexes],i=[...e.checks],a=e.headerColor,o=e.note,s=[...t.tablePartials.values()];for(let t of[...e.partials].reverse()){let{name:e}=t,n=s.find(t=>t.name===e);n&&(r.push(...n.indexes),i.push(...n.checks),n.headerColor!==void 0&&(a=n.headerColor),n.note!==void 0&&(o=n.note))}let c=new Map(e.fields.map(e=>[e.name,e])),l=new Set(c.keys()),u=new Map(s.map(e=>[e.name,e])),d=[];for(let e of n.body.body)if(e instanceof x)if(Tu(e.callee)){let t=F(e.callee.expression).unwrap_or(void 0),n=u.get(t);if(!n)continue;for(let e of n.fields)l.has(e.name)||d.push(e)}else{let t=F(e.callee).unwrap(),n=c.get(t);if(!n)continue;d.push(n)}let f=Vc([...d].reverse(),`name`).reverse();return{...e,fields:f,indexes:r,checks:i,headerColor:a,note:o}}function Jd(e,t){let n=[],r=[...t.tablePartials.values()],i=new Set(e.fields.map(e=>e.name));for(let t of[...e.partials].reverse()){let{name:a}=t,o=r.find(e=>e.name===a);if(o){for(let t of o.fields)if(!i.has(t.name))for(let r of t.inline_refs){let i=Rd(r.relation);n.push({name:null,schemaName:null,token:r.token,endpoints:[{schemaName:r.schemaName,tableName:r.tableName,fieldNames:r.fieldNames,token:r.token,relation:i[1]},{schemaName:e.schemaName,tableName:e.name,fieldNames:[t.name],token:t.token,relation:i[0]}]})}}}return n}var Yd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=H(this.declarationNode),this.env.tables.set(this.declarationNode,this.table);let e=[...this.interpretName(this.declarationNode.name),...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}},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),e}interpretName(e){let{name:t,schemaName:n}=Bd(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new E(T.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.table.name=t,this.table.schemaName=n.length?n[0]:null,[])}interpretAlias(e){if(!e)return[];let t=I(e).unwrap_or(null);return t&&(this.env.aliases.push({name:t,kind:`table`,value:{tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=t),[]}interpretSettingList(e){let t=N(e).getValue();this.table.headerColor=t[j.HeaderColor]?.length?Vd(t[j.HeaderColor]?.at(0)?.value):void 0;let[n]=t[j.Note]||[];return this.table.note=n&&{value:L(n?.value).map(Wd).unwrap(),token:H(n)},[]}interpretBody(e){let[t,n]=h(e.body,e=>e instanceof x);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case A.Note:return this.table.note={value:L(e.body instanceof S?e.body.body[0].callee:e.body.callee).map(Wd).unwrap(),token:H(e)},[];case A.Indexes:return this.interpretIndexes(e);case A.Check:return this.interpretChecks(e);case A.Records:return this.env.recordsElements.push(e),[];default:return[]}})}interpretInjection(e,t){let n={order:t,token:H(e)};return n.name=F(e.expression).unwrap_or(``),this.table.partials.push(n),[]}interpretFields(e){let t=(this.declarationNode.symbol?.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([e])=>au(e).unwrap_or(null)?.kind===M.Column).length?[]:[new E(T.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],n=e.flatMap((e,t)=>Tu(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...t,...n]}interpretColumn(e){let t=[],n={};n.name=I(e.callee).unwrap();let r=Kd(e.args[0],this.env);n.type=r.getValue(),t.push(...r.getErrors()),n.token=H(e),n.inline_refs=[];let i=e.args.slice(1);if(m(i)instanceof C){let r=N(i.pop()).getValue();n.pk=!!r[j.PK]?.length||!!r[j.PrimaryKey]?.length,n.increment=!!r[j.Increment]?.length,n.unique=!!r[j.Unique]?.length,n.not_null=r[j.NotNull]?.length?!0:r[j.Null]?.length?!1:void 0,n.dbdefault=Gd(r[j.Default]?.at(0)?.value);let a=r[j.Note]?.at(0);n.note=a&&{value:L(a.value).map(Wd).unwrap(),token:H(a)},n.inline_refs=(r[j.Ref]||[]).flatMap(n=>{let[r]=zd(n.value.expression);if(Ud(r,e.symbol))return t.push(new E(T.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=P(n.value.expression).unwrap(),o;if(a.length===1){let[e]=a;o={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[e],relation:i.value,token:H(n)}}else if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:H(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:H(n)}}else{t.push(new E(T.UNSUPPORTED,`Nested schema is not supported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:H(n)}}let s=this.registerInlineRefToEnv(e,r,o,n);return t.push(...s),s.length===0?o:[]}),n.checks=(r[j.Check]||[]).map(e=>({token:H(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>F(e).unwrap().toLowerCase()===`pk`),n.unique||=i.some(e=>F(e).unwrap().toLowerCase()===`unique`),this.table.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){return this.table.indexes.push(...e.body.body.map(e=>{let t={columns:[]},n=e;t.token=H(n);let r=[n.callee,...n.args];if(m(r)instanceof C){let e=N(r.pop()).getValue();t.pk=!!e[j.PK]?.length,t.unique=!!e[j.Unique]?.length,t.name=L(e[j.Name]?.at(0)?.value).unwrap_or(void 0);let n=e[j.Note]?.at(0);t.note=n&&{value:L(n.value).unwrap(),token:H(n)},t.type=F(e[j.Type]?.at(0)?.value).unwrap_or(void 0)}return r.flatMap(e=>{if(!(e instanceof w))return e;let t=[];for(;e instanceof w;)t.push(e.argumentList),e=e.callee;return t.push(e),t}).forEach(e=>{let{functional:n,nonFunctional:r}=Ru(e).unwrap();t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:H(e)})),...r.map(e=>({value:I(e).unwrap(),type:`column`,token:H(e)})))}),t})),[]}interpretChecks(e){return this.table.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=H(n),n.args[0]instanceof C&&(t.name=L(N(n.args[0]).getValue()[j.Name]?.at(0)?.value).unwrap_or(void 0)),t.expression=n.callee.value.value,t})),[]}registerInlineRefToEnv(e,t,n,r){let i=Hd(e.symbol,t);if(this.env.refIds[i])return[new E(T.CIRCULAR_REF,`References with same endpoints exist`,r),new E(T.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[i])];let a=Rd(n.relation);return this.env.refIds[i]=r,this.env.ref.set(r,{name:null,schemaName:null,token:n.token,endpoints:[{...n,relation:a[1]},{schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[F(e.callee).unwrap()],token:H(e),relation:a[0]}]}),[]}},Xd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.note={name:void 0,content:void 0,token:void 0}}interpret(){return this.note.token=H(this.declarationNode),this.env.notes.set(this.declarationNode,this.note),[...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let{name:t}=Bd(e);return this.note.name=t,[]}interpretSettingList(e){let t=N(e).getValue();return this.note.headerColor=t.headercolor?.length?Vd(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=h(e.body,e=>e instanceof x);return t.length!==1||n.length>0?[new E(T.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=na(e,`callee.expression.literal.value`,``);return this.note.content=Wd(t),[]}},Zd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.container=this.declarationNode.parent instanceof b?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=H(this.declarationNode),this.env.ref.set(this.declarationNode,this.ref),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let t=[],n=P(this.declarationNode.name).unwrap_or([]);return this.ref.name=n.pop()||null,n.length>1&&t.push(new E(T.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=n.join(`.`)||null,t}interpretBody(e){return e instanceof x?this.interpretField(e):this.interpretField(e.body[0])}interpretField(e){let t=e.callee.op.value,{leftExpression:n,rightExpression:r}=e.callee,i=zd(n),a=zd(r);if(Ud(i,a))return[new E(T.SAME_ENDPOINT,`Two endpoints are the same`,e)];let o=Hd(i,a);if(this.env.refIds[o])return[new E(T.CIRCULAR_REF,`References with same endpoints exist`,this.declarationNode),new E(T.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[o])];if(e.args[0]){let t=N(e.args[0]).getValue(),n=t.delete?.at(0)?.value;this.ref.onDelete=n instanceof il?nd(n).unwrap_or(void 0):F(n).unwrap_or(void 0);let r=t.update?.at(0)?.value;this.ref.onUpdate=r instanceof il?nd(r).unwrap_or(void 0):F(r).unwrap_or(void 0),this.ref.color=t.color?.length?Vd(t.color?.at(0)?.value):void 0}let s=Rd(t);return this.ref.endpoints=[{...Ld(n,this.container),relation:s[0],token:H(n)},{...Ld(r,this.container),relation:s[1],token:H(r)}],this.env.refIds[o]=this.declarationNode,[]}},Qd=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=H(this.declarationNode),this.env.tableGroups.set(this.declarationNode,this.tableGroup),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),e}interpretName(e){let t=[],{name:n,schemaName:r}=Bd(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new E(T.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name))),this.tableGroup.name=n,this.tableGroup.schemaName=r[0]||null,t}interpretBody(e){let[t,n]=h(e.body,e=>e instanceof x);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case`note`:this.tableGroup.note={value:L(e.body instanceof S?e.body.body[0].callee:e.body.callee).map(Wd).unwrap(),token:H(e)};break;default:break}return[]})}interpretFields(e){let t=[];return this.tableGroup.tables=e.map(e=>{let n=P(e.callee).unwrap();n.length>2&&t.push(new E(T.UNSUPPORTED,`Nested schema is not supported`,e));let r=Iu(e.callee).unwrap().pop().referee.id;if(this.env.tableOwnerGroup[r]){let i=this.env.tableOwnerGroup[r],{schemaName:a,name:o}=this.env.tableGroups.get(i),s=a?`${a}.${o}`:o;t.push(new E(T.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${n.join(`.`)}" already appears in group "${s}"`,e))}else this.env.tableOwnerGroup[r]=this.declarationNode;return{name:n.pop(),schemaName:n.join(`.`)}}),t}interpretSettingList(e){let t=N(e).getValue();this.tableGroup.color=t.color?.length?Vd(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:L(n?.value).map(Wd).unwrap(),token:H(n)},[]}},$d=class{constructor(e,t){this.declarationNode=e,this.env=t,this.enum={values:[]}}interpret(){return this.enum.token=H(this.declarationNode),this.env.enums.set(this.declarationNode,this.enum),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let{name:t,schemaName:n}=Bd(e);return n.length>1?(this.enum.name=t,this.enum.schemaName=n.join(`.`),[new E(T.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.enum.name=t,this.enum.schemaName=n.length?n[0]:null,[])}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=H(t),n.name=F(t.callee).unwrap();let r=N(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:L(r.value).map(Wd).unwrap(),token:H(r)},this.enum.values.push(n),[]})}},ef=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=H(this.declarationNode),this.env.tablePartials.set(this.declarationNode,this.tablePartial);let e=[...this.interpretName(this.declarationNode.name),...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})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),e}interpretName(e){let{name:t}=Bd(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=N(e).getValue(),n=hc(t[j.HeaderColor]);this.tablePartial.headerColor=n?Vd(n.value):void 0;let[r]=t[j.Note]||[];return this.tablePartial.note=r&&{value:L(r?.value).map(Wd).unwrap(),token:H(r)},[]}interpretBody(e){let[t,n]=h(e.body,e=>e instanceof x);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case A.Note:return this.tablePartial.note={value:L(e.body instanceof S?e.body.body[0].callee:e.body.callee).map(Wd).unwrap(),token:H(e)},[];case A.Indexes:return this.interpretIndexes(e);case A.Check:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let t=[],n={};n.name=I(e.callee).unwrap();let r=Kd(e.args[0],this.env);n.type=r.getValue(),t.push(...r.getErrors()),n.token=H(e),n.inline_refs=[];let i=e.args.slice(1);if(m(i)instanceof C){let r=N(i.pop()).getValue();n.pk=!!r[j.PK]?.length||!!r[j.PrimaryKey]?.length,n.increment=!!r[j.Increment]?.length,n.unique=!!r[j.Unique]?.length,n.not_null=r[j.NotNull]?.length?!0:r[j.Null]?.length?!1:void 0,n.dbdefault=Gd(r[j.Default]?.at(0)?.value);let a=r[j.Note]?.at(0);n.note=a&&{value:L(a.value).map(Wd).unwrap(),token:H(a)},n.inline_refs=(r[j.Ref]||[]).flatMap(n=>{let[r]=zd(n.value.expression);if(Ud(r,e.symbol))return t.push(new E(T.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=P(n.value.expression).unwrap(),o;if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:H(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:H(n)}}else{t.push(new E(T.UNSUPPORTED,`Unsupported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:H(n)}}return o}),n.checks=(r[j.Check]||[]).map(e=>({token:H(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>F(e).unwrap().toLowerCase()===`pk`),n.unique||=i.some(e=>F(e).unwrap().toLowerCase()===`unique`),this.tablePartial.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){return this.tablePartial.indexes.push(...e.body.body.map(e=>{let t={columns:[]},n=e;t.token=H(n);let r=[n.callee,...n.args];if(m(r)instanceof C){let e=N(r.pop()).getValue();t.pk=!!e[j.PK]?.length,t.unique=!!e[j.Unique]?.length,t.name=L(e[j.Name]?.at(0)?.value).unwrap_or(void 0);let n=e[j.Note]?.at(0);t.note=n&&{value:L(n.value).unwrap(),token:H(n)},t.type=F(e[j.Type]?.at(0)?.value).unwrap_or(void 0)}return r.flatMap(e=>{if(!(e instanceof w))return e;let t=[],n=e;for(;n instanceof w;)t.push(n.argumentList),n=n.callee;return t.push(n),t}).forEach(e=>{let{functional:n,nonFunctional:r}=Ru(e).unwrap();t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:H(e)})),...r.map(e=>({value:I(e).unwrap(),type:`column`,token:H(e)})))}),t})),[]}interpretChecks(e){return this.tablePartial.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=H(n),n.args[0]instanceof C&&(t.name=L(N(n.args[0]).getValue()[j.Name]?.at(0)?.value).unwrap_or(void 0)),t.expression=n.callee.value.value,t})),[]}},tf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){return this.env.project.set(this.declarationNode,this.project),this.project.token=H(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=Bd(e);return this.project.name=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.type?.value.toLowerCase()){case`table`:{let e=new Yd(t,this.env).interpret();return this.project.tables.push(this.env.tables.get(t)),e}case`ref`:{let e=new Zd(t,this.env).interpret();return this.project.refs.push(this.env.ref.get(t)),e}case`tablegroup`:{let e=new Qd(t,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(t)),e}case`enum`:{let e=new $d(t,this.env).interpret();return this.project.enums.push(this.env.enums.get(t)),e}case`note`:return this.project.note={value:L(t.body instanceof S?t.body.body[0].callee:t.body.callee).map(Wd).unwrap(),token:H(t)},[];case`tablepartial`:{let e=new ef(t,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(t)),e}default:return this.project[t.type.value.toLowerCase()]=L(t.body.callee).unwrap(),[]}})}};function nf(e){return e&&e instanceof hl&&e.expression instanceof ml?e.expression.variable?.value===`*`:!1}var rf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null},_explicitWildcards:new Set,_explicitlySet:new Set}}interpret(){let e=[];return this.diagramView.token=H(this.declarationNode),this.env.diagramViews||(this.env.diagramViews=new Map),this.env.diagramViews.set(this.declarationNode,this.diagramView),this.declarationNode.name&&e.push(...this.interpretName(this.declarationNode.name)),this.declarationNode.body instanceof S&&e.push(...this.interpretBody(this.declarationNode.body)),e}interpretName(e){let t=P(e).unwrap_or([]);return t.length>0&&(this.diagramView.name=t[t.length-1],t.length>1&&(this.diagramView.schemaName=t.slice(0,-1).join(`.`))),[]}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof x&&nf(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramView._explicitWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramView._explicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=h(e.body,e=>e instanceof b),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof S&&this.interpretSubBlock(e.body,t)}let r=this.diagramView.visibleEntities;return(n.has(`tables`)&&r.tables!==null||n.has(`tablegroups`)&&r.tableGroups!==null||n.has(`schemas`)&&r.schemas!==null)&&(n.has(`tables`)||(r.tables=[]),n.has(`tablegroups`)||(r.tableGroups=[]),n.has(`schemas`)||(r.schemas=[])),n.has(`tables`)&&this.diagramView._explicitlySet.add(`tables`),n.has(`tablegroups`)&&this.diagramView._explicitlySet.add(`tableGroups`),n.has(`schemas`)&&this.diagramView._explicitlySet.add(`schemas`),n.has(`notes`)&&this.diagramView._explicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,t){if(!t)return;if(e.body.some(e=>e instanceof x&&nf(e.callee))){switch(t){case`tables`:this.diagramView.visibleEntities.tables=[],this.diagramView._explicitWildcards.add(`tables`);break;case`notes`:this.diagramView.visibleEntities.stickyNotes=[],this.diagramView._explicitWildcards.add(`stickyNotes`);break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=[],this.diagramView._explicitWildcards.add(`tableGroups`);break;case`schemas`:this.diagramView.visibleEntities.schemas=[],this.diagramView._explicitWildcards.add(`schemas`);break}return}if(e.body.length===0)return;let n=[];for(let t of e.body){if(!(t instanceof x))continue;let e=Bu(t.callee);if(e?.declaration instanceof b){let t=P(e.declaration.name).unwrap_or([]);if(t.length>0){let e=t[t.length-1],r=t.length>1?t.slice(0,-1).join(`.`):Wl;n.push({name:e,schemaName:r});continue}}let r=P(t.callee).unwrap_or([]);if(r.length===0)continue;let i=r[r.length-1],a=r.length>1?r[0]:Wl;n.push({name:i,schemaName:a})}switch(t){case`tables`:this.diagramView.visibleEntities.tables=n.length>0?n:null;break;case`notes`:this.diagramView.visibleEntities.stickyNotes=n.length>0?n.map(e=>({name:e.name})):null;break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=n.length>0?n.map(e=>({name:e.name})):null;break;case`schemas`:this.diagramView.visibleEntities.schemas=n.length>0?n.map(e=>({name:e.name})):null;break}}},af={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`])},of={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`])},sf={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},cf={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`])},lf={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`])},uf={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`])},df={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function ff(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function pf(e,t){let n=ff(e);return t?af[t].has(n):Object.values(af).some(e=>e.has(n))}function mf(e,t){let n=ff(e);return t?of[t].has(n):Object.values(of).some(e=>e.has(n))}function hf(e,t){return pf(e,t)||mf(e,t)}function gf(e,t){let n=ff(e);return t?sf[t].has(n):Object.values(sf).some(e=>e.has(n))}function _f(e,t){let n=ff(e);return t?cf[t].has(n):Object.values(cf).some(e=>e.has(n))}function vf(e,t){let n=ff(e);return t?lf[t].has(n):Object.values(lf).some(e=>e.has(n))}function yf(e,t){let n=ff(e);return t?uf[t].has(n):Object.values(uf).some(e=>e.has(n))}function bf(e,t){let n=ff(e);return t?df[t].has(n):Object.values(df).some(e=>e.has(n))}function xf(e){let t=e.declaration;return t instanceof x&&t.args[0]||null}function Sf(e){let t=xf(e);if(!(t instanceof w)||!t.argumentList||t.argumentList.elementList.length!==2)return{};let n=zu(t.argumentList.elementList[0]),r=zu(t.argumentList.elementList[1]);return n===null||r===null?{}:{precision:Math.trunc(n),scale:Math.trunc(r)}}function Cf(e){let t=xf(e);if(!(t instanceof w)||!t.argumentList||t.argumentList.elementList.length!==1)return{};let n=zu(t.argumentList.elementList[0]);return n===null?{}:{length:Math.trunc(n)}}function wf(e,t){if(t)return`string`;if(pf(e))return`integer`;if(mf(e))return`real`;if(gf(e))return`bool`;if(_f(e))return`string`;let n=ff(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:yf(e)?`datetime`:e}var Tf=class extends Error{},Ef=class extends Tf{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Df=class extends Tf{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Of=class extends Tf{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},kf=class extends Tf{},Af=class extends Tf{constructor(e){super(`Invalid unit ${e}`)}},jf=class extends Tf{},Mf=class extends Tf{constructor(){super(`Zone is an abstract class`)}},U=`numeric`,Nf=`short`,Pf=`long`,Ff={year:U,month:U,day:U},If={year:U,month:Nf,day:U},Lf={year:U,month:Nf,day:U,weekday:Nf},Rf={year:U,month:Pf,day:U},zf={year:U,month:Pf,day:U,weekday:Pf},Bf={hour:U,minute:U},Vf={hour:U,minute:U,second:U},Hf={hour:U,minute:U,second:U,timeZoneName:Nf},Uf={hour:U,minute:U,second:U,timeZoneName:Pf},Wf={hour:U,minute:U,hourCycle:`h23`},Gf={hour:U,minute:U,second:U,hourCycle:`h23`},Kf={hour:U,minute:U,second:U,hourCycle:`h23`,timeZoneName:Nf},qf={hour:U,minute:U,second:U,hourCycle:`h23`,timeZoneName:Pf},Jf={year:U,month:U,day:U,hour:U,minute:U},Yf={year:U,month:U,day:U,hour:U,minute:U,second:U},Xf={year:U,month:Nf,day:U,hour:U,minute:U},Zf={year:U,month:Nf,day:U,hour:U,minute:U,second:U},Qf={year:U,month:Nf,day:U,weekday:Nf,hour:U,minute:U},$f={year:U,month:Pf,day:U,hour:U,minute:U,timeZoneName:Nf},ep={year:U,month:Pf,day:U,hour:U,minute:U,second:U,timeZoneName:Nf},tp={year:U,month:Pf,day:U,weekday:Pf,hour:U,minute:U,timeZoneName:Pf},np={year:U,month:Pf,day:U,weekday:Pf,hour:U,minute:U,second:U,timeZoneName:Pf},rp=class{get type(){throw new Mf}get name(){throw new Mf}get ianaName(){return this.name}get isUniversal(){throw new Mf}offsetName(e,t){throw new Mf}formatOffset(e,t){throw new Mf}offset(e){throw new Mf}equals(e){throw new Mf}get isValid(){throw new Mf}},ip=null,ap=class e extends rp{static get instance(){return ip===null&&(ip=new e),ip}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Um(e,t,n)}formatOffset(e,t){return qm(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},op=new Map;function sp(e){let t=op.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`}),op.set(e,t)),t}var cp={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function lp(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 up(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=cp[t];t===`era`?r[a]=i:K(a)||(r[a]=parseInt(i,10))}return r}var dp=new Map,fp=class e extends rp{static create(t){let n=dp.get(t);return n===void 0&&dp.set(t,n=new e(t)),n}static resetCache(){dp.clear(),op.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 Um(e,t,n,this.name)}formatOffset(e,t){return qm(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=sp(this.name),[r,i,a,o,s,c,l]=n.formatToParts?up(n,t):lp(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=zm({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}},pp={};function mp(e,t={}){let n=JSON.stringify([e,t]),r=pp[n];return r||(r=new Intl.ListFormat(e,t),pp[n]=r),r}var hp=new Map;function gp(e,t={}){let n=JSON.stringify([e,t]),r=hp.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),hp.set(n,r)),r}var _p=new Map;function vp(e,t={}){let n=JSON.stringify([e,t]),r=_p.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),_p.set(n,r)),r}var yp=new Map;function bp(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=yp.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),yp.set(i,a)),a}var xp=null;function Sp(){return xp||(xp=new Intl.DateTimeFormat().resolvedOptions().locale,xp)}var Cp=new Map;function wp(e){let t=Cp.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Cp.set(e,t)),t}var Tp=new Map;function Ep(e){let t=Tp.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Ip,...t}),Tp.set(e,t)}return t}function Dp(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=gp(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=gp(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Op(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function kp(e){let t=[];for(let n=1;n<=12;n++){let r=Y.utc(2009,n,1);t.push(e(r))}return t}function Ap(e){let t=[];for(let n=1;n<=7;n++){let r=Y.utc(2016,11,13+n);t.push(e(r))}return t}function jp(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Mp(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||wp(e.locale).numberingSystem===`latn`}var Np=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=vp(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return q(this.floor?Math.floor(e):Fm(e,3),this.padTo)}},Pp=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&&fp.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=gp(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()}},Fp=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Cm()&&(this.rtf=bp(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):fh(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Ip={firstDay:1,minimalDays:4,weekend:[6,7]},W=class e{static fromOpts(t){return e.create(t.locale,t.numberingSystem,t.outputCalendar,t.weekSettings,t.defaultToEN)}static create(t,n,r,i,a=!1){let o=t||G.defaultLocale;return new e(o||(a?`en-US`:Sp()),n||G.defaultNumberingSystem,r||G.defaultOutputCalendar,km(i)||G.defaultWeekSettings,o)}static resetCache(){xp=null,hp.clear(),_p.clear(),yp.clear(),Cp.clear(),Tp.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]=Dp(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Op(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??=Mp(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,km(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 jp(this,e,Qm,()=>{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]=kp(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return jp(this,e,nh,()=>{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]=Ap(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return jp(this,void 0,()=>rh,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[Y.utc(2016,11,13,9),Y.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return jp(this,e,sh,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[Y.utc(-40,1,1),Y.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 Np(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new Pp(e,this.intl,t)}relFormatter(e={}){return new Fp(this.intl,this.isEnglish(),e)}listFormatter(e={}){return mp(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||wp(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:wm()?Ep(this.locale):Ip}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})`}},Lp=null,Rp=class e extends rp{static get utcInstance(){return Lp===null&&(Lp=new e(0)),Lp}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(Wm(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${qm(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${qm(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return qm(this.fixed,t)}get isUniversal(){return!0}offset(){return this.fixed}equals(e){return e.type===`fixed`&&e.fixed===this.fixed}get isValid(){return!0}},zp=class extends rp{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 Bp(e,t){if(K(e)||e===null)return t;if(e instanceof rp)return e;if(xm(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?ap.instance:n===`utc`||n===`gmt`?Rp.utcInstance:Rp.parseSpecifier(n)||fp.create(e)}else if(ym(e))return Rp.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new zp(e)}var Vp={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},Hp={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]},Up=Vp.hanidec.replace(/[\[|\]]/g,``).split(``);function Wp(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(Vp.hanidec)!==-1)t+=Up.indexOf(e[n]);else for(let e in Hp){let[n,i]=Hp[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Gp=new Map;function Kp(){Gp.clear()}function qp({numberingSystem:e},t=``){let n=e||`latn`,r=Gp.get(n);r===void 0&&(r=new Map,Gp.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Vp[n]}${t}`),r.set(t,i)),i}var Jp=()=>Date.now(),Yp=`system`,Xp=null,Zp=null,Qp=null,$p=60,em,tm=null,G=class{static get now(){return Jp}static set now(e){Jp=e}static set defaultZone(e){Yp=e}static get defaultZone(){return Bp(Yp,ap.instance)}static get defaultLocale(){return Xp}static set defaultLocale(e){Xp=e}static get defaultNumberingSystem(){return Zp}static set defaultNumberingSystem(e){Zp=e}static get defaultOutputCalendar(){return Qp}static set defaultOutputCalendar(e){Qp=e}static get defaultWeekSettings(){return tm}static set defaultWeekSettings(e){tm=km(e)}static get twoDigitCutoffYear(){return $p}static set twoDigitCutoffYear(e){$p=e%100}static get throwOnInvalid(){return em}static set throwOnInvalid(e){em=e}static resetCaches(){W.resetCache(),fp.resetCache(),Y.resetCache(),Kp()}},nm=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},rm=[0,31,59,90,120,151,181,212,243,273,304,334],im=[0,31,60,91,121,152,182,213,244,274,305,335];function am(e,t){return new nm(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function om(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 sm(e,t,n){return n+(Im(e)?im:rm)[t-1]}function cm(e,t){let n=Im(e)?im:rm,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function lm(e,t){return(e-t+7)%7+1}function um(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=sm(r,i,a),s=lm(om(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=Vm(l,t,n)):c>Vm(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...Jm(e)}}function dm(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=lm(om(r,1,t),n),s=Lm(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=Lm(l)):c>s?(l=r+1,c-=Lm(r)):l=r;let{month:u,day:d}=cm(l,c);return{year:l,month:u,day:d,...Jm(e)}}function fm(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:sm(t,n,r),...Jm(e)}}function pm(e){let{year:t,ordinal:n}=e,{month:r,day:i}=cm(t,n);return{year:t,month:r,day:i,...Jm(e)}}function mm(e,t){if(!K(e.localWeekday)||!K(e.localWeekNumber)||!K(e.localWeekYear)){if(!K(e.weekday)||!K(e.weekNumber)||!K(e.weekYear))throw new kf(`Cannot mix locale-based week fields with ISO-based week fields`);return K(e.localWeekday)||(e.weekday=e.localWeekday),K(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),K(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 hm(e,t=4,n=1){let r=bm(e.weekYear),i=Am(e.weekNumber,1,Vm(e.weekYear,t,n)),a=Am(e.weekday,1,7);return r?i?a?!1:am(`weekday`,e.weekday):am(`week`,e.weekNumber):am(`weekYear`,e.weekYear)}function gm(e){let t=bm(e.year),n=Am(e.ordinal,1,Lm(e.year));return t?n?!1:am(`ordinal`,e.ordinal):am(`year`,e.year)}function _m(e){let t=bm(e.year),n=Am(e.month,1,12),r=Am(e.day,1,Rm(e.year,e.month));return t?n?r?!1:am(`day`,e.day):am(`month`,e.month):am(`year`,e.year)}function vm(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Am(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Am(n,0,59),s=Am(r,0,59),c=Am(i,0,999);return a?o?s?c?!1:am(`millisecond`,i):am(`second`,r):am(`minute`,n):am(`hour`,t)}function K(e){return e===void 0}function ym(e){return typeof e==`number`}function bm(e){return typeof e==`number`&&e%1==0}function xm(e){return typeof e==`string`}function Sm(e){return Object.prototype.toString.call(e)===`[object Date]`}function Cm(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function wm(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Tm(e){return Array.isArray(e)?e:[e]}function Em(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 Dm(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Om(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function km(e){if(e==null)return null;if(typeof e!=`object`)throw new jf(`Week settings must be an object`);if(!Am(e.firstDay,1,7)||!Am(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Am(e,1,7)))throw new jf(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Am(e,t,n){return bm(e)&&e>=t&&e<=n}function jm(e,t){return e-t*Math.floor(e/t)}function q(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Mm(e){if(!(K(e)||e===null||e===``))return parseInt(e,10)}function Nm(e){if(!(K(e)||e===null||e===``))return parseFloat(e)}function Pm(e){if(!(K(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Fm(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 Im(e){return e%4==0&&(e%100!=0||e%400==0)}function Lm(e){return Im(e)?366:365}function Rm(e,t){let n=jm(t-1,12)+1,r=e+(t-n)/12;return n===2?Im(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function zm(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 Bm(e,t,n){return-lm(om(e,1,t),n)+t-1}function Vm(e,t=4,n=1){let r=Bm(e,t,n),i=Bm(e+1,t,n);return(Lm(e)-r+i)/7}function Hm(e){return e>99?e:e>G.twoDigitCutoffYear?1900+e:2e3+e}function Um(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 Wm(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 Gm(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new jf(`Invalid unit value ${e}`);return t}function Km(e,t){let n={};for(let r in e)if(Om(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=Gm(i)}return n}function qm(e,t){let n=Math.trunc(Math.abs(e/60)),r=Math.trunc(Math.abs(e%60)),i=e>=0?`+`:`-`;switch(t){case`short`:return`${i}${q(n,2)}:${q(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${q(n,2)}${q(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function Jm(e){return Dm(e,[`hour`,`minute`,`second`,`millisecond`])}var Ym=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Xm=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Zm=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function Qm(e){switch(e){case`narrow`:return[...Zm];case`short`:return[...Xm];case`long`:return[...Ym];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 $m=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],eh=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],th=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function nh(e){switch(e){case`narrow`:return[...th];case`short`:return[...eh];case`long`:return[...$m];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var rh=[`AM`,`PM`],ih=[`Before Christ`,`Anno Domini`],ah=[`BC`,`AD`],oh=[`B`,`A`];function sh(e){switch(e){case`narrow`:return[...oh];case`short`:return[...ah];case`long`:return[...ih];default:return null}}function ch(e){return rh[e.hour<12?0:1]}function lh(e,t){return nh(t)[e.weekday-1]}function uh(e,t){return Qm(t)[e.month-1]}function dh(e,t){return sh(t)[e.year<0?0:1]}function fh(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 ph(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var mh={D:Ff,DD:If,DDD:Rf,DDDD:zf,t:Bf,tt:Vf,ttt:Hf,tttt:Uf,T:Wf,TT:Gf,TTT:Kf,TTTT:qf,f:Jf,ff:Xf,fff:$f,ffff:tp,F:Yf,FF:Zf,FFF:ep,FFFF:np},hh=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 mh[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 q(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?ch(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?uh(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?lh(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?dh(t,e):a({era:e},`era`);return ph(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 ph(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},gh=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function _h(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function vh(...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 yh(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 bh(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Mm(t[n+i]);return[r,null,n+i]}}var xh=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Sh=`(?:${xh.source}?(?:\\[(${gh.source})\\])?)?`,Ch=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,wh=RegExp(`${Ch.source}${Sh}`),Th=RegExp(`(?:[Tt]${wh.source})?`),Eh=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Dh=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Oh=/(\d{4})-?(\d{3})/,kh=bh(`weekYear`,`weekNumber`,`weekDay`),Ah=bh(`year`,`ordinal`),jh=/(\d{4})-(\d\d)-(\d\d)/,Mh=RegExp(`${Ch.source} ?(?:${xh.source}|(${gh.source}))?`),Nh=RegExp(`(?: ${Mh.source})?`);function Ph(e,t,n){let r=e[t];return K(r)?n:Mm(r)}function Fh(e,t){return[{year:Ph(e,t),month:Ph(e,t+1,1),day:Ph(e,t+2,1)},null,t+3]}function Ih(e,t){return[{hours:Ph(e,t,0),minutes:Ph(e,t+1,0),seconds:Ph(e,t+2,0),milliseconds:Pm(e[t+3])},null,t+4]}function Lh(e,t){let n=!e[t]&&!e[t+1],r=Wm(e[t+1],e[t+2]);return[{},n?null:Rp.instance(r),t+3]}function Rh(e,t){return[{},e[t]?fp.create(e[t]):null,t+1]}var zh=RegExp(`^T?${Ch.source}$`),Bh=/^-?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 Vh(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(Nm(n)),months:f(Nm(r)),weeks:f(Nm(i)),days:f(Nm(a)),hours:f(Nm(o)),minutes:f(Nm(s)),seconds:f(Nm(c),c===`-0`),milliseconds:f(Pm(l),d)}]}var Hh={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Uh(e,t,n,r,i,a,o){let s={year:t.length===2?Hm(Mm(t)):Mm(t),month:Xm.indexOf(n)+1,day:Mm(r),hour:Mm(i),minute:Mm(a)};return o&&(s.second=Mm(o)),e&&(s.weekday=e.length>3?$m.indexOf(e)+1:eh.indexOf(e)+1),s}var Wh=/^(?:(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 Gh(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=Uh(t,i,r,n,a,o,s),ee;return ee=c?Hh[c]:l?0:Wm(u,d),[f,new Rp(ee)]}function Kh(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var qh=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,Jh=/^(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$/,Yh=/^(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 Xh(e){let[,t,n,r,i,a,o,s]=e;return[Uh(t,i,r,n,a,o,s),Rp.utcInstance]}function Zh(e){let[,t,n,r,i,a,o,s]=e;return[Uh(t,s,n,r,i,a,o),Rp.utcInstance]}var Qh=_h(Eh,Th),$h=_h(Dh,Th),eg=_h(Oh,Th),tg=_h(wh),ng=vh(Fh,Ih,Lh,Rh),rg=vh(kh,Ih,Lh,Rh),ig=vh(Ah,Ih,Lh,Rh),ag=vh(Ih,Lh,Rh);function og(e){return yh(e,[Qh,ng],[$h,rg],[eg,ig],[tg,ag])}function sg(e){return yh(Kh(e),[Wh,Gh])}function cg(e){return yh(e,[qh,Xh],[Jh,Xh],[Yh,Zh])}function lg(e){return yh(e,[Bh,Vh])}var ug=vh(Ih);function dg(e){return yh(e,[zh,ug])}var fg=_h(jh,Nh),pg=_h(Mh),mg=vh(Ih,Lh,Rh);function hg(e){return yh(e,[fg,ng],[pg,mg])}var gg=`Invalid Duration`,_g={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}},vg={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},..._g},yg=146097/400,bg=146097/4800,xg={years:{quarters:4,months:12,weeks:yg/7,days:yg,hours:yg*24,minutes:yg*24*60,seconds:yg*24*60*60,milliseconds:yg*24*60*60*1e3},quarters:{months:3,weeks:yg/28,days:yg/4,hours:yg*24/4,minutes:yg*24*60/4,seconds:yg*24*60*60/4,milliseconds:yg*24*60*60*1e3/4},months:{weeks:bg/7,days:bg,hours:bg*24,minutes:bg*24*60,seconds:bg*24*60*60,milliseconds:bg*24*60*60*1e3},..._g},Sg=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Cg=Sg.slice(0).reverse();function wg(e,t,n=!1){return new Og({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 Tg(e,t){let n=t.milliseconds??0;for(let r of Cg.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function Eg(e,t){let n=Tg(e,t)<0?-1:1;Sg.reduceRight((r,i)=>{if(K(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),Sg.reduce((n,r)=>{if(K(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function Dg(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Og=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?xg:vg;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||W.create(),this.conversionAccuracy=t?`longterm`:`casual`,this.invalid=e.invalid||null,this.matrix=n,this.isLuxonDuration=!0}static fromMillis(t,n){return e.fromObject({milliseconds:t},n)}static fromObject(t,n={}){if(typeof t!=`object`||!t)throw new jf(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:Km(t,e.normalizeUnit),loc:W.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(ym(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new jf(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=lg(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]=dg(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 jf(`need to specify a reason the Duration is invalid`);let r=t instanceof nm?t:new nm(t,n);if(G.throwOnInvalid)throw new Of(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 Af(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?hh.create(this.loc,n).formatDurationFromString(this,e):gg}toHuman(e={}){if(!this.isValid)return gg;let t=e.showZeros!==!1,n=Sg.map(n=>{let r=this.values[n];return K(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+=Fm(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},Y.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?Tg(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 Sg)(Om(n.values,e)||Om(this.values,e))&&(r[e]=n.get(e)+this.get(e));return wg(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]=Gm(e(this.values[n],n));return wg(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...Km(t,e.normalizeUnit)};return wg(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 wg(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return Eg(this.matrix,e),wg(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Dg(this.normalize().shiftToAll().toObject());return wg(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 Sg)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;ym(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else ym(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 Eg(this.matrix,n),wg(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 wg(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Dg(this.values);return wg(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 Sg)if(!t(this.values[n],e.values[n]))return!1;return!0}},kg=`Invalid Interval`;function Ag(e,t){return!e||!e.isValid?jg.invalid(`missing or invalid start`):!t||!t.isValid?jg.invalid(`missing or invalid end`):t<e?jg.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 jg=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 jf(`need to specify a reason the Interval is invalid`);let r=t instanceof nm?t:new nm(t,n);if(G.throwOnInvalid)throw new Df(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=N_(t),i=N_(n);return Ag(r,i)??new e({start:r,end:i})}static after(t,n){let r=Og.fromDurationLike(n),i=N_(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Og.fromDurationLike(n),i=N_(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=Y.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=Y.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Og.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Og.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(N_).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=Og.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()})`:kg}[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=Ff,t={}){return this.isValid?hh.create(this.s.loc.clone(t),e).formatInterval(this):kg}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:kg}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:kg}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:kg}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:kg}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Og.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Mg=class{static hasDST(e=G.defaultZone){let t=Y.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return fp.isValidZone(e)}static normalizeZone(e){return Bp(e,G.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||W.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||W.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||W.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||W.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||W.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return W.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return W.create(t,null,`gregory`).eras(e)}static features(){return{relative:Cm(),localeWeek:wm()}}};function Ng(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Og.fromMillis(r).as(`days`))}function Pg(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=Ng(e,t);return(n-n%7)/7}],[`days`,Ng]],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 Fg(e,t,n,r){let[i,a,o,s]=Pg(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=Og.fromObject(a,r);return l.length>0?Og.fromMillis(c,r).shiftTo(...l).plus(u):u}var Ig=`missing Intl.DateTimeFormat.formatToParts support`;function J(e,t=e=>e){return{regex:e,deser:([e])=>t(Wp(e))}}var Lg=`[ \xA0]`,Rg=new RegExp(Lg,`g`);function zg(e){return e.replace(/\./g,`\\.?`).replace(Rg,Lg)}function Bg(e){return e.replace(/\./g,``).replace(Rg,` `).toLowerCase()}function Vg(e,t){return e===null?null:{regex:RegExp(e.map(zg).join(`|`)),deser:([n])=>e.findIndex(e=>Bg(n)===Bg(e))+t}}function Hg(e,t){return{regex:e,deser:([,e,t])=>Wm(e,t),groups:t}}function Ug(e){return{regex:e,deser:([e])=>e}}function Wg(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function Gg(e,t){let n=qp(t),r=qp(t,`{2}`),i=qp(t,`{3}`),a=qp(t,`{4}`),o=qp(t,`{6}`),s=qp(t,`{1,2}`),c=qp(t,`{1,3}`),l=qp(t,`{1,6}`),u=qp(t,`{1,9}`),d=qp(t,`{2,4}`),f=qp(t,`{4,6}`),ee=e=>({regex:RegExp(Wg(e.val)),deser:([e])=>e,literal:!0}),te=(te=>{if(e.literal)return ee(te);switch(te.val){case`G`:return Vg(t.eras(`short`),0);case`GG`:return Vg(t.eras(`long`),0);case`y`:return J(l);case`yy`:return J(d,Hm);case`yyyy`:return J(a);case`yyyyy`:return J(f);case`yyyyyy`:return J(o);case`M`:return J(s);case`MM`:return J(r);case`MMM`:return Vg(t.months(`short`,!0),1);case`MMMM`:return Vg(t.months(`long`,!0),1);case`L`:return J(s);case`LL`:return J(r);case`LLL`:return Vg(t.months(`short`,!1),1);case`LLLL`:return Vg(t.months(`long`,!1),1);case`d`:return J(s);case`dd`:return J(r);case`o`:return J(c);case`ooo`:return J(i);case`HH`:return J(r);case`H`:return J(s);case`hh`:return J(r);case`h`:return J(s);case`mm`:return J(r);case`m`:return J(s);case`q`:return J(s);case`qq`:return J(r);case`s`:return J(s);case`ss`:return J(r);case`S`:return J(c);case`SSS`:return J(i);case`u`:return Ug(u);case`uu`:return Ug(s);case`uuu`:return J(n);case`a`:return Vg(t.meridiems(),0);case`kkkk`:return J(a);case`kk`:return J(d,Hm);case`W`:return J(s);case`WW`:return J(r);case`E`:case`c`:return J(n);case`EEE`:return Vg(t.weekdays(`short`,!1),1);case`EEEE`:return Vg(t.weekdays(`long`,!1),1);case`ccc`:return Vg(t.weekdays(`short`,!0),1);case`cccc`:return Vg(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return Hg(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return Hg(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return Ug(/[a-z_+-/]{1,256}?/i);case` `:return Ug(/[^\S\n\r]/);default:return ee(te)}})(e)||{invalidReason:Ig};return te.token=e,te}var Kg={year:{"2-digit":`yy`,numeric:`yyyyy`},month:{numeric:`M`,"2-digit":`MM`,short:`MMM`,long:`MMMM`},day:{numeric:`d`,"2-digit":`dd`},weekday:{short:`EEE`,long:`EEEE`},dayperiod:`a`,dayPeriod:`a`,hour12:{numeric:`h`,"2-digit":`hh`},hour24:{numeric:`H`,"2-digit":`HH`},minute:{numeric:`m`,"2-digit":`mm`},second:{numeric:`s`,"2-digit":`ss`},timeZoneName:{long:`ZZZZZ`,short:`ZZZ`}};function qg(e,t,n){let{type:r,value:i}=e;if(r===`literal`){let e=/^\s+$/.test(i);return{literal:!e,val:e?` `:i}}let a=t[r],o=r;r===`hour`&&(o=t.hour12==null?t.hourCycle==null?n.hour12?`hour12`:`hour24`:t.hourCycle===`h11`||t.hourCycle===`h12`?`hour12`:`hour24`:t.hour12?`hour12`:`hour24`);let s=Kg[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function Jg(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function Yg(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Om(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 Xg(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 K(e.z)||(n=fp.create(e.z)),K(e.Z)||(n||=new Rp(e.Z),r=e.Z),K(e.q)||(e.M=(e.q-1)*3+1),K(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),K(e.u)||(e.S=Pm(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var Zg=null;function Qg(){return Zg||=Y.fromMillis(1555555555555),Zg}function $g(e,t){if(e.literal)return e;let n=i_(hh.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function e_(e,t){return Array.prototype.concat(...e.map(e=>$g(e,t)))}var t_=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=e_(hh.parseFormat(t),e),this.units=this.tokens.map(t=>Gg(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=Jg(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=Yg(e,this.regex,this.handlers),[r,i,a]=n?Xg(n):[null,null,void 0];if(Om(n,`a`)&&Om(n,`H`))throw new kf(`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 n_(e,t,n){return new t_(e,n).explainFromTokens(t)}function r_(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=n_(e,t,n);return[r,i,a,o]}function i_(e,t){if(!e)return null;let n=hh.create(t,e).dtFormatter(Qg()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>qg(t,e,i))}var a_=`Invalid DateTime`,o_=864e13;function s_(e){return new nm(`unsupported zone`,`the zone "${e.name}" is not supported`)}function c_(e){return e.weekData===null&&(e.weekData=um(e.c)),e.weekData}function l_(e){return e.localWeekData===null&&(e.localWeekData=um(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function u_(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new Y({...n,...t,old:n})}function d_(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 f_(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 p_(e,t,n){return d_(zm(e),t,n)}function m_(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,Rm(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Og.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]=d_(zm(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function h_(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=Y.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return Y.invalid(new nm(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function g_(e,t,n=!0){return e.isValid?hh.create(W.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function __(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=q(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=q(e.c.month),n===`month`)return i;i+=`-`}else if(i+=q(e.c.month),n===`month`)return i;return i+=q(e.c.day),i}function v_(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+=q(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=q(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=q(e.c.second))}else{if(c+=q(e.c.minute),o===`minute`)break;s&&(c+=q(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=q(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=q(Math.trunc(-e.o/60)),c+=`:`,c+=q(Math.trunc(-e.o%60))):(c+=`+`,c+=q(Math.trunc(e.o/60)),c+=`:`,c+=q(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var y_={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},b_={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},x_={ordinal:1,hour:0,minute:0,second:0,millisecond:0},S_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],C_=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],w_=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function T_(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 Af(e);return t}function E_(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return T_(e)}}function D_(e){if(j_===void 0&&(j_=G.now()),e.type!==`iana`)return e.offset(j_);let t=e.name,n=M_.get(t);return n===void 0&&(n=e.offset(j_),M_.set(t,n)),n}function O_(e,t){let n=Bp(t.zone,G.defaultZone);if(!n.isValid)return Y.invalid(s_(n));let r=W.fromObject(t),i,a;if(K(e.year))i=G.now();else{for(let t of S_)K(e[t])&&(e[t]=y_[t]);let t=_m(e)||vm(e);if(t)return Y.invalid(t);let r=D_(n);[i,a]=p_(e,r,n)}return new Y({ts:i,zone:n,loc:r,o:a})}function k_(e,t,n){let r=K(n.round)?!0:n.round,i=K(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Fm(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 A_(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 j_,M_=new Map,Y=class e{constructor(e){let t=e.zone||G.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new nm(`invalid input`):null)||(t.isValid?null:s_(t));this.ts=K(e.ts)?G.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=ym(e.o)&&!e.old?e.o:t.offset(this.ts);r=f_(this.ts,a),n=Number.isNaN(r.year)?new nm(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||W.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=A_(arguments),[n,r,i,a,o,s,c]=t;return O_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=A_(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Rp.utcInstance,O_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Sm(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Bp(n.zone,G.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:W.fromObject(n)}):e.invalid(s_(i))}static fromMillis(t,n={}){if(ym(t))return t<-o_||t>o_?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Bp(n.zone,G.defaultZone),loc:W.fromObject(n)});throw new jf(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(ym(t))return new e({ts:t*1e3,zone:Bp(n.zone,G.defaultZone),loc:W.fromObject(n)});throw new jf(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Bp(n.zone,G.defaultZone);if(!r.isValid)return e.invalid(s_(r));let i=W.fromObject(n),a=Km(t,E_),{minDaysInFirstWeek:o,startOfWeek:s}=mm(a,i),c=G.now(),l=K(n.specificOffset)?r.offset(c):n.specificOffset,u=!K(a.ordinal),d=!K(a.year),f=!K(a.month)||!K(a.day),ee=d||f,te=a.weekYear||a.weekNumber;if((ee||u)&&te)throw new kf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new kf(`Can't mix ordinal dates with month/day`);let ne=te||a.weekday&&!ee,re,ie,ae=f_(c,l);ne?(re=C_,ie=b_,ae=um(ae,o,s)):u?(re=w_,ie=x_,ae=fm(ae)):(re=S_,ie=y_);let oe=!1;for(let e of re){let t=a[e];K(t)?oe?a[e]=ie[e]:a[e]=ae[e]:oe=!0}let se=(ne?hm(a,o,s):u?gm(a):_m(a))||vm(a);if(se)return e.invalid(se);let[ce,le]=p_(ne?dm(a,o,s):u?pm(a):a,l,r),ue=new e({ts:ce,zone:r,o:le,loc:i});return a.weekday&&ee&&t.weekday!==ue.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${ue.toISO()}`):ue.isValid?ue:e.invalid(ue.invalid)}static fromISO(e,t={}){let[n,r]=og(e);return h_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=sg(e);return h_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=cg(e);return h_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(K(t)||K(n))throw new jf(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=r_(W.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):h_(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]=hg(e);return h_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new jf(`need to specify a reason the DateTime is invalid`);let r=t instanceof nm?t:new nm(t,n);if(G.throwOnInvalid)throw new Ef(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=i_(e,W.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return e_(hh.parseFormat(e),W.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){j_=void 0,M_.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?c_(this).weekYear:NaN}get weekNumber(){return this.isValid?c_(this).weekNumber:NaN}get weekday(){return this.isValid?c_(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?l_(this).weekday:NaN}get localWeekNumber(){return this.isValid?l_(this).weekNumber:NaN}get localWeekYear(){return this.isValid?l_(this).weekYear:NaN}get ordinal(){return this.isValid?fm(this.c).ordinal:NaN}get monthShort(){return this.isValid?Mg.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Mg.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Mg.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Mg.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=zm(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=f_(s,a),u=f_(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[u_(this,{ts:s}),u_(this,{ts:c})]:[this]}get isInLeapYear(){return Im(this.year)}get daysInMonth(){return Rm(this.year,this.month)}get daysInYear(){return this.isValid?Lm(this.year):NaN}get weeksInWeekYear(){return this.isValid?Vm(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?Vm(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=hh.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Rp.instance(e),t)}toLocal(){return this.setZone(G.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Bp(t,G.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]=p_(r,n,t)}return u_(this,{ts:e,zone:t})}else return e.invalid(s_(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return u_(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=Km(e,E_),{minDaysInFirstWeek:n,startOfWeek:r}=mm(t,this.loc),i=!K(t.weekYear)||!K(t.weekNumber)||!K(t.weekday),a=!K(t.ordinal),o=!K(t.year),s=!K(t.month)||!K(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new kf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new kf(`Can't mix ordinal dates with month/day`);let u;i?u=dm({...um(this.c,n,r),...t},n,r):K(t.ordinal)?(u={...this.toObject(),...t},K(t.day)&&(u.day=Math.min(Rm(u.year,u.month),u.day))):u=pm({...fm(this.c),...t});let[d,f]=p_(u,this.o,this.zone);return u_(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Og.fromDurationLike(e);return u_(this,m_(this,t))}minus(e){if(!this.isValid)return this;let t=Og.fromDurationLike(e).negate();return u_(this,m_(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Og.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?hh.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):a_}toLocaleString(e=Ff,t={}){return this.isValid?hh.create(this.loc.clone(t),e).formatDateTime(this):a_}toLocaleParts(e={}){return this.isValid?hh.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=T_(a);let o=e===`extended`,s=__(this,o,a);return S_.indexOf(a)>=3&&(s+=`T`),s+=v_(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?__(this,e===`extended`,T_(t)):null}toISOWeekDate(){return g_(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=T_(o),(r&&S_.indexOf(o)>=3?`T`:``)+v_(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return g_(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return g_(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?__(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`)),g_(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():a_}[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 Og.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Tm(t).map(Og.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Fg(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?jg.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),k_(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?k_(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 jf(`min requires all arguments be DateTimes`);return Em(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new jf(`max requires all arguments be DateTimes`);return Em(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return n_(W.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new t_(W.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(K(t)||K(n))throw new jf(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=W.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new jf(`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):h_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Ff}static get DATE_MED(){return If}static get DATE_MED_WITH_WEEKDAY(){return Lf}static get DATE_FULL(){return Rf}static get DATE_HUGE(){return zf}static get TIME_SIMPLE(){return Bf}static get TIME_WITH_SECONDS(){return Vf}static get TIME_WITH_SHORT_OFFSET(){return Hf}static get TIME_WITH_LONG_OFFSET(){return Uf}static get TIME_24_SIMPLE(){return Wf}static get TIME_24_WITH_SECONDS(){return Gf}static get TIME_24_WITH_SHORT_OFFSET(){return Kf}static get TIME_24_WITH_LONG_OFFSET(){return qf}static get DATETIME_SHORT(){return Jf}static get DATETIME_SHORT_WITH_SECONDS(){return Yf}static get DATETIME_MED(){return Xf}static get DATETIME_MED_WITH_SECONDS(){return Zf}static get DATETIME_MED_WITH_WEEKDAY(){return Qf}static get DATETIME_FULL(){return $f}static get DATETIME_FULL_WITH_SECONDS(){return ep}static get DATETIME_HUGE(){return tp}static get DATETIME_HUGE_WITH_SECONDS(){return np}};function N_(e){if(Y.isDateTime(e))return e;if(e&&e.valueOf&&ym(e.valueOf()))return Y.fromJSDate(e);if(e&&typeof e==`object`)return Y.fromObject(e);throw new jf(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function P_(e){return $u(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof gl}function F_(e){return L(e).unwrap_or(void 0)===``}function I_(e){return e instanceof ll}function L_(e){let t=zu(e);if(t!==null)return t;if(ju(e)&&e instanceof ol&&e.expression){let t=e.op?.value,n=zu(e.expression);if(n!==null)return t===`-`?-n:n}return null}function R_(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=L_(e);if(t!==null)return t;let n=L(e).unwrap_or(void 0);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function z_(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=L_(e);if(t!==null)return Number.isInteger(t)?t:null;let n=L(e).unwrap_or(void 0);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}const B_=[`true`,`yes`,`y`,`t`,`1`],V_=[`false`,`no`,`n`,`f`,`0`];function H_(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 B_.includes(t)?!0:V_.includes(t)?!1:null}if($u(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=zu(e);if(t===0)return!1;if(t===1)return!0;let n=L(e)?.unwrap_or(``).toLowerCase();if(n){if(B_.includes(n))return!0;if(V_.includes(n))return!1}return null}function U_(e){if(e==null)return null;if(typeof e==`string`)return e;let t=P(e).unwrap_or(void 0);return t?m(t):L(e).unwrap_or(null)}function W_(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=L(e).unwrap_or(null)??R_(e)??H_(e);return t===null?null:t.toString()}var G_=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],K_=[`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`],q_=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function J_(e){if(e==null)return null;let t=typeof e==`string`?e:L(e).unwrap_or(null);if(t===null)return null;for(let e of q_){let n=Y.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of G_){let n=Y.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of K_){let n=Y.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=Y.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 Y_(e,t,n){return t.map((t,r)=>{let i=e[t]?.value;if(i==null&&n&&n[r]){let e=n[r];if(e?.dbdefault)return JSON.stringify(e.dbdefault.value)}return JSON.stringify(i)}).join(`|`)}function X_(e,t,n){return t.some((t,r)=>{let i=e[t]?.value;return i==null&&n&&n[r]&&n[r]?.dbdefault?!1:i==null})}function Z_(e){return e.increment||bf(e.type.type_name)}function Q_(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function $_(e,t,n){return n.length===1?Q_(e,t,n[0]):`(${n.map(n=>Q_(e,t,n)).join(`, `)})`}function ev(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function tv(e,t,n){let r=t.map(t=>e.columnNodes[t]).filter(Boolean);return r.length>0?r.map(e=>new E(T.INVALID_RECORDS_FIELD,n,e)):[new E(T.INVALID_RECORDS_FIELD,n,e.node)]}var nv=e=>e>1?`Composite PK`:`PK`;function rv(e){return xc(Array.from(e.records),([t,n])=>{if(jc(n))return[];e.cachedMergedTables.has(t)||e.cachedMergedTables.set(t,qd(t,e));let r=e.cachedMergedTables.get(t),i=sv(r),a=cv(n),o=Nc(r.fields,`name`);return xc(i,e=>iv(e,n,a,o,r))})}function iv(e,t,n,r,i){let a=lv(e,n,r,i,t);if(!jc(a))return a;let o=ao(e.map(e=>r[e])),s=o.every(e=>e&&Z_(e)),[c,l]=h(t,t=>X_(t.values,e,o)),u=s?[]:av(c,e,i),d=ov(l,e,o,i);return[...u,...d]}function av(e,t,n){if(jc(e))return[];let r=`NULL in ${nv(t.length)}: ${$_(n.schemaName,n.name,t)} cannot be NULL`;return xc(e,e=>tv(e,t,r))}function ov(e,t,n,r){return xc(lc(Ec(e,e=>Y_(e.values,t,n)),e=>e.length>1),e=>{let n=nv(t.length),i=$_(r.schemaName,r.name,t);return xc(e.slice(1),e=>tv(e,t,`Duplicate ${n}: ${i} = ${ev(e.values,t)}`))})}function sv(e){return[...e.fields.filter(e=>e.pk).map(e=>[e.name]),...e.indexes.filter(e=>e.pk).map(e=>e.columns.map(e=>e.value))]}function cv(e){return new Set(e.flatMap(e=>Object.keys(e.values)))}function lv(e,t,n,r,i){let a=nc(e,Array.from(t));if(jc(a))return[];let o=a.filter(e=>{let t=n[e];return t&&!t.increment&&!bf(t.type.type_name)&&!t.dbdefault});if(jc(o))return[];let s=`${nv(o.length)}: Column ${$_(r.schemaName,r.name,o)} is missing from record and has no default value`;return i.map(e=>new E(T.INVALID_RECORDS_FIELD,s,e.node))}var uv=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function dv(e){return xc(Array.from(e.records),([t,n])=>{e.cachedMergedTables.has(t)||e.cachedMergedTables.set(t,qd(t,e));let r=e.cachedMergedTables.get(t);if(jc(n))return[];let i=fv(r),a=Nc(r.fields,`name`);return xc(i,e=>pv(n,e,ao(e.map(e=>a[e])),r))})}function fv(e){return[...e.fields.filter(e=>e.unique).map(e=>[e.name]),...e.indexes.filter(e=>e.unique).map(e=>e.columns.map(e=>e.value))]}function pv(e,t,n,r){return xc(lc(Ec(e.filter(e=>!X_(e.values,t,n)),e=>Y_(e.values,t,n)),e=>e.length>1),e=>{let n=uv(t.length),i=$_(r.schemaName,r.name,t);return xc(e.slice(1),e=>tv(e,t,`Duplicate ${n}: ${i} = ${ev(e.values,t)}`))})}function mv(e){let t=[...e.ref.values(),...xc(Array.from(e.tables.values()),t=>Jd(t,e))],n=hv(e);return xc(t,e=>vv(e,n))}function hv(e){let t=new Map;for(let n of e.tables.values()){let r=gv(n.schemaName,n.name),i=e.records.get(n)||[];e.cachedMergedTables.has(n)||e.cachedMergedTables.set(n,qd(n,e));let a=e.cachedMergedTables.get(n);t.set(r,{mergedTable:a,rows:i})}return t}function gv(e,t){return e?`${e}.${t}`:`${Wl}.${t}`}function _v(e,t,n,r){if(jc(e.rows))return[];let i=new Set(t.rows.map(e=>Y_(e.values,r.fieldNames)));return xc(e.rows.filter(e=>!X_(e.values,n.fieldNames)).filter(e=>{let t=Y_(e.values,n.fieldNames);return!i.has(t)}),i=>{let a=$_(e.mergedTable.schemaName,e.mergedTable.name,n.fieldNames),o=$_(t.mergedTable.schemaName,t.mergedTable.name,r.fieldNames),s=`FK violation: ${a} = ${ev(i.values,n.fieldNames)} does not exist in ${o}`;return tv(i,n.fieldNames,s)})}function vv(e,t){if(!e.endpoints)return[];let[n,r]=e.endpoints,i=t.get(gv(n.schemaName,n.tableName)),a=t.get(gv(r.schemaName,r.tableName));return!i||!a?[]:yv(i,a,n,r)}function yv(e,t,n,r){let i=n.relation,a=r.relation;return i===`1`&&a===`1`||i===`*`&&a===`*`?[..._v(e,t,n,r),..._v(t,e,r,n)]:i===`*`&&a===`1`?_v(e,t,n,r):i===`1`&&a===`*`?_v(t,e,r,n):[]}var bv=class{constructor(e){this.env=e,this.tableToRecordMap=new Map}interpret(e){let t=[],n=[];for(let r of e){let{table:e,mergedColumns:i}=xv(r,this.env),a=this.tableToRecordMap.get(e);if(a){t.push(new E(T.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${e.name}' - A Table can only have one Records block`,a)),t.push(new E(T.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${e.name}' - A Table can only have one Records block`,r));continue}this.tableToRecordMap.set(e,r);for(let a of r.body.body){let r=a,o=Sv(r,i,this.env);t.push(...o.getErrors()),n.push(...o.getWarnings());let s=o.getValue();s.row&&(this.env.records.has(e)||this.env.records.set(e,[]),this.env.records.get(e).push({values:s.row,node:r,columnNodes:s.columnNodes}))}}let r=this.validateConstraints();return n.push(...r),new D(void 0,t,n)}validateConstraints(){let e=[];return e.push(...rv(this.env).map(e=>e.toWarning())),e.push(...dv(this.env).map(e=>e.toWarning())),e.push(...mv(this.env).map(e=>e.toWarning())),e}};function xv(e,t){let n=e.name,r=e.parent;if(r instanceof b){let e=t.tables.get(r),i=qd(e,t);return n?{table:e,mergedTable:i,mergedColumns:n.elementList.map(e=>i.fields.find(t=>t.name===F(e).unwrap()))}:{table:e,mergedTable:i,mergedColumns:i.fields}}let i=Wu(n).unwrap(),a=m(i.variables).referee.declaration,o=t.tables.get(a),s=qd(o,t);return{table:o,mergedTable:s,mergedColumns:i.args.map(e=>s.fields.find(t=>t.name===F(e).unwrap()))}}function Sv(e,t,n){let r=[],i=[],a={},o={},s=e.callee instanceof dl?e.callee.elementList:[e.callee];if(s.length!==t.length)return r.push(new E(T.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new D({row:null,columnNodes:{}},r,i);for(let e=0;e<t.length;e++){let c=s[e],l=t[e];o[l.name]=c;let u=wv(c,l,n);r.push(...u.getErrors()),i.push(...u.getWarnings());let d=u.getValue();d!==null&&(a[l.name]=d)}return new D({row:a,columnNodes:o},r,i)}function Cv(e,t){return e instanceof ll?e.value?.value||``:!isNaN(e.start)&&!isNaN(e.end)?t.slice(e.start,e.end):``}function wv(e,t,n){let r=t.type.type_name.split(`(`)[0],{increment:i,not_null:a,dbdefault:o}=t,s=t.type.isEnum||!1,c=wf(r,s),l=W_(e),u=l===null?Cv(e,n.source):l,d=l===null?`expression`:c;if(e instanceof ll)return new D({value:e.value?.value||``,type:`expression`},[],[]);if(P_(e)||F_(e)&&!_f(r)){let n=o&&o.value.toString().toLowerCase()!==`null`,s=bf(r);return a&&!n&&!i&&!s?new D({value:null,type:c},[],[new Nl(T.INVALID_RECORDS_FIELD,`NULL not allowed for non-nullable column '${t.name}' without default and increment`,e)]):new D({value:null,type:c},[],[])}if(s){let r=([...n.enums.values()].find(e=>e.schemaName===t.type.schemaName&&e.name===t.type.type_name)?.values||[]).map(e=>e.name),i=L(e).unwrap_or(void 0);return i===void 0&&(i=P(e).unwrap_or([]).pop()),r.includes(i)?new D({value:i,type:c},[],[]):new D({value:i,type:c},[],[new Nl(T.INVALID_RECORDS_FIELD,`Invalid enum value for column '${t.name}'`,e)])}if(hf(r)){let n=R_(e);if(n===null)return new D({value:u,type:d},[],[new Nl(T.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${t.name}'`,e)]);if(pf(r)&&!Number.isInteger(n))return new D({value:Math.floor(n),type:c},[],[new Nl(T.INVALID_RECORDS_FIELD,`Invalid integer value ${n} for column '${t.name}': expected integer, got decimal`,e)]);if(mf(r)&&t.type.numericParams){let{precision:r,scale:i}=t.type.numericParams,a=n.toString().split(`.`),o=a[0].replace(/^-/,``),s=a[1]||``,l=o.length+s.length,u=s.length;if(l>r)return new D({value:n,type:c},[],[new Nl(T.INVALID_RECORDS_FIELD,`Numeric value ${n} for column '${t.name}' exceeds precision: expected at most ${r} total digits, got ${l}`,e)]);if(u>i)return new D({value:n,type:c},[],[new Nl(T.INVALID_RECORDS_FIELD,`Numeric value ${n} for column '${t.name}' exceeds scale: expected at most ${i} decimal digits, got ${u}`,e)])}return new D({value:n,type:c},[],[])}if(gf(r)){let n=H_(e);return n===null?new D({value:u,type:d},[],[new Nl(T.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${t.name}'`,e)]):new D({value:n,type:c},[],[])}if(yf(r)){let n=J_(e);return n===null?new D({value:u,type:d},[],[new Nl(T.INVALID_RECORDS_FIELD,`Invalid datetime value for column '${t.name}', expected valid datetime format (e.g., 'YYYY-MM-DD', 'HH:MM:SS', 'YYYY-MM-DD HH:MM:SS', 'MM/DD/YYYY', 'D MMM YYYY', or 'MMM D, YYYY')`,e)]):new D({value:n,type:c},[],[])}if(_f(r)){let n=W_(e);if(n===null)return new D({value:u,type:d},[],[new Nl(T.INVALID_RECORDS_FIELD,`Invalid string value for column '${t.name}'`,e)]);if(t.type.lengthParam){let{length:r}=t.type.lengthParam,i=new TextEncoder().encode(n).length;if(i>r)return new D({value:n,type:c},[],[new Nl(T.INVALID_RECORDS_FIELD,`String value for column '${t.name}' exceeds maximum length: expected at most ${r} bytes (UTF-8), got ${i} bytes`,e)])}return new D({value:n,type:`string`},[],[])}return new D({value:u,type:d},[],[])}function Tv(e){return{...e,fields:e.fields.map(e=>({...e,type:{...e.type,isEnum:void 0,lengthParam:void 0,numericParams:void 0}}))}}var Ev=new Set([`tableGroups`]);function Dv(e){if(e.diagramViews)for(let t of e.diagramViews.values()){let n=t.visibleEntities,r=t._explicitWildcards,i=t._explicitlySet;!r||!i||(Ev.has(`tables`)&&r.has(`tables`)&&n.tables&&n.tables.length===0&&(i.has(`tableGroups`)||i.has(`schemas`)||(n.tables=Array.from(e.tables.values()).map(e=>({name:e.name,schemaName:e.schemaName||`public`})))),Ev.has(`tableGroups`)&&r.has(`tableGroups`)&&n.tableGroups&&n.tableGroups.length===0&&(i.has(`tables`)||i.has(`schemas`)||(n.tableGroups=Array.from(e.tableGroups.values()).map(e=>({name:e.name})))),Ev.has(`stickyNotes`)&&r.has(`stickyNotes`)&&n.stickyNotes&&n.stickyNotes.length===0&&(n.stickyNotes=Array.from(e.notes.values()).map(e=>({name:e.name}))),Ev.has(`schemas`)&&r.has(`schemas`)&&n.schemas&&n.schemas.length===0&&(i.has(`tables`)||i.has(`tableGroups`)||(n.schemas=[...new Set(Array.from(e.tables.values()).map(e=>e.schemaName||`public`))].map(e=>({name:e})))),delete t._explicitWildcards,delete t._explicitlySet)}}function Ov(e){let t=[];for(let[n,r]of e.records){if(!r.length)continue;let e=Object.keys(r[0].columnNodes);t.push({schemaName:n.schemaName||void 0,tableName:n.name,columns:e,values:r.map(t=>e.map(e=>{let n=t.values[e];return n?{value:n.value,type:n.type}:{value:null,type:`expression`}}))})}return{schemas:[],tables:Array.from(e.tables.values()).map(Tv),notes:Array.from(e.notes.values()),refs:Array.from(e.ref.values()),enums:Array.from(e.enums.values()),tableGroups:Array.from(e.tableGroups.values()),aliases:e.aliases,project:Array.from(e.project.values())[0]||{},tablePartials:Array.from(e.tablePartials.values()).map(Tv),records:t,diagramViews:e.diagramViews?Array.from(e.diagramViews.values()):[]}}var kv=class{constructor(e){this.ast=e,this.env={schema:[],tables:new Map,notes:new Map,refIds:{},ref:new Map,enums:new Map,tableOwnerGroup:{},tableGroups:new Map,aliases:[],project:new Map,tablePartials:new Map,records:new Map,recordsElements:[],cachedMergedTables:new Map,source:e.source,diagramViews:new Map}}interpret(){let e=this.ast.body.flatMap(e=>{switch(Fu(e).unwrap_or(void 0)){case A.Table:return new Yd(e,this.env).interpret();case A.Note:return new Xd(e,this.env).interpret();case A.Ref:return new Zd(e,this.env).interpret();case A.TableGroup:return new Qd(e,this.env).interpret();case A.TablePartial:return new ef(e,this.env).interpret();case A.Enum:return new $d(e,this.env).interpret();case A.Project:return new tf(e,this.env).interpret();case A.DiagramView:return new rf(e,this.env).interpret();case A.Records:return this.env.recordsElements.push(e),[];default:return[]}}),t=[];if(this.env.recordsElements.length){let n=new bv(this.env).interpret(this.env.recordsElements);e.push(...n.getErrors()),t.push(...n.getWarnings())}return Dv(this.env),new D(Ov(this.env),e,t)}};let X=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}({}),Z=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),Av=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 jv(e){return e?e.split(``).every(e=>Pl(e)||Fl(e))&&!Fl(e[0]):!1}function Mv(e){return jv(e)?e:`"${Pv(e)}"`}function Nv(e){let t=``,n=0,r={n:`
|
|
12
|
+
`,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 Pv(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`
|
|
13
|
+
`: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 Fv(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`'${Pv(e)}'`;let{value:t,type:n}=e;if(t==null||gf(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(gf(n)){let e=H_(t);return e===null?`\`${t}\``:e?`true`:`false`}if(hf(n)){let e=R_(t);return e===null?`\`${t}\``:String(e)}if(yf(n)){let e=J_(t);return e===null?`\`${t}\``:`'${Pv(e)}'`}let r=W_(t);return r===null?`\`${t}\``:`'${Pv(r)}'`}function Iv(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?Nv(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function Lv(e){switch(e){case M.Schema:return X.Module;case M.Table:case M.TablePartial:return X.Class;case M.Column:case M.TableGroupField:return X.Field;case M.Enum:return X.Enum;case M.EnumField:return X.EnumMember;case M.TableGroup:return X.Struct;default:return X.Text}}function Rv(e,t){if(!e||$c(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===g.NEWLINE&&n.end<=t)return!1}return!0}function Q(){return{suggestions:[]}}function zv(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function Bv(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:Mv(e.insertText??``),quoted:!0}))}}function Vv(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:Z.KeepWhitespace,kind:X.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function Hv(e,t){return e<t.start||e>t.end?!1:t.body?e<t.body.start||e>t.body.end:!0}function Uv(e){return e.commaList.length+e.elementList.length===0}function Wv(e){let t=[];for(let[n,r]of e.symbolTable.entries()){let e=au(n).unwrap_or(void 0);if(e===void 0||e.kind!==M.Column||!(r instanceof wl||r instanceof Ml))continue;let i=Gv(r,e.name);i&&t.push(i)}return t}function Gv(e,t){let n=Jl(t),r=e instanceof Ml?e.tablePartialSymbol.symbolTable.get(n)?.declaration:e.declaration;if(!(r instanceof x))return null;let i=F(r.callee).unwrap_or(null),a=F(r.args[0]).unwrap_or(null);return i===null||a===null?null:{name:i,type:a}}function Kv(e,t,n,r){let i=e.container.element(r);return!(i instanceof b)||Fu(i).unwrap_or(void 0)!==A.Records||!(i.body instanceof S)||!i.body||!zl(r,i.body)||t.getLineContent(n.lineNumber).trim()!==``?null:i.parent instanceof y?qv(e,i):Jv(e,i)}function qv(e,t){if(!(t.name instanceof w))return Q();let n=t.name.argumentList?.elementList||[],r=n.map(e=>Bu(e));if(!r||r.length===0)return Q();let i=n.map((e,t)=>{let n=r[t];if(!n||!(n instanceof wl||n instanceof Ml))return null;let i=F(e).unwrap_or(void 0);return i?Gv(n,i):null}).filter(e=>e!==null);return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}function Jv(e,t){let n=t.parent;if(!(n instanceof b))return Q();let r=n.symbol;if(!(r instanceof Cl))return Q();let i;if(t.name instanceof ul){let e=t.name.elementList,n=e.map(e=>Bu(e)).filter(e=>e!==void 0);i=e.map((e,t)=>{let r=n[t];if(!r||!(r instanceof wl||r instanceof Ml))return null;let i=F(e).unwrap_or(void 0);return i===void 0?null:Gv(r,i)}).filter(e=>e!==null)}else{let e=Wv(r);if(!e)return Q();i=e}return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}function Yv(e,t){return e.getOffsetAt(t)}var Xv=class{constructor(e,t=[]){this.compiler=e,this.triggerCharacters=t}provideCompletionItems(e,t){let n=Yv(e,t),r=Kv(this.compiler,e,t,n);if(r!==null)return r;let i=this.compiler.token.flatStream(),{token:a,index:o}=this.compiler.container.token(n),s=o===void 0?i[0]:i[o+1];if([...a?.trailingTrivia||[],...a?.leadingTrivia||[],...s?.leadingTrivia||[]].find(e=>nl(e)&&zl(n,e)))return Q();if(o===void 0)return cy();if([g.STRING_LITERAL,g.QUOTED_STRING].includes(a.kind)&&zl(n,a))return Q();let c=this.compiler.container.element(n);if(this.compiler.container.scopeKind(n)===$.TOPLEVEL||c instanceof b&&c.type&&c.type.start<=n&&c.type.end>=n)return cy();let l=[...this.compiler.container.stack(n)].reverse();for(let e of l)if(e instanceof ol)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return Qv(this.compiler,n,e);case`~`:return Zv(this.compiler,n);default:}else if(e instanceof sl)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return Qv(this.compiler,n,e);case`.`:return oy(this.compiler,n,e);default:}else if(e instanceof al)return ry(this.compiler,n,e);else if(e instanceof C)return ry(this.compiler,n,e);else if(e instanceof ul)return ty(this.compiler,n,e);else if(e instanceof dl)return ny(this.compiler,n);else if(e instanceof w)return my(this.compiler,n,e);else if(e instanceof x)return sy(this.compiler,n,e);else if(e instanceof b){if(Hv(n,e))return py(this.compiler,n,e);if(e.bodyColon&&n>=e.bodyColon.end||e.body&&zl(n,e.body))return sy(this.compiler,n,void 0)}return Q()}};function Zv(e,t){return ey(e,t,e.parse.ast(),[M.TablePartial])}function Qv(e,t,n){let r=e.container.scopeKind(t);if([$.REF,$.TABLE,$.TABLEPARTIAL].includes(r)){let r=ey(e,t,e.container.element(t),[M.Table,M.Schema,M.Column]);return Rv(n.op,t)?zv(r):r}return Q()}function $v(e,t,n){return Bv({suggestions:e.symbol.members(t).filter(({kind:e})=>n.includes(e)).map(({name:e,kind:t})=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:Lv(t),sortText:Lv(t).toString().padStart(2,`0`),range:void 0}))})}function ey(e,t,n,r){if(n===void 0)return Q();let i=n,a={suggestions:[]};for(;i;){if(i?.symbol?.symbolTable){let{symbol:t}=i;a.suggestions.push(...$v(e,t,r).suggestions)}i=i instanceof b?i.parent:void 0}return Bv(a)}function ty(e,t,n){let r=e.container.scopeKind(t),i=e.container.element(t),a=[...e.container.stack(t)];for(let r of a)if(r instanceof w&&r.argumentList===n)return my(e,t,r);if(i instanceof b&&Fu(i).unwrap_or(void 0)===A.Records&&!(i.name instanceof w)&&Hv(t,i)){let t=i.parent?.symbol||i.name?.referee;if(t){let r=$v(e,t,[M.Column]);return Uv(n)?Vv(r):r}}switch(r){case $.INDEXES:return by(e,t);case $.REF:for(;a.length>0;){let n=a.pop();if(n instanceof sl&&n.op?.value===`.`)return oy(e,t,n)}return fy(e,t);default:break}return Q()}function ny(e,t){return e.container.scopeKind(t)===$.RECORDS?ey(e,t,e.container.element(t),[M.Schema,M.Enum,M.EnumField]):Q()}function ry(e,t,n){let{token:r}=e.container.token(t);if([g.COMMA,g.LBRACKET].includes(r?.kind)){let n=iy(e,t);return r?.kind===g.COMMA&&Rv(r,t)?zv(n):n}if(n.name&&n.name.start<=t&&n.name.end>=t)return iy(e,t);if(n.name instanceof il){let i=ay(e,t,nd(n.name).unwrap_or(``));return r?.kind===g.COLON&&Rv(r,t)?zv(i):i}return Q()}function iy(e,t){let n=e.container.element(t);if(n instanceof y)return Q();let r=e.container.scopeKind(t);if(n.body&&!zl(t,n.body)){let e;switch(r){case $.TABLE:case $.TABLEPARTIAL:e=[j.HeaderColor,j.Note];break;case $.TABLEGROUP:e=[j.Color,j.Note];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:X.Field,insertTextRules:Z.KeepWhitespace,range:void 0}))}}switch(r){case $.TABLE:case $.TABLEPARTIAL:return{suggestions:[...[j.PK,j.PrimaryKey,j.Null,j.NotNull,j.Increment,j.Unique].map(e=>({label:e,insertText:e,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0})),...[j.Ref,j.Default,j.Note,j.Check].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.ENUM:return{suggestions:[...[j.Note].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.INDEXES:return{suggestions:[...[j.Unique,j.PK].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Property,range:void 0})),...[j.Note,j.Name,j.Type].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.REF:return{suggestions:[j.Update,j.Delete,j.Color].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};case $.CHECKS:return{suggestions:[j.Name].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};default:break}return Q()}function ay(e,t,n){switch(n?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`default`:return ey(e,t,e.container.element(t),[M.Schema,M.Enum]);default:break}return Q()}function oy(e,t,n){let r=Iu(n).unwrap_or([]);if(r.pop(),r.some(e=>!B(e)))return Q();let i=r.map(e=>F(e).unwrap());return Bv({suggestions:e.symbol.ofName(i,e.container.element(t)).flatMap(({symbol:t})=>e.symbol.members(t)).map(({kind:e,name:t})=>({label:t,insertText:t,kind:Lv(e),range:void 0}))})}function sy(e,t,n){switch(e.container.scopeKind(t)){case $.TABLE:case $.TABLEPARTIAL:return uy(e,t,n);case $.PROJECT:return dy(e,t,n);case $.INDEXES:return vy(e,t);case $.ENUM:return ly(e,t,n);case $.REF:{let n=fy(e,t);return e.container.token(t).token?.kind===g.COLON&&Rv(e.container.token(t).token,t)?zv(n):n}case $.TABLEGROUP:return hy(e);case $.DIAGRAMVIEW:return gy();case $.CUSTOM:{let n=e.container.element(t);return n instanceof b&&n.parent instanceof b&&n.parent.type?.value.toLowerCase()===`diagramview`?_y(e,t):Q()}default:return Q()}}function cy(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`,`DiagramView`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}}function ly(e,t,n){return n?.callee&&xy(t,n)===1?ey(e,t,e.container.element(t),[M.Schema,M.Table,M.Column]):Q()}function uy(e,t,n){let r=[`Note`,`indexes`,`checks`,`Records`];if(!n?.callee)return{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))};let i=xy(t,n);return i===0?{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:i===1?yy(e,t):Q()}function dy(e,t,n){return!n?.callee||xy(t,n)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:Q()}function fy(e,t){return ey(e,t,e.container.element(t),[M.Schema,M.Table,M.Column])}function py(e,t,n){return Fu(n).unwrap_or(void 0)===A.Records?ey(e,t,n.parent,[M.Schema,M.Table]):Q()}function my(e,t,n){let r=e.container.element(t),i=n.callee&&zl(t,n.callee),a=n.argumentList&&zl(t,n.argumentList);if(r instanceof b&&Fu(r).unwrap_or(void 0)===A.Records&&Hv(t,r)){if(i)return ey(e,t,r.parent,[M.Schema,M.Table]);if(!a)return Q();let o=n.callee;if(!o)return Q();let s=Iu(o).unwrap_or([o]),c=s[s.length-1]?.referee;if(!c)return Q();let l=$v(e,c,[M.Column]),{argumentList:u}=n;return!u||!Uv(u)?l:Vv(l)}let o=[...e.container.stack(t)];for(let r of o){if(!a||!(r instanceof x)||r.callee!==n||F(n.callee).unwrap_or(``).toLowerCase()!==A.Records)continue;let i=e.container.element(t).symbol;if(!i)return Q();let o=$v(e,i,[M.Column]),{argumentList:s}=n;return!s||!Uv(s)?o:Vv(o)}return Q()}function hy(e){return{suggestions:[...Bv({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=au(e).unwrap_or(void 0);if(t===void 0)return[];let{kind:n,name:r}=t;return n!==M.Table&&n!==M.Schema?[]:{label:r,insertText:r,insertTextRules:Z.KeepWhitespace,kind:Lv(n),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))]}}function gy(){return{suggestions:[...[`Tables`,`TableGroups`,`Notes`,`Schemas`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0})),{label:`*`,insertText:`*`,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}]}}function _y(e,t){let n=e.container.element(t);if(!(n instanceof b))return Q();let r=n.type?.value.toLowerCase(),i={label:`*`,insertText:`*`,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0};switch(r){case`tables`:return{suggestions:[i,...Bv({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=au(e).unwrap_or(void 0);if(t===void 0)return[];let{kind:n,name:r}=t;return n!==M.Table&&n!==M.Schema?[]:{label:r,insertText:r,insertTextRules:Z.KeepWhitespace,kind:Lv(n),range:void 0}})}).suggestions]};case`tablegroups`:return{suggestions:[i,...Bv({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=au(e).unwrap_or(void 0);if(t===void 0)return[];let{kind:n,name:r}=t;return n===M.TableGroup?{label:r,insertText:r,insertTextRules:Z.KeepWhitespace,kind:Lv(n),range:void 0}:[]})}).suggestions]};case`schemas`:{let t=new Set,n=e.parse.ast();for(let e of n?.body||[])if(e instanceof b&&e.name instanceof sl&&e.name.op?.value===`.`){let n=Iu(e.name).unwrap_or([]);if(n.length>=2){let e=F(n[0]).unwrap_or(``);e&&t.add(e)}}return{suggestions:[i,...[...t].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Module,range:void 0}))]}}case`notes`:return{suggestions:[i]};default:return Q()}}function vy(e,t){return by(e,t)}function yy(e,t){return{suggestions:[...`integer.int.tinyint.smallint.mediumint.bigint.bit.bool.binary.varbinary.logical.char.nchar.varchar.varchar2.nvarchar.nvarchar2.binary_float.binary_double.float.double.decimal.dec.real.money.smallmoney.enum.tinyblob.tinytext.blob.text.mediumblob.mediumtext.longblob.longtext.ntext.set.inet6.uuid.image.date.time.datetime.datetime2.timestamp.year.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`).map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.TypeParameter,sortText:X.TypeParameter.toString().padStart(2,`0`),range:void 0})),...ey(e,t,e.container.element(t),[M.Enum,M.Schema]).suggestions]}}function by(e,t){let n=e.container.element(t)?.parent;if(!(n?.symbol instanceof Cl))return Q();let{symbolTable:r}=n.symbol;return Bv({suggestions:[...r.entries()].flatMap(([e])=>{let t=au(e).unwrap_or(void 0);if(t===void 0)return[];let{name:n}=t;return{label:n,insertText:n,insertTextRules:Z.KeepWhitespace,kind:Lv(M.Column),range:void 0}})})}function xy(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 Sy=class{constructor(e){this.compiler=e}provideDefinition(e,t){let{uri:n}=e,r=Yv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(!e?.referee)continue;let t;if(e.referee?.declaration&&[v.PRIMARY_EXPRESSION,v.VARIABLE].includes(e?.kind)&&({declaration:t}=e.referee),t){let{startPos:e,endPos:r}=t;return[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:r.column+1,endLineNumber:r.line+1},uri:n}]}}return[]}},Cy=class{constructor(e){this.compiler=e}provideReferences(e,t){let{uri:n}=e,r=Yv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(e&&[v.ELEMENT_DECLARATION,v.FUNCTION_APPLICATION,v.PRIMARY_EXPRESSION].includes(e?.kind)){let{symbol:t}=e;if(t?.references.length)return t.references.map(({startPos:e,endPos:t})=>({range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}))}}return[]}},wy=class{constructor(e){this.compiler=e}provideDiagnostics(){let e=[],t=this.compiler.parse._(),n=t.getErrors();for(let t of n)e.push(this.createDiagnostic(t,`error`));let r=t.getWarnings();for(let t of r)e.push(this.createDiagnostic(t,`warning`));return e}provideErrors(){return this.compiler.parse._().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(){return this.compiler.parse._().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideMarkers(){return this.provideDiagnostics().map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos;return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code}}getSeverityValue(e){return e===`error`?Av.Error:Av.Warning}},Ty={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`note`,`tablepartial`,`records`,`checks`,`diagramview`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`check`,`tables`,`tablegroups`,`notes`,`schemas`],symbols:/[=><!~?:&|+\-\/\^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}\[\]\(\)]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^\/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[\/*]/,`comment`]]}},Ey=t({CompletionItemInsertTextRule:()=>Z,CompletionItemKind:()=>X,DBMLCompletionItemProvider:()=>Xv,DBMLDefinitionProvider:()=>Sy,DBMLDiagnosticsProvider:()=>wy,DBMLReferencesProvider:()=>Cy,MarkerSeverity:()=>Av,dbmlMonarchTokensProvider:()=>Ty},1);function Dy(){return this.parse._().getValue().ast}function Oy(){return this.parse._().getErrors()}function ky(){return this.parse._().getWarnings()}function Ay(){return this.parse._().getValue().tokens}function jy(){return this.parse._().getValue().rawDb}function My(){return this.parse._().getValue().ast.symbol.symbolTable}function Ny(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function Py(){return this.parse.tokens().filter(Yu)}function Fy(e){return e.symbolTable?[...e.symbolTable.entries()].map(([e,t])=>({...au(e).unwrap(),symbol:t})):[]}function Iy(e,t){if(e.length===0)return[];let n=[];for(let r=t;r;r=r instanceof b?r.parent:void 0){if(!r.symbol?.symbolTable)continue;let{symbolTable:t}=r.symbol,i=[t],a=[];for(let t of e)a=i.flatMap(e=>Od(t).flatMap(t=>{let n=e.get(t),r=au(t).unwrap_or(void 0);return!n||!r?[]:{...r,symbol:n}})),i=a.flatMap(e=>e.symbol.symbolTable?e.symbol.symbolTable:[]);n.push(...a)}return n}function Ly(e,t){return`${e.join(`.`)}@${t.id}`}function Ry(e){let t=this.token.flatStream(),{index:n,token:r}=this.container.token(e),i=n===void 0?-1:pc(t,e=>!e.isInvalid,n);if(i===-1)return[this.parse.ast()];let a=t[i].start,o=this.parse.ast(),s=[o];for(;;){let e=Zu(o).find(e=>zl(a,e));if(e===void 0||e instanceof Xc)break;s.push(e),o=e}if(r?.kind===g.COLON)return s;for(;s.length>0;){let t=!1,n=m(s);if(n instanceof x){let r=this.parse.source();for(let i=n.end;i<e;i+=1)r[i]===`
|
|
14
|
+
`&&(s.pop(),t=!0)}else n instanceof ol||n instanceof sl?this.container.token(e).token!==n.op&&(s.pop(),t=!0):n instanceof C?n.listCloseBracket&&n.end<=e&&(s.pop(),t=!0):n instanceof ul?n.tupleCloseParen&&n.end<=e&&(s.pop(),t=!0):n instanceof dl?n.end<=e&&(s.pop(),t=!0):n instanceof S?n.blockCloseBrace&&n.end<=e&&(s.pop(),t=!0):n instanceof il||n.end<e&&(s.pop(),t=!0);if(t){let t=m(s);t instanceof b&&t.end<=e&&s.pop()}if(!t)break}return s}function zy(e){let t=this.token.flatStream().findIndex(t=>t.start>=e);return t===void 0||t<=0?{token:void 0,index:void 0}:{token:this.token.flatStream()[t-1],index:t-1}}function By(e){let t=this.container.stack(e);for(let e=t.length-1;e>=0;--e)if(t[e]instanceof b)return t[e];return this.parse.ast()}function Vy(e){return this.container.element(e)?.symbol?.symbolTable}let $=function(e){return e[e.TABLE=0]=`TABLE`,e[e.ENUM=1]=`ENUM`,e[e.TABLEGROUP=2]=`TABLEGROUP`,e[e.INDEXES=3]=`INDEXES`,e[e.NOTE=4]=`NOTE`,e[e.REF=5]=`REF`,e[e.PROJECT=6]=`PROJECT`,e[e.CUSTOM=7]=`CUSTOM`,e[e.TOPLEVEL=8]=`TOPLEVEL`,e[e.TABLEPARTIAL=9]=`TABLEPARTIAL`,e[e.CHECKS=10]=`CHECKS`,e[e.RECORDS=11]=`RECORDS`,e[e.DIAGRAMVIEW=12]=`DIAGRAMVIEW`,e}({});function Hy(e){let t=this.container.element(e);if(t instanceof y)return $.TOPLEVEL;switch(t.type?.value.toLowerCase()){case`table`:return $.TABLE;case`enum`:return $.ENUM;case`ref`:return $.REF;case`tablegroup`:return $.TABLEGROUP;case`indexes`:return $.INDEXES;case`note`:return $.NOTE;case`project`:return $.PROJECT;case`tablepartial`:return $.TABLEPARTIAL;case`checks`:return $.CHECKS;case`records`:return $.RECORDS;case`diagramview`:return $.DIAGRAMVIEW;default:return $.CUSTOM}}function Uy(e,t){let n=[...t].sort((e,t)=>t.start-e.start),r=e;for(let{start:e,end:t,newText:i}of n)r=r.substring(0,e)+i+r.substring(t);return r}function Wy(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=Iv(e);if(t.length===0)return{schema:Wl,table:``};if(t.length===1)return{schema:Wl,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 Gy(e,t,n){let r=ql(n);if(t===`public`){let t=e.get(r);return t instanceof Cl?t:null}let i=Kl(t),a=e.get(i);if(!a||!a.symbolTable)return null;let o=a.symbolTable.get(r);return o instanceof Cl?o:null}function Ky(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function qy(e){return e?e.split(``).every(e=>Pl(e)||Fl(e))&&!Fl(e[0]):!1}function Jy(e,t){if(!e.declaration)return!1;let n=e.declaration;if(!n.name)return!1;let r=n.name;return t.substring(r.start,r.end).includes(`"`)}function Yy(e,t,n){let r=!qy(t),i=!qy(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 Xy(e,t,n,r,i){let a=ql(i),o;if(r===`public`)o=e.get(a);else{let t=Kl(r),n=e.get(t);if(!n||!n.symbolTable)return!1;o=n.symbolTable.get(a)}return!(!o||t===r&&n===i)}function Zy(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 Ky(n.substring(i,a))===t?{start:i,end:e.end}:null}function Qy(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=Zy(o,t,r)??{start:o.start,end:o.end},s=`${e.start}-${e.end}`;if(a.has(s))continue;a.add(s);let c=n.schema===`public`?n.formattedTable:`${n.formattedSchema}.${n.formattedTable}`;i.push({start:e.start,end:e.end,newText:c})}return i}function $y(e,t){let n=this.parse.source(),r=this.parse.publicSymbolTable(),i=Wy(e),a=Wy(t),o=i.schema,s=i.table,c=a.schema,l=a.table,u=Gy(r,o,s);if(!u||Xy(r,o,s,c,l))return n;let d=Yy(c,l,Jy(u,n)),f=[];if(u.declaration){let e=u.declaration;e.name&&f.push(e.name)}for(let e of u.references)n.substring(e.start,e.end).replace(/"/g,``)===s&&f.push(e);return Uy(n,Qy(f,o,d,n))}var eb=class{constructor(){this.source=``,this.cache=new Map,this.nodeIdGenerator=new rl,this.symbolIdGenerator=new yl,this.token={invalidStream:this.query(Py),flatStream:this.query(Ny)},this.parse={source:()=>this.source,_:this.query(this.interpret),ast:this.query(Dy),errors:this.query(Oy),warnings:this.query(ky),tokens:this.query(Ay),rawDb:this.query(jy),publicSymbolTable:this.query(My)},this.container={stack:this.query(Ry),token:this.query(zy),element:this.query(By),scope:this.query(Vy),scopeKind:this.query(Hy)},this.symbol={ofName:this.query(Iy,Ly),members:this.query(Fy)}}setSource(e){this.source=e,this.cache.clear(),this.nodeIdGenerator.reset(),this.symbolIdGenerator.reset()}query(e,t){let n=Symbol();return((...r)=>{if(r.length===0){if(this.cache.has(n))return this.cache.get(n);let t=e.apply(this,r);return this.cache.set(n,t),t}let i=t?t(...r):r[0],a=this.cache.get(n);if(a instanceof Map&&a.has(i))return a.get(i);let o=e.apply(this,r);return a instanceof Map||(a=new Map,this.cache.set(n,a)),a.set(i,o),o})}interpret(){let e=new id(this.source).lex().chain(e=>new cd(this.source,e,this.nodeIdGenerator).parse()).chain(({ast:e,tokens:t})=>new Id(e,this.symbolIdGenerator).analyze().map(()=>({ast:e,tokens:t})));return e.getErrors().length>0?e:e.chain(({ast:e,tokens:t})=>new kv(e).interpret().map(n=>({ast:e,tokens:t,rawDb:n})))}renameTable(e,t){return $y.call(this,e,t)}applyTextEdits(e){return Uy(this.parse.source(),e)}initMonacoServices(){return{definitionProvider:new Sy(this),referenceProvider:new Cy(this),autocompletionProvider:new Xv(this),diagnosticsProvider:new wy(this)}}};function tb(e){let t=[],n=new id(e).lex();if(n.getErrors().length>0)return t;let r=new cd(e,n.getValue(),new rl).parse();if(r.getErrors().length>0)return t;let i=r.getValue().ast;for(let e of i.body)if(e.type?.value===`DiagramView`){let n=e.name?P(e.name).unwrap_or([]):[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function nb(e){return!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function rb(e){return nb(e)?`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`:e}function ib(e,t){let n=[`DiagramView ${rb(e)} {`];if(t?.tables!==void 0&&t.tables!==null)if(t.tables.length===0)n.push(` Tables { * }`);else{let e=t.tables.map(e=>e.schemaName===`public`?e.name:`${e.schemaName}.${e.name}`);n.push(` Tables {`),e.forEach(e=>n.push(` ${e}`)),n.push(` }`)}return t?.stickyNotes!==void 0&&(t.stickyNotes===null||(t.stickyNotes.length===0?n.push(` Notes { * }`):(n.push(` Notes {`),t.stickyNotes.forEach(e=>n.push(` ${e.name}`)),n.push(` }`)))),t?.tableGroups!==void 0&&(t.tableGroups===null||(t.tableGroups.length===0?n.push(` TableGroups { * }`):(n.push(` TableGroups {`),t.tableGroups.forEach(e=>n.push(` ${e.name}`)),n.push(` }`)))),t?.schemas!==void 0&&(t.schemas===null||(t.schemas.length===0?n.push(` Schemas { * }`):(n.push(` Schemas {`),t.schemas.forEach(e=>n.push(` ${e.name}`)),n.push(` }`)))),n.push(`}`),n.join(`
|
|
15
|
+
`)}function ab(e,t){let n=e;for(let e of t)n=ob(n,e);return{newDbml:n}}function ob(e,t){switch(t.operation){case`create`:return sb(e,t);case`update`:return cb(e,t,tb(e));case`delete`:return lb(e,t,tb(e));default:return e}}function sb(e,t){let n=tb(e);if(n.find(e=>e.name===t.name))return cb(e,t,n);let r=ib(t.name,t.visibleEntities);return e.trimEnd()+`
|
|
16
|
+
|
|
17
|
+
`+r+`
|
|
18
|
+
`}function cb(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return e;let i=[];if(t.newName||t.visibleEntities){let e=ib(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return Uy(e,i)}function lb(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return e;let i=e.split(`
|
|
19
|
+
`),a=0,o=i.length-1,s=0;for(let e=0;e<i.length;e++){let t=s,n=s+i[e].length;t<=r.startIndex&&r.startIndex<=n&&(a=e),t<=r.endIndex&&r.endIndex<=n&&(o=e),s=n+1}return[...i.slice(0,a),...i.slice(o+1)].join(`
|
|
20
|
+
`)}exports.CompileError=E,exports.CompileErrorCode=T,exports.Compiler=eb,exports.ElementDeclarationNode=b,exports.ElementKind=A,exports.FALSY_VALUES=V_,exports.ProgramNode=y,exports.ScopeKind=$,exports.SyntaxNode=_,exports.SyntaxNodeKind=v,exports.SyntaxToken=Xc,exports.SyntaxTokenKind=g,exports.TRUTHY_VALUES=B_,exports.addDoubleQuoteIfNeeded=Mv,exports.dbmlMonarchTokensProvider=Ty,exports.escapeString=Pv,exports.extractNumericLiteral=zu,exports.extractSignedNumber=L_,exports.formatRecordValue=Fv,exports.getLengthTypeParam=Cf,exports.getNumericTypeParams=Sf,exports.getRecordValueType=wf,exports.isBinaryType=vf,exports.isBooleanType=gf,exports.isDateTimeType=yf,exports.isEmptyStringLiteral=F_,exports.isFloatType=mf,exports.isFunctionExpression=I_,exports.isIntegerType=pf,exports.isNullish=P_,exports.isNumericType=hf,exports.isSerialType=bf,exports.isStringType=_f,exports.isValidIdentifier=jv,exports.normalizeTypeName=ff,Object.defineProperty(exports,`services`,{enumerable:!0,get:function(){return Ey}}),exports.splitQualifiedIdentifier=Iv,exports.syncDiagramView=ab,exports.tryExtractBoolean=H_,exports.tryExtractDateTime=J_,exports.tryExtractEnum=U_,exports.tryExtractInteger=z_,exports.tryExtractNumeric=R_,exports.tryExtractString=W_,exports.unescapeString=Nv,exports.validateForeignKeys=mv,exports.validatePrimaryKey=rv,exports.validateUnique=dv;
|