@dbml/parse 10.4.0-alpha.13 → 10.4.0-alpha.14

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.
@@ -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&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return AC(this,e,n,u,c,l)}return jC(this,u,o,s,c,l)}function AC(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=wC(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,lC(o,c)]])}function jC(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof R))return new Map;let c=s.filepath;if(!c)return new Map;let l=wC(i,a,CC(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:DC(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of OC([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,lC(r,n))}return m}function MC(e,t,n,r){if(t.kind===`dep`)return FC(this,e,t,n,r);if(t.kind===`ref`)return IC(this,e,t,n,r);let i=PC(this,e,t);if(!i)return[];let a=Og(i,n,r,this.getSource(e)??``);return a?[a]:[]}function NC(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:lC(i,a)}function PC(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case 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 FC(e,t,n,r,i){let a=e.getSource(t)??``,o=gC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=xC(n.upstream),t=xC(n.downstream),s=SC(r,i),c=s?`Dep [${s}] {\n ${e} -> ${t}\n}`:`Dep {\n ${e} -> ${t}\n}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
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:`
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 IC(e,t,n,r,i){let a=e.getSource(t)??``,o=uC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=xC(n.endpoints[0]),t=xC(n.endpoints[1]),s=SC(r,i),c=s?`Ref: ${e} ${o.op} ${t} [${s}]`:`Ref: ${e} ${o.op} ${t}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
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 LC(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 LC(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 RC(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 zC(e,t,n){if(b_(e)!==t)return!1;let r=A(e.name);return r?r.join(`.`).toLowerCase()===n.toLowerCase():!1}function BC(e,t){let n=LC(t.kind);if(!n)return;let i=RC(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)&&zC(e,n,i))return e}}function VC(e,t,n,r){return`Metadata ${e} ${t} {\n ${n}: ${r}\n}`}function HC(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 UC(e,t,n,r){let i=LC(t.kind);if(!i)return[];let a=RC(t);if(!a)return[];let o=this.getSource(e)??``,s=BC.call(this,e,t);if(!s){if(r===null)return[];let e=VC(HC(i),a,n,U_(r));return[{start:o.length,end:o.length,newText:`
31
+ `}]}let s=Og(o.node,r,i,a);return s?[s]:[]}function RC(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 zC(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 BC(e,t,n){if(b_(e)!==t)return!1;let r=A(e.name);return r?r.join(`.`).toLowerCase()===n.toLowerCase():!1}function VC(e,t){let n=RC(t.kind);if(!n)return;let i=zC(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)&&BC(e,n,i))return e}}function HC(e,t,n,r){return`Metadata ${e} ${t} {\n ${n}: ${r}\n}`}function UC(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 WC(e,t,n,r){let i=RC(t.kind);if(!i)return[];let a=zC(t);if(!a)return[];let o=this.getSource(e)??``,s=VC.call(this,e,t);if(!s){if(r===null)return[];let e=HC(UC(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 WC(e,t,n,r){let i=this.getSource(e)??``,a=UC.call(this,e,t,n,r);return a.length===0?i:lC(i,a,!0)}function GC(e,t,n,r,i,a){let o=UC.call(t,n,r,i,a);return o.length===0?{newDbml:e,edits:[]}:{newDbml:lC(e,o,!0),edits:o}}function KC(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 qC(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function JC(e,t){e.push(` ${t} { * }`)}function YC(e){return e==null?`null`:e.length===0?`empty`:`items`}function XC(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:YC(t.tables),tableGroups:YC(t.tableGroups),schemas:YC(t.schemas),stickyNotes:YC(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`&&qC(d,`Tables`,i),c.tableGroups===`items`&&qC(d,`TableGroups`,a),c.schemas===`items`&&qC(d,`Schemas`,o)):u&&JC(d,`Tables`),c.stickyNotes===`items`?qC(d,`Notes`,s):c.stickyNotes===`empty`&&JC(d,`Notes`),d.push(`}`),d.join(`
36
- `)}function ZC(e,t,n){let r=this.getSource(e)??``,i=n??KC(r),a=[];for(let e of t){let t=QC(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:lC(r,a,!0),edits:a}}function QC(e,t,n){switch(t.operation){case`create`:return $C(e,t,n);case`update`:return ew(e,t,n);case`delete`:return tw(e,t,n);default:return[]}}function $C(e,t,n){if(n.find(e=>e.name===t.name))return ew(e,t,n);let r=`
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 GC(e,t,n,r){let i=this.getSource(e)??``,a=WC.call(this,e,t,n,r);return a.length===0?i:lC(i,a,!0)}function KC(e,t,n,r,i,a){let o=WC.call(t,n,r,i,a);return o.length===0?{newDbml:e,edits:[]}:{newDbml:lC(e,o,!0),edits:o}}function qC(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 JC(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function YC(e,t){e.push(` ${t} { * }`)}function XC(e){return e==null?`null`:e.length===0?`empty`:`items`}function ZC(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:XC(t.tables),tableGroups:XC(t.tableGroups),schemas:XC(t.schemas),stickyNotes:XC(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`&&JC(d,`Tables`,i),c.tableGroups===`items`&&JC(d,`TableGroups`,a),c.schemas===`items`&&JC(d,`Schemas`,o)):u&&YC(d,`Tables`),c.stickyNotes===`items`?JC(d,`Notes`,s):c.stickyNotes===`empty`&&YC(d,`Notes`),d.push(`}`),d.join(`
36
+ `)}function QC(e,t,n){let r=this.getSource(e)??``,i=n??qC(r),a=[];for(let e of t){let t=$C(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:lC(r,a,!0),edits:a}}function $C(e,t,n){switch(t.operation){case`create`:return ew(e,t,n);case`update`:return tw(e,t,n);case`delete`:return nw(e,t,n);default:return[]}}function ew(e,t,n){if(n.find(e=>e.name===t.name))return tw(e,t,n);let r=`
37
37
 
38
- `+XC(t.name,t.visibleEntities)+`
39
- `;return[{start:e.length,end:e.length,newText:r}]}function ew(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=XC(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function tw(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]===`
38
+ `+ZC(t.name,t.visibleEntities)+`
39
+ `;return[{start:e.length,end:e.length,newText:r}]}function tw(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=ZC(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function nw(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 nw(e,t){let n=aw(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:q_(t)}}function rw(e){let t=aw(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function iw(e,t){if(aw(e)||!(e instanceof R))return;let n=ow(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 aw(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=sw(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 cw(n)}function ow(e){let t=e.body;if(!(!t||t instanceof V)&&t.blockCloseBrace)return t.blockCloseBrace.start}function sw(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 cw(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 lw(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...dw(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:lC(n,r,!0),edits:r}}function uw(e,t){return`Dep [color: ${t}] {\n ${xC(e.upstream)} -> ${xC(e.downstream)}\n}`}function dw(e,t,n,r){let i=gC(e,t,r.edge);switch(r.operation){case`create`:return pw(n,r,i);case`update`:return i?.kind===`block`?fw(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?fw({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function fw(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=rw(t);e&&r.push(e)}else if(e.note!==void 0){let n=nw(t,e.note)??iw(t,e.note);n&&r.push(n)}return r}function pw(e,t,n){if(n?.kind===`block`)return fw(t,n.declaration,e);let r=uw(t.edge,t.color??``),i={start:e.length,end:e.length,newText:`
43
+ `&&a++,[{start:i,end:a,newText:``}]}function rw(e,t){let n=ow(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:q_(t)}}function iw(e){let t=ow(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function aw(e,t){if(ow(e)||!(e instanceof R))return;let n=sw(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 ow(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=cw(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 lw(n)}function sw(e){let t=e.body;if(!(!t||t instanceof V)&&t.blockCloseBrace)return t.blockCloseBrace.start}function cw(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 lw(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 uw(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...fw(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:lC(n,r,!0),edits:r}}function dw(e,t){return`Dep [color: ${t}] {\n ${xC(e.upstream)} -> ${xC(e.downstream)}\n}`}function fw(e,t,n,r){let i=gC(e,t,r.edge);switch(r.operation){case`create`:return mw(n,r,i);case`update`:return i?.kind===`block`?pw(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?pw({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function pw(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=iw(t);e&&r.push(e)}else if(e.note!==void 0){let n=rw(t,e.note)??aw(t,e.note);n&&r.push(n)}return r}function mw(e,t,n){if(n?.kind===`block`)return pw(t,n.declaration,e);let r=dw(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 mw=Symbol(`COMPUTING`),hw=class{constructor(e){this.layout=e,this.nodeIdGenerator=new fm,this.symbolIdGenerator=new Wp,this.symbolFactory=new to(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery($S),this.parseProject=this.globalQuery(eC),this.validateNode=this.localQuery(xy),this.validateFile=this.localQuery(LS),this.nodeFullname=this.localQuery(Cy),this.nodeAlias=this.localQuery(wy),this.nodeSettings=this.localQuery(Sy),this.canonicalName=this.globalQuery(vS),this.bindNode=this.globalQuery(Dv),this.bindFile=this.globalQuery(NS),this.bindProject=this.globalQuery(PS),this.interpretSymbol=this.globalQuery(kv),this.interpretMetadata=this.globalQuery(Av),this.interpretFile=this.globalQuery(FS),this.interpretProject=this.globalQuery(IS),this.nodeSymbol=this.globalQuery(wv),this.nodeMetadata=this.globalQuery(Ov),this.symbolMembers=this.globalQuery(Tv),this.symbolMembersLookupMap=this.globalQuery(tC),this.lookupMembers=this.globalQuery(nC),this.nodeReferee=this.globalQuery(Ev),this.resolutionIndex=this.globalQuery(iC),this.symbolReferences=this.globalQuery(oC),this.symbolParent=this.globalQuery(aC),this.symbolMetadata=this.globalQuery(sC),this.symbolAliases=this.globalQuery(rC),this.symbolUses=this.globalQuery(cC),this.fileDependencies=this.localQuery(xS),this.reachableFiles=this.globalQuery(CS),this.usableMembers=this.globalQuery(u_),this.nodeAtPosition=this.localQuery(MS),this.renameTable=kC.bind(this),this.updateElementSetting=NC.bind(this),this.updateElementSettingEdit=MC.bind(this),this.findMetadataBlock=BC.bind(this),this.updateElementMetadata=WC.bind(this),this.updateElementMetadataEdit=UC.bind(this),this.syncDiagramView=ZC.bind(this),this.syncDep=lw.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===mw)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,mw);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===mw)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,mw);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)}}},gw=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=hw,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=gw,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=KC,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=GC,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;
46
+ `};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var hw=Symbol(`COMPUTING`),gw=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=PC.bind(this),this.updateElementSettingEdit=NC.bind(this),this.findMetadataBlock=VC.bind(this),this.updateElementMetadata=GC.bind(this),this.updateElementMetadataEdit=WC.bind(this),this.syncDiagramView=QC.bind(this),this.syncDep=uw.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===hw)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,hw);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===hw)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,hw);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)}}},_w=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=gw,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=_w,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=qC,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=KC,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;
@@ -16727,11 +16727,13 @@ 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 && u.useSpecifierDeclaration.alias) {
16730
+ if (u instanceof um && u.useSpecifierDeclaration instanceof hm) {
16731
16731
  let n = u.useSpecifierDeclaration;
16732
- if (this.nodeAlias(n).getFiltered(t) === s) return AC(this, e, n, u, c, l);
16732
+ if (n.alias) {
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);
16733
16735
  }
16734
- return jC(this, u, o, s, c, l);
16736
+ return MC(this, u, o, s, c, l);
16735
16737
  }
16736
16738
  function AC(e, t, n, r, i, a) {
16737
16739
  let o = e.getSource(t) ?? "";
@@ -16751,6 +16753,21 @@ function AC(e, t, n, r, i, a) {
16751
16753
  return /* @__PURE__ */ new Map([[t.absolute, lC(o, c)]]);
16752
16754
  }
16753
16755
  function jC(e, t, n, r, i, a) {
16756
+ let o = e.getSource(t) ?? "", s = n.name;
16757
+ if (!s) return /* @__PURE__ */ new Map();
16758
+ let c = wC(i, a, !1), l = s.end, u = [{
16759
+ start: l,
16760
+ end: l,
16761
+ newText: ` as ${c.formattedTable}`
16762
+ }], d = e.symbolReferences(r);
16763
+ for (let e of d) e.filepath.absolute === t.absolute && (e === s || s.start <= e.start && e.end <= s.end || u.push({
16764
+ start: e.start,
16765
+ end: e.end,
16766
+ newText: c.formattedTable
16767
+ }));
16768
+ return /* @__PURE__ */ new Map([[t.absolute, lC(o, u)]]);
16769
+ }
16770
+ function MC(e, t, n, r, i, a) {
16754
16771
  let o = t.originalSymbol, s = o.declaration;
16755
16772
  if (!s || !(s instanceof R)) return /* @__PURE__ */ new Map();
16756
16773
  let c = s.filepath;
@@ -16782,19 +16799,19 @@ function jC(e, t, n, r, i, a) {
16782
16799
  }
16783
16800
  //#endregion
16784
16801
  //#region src/compiler/queries/transform/updateElementSetting.ts
16785
- function MC(e, t, n, r) {
16786
- if (t.kind === "dep") return FC(this, e, t, n, r);
16787
- if (t.kind === "ref") return IC(this, e, t, n, r);
16788
- let i = PC(this, e, t);
16802
+ function NC(e, t, n, r) {
16803
+ if (t.kind === "dep") return IC(this, e, t, n, r);
16804
+ if (t.kind === "ref") return LC(this, e, t, n, r);
16805
+ let i = FC(this, e, t);
16789
16806
  if (!i) return [];
16790
16807
  let a = Og(i, n, r, this.getSource(e) ?? "");
16791
16808
  return a ? [a] : [];
16792
16809
  }
16793
- function NC(e, t, n, r) {
16810
+ function PC(e, t, n, r) {
16794
16811
  let i = this.getSource(e) ?? "", a = this.updateElementSettingEdit(e, t, n, r);
16795
16812
  return a.length === 0 ? i : lC(i, a);
16796
16813
  }
16797
- function PC(e, t, n) {
16814
+ function FC(e, t, n) {
16798
16815
  let r = ("schema" in n ? n.schema : void 0) ?? "public";
16799
16816
  switch (n.kind) {
16800
16817
  case P.Column: {
@@ -16809,7 +16826,7 @@ function PC(e, t, n) {
16809
16826
  default: return;
16810
16827
  }
16811
16828
  }
16812
- function FC(e, t, n, r, i) {
16829
+ function IC(e, t, n, r, i) {
16813
16830
  let a = e.getSource(t) ?? "", o = gC(e, t, n);
16814
16831
  if (!o) return [];
16815
16832
  if (o.kind === "inline") {
@@ -16835,7 +16852,7 @@ function FC(e, t, n, r, i) {
16835
16852
  let l = Og(s, r, i, a);
16836
16853
  return l ? [l] : [];
16837
16854
  }
16838
- function IC(e, t, n, r, i) {
16855
+ function LC(e, t, n, r, i) {
16839
16856
  let a = e.getSource(t) ?? "", o = uC(e, t, n);
16840
16857
  if (!o) return [];
16841
16858
  if (o.kind === "inline") {
@@ -16856,7 +16873,7 @@ function IC(e, t, n, r, i) {
16856
16873
  }
16857
16874
  //#endregion
16858
16875
  //#region src/compiler/queries/transform/updateElementMetadata.ts
16859
- function LC(e) {
16876
+ function RC(e) {
16860
16877
  switch (e) {
16861
16878
  case P.Table: return F.Table;
16862
16879
  case P.Column: return F.Column;
@@ -16865,7 +16882,7 @@ function LC(e) {
16865
16882
  default: return;
16866
16883
  }
16867
16884
  }
16868
- function RC(e) {
16885
+ function zC(e) {
16869
16886
  let t = _C("schema" in e ? e.schema : void 0);
16870
16887
  switch (e.kind) {
16871
16888
  case P.Table: {
@@ -16884,25 +16901,25 @@ function RC(e) {
16884
16901
  default: return;
16885
16902
  }
16886
16903
  }
16887
- function zC(e, t, n) {
16904
+ function BC(e, t, n) {
16888
16905
  if (b_(e) !== t) return !1;
16889
16906
  let r = A(e.name);
16890
16907
  return r ? r.join(".").toLowerCase() === n.toLowerCase() : !1;
16891
16908
  }
16892
- function BC(e, t) {
16893
- let n = LC(t.kind);
16909
+ function VC(e, t) {
16910
+ let n = RC(t.kind);
16894
16911
  if (!n) return;
16895
- let i = RC(t);
16912
+ let i = zC(t);
16896
16913
  if (!i) return;
16897
16914
  let a = this.parseFile(e).getValue().ast;
16898
16915
  if (a) {
16899
- for (let e of a.body ?? []) if (e instanceof R && O(e, r.Metadata) && zC(e, n, i)) return e;
16916
+ for (let e of a.body ?? []) if (e instanceof R && O(e, r.Metadata) && BC(e, n, i)) return e;
16900
16917
  }
16901
16918
  }
16902
- function VC(e, t, n, r) {
16919
+ function HC(e, t, n, r) {
16903
16920
  return `Metadata ${e} ${t} {\n ${n}: ${r}\n}`;
16904
16921
  }
16905
- function HC(e) {
16922
+ function UC(e) {
16906
16923
  switch (e) {
16907
16924
  case F.Table: return "Table";
16908
16925
  case F.Column: return "Column";
@@ -16911,15 +16928,15 @@ function HC(e) {
16911
16928
  default: return e;
16912
16929
  }
16913
16930
  }
16914
- function UC(e, t, n, r) {
16915
- let i = LC(t.kind);
16931
+ function WC(e, t, n, r) {
16932
+ let i = RC(t.kind);
16916
16933
  if (!i) return [];
16917
- let a = RC(t);
16934
+ let a = zC(t);
16918
16935
  if (!a) return [];
16919
- let o = this.getSource(e) ?? "", s = BC.call(this, e, t);
16936
+ let o = this.getSource(e) ?? "", s = VC.call(this, e, t);
16920
16937
  if (!s) {
16921
16938
  if (r === null) return [];
16922
- let e = VC(HC(i), a, n, U_(r));
16939
+ let e = HC(UC(i), a, n, U_(r));
16923
16940
  return [{
16924
16941
  start: o.length,
16925
16942
  end: o.length,
@@ -16960,12 +16977,12 @@ function UC(e, t, n, r) {
16960
16977
  newText: ` ${u}\n`
16961
16978
  }];
16962
16979
  }
16963
- function WC(e, t, n, r) {
16964
- let i = this.getSource(e) ?? "", a = UC.call(this, e, t, n, r);
16980
+ function GC(e, t, n, r) {
16981
+ let i = this.getSource(e) ?? "", a = WC.call(this, e, t, n, r);
16965
16982
  return a.length === 0 ? i : lC(i, a, !0);
16966
16983
  }
16967
- function GC(e, t, n, r, i, a) {
16968
- let o = UC.call(t, n, r, i, a);
16984
+ function KC(e, t, n, r, i, a) {
16985
+ let o = WC.call(t, n, r, i, a);
16969
16986
  return o.length === 0 ? {
16970
16987
  newDbml: e,
16971
16988
  edits: []
@@ -16976,7 +16993,7 @@ function GC(e, t, n, r, i, a) {
16976
16993
  }
16977
16994
  //#endregion
16978
16995
  //#region src/compiler/queries/transform/syncDiagramView.ts
16979
- function KC(e) {
16996
+ function qC(e) {
16980
16997
  let t = [], n = new RS(e, Oo).lex();
16981
16998
  if (n.getErrors().length > 0) return t;
16982
16999
  let i = new HS(e, n.getValue(), new fm(), Oo).parse();
@@ -16992,36 +17009,36 @@ function KC(e) {
16992
17009
  }
16993
17010
  return t;
16994
17011
  }
16995
- function qC(e, t, n) {
17012
+ function JC(e, t, n) {
16996
17013
  e.push(` ${t} {`), n.forEach((t) => e.push(` ${t}`)), e.push(" }");
16997
17014
  }
16998
- function JC(e, t) {
17015
+ function YC(e, t) {
16999
17016
  e.push(` ${t} { * }`);
17000
17017
  }
17001
- function YC(e) {
17018
+ function XC(e) {
17002
17019
  return e == null ? "null" : e.length === 0 ? "empty" : "items";
17003
17020
  }
17004
- function XC(e, t) {
17021
+ function ZC(e, t) {
17005
17022
  let n = `DiagramView ${z_(e)} {`, r = (e) => z_(e.name), i = t?.tables?.map((e) => {
17006
17023
  let t = z_(e.name);
17007
17024
  return e.schemaName === "public" ? t : `${z_(e.schemaName)}.${t}`;
17008
17025
  }) ?? [], a = t?.tableGroups?.map(r) ?? [], o = t?.schemas?.map(r) ?? [], s = t?.stickyNotes?.map(r) ?? [];
17009
17026
  if (!t) return `${n}\n}`;
17010
17027
  let c = {
17011
- tables: YC(t.tables),
17012
- tableGroups: YC(t.tableGroups),
17013
- schemas: YC(t.schemas),
17014
- stickyNotes: YC(t.stickyNotes)
17028
+ tables: XC(t.tables),
17029
+ tableGroups: XC(t.tableGroups),
17030
+ schemas: XC(t.schemas),
17031
+ stickyNotes: XC(t.stickyNotes)
17015
17032
  };
17016
17033
  if (Object.values(c).every((e) => e === "null")) return `${n}\n}`;
17017
17034
  if (Object.values(c).every((e) => e === "empty")) return `${n}\n *\n}`;
17018
17035
  let l = c.tables === "items" || c.tableGroups === "items" || c.schemas === "items", u = c.tables === "empty" && c.tableGroups === "empty" && c.schemas === "empty", d = [n];
17019
- return l ? (c.tables === "items" && qC(d, "Tables", i), c.tableGroups === "items" && qC(d, "TableGroups", a), c.schemas === "items" && qC(d, "Schemas", o)) : u && JC(d, "Tables"), c.stickyNotes === "items" ? qC(d, "Notes", s) : c.stickyNotes === "empty" && JC(d, "Notes"), d.push("}"), d.join("\n");
17036
+ return l ? (c.tables === "items" && JC(d, "Tables", i), c.tableGroups === "items" && JC(d, "TableGroups", a), c.schemas === "items" && JC(d, "Schemas", o)) : u && YC(d, "Tables"), c.stickyNotes === "items" ? JC(d, "Notes", s) : c.stickyNotes === "empty" && YC(d, "Notes"), d.push("}"), d.join("\n");
17020
17037
  }
17021
- function ZC(e, t, n) {
17022
- let r = this.getSource(e) ?? "", i = n ?? KC(r), a = [];
17038
+ function QC(e, t, n) {
17039
+ let r = this.getSource(e) ?? "", i = n ?? qC(r), a = [];
17023
17040
  for (let e of t) {
17024
- let t = QC(r, e, i);
17041
+ let t = $C(r, e, i);
17025
17042
  a.push(...t);
17026
17043
  }
17027
17044
  return a.sort((e, t) => t.start - e.start), {
@@ -17029,29 +17046,29 @@ function ZC(e, t, n) {
17029
17046
  edits: a
17030
17047
  };
17031
17048
  }
17032
- function QC(e, t, n) {
17049
+ function $C(e, t, n) {
17033
17050
  switch (t.operation) {
17034
- case "create": return $C(e, t, n);
17035
- case "update": return ew(e, t, n);
17036
- case "delete": return tw(e, t, n);
17051
+ case "create": return ew(e, t, n);
17052
+ case "update": return tw(e, t, n);
17053
+ case "delete": return nw(e, t, n);
17037
17054
  default: return [];
17038
17055
  }
17039
17056
  }
17040
- function $C(e, t, n) {
17041
- if (n.find((e) => e.name === t.name)) return ew(e, t, n);
17042
- let r = "\n\n" + XC(t.name, t.visibleEntities) + "\n";
17057
+ function ew(e, t, n) {
17058
+ if (n.find((e) => e.name === t.name)) return tw(e, t, n);
17059
+ let r = "\n\n" + ZC(t.name, t.visibleEntities) + "\n";
17043
17060
  return [{
17044
17061
  start: e.length,
17045
17062
  end: e.length,
17046
17063
  newText: r
17047
17064
  }];
17048
17065
  }
17049
- function ew(e, t, n) {
17066
+ function tw(e, t, n) {
17050
17067
  let r = n.find((e) => e.name === t.name);
17051
17068
  if (!r) return [];
17052
17069
  let i = [];
17053
17070
  if (t.newName || t.visibleEntities) {
17054
- let e = XC(t.newName || t.name, t.visibleEntities);
17071
+ let e = ZC(t.newName || t.name, t.visibleEntities);
17055
17072
  i.push({
17056
17073
  start: r.startIndex,
17057
17074
  end: r.endIndex,
@@ -17060,7 +17077,7 @@ function ew(e, t, n) {
17060
17077
  }
17061
17078
  return i;
17062
17079
  }
17063
- function tw(e, t, n) {
17080
+ function nw(e, t, n) {
17064
17081
  let r = n.find((e) => e.name === t.name);
17065
17082
  if (!r) return [];
17066
17083
  let i = r.startIndex, a = r.endIndex;
@@ -17080,25 +17097,25 @@ function tw(e, t, n) {
17080
17097
  }
17081
17098
  //#endregion
17082
17099
  //#region src/core/utils/note.ts
17083
- function nw(e, t) {
17084
- let n = aw(e);
17100
+ function rw(e, t) {
17101
+ let n = ow(e);
17085
17102
  if (n) return {
17086
17103
  start: n.noteValueStart,
17087
17104
  end: n.noteValueEnd,
17088
17105
  newText: q_(t)
17089
17106
  };
17090
17107
  }
17091
- function rw(e) {
17092
- let t = aw(e);
17108
+ function iw(e) {
17109
+ let t = ow(e);
17093
17110
  if (t) return {
17094
17111
  start: t.fullNoteStart,
17095
17112
  end: t.fullNoteEnd,
17096
17113
  newText: ""
17097
17114
  };
17098
17115
  }
17099
- function iw(e, t) {
17100
- if (aw(e) || !(e instanceof R)) return;
17101
- let n = ow(e);
17116
+ function aw(e, t) {
17117
+ if (ow(e) || !(e instanceof R)) return;
17118
+ let n = sw(e);
17102
17119
  if (n !== void 0) return {
17103
17120
  start: n,
17104
17121
  end: n,
@@ -17122,12 +17139,12 @@ function iw(e, t) {
17122
17139
  };
17123
17140
  }
17124
17141
  }
17125
- function aw(e) {
17142
+ function ow(e) {
17126
17143
  if (!(e instanceof R)) return;
17127
17144
  let t = e.body;
17128
17145
  if (t && !(t instanceof V)) for (let e of t.body) {
17129
17146
  if (!(e instanceof R) || !e.isKind(r.Note)) continue;
17130
- let t = sw(e);
17147
+ let t = cw(e);
17131
17148
  if (t) return {
17132
17149
  kind: pm.ELEMENT_DECLARATION,
17133
17150
  noteValueStart: t.start,
@@ -17137,18 +17154,18 @@ function aw(e) {
17137
17154
  };
17138
17155
  }
17139
17156
  let n = e.attributeList ?? (t instanceof V ? t.args.find((e) => e instanceof U) : void 0);
17140
- if (n) return cw(n);
17157
+ if (n) return lw(n);
17141
17158
  }
17142
- function ow(e) {
17159
+ function sw(e) {
17143
17160
  let t = e.body;
17144
17161
  if (!(!t || t instanceof V) && t.blockCloseBrace) return t.blockCloseBrace.start;
17145
17162
  }
17146
- function sw(e) {
17163
+ function cw(e) {
17147
17164
  let t = e.body;
17148
17165
  if (t instanceof V) return t.callee ?? void 0;
17149
17166
  if (t instanceof H && t.body[0] instanceof V) return t.body[0].callee ?? void 0;
17150
17167
  }
17151
- function cw(e) {
17168
+ function lw(e) {
17152
17169
  let t = w(e).getValue()[i.Note];
17153
17170
  if (!t?.length) return;
17154
17171
  let n = t[0];
@@ -17164,23 +17181,23 @@ function cw(e) {
17164
17181
  }
17165
17182
  //#endregion
17166
17183
  //#region src/compiler/queries/transform/syncDep.ts
17167
- function lw(e, t) {
17184
+ function uw(e, t) {
17168
17185
  let n = this.getSource(e) ?? "", r = [];
17169
- for (let i of t) r.push(...dw(this, e, n, i));
17186
+ for (let i of t) r.push(...fw(this, e, n, i));
17170
17187
  return r.sort((e, t) => t.start - e.start), {
17171
17188
  newDbml: lC(n, r, !0),
17172
17189
  edits: r
17173
17190
  };
17174
17191
  }
17175
- function uw(e, t) {
17192
+ function dw(e, t) {
17176
17193
  return `Dep [color: ${t}] {\n ${xC(e.upstream)} -> ${xC(e.downstream)}\n}`;
17177
17194
  }
17178
- function dw(e, t, n, r) {
17195
+ function fw(e, t, n, r) {
17179
17196
  let i = gC(e, t, r.edge);
17180
17197
  switch (r.operation) {
17181
- case "create": return pw(n, r, i);
17182
- case "update": return i?.kind === "block" ? fw(r, i.declaration, n) : [];
17183
- case "remove": return i?.kind === "block" ? fw({
17198
+ case "create": return mw(n, r, i);
17199
+ case "update": return i?.kind === "block" ? pw(r, i.declaration, n) : [];
17200
+ case "remove": return i?.kind === "block" ? pw({
17184
17201
  ...r,
17185
17202
  color: void 0,
17186
17203
  note: void 0
@@ -17188,24 +17205,24 @@ function dw(e, t, n, r) {
17188
17205
  default: return [];
17189
17206
  }
17190
17207
  }
17191
- function fw(e, t, n) {
17208
+ function pw(e, t, n) {
17192
17209
  let r = [];
17193
17210
  if (e.color !== void 0) {
17194
17211
  let a = Og(t, i.Color, e.color, n);
17195
17212
  a && r.push(a);
17196
17213
  }
17197
17214
  if (e.note === null) {
17198
- let e = rw(t);
17215
+ let e = iw(t);
17199
17216
  e && r.push(e);
17200
17217
  } else if (e.note !== void 0) {
17201
- let n = nw(t, e.note) ?? iw(t, e.note);
17218
+ let n = rw(t, e.note) ?? aw(t, e.note);
17202
17219
  n && r.push(n);
17203
17220
  }
17204
17221
  return r;
17205
17222
  }
17206
- function pw(e, t, n) {
17207
- if (n?.kind === "block") return fw(t, n.declaration, e);
17208
- let r = uw(t.edge, t.color ?? ""), i = {
17223
+ function mw(e, t, n) {
17224
+ if (n?.kind === "block") return pw(t, n.declaration, e);
17225
+ let r = dw(t.edge, t.color ?? ""), i = {
17209
17226
  start: e.length,
17210
17227
  end: e.length,
17211
17228
  newText: "\n\n" + r + "\n"
@@ -17218,9 +17235,9 @@ function pw(e, t, n) {
17218
17235
  }
17219
17236
  //#endregion
17220
17237
  //#region src/compiler/index.ts
17221
- var mw = Symbol("COMPUTING"), hw = class {
17238
+ var hw = Symbol("COMPUTING"), gw = class {
17222
17239
  constructor(e) {
17223
- 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 = NC.bind(this), this.updateElementSettingEdit = MC.bind(this), this.findMetadataBlock = BC.bind(this), this.updateElementMetadata = WC.bind(this), this.updateElementMetadataEdit = UC.bind(this), this.syncDiagramView = ZC.bind(this), this.syncDep = lw.bind(this), this.token = {
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 = PC.bind(this), this.updateElementSettingEdit = NC.bind(this), this.findMetadataBlock = VC.bind(this), this.updateElementMetadata = GC.bind(this), this.updateElementMetadataEdit = WC.bind(this), this.syncDiagramView = QC.bind(this), this.syncDep = uw.bind(this), this.token = {
17224
17241
  invalidStream: this.localQuery(jS),
17225
17242
  flatStream: this.localQuery(AS)
17226
17243
  }, this.parse = {
@@ -17262,10 +17279,10 @@ var mw = Symbol("COMPUTING"), hw = class {
17262
17279
  r || (r = /* @__PURE__ */ new Map(), this.globalCache.set(t, r));
17263
17280
  let i = n.length === 0 ? "" : n.length === 1 ? ph(n[0]) : n.map((e) => ph(e)).join("\0"), a = r.get(i);
17264
17281
  if (a) {
17265
- if (a === mw) throw Error(`Cycle detected in query: ${e.name}(${i})`);
17282
+ if (a === hw) throw Error(`Cycle detected in query: ${e.name}(${i})`);
17266
17283
  return a;
17267
17284
  }
17268
- r.set(i, mw);
17285
+ r.set(i, hw);
17269
17286
  try {
17270
17287
  let t = e.apply(this, n);
17271
17288
  return r.set(i, t), t;
@@ -17287,10 +17304,10 @@ var mw = Symbol("COMPUTING"), hw = class {
17287
17304
  let c = s.get(t);
17288
17305
  if (c || (c = /* @__PURE__ */ new Map(), s.set(t, c)), c.has(o)) {
17289
17306
  let t = c.get(o);
17290
- if (t === mw) throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);
17307
+ if (t === hw) throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);
17291
17308
  return t;
17292
17309
  }
17293
- c.set(o, mw);
17310
+ c.set(o, hw);
17294
17311
  try {
17295
17312
  let t = e.apply(this, n);
17296
17313
  return c.set(o, t), t;
@@ -17312,7 +17329,7 @@ var mw = Symbol("COMPUTING"), hw = class {
17312
17329
  codeActionProvider: new Nb(this)
17313
17330
  };
17314
17331
  }
17315
- }, gw = class e {
17332
+ }, _w = class e {
17316
17333
  constructor(e = {}) {
17317
17334
  this.files = e instanceof Map ? new Map(e) : new Map(Object.entries(e));
17318
17335
  }
@@ -17365,4 +17382,4 @@ var mw = Symbol("COMPUTING"), hw = class {
17365
17382
  }
17366
17383
  };
17367
17384
  //#endregion
17368
- 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, hw 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, gw 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, KC 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, GC 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 };
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, gw 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, _w 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, qC 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, KC 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.13",
4
+ "version": "10.4.0-alpha.14",
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": "eb532f0c02afa5195a0e4f52b615025d6a9cea9c"
54
+ "gitHead": "7934ffc1a01e42a515f12d9b67da5bbc4f220837"
55
55
  }