@dbml/parse 10.4.0-alpha.15 → 10.4.0-alpha.16

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.
@@ -7,7 +7,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(
7
7
  `);return new Tf(S.INVALID_REF_RELATIONSHIP,c,t,{category:Cf.RefColumnMismatch,explanation:l,quickFixes:o})}function zh(e,t,n){let{relOp:r,columns:i,refNode:a,quickFixes:o}=n,s=Fh(e,i),c=i.length>1?`Columns (\`${s}\`) should have a composite unique index for operator \`${r}\``:`Column \`${s}\` should be unique or primary key for operator \`${r}\``,l=[`- In ref definition \`${Ph(e,a)??r}\`, the operator \`${r}\` implies \`${s}\` has at most one row.`,`- \`${s}\` has no unique or primary key constraint.`].join(`
8
8
  `);return new Tf(S.INVALID_REF_RELATIONSHIP,c,t,{category:Cf.RefColumnMismatch,explanation:l,quickFixes:o})}function Bh(e,t,n,r){let{schema:i,name:a}=r?t.interpretedName(e,r):{schema:t.schema(e),name:t.name??``},o=n.map(e=>{let t=e.name??``;return i?`${i}.${a}.${t}`:`${a}.${t}`});return o.length===1?o[0]:`(${o.join(`, `)})`}function Vh(e,t){return e.length>1?`Composite ${t}`:t}function Hh(e,t){let{colName:n}=t;return new Tf(S.INVALID_RECORDS_FIELD,`NULL not allowed for NOT NULL column \`${n}\` without a default value or auto-increment`,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` is marked NOT NULL and has no default value or auto-increment.`})}function Uh(e,t){let{colName:n}=t;return new Tf(S.INVALID_RECORDS_FIELD,`Invalid enum value for column \`${n}\``,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` uses an enum type. The value must match one of the defined enum members.`})}function Wh(e,t){let{colName:n,typeName:r}=t;return new Tf(S.INVALID_RECORDS_FIELD,`Invalid numeric value for column \`${n}\``,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` has type \`${r}\` which expects a numeric value. Provide a valid integer or decimal.`})}function Gh(e,t){let{colName:n,value:r}=t;return new Tf(S.INVALID_RECORDS_FIELD,`Invalid integer value \`${r}\` for column \`${n}\`: expected integer, got decimal`,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` is an integer column and cannot store decimal values.`})}function Kh(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,totalDigits:s}=t;return new Tf(S.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds precision: expected at most ${a} total digits, got ${s}`,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${a} total digits. The value \`${i}\` has ${s}.`})}function qh(e,t){let{colName:n,typeName:r,value:i,precision:a,scale:o,decimalDigits:s}=t;return new Tf(S.INVALID_RECORDS_FIELD,`Numeric value \`${i}\` for column \`${n}\` exceeds scale: expected at most ${o} decimal digits, got ${s}`,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${a},${o})\`, allowing at most ${o} decimal places. The value \`${i}\` has ${s}.`})}function Jh(e,t){let{colName:n}=t;return new Tf(S.INVALID_RECORDS_FIELD,`Invalid boolean value for column \`${n}\``,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` is a boolean column. Use \`true\`/\`false\`, \`1\`/\`0\`, or \`'yes'\`/\`'no'\`.`})}function Yh(e,t){let{colName:n}=t;return new Tf(S.INVALID_RECORDS_FIELD,`Invalid datetime value for column \`${n}\``,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` expects a date or time value. Supported formats include \`'YYYY-MM-DD'\`, \`'HH:MM:SS'\`, \`'YYYY-MM-DD HH:MM:SS'\`, \`'MM/DD/YYYY'\`, \`'D MMM YYYY'\`, or \`'MMM D, YYYY'\`.`})}function Xh(e,t){let{colName:n}=t;return new Tf(S.INVALID_RECORDS_FIELD,`Invalid string value for column \`${n}\``,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` is a string column. Values must be wrapped in quotes.`})}function Zh(e,t){let{colName:n,typeName:r,typeArg:i,maxLength:a,actualLength:o}=t;return new Tf(S.INVALID_RECORDS_FIELD,`String value for column \`${n}\` exceeds maximum length: expected at most ${a} bytes (UTF-8), got ${o} bytes`,e,{category:Cf.RecordValueTypeMismatch,explanation:`\`${n}\` is defined as \`${r}(${i})\`, limiting values to ${a} bytes in UTF-8 encoding. The provided value uses ${o} bytes.`})}function Qh(e,t,n){let{table:r,columns:i}=n,a=Bh(e,r,i),o=Vh(i,`PK`);return new Tf(S.INVALID_RECORDS_FIELD,`NULL in ${o}: \`${a}\` cannot be NULL`,t,{category:Cf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key and cannot be NULL.`})}function $h(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=Bh(e,r,i),s=Vh(i,`PK`);return new Tf(S.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:Cf.RecordConstraintViolation,explanation:`\`${o}\` is a primary key and must be unique across all rows.`})}function eg(e,t,n){let{table:r,columns:i}=n,a=Bh(e,r,i),o=Vh(i,`PK`);return new Tf(S.INVALID_RECORDS_FIELD,`${o}: Column \`${a}\` is missing from record and has no default value`,t,{category:Cf.RecordConstraintViolation,explanation:`\`${a}\` is a primary key with no default or auto-increment, so it must be specified in the records block.`})}function tg(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=Bh(e,r,i,s),u=Bh(e,a,o,s);return new Tf(S.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` must not be NULL`,t,{category:Cf.RecordConstraintViolation,explanation:`\`${l}\` references \`${u}\`, so every row must have a non-null value.`})}function ng(e,t,n){let{leftTable:r,leftColumns:i,rightTable:a,rightColumns:o,filepath:s,valueStr:c}=n,l=Bh(e,r,i,s),u=Bh(e,a,o,s);return new Tf(S.INVALID_RECORDS_FIELD,`FK violation: \`${l}\` = \`${c}\` does not exist in \`${u}\``,t,{category:Cf.RecordConstraintViolation,explanation:`\`${l}\` is a foreign key referencing \`${u}\`. Every non-null value in an FK must match an existing row in the referenced column.`})}function rg(e,t,n){let{table:r,columns:i,valueStr:a}=n,o=Bh(e,r,i),s=Vh(i,`UNIQUE`);return new Tf(S.INVALID_RECORDS_FIELD,`Duplicate ${s}: \`${o}\` = \`${a}\``,t,{category:Cf.RecordConstraintViolation,explanation:`\`${o}\` has a unique constraint, so no two rows can have the same value.`})}function ig(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function ag(e,t){return e?`${e}.${t}`:`${v}.${t}`}function og(e,t,n){return n.map(n=>{let r=t[n.name??``]?.value;if(r==null){let t=n.default(e);if(t)return JSON.stringify(t.value)}return JSON.stringify(r)}).join(`|`)}function sg(e,t,n){return n.some(n=>{let r=t[n.name??``]?.value;return r==null&&n.default(e)?!1:r==null})}function cg(e,t,n){let r=n.map(n=>{let r=n.name??``,i=t[r]===void 0?n.default(e)?.value:t[r].value;return JSON.stringify(i)}).join(`, `);return n.length===1?r:`(${r})`}function lg(e,t){let n=t.filter(t=>e[t]).map(t=>e[t]);return n.length>0?n:Object.values(e).filter(Boolean)}function ug(e,t){let{token:n}=t;return e.nodeAtPosition(n.filepath,n.start.offset)??e.parse.ast(n.filepath)}function dg(e,t,n,r){return ka(r.values)?[]:Sa(gg(t,e),i=>fg(e,t,n,i,r))}function fg(e,t,n,r,i){let a=ig(i),o=hg(e,t,n,r,i);if(!ka(o))return o;let s=r.filter(t=>!t.increment(e)&&!t.default(e)),[c,l]=g(a,t=>sg(e,t,s)),u=pg(e,t,s,c),d=r.some(t=>t.increment(e))?[]:mg(e,t,r,l);return[...u,...d]}function pg(e,t,n,r){if(ka(r))return[];let i=n.map(e=>e.name??``);return Sa(r,r=>lg(r,i).map(r=>Qh(e,ug(e,r),{table:t,columns:n})))}function mg(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r,t=>og(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=cg(e,r,n);return lg(r,i).map(r=>$h(e,ug(e,r),{table:t,columns:n,valueStr:a}))}))}function hg(e,t,n,r,i){let a=r.map(e=>e.name??``),o=new Set(i.columns),s=fa(a,Array.from(o));if(ka(s))return[];let c=new Set(s),l=r.filter(e=>c.has(e.name??``)).filter(t=>!t.increment(e)&&!t.default(e));return ka(l)?[]:i.values.map(()=>eg(e,n,{table:t,columns:l}))}function gg(e,t){let n=e.mergedColumns(t),r=Aa(n,e=>e.name??``);return[...n.filter(e=>e.pk(t)).map(e=>[e]),...e.mergedIndexes(t).flatMap(e=>{let n=t.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.pk).map(e=>$r(e.columns.map(e=>r[e.value]))):[]})]}function _g(e,t,n){if(ka(n.values))return[];let r=ig(n);return Sa(vg(e,t),n=>yg(e,t,n,r))}function vg(e,t){let n=t.mergedColumns(e),r=Aa(n,e=>e.name??``);return[...n.filter(t=>t.isUniqueSet(e)).map(e=>[e]),...t.mergedIndexes(e).flatMap(t=>{let n=e.interpretMetadata(t,t.declaration.filepath).getValue();return Array.isArray(n)?n.filter(e=>e.unique).map(e=>$r(e.columns.map(e=>r[e.value]))):[]})]}function yg(e,t,n,r){let i=n.map(e=>e.name??``);return Sa(ha(Ta(r.filter(t=>!sg(e,t,n)),t=>og(e,t,n)),e=>e.length>1),r=>Sa(r,r=>{let a=cg(e,r,n);return lg(r,i).map(r=>rg(e,ug(e,r),{table:t,columns:n,valueStr:a}))}))}function bg(e,t,n){let r=new Map;for(let i of e.values()){let{name:e,schema:a}=i.tableSymbol.interpretedName(t,n);r.set(ag(a,e),i)}return r}function xg(e,t,n,r){let i=bg(n,e,r),a=new Set;for(let[e,t]of i)t.record&&!ka(t.record.values)&&a.add(e);return Sa(t.filter(e=>e.endpoints?e.endpoints.some(e=>a.has(ag(e.schemaName,e.tableName))):!1),t=>Sg(e,t,i,r))}function Sg(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=n.get(ag(i.schemaName,i.tableName)),s=n.get(ag(a.schemaName,a.tableName));if(!o||!s)return[];let c=o.tableSymbol.mergedColumns(e),l=s.tableSymbol.mergedColumns(e),u=$r(i.fieldNames.map(e=>c.find(t=>t.name===e))),d=$r(a.fieldNames.map(e=>l.find(t=>t.name===e))),{min:f,max:p}=of(i.relation),{min:m,max:ee}=of(a.relation),te=p===1&&m===0||p!==`*`&&ee!==`*`,ne=ee===1&&f===0;return[...te?[]:Cg(e,o,u,s,d,i.relation,a.relation,r),...ne?[]:Cg(e,s,d,o,u,a.relation,i.relation,r)]}function Cg(e,t,n,r,i,a,o,s){if(!t.record||ka(t.record.values))return[];let{min:c,max:l}=of(a),{min:u,max:d}=of(o),f=$r(n.map(e=>e.name));$r(i.map(e=>e.name));let p=u===0,m=ig(t.record),ee=r.record?ig(r.record):[],te=new Set(ee.map(t=>og(e,t,i))),ne={leftTable:t.tableSymbol,leftColumns:n,rightTable:r.tableSymbol,rightColumns:i,filepath:s};return Sa(m,t=>{if(sg(e,t,n)){if(p)return[];let r=cg(e,t,n);return lg(t,f).map(t=>tg(e,ug(e,t),{...ne,valueStr:r}))}if(d===`*`&&c===0&&l===`*`)return[];let r=og(e,t,n);if(te.has(r))return[];let i=cg(e,t,n);return lg(t,f).map(t=>ng(e,ug(e,t),{...ne,valueStr:i}))})}function wg(e){return e instanceof qm&&e.declaration instanceof R&&e.declaration.body instanceof H}function Tg(e,t){let n=e.edges??[];if(n.length===0||!wg(t))return[];let r=[],i=ag(n[0].downstream.schemaName,n[0].downstream.tableName);for(let e=1;e<n.length;e++){let a=ag(n[e].downstream.schemaName,n[e].downstream.tableName);if(a!==i){r.push(new C(S.DEP_MIXED_DOWNSTREAM_TABLES,`All edges in a Dep block must target the same downstream table, but found '${i}' and '${a}'`,t.declaration));break}}let a=e=>e.upstream.fieldNames.length>0||e.downstream.fieldNames.length>0,o=a(n[0]);for(let e=1;e<n.length;e++)if(a(n[e])!==o){r.push(new C(S.DEP_MIXED_LEVEL,`All edges in a Dep block must be at the same level (all table-level or all column-level)`,t.declaration));break}return r}function Eg(e,t){let n=Ag(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof z&&vp(e)?.toLowerCase()===t.toLowerCase());if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof R){let n=jg(e,t);if(n)return{kind:`body`,declaration:n}}}function Dg(e,t){let n=Ag(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof R){let n=e.body;if(n&&!(n instanceof V))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function Og(e,t,n,r){if(n===null)return kg(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=Eg(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return Dg(e,i)}function kg(e,t,n){let r=Eg(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function Ag(e){if(e instanceof V)return e.args.find(e=>e instanceof U);if(e instanceof R){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof V)return t.args.find(e=>e instanceof U)}}function jg(e,t){let n=e.body;if(!(!n||Nf(e)||n instanceof V)){for(let e of n.body)if(e instanceof R&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function Mg(e,t,n,r){let{allowOtherColFix:i=!0,allowOwnColFix:a=!0}=r??{},o=t.op(e),s=t.opToken(),c=t.cardinalities(e);if(!o||!s||!c)return[];let l=n===`left`?c[0]:c[1],u=of(l),d=n===`left`?c[1]:c[0],f=of(d),p=n===`left`?t.leftColumns(e):t.rightColumns(e),m=n===`left`?t.rightColumns(e):t.leftColumns(e),ee=n===`left`?t.leftToken():t.rightToken(),te=n===`left`?t.rightToken():t.leftToken(),ne=[];function re(e,t,n){ne.push(n(e));for(let r of t)r.declaration&&r.declaration!==e&&ne.push(n(r.declaration))}let ie=f.max===`*`||u.max===1&&f.max===1&&n===`left`;if(u.min>=1&&ie&&m.length>0&&m.every(t=>t.nullable(e))){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Pg(s,bf(l),d,n,`Make '${r}' optional in the ref`),...i?m.map(t=>Fg(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Ih(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.min===0&&ie&&m.length>0&&m.every(t=>t.nullable(e)===!1)){let r=m.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),a=[s&&Pg(s,xf(l),d,n,`Make '${r}' required in the ref`),...i?m.map(t=>Ig(t,e)).filter(e=>!!e):[]].filter(e=>!!e);re(te,m,n=>Lh(e,n,{relOp:o,columns:m,refNode:t.declaration,quickFixes:a}))}if(u.max===`*`&&Lg(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Pg(s,`1`,d,n,`Make '${r}' one in the ref`)].filter(e=>!!e);re(ee,p,n=>Rh(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}if(u.max===1&&!Lg(e,p)){let r=p.map(t=>t.qualifiedName(e).join(`.`)).join(`, `),i=[s&&Pg(s,Sf(l),d,n,`Make '${r}' many in the ref`),a&&p.length===1&&Rg(p[0],e)].filter(e=>!!e);re(ee,p,n=>zh(e,n,{relOp:o,columns:p,refNode:t.declaration,quickFixes:i}))}return ne}function Ng(e,t){return[...Mg(e,t,`right`,{allowOtherColFix:!1}),...Mg(e,t,`left`,{allowOwnColFix:!1})]}function Pg(e,t,n,r,i){let a=yf(r===`left`?t:n,r===`right`?t:n);return{title:`${i} (change operator to '${a}')`,shortTitle:`Change to ${a}`,filepath:e.filepath,edits:[{start:e.start,end:e.end,newText:a}],isPreferred:!0}}function Fg(e,t){if(!e.declaration||e.pk(t)||e.increment(t)||e.isNotNullSet(t))return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=e.qualifiedName(t).join(`.`),i=kg(e.declaration,`null`,n);if(i)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[i]};let a=Dg(e.declaration,`not null`);if(a)return{title:`Mark '${r}' as NOT NULL`,shortTitle:`Add not null`,filepath:e.declaration.filepath,edits:[a]}}function Ig(e,t){if(!e.declaration)return;let n=t.getSource(e.declaration.filepath);if(!n)return;let r=kg(e.declaration,`not null`,n);if(r)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as NULL`,shortTitle:`Make nullable`,filepath:e.declaration.filepath,edits:[r]}}function Lg(e,n){if(n.length===0)return!1;if(n.length===1&&n[0].unique(e))return!0;let r=n[0],i=(r instanceof dm?r.injectionDeclaration:r.declaration)?.parentOfKind(R);if(!i)return!1;let a=e.nodeSymbol(i).getFiltered(t);if(!(a instanceof Yp))return!1;let o=a.mergedIndexes(e),s=new Set(n.map(e=>e.name));for(let t of o){let r=e.interpretMetadata(t,n[0].filepath).getValue();if(r&&Array.isArray(r)){for(let e of r)if((e.unique||e.pk)&&e.columns.length===s.size&&e.columns.every(e=>s.has(e.value)))return!0}}return!1}function Rg(e,t){if(!e.declaration||e.isUniqueSet(t)||e.pk(t))return;let n=Dg(e.declaration,`unique`);if(n)return{title:`Mark '${e.qualifiedName(t).join(`.`)}' as UNIQUE`,shortTitle:`Add unique`,filepath:e.declaration.filepath,edits:[n]}}var zg=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.infos=[],this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],deps:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:N(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.validatePartialRefs(),this.infos.push(...this.validateRecords()),new n(this.db,this.errors,this.warnings,this.infos)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let n=this.compiler.nodeSymbol(e).getFiltered(t);if(!n||n instanceof um)continue;let r=this.compiler.interpretSymbol(n,this.filepath);if(r.hasValue(t))continue;this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let i=r.getValue();i&&this.pushElement(n,i)}let e=new Set,n=(this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[]).filter(e=>e instanceof Kp);for(;n.length>0;){let r=n.shift(),i=this.compiler.symbolMembers(r).getFiltered(t)??[];for(let t of i){if(t instanceof Kp){n.push(t);continue}if(!(t instanceof um))continue;let r=t.originalSymbol.intern();e.has(r)||(e.add(r),this.interpretUseSymbol(t))}}}interpretUseSymbol(e){let n=e.originalSymbol,r=this.compiler.interpretSymbol(n,this.filepath);if(!r.hasValue(t)){this.errors.push(...r.getErrors()),this.warnings.push(...r.getWarnings()),this.infos.push(...r.getInfos());let t=r.getValue();t&&this.pushElement(e,t)}let i=n instanceof Yp?n.interpretedName(this.compiler,n.filepath):{name:n.name??``,schema:null},a=n instanceof Yp?n.interpretedName(this.compiler,this.filepath):{name:e.name??n.name??``,schema:null},o={name:i.name,schemaName:i.schema,filepath:n.filepath,visibleNames:[{schemaName:a.schema,name:a.name}]};jh(this.db,e,o)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],n=new Set,r=new Set,i=new Map;for(let t of e){if(!(t instanceof Zm))continue;let e=t.table(this.compiler);if(!e)continue;let n=e.originalSymbol.intern(),r=i.get(n);r?r.count++:i.set(n,{count:1,tableName:e.name??``})}for(let a of e){let e=this.compiler.interpretMetadata(a,this.filepath);if(e.hasValue(t))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings()),this.infos.push(...e.getInfos());let o=e.getValue();if(o!==void 0)switch(a.kind){case Wm.Ref:{let e=o,[t,r]=e.endpoints??[];if(t&&r){let e=[t.schemaName,t.tableName,t.fieldNames.join(`,`),r.schemaName,r.tableName,r.fieldNames.join(`,`)].join(`|`),i=[r.schemaName,r.tableName,r.fieldNames.join(`,`),t.schemaName,t.tableName,t.fieldNames.join(`,`)].join(`|`);if(n.has(e)||n.has(i)){this.errors.push(new C(S.SAME_ENDPOINT,`Ref with same endpoints already exists`,a.declaration));break}n.add(e)}this.db.refs.push(e);break}case Wm.Dep:{let e=o,t=a instanceof qm?a.edgeExpressions():[],n=-1;if((e.edges??[]).some((e,t)=>{let{upstream:i,downstream:a}=e,o=[i.schemaName,i.tableName,i.fieldNames.join(`,`),a.schemaName,a.tableName,a.fieldNames.join(`,`)].join(`|`);return r.has(o)?(n=t,!0):(r.add(o),!1)}),n>=0){let e=t[n]??a.declaration;this.errors.push(new C(S.SAME_ENDPOINT,`Dep with same endpoints already exists`,e));break}let i=Tg(e,a);if(i.length>0){this.errors.push(...i);break}this.db.deps.push(e);break}case Wm.Records:if(a instanceof Zm){let e=a.table(this.compiler)?.originalSymbol.intern()??``,t=e?i.get(e):void 0;if(t&&t.count>1){this.errors.push(new C(S.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,a.declaration));break}}this.db.records.push(o);break;case Wm.Project:this.db.project=o;break;case Wm.MetadataElement:}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let t of e){if(!(t instanceof lm)||!t.isKind(P.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:jm.Table,value:{tableName:e,schemaName:n}};this.db.aliases.push(r)}}validateRecords(){let e=[],n=new Map,r=this.compiler.symbolMembers(this.programSymbol).getFiltered(t)??[];for(let e of r){if(!(e instanceof Kp))continue;let r=this.compiler.symbolMembers(e).getFiltered(t)??[];for(let e of r){if(!e.isKind(P.Table))continue;let t=e.originalSymbol;if(!(t instanceof Yp))continue;let r=t.intern();n.has(r)||n.set(r,{tableSymbol:t,record:void 0,recordBlock:t.declaration})}}let i=this.compiler.symbolMetadata(this.programSymbol);for(let r of i){if(!(r instanceof Zm))continue;let i=r.table(this.compiler);if(!(i instanceof Yp))continue;let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))continue;let o=a.getValue();if(!o)continue;e.push(...dg(this.compiler,i,r.declaration,o)),e.push(..._g(this.compiler,i,o));let s=i.originalSymbol.intern(),c=n.get(s);c?c.record=o:n.set(s,{tableSymbol:i,record:o,recordBlock:r.declaration})}let a=this.collectPartialRefs(n);return e.push(...xg(this.compiler,[...this.db.refs,...a],n,this.filepath)),e}validatePartialRefs(){let e=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Jm);for(let t of e)this.infos.push(...Ng(this.compiler,t))}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Jm),n=[];for(let{tableSymbol:r}of e.values())for(let e of r.resolvedPartials(this.compiler))for(let i of t){if(i.leftTablePartial(this.compiler)?.originalSymbol!==e.originalSymbol)continue;let t=i.leftColumns(this.compiler),a=i.rightTable(this.compiler),o=i.rightColumns(this.compiler),s=i.op(this.compiler);if(!a||!s||t.length===0||o.length===0)continue;let c=r.mergedColumns(this.compiler);if(!t.some(e=>c.some(t=>t instanceof dm&&t.declaration===e.declaration)))continue;let l=pf(s);if(!l)continue;let u=a instanceof em&&a.originalSymbol===e.originalSymbol?r:a,d=r.interpretedName(this.compiler,this.filepath),f=u.interpretedName(this.compiler,this.filepath),p={schemaName:d.schema,tableName:d.name,fieldNames:t.map(e=>e.name??``),relation:l[0],token:N(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:N(i.rightToken())};n.push({token:N(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case P.Table:this.db.tables.push(t);break;case P.Enum:this.db.enums.push(t);break;case P.TableGroup:this.db.tableGroups.push(t);break;case P.TablePartial:this.db.tablePartials.push(t);break;case P.StickyNote:this.db.notes.push(t);break;case P.DiagramView:this.db.diagramViews.push(t)}}},Bg={nodeSymbol(t,r){return Zf(r)?n.create(t.symbolFactory.create(cm,{declaration:r,name:r.filepath.absolute},r.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(P.Program))return n.create(e);if(!(i.declaration instanceof L))return n.create([]);let a=new Map;for(let e of r.reachableFiles(i.filepath)){let{schemaMembers:t}=r.usableMembers(e).getValue();for(let e of t)a.has(e.name)||a.set(e.name,e)}let o=a.get(v);if(!o)return n.create([...a.values()]);let s=r.symbolMembers(o).getFiltered(t)?.filter(e=>!e.isKind(P.Schema));return s?n.create([...a.values(),...s]):n.create([...a.values()])},bindNode(t,r){return Zf(r)?new kh(r,t).resolve():n.create(e)},interpretSymbol(t,r,i){if(!(r instanceof cm))return n.create(e);if(!(r.declaration instanceof L))return n.create(void 0);if(!Rm(t,r.declaration)){let e=t.reachableFiles(i).flatMap(e=>t.bindFile(e).getErrors());return n.create(void 0,e)}return new zg(t,r,i).interpret()}},Vg=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof V)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Hg=class{constructor(e,t,n){this.declarationNode=t,this.compiler=e,this.filepath=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){this.project.token=N(this.declarationNode);let e=[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)];return new n(this.project,e)}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=Lp(e);return this.project.name=t,[]}interpretSubElement(e){let r=this.compiler.nodeSymbol(e).getFiltered(t);if(r){let e=this.compiler.interpretSymbol(r,this.filepath);if(!e.hasValue(t))return e}return n.create(void 0)}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.getElementKind()){case r.Table:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tables?.push(e.getValue()),e.getErrors()}case r.TableGroup:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tableGroups?.push(e.getValue()),e.getErrors()}case r.Enum:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.enums?.push(e.getValue()),e.getErrors()}case r.Note:{let e=t.body instanceof H?t.body.body[0]?.callee:t.body?.callee,n=e?j(e):void 0;return n&&(this.project.note={value:Ip(n),token:N(t)}),[]}case r.TablePartial:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tablePartials?.push(e.getValue()),e.getErrors()}default:return this.project[t.type.value.toLowerCase()]=j(t.body.callee),[]}})}},Ug={nodeMetadata(t,i){return O(i,r.Project)?n.create(new $m(i)):n.create(e)},bindNode(t,i){return O(i,r.Project)?n.create(void 0,new Vg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return!(r instanceof $m)||!(r.declaration instanceof R)?n.create(e):new Hg(t,r.declaration,i).interpret()}},Wg=class{constructor(e,t){this.compiler=e,this.declarationNode=t,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof H&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof L?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let n=gp(e);if(!n)return[];let r=n.variables.pop(),i=n.variables;if(!r)return[];let a=this.compiler.nodeReferee(r).getErrors();if(a.length>0)return a;let o=this.compiler.nodeReferee(r).getFiltered(t);if(!o)return[];let s=lp(o.declaration)??`<invalid name>`,c=i.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of n.args){let n=_p(e)??`<unnamed>`,r=this.compiler.nodeReferee(e).getFiltered(t);if(!r){c.push(new C(S.BINDING_ERROR,`Column '${n}' does not exist in Table '${s}'`,e));continue}let i=this.boundColumns.get(r);i&&(c.push(new C(S.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,i)),c.push(new C(S.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${n}' is referenced more than once in a Records for Table '${s}'`,e))),this.boundColumns.set(r,e)}return c}bindInsideTableName(e){let n=this.declarationNode.parent;if(!(n instanceof R)||!n.isKind(r.Table)||!this.compiler.nodeSymbol(n).getFiltered(t)||!Uf(e))return[];let i=lp(n)??`<invalid name>`,a=[];for(let n of e.elementList){let e=_p(n)??`<unnamed>`;this.compiler.nodeReferee(n).getFiltered(t)||a.push(new C(S.BINDING_ERROR,`Column '${e}' does not exist in Table '${i}'`,n))}return a}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof V),n=e.body.filter(e=>e instanceof R);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof Sm?e.callee.elementList:[e.callee]).flatMap(zm).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();return!t||!n?[]:[...e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors()),...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}):[]}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Gg=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],r=Kg(this.element,this.compiler,this.filepath);if(!r||r.columns.length===0)return new n(void 0,e);let i=[];for(let n of this.element.body.body){let a=qg(n,r.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getInfos());let o=a.getValue();o.row&&i.push(o.row)}let a=N(this.element),o=this.metadata.example(this.compiler)||void 0;return new n({schemaName:r.schemaName,tableName:r.tableName,columns:r.columns.map(e=>e.name??``),values:i,example:o,token:a},e,[],t)}};function Kg(e,n,i){let a=e.name,o=e.parent;if(o instanceof R&&o.isKind(r.Table)){let e=n.nodeSymbol(o).getFiltered(t);if(!(e instanceof Yp))return;let r=e.mergedColumns(n),s=e.interpretedName(n,i),c=s.schema,l=s.name;return a?{schemaName:c,tableName:l,columns:a.elementList.flatMap(e=>r.find(t=>t.name===M(e))||[])}:{schemaName:c,tableName:l,columns:r}}let s=gp(a);if(!s)return;let c=s.variables.map(e=>e.expression.variable?.value??``),l=c.at(-1)??``,u=c.length>1?c.slice(0,-1).join(`.`):void 0,d=n.parseFile(e.filepath).getValue().ast,f=n.nodeSymbol(d).getFiltered(t);if(!f)return;let p;if(u){let e=n.lookupMembers(f,P.Schema,u);e&&(p=n.lookupMembers(e,P.Table,l))}if(p||=n.lookupMembers(f,P.Table,l),!p)return;let m=p.originalSymbol;if(!(m instanceof Yp))return;let ee=m.mergedColumns(n),te=s.args.map(e=>ee.find(t=>t.name===M(e))).filter(Boolean),ne=m.interpretedName(n,i);return{schemaName:ne.schema,tableName:ne.name,columns:te}}function qg(e,t,r){let i=[],a=[],o={},s=e.callee instanceof Sm?e.callee.elementList:[e.callee];if(s.length!==t.length)return i.push(new C(S.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new n({row:null,columnNodes:{}},i,[],a);let c=[];for(let e=0;e<t.length;e++){let n=s[e],l=t[e];o[l.name??``]=n;let u=Yg(n,l,r);i.push(...u.getErrors()),a.push(...u.getInfos());let d=u.getValue();c.push(d??{value:null,type:`expression`,token:N(n)})}return new n({row:c,columnNodes:o},i,[],a)}function Jg(e){return e instanceof bm&&e.value?.value||``}function Yg(e,t,r){let i=N(e),a=t.type(r),o=(a?.name??``).split(`(`)[0],s=!!a?.enumSymbol,c=t.increment(r),l=t.isNotNullSet(r)===!0,u=t.default(r),d=t.name??``,f=Go(o,s),p=kp(e),m=p===null?Jg(e):p,ee=p===null?`expression`:f;if(e instanceof bm)return new n({value:e.value?.value||``,type:`expression`,token:i},[],[]);if(yp(e)||bp(e)&&!Vo(o)){let t=u&&u.value.toString().toLowerCase()!==`null`,r=Wo(o);return l&&!t&&!c&&!r?new n({value:null,type:f,token:i},[],[],[Hh(e,{colName:d})]):new n({value:null,type:f,token:i},[],[])}if(s){let a=t.type(r)?.enumSymbol,o=a?a.members(r).filter(e=>e.isKind(P.EnumField)).map(e=>e.name).filter(Boolean):[],s=j(e);return s===void 0&&(s=E(e)?e.expression.variable.value:void 0),o.includes(s)?new n({value:s,type:f,token:i},[],[]):new n({value:s,type:f,token:i},[],[],[Uh(e,{colName:d})])}if(Lo(o)||Ro(o)||Wo(o)){let t=Sp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Wh(e,{colName:d,typeName:o})]);if(Lo(o)&&!Number.isInteger(t))return new n({value:Math.floor(t),type:f,token:i},[],[],[Gh(e,{colName:d,value:t})]);let r=Ro(o)&&a?.args?.length?{precision:Number(a.args[0]),scale:a.args.length>=2?Number(a.args[1]):0}:void 0;if(Ro(o)&&r){let{precision:a,scale:s}=r,c=t.toString().split(`.`),l=c[0].replace(/^-/,``),u=c[1]||``,p=l.length+u.length,m=u.length;if(p>a)return new n({value:t,type:f,token:i},[],[],[Kh(e,{colName:d,typeName:o,value:t,precision:a,scale:s,totalDigits:p})]);if(m>s)return new n({value:t,type:f,token:i},[],[],[qh(e,{colName:d,typeName:o,value:t,precision:a,scale:s,decimalDigits:m})])}return new n({value:t,type:f,token:i},[],[])}if(Bo(o)){let t=Dp(e);return t===null?new n({value:m,type:ee,token:i},[],[],[Jh(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Uo(o)){let t=Np(e);return t===null?new n({value:m,type:ee,token:i},[],[],[Yh(e,{colName:d})]):new n({value:t,type:f,token:i},[],[])}if(Vo(o)){let t=kp(e);if(t===null)return new n({value:m,type:ee,token:i},[],[],[Xh(e,{colName:d})]);let r=a?.args?.length?Number(a.args[0]):void 0;if(r&&!Number.isNaN(r)){let s=r,c=new TextEncoder().encode(t).length;if(c>s)return new n({value:t,type:f,token:i},[],[],[Zh(e,{colName:d,typeName:o,typeArg:String(a.args[0]),maxLength:s,actualLength:c})])}return new n({value:t,type:`string`,token:i},[],[])}return new n({value:m,type:ee,token:i},[],[])}var Xg={nodeMetadata(t,i){if(!O(i,r.Records))return n.create(e);let a=i.parent;if(a&&O(a,r.Table))return n.create(new Zm(i));let o=i.name;return o instanceof W&&o.callee?n.create(new Zm(i)):n.create(e)},nodeReferee(i,a){if(!E(a))return n.create(e);let o=a.parentOfKind(R);if(!o?.isKind(r.Records))return n.create(e);let s=i.parseFile(a.filepath).getValue().ast,c=i.nodeSymbol(s).getFiltered(t);if(!c)return n.create(void 0);let l=a.parentOfKind(xm);if(l?.parentNode===o)return Zg(i,o,a);let u=a.parentOfKind(W);return u?.parentNode===o&&l?.parentNode===u?Qg(i,u,a):u?.parentNode===o&&u.callee?.containsEq(a)?$g(i,c,a):t_(i,c,a)},bindNode(t,i){return O(i,r.Records)?n.create(void 0,new Wg(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Zm?r.declaration instanceof R?new Gg(t,r,i).interpret():n.create(void 0):n.create(e)}};function Zg(e,i,a){let o=i.parent;if(o instanceof R&&o.isKind(r.Table)){let n=e.nodeSymbol(o).getFiltered(t);if(n)return e_(e,n,a)}return new n(void 0)}function Qg(e,r,i){if(r.callee){let n;if(E(r.callee))n=e.nodeReferee(r.callee).getFiltered(t);else{let i=fp(r.callee);if(i&&i.length>0){let r=i[i.length-1];n=e.nodeReferee(r).getFiltered(t)}}if(n)return e_(e,n,i)}return new n(void 0)}function $g(e,t,r){if(!E(r))return new n(void 0);let i=_p(r)??``;if(!D(r.parentNode)){let a=e.lookupMembers(t,[P.Table,P.Schema],i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Table '${i}' does not exist in Schema 'public'`,r)])}let a=Bm(e,r);if(!a){let a=e.lookupMembers(t,[P.Table,P.Schema],i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Table,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${i}' does not exist`,r)])}return new n(void 0)}function e_(e,t,r){if(!E(r))return new n(void 0);let i=_p(r)??``,a=e.lookupMembers(t,P.Column,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Column '${i}' does not exist in Table 'public.${t.name}'`,r)])}function t_(e,t,r){if(!E(r))return new n(void 0);let i=_p(r)??``;if(!D(r.parentNode))return new n(void 0);let a=Bm(e,r);if(a){if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Enum,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(P.Enum)){let t=e.lookupMembers(a,P.EnumField,i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(D(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,P.Enum,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var n_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof L)&&!this.declarationNode.parent?.isKind(r.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(zm).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();return!t||!n?[]:(Array.isArray(t)||(t=[t]),[...e.variables,n,...t].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},r_=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=N(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()],{infos:t}=this.validateRefConstraints();return n.create(this.ref,e,void 0,t)}interpretName(){if(!(this.declarationNode instanceof R))return[];let e=[],t=A(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new C(S.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if(Ra(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new C(S.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=pf(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=N(this.metadata.leftToken()),l=N(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof R?[{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c},{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l}]:[{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l},{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c}],!(this.declarationNode instanceof R))return[];let u=dp(this.declarationNode)[0];if(u.args[0]){let e=w(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof _m?cp(t):M(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof _m?cp(n):M(n),this.ref.color=e.color?.length?Rp(e.color?.at(0)?.value):void 0,this.ref.inactive=e.inactive?.length?!0:void 0}return[]}validateRefConstraints(){return this.metadata.cardinalities(this.compiler)?{infos:[...Mg(this.compiler,this.metadata,`right`),...Mg(this.compiler,this.metadata,`left`)]}:{infos:[]}}};function i_(e){let t=e.parent;for(;t;){if(t instanceof R&&t.isKind(r.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var a_={nodeReferee(r,i){if(!E(i)&&!D(i)||!i_(i)||i.parentOfKind(z))return n.create(e);let a=r.parseFile(i.filepath).getValue().ast,o=r.nodeSymbol(a).getValue();return o===t?n.create(void 0):o_(r,o,i)},nodeMetadata(t,a){if(O(a,r.Ref)){let t=dp(a)[0];if(!(t instanceof V)||!t.callee)return n.create(e);let r=t.callee;return!(r instanceof vm)||!r.op?n.create(e):n.create(new Km(a))}if(a instanceof z){if(!(a.name instanceof _m)||cp(a.name)?.toLowerCase()!==i.Ref)return n.create(e);let t=a.parent;return t instanceof R&&t.isKind(r.TablePartial)?n.create(new Jm(a)):n.create(new Km(a))}return n.create(e)},bindNode(t,i){return O(i,r.Ref)?n.create(void 0,new n_(t,i).bind()):n.create(e)},interpretMetadata(t,r,i){return r instanceof Km?new r_(t,r,i).interpret():n.create(e)}};function o_(e,r,i){if(!E(i))return new n(void 0);let a=_p(i)??``;if(!D(i.parentNode)){let r=i.parentNode;if(r&&D(r.parentNode)&&r.parentNode.rightExpression===r){let o=r.parentNode.leftExpression,s=D(o)?o.rightExpression??o:o,c=e.nodeReferee(s).getFiltered(t);if(c?.isKind(P.Table)){let r=e.lookupMembers(c,P.Column,a);if(r)return n.create(r);let o=c.declaration?e.nodeFullname(c.declaration).getFiltered(t)?.join(`.`)??c.name:c.name;return new n(void 0,[new C(S.BINDING_ERROR,`Column '${a}' does not exist in Table '${o}'`,i)])}}return n.create(void 0)}let o=Bm(e,i);if(o){if(o.isKind(P.Schema)){let t=e.lookupMembers(o,[P.Table,P.Schema],a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}if(o.isKind(P.Table)){let r=e.lookupMembers(o,P.Column,a);return r?n.create(r):new n(void 0,[new C(S.BINDING_ERROR,`Column '${a}' does not exist in Table '${o.declaration?e.nodeFullname(o.declaration).getFiltered(t)?.join(`.`)??o.name:o.name}'`,i)])}return new n(void 0)}let s=i.parentNode;if(s.leftExpression===i){if(D(s.parentNode)&&s.parentNode.leftExpression===s){let t=e.lookupMembers(r,P.Schema,a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}let t=Hm(e,r);if(t){let r=e.lookupMembers(t,P.Table,a);if(r)return n.create(r)}let o=e.lookupMembers(r,P.Table,a);return o?n.create(o):new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}return new n(void 0)}var s_={visibleName(e,n){if(n instanceof Gp&&!(n.useSpecifierDeclaration instanceof hm))return n.name===void 0?void 0:[n.name];let r=n instanceof I?n:n.useSpecifierDeclaration instanceof hm?n.useSpecifierDeclaration:n.declaration;if(r instanceof hm&&n instanceof Gp&&r.getSymbolKind()!==n.kind&&(r=n.declaration),!r)return;let i=e.nodeAlias(r).getFiltered(t);return i===void 0?e.nodeFullname(r).getFiltered(t):[i]}},c_={nodeSymbol(r,i){if(!Xf(i)||!i.name)return n.create(e);let a=i.getSymbolKind();if(a===void 0||a===P.Schema)return n.create(e);let o=r.nodeReferee(i.name).getFiltered(t);return o&&!o.canBeImported?n.create(e):n.create(r.symbolFactory.create(um,{useSpecifierDeclaration:i,declaration:o?.declaration,usedSymbol:o,kind:a,name:s_.visibleName(r,i)?.at(-1)},i.filepath),o===void 0?[new C(S.BINDING_ERROR,`Failed to resolve the import of ${a} '${(A(i.name)||[]).map(z_).join(`.`)}'`,i)]:[])},symbolMembers(r,i){if(!(i instanceof um))return n.create(e);if(i.originalSymbol===i)return n.create([]);let a=r.symbolMembers(i.originalSymbol).getFiltered(t);return n.create(a??[])},nodeReferee(r,i){if(!E(i)&&!Jf(i))return n.create(e);let a=i.parentOfKind(hm);if(!a)return n.create(e);let o=a.name===i||D(a.name)&&a.name.rightExpression===i?a.getSymbolKind():P.Schema;if(o===void 0)return n.create(void 0);let s=A(i.parentOfKind(vm)),c=M(i)??s?.at(-1);if(c===void 0)return n.create(void 0);let l=i.parentOfKind(mm);if(l?.importPath?.value===void 0)return n.create(void 0);let u=r.layout.resolveFileSpecifier(i.filepath,l.importPath.value);if(!u)return n.create(void 0,[new C(S.BINDING_ERROR,`Import path must be relative, got '${l.importPath.value}'`,i)]);if(!r.layout.exists(u))return n.create(void 0,[new C(S.NONEXISTENT_MODULE,`${o} '${s?.join(`.`)??c}' does not exist in file ${u.toKey()}. Does the file exist?`,i)]);let d=i.parentOfKind(vm)?.leftExpression;if(d&&d!==i){let e=r.nodeReferee(d).getFiltered(t);if(!e)return n.create(void 0);let a=r.lookupMembers(e,o,c);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Could not find ${o} '${c}'`,i)])}let f=l_(r,u,c,o);return f?n.create(f):n.create(void 0,[new C(S.BINDING_ERROR,`${o} '${c}' does not exist in file ${u.toKey()}`,i)])},bindNode(t,r){if(Yf(r)){let e=[];if(r.importPath?.value){let n=t.layout.resolveFileSpecifier(r.filepath,r.importPath.value);(!n||!t.layout.exists(n))&&e.push(new C(S.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${r.importPath.value}'`,r.importPath))}if(r.specifiers){let n=t.bindNode(r.specifiers);e.push(...n.getErrors())}return new n(void 0,e)}return r instanceof gm?new n(void 0,r.specifiers.flatMap(e=>t.bindNode(e).getErrors())):Xf(r)?r.name?new n(void 0,t.nodeReferee(r.name).getErrors()):new n(void 0):n.create(e)},interpretSymbol(r,i,a){if(!(i instanceof um))return n.create(e);if(!i.usedSymbol)return n.create(void 0);let o=r.interpretSymbol(i.usedSymbol,a);if(o.hasValue(t))return n.create(void 0);let s=o.getValue();if(!s||Array.isArray(s))return o;let c=i.name;return c&&`name`in s?n.create({...s,name:c}):n.create(s)}};function l_(e,n,r,i,a=new Set){if(!n||a.has(n.intern()))return;a.add(n.intern());let o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.nonSchemaMembers.find(e=>e.name===r&&e.isKind(i));if(s)return s;let c=o.schemaMembers.find(e=>e.name===r);if(c?.isKind(P.Schema))return c;for(let t of o.reuses.selective)if(A(t.alias??t.name)?.at(-1)===r){let o=t.parentOfKind(mm);if(o?.importPath?.value){let s=l_(e,e.layout.resolveFileSpecifier(n,o.importPath.value),A(t.name)?.at(-1)??r,i,a);if(s)return s}}for(let{importPath:t}of o.reuses.wildcard){let n=l_(e,t,r,i,a);if(n)return n}}function u_(e){if(e instanceof So){let{ast:n}=this.parseFile(e).getValue(),r=this.nodeSymbol(n).getFiltered(t);return this.usableMembers(r)}let r=e.filepath,i=f_(this,r),{nonSchemaMembers:a,schemaMembers:o}=e instanceof cm?p_(this,e,i):m_(this,e,i);return new n({nonSchemaMembers:a,schemaMembers:o,reuses:{selective:i.selectiveReuses,wildcard:i.wildcardReuses},uses:{selective:i.selectiveUses,wildcard:i.wildcardUses}},i.parseResult.getErrors(),i.parseResult.getWarnings())}function d_(e,n,r){let i=n.qualifiedName,a;if(a=r instanceof hm?s_.visibleName(e,r):e.nodeFullname(r).getFiltered(t),!a)return{kind:`none`};let o=r instanceof hm&&r.getSymbolKind()===P.Schema?a:a.length<=1?[v]:a.slice(0,-1);return o.length<i.length||!i.every((e,t)=>e===o[t])?{kind:`none`}:o.length===i.length?{kind:`direct`}:{kind:`child`,schemaName:o[i.length]}}function f_(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let n of r.body){if(!(n instanceof mm)||!n.specifiers||!n.importPath)continue;let r=e.layout.resolveFileSpecifier(t,n.importPath.value);r&&(n.isReuse?n.specifiers instanceof Tm?i.push({importPath:r,node:n.specifiers}):a.push(...n.specifiers.specifiers):n.specifiers instanceof Tm?o.push({importPath:r,node:n.specifiers}):s.push(...n.specifiers.specifiers))}return{ast:r,parseResult:n,selectiveReuses:a,wildcardReuses:i,selectiveUses:s,wildcardUses:o}}function p_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=n.filepath,c=new Map([[v,e.symbolFactory.create(Kp,{name:v},s)]]);for(let n of i.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],i=r.length<=1?v:r[0];c.has(i)||c.set(i,e.symbolFactory.create(Kp,{name:i},s))}h_(e,[...a,...o],c,s);for(let t of e.reachableFiles(s))for(let n of __(e,t))c.has(n)||c.set(n,e.symbolFactory.create(Kp,{name:n},s));let l=[...c.values()],u=[],d=l.find(e=>e.isPublicSchema());if(d){let n=e.usableMembers(d).getFiltered(t);n&&u.push(...n.nonSchemaMembers)}return{nonSchemaMembers:u,schemaMembers:l}}function m_(e,n,r){let{ast:i,selectiveUses:a,selectiveReuses:o}=r,s=[],c=new Map;for(let r of i.body){if(!(r instanceof R))continue;let i=d_(e,n,r),a=e.nodeAlias(r).getFiltered(t),o=e.nodeSymbol(r).getFiltered(t);if(a!==void 0&&n.isPublicSchema()&&o&&s.push(e.symbolFactory.create(lm,{kind:o.kind,declaration:r,aliasedSymbol:o,name:a},n.filepath)),i.kind!==`none`){if(i.kind===`direct`){let n=e.nodeSymbol(r).getFiltered(t);if(!n)continue;s.push(n)}else c.has(i.schemaName)||c.set(i.schemaName,e.symbolFactory.create(Kp,{name:i.schemaName,parent:n},n.filepath))}}g_(e,[...a,...o],n,c);let l=n.qualifiedName;for(let t of e.reachableFiles(n.filepath))for(let r of v_(e,t,l))c.has(r)||c.set(r,e.symbolFactory.create(Kp,{name:r,parent:n},n.filepath));return{nonSchemaMembers:s,schemaMembers:[...c.values()]}}function h_(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==P.Schema)continue;let t=s_.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(Kp,{name:t},r))}}function g_(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==P.Schema)continue;let t=s_.visibleName(e,a);if(!t||t.length<=i.length||!i.every((e,n)=>e===t[n]))continue;let o=t[i.length];o&&!r.has(o)&&r.set(o,e.symbolFactory.create(Kp,{name:o,parent:n},n.filepath))}}function __(e,n){let{ast:r}=e.parseFile(n).getValue(),i=[];for(let n of r.declarations){let r=e.nodeFullname(n).getFiltered(t)||[],a=r.length<=1?v:r[0];i.push(a)}let a=f_(e,n);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==P.Schema)continue;let n=s_.visibleName(e,t)?.at(0);n!==void 0&&i.push(n)}return i}function v_(e,n,r){let{ast:i}=e.parseFile(n).getValue(),a=[];for(let n of i.declarations){let i=e.nodeFullname(n).getFiltered(t)||[],o=i.length<=1?[v]:i.slice(0,-1);o.length>r.length&&r.every((e,t)=>e===o[t])&&a.push(o[r.length])}let o=f_(e,n);for(let t of[...o.selectiveUses,...o.selectiveReuses]){if(t.getSymbolKind()!==P.Schema)continue;let n=s_.visibleName(e,t);!n||n.length<=r.length||r.every((e,t)=>e===n[t])&&a.push(n[r.length])}return a}var y_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){let e=[];return this.declarationNode.attributeList&&e.push(...this.bindHeaderSettings(this.declarationNode.attributeList)),this.declarationNode.body instanceof H&&e.push(...this.bindBody(this.declarationNode.body)),e}bindHeaderSettings(e){return w(e).getValue().dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])??[]}bindInlineDepValue(e){return zm(e).flatMap(e=>[...e.variables,...e.tupleElements].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return(e=>e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(h(n)instanceof U){let e=w(h(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.dep?.flatMap(e=>e.value?this.bindInlineDepValue(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!Pf(e.callee)))}tryToBindColumnType(e){let t=pp(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(T(e))return[];if(E(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&To.includes(t))return[]}let t=pp(e);if(!t){if(D(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return zm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}};function b_(e){let t=e.targetKind?.value?.toLowerCase();return Object.values(F).find(e=>e.toLowerCase()===t)}function x_(e,t,n){let r=[];return t.length>1&&r.push(...t.map(t=>new C(n.duplicate,`'${e}' can only appear once`,t))),t.forEach(t=>{Gf(t.value)||r.push(new C(n.invalidValue,`Custom setting '${e}' must be a string or a color literal`,t.value||t.name||t))}),r}function S_(e,t,n){if(!n.length)return;let{name:r,symbolKind:i}=n[0],a=e.lookupMembers(t,i,r);return n.length>1&&a?S_(e,a,n.slice(1)):a}function C_(e,t){if(e.length===0)return[];let n;switch(t){case F.Table:n=[...Array(e.length-1).fill(P.Schema),P.Table];break;case F.Column:n=e.length===1?[P.Column]:[...Array(e.length-2).fill(P.Schema),P.Table,P.Column];break;case F.TableGroup:n=[...Array(e.length-1).fill(P.Schema),P.TableGroup];break;case F.Note:n=[...Array(e.length-1).fill(P.Schema),P.StickyNote]}return e.map((e,t)=>({name:e,symbolKind:n[t]}))}function w_(e,t){let n=Um(e,t.filepath);if(!n)return;let r=b_(t),i=A(t.name);if(!i?.length||!r)return;let a=C_(i,r),{name:o,symbolKind:s}=a[0];if(o===`public`&&s===P.Schema){let t=Hm(e,n);if(t)return S_(e,t,a.slice(1))}return S_(e,n,a)}function T_(e,t){let n=[],r=new Set,i=t=>{let a=t.intern();if(!r.has(a)){r.add(a);for(let n of e.fileDependencies(t))i(n);n.push(t)}};i(t);let a=new Map;return n.forEach((e,t)=>a.set(e.intern(),t)),a}function E_(e,n,r,i,a){let o=Um(e,a);if(!o)return;let s=e.symbolMetadata(r).filter(t=>t.owners(e).includes(o));if(!s.length)return;let c=T_(e,a),l=[...s].sort((e,t)=>{let n=c.get(e.declaration.filepath.intern())??-1,r=c.get(t.declaration.filepath.intern())??-1;return n===r?e.declaration.start-t.declaration.start:n-r}).map(n=>e.interpretMetadata(n,a).getFiltered(t)).filter(e=>!!e);if(!l.length)return;let u={};for(let e of l)for(let[t,{value:n,token:r}]of Object.entries(e))u[t.toLowerCase()]={originalKey:t,value:n,token:r};let d=n.metadata?Object.fromEntries(Object.entries(n.metadata).map(([e,t])=>[e.toLowerCase(),{originalKey:e,value:t}])):{};Object.entries(u).forEach(([e,t])=>{let{originalKey:r,value:a,token:o}=t;i[e]?i[e].assignBuiltinField(n,a,o):d[e]={originalKey:r,value:a}}),n.metadata=Object.fromEntries(Object.values(d).map(e=>[e.originalKey,e.value]))}var D_=class{constructor(e,t,n,r){this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=this.symbol?.token??N(this.declarationNode);let e=[];if(this.symbol){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);this.table.name=e,this.table.schemaName=t}else e.push(...this.interpretName(this.declarationNode.name));let t=[...e,...this.interpretAlias(this.declarationNode.alias),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.table.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),this.attachTableAndColumnMetadata(),n.create(this.table,t)}attachTableAndColumnMetadata(){if(!this.symbol)return;E_(this.compiler,this.table,this.symbol,k_,this.filepath);let e=this.compiler.symbolMembers(this.symbol).getFiltered(t)??[];for(let t of e){if(!t.isKind(P.Column))continue;let e=this.table.fields.find(e=>e.name===t.name);e&&E_(this.compiler,e,t,A_,this.filepath)}}interpretName(e){let{name:t,schemaName:n}=Lp(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new C(S.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.table.name=t,this.table.schemaName=n.length?n[0]:null,[])}interpretAlias(e){if(!e)return[];let t=_p(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=w(e).getValue();this.table.headerColor=t[i.HeaderColor]?.length?Rp(t[i.HeaderColor]?.at(0)?.value):void 0;let[n]=t[i.Note]||[];return this.table.note=n&&{value:Ip(j(n?.value)),token:N(n)},this.table.metadata=Vp(t,Object.keys(k_)),[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.table.note={value:Ip(j(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:N(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);case r.Records:return[];default:return[]}})}interpretInjection(e,n){let r=[],i={order:n,token:N(e)};i.name=M(e.expression)||``;let a=e.expression?this.compiler.nodeReferee(e.expression).getFiltered(t):void 0,o=this.compiler.parseFile(this.filepath).getValue().ast,s=this.compiler.nodeSymbol(o).getFiltered(t);if(a&&!s.inNestedSchema(this.compiler,a)){let n=this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),o=n?(this.compiler.symbolUses(n).getFiltered(t)??[]).find(e=>e.filepath.equals(this.filepath)):void 0;r.push(new C(S.UNSUPPORTED,`TablePartial ${i.name} from '${a.filepath}' should be imported. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,o?.useSpecifierDeclaration??e))}return this.table.partials.push(i),r}interpretFields(e){let n=this.symbol??this.compiler.nodeSymbol(this.declarationNode).getFiltered(t),r=(n?this.compiler.symbolMembers(n).getFiltered(t)??[]:[]).filter(e=>e.isKind(P.Column)).length?[]:[new C(S.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],i=e.flatMap((e,t)=>Pf(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...r,...i]}interpretColumn(e){let n=[],r={},a=this.compiler.nodeSymbol(e).getFiltered(t);r.name=_p(e.callee),r.token=N(e);let o=Bp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||!1,r.unique=a?.isUniqueSet(this.compiler)||!1,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{};r.metadata=Vp(s,O_);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.endpoints?.[0])return[];let s=o.endpoints[0],c=r.op(this.compiler);return c?{schemaName:s.schemaName,tableName:s.tableName,fieldNames:s.fieldNames,relation:c,token:s.token}:[]}),r.inline_deps=(s[i.Dep]||[]).flatMap(e=>{let r=this.compiler.nodeMetadata(e).getFiltered(t);if(!r)return[];let i=r.owners(this.compiler);if(l&&i.length>0&&!i.some(e=>e===l))return[];let a=this.compiler.interpretMetadata(r,this.filepath);if(a.hasValue(t))return[];n.push(...a.getErrors());let o=a.getValue();if(!o?.edges?.[0])return[];let s=e.value;if(!(s instanceof B))return[];let c=s.op?.value;if(c!==`->`&&c!==`<-`)return[];let u=o.edges[0],d=c===`->`?u.downstream:u.upstream;return{schemaName:d.schemaName,tableName:d.tableName,fieldNames:d.fieldNames,direction:c,token:d.token}}),r.checks=(s[i.Check]||[]).map(e=>({token:N(e),expression:e.value.value.value})),this.table.fields.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.indexes.push(...i):i&&this.table.indexes.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.table.checks.push(...i):i&&this.table.checks.push(i),r.getErrors()}},O_=[i.Note,i.Ref,i.PrimaryKey,i.PK,i.NotNull,i.Null,i.Unique,i.Increment,i.Default,i.Check],k_={[i.Note]:{isValidBuiltinFieldValue:T,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.HeaderColor]:{isValidBuiltinFieldValue:Lf,message:`'headercolor' must be a color literal`,assignBuiltinField(e,t){e.headerColor=t}}},A_={[i.Note]:{isValidBuiltinFieldValue:T,message:`'note' must be a quoted string`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}}},j_={getDuplicateError(e,t,n){return new C(S.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new C(S.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new C(S.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},M_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return O(a,r.Table)?new n(i.symbolFactory.create(Yp,{declaration:a,name:o},a.filepath)):k(a,r.Table)?Pf(a.callee)?new n(i.symbolFactory.create(tm,{declaration:a,name:o},a.filepath)):new n(i.symbolFactory.create(Xp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(r,i){if(!i.isKind(P.Table))return n.create(e);let a=i.declaration;if(!(a instanceof R))return new n([]);let o=dp(a),s=[],c=[];for(let e of o){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(s.push(i),c.push(...n.getErrors()))}let l=new Map;for(let e of s){if(!e.isKind(P.Column,P.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=l.get(t);r?e.isKind(P.Column)?(c.push(j_.getColumnDuplicateError(e.name,r)),c.push(j_.getColumnDuplicateError(e.name,n))):(c.push(j_.getPartialInjectionDuplicateError(e.name,r)),c.push(j_.getPartialInjectionDuplicateError(e.name,n))):l.set(t,n)}}let u=[];for(let e=0;e<s.length;e++){let n=s[e];if(!(n.declaration instanceof V)||!Pf(n.declaration.callee))continue;let i=n.declaration.callee.expression,o=M(i);if(i===void 0||o===void 0)continue;let l=r.nodeReferee(i).getFiltered(t);if(!l){c.push(new C(S.BINDING_ERROR,`TablePartial '${o}' does not exist in Schema 'public'`,i||a));continue}let d=r.symbolMembers(l).getFiltered(t);if(d){let t=d.flatMap(e=>{if(!e.declaration)return[];let t=e.name;return t===void 0?e:r.symbolFactory.create(dm,{kind:P.Column,injectionDeclaration:n.declaration,declaration:e.declaration,name:t},a.filepath)});u.push({index:e,partialMembers:t})}}for(let e=u.length-1;e>=0;e--){let{index:t,partialMembers:n}=u[e];s.splice(t,0,...n)}let d=new Set(s.filter(e=>e.isKind(P.Column)&&!(e instanceof dm)).map(e=>e.name));return new n(Fa([...s.filter(e=>!(e instanceof dm&&d.has(e.name)))].reverse(),e=>e.isKind(P.Column)?e.name:e).reverse(),c)},nodeReferee(a,o){if(tp(o,i.Dep)&&o.parent instanceof R&&o.parent.isKind(r.Table)&&!Qf(o,r.Table)){let e=a.parseFile(o.filepath).getValue().ast,r=a.nodeSymbol(e).getValue();return r===t?n.create(void 0):I_(a,r,o)}if(!Qf(o,r.Table))return n.create(e);let s=a.parseFile(o.filepath).getValue().ast,c=a.nodeSymbol(s).getValue();return c===t?n.create(void 0):E(o)&&o.parentNode instanceof B&&o.parentNode.op?.value===`~`?N_(a,c,o):$f(o,1)?P_(a,c,o):tp(o,i.Ref)?F_(a,c,o):tp(o,i.Dep)?I_(a,c,o):$f(o,0)?n.create(e):L_(a,c,o)},bindNode(i,a){if(!O(a,r.Table))return n.create(e);let o=new y_(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof Yp?r.declaration instanceof R?new D_(t,r.declaration,r,i).interpret():n.create(void 0):n.create(e)}};function N_(e,r,i){let a=M(i)??``,o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Kp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,P.TablePartial,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,P.TablePartial,a);return s?n.create(s):new n(void 0,[new C(S.BINDING_ERROR,`TablePartial '${a}' does not exist in Schema 'public'`,i)])}function P_(e,t,r){if(!E(r))return new n(void 0);let i=_p(r)??``;if(!D(r.parentNode))return n.create(e.lookupMembers(t,P.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(P.Schema)){let t=op(r),o=e.lookupMembers(a,t?P.Enum:P.Schema,i);return o?n.create(o):new n(void 0,[new C(S.BINDING_ERROR,t?`Enum '${i}' does not exist in Schema 'public'`:`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function F_(e,i,a){if(!E(a))return new n(void 0);let o=_p(a)??``;if(!D(a.parentNode)){let s=a.parent,c=s instanceof R&&s.isKind(r.Table)?e.nodeSymbol(s).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,P.Column,o);if(t)return n.create(t)}let l=e.lookupMembers(i,P.Column,o);return l?n.create(l):new n(void 0,[new C(S.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${c?.name??``}'`,a)])}return Vm(e,i,a,P.Column)}function I_(e,i,a){if(!E(a))return new n(void 0);let o=Qf(a,r.Table),s=_p(a)??``;if(!D(a.parentNode)){if(o){let o=a.parent,c=o instanceof R&&o.isKind(r.Table)?e.nodeSymbol(o).getFiltered(t):void 0;if(c){let t=e.lookupMembers(c,P.Column,s);if(t)return n.create(t)}let l=e.lookupMembers(i,P.Column,s);return l?n.create(l):new n(void 0,[new C(S.BINDING_ERROR,`Column '${s}' does not exist in Table 'public.${c?.name??``}'`,a)])}{let t=e.lookupMembers(i,P.Table,s);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table '${s}' does not exist in Schema 'public'`,a)])}}return Vm(e,i,a,o?P.Column:P.Table)}function L_(e,t,r){if(!E(r))return new n(void 0);let i=_p(r)??``;if(!D(r.parentNode))return To.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,P.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Enum,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(P.Enum)){let t=e.lookupMembers(a,P.EnumField,i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(D(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,P.Enum,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function R_(e){return e?e.split(``).every(e=>Ef(e)||Df(e))&&!Df(e[0]):!1}function z_(e){return R_(e)?e:`"${H_(e)}"`}function B_(...e){return e.map(z_).join(`.`)}function V_(e){let t=``,n=0,r={n:`
9
9
  `,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function H_(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
10
- `:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function U_(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return`'${H_(e)}'`;let{value:t,type:n}=e;if(t==null||Bo(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(n===`color`)return String(t);if(Bo(n)){let e=Dp(t);return e===null?`\`${t}\``:e?`true`:`false`}if(zo(n)){let e=Cp(t);return e===null?`\`${t}\``:String(e)}if(Uo(n)){let e=Np(t);return e===null?`\`${t}\``:`'${H_(e)}'`}let r=kp(t);return r===null?`\`${t}\``:`'${H_(r)}'`}function W_(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?V_(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function G_(e,t){let n=new Set,r=[];for(let i of t)for(let t of e.reachableFiles(i))n.has(t.intern())||(n.add(t.intern()),r.push(t));return r}function K_(e){let r=[],i=[],a=[];e.bindProject();for(let n of e.parseProject().values()){i.push(...n.getErrors()),a.push(...n.getWarnings());let o=e.nodeSymbol(n.getValue().ast).getFiltered(t);if(!o)continue;let s=e.symbolMembers(o);i.push(...s.getErrors()),a.push(...s.getWarnings());for(let n of s.getFiltered(t)??[])if(r.push(n),n instanceof Kp&&n.isKind(P.Schema)){let o=e.symbolMembers(n);i.push(...o.getErrors()),a.push(...o.getWarnings()),r.push(...o.getFiltered(t)??[])}}return new n(r,i,a)}function q_(e){return e.includes(`
10
+ `:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function U_(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return q_(e);let{value:t,type:n}=e;if(t==null||Bo(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(n===`color`)return String(t);if(Bo(n)){let e=Dp(t);return e===null?`\`${t}\``:e?`true`:`false`}if(zo(n)){let e=Cp(t);return e===null?`\`${t}\``:String(e)}if(Uo(n)){let e=Np(t);return e===null?`\`${t}\``:`'${H_(e)}'`}let r=kp(t);return r===null?`\`${t}\``:q_(r)}function W_(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?V_(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function G_(e,t){let n=new Set,r=[];for(let i of t)for(let t of e.reachableFiles(i))n.has(t.intern())||(n.add(t.intern()),r.push(t));return r}function K_(e){let r=[],i=[],a=[];e.bindProject();for(let n of e.parseProject().values()){i.push(...n.getErrors()),a.push(...n.getWarnings());let o=e.nodeSymbol(n.getValue().ast).getFiltered(t);if(!o)continue;let s=e.symbolMembers(o);i.push(...s.getErrors()),a.push(...s.getWarnings());for(let n of s.getFiltered(t)??[])if(r.push(n),n instanceof Kp&&n.isKind(P.Schema)){let o=e.symbolMembers(n);i.push(...o.getErrors()),a.push(...o.getWarnings()),r.push(...o.getFiltered(t)??[])}}return new n(r,i,a)}function q_(e){return e.includes(`
11
11
  `)?`'''\n${e}\n'''`:`'${H_(e)}'`}var J_=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(zm).flatMap(e=>{let n=e.variables.pop();if(!n)return[];let r=this.compiler.nodeReferee(n),i=r.getFiltered(t);return i instanceof um?[...r.getErrors(),new C(S.BINDING_ERROR,`TableGroup cannot reference imported table '${i.name}'`,n)]:r.getErrors()}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Y_={[i.Note]:{isValidBuiltinFieldValue:T,message:`'note' must be a string literal`,assignBuiltinField(e,t,n){e.note={value:t,token:n}}},[i.Color]:{isValidBuiltinFieldValue:Lf,message:`'color' must be a color literal`,assignBuiltinField(e,t){e.color=t}}},X_=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=N(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),E_(this.compiler,this.tableGroup,this.symbol,Y_,this.filepath),n.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=Lp(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new C(S.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name))),this.tableGroup.name=n,this.tableGroup.schemaName=r[0]||null,t}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:this.tableGroup.note={value:Ip(j(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:N(e)}}return[]})}interpretFields(e){let n=[];return this.tableGroup.tables=e.map(e=>{let r=e.callee?this.compiler.nodeReferee(e.callee).getFiltered(t):void 0;if(r?.isKind(P.Table)){let{name:e,schema:t}=r.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let i=A(e.callee);return i.length>2&&n.push(new C(S.UNSUPPORTED,`Nested schema is not supported`,e)),{name:i.pop(),schemaName:i.join(`.`)||null}}),n}interpretSettingList(e){let t=w(e).getValue();this.tableGroup.color=t.color?.length?Rp(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Ip(j(n?.value)),token:N(n)},this.tableGroup.metadata=Vp(t,Object.keys(Y_)),[]}},Z_={getDuplicateError(e,t,n){return new C(S.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new C(S.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Q_={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t),s=o?.at(-1);return O(a,r.TableGroup)?new n(i.symbolFactory.create(Zp,{declaration:a,name:s},a.filepath)):k(a,r.TableGroup)?new n(i.symbolFactory.create(Qp,{declaration:a,name:o?.map(z_).join(`.`)},a.filepath)):n.create(e)},symbolMembers(r,i){if(i.isKind(P.TableGroup)){let e=i.declaration;if(!(e instanceof R))return new n([]);let a=dp(e),o=[],s=[];for(let e of a){let n=r.nodeSymbol(e),i=n.getFiltered(t);i&&(o.push(i),s.push(...n.getErrors()))}let c=new Map;for(let e of o){if(!e.isKind(P.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(Z_.getFieldDuplicateError(e.name,r)),s.push(Z_.getFieldDuplicateError(e.name,n))):c.set(t,n)}}return new n(o,s)}return i.isKind(P.TableGroupField)?new n([]):n.create(e)},nodeReferee(i,a){if(!E(a)||!Qf(a,r.TableGroup)||a.parent&&ep(a))return n.create(e);let o=i.parseFile(a.filepath).getValue().ast,s=i.nodeSymbol(o).getValue();return s===t?n.create(void 0):$_(i,s,a)},bindNode(i,a){if(!O(a,r.TableGroup))return n.create(e);let o=new J_(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,i,a){let o=i.declaration;return!O(o,r.TableGroup)||!(i instanceof Zp)?n.create(e):Rm(t,o)?new X_(t,i,a).interpret():n.create(void 0)}};function $_(e,r,i){let a=_p(i)??``;if(!D(i.parentNode)){let o=e.symbolMembers(r).getFiltered(t);if(o){let t=o.find(e=>e instanceof Kp&&e.isPublicSchema());if(t){let r=e.lookupMembers(t,P.Table,a);if(r)return n.create(r)}}let s=e.lookupMembers(r,P.Table,a);return s?n.create(s):new n(void 0,[new C(S.BINDING_ERROR,`Table '${a}' does not exist in Schema 'public'`,i)])}let o=Bm(e,i);if(o){if(o.isKind(P.Schema)){let t=e.lookupMembers(o,[P.Table,P.Schema],a);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${a}' does not exist`,i)])}return new n(void 0)}let s=e.lookupMembers(r,P.Schema,a);return s?n.create(s):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${a}' does not exist`,i)])}var ev=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof H?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof V)return this.bindFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(h(n)instanceof U){let e=w(h(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t})}tryToBindColumnType(e){let t=pp(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return zm(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];if(n){let r=[],i=e.variables;for(let e of i)r.push(...this.compiler.nodeReferee(e).getErrors());let a=this.compiler.nodeReferee(n);return r.push(...a.getErrors()),a.getValue()&&r.push(...this.compiler.nodeReferee(t).getErrors()),r}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},tv=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=this.symbol?.token??N(this.declarationNode),this.symbol?this.tablePartial.name=this.symbol.interpretedName(this.compiler,this.filepath).name:this.interpretName(this.declarationNode.name);let e=[...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.tablePartial.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),pk:!0,token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath}}),this.pkColumns.forEach(e=>{e.pk=!1})),new n(this.tablePartial,e)}interpretName(e){let{name:t}=Lp(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=w(e).getValue(),n=ya(t[i.HeaderColor]);this.tablePartial.headerColor=n?Rp(n.value):void 0;let[r]=t[i.Note]||[];return this.tablePartial.note=r&&{value:Ip(j(r?.value)),token:N(r)},[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof V);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.getElementKind()){case r.Note:return this.tablePartial.note={value:Ip(j(e.body instanceof H?e.body.body[0].callee:e.body.callee)),token:N(e)},[];case r.Indexes:return this.interpretIndexes(e);case r.Checks:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let n=[],r={},a=this.compiler.nodeSymbol(e).getFiltered(t);r.name=_p(e.callee)??``,r.token=N(e);let o=Bp(this.compiler,e.args[0]);r.type=o.getValue(),n.push(...o.getErrors()),r.pk=a?.pk(this.compiler)||void 0,r.unique=a?.isUniqueSet(this.compiler)||void 0,r.increment=a?.isIncrementSet(this.compiler)||void 0,r.not_null=a?.isNotNullSet(this.compiler),r.dbdefault=a?.default(this.compiler),r.note=a?.note(this.compiler);let s=this.compiler.nodeSettings(e).getFiltered(t)??{};r.metadata=Vp(s,O_);let c=this.compiler.parseFile(this.filepath).getValue().ast,l=this.compiler.nodeSymbol(c).getFiltered(t);return r.inline_refs=(s[i.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!(n instanceof Jm))return[];let r=n.owners(this.compiler);if(l&&r.length>0&&!r.some(e=>e===l))return[];let i=n.op(this.compiler);if(!i)return[];let a=n.rightTable(this.compiler),o=n.rightColumns(this.compiler);if(!a||o.length===0)return[];let s=a.interpretedName(this.compiler,this.filepath);return{schemaName:s.schema,tableName:s.name,fieldNames:o.map(e=>e.name??``),relation:i,token:N(n.rightToken())}}),r.inline_deps=[],r.checks=(s[i.Check]||[]).map(e=>({token:N(e),expression:e.value.value.value})),this.tablePartial.fields?.push(r),r.pk&&this.pkColumns.push(r),n}interpretIndexes(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.indexes?.push(...i):i&&this.tablePartial.indexes?.push(i),r.getErrors()}interpretChecks(e){let n=this.compiler.nodeMetadata(e).getFiltered(t);if(!n)return[];let r=this.compiler.interpretMetadata(n,this.filepath);if(r.hasValue(t))return[];let i=r.getValue();return Array.isArray(i)?this.tablePartial.checks?.push(...i):i&&this.tablePartial.checks?.push(i),r.getErrors()}},nv={getDuplicateError(e,t,n){return new C(S.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},rv={nodeSymbol(i,a){let o=i.nodeFullname(a).getFiltered(t)?.at(-1);return O(a,r.TablePartial)?new n(i.symbolFactory.create(em,{declaration:a,name:o},a.filepath)):k(a,r.TablePartial)?new n(i.symbolFactory.create(Xp,{declaration:a,name:o},a.filepath)):n.create(e)},symbolMembers(i,a){if(a.isKind(P.TablePartial)){let e=a.declaration;if(!(e instanceof R))return new n([]);let r=dp(e),o=[],s=[];for(let e of r){let n=i.nodeSymbol(e),r=n.getFiltered(t);r&&(o.push(r),s.push(...n.getErrors()))}let c=new Map;for(let e of o){if(!e.isKind(P.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration,r=c.get(t);r?(s.push(j_.getColumnDuplicateError(t,r)),s.push(j_.getColumnDuplicateError(t,n))):c.set(t,n)}}return new n(o,s)}return a.isKind(P.Column)&&O(a.declaration?.parent,r.TablePartial)?new n([]):n.create(e)},nodeReferee(a,o){if(!E(o)&&!D(o)||!Qf(o,r.TablePartial))return n.create(e);let s=a.parseFile(o.filepath).getValue().ast,c=a.nodeSymbol(s).getValue();return c===t?n.create(void 0):$f(o,1)?iv(a,c,o):tp(o,i.Ref)?av(a,c,o):ov(a,c,o)},bindNode(i,a){if(!O(a,r.TablePartial))return n.create(e);let o=new ev(i,a).bind(),s=i.nodeSymbol(a).getFiltered(t);return s&&o.push(...i.symbolMembers(s).getErrors()),n.create(void 0,o)},interpretSymbol(t,r,i){return r instanceof em?r.declaration instanceof R?new tv(t,r,i).interpret():n.create(void 0):n.create(e)}};function iv(e,t,r){if(!E(r))return new n(void 0);let i=_p(r)??``;if(!D(r.parentNode))return n.create(e.lookupMembers(t,P.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Enum,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}return new n(void 0)}if(r.parentNode.leftExpression===r){let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}function av(e,i,a){if(!E(a))return new n(void 0);let o=_p(a)??``;if(!D(a.parentNode)){let s=a.parent;if(s instanceof R&&s.isKind(r.TablePartial)){let r=e.nodeSymbol(s).getFiltered(t);if(r){let t=e.lookupMembers(r,P.Column,o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Column '${o}' does not exist in TablePartial '${r.name}'`,a)])}}let c=e.lookupMembers(i,P.Column,o);return c?n.create(c):new n(void 0,[new C(S.BINDING_ERROR,`Column '${o}' does not exist`,a)])}let s=Bm(e,a);if(s){if(s.isKind(P.Schema)){let t=e.lookupMembers(s,[P.Table,P.Schema],o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table or schema '${o}' does not exist`,a)])}if(s.isKind(P.Table)){let t=e.lookupMembers(s,P.Column,o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Column '${o}' does not exist in Table 'public.${s.name}'`,a)])}return new n(void 0)}let c=a.parentNode;if(c.leftExpression===a){if(D(c.parentNode)&&c.parentNode.leftExpression===c){let t=e.lookupMembers(i,P.Schema,o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${o}' does not exist in Schema 'public'`,a)])}let t=e.lookupMembers(i,P.Table,o);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Table '${o}' does not exist in Schema 'public'`,a)])}return new n(void 0)}function ov(e,t,r){if(!E(r))return new n(void 0);let i=_p(r)??``;if(!D(r.parentNode))return To.includes(i.toLowerCase())?new n(void 0):n.create(e.lookupMembers(t,P.Enum,i));let a=Bm(e,r);if(a){if(a.isKind(P.Schema)){let t=e.lookupMembers(a,[P.Enum,P.Schema],i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum or schema '${i}' does not exist`,r)])}if(a.isKind(P.Enum)){let t=e.lookupMembers(a,P.EnumField,i);return t?n.create(t):new n(void 0,[new C(S.BINDING_ERROR,`Enum field '${i}' does not exist in Enum 'public.${a.name}'`,r)])}return new n(void 0)}let o=r.parentNode;if(o.leftExpression===r){if(D(o.parentNode)&&o.parentNode.leftExpression===o){let a=e.lookupMembers(t,P.Schema,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Schema '${i}' does not exist in Schema 'public'`,r)])}let a=e.lookupMembers(t,P.Enum,i);return a?n.create(a):new n(void 0,[new C(S.BINDING_ERROR,`Enum '${i}' does not exist in Schema 'public'`,r)])}return new n(void 0)}var sv={symbolMembers(r,i){if(!i.isKind(P.Schema)||!(i instanceof Kp))return n.create(e);let a=i.qualifiedName,o=r.usableMembers(i).getFiltered(t);if(!o)return n.create([]);let s=[...o.nonSchemaMembers],c=new Map(o.schemaMembers.map(e=>[e.name,e])),l=[];for(let e of o.reuses.selective){let n=lv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...uv(r,i,e))}for(let{importPath:e,node:t}of o.reuses.wildcard)s.push(...fv(r,i,e,t,c));for(let e of o.uses.selective){let n=lv(r,i,e,c);l.push(...n.getErrors());let a=n.getFiltered(t);a&&s.push(a),s.push(...uv(r,i,e))}for(let{importPath:e,node:t}of o.uses.wildcard)s.push(...fv(r,i,e,t,c));s.push(...c.values());let u=[...s];{let e=s.filter(e=>e.isKind(P.TableGroup));if(!i.isPublicSchema()){let n=r.usableMembers(i.filepath).getFiltered(t)?.schemaMembers.find(e=>e.isPublicSchema());if(n){let i=r.symbolMembers(n).getFiltered(t);i&&e.push(...i.filter(e=>e.isKind(P.TableGroup)))}}for(let t of e)u.push(...mv(r,i,t))}let d=new Set,f=u.filter(e=>{if(e instanceof um&&e.isKind(P.Schema))return!1;let t=`${e.originalSymbol.intern()}:${e.name??``}`;return!d.has(t)&&(d.add(t),!0)}),p=new Map;for(let e of f){let t=`${e.kind}:${e.name}`;if(p.get(t)){if(e.isKind(P.Schema))continue;let t=e instanceof um?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof R&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&l.push(cv(e.kind,e.name,a.join(`.`),t))}else p.set(t,e)}return new n(f,l)}};function cv(e,t,n,r){switch(e){case P.Table:return j_.getDuplicateError(t,n,r);case P.Enum:return Sh.getDuplicateError(t,n,r);case P.TablePartial:return nv.getDuplicateError(t,n,r);case P.TableGroup:return Z_.getDuplicateError(t,n,r);case P.DiagramView:return mh.getDuplicateError(t,n,r);default:return new C(S.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function lv(e,r,i,a){let o=d_(e,r,i);if(o.kind===`none`)return n.create(void 0);if(o.kind===`direct`){let r=e.nodeSymbol(i);return r.hasValue(t)?n.create(void 0):r}return a.has(o.schemaName)||a.set(o.schemaName,e.symbolFactory.create(Kp,{name:o.schemaName,parent:r},r.filepath)),n.create(void 0)}function uv(e,n,r,i=new Set){if(r.getSymbolKind()!==P.Schema||!r.name)return[];let a=e.nodeReferee(r.name).getFiltered(t);if(!a||!a.isKind(P.Schema))return[];let o=s_.visibleName(e,r),s=n.qualifiedName;return!o||o.length!==s.length||!o.every((e,t)=>e===s[t])?[]:dv(e,n,r,a,i)}function dv(e,n,r,i,a){let o=i.intern();if(a.has(o))return[];a.add(o);let s=e.usableMembers(i).getFiltered(t);if(!s)return[];let c=s.nonSchemaMembers.filter(e=>e.canBeImported).map(t=>e.symbolFactory.create(um,{kind:t.kind,declaration:t.originalSymbol.declaration,usedSymbol:t.originalSymbol,useSpecifierDeclaration:r,name:t.name},n.filepath));for(let t of[...c])t.isKind(P.TableGroup)&&c.push(...mv(e,n,t));for(let i of s.reuses.selective)if(c.push(...uv(e,n,i,a)),d_(e,n,i).kind===`direct`){let a=e.nodeSymbol(i).getFiltered(t);a&&a.canBeImported&&c.push(e.symbolFactory.create(um,{kind:a.kind,declaration:a.originalSymbol.declaration,usedSymbol:a.originalSymbol,useSpecifierDeclaration:r,name:a.name},n.filepath))}for(let{importPath:t}of s.reuses.wildcard){let i=pv(e,t,n.qualifiedName);i&&c.push(...dv(e,n,r,i,a))}return c}function fv(e,n,r,i,a,o=new Set){if(o.has(r))return[];o.add(r);let s=pv(e,r,n.qualifiedName);if(!s)return[];let c=e.usableMembers(s).getFiltered(t);if(!c)return[];let l=c.nonSchemaMembers.filter(e=>e.canBeImported).map(t=>e.symbolFactory.create(um,{kind:t.kind,declaration:t.declaration,usedSymbol:t,useSpecifierDeclaration:i,name:t.name},n.filepath));for(let t of c.schemaMembers)a.has(t.name)||a.set(t.name,e.symbolFactory.create(Kp,{name:t.name},n.filepath));let{reuses:{selective:u,wildcard:d}}=c;for(let r of u){let i=lv(e,n,r,a).getFiltered(t);i&&l.push(i),l.push(...uv(e,n,r))}for(let{importPath:t}of d)l.push(...fv(e,n,t,i,a,o));return l}function pv(e,n,r){if(r.length===0)return;let i=e.usableMembers(n).getFiltered(t);if(!i)return;let{schemaMembers:a}=i,o,s=[...r];for(;s.length>0;){let t=s.shift();if(o=a.find(e=>e.name===t),!o)return;let n=e.usableMembers(o).getValue();({schemaMembers:a}=n)}return o}function mv(e,n,r){if(!r.isKind(P.TableGroup)||!(r instanceof um))return[];let i=r.originalSymbol,a=e.symbolMembers(i).getFiltered(t);if(!a)return[];let o=n.qualifiedName,s=[];for(let t of a){if(!t.isKind(P.TableGroupField)||!t.declaration)continue;let n=t.declaration.callee;if(!n)continue;let i=A(n);if(!i||i.length===0)continue;let a=i.length<=1?[v]:i.slice(0,-1);if(a.length!==o.length||!o.every((e,t)=>e===a[t]))continue;let c=t.declaration.filepath,l=hv(e,c,i);l&&s.push(e.symbolFactory.create(um,{kind:P.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},r.filepath))}return s}function hv(e,n,r){if(r.length===1){let i=e.usableMembers(n).getFiltered(t);return i?i.nonSchemaMembers.find(e=>e.isKind(P.Table)&&e.name===r[0]):void 0}let i=r[0],a=r[r.length-1],o=e.usableMembers(n).getFiltered(t);if(!o)return;let s=o.schemaMembers.find(e=>e.name===i);if(!s)return;let c=e.usableMembers(s).getFiltered(t);if(c)return c.nonSchemaMembers.find(e=>e.isKind(P.Table)&&e.name===a)}var gv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof V)return[];let t=e.body.filter(e=>e instanceof R);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},_v={[i.Color]:{isValidBuiltinFieldValue:Rf,message:`'color' must be a color literal or 'none'`,assignBuiltinField(e,t){e.color=t}}},vv=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){this.note.token=N(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return E_(this.compiler,this.note,this.symbol,_v,this.filepath),n.create(this.note,e)}interpretName(){let{name:e}=this.symbol.interpretedName(this.compiler,this.filepath);return this.note.name=e,[]}interpretSettingList(e){let t=w(e).getValue();return t.color?.length&&(this.note.color=Rp(t.color.at(0)?.value)),this.note.metadata=Vp(t,Object.keys(_v)),[]}interpretBody(e){let[t,n]=g(e.body,e=>e instanceof V);return t.length!==1||n.length>0?[new C(S.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=j(e.callee)??``;return this.note.content=Ip(t),[]}},yv={nodeSymbol(i,a){return!O(a,r.Note)||!(a.parentNode instanceof L)?n.create(e):new n(i.symbolFactory.create($p,{declaration:a,name:i.nodeFullname(a).getFiltered(t)?.at(-1)},a.filepath))},symbolMembers(t,r){return r.isKind(P.StickyNote)?new n([]):n.create(e)},bindNode(t,i){return O(i,r.Note)?n.create(void 0,new gv(t,i).bind()):n.create(e)},interpretSymbol(t,r,i){return r instanceof $p?r.declaration instanceof R?new vv(t,r,i).interpret():n.create(void 0):n.create(e)}},bv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[...this.bindTargetElement(this.declarationNode.name),...this.bindBody(this.declarationNode.body)]}bindTargetElement(e){let t=b_(this.declarationNode);return!A(e)?.length||!t||w_(this.compiler,this.declarationNode)?[]:[new C(S.BINDING_ERROR,`cannot find metadata target element`,e??this.declarationNode)]}bindBody(e){return e instanceof H?e.body.filter(e=>e instanceof R).flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[]):[]}},xv=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.filepath=n,this.values={}}interpret(){let e=this.interpretValues(this.declarationNode.body);return new n(this.values,e)}interpretValues(e){if(!(e instanceof H))return[];for(let t of e.body){if(!(t instanceof R))continue;let e=t.type?.value;if(!e)continue;let n=Hp(t.body instanceof V?t.body.callee:void 0);n&&(this.values[e]={value:e===`note`?Ip(n):n,token:N(t)})}return[]}},Sv=[c_,M_,Ch,Xg,Eh,ah,a_,lh,Ug,Q_,rv,yv,{nodeMetadata(t,i){return O(i,r.Metadata)?new n(new Qm(i)):new n(e)},nodeReferee(t,i){if(!E(i))return new n(e);let a=i.parentOfKind(R);return!a||!O(a,r.Metadata)||!a.name?.containsEq(i)?new n(e):!A(a.name)||!b_(a)?new n(void 0):new n(w_(t,a))},bindNode(t,i){return O(i,r.Metadata)?new n(void 0,new bv(t,i).bind()):new n(e)},interpretMetadata(t,i,a){return i instanceof Qm?O(i.declaration,r.Metadata)?new xv(t,i,a).interpret():new n(void 0):new n(e)}},sv,hh,Bg];function Cv(t,...r){for(let i of Sv){let a=i[t];if(a){let t=a(...r);if(t instanceof n&&!t.hasValue(e))return t}}return n.create(e)}function wv(r){let i=Cv(`nodeSymbol`,this,r);return i.hasValue(e)?n.create(t):i}function Tv(r){let i=Cv(`symbolMembers`,this,r);return i.hasValue(e)?n.create(t):i}function Ev(r){let i=Cv(`nodeReferee`,this,r);return i.hasValue(e)?n.create(t):i}function Dv(r){let i=Cv(`bindNode`,this,r);return i.hasValue(e)?n.create(t):i}function Ov(r){let i=Cv(`nodeMetadata`,this,r);return i.hasValue(e)?n.create(t):i}function kv(r,i){let a=Cv(`interpretSymbol`,this,r,i);return a.hasValue(e)?n.create(t):a}function Av(r,i){let a=Cv(`interpretMetadata`,this,r,i);return a.hasValue(e)?n.create(t):a}var jv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new C(S.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new C(S.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return h(n)instanceof U&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof bm))&&t.push(new C(S.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=w(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`name`:t.length>1&&t.forEach(t=>n.push(new C(S.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{T(t.value)||n.push(new C(S.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new C(S.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Mv={validateNode(t,i){if(!O(i,r.Checks))return n.create(e);let a=new jv(t,i);return n.create(void 0,a.validate())},nodeFullname(t,i){return O(i,r.Checks)?i.name?new n(void 0,[new C(S.UNEXPECTED_NAME,`A Checks shouldn't have a name`,i.name)]):new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Checks)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Checks)?i.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},Nv=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Project,r.Dep)?[]:[new C(S.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project or a Dep`,this.declarationNode)]}validateName(e){return e?[new C(S.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof H)return[new C(S.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return!(this.declarationNode.parent instanceof R&&this.declarationNode.parent.isKind(r.Dep))&&!T(e.callee)&&t.push(new C(S.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e)),e.args.length>0&&t.push(...e.args.map(e=>new C(S.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function Pv(e){return e instanceof R&&!!e.type?.value}var Fv={validateNode(t,r){if(!Pv(r))return n.create(e);let i=new Nv(t,r);return n.create(void 0,i.validate())},nodeFullname(t,r){return Pv(r)?r.name?new n(void 0,[new C(S.UNEXPECTED_NAME,`A custom field shouldn't have a name`,r.name)]):new n(void 0):n.create(e)},nodeAlias(t,r){return Pv(r)?r.alias?new n(void 0,[new C(S.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return Pv(r)?r.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,r.attributeList)]):new n({}):n.create(e)}},Iv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettings(),...this.validateBody(this.declarationNode.body)]}validateSettings(){let e=[];this.declarationNode.attributeList&&e.push(...Lv(this.declarationNode.attributeList).getErrors());let t=this.declarationNode.body;if(t instanceof V){let n=t.args.find(e=>e instanceof U);n&&e.push(...Lv(n).getErrors())}return e}validateContext(){return this.declarationNode.parent instanceof L?[]:[new C(S.INVALID_DEP_CONTEXT,`A Dep must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Tm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Dep name`,e)]:Mf(e)?[]:[new C(S.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.forEach(e=>{if(!e.callee){t.push(new C(S.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e));return}if(!(e.callee instanceof vm)){t.push(new C(S.INVALID_DEP_FIELD,`A Dep field must be a binary relationship`,e.callee));return}let n=e.callee;n.op?.value!==`->`&&n.op?.value!==`<-`&&t.push(new C(S.INVALID_DEP_FIELD,`Dep edges must use the '->' or '<-' operator`,e.callee));let r=pp(n.leftExpression)??{variables:[],tupleElements:[]},i=pp(n.rightExpression)??{variables:[],tupleElements:[]};r.variables.length===0&&r.tupleElements.length===0&&t.push(new C(S.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.leftExpression||e.callee)),i.variables.length===0&&i.tupleElements.length===0&&t.push(new C(S.INVALID_DEP_FIELD,`Invalid Dep endpoint`,n.rightExpression||e.callee));let a=[...e.args];h(a)instanceof U?a.pop():a[0]instanceof U&&a.shift(),a.length>0&&t.push(...a.map(e=>new C(S.INVALID_DEP_FIELD,`A Dep field should only have a single binary relationship`,e)))}),t}validateSubElements(e){return e.flatMap(e=>{if(!e.type)return[];let t=e.type.value?.toLowerCase(),n=e.body;if(!t)return[];switch(t){case i.Color:return e.name||!(n instanceof V)||!n.callee||!Lf(n.callee)?[new C(S.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,e)]:[];case i.Note:{let t;return n instanceof V?t=n.callee:n instanceof H&&n.body[0]instanceof V&&(t=n.body[0].callee),!t||!T(t)?[new C(S.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,e)]:[]}default:return e.name||n instanceof H?[new C(S.INVALID_SETTINGS,`'${t}' must be a simple field (e.g. ${t}: value). Block syntax is not allowed`,e)]:!(n instanceof V)||!n.callee?[]:!T(n.callee)&&!Lf(n.callee)&&!Bf(n.callee)&&!Mf(n.callee)?[new C(S.INVALID_SETTINGS,`Invalid value for '${t}'. Expected a string, number, color, or identifier`,e)]:[]}})}};function Lv(e){let t=w(e),r=[...t.getErrors()],a=t.getValue();for(let[e,t]of Object.entries(a))for(let n of t)switch(e){case i.Color:Lf(n.value)||r.push(new C(S.INVALID_SETTINGS,`Invalid color value. Expected a hex color (e.g. #fff or #aabbcc)`,n));break;case i.Note:T(n.value)||r.push(new C(S.INVALID_SETTINGS,`Invalid note value. Expected a quoted string`,n));break;default:n.value&&!T(n.value)&&!Lf(n.value)&&!Bf(n.value)&&!Mf(n.value)&&r.push(new C(S.INVALID_SETTINGS,`Invalid value for setting '${e}'. Expected a string, number, color, or identifier`,n))}return new n(a,r)}var Rv={validateNode(t,i){return O(i,r.Dep)?n.create(void 0,new Iv(t,i).validate()):n.create(e)},nodeFullname(t,i){return O(i,r.Dep)?i.name?Mf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A Dep's name is optional or must be an identifier or a quoted identifier`,i.name)]):new n(void 0):k(i,r.Dep)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Dep)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Dep shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.Dep)?new n(void 0):n.create(e)},nodeSettings(t,i){if(O(i,r.Dep))return i.attributeList?Lv(i.attributeList):new n({});if(k(i,r.Dep)){let e=[...i.args],t;return h(e)instanceof U?t=h(e):e[0]instanceof U&&(t=e[0]),t?Lv(t):new n({})}return n.create(e)}},zv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList)],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof R?[new C(S.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Mf(e)?[]:[new C(S.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new C(S.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=w(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new C(S.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof V)return{errors:[new C(S.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=g(e.body,e=>e instanceof V),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Kf(e.callee)?e.args.length>0?e.args.map(e=>new C(S.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new C(S.INVALID_DIAGRAMVIEW_FIELD,`Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.`,e)])}validateSubElements(e){let t=[],n=[],r=[`tables`,`notes`,`tablegroups`,`schemas`];for(let i of e){if(!i.type)continue;let e=i.type.value.toLowerCase();if(!r.includes(e)){t.push(new C(S.INVALID_DIAGRAMVIEW_FIELD,`Unknown block type "${i.type.value}" in DiagramView. Allowed: Tables, Notes, TableGroups, Schemas`,i));continue}let a=this.validateSubBlock(i);t.push(...a.errors),n.push(...a.warnings)}return{errors:t,warnings:n}}validateSubBlock(e){let t=[],n=[];if(Nf(e))return t.push(new C(S.UNEXPECTED_SIMPLE_BODY,`${e.type?.value} body must be a block`,e.bodyColon)),{errors:t,warnings:n};if(!e.body||!(e.body instanceof H))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof V&&Kf(e.callee)),a=r.body.some(e=>e instanceof V&&!Kf(e.callee));return i&&a&&n.push(new wf(S.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t.push(...this.validateSubBlockFields(e)),{errors:t,warnings:n}}validateSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof H))return t;let n=e.body.body.filter(e=>e instanceof V);for(let e of n)Kf(e.callee)||(e.args.length>0||!A(e.callee))&&t.push(...e.args.map(e=>new C(S.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},Bv={validateNode(t,i){if(!O(i,r.DiagramView))return n.create(e);let{errors:a,warnings:o}=new zv(t,i).validate();return n.create(void 0,a,o)},nodeFullname(t,i){if(O(i,r.DiagramView)){if(!i.name)return new n(void 0,[new C(S.NAME_NOT_FOUND,`A DiagramView must have a name`,i)]);let e=A(i.name);return e?new n(e):new n(void 0)}if(k(i,r.DiagramViewTables,r.DiagramViewNotes,r.DiagramViewSchemas,r.DiagramViewTableGroups)){let e=A(i.callee);return e?(e.length===1&&k(i,r.DiagramViewTables)&&e.unshift(v),new n(e)):new n(void 0)}return new n(e)},nodeAlias(t,i){return O(i,r.DiagramView)?new n(void 0):n.create(e)}},Vv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new C(S.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:Af(e)?[]:[new C(S.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new C(S.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new C(S.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!E(n.callee)&&t.push(new C(S.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];h(e)instanceof U?(t.push(...this.validateFieldSettings(h(e))),e.pop()):e[0]instanceof U&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new C(S.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=w(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];if(t)switch(e){case i.Note:t.length>1&&t.forEach(e=>n.push(new C(S.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{T(e.value)||n.push(new C(S.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new C(S.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Hv={validateNode(t,i){return O(i,r.Enum)?n.create(void 0,new Vv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(O(i,r.Enum)){if(!i.name)return new n(void 0,[new C(S.NAME_NOT_FOUND,`An Enum must have a name`,i)]);if(!Af(i.name))return new n(void 0,[new C(S.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,i.name)]);let e=A(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(k(i,r.Enum)){let e=M(i.callee);return new n(e===void 0?void 0:[e])}return n.create(e)},nodeAlias(t,i){return O(i,r.Enum)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.Enum)?new n(void 0):n.create(e)},nodeSettings(t,a){if(O(a,r.Enum))return a.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,a.attributeList)]):new n({});if(k(a,r.Enum)){let e=[...a.args],t;if(h(e)instanceof U?t=h(e):e[0]instanceof U&&(t=e[0]),!t)return new n({});let r=w(t),o=r.getErrors(),s=r.getValue(),c={};for(let[e,t]of Object.entries(s))switch(e){case i.Note:t.length>1&&t.forEach(e=>o.push(new C(S.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{T(e.value)||o.push(new C(S.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new C(S.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Uv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new C(S.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof L?[e]:this.declarationNode.parent?.isKind(r.Table,r.TablePartial)?[]:[e]}validateName(e){return e?[new C(S.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return h(n)instanceof U&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof W;)e.argumentList&&mp(e.argumentList)===void 0&&t.push(new C(S.INVALID_INDEXES_FIELD,`An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such`,e.argumentList)),e=e.callee;mp(e)===void 0&&t.push(new C(S.INVALID_INDEXES_FIELD,`An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such`,e))}),t})}validateFieldSetting(e){let t=w(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`note`:case`name`:t.length>1&&t.forEach(t=>n.push(new C(S.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{T(t.value)||n.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new C(S.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new C(S.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{E(e.value)||n.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new C(S.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Wv={validateNode(t,i){return O(i,r.Indexes)?n.create(void 0,new Uv(t,i).validate()):n.create(e)},nodeFullname(t,i){return O(i,r.Indexes)?i.name?new n(void 0,[new C(S.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,i.name)]):new n(void 0):k(i,r.Indexes)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Indexes)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.Indexes)?new n(void 0):n.create(e)},nodeSettings(t,a){if(O(a,r.Indexes))return a.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,a.attributeList)]):new n({});if(k(a,r.Indexes)){let e=[a.callee,...a.args],t;if(h(e)instanceof U&&(t=h(e)),!t)return new n({});let r=w(t),o=r.getErrors(),s=r.getValue(),c={};for(let[e,t]of Object.entries(s))switch(e){case i.Note:case i.Name:t.length>1&&t.forEach(t=>o.push(new C(S.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{T(t.value)||o.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))}),c[e]=t;break;case i.Unique:case i.PK:t.length>1&&t.forEach(t=>o.push(new C(S.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&o.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))}),c[e]=t;break;case i.Type:t.length>1&&t.forEach(e=>o.push(new C(S.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{E(e.value)||o.push(new C(S.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),c[e]=t;break;default:t.forEach(t=>o.push(new C(S.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new n(c,o)}return n.create(e)}},Gv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return!(e instanceof L)&&!(e instanceof R&&e.isKind(r.Table,r.TableGroup,r.TablePartial,r.Project,r.Dep))?[new C(S.INVALID_NOTE_CONTEXT,`A Note can only appear inside a Table, a TableGroup, a TablePartial or a Project. Sticky note can only appear at the global scope.`,this.declarationNode)]:[]}validateName(e){return this.compiler.nodeFullname(this.declarationNode).getErrors()}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}isStickyNote(){return this.declarationNode.parent instanceof L}validateSettingList(e){if(!e)return[];if(!this.isStickyNote())return[new C(S.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)];let t=w(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.Color:{let t=_v[i.Color];e.length>1&&n.push(...e.map(e=>new C(S.DUPLICATE_NOTE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{t.isValidBuiltinFieldValue(e.value)||n.push(new C(S.INVALID_NOTE_SETTING_VALUE,t.message,e.value||e.name))});break}default:n.push(...x_(t,e,{duplicate:S.DUPLICATE_NOTE_SETTING,invalidValue:S.INVALID_NOTE_SETTING_VALUE}))}}),n}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new C(S.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new C(S.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),T(e[0].callee)||t.push(new C(S.INVALID_NOTE,`A Note content must be a quoted string`,e[0])),e[0].args.length>0&&t.push(...e[0].args.map(e=>new C(S.INVALID_NOTE,`A Note can only contain one quoted string`,e))),t)}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},Kv={validateNode(t,i){return O(i,r.Note)?n.create(void 0,new Gv(t,i).validate()):n.create(e)},nodeFullname(t,i){if(!O(i,r.Note))return n.create(e);if(!(i.parent instanceof L))return i.name?new n(void 0,[new C(S.UNEXPECTED_NAME,`A Note shouldn't have a name`,i.name)]):new n(void 0);if(!i.name)return new n(void 0,[new C(S.INVALID_NAME,`Sticky note must have a name`,i)]);if(i.name instanceof Tm)return new n(void 0,[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,i.name)]);let a=A(i.name);return a===void 0?new n(void 0,[new C(S.INVALID_NAME,`Invalid name for sticky note `,i)]):new n(a)},nodeAlias(t,i){return O(i,r.Note)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,i.alias)]):new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Note)?i.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,i.attributeList)]):new n({}):n.create(e)}},qv={[F.Table]:k_,[F.Column]:A_,[F.TableGroup]:Y_,[F.Note]:_v},Jv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateTargetKind(),...this.validateTargetName(this.declarationNode.name),...this.validateBody(this.declarationNode.body)]}validateTargetKind(){return b_(this.declarationNode)?[]:[new C(S.INVALID_METADATA_TARGET_KIND,`A Metadata target kind must be one of: ${Object.values(F).join(`, `)}`,this.declarationNode.targetKind??this.declarationNode)]}validateTargetName(e){return e?e instanceof Tm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Metadata target's name`,e)]:Af(e)?[]:[new C(S.INVALID_NAME,`A Metadata target's name must be of the form <schema>.<table>, <table>.<column>, <schema>.<table>.<column> or a single identifier`,e)]:[new C(S.NAME_NOT_FOUND,`A Metadata target must have a name`,this.declarationNode)]}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A Metadata's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.map(e=>new C(S.INVALID_METADATA_FIELD,`A Metadata field must use the 'key: value' syntax`,e))}validateSubElements(e){let t={},n=b_(this.declarationNode),r=e.flatMap(e=>{if(!e.type)return[];if(e.body instanceof H)return[new C(S.UNEXPECTED_COMPLEX_BODY,`A Metadata field can only have an inline value`,e.body)];let r=e.type.value.toLowerCase();t[r]||(t[r]=[]),t[r].push(e);let i=n?qv[n][r]:void 0;return i?i.isValidBuiltinFieldValue(e.body?.callee)?[]:[new C(S.INVALID_METADATA_FIELD,i.message,e)]:Gf(e.body?.callee)?[]:[new C(S.INVALID_METADATA_FIELD,`A Metadata field value must be a string or a color literal`,e.body??e)]});return r.push(...Object.values(t).flatMap(e=>e.length<=1?[]:e.map(e=>new C(S.DUPLICATE_METADATA_FIELD,`Duplicate Metadata fields are defined`,e)))),r}},Yv={validateNode(t,i){return O(i,r.Metadata)?new n(void 0,new Jv(t,i).validate()):new n(e)},nodeFullname(t,i){return O(i,r.Metadata)?new n(void 0):new n(e)},nodeAlias(t,i){return O(i,r.Metadata)?new n(void 0):new n(e)},nodeSettings(t,i){return O(i,r.Metadata)?new n({}):new n(e)}},Xv=class{constructor(e,t){this.ast=t,this.compiler=e}validate(){let e=[],t=[];for(let n of this.ast.body){let r=this.compiler.validateNode(n);e.push(...r.getErrors()),t.push(...r.getWarnings())}return new n(this.ast,e,t)}},Zv={validateNode(t,r){return Zf(r)?n.create(void 0,new Xv(t,r).validate().getErrors()):n.create(e)},nodeFullname(t,r){return Zf(r)?new n(void 0):n.create(e)},nodeAlias(t,r){return Zf(r)?new n(void 0):n.create(e)},nodeSettings(t,r){return Zf(r)?new n({}):n.create(e)}},Qv=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name).getErrors(),...this.validateAlias(this.declarationNode.alias).getErrors(),...this.validateSettingList(this.declarationNode.attributeList).getErrors(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new C(S.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?Mf(e)?new n(A(e)):new n(void 0,[new C(S.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]):new n(void 0)}validateAlias(e){return e?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new n(void 0)}validateSettingList(e){return e?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new n({})}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...t.map(e=>new C(S.INVALID_PROJECT_FIELD,`A Project can not have inline fields`,e)),...this.validateSubElements(n)]}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},$v={validateNode(t,i){return O(i,r.Project)?n.create(void 0,new Qv(t,i).validate()):n.create(e)},nodeFullname(t,i){return O(i,r.Project)?i.name?Mf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):k(i,r.Project)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Project)&&i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,i.alias)]):k(i,r.Project)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Project)?i.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,i.attributeList)]):new n({}):k(i,r.Project)?new n({}):n.create(e)}},ey=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return e instanceof L||e instanceof R&&e.isKind(r.Table)?[]:[new C(S.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof Tm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof L?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof W))return[new C(S.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,e||this.declarationNode.type||this.declarationNode)];let t=[];return(!e.callee||!Af(e.callee))&&t.push(new C(S.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Uf(e.argumentList))&&t.push(new C(S.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Uf(e)?[new C(S.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return ty(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateDataRow(e);let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateDataRows(t),...this.validateSubElements(n)]}validateDataRows(e){return e.flatMap(e=>this.validateDataRow(e))}validateDataRow(e){let t=[];if(!e.callee||e.args.length>0)return t.push(new C(S.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof Sm)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new C(S.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,n));else this.isValidRecordValue(e.callee)||t.push(new C(S.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,e.callee));return t}isValidRecordValue(e){if(e instanceof Om||Bf(e)||T(e)||e instanceof bm)return!0;if(E(e)){let t=e.expression.variable.value.toLowerCase();return To.includes(t)}if(D(e)){let t=A(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function ty(e){let t=w(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.Example:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_RECORDS_SETTING,`'example' can only appear once`,e))),e.forEach(e=>{e.value&&r.push(new C(S.INVALID_RECORDS_SETTING_VALUE,`'example' cannot have a value`,e))});break;default:r.push(...e.map(e=>new C(S.UNKNOWN_RECORDS_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}var ny={validateNode(t,i){return O(i,r.Records)?n.create(void 0,new ey(t,i).validate()):n.create(e)},nodeFullname(i,a){if(O(a,r.Records)){if(a.name instanceof Tm)return new n(void 0,[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,a.name)]);if(a.parent instanceof L){if(!(a.name instanceof W))return new n(void 0,[new C(S.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,a.name||a.type||a)]);let e=[];(!a.name.callee||!Af(a.name.callee))&&e.push(new C(S.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,a.name.callee||a.name)),(!a.name.argumentList||!Uf(a.name.argumentList))&&e.push(new C(S.INVALID_RECORDS_NAME,`Records column list must be simple column names`,a.name.argumentList||a.name));let t=A(a.name.callee);return t?.length===1&&t.unshift(v),new n(t,e)}{let e=a.parent&&i.nodeFullname(a.parent).getFiltered(t);return a.name&&!Uf(a.name)?new n(e,[new C(S.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,a.name)]):new n(e)}}return k(a,r.Records)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Records)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`Records cannot have an alias`,i.alias)]):new n(void 0):k(i,r.Records)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Records)?i.attributeList?ty(i.attributeList):new n({}):k(i,r.Records)?new n({}):n.create(e)}},ry=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new C(S.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Tm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:Mf(e)?[]:[new C(S.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new C(S.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof V)return this.validateFields([e]);let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new C(S.EMPTY_REF,`A Ref must have at least one field`,this.declarationNode)];let t=[];return e.length>1&&t.push(...e.slice(1).map(e=>new C(S.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!np(e.callee)&&t.push(new C(S.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&np(e.callee)){let n=pp(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=pp(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new C(S.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new C(S.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!rp(e.callee)&&t.push(new C(S.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(h(n)instanceof U){let e=this.validateFieldSettings(h(n));t.push(...e),n.pop()}else n[0]instanceof U&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new C(S.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return ay(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function iy(e){if(!(E(e)&&e.expression.variable.kind!==_.QUOTED_STRING)&&!(e instanceof _m))return!1;let t;if(t=e instanceof _m?cp(e)||``:e.expression.variable.value,t)switch(t.toLowerCase()){case`cascade`:case`no action`:case`set null`:case`set default`:case`restrict`:return!0;default:return!1}return!1}function ay(e){let t=w(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Delete:case i.Update:t.length>1&&t.forEach(t=>r.push(new C(S.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{iy(t.value)||r.push(new C(S.INVALID_REF_SETTING_VALUE,`'${e}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,t))}),o[e]=t;break;case i.Color:t.length>1&&r.push(...t.map(e=>new C(S.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{Lf(e.value)||r.push(new C(S.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),o[e]=t;break;case i.Inactive:t.length>1&&r.push(...t.map(e=>new C(S.DUPLICATE_REF_SETTING,`'inactive' can only appear once`,e))),t.forEach(e=>{e.value&&r.push(new C(S.INVALID_REF_SETTING_VALUE,`'inactive' cannot have a value`,e))}),o[e]=t;break;default:t.forEach(t=>r.push(new C(S.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new n(o,r)}var oy={validateNode(t,i){return O(i,r.Ref)?n.create(void 0,new ry(t,i).validate()):n.create(e)},nodeFullname(t,i){return O(i,r.Ref)?i.name?Mf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,i.name)]):new n(void 0):k(i,r.Ref)?new n(void 0):n.create(e)},nodeAlias(t,i){return O(i,r.Ref)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.Ref)?new n(void 0):n.create(e)},nodeSettings(t,i){if(O(i,r.Ref))return i.attributeList?new n({},[new C(S.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,i.attributeList)]):new n({});if(k(i,r.Ref)){let e=[...i.args],t;return h(e)instanceof U?t=h(e):e[0]instanceof U&&(t=e[0]),t?ay(t):new n({})}return n.create(e)}},sy=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new C(S.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof km?[new C(S.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof Tm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:Af(e)?[]:[new C(S.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new C(S.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?jf(e)?[]:[new C(S.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){return cy(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=e=>{let t=[];if(!e.callee)return[];e.args.length===0&&t.push(new C(S.INVALID_COLUMN,`A column must have a type`,e.callee)),E(e.callee)||t.push(new C(S.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Wf(e.args[0])&&t.push(new C(S.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t},n=e=>{let t=[];return e.callee?(Pf(e.callee)||t.push(new C(S.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee)),e.args.length&&t.push(...e.args.map(e=>new C(S.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof B&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){return ly(e).getErrors()}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new C(S.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function cy(e){let t=w(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{let t=k_[i.HeaderColor];t.isValidBuiltinFieldValue(e.value)||r.push(new C(S.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{let t=k_[i.Note];t.isValidBuiltinFieldValue(e.value)||r.push(new C(S.INVALID_TABLE_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Hf(e.value)||r.push(new C(S.INVALID_TABLE_SETTING_VALUE,"'dep' must be `-> target` or `<- source`",e.value||e.name))});break;default:r.push(...x_(t,e,{duplicate:S.DUPLICATE_TABLE_SETTING,invalidValue:S.INVALID_TABLE_SETTING_VALUE}))}}),new n(a,r)}function ly(e){if(!e.slice(0,-1).every(qf)||!e.slice(-1).every(e=>qf(e)||e instanceof U))return new n({},e.map(e=>new C(S.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let t;h(e)instanceof U&&(t=e.pop());let r=w(t),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(M(e)??``).toLowerCase();t!==i.PK&&t!==i.Unique?a.push(new C(S.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e)):o[t]===void 0?o[t]=[e]:o[t].push(e)});let s=o[i.PK]||[],c=o[i.PrimaryKey]||[];return s.length>=1&&c.length>=1&&a.push(...[...s,...c].map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{let t=A_[i.Note];t.isValidBuiltinFieldValue(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,t.message,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Vf(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=o[i.Null]||[];e.length>=1&&t.length>=1&&a.push(...[...e,...t].map(e=>new C(S.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{zf(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'default' must be an enum value, a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof bm||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;case i.Dep:e.forEach(e=>{Hf(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'dep' must be a valid unary relationship`,e.value||e.name))});break;default:a.push(...x_(t,e,{duplicate:S.DUPLICATE_COLUMN_SETTING,invalidValue:S.INVALID_COLUMN_SETTING_VALUE}))}}),new n(o,a)}var uy={validateNode(t,i){return O(i,r.Table)?n.create(void 0,new sy(t,i).validate()):n.create(e)},nodeFullname(t,i){if(O(i,r.Table)){if(!i.name)return new n(void 0,[new C(S.NAME_NOT_FOUND,`A Table must have a name`,i)]);if(i.name instanceof km)return new n(void 0,[new C(S.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,i.name)]);let e=A(i.name);return e?.length===1&&e.unshift(v),new n(e)}if(k(i,r.Table)){if(Pf(i.callee)){let e=M(i.callee.expression);return new n(e?[e]:void 0)}let e=M(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return O(i,r.Table)?i.alias?jf(i.alias)?new n(M(i.alias)):new n(void 0,[new C(S.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,i.alias)]):new n(void 0):k(i,r.Table)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.Table)?i.attributeList?cy(i.attributeList):new n({}):k(i,r.Table)?ly(i.args.slice(1)):n.create(e)}},dy=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new C(S.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:Mf(e)?[]:[new C(S.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new C(S.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){return fy(e).getErrors()}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&A(e.callee)===void 0&&t.push(new C(S.INVALID_TABLEGROUP_FIELD,`A TableGroup field must be of the form <table> or <schema>.<table>`,e.callee)),e.args.length>0&&t.push(...e.args.map(e=>new C(S.INVALID_TABLEGROUP_FIELD,`A TableGroup field should only have a single Table name`,e))),t})}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new C(S.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function fy(e){let t=w(e),r=t.getErrors(),a=t.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case i.Color:case i.Note:{let n=Y_[e];t.length>1&&r.push(...t.map(t=>new C(S.DUPLICATE_TABLE_SETTING,`'${e}' can only appear once`,t))),t.forEach(e=>{n.isValidBuiltinFieldValue(e.value)||r.push(new C(S.INVALID_TABLE_SETTING_VALUE,n.message,e.value||e.name))}),o[e]=t;break}default:r.push(...x_(e,t,{duplicate:S.DUPLICATE_TABLE_SETTING,invalidValue:S.INVALID_TABLE_SETTING_VALUE})),o[e]=t}return new n(o,r)}var py={validateNode(t,i){return O(i,r.TableGroup)?n.create(void 0,new dy(t,i).validate()):n.create(e)},nodeFullname(t,i){if(O(i,r.TableGroup))return i.name?Mf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A TableGroup name must be a single identifier`,i.name)]):new n(void 0,[new C(S.NAME_NOT_FOUND,`A TableGroup must have a name`,i)]);if(k(i,r.TableGroup)){let e=A(i.callee);return e?.length===1&&e.unshift(v),new n(e)}return n.create(e)},nodeAlias(t,i){return O(i,r.TableGroup)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,i.alias)]):new n(void 0):k(i,r.TableGroup)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.TableGroup)?fy(i.attributeList):k(i,r.TableGroup)?new n({}):n.create(e)}},my=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof R?[new C(S.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Tm?[new C(S.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:Mf(e)?[]:[new C(S.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new C(S.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new C(S.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=w(e),n=t.getErrors();return Ca(t.getValue(),(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&n.push(...e.map(e=>new C(S.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Lf(e.value)||n.push(new C(S.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&n.push(...e.map(e=>new C(S.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{T(e.value)||n.push(new C(S.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new C(S.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof V)return[new C(S.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=g(e.body,e=>e instanceof V);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[];e.args.length===0&&t.push(new C(S.INVALID_COLUMN,`A column must have a type`,e.callee)),E(e.callee)||t.push(new C(S.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Wf(e.args[0])&&t.push(new C(S.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t})}validateFieldSetting(e){let t=h(e);if(!e.slice(0,-1).every(qf)||!(qf(t)||t instanceof U))return e.map(e=>new C(S.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;h(e)instanceof U&&(n=e.pop());let r=w(n),a=r.getErrors(),o=r.getValue();e.forEach(e=>{let t=(M(e)??``).toLowerCase();t!==i.PK&&t!==i.Unique?a.push(new C(S.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e)):o[t]===void 0?o[t]=[e]:o[t].push(e)});let s=o[i.PK]||[],c=o[i.PrimaryKey]||[];return s.length>=1&&c.length>=1&&a.push(...[...s,...c].map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(o,(e,t)=>{switch(t){case i.Note:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{T(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Vf(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=o[i.Null]||[];e.length>=1&&n.length>=1&&a.push(...[...e,...n].map(e=>new C(S.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&a.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{zf(e.value)||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof bm||a.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:a.push(...x_(t,e,{duplicate:S.DUPLICATE_COLUMN_SETTING,invalidValue:S.INVALID_COLUMN_SETTING_VALUE}))}}),a}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(r.Note));return n.length>1&&t.push(...n.map(e=>new C(S.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function hy(e){let t=w(e),r=t.getErrors(),a=t.getValue();return Ca(a,(e,t)=>{switch(t){case i.HeaderColor:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Lf(e.value)||r.push(new C(S.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case i.Note:e.length>1&&r.push(...e.map(e=>new C(S.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{T(e.value)||r.push(new C(S.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:r.push(...e.map(e=>new C(S.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new n(a,r)}function gy(e){let t=h(e);if(e.length>0&&(!e.slice(0,-1).every(qf)||!(qf(t)||t instanceof U)))return new n({},e.map(e=>new C(S.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new n({});let r;h(e)instanceof U&&(r=e.pop());let a=w(r),o=a.getErrors(),s=a.getValue();e.forEach(e=>{let t=(M(e)??``).toLowerCase();t!==i.PK&&t!==i.Unique?o.push(new C(S.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e)):s[t]===void 0?s[t]=[e]:s[t].push(e)});let c=s[i.PK]||[],l=s[i.PrimaryKey]||[];return c.length>=1&&l.length>=1&&o.push(...[...c,...l].map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Ca(s,(e,t)=>{switch(t){case i.Note:e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{T(e.value)||o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case i.Ref:e.forEach(e=>{Vf(e.value)||o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case i.PrimaryKey:e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.PK:e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.NotNull:{e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=s[i.Null]||[];e.length>=1&&n.length>=1&&o.push(...[...e,...n].map(e=>new C(S.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case i.Null:e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Unique:e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Increment:e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof z&&e.value!==void 0&&o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case i.Default:e.length>1&&o.push(...e.map(e=>new C(S.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{zf(e.value)||o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case i.Check:e.forEach(e=>{e.value instanceof bm||o.push(new C(S.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:o.push(...x_(t,e,{duplicate:S.DUPLICATE_COLUMN_SETTING,invalidValue:S.INVALID_COLUMN_SETTING_VALUE}))}}),new n(s,o)}var _y={validateNode(t,i){return O(i,r.TablePartial)?n.create(void 0,new my(t,i).validate()):n.create(e)},nodeFullname(t,i){if(O(i,r.TablePartial))return i.name?Mf(i.name)?new n(A(i.name)):new n(void 0,[new C(S.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,i.name)]):new n(void 0,[new C(S.NAME_NOT_FOUND,`A TablePartial must have a name`,i)]);if(k(i,r.TablePartial)){let e=M(i.callee);return new n(e?[e]:void 0)}return n.create(e)},nodeAlias(t,i){return O(i,r.TablePartial)?i.alias?new n(void 0,[new C(S.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,i.alias)]):new n(M(i.alias)):k(i,r.TablePartial)?new n(void 0):n.create(e)},nodeSettings(t,i){return O(i,r.TablePartial)?hy(i.attributeList):k(i,r.TablePartial)?gy(i.args.slice(1)):n.create(e)}},vy=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof L?[]:[new C(S.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.specifiers instanceof Tm)return[];for(let t of this.declarationNode.specifiers?.specifiers||[])e.push(...this.validateSpecifier(t));return e}validateSpecifier(e){let t=[];return e.importKind===void 0?t.push(new C(S.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(Up))||t.push(new C(S.INVALID_USE_SPECIFIER_KIND,`'${e.importKind.value}' is not a valid specifier type`,e.importKind)),[...t,...this.compiler.nodeFullname(e).getErrors(),...this.compiler.nodeAlias(e).getErrors()]}},yy=[uy,Hv,ny,Wv,Mv,oy,Rv,$v,py,_y,Kv,Yv,Bv,Zv,{validateNode(t,r){return r instanceof mm?n.create(void 0,new vy(t,r).validate()):n.create(e)},nodeFullname(t,r){if(!Xf(r))return n.create(e);let i=A(r.name);return!i||i.length===0?n.create(void 0,[new C(S.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,r)]):r.isKind(Up.TableGroup)&&i.length>1?n.create(i,[new C(S.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,r)]):r.isKind(Up.TablePartial)&&i.length>1?n.create(i,[new C(S.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,r)]):r.isKind(Up.Note)&&i.length>1?n.create(i,[new C(S.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,r)]):(i.length===1&&!r.isKind(Up.Schema)&&i.unshift(v),new n(i))},nodeAlias(t,r){return Xf(r)?r.alias?jf(r.alias)?new n(M(r.alias)):new n(void 0,[new C(S.INVALID_ALIAS,`Use aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,r.alias)]):new n(void 0):n.create(e)},nodeSettings(t,r){return r instanceof mm?n.create({}):n.create(e)}},Fv];function by(t,...r){for(let n of yy){let i=n[t];if(i){let t=i(...r);if(!t.hasValue(e))return t}}return n.create(e)}function xy(r){let i=by(`validateNode`,this,r);return i.hasValue(e)?n.create(t):i}function Sy(r){let i=by(`nodeSettings`,this,r);return i.hasValue(e)?n.create(t):i}function Cy(r){let i=by(`nodeFullname`,this,r);return i.hasValue(e)?n.create(t):i}function wy(r){let i=by(`nodeAlias`,this,r);return i.hasValue(e)?n.create(t):i}var Ty=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Ey(e,t){let n;return n=t.length===0?e:e.replace(/\{(\d+)\}/g,(e,n)=>{let r=t[n[0]],i=e;return typeof r==`string`?i=r:(typeof r==`number`||typeof r==`boolean`||r==null)&&(i=String(r)),i}),Ty&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function Dy(e,t,...n){return Ey(t,n)}var Oy=!1,ky=!1,Ay=!1,jy=!1,My=void 0,Ny=typeof self==`object`?self:typeof global==`object`?global:{},Py=void 0;Ny.vscode!==void 0&&Ny.vscode.process!==void 0?Py=Ny.vscode.process:typeof process<`u`&&(Py=process);var Fy=typeof Py?.versions?.electron==`string`&&Py?.type===`renderer`;if(typeof navigator==`object`&&!Fy)My=navigator.userAgent,Oy=My.indexOf(`Windows`)>=0,ky=My.indexOf(`Macintosh`)>=0,(My.indexOf(`Macintosh`)>=0||My.indexOf(`iPad`)>=0||My.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,Ay=My.indexOf(`Linux`)>=0,My?.indexOf(`Mobi`),jy=!0,Dy({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof Py==`object`){Oy=Py.platform===`win32`,ky=Py.platform===`darwin`,Ay=Py.platform===`linux`,Ay&&Py.env.SNAP&&Py.env.SNAP_REVISION,Py.env.CI||Py.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=Py.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.availableLanguages[`*`],t.locale,t.osLocale,t._translationsConfigFile}catch{}}else console.error(`Unable to resolve platform.`);var Iy=Oy,Ly=ky;jy&&Ny.importScripts;var Ry=My,zy=typeof Ny.postMessage==`function`&&!Ny.importScripts;(()=>{if(zy){let e=[];Ny.addEventListener(`message`,t=>{if(t.data&&t.data.vscodeScheduleAsyncWork)for(let n=0,r=e.length;n<r;n++){let r=e[n];if(r.id===t.data.vscodeScheduleAsyncWork){e.splice(n,1),r.callback();return}}});let t=0;return n=>{let r=++t;e.push({id:r,callback:n}),Ny.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var By=!!(Ry&&Ry.indexOf(`Chrome`)>=0);Ry&&Ry.indexOf(`Firefox`),!By&&Ry&&Ry.indexOf(`Safari`),Ry&&Ry.indexOf(`Edg/`),Ry&&Ry.indexOf(`Android`);var Vy;if(Ny.vscode!==void 0&&Ny.vscode.process!==void 0){let e=Ny.vscode.process;Vy={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else Vy=typeof process<`u`?{get platform(){return process.platform},get arch(){return process.arch},get env(){return process.env},cwd(){return process.env.VSCODE_CWD||process.cwd()}}:{get platform(){return Iy?`win32`:Ly?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var Hy=Vy.cwd,Uy=Vy.env,Wy=Vy.platform,Gy=65,Ky=97,qy=90,Jy=122,Yy=46,Xy=47,Zy=92,Qy=58,$y=63,eb=class extends Error{constructor(e,t,n){let r;typeof t==`string`&&t.indexOf(`not `)===0?(r=`must not be`,t=t.replace(/^not /,``)):r=`must be`;let i=`The "${e}" ${e.indexOf(`.`)===-1?`argument`:`property`} ${r} of type ${t}`;i+=`. Received type ${typeof n}`,super(i),this.code=`ERR_INVALID_ARG_TYPE`}};function tb(e,t){if(typeof e!=`object`||!e)throw new eb(t,`Object`,e)}function nb(e,t){if(typeof e!=`string`)throw new eb(t,`string`,e)}var rb=Wy===`win32`;function K(e){return e===Xy||e===Zy}function ib(e){return e===Xy}function ab(e){return e>=Gy&&e<=qy||e>=Ky&&e<=Jy}function ob(e,t,n,r){let i=``,a=0,o=-1,s=0,c=0;for(let l=0;l<=e.length;++l){if(l<e.length)c=e.charCodeAt(l);else if(r(c))break;else c=Xy;if(r(c)){if(o!==l-1&&s!==1){if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==Yy||i.charCodeAt(i.length-2)!==Yy){if(i.length>2){let e=i.lastIndexOf(n);e===-1?(i=``,a=0):(i=i.slice(0,e),a=i.length-1-i.lastIndexOf(n)),o=l,s=0;continue}if(i.length!==0){i=``,a=0,o=l,s=0;continue}}t&&(i+=i.length>0?`${n}..`:`..`,a=2)}else i.length>0?i+=`${n}${e.slice(o+1,l)}`:i=e.slice(o+1,l),a=l-o-1}o=l,s=0}else c===Yy&&s!==-1?++s:s=-1}return i}function sb(e,t){tb(t,`pathObject`);let n=t.dir||t.root,r=t.base||`${t.name||``}${t.ext||``}`;return n?n===t.root?`${n}${r}`:`${n}${e}${r}`:r}var cb={resolve(...e){let t=``,n=``,r=!1;for(let i=e.length-1;i>=-1;i--){let a;if(i>=0){if(a=e[i],nb(a,`path`),a.length===0)continue}else t.length===0?a=Hy():(a=Uy[`=${t}`]||Hy(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===Zy)&&(a=`${t}\\`));let o=a.length,s=0,c=``,l=!1,u=a.charCodeAt(0);if(o===1)K(u)&&(s=1,l=!0);else if(K(u)){if(l=!0,K(a.charCodeAt(1))){let e=2,t=e;for(;e<o&&!K(a.charCodeAt(e));)e++;if(e<o&&e!==t){let n=a.slice(t,e);for(t=e;e<o&&K(a.charCodeAt(e));)e++;if(e<o&&e!==t){for(t=e;e<o&&!K(a.charCodeAt(e));)e++;(e===o||e!==t)&&(c=`\\\\${n}\\${a.slice(t,e)}`,s=e)}}}else s=1}else ab(u)&&a.charCodeAt(1)===Qy&&(c=a.slice(0,2),s=2,o>2&&K(a.charCodeAt(2))&&(l=!0,s=3));if(c.length>0){if(t.length>0){if(c.toLowerCase()!==t.toLowerCase())continue}else t=c}if(r){if(t.length>0)break}else if(n=`${a.slice(s)}\\${n}`,r=l,l&&t.length>0)break}return n=ob(n,!r,`\\`,K),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){nb(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return ib(a)?`\\`:e;if(K(a)){if(i=!0,K(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!K(e.charCodeAt(i));)i++;if(i<t&&i!==a){let o=e.slice(a,i);for(a=i;i<t&&K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!K(e.charCodeAt(i));)i++;if(i===t)return`\\\\${o}\\${e.slice(a)}\\`;i!==a&&(r=`\\\\${o}\\${e.slice(a,i)}`,n=i)}}}else n=1}else ab(a)&&e.charCodeAt(1)===Qy&&(r=e.slice(0,2),n=2,t>2&&K(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?ob(e.slice(n),!i,`\\`,K):``;return o.length===0&&!i&&(o=`.`),o.length>0&&K(e.charCodeAt(t-1))&&(o+=`\\`),r===void 0?i?`\\${o}`:o:i?`${r}\\${o}`:`${r}${o}`},isAbsolute(e){nb(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return K(n)||t>2&&ab(n)&&e.charCodeAt(1)===Qy&&K(e.charCodeAt(2))},join(...e){if(e.length===0)return`.`;let t,n;for(let r=0;r<e.length;++r){let i=e[r];nb(i,`path`),i.length>0&&(t===void 0?t=n=i:t+=`\\${i}`)}if(t===void 0)return`.`;let r=!0,i=0;if(typeof n==`string`&&K(n.charCodeAt(0))){++i;let e=n.length;e>1&&K(n.charCodeAt(1))&&(++i,e>2&&(K(n.charCodeAt(2))?++i:r=!1))}if(r){for(;i<t.length&&K(t.charCodeAt(i));)i++;i>=2&&(t=`\\${t.slice(i)}`)}return cb.normalize(t)},relative(e,t){if(nb(e,`from`),nb(t,`to`),e===t)return``;let n=cb.resolve(e),r=cb.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===Zy;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===Zy;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===Zy;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===Zy;)c--;let l=c-s,u=o<l?o:l,d=-1,f=0;for(;f<u;f++){let n=e.charCodeAt(i+f);if(n!==t.charCodeAt(s+f))break;n===Zy&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===Zy)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===Zy?d=f:f===2&&(d=3)),d===-1&&(d=0)}let p=``;for(f=i+d+1;f<=a;++f)(f===a||e.charCodeAt(f)===Zy)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===Zy&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=cb.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===Zy){if(t.charCodeAt(1)===Zy){let e=t.charCodeAt(2);if(e!==$y&&e!==Yy)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(ab(t.charCodeAt(0))&&t.charCodeAt(1)===Qy&&t.charCodeAt(2)===Zy)return`\\\\?\\${t}`;return e},dirname(e){nb(e,`path`);let t=e.length;if(t===0)return`.`;let n=-1,r=0,i=e.charCodeAt(0);if(t===1)return K(i)?e:`.`;if(K(i)){if(n=r=1,K(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&K(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!K(e.charCodeAt(i));)i++;if(i===t)return e;i!==a&&(n=r=i+1)}}}}else ab(i)&&e.charCodeAt(1)===Qy&&(n=t>2&&K(e.charCodeAt(2))?3:2,r=n);let a=-1,o=!0;for(let n=t-1;n>=r;--n)if(K(e.charCodeAt(n))){if(!o){a=n;break}}else o=!1;if(a===-1){if(n===-1)return`.`;a=n}return e.slice(0,a)},basename(e,t){t!==void 0&&nb(t,`ext`),nb(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&ab(e.charCodeAt(0))&&e.charCodeAt(1)===Qy&&(n=2),t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=n;--a){let c=e.charCodeAt(a);if(K(c)){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=n;--a)if(K(e.charCodeAt(a))){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){nb(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Qy&&ab(e.charCodeAt(0))&&(t=r=2);for(let s=e.length-1;s>=t;--s){let t=e.charCodeAt(s);if(K(t)){if(!a){r=s+1;break}}else i===-1&&(a=!1,i=s+1),t===Yy?n===-1?n=s:o!==1&&(o=1):n!==-1&&(o=-1)}return n===-1||i===-1||o===0||o===1&&n===i-1&&n===r+1?``:e.slice(n,i)},format:sb.bind(null,`\\`),parse(e){nb(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.length,r=0,i=e.charCodeAt(0);if(n===1)return K(i)?(t.root=t.dir=e,t):(t.base=t.name=e,t);if(K(i)){if(r=1,K(e.charCodeAt(1))){let t=2,i=t;for(;t<n&&!K(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&K(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&!K(e.charCodeAt(t));)t++;t===n?r=t:t!==i&&(r=t+1)}}}}else if(ab(i)&&e.charCodeAt(1)===Qy){if(n<=2)return t.root=t.dir=e,t;if(r=2,K(e.charCodeAt(2))){if(n===3)return t.root=t.dir=e,t;r=3}}r>0&&(t.root=e.slice(0,r));let a=-1,o=r,s=-1,c=!0,l=e.length-1,u=0;for(;l>=r;--l)if(i=e.charCodeAt(l),K(i)){if(!c){o=l+1;break}}else s===-1&&(c=!1,s=l+1),i===Yy?a===-1?a=l:u!==1&&(u=1):a!==-1&&(u=-1);return s!==-1&&(a===-1||u===0||u===1&&a===s-1&&a===o+1?t.base=t.name=e.slice(o,s):(t.name=e.slice(o,a),t.base=e.slice(o,s),t.ext=e.slice(a,s))),t.dir=o>0&&o!==r?e.slice(0,o-1):t.root,t},sep:`\\`,delimiter:`;`,win32:null,posix:null},lb=(()=>{if(rb){let e=/\\/g;return()=>{let t=Hy().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Hy()})(),ub={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:lb();nb(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Xy)}return t=ob(t,!n,`/`,ib),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(nb(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Xy,n=e.charCodeAt(e.length-1)===Xy;return e=ob(e,!t,`/`,ib),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return nb(e,`path`),e.length>0&&e.charCodeAt(0)===Xy},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];nb(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:ub.normalize(t)},relative(e,t){if(nb(e,`from`),nb(t,`to`),e===t||(e=ub.resolve(e),t=ub.resolve(t),e===t))return``;let n=e.length,r=n-1,i=t.length-1,a=r<i?r:i,o=-1,s=0;for(;s<a;s++){let n=e.charCodeAt(1+s);if(n!==t.charCodeAt(1+s))break;n===Xy&&(o=s)}if(s===a){if(i>a){if(t.charCodeAt(1+s)===Xy)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Xy?o=s:s===0&&(o=0))}let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Xy)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(nb(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Xy,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Xy){if(!r){n=t;break}}else r=!1;return n===-1?t?`/`:`.`:t&&n===1?`//`:e.slice(0,n)},basename(e,t){t!==void 0&&nb(t,`ext`),nb(e,`path`);let n=0,r=-1,i=!0,a;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=0;--a){let c=e.charCodeAt(a);if(c===Xy){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=0;--a)if(e.charCodeAt(a)===Xy){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){nb(e,`path`);let t=-1,n=0,r=-1,i=!0,a=0;for(let o=e.length-1;o>=0;--o){let s=e.charCodeAt(o);if(s===Xy){if(!i){n=o+1;break}}else r===-1&&(i=!1,r=o+1),s===Yy?t===-1?t=o:a!==1&&(a=1):t!==-1&&(a=-1)}return t===-1||r===-1||a===0||a===1&&t===r-1&&t===n+1?``:e.slice(t,r)},format:sb.bind(null,`/`),parse(e){nb(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Xy,r;n?(t.root=`/`,r=1):r=0;let i=-1,a=0,o=-1,s=!0,c=e.length-1,l=0;for(;c>=r;--c){let t=e.charCodeAt(c);if(t===Xy){if(!s){a=c+1;break}}else o===-1&&(s=!1,o=c+1),t===Yy?i===-1?i=c:l!==1&&(l=1):i!==-1&&(l=-1)}if(o!==-1){let r=a===0&&n?1:a;i===-1||l===0||l===1&&i===o-1&&i===a+1?t.base=t.name=e.slice(r,o):(t.name=e.slice(r,i),t.base=e.slice(r,o),t.ext=e.slice(i,o))}return a>0?t.dir=e.slice(0,a-1):n&&(t.dir=`/`),t},sep:`/`,delimiter:`:`,win32:null,posix:null};ub.win32=cb.win32=cb,ub.posix=cb.posix=ub,rb?cb.normalize:ub.normalize,rb?cb.resolve:ub.resolve,rb?cb.relative:ub.relative,rb?cb.dirname:ub.dirname,rb?cb.basename:ub.basename,rb?cb.extname:ub.extname,rb?cb.sep:ub.sep;var db=/^\w[\w\d+.-]*$/,fb=/^\//,pb=/^\/\//;function mb(e,t){if(!e.scheme&&t)throw Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${e.authority}", path: "${e.path}", query: "${e.query}", fragment: "${e.fragment}"}`);if(e.scheme&&!db.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!fb.test(e.path))throw Error(`[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character`)}else if(pb.test(e.path))throw Error(`[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")`)}}function hb(e,t){return!e&&!t?`file`:e}function gb(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==_b&&(t=_b+t):t=_b}return t}var q=``,_b=`/`,vb=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,yb=class e{static isUri(t){return t instanceof e?!0:t?typeof t.authority==`string`&&typeof t.fragment==`string`&&typeof t.path==`string`&&typeof t.query==`string`&&typeof t.scheme==`string`&&typeof t.fsPath==`string`&&typeof t.with==`function`&&typeof t.toString==`function`:!1}constructor(e,t,n,r,i,a=!1){typeof e==`object`?(this.scheme=e.scheme||q,this.authority=e.authority||q,this.path=e.path||q,this.query=e.query||q,this.fragment=e.fragment||q):(this.scheme=hb(e,a),this.authority=t||q,this.path=gb(this.scheme,n||q),this.query=r||q,this.fragment=i||q,mb(this,a))}get fsPath(){return Tb(this,!1)}with(e){if(!e)return this;let{scheme:t,authority:n,path:r,query:i,fragment:a}=e;return t===void 0?t=this.scheme:t===null&&(t=q),n===void 0?n=this.authority:n===null&&(n=q),r===void 0?r=this.path:r===null&&(r=q),i===void 0?i=this.query:i===null&&(i=q),a===void 0?a=this.fragment:a===null&&(a=q),t===this.scheme&&n===this.authority&&r===this.path&&i===this.query&&a===this.fragment?this:new xb(t,n,r,i,a)}static parse(e,t=!1){let n=vb.exec(e);return n?new xb(n[2]||q,kb(n[4]||q),kb(n[5]||q),kb(n[7]||q),kb(n[9]||q),t):new xb(q,q,q,q,q)}static file(e){let t=q;if(Iy&&(e=e.replace(/\\/g,_b)),e[0]===_b&&e[1]===_b){let n=e.indexOf(_b,2);n===-1?(t=e.substring(2),e=_b):(t=e.substring(2,n),e=e.substring(n)||_b)}return new xb(`file`,t,e,q,q)}static from(e,t){return new xb(e.scheme,e.authority,e.path,e.query,e.fragment,t)}static joinPath(t,...n){if(!t.path)throw Error(`[UriError]: cannot call joinPath on URI without path`);let r;return r=Iy&&t.scheme===`file`?e.file(cb.join(Tb(t,!0),...n)).path:ub.join(t.path,...n),t.with({path:r})}toString(e=!1){return Eb(this,e)}toJSON(){return this}static revive(t){if(!t||t instanceof e)return t;{let e=new xb(t);return e._formatted=t.external??null,e._fsPath=t._sep===bb?t.fsPath??null:null,e}}},bb=Iy?1:void 0,xb=class extends yb{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=Tb(this,!1),this._fsPath}toString(e=!1){return e?Eb(this,!0):(this._formatted||=Eb(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=bb),this._formatted&&(e.external=this._formatted),this.path&&(e.path=this.path),this.scheme&&(e.scheme=this.scheme),this.authority&&(e.authority=this.authority),this.query&&(e.query=this.query),this.fragment&&(e.fragment=this.fragment),e}},Sb={58:`%3A`,47:`%2F`,63:`%3F`,35:`%23`,91:`%5B`,93:`%5D`,64:`%40`,33:`%21`,36:`%24`,38:`%26`,39:`%27`,40:`%28`,41:`%29`,42:`%2A`,43:`%2B`,44:`%2C`,59:`%3B`,61:`%3D`,32:`%20`};function Cb(e,t,n){let r,i=-1;for(let a=0;a<e.length;a++){let o=e.charCodeAt(a);if(o>=97&&o<=122||o>=65&&o<=90||o>=48&&o<=57||o===45||o===46||o===95||o===126||t&&o===47||n&&o===91||n&&o===93||n&&o===58)i!==-1&&(r+=encodeURIComponent(e.substring(i,a)),i=-1),r!==void 0&&(r+=e.charAt(a));else{r===void 0&&(r=e.substr(0,a));let t=Sb[o];t===void 0?i===-1&&(i=a):(i!==-1&&(r+=encodeURIComponent(e.substring(i,a)),i=-1),r+=t)}}return i!==-1&&(r+=encodeURIComponent(e.substring(i))),r===void 0?e:r}function wb(e){let t;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r===35||r===63?(t===void 0&&(t=e.substr(0,n)),t+=Sb[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function Tb(e,t){let n;return n=e.authority&&e.path.length>1&&e.scheme===`file`?`//${e.authority}${e.path}`:e.path.charCodeAt(0)===47&&(e.path.charCodeAt(1)>=65&&e.path.charCodeAt(1)<=90||e.path.charCodeAt(1)>=97&&e.path.charCodeAt(1)<=122)&&e.path.charCodeAt(2)===58?t?e.path.substr(1):e.path[1].toLowerCase()+e.path.substr(2):e.path,Iy&&(n=n.replace(/\//g,`\\`)),n}function Eb(e,t){let n=t?wb:Cb,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=_b,r+=_b),a){let e=a.indexOf(`@`);if(e!==-1){let t=a.substr(0,e);a=a.substr(e+1),e=t.lastIndexOf(`:`),e===-1?r+=n(t,!1,!1):(r+=n(t.substr(0,e),!1,!1),r+=`:`,r+=n(t.substr(e+1),!1,!0)),r+=`@`}a=a.toLowerCase(),e=a.lastIndexOf(`:`),e===-1?r+=n(a,!1,!0):(r+=n(a.substr(0,e),!1,!0),r+=a.substr(e))}if(o){if(o.length>=3&&o.charCodeAt(0)===47&&o.charCodeAt(2)===58){let e=o.charCodeAt(1);e>=65&&e<=90&&(o=`/${String.fromCharCode(e+32)}:${o.substr(3)}`)}else if(o.length>=2&&o.charCodeAt(1)===58){let e=o.charCodeAt(0);e>=65&&e<=90&&(o=`${String.fromCharCode(e+32)}:${o.substr(2)}`)}r+=n(o,!0,!1)}return s&&(r+=`?`,r+=n(s,!1,!1)),c&&(r+=`#`,r+=t?c:Cb(c,!1,!1)),r}function Db(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+Db(e.substr(3)):e}}var Ob=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function kb(e){return e.match(Ob)?e.replace(Ob,e=>Db(e)):e}var J=function(e){return e[e.Function=1]=`Function`,e[e.Constructor=2]=`Constructor`,e[e.Field=3]=`Field`,e[e.Variable=4]=`Variable`,e[e.Class=5]=`Class`,e[e.Struct=6]=`Struct`,e[e.Interface=7]=`Interface`,e[e.Module=8]=`Module`,e[e.Property=9]=`Property`,e[e.Event=10]=`Event`,e[e.Operator=11]=`Operator`,e[e.Unit=12]=`Unit`,e[e.Value=13]=`Value`,e[e.Constant=14]=`Constant`,e[e.Enum=15]=`Enum`,e[e.EnumMember=16]=`EnumMember`,e[e.Keyword=17]=`Keyword`,e[e.Text=18]=`Text`,e[e.Color=19]=`Color`,e[e.File=20]=`File`,e[e.Reference=21]=`Reference`,e[e.Customcolor=22]=`Customcolor`,e[e.Folder=23]=`Folder`,e[e.TypeParameter=24]=`TypeParameter`,e[e.User=25]=`User`,e[e.Issue=26]=`Issue`,e[e.Snippet=27]=`Snippet`,e}({}),Y=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),Ab=function(e){return e[e.Hint=1]=`Hint`,e[e.Info=2]=`Info`,e[e.Warning=4]=`Warning`,e[e.Error=8]=`Error`,e}({});function jb(e,t){return e.getOffsetAt(t)}function Mb(e,t){let{startPos:n,endPos:r}=t;return{startLineNumber:n.line+1,startColumn:n.column+1,endLineNumber:r.line+1,endColumn:r.column+1}}var Nb=class{constructor(e){this.compiler=e}provideCodeActions(e,t,n,r){if(!n.markers.length)return;let i=So.fromUri(String(e.uri)),a=this.compiler.interpretProject().getInfos().filter(e=>e.quickFixes?.length&&e.filepath.equals(i));if(!a.length)return;let o=[];for(let t of n.markers)for(let n of a){let r=Mb(e,n.nodeOrToken);if(r.startLineNumber===t.startLineNumber&&r.startColumn===t.startColumn&&r.endLineNumber===t.endLineNumber&&r.endColumn===t.endColumn)for(let r of n.quickFixes??[]){let n=this.quickFixToCodeAction(r,e,t);n&&o.push(n)}}let s=Fa(o,e=>{let t=e.diagnostics?.[0];return`${e.title}@${t?.startLineNumber}:${t?.startColumn}`});if(s.length)return{actions:s,dispose(){}}}quickFixToCodeAction(e,t,n){let r=So.fromUri(String(t.uri));if(!e.filepath.equals(r))return;let i=yb.parse(e.filepath.toUri({protocol:t.uri.scheme})),a={edits:e.edits.map(e=>{let n=t.getPositionAt(e.start),r=t.getPositionAt(e.end);return{resource:i,textEdit:{range:{startLineNumber:n.lineNumber,startColumn:n.column,endLineNumber:r.lineNumber,endColumn:r.column},text:e.newText},versionId:t.getVersionId()}})};return{title:e.title,kind:`quickfix`,edit:a,diagnostics:[n]}}},Pb=class{constructor(e){this.compiler=e}provideDefinition(e,n){let{uri:r}=e,i=So.fromUri(String(e.uri)),a=jb(e,n),o=this.resolveImportPath(i,a,r);if(o)return o;let s=[...this.compiler.container.stack(i,a)];for(;s.length!==0;){let e=s.pop();if(!e)continue;let n=this.compiler.nodeReferee(e).getFiltered(t);if(!n)continue;let i;if(n.declaration&&[pm.PRIMARY_EXPRESSION,pm.VARIABLE].includes(e.kind)&&({declaration:i}=n),i){let{startPos:e,endPos:t}=i,n=r;return r&&i.filepath&&(n=yb.parse(i.filepath.toUri({protocol:r.scheme}))),[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}]}}return[]}resolveImportPath(e,t,n){let r=this.compiler.parse.ast(e);for(let i of r.body){if(!(i instanceof mm)||!i.importPath||!Mh(t,i.importPath))continue;let r=i.importPath.value;if(!r)continue;let a=this.compiler.layout.resolveFileSpecifier(e,r);if(a&&this.compiler.layout.exists(a))return[{range:{startColumn:1,startLineNumber:1,endColumn:1,endLineNumber:1},uri:n&&yb.parse(a.toUri({protocol:n.scheme}))}]}}},Fb=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e),...this.provideInfos(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideInfos(e){return e?this.compiler.interpretFile(e).getInfos().map(e=>this.createDiagnostic(e,`info`)):this.compiler.interpretProject().getInfos().map(e=>this.createDiagnostic(e,`info`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos,a=e.details,o=a?.quickFixes?.filter(e=>e.edits.length>0).map(e=>({title:e.title,shortTitle:e.shortTitle,edits:e.edits.map(e=>({start:e.start,end:e.end,newText:e.newText})),isPreferred:e.isPreferred}));return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code,category:a?.category,explanation:a?.explanation,filepath:e.filepath,quickFixes:o}}getSeverityValue(e){return e===`error`?Ab.Error:e===`warning`?Ab.Warning:Ab.Info}},Ib=class{constructor(e){this.compiler=e}provideReferences(e,n){let{uri:r}=e,i=So.fromUri(String(r)),a=jb(e,n);this.compiler.bindProject();let o=[...this.compiler.container.stack(i,a)];for(;o.length!==0;){let e=o.pop();if(e&&[pm.ELEMENT_DECLARATION,pm.FUNCTION_APPLICATION,pm.PRIMARY_EXPRESSION].includes(e?.kind)){let n=this.compiler.nodeSymbol(e).getFiltered(t)??this.compiler.nodeReferee(e).getFiltered(t),i=n?this.compiler.symbolReferences(n):void 0;if(i&&i.length>0)return i.map(e=>{let t=r;return r&&e.filepath&&(t=yb.parse(e.filepath.toUri({protocol:r.scheme}))),{range:{startColumn:e.startPos.column+1,startLineNumber:e.startPos.line+1,endColumn:e.endPos.column+1,endLineNumber:e.endPos.line+1},uri:t}})}}return[]}};function Lb(e,t){let n=[],r=e.parseFile(t).getValue()?.ast;if(!r)return n;for(let e of r.uses){let t=e.importPath?.value??``,r=[];if(e.specifiers instanceof gm)for(let t of e.specifiers.specifiers){let e,n;if(t.name?(e=t.importKind?.value,n=M(t.name)):t.importKind&&(n=t.importKind.value??void 0),n){let i=t.alias?M(t.alias):void 0;r.push({kind:e,name:n,alias:i})}}else e.specifiers instanceof Tm&&r.push({name:`*`});(r.length!==0||e.specifiers instanceof Tm)&&n.push({startOffset:e.fullStart,endOffset:e.fullEnd,sourceFile:t,specifiers:r,node:e})}return n}function Rb(e,t,n,r,i,a){let o=Lb(e,i),s=r.relativeTo(i.dirname).replace(/\.dbml$/,``),c=o.findIndex(e=>e.sourceFile===s),l=`${n} ${t}`;if(c!==-1){let e=o[c];return e.specifiers.some(e=>e.name===t)?{topInsert:``}:{topInsert:zb(Pa([...e.specifiers.filter(e=>e.name!==`*`).map(e=>`${e.kind??n} ${e.name}${e.alias?` as ${e.alias}`:``}`),l]),s,`
12
12
  `),removeRange:Bb(a,e.startOffset,e.endOffset)}}return{topInsert:zb([l],s,`
13
13
  `)}}function zb(e,t,n){return`use {${n}${e.map(e=>` ${e}`).join(n)}${n}} from '${t}'${n}${n}`}function Bb(e,t,n){let r=e.lastIndexOf(`
@@ -10496,7 +10496,7 @@ function U_(e) {
10496
10496
  if (e == null) return "null";
10497
10497
  if (typeof e == "boolean") return e ? "true" : "false";
10498
10498
  if (typeof e == "number") return String(e);
10499
- if (typeof e == "string") return `'${H_(e)}'`;
10499
+ if (typeof e == "string") return q_(e);
10500
10500
  let { value: t, type: n } = e;
10501
10501
  if (t == null || Bo(n) && typeof t == "string" && t.toLowerCase() === "null") return "null";
10502
10502
  if (n === "expression") return typeof t == "string" && t.toLowerCase().trim() === "null" ? "null" : `\`${t}\``;
@@ -10514,7 +10514,7 @@ function U_(e) {
10514
10514
  return e === null ? `\`${t}\`` : `'${H_(e)}'`;
10515
10515
  }
10516
10516
  let r = kp(t);
10517
- return r === null ? `\`${t}\`` : `'${H_(r)}'`;
10517
+ return r === null ? `\`${t}\`` : q_(r);
10518
10518
  }
10519
10519
  function W_(e) {
10520
10520
  return (e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g) || []).map((e) => e.startsWith("\"") && e.endsWith("\"") ? V_(e.slice(1, -1)) : e.trim()).filter((e) => e.length > 0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/parse",
4
- "version": "10.4.0-alpha.15",
4
+ "version": "10.4.0-alpha.16",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -51,5 +51,5 @@
51
51
  "engines": {
52
52
  "node": ">=18"
53
53
  },
54
- "gitHead": "7f627f78732684f69b9af1b8f97663893b4d3d73"
54
+ "gitHead": "c88c4064ea4536ad26a0c98ce21f2986f51bf6f6"
55
55
  }