@dbml/parse 10.4.0-alpha.14 → 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.
- package/dist/dbml-parse.js +10 -10
- package/dist/dbml-parse.mjs +119 -100
- package/package.json +2 -2
package/dist/dbml-parse.js
CHANGED
|
@@ -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
|
|
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(`
|
|
@@ -22,25 +22,25 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(
|
|
|
22
22
|
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(_.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&kf(this.peek());)this.advance();this.addToken(_.IDENTIFIER)}operator(e){switch(e){case`<`:this.peek()===`=`?this.advance():this.peek()===`>`?(this.advance(),this.peek()===`?`&&this.advance()):(this.peek()===`?`||this.peek()===`-`)&&this.advance();break;case`>`:(this.peek()===`=`||this.peek()===`?`)&&this.advance();break;case`-`:(this.peek()===`>`||this.peek()===`?`)&&this.advance();break;case`?`:this.peek()===`-`?(this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`<`?(this.advance(),this.peek()===`>`&&this.advance(),this.peek()===`?`&&this.advance()):this.peek()===`>`&&(this.advance(),this.peek()===`?`&&this.advance());break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance()}this.addToken(_.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(_.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=+!!t,e>1)break;if(this.check(`e`)||this.check(`E`)){let e=this.peek(1),t=e===`+`||e===`-`,n=t?this.peek(2):e;if(n&&Df(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Df(this.peek());)this.advance();if(this.isAtEnd()||!kf(this.peek()))return this.addToken(_.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(_.NUMERIC_LITERAL);if(!t&&!kf(this.peek()))return this.addToken(_.NUMERIC_LITERAL);if(!t&&!Df(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||kf(this.peek()));)this.advance();let e=this.createToken(_.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new C(S.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&kf(this.peek());)this.advance();let e=this.createToken(_.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&kf(this.peek());)this.advance();this.addToken(_.COLOR_LITERAL)}escapedString(){let e={column:this.current.column-1,offset:this.current.offset-1,line:this.current.line};if(this.isAtEnd())return`\\`;switch(this.advance()){case`\r`:return this.check(`
|
|
23
23
|
`)&&this.advance(),``;case`
|
|
24
24
|
`:return``;case`t`:return` `;case`n`:return`
|
|
25
|
-
`;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!kf(this.peek()))return this.errors.push(new C(S.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Ha.create(_.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},zS=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),BS=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return h(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case _.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case _.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case _.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case _.RBRACKET:if(this.isWithinListExpressionContext())return 0}}},VS=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},HS=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new BS,this.useSpecifierList=this.contextStack.withContextDo(zS.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(gm,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof hm&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(_.IDENTIFIER)&&Qa(this.peek()))break;!Ua(this.previous())&&!this.check(_.RBRACE)&&this.logError(this.peek(),S.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(_.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||this.check(_.STRING_LITERAL)||this.check(_.IDENTIFIER)&&Qa(e)||Wa(this.previous(),e))break;G(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===_.EOF?this.logError(e,S.UNEXPECTED_EOF,`Unexpected EOF`):G(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ya(e)||this.check(_.COLON,_.LBRACE,_.LBRACKET))break;G(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COLON,_.LBRACE,_.LBRACKET))break;G(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(zS.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(H,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(_.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||Wa(this.previous(),e))break;G(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(zS.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(Cm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(xm,e);try{this.consume(`Expect an opening parenthesis '('`,_.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(_.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(_.RPAREN);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof I&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,_.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.RPAREN,_.COMMA))break;G(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(zS.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(U,e);try{this.consume(`Expect an opening bracket '['`,_.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(_.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(_.RBRACKET);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof I&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,_.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;G(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET,_.COLON))break;G(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;G(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new VS(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===_.EOF}advance(){return this.isAtEnd()?h(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?h(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),S.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(G(this.peek()),this.logError(this.advance(),S.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)G(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(L,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Im(e).forEach(t=>{t instanceof I&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Xa(this.peek())||$a(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof mm&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(mm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===_.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(Tm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof gm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof Tm?`'*'`:`specifier list`;return Qa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(_.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(hm,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,_.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(_.IDENTIFIER,_.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof I&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect an element name`);if(Ya(this.peek())){e.asKeyword=this.advance();try{if(!this.check(_.IDENTIFIER,_.QUOTED_STRING))throw this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(Za(e.type))try{this.consume(`Expect a metadata target kind`,_.IDENTIFIER),e.targetKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(_.COLON,_.LBRACE,_.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ya(this.peek())){if(e.as=this.advance(),this.check(_.COLON,_.LBRACE,_.LBRACKET))this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}}try{e.attributeList=this.check(_.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,_.LBRACE,_.COLON))return t();try{if(this.match(_.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof R?(G(t),this.logError(t,S.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,_.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof R?this.errors.push(new C(S.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}expression(){let e={args:[]},t=()=>Mm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(V,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Ga(this.previous())||this.logError(n,S.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ua(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.RBRACKET,_.RPAREN,_.COMMA,_.COLON].includes(e)}commaExpression(){let e=this.check(_.COMMA)?this.nodeFactory.create(Om,{prevToken:this.previous()}):this.normalExpression();if(!this.check(_.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(Om,{prevToken:this.previous()}));break}if(this.check(_.COMMA))t.elementList.push(this.nodeFactory.create(Om,{prevToken:this.previous()}));else try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(Sm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(_.COMMA));return this.nodeFactory.create(Sm,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ua(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.LBRACE,_.RBRACKET,_.LBRACKET,_.RPAREN,_.LPAREN,_.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===_.LPAREN){let{left:r}=QS(n);if(r<e||Wa(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(W,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(W,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===_.LBRACKET){if(Ga(this.previous()))break;try{t=this.nodeFactory.create(km,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(km,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Va(n)){let r=n,i=QS(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(ym,{expression:t,op:r})}else{let n=JS(r);if(n.left===null||n.left<=e||XS(r).right!==null&&Wa(this.previous(),r)&&this.contextStack.top()===zS.BlockExpression)break;this.advance();try{t=this.nodeFactory.create(vm,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(vm,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Va(this.peek())){let t={};t.op=this.peek();let n=XS(t.op);if(n.right===null)throw this.logError(t.op,S.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Om,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(B,t),e.handlerContext)):e}e=this.nodeFactory.create(B,t)}else if(e=this.extractOperand(),e instanceof Om)throw new $(this.peek(),this.nodeFactory.create(Om,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(_.WILDCARD)?this.wildcardExpression():this.check(_.NUMERIC_LITERAL,_.STRING_LITERAL,_.COLOR_LITERAL,_.QUOTED_STRING,_.IDENTIFIER)?this.primaryExpression():this.check(_.FUNCTION_EXPRESSION)?this.functionExpression():this.check(_.LBRACKET)?this.listExpression():this.check(_.LBRACE)?this.blockExpression():this.check(_.LPAREN)?this.tupleExpression():(this.peek().kind===_.EOF?this.logError(this.peek(),S.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),S.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Om,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,_.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(bm,e),t.handlerContext):t}return this.nodeFactory.create(bm,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(Tm,{token:this.previous()})}canBeField(){return this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.COLON}primaryExpression(){if(this.match(_.COLOR_LITERAL,_.STRING_LITERAL,_.NUMERIC_LITERAL))return this.nodeFactory.create(Dm,{expression:this.nodeFactory.create(wm,{literal:this.previous()})});if(this.match(_.QUOTED_STRING,_.IDENTIFIER))return this.nodeFactory.create(Dm,{expression:this.nodeFactory.create(Em,{variable:this.previous()})});throw this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(_.COLON,_.RBRACKET,_.COMMA)){let t=this.peek();this.logError(t,S.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(_m,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(z,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(_.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(z,e)}attributeValue(){let e;try{e=this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==_.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(_.COLON,_.COMMA,_.RBRACKET);)try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(_m,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(_m,{identifiers:e})}logError(e,t,n){this.errors.push(new C(t,n,e))}},US=e=>({left:e,right:e+1}),WS=e=>({left:null,right:e}),GS=e=>({left:e,right:null}),KS={left:null,right:null},qS={".":US(16),"/":US(11),"%":US(11),"+":US(9),"=":US(2),"==":US(4),"!=":US(4),"-":US(9),"-?":US(9),"?-":US(9),"?-?":US(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`].map(e=>[e,US(7)]))};function JS(e){return qS[e.value]??KS}var YS=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`,`!`,`~`].map(e=>[e,WS(15)]));function XS(e){return YS[e.value]??KS}var ZS={"(":GS(14)};function QS(e){return ZS[e.value]??KS}function $S(e){let t=this.getSource(e);return new RS(t??``,e).lex().chain(n=>new HS(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function eC(){let e=G_(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function tC(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof um?s_.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function nC(e,n,r){let i;if(e instanceof Gp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Gp))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function rC(e){let t=e.originalSymbol;return K_(this).map(n=>n.filter(n=>n instanceof lm&&n.originalSymbol===t&&n!==e))}function iC(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{if(e instanceof Qm){let t=e.target(this);if(!t)return;let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}else for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(E(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof xm&&D(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ap(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Im(e))t instanceof I&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Kp&&t.isKind(P.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function aC(e){return this.resolutionIndex().parents.get(e.intern())??[]}function oC(e){return this.resolutionIndex().references.get(e.intern())??[]}function sC(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function cC(e){let t=e.originalSymbol;return K_(this).map(n=>n.filter(n=>n instanceof um&&n.originalSymbol===t&&n!==e))}function lC(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function uC(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=e.getSource(n)??``;for(let t of e.symbolMetadata(o))if(t instanceof Km&&fC(e,t,r)){if(t.declaration instanceof z){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(V);if(!r)continue;let a=kg(r,i.Ref,s);if(!a)continue;return{kind:`inline`,op:n,fullStart:a.start,fullEnd:a.end}}if(t.declaration instanceof R){let e=dp(t.declaration)[0];if(e instanceof V)return{kind:`standalone`,node:e}}}}function dC(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0||t.length===r.length&&t.every((e,t)=>e.name===r[t])}function fC(e,t,n){let r=t.leftTable(e),i=t.leftColumns(e),a=t.rightTable(e),o=t.rightColumns(e),[s,c]=n.endpoints;return dC(r,i,s)&&dC(a,o,c)||dC(r,i,c)&&dC(a,o,s)}function pC(e,t,n){let r=yC(e,t,_C(n.schemaName),n.tableName,P.Table);return{table:r,columns:(n.fieldNames??[]).map(t=>r?e.lookupMembers(r,P.Column,t):void 0)}}function mC(e,t){let n=e?.originalSymbol.declaration;return!!n&&n===t?.originalSymbol.declaration}function hC(e,t,n){return!mC(e,n.table)||t.length!==n.columns.length?!1:t.every((e,t)=>mC(e,n.columns[t]))}function gC(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=pC(e,n,r.upstream),c=pC(e,n,r.downstream);if(!s.table||!c.table)return;let l=e.getSource(n)??``;for(let t of e.symbolMetadata(o)){if(!(t instanceof qm))continue;let n=t.upstreamTables(e),r=t.upstreamColumns(e),a=t.downstreamTables(e),o=t.downstreamColumns(e);if(!n.some((e,t)=>hC(n[t],r[t]??[],s)&&hC(a[t],o[t]??[],c)))continue;if(t.declaration instanceof R)return{kind:`block`,declaration:t.declaration};let u=t.declaration.parentOfKind(V);if(!u)continue;let d=kg(u,i.Dep,l);if(!d)continue;let f=t.declaration.value;if(!(f instanceof B))continue;let p=f.op?.value;if(p)return{kind:`inline`,op:p,fullStart:d.start,fullEnd:d.end}}}function _C(e){return e&&e.length>0?e:v}function vC(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=W_(e);if(t.length===0)return{schema:v,table:``};if(t.length===1)return{schema:v,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function yC(e,n,r,i,a=P.Table){let o=e.parseFile(n).getValue().ast,s=e.nodeSymbol(o).getFiltered(t);if(!s)return;if(r===`public`)return e.lookupMembers(s,a,i)??void 0;let c=e.lookupMembers(s,P.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function bC(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function xC(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(z_(e.schemaName)),t.push(z_(e.tableName));for(let n of e.fieldNames??[])t.push(z_(n));return t.join(`.`)}function SC(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function CC(e,t){if(!e||!(e instanceof R))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function wC(e,t,n){let r=!R_(t),i=!R_(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function TC(e,t,n,r,i,a){return n===i&&r===a?!1:yC(e,t,i,a)!==void 0}function EC(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return bC(n.substring(i,a))===t?{start:i,end:e.end}:null}function DC(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function OC(e,t,n,r,i){let a=[],o=new Set,s=DC(r);for(let r of e){if(bC(i.substring(r.start,r.end))!==n)continue;let e=EC(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function kC(e,n,r){let i=vC(n),a=vC(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=yC(this,e,o,s);if(!u||u instanceof lm||TC(this,e,o,s,c,l))return new Map;if(u instanceof um&&u.useSpecifierDeclaration instanceof hm){let n=u.useSpecifierDeclaration;if(n.alias){if(this.nodeAlias(n).getFiltered(t)===s)return AC(this,e,n,u,c,l)}else return jC(this,e,n,u,c,l)}return MC(this,u,o,s,c,l)}function AC(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=wC(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,lC(o,c)]])}function jC(e,t,n,r,i,a){let o=e.getSource(t)??``,s=n.name;if(!s)return new Map;let c=wC(i,a,!1),l=s.end,u=[{start:l,end:l,newText:` as ${c.formattedTable}`}],d=e.symbolReferences(r);for(let e of d)e.filepath.absolute===t.absolute&&(e===s||s.start<=e.start&&e.end<=s.end||u.push({start:e.start,end:e.end,newText:c.formattedTable}));return new Map([[t.absolute,lC(o,u)]])}function MC(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof R))return new Map;let c=s.filepath;if(!c)return new Map;let l=wC(i,a,CC(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:DC(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of OC([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,lC(r,n))}return m}function NC(e,t,n,r){if(t.kind===`dep`)return IC(this,e,t,n,r);if(t.kind===`ref`)return LC(this,e,t,n,r);let i=FC(this,e,t);if(!i)return[];let a=Og(i,n,r,this.getSource(e)??``);return a?[a]:[]}function PC(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:lC(i,a)}function FC(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case P.Column:{let i=yC(e,t,r,n.table,P.Table);return i?e.lookupMembers(i,P.Column,n.column)?.declaration:void 0}case P.Table:return yC(e,t,r,n.table)?.declaration;case P.Enum:case P.StickyNote:case P.TableGroup:return yC(e,t,r,n.name,n.kind)?.declaration;case P.Schema:return yC(e,t,n.schema,``,P.Schema)?.declaration;default:return}}function IC(e,t,n,r,i){let a=e.getSource(t)??``,o=gC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=xC(n.upstream),t=xC(n.downstream),s=SC(r,i),c=s?`Dep [${s}] {\n ${e} -> ${t}\n}`:`Dep {\n ${e} -> ${t}\n}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
|
|
25
|
+
`;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!kf(this.peek()))return this.errors.push(new C(S.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Ha.create(_.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},zS=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),BS=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return h(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case _.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case _.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case _.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case _.RBRACKET:if(this.isWithinListExpressionContext())return 0}}},VS=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},HS=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new BS,this.useSpecifierList=this.contextStack.withContextDo(zS.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(gm,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof hm&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(_.IDENTIFIER)&&Qa(this.peek()))break;!Ua(this.previous())&&!this.check(_.RBRACE)&&this.logError(this.peek(),S.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(_.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||this.check(_.STRING_LITERAL)||this.check(_.IDENTIFIER)&&Qa(e)||Wa(this.previous(),e))break;G(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===_.EOF?this.logError(e,S.UNEXPECTED_EOF,`Unexpected EOF`):G(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ya(e)||this.check(_.COLON,_.LBRACE,_.LBRACKET))break;G(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COLON,_.LBRACE,_.LBRACKET))break;G(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(zS.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(H,e);try{this.consume(`Expect an opening brace '{'`,_.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(_.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,_.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(_.RBRACE))for(G(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(_.RBRACE)||Wa(this.previous(),e))break;G(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(zS.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(Cm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(xm,e);try{this.consume(`Expect an opening parenthesis '('`,_.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(_.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(_.RPAREN);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof I&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,_.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.RPAREN,_.COMMA))break;G(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(zS.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(U,e);try{this.consume(`Expect an opening bracket '['`,_.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(_.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(_.RBRACKET);)try{this.consume(`Expect a comma ','`,_.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof I&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,_.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;G(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET,_.COLON))break;G(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(_.COMMA,_.RBRACKET))break;G(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new VS(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===_.EOF}advance(){return this.isAtEnd()?h(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?h(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),S.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(G(this.peek()),this.logError(this.advance(),S.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)G(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(L,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){Im(e).forEach(t=>{t instanceof I&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Xa(this.peek())||$a(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof mm&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(mm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===_.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(Tm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof gm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof Tm?`'*'`:`specifier list`;return Qa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(_.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(hm,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,_.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(_.IDENTIFIER,_.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof I&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect an element name`);if(Ya(this.peek())){e.asKeyword=this.advance();try{if(!this.check(_.IDENTIFIER,_.QUOTED_STRING))throw this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(Za(e.type))try{this.consume(`Expect a metadata target kind`,_.IDENTIFIER),e.targetKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(_.COLON,_.LBRACE,_.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ya(this.peek())){if(e.as=this.advance(),this.check(_.COLON,_.LBRACE,_.LBRACKET))this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}}try{e.attributeList=this.check(_.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,_.LBRACE,_.COLON))return t();try{if(this.match(_.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof R?(G(t),this.logError(t,S.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(R,e);try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,_.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof R?this.errors.push(new C(S.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(R,e)}expression(){let e={args:[]},t=()=>Mm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(V,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Ga(this.previous())||this.logError(n,S.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ua(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.RBRACKET,_.RPAREN,_.COMMA,_.COLON].includes(e)}commaExpression(){let e=this.check(_.COMMA)?this.nodeFactory.create(Om,{prevToken:this.previous()}):this.normalExpression();if(!this.check(_.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(Om,{prevToken:this.previous()}));break}if(this.check(_.COMMA))t.elementList.push(this.nodeFactory.create(Om,{prevToken:this.previous()}));else try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(Sm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(_.COMMA));return this.nodeFactory.create(Sm,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ua(this.previous()))return!0;let e=this.peek().kind;return[_.RBRACE,_.LBRACE,_.RBRACKET,_.LBRACKET,_.RPAREN,_.LPAREN,_.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===_.LPAREN){let{left:r}=QS(n);if(r<e||Wa(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(W,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(W,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===_.LBRACKET){if(Ga(this.previous()))break;try{t=this.nodeFactory.create(km,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(km,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Va(n)){let r=n,i=QS(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(ym,{expression:t,op:r})}else{let n=JS(r);if(n.left===null||n.left<=e||XS(r).right!==null&&Wa(this.previous(),r)&&this.contextStack.top()===zS.BlockExpression)break;this.advance();try{t=this.nodeFactory.create(vm,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(vm,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Va(this.peek())){let t={};t.op=this.peek();let n=XS(t.op);if(n.right===null)throw this.logError(t.op,S.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Om,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(B,t),e.handlerContext)):e}e=this.nodeFactory.create(B,t)}else if(e=this.extractOperand(),e instanceof Om)throw new $(this.peek(),this.nodeFactory.create(Om,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(_.WILDCARD)?this.wildcardExpression():this.check(_.NUMERIC_LITERAL,_.STRING_LITERAL,_.COLOR_LITERAL,_.QUOTED_STRING,_.IDENTIFIER)?this.primaryExpression():this.check(_.FUNCTION_EXPRESSION)?this.functionExpression():this.check(_.LBRACKET)?this.listExpression():this.check(_.LBRACE)?this.blockExpression():this.check(_.LPAREN)?this.tupleExpression():(this.peek().kind===_.EOF?this.logError(this.peek(),S.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),S.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Om,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,_.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(bm,e),t.handlerContext):t}return this.nodeFactory.create(bm,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(Tm,{token:this.previous()})}canBeField(){return this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.COLON}primaryExpression(){if(this.match(_.COLOR_LITERAL,_.STRING_LITERAL,_.NUMERIC_LITERAL))return this.nodeFactory.create(Dm,{expression:this.nodeFactory.create(wm,{literal:this.previous()})});if(this.match(_.QUOTED_STRING,_.IDENTIFIER))return this.nodeFactory.create(Dm,{expression:this.nodeFactory.create(Em,{variable:this.previous()})});throw this.logError(this.peek(),S.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(_.COLON,_.RBRACKET,_.COMMA)){let t=this.peek();this.logError(t,S.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(_m,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(z,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(_.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(z,e)}attributeValue(){let e;try{e=this.peek().kind===_.IDENTIFIER&&this.peek(1).kind===_.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==_.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(_.COLON,_.COMMA,_.RBRACKET);)try{this.consume(`Expect an identifier`,_.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(_m,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(_m,{identifiers:e})}logError(e,t,n){this.errors.push(new C(t,n,e))}},US=e=>({left:e,right:e+1}),WS=e=>({left:null,right:e}),GS=e=>({left:e,right:null}),KS={left:null,right:null},qS={".":US(16),"/":US(11),"%":US(11),"+":US(9),"=":US(2),"==":US(4),"!=":US(4),"-":US(9),"-?":US(9),"?-":US(9),"?-?":US(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`].map(e=>[e,US(7)]))};function JS(e){return qS[e.value]??KS}var YS=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`,`!`,`~`].map(e=>[e,WS(15)]));function XS(e){return YS[e.value]??KS}var ZS={"(":GS(14)};function QS(e){return ZS[e.value]??KS}function $S(e){let t=this.getSource(e);return new RS(t??``,e).lex().chain(n=>new HS(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function eC(){let e=G_(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function tC(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof um?s_.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function nC(e,n,r){let i;if(e instanceof Gp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Gp))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function rC(e){let t=e.originalSymbol;return K_(this).map(n=>n.filter(n=>n instanceof lm&&n.originalSymbol===t&&n!==e))}function iC(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{if(e instanceof Qm){let t=e.target(this);if(!t)return;let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}else for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(E(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof xm&&D(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ap(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of Im(e))t instanceof I&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Kp&&t.isKind(P.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function aC(e){return this.resolutionIndex().parents.get(e.intern())??[]}function oC(e){return this.resolutionIndex().references.get(e.intern())??[]}function sC(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function cC(e){let t=e.originalSymbol;return K_(this).map(n=>n.filter(n=>n instanceof um&&n.originalSymbol===t&&n!==e))}function lC(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function uC(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=e.getSource(n)??``;for(let t of e.symbolMetadata(o))if(t instanceof Km&&fC(e,t,r)){if(t.declaration instanceof z){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(V);if(!r)continue;let a=kg(r,i.Ref,s);if(!a)continue;return{kind:`inline`,op:n,fullStart:a.start,fullEnd:a.end}}if(t.declaration instanceof R){let e=dp(t.declaration)[0];if(e instanceof V)return{kind:`standalone`,node:e}}}}function dC(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0||t.length===r.length&&t.every((e,t)=>e.name===r[t])}function fC(e,t,n){let r=t.leftTable(e),i=t.leftColumns(e),a=t.rightTable(e),o=t.rightColumns(e),[s,c]=n.endpoints;return dC(r,i,s)&&dC(a,o,c)||dC(r,i,c)&&dC(a,o,s)}function pC(e,t,n){let r=yC(e,t,_C(n.schemaName),n.tableName,P.Table);return{table:r,columns:(n.fieldNames??[]).map(t=>r?e.lookupMembers(r,P.Column,t):void 0)}}function mC(e,t){let n=e?.originalSymbol.declaration;return!!n&&n===t?.originalSymbol.declaration}function hC(e,t,n){return!mC(e,n.table)||t.length!==n.columns.length?!1:t.every((e,t)=>mC(e,n.columns[t]))}function gC(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=pC(e,n,r.upstream),c=pC(e,n,r.downstream);if(!s.table||!c.table)return;let l=e.getSource(n)??``;for(let t of e.symbolMetadata(o)){if(!(t instanceof qm))continue;let n=t.upstreamTables(e),r=t.upstreamColumns(e),a=t.downstreamTables(e),o=t.downstreamColumns(e);if(!n.some((e,t)=>hC(n[t],r[t]??[],s)&&hC(a[t],o[t]??[],c)))continue;if(t.declaration instanceof R)return{kind:`block`,declaration:t.declaration};let u=t.declaration.parentOfKind(V);if(!u)continue;let d=kg(u,i.Dep,l);if(!d)continue;let f=t.declaration.value;if(!(f instanceof B))continue;let p=f.op?.value;if(p)return{kind:`inline`,op:p,fullStart:d.start,fullEnd:d.end}}}function _C(e){return e&&e.length>0?e:v}function vC(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=W_(e);if(t.length===0)return{schema:v,table:``};if(t.length===1)return{schema:v,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function yC(e,n,r,i,a=P.Table){let o=e.parseFile(n).getValue().ast,s=e.nodeSymbol(o).getFiltered(t);if(!s)return;if(r===`public`)return e.lookupMembers(s,a,i)??void 0;let c=e.lookupMembers(s,P.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function bC(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function xC(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(z_(e.schemaName)),t.push(z_(e.tableName));for(let n of e.fieldNames??[])t.push(z_(n));return t.join(`.`)}function SC(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function CC(e,t){if(!e||!(e instanceof R))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function wC(e,t,n){let r=!R_(t),i=!R_(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function TC(e,t,n,r,i,a){return n===i&&r===a?!1:yC(e,t,i,a)!==void 0}function EC(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return bC(n.substring(i,a))===t?{start:i,end:e.end}:null}function DC(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function OC(e,t,n,r,i){let a=[],o=new Set,s=DC(r);for(let r of e){if(bC(i.substring(r.start,r.end))!==n)continue;let e=EC(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function kC(e,n,r){let i=vC(n),a=vC(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=yC(this,e,o,s);if(!u||u instanceof lm||TC(this,e,o,s,c,l))return new Map;if(u instanceof um&&u.useSpecifierDeclaration instanceof hm&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return AC(this,e,n,u,c,l)}if(u instanceof um){if(u.useSpecifierDeclaration instanceof hm&&!u.useSpecifierDeclaration.alias)return jC(this,e,u.useSpecifierDeclaration,u,s,c,l);if(u.useSpecifierDeclaration instanceof Tm)return MC(this,e,u,s,c,l)}return NC(this,u,o,s,c,l)}function AC(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=wC(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,lC(o,c)]])}function jC(e,t,n,r,i,a,o){let s=e.getSource(t)??``,c=wC(a,o,n.name?s.substring(n.name.start,n.name.end).includes(`"`):!1),l=[];n.name&&l.push({start:n.name.end,end:n.name.end,newText:` as ${c.formattedTable}`});let u=e.symbolReferences(r);for(let e of u)e.filepath.absolute!==t.absolute||n.name&&e.start===n.name.start&&e.end===n.name.end||bC(s.substring(e.start,e.end))!==i||l.push({start:e.start,end:e.end,newText:c.formattedTable});return new Map([[t.absolute,lC(s,l)]])}function MC(e,t,n,r,i,a){let o=n.useSpecifierDeclaration.parentOfKind(mm);if(!o)return new Map;let s=e.getSource(t)??``,c=wC(i,a,!1),l=n.kind.toLowerCase(),u=o.importPath?s.substring(o.importPath.start,o.importPath.end):`''`,d=`${o.isReuse?`reuse`:`use`} { ${l} ${r} as ${c.formattedTable} } from ${u}`,f=[];f.push({start:o.end,end:o.end,newText:`\n${d}`});let p=e.symbolReferences(n);for(let e of p)e.filepath.absolute===t.absolute&&bC(s.substring(e.start,e.end))===r&&f.push({start:e.start,end:e.end,newText:c.formattedTable});return new Map([[t.absolute,lC(s,f)]])}function NC(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof R))return new Map;let c=s.filepath;if(!c)return new Map;let l=wC(i,a,CC(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:DC(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of OC([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,lC(r,n))}return m}function PC(e,t,n,r){if(t.kind===`dep`)return LC(this,e,t,n,r);if(t.kind===`ref`)return RC(this,e,t,n,r);let i=IC(this,e,t);if(!i)return[];let a=Og(i,n,r,this.getSource(e)??``);return a?[a]:[]}function FC(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:lC(i,a)}function IC(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case P.Column:{let i=yC(e,t,r,n.table,P.Table);return i?e.lookupMembers(i,P.Column,n.column)?.declaration:void 0}case P.Table:return yC(e,t,r,n.table)?.declaration;case P.Enum:case P.StickyNote:case P.TableGroup:return yC(e,t,r,n.name,n.kind)?.declaration;case P.Schema:return yC(e,t,n.schema,``,P.Schema)?.declaration;default:return}}function LC(e,t,n,r,i){let a=e.getSource(t)??``,o=gC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=xC(n.upstream),t=xC(n.downstream),s=SC(r,i),c=s?`Dep [${s}] {\n ${e} -> ${t}\n}`:`Dep {\n ${e} -> ${t}\n}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
|
|
26
26
|
|
|
27
27
|
`+c+`
|
|
28
|
-
`}]}let{declaration:s}=o,{body:c}=s;if(c instanceof V){let e=Og(s,r,i,a);if(e)return[e];let t=Og(c,r,i,a);return t?[t]:[]}let l=Og(s,r,i,a);return l?[l]:[]}function
|
|
28
|
+
`}]}let{declaration:s}=o,{body:c}=s;if(c instanceof V){let e=Og(s,r,i,a);if(e)return[e];let t=Og(c,r,i,a);return t?[t]:[]}let l=Og(s,r,i,a);return l?[l]:[]}function RC(e,t,n,r,i){let a=e.getSource(t)??``,o=uC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=xC(n.endpoints[0]),t=xC(n.endpoints[1]),s=SC(r,i),c=s?`Ref: ${e} ${o.op} ${t} [${s}]`:`Ref: ${e} ${o.op} ${t}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
|
|
29
29
|
|
|
30
30
|
`+c+`
|
|
31
|
-
`}]}let s=Og(o.node,r,i,a);return s?[s]:[]}function
|
|
31
|
+
`}]}let s=Og(o.node,r,i,a);return s?[s]:[]}function zC(e){switch(e){case P.Table:return F.Table;case P.Column:return F.Column;case P.TableGroup:return F.TableGroup;case P.StickyNote:return F.Note;default:return}}function BC(e){let t=_C(`schema`in e?e.schema:void 0);switch(e.kind){case P.Table:{let n=e;return t===`public`?n.table:`${t}.${n.table}`}case P.Column:{let n=e;return t===`public`?`${n.table}.${n.column}`:`${t}.${n.table}.${n.column}`}case P.TableGroup:case P.StickyNote:{let n=e;return t===`public`?n.name:`${t}.${n.name}`}default:return}}function VC(e,t,n){if(b_(e)!==t)return!1;let r=A(e.name);return r?r.join(`.`).toLowerCase()===n.toLowerCase():!1}function HC(e,t){let n=zC(t.kind);if(!n)return;let i=BC(t);if(!i)return;let a=this.parseFile(e).getValue().ast;if(a){for(let e of a.body??[])if(e instanceof R&&O(e,r.Metadata)&&VC(e,n,i))return e}}function UC(e,t,n,r){return`Metadata ${e} ${t} {\n ${n}: ${r}\n}`}function WC(e){switch(e){case F.Table:return`Table`;case F.Column:return`Column`;case F.TableGroup:return`TableGroup`;case F.Note:return`Note`;default:return e}}function GC(e,t,n,r){let i=zC(t.kind);if(!i)return[];let a=BC(t);if(!a)return[];let o=this.getSource(e)??``,s=HC.call(this,e,t);if(!s){if(r===null)return[];let e=UC(WC(i),a,n,U_(r));return[{start:o.length,end:o.length,newText:`
|
|
32
32
|
|
|
33
33
|
`+e+`
|
|
34
34
|
`}]}let c=s.body instanceof H?s.body.body:[],l=c.find(e=>e instanceof R&&e.type?.value?.toLowerCase()===n.toLowerCase());if(r===null){let e=c.filter(e=>e instanceof R&&e.type?.value);if(l){if(e.length<=1){let e=s.start;for(;e>0&&(o[e-1]===`
|
|
35
|
-
`||o[e-1]===`\r`||o[e-1]===` `);)e--;return[{start:e,end:s.end,newText:``}]}return[{start:l.start,end:l.end,newText:``}]}return[]}let u=`${n}: ${U_(r)}`;if(l)return[{start:l.start,end:l.end,newText:u}];let d=s.end-1;return[{start:d,end:d,newText:` ${u}\n`}]}function
|
|
36
|
-
`)}function
|
|
35
|
+
`||o[e-1]===`\r`||o[e-1]===` `);)e--;return[{start:e,end:s.end,newText:``}]}return[{start:l.start,end:l.end,newText:``}]}return[]}let u=`${n}: ${U_(r)}`;if(l)return[{start:l.start,end:l.end,newText:u}];let d=s.end-1;return[{start:d,end:d,newText:` ${u}\n`}]}function KC(e,t,n,r){let i=this.getSource(e)??``,a=GC.call(this,e,t,n,r);return a.length===0?i:lC(i,a,!0)}function qC(e,t,n,r,i,a){let o=GC.call(t,n,r,i,a);return o.length===0?{newDbml:e,edits:[]}:{newDbml:lC(e,o,!0),edits:o}}function JC(e){let t=[],n=new RS(e,Oo).lex();if(n.getErrors().length>0)return t;let i=new HS(e,n.getValue(),new fm,Oo).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?A(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function YC(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function XC(e,t){e.push(` ${t} { * }`)}function ZC(e){return e==null?`null`:e.length===0?`empty`:`items`}function QC(e,t){let n=`DiagramView ${z_(e)} {`,r=e=>z_(e.name),i=t?.tables?.map(e=>{let t=z_(e.name);return e.schemaName===`public`?t:`${z_(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:ZC(t.tables),tableGroups:ZC(t.tableGroups),schemas:ZC(t.schemas),stickyNotes:ZC(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&YC(d,`Tables`,i),c.tableGroups===`items`&&YC(d,`TableGroups`,a),c.schemas===`items`&&YC(d,`Schemas`,o)):u&&XC(d,`Tables`),c.stickyNotes===`items`?YC(d,`Notes`,s):c.stickyNotes===`empty`&&XC(d,`Notes`),d.push(`}`),d.join(`
|
|
36
|
+
`)}function $C(e,t,n){let r=this.getSource(e)??``,i=n??JC(r),a=[];for(let e of t){let t=ew(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:lC(r,a,!0),edits:a}}function ew(e,t,n){switch(t.operation){case`create`:return tw(e,t,n);case`update`:return nw(e,t,n);case`delete`:return rw(e,t,n);default:return[]}}function tw(e,t,n){if(n.find(e=>e.name===t.name))return nw(e,t,n);let r=`
|
|
37
37
|
|
|
38
|
-
`+
|
|
39
|
-
`;return[{start:e.length,end:e.length,newText:r}]}function
|
|
38
|
+
`+QC(t.name,t.visibleEntities)+`
|
|
39
|
+
`;return[{start:e.length,end:e.length,newText:r}]}function nw(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=QC(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function rw(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
|
|
40
40
|
`;){i--,i>0&&e[i-1]===`\r`&&i--;let t=e.lastIndexOf(`
|
|
41
41
|
`,i-1)+1;if(e.substring(t,i).trim()!==``){i=r.startIndex,i>0&&e[i-1]===`
|
|
42
42
|
`&&(i--,i>0&&e[i-1]===`\r`&&i--);break}}return a<e.length&&e[a]===`\r`&&a++,a<e.length&&e[a]===`
|
|
43
|
-
`&&a++,[{start:i,end:a,newText:``}]}function
|
|
43
|
+
`&&a++,[{start:i,end:a,newText:``}]}function iw(e,t){let n=sw(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:q_(t)}}function aw(e){let t=sw(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function ow(e,t){if(sw(e)||!(e instanceof R))return;let n=cw(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${q_(t)}\n`};let r=e.body;if(r instanceof V){let n=r.args.find(e=>e instanceof U);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${q_(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${q_(t)}]`}}}function sw(e){if(!(e instanceof R))return;let t=e.body;if(t&&!(t instanceof V))for(let e of t.body){if(!(e instanceof R)||!e.isKind(r.Note))continue;let t=lw(e);if(t)return{kind:pm.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof V?t.args.find(e=>e instanceof U):void 0);if(n)return uw(n)}function cw(e){let t=e.body;if(!(!t||t instanceof V)&&t.blockCloseBrace)return t.blockCloseBrace.start}function lw(e){let t=e.body;if(t instanceof V)return t.callee??void 0;if(t instanceof H&&t.body[0]instanceof V)return t.body[0].callee??void 0}function uw(e){let t=w(e).getValue()[i.Note];if(!t?.length)return;let n=t[0];if(!n.value)return;let r=e.elementList,a=r.indexOf(n),o=n.start,s=n.end;return r.length===1?(o=e.start,s=e.end):a<r.length-1?s=r[a+1].start:o=r[a-1].end,{kind:pm.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function dw(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...pw(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:lC(n,r,!0),edits:r}}function fw(e,t){return`Dep [color: ${t}] {\n ${xC(e.upstream)} -> ${xC(e.downstream)}\n}`}function pw(e,t,n,r){let i=gC(e,t,r.edge);switch(r.operation){case`create`:return hw(n,r,i);case`update`:return i?.kind===`block`?mw(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?mw({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function mw(e,t,n){let r=[];if(e.color!==void 0){let a=Og(t,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=aw(t);e&&r.push(e)}else if(e.note!==void 0){let n=iw(t,e.note)??ow(t,e.note);n&&r.push(n)}return r}function hw(e,t,n){if(n?.kind===`block`)return mw(t,n.declaration,e);let r=fw(t.edge,t.color??``),i={start:e.length,end:e.length,newText:`
|
|
44
44
|
|
|
45
45
|
`+r+`
|
|
46
|
-
`};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var
|
|
46
|
+
`};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var gw=Symbol(`COMPUTING`),_w=class{constructor(e){this.layout=e,this.nodeIdGenerator=new fm,this.symbolIdGenerator=new Wp,this.symbolFactory=new to(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery($S),this.parseProject=this.globalQuery(eC),this.validateNode=this.localQuery(xy),this.validateFile=this.localQuery(LS),this.nodeFullname=this.localQuery(Cy),this.nodeAlias=this.localQuery(wy),this.nodeSettings=this.localQuery(Sy),this.canonicalName=this.globalQuery(vS),this.bindNode=this.globalQuery(Dv),this.bindFile=this.globalQuery(NS),this.bindProject=this.globalQuery(PS),this.interpretSymbol=this.globalQuery(kv),this.interpretMetadata=this.globalQuery(Av),this.interpretFile=this.globalQuery(FS),this.interpretProject=this.globalQuery(IS),this.nodeSymbol=this.globalQuery(wv),this.nodeMetadata=this.globalQuery(Ov),this.symbolMembers=this.globalQuery(Tv),this.symbolMembersLookupMap=this.globalQuery(tC),this.lookupMembers=this.globalQuery(nC),this.nodeReferee=this.globalQuery(Ev),this.resolutionIndex=this.globalQuery(iC),this.symbolReferences=this.globalQuery(oC),this.symbolParent=this.globalQuery(aC),this.symbolMetadata=this.globalQuery(sC),this.symbolAliases=this.globalQuery(rC),this.symbolUses=this.globalQuery(cC),this.fileDependencies=this.localQuery(xS),this.reachableFiles=this.globalQuery(CS),this.usableMembers=this.globalQuery(u_),this.nodeAtPosition=this.localQuery(MS),this.renameTable=kC.bind(this),this.updateElementSetting=FC.bind(this),this.updateElementSettingEdit=PC.bind(this),this.findMetadataBlock=HC.bind(this),this.updateElementMetadata=KC.bind(this),this.updateElementMetadataEdit=GC.bind(this),this.syncDiagramView=$C.bind(this),this.syncDep=dw.bind(this),this.token={invalidStream:this.localQuery(jS),flatStream:this.localQuery(AS)},this.parse={source:e=>this.getSource(e)||``,ast:(e=Oo)=>wS.call(this,e),errors:(e=Oo)=>TS.call(this,e),warnings:(e=Oo)=>ES.call(this,e),tokens:(e=Oo)=>DS.call(this,e),rawDb:(e=Oo)=>OS.call(this,e),publicSymbolTable:(e=Oo)=>kS.call(this,e)},this.container={stack:this.localQuery(pS),token:this.localQuery(mS),element:this.localQuery(hS),scope:this.localQuery(gS),scopeKind:this.localQuery(_S)}}getSource(e){return this.layout.getSource(e)}cleanStaleLocalCache(e){let t=this.layout.getSource(e),n=e.absolute,r=this.sourceSnapshot.get(n);r===void 0?this.sourceSnapshot.set(n,t):r!==t&&(this.localCache.delete(e.intern()),this.globalCache.clear(),this.sourceSnapshot.set(n,t))}cleanStaleGlobalCache(){let e=this.layout.getEntrypoints(),t=!1;this.entrypointsSnapshot!==void 0&&(this.entrypointsSnapshot.length!==e.length||this.entrypointsSnapshot.some((t,n)=>t.absolute!==e[n].absolute))&&(t=!0),this.entrypointsSnapshot=e;for(let t of SS(this,e))this.cleanStaleLocalCache(t);t&&this.globalCache.clear()}globalQuery(e){let t=Symbol();return((...n)=>{let r=!this.globallyQuerying;r&&(this.globallyQuerying=!0,this.cleanStaleGlobalCache());try{let r=this.globalCache.get(t);r||(r=new Map,this.globalCache.set(t,r));let i=n.length===0?``:n.length===1?ph(n[0]):n.map(e=>ph(e)).join(`\0`),a=r.get(i);if(a){if(a===gw)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,gw);try{let t=e.apply(this,n);return r.set(i,t),t}catch(e){throw r.delete(i),e}}finally{r&&(this.globallyQuerying=!1)}})}localQuery(e){let t=Symbol();return((...n)=>{let[r]=n,i=r instanceof I?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?ph(n[0]):n.map(e=>ph(e)).join(`\0`),s=this.localCache.get(a);s||(s=new Map,this.localCache.set(a,s));let c=s.get(t);if(c||(c=new Map,s.set(t,c)),c.has(o)){let t=c.get(o);if(t===gw)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,gw);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}initMonacoServices(e){let{triggerCharacters:t=[],fileListDepth:n}=e?.autocompletion??{};return{definitionProvider:new Pb(this),referenceProvider:new Ib(this),autocompletionProvider:new jx(this,{triggerCharacters:t,fileListDepth:n}),diagnosticsProvider:new Fb(this),codeActionProvider:new Nb(this)}}},vw=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}resolveFileSpecifier(e,t){if(!So.isRelative(t))return;let n=So.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:So.from(n.absolute+`.dbml`)}getFileSpecifierInfo(e,t){let n=t.relativeTo(e.dirname);return n.endsWith(`.dbml`)&&(n=n.slice(0,-5)),{specifier:n}}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(So.from)}getEntrypoints(){return[...this.files.keys()].map(So.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=km,exports.AttributeNode=z,exports.BlockExpressionNode=H,exports.CARDINALITY_MANY=uf,exports.CARDINALITY_MAYBE=cf,exports.CARDINALITY_ONE=sf,exports.CARDINALITY_SOME=lf,exports.CallExpressionNode=W,exports.CommaExpressionNode=Sm,exports.CompileError=C,exports.CompileErrorCode=S,exports.CompileInfo=Tf,exports.CompileWarning=wf,exports.Compiler=_w,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=Nb,exports.DBMLCompletionItemProvider=jx,exports.DBMLDefinitionProvider=Pb,exports.DBMLDiagnosticsProvider=Fb,exports.DBMLReferencesProvider=Ib,exports.DEFAULT_ENTRY=Oo,exports.ElementDeclarationNode=R,exports.ElementKind=r,exports.EmptyNode=Om,exports.FALSY_VALUES=Ep,exports.Filepath=So,exports.FunctionApplicationNode=V,exports.FunctionExpressionNode=bm,exports.GroupExpressionNode=Cm,exports.IdentifierStreamNode=_m,exports.InfixExpressionNode=vm,exports.ListExpressionNode=U,exports.LiteralNode=wm,exports.MarkerSeverity=Ab,exports.MemoryProjectLayout=vw,exports.MetadataKind=Wm,exports.PostfixExpressionNode=ym,exports.PrefixExpressionNode=B,exports.PrimaryExpressionNode=Dm,exports.ProgramNode=L,exports.ScopeKind=Q,exports.SymbolKind=P,exports.SyntaxNode=I,exports.SyntaxNodeIdGenerator=fm,exports.SyntaxNodeKind=pm,exports.SyntaxToken=Ha,exports.SyntaxTokenKind=_,exports.TRUTHY_VALUES=Tp,exports.TupleExpressionNode=xm,exports.UNHANDLED=t,exports.Uri=yb,exports.UseDeclarationNode=mm,exports.UseSpecifierListNode=gm,exports.UseSpecifierNode=hm,exports.VariableNode=Em,exports.WildcardNode=Tm,exports.addDoubleQuoteIfNeeded=z_,exports.applyTextEdits=lC,exports.dbmlLanguageConfig=dS,exports.dbmlMonarchTokensProvider=fS,exports.escapeString=H_,exports.extractNumericLiteral=hp,exports.extractSignedNumber=Sp,exports.findDiagramViewBlocks=JC,exports.formatTypedValue=U_,exports.getMultiplicities=pf,exports.getRecordValueType=Go,exports.getRelationshipOp=yf,exports.isBinaryType=Ho,exports.isBooleanType=Bo,exports.isDateTimeType=Uo,exports.isEmptyStringLiteral=bp,exports.isEndpointManySide=hf,exports.isEndpointOneSide=mf,exports.isEndpointOptional=gf,exports.isEndpointRequired=_f,exports.isFloatType=Ro,exports.isFunctionExpression=xp,exports.isIntegerType=Lo,exports.isNullish=yp,exports.isNumericType=zo,exports.isOp=Ba,exports.isOpToken=Va,exports.isSerialType=Wo,exports.isStringType=Vo,exports.isTriviaToken=za,exports.isValidIdentifier=R_,exports.makeCardinalityOptional=bf,exports.makeCardinalityRequired=xf,exports.makeRelationshipRequired=vf,exports.normalizeQualifiedName=B_,exports.normalizeTypeName=Io,exports.parseCardinality=of,exports.splitQualifiedIdentifier=W_,exports.syncElementMetadata=qC,exports.tryExtractBoolean=Dp,exports.tryExtractDateTime=Np,exports.tryExtractEnum=Op,exports.tryExtractInteger=wp,exports.tryExtractNumeric=Cp,exports.tryExtractString=kp,exports.unescapeString=V_,exports.validateForeignKeys=xg,exports.validatePrimaryKey=dg,exports.validateUnique=_g;
|
package/dist/dbml-parse.mjs
CHANGED
|
@@ -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
|
|
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}\`` :
|
|
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);
|
|
@@ -16727,13 +16727,15 @@ function OC(e, t, n, r, i) {
|
|
|
16727
16727
|
function kC(e, n, r) {
|
|
16728
16728
|
let i = vC(n), a = vC(r), o = i.schema, s = i.table, c = a.schema, l = a.table, u = yC(this, e, o, s);
|
|
16729
16729
|
if (!u || u instanceof lm || TC(this, e, o, s, c, l)) return /* @__PURE__ */ new Map();
|
|
16730
|
-
if (u instanceof um && u.useSpecifierDeclaration instanceof hm) {
|
|
16730
|
+
if (u instanceof um && u.useSpecifierDeclaration instanceof hm && u.useSpecifierDeclaration.alias) {
|
|
16731
16731
|
let n = u.useSpecifierDeclaration;
|
|
16732
|
-
if (n.
|
|
16733
|
-
if (this.nodeAlias(n).getFiltered(t) === s) return AC(this, e, n, u, c, l);
|
|
16734
|
-
} else return jC(this, e, n, u, c, l);
|
|
16732
|
+
if (this.nodeAlias(n).getFiltered(t) === s) return AC(this, e, n, u, c, l);
|
|
16735
16733
|
}
|
|
16736
|
-
|
|
16734
|
+
if (u instanceof um) {
|
|
16735
|
+
if (u.useSpecifierDeclaration instanceof hm && !u.useSpecifierDeclaration.alias) return jC(this, e, u.useSpecifierDeclaration, u, s, c, l);
|
|
16736
|
+
if (u.useSpecifierDeclaration instanceof Tm) return MC(this, e, u, s, c, l);
|
|
16737
|
+
}
|
|
16738
|
+
return NC(this, u, o, s, c, l);
|
|
16737
16739
|
}
|
|
16738
16740
|
function AC(e, t, n, r, i, a) {
|
|
16739
16741
|
let o = e.getSource(t) ?? "";
|
|
@@ -16752,22 +16754,39 @@ function AC(e, t, n, r, i, a) {
|
|
|
16752
16754
|
});
|
|
16753
16755
|
return /* @__PURE__ */ new Map([[t.absolute, lC(o, c)]]);
|
|
16754
16756
|
}
|
|
16755
|
-
function jC(e, t, n, r, i, a) {
|
|
16756
|
-
let
|
|
16757
|
-
|
|
16758
|
-
|
|
16759
|
-
|
|
16760
|
-
end: l,
|
|
16757
|
+
function jC(e, t, n, r, i, a, o) {
|
|
16758
|
+
let s = e.getSource(t) ?? "", c = wC(a, o, n.name ? s.substring(n.name.start, n.name.end).includes("\"") : !1), l = [];
|
|
16759
|
+
n.name && l.push({
|
|
16760
|
+
start: n.name.end,
|
|
16761
|
+
end: n.name.end,
|
|
16761
16762
|
newText: ` as ${c.formattedTable}`
|
|
16762
|
-
}
|
|
16763
|
-
|
|
16763
|
+
});
|
|
16764
|
+
let u = e.symbolReferences(r);
|
|
16765
|
+
for (let e of u) e.filepath.absolute !== t.absolute || n.name && e.start === n.name.start && e.end === n.name.end || bC(s.substring(e.start, e.end)) !== i || l.push({
|
|
16764
16766
|
start: e.start,
|
|
16765
16767
|
end: e.end,
|
|
16766
16768
|
newText: c.formattedTable
|
|
16767
|
-
})
|
|
16768
|
-
return /* @__PURE__ */ new Map([[t.absolute, lC(
|
|
16769
|
+
});
|
|
16770
|
+
return /* @__PURE__ */ new Map([[t.absolute, lC(s, l)]]);
|
|
16769
16771
|
}
|
|
16770
16772
|
function MC(e, t, n, r, i, a) {
|
|
16773
|
+
let o = n.useSpecifierDeclaration.parentOfKind(mm);
|
|
16774
|
+
if (!o) return /* @__PURE__ */ new Map();
|
|
16775
|
+
let s = e.getSource(t) ?? "", c = wC(i, a, !1), l = n.kind.toLowerCase(), u = o.importPath ? s.substring(o.importPath.start, o.importPath.end) : "''", d = `${o.isReuse ? "reuse" : "use"} { ${l} ${r} as ${c.formattedTable} } from ${u}`, f = [];
|
|
16776
|
+
f.push({
|
|
16777
|
+
start: o.end,
|
|
16778
|
+
end: o.end,
|
|
16779
|
+
newText: `\n${d}`
|
|
16780
|
+
});
|
|
16781
|
+
let p = e.symbolReferences(n);
|
|
16782
|
+
for (let e of p) e.filepath.absolute === t.absolute && bC(s.substring(e.start, e.end)) === r && f.push({
|
|
16783
|
+
start: e.start,
|
|
16784
|
+
end: e.end,
|
|
16785
|
+
newText: c.formattedTable
|
|
16786
|
+
});
|
|
16787
|
+
return /* @__PURE__ */ new Map([[t.absolute, lC(s, f)]]);
|
|
16788
|
+
}
|
|
16789
|
+
function NC(e, t, n, r, i, a) {
|
|
16771
16790
|
let o = t.originalSymbol, s = o.declaration;
|
|
16772
16791
|
if (!s || !(s instanceof R)) return /* @__PURE__ */ new Map();
|
|
16773
16792
|
let c = s.filepath;
|
|
@@ -16799,19 +16818,19 @@ function MC(e, t, n, r, i, a) {
|
|
|
16799
16818
|
}
|
|
16800
16819
|
//#endregion
|
|
16801
16820
|
//#region src/compiler/queries/transform/updateElementSetting.ts
|
|
16802
|
-
function
|
|
16803
|
-
if (t.kind === "dep") return
|
|
16804
|
-
if (t.kind === "ref") return
|
|
16805
|
-
let i =
|
|
16821
|
+
function PC(e, t, n, r) {
|
|
16822
|
+
if (t.kind === "dep") return LC(this, e, t, n, r);
|
|
16823
|
+
if (t.kind === "ref") return RC(this, e, t, n, r);
|
|
16824
|
+
let i = IC(this, e, t);
|
|
16806
16825
|
if (!i) return [];
|
|
16807
16826
|
let a = Og(i, n, r, this.getSource(e) ?? "");
|
|
16808
16827
|
return a ? [a] : [];
|
|
16809
16828
|
}
|
|
16810
|
-
function
|
|
16829
|
+
function FC(e, t, n, r) {
|
|
16811
16830
|
let i = this.getSource(e) ?? "", a = this.updateElementSettingEdit(e, t, n, r);
|
|
16812
16831
|
return a.length === 0 ? i : lC(i, a);
|
|
16813
16832
|
}
|
|
16814
|
-
function
|
|
16833
|
+
function IC(e, t, n) {
|
|
16815
16834
|
let r = ("schema" in n ? n.schema : void 0) ?? "public";
|
|
16816
16835
|
switch (n.kind) {
|
|
16817
16836
|
case P.Column: {
|
|
@@ -16826,7 +16845,7 @@ function FC(e, t, n) {
|
|
|
16826
16845
|
default: return;
|
|
16827
16846
|
}
|
|
16828
16847
|
}
|
|
16829
|
-
function
|
|
16848
|
+
function LC(e, t, n, r, i) {
|
|
16830
16849
|
let a = e.getSource(t) ?? "", o = gC(e, t, n);
|
|
16831
16850
|
if (!o) return [];
|
|
16832
16851
|
if (o.kind === "inline") {
|
|
@@ -16852,7 +16871,7 @@ function IC(e, t, n, r, i) {
|
|
|
16852
16871
|
let l = Og(s, r, i, a);
|
|
16853
16872
|
return l ? [l] : [];
|
|
16854
16873
|
}
|
|
16855
|
-
function
|
|
16874
|
+
function RC(e, t, n, r, i) {
|
|
16856
16875
|
let a = e.getSource(t) ?? "", o = uC(e, t, n);
|
|
16857
16876
|
if (!o) return [];
|
|
16858
16877
|
if (o.kind === "inline") {
|
|
@@ -16873,7 +16892,7 @@ function LC(e, t, n, r, i) {
|
|
|
16873
16892
|
}
|
|
16874
16893
|
//#endregion
|
|
16875
16894
|
//#region src/compiler/queries/transform/updateElementMetadata.ts
|
|
16876
|
-
function
|
|
16895
|
+
function zC(e) {
|
|
16877
16896
|
switch (e) {
|
|
16878
16897
|
case P.Table: return F.Table;
|
|
16879
16898
|
case P.Column: return F.Column;
|
|
@@ -16882,7 +16901,7 @@ function RC(e) {
|
|
|
16882
16901
|
default: return;
|
|
16883
16902
|
}
|
|
16884
16903
|
}
|
|
16885
|
-
function
|
|
16904
|
+
function BC(e) {
|
|
16886
16905
|
let t = _C("schema" in e ? e.schema : void 0);
|
|
16887
16906
|
switch (e.kind) {
|
|
16888
16907
|
case P.Table: {
|
|
@@ -16901,25 +16920,25 @@ function zC(e) {
|
|
|
16901
16920
|
default: return;
|
|
16902
16921
|
}
|
|
16903
16922
|
}
|
|
16904
|
-
function
|
|
16923
|
+
function VC(e, t, n) {
|
|
16905
16924
|
if (b_(e) !== t) return !1;
|
|
16906
16925
|
let r = A(e.name);
|
|
16907
16926
|
return r ? r.join(".").toLowerCase() === n.toLowerCase() : !1;
|
|
16908
16927
|
}
|
|
16909
|
-
function
|
|
16910
|
-
let n =
|
|
16928
|
+
function HC(e, t) {
|
|
16929
|
+
let n = zC(t.kind);
|
|
16911
16930
|
if (!n) return;
|
|
16912
|
-
let i =
|
|
16931
|
+
let i = BC(t);
|
|
16913
16932
|
if (!i) return;
|
|
16914
16933
|
let a = this.parseFile(e).getValue().ast;
|
|
16915
16934
|
if (a) {
|
|
16916
|
-
for (let e of a.body ?? []) if (e instanceof R && O(e, r.Metadata) &&
|
|
16935
|
+
for (let e of a.body ?? []) if (e instanceof R && O(e, r.Metadata) && VC(e, n, i)) return e;
|
|
16917
16936
|
}
|
|
16918
16937
|
}
|
|
16919
|
-
function
|
|
16938
|
+
function UC(e, t, n, r) {
|
|
16920
16939
|
return `Metadata ${e} ${t} {\n ${n}: ${r}\n}`;
|
|
16921
16940
|
}
|
|
16922
|
-
function
|
|
16941
|
+
function WC(e) {
|
|
16923
16942
|
switch (e) {
|
|
16924
16943
|
case F.Table: return "Table";
|
|
16925
16944
|
case F.Column: return "Column";
|
|
@@ -16928,15 +16947,15 @@ function UC(e) {
|
|
|
16928
16947
|
default: return e;
|
|
16929
16948
|
}
|
|
16930
16949
|
}
|
|
16931
|
-
function
|
|
16932
|
-
let i =
|
|
16950
|
+
function GC(e, t, n, r) {
|
|
16951
|
+
let i = zC(t.kind);
|
|
16933
16952
|
if (!i) return [];
|
|
16934
|
-
let a =
|
|
16953
|
+
let a = BC(t);
|
|
16935
16954
|
if (!a) return [];
|
|
16936
|
-
let o = this.getSource(e) ?? "", s =
|
|
16955
|
+
let o = this.getSource(e) ?? "", s = HC.call(this, e, t);
|
|
16937
16956
|
if (!s) {
|
|
16938
16957
|
if (r === null) return [];
|
|
16939
|
-
let e =
|
|
16958
|
+
let e = UC(WC(i), a, n, U_(r));
|
|
16940
16959
|
return [{
|
|
16941
16960
|
start: o.length,
|
|
16942
16961
|
end: o.length,
|
|
@@ -16977,12 +16996,12 @@ function WC(e, t, n, r) {
|
|
|
16977
16996
|
newText: ` ${u}\n`
|
|
16978
16997
|
}];
|
|
16979
16998
|
}
|
|
16980
|
-
function
|
|
16981
|
-
let i = this.getSource(e) ?? "", a =
|
|
16999
|
+
function KC(e, t, n, r) {
|
|
17000
|
+
let i = this.getSource(e) ?? "", a = GC.call(this, e, t, n, r);
|
|
16982
17001
|
return a.length === 0 ? i : lC(i, a, !0);
|
|
16983
17002
|
}
|
|
16984
|
-
function
|
|
16985
|
-
let o =
|
|
17003
|
+
function qC(e, t, n, r, i, a) {
|
|
17004
|
+
let o = GC.call(t, n, r, i, a);
|
|
16986
17005
|
return o.length === 0 ? {
|
|
16987
17006
|
newDbml: e,
|
|
16988
17007
|
edits: []
|
|
@@ -16993,7 +17012,7 @@ function KC(e, t, n, r, i, a) {
|
|
|
16993
17012
|
}
|
|
16994
17013
|
//#endregion
|
|
16995
17014
|
//#region src/compiler/queries/transform/syncDiagramView.ts
|
|
16996
|
-
function
|
|
17015
|
+
function JC(e) {
|
|
16997
17016
|
let t = [], n = new RS(e, Oo).lex();
|
|
16998
17017
|
if (n.getErrors().length > 0) return t;
|
|
16999
17018
|
let i = new HS(e, n.getValue(), new fm(), Oo).parse();
|
|
@@ -17009,36 +17028,36 @@ function qC(e) {
|
|
|
17009
17028
|
}
|
|
17010
17029
|
return t;
|
|
17011
17030
|
}
|
|
17012
|
-
function
|
|
17031
|
+
function YC(e, t, n) {
|
|
17013
17032
|
e.push(` ${t} {`), n.forEach((t) => e.push(` ${t}`)), e.push(" }");
|
|
17014
17033
|
}
|
|
17015
|
-
function
|
|
17034
|
+
function XC(e, t) {
|
|
17016
17035
|
e.push(` ${t} { * }`);
|
|
17017
17036
|
}
|
|
17018
|
-
function
|
|
17037
|
+
function ZC(e) {
|
|
17019
17038
|
return e == null ? "null" : e.length === 0 ? "empty" : "items";
|
|
17020
17039
|
}
|
|
17021
|
-
function
|
|
17040
|
+
function QC(e, t) {
|
|
17022
17041
|
let n = `DiagramView ${z_(e)} {`, r = (e) => z_(e.name), i = t?.tables?.map((e) => {
|
|
17023
17042
|
let t = z_(e.name);
|
|
17024
17043
|
return e.schemaName === "public" ? t : `${z_(e.schemaName)}.${t}`;
|
|
17025
17044
|
}) ?? [], a = t?.tableGroups?.map(r) ?? [], o = t?.schemas?.map(r) ?? [], s = t?.stickyNotes?.map(r) ?? [];
|
|
17026
17045
|
if (!t) return `${n}\n}`;
|
|
17027
17046
|
let c = {
|
|
17028
|
-
tables:
|
|
17029
|
-
tableGroups:
|
|
17030
|
-
schemas:
|
|
17031
|
-
stickyNotes:
|
|
17047
|
+
tables: ZC(t.tables),
|
|
17048
|
+
tableGroups: ZC(t.tableGroups),
|
|
17049
|
+
schemas: ZC(t.schemas),
|
|
17050
|
+
stickyNotes: ZC(t.stickyNotes)
|
|
17032
17051
|
};
|
|
17033
17052
|
if (Object.values(c).every((e) => e === "null")) return `${n}\n}`;
|
|
17034
17053
|
if (Object.values(c).every((e) => e === "empty")) return `${n}\n *\n}`;
|
|
17035
17054
|
let l = c.tables === "items" || c.tableGroups === "items" || c.schemas === "items", u = c.tables === "empty" && c.tableGroups === "empty" && c.schemas === "empty", d = [n];
|
|
17036
|
-
return l ? (c.tables === "items" &&
|
|
17055
|
+
return l ? (c.tables === "items" && YC(d, "Tables", i), c.tableGroups === "items" && YC(d, "TableGroups", a), c.schemas === "items" && YC(d, "Schemas", o)) : u && XC(d, "Tables"), c.stickyNotes === "items" ? YC(d, "Notes", s) : c.stickyNotes === "empty" && XC(d, "Notes"), d.push("}"), d.join("\n");
|
|
17037
17056
|
}
|
|
17038
|
-
function
|
|
17039
|
-
let r = this.getSource(e) ?? "", i = n ??
|
|
17057
|
+
function $C(e, t, n) {
|
|
17058
|
+
let r = this.getSource(e) ?? "", i = n ?? JC(r), a = [];
|
|
17040
17059
|
for (let e of t) {
|
|
17041
|
-
let t =
|
|
17060
|
+
let t = ew(r, e, i);
|
|
17042
17061
|
a.push(...t);
|
|
17043
17062
|
}
|
|
17044
17063
|
return a.sort((e, t) => t.start - e.start), {
|
|
@@ -17046,29 +17065,29 @@ function QC(e, t, n) {
|
|
|
17046
17065
|
edits: a
|
|
17047
17066
|
};
|
|
17048
17067
|
}
|
|
17049
|
-
function
|
|
17068
|
+
function ew(e, t, n) {
|
|
17050
17069
|
switch (t.operation) {
|
|
17051
|
-
case "create": return
|
|
17052
|
-
case "update": return
|
|
17053
|
-
case "delete": return
|
|
17070
|
+
case "create": return tw(e, t, n);
|
|
17071
|
+
case "update": return nw(e, t, n);
|
|
17072
|
+
case "delete": return rw(e, t, n);
|
|
17054
17073
|
default: return [];
|
|
17055
17074
|
}
|
|
17056
17075
|
}
|
|
17057
|
-
function
|
|
17058
|
-
if (n.find((e) => e.name === t.name)) return
|
|
17059
|
-
let r = "\n\n" +
|
|
17076
|
+
function tw(e, t, n) {
|
|
17077
|
+
if (n.find((e) => e.name === t.name)) return nw(e, t, n);
|
|
17078
|
+
let r = "\n\n" + QC(t.name, t.visibleEntities) + "\n";
|
|
17060
17079
|
return [{
|
|
17061
17080
|
start: e.length,
|
|
17062
17081
|
end: e.length,
|
|
17063
17082
|
newText: r
|
|
17064
17083
|
}];
|
|
17065
17084
|
}
|
|
17066
|
-
function
|
|
17085
|
+
function nw(e, t, n) {
|
|
17067
17086
|
let r = n.find((e) => e.name === t.name);
|
|
17068
17087
|
if (!r) return [];
|
|
17069
17088
|
let i = [];
|
|
17070
17089
|
if (t.newName || t.visibleEntities) {
|
|
17071
|
-
let e =
|
|
17090
|
+
let e = QC(t.newName || t.name, t.visibleEntities);
|
|
17072
17091
|
i.push({
|
|
17073
17092
|
start: r.startIndex,
|
|
17074
17093
|
end: r.endIndex,
|
|
@@ -17077,7 +17096,7 @@ function tw(e, t, n) {
|
|
|
17077
17096
|
}
|
|
17078
17097
|
return i;
|
|
17079
17098
|
}
|
|
17080
|
-
function
|
|
17099
|
+
function rw(e, t, n) {
|
|
17081
17100
|
let r = n.find((e) => e.name === t.name);
|
|
17082
17101
|
if (!r) return [];
|
|
17083
17102
|
let i = r.startIndex, a = r.endIndex;
|
|
@@ -17097,25 +17116,25 @@ function nw(e, t, n) {
|
|
|
17097
17116
|
}
|
|
17098
17117
|
//#endregion
|
|
17099
17118
|
//#region src/core/utils/note.ts
|
|
17100
|
-
function
|
|
17101
|
-
let n =
|
|
17119
|
+
function iw(e, t) {
|
|
17120
|
+
let n = sw(e);
|
|
17102
17121
|
if (n) return {
|
|
17103
17122
|
start: n.noteValueStart,
|
|
17104
17123
|
end: n.noteValueEnd,
|
|
17105
17124
|
newText: q_(t)
|
|
17106
17125
|
};
|
|
17107
17126
|
}
|
|
17108
|
-
function
|
|
17109
|
-
let t =
|
|
17127
|
+
function aw(e) {
|
|
17128
|
+
let t = sw(e);
|
|
17110
17129
|
if (t) return {
|
|
17111
17130
|
start: t.fullNoteStart,
|
|
17112
17131
|
end: t.fullNoteEnd,
|
|
17113
17132
|
newText: ""
|
|
17114
17133
|
};
|
|
17115
17134
|
}
|
|
17116
|
-
function
|
|
17117
|
-
if (
|
|
17118
|
-
let n =
|
|
17135
|
+
function ow(e, t) {
|
|
17136
|
+
if (sw(e) || !(e instanceof R)) return;
|
|
17137
|
+
let n = cw(e);
|
|
17119
17138
|
if (n !== void 0) return {
|
|
17120
17139
|
start: n,
|
|
17121
17140
|
end: n,
|
|
@@ -17139,12 +17158,12 @@ function aw(e, t) {
|
|
|
17139
17158
|
};
|
|
17140
17159
|
}
|
|
17141
17160
|
}
|
|
17142
|
-
function
|
|
17161
|
+
function sw(e) {
|
|
17143
17162
|
if (!(e instanceof R)) return;
|
|
17144
17163
|
let t = e.body;
|
|
17145
17164
|
if (t && !(t instanceof V)) for (let e of t.body) {
|
|
17146
17165
|
if (!(e instanceof R) || !e.isKind(r.Note)) continue;
|
|
17147
|
-
let t =
|
|
17166
|
+
let t = lw(e);
|
|
17148
17167
|
if (t) return {
|
|
17149
17168
|
kind: pm.ELEMENT_DECLARATION,
|
|
17150
17169
|
noteValueStart: t.start,
|
|
@@ -17154,18 +17173,18 @@ function ow(e) {
|
|
|
17154
17173
|
};
|
|
17155
17174
|
}
|
|
17156
17175
|
let n = e.attributeList ?? (t instanceof V ? t.args.find((e) => e instanceof U) : void 0);
|
|
17157
|
-
if (n) return
|
|
17176
|
+
if (n) return uw(n);
|
|
17158
17177
|
}
|
|
17159
|
-
function
|
|
17178
|
+
function cw(e) {
|
|
17160
17179
|
let t = e.body;
|
|
17161
17180
|
if (!(!t || t instanceof V) && t.blockCloseBrace) return t.blockCloseBrace.start;
|
|
17162
17181
|
}
|
|
17163
|
-
function
|
|
17182
|
+
function lw(e) {
|
|
17164
17183
|
let t = e.body;
|
|
17165
17184
|
if (t instanceof V) return t.callee ?? void 0;
|
|
17166
17185
|
if (t instanceof H && t.body[0] instanceof V) return t.body[0].callee ?? void 0;
|
|
17167
17186
|
}
|
|
17168
|
-
function
|
|
17187
|
+
function uw(e) {
|
|
17169
17188
|
let t = w(e).getValue()[i.Note];
|
|
17170
17189
|
if (!t?.length) return;
|
|
17171
17190
|
let n = t[0];
|
|
@@ -17181,23 +17200,23 @@ function lw(e) {
|
|
|
17181
17200
|
}
|
|
17182
17201
|
//#endregion
|
|
17183
17202
|
//#region src/compiler/queries/transform/syncDep.ts
|
|
17184
|
-
function
|
|
17203
|
+
function dw(e, t) {
|
|
17185
17204
|
let n = this.getSource(e) ?? "", r = [];
|
|
17186
|
-
for (let i of t) r.push(...
|
|
17205
|
+
for (let i of t) r.push(...pw(this, e, n, i));
|
|
17187
17206
|
return r.sort((e, t) => t.start - e.start), {
|
|
17188
17207
|
newDbml: lC(n, r, !0),
|
|
17189
17208
|
edits: r
|
|
17190
17209
|
};
|
|
17191
17210
|
}
|
|
17192
|
-
function
|
|
17211
|
+
function fw(e, t) {
|
|
17193
17212
|
return `Dep [color: ${t}] {\n ${xC(e.upstream)} -> ${xC(e.downstream)}\n}`;
|
|
17194
17213
|
}
|
|
17195
|
-
function
|
|
17214
|
+
function pw(e, t, n, r) {
|
|
17196
17215
|
let i = gC(e, t, r.edge);
|
|
17197
17216
|
switch (r.operation) {
|
|
17198
|
-
case "create": return
|
|
17199
|
-
case "update": return i?.kind === "block" ?
|
|
17200
|
-
case "remove": return i?.kind === "block" ?
|
|
17217
|
+
case "create": return hw(n, r, i);
|
|
17218
|
+
case "update": return i?.kind === "block" ? mw(r, i.declaration, n) : [];
|
|
17219
|
+
case "remove": return i?.kind === "block" ? mw({
|
|
17201
17220
|
...r,
|
|
17202
17221
|
color: void 0,
|
|
17203
17222
|
note: void 0
|
|
@@ -17205,24 +17224,24 @@ function fw(e, t, n, r) {
|
|
|
17205
17224
|
default: return [];
|
|
17206
17225
|
}
|
|
17207
17226
|
}
|
|
17208
|
-
function
|
|
17227
|
+
function mw(e, t, n) {
|
|
17209
17228
|
let r = [];
|
|
17210
17229
|
if (e.color !== void 0) {
|
|
17211
17230
|
let a = Og(t, i.Color, e.color, n);
|
|
17212
17231
|
a && r.push(a);
|
|
17213
17232
|
}
|
|
17214
17233
|
if (e.note === null) {
|
|
17215
|
-
let e =
|
|
17234
|
+
let e = aw(t);
|
|
17216
17235
|
e && r.push(e);
|
|
17217
17236
|
} else if (e.note !== void 0) {
|
|
17218
|
-
let n =
|
|
17237
|
+
let n = iw(t, e.note) ?? ow(t, e.note);
|
|
17219
17238
|
n && r.push(n);
|
|
17220
17239
|
}
|
|
17221
17240
|
return r;
|
|
17222
17241
|
}
|
|
17223
|
-
function
|
|
17224
|
-
if (n?.kind === "block") return
|
|
17225
|
-
let r =
|
|
17242
|
+
function hw(e, t, n) {
|
|
17243
|
+
if (n?.kind === "block") return mw(t, n.declaration, e);
|
|
17244
|
+
let r = fw(t.edge, t.color ?? ""), i = {
|
|
17226
17245
|
start: e.length,
|
|
17227
17246
|
end: e.length,
|
|
17228
17247
|
newText: "\n\n" + r + "\n"
|
|
@@ -17235,9 +17254,9 @@ function mw(e, t, n) {
|
|
|
17235
17254
|
}
|
|
17236
17255
|
//#endregion
|
|
17237
17256
|
//#region src/compiler/index.ts
|
|
17238
|
-
var
|
|
17257
|
+
var gw = Symbol("COMPUTING"), _w = class {
|
|
17239
17258
|
constructor(e) {
|
|
17240
|
-
this.layout = e, this.nodeIdGenerator = new fm(), this.symbolIdGenerator = new Wp(), this.symbolFactory = new to(this.symbolIdGenerator), this.sourceSnapshot = /* @__PURE__ */ new Map(), this.globalCache = /* @__PURE__ */ new Map(), this.globallyQuerying = !1, this.localCache = /* @__PURE__ */ new Map(), this.parseFile = this.localQuery($S), this.parseProject = this.globalQuery(eC), this.validateNode = this.localQuery(xy), this.validateFile = this.localQuery(LS), this.nodeFullname = this.localQuery(Cy), this.nodeAlias = this.localQuery(wy), this.nodeSettings = this.localQuery(Sy), this.canonicalName = this.globalQuery(vS), this.bindNode = this.globalQuery(Dv), this.bindFile = this.globalQuery(NS), this.bindProject = this.globalQuery(PS), this.interpretSymbol = this.globalQuery(kv), this.interpretMetadata = this.globalQuery(Av), this.interpretFile = this.globalQuery(FS), this.interpretProject = this.globalQuery(IS), this.nodeSymbol = this.globalQuery(wv), this.nodeMetadata = this.globalQuery(Ov), this.symbolMembers = this.globalQuery(Tv), this.symbolMembersLookupMap = this.globalQuery(tC), this.lookupMembers = this.globalQuery(nC), this.nodeReferee = this.globalQuery(Ev), this.resolutionIndex = this.globalQuery(iC), this.symbolReferences = this.globalQuery(oC), this.symbolParent = this.globalQuery(aC), this.symbolMetadata = this.globalQuery(sC), this.symbolAliases = this.globalQuery(rC), this.symbolUses = this.globalQuery(cC), this.fileDependencies = this.localQuery(xS), this.reachableFiles = this.globalQuery(CS), this.usableMembers = this.globalQuery(u_), this.nodeAtPosition = this.localQuery(MS), this.renameTable = kC.bind(this), this.updateElementSetting =
|
|
17259
|
+
this.layout = e, this.nodeIdGenerator = new fm(), this.symbolIdGenerator = new Wp(), this.symbolFactory = new to(this.symbolIdGenerator), this.sourceSnapshot = /* @__PURE__ */ new Map(), this.globalCache = /* @__PURE__ */ new Map(), this.globallyQuerying = !1, this.localCache = /* @__PURE__ */ new Map(), this.parseFile = this.localQuery($S), this.parseProject = this.globalQuery(eC), this.validateNode = this.localQuery(xy), this.validateFile = this.localQuery(LS), this.nodeFullname = this.localQuery(Cy), this.nodeAlias = this.localQuery(wy), this.nodeSettings = this.localQuery(Sy), this.canonicalName = this.globalQuery(vS), this.bindNode = this.globalQuery(Dv), this.bindFile = this.globalQuery(NS), this.bindProject = this.globalQuery(PS), this.interpretSymbol = this.globalQuery(kv), this.interpretMetadata = this.globalQuery(Av), this.interpretFile = this.globalQuery(FS), this.interpretProject = this.globalQuery(IS), this.nodeSymbol = this.globalQuery(wv), this.nodeMetadata = this.globalQuery(Ov), this.symbolMembers = this.globalQuery(Tv), this.symbolMembersLookupMap = this.globalQuery(tC), this.lookupMembers = this.globalQuery(nC), this.nodeReferee = this.globalQuery(Ev), this.resolutionIndex = this.globalQuery(iC), this.symbolReferences = this.globalQuery(oC), this.symbolParent = this.globalQuery(aC), this.symbolMetadata = this.globalQuery(sC), this.symbolAliases = this.globalQuery(rC), this.symbolUses = this.globalQuery(cC), this.fileDependencies = this.localQuery(xS), this.reachableFiles = this.globalQuery(CS), this.usableMembers = this.globalQuery(u_), this.nodeAtPosition = this.localQuery(MS), this.renameTable = kC.bind(this), this.updateElementSetting = FC.bind(this), this.updateElementSettingEdit = PC.bind(this), this.findMetadataBlock = HC.bind(this), this.updateElementMetadata = KC.bind(this), this.updateElementMetadataEdit = GC.bind(this), this.syncDiagramView = $C.bind(this), this.syncDep = dw.bind(this), this.token = {
|
|
17241
17260
|
invalidStream: this.localQuery(jS),
|
|
17242
17261
|
flatStream: this.localQuery(AS)
|
|
17243
17262
|
}, this.parse = {
|
|
@@ -17279,10 +17298,10 @@ var hw = Symbol("COMPUTING"), gw = class {
|
|
|
17279
17298
|
r || (r = /* @__PURE__ */ new Map(), this.globalCache.set(t, r));
|
|
17280
17299
|
let i = n.length === 0 ? "" : n.length === 1 ? ph(n[0]) : n.map((e) => ph(e)).join("\0"), a = r.get(i);
|
|
17281
17300
|
if (a) {
|
|
17282
|
-
if (a ===
|
|
17301
|
+
if (a === gw) throw Error(`Cycle detected in query: ${e.name}(${i})`);
|
|
17283
17302
|
return a;
|
|
17284
17303
|
}
|
|
17285
|
-
r.set(i,
|
|
17304
|
+
r.set(i, gw);
|
|
17286
17305
|
try {
|
|
17287
17306
|
let t = e.apply(this, n);
|
|
17288
17307
|
return r.set(i, t), t;
|
|
@@ -17304,10 +17323,10 @@ var hw = Symbol("COMPUTING"), gw = class {
|
|
|
17304
17323
|
let c = s.get(t);
|
|
17305
17324
|
if (c || (c = /* @__PURE__ */ new Map(), s.set(t, c)), c.has(o)) {
|
|
17306
17325
|
let t = c.get(o);
|
|
17307
|
-
if (t ===
|
|
17326
|
+
if (t === gw) throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);
|
|
17308
17327
|
return t;
|
|
17309
17328
|
}
|
|
17310
|
-
c.set(o,
|
|
17329
|
+
c.set(o, gw);
|
|
17311
17330
|
try {
|
|
17312
17331
|
let t = e.apply(this, n);
|
|
17313
17332
|
return c.set(o, t), t;
|
|
@@ -17329,7 +17348,7 @@ var hw = Symbol("COMPUTING"), gw = class {
|
|
|
17329
17348
|
codeActionProvider: new Nb(this)
|
|
17330
17349
|
};
|
|
17331
17350
|
}
|
|
17332
|
-
},
|
|
17351
|
+
}, vw = class e {
|
|
17333
17352
|
constructor(e = {}) {
|
|
17334
17353
|
this.files = e instanceof Map ? new Map(e) : new Map(Object.entries(e));
|
|
17335
17354
|
}
|
|
@@ -17382,4 +17401,4 @@ var hw = Symbol("COMPUTING"), gw = class {
|
|
|
17382
17401
|
}
|
|
17383
17402
|
};
|
|
17384
17403
|
//#endregion
|
|
17385
|
-
export { km as ArrayNode, z as AttributeNode, H as BlockExpressionNode, uf as CARDINALITY_MANY, cf as CARDINALITY_MAYBE, sf as CARDINALITY_ONE, lf as CARDINALITY_SOME, W as CallExpressionNode, Sm as CommaExpressionNode, C as CompileError, S as CompileErrorCode, Tf as CompileInfo, wf as CompileWarning,
|
|
17404
|
+
export { km as ArrayNode, z as AttributeNode, H as BlockExpressionNode, uf as CARDINALITY_MANY, cf as CARDINALITY_MAYBE, sf as CARDINALITY_ONE, lf as CARDINALITY_SOME, W as CallExpressionNode, Sm as CommaExpressionNode, C as CompileError, S as CompileErrorCode, Tf as CompileInfo, wf as CompileWarning, _w as Compiler, Y as CompletionItemInsertTextRule, J as CompletionItemKind, Nb as DBMLCodeActionProvider, jx as DBMLCompletionItemProvider, Pb as DBMLDefinitionProvider, Fb as DBMLDiagnosticsProvider, Ib as DBMLReferencesProvider, Oo as DEFAULT_ENTRY, R as ElementDeclarationNode, r as ElementKind, Om as EmptyNode, Ep as FALSY_VALUES, So as Filepath, V as FunctionApplicationNode, bm as FunctionExpressionNode, Cm as GroupExpressionNode, _m as IdentifierStreamNode, vm as InfixExpressionNode, U as ListExpressionNode, wm as LiteralNode, Ab as MarkerSeverity, vw as MemoryProjectLayout, Wm as MetadataKind, ym as PostfixExpressionNode, B as PrefixExpressionNode, Dm as PrimaryExpressionNode, L as ProgramNode, Q as ScopeKind, P as SymbolKind, I as SyntaxNode, fm as SyntaxNodeIdGenerator, pm as SyntaxNodeKind, Ha as SyntaxToken, _ as SyntaxTokenKind, Tp as TRUTHY_VALUES, xm as TupleExpressionNode, t as UNHANDLED, yb as Uri, mm as UseDeclarationNode, gm as UseSpecifierListNode, hm as UseSpecifierNode, Em as VariableNode, Tm as WildcardNode, z_ as addDoubleQuoteIfNeeded, lC as applyTextEdits, dS as dbmlLanguageConfig, fS as dbmlMonarchTokensProvider, H_ as escapeString, hp as extractNumericLiteral, Sp as extractSignedNumber, JC as findDiagramViewBlocks, U_ as formatTypedValue, pf as getMultiplicities, Go as getRecordValueType, yf as getRelationshipOp, Ho as isBinaryType, Bo as isBooleanType, Uo as isDateTimeType, bp as isEmptyStringLiteral, hf as isEndpointManySide, mf as isEndpointOneSide, gf as isEndpointOptional, _f as isEndpointRequired, Ro as isFloatType, xp as isFunctionExpression, Lo as isIntegerType, yp as isNullish, zo as isNumericType, Ba as isOp, Va as isOpToken, Wo as isSerialType, Vo as isStringType, za as isTriviaToken, R_ as isValidIdentifier, bf as makeCardinalityOptional, xf as makeCardinalityRequired, vf as makeRelationshipRequired, B_ as normalizeQualifiedName, Io as normalizeTypeName, of as parseCardinality, W_ as splitQualifiedIdentifier, qC as syncElementMetadata, Dp as tryExtractBoolean, Np as tryExtractDateTime, Op as tryExtractEnum, wp as tryExtractInteger, Cp as tryExtractNumeric, kp as tryExtractString, V_ as unescapeString, xg as validateForeignKeys, dg as validatePrimaryKey, _g as validateUnique };
|
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.
|
|
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": "
|
|
54
|
+
"gitHead": "c88c4064ea4536ad26a0c98ce21f2986f51bf6f6"
|
|
55
55
|
}
|