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

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