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