@dbml/parse 4.0.0 → 5.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/dist/dbml-parse.js +8 -8
- package/dist/dbml-parse.mjs +632 -602
- package/dist/src/compiler.d.ts +1 -1
- package/dist/src/lib/analyzer/binder/elementBinder/{constraints.d.ts → checks.d.ts} +1 -1
- package/dist/src/lib/analyzer/binder/elementBinder/table.d.ts +1 -1
- package/dist/src/lib/analyzer/binder/elementBinder/tablePartial.d.ts +3 -0
- package/dist/src/lib/analyzer/binder/utils.d.ts +2 -1
- package/dist/src/lib/analyzer/types.d.ts +2 -2
- package/dist/src/lib/analyzer/validator/elementValidators/{constraints.d.ts → checks.d.ts} +2 -2
- package/dist/src/lib/analyzer/validator/elementValidators/custom.d.ts +1 -1
- package/dist/src/lib/analyzer/validator/elementValidators/enum.d.ts +1 -1
- package/dist/src/lib/analyzer/validator/elementValidators/indexes.d.ts +1 -1
- package/dist/src/lib/analyzer/validator/elementValidators/project.d.ts +1 -1
- package/dist/src/lib/analyzer/validator/elementValidators/ref.d.ts +1 -1
- package/dist/src/lib/analyzer/validator/utils.d.ts +2 -2
- package/dist/src/lib/errors.d.ts +6 -6
- package/dist/src/lib/interpreter/elementInterpreter/table.d.ts +1 -1
- package/dist/src/lib/interpreter/elementInterpreter/tablePartial.d.ts +1 -1
- package/dist/src/lib/interpreter/types.d.ts +4 -4
- package/package.json +2 -2
package/dist/dbml-parse.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Wn=typeof global=="object"&&global&&global.Object===Object&&global,zs=typeof self=="object"&&self&&self.Object===Object&&self,_e=Wn||zs||Function("return this")(),Ne=_e.Symbol,Hn=Object.prototype,Ys=Hn.hasOwnProperty,qs=Hn.toString,ze=Ne?Ne.toStringTag:void 0;function Ks(e){var t=Ys.call(e,ze),n=e[ze];try{e[ze]=void 0;var s=!0}catch{}var r=qs.call(e);return s&&(t?e[ze]=n:delete e[ze]),r}var Qs=Object.prototype,Js=Qs.toString;function Zs(e){return Js.call(e)}var er="[object Null]",tr="[object Undefined]",sn=Ne?Ne.toStringTag:void 0;function Xe(e){return e==null?e===void 0?tr:er:sn&&sn in Object(e)?Ks(e):Zs(e)}function xe(e){return e!=null&&typeof e=="object"}var nr="[object Symbol]";function dt(e){return typeof e=="symbol"||xe(e)&&Xe(e)==nr}function zn(e,t){for(var n=-1,s=e==null?0:e.length,r=Array(s);++n<s;)r[n]=t(e[n],n,e);return r}var pe=Array.isArray,rn=Ne?Ne.prototype:void 0,an=rn?rn.toString:void 0;function Yn(e){if(typeof e=="string")return e;if(pe(e))return zn(e,Yn)+"";if(dt(e))return an?an.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}var sr=/\s/;function rr(e){for(var t=e.length;t--&&sr.test(e.charAt(t)););return t}var ir=/^\s+/;function ar(e){return e&&e.slice(0,rr(e)+1).replace(ir,"")}function Ge(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var on=NaN,or=/^[-+]0x[0-9a-f]+$/i,lr=/^0b[01]+$/i,cr=/^0o[0-7]+$/i,ur=parseInt;function hr(e){if(typeof e=="number")return e;if(dt(e))return on;if(Ge(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Ge(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=ar(e);var n=lr.test(e);return n||cr.test(e)?ur(e.slice(2),n?2:8):or.test(e)?on:+e}var ln=1/0,fr=17976931348623157e292;function pr(e){if(!e)return e===0?e:0;if(e=hr(e),e===ln||e===-ln){var t=e<0?-1:1;return t*fr}return e===e?e:0}function dr(e){var t=pr(e),n=t%1;return t===t?n?t-n:t:0}function Et(e){return e}var Er="[object AsyncFunction]",Nr="[object Function]",Tr="[object GeneratorFunction]",br="[object Proxy]";function qn(e){if(!Ge(e))return!1;var t=Xe(e);return t==Nr||t==Tr||t==Er||t==br}var yt=_e["__core-js_shared__"],cn=function(){var e=/[^.]+$/.exec(yt&&yt.keys&&yt.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function mr(e){return!!cn&&cn in e}var Ir=Function.prototype,_r=Ir.toString;function Me(e){if(e!=null){try{return _r.call(e)}catch{}try{return e+""}catch{}}return""}var gr=/[\\^$.*+?()[\]{}|]/g,Ar=/^\[object .+?Constructor\]$/,Lr=Function.prototype,vr=Object.prototype,yr=Lr.toString,wr=vr.hasOwnProperty,Sr=RegExp("^"+yr.call(wr).replace(gr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Pr(e){if(!Ge(e)||mr(e))return!1;var t=qn(e)?Sr:Ar;return t.test(Me(e))}function Or(e,t){return e==null?void 0:e[t]}function Fe(e,t){var n=Or(e,t);return Pr(n)?n:void 0}var Pt=Fe(_e,"WeakMap");function xr(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 Dr=800,Rr=16,kr=Date.now;function Ur(e){var t=0,n=0;return function(){var s=kr(),r=Rr-(s-n);if(n=s,r>0){if(++t>=Dr)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function Mr(e){return function(){return e}}var un=function(){try{var e=Fe(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Fr=un?function(e,t){return un(e,"toString",{configurable:!0,enumerable:!1,value:Mr(t),writable:!0})}:Et,Br=Ur(Fr);function Vr(e,t,n,s){e.length;for(var r=n+1;r--;)if(t(e[r],r,e))return r;return-1}var Cr=9007199254740991,Gr=/^(?:0|[1-9]\d*)$/;function Kn(e,t){var n=typeof e;return t=t??Cr,!!t&&(n=="number"||n!="symbol"&&Gr.test(e))&&e>-1&&e%1==0&&e<t}function Qn(e,t){return e===t||e!==e&&t!==t}var hn=Math.max;function $r(e,t,n){return t=hn(t===void 0?e.length-1:t,0),function(){for(var s=arguments,r=-1,i=hn(s.length-t,0),a=Array(i);++r<i;)a[r]=s[t+r];r=-1;for(var o=Array(t+1);++r<t;)o[r]=s[r];return o[t]=n(a),xr(e,this,o)}}function Xr(e,t){return Br($r(e,t,Et),e+"")}var jr=9007199254740991;function Bt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=jr}function Nt(e){return e!=null&&Bt(e.length)&&!qn(e)}var Wr=Object.prototype;function Jn(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||Wr;return e===n}function Zn(e,t){for(var n=-1,s=Array(e);++n<e;)s[n]=t(n);return s}var Hr="[object Arguments]";function fn(e){return xe(e)&&Xe(e)==Hr}var es=Object.prototype,zr=es.hasOwnProperty,Yr=es.propertyIsEnumerable,Vt=fn(function(){return arguments}())?fn:function(e){return xe(e)&&zr.call(e,"callee")&&!Yr.call(e,"callee")};function qr(){return!1}var ts=typeof exports=="object"&&exports&&!exports.nodeType&&exports,pn=ts&&typeof module=="object"&&module&&!module.nodeType&&module,Kr=pn&&pn.exports===ts,dn=Kr?_e.Buffer:void 0,Qr=dn?dn.isBuffer:void 0,Ot=Qr||qr,Jr="[object Arguments]",Zr="[object Array]",ei="[object Boolean]",ti="[object Date]",ni="[object Error]",si="[object Function]",ri="[object Map]",ii="[object Number]",ai="[object Object]",oi="[object RegExp]",li="[object Set]",ci="[object String]",ui="[object WeakMap]",hi="[object ArrayBuffer]",fi="[object DataView]",pi="[object Float32Array]",di="[object Float64Array]",Ei="[object Int8Array]",Ni="[object Int16Array]",Ti="[object Int32Array]",bi="[object Uint8Array]",mi="[object Uint8ClampedArray]",Ii="[object Uint16Array]",_i="[object Uint32Array]",O={};O[pi]=O[di]=O[Ei]=O[Ni]=O[Ti]=O[bi]=O[mi]=O[Ii]=O[_i]=!0;O[Jr]=O[Zr]=O[hi]=O[ei]=O[fi]=O[ti]=O[ni]=O[si]=O[ri]=O[ii]=O[ai]=O[oi]=O[li]=O[ci]=O[ui]=!1;function gi(e){return xe(e)&&Bt(e.length)&&!!O[Xe(e)]}function Ai(e){return function(t){return e(t)}}var ns=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ye=ns&&typeof module=="object"&&module&&!module.nodeType&&module,Li=Ye&&Ye.exports===ns,wt=Li&&Wn.process,En=function(){try{var e=Ye&&Ye.require&&Ye.require("util").types;return e||wt&&wt.binding&&wt.binding("util")}catch{}}(),Nn=En&&En.isTypedArray,ss=Nn?Ai(Nn):gi,vi=Object.prototype,yi=vi.hasOwnProperty;function rs(e,t){var n=pe(e),s=!n&&Vt(e),r=!n&&!s&&Ot(e),i=!n&&!s&&!r&&ss(e),a=n||s||r||i,o=a?Zn(e.length,String):[],u=o.length;for(var p in e)(t||yi.call(e,p))&&!(a&&(p=="length"||r&&(p=="offset"||p=="parent")||i&&(p=="buffer"||p=="byteLength"||p=="byteOffset")||Kn(p,u)))&&o.push(p);return o}function wi(e,t){return function(n){return e(t(n))}}var Si=wi(Object.keys,Object),Pi=Object.prototype,Oi=Pi.hasOwnProperty;function xi(e){if(!Jn(e))return Si(e);var t=[];for(var n in Object(e))Oi.call(e,n)&&n!="constructor"&&t.push(n);return t}function Ct(e){return Nt(e)?rs(e):xi(e)}function Di(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Ri=Object.prototype,ki=Ri.hasOwnProperty;function Ui(e){if(!Ge(e))return Di(e);var t=Jn(e),n=[];for(var s in e)s=="constructor"&&(t||!ki.call(e,s))||n.push(s);return n}function Mi(e){return Nt(e)?rs(e,!0):Ui(e)}var Fi=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Bi=/^\w*$/;function Gt(e,t){if(pe(e))return!1;var n=typeof e;return n=="number"||n=="symbol"||n=="boolean"||e==null||dt(e)?!0:Bi.test(e)||!Fi.test(e)||t!=null&&e in Object(t)}var Ke=Fe(Object,"create");function Vi(){this.__data__=Ke?Ke(null):{},this.size=0}function Ci(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Gi="__lodash_hash_undefined__",$i=Object.prototype,Xi=$i.hasOwnProperty;function ji(e){var t=this.__data__;if(Ke){var n=t[e];return n===Gi?void 0:n}return Xi.call(t,e)?t[e]:void 0}var Wi=Object.prototype,Hi=Wi.hasOwnProperty;function zi(e){var t=this.__data__;return Ke?t[e]!==void 0:Hi.call(t,e)}var Yi="__lodash_hash_undefined__";function qi(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Ke&&t===void 0?Yi:t,this}function De(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}De.prototype.clear=Vi;De.prototype.delete=Ci;De.prototype.get=ji;De.prototype.has=zi;De.prototype.set=qi;function Ki(){this.__data__=[],this.size=0}function Tt(e,t){for(var n=e.length;n--;)if(Qn(e[n][0],t))return n;return-1}var Qi=Array.prototype,Ji=Qi.splice;function Zi(e){var t=this.__data__,n=Tt(t,e);if(n<0)return!1;var s=t.length-1;return n==s?t.pop():Ji.call(t,n,1),--this.size,!0}function ea(e){var t=this.__data__,n=Tt(t,e);return n<0?void 0:t[n][1]}function ta(e){return Tt(this.__data__,e)>-1}function na(e,t){var n=this.__data__,s=Tt(n,e);return s<0?(++this.size,n.push([e,t])):n[s][1]=t,this}function ge(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}ge.prototype.clear=Ki;ge.prototype.delete=Zi;ge.prototype.get=ea;ge.prototype.has=ta;ge.prototype.set=na;var Qe=Fe(_e,"Map");function sa(){this.size=0,this.__data__={hash:new De,map:new(Qe||ge),string:new De}}function ra(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function bt(e,t){var n=e.__data__;return ra(t)?n[typeof t=="string"?"string":"hash"]:n.map}function ia(e){var t=bt(this,e).delete(e);return this.size-=t?1:0,t}function aa(e){return bt(this,e).get(e)}function oa(e){return bt(this,e).has(e)}function la(e,t){var n=bt(this,e),s=n.size;return n.set(e,t),this.size+=n.size==s?0:1,this}function Ae(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}Ae.prototype.clear=sa;Ae.prototype.delete=ia;Ae.prototype.get=aa;Ae.prototype.has=oa;Ae.prototype.set=la;var ca="Expected a function";function $t(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(ca);var n=function(){var s=arguments,r=t?t.apply(this,s):s[0],i=n.cache;if(i.has(r))return i.get(r);var a=e.apply(this,s);return n.cache=i.set(r,a)||i,a};return n.cache=new($t.Cache||Ae),n}$t.Cache=Ae;var ua=500;function ha(e){var t=$t(e,function(s){return n.size===ua&&n.clear(),s}),n=t.cache;return t}var fa=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,pa=/\\(\\)?/g,da=ha(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(fa,function(n,s,r,i){t.push(r?i.replace(pa,"$1"):s||n)}),t});function Ea(e){return e==null?"":Yn(e)}function is(e,t){return pe(e)?e:Gt(e,t)?[e]:da(Ea(e))}function mt(e){if(typeof e=="string"||dt(e))return e;var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function as(e,t){t=is(t,e);for(var n=0,s=t.length;e!=null&&n<s;)e=e[mt(t[n++])];return n&&n==s?e:void 0}function os(e,t,n){var s=e==null?void 0:as(e,t);return s===void 0?n:s}function ls(e,t){for(var n=-1,s=t.length,r=e.length;++n<s;)e[r+n]=t[n];return e}var Tn=Ne?Ne.isConcatSpreadable:void 0;function Na(e){return pe(e)||Vt(e)||!!(Tn&&e&&e[Tn])}function Ta(e,t,n,s,r){var i=-1,a=e.length;for(n||(n=Na),r||(r=[]);++i<a;){var o=e[i];n(o)?ls(r,o):r[r.length]=o}return r}function bn(e){var t=e==null?0:e.length;return t?Ta(e):[]}function ba(){this.__data__=new ge,this.size=0}function ma(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Ia(e){return this.__data__.get(e)}function _a(e){return this.__data__.has(e)}var ga=200;function Aa(e,t){var n=this.__data__;if(n instanceof ge){var s=n.__data__;if(!Qe||s.length<ga-1)return s.push([e,t]),this.size=++n.size,this;n=this.__data__=new Ae(s)}return n.set(e,t),this.size=n.size,this}function Ie(e){var t=this.__data__=new ge(e);this.size=t.size}Ie.prototype.clear=ba;Ie.prototype.delete=ma;Ie.prototype.get=Ia;Ie.prototype.has=_a;Ie.prototype.set=Aa;function cs(e,t){for(var n=-1,s=e==null?0:e.length,r=0,i=[];++n<s;){var a=e[n];t(a,n,e)&&(i[r++]=a)}return i}function La(){return[]}var va=Object.prototype,ya=va.propertyIsEnumerable,mn=Object.getOwnPropertySymbols,wa=mn?function(e){return e==null?[]:(e=Object(e),cs(mn(e),function(t){return ya.call(e,t)}))}:La;function Sa(e,t,n){var s=t(e);return pe(e)?s:ls(s,n(e))}function In(e){return Sa(e,Ct,wa)}var xt=Fe(_e,"DataView"),Dt=Fe(_e,"Promise"),Rt=Fe(_e,"Set"),_n="[object Map]",Pa="[object Object]",gn="[object Promise]",An="[object Set]",Ln="[object WeakMap]",vn="[object DataView]",Oa=Me(xt),xa=Me(Qe),Da=Me(Dt),Ra=Me(Rt),ka=Me(Pt),we=Xe;(xt&&we(new xt(new ArrayBuffer(1)))!=vn||Qe&&we(new Qe)!=_n||Dt&&we(Dt.resolve())!=gn||Rt&&we(new Rt)!=An||Pt&&we(new Pt)!=Ln)&&(we=function(e){var t=Xe(e),n=t==Pa?e.constructor:void 0,s=n?Me(n):"";if(s)switch(s){case Oa:return vn;case xa:return _n;case Da:return gn;case Ra:return An;case ka:return Ln}return t});var yn=_e.Uint8Array,Ua="__lodash_hash_undefined__";function Ma(e){return this.__data__.set(e,Ua),this}function Fa(e){return this.__data__.has(e)}function ot(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Ae;++t<n;)this.add(e[t])}ot.prototype.add=ot.prototype.push=Ma;ot.prototype.has=Fa;function Ba(e,t){for(var n=-1,s=e==null?0:e.length;++n<s;)if(t(e[n],n,e))return!0;return!1}function Va(e,t){return e.has(t)}var Ca=1,Ga=2;function us(e,t,n,s,r,i){var a=n&Ca,o=e.length,u=t.length;if(o!=u&&!(a&&u>o))return!1;var p=i.get(e),h=i.get(t);if(p&&h)return p==t&&h==e;var d=-1,N=!0,b=n&Ga?new ot:void 0;for(i.set(e,t),i.set(t,e);++d<o;){var A=e[d],m=t[d];if(s)var v=a?s(m,A,d,t,e,i):s(A,m,d,e,t,i);if(v!==void 0){if(v)continue;N=!1;break}if(b){if(!Ba(t,function(H,z){if(!Va(b,z)&&(A===H||r(A,H,n,s,i)))return b.push(z)})){N=!1;break}}else if(!(A===m||r(A,m,n,s,i))){N=!1;break}}return i.delete(e),i.delete(t),N}function $a(e){var t=-1,n=Array(e.size);return e.forEach(function(s,r){n[++t]=[r,s]}),n}function Xa(e){var t=-1,n=Array(e.size);return e.forEach(function(s){n[++t]=s}),n}var ja=1,Wa=2,Ha="[object Boolean]",za="[object Date]",Ya="[object Error]",qa="[object Map]",Ka="[object Number]",Qa="[object RegExp]",Ja="[object Set]",Za="[object String]",eo="[object Symbol]",to="[object ArrayBuffer]",no="[object DataView]",wn=Ne?Ne.prototype:void 0,St=wn?wn.valueOf:void 0;function so(e,t,n,s,r,i,a){switch(n){case no:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case to:return!(e.byteLength!=t.byteLength||!i(new yn(e),new yn(t)));case Ha:case za:case Ka:return Qn(+e,+t);case Ya:return e.name==t.name&&e.message==t.message;case Qa:case Za:return e==t+"";case qa:var o=$a;case Ja:var u=s&ja;if(o||(o=Xa),e.size!=t.size&&!u)return!1;var p=a.get(e);if(p)return p==t;s|=Wa,a.set(e,t);var h=us(o(e),o(t),s,r,i,a);return a.delete(e),h;case eo:if(St)return St.call(e)==St.call(t)}return!1}var ro=1,io=Object.prototype,ao=io.hasOwnProperty;function oo(e,t,n,s,r,i){var a=n&ro,o=In(e),u=o.length,p=In(t),h=p.length;if(u!=h&&!a)return!1;for(var d=u;d--;){var N=o[d];if(!(a?N in t:ao.call(t,N)))return!1}var b=i.get(e),A=i.get(t);if(b&&A)return b==t&&A==e;var m=!0;i.set(e,t),i.set(t,e);for(var v=a;++d<u;){N=o[d];var H=e[N],z=t[N];if(s)var w=a?s(z,H,N,t,e,i):s(H,z,N,e,t,i);if(!(w===void 0?H===z||r(H,z,n,s,i):w)){m=!1;break}v||(v=N=="constructor")}if(m&&!v){var ee=e.constructor,G=t.constructor;ee!=G&&"constructor"in e&&"constructor"in t&&!(typeof ee=="function"&&ee instanceof ee&&typeof G=="function"&&G instanceof G)&&(m=!1)}return i.delete(e),i.delete(t),m}var lo=1,Sn="[object Arguments]",Pn="[object Array]",st="[object Object]",co=Object.prototype,On=co.hasOwnProperty;function uo(e,t,n,s,r,i){var a=pe(e),o=pe(t),u=a?Pn:we(e),p=o?Pn:we(t);u=u==Sn?st:u,p=p==Sn?st:p;var h=u==st,d=p==st,N=u==p;if(N&&Ot(e)){if(!Ot(t))return!1;a=!0,h=!1}if(N&&!h)return i||(i=new Ie),a||ss(e)?us(e,t,n,s,r,i):so(e,t,u,n,s,r,i);if(!(n&lo)){var b=h&&On.call(e,"__wrapped__"),A=d&&On.call(t,"__wrapped__");if(b||A){var m=b?e.value():e,v=A?t.value():t;return i||(i=new Ie),r(m,v,n,s,i)}}return N?(i||(i=new Ie),oo(e,t,n,s,r,i)):!1}function Xt(e,t,n,s,r){return e===t?!0:e==null||t==null||!xe(e)&&!xe(t)?e!==e&&t!==t:uo(e,t,n,s,Xt,r)}var ho=1,fo=2;function po(e,t,n,s){var r=n.length,i=r;if(e==null)return!i;for(e=Object(e);r--;){var a=n[r];if(a[2]?a[1]!==e[a[0]]:!(a[0]in e))return!1}for(;++r<i;){a=n[r];var o=a[0],u=e[o],p=a[1];if(a[2]){if(u===void 0&&!(o in e))return!1}else{var h=new Ie,d;if(!(d===void 0?Xt(p,u,ho|fo,s,h):d))return!1}}return!0}function hs(e){return e===e&&!Ge(e)}function Eo(e){for(var t=Ct(e),n=t.length;n--;){var s=t[n],r=e[s];t[n]=[s,r,hs(r)]}return t}function fs(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function No(e){var t=Eo(e);return t.length==1&&t[0][2]?fs(t[0][0],t[0][1]):function(n){return n===e||po(n,e,t)}}function To(e,t){return e!=null&&t in Object(e)}function bo(e,t,n){t=is(t,e);for(var s=-1,r=t.length,i=!1;++s<r;){var a=mt(t[s]);if(!(i=e!=null&&n(e,a)))break;e=e[a]}return i||++s!=r?i:(r=e==null?0:e.length,!!r&&Bt(r)&&Kn(a,r)&&(pe(e)||Vt(e)))}function mo(e,t){return e!=null&&bo(e,t,To)}var Io=1,_o=2;function go(e,t){return Gt(e)&&hs(t)?fs(mt(e),t):function(n){var s=os(n,e);return s===void 0&&s===t?mo(n,e):Xt(t,s,Io|_o)}}function ps(e){return function(t){return t==null?void 0:t[e]}}function Ao(e){return function(t){return as(t,e)}}function Lo(e){return Gt(e)?ps(mt(e)):Ao(e)}function ds(e){return typeof e=="function"?e:e==null?Et:typeof e=="object"?pe(e)?go(e[0],e[1]):No(e):Lo(e)}function vo(e,t,n,s){for(var r=-1,i=e==null?0:e.length;++r<i;){var a=e[r];t(s,a,n(a),e)}return s}function yo(e){return function(t,n,s){for(var r=-1,i=Object(t),a=s(t),o=a.length;o--;){var u=a[++r];if(n(i[u],u,i)===!1)break}return t}}var Es=yo();function wo(e,t){return e&&Es(e,t,Ct)}function So(e,t){return function(n,s){if(n==null)return n;if(!Nt(n))return e(n,s);for(var r=n.length,i=-1,a=Object(n);++i<r&&s(a[i],i,a)!==!1;);return n}}var Po=So(wo);function Oo(e,t,n,s){return Po(e,function(r,i,a){t(s,r,n(r),a)}),s}function xo(e,t){return function(n,s){var r=pe(n)?vo:Oo,i=t?t():{};return r(n,e,ds(s),i)}}function Do(e){return xe(e)&&Nt(e)}function F(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function Ro(e){return typeof e=="function"?e:Et}var ko=Math.max,Uo=Math.min;function Mo(e,t,n){var s=e==null?0:e.length;if(!s)return-1;var r=s-1;return n!==void 0&&(r=dr(n),r=n<0?ko(s+r,0):Uo(r,s-1)),Vr(e,ds(t),r)}function Fo(e){return e&&e.length?e[0]:void 0}function Je(e,t){return e==null?e:Es(e,Ro(t),Mi)}var oe=xo(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),Bo=Math.max;function Vo(e){if(!(e&&e.length))return[];var t=0;return e=cs(e,function(n){if(Do(n))return t=Bo(n.length,t),!0}),Zn(t,function(n){return zn(e,ps(n))})}var kt=Xr(Vo),f=(e=>(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.TILDE="<tilde>",e.SINGLE_LINE_COMMENT="<single-line-comment>",e.MULTILINE_COMMENT="<multiline-comment>",e))(f||{});function Co(e){switch(e.kind){case"<newline>":case"<space>":case"<tab>":case"<single-line-comment>":case"<multiline-comment>":return!0;default:return!1}}function Go(e){if(!e)return!1;switch(e){case"+":case"-":case"*":case"/":case"%":case"<":case">":case"=":case"!":case".":case"&":case"|":return!0;default:return!1}}function xn(e){return e!==void 0&&e.kind==="<op>"}class K{constructor(t,n,s,r,i){this.kind=t,this.startPos=n,this.endPos=s,this.value=r,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=i,this.start=n.offset,this.end=s.offset}static create(t,n,s,r,i){return new K(t,n,s,r,i)}}function Ns(e){return e.trailingTrivia.find(({kind:t})=>t===f.NEWLINE)!==void 0}function Dn(e,t){return t.leadingTrivia.find(({kind:s})=>s===f.NEWLINE)!==void 0||Ns(e)}function Ut(e){return e.trailingTrivia.find(({kind:t})=>[f.SPACE,f.TAB].includes(t))!==void 0}function Ts(e){return e.trailingTrivia.length===0?e.end:Ts(F(e.trailingTrivia))}function bs(e){return e.leadingTrivia.length===0?e.start:bs(e.leadingTrivia[0])}function $o(e){return[f.SINGLE_LINE_COMMENT,f.MULTILINE_COMMENT].includes(e.kind)}class Xo{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}}class R{constructor(t,n,s){this.id=t,this.kind=n;const r=s.find(a=>a!==void 0&&!Number.isNaN(a.start));r?(this.startPos=r.startPos,this.fullStart=r instanceof K?bs(r):r.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);const i=[...s].reverse().find(a=>a!==void 0&&!Number.isNaN(a.end));i?(this.endPos=i.endPos,this.fullEnd=i instanceof K?Ts(i):i.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}}var Se=(e=>(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.DUMMY="<dummy>",e.ARRAY="<array>",e.PARTIAL_INJECTION="<partial-injection>",e))(Se||{});class J extends R{constructor({body:t=[],eof:n},s){super(s,"<program>",[...t,n]),this.body=t,this.eof=n}}class S extends R{constructor({type:t,name:n,as:s,alias:r,attributeList:i,bodyColon:a,body:o},u){if(super(u,"<element-declaration>",[t,n,s,r,i,a,o]),o&&a&&!(o instanceof y||o instanceof S))throw new Error("If an element has a simple body, it must be a function application node");this.type=t,this.name=n,this.as=s,this.alias=r,this.attributeList=i,this.bodyColon=a,this.body=o}}class ce extends R{constructor({identifiers:t=[]},n){super(n,"<identifer-stream>",t||[]),this.identifiers=t}}class ue extends R{constructor({name:t,colon:n,value:s},r){super(r,"<attribute>",[t,n,s]),this.name=t,this.value=s,this.colon=n}}class re extends R{constructor({op:t,expression:n},s){super(s,"<prefix-expression>",[t,n]),this.op=t,this.expression=n}}class Te extends R{constructor({op:t,leftExpression:n,rightExpression:s},r){super(r,"<infix-expression>",[n,t,s]),this.op=t,this.leftExpression=n,this.rightExpression=s}}class It extends R{constructor({op:t,expression:n},s){super(s,"<postfix-expression>",[n,t]),this.op=t,this.expression=n}}class ie extends R{constructor({value:t},n){super(n,"<function-expression>",[t]),this.value=t}}class y extends R{constructor({callee:t,args:n=[]},s){super(s,"<function-application>",[t,...n]),this.callee=t,this.args=n}}class Ee extends R{constructor({blockOpenBrace:t,body:n=[],blockCloseBrace:s},r){super(r,"<block-expression>",[t,...n,s]),this.blockOpenBrace=t,this.body=n,this.blockCloseBrace=s}}class Re extends R{constructor({op:t,partial:n},s){super(s,"<partial-injection>",[t,n]),this.partial=n}}class U extends R{constructor({listOpenBracket:t,elementList:n=[],commaList:s=[],listCloseBracket:r},i){super(i,"<list-expression>",[t,...ms(n,s),r]),this.listOpenBracket=t,this.elementList=n,this.commaList=s,this.listCloseBracket=r}}class be extends R{constructor({tupleOpenParen:t,elementList:n=[],commaList:s=[],tupleCloseParen:r},i){super(i,"<tuple-expression>",[t,...ms(n,s),r]),this.tupleOpenParen=t,this.elementList=n,this.commaList=s,this.tupleCloseParen=r}}class jt extends be{constructor({groupOpenParen:t,expression:n,groupCloseParen:s},r){super({tupleOpenParen:t,elementList:n&&[n],commaList:[],tupleCloseParen:s},r),this.kind="<group-expression>"}}class ae extends R{constructor({callee:t,argumentList:n},s){super(s,"<call-expression>",[t,n]),this.callee=t,this.argumentList=n}}class je extends R{constructor({literal:t},n){super(n,"<literal>",[t]),this.literal=t}}class de extends R{constructor({variable:t},n){super(n,"<variable>",[t]),this.variable=t}}class Y extends R{constructor({expression:t},n){super(n,"<primary-expression>",[t]),this.expression=t}}class rt extends R{constructor({pre:t},n){const s=K.create(f.SPACE,t.endPos,t.endPos," ",!1);super(n,"<dummy>",[s])}}class ke extends R{constructor({expression:t,indexer:n},s){super(s,"<array>",[t,n]),this.array=t,this.indexer=n}}function ms(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];const[n]=e,[s]=t;return(n.start<s.start?bn(kt(e,t)):bn(kt(t,e))).filter(r=>r!==null)}function jo(e,t=!1){return JSON.stringify(e,function(n,s){var r;return!(this instanceof J)&&n==="symbol"?s==null?void 0:s.id:n==="symbol"?{symbolTable:s==null?void 0:s.symbolTable,id:s==null?void 0:s.id,references:s==null?void 0:s.references.map(i=>i.id),declaration:(r=s==null?void 0:s.declaration)==null?void 0:r.id}:n==="referee"||n==="parent"||n==="declaration"?s==null?void 0:s.id:n==="symbolTable"?Object.fromEntries(s.table):s},t?2:0)}class V{constructor(t){this.value=t}unwrap(){return this.value}unwrap_or(t){return this.value}and_then(t){return t(this.value)}map(t){return new V(t(this.value))}isOk(){return!0}}class x{constructor(){this.value=void 0}unwrap(){throw new Error("Trying to unwrap a None value")}unwrap_or(t){return t}and_then(t){return new x}map(t){return new x}isOk(){return!1}}var I=(e=>(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.TablePartialInjection="TablePartialInjection",e))(I||{});function Wt(e){return`Schema:${e}`}function lt(e){return`Table:${e}`}function _t(e){return`Column:${e}`}function Ht(e){return`Enum:${e}`}function zt(e){return`Enum field:${e}`}function Yt(e){return`TableGroup:${e}`}function qt(e){return`TableGroup field:${e}`}function Wo(e){return`Note:${e}`}function Kt(e){return`TablePartial:${e}`}function Is(e){return`TablePartialInjection:${e}`}function it(e,t){switch(t){case"Column":return _t(e);case"Enum":return Ht(e);case"Enum field":return zt(e);case"Schema":return Wt(e);case"Table":return lt(e);case"TableGroup":return Yt(e);case"TableGroup field":return qt(e);case"TablePartial":return Kt(e);default:throw new Error("Unreachable")}}function he(e){const[t,n]=e.split(":");return Object.values(I).includes(t)?new V({name:n,kind:t}):new x}function Ho(e){const t=he(e).unwrap_or(void 0);if(!t)return!1;const{kind:n,name:s}=t;return n==="Schema"&&s==="public"}function zo(e){const t=he(e).unwrap_or(void 0);if(!t)return!1;const{kind:n}=t;return n==="TablePartialInjection"}function Yo(e){const t=he(e).unwrap_or(void 0);if(!t)return null;const{kind:n,name:s}=t;return n==="TablePartialInjection"?it(s,"TablePartial"):null}class qo{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}}class _s{constructor({symbolTable:t},n){this.references=[],this.id=n,this.symbolTable=t}}class Ko{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Qo{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class gs{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Qt{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class Jo{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Zo{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class el{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class tl{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class nl{constructor({injectorFieldSymbol:t,injectorDeclaration:n},s){this.references=[],this.id=s,this.injectorDeclaration=n,this.injectorFieldSymbol=t}}function sl(e){return[Wt,lt,Ht,Yt,_t,zt,qt,Kt,Is].map(t=>t(e))}function rl(e){return e instanceof Qt?nl:null}function gt(e){return!!e.match(new RegExp("(\\p{L}|_|\\p{M})","gu"))}function ct(e){const[t]=e;return t>="0"&&t<="9"}function il(e){const[t]=e;return ct(t)||gt(t)&&t.toLowerCase()>="a"&&t.toLowerCase()<="f"}function Ce(e){return gt(e)||ct(e)}function Rn(e,t){const n=[],s=Math.min(e.length,t.length);for(let r=0;r<s;r+=1)n.push(e[r],t[r]);return n.push(...e.slice(s),...t.slice(s)),n}function qe(e,t){return e>=t.start&&e<t.end}function As(e){var t;return e instanceof re?`${(t=e.op)==null?void 0:t.value}${As(e.expression)}`:e.expression.literal.value}function Mt(e){var t;return e instanceof re?((t=e.op)==null?void 0:t.value)==="-"?-Mt(e.expression):Mt(e.expression):Number.parseFloat(e.expression.literal.value)}var l=(e=>(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_CONSTRAINTS_CONTEXT=3071]="INVALID_CONSTRAINTS_CONTEXT",e[e.INVALID_CONSTRAINTS_FIELD=3072]="INVALID_CONSTRAINTS_FIELD",e[e.INVALID_CONSTRAINT=3073]="INVALID_CONSTRAINT",e[e.UNKNOWN_CONSTRAINT_SETTING=3074]="UNKNOWN_CONSTRAINT_SETTING",e[e.DUPLICATE_CONSTRAINT_SETTING=3075]="DUPLICATE_CONSTRAINT_SETTING",e[e.INVALID_CONSTRAINT_SETTING_VALUE=3076]="INVALID_CONSTRAINT_SETTING_VALUE",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))(l||{});class c extends Error{constructor(t,n,s){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=s,this.start=s.start,this.end=s.end,this.name=this.constructor.name,Object.setPrototypeOf(this,c.prototype)}}class se{constructor(t,n){this.value=t,this.errors=n===void 0?[]:n}getValue(){return this.value}getErrors(){return this.errors}chain(t){const n=t(this.value),s=[...this.errors,...n.errors];return new se(n.value,s)}map(t){return new se(t(this.value),this.errors)}}function al(e,t,n){if(!e||!Pe(e)||t.length===0)return new x;const s=[...t],r=kn(e).unwrap(),i=s.pop();if(!(i instanceof Ee))return new x;const a=F(s)instanceof U?s.pop():void 0;if(s.length===3){const o=kn(s[1]).value;return!o||!Ft(o)?new x:new V(n.create(S,{type:r,name:s[0],as:o,alias:s[2],attributeList:a,body:i}))}return s.length===1?new V(n.create(S,{type:r,name:s[0],attributeList:a,body:i})):s.length===0?new V(n.create(S,{type:r,attributeList:a,body:i})):new x}function Ft(e){return e.kind===f.IDENTIFIER&&e.value==="as"}function g(e){e&&(e instanceof K?ol(e):ll(e))}function ol(e){e.kind!==f.EOF&&(e.isInvalid=!0)}function ll(e){if(e instanceof S)g(e.type),g(e.name),g(e.as),g(e.alias),g(e.bodyColon),g(e.attributeList),g(e.body);else if(e instanceof ce)e.identifiers.forEach(g);else if(e instanceof ue)g(e.name),g(e.colon),g(e.value);else if(e instanceof re)g(e.op),g(e.expression);else if(e instanceof Te)g(e.leftExpression),g(e.op),g(e.rightExpression);else if(e instanceof It)g(e.op),g(e.expression);else if(e instanceof Ee)g(e.blockOpenBrace),e.body.forEach(g),g(e.blockCloseBrace);else if(e instanceof U)g(e.listOpenBracket),e.commaList.forEach(g),e.elementList.forEach(g),g(e.listCloseBracket);else if(e instanceof be)g(e.tupleOpenParen),e.commaList.forEach(g),e.elementList.forEach(g),g(e.tupleCloseParen);else if(e instanceof ae)g(e.callee),g(e.argumentList);else if(e instanceof y)g(e.callee),e.args.forEach(g);else if(e instanceof Y)g(e.expression);else if(e instanceof ie)g(e.value);else if(e instanceof de)g(e.variable);else if(e instanceof je)g(e.literal);else throw e instanceof jt?new Error("This case is handled by the TupleExpressionNode case"):new Error("Unreachable case in markInvalidNode")}function Ls(e){return!!(e!=null&&e.isInvalid)}function X(...e){return e.filter(t=>t!==void 0)}function cl(e){if(e instanceof J)return X(...e.body,e.eof);if(e instanceof S)return X(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof ue)return X(e.name,e.colon,e.value);if(e instanceof ce)return e.identifiers;if(e instanceof je)return e.literal?[e.literal]:[];if(e instanceof de)return X(e.variable);if(e instanceof re)return X(e.op,e.expression);if(e instanceof Te)return X(e.leftExpression,e.op,e.rightExpression);if(e instanceof It)return X(e.expression,e.op);if(e instanceof ie)return X(e.value);if(e instanceof y)return X(e.callee,...e.args);if(e instanceof Ee)return X(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof U)return X(e.listOpenBracket,...Rn(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof be)return X(e.tupleOpenParen,...Rn(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof ae)return X(e.callee,e.argumentList);if(e instanceof Y)return X(e.expression);if(e instanceof ke)return X(e.array,e.indexer);if(e instanceof Re)return X(e.partial);throw e instanceof jt?new Error("This case is already handled by TupleExpressionNode"):new Error("Unreachable - no other possible cases")}function kn(e){return W(e)?new V(e.expression.variable):new x}function q(e){var t;return e instanceof Y&&(e.expression instanceof de&&e.expression.variable instanceof K&&e.expression.variable.kind===f.QUOTED_STRING||e.expression instanceof je&&((t=e.expression.literal)==null?void 0:t.kind)===f.STRING_LITERAL)}function W(e){return e instanceof Y&&e.expression instanceof de&&e.expression.variable instanceof K}function Pe(e){var t;return e instanceof Y&&e.expression instanceof de&&((t=e.expression.variable)==null?void 0:t.kind)===f.IDENTIFIER}function Jt(e){var t;return e instanceof Te&&e.leftExpression instanceof R&&e.rightExpression instanceof R&&((t=e.op)==null?void 0:t.value)==="."}function $e(e){if(e===void 0)return new x;const t=e.identifiers.map(n=>n.value).join(" ");return t===""?new x:new V(t)}class ul{constructor(t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){const t=this.peek();return this.current={...this.current},t===`
|
|
2
|
-
`?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,t}peek(t=0){if(!(this.current.offset+t>=this.text.length))return this.text[this.current.offset+t]}check(t){for(let n=0;n<t.length;n+=1)if(t[n]!==this.peek(n))return!1;return!0}match(t){return this.check(t)?(t.split("").forEach(()=>this.advance()),!0):!1}addToken(t,n=!1){this.tokens.push(this.createToken(t,n))}createToken(t,n=!1){return
|
|
3
|
-
`:this.addToken(f.NEWLINE);break;case" ":this.addToken(f.TAB);break;case",":this.addToken(f.COMMA);break;case"(":this.addToken(f.LPAREN);break;case")":this.addToken(f.RPAREN);break;case"[":this.addToken(f.LBRACKET);break;case"]":this.addToken(f.RBRACKET);break;case"{":this.addToken(f.LBRACE);break;case"}":this.addToken(f.RBRACE);break;case";":this.addToken(f.SEMICOLON);break;case":":this.addToken(f.COLON);break;case"~":this.addToken(f.TILDE);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(t);break;default:if(Go(t)){this.operator(t);break}if(gt(t)){this.identifier();break}if(ct(t)){this.numericLiteralOrIdentifier();break}this.addToken(f.OP,!0),this.errors.push(new c(l.UNKNOWN_SYMBOL,`Unexpected token '${t}'`,this.createToken(f.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let t=!0,n=[],s;const r=[];for(const i of this.tokens)
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Wn=typeof global=="object"&&global&&global.Object===Object&&global,Ks=typeof self=="object"&&self&&self.Object===Object&&self,ge=Wn||Ks||Function("return this")(),Ne=ge.Symbol,Hn=Object.prototype,zs=Hn.hasOwnProperty,Ys=Hn.toString,Ke=Ne?Ne.toStringTag:void 0;function qs(e){var t=zs.call(e,Ke),n=e[Ke];try{e[Ke]=void 0;var s=!0}catch{}var r=Ys.call(e);return s&&(t?e[Ke]=n:delete e[Ke]),r}var Qs=Object.prototype,Js=Qs.toString;function Zs(e){return Js.call(e)}var er="[object Null]",tr="[object Undefined]",sn=Ne?Ne.toStringTag:void 0;function Xe(e){return e==null?e===void 0?tr:er:sn&&sn in Object(e)?qs(e):Zs(e)}function xe(e){return e!=null&&typeof e=="object"}var nr="[object Symbol]";function dt(e){return typeof e=="symbol"||xe(e)&&Xe(e)==nr}function Kn(e,t){for(var n=-1,s=e==null?0:e.length,r=Array(s);++n<s;)r[n]=t(e[n],n,e);return r}var pe=Array.isArray,rn=Ne?Ne.prototype:void 0,an=rn?rn.toString:void 0;function zn(e){if(typeof e=="string")return e;if(pe(e))return Kn(e,zn)+"";if(dt(e))return an?an.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}var sr=/\s/;function rr(e){for(var t=e.length;t--&&sr.test(e.charAt(t)););return t}var ir=/^\s+/;function ar(e){return e&&e.slice(0,rr(e)+1).replace(ir,"")}function Ge(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var on=NaN,or=/^[-+]0x[0-9a-f]+$/i,lr=/^0b[01]+$/i,cr=/^0o[0-7]+$/i,ur=parseInt;function hr(e){if(typeof e=="number")return e;if(dt(e))return on;if(Ge(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Ge(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=ar(e);var n=lr.test(e);return n||cr.test(e)?ur(e.slice(2),n?2:8):or.test(e)?on:+e}var ln=1/0,fr=17976931348623157e292;function pr(e){if(!e)return e===0?e:0;if(e=hr(e),e===ln||e===-ln){var t=e<0?-1:1;return t*fr}return e===e?e:0}function dr(e){var t=pr(e),n=t%1;return t===t?n?t-n:t:0}function Et(e){return e}var Er="[object AsyncFunction]",Nr="[object Function]",Tr="[object GeneratorFunction]",br="[object Proxy]";function Yn(e){if(!Ge(e))return!1;var t=Xe(e);return t==Nr||t==Tr||t==Er||t==br}var yt=ge["__core-js_shared__"],cn=function(){var e=/[^.]+$/.exec(yt&&yt.keys&&yt.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function mr(e){return!!cn&&cn in e}var Ir=Function.prototype,_r=Ir.toString;function Me(e){if(e!=null){try{return _r.call(e)}catch{}try{return e+""}catch{}}return""}var gr=/[\\^$.*+?()[\]{}|]/g,Ar=/^\[object .+?Constructor\]$/,Lr=Function.prototype,vr=Object.prototype,yr=Lr.toString,wr=vr.hasOwnProperty,Sr=RegExp("^"+yr.call(wr).replace(gr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Pr(e){if(!Ge(e)||mr(e))return!1;var t=Yn(e)?Sr:Ar;return t.test(Me(e))}function Or(e,t){return e==null?void 0:e[t]}function Fe(e,t){var n=Or(e,t);return Pr(n)?n:void 0}var Pt=Fe(ge,"WeakMap");function xr(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 Dr=800,kr=16,Rr=Date.now;function Ur(e){var t=0,n=0;return function(){var s=Rr(),r=kr-(s-n);if(n=s,r>0){if(++t>=Dr)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function Mr(e){return function(){return e}}var un=function(){try{var e=Fe(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Fr=un?function(e,t){return un(e,"toString",{configurable:!0,enumerable:!1,value:Mr(t),writable:!0})}:Et,Br=Ur(Fr);function Cr(e,t,n,s){e.length;for(var r=n+1;r--;)if(t(e[r],r,e))return r;return-1}var Vr=9007199254740991,Gr=/^(?:0|[1-9]\d*)$/;function qn(e,t){var n=typeof e;return t=t??Vr,!!t&&(n=="number"||n!="symbol"&&Gr.test(e))&&e>-1&&e%1==0&&e<t}function Qn(e,t){return e===t||e!==e&&t!==t}var hn=Math.max;function $r(e,t,n){return t=hn(t===void 0?e.length-1:t,0),function(){for(var s=arguments,r=-1,i=hn(s.length-t,0),a=Array(i);++r<i;)a[r]=s[t+r];r=-1;for(var o=Array(t+1);++r<t;)o[r]=s[r];return o[t]=n(a),xr(e,this,o)}}function Xr(e,t){return Br($r(e,t,Et),e+"")}var jr=9007199254740991;function Bt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=jr}function Nt(e){return e!=null&&Bt(e.length)&&!Yn(e)}var Wr=Object.prototype;function Jn(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||Wr;return e===n}function Zn(e,t){for(var n=-1,s=Array(e);++n<e;)s[n]=t(n);return s}var Hr="[object Arguments]";function fn(e){return xe(e)&&Xe(e)==Hr}var es=Object.prototype,Kr=es.hasOwnProperty,zr=es.propertyIsEnumerable,Ct=fn(function(){return arguments}())?fn:function(e){return xe(e)&&Kr.call(e,"callee")&&!zr.call(e,"callee")};function Yr(){return!1}var ts=typeof exports=="object"&&exports&&!exports.nodeType&&exports,pn=ts&&typeof module=="object"&&module&&!module.nodeType&&module,qr=pn&&pn.exports===ts,dn=qr?ge.Buffer:void 0,Qr=dn?dn.isBuffer:void 0,Ot=Qr||Yr,Jr="[object Arguments]",Zr="[object Array]",ei="[object Boolean]",ti="[object Date]",ni="[object Error]",si="[object Function]",ri="[object Map]",ii="[object Number]",ai="[object Object]",oi="[object RegExp]",li="[object Set]",ci="[object String]",ui="[object WeakMap]",hi="[object ArrayBuffer]",fi="[object DataView]",pi="[object Float32Array]",di="[object Float64Array]",Ei="[object Int8Array]",Ni="[object Int16Array]",Ti="[object Int32Array]",bi="[object Uint8Array]",mi="[object Uint8ClampedArray]",Ii="[object Uint16Array]",_i="[object Uint32Array]",O={};O[pi]=O[di]=O[Ei]=O[Ni]=O[Ti]=O[bi]=O[mi]=O[Ii]=O[_i]=!0;O[Jr]=O[Zr]=O[hi]=O[ei]=O[fi]=O[ti]=O[ni]=O[si]=O[ri]=O[ii]=O[ai]=O[oi]=O[li]=O[ci]=O[ui]=!1;function gi(e){return xe(e)&&Bt(e.length)&&!!O[Xe(e)]}function Ai(e){return function(t){return e(t)}}var ns=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ze=ns&&typeof module=="object"&&module&&!module.nodeType&&module,Li=ze&&ze.exports===ns,wt=Li&&Wn.process,En=function(){try{var e=ze&&ze.require&&ze.require("util").types;return e||wt&&wt.binding&&wt.binding("util")}catch{}}(),Nn=En&&En.isTypedArray,ss=Nn?Ai(Nn):gi,vi=Object.prototype,yi=vi.hasOwnProperty;function rs(e,t){var n=pe(e),s=!n&&Ct(e),r=!n&&!s&&Ot(e),i=!n&&!s&&!r&&ss(e),a=n||s||r||i,o=a?Zn(e.length,String):[],u=o.length;for(var p in e)(t||yi.call(e,p))&&!(a&&(p=="length"||r&&(p=="offset"||p=="parent")||i&&(p=="buffer"||p=="byteLength"||p=="byteOffset")||qn(p,u)))&&o.push(p);return o}function wi(e,t){return function(n){return e(t(n))}}var Si=wi(Object.keys,Object),Pi=Object.prototype,Oi=Pi.hasOwnProperty;function xi(e){if(!Jn(e))return Si(e);var t=[];for(var n in Object(e))Oi.call(e,n)&&n!="constructor"&&t.push(n);return t}function Vt(e){return Nt(e)?rs(e):xi(e)}function Di(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var ki=Object.prototype,Ri=ki.hasOwnProperty;function Ui(e){if(!Ge(e))return Di(e);var t=Jn(e),n=[];for(var s in e)s=="constructor"&&(t||!Ri.call(e,s))||n.push(s);return n}function Mi(e){return Nt(e)?rs(e,!0):Ui(e)}var Fi=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Bi=/^\w*$/;function Gt(e,t){if(pe(e))return!1;var n=typeof e;return n=="number"||n=="symbol"||n=="boolean"||e==null||dt(e)?!0:Bi.test(e)||!Fi.test(e)||t!=null&&e in Object(t)}var qe=Fe(Object,"create");function Ci(){this.__data__=qe?qe(null):{},this.size=0}function Vi(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Gi="__lodash_hash_undefined__",$i=Object.prototype,Xi=$i.hasOwnProperty;function ji(e){var t=this.__data__;if(qe){var n=t[e];return n===Gi?void 0:n}return Xi.call(t,e)?t[e]:void 0}var Wi=Object.prototype,Hi=Wi.hasOwnProperty;function Ki(e){var t=this.__data__;return qe?t[e]!==void 0:Hi.call(t,e)}var zi="__lodash_hash_undefined__";function Yi(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=qe&&t===void 0?zi:t,this}function De(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}De.prototype.clear=Ci;De.prototype.delete=Vi;De.prototype.get=ji;De.prototype.has=Ki;De.prototype.set=Yi;function qi(){this.__data__=[],this.size=0}function Tt(e,t){for(var n=e.length;n--;)if(Qn(e[n][0],t))return n;return-1}var Qi=Array.prototype,Ji=Qi.splice;function Zi(e){var t=this.__data__,n=Tt(t,e);if(n<0)return!1;var s=t.length-1;return n==s?t.pop():Ji.call(t,n,1),--this.size,!0}function ea(e){var t=this.__data__,n=Tt(t,e);return n<0?void 0:t[n][1]}function ta(e){return Tt(this.__data__,e)>-1}function na(e,t){var n=this.__data__,s=Tt(n,e);return s<0?(++this.size,n.push([e,t])):n[s][1]=t,this}function Ae(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}Ae.prototype.clear=qi;Ae.prototype.delete=Zi;Ae.prototype.get=ea;Ae.prototype.has=ta;Ae.prototype.set=na;var Qe=Fe(ge,"Map");function sa(){this.size=0,this.__data__={hash:new De,map:new(Qe||Ae),string:new De}}function ra(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function bt(e,t){var n=e.__data__;return ra(t)?n[typeof t=="string"?"string":"hash"]:n.map}function ia(e){var t=bt(this,e).delete(e);return this.size-=t?1:0,t}function aa(e){return bt(this,e).get(e)}function oa(e){return bt(this,e).has(e)}function la(e,t){var n=bt(this,e),s=n.size;return n.set(e,t),this.size+=n.size==s?0:1,this}function Le(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}Le.prototype.clear=sa;Le.prototype.delete=ia;Le.prototype.get=aa;Le.prototype.has=oa;Le.prototype.set=la;var ca="Expected a function";function $t(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(ca);var n=function(){var s=arguments,r=t?t.apply(this,s):s[0],i=n.cache;if(i.has(r))return i.get(r);var a=e.apply(this,s);return n.cache=i.set(r,a)||i,a};return n.cache=new($t.Cache||Le),n}$t.Cache=Le;var ua=500;function ha(e){var t=$t(e,function(s){return n.size===ua&&n.clear(),s}),n=t.cache;return t}var fa=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,pa=/\\(\\)?/g,da=ha(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(fa,function(n,s,r,i){t.push(r?i.replace(pa,"$1"):s||n)}),t});function Ea(e){return e==null?"":zn(e)}function is(e,t){return pe(e)?e:Gt(e,t)?[e]:da(Ea(e))}function mt(e){if(typeof e=="string"||dt(e))return e;var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function as(e,t){t=is(t,e);for(var n=0,s=t.length;e!=null&&n<s;)e=e[mt(t[n++])];return n&&n==s?e:void 0}function os(e,t,n){var s=e==null?void 0:as(e,t);return s===void 0?n:s}function ls(e,t){for(var n=-1,s=t.length,r=e.length;++n<s;)e[r+n]=t[n];return e}var Tn=Ne?Ne.isConcatSpreadable:void 0;function Na(e){return pe(e)||Ct(e)||!!(Tn&&e&&e[Tn])}function Ta(e,t,n,s,r){var i=-1,a=e.length;for(n||(n=Na),r||(r=[]);++i<a;){var o=e[i];n(o)?ls(r,o):r[r.length]=o}return r}function bn(e){var t=e==null?0:e.length;return t?Ta(e):[]}function ba(){this.__data__=new Ae,this.size=0}function ma(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Ia(e){return this.__data__.get(e)}function _a(e){return this.__data__.has(e)}var ga=200;function Aa(e,t){var n=this.__data__;if(n instanceof Ae){var s=n.__data__;if(!Qe||s.length<ga-1)return s.push([e,t]),this.size=++n.size,this;n=this.__data__=new Le(s)}return n.set(e,t),this.size=n.size,this}function _e(e){var t=this.__data__=new Ae(e);this.size=t.size}_e.prototype.clear=ba;_e.prototype.delete=ma;_e.prototype.get=Ia;_e.prototype.has=_a;_e.prototype.set=Aa;function cs(e,t){for(var n=-1,s=e==null?0:e.length,r=0,i=[];++n<s;){var a=e[n];t(a,n,e)&&(i[r++]=a)}return i}function La(){return[]}var va=Object.prototype,ya=va.propertyIsEnumerable,mn=Object.getOwnPropertySymbols,wa=mn?function(e){return e==null?[]:(e=Object(e),cs(mn(e),function(t){return ya.call(e,t)}))}:La;function Sa(e,t,n){var s=t(e);return pe(e)?s:ls(s,n(e))}function In(e){return Sa(e,Vt,wa)}var xt=Fe(ge,"DataView"),Dt=Fe(ge,"Promise"),kt=Fe(ge,"Set"),_n="[object Map]",Pa="[object Object]",gn="[object Promise]",An="[object Set]",Ln="[object WeakMap]",vn="[object DataView]",Oa=Me(xt),xa=Me(Qe),Da=Me(Dt),ka=Me(kt),Ra=Me(Pt),we=Xe;(xt&&we(new xt(new ArrayBuffer(1)))!=vn||Qe&&we(new Qe)!=_n||Dt&&we(Dt.resolve())!=gn||kt&&we(new kt)!=An||Pt&&we(new Pt)!=Ln)&&(we=function(e){var t=Xe(e),n=t==Pa?e.constructor:void 0,s=n?Me(n):"";if(s)switch(s){case Oa:return vn;case xa:return _n;case Da:return gn;case ka:return An;case Ra:return Ln}return t});var yn=ge.Uint8Array,Ua="__lodash_hash_undefined__";function Ma(e){return this.__data__.set(e,Ua),this}function Fa(e){return this.__data__.has(e)}function ot(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Le;++t<n;)this.add(e[t])}ot.prototype.add=ot.prototype.push=Ma;ot.prototype.has=Fa;function Ba(e,t){for(var n=-1,s=e==null?0:e.length;++n<s;)if(t(e[n],n,e))return!0;return!1}function Ca(e,t){return e.has(t)}var Va=1,Ga=2;function us(e,t,n,s,r,i){var a=n&Va,o=e.length,u=t.length;if(o!=u&&!(a&&u>o))return!1;var p=i.get(e),h=i.get(t);if(p&&h)return p==t&&h==e;var d=-1,N=!0,m=n&Ga?new ot:void 0;for(i.set(e,t),i.set(t,e);++d<o;){var A=e[d],I=t[d];if(s)var v=a?s(I,A,d,t,e,i):s(A,I,d,e,t,i);if(v!==void 0){if(v)continue;N=!1;break}if(m){if(!Ba(t,function(H,K){if(!Ca(m,K)&&(A===H||r(A,H,n,s,i)))return m.push(K)})){N=!1;break}}else if(!(A===I||r(A,I,n,s,i))){N=!1;break}}return i.delete(e),i.delete(t),N}function $a(e){var t=-1,n=Array(e.size);return e.forEach(function(s,r){n[++t]=[r,s]}),n}function Xa(e){var t=-1,n=Array(e.size);return e.forEach(function(s){n[++t]=s}),n}var ja=1,Wa=2,Ha="[object Boolean]",Ka="[object Date]",za="[object Error]",Ya="[object Map]",qa="[object Number]",Qa="[object RegExp]",Ja="[object Set]",Za="[object String]",eo="[object Symbol]",to="[object ArrayBuffer]",no="[object DataView]",wn=Ne?Ne.prototype:void 0,St=wn?wn.valueOf:void 0;function so(e,t,n,s,r,i,a){switch(n){case no:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case to:return!(e.byteLength!=t.byteLength||!i(new yn(e),new yn(t)));case Ha:case Ka:case qa:return Qn(+e,+t);case za:return e.name==t.name&&e.message==t.message;case Qa:case Za:return e==t+"";case Ya:var o=$a;case Ja:var u=s&ja;if(o||(o=Xa),e.size!=t.size&&!u)return!1;var p=a.get(e);if(p)return p==t;s|=Wa,a.set(e,t);var h=us(o(e),o(t),s,r,i,a);return a.delete(e),h;case eo:if(St)return St.call(e)==St.call(t)}return!1}var ro=1,io=Object.prototype,ao=io.hasOwnProperty;function oo(e,t,n,s,r,i){var a=n&ro,o=In(e),u=o.length,p=In(t),h=p.length;if(u!=h&&!a)return!1;for(var d=u;d--;){var N=o[d];if(!(a?N in t:ao.call(t,N)))return!1}var m=i.get(e),A=i.get(t);if(m&&A)return m==t&&A==e;var I=!0;i.set(e,t),i.set(t,e);for(var v=a;++d<u;){N=o[d];var H=e[N],K=t[N];if(s)var w=a?s(K,H,N,t,e,i):s(H,K,N,e,t,i);if(!(w===void 0?H===K||r(H,K,n,s,i):w)){I=!1;break}v||(v=N=="constructor")}if(I&&!v){var ee=e.constructor,V=t.constructor;ee!=V&&"constructor"in e&&"constructor"in t&&!(typeof ee=="function"&&ee instanceof ee&&typeof V=="function"&&V instanceof V)&&(I=!1)}return i.delete(e),i.delete(t),I}var lo=1,Sn="[object Arguments]",Pn="[object Array]",st="[object Object]",co=Object.prototype,On=co.hasOwnProperty;function uo(e,t,n,s,r,i){var a=pe(e),o=pe(t),u=a?Pn:we(e),p=o?Pn:we(t);u=u==Sn?st:u,p=p==Sn?st:p;var h=u==st,d=p==st,N=u==p;if(N&&Ot(e)){if(!Ot(t))return!1;a=!0,h=!1}if(N&&!h)return i||(i=new _e),a||ss(e)?us(e,t,n,s,r,i):so(e,t,u,n,s,r,i);if(!(n&lo)){var m=h&&On.call(e,"__wrapped__"),A=d&&On.call(t,"__wrapped__");if(m||A){var I=m?e.value():e,v=A?t.value():t;return i||(i=new _e),r(I,v,n,s,i)}}return N?(i||(i=new _e),oo(e,t,n,s,r,i)):!1}function Xt(e,t,n,s,r){return e===t?!0:e==null||t==null||!xe(e)&&!xe(t)?e!==e&&t!==t:uo(e,t,n,s,Xt,r)}var ho=1,fo=2;function po(e,t,n,s){var r=n.length,i=r;if(e==null)return!i;for(e=Object(e);r--;){var a=n[r];if(a[2]?a[1]!==e[a[0]]:!(a[0]in e))return!1}for(;++r<i;){a=n[r];var o=a[0],u=e[o],p=a[1];if(a[2]){if(u===void 0&&!(o in e))return!1}else{var h=new _e,d;if(!(d===void 0?Xt(p,u,ho|fo,s,h):d))return!1}}return!0}function hs(e){return e===e&&!Ge(e)}function Eo(e){for(var t=Vt(e),n=t.length;n--;){var s=t[n],r=e[s];t[n]=[s,r,hs(r)]}return t}function fs(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function No(e){var t=Eo(e);return t.length==1&&t[0][2]?fs(t[0][0],t[0][1]):function(n){return n===e||po(n,e,t)}}function To(e,t){return e!=null&&t in Object(e)}function bo(e,t,n){t=is(t,e);for(var s=-1,r=t.length,i=!1;++s<r;){var a=mt(t[s]);if(!(i=e!=null&&n(e,a)))break;e=e[a]}return i||++s!=r?i:(r=e==null?0:e.length,!!r&&Bt(r)&&qn(a,r)&&(pe(e)||Ct(e)))}function mo(e,t){return e!=null&&bo(e,t,To)}var Io=1,_o=2;function go(e,t){return Gt(e)&&hs(t)?fs(mt(e),t):function(n){var s=os(n,e);return s===void 0&&s===t?mo(n,e):Xt(t,s,Io|_o)}}function ps(e){return function(t){return t==null?void 0:t[e]}}function Ao(e){return function(t){return as(t,e)}}function Lo(e){return Gt(e)?ps(mt(e)):Ao(e)}function ds(e){return typeof e=="function"?e:e==null?Et:typeof e=="object"?pe(e)?go(e[0],e[1]):No(e):Lo(e)}function vo(e,t,n,s){for(var r=-1,i=e==null?0:e.length;++r<i;){var a=e[r];t(s,a,n(a),e)}return s}function yo(e){return function(t,n,s){for(var r=-1,i=Object(t),a=s(t),o=a.length;o--;){var u=a[++r];if(n(i[u],u,i)===!1)break}return t}}var Es=yo();function wo(e,t){return e&&Es(e,t,Vt)}function So(e,t){return function(n,s){if(n==null)return n;if(!Nt(n))return e(n,s);for(var r=n.length,i=-1,a=Object(n);++i<r&&s(a[i],i,a)!==!1;);return n}}var Po=So(wo);function Oo(e,t,n,s){return Po(e,function(r,i,a){t(s,r,n(r),a)}),s}function xo(e,t){return function(n,s){var r=pe(n)?vo:Oo,i=t?t():{};return r(n,e,ds(s),i)}}function Do(e){return xe(e)&&Nt(e)}function M(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function ko(e){return typeof e=="function"?e:Et}var Ro=Math.max,Uo=Math.min;function Mo(e,t,n){var s=e==null?0:e.length;if(!s)return-1;var r=s-1;return n!==void 0&&(r=dr(n),r=n<0?Ro(s+r,0):Uo(r,s-1)),Cr(e,ds(t),r)}function Fo(e){return e&&e.length?e[0]:void 0}function Je(e,t){return e==null?e:Es(e,ko(t),Mi)}var oe=xo(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),Bo=Math.max;function Co(e){if(!(e&&e.length))return[];var t=0;return e=cs(e,function(n){if(Do(n))return t=Bo(n.length,t),!0}),Zn(t,function(n){return Kn(e,ps(n))})}var Rt=Xr(Co),f=(e=>(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.TILDE="<tilde>",e.SINGLE_LINE_COMMENT="<single-line-comment>",e.MULTILINE_COMMENT="<multiline-comment>",e))(f||{});function Vo(e){switch(e.kind){case"<newline>":case"<space>":case"<tab>":case"<single-line-comment>":case"<multiline-comment>":return!0;default:return!1}}function Go(e){if(!e)return!1;switch(e){case"+":case"-":case"*":case"/":case"%":case"<":case">":case"=":case"!":case".":case"&":case"|":return!0;default:return!1}}function xn(e){return e!==void 0&&e.kind==="<op>"}class q{constructor(t,n,s,r,i){this.kind=t,this.startPos=n,this.endPos=s,this.value=r,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=i,this.start=n.offset,this.end=s.offset}static create(t,n,s,r,i){return new q(t,n,s,r,i)}}function Ns(e){return e.trailingTrivia.find(({kind:t})=>t===f.NEWLINE)!==void 0}function Dn(e,t){return t.leadingTrivia.find(({kind:s})=>s===f.NEWLINE)!==void 0||Ns(e)}function Ut(e){return e.trailingTrivia.find(({kind:t})=>[f.SPACE,f.TAB].includes(t))!==void 0}function Ts(e){return e.trailingTrivia.length===0?e.end:Ts(M(e.trailingTrivia))}function bs(e){return e.leadingTrivia.length===0?e.start:bs(e.leadingTrivia[0])}function $o(e){return[f.SINGLE_LINE_COMMENT,f.MULTILINE_COMMENT].includes(e.kind)}class Xo{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}}class k{constructor(t,n,s){this.id=t,this.kind=n;const r=s.find(a=>a!==void 0&&!Number.isNaN(a.start));r?(this.startPos=r.startPos,this.fullStart=r instanceof q?bs(r):r.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);const i=[...s].reverse().find(a=>a!==void 0&&!Number.isNaN(a.end));i?(this.endPos=i.endPos,this.fullEnd=i instanceof q?Ts(i):i.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}}var Se=(e=>(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.DUMMY="<dummy>",e.ARRAY="<array>",e.PARTIAL_INJECTION="<partial-injection>",e))(Se||{});class J extends k{constructor({body:t=[],eof:n},s){super(s,"<program>",[...t,n]),this.body=t,this.eof=n}}class S extends k{constructor({type:t,name:n,as:s,alias:r,attributeList:i,bodyColon:a,body:o},u){if(super(u,"<element-declaration>",[t,n,s,r,i,a,o]),o&&a&&!(o instanceof y||o instanceof S))throw new Error("If an element has a simple body, it must be a function application node");this.type=t,this.name=n,this.as=s,this.alias=r,this.attributeList=i,this.bodyColon=a,this.body=o}}class ce extends k{constructor({identifiers:t=[]},n){super(n,"<identifer-stream>",t||[]),this.identifiers=t}}class ue extends k{constructor({name:t,colon:n,value:s},r){super(r,"<attribute>",[t,n,s]),this.name=t,this.value=s,this.colon=n}}class re extends k{constructor({op:t,expression:n},s){super(s,"<prefix-expression>",[t,n]),this.op=t,this.expression=n}}class Te extends k{constructor({op:t,leftExpression:n,rightExpression:s},r){super(r,"<infix-expression>",[n,t,s]),this.op=t,this.leftExpression=n,this.rightExpression=s}}class It extends k{constructor({op:t,expression:n},s){super(s,"<postfix-expression>",[n,t]),this.op=t,this.expression=n}}class ie extends k{constructor({value:t},n){super(n,"<function-expression>",[t]),this.value=t}}class y extends k{constructor({callee:t,args:n=[]},s){super(s,"<function-application>",[t,...n]),this.callee=t,this.args=n}}class Ee extends k{constructor({blockOpenBrace:t,body:n=[],blockCloseBrace:s},r){super(r,"<block-expression>",[t,...n,s]),this.blockOpenBrace=t,this.body=n,this.blockCloseBrace=s}}class ke extends k{constructor({op:t,partial:n},s){super(s,"<partial-injection>",[t,n]),this.partial=n}}class R extends k{constructor({listOpenBracket:t,elementList:n=[],commaList:s=[],listCloseBracket:r},i){super(i,"<list-expression>",[t,...ms(n,s),r]),this.listOpenBracket=t,this.elementList=n,this.commaList=s,this.listCloseBracket=r}}class be extends k{constructor({tupleOpenParen:t,elementList:n=[],commaList:s=[],tupleCloseParen:r},i){super(i,"<tuple-expression>",[t,...ms(n,s),r]),this.tupleOpenParen=t,this.elementList=n,this.commaList=s,this.tupleCloseParen=r}}class jt extends be{constructor({groupOpenParen:t,expression:n,groupCloseParen:s},r){super({tupleOpenParen:t,elementList:n&&[n],commaList:[],tupleCloseParen:s},r),this.kind="<group-expression>"}}class ae extends k{constructor({callee:t,argumentList:n},s){super(s,"<call-expression>",[t,n]),this.callee=t,this.argumentList=n}}class je extends k{constructor({literal:t},n){super(n,"<literal>",[t]),this.literal=t}}class de extends k{constructor({variable:t},n){super(n,"<variable>",[t]),this.variable=t}}class z extends k{constructor({expression:t},n){super(n,"<primary-expression>",[t]),this.expression=t}}class rt extends k{constructor({pre:t},n){const s=q.create(f.SPACE,t.endPos,t.endPos," ",!1);super(n,"<dummy>",[s])}}class Re extends k{constructor({expression:t,indexer:n},s){super(s,"<array>",[t,n]),this.array=t,this.indexer=n}}function ms(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];const[n]=e,[s]=t;return(n.start<s.start?bn(Rt(e,t)):bn(Rt(t,e))).filter(r=>r!==null)}function jo(e,t=!1){return JSON.stringify(e,function(n,s){var r;return!(this instanceof J)&&n==="symbol"?s==null?void 0:s.id:n==="symbol"?{symbolTable:s==null?void 0:s.symbolTable,id:s==null?void 0:s.id,references:s==null?void 0:s.references.map(i=>i.id),declaration:(r=s==null?void 0:s.declaration)==null?void 0:r.id}:n==="referee"||n==="parent"||n==="declaration"?s==null?void 0:s.id:n==="symbolTable"?Object.fromEntries(s.table):s},t?2:0)}class B{constructor(t){this.value=t}unwrap(){return this.value}unwrap_or(t){return this.value}and_then(t){return t(this.value)}map(t){return new B(t(this.value))}isOk(){return!0}}class x{constructor(){this.value=void 0}unwrap(){throw new Error("Trying to unwrap a None value")}unwrap_or(t){return t}and_then(t){return new x}map(t){return new x}isOk(){return!1}}var _=(e=>(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.TablePartialInjection="TablePartialInjection",e))(_||{});function Wt(e){return`Schema:${e}`}function lt(e){return`Table:${e}`}function _t(e){return`Column:${e}`}function Ht(e){return`Enum:${e}`}function Kt(e){return`Enum field:${e}`}function zt(e){return`TableGroup:${e}`}function Yt(e){return`TableGroup field:${e}`}function Wo(e){return`Note:${e}`}function qt(e){return`TablePartial:${e}`}function Is(e){return`TablePartialInjection:${e}`}function it(e,t){switch(t){case"Column":return _t(e);case"Enum":return Ht(e);case"Enum field":return Kt(e);case"Schema":return Wt(e);case"Table":return lt(e);case"TableGroup":return zt(e);case"TableGroup field":return Yt(e);case"TablePartial":return qt(e);default:throw new Error("Unreachable")}}function he(e){const[t,n]=e.split(":");return Object.values(_).includes(t)?new B({name:n,kind:t}):new x}function Ho(e){const t=he(e).unwrap_or(void 0);if(!t)return!1;const{kind:n,name:s}=t;return n==="Schema"&&s==="public"}function Ko(e){const t=he(e).unwrap_or(void 0);if(!t)return!1;const{kind:n}=t;return n==="TablePartialInjection"}function zo(e){const t=he(e).unwrap_or(void 0);if(!t)return null;const{kind:n,name:s}=t;return n==="TablePartialInjection"?it(s,"TablePartial"):null}class Yo{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}}class _s{constructor({symbolTable:t},n){this.references=[],this.id=n,this.symbolTable=t}}class qo{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Qo{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class gs{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Qt{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class Jo{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Zo{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class el{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class tl{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class nl{constructor({injectorFieldSymbol:t,injectorDeclaration:n},s){this.references=[],this.id=s,this.injectorDeclaration=n,this.injectorFieldSymbol=t}}function sl(e){return[Wt,lt,Ht,zt,_t,Kt,Yt,qt,Is].map(t=>t(e))}function rl(e){return e instanceof Qt?nl:null}function gt(e){return!!e.match(new RegExp("(\\p{L}|_|\\p{M})","gu"))}function ct(e){const[t]=e;return t>="0"&&t<="9"}function il(e){const[t]=e;return ct(t)||gt(t)&&t.toLowerCase()>="a"&&t.toLowerCase()<="f"}function Ve(e){return gt(e)||ct(e)}function kn(e,t){const n=[],s=Math.min(e.length,t.length);for(let r=0;r<s;r+=1)n.push(e[r],t[r]);return n.push(...e.slice(s),...t.slice(s)),n}function Ye(e,t){return e>=t.start&&e<t.end}function As(e){var t;return e instanceof re?`${(t=e.op)==null?void 0:t.value}${As(e.expression)}`:e.expression.literal.value}function Mt(e){var t;return e instanceof re?((t=e.op)==null?void 0:t.value)==="-"?-Mt(e.expression):Mt(e.expression):Number.parseFloat(e.expression.literal.value)}var l=(e=>(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.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))(l||{});class c extends Error{constructor(t,n,s){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=s,this.start=s.start,this.end=s.end,this.name=this.constructor.name,Object.setPrototypeOf(this,c.prototype)}}class se{constructor(t,n){this.value=t,this.errors=n===void 0?[]:n}getValue(){return this.value}getErrors(){return this.errors}chain(t){const n=t(this.value),s=[...this.errors,...n.errors];return new se(n.value,s)}map(t){return new se(t(this.value),this.errors)}}function al(e,t,n){if(!e||!Pe(e)||t.length===0)return new x;const s=[...t],r=Rn(e).unwrap(),i=s.pop();if(!(i instanceof Ee))return new x;const a=M(s)instanceof R?s.pop():void 0;if(s.length===3){const o=Rn(s[1]).value;return!o||!Ft(o)?new x:new B(n.create(S,{type:r,name:s[0],as:o,alias:s[2],attributeList:a,body:i}))}return s.length===1?new B(n.create(S,{type:r,name:s[0],attributeList:a,body:i})):s.length===0?new B(n.create(S,{type:r,attributeList:a,body:i})):new x}function Ft(e){return e.kind===f.IDENTIFIER&&e.value==="as"}function g(e){e&&(e instanceof q?ol(e):ll(e))}function ol(e){e.kind!==f.EOF&&(e.isInvalid=!0)}function ll(e){if(e instanceof S)g(e.type),g(e.name),g(e.as),g(e.alias),g(e.bodyColon),g(e.attributeList),g(e.body);else if(e instanceof ce)e.identifiers.forEach(g);else if(e instanceof ue)g(e.name),g(e.colon),g(e.value);else if(e instanceof re)g(e.op),g(e.expression);else if(e instanceof Te)g(e.leftExpression),g(e.op),g(e.rightExpression);else if(e instanceof It)g(e.op),g(e.expression);else if(e instanceof Ee)g(e.blockOpenBrace),e.body.forEach(g),g(e.blockCloseBrace);else if(e instanceof R)g(e.listOpenBracket),e.commaList.forEach(g),e.elementList.forEach(g),g(e.listCloseBracket);else if(e instanceof be)g(e.tupleOpenParen),e.commaList.forEach(g),e.elementList.forEach(g),g(e.tupleCloseParen);else if(e instanceof ae)g(e.callee),g(e.argumentList);else if(e instanceof y)g(e.callee),e.args.forEach(g);else if(e instanceof z)g(e.expression);else if(e instanceof ie)g(e.value);else if(e instanceof de)g(e.variable);else if(e instanceof je)g(e.literal);else throw e instanceof jt?new Error("This case is handled by the TupleExpressionNode case"):new Error("Unreachable case in markInvalidNode")}function Ls(e){return!!(e!=null&&e.isInvalid)}function X(...e){return e.filter(t=>t!==void 0)}function cl(e){if(e instanceof J)return X(...e.body,e.eof);if(e instanceof S)return X(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof ue)return X(e.name,e.colon,e.value);if(e instanceof ce)return e.identifiers;if(e instanceof je)return e.literal?[e.literal]:[];if(e instanceof de)return X(e.variable);if(e instanceof re)return X(e.op,e.expression);if(e instanceof Te)return X(e.leftExpression,e.op,e.rightExpression);if(e instanceof It)return X(e.expression,e.op);if(e instanceof ie)return X(e.value);if(e instanceof y)return X(e.callee,...e.args);if(e instanceof Ee)return X(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof R)return X(e.listOpenBracket,...kn(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof be)return X(e.tupleOpenParen,...kn(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof ae)return X(e.callee,e.argumentList);if(e instanceof z)return X(e.expression);if(e instanceof Re)return X(e.array,e.indexer);if(e instanceof ke)return X(e.partial);throw e instanceof jt?new Error("This case is already handled by TupleExpressionNode"):new Error("Unreachable - no other possible cases")}function Rn(e){return W(e)?new B(e.expression.variable):new x}function Y(e){var t;return e instanceof z&&(e.expression instanceof de&&e.expression.variable instanceof q&&e.expression.variable.kind===f.QUOTED_STRING||e.expression instanceof je&&((t=e.expression.literal)==null?void 0:t.kind)===f.STRING_LITERAL)}function W(e){return e instanceof z&&e.expression instanceof de&&e.expression.variable instanceof q}function Pe(e){var t;return e instanceof z&&e.expression instanceof de&&((t=e.expression.variable)==null?void 0:t.kind)===f.IDENTIFIER}function Jt(e){var t;return e instanceof Te&&e.leftExpression instanceof k&&e.rightExpression instanceof k&&((t=e.op)==null?void 0:t.value)==="."}function $e(e){if(e===void 0)return new x;const t=e.identifiers.map(n=>n.value).join(" ");return t===""?new x:new B(t)}class ul{constructor(t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){const t=this.peek();return this.current={...this.current},t===`
|
|
2
|
+
`?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,t}peek(t=0){if(!(this.current.offset+t>=this.text.length))return this.text[this.current.offset+t]}check(t){for(let n=0;n<t.length;n+=1)if(t[n]!==this.peek(n))return!1;return!0}match(t){return this.check(t)?(t.split("").forEach(()=>this.advance()),!0):!1}addToken(t,n=!1){this.tokens.push(this.createToken(t,n))}createToken(t,n=!1){return q.create(t,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),n)}lex(){return this.scanTokens(),this.tokens.push(q.create(f.EOF,this.start,this.current,"",!1)),this.gatherTrivia(),this.gatherInvalid(),new se(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){const t=this.advance();switch(t){case" ":this.addToken(f.SPACE);break;case"\r":break;case`
|
|
3
|
+
`:this.addToken(f.NEWLINE);break;case" ":this.addToken(f.TAB);break;case",":this.addToken(f.COMMA);break;case"(":this.addToken(f.LPAREN);break;case")":this.addToken(f.RPAREN);break;case"[":this.addToken(f.LBRACKET);break;case"]":this.addToken(f.RBRACKET);break;case"{":this.addToken(f.LBRACE);break;case"}":this.addToken(f.RBRACE);break;case";":this.addToken(f.SEMICOLON);break;case":":this.addToken(f.COLON);break;case"~":this.addToken(f.TILDE);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(t);break;default:if(Go(t)){this.operator(t);break}if(gt(t)){this.identifier();break}if(ct(t)){this.numericLiteralOrIdentifier();break}this.addToken(f.OP,!0),this.errors.push(new c(l.UNKNOWN_SYMBOL,`Unexpected token '${t}'`,this.createToken(f.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let t=!0,n=[],s;const r=[];for(const i of this.tokens)Vo(i)?(n.push(i),i.kind===f.NEWLINE&&s&&(s.trailingTrivia=n,t=!0,s=void 0,n=[])):(t?i.leadingTrivia=n:s.trailingTrivia=n,r.push(i),n=[],s=i,t=!1);this.tokens=r}gatherInvalid(){let t;const n=[],s=[];for(t=0;t<this.tokens.length&&Ls(this.tokens[t]);t+=1)s.push(this.tokens[t]);let r=this.tokens[t];for(r.leadingInvalid=[...s,...r.leadingInvalid];t<this.tokens.length;t+=1){const i=this.tokens[t];i.isInvalid?r.trailingInvalid.push(i):(r=i,n.push(i))}this.tokens=n}consumeUntil(t,n,{allowNewline:s,allowEof:r,raw:i,consumeStopSequence:a=!0}){let o="";for(;!this.isAtEnd()&&(s||!this.check(`
|
|
4
4
|
`))&&!this.check(n);)this.peek()==="\\"&&!i?(this.advance(),o+=this.escapedString()):o+=this.advance();if(this.isAtEnd()&&!r){const u=this.createToken(t,!0);this.tokens.push(u),this.errors.push(new c(l.UNEXPECTED_EOF,"EOF reached while parsing",u));return}if(this.check(`
|
|
5
|
-
`)&&!s){const u=this.createToken(t,!0);this.tokens.push(u),this.errors.push(new c(l.UNEXPECTED_NEWLINE,"Invalid newline encountered while parsing",u));return}a&&this.match(n),this.tokens.push(
|
|
6
|
-
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(f.MULTILINE_COMMENT,"*/",{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&
|
|
5
|
+
`)&&!s){const u=this.createToken(t,!0);this.tokens.push(u),this.errors.push(new c(l.UNEXPECTED_NEWLINE,"Invalid newline encountered while parsing",u));return}a&&this.match(n),this.tokens.push(q.create(t,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(f.STRING_LITERAL,"'",{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(f.STRING_LITERAL,"'''",{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(f.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(f.QUOTED_STRING,'"',{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(f.SINGLE_LINE_COMMENT,`
|
|
6
|
+
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(f.MULTILINE_COMMENT,"*/",{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Ve(this.peek());)this.advance();this.addToken(f.IDENTIFIER)}operator(t){switch(t){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}this.addToken(f.OP)}numericLiteralOrIdentifier(){let t=0;if(this.isAtEnd())return this.addToken(f.NUMERIC_LITERAL);for(;!this.isAtEnd();){const n=this.check(".");if(t+=n?1:0,t>1)break;if(!n&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(f.NUMERIC_LITERAL);if(!n&&!Ve(this.peek()))return this.addToken(f.NUMERIC_LITERAL);if(!n&&!ct(this.peek()))break;this.advance()}if(t>0){for(;!this.isAtEnd()&&(this.check(".")||Ve(this.peek()));)this.advance();const n=this.createToken(f.NUMERIC_LITERAL,!0);this.tokens.push(n),this.errors.push(new c(l.UNKNOWN_TOKEN,"Invalid number",n))}else{for(;!this.isAtEnd()&&Ve(this.peek());)this.advance();const n=this.createToken(f.IDENTIFIER,!1);this.tokens.push(n)}}colorLiteral(){for(;!this.isAtEnd()&&Ve(this.peek());)this.advance();this.addToken(f.COLOR_LITERAL)}escapedString(){const t={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 n="";for(let s=0;s<=3;s+=1){if(this.isAtEnd()||!Ce(this.peek()))return this.errors.push(new c(l.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${n}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,K.create(f.STRING_LITERAL,t,this.current,`\\u${n}`,!0))),`\\u${n}`;n+=this.advance()}return String.fromCharCode(parseInt(n,16))}default:return this.text[this.current.offset-1]}}}var at=(e=>(e[e.ListExpression=0]="ListExpression",e[e.GroupExpression=1]="GroupExpression",e[e.BlockExpression=2]="BlockExpression",e))(at||{});class hl{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(t){this.stack.push(t),t===0&&(this.numberOfNestedLBrackets+=1),t===1&&(this.numberOfNestedLParens+=1),t===2&&(this.numberOfNestedLBraces+=1)}pop(){const t=this.stack.pop();return t===0&&(this.numberOfNestedLBrackets-=1),t===1&&(this.numberOfNestedLParens-=1),t===2&&(this.numberOfNestedLBraces-=1),t}top(){return F(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(t,n){return()=>{this.push(t);try{return n()}finally{this.pop()}}}findHandlerContext(t,n){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let s=n;s<t.length-1;s+=1)switch(t[s].kind){case f.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(i=>[1,0].includes(i));break;case f.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case f.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case f.RBRACKET:if(this.isWithinListExpressionContext())return 0;break}}}class fl{constructor(t){this.generator=t}create(t,n){return new t(n,this.generator.nextId())}}class T{constructor(t,n,s){this.token=t,this.partialNode=n,this.handlerContext=s}}class pl{constructor(t,n){this.current=0,this.errors=[],this.contextStack=new hl,this.synchronizeProgram=()=>{const s=this.peek();s.kind!==f.EOF?g(this.advance()):(g(this.peek()),this.logError(s,l.UNEXPECTED_EOF,"Unexpected EOF"))},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){const s=this.peek();if(Ft(s)||this.check(f.COLON,f.LBRACE,f.LBRACKET))break;g(s),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.COLON,f.LBRACE,f.LBRACKET))break;g(s),this.advance()}},this.blockExpression=this.contextStack.withContextDo(at.BlockExpression,()=>{const s={body:[]},r=()=>this.nodeFactory.create(Ee,s);try{this.consume("Expect an opening brace '{'",f.LBRACE),s.blockOpenBrace=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.blockOpenBrace=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(f.RBRACE);)try{if(this.match(f.TILDE)){const i=this.previous(),a=this.variable(),o=this.nodeFactory.create(Re,{op:i,partial:a});s.body.push(o)}else s.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(i){if(!(i instanceof T))throw i;if(s.body.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}try{this.consume("Expect a closing brace '}'",f.RBRACE),s.blockCloseBrace=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.blockCloseBrace=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}return r()}),this.synchronizeBlock=()=>{if(!this.check(f.RBRACE))for(g(this.advance());!this.isAtEnd();){const s=this.peek();if(this.check(f.RBRACE)||Dn(this.previous(),s))break;g(s),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(at.GroupExpression,()=>{const s={elementList:[],commaList:[]},r=()=>this.nodeFactory.create(jt,{groupOpenParen:s.tupleOpenParen,groupCloseParen:s.tupleCloseParen,expression:s.elementList[0]}),i=()=>this.nodeFactory.create(be,s);try{this.consume("Expect an opening parenthesis '('",f.LPAREN),s.tupleOpenParen=this.previous()}catch(a){if(!(a instanceof T))throw a;if(s.tupleOpenParen=a.partialNode,!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(f.RPAREN))try{s.elementList.push(this.normalExpression())}catch(a){if(!(a instanceof T))throw a;if(s.elementList.push(a.partialNode),!this.canHandle(a))throw new T(a.token,r(),a.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(f.RPAREN);)try{this.consume("Expect a comma ','",f.COMMA),s.commaList.push(this.previous()),s.elementList.push(this.normalExpression())}catch(a){if(!(a instanceof T))throw a;if(a.partialNode instanceof R&&s.elementList.push(a.partialNode),!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}try{this.consume("Expect a closing parenthesis ')'",f.RPAREN),s.tupleCloseParen=this.previous()}catch(a){if(!(a instanceof T))throw a;if(s.tupleCloseParen=a.partialNode,!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}return s.elementList.length===1?r():i()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.RPAREN,f.COMMA))break;g(s),this.advance()}},this.listExpression=this.contextStack.withContextDo(at.ListExpression,()=>{const s={elementList:[],commaList:[]},r=()=>this.nodeFactory.create(U,s);try{this.consume("Expect an opening bracket '['",f.LBRACKET),s.listOpenBracket=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.listOpenBracket=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(f.RBRACKET))try{s.elementList.push(this.attribute())}catch(i){if(!(i instanceof T))throw i;if(s.elementList.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(f.RBRACKET);)try{this.consume("Expect a comma ','",f.COMMA),s.commaList.push(this.previous()),s.elementList.push(this.attribute())}catch(i){if(!(i instanceof T))throw i;if(i.partialNode instanceof R&&s.elementList.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}try{this.consume("Expect a closing bracket ']'",f.RBRACKET),s.listCloseBracket=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.listCloseBracket=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}return r()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.COMMA,f.RBRACKET))break;g(s),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.COMMA,f.RBRACKET,f.COLON))break;g(s),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.COMMA,f.RBRACKET))break;g(s),this.advance()}},this.tokens=t,this.nodeFactory=new fl(n)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===f.EOF}advance(){return this.isAtEnd()?F(this.tokens):this.tokens[this.current++]}peek(t=0){return t+this.current>=this.tokens.length?F(this.tokens):this.tokens[this.current+t]}match(...t){const n=this.check(...t);return n&&this.advance(),n}check(...t){const n=this.peek();return t.includes(n.kind)}previous(){return this.tokens[this.current-1]}canHandle(t){return t.handlerContext===void 0||t.handlerContext===this.contextStack.top()}consume(t,...n){if(!this.match(...n))throw this.logError(this.peek(),l.UNEXPECTED_TOKEN,t),new T(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(t,...n){if(this.isAtEnd()||!this.check(...n)){for(g(this.peek()),this.logError(this.advance(),l.UNEXPECTED_TOKEN,t);!this.isAtEnd()&&!this.check(...n);)g(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){const t=[],n=[];let s,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)n.push(this.tokens[r]);for(s=this.tokens[r],s.leadingInvalid=n,t.push(s),r+=1;r<this.tokens.length;r+=1){const i=this.tokens[r];i.isInvalid?s.trailingInvalid.push(i):(s=i,t.push(s))}this.tokens=t}parse(){const t=this.program(),n=this.advance(),s=this.nodeFactory.create(J,{body:t,eof:n});return this.gatherInvalid(),new se({ast:s,tokens:this.tokens},this.errors)}program(){const t=[];for(;!this.isAtEnd();)try{const n=this.elementDeclaration();t.push(n)}catch(n){if(!(n instanceof T))throw n;t.push(n.partialNode),this.synchronizeProgram()}return t}elementDeclaration(){const t={},n=()=>this.nodeFactory.create(S,t);try{this.consume("Expect an identifier",f.IDENTIFIER),t.type=this.previous()}catch(s){throw s instanceof T?(t.type=s.partialNode,new T(s.token,n(),s.handlerContext)):s}if(!this.check(f.COLON,f.LBRACE,f.LBRACKET))try{t.name=this.normalExpression()}catch(s){if(!(s instanceof T))throw s;if(t.name=s.partialNode,!this.canHandle(s))throw new T(s.token,n(),s.handlerContext);this.synchronizeElementDeclarationName()}if(Ft(this.peek()))if(t.as=this.advance(),this.check(f.COLON,f.LBRACE,f.LBRACKET))this.logError(this.peek(),l.UNEXPECTED_TOKEN,"Expect an alias");else try{t.alias=this.normalExpression()}catch(s){if(!(s instanceof T))throw s;if(t.alias=s.partialNode,!this.canHandle(s))throw new T(s.token,n(),s.handlerContext);this.synchronizeElementDeclarationAlias()}try{t.attributeList=this.check(f.LBRACKET)?this.listExpression():void 0}catch(s){throw s instanceof T?(t.attributeList=s.partialNode,new T(s.token,n(),s.handlerContext)):s}if(!this.discardUntil("Expect an opening brace '{' or a colon ':'",f.LBRACE,f.COLON))return n();try{if(this.match(f.COLON)){t.bodyColon=this.previous();const s=this.expression();s instanceof S?(g(s),this.logError(s,l.UNEXPECTED_ELEMENT_DECLARATION,"An element's simple body must not be an element declaration")):t.body=s}else t.body=this.blockExpression()}catch(s){throw s instanceof T?(t.body=s.partialNode,new T(s.token,n(),s.handlerContext)):s}return this.nodeFactory.create(S,t)}fieldDeclaration(){const t={},n=()=>this.nodeFactory.create(S,t);try{this.consume("Expect an identifier",f.IDENTIFIER),t.type=this.previous()}catch(s){throw s instanceof T?(t.type=s.partialNode,new T(s.token,n(),s.handlerContext)):s}try{this.consume("Expect a colon ':'",f.COLON),t.bodyColon=this.previous()}catch(s){throw s instanceof T?(t.bodyColon=s.partialNode,new T(s.token,n(),s.handlerContext)):s}try{const s=this.expression();s instanceof S?this.errors.push(new c(l.INVALID_ELEMENT_IN_SIMPLE_BODY,"Simple body cannot be an element declaration",s)):t.body=s}catch(s){throw s instanceof T?(t.body=s.partialNode,new T(s.token,n(),s.handlerContext)):s}return this.nodeFactory.create(S,t)}expression(){const t={args:[]},n=()=>al(t.callee,t.args,this.nodeFactory).unwrap_or(this.nodeFactory.create(y,t));try{t.callee=this.normalExpression()}catch(r){throw r instanceof T?(t.callee=r.partialNode,new T(r.token,n(),r.handlerContext)):r}if(this.shouldStopExpression())return n();let s=t.callee;for(;!this.shouldStopExpression();){Ut(this.previous())||this.logError(s,l.MISSING_SPACES,"Expect a following space");try{s=this.normalExpression(),t.args.push(s)}catch(r){throw r instanceof T?(s=r.partialNode,t.args.push(s),new T(r.token,n(),r.handlerContext)):r}}return n()}shouldStopExpression(){if(this.isAtEnd()||Ns(this.previous()))return!0;const t=this.peek().kind;return t===f.RBRACE||t===f.RBRACKET||t===f.RPAREN||t===f.COMMA||t===f.COLON}normalExpression(){return this.expression_bp(0)}expression_bp(t){let n=this.leftExpression_bp();for(;!this.isAtEnd();){const s=this.peek();if(s.kind===f.LPAREN){const{left:r}=Un(s);if(r<t||Dn(this.previous(),s)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{n=this.nodeFactory.create(ae,{callee:n,argumentList:this.tupleExpression()})}catch(i){throw i instanceof T?(n=this.nodeFactory.create(ae,{callee:n,argumentList:i.partialNode}),new T(i.token,n,i.handlerContext)):i}}else if(s.kind===f.LBRACKET){if(Ut(this.previous()))break;try{n=this.nodeFactory.create(ke,{expression:n,indexer:this.listExpression()})}catch(r){throw r instanceof T?(n=this.nodeFactory.create(ke,{expression:n,indexer:r.partialNode}),new T(r.token,n,r.handlerContext)):r}}else if(xn(s)){const r=s,i=Un(r);if(i.left!==null){if(i.left<=t)break;this.advance(),n=this.nodeFactory.create(It,{expression:n,op:r})}else{const a=El(r);if(a.left===null||a.left<=t)break;this.advance();try{n=this.nodeFactory.create(Te,{leftExpression:n,op:r,rightExpression:r.value==="."?this.extractOperand():this.expression_bp(a.right)})}catch(o){throw o instanceof T?(n=this.nodeFactory.create(Te,{leftExpression:n,op:r,rightExpression:o.partialNode}),new T(o.token,n,o.handlerContext)):o}}}else break}return n}leftExpression_bp(){let t;if(xn(this.peek())){const n={};n.op=this.peek();const s=Tl(n.op);if(s.right===null)throw this.logError(n.op,l.UNKNOWN_PREFIX_OP,`Unexpected '${n.op.value}' in an expression`),new T(n.op,this.nodeFactory.create(rt,{pre:n.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{n.expression=this.expression_bp(s.right)}catch(r){throw r instanceof T?(n.expression=r.partialNode,new T(r.token,this.nodeFactory.create(re,n),r.handlerContext)):r}t=this.nodeFactory.create(re,n)}else if(t=this.extractOperand(),t instanceof rt)throw new T(this.peek(),this.nodeFactory.create(rt,{pre:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return t}extractOperand(){return this.check(f.NUMERIC_LITERAL,f.STRING_LITERAL,f.COLOR_LITERAL,f.QUOTED_STRING,f.IDENTIFIER)?this.primaryExpression():this.check(f.FUNCTION_EXPRESSION)?this.functionExpression():this.check(f.LBRACKET)?this.listExpression():this.check(f.LBRACE)?this.blockExpression():this.check(f.LPAREN)?this.tupleExpression():(this.peek().kind===f.EOF?this.logError(this.peek(),l.UNEXPECTED_EOF,"Unexpected EOF"):this.logError(this.peek(),l.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(rt,{pre:this.previous()}))}functionExpression(){const t={};try{this.consume("Expect a function expression",f.FUNCTION_EXPRESSION),t.value=this.previous()}catch(n){throw n instanceof T?(t.value=n.partialNode,new T(n.token,this.nodeFactory.create(ie,t),n.handlerContext)):n}return this.nodeFactory.create(ie,t)}variable(){this.consume("Expect a variable",f.IDENTIFIER);const t=this.previous();return this.nodeFactory.create(de,{variable:t})}canBeField(){return this.peek().kind===f.IDENTIFIER&&this.peek(1).kind===f.COLON}primaryExpression(){if(this.match(f.COLOR_LITERAL,f.STRING_LITERAL,f.NUMERIC_LITERAL))return this.nodeFactory.create(Y,{expression:this.nodeFactory.create(je,{literal:this.previous()})});if(this.match(f.QUOTED_STRING,f.IDENTIFIER))return this.nodeFactory.create(Y,{expression:this.nodeFactory.create(de,{variable:this.previous()})});throw this.logError(this.peek(),l.UNEXPECTED_TOKEN,"Expect a variable or literal"),new T(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){const t={};if(this.check(f.COLON,f.RBRACKET,f.COMMA)){const n=this.peek();this.logError(n,l.EMPTY_ATTRIBUTE_NAME,"Expect a non-empty attribute name"),t.name=this.nodeFactory.create(ce,{identifiers:[]})}else try{t.name=this.attributeName()}catch(n){if(!(n instanceof T))throw n;if(t.name=n.partialNode,!this.canHandle(n))throw new T(n.token,this.nodeFactory.create(ue,t),n.handlerContext);this.synchronizeAttributeName()}return this.match(f.COLON)&&(t.colon=this.previous(),t.value=this.attributeValue()),this.nodeFactory.create(ue,t)}attributeValue(){let t;try{t=this.peek().kind===f.IDENTIFIER&&this.peek(1).kind===f.IDENTIFIER?this.attributeName():this.normalExpression()}catch(n){if(!(n instanceof T)||!this.canHandle(n))throw n;t=n.partialNode,this.synchronizeAttributeValue()}return t}attributeName(){const t=[];if(this.peek().kind!==f.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(f.COLON,f.COMMA,f.RBRACKET);)try{this.consume("Expect an identifier",f.IDENTIFIER),t.push(this.previous())}catch(n){throw n instanceof T?new T(n.token,this.nodeFactory.create(ce,{identifiers:t}),n.handlerContext):n}return this.nodeFactory.create(ce,{identifiers:t})}logError(t,n,s){this.errors.push(new c(n,s,t))}}const dl={"+":{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 El(e){return dl[e.value]||{left:null,right:null}}const Nl={"+":{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 Tl(e){return Nl[e.value]||{left:null,right:null}}const bl={"(":{left:14,right:null}};function Un(e){return bl[e.value]||{left:null,right:null}}var _=(e=>(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.Constraints="constraints",e))(_||{}),E=(e=>(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.Constraint="constraint",e.Update="update",e.Delete="delete",e))(E||{});function Oe(e){var n;const t=(n=e==null?void 0:e.type)==null?void 0:n.value.toLowerCase();switch(t){case _.Enum:case _.Table:case _.Indexes:case _.Note:case _.Project:case _.Ref:case _.TableGroup:case _.TablePartial:case _.Constraints:return new V(t);default:return new x}}function Be(e){if(!Jt(e))return new V([e]);const t=Be(e.leftExpression).unwrap_or(void 0);return t?(t.push(e.rightExpression),new V(t)):new x}function Z(e){if(e===void 0)return new x;const t=Be(e).unwrap_or(void 0);if(!t)return new x;const n=[];for(const s of t){const r=Q(s).unwrap_or(void 0);if(!r)return new x;n.push(r)}return new V(n)}function Ze(e){if(e===void 0)return new x;const t=Be(e).unwrap_or(void 0);if(!t||t.length===0)return new x;const n=[];let s;if(!W(F(t))){const r=t.pop();if(Ps(r))s=r.elementList.map(i=>j(i).unwrap());else return new x}for(const r of t){const i=Q(r).unwrap_or(void 0);if(!i)return new x;n.push(i)}return new V({variables:n,tupleElements:s})}function Q(e){return W(e)?new V(e.expression.variable.value):new x}function ut(e){if(Mn(e))return e instanceof ie?new V({functional:[e],nonFunctional:[]}):new V({functional:[],nonFunctional:[e]});if(e instanceof be&&e.elementList.every(Mn)){const t=e.elementList.filter(s=>s instanceof ie),n=e.elementList.filter(W);return new V({functional:t,nonFunctional:n})}return new x}function j(e){var n;const t=(n=e==null?void 0:e.expression.variable)==null?void 0:n.value;return t===void 0?new x:new V(t)}function ml(e){var n,s;const t=(s=(n=e==null?void 0:e.partial)==null?void 0:n.variable)==null?void 0:s.value;return t===void 0?new x:new V(t)}function C(e){return q(e)?e.expression instanceof de?new V(e.expression.variable.value):new V(e.expression.literal.value):new x}function Il(e){var t;return!(e instanceof Te)||!ys((t=e.op)==null?void 0:t.value)?!1:Ze(e.leftExpression).and_then(()=>Ze(e.rightExpression)).unwrap_or(void 0)!==void 0}function _l(e){const t=Ze(e.leftExpression),n=Ze(e.rightExpression);if(!t.isOk()||!n.isOk())return!1;const{tupleElements:s}=t.unwrap(),{tupleElements:r}=n.unwrap();return(s==null?void 0:s.length)===(r==null?void 0:r.length)}function Mn(e){return e instanceof Y&&e.expression instanceof de||e instanceof ie}function Fn(e,t){var r,i,a,o;let n=t;const s=Ho(e);for(;n;){if((i=(r=n.symbol)==null?void 0:r.symbolTable)!=null&&i.has(e))return(a=n.symbol.symbolTable)==null?void 0:a.get(e);if(((o=n.symbol)==null?void 0:o.declaration)instanceof J&&s)return n.symbol;if(n instanceof J)return;n=n.parent}}class gl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 J||Oe(this.declarationNode.parent).unwrap_or(void 0)!==_.Project?[new c(l.INVALID_CUSTOM_CONTEXT,"A custom element can only appear in a Project",this.declarationNode)]:[]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"A Custom element shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_NAME,"A Custom element shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Custom element shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof Ee)return[new c(l.UNEXPECTED_COMPLEX_BODY,"A Custom element can only have an inline field",t)];const n=[];return q(t.callee)||n.push(new c(l.INVALID_CUSTOM_ELEMENT_VALUE,"A Custom element value can only be a string",t)),t.args.length>0&&n.push(...t.args.map(s=>new c(l.INVALID_CUSTOM_ELEMENT_VALUE,"A Custom element value can only be a string",s))),n}}class We{constructor(){this.table=new Map}has(t){return this.table.has(t)}set(t,n){this.table.set(t,n)}get(t,n){return this.table.get(t)||n!==void 0&&this.set(t,n)||n}entries(){return this.table.entries()}forEach(t){return this.table.forEach(t)}}class Al{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 S?[new c(l.INVALID_PROJECT_CONTEXT,"An Enum can only appear top-level",this.declarationNode)]:[]}validateName(t){return t?vs(t)?[]:[new c(l.INVALID_NAME,"An Enum name must be of the form <enum> or <schema>.<enum>",t)]:[new c(l.NAME_NOT_FOUND,"An Enum must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}registerElement(){const t=[];this.declarationNode.symbol=this.symbolFactory.create(Ko,{declaration:this.declarationNode,symbolTable:new We});const{name:n}=this.declarationNode,s=Z(n);if(s.isOk()){const r=s.unwrap(),i=r.pop(),a=At(r,this.publicSymbolTable,this.symbolFactory),o=Ht(i);a.has(o)&&t.push(new c(l.DUPLICATE_NAME,`Enum name ${i} already exists in schema '${r.join(".")||"public"}'`,n)),a.set(o,this.declarationNode.symbol)}return t}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"An Enum shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.length===0?[new c(l.EMPTY_ENUM,"An Enum must have at least one element",this.declarationNode)]:t.flatMap(n=>{const s=[];n.callee&&!W(n.callee)&&s.push(new c(l.INVALID_ENUM_ELEMENT_NAME,"An enum field must be an identifier or a quoted identifier",n.callee));const r=[...n.args];return F(r)instanceof U?(s.push(...this.validateFieldSettings(F(r))),r.pop()):r[0]instanceof U&&(s.push(...this.validateFieldSettings(r[0])),r.shift()),r.length>0&&s.push(...r.map(i=>new c(l.INVALID_ENUM_ELEMENT,"An Enum must have only a field and optionally a setting list",i))),s.push(...this.registerField(n)),s})}validateFieldSettings(t){const n=B(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"note":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_ENUM_ELEMENT_SETTING,"'note' can only appear once",o))),a.forEach(o=>{q(o.value)||s.push(new c(l.INVALID_ENUM_ELEMENT_SETTING,"'note' must be a string",o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}registerField(t){if(t.callee&&W(t.callee)){const n=j(t.callee).unwrap(),s=zt(n),r=this.symbolFactory.create(Qo,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${n}`,a.declaration)]}i.set(s,r)}return[]}}class Ll{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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(){const t=new c(l.INVALID_INDEXES_CONTEXT,"An Indexes can only appear inside a Table or a TablePartial",this.declarationNode);if(this.declarationNode.parent instanceof J)return[t];const n=Oe(this.declarationNode.parent).unwrap_or(void 0);return n&&[_.Table,_.TablePartial].includes(n)?[]:[t]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"An Indexes shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"An Indexes shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"An Indexes shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"An Indexes must have a complex body",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[],r=[n.callee,...n.args];return F(r)instanceof U&&s.push(...this.validateFieldSetting(r.pop())),r.forEach(i=>{for(;i instanceof ae;)i.argumentList&&!ut(i.argumentList).isOk()&&s.push(new c(l.INVALID_INDEXES_FIELD,"An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such",i.argumentList)),i=i.callee;ut(i).isOk()||s.push(new c(l.INVALID_INDEXES_FIELD,"An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such",i))}),s})}validateFieldSetting(t){const n=B(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"note":case"name":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{q(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'${i}' must be a string`,o))});break;case"unique":case"pk":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{ne(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'${i}' must not have a value`,o))});break;case"type":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,"'type' can only appear once",o))),a.forEach(o=>{W(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_INDEX_SETTING,`Unknown index setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class vl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 J)&&![_.Table,_.TableGroup,_.TablePartial,_.Project].includes(Oe(this.declarationNode.parent).unwrap_or(void 0))?[new c(l.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(t){if(!(this.declarationNode.parent instanceof J))return t?[new c(l.UNEXPECTED_NAME,"A Note shouldn't have a name",t)]:[];if(!t)return[new c(l.INVALID_NAME,"Sticky note must have a name",this.declarationNode)];const n=Z(t);if(!n.isOk())return[new c(l.INVALID_NAME,"Invalid name for sticky note ",this.declarationNode)];const r=n.unwrap().join("."),i=Wo(r);return this.publicSymbolTable.has(i)?[new c(l.DUPLICATE_NAME,`Sticky note "${r}" has already been defined`,t)]:(this.publicSymbolTable.set(i,this.declarationNode.symbol),[])}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Note shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){const n=[];return t.length===0?[new c(l.EMPTY_NOTE,"A Note must have a content",this.declarationNode)]:(t.length>1&&t.slice(1).forEach(s=>n.push(new c(l.NOTE_CONTENT_REDEFINED,"A Note can only contain one string",s))),q(t[0].callee)||n.push(new c(l.INVALID_NOTE,"A Note content must be a quoted string",t[0])),t[0].args.length>0&&n.push(...t[0].args.map(s=>new c(l.INVALID_NOTE,"A Note can only contain one quoted string",s))),n)}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class yl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 S?[new c(l.INVALID_PROJECT_CONTEXT,"A Project can only appear top-level",this.declarationNode)]:[]}validateName(t){return t?He(t)?[]:[new c(l.INVALID_NAME,"A Project's name is optional or must be an identifier or a quoted identifer",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Project shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Project shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Project's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...n.map(r=>new c(l.INVALID_PROJECT_FIELD,"A Project can not have inline fields",r)),...this.validateSubElements(s)]}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class wl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 J?[]:[new c(l.INVALID_REF_CONTEXT,"A Ref must appear top-level",this.declarationNode)]}validateName(t){return t?He(t)?[]:[new c(l.INVALID_NAME,"A Ref's name is optional or must be an identifier or a quoted identifer",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Ref shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){if(t.length===0)return[new c(l.EMPTY_REF,"A Ref must have at least one field",this.declarationNode)];const n=[];return t.length>1&&n.push(...t.slice(1).map(s=>new c(l.REF_REDEFINED,"A Ref can only contain one binary relationship",s))),t.forEach(s=>{s.callee&&!Il(s.callee)&&n.push(new c(l.INVALID_REF_FIELD,"A Ref field must be a binary relationship",s.callee)),s.callee&&!_l(s.callee)&&n.push(new c(l.UNEQUAL_FIELDS_BINARY_REF,"Unequal fields in ref endpoints",s.callee));const r=[...s.args];if(F(r)instanceof U){const i=this.validateFieldSettings(F(r));n.push(...i),r.pop()}else r[0]instanceof U&&(n.push(...this.validateFieldSettings(r[0])),r.shift());r.length>0&&n.push(...r.map(i=>new c(l.INVALID_REF_FIELD,"A Ref field should only have a single binary relationship",i)))}),n}validateFieldSettings(t){const n=B(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"delete":case"update":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_REF_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{Sl(o.value)||s.push(new c(l.INVALID_REF_SETTING_VALUE,`'${i}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,o))});break;case"color":a.length>1&&s.push(...a.map(o=>new c(l.DUPLICATE_REF_SETTING,"'color' can only appear once",o))),a.forEach(o=>{Lt(o.value)||s.push(new c(l.INVALID_REF_SETTING_VALUE,"'color' must be a color literal",o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_REF_SETTING,`Unknown ref setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}function Sl(e){if(!(W(e)&&e.expression.variable.kind!==f.QUOTED_STRING)&&!(e instanceof ce))return!1;let t;if(e instanceof ce?t=$e(e).unwrap_or(""):t=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}class Pl{constructor(t,n,s){this.declarationNode=t,this.symbolFactory=s,this.publicSymbolTable=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 S?[new c(l.INVALID_TABLE_CONTEXT,"Table must appear top-level",this.declarationNode)]:[]}validateName(t){return t?t instanceof ke?[new c(l.INVALID_NAME,"Invalid array as Table name, maybe you forget to add a space between the name and the setting list?",t)]:vs(t)?[]:[new c(l.INVALID_NAME,"A Table name must be of the form <table> or <schema>.<table>",t)]:[new c(l.NAME_NOT_FOUND,"A Table must have a name",this.declarationNode)]}validateAlias(t){return t?Ul(t)?[]:[new c(l.INVALID_ALIAS,"Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes",t)]:[]}validateSettingList(t){const n=B(t),s=n.getErrors(),r=n.getValue();return Je(r,(i,a)=>{switch(a){case E.HeaderColor:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'headercolor' can only appear once",o))),i.forEach(o=>{Lt(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'headercolor' must be a color literal",o.value||o.name))});break;case E.Note:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'note' can only appear once",o))),i.forEach(o=>{q(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'note' must be a string literal",o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_SETTING,`Unknown '${a}' setting`,o)))}}),s}registerElement(){const t=[];this.declarationNode.symbol=this.symbolFactory.create(gs,{declaration:this.declarationNode,symbolTable:new We});const{name:n,alias:s}=this.declarationNode,r=Z(n);if(r.isOk()){const i=[...r.unwrap()],a=i.pop(),o=At(i,this.publicSymbolTable,this.symbolFactory),u=lt(a);o.has(u)&&t.push(new c(l.DUPLICATE_NAME,`Table name '${a}' already exists in schema '${i.join(".")||"public"}'`,n)),o.set(u,this.declarationNode.symbol)}if(s&&He(s)&&!Ol(s.expression.variable.value,r.unwrap_or([]))){const i=j(s).unwrap(),a=lt(i);this.publicSymbolTable.has(a)&&t.push(new c(l.DUPLICATE_NAME,`Table name '${i}' already exists`,n)),this.publicSymbolTable.set(a,this.declarationNode.symbol)}return t}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Table's body must be a block",t)];const[n,s,r]=t.body.reduce((i,a)=>(a instanceof y?i[0].push(a):a instanceof Re?i[1].push(a):a instanceof S&&i[2].push(a),i),[[],[],[]]);return[...this.validateFields(n),...this.validateInjections(s),...this.validateSubElements(r)]}validateInjections(t){return t.flatMap(n=>this.registerInjection(n))}registerInjection(t){var o,u,p;if(!((u=(o=t.partial)==null?void 0:o.variable)!=null&&u.value))return[];const n=(p=t.partial.variable)==null?void 0:p.value,s=Is(n),r=this.symbolFactory.create(tl,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable,a=i.get(s);return a?[new c(l.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate injection ${n}`,t),new c(l.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate injection ${n}`,a.declaration)]:(i.set(s,r),[])}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[];n.args.length===0&&s.push(new c(l.INVALID_COLUMN,"A column must have a type",n.callee)),W(n.callee)||s.push(new c(l.INVALID_COLUMN_NAME,"A column name must be an identifier or a quoted identifier",n.callee)),n.args[0]&&!Os(n.args[0])&&s.push(new c(l.INVALID_COLUMN_TYPE,"Invalid column type",n.args[0]));const r=n.args.slice(1);return s.push(...this.validateFieldSetting(r)),s.push(...this.registerField(n)),s})}registerField(t){if(t.callee&&W(t.callee)){const n=j(t.callee).unwrap(),s=_t(n),r=this.symbolFactory.create(Qt,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,a.declaration)]}i.set(s,r)}return[]}validateFieldSetting(t){if(!t.slice(0,-1).every(Pe)||!t.slice(-1).every(u=>Pe(u)||u instanceof U))return[...t.map(u=>new c(l.INVALID_COLUMN,"These fields must be some inline settings optionally ended with a setting list",u))];if(t.length===0)return[];let n;F(t)instanceof U&&(n=t.pop());const s=B(n),r=s.getErrors(),i=s.getValue();t.forEach(u=>{const p=j(u).unwrap_or("").toLowerCase();if(p!=="pk"&&p!=="unique"){r.push(new c(l.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",u));return}i[p]===void 0?i[p]=[u]:i[p].push(u)});const a=i[E.PK]||[],o=i[E.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"Either one of 'primary key' and 'pk' can appear",u))),Je(i,(u,p)=>{switch(p){case E.Note:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"note can only appear once",h))),u.forEach(h=>{q(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'note' must be a quoted string",h.value||h.name))});break;case E.Ref:u.forEach(h=>{Ss(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'ref' must be a valid unary relationship",h.value||h.name))});break;case E.PrimaryKey:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"primary key can only appear once",h))),u.forEach(h=>{ne(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'primary key' must not have a value",h.value||h.name))});break;case E.PK:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'pk' can only appear once",h))),u.forEach(h=>{h instanceof ue&&!ne(h.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'pk' must not have a value",h.value||h.name))});break;case E.NotNull:{u.length>1&&r.push(...u.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,"'not null' can only appear once",d)));const h=i[E.Null]||[];u.length>=1&&h.length>=1&&r.push(...[...u,...h].map(d=>new c(l.CONFLICTING_SETTING,"'not null' and 'null' can not be set at the same time",d))),u.forEach(d=>{ne(d.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'not null' must not have a value",d.value||d.name))});break}case E.Null:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'null' can only appear once",h))),u.forEach(h=>{ne(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'null' must not have a value",h.value||h.name))});break;case E.Unique:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'unique' can only appear once",h))),u.forEach(h=>{h instanceof ue&&!ne(h.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'unique' must not have a value",h.value||h.name))});break;case E.Increment:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'increment' can only appear once",h))),u.forEach(h=>{h instanceof ue&&!ne(h.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'increment' must not have a value",h.value||h.name))});break;case E.Default:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'default' can only appear once",h))),u.forEach(h=>{ws(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'default' must be a string literal, number literal, function expression, true, false or null",h.value||h.name))});break;case E.Constraint:u.forEach(h=>{h.value instanceof ie||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'constraint' must be a function expression",h.value||h.name))});break;default:u.forEach(h=>r.push(new c(l.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${p}'`,h)))}}),r}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=me(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())==="note"});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}}function Ol(e,t){return t.length===1&&e===t[0]}class xl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 S?[new c(l.INVALID_TABLEGROUP_CONTEXT,"TableGroup must appear top-level",this.declarationNode)]:[]}validateName(t){return t?He(t)?[]:[new c(l.INVALID_NAME,"A TableGroup name must be a single identifier",t)]:[new c(l.NAME_NOT_FOUND,"A TableGroup must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A TableGroup shouldn't have an alias",t)]:[]}registerElement(){const{name:t}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Jo,{declaration:this.declarationNode,symbolTable:new We});const n=Z(t);if(n.isOk()){const s=n.unwrap(),r=s.pop(),i=At(s,this.publicSymbolTable,this.symbolFactory),a=Yt(r);if(i.has(a))return[new c(l.DUPLICATE_NAME,`TableGroup name '${r}' already exists`,t)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(t){const n=B(t),s=n.getErrors(),r=n.getValue();return Je(r,(i,a)=>{switch(a){case"color":i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'color' can only appear once",o))),i.forEach(o=>{Lt(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'color' must be a color literal",o.value||o.name))});break;case"note":i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'note' can only appear once",o))),i.filter(o=>!q(o.value)).forEach(o=>{s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'note' must be a string literal",o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_SETTING,`Unknown '${a}' setting`,o)));break}}),s}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A TableGroup's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{const s=[];return n.callee&&!Z(n.callee).isOk()&&s.push(new c(l.INVALID_TABLEGROUP_FIELD,"A TableGroup field must be of the form <table> or <schema>.<table>",n.callee)),this.registerField(n),n.args.length>0&&s.push(...n.args.map(r=>new c(l.INVALID_TABLEGROUP_FIELD,"A TableGroup field should only have a single Table name",r))),s})}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=me(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())==="note"});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}registerField(t){if(t.callee&&W(t.callee)){const n=j(t.callee).unwrap(),s=qt(n),r=this.symbolFactory.create(Zo,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_TABLEGROUP_FIELD_NAME,`${n} already exists in the group`,t),new c(l.DUPLICATE_TABLEGROUP_FIELD_NAME,`${n} already exists in the group`,a.declaration)]}i.set(s,r)}return[]}}const Dl=["-","+"];class Rl{constructor(t,n,s){this.declarationNode=t,this.symbolFactory=s,this.publicSymbolTable=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 S?[new c(l.INVALID_TABLE_PARTIAL_CONTEXT,"TablePartial must appear top-level",this.declarationNode)]:[]}validateName(t){return t?He(t)?[]:[new c(l.INVALID_NAME,"A TablePartial name must be an identifier or a quoted identifer",t)]:[new c(l.NAME_NOT_FOUND,"A TablePartial must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A TablePartial shouldn't have an alias",t)]:[]}validateSettingList(t){const n=B(t),s=n.getErrors(),r=n.getValue();return Je(r,(i,a)=>{switch(a){case E.HeaderColor:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_PARTIAL_SETTING,`'${a}' can only appear once`,o))),i.forEach(o=>{Lt(o.value)||s.push(new c(l.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${a}' must be a color literal`,o.value||o.name))});break;case E.Note:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_PARTIAL_SETTING,`'${a}' can only appear once`,o))),i.forEach(o=>{q(o.value)||s.push(new c(l.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${a}' must be a string literal`,o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${a}' setting`,o)))}}),s}registerElement(){const{name:t}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(el,{declaration:this.declarationNode,symbolTable:new We});const n=Z(t);if(!n.isOk())return[];const s=n.unwrap(),r=s.pop(),i=At(s,this.publicSymbolTable,this.symbolFactory),a=Kt(r);return i.has(a)?[new c(l.DUPLICATE_NAME,`TablePartial name '${r}' already exists`,t)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A TablePartial's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[];n.args.length===0&&s.push(new c(l.INVALID_COLUMN,"A column must have a type",n.callee)),W(n.callee)||s.push(new c(l.INVALID_COLUMN_NAME,"A column name must be an identifier or a quoted identifier",n.callee)),n.args[0]&&!Os(n.args[0])&&s.push(new c(l.INVALID_COLUMN_TYPE,"Invalid column type",n.args[0]));const r=n.args.slice(1);return s.push(...this.validateFieldSetting(r),...this.registerField(n)),s})}registerField(t){if(!t.callee||!W(t.callee))return[];const n=j(t.callee).unwrap(),s=_t(n),r=this.symbolFactory.create(Qt,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,a.declaration)]}return i.set(s,r),[]}validateFieldSetting(t){const n=F(t);if(!t.slice(0,-1).every(Pe)||!(Pe(n)||n instanceof U))return[...t.map(p=>new c(l.INVALID_COLUMN,"These fields must be some inline settings optionally ended with a setting list",p))];if(t.length===0)return[];let s;F(t)instanceof U&&(s=t.pop());const r=B(s),i=r.getErrors(),a=r.getValue();t.forEach(p=>{const h=j(p).unwrap_or("").toLowerCase();if(h!==E.PK&&h!==E.Unique){i.push(new c(l.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",p));return}a[h]===void 0?a[h]=[p]:a[h].push(p)});const o=a[E.PK]||[],u=a[E.PrimaryKey]||[];return o.length>=1&&u.length>=1&&i.push(...[...o,...u].map(p=>new c(l.DUPLICATE_COLUMN_SETTING,"Either one of 'primary key' and 'pk' can appear",p))),Je(a,(p,h)=>{switch(h){case E.Note:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{q(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must be a quoted string`,d.value||d.name))});break;case E.Ref:p.forEach(d=>{Ss(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must be a valid unary relationship`,d.value||d.name))});break;case E.PrimaryKey:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{ne(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.PK:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.NotNull:{p.length>1&&i.push(...p.map(N=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,N)));const d=a[E.Null]||[];p.length>=1&&d.length>=1&&i.push(...[...p,...d].map(N=>new c(l.CONFLICTING_SETTING,"'not null' and 'null' can not be set at the same time",N))),p.forEach(N=>{ne(N.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,N.value||N.name))});break}case E.Null:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{ne(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.Unique:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.Increment:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.Default:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{ws(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must be a string literal, number literal, function expression, true, false or null`,d.value||d.name))});break;case E.Constraint:p.forEach(d=>{d.value instanceof ie||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'constraint' must be a function expression",d.value||d.name))});break;default:p.forEach(d=>i.push(new c(l.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${h}'`,d)))}}),i}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=me(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())===_.Note});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}}class kl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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(){const t=new c(l.INVALID_CONSTRAINTS_CONTEXT,"A Constraints can only appear inside a Table or a TablePartial",this.declarationNode);if(this.declarationNode.parent instanceof J)return[t];const n=Oe(this.declarationNode.parent).unwrap_or(void 0);return n&&[_.Table,_.TablePartial].includes(n)?[]:[t]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"A Constraints shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Constraints shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Constraints shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Constraints must have a complex body",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[],r=[n.callee,...n.args];return F(r)instanceof U&&s.push(...this.validateFieldSetting(r.pop())),(r.length>1||!(r[0]instanceof ie))&&s.push(new c(l.INVALID_CONSTRAINTS_FIELD,"A constraint field must be a function expression",n)),s})}validateFieldSetting(t){const n=B(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"name":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_CONSTRAINT_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{q(o.value)||s.push(new c(l.INVALID_CONSTRAINT_SETTING_VALUE,`'${i}' must be a string`,o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_CONSTRAINT_SETTING,`Unknown constraint setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}function me(e){switch(e.type.value.toLowerCase()){case _.Enum:return Al;case _.Table:return Pl;case _.TableGroup:return xl;case _.Project:return yl;case _.Ref:return wl;case _.Note:return vl;case _.Indexes:return Ll;case _.TablePartial:return Rl;case _.Constraints:return kl;default:return gl}}function vs(e){return!!Z(e).unwrap_or(!1)}function Ul(e){return He(e)}function He(e){return e instanceof Y&&e.expression instanceof de}function At(e,t,n){var r;e[0]==="public"&&(e=e.slice(1));let s=t;for(const i of e){let a;const o=Wt(i);if(s.has(o)){if(a=(r=s.get(o))==null?void 0:r.symbolTable,!a)throw new Error("Expect a symbol table in a schema symbol")}else{a=new We;const u=n.create(_s,{symbolTable:a});s.set(o,u)}s=a}return s}function ys(e){return e==="-"||e==="<>"||e===">"||e==="<"}function Lt(e){var n;if(!(e instanceof Y)||!(e.expression instanceof je)||((n=e.expression.literal)==null?void 0:n.kind)!==f.COLOR_LITERAL)return!1;const t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!=="#")return!1;for(let s=1;s<t.length;s+=1)if(!il(t[s]))return!1;return!0}function ne(e){return e===void 0}function ws(e){var t;return!!(q(e)||Ue(e)||Pe(e)&&["true","false","null"].includes(e.expression.variable.value.toLowerCase())||e instanceof re&&Dl.includes((t=e.op)==null?void 0:t.value)&&Ue(e.expression)||e instanceof ie)}function Ue(e){var t,n,s;return e instanceof re?((t=e.op)==null?void 0:t.value)!=="-"&&((n=e.op)==null?void 0:n.value)!=="+"?!1:Ue(e.expression):e instanceof Y&&e.expression instanceof je&&((s=e.expression.literal)==null?void 0:s.kind)===f.NUMERIC_LITERAL}function Ss(e){var n;if(!(e instanceof re)||!ys((n=e.op)==null?void 0:n.value))return!1;const t=Z(e.expression).unwrap_or(void 0);return t!==void 0&&t.length>0}function Ps(e){return e instanceof be&&e.elementList.every(W)}function Os(e){if(!(e instanceof ae||Jt(e)||e instanceof Y||e instanceof ke))return!1;if(e instanceof ae){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(n=>Ue(n)||q(n)||Pe(n)))return!1;e=e.callee}for(;e instanceof ke;){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(n=>!n.colon&&!n.value&&Ue(n.name)))return!1;e=e.array}const t=Z(e).unwrap_or(void 0);return t!==void 0&&t.length>0}function B(e){var s;const t={},n=[];if(!e)return new se({});for(const r of e.elementList){if(!r.name)continue;if(r.name instanceof Y){n.push(new c(l.INVALID_SETTINGS,"A setting name must be a stream of identifiers",r.name));continue}const i=(s=$e(r.name).unwrap_or(void 0))==null?void 0:s.toLowerCase();i&&(t[i]===void 0?t[i]=[r]:t[i].push(r))}return new se(t,n)}class Bn{constructor(t,n){this.ast=t,this.symbolFactory=n,this.publicSchemaSymbol=this.symbolFactory.create(_s,{symbolTable:new We}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){const t=[];this.ast.body.forEach(s=>{if(s.parent=this.ast,s.type===void 0)return;const r=me(s),i=new r(s,this.publicSchemaSymbol.symbolTable,this.symbolFactory);t.push(...i.validate())});const n=this.ast.body.filter(s=>Oe(s).unwrap_or(void 0)===_.Project);return n.length>1&&n.forEach(s=>t.push(new c(l.PROJECT_REDEFINED,"Only one project can exist",s))),new se(this.ast,t)}}class Le{constructor(t,n){this.declarationNode=t,this.errors=n}bind(){this.bindSettingList(this.declarationNode.attributeList,this.settingList),this.bindBody()}bindSettingList(t,n){t&&t.elementList.forEach(s=>{if(s.name instanceof Y)return;const r=$e(s.name).unwrap_or(void 0);if(!r)return;const i=n[r.toLowerCase()];i!=null&&i.shouldBind&&this.scanAndBind(s.value,i)})}bindBody(){const t=this.declarationNode;if(!t.body)return;const{body:n}=t;n instanceof Ee?n.body.forEach(s=>{if(s instanceof S){if(!s.type||Oe(this.declarationNode).unwrap_or(null)===_.TablePartial&&Oe(s).unwrap_or(null)===_.Indexes)return;const r=xs(s);new r(s,this.errors).bind()}else s instanceof y?this.bindSubfield(s):this.bindPartialInjection(s)}):this.bindSubfield(n)}bindSubfield(t){const n=[t.callee,...t.args],s=F(n);s instanceof U&&(n.pop(),this.bindSettingList(s,this.subfield.settingList));const{argBinderRules:r}=this.subfield.arg;for(let i=0;i<Math.min(n.length,r.length);i+=1)r[i].shouldBind&&this.scanAndBind(n[i],r[i])}bindPartialInjection(t){var n;(n=this.injectionBinderRule)!=null&&n.shouldBind&&this.scanAndBind(t,this.injectionBinderRule)}scanAndBind(t,n){var s,r;if(t)if(t instanceof Y){if(t.expression instanceof de&&((r=n.keywords)!=null&&r.includes((s=t.expression.variable)==null?void 0:s.value.toLowerCase())))return;this.bindFragments([t],n)}else t instanceof Te?Jt(t)?this.bindFragments(Be(t).unwrap_or([]),n):(this.scanAndBind(t.leftExpression,n),this.scanAndBind(t.rightExpression,n)):t instanceof re?this.scanAndBind(t.expression,n):t instanceof It?this.scanAndBind(t.expression,n):t instanceof be?t.elementList.forEach(i=>this.scanAndBind(i,n)):t instanceof Re&&this.bindFragments([t],n)}bindFragments(t,n){if(t.length===0)return;const s=t.length===1&&t[0]instanceof Re,r=[...n.topSubnamesSymbolKind],{remainingSubnamesSymbolKind:i}=n,a=s?-1:t.findIndex(N=>!W(N)),u=a!==-1&&Ps(t[a])?t[a]:void 0,p=a>=0?r.pop():void 0,h=t.slice(0,a===-1?void 0:a);if(h.length===0)return;const d=[];for(;r.length&&h.length;){const N=r.pop(),b=h.pop(),A=j(b).unwrap();d.unshift({index:it(A,N),referrer:b})}for(;h.length;){const N=h.pop(),b=s?ml(N).unwrap():j(N).unwrap();d.unshift({index:it(b,i),referrer:N})}return u?u.elementList.forEach(N=>this.resolveIndexStack([...d,{index:it(j(N).unwrap(),p),referrer:N}],n.ignoreNameNotFound)):this.resolveIndexStack(d,n.ignoreNameNotFound)}resolveIndexStack(t,n){if(t.length===0)throw new Error("Unreachable - An unresolved name must have at least one name component");const[s,...r]=t,i=Fn(s.index,this.declarationNode);if(i===void 0){const{kind:p,name:h}=he(s.index).unwrap();this.logError(s.referrer,`Can not find ${p} '${h}'`,n);return}i.references.push(s.referrer),s.referrer.referee=i;let a=i.symbolTable,{kind:o,name:u}=he(s.index).unwrap();for(const p of r){const{kind:h,name:d}=he(p.index).unwrap(),N=a.get(p.index);if(!N){this.logError(p.referrer,`${o} '${u}' does not have ${h} '${d}'`,n);return}if(o=h,u=d,p.referrer.referee=N,N.references.push(p.referrer),!N.symbolTable)break;a=N.symbolTable}}logError(t,n,s){s||this.errors.push(new c(l.BINDING_ERROR,n,t))}resolveInjections(t){var r;const n=(r=this.declarationNode.symbol)==null?void 0:r.symbolTable;if(!n)return;const s=new Map;n.forEach((i,a)=>{var p,h;if(!zo(a))return;const o=Fn(Yo(a),this.declarationNode),u=(h=(p=o==null?void 0:o.declaration)==null?void 0:p.symbol)==null?void 0:h.symbolTable;u&&u.forEach((d,N)=>{n.has(N)||s.set(N,{injectorFieldSymbol:d,injectorDeclaration:i.declaration})})}),s.forEach((i,a)=>{const o=rl(i.injectorFieldSymbol);if(!o)return;const u=t.create(o,i);n.set(a,u)})}}class Ml extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[]},settingList:{}},this.settingList={}}}class Fl extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class Bl extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1}]},settingList:{}},this.settingList={}}}class Vl extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class Cl extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[]},settingList:{}},this.settingList={}}}class Gl extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1}]},settingList:{}},this.settingList={}}}class $l extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Enum],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!0}]},settingList:{ref:{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1},default:{shouldBind:!1},constraint:{shouldBind:!1}}},this.settingList={},this.injectionBinderRule={shouldBind:!0,topSubnamesSymbolKind:[],remainingSubnamesSymbolKind:I.TablePartial,ignoreNameNotFound:!1}}}class Xl extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[I.Table],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1}]},settingList:{}},this.settingList={}}}class jl extends Le{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Enum],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!0}]},settingList:{ref:{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1},default:{shouldBind:!1}}},this.settingList={}}}function xs(e){switch(e.type.value.toLowerCase()){case _.Enum:return Fl;case _.Table:return $l;case _.TableGroup:return Xl;case _.Project:return Cl;case _.Ref:return Gl;case _.Note:return Vl;case _.Indexes:return Bl;case _.TablePartial:return jl;default:return Ml}}class Wl{constructor(t){this.ast=t,this.errors=[]}resolve(t){return this.ast.body.map(n=>{if(!n.type)return null;const s=xs(n),r=new s(n,this.errors);return r.resolveInjections(t),r}).forEach(n=>n==null?void 0:n.bind()),new se(this.ast,this.errors)}}class Hl{constructor(t){this.generator=t}create(t,n){return new t(n,this.generator.nextId())}}class zl{constructor(t,n){this.ast=t,this.symbolFactory=new Hl(n)}analyze(){return new Bn(this.ast,this.symbolFactory).validate().chain(n=>new Wl(n).resolve(this.symbolFactory))}validate(){return new Bn(this.ast,this.symbolFactory).validate().chain(n=>new se(n,[]))}}function Vn(e,t){const{variables:n,tupleElements:s}=Ze(e).unwrap();return s?n.length===0?{schemaName:t.schemaName,tableName:t.name,fieldNames:s}:{tableName:n.pop(),schemaName:n.pop()||null,fieldNames:s}:n.length===1?{schemaName:t.schemaName,tableName:t.name,fieldNames:[n[0]]}:{fieldNames:[n.pop()],tableName:n.pop(),schemaName:n.pop()||null}}function Ds(e){switch(e){case"<":return["1","*"];case"<>":return["*","*"];case">":return["*","1"];case"-":return["1","1"];default:throw new Error("Invalid relation op")}}function L(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 ht(e){var n;const t=(n=Be(e).unwrap_or(void 0))==null?void 0:n.pop();return t instanceof be?t.elementList.map(s=>s.referee):[t.referee]}function Ve(e){const t=Z(e).unwrap();return{name:t.pop(),schemaName:t}}function tt(e){return e.expression.literal.value}function Rs(e,t){if(Array.isArray(e)){const r=e.map(({id:a})=>a).sort().join(","),i=t.map(({id:a})=>a).sort().join(",");return r<i?`${r}-${i}`:`${i}-${r}`}const n=e.id.toString(),s=t.id.toString();return n<s?`${n}-${s}`:`${s}-${n}`}function Zt(e,t){if(Array.isArray(e)){const r=e.map(({id:a})=>a).sort(),i=t.map(({id:a})=>a).sort();return kt(r,i).every(([a,o])=>a===o)}const n=e.id,s=t.id;return n===s}function fe(e){const 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 n="";for(let s=0;s<=3;s+=1){if(this.isAtEnd()||!Ve(this.peek()))return this.errors.push(new c(l.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${n}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,q.create(f.STRING_LITERAL,t,this.current,`\\u${n}`,!0))),`\\u${n}`;n+=this.advance()}return String.fromCharCode(parseInt(n,16))}default:return this.text[this.current.offset-1]}}}var at=(e=>(e[e.ListExpression=0]="ListExpression",e[e.GroupExpression=1]="GroupExpression",e[e.BlockExpression=2]="BlockExpression",e))(at||{});class hl{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(t){this.stack.push(t),t===0&&(this.numberOfNestedLBrackets+=1),t===1&&(this.numberOfNestedLParens+=1),t===2&&(this.numberOfNestedLBraces+=1)}pop(){const t=this.stack.pop();return t===0&&(this.numberOfNestedLBrackets-=1),t===1&&(this.numberOfNestedLParens-=1),t===2&&(this.numberOfNestedLBraces-=1),t}top(){return M(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(t,n){return()=>{this.push(t);try{return n()}finally{this.pop()}}}findHandlerContext(t,n){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let s=n;s<t.length-1;s+=1)switch(t[s].kind){case f.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(i=>[1,0].includes(i));break;case f.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case f.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case f.RBRACKET:if(this.isWithinListExpressionContext())return 0;break}}}class fl{constructor(t){this.generator=t}create(t,n){return new t(n,this.generator.nextId())}}class T{constructor(t,n,s){this.token=t,this.partialNode=n,this.handlerContext=s}}class pl{constructor(t,n){this.current=0,this.errors=[],this.contextStack=new hl,this.synchronizeProgram=()=>{const s=this.peek();s.kind!==f.EOF?g(this.advance()):(g(this.peek()),this.logError(s,l.UNEXPECTED_EOF,"Unexpected EOF"))},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){const s=this.peek();if(Ft(s)||this.check(f.COLON,f.LBRACE,f.LBRACKET))break;g(s),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.COLON,f.LBRACE,f.LBRACKET))break;g(s),this.advance()}},this.blockExpression=this.contextStack.withContextDo(at.BlockExpression,()=>{const s={body:[]},r=()=>this.nodeFactory.create(Ee,s);try{this.consume("Expect an opening brace '{'",f.LBRACE),s.blockOpenBrace=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.blockOpenBrace=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(f.RBRACE);)try{if(this.match(f.TILDE)){const i=this.previous(),a=this.variable(),o=this.nodeFactory.create(ke,{op:i,partial:a});s.body.push(o)}else s.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(i){if(!(i instanceof T))throw i;if(s.body.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}try{this.consume("Expect a closing brace '}'",f.RBRACE),s.blockCloseBrace=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.blockCloseBrace=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}return r()}),this.synchronizeBlock=()=>{if(!this.check(f.RBRACE))for(g(this.advance());!this.isAtEnd();){const s=this.peek();if(this.check(f.RBRACE)||Dn(this.previous(),s))break;g(s),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(at.GroupExpression,()=>{const s={elementList:[],commaList:[]},r=()=>this.nodeFactory.create(jt,{groupOpenParen:s.tupleOpenParen,groupCloseParen:s.tupleCloseParen,expression:s.elementList[0]}),i=()=>this.nodeFactory.create(be,s);try{this.consume("Expect an opening parenthesis '('",f.LPAREN),s.tupleOpenParen=this.previous()}catch(a){if(!(a instanceof T))throw a;if(s.tupleOpenParen=a.partialNode,!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(f.RPAREN))try{s.elementList.push(this.normalExpression())}catch(a){if(!(a instanceof T))throw a;if(s.elementList.push(a.partialNode),!this.canHandle(a))throw new T(a.token,r(),a.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(f.RPAREN);)try{this.consume("Expect a comma ','",f.COMMA),s.commaList.push(this.previous()),s.elementList.push(this.normalExpression())}catch(a){if(!(a instanceof T))throw a;if(a.partialNode instanceof k&&s.elementList.push(a.partialNode),!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}try{this.consume("Expect a closing parenthesis ')'",f.RPAREN),s.tupleCloseParen=this.previous()}catch(a){if(!(a instanceof T))throw a;if(s.tupleCloseParen=a.partialNode,!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}return s.elementList.length===1?r():i()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.RPAREN,f.COMMA))break;g(s),this.advance()}},this.listExpression=this.contextStack.withContextDo(at.ListExpression,()=>{const s={elementList:[],commaList:[]},r=()=>this.nodeFactory.create(R,s);try{this.consume("Expect an opening bracket '['",f.LBRACKET),s.listOpenBracket=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.listOpenBracket=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(f.RBRACKET))try{s.elementList.push(this.attribute())}catch(i){if(!(i instanceof T))throw i;if(s.elementList.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(f.RBRACKET);)try{this.consume("Expect a comma ','",f.COMMA),s.commaList.push(this.previous()),s.elementList.push(this.attribute())}catch(i){if(!(i instanceof T))throw i;if(i.partialNode instanceof k&&s.elementList.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}try{this.consume("Expect a closing bracket ']'",f.RBRACKET),s.listCloseBracket=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.listCloseBracket=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}return r()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.COMMA,f.RBRACKET))break;g(s),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.COMMA,f.RBRACKET,f.COLON))break;g(s),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(f.COMMA,f.RBRACKET))break;g(s),this.advance()}},this.tokens=t,this.nodeFactory=new fl(n)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===f.EOF}advance(){return this.isAtEnd()?M(this.tokens):this.tokens[this.current++]}peek(t=0){return t+this.current>=this.tokens.length?M(this.tokens):this.tokens[this.current+t]}match(...t){const n=this.check(...t);return n&&this.advance(),n}check(...t){const n=this.peek();return t.includes(n.kind)}previous(){return this.tokens[this.current-1]}canHandle(t){return t.handlerContext===void 0||t.handlerContext===this.contextStack.top()}consume(t,...n){if(!this.match(...n))throw this.logError(this.peek(),l.UNEXPECTED_TOKEN,t),new T(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(t,...n){if(this.isAtEnd()||!this.check(...n)){for(g(this.peek()),this.logError(this.advance(),l.UNEXPECTED_TOKEN,t);!this.isAtEnd()&&!this.check(...n);)g(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){const t=[],n=[];let s,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)n.push(this.tokens[r]);for(s=this.tokens[r],s.leadingInvalid=n,t.push(s),r+=1;r<this.tokens.length;r+=1){const i=this.tokens[r];i.isInvalid?s.trailingInvalid.push(i):(s=i,t.push(s))}this.tokens=t}parse(){const t=this.program(),n=this.advance(),s=this.nodeFactory.create(J,{body:t,eof:n});return this.gatherInvalid(),new se({ast:s,tokens:this.tokens},this.errors)}program(){const t=[];for(;!this.isAtEnd();)try{const n=this.elementDeclaration();t.push(n)}catch(n){if(!(n instanceof T))throw n;t.push(n.partialNode),this.synchronizeProgram()}return t}elementDeclaration(){const t={},n=()=>this.nodeFactory.create(S,t);try{this.consume("Expect an identifier",f.IDENTIFIER),t.type=this.previous()}catch(s){throw s instanceof T?(t.type=s.partialNode,new T(s.token,n(),s.handlerContext)):s}if(!this.check(f.COLON,f.LBRACE,f.LBRACKET))try{t.name=this.normalExpression()}catch(s){if(!(s instanceof T))throw s;if(t.name=s.partialNode,!this.canHandle(s))throw new T(s.token,n(),s.handlerContext);this.synchronizeElementDeclarationName()}if(Ft(this.peek()))if(t.as=this.advance(),this.check(f.COLON,f.LBRACE,f.LBRACKET))this.logError(this.peek(),l.UNEXPECTED_TOKEN,"Expect an alias");else try{t.alias=this.normalExpression()}catch(s){if(!(s instanceof T))throw s;if(t.alias=s.partialNode,!this.canHandle(s))throw new T(s.token,n(),s.handlerContext);this.synchronizeElementDeclarationAlias()}try{t.attributeList=this.check(f.LBRACKET)?this.listExpression():void 0}catch(s){throw s instanceof T?(t.attributeList=s.partialNode,new T(s.token,n(),s.handlerContext)):s}if(!this.discardUntil("Expect an opening brace '{' or a colon ':'",f.LBRACE,f.COLON))return n();try{if(this.match(f.COLON)){t.bodyColon=this.previous();const s=this.expression();s instanceof S?(g(s),this.logError(s,l.UNEXPECTED_ELEMENT_DECLARATION,"An element's simple body must not be an element declaration")):t.body=s}else t.body=this.blockExpression()}catch(s){throw s instanceof T?(t.body=s.partialNode,new T(s.token,n(),s.handlerContext)):s}return this.nodeFactory.create(S,t)}fieldDeclaration(){const t={},n=()=>this.nodeFactory.create(S,t);try{this.consume("Expect an identifier",f.IDENTIFIER),t.type=this.previous()}catch(s){throw s instanceof T?(t.type=s.partialNode,new T(s.token,n(),s.handlerContext)):s}try{this.consume("Expect a colon ':'",f.COLON),t.bodyColon=this.previous()}catch(s){throw s instanceof T?(t.bodyColon=s.partialNode,new T(s.token,n(),s.handlerContext)):s}try{const s=this.expression();s instanceof S?this.errors.push(new c(l.INVALID_ELEMENT_IN_SIMPLE_BODY,"Simple body cannot be an element declaration",s)):t.body=s}catch(s){throw s instanceof T?(t.body=s.partialNode,new T(s.token,n(),s.handlerContext)):s}return this.nodeFactory.create(S,t)}expression(){const t={args:[]},n=()=>al(t.callee,t.args,this.nodeFactory).unwrap_or(this.nodeFactory.create(y,t));try{t.callee=this.normalExpression()}catch(r){throw r instanceof T?(t.callee=r.partialNode,new T(r.token,n(),r.handlerContext)):r}if(this.shouldStopExpression())return n();let s=t.callee;for(;!this.shouldStopExpression();){Ut(this.previous())||this.logError(s,l.MISSING_SPACES,"Expect a following space");try{s=this.normalExpression(),t.args.push(s)}catch(r){throw r instanceof T?(s=r.partialNode,t.args.push(s),new T(r.token,n(),r.handlerContext)):r}}return n()}shouldStopExpression(){if(this.isAtEnd()||Ns(this.previous()))return!0;const t=this.peek().kind;return t===f.RBRACE||t===f.RBRACKET||t===f.RPAREN||t===f.COMMA||t===f.COLON}normalExpression(){return this.expression_bp(0)}expression_bp(t){let n=this.leftExpression_bp();for(;!this.isAtEnd();){const s=this.peek();if(s.kind===f.LPAREN){const{left:r}=Un(s);if(r<t||Dn(this.previous(),s)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{n=this.nodeFactory.create(ae,{callee:n,argumentList:this.tupleExpression()})}catch(i){throw i instanceof T?(n=this.nodeFactory.create(ae,{callee:n,argumentList:i.partialNode}),new T(i.token,n,i.handlerContext)):i}}else if(s.kind===f.LBRACKET){if(Ut(this.previous()))break;try{n=this.nodeFactory.create(Re,{expression:n,indexer:this.listExpression()})}catch(r){throw r instanceof T?(n=this.nodeFactory.create(Re,{expression:n,indexer:r.partialNode}),new T(r.token,n,r.handlerContext)):r}}else if(xn(s)){const r=s,i=Un(r);if(i.left!==null){if(i.left<=t)break;this.advance(),n=this.nodeFactory.create(It,{expression:n,op:r})}else{const a=El(r);if(a.left===null||a.left<=t)break;this.advance();try{n=this.nodeFactory.create(Te,{leftExpression:n,op:r,rightExpression:r.value==="."?this.extractOperand():this.expression_bp(a.right)})}catch(o){throw o instanceof T?(n=this.nodeFactory.create(Te,{leftExpression:n,op:r,rightExpression:o.partialNode}),new T(o.token,n,o.handlerContext)):o}}}else break}return n}leftExpression_bp(){let t;if(xn(this.peek())){const n={};n.op=this.peek();const s=Tl(n.op);if(s.right===null)throw this.logError(n.op,l.UNKNOWN_PREFIX_OP,`Unexpected '${n.op.value}' in an expression`),new T(n.op,this.nodeFactory.create(rt,{pre:n.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{n.expression=this.expression_bp(s.right)}catch(r){throw r instanceof T?(n.expression=r.partialNode,new T(r.token,this.nodeFactory.create(re,n),r.handlerContext)):r}t=this.nodeFactory.create(re,n)}else if(t=this.extractOperand(),t instanceof rt)throw new T(this.peek(),this.nodeFactory.create(rt,{pre:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return t}extractOperand(){return this.check(f.NUMERIC_LITERAL,f.STRING_LITERAL,f.COLOR_LITERAL,f.QUOTED_STRING,f.IDENTIFIER)?this.primaryExpression():this.check(f.FUNCTION_EXPRESSION)?this.functionExpression():this.check(f.LBRACKET)?this.listExpression():this.check(f.LBRACE)?this.blockExpression():this.check(f.LPAREN)?this.tupleExpression():(this.peek().kind===f.EOF?this.logError(this.peek(),l.UNEXPECTED_EOF,"Unexpected EOF"):this.logError(this.peek(),l.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(rt,{pre:this.previous()}))}functionExpression(){const t={};try{this.consume("Expect a function expression",f.FUNCTION_EXPRESSION),t.value=this.previous()}catch(n){throw n instanceof T?(t.value=n.partialNode,new T(n.token,this.nodeFactory.create(ie,t),n.handlerContext)):n}return this.nodeFactory.create(ie,t)}variable(){this.consume("Expect a variable",f.IDENTIFIER);const t=this.previous();return this.nodeFactory.create(de,{variable:t})}canBeField(){return this.peek().kind===f.IDENTIFIER&&this.peek(1).kind===f.COLON}primaryExpression(){if(this.match(f.COLOR_LITERAL,f.STRING_LITERAL,f.NUMERIC_LITERAL))return this.nodeFactory.create(z,{expression:this.nodeFactory.create(je,{literal:this.previous()})});if(this.match(f.QUOTED_STRING,f.IDENTIFIER))return this.nodeFactory.create(z,{expression:this.nodeFactory.create(de,{variable:this.previous()})});throw this.logError(this.peek(),l.UNEXPECTED_TOKEN,"Expect a variable or literal"),new T(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){const t={};if(this.check(f.COLON,f.RBRACKET,f.COMMA)){const n=this.peek();this.logError(n,l.EMPTY_ATTRIBUTE_NAME,"Expect a non-empty attribute name"),t.name=this.nodeFactory.create(ce,{identifiers:[]})}else try{t.name=this.attributeName()}catch(n){if(!(n instanceof T))throw n;if(t.name=n.partialNode,!this.canHandle(n))throw new T(n.token,this.nodeFactory.create(ue,t),n.handlerContext);this.synchronizeAttributeName()}return this.match(f.COLON)&&(t.colon=this.previous(),t.value=this.attributeValue()),this.nodeFactory.create(ue,t)}attributeValue(){let t;try{t=this.peek().kind===f.IDENTIFIER&&this.peek(1).kind===f.IDENTIFIER?this.attributeName():this.normalExpression()}catch(n){if(!(n instanceof T)||!this.canHandle(n))throw n;t=n.partialNode,this.synchronizeAttributeValue()}return t}attributeName(){const t=[];if(this.peek().kind!==f.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(f.COLON,f.COMMA,f.RBRACKET);)try{this.consume("Expect an identifier",f.IDENTIFIER),t.push(this.previous())}catch(n){throw n instanceof T?new T(n.token,this.nodeFactory.create(ce,{identifiers:t}),n.handlerContext):n}return this.nodeFactory.create(ce,{identifiers:t})}logError(t,n,s){this.errors.push(new c(n,s,t))}}const dl={"+":{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 El(e){return dl[e.value]||{left:null,right:null}}const Nl={"+":{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 Tl(e){return Nl[e.value]||{left:null,right:null}}const bl={"(":{left:14,right:null}};function Un(e){return bl[e.value]||{left:null,right:null}}var b=(e=>(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))(b||{}),E=(e=>(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))(E||{});function Oe(e){var n;const t=(n=e==null?void 0:e.type)==null?void 0:n.value.toLowerCase();switch(t){case b.Enum:case b.Table:case b.Indexes:case b.Note:case b.Project:case b.Ref:case b.TableGroup:case b.TablePartial:case b.Check:return new B(t);default:return new x}}function Be(e){if(!Jt(e))return new B([e]);const t=Be(e.leftExpression).unwrap_or(void 0);return t?(t.push(e.rightExpression),new B(t)):new x}function Z(e){if(e===void 0)return new x;const t=Be(e).unwrap_or(void 0);if(!t)return new x;const n=[];for(const s of t){const r=Q(s).unwrap_or(void 0);if(!r)return new x;n.push(r)}return new B(n)}function Ze(e){if(e===void 0)return new x;const t=Be(e).unwrap_or(void 0);if(!t||t.length===0)return new x;const n=[];let s;if(!W(M(t))){const r=t.pop();if(Ps(r))s=r.elementList.map(i=>j(i).unwrap());else return new x}for(const r of t){const i=Q(r).unwrap_or(void 0);if(!i)return new x;n.push(i)}return new B({variables:n,tupleElements:s})}function Q(e){return W(e)?new B(e.expression.variable.value):new x}function ut(e){if(Mn(e))return e instanceof ie?new B({functional:[e],nonFunctional:[]}):new B({functional:[],nonFunctional:[e]});if(e instanceof be&&e.elementList.every(Mn)){const t=e.elementList.filter(s=>s instanceof ie),n=e.elementList.filter(W);return new B({functional:t,nonFunctional:n})}return new x}function j(e){var n;const t=(n=e==null?void 0:e.expression.variable)==null?void 0:n.value;return t===void 0?new x:new B(t)}function ml(e){var n,s;const t=(s=(n=e==null?void 0:e.partial)==null?void 0:n.variable)==null?void 0:s.value;return t===void 0?new x:new B(t)}function C(e){return Y(e)?e.expression instanceof de?new B(e.expression.variable.value):new B(e.expression.literal.value):new x}function Il(e){var t;return!(e instanceof Te)||!ys((t=e.op)==null?void 0:t.value)?!1:Ze(e.leftExpression).and_then(()=>Ze(e.rightExpression)).unwrap_or(void 0)!==void 0}function _l(e){const t=Ze(e.leftExpression),n=Ze(e.rightExpression);if(!t.isOk()||!n.isOk())return!1;const{tupleElements:s}=t.unwrap(),{tupleElements:r}=n.unwrap();return(s==null?void 0:s.length)===(r==null?void 0:r.length)}function Mn(e){return e instanceof z&&e.expression instanceof de||e instanceof ie}function Fn(e,t){var r,i,a,o;let n=t;const s=Ho(e);for(;n;){if((i=(r=n.symbol)==null?void 0:r.symbolTable)!=null&&i.has(e))return(a=n.symbol.symbolTable)==null?void 0:a.get(e);if(((o=n.symbol)==null?void 0:o.declaration)instanceof J&&s)return n.symbol;if(n instanceof J)return;n=n.parent}}class gl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 J||Oe(this.declarationNode.parent).unwrap_or(void 0)!==b.Project?[new c(l.INVALID_CUSTOM_CONTEXT,"A Custom element can only appear in a Project",this.declarationNode)]:[]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"A Custom element shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_NAME,"A Custom element shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Custom element shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof Ee)return[new c(l.UNEXPECTED_COMPLEX_BODY,"A Custom element can only have an inline field",t)];const n=[];return Y(t.callee)||n.push(new c(l.INVALID_CUSTOM_ELEMENT_VALUE,"A Custom element value can only be a string",t)),t.args.length>0&&n.push(...t.args.map(s=>new c(l.INVALID_CUSTOM_ELEMENT_VALUE,"A Custom element value can only be a string",s))),n}}class We{constructor(){this.table=new Map}has(t){return this.table.has(t)}set(t,n){this.table.set(t,n)}get(t,n){return this.table.get(t)||n!==void 0&&this.set(t,n)||n}entries(){return this.table.entries()}forEach(t){return this.table.forEach(t)}}class Al{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 S?[new c(l.INVALID_PROJECT_CONTEXT,"An Enum can only appear top-level",this.declarationNode)]:[]}validateName(t){return t?vs(t)?[]:[new c(l.INVALID_NAME,"An Enum name must be of the form <enum> or <schema>.<enum>",t)]:[new c(l.NAME_NOT_FOUND,"An Enum must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}registerElement(){const t=[];this.declarationNode.symbol=this.symbolFactory.create(qo,{declaration:this.declarationNode,symbolTable:new We});const{name:n}=this.declarationNode,s=Z(n);if(s.isOk()){const r=s.unwrap(),i=r.pop(),a=At(r,this.publicSymbolTable,this.symbolFactory),o=Ht(i);a.has(o)&&t.push(new c(l.DUPLICATE_NAME,`Enum name ${i} already exists in schema '${r.join(".")||"public"}'`,n)),a.set(o,this.declarationNode.symbol)}return t}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"An Enum shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.length===0?[new c(l.EMPTY_ENUM,"An Enum must have at least one element",this.declarationNode)]:t.flatMap(n=>{const s=[];n.callee&&!W(n.callee)&&s.push(new c(l.INVALID_ENUM_ELEMENT_NAME,"An enum field must be an identifier or a quoted identifier",n.callee));const r=[...n.args];return M(r)instanceof R?(s.push(...this.validateFieldSettings(M(r))),r.pop()):r[0]instanceof R&&(s.push(...this.validateFieldSettings(r[0])),r.shift()),r.length>0&&s.push(...r.map(i=>new c(l.INVALID_ENUM_ELEMENT,"An Enum must have only a field and optionally a setting list",i))),s.push(...this.registerField(n)),s})}validateFieldSettings(t){const n=F(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"note":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_ENUM_ELEMENT_SETTING,"'note' can only appear once",o))),a.forEach(o=>{Y(o.value)||s.push(new c(l.INVALID_ENUM_ELEMENT_SETTING,"'note' must be a string",o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}registerField(t){if(t.callee&&W(t.callee)){const n=j(t.callee).unwrap(),s=Kt(n),r=this.symbolFactory.create(Qo,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${n}`,a.declaration)]}i.set(s,r)}return[]}}class Ll{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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(){const t=new c(l.INVALID_INDEXES_CONTEXT,"An Indexes can only appear inside a Table or a TablePartial",this.declarationNode);if(this.declarationNode.parent instanceof J)return[t];const n=Oe(this.declarationNode.parent).unwrap_or(void 0);return n&&[b.Table,b.TablePartial].includes(n)?[]:[t]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"An Indexes shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"An Indexes shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"An Indexes shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"An Indexes must have a complex body",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[],r=[n.callee,...n.args];return M(r)instanceof R&&s.push(...this.validateFieldSetting(r.pop())),r.forEach(i=>{for(;i instanceof ae;)i.argumentList&&!ut(i.argumentList).isOk()&&s.push(new c(l.INVALID_INDEXES_FIELD,"An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such",i.argumentList)),i=i.callee;ut(i).isOk()||s.push(new c(l.INVALID_INDEXES_FIELD,"An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such",i))}),s})}validateFieldSetting(t){const n=F(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"note":case"name":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{Y(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'${i}' must be a string`,o))});break;case"unique":case"pk":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{ne(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'${i}' must not have a value`,o))});break;case"type":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,"'type' can only appear once",o))),a.forEach(o=>{W(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_INDEX_SETTING,`Unknown index setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class vl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 J)&&![b.Table,b.TableGroup,b.TablePartial,b.Project].includes(Oe(this.declarationNode.parent).unwrap_or(void 0))?[new c(l.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(t){if(!(this.declarationNode.parent instanceof J))return t?[new c(l.UNEXPECTED_NAME,"A Note shouldn't have a name",t)]:[];if(!t)return[new c(l.INVALID_NAME,"Sticky note must have a name",this.declarationNode)];const n=Z(t);if(!n.isOk())return[new c(l.INVALID_NAME,"Invalid name for sticky note ",this.declarationNode)];const r=n.unwrap().join("."),i=Wo(r);return this.publicSymbolTable.has(i)?[new c(l.DUPLICATE_NAME,`Sticky note "${r}" has already been defined`,t)]:(this.publicSymbolTable.set(i,this.declarationNode.symbol),[])}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Note shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){const n=[];return t.length===0?[new c(l.EMPTY_NOTE,"A Note must have a content",this.declarationNode)]:(t.length>1&&t.slice(1).forEach(s=>n.push(new c(l.NOTE_CONTENT_REDEFINED,"A Note can only contain one string",s))),Y(t[0].callee)||n.push(new c(l.INVALID_NOTE,"A Note content must be a quoted string",t[0])),t[0].args.length>0&&n.push(...t[0].args.map(s=>new c(l.INVALID_NOTE,"A Note can only contain one quoted string",s))),n)}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class yl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 S?[new c(l.INVALID_PROJECT_CONTEXT,"A Project can only appear top-level",this.declarationNode)]:[]}validateName(t){return t?He(t)?[]:[new c(l.INVALID_NAME,"A Project's name is optional or must be an identifier or a quoted identifer",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Project shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Project shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Project's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...n.map(r=>new c(l.INVALID_PROJECT_FIELD,"A Project can not have inline fields",r)),...this.validateSubElements(s)]}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class wl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 J?[]:[new c(l.INVALID_REF_CONTEXT,"A Ref must appear top-level",this.declarationNode)]}validateName(t){return t?He(t)?[]:[new c(l.INVALID_NAME,"A Ref's name is optional or must be an identifier or a quoted identifer",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Ref shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){if(t.length===0)return[new c(l.EMPTY_REF,"A Ref must have at least one field",this.declarationNode)];const n=[];return t.length>1&&n.push(...t.slice(1).map(s=>new c(l.REF_REDEFINED,"A Ref can only contain one binary relationship",s))),t.forEach(s=>{s.callee&&!Il(s.callee)&&n.push(new c(l.INVALID_REF_FIELD,"A Ref field must be a binary relationship",s.callee)),s.callee&&!_l(s.callee)&&n.push(new c(l.UNEQUAL_FIELDS_BINARY_REF,"Unequal fields in ref endpoints",s.callee));const r=[...s.args];if(M(r)instanceof R){const i=this.validateFieldSettings(M(r));n.push(...i),r.pop()}else r[0]instanceof R&&(n.push(...this.validateFieldSettings(r[0])),r.shift());r.length>0&&n.push(...r.map(i=>new c(l.INVALID_REF_FIELD,"A Ref field should only have a single binary relationship",i)))}),n}validateFieldSettings(t){const n=F(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"delete":case"update":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_REF_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{Sl(o.value)||s.push(new c(l.INVALID_REF_SETTING_VALUE,`'${i}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,o))});break;case"color":a.length>1&&s.push(...a.map(o=>new c(l.DUPLICATE_REF_SETTING,"'color' can only appear once",o))),a.forEach(o=>{Lt(o.value)||s.push(new c(l.INVALID_REF_SETTING_VALUE,"'color' must be a color literal",o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_REF_SETTING,`Unknown ref setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}function Sl(e){if(!(W(e)&&e.expression.variable.kind!==f.QUOTED_STRING)&&!(e instanceof ce))return!1;let t;if(e instanceof ce?t=$e(e).unwrap_or(""):t=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}class Pl{constructor(t,n,s){this.declarationNode=t,this.symbolFactory=s,this.publicSymbolTable=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 S?[new c(l.INVALID_TABLE_CONTEXT,"Table must appear top-level",this.declarationNode)]:[]}validateName(t){return t?t instanceof Re?[new c(l.INVALID_NAME,"Invalid array as Table name, maybe you forget to add a space between the name and the setting list?",t)]:vs(t)?[]:[new c(l.INVALID_NAME,"A Table name must be of the form <table> or <schema>.<table>",t)]:[new c(l.NAME_NOT_FOUND,"A Table must have a name",this.declarationNode)]}validateAlias(t){return t?Ul(t)?[]:[new c(l.INVALID_ALIAS,"Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes",t)]:[]}validateSettingList(t){const n=F(t),s=n.getErrors(),r=n.getValue();return Je(r,(i,a)=>{switch(a){case E.HeaderColor:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'headercolor' can only appear once",o))),i.forEach(o=>{Lt(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'headercolor' must be a color literal",o.value||o.name))});break;case E.Note:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'note' can only appear once",o))),i.forEach(o=>{Y(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'note' must be a string literal",o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_SETTING,`Unknown '${a}' setting`,o)))}}),s}registerElement(){const t=[];this.declarationNode.symbol=this.symbolFactory.create(gs,{declaration:this.declarationNode,symbolTable:new We});const{name:n,alias:s}=this.declarationNode,r=Z(n);if(r.isOk()){const i=[...r.unwrap()],a=i.pop(),o=At(i,this.publicSymbolTable,this.symbolFactory),u=lt(a);o.has(u)&&t.push(new c(l.DUPLICATE_NAME,`Table name '${a}' already exists in schema '${i.join(".")||"public"}'`,n)),o.set(u,this.declarationNode.symbol)}if(s&&He(s)&&!Ol(s.expression.variable.value,r.unwrap_or([]))){const i=j(s).unwrap(),a=lt(i);this.publicSymbolTable.has(a)&&t.push(new c(l.DUPLICATE_NAME,`Table name '${i}' already exists`,n)),this.publicSymbolTable.set(a,this.declarationNode.symbol)}return t}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Table's body must be a block",t)];const[n,s,r]=t.body.reduce((i,a)=>(a instanceof y?i[0].push(a):a instanceof ke?i[1].push(a):a instanceof S&&i[2].push(a),i),[[],[],[]]);return[...this.validateFields(n),...this.validateInjections(s),...this.validateSubElements(r)]}validateInjections(t){return t.flatMap(n=>this.registerInjection(n))}registerInjection(t){var o,u,p;if(!((u=(o=t.partial)==null?void 0:o.variable)!=null&&u.value))return[];const n=(p=t.partial.variable)==null?void 0:p.value,s=Is(n),r=this.symbolFactory.create(tl,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable,a=i.get(s);return a?[new c(l.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate injection ${n}`,t),new c(l.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate injection ${n}`,a.declaration)]:(i.set(s,r),[])}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[];n.args.length===0&&s.push(new c(l.INVALID_COLUMN,"A column must have a type",n.callee)),W(n.callee)||s.push(new c(l.INVALID_COLUMN_NAME,"A column name must be an identifier or a quoted identifier",n.callee)),n.args[0]&&!Os(n.args[0])&&s.push(new c(l.INVALID_COLUMN_TYPE,"Invalid column type",n.args[0]));const r=n.args.slice(1);return s.push(...this.validateFieldSetting(r)),s.push(...this.registerField(n)),s})}registerField(t){if(t.callee&&W(t.callee)){const n=j(t.callee).unwrap(),s=_t(n),r=this.symbolFactory.create(Qt,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,a.declaration)]}i.set(s,r)}return[]}validateFieldSetting(t){if(!t.slice(0,-1).every(Pe)||!t.slice(-1).every(u=>Pe(u)||u instanceof R))return[...t.map(u=>new c(l.INVALID_COLUMN,"These fields must be some inline settings optionally ended with a setting list",u))];if(t.length===0)return[];let n;M(t)instanceof R&&(n=t.pop());const s=F(n),r=s.getErrors(),i=s.getValue();t.forEach(u=>{const p=j(u).unwrap_or("").toLowerCase();if(p!=="pk"&&p!=="unique"){r.push(new c(l.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",u));return}i[p]===void 0?i[p]=[u]:i[p].push(u)});const a=i[E.PK]||[],o=i[E.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"Either one of 'primary key' and 'pk' can appear",u))),Je(i,(u,p)=>{switch(p){case E.Note:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"note can only appear once",h))),u.forEach(h=>{Y(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'note' must be a quoted string",h.value||h.name))});break;case E.Ref:u.forEach(h=>{Ss(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'ref' must be a valid unary relationship",h.value||h.name))});break;case E.PrimaryKey:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"primary key can only appear once",h))),u.forEach(h=>{ne(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'primary key' must not have a value",h.value||h.name))});break;case E.PK:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'pk' can only appear once",h))),u.forEach(h=>{h instanceof ue&&!ne(h.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'pk' must not have a value",h.value||h.name))});break;case E.NotNull:{u.length>1&&r.push(...u.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,"'not null' can only appear once",d)));const h=i[E.Null]||[];u.length>=1&&h.length>=1&&r.push(...[...u,...h].map(d=>new c(l.CONFLICTING_SETTING,"'not null' and 'null' can not be set at the same time",d))),u.forEach(d=>{ne(d.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'not null' must not have a value",d.value||d.name))});break}case E.Null:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'null' can only appear once",h))),u.forEach(h=>{ne(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'null' must not have a value",h.value||h.name))});break;case E.Unique:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'unique' can only appear once",h))),u.forEach(h=>{h instanceof ue&&!ne(h.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'unique' must not have a value",h.value||h.name))});break;case E.Increment:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'increment' can only appear once",h))),u.forEach(h=>{h instanceof ue&&!ne(h.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'increment' must not have a value",h.value||h.name))});break;case E.Default:u.length>1&&r.push(...u.map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"'default' can only appear once",h))),u.forEach(h=>{ws(h.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'default' must be a string literal, number literal, function expression, true, false or null",h.value||h.name))});break;case E.Check:u.forEach(h=>{h.value instanceof ie||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'check' must be a function expression",h.value||h.name))});break;default:u.forEach(h=>r.push(new c(l.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${p}'`,h)))}}),r}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=me(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())==="note"});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}}function Ol(e,t){return t.length===1&&e===t[0]}class xl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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 S?[new c(l.INVALID_TABLEGROUP_CONTEXT,"TableGroup must appear top-level",this.declarationNode)]:[]}validateName(t){return t?He(t)?[]:[new c(l.INVALID_NAME,"A TableGroup name must be a single identifier",t)]:[new c(l.NAME_NOT_FOUND,"A TableGroup must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A TableGroup shouldn't have an alias",t)]:[]}registerElement(){const{name:t}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Jo,{declaration:this.declarationNode,symbolTable:new We});const n=Z(t);if(n.isOk()){const s=n.unwrap(),r=s.pop(),i=At(s,this.publicSymbolTable,this.symbolFactory),a=zt(r);if(i.has(a))return[new c(l.DUPLICATE_NAME,`TableGroup name '${r}' already exists`,t)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(t){const n=F(t),s=n.getErrors(),r=n.getValue();return Je(r,(i,a)=>{switch(a){case"color":i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'color' can only appear once",o))),i.forEach(o=>{Lt(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'color' must be a color literal",o.value||o.name))});break;case"note":i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'note' can only appear once",o))),i.filter(o=>!Y(o.value)).forEach(o=>{s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'note' must be a string literal",o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_SETTING,`Unknown '${a}' setting`,o)));break}}),s}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A TableGroup's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{const s=[];return n.callee&&!Z(n.callee).isOk()&&s.push(new c(l.INVALID_TABLEGROUP_FIELD,"A TableGroup field must be of the form <table> or <schema>.<table>",n.callee)),this.registerField(n),n.args.length>0&&s.push(...n.args.map(r=>new c(l.INVALID_TABLEGROUP_FIELD,"A TableGroup field should only have a single Table name",r))),s})}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=me(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())==="note"});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}registerField(t){if(t.callee&&W(t.callee)){const n=j(t.callee).unwrap(),s=Yt(n),r=this.symbolFactory.create(Zo,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_TABLEGROUP_FIELD_NAME,`${n} already exists in the group`,t),new c(l.DUPLICATE_TABLEGROUP_FIELD_NAME,`${n} already exists in the group`,a.declaration)]}i.set(s,r)}return[]}}const Dl=["-","+"];class kl{constructor(t,n,s){this.declarationNode=t,this.symbolFactory=s,this.publicSymbolTable=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 S?[new c(l.INVALID_TABLE_PARTIAL_CONTEXT,"TablePartial must appear top-level",this.declarationNode)]:[]}validateName(t){return t?He(t)?[]:[new c(l.INVALID_NAME,"A TablePartial name must be an identifier or a quoted identifer",t)]:[new c(l.NAME_NOT_FOUND,"A TablePartial must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A TablePartial shouldn't have an alias",t)]:[]}validateSettingList(t){const n=F(t),s=n.getErrors(),r=n.getValue();return Je(r,(i,a)=>{switch(a){case E.HeaderColor:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_PARTIAL_SETTING,`'${a}' can only appear once`,o))),i.forEach(o=>{Lt(o.value)||s.push(new c(l.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${a}' must be a color literal`,o.value||o.name))});break;case E.Note:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_PARTIAL_SETTING,`'${a}' can only appear once`,o))),i.forEach(o=>{Y(o.value)||s.push(new c(l.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${a}' must be a string literal`,o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${a}' setting`,o)))}}),s}registerElement(){const{name:t}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(el,{declaration:this.declarationNode,symbolTable:new We});const n=Z(t);if(!n.isOk())return[];const s=n.unwrap(),r=s.pop(),i=At(s,this.publicSymbolTable,this.symbolFactory),a=qt(r);return i.has(a)?[new c(l.DUPLICATE_NAME,`TablePartial name '${r}' already exists`,t)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A TablePartial's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[];n.args.length===0&&s.push(new c(l.INVALID_COLUMN,"A column must have a type",n.callee)),W(n.callee)||s.push(new c(l.INVALID_COLUMN_NAME,"A column name must be an identifier or a quoted identifier",n.callee)),n.args[0]&&!Os(n.args[0])&&s.push(new c(l.INVALID_COLUMN_TYPE,"Invalid column type",n.args[0]));const r=n.args.slice(1);return s.push(...this.validateFieldSetting(r),...this.registerField(n)),s})}registerField(t){if(!t.callee||!W(t.callee))return[];const n=j(t.callee).unwrap(),s=_t(n),r=this.symbolFactory.create(Qt,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,a.declaration)]}return i.set(s,r),[]}validateFieldSetting(t){const n=M(t);if(!t.slice(0,-1).every(Pe)||!(Pe(n)||n instanceof R))return[...t.map(p=>new c(l.INVALID_COLUMN,"These fields must be some inline settings optionally ended with a setting list",p))];if(t.length===0)return[];let s;M(t)instanceof R&&(s=t.pop());const r=F(s),i=r.getErrors(),a=r.getValue();t.forEach(p=>{const h=j(p).unwrap_or("").toLowerCase();if(h!==E.PK&&h!==E.Unique){i.push(new c(l.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",p));return}a[h]===void 0?a[h]=[p]:a[h].push(p)});const o=a[E.PK]||[],u=a[E.PrimaryKey]||[];return o.length>=1&&u.length>=1&&i.push(...[...o,...u].map(p=>new c(l.DUPLICATE_COLUMN_SETTING,"Either one of 'primary key' and 'pk' can appear",p))),Je(a,(p,h)=>{switch(h){case E.Note:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{Y(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must be a quoted string`,d.value||d.name))});break;case E.Ref:p.forEach(d=>{Ss(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must be a valid unary relationship`,d.value||d.name))});break;case E.PrimaryKey:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{ne(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.PK:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.NotNull:{p.length>1&&i.push(...p.map(N=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,N)));const d=a[E.Null]||[];p.length>=1&&d.length>=1&&i.push(...[...p,...d].map(N=>new c(l.CONFLICTING_SETTING,"'not null' and 'null' can not be set at the same time",N))),p.forEach(N=>{ne(N.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,N.value||N.name))});break}case E.Null:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{ne(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.Unique:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.Increment:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must not have a value`,d.value||d.name))});break;case E.Default:p.length>1&&i.push(...p.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${h}' can only appear once`,d))),p.forEach(d=>{ws(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${h}' must be a string literal, number literal, function expression, true, false or null`,d.value||d.name))});break;case E.Check:p.forEach(d=>{d.value instanceof ie||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'check' must be a function expression",d.value||d.name))});break;default:p.forEach(d=>i.push(new c(l.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${h}'`,d)))}}),i}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=me(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())===b.Note});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}}class Rl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}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(){const t=new c(l.INVALID_CHECKS_CONTEXT,"A Checks can only appear inside a Table or a TablePartial",this.declarationNode);if(this.declarationNode.parent instanceof J)return[t];const n=Oe(this.declarationNode.parent).unwrap_or(void 0);return n&&[b.Table,b.TablePartial].includes(n)?[]:[t]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"A Checks shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Checks shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Checks shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof y)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Checks must have a complex body",t)];const[n,s]=oe(t.body,r=>r instanceof y);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[],r=[n.callee,...n.args];return M(r)instanceof R&&s.push(...this.validateFieldSetting(r.pop())),(r.length>1||!(r[0]instanceof ie))&&s.push(new c(l.INVALID_CHECKS_FIELD,"A check field must be a function expression",n)),s})}validateFieldSetting(t){const n=F(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"name":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_CHECK_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{Y(o.value)||s.push(new c(l.INVALID_CHECK_SETTING_VALUE,`'${i}' must be a string`,o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_CHECK_SETTING,`Unknown check setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=me(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}function me(e){switch(e.type.value.toLowerCase()){case b.Enum:return Al;case b.Table:return Pl;case b.TableGroup:return xl;case b.Project:return yl;case b.Ref:return wl;case b.Note:return vl;case b.Indexes:return Ll;case b.TablePartial:return kl;case b.Check:return Rl;default:return gl}}function vs(e){return!!Z(e).unwrap_or(!1)}function Ul(e){return He(e)}function He(e){return e instanceof z&&e.expression instanceof de}function At(e,t,n){var r;e[0]==="public"&&(e=e.slice(1));let s=t;for(const i of e){let a;const o=Wt(i);if(s.has(o)){if(a=(r=s.get(o))==null?void 0:r.symbolTable,!a)throw new Error("Expect a symbol table in a schema symbol")}else{a=new We;const u=n.create(_s,{symbolTable:a});s.set(o,u)}s=a}return s}function ys(e){return e==="-"||e==="<>"||e===">"||e==="<"}function Lt(e){var n;if(!(e instanceof z)||!(e.expression instanceof je)||((n=e.expression.literal)==null?void 0:n.kind)!==f.COLOR_LITERAL)return!1;const t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!=="#")return!1;for(let s=1;s<t.length;s+=1)if(!il(t[s]))return!1;return!0}function ne(e){return e===void 0}function ws(e){var t;return!!(Y(e)||Ue(e)||Pe(e)&&["true","false","null"].includes(e.expression.variable.value.toLowerCase())||e instanceof re&&Dl.includes((t=e.op)==null?void 0:t.value)&&Ue(e.expression)||e instanceof ie)}function Ue(e){var t,n,s;return e instanceof re?((t=e.op)==null?void 0:t.value)!=="-"&&((n=e.op)==null?void 0:n.value)!=="+"?!1:Ue(e.expression):e instanceof z&&e.expression instanceof je&&((s=e.expression.literal)==null?void 0:s.kind)===f.NUMERIC_LITERAL}function Ss(e){var n;if(!(e instanceof re)||!ys((n=e.op)==null?void 0:n.value))return!1;const t=Z(e.expression).unwrap_or(void 0);return t!==void 0&&t.length>0}function Ps(e){return e instanceof be&&e.elementList.every(W)}function Os(e){if(!(e instanceof ae||Jt(e)||e instanceof z||e instanceof Re))return!1;if(e instanceof ae){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(n=>Ue(n)||Y(n)||Pe(n)))return!1;e=e.callee}for(;e instanceof Re;){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(n=>!n.colon&&!n.value&&Ue(n.name)))return!1;e=e.array}const t=Z(e).unwrap_or(void 0);return t!==void 0&&t.length>0}function F(e){var s;const t={},n=[];if(!e)return new se({});for(const r of e.elementList){if(!r.name)continue;if(r.name instanceof z){n.push(new c(l.INVALID_SETTINGS,"A setting name must be a stream of identifiers",r.name));continue}const i=(s=$e(r.name).unwrap_or(void 0))==null?void 0:s.toLowerCase();i&&(t[i]===void 0?t[i]=[r]:t[i].push(r))}return new se(t,n)}class Bn{constructor(t,n){this.ast=t,this.symbolFactory=n,this.publicSchemaSymbol=this.symbolFactory.create(_s,{symbolTable:new We}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){const t=[];this.ast.body.forEach(s=>{if(s.parent=this.ast,s.type===void 0)return;const r=me(s),i=new r(s,this.publicSchemaSymbol.symbolTable,this.symbolFactory);t.push(...i.validate())});const n=this.ast.body.filter(s=>Oe(s).unwrap_or(void 0)===b.Project);return n.length>1&&n.forEach(s=>t.push(new c(l.PROJECT_REDEFINED,"Only one project can exist",s))),new se(this.ast,t)}}class Ie{constructor(t,n){this.declarationNode=t,this.errors=n}bind(){this.bindSettingList(this.declarationNode.attributeList,this.settingList),this.bindBody()}bindSettingList(t,n){t&&t.elementList.forEach(s=>{if(s.name instanceof z)return;const r=$e(s.name).unwrap_or(void 0);if(!r)return;const i=n[r.toLowerCase()];i!=null&&i.shouldBind&&this.scanAndBind(s.value,i)})}bindBody(){const t=this.declarationNode;if(!t.body)return;const{body:n}=t;n instanceof Ee?n.body.forEach(s=>{if(s instanceof S){if(!s.type||Oe(this.declarationNode).unwrap_or(null)===b.TablePartial&&Oe(s).unwrap_or(null)===b.Indexes)return;const r=xs(s);new r(s,this.errors).bind()}else s instanceof y?this.bindSubfield(s):this.bindPartialInjection(s)}):this.bindSubfield(n)}bindSubfield(t){const n=[t.callee,...t.args],s=M(n);s instanceof R&&(n.pop(),this.bindSettingList(s,this.subfield.settingList));const{argBinderRules:r}=this.subfield.arg;for(let i=0;i<Math.min(n.length,r.length);i+=1)r[i].shouldBind&&this.scanAndBind(n[i],r[i])}bindPartialInjection(t){var n;(n=this.injectionBinderRule)!=null&&n.shouldBind&&this.scanAndBind(t,this.injectionBinderRule)}scanAndBind(t,n){var s,r;if(t)if(t instanceof z){if(t.expression instanceof de&&((r=n.keywords)!=null&&r.includes((s=t.expression.variable)==null?void 0:s.value.toLowerCase())))return;this.bindFragments([t],n)}else t instanceof Te?Jt(t)?this.bindFragments(Be(t).unwrap_or([]),n):(this.scanAndBind(t.leftExpression,n),this.scanAndBind(t.rightExpression,n)):t instanceof re?this.scanAndBind(t.expression,n):t instanceof It?this.scanAndBind(t.expression,n):t instanceof be?t.elementList.forEach(i=>this.scanAndBind(i,n)):t instanceof ke&&this.bindFragments([t],n)}bindFragments(t,n){if(t.length===0)return;const s=t.length===1&&t[0]instanceof ke,r=[...n.topSubnamesSymbolKind],{remainingSubnamesSymbolKind:i}=n,a=s?-1:t.findIndex(N=>!W(N)),u=a!==-1&&Ps(t[a])?t[a]:void 0,p=a>=0?r.pop():void 0,h=t.slice(0,a===-1?void 0:a);if(h.length===0)return;const d=[];for(;r.length&&h.length;){const N=r.pop(),m=h.pop(),A=j(m).unwrap();d.unshift({index:it(A,N),referrer:m})}for(;h.length;){const N=h.pop(),m=s?ml(N).unwrap():j(N).unwrap();d.unshift({index:it(m,i),referrer:N})}return u?u.elementList.forEach(N=>this.resolveIndexStack([...d,{index:it(j(N).unwrap(),p),referrer:N}],n.ignoreNameNotFound)):this.resolveIndexStack(d,n.ignoreNameNotFound)}resolveIndexStack(t,n){if(t.length===0)throw new Error("Unreachable - An unresolved name must have at least one name component");const[s,...r]=t,i=Fn(s.index,this.declarationNode);if(i===void 0){const{kind:p,name:h}=he(s.index).unwrap();this.logError(s.referrer,`Can not find ${p} '${h}'`,n);return}i.references.push(s.referrer),s.referrer.referee=i;let a=i.symbolTable,{kind:o,name:u}=he(s.index).unwrap();for(const p of r){const{kind:h,name:d}=he(p.index).unwrap(),N=a.get(p.index);if(!N){this.logError(p.referrer,`${o} '${u}' does not have ${h} '${d}'`,n);return}if(o=h,u=d,p.referrer.referee=N,N.references.push(p.referrer),!N.symbolTable)break;a=N.symbolTable}}logError(t,n,s){s||this.errors.push(new c(l.BINDING_ERROR,n,t))}resolveInjections(t){var r;const n=(r=this.declarationNode.symbol)==null?void 0:r.symbolTable;if(!n)return;const s=new Map;n.forEach((i,a)=>{var p,h;if(!Ko(a))return;const o=Fn(zo(a),this.declarationNode),u=(h=(p=o==null?void 0:o.declaration)==null?void 0:p.symbol)==null?void 0:h.symbolTable;u&&u.forEach((d,N)=>{n.has(N)||s.set(N,{injectorFieldSymbol:d,injectorDeclaration:i.declaration})})}),s.forEach((i,a)=>{const o=rl(i.injectorFieldSymbol);if(!o)return;const u=t.create(o,i);n.set(a,u)})}}class Ml extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class Fl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[]},settingList:{}},this.settingList={}}}class Bl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class Cl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[_.Table,_.Column],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!1},{shouldBind:!0,topSubnamesSymbolKind:[_.Table,_.Column],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!1},{shouldBind:!0,topSubnamesSymbolKind:[_.Table,_.Column],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!1},{shouldBind:!0,topSubnamesSymbolKind:[_.Table,_.Column],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!1}]},settingList:{}},this.settingList={}}}class Vl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class Gl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[]},settingList:{}},this.settingList={}}}class $l extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[_.Table,_.Column],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!1}]},settingList:{}},this.settingList={}}}class Xl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1},{shouldBind:!0,topSubnamesSymbolKind:[_.Enum],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!0}]},settingList:{ref:{shouldBind:!0,topSubnamesSymbolKind:[_.Table,_.Column],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!1},default:{shouldBind:!1},check:{shouldBind:!1}}},this.settingList={},this.injectionBinderRule={shouldBind:!0,topSubnamesSymbolKind:[],remainingSubnamesSymbolKind:_.TablePartial,ignoreNameNotFound:!1}}}class jl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[_.Table],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!1}]},settingList:{}},this.settingList={}}}class Wl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1},{shouldBind:!0,topSubnamesSymbolKind:[_.Enum],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!0}]},settingList:{ref:{shouldBind:!0,topSubnamesSymbolKind:[_.Table,_.Column],remainingSubnamesSymbolKind:_.Schema,ignoreNameNotFound:!1},default:{shouldBind:!1},check:{shouldBind:!1}}},this.settingList={}}}function xs(e){switch(e.type.value.toLowerCase()){case b.Enum:return Bl;case b.Table:return Xl;case b.TableGroup:return jl;case b.Project:return Gl;case b.Ref:return $l;case b.Note:return Vl;case b.Indexes:return Cl;case b.TablePartial:return Wl;case b.Check:return Ml;default:return Fl}}class Hl{constructor(t){this.ast=t,this.errors=[]}resolve(t){return this.ast.body.map(n=>{if(!n.type)return null;const s=xs(n),r=new s(n,this.errors);return r.resolveInjections(t),r}).forEach(n=>n==null?void 0:n.bind()),new se(this.ast,this.errors)}}class Kl{constructor(t){this.generator=t}create(t,n){return new t(n,this.generator.nextId())}}class zl{constructor(t,n){this.ast=t,this.symbolFactory=new Kl(n)}analyze(){return new Bn(this.ast,this.symbolFactory).validate().chain(n=>new Hl(n).resolve(this.symbolFactory))}validate(){return new Bn(this.ast,this.symbolFactory).validate().chain(n=>new se(n,[]))}}function Cn(e,t){const{variables:n,tupleElements:s}=Ze(e).unwrap();return s?n.length===0?{schemaName:t.schemaName,tableName:t.name,fieldNames:s}:{tableName:n.pop(),schemaName:n.pop()||null,fieldNames:s}:n.length===1?{schemaName:t.schemaName,tableName:t.name,fieldNames:[n[0]]}:{fieldNames:[n.pop()],tableName:n.pop(),schemaName:n.pop()||null}}function Ds(e){switch(e){case"<":return["1","*"];case"<>":return["*","*"];case">":return["*","1"];case"-":return["1","1"];default:throw new Error("Invalid relation op")}}function L(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 ht(e){var n;const t=(n=Be(e).unwrap_or(void 0))==null?void 0:n.pop();return t instanceof be?t.elementList.map(s=>s.referee):[t.referee]}function Ce(e){const t=Z(e).unwrap();return{name:t.pop(),schemaName:t}}function tt(e){return e.expression.literal.value}function ks(e,t){if(Array.isArray(e)){const r=e.map(({id:a})=>a).sort().join(","),i=t.map(({id:a})=>a).sort().join(",");return r<i?`${r}-${i}`:`${i}-${r}`}const n=e.id.toString(),s=t.id.toString();return n<s?`${n}-${s}`:`${s}-${n}`}function Zt(e,t){if(Array.isArray(e)){const r=e.map(({id:a})=>a).sort(),i=t.map(({id:a})=>a).sort();return Rt(r,i).every(([a,o])=>a===o)}const n=e.id,s=t.id;return n===s}function fe(e){const t=e.split(`
|
|
10
10
|
`),n=t.slice(t.findIndex(i=>i.trimStart()!=="")),s=n.filter(i=>i.trimStart()),r=Math.min(...s.map(i=>i.length-i.trimStart().length));return n.map(i=>i.slice(r)).join(`
|
|
11
|
-
`)}function ks(e){if(e){if(q(e))return{value:C(e).unwrap(),type:"string"};if(Ue(e))return{type:"number",value:Mt(e)};if(Pe(e))return{value:e.expression.variable.value.toLowerCase(),type:"boolean"};if(e instanceof ie&&e.value)return{value:e.value.value,type:"expression"};throw new Error("Unreachable")}}function Us(e){let t=null;e instanceof ae&&(t=e.argumentList.elementList.map(i=>Ue(i)?As(i):q(i)?C(i).unwrap():Q(i).unwrap()).join(","),e=e.callee);let n="";for(;e instanceof ke;)n=`[${e.indexer.elementList.map(i=>i.name.expression.literal.value).join(",")}]${n}`,e=e.array;const{name:s,schemaName:r}=Ve(e);return r.length>1?new se({schemaName:r.length===0?null:r[0],type_name:`${s}${n}${t?`(${t})`:""}`,args:t},[new c(l.UNSUPPORTED,"Nested schema is not supported",e)]):new se({schemaName:r.length===0?null:r[0],type_name:`${s}${n}${t?`(${t})`:""}`,args:t})}class Ms{constructor(t,n){this.declarationNode=t,this.env=n,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],constraints:[]},this.pkColumns=[]}interpret(){this.table.token=L(this.declarationNode),this.env.tables.set(this.declarationNode,this.table);const t=[...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:n,token:s})=>({value:n,type:"column",token:s})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(n=>{n.pk=!1})),t}interpretName(t){const{name:n,schemaName:s}=Ve(t);return s.length>1?(this.table.name=n,this.table.schemaName=s.join("."),[new c(l.UNSUPPORTED,"Nested schema is not supported",t)]):(this.table.name=n,this.table.schemaName=s.length?s[0]:null,[])}interpretAlias(t){if(!t)return[];const n=j(t).unwrap_or(null);return n&&(this.env.aliases.push({name:n,kind:"table",value:{tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=n),[]}interpretSettingList(t){var r,i,a;const n=B(t).getValue();this.table.headerColor=(r=n[E.HeaderColor])!=null&&r.length?tt((a=(i=n[E.HeaderColor])==null?void 0:i.at(0))==null?void 0:a.value):void 0;const[s]=n[E.Note]||[];return this.table.note=s&&{value:C(s==null?void 0:s.value).map(fe).unwrap(),token:L(s)},[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof y||r instanceof Re);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case _.Note:return this.table.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)},[];case _.Indexes:return this.interpretIndexes(n);case _.Constraints:return this.interpretConstraints(n);default:return[]}})}interpretInjection(t,n){const s={order:n,token:L(t)};return s.name=t.partial.variable.value,this.table.partials.push(s),[]}interpretFields(t){var a;const r=((a=this.declarationNode.symbol)!=null&&a.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([o])=>{const u=he(o).unwrap_or(null);return(u==null?void 0:u.kind)===I.Column}).length?[]:[new c(l.EMPTY_TABLE,"A Table must have at least one column",this.declarationNode)],i=t.flatMap((o,u)=>o instanceof y?this.interpretColumn(o):this.interpretInjection(o,u));return[...r,...i]}interpretColumn(t){var a,o,u,p,h,d,N,b,A;const n=[],s={};s.name=j(t.callee).unwrap();const r=Us(t.args[0]);s.type=r.getValue(),n.push(...r.getErrors()),s.token=L(t),s.inline_refs=[];const i=t.args.slice(1);if(F(i)instanceof U){const m=B(i.pop()).getValue();s.pk=!!((a=m[E.PK])!=null&&a.length)||!!((o=m[E.PrimaryKey])!=null&&o.length),s.increment=!!((u=m[E.Increment])!=null&&u.length),s.unique=!!((p=m[E.Unique])!=null&&p.length),s.not_null=(h=m[E.NotNull])!=null&&h.length?!0:(d=m[E.Null])!=null&&d.length?!1:void 0,s.dbdefault=ks((b=(N=m[E.Default])==null?void 0:N.at(0))==null?void 0:b.value);const v=(A=m[E.Note])==null?void 0:A.at(0);s.note=v&&{value:C(v.value).map(fe).unwrap(),token:L(v)};const H=m[E.Ref]||[];s.inline_refs=H.flatMap(w=>{const[ee]=ht(w.value.expression);if(Zt(ee,t.symbol))return n.push(new c(l.SAME_ENDPOINT,"Two endpoints are the same",w)),[];const G=w.value.op,k=Z(w.value.expression).unwrap();let le;if(k.length===1){const[te]=k;le={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[te],relation:G.value,token:L(w)}}else if(k.length===2){const[te,ye]=k;le={schemaName:null,tableName:te,fieldNames:[ye],relation:G.value,token:L(w)}}else if(k.length===3){const[te,ye,nn]=k;le={schemaName:te,tableName:ye,fieldNames:[nn],relation:G.value,token:L(w)}}else{n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",w));const te=k.pop(),ye=k.pop();le={schemaName:k.join("."),tableName:ye,fieldNames:[te],relation:G.value,token:L(w)}}const ve=this.registerInlineRefToEnv(t,ee,le,w);return n.push(...ve),ve.length===0?le:[]});const z=m[E.Constraint]||[];s.constraints=z.map(w=>{var k;const ee=L(w),G=(k=w.value.value)==null?void 0:k.value;return{token:ee,expression:G}})}return s.pk||(s.pk=i.some(m=>Q(m).unwrap().toLowerCase()==="pk")),s.unique||(s.unique=i.some(m=>Q(m).unwrap().toLowerCase()==="unique")),this.table.fields.push(s),s.pk&&this.pkColumns.push(s),n}interpretIndexes(t){return this.table.indexes.push(...t.body.body.map(n=>{var a,o,u,p,h,d,N;const s={columns:[]},r=n;s.token=L(r);const i=[r.callee,...r.args];if(F(i)instanceof U){const b=B(i.pop()).getValue();s.pk=!!((a=b[E.PK])!=null&&a.length),s.unique=!!((o=b[E.Unique])!=null&&o.length),s.name=C((p=(u=b[E.Name])==null?void 0:u.at(0))==null?void 0:p.value).unwrap_or(void 0);const A=(h=b[E.Note])==null?void 0:h.at(0);s.note=A&&{value:C(A.value).unwrap(),token:L(A)},s.type=Q((N=(d=b[E.Type])==null?void 0:d.at(0))==null?void 0:N.value).unwrap_or(void 0)}return i.flatMap(b=>{if(!(b instanceof ae))return b;const A=[];for(;b instanceof ae;)A.push(b.argumentList),b=b.callee;return A.push(b),A}).forEach(b=>{const{functional:A,nonFunctional:m}=ut(b).unwrap();s.columns.push(...A.map(v=>({value:v.value.value,type:"expression",token:L(v)})),...m.map(v=>({value:j(v).unwrap(),type:"column",token:L(v)})))}),s})),[]}interpretConstraints(t){return this.table.constraints.push(...t.body.body.map(n=>{var i,a,o;const s={},r=n;if(s.token=L(r),r.args[0]instanceof U){const u=B(r.args[0]).getValue();s.name=C((a=(i=u[E.Name])==null?void 0:i.at(0))==null?void 0:a.value).unwrap_or(void 0)}return s.expression=(o=r.callee.value)==null?void 0:o.value,s})),[]}registerInlineRefToEnv(t,n,s,r){const i=Rs(t.symbol,n);if(this.env.refIds[i])return[new c(l.CIRCULAR_REF,"References with same endpoints exist",r),new c(l.CIRCULAR_REF,"References with same endpoints exist",this.env.refIds[i])];const a=Ds(s.relation);return this.env.refIds[i]=r,this.env.ref.set(r,{name:null,schemaName:null,token:s.token,endpoints:[{...s,relation:a[1]},{schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[Q(t.callee).unwrap()],token:L(t),relation:a[0]}]}),[]}}class Yl{constructor(t,n){this.declarationNode=t,this.env=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){return this.note.token=L(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(t){const{name:n}=Ve(t);return this.note.name=n,[]}interpretSettingList(t){var s,r,i;const n=B(t).getValue();return this.note.headerColor=(s=n.headercolor)!=null&&s.length?tt((i=(r=n.headercolor)==null?void 0:r.at(0))==null?void 0:i.value):void 0,[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof y);return n.length!==1||s.length>0?[new c(l.INVALID_NOTE,"Invalid note syntax",t)]:[...this.interpretNote(n[0])]}interpretNote(t){const n=os(t,"callee.expression.literal.value","");return this.note.content=fe(n),[]}}class Fs{constructor(t,n){this.declarationNode=t,this.env=n,this.container=this.declarationNode.parent instanceof S?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=L(this.declarationNode),this.env.ref.set(this.declarationNode,this.ref),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const n=[],s=Z(this.declarationNode.name).unwrap_or([]);return this.ref.name=s.pop()||null,s.length>1&&n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",this.declarationNode.name)),this.ref.schemaName=s.join(".")||null,n}interpretBody(t){return t instanceof y?this.interpretField(t):this.interpretField(t.body[0])}interpretField(t){var p,h,d,N,b,A,m;const n=t.callee.op.value,{leftExpression:s,rightExpression:r}=t.callee,i=ht(s),a=ht(r);if(Zt(i,a))return[new c(l.SAME_ENDPOINT,"Two endpoints are the same",t)];const o=Rs(i,a);if(this.env.refIds[o])return[new c(l.CIRCULAR_REF,"References with same endpoints exist",this.declarationNode),new c(l.CIRCULAR_REF,"References with same endpoints exist",this.env.refIds[o])];if(t.args[0]){const v=B(t.args[0]).getValue(),H=(h=(p=v.delete)==null?void 0:p.at(0))==null?void 0:h.value;this.ref.onDelete=H instanceof ce?$e(H).unwrap_or(void 0):Q(H).unwrap_or(void 0);const z=(N=(d=v.update)==null?void 0:d.at(0))==null?void 0:N.value;this.ref.onUpdate=z instanceof ce?$e(z).unwrap_or(void 0):Q(z).unwrap_or(void 0),this.ref.color=(b=v.color)!=null&&b.length?tt((m=(A=v.color)==null?void 0:A.at(0))==null?void 0:m.value):void 0}const u=Ds(n);return this.ref.endpoints=[{...Vn(s,this.container),relation:u[0],token:L(s)},{...Vn(r,this.container),relation:u[1],token:L(r)}],this.env.refIds[o]=this.declarationNode,[]}}class Bs{constructor(t,n){this.declarationNode=t,this.env=n,this.tableGroup={tables:[]}}interpret(){const t=[];return this.tableGroup.token=L(this.declarationNode),this.env.tableGroups.set(this.declarationNode,this.tableGroup),t.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),t}interpretName(t){const n=[],{name:s,schemaName:r}=Ve(t);return r.length>=2&&(this.tableGroup.name=s,this.tableGroup.schemaName=r.join("."),n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",this.declarationNode.name))),this.tableGroup.name=s,this.tableGroup.schemaName=r[0]||null,n}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof y);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case"note":this.tableGroup.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)};break}return[]})}interpretFields(t){const n=[];return this.tableGroup.tables=t.map(s=>{const r=Z(s.callee).unwrap();r.length>2&&n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",s));const i=Be(s.callee).unwrap().pop().referee.id;if(this.env.groupOfTable[i]){const a=this.env.groupOfTable[i],{schemaName:o,name:u}=this.env.tableGroups.get(a),p=o?`${o}.${u}`:u;n.push(new c(l.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${r.join(".")}" already appears in group "${p}"`,s))}else this.env.groupOfTable[i]=this.declarationNode;return{name:r.pop(),schemaName:r.join(".")}}),n}interpretSettingList(t){var r,i,a;const n=B(t).getValue();this.tableGroup.color=(r=n.color)!=null&&r.length?tt((a=(i=n.color)==null?void 0:i.at(0))==null?void 0:a.value):void 0;const[s]=n.note||[];return this.tableGroup.note=s&&{value:C(s==null?void 0:s.value).map(fe).unwrap(),token:L(s)},[]}}class Vs{constructor(t,n){this.declarationNode=t,this.env=n,this.enum={values:[]}}interpret(){return this.enum.token=L(this.declarationNode),this.env.enums.set(this.declarationNode,this.enum),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const{name:n,schemaName:s}=Ve(t);return s.length>1?(this.enum.name=n,this.enum.schemaName=s.join("."),[new c(l.UNSUPPORTED,"Nested schema is not supported",t)]):(this.enum.name=n,this.enum.schemaName=s.length?s[0]:null,[])}interpretBody(t){return t.body.flatMap(n=>{var o;const s=n,r={};r.token=L(s),r.name=Q(s.callee).unwrap();const a=(o=B(s.args[0]).getValue().note)==null?void 0:o.at(0);return r.note=a&&{value:C(a.value).map(fe).unwrap(),token:L(a)},this.enum.values.push(r),[]})}}class Cs{constructor(t,n){this.declarationNode=t,this.env=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],constraints:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=L(this.declarationNode),this.env.tablePartials.set(this.declarationNode,this.tablePartial);const t=[...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:n,token:s})=>({value:n,type:"column",token:s})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(n=>{n.pk=!1})),t}interpretName(t){const{name:n}=Ve(t);return this.tablePartial.name=n,[]}interpretSettingList(t){const n=B(t).getValue(),s=Fo(n[E.HeaderColor]);this.tablePartial.headerColor=s?tt(s.value):void 0;const[r]=n[E.Note]||[];return this.tablePartial.note=r&&{value:C(r==null?void 0:r.value).map(fe).unwrap(),token:L(r)},[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof y);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case _.Note:return this.tablePartial.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)},[];case _.Indexes:return this.interpretIndexes(n);case _.Constraints:return this.interpretConstraints(n);default:return[]}})}interpretFields(t){return t.flatMap(n=>this.interpretColumn(n))}interpretColumn(t){var a,o,u,p,h,d,N,b,A;const n=[],s={};s.name=j(t.callee).unwrap();const r=Us(t.args[0]);s.type=r.getValue(),n.push(...r.getErrors()),s.token=L(t),s.inline_refs=[];const i=t.args.slice(1);if(F(i)instanceof U){const m=B(i.pop()).getValue();s.pk=!!((a=m[E.PK])!=null&&a.length)||!!((o=m[E.PrimaryKey])!=null&&o.length),s.increment=!!((u=m[E.Increment])!=null&&u.length),s.unique=!!((p=m[E.Unique])!=null&&p.length),s.not_null=(h=m[E.NotNull])!=null&&h.length?!0:(d=m[E.Null])!=null&&d.length?!1:void 0,s.dbdefault=ks((b=(N=m[E.Default])==null?void 0:N.at(0))==null?void 0:b.value);const v=(A=m[E.Note])==null?void 0:A.at(0);s.note=v&&{value:C(v.value).map(fe).unwrap(),token:L(v)};const H=m[E.Ref]||[];s.inline_refs=H.flatMap(w=>{const[ee]=ht(w.value.expression);if(Zt(ee,t.symbol))return n.push(new c(l.SAME_ENDPOINT,"Two endpoints are the same",w)),[];const G=w.value.op,k=Z(w.value.expression).unwrap();let le;if(k.length===2){const[ve,te]=k;le={schemaName:null,tableName:ve,fieldNames:[te],relation:G.value,token:L(w)}}else if(k.length===3){const[ve,te,ye]=k;le={schemaName:ve,tableName:te,fieldNames:[ye],relation:G.value,token:L(w)}}else{n.push(new c(l.UNSUPPORTED,"Unsupported",w));const ve=k.pop(),te=k.pop();le={schemaName:k.join("."),tableName:te,fieldNames:[ve],relation:G.value,token:L(w)}}return le});const z=m[E.Constraint]||[];s.constraints=z.map(w=>{var k;const ee=L(w),G=(k=w.value.value)==null?void 0:k.value;return{token:ee,expression:G}})}return s.pk||(s.pk=i.some(m=>Q(m).unwrap().toLowerCase()==="pk")),s.unique||(s.unique=i.some(m=>Q(m).unwrap().toLowerCase()==="unique")),this.tablePartial.fields.push(s),s.pk&&this.pkColumns.push(s),n}interpretIndexes(t){return this.tablePartial.indexes.push(...t.body.body.map(n=>{var a,o,u,p,h,d,N;const s={columns:[]},r=n;s.token=L(r);const i=[r.callee,...r.args];if(F(i)instanceof U){const b=B(i.pop()).getValue();s.pk=!!((a=b[E.PK])!=null&&a.length),s.unique=!!((o=b[E.Unique])!=null&&o.length),s.name=C((p=(u=b[E.Name])==null?void 0:u.at(0))==null?void 0:p.value).unwrap_or(void 0);const A=(h=b[E.Note])==null?void 0:h.at(0);s.note=A&&{value:C(A.value).unwrap(),token:L(A)},s.type=Q((N=(d=b[E.Type])==null?void 0:d.at(0))==null?void 0:N.value).unwrap_or(void 0)}return i.flatMap(b=>{if(!(b instanceof ae))return b;const A=[];let m=b;for(;m instanceof ae;)A.push(m.argumentList),m=m.callee;return A.push(m),A}).forEach(b=>{const{functional:A,nonFunctional:m}=ut(b).unwrap();s.columns.push(...A.map(v=>({value:v.value.value,type:"expression",token:L(v)})),...m.map(v=>({value:j(v).unwrap(),type:"column",token:L(v)})))}),s})),[]}interpretConstraints(t){return this.tablePartial.constraints.push(...t.body.body.map(n=>{var i,a,o;const s={},r=n;if(s.token=L(r),r.args[0]instanceof U){const u=B(r.args[0]).getValue();s.name=C((a=(i=u[E.Name])==null?void 0:i.at(0))==null?void 0:a.value).unwrap_or(void 0)}return s.expression=(o=r.callee.value)==null?void 0:o.value,s})),[]}}class ql{constructor(t,n){this.declarationNode=t,this.env=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){return this.env.project.set(this.declarationNode,this.project),this.project.token=L(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){if(!t)return this.project.name=null,[];const{name:n}=Ve(t);return this.project.name=n,[]}interpretBody(t){return t.body.flatMap(n=>{var r;const s=n;switch((r=s.type)==null?void 0:r.value.toLowerCase()){case"table":{const i=new Ms(s,this.env).interpret();return this.project.tables.push(this.env.tables.get(s)),i}case"ref":{const i=new Fs(s,this.env).interpret();return this.project.refs.push(this.env.ref.get(s)),i}case"tablegroup":{const i=new Bs(s,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(s)),i}case"enum":{const i=new Vs(s,this.env).interpret();return this.project.enums.push(this.env.enums.get(s)),i}case"note":return this.project.note={value:C(s.body instanceof Ee?s.body.body[0].callee:s.body.callee).map(fe).unwrap(),token:L(s)},[];case"tablepartial":{const i=new Cs(s,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(s)),i}default:return this.project[s.type.value.toLowerCase()]=C(s.body.callee).unwrap(),[]}})}}function Kl(e){return{schemas:[],tables:Array.from(e.tables.values()),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())}}class Ql{constructor(t){this.ast=t,this.env={schema:[],tables:new Map,notes:new Map,refIds:{},ref:new Map,enums:new Map,tableGroups:new Map,groupOfTable:{},aliases:[],project:new Map,tablePartials:new Map}}interpret(){const t=this.ast.body.flatMap(n=>{switch(Oe(n).unwrap_or(void 0)){case _.Table:return new Ms(n,this.env).interpret();case _.Note:return new Yl(n,this.env).interpret();case _.Ref:return new Fs(n,this.env).interpret();case _.TableGroup:return new Bs(n,this.env).interpret();case _.TablePartial:return new Cs(n,this.env).interpret();case _.Enum:return new Vs(n,this.env).interpret();case _.Project:return new ql(n,this.env).interpret();default:return[]}});return new se(Kl(this.env),t)}}var P=(e=>(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))(P||{}),M=(e=>(e[e.None=0]="None",e[e.KeepWhitespace=1]="KeepWhitespace",e[e.InsertAsSnippet=4]="InsertAsSnippet",e))(M||{});function et(e){switch(e){case I.Schema:return P.Module;case I.Table:case I.TablePartial:return P.Class;case I.Column:case I.TableGroupField:return P.Field;case I.Enum:return P.Enum;case I.EnumField:return P.EnumMember;case I.TableGroup:return P.Struct;default:return P.Text}}function ft(e,t){if(!e||Ut(e))return!1;for(const n of e.trailingTrivia){if(n.start>t)break;if(n.kind===f.NEWLINE&&n.end<=t)return!1}return!0}function $(){return{suggestions:[]}}function pt(e){return{...e,suggestions:e.suggestions.map(t=>({...t,insertText:` ${t.insertText}`}))}}function vt(e){return{...e,suggestions:e.suggestions.map(t=>({...t,insertText:t.insertText.split("").every(gt)?t.insertText:`"${t.insertText}"`}))}}function en(e,t){return e.getOffsetAt(t)}class Gs{constructor(t,n=[]){this.compiler=t,this.triggerCharacters=n}provideCompletionItems(t,n){var h,d;const s=en(t,n),r=this.compiler.token.flatStream(),{token:i,index:a}=this.compiler.container.token(s),o=a===void 0?r[0]:r[a+1];if([...(i==null?void 0:i.trailingTrivia)||[],...(i==null?void 0:i.leadingTrivia)||[],...(o==null?void 0:o.leadingTrivia)||[]].find(N=>$o(N)&&qe(s,N)))return $();if(a===void 0)return jn();if([f.STRING_LITERAL,f.QUOTED_STRING].includes(i.kind)&&qe(s,i))return $();const u=this.compiler.container.element(s);if(this.compiler.container.scopeKind(s)===D.TOPLEVEL||u instanceof S&&u.type&&u.type.start<=s&&u.type.end>=s)return jn();const p=[...this.compiler.container.stack(s)].reverse();for(const N of p)if(N instanceof re)switch((h=N.op)==null?void 0:h.value){case">":case"<":case"<>":case"-":return Cn(this.compiler,s,N)}else if(N instanceof Te)switch((d=N.op)==null?void 0:d.value){case">":case"<":case"<>":case"-":return Cn(this.compiler,s,N);case".":return $s(this.compiler,s,N)}else{if(N instanceof ue)return Gn(this.compiler,s,N);if(N instanceof U)return Gn(this.compiler,s,N);if(N instanceof be)return Zl(this.compiler,s);if(N instanceof Re)return Jl(this.compiler,s);if(N instanceof y)return Xn(this.compiler,s,N);if(N instanceof S&&(N.bodyColon&&s>=N.bodyColon.end||N.body&&qe(s,N.body)))return Xn(this.compiler,s,void 0)}return $()}}function Jl(e,t){const n=e.container.element(t);return nt(e,t,n,[I.TablePartial])}function Cn(e,t,n){const s=e.container.scopeKind(t);if([D.REF,D.TABLE,D.TABLEPARTIAL].includes(s)){const r=nt(e,t,e.container.element(t),[I.Table,I.Schema,I.Column]);return ft(n.op,t)?pt(r):r}return $()}function nt(e,t,n,s){var a;if(n===void 0)return $();let r=n;const i={suggestions:[]};for(;r;){if((a=r==null?void 0:r.symbol)!=null&&a.symbolTable){const{symbol:o}=r;i.suggestions.push(...e.symbol.members(o).filter(({kind:u})=>s.includes(u)).map(({name:u,kind:p})=>({label:u,insertText:u,insertTextRules:M.KeepWhitespace,kind:et(p),sortText:et(p).toString().padStart(2,"0"),range:void 0})))}r=r instanceof S?r.parent:void 0}return vt(i)}function Zl(e,t){var s;switch(e.container.scopeKind(t)){case D.INDEXES:return js(e,t);case D.REF:{const r=[...e.container.stack(t)];for(;r.length>0;){const i=r.pop();if(i instanceof Te&&((s=i.op)==null?void 0:s.value)===".")return $s(e,t,i)}}return Xs(e,t)}return $()}function Gn(e,t,n){const{token:s}=e.container.token(t);if([f.COMMA,f.LBRACKET].includes(s==null?void 0:s.kind)){const r=$n(e,t);return(s==null?void 0:s.kind)===f.COMMA&&ft(s,t)?pt(r):r}if(n.name&&n.name.start<=t&&n.name.end>=t)return $n(e,t);if(n.name instanceof ce){const r=ec(e,t,$e(n.name).unwrap_or(""));return(s==null?void 0:s.kind)===f.COLON&&ft(s,t)?pt(r):r}return $()}function $n(e,t){const n=e.container.element(t);if(n instanceof J)return $();const s=e.container.scopeKind(t);if(n.body&&!qe(t,n.body)){let r;switch(s){case D.TABLE:case D.TABLEPARTIAL:r=[E.HeaderColor,E.Note];break;case D.TABLEGROUP:r=[E.Color,E.Note];break;default:r=[]}return{suggestions:r.map(i=>({label:i,insertText:`${i}: `,kind:P.Field,insertTextRules:M.KeepWhitespace,range:void 0}))}}switch(s){case D.TABLE:case D.TABLEPARTIAL:return{suggestions:[...[E.PK,E.PrimaryKey,E.Null,E.NotNull,E.Increment,E.Unique].map(r=>({label:r,insertText:r,kind:P.Property,insertTextRules:M.KeepWhitespace,range:void 0})),...[E.Ref,E.Default,E.Note,E.Constraint].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:M.KeepWhitespace,range:void 0}))]};case D.ENUM:return{suggestions:[...[E.Note].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:M.KeepWhitespace,range:void 0}))]};case D.INDEXES:return{suggestions:[...[E.Unique,E.PK].map(r=>({label:r,insertText:r,insertTextRules:M.KeepWhitespace,kind:P.Property,range:void 0})),...[E.Note,E.Name,E.Type].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:M.KeepWhitespace,range:void 0}))]};case D.REF:return{suggestions:[E.Update,E.Delete,E.Color].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:M.KeepWhitespace,range:void 0}))};case D.CONSTRAINTS:return{suggestions:[E.Name].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:M.KeepWhitespace,range:void 0}))}}return $()}function ec(e,t,n){switch(n==null?void 0:n.toLowerCase()){case"update":case"delete":return{suggestions:["cascade","set default","set null","restrict"].map(s=>({label:s,insertText:s,kind:P.Value,insertTextRules:M.KeepWhitespace,range:void 0}))};case"type":return{suggestions:["btree","hash"].map(s=>({label:s,insertText:`${s}`,kind:P.Value,insertTextRules:M.KeepWhitespace,range:void 0}))}}return $()}function $s(e,t,n){const s=Be(n).unwrap_or([]);if(s.pop(),s.some(i=>!W(i)))return $();const r=s.map(i=>Q(i).unwrap());return vt({suggestions:e.symbol.ofName({nameStack:r,owner:e.container.element(t)}).flatMap(({symbol:i})=>e.symbol.members(i)).map(({kind:i,name:a})=>({label:a,insertText:a,kind:et(i),range:void 0}))})}function Xn(e,t,n){var r;switch(e.container.scopeKind(t)){case D.TABLE:case D.TABLEPARTIAL:return nc(e,t,n);case D.PROJECT:return sc(e,t,n);case D.INDEXES:return ic(e,t);case D.ENUM:return tc(e,t,n);case D.REF:{const i=Xs(e,t);return((r=e.container.token(t).token)==null?void 0:r.kind)===f.COLON&&ft(e.container.token(t).token,t)?pt(i):i}case D.TABLEGROUP:return rc(e);default:return $()}}function jn(){return{suggestions:["Table","TableGroup","Enum","Project","Ref","TablePartial"].map(e=>({label:e,insertText:e,insertTextRules:M.KeepWhitespace,kind:P.Keyword,range:void 0}))}}function tc(e,t,n){return n!=null&&n.callee&&tn(t,n)===1?nt(e,t,e.container.element(t),[I.Schema,I.Table,I.Column]):$()}function nc(e,t,n){const s=["Note","indexes","constraints"];if(!(n!=null&&n.callee))return{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:M.KeepWhitespace,kind:P.Keyword,range:void 0}))};const r=tn(t,n);return r===0?{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:M.KeepWhitespace,kind:P.Keyword,range:void 0}))}:r===1?ac(e,t):$()}function sc(e,t,n){const s=["Table","TableGroup","Enum","Note","Ref","TablePartial"];return n!=null&&n.callee?tn(t,n)===0?{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:M.KeepWhitespace,kind:P.Keyword,range:void 0}))}:$():{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:M.KeepWhitespace,kind:P.Keyword,range:void 0}))}}function Xs(e,t){return nt(e,t,e.container.element(t),[I.Schema,I.Table,I.Column])}function rc(e){return{suggestions:[...vt({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([t])=>{const n=he(t).unwrap_or(void 0);if(n===void 0)return[];const{kind:s,name:r}=n;return s!==I.Table&&s!==I.Schema?[]:{label:r,insertText:r,insertTextRules:M.KeepWhitespace,kind:et(s),range:void 0}})}).suggestions,...["Note"].map(t=>({label:t,insertText:t,insertTextRules:M.KeepWhitespace,kind:P.Keyword,range:void 0}))]}}function ic(e,t){return js(e,t)}function ac(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"].map(n=>({label:n,insertText:n,insertTextRules:M.KeepWhitespace,kind:P.TypeParameter,sortText:P.TypeParameter.toString().padStart(2,"0"),range:void 0})),...nt(e,t,e.container.element(t),[I.Enum,I.Schema]).suggestions]}}function js(e,t){const n=e.container.element(t),s=n==null?void 0:n.parent;if(!((s==null?void 0:s.symbol)instanceof gs))return $();const{symbolTable:r}=s.symbol;return vt({suggestions:[...r.entries()].flatMap(([i])=>{const a=he(i).unwrap_or(void 0);if(a===void 0)return[];const{name:o}=a;return{label:o,insertText:o,insertTextRules:M.KeepWhitespace,kind:et(I.Column),range:void 0}})})}function tn(e,t){if(!t.callee)return-1;const n=[t.callee,...t.args],s=n.findIndex(r=>e<=r.end);return s===-1?n.length:s}class Ws{constructor(t){this.compiler=t}provideDefinition(t,n){var a,o;const{uri:s}=t,r=en(t,n),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){const u=i.pop();if(!(u!=null&&u.referee))continue;let p;if((a=u.referee)!=null&&a.declaration&&[Se.PRIMARY_EXPRESSION,Se.VARIABLE,Se.PARTIAL_INJECTION].includes(u==null?void 0:u.kind)?{declaration:p}=u.referee:(o=u.referee)!=null&&o.injectorDeclaration&&(p=u.referee.injectorDeclaration),p){const{startPos:h,endPos:d}=p;return[{range:{startColumn:h.column+1,startLineNumber:h.line+1,endColumn:d.column+1,endLineNumber:d.line+1},uri:s}]}}return[]}}class Hs{constructor(t){this.compiler=t}provideReferences(t,n){const{uri:s}=t,r=en(t,n),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){const a=i.pop();if(a&&[Se.ELEMENT_DECLARATION,Se.FUNCTION_APPLICATION,Se.PRIMARY_EXPRESSION].includes(a==null?void 0:a.kind)){const{symbol:o}=a;if(o!=null&&o.references.length)return o.references.map(({startPos:u,endPos:p})=>({range:{startColumn:u.column+1,startLineNumber:u.line+1,endColumn:p.column+1,endLineNumber:p.line+1},uri:s}))}}return[]}}const oc=Object.freeze(Object.defineProperty({__proto__:null,CompletionItemInsertTextRule:M,CompletionItemKind:P,DBMLCompletionItemProvider:Gs,DBMLDefinitionProvider:Ws,DBMLReferencesProvider:Hs},Symbol.toStringTag,{value:"Module"}));var D=(e=>(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.CONSTRAINTS=10]="CONSTRAINTS",e))(D||{});class lc{constructor(){this.source="",this.cache=new Array(16).fill(null),this.nodeIdGenerator=new Xo,this.symbolIdGenerator=new qo,this.token={invalidStream:this.createQuery(6,()=>this.parse.tokens().filter(Ls)),flatStream:this.createQuery(7,()=>this.parse.tokens().flatMap(t=>[...t.leadingInvalid,t,...t.trailingInvalid]))},this.parse={source:()=>this.source,_:this.createQuery(0,()=>{const t=new ul(this.source).lex().chain(n=>new pl(n,this.nodeIdGenerator).parse()).chain(({ast:n,tokens:s})=>new zl(n,this.symbolIdGenerator).analyze().map(()=>({ast:n,tokens:s})));return t.getErrors().length>0?t:t.chain(({ast:n,tokens:s})=>new Ql(n).interpret().map(i=>({ast:n,tokens:s,rawDb:i})))}),ast:this.createQuery(1,()=>this.parse._().getValue().ast),errors:this.createQuery(2,()=>this.parse._().getErrors()),tokens:this.createQuery(4,()=>this.parse._().getValue().tokens),rawDb:this.createQuery(3,()=>this.parse._().getValue().rawDb),publicSymbolTable:this.createQuery(5,()=>this.parse._().getValue().ast.symbol.symbolTable)},this.container={stack:this.createQuery(10,t=>{const n=this.token.flatStream(),{index:s,token:r}=this.container.token(t),i=s===void 0?-1:Mo(n,p=>!p.isInvalid,s);if(i===-1)return[this.parse.ast()];const a=n[i].start;let o=this.parse.ast();const u=[o];for(;;){const h=cl(o).find(d=>qe(a,d));if(h===void 0||h instanceof K)break;u.push(h),o=h}if((r==null?void 0:r.kind)===f.COLON)return u;for(;u.length>0;){let p=!1;const h=F(u);if(h instanceof y){const d=this.parse.source();for(let N=h.end;N<t;N+=1)d[N]===`
|
|
12
|
-
`&&(u.pop(),p=!0)}else h instanceof re||h instanceof Te?this.container.token(t).token!==h.op&&(u.pop(),p=!0):h instanceof
|
|
11
|
+
`)}function Rs(e){if(e){if(Y(e))return{value:C(e).unwrap(),type:"string"};if(Ue(e))return{type:"number",value:Mt(e)};if(Pe(e))return{value:e.expression.variable.value.toLowerCase(),type:"boolean"};if(e instanceof ie&&e.value)return{value:e.value.value,type:"expression"};throw new Error("Unreachable")}}function Us(e){let t=null;e instanceof ae&&(t=e.argumentList.elementList.map(i=>Ue(i)?As(i):Y(i)?C(i).unwrap():Q(i).unwrap()).join(","),e=e.callee);let n="";for(;e instanceof Re;)n=`[${e.indexer.elementList.map(i=>i.name.expression.literal.value).join(",")}]${n}`,e=e.array;const{name:s,schemaName:r}=Ce(e);return r.length>1?new se({schemaName:r.length===0?null:r[0],type_name:`${s}${n}${t?`(${t})`:""}`,args:t},[new c(l.UNSUPPORTED,"Nested schema is not supported",e)]):new se({schemaName:r.length===0?null:r[0],type_name:`${s}${n}${t?`(${t})`:""}`,args:t})}class Ms{constructor(t,n){this.declarationNode=t,this.env=n,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=L(this.declarationNode),this.env.tables.set(this.declarationNode,this.table);const t=[...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:n,token:s})=>({value:n,type:"column",token:s})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(n=>{n.pk=!1})),t}interpretName(t){const{name:n,schemaName:s}=Ce(t);return s.length>1?(this.table.name=n,this.table.schemaName=s.join("."),[new c(l.UNSUPPORTED,"Nested schema is not supported",t)]):(this.table.name=n,this.table.schemaName=s.length?s[0]:null,[])}interpretAlias(t){if(!t)return[];const n=j(t).unwrap_or(null);return n&&(this.env.aliases.push({name:n,kind:"table",value:{tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=n),[]}interpretSettingList(t){var r,i,a;const n=F(t).getValue();this.table.headerColor=(r=n[E.HeaderColor])!=null&&r.length?tt((a=(i=n[E.HeaderColor])==null?void 0:i.at(0))==null?void 0:a.value):void 0;const[s]=n[E.Note]||[];return this.table.note=s&&{value:C(s==null?void 0:s.value).map(fe).unwrap(),token:L(s)},[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof y||r instanceof ke);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case b.Note:return this.table.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)},[];case b.Indexes:return this.interpretIndexes(n);case b.Check:return this.interpretChecks(n);default:return[]}})}interpretInjection(t,n){const s={order:n,token:L(t)};return s.name=t.partial.variable.value,this.table.partials.push(s),[]}interpretFields(t){var a;const r=((a=this.declarationNode.symbol)!=null&&a.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([o])=>{const u=he(o).unwrap_or(null);return(u==null?void 0:u.kind)===_.Column}).length?[]:[new c(l.EMPTY_TABLE,"A Table must have at least one column",this.declarationNode)],i=t.flatMap((o,u)=>o instanceof y?this.interpretColumn(o):this.interpretInjection(o,u));return[...r,...i]}interpretColumn(t){var a,o,u,p,h,d,N,m,A;const n=[],s={};s.name=j(t.callee).unwrap();const r=Us(t.args[0]);s.type=r.getValue(),n.push(...r.getErrors()),s.token=L(t),s.inline_refs=[];const i=t.args.slice(1);if(M(i)instanceof R){const I=F(i.pop()).getValue();s.pk=!!((a=I[E.PK])!=null&&a.length)||!!((o=I[E.PrimaryKey])!=null&&o.length),s.increment=!!((u=I[E.Increment])!=null&&u.length),s.unique=!!((p=I[E.Unique])!=null&&p.length),s.not_null=(h=I[E.NotNull])!=null&&h.length?!0:(d=I[E.Null])!=null&&d.length?!1:void 0,s.dbdefault=Rs((m=(N=I[E.Default])==null?void 0:N.at(0))==null?void 0:m.value);const v=(A=I[E.Note])==null?void 0:A.at(0);s.note=v&&{value:C(v.value).map(fe).unwrap(),token:L(v)};const H=I[E.Ref]||[];s.inline_refs=H.flatMap(w=>{const[ee]=ht(w.value.expression);if(Zt(ee,t.symbol))return n.push(new c(l.SAME_ENDPOINT,"Two endpoints are the same",w)),[];const V=w.value.op,G=Z(w.value.expression).unwrap();let le;if(G.length===1){const[te]=G;le={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[te],relation:V.value,token:L(w)}}else if(G.length===2){const[te,ye]=G;le={schemaName:null,tableName:te,fieldNames:[ye],relation:V.value,token:L(w)}}else if(G.length===3){const[te,ye,nn]=G;le={schemaName:te,tableName:ye,fieldNames:[nn],relation:V.value,token:L(w)}}else{n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",w));const te=G.pop(),ye=G.pop();le={schemaName:G.join("."),tableName:ye,fieldNames:[te],relation:V.value,token:L(w)}}const ve=this.registerInlineRefToEnv(t,ee,le,w);return n.push(...ve),ve.length===0?le:[]});const K=I[E.Check]||[];s.checks=K.map(w=>{const ee=L(w),V=w.value.value.value;return{token:ee,expression:V}})}return s.pk||(s.pk=i.some(I=>Q(I).unwrap().toLowerCase()==="pk")),s.unique||(s.unique=i.some(I=>Q(I).unwrap().toLowerCase()==="unique")),this.table.fields.push(s),s.pk&&this.pkColumns.push(s),n}interpretIndexes(t){return this.table.indexes.push(...t.body.body.map(n=>{var a,o,u,p,h,d,N;const s={columns:[]},r=n;s.token=L(r);const i=[r.callee,...r.args];if(M(i)instanceof R){const m=F(i.pop()).getValue();s.pk=!!((a=m[E.PK])!=null&&a.length),s.unique=!!((o=m[E.Unique])!=null&&o.length),s.name=C((p=(u=m[E.Name])==null?void 0:u.at(0))==null?void 0:p.value).unwrap_or(void 0);const A=(h=m[E.Note])==null?void 0:h.at(0);s.note=A&&{value:C(A.value).unwrap(),token:L(A)},s.type=Q((N=(d=m[E.Type])==null?void 0:d.at(0))==null?void 0:N.value).unwrap_or(void 0)}return i.flatMap(m=>{if(!(m instanceof ae))return m;const A=[];for(;m instanceof ae;)A.push(m.argumentList),m=m.callee;return A.push(m),A}).forEach(m=>{const{functional:A,nonFunctional:I}=ut(m).unwrap();s.columns.push(...A.map(v=>({value:v.value.value,type:"expression",token:L(v)})),...I.map(v=>({value:j(v).unwrap(),type:"column",token:L(v)})))}),s})),[]}interpretChecks(t){return this.table.checks.push(...t.body.body.map(n=>{var i,a;const s={},r=n;if(s.token=L(r),r.args[0]instanceof R){const o=F(r.args[0]).getValue();s.name=C((a=(i=o[E.Name])==null?void 0:i.at(0))==null?void 0:a.value).unwrap_or(void 0)}return s.expression=r.callee.value.value,s})),[]}registerInlineRefToEnv(t,n,s,r){const i=ks(t.symbol,n);if(this.env.refIds[i])return[new c(l.CIRCULAR_REF,"References with same endpoints exist",r),new c(l.CIRCULAR_REF,"References with same endpoints exist",this.env.refIds[i])];const a=Ds(s.relation);return this.env.refIds[i]=r,this.env.ref.set(r,{name:null,schemaName:null,token:s.token,endpoints:[{...s,relation:a[1]},{schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[Q(t.callee).unwrap()],token:L(t),relation:a[0]}]}),[]}}class Yl{constructor(t,n){this.declarationNode=t,this.env=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){return this.note.token=L(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(t){const{name:n}=Ce(t);return this.note.name=n,[]}interpretSettingList(t){var s,r,i;const n=F(t).getValue();return this.note.headerColor=(s=n.headercolor)!=null&&s.length?tt((i=(r=n.headercolor)==null?void 0:r.at(0))==null?void 0:i.value):void 0,[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof y);return n.length!==1||s.length>0?[new c(l.INVALID_NOTE,"Invalid note syntax",t)]:[...this.interpretNote(n[0])]}interpretNote(t){const n=os(t,"callee.expression.literal.value","");return this.note.content=fe(n),[]}}class Fs{constructor(t,n){this.declarationNode=t,this.env=n,this.container=this.declarationNode.parent instanceof S?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=L(this.declarationNode),this.env.ref.set(this.declarationNode,this.ref),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const n=[],s=Z(this.declarationNode.name).unwrap_or([]);return this.ref.name=s.pop()||null,s.length>1&&n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",this.declarationNode.name)),this.ref.schemaName=s.join(".")||null,n}interpretBody(t){return t instanceof y?this.interpretField(t):this.interpretField(t.body[0])}interpretField(t){var p,h,d,N,m,A,I;const n=t.callee.op.value,{leftExpression:s,rightExpression:r}=t.callee,i=ht(s),a=ht(r);if(Zt(i,a))return[new c(l.SAME_ENDPOINT,"Two endpoints are the same",t)];const o=ks(i,a);if(this.env.refIds[o])return[new c(l.CIRCULAR_REF,"References with same endpoints exist",this.declarationNode),new c(l.CIRCULAR_REF,"References with same endpoints exist",this.env.refIds[o])];if(t.args[0]){const v=F(t.args[0]).getValue(),H=(h=(p=v.delete)==null?void 0:p.at(0))==null?void 0:h.value;this.ref.onDelete=H instanceof ce?$e(H).unwrap_or(void 0):Q(H).unwrap_or(void 0);const K=(N=(d=v.update)==null?void 0:d.at(0))==null?void 0:N.value;this.ref.onUpdate=K instanceof ce?$e(K).unwrap_or(void 0):Q(K).unwrap_or(void 0),this.ref.color=(m=v.color)!=null&&m.length?tt((I=(A=v.color)==null?void 0:A.at(0))==null?void 0:I.value):void 0}const u=Ds(n);return this.ref.endpoints=[{...Cn(s,this.container),relation:u[0],token:L(s)},{...Cn(r,this.container),relation:u[1],token:L(r)}],this.env.refIds[o]=this.declarationNode,[]}}class Bs{constructor(t,n){this.declarationNode=t,this.env=n,this.tableGroup={tables:[]}}interpret(){const t=[];return this.tableGroup.token=L(this.declarationNode),this.env.tableGroups.set(this.declarationNode,this.tableGroup),t.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),t}interpretName(t){const n=[],{name:s,schemaName:r}=Ce(t);return r.length>=2&&(this.tableGroup.name=s,this.tableGroup.schemaName=r.join("."),n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",this.declarationNode.name))),this.tableGroup.name=s,this.tableGroup.schemaName=r[0]||null,n}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof y);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case"note":this.tableGroup.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)};break}return[]})}interpretFields(t){const n=[];return this.tableGroup.tables=t.map(s=>{const r=Z(s.callee).unwrap();r.length>2&&n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",s));const i=Be(s.callee).unwrap().pop().referee.id;if(this.env.groupOfTable[i]){const a=this.env.groupOfTable[i],{schemaName:o,name:u}=this.env.tableGroups.get(a),p=o?`${o}.${u}`:u;n.push(new c(l.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${r.join(".")}" already appears in group "${p}"`,s))}else this.env.groupOfTable[i]=this.declarationNode;return{name:r.pop(),schemaName:r.join(".")}}),n}interpretSettingList(t){var r,i,a;const n=F(t).getValue();this.tableGroup.color=(r=n.color)!=null&&r.length?tt((a=(i=n.color)==null?void 0:i.at(0))==null?void 0:a.value):void 0;const[s]=n.note||[];return this.tableGroup.note=s&&{value:C(s==null?void 0:s.value).map(fe).unwrap(),token:L(s)},[]}}class Cs{constructor(t,n){this.declarationNode=t,this.env=n,this.enum={values:[]}}interpret(){return this.enum.token=L(this.declarationNode),this.env.enums.set(this.declarationNode,this.enum),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const{name:n,schemaName:s}=Ce(t);return s.length>1?(this.enum.name=n,this.enum.schemaName=s.join("."),[new c(l.UNSUPPORTED,"Nested schema is not supported",t)]):(this.enum.name=n,this.enum.schemaName=s.length?s[0]:null,[])}interpretBody(t){return t.body.flatMap(n=>{var o;const s=n,r={};r.token=L(s),r.name=Q(s.callee).unwrap();const a=(o=F(s.args[0]).getValue().note)==null?void 0:o.at(0);return r.note=a&&{value:C(a.value).map(fe).unwrap(),token:L(a)},this.enum.values.push(r),[]})}}class Vs{constructor(t,n){this.declarationNode=t,this.env=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=L(this.declarationNode),this.env.tablePartials.set(this.declarationNode,this.tablePartial);const t=[...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:n,token:s})=>({value:n,type:"column",token:s})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(n=>{n.pk=!1})),t}interpretName(t){const{name:n}=Ce(t);return this.tablePartial.name=n,[]}interpretSettingList(t){const n=F(t).getValue(),s=Fo(n[E.HeaderColor]);this.tablePartial.headerColor=s?tt(s.value):void 0;const[r]=n[E.Note]||[];return this.tablePartial.note=r&&{value:C(r==null?void 0:r.value).map(fe).unwrap(),token:L(r)},[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof y);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case b.Note:return this.tablePartial.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)},[];case b.Indexes:return this.interpretIndexes(n);case b.Check:return this.interpretChecks(n);default:return[]}})}interpretFields(t){return t.flatMap(n=>this.interpretColumn(n))}interpretColumn(t){var a,o,u,p,h,d,N,m,A;const n=[],s={};s.name=j(t.callee).unwrap();const r=Us(t.args[0]);s.type=r.getValue(),n.push(...r.getErrors()),s.token=L(t),s.inline_refs=[];const i=t.args.slice(1);if(M(i)instanceof R){const I=F(i.pop()).getValue();s.pk=!!((a=I[E.PK])!=null&&a.length)||!!((o=I[E.PrimaryKey])!=null&&o.length),s.increment=!!((u=I[E.Increment])!=null&&u.length),s.unique=!!((p=I[E.Unique])!=null&&p.length),s.not_null=(h=I[E.NotNull])!=null&&h.length?!0:(d=I[E.Null])!=null&&d.length?!1:void 0,s.dbdefault=Rs((m=(N=I[E.Default])==null?void 0:N.at(0))==null?void 0:m.value);const v=(A=I[E.Note])==null?void 0:A.at(0);s.note=v&&{value:C(v.value).map(fe).unwrap(),token:L(v)};const H=I[E.Ref]||[];s.inline_refs=H.flatMap(w=>{const[ee]=ht(w.value.expression);if(Zt(ee,t.symbol))return n.push(new c(l.SAME_ENDPOINT,"Two endpoints are the same",w)),[];const V=w.value.op,G=Z(w.value.expression).unwrap();let le;if(G.length===2){const[ve,te]=G;le={schemaName:null,tableName:ve,fieldNames:[te],relation:V.value,token:L(w)}}else if(G.length===3){const[ve,te,ye]=G;le={schemaName:ve,tableName:te,fieldNames:[ye],relation:V.value,token:L(w)}}else{n.push(new c(l.UNSUPPORTED,"Unsupported",w));const ve=G.pop(),te=G.pop();le={schemaName:G.join("."),tableName:te,fieldNames:[ve],relation:V.value,token:L(w)}}return le});const K=I[E.Check]||[];s.checks=K.map(w=>{const ee=L(w),V=w.value.value.value;return{token:ee,expression:V}})}return s.pk||(s.pk=i.some(I=>Q(I).unwrap().toLowerCase()==="pk")),s.unique||(s.unique=i.some(I=>Q(I).unwrap().toLowerCase()==="unique")),this.tablePartial.fields.push(s),s.pk&&this.pkColumns.push(s),n}interpretIndexes(t){return this.tablePartial.indexes.push(...t.body.body.map(n=>{var a,o,u,p,h,d,N;const s={columns:[]},r=n;s.token=L(r);const i=[r.callee,...r.args];if(M(i)instanceof R){const m=F(i.pop()).getValue();s.pk=!!((a=m[E.PK])!=null&&a.length),s.unique=!!((o=m[E.Unique])!=null&&o.length),s.name=C((p=(u=m[E.Name])==null?void 0:u.at(0))==null?void 0:p.value).unwrap_or(void 0);const A=(h=m[E.Note])==null?void 0:h.at(0);s.note=A&&{value:C(A.value).unwrap(),token:L(A)},s.type=Q((N=(d=m[E.Type])==null?void 0:d.at(0))==null?void 0:N.value).unwrap_or(void 0)}return i.flatMap(m=>{if(!(m instanceof ae))return m;const A=[];let I=m;for(;I instanceof ae;)A.push(I.argumentList),I=I.callee;return A.push(I),A}).forEach(m=>{const{functional:A,nonFunctional:I}=ut(m).unwrap();s.columns.push(...A.map(v=>({value:v.value.value,type:"expression",token:L(v)})),...I.map(v=>({value:j(v).unwrap(),type:"column",token:L(v)})))}),s})),[]}interpretChecks(t){return this.tablePartial.checks.push(...t.body.body.map(n=>{var i,a;const s={},r=n;if(s.token=L(r),r.args[0]instanceof R){const o=F(r.args[0]).getValue();s.name=C((a=(i=o[E.Name])==null?void 0:i.at(0))==null?void 0:a.value).unwrap_or(void 0)}return s.expression=r.callee.value.value,s})),[]}}class ql{constructor(t,n){this.declarationNode=t,this.env=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){return this.env.project.set(this.declarationNode,this.project),this.project.token=L(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){if(!t)return this.project.name=null,[];const{name:n}=Ce(t);return this.project.name=n,[]}interpretBody(t){return t.body.flatMap(n=>{var r;const s=n;switch((r=s.type)==null?void 0:r.value.toLowerCase()){case"table":{const i=new Ms(s,this.env).interpret();return this.project.tables.push(this.env.tables.get(s)),i}case"ref":{const i=new Fs(s,this.env).interpret();return this.project.refs.push(this.env.ref.get(s)),i}case"tablegroup":{const i=new Bs(s,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(s)),i}case"enum":{const i=new Cs(s,this.env).interpret();return this.project.enums.push(this.env.enums.get(s)),i}case"note":return this.project.note={value:C(s.body instanceof Ee?s.body.body[0].callee:s.body.callee).map(fe).unwrap(),token:L(s)},[];case"tablepartial":{const i=new Vs(s,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(s)),i}default:return this.project[s.type.value.toLowerCase()]=C(s.body.callee).unwrap(),[]}})}}function Ql(e){return{schemas:[],tables:Array.from(e.tables.values()),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())}}class Jl{constructor(t){this.ast=t,this.env={schema:[],tables:new Map,notes:new Map,refIds:{},ref:new Map,enums:new Map,tableGroups:new Map,groupOfTable:{},aliases:[],project:new Map,tablePartials:new Map}}interpret(){const t=this.ast.body.flatMap(n=>{switch(Oe(n).unwrap_or(void 0)){case b.Table:return new Ms(n,this.env).interpret();case b.Note:return new Yl(n,this.env).interpret();case b.Ref:return new Fs(n,this.env).interpret();case b.TableGroup:return new Bs(n,this.env).interpret();case b.TablePartial:return new Vs(n,this.env).interpret();case b.Enum:return new Cs(n,this.env).interpret();case b.Project:return new ql(n,this.env).interpret();default:return[]}});return new se(Ql(this.env),t)}}var P=(e=>(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))(P||{}),U=(e=>(e[e.None=0]="None",e[e.KeepWhitespace=1]="KeepWhitespace",e[e.InsertAsSnippet=4]="InsertAsSnippet",e))(U||{});function et(e){switch(e){case _.Schema:return P.Module;case _.Table:case _.TablePartial:return P.Class;case _.Column:case _.TableGroupField:return P.Field;case _.Enum:return P.Enum;case _.EnumField:return P.EnumMember;case _.TableGroup:return P.Struct;default:return P.Text}}function ft(e,t){if(!e||Ut(e))return!1;for(const n of e.trailingTrivia){if(n.start>t)break;if(n.kind===f.NEWLINE&&n.end<=t)return!1}return!0}function $(){return{suggestions:[]}}function pt(e){return{...e,suggestions:e.suggestions.map(t=>({...t,insertText:` ${t.insertText}`}))}}function vt(e){return{...e,suggestions:e.suggestions.map(t=>({...t,insertText:t.insertText.split("").every(gt)?t.insertText:`"${t.insertText}"`}))}}function en(e,t){return e.getOffsetAt(t)}class Gs{constructor(t,n=[]){this.compiler=t,this.triggerCharacters=n}provideCompletionItems(t,n){var h,d;const s=en(t,n),r=this.compiler.token.flatStream(),{token:i,index:a}=this.compiler.container.token(s),o=a===void 0?r[0]:r[a+1];if([...(i==null?void 0:i.trailingTrivia)||[],...(i==null?void 0:i.leadingTrivia)||[],...(o==null?void 0:o.leadingTrivia)||[]].find(N=>$o(N)&&Ye(s,N)))return $();if(a===void 0)return jn();if([f.STRING_LITERAL,f.QUOTED_STRING].includes(i.kind)&&Ye(s,i))return $();const u=this.compiler.container.element(s);if(this.compiler.container.scopeKind(s)===D.TOPLEVEL||u instanceof S&&u.type&&u.type.start<=s&&u.type.end>=s)return jn();const p=[...this.compiler.container.stack(s)].reverse();for(const N of p)if(N instanceof re)switch((h=N.op)==null?void 0:h.value){case">":case"<":case"<>":case"-":return Vn(this.compiler,s,N)}else if(N instanceof Te)switch((d=N.op)==null?void 0:d.value){case">":case"<":case"<>":case"-":return Vn(this.compiler,s,N);case".":return $s(this.compiler,s,N)}else{if(N instanceof ue)return Gn(this.compiler,s,N);if(N instanceof R)return Gn(this.compiler,s,N);if(N instanceof be)return ec(this.compiler,s);if(N instanceof ke)return Zl(this.compiler,s);if(N instanceof y)return Xn(this.compiler,s,N);if(N instanceof S&&(N.bodyColon&&s>=N.bodyColon.end||N.body&&Ye(s,N.body)))return Xn(this.compiler,s,void 0)}return $()}}function Zl(e,t){const n=e.container.element(t);return nt(e,t,n,[_.TablePartial])}function Vn(e,t,n){const s=e.container.scopeKind(t);if([D.REF,D.TABLE,D.TABLEPARTIAL].includes(s)){const r=nt(e,t,e.container.element(t),[_.Table,_.Schema,_.Column]);return ft(n.op,t)?pt(r):r}return $()}function nt(e,t,n,s){var a;if(n===void 0)return $();let r=n;const i={suggestions:[]};for(;r;){if((a=r==null?void 0:r.symbol)!=null&&a.symbolTable){const{symbol:o}=r;i.suggestions.push(...e.symbol.members(o).filter(({kind:u})=>s.includes(u)).map(({name:u,kind:p})=>({label:u,insertText:u,insertTextRules:U.KeepWhitespace,kind:et(p),sortText:et(p).toString().padStart(2,"0"),range:void 0})))}r=r instanceof S?r.parent:void 0}return vt(i)}function ec(e,t){var s;switch(e.container.scopeKind(t)){case D.INDEXES:return js(e,t);case D.REF:{const r=[...e.container.stack(t)];for(;r.length>0;){const i=r.pop();if(i instanceof Te&&((s=i.op)==null?void 0:s.value)===".")return $s(e,t,i)}}return Xs(e,t)}return $()}function Gn(e,t,n){const{token:s}=e.container.token(t);if([f.COMMA,f.LBRACKET].includes(s==null?void 0:s.kind)){const r=$n(e,t);return(s==null?void 0:s.kind)===f.COMMA&&ft(s,t)?pt(r):r}if(n.name&&n.name.start<=t&&n.name.end>=t)return $n(e,t);if(n.name instanceof ce){const r=tc(e,t,$e(n.name).unwrap_or(""));return(s==null?void 0:s.kind)===f.COLON&&ft(s,t)?pt(r):r}return $()}function $n(e,t){const n=e.container.element(t);if(n instanceof J)return $();const s=e.container.scopeKind(t);if(n.body&&!Ye(t,n.body)){let r;switch(s){case D.TABLE:case D.TABLEPARTIAL:r=[E.HeaderColor,E.Note];break;case D.TABLEGROUP:r=[E.Color,E.Note];break;default:r=[]}return{suggestions:r.map(i=>({label:i,insertText:`${i}: `,kind:P.Field,insertTextRules:U.KeepWhitespace,range:void 0}))}}switch(s){case D.TABLE:case D.TABLEPARTIAL:return{suggestions:[...[E.PK,E.PrimaryKey,E.Null,E.NotNull,E.Increment,E.Unique].map(r=>({label:r,insertText:r,kind:P.Property,insertTextRules:U.KeepWhitespace,range:void 0})),...[E.Ref,E.Default,E.Note,E.Check].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:U.KeepWhitespace,range:void 0}))]};case D.ENUM:return{suggestions:[...[E.Note].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:U.KeepWhitespace,range:void 0}))]};case D.INDEXES:return{suggestions:[...[E.Unique,E.PK].map(r=>({label:r,insertText:r,insertTextRules:U.KeepWhitespace,kind:P.Property,range:void 0})),...[E.Note,E.Name,E.Type].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:U.KeepWhitespace,range:void 0}))]};case D.REF:return{suggestions:[E.Update,E.Delete,E.Color].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:U.KeepWhitespace,range:void 0}))};case D.CHECKS:return{suggestions:[E.Name].map(r=>({label:r,insertText:`${r}: `,kind:P.Property,insertTextRules:U.KeepWhitespace,range:void 0}))}}return $()}function tc(e,t,n){switch(n==null?void 0:n.toLowerCase()){case"update":case"delete":return{suggestions:["cascade","set default","set null","restrict"].map(s=>({label:s,insertText:s,kind:P.Value,insertTextRules:U.KeepWhitespace,range:void 0}))};case"type":return{suggestions:["btree","hash"].map(s=>({label:s,insertText:`${s}`,kind:P.Value,insertTextRules:U.KeepWhitespace,range:void 0}))}}return $()}function $s(e,t,n){const s=Be(n).unwrap_or([]);if(s.pop(),s.some(i=>!W(i)))return $();const r=s.map(i=>Q(i).unwrap());return vt({suggestions:e.symbol.ofName({nameStack:r,owner:e.container.element(t)}).flatMap(({symbol:i})=>e.symbol.members(i)).map(({kind:i,name:a})=>({label:a,insertText:a,kind:et(i),range:void 0}))})}function Xn(e,t,n){var r;switch(e.container.scopeKind(t)){case D.TABLE:case D.TABLEPARTIAL:return sc(e,t,n);case D.PROJECT:return rc(e,t,n);case D.INDEXES:return ac(e,t);case D.ENUM:return nc(e,t,n);case D.REF:{const i=Xs(e,t);return((r=e.container.token(t).token)==null?void 0:r.kind)===f.COLON&&ft(e.container.token(t).token,t)?pt(i):i}case D.TABLEGROUP:return ic(e);default:return $()}}function jn(){return{suggestions:["Table","TableGroup","Enum","Project","Ref","TablePartial"].map(e=>({label:e,insertText:e,insertTextRules:U.KeepWhitespace,kind:P.Keyword,range:void 0}))}}function nc(e,t,n){return n!=null&&n.callee&&tn(t,n)===1?nt(e,t,e.container.element(t),[_.Schema,_.Table,_.Column]):$()}function sc(e,t,n){const s=["Note","indexes","checks"];if(!(n!=null&&n.callee))return{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:U.KeepWhitespace,kind:P.Keyword,range:void 0}))};const r=tn(t,n);return r===0?{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:U.KeepWhitespace,kind:P.Keyword,range:void 0}))}:r===1?oc(e,t):$()}function rc(e,t,n){const s=["Table","TableGroup","Enum","Note","Ref","TablePartial"];return n!=null&&n.callee?tn(t,n)===0?{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:U.KeepWhitespace,kind:P.Keyword,range:void 0}))}:$():{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:U.KeepWhitespace,kind:P.Keyword,range:void 0}))}}function Xs(e,t){return nt(e,t,e.container.element(t),[_.Schema,_.Table,_.Column])}function ic(e){return{suggestions:[...vt({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([t])=>{const n=he(t).unwrap_or(void 0);if(n===void 0)return[];const{kind:s,name:r}=n;return s!==_.Table&&s!==_.Schema?[]:{label:r,insertText:r,insertTextRules:U.KeepWhitespace,kind:et(s),range:void 0}})}).suggestions,...["Note"].map(t=>({label:t,insertText:t,insertTextRules:U.KeepWhitespace,kind:P.Keyword,range:void 0}))]}}function ac(e,t){return js(e,t)}function oc(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"].map(n=>({label:n,insertText:n,insertTextRules:U.KeepWhitespace,kind:P.TypeParameter,sortText:P.TypeParameter.toString().padStart(2,"0"),range:void 0})),...nt(e,t,e.container.element(t),[_.Enum,_.Schema]).suggestions]}}function js(e,t){const n=e.container.element(t),s=n==null?void 0:n.parent;if(!((s==null?void 0:s.symbol)instanceof gs))return $();const{symbolTable:r}=s.symbol;return vt({suggestions:[...r.entries()].flatMap(([i])=>{const a=he(i).unwrap_or(void 0);if(a===void 0)return[];const{name:o}=a;return{label:o,insertText:o,insertTextRules:U.KeepWhitespace,kind:et(_.Column),range:void 0}})})}function tn(e,t){if(!t.callee)return-1;const n=[t.callee,...t.args],s=n.findIndex(r=>e<=r.end);return s===-1?n.length:s}class Ws{constructor(t){this.compiler=t}provideDefinition(t,n){var a,o;const{uri:s}=t,r=en(t,n),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){const u=i.pop();if(!(u!=null&&u.referee))continue;let p;if((a=u.referee)!=null&&a.declaration&&[Se.PRIMARY_EXPRESSION,Se.VARIABLE,Se.PARTIAL_INJECTION].includes(u==null?void 0:u.kind)?{declaration:p}=u.referee:(o=u.referee)!=null&&o.injectorDeclaration&&(p=u.referee.injectorDeclaration),p){const{startPos:h,endPos:d}=p;return[{range:{startColumn:h.column+1,startLineNumber:h.line+1,endColumn:d.column+1,endLineNumber:d.line+1},uri:s}]}}return[]}}class Hs{constructor(t){this.compiler=t}provideReferences(t,n){const{uri:s}=t,r=en(t,n),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){const a=i.pop();if(a&&[Se.ELEMENT_DECLARATION,Se.FUNCTION_APPLICATION,Se.PRIMARY_EXPRESSION].includes(a==null?void 0:a.kind)){const{symbol:o}=a;if(o!=null&&o.references.length)return o.references.map(({startPos:u,endPos:p})=>({range:{startColumn:u.column+1,startLineNumber:u.line+1,endColumn:p.column+1,endLineNumber:p.line+1},uri:s}))}}return[]}}const lc=Object.freeze(Object.defineProperty({__proto__:null,CompletionItemInsertTextRule:U,CompletionItemKind:P,DBMLCompletionItemProvider:Gs,DBMLDefinitionProvider:Ws,DBMLReferencesProvider:Hs},Symbol.toStringTag,{value:"Module"}));var D=(e=>(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))(D||{});class cc{constructor(){this.source="",this.cache=new Array(16).fill(null),this.nodeIdGenerator=new Xo,this.symbolIdGenerator=new Yo,this.token={invalidStream:this.createQuery(6,()=>this.parse.tokens().filter(Ls)),flatStream:this.createQuery(7,()=>this.parse.tokens().flatMap(t=>[...t.leadingInvalid,t,...t.trailingInvalid]))},this.parse={source:()=>this.source,_:this.createQuery(0,()=>{const t=new ul(this.source).lex().chain(n=>new pl(n,this.nodeIdGenerator).parse()).chain(({ast:n,tokens:s})=>new zl(n,this.symbolIdGenerator).analyze().map(()=>({ast:n,tokens:s})));return t.getErrors().length>0?t:t.chain(({ast:n,tokens:s})=>new Jl(n).interpret().map(i=>({ast:n,tokens:s,rawDb:i})))}),ast:this.createQuery(1,()=>this.parse._().getValue().ast),errors:this.createQuery(2,()=>this.parse._().getErrors()),tokens:this.createQuery(4,()=>this.parse._().getValue().tokens),rawDb:this.createQuery(3,()=>this.parse._().getValue().rawDb),publicSymbolTable:this.createQuery(5,()=>this.parse._().getValue().ast.symbol.symbolTable)},this.container={stack:this.createQuery(10,t=>{const n=this.token.flatStream(),{index:s,token:r}=this.container.token(t),i=s===void 0?-1:Mo(n,p=>!p.isInvalid,s);if(i===-1)return[this.parse.ast()];const a=n[i].start;let o=this.parse.ast();const u=[o];for(;;){const h=cl(o).find(d=>Ye(a,d));if(h===void 0||h instanceof q)break;u.push(h),o=h}if((r==null?void 0:r.kind)===f.COLON)return u;for(;u.length>0;){let p=!1;const h=M(u);if(h instanceof y){const d=this.parse.source();for(let N=h.end;N<t;N+=1)d[N]===`
|
|
12
|
+
`&&(u.pop(),p=!0)}else h instanceof re||h instanceof Te?this.container.token(t).token!==h.op&&(u.pop(),p=!0):h instanceof R?h.listCloseBracket&&h.end<=t&&(u.pop(),p=!0):h instanceof be?h.tupleCloseParen&&h.end<=t&&(u.pop(),p=!0):h instanceof Ee?h.blockCloseBrace&&h.end<=t&&(u.pop(),p=!0):h instanceof ce||h.end<t&&(u.pop(),p=!0);if(p){const d=M(u);d instanceof S&&d.end<=t&&u.pop()}if(!p)break}return u}),token:this.createQuery(11,t=>{const n=this.token.flatStream().findIndex(s=>s.start>=t);return n===void 0?{token:void 0,index:void 0}:n<=0?{token:void 0,index:void 0}:{token:this.token.flatStream()[n-1],index:n-1}}),element:this.createQuery(12,t=>{const n=this.container.stack(t);for(let s=n.length-1;s>=0;s-=1)if(n[s]instanceof S)return n[s];return this.parse.ast()}),scope:this.createQuery(14,t=>{var n,s;return(s=(n=this.container.element(t))==null?void 0:n.symbol)==null?void 0:s.symbolTable}),scopeKind:this.createQuery(15,t=>{var s;if(this.container.element(t)instanceof J)return 8;switch((s=this.container.element(t).type)==null?void 0:s.value.toLowerCase()){case"table":return 0;case"enum":return 1;case"ref":return 5;case"tablegroup":return 2;case"indexes":return 3;case"note":return 4;case"project":return 6;case"tablepartial":return 9;case"checks":return 10;default:return 7}})},this.symbol={ofName:this.createQuery(8,({nameStack:t,owner:n=this.parse.ast()})=>{var r;if(t.length===0)return[];const s=[];for(let i=n;i;i=i instanceof S?i.parent:void 0){if(!((r=i.symbol)!=null&&r.symbolTable))continue;const{symbolTable:a}=i.symbol;let o=[a],u=[];for(const p of t)u=o.flatMap(h=>sl(p).flatMap(d=>{const N=h.get(d),m=he(d).unwrap_or(void 0);return!N||!m?[]:{...m,symbol:N}})),o=u.flatMap(h=>h.symbol.symbolTable?h.symbol.symbolTable:[]);s.push(...u)}return s},({nameStack:t,owner:n})=>`${t.join(".")}@${n.id}`),members:this.createQuery(9,t=>t.symbolTable?[...t.symbolTable.entries()].map(([n,s])=>({...he(n).unwrap(),symbol:s})):[])}}createQuery(t,n,s){return r=>{const i=this.cache[t],a=r&&s?s(r):r;if(i!==null){if(!(i instanceof Map))return i;if(i.has(a))return i.get(a)}const o=n(r);return r!==void 0?i instanceof Map?i.set(a,o):(this.cache[t]=new Map,this.cache[t].set(a,o)):this.cache[t]=o,o}}setSource(t){this.source=t,this.cache=new Array(16).fill(null),this.nodeIdGenerator.reset(),this.symbolIdGenerator.reset()}initMonacoServices(){return{definitionProvider:new Ws(this),referenceProvider:new Hs(this),autocompletionProvider:new Gs(this)}}}exports.CompileError=c;exports.CompileErrorCode=l;exports.Compiler=cc;exports.ElementDeclarationNode=S;exports.ElementKind=b;exports.ProgramNode=J;exports.ScopeKind=D;exports.SyntaxNode=k;exports.SyntaxNodeKind=Se;exports.SyntaxToken=q;exports.SyntaxTokenKind=f;exports.serialize=jo;exports.services=lc;
|