@dbml/parse 9.0.0-alpha.10 → 9.0.0-alpha.11
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
CHANGED
|
@@ -18,10 +18,10 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(
|
|
|
18
18
|
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(v.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();this.addToken(v.IDENTIFIER)}operator(e){switch(e){case`<`:[`>`,`=`,`-`].includes(this.peek())&&this.advance();break;case`>`:this.peek()===`=`&&this.advance();break;case`-`:this.peek()===`>`&&this.advance();break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(v.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(v.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&&Oo(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Oo(this.peek());)this.advance();if(this.isAtEnd()||!Ao(this.peek()))return this.addToken(v.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(v.NUMERIC_LITERAL);if(!t&&!Ao(this.peek()))return this.addToken(v.NUMERIC_LITERAL);if(!t&&!Oo(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||Ao(this.peek()));)this.advance();let e=this.createToken(v.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new x(b.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();let e=this.createToken(v.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();this.addToken(v.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(`
|
|
19
19
|
`)&&this.advance(),``;case`
|
|
20
20
|
`:return``;case`t`:return` `;case`n`:return`
|
|
21
|
-
`;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()||!Ao(this.peek()))return this.errors.push(new x(b.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`,Va.create(v.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]}}},Mb=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),Nb=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 g(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 v.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case v.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case v.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case v.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},Pb=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}},Fb=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Nb,this.useSpecifierList=this.contextStack.withContextDo(Mb.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(Xs,e);try{this.consume(`Expect an opening brace '{'`,v.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(v.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof Ys&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(v.IDENTIFIER)&&Xa(this.peek()))break;!Ha(this.previous())&&!this.check(v.RBRACE)&&this.logError(this.peek(),b.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,v.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(v.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||this.check(v.STRING_LITERAL)||this.check(v.IDENTIFIER)&&Xa(e)||Ua(this.previous(),e))break;U(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===v.EOF?this.logError(e,b.UNEXPECTED_EOF,`Unexpected EOF`):U(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ja(e)||this.check(v.COLON,v.LBRACE,v.LBRACKET))break;U(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COLON,v.LBRACE,v.LBRACKET))break;U(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Mb.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(B,e);try{this.consume(`Expect an opening brace '{'`,v.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(v.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 '}'`,v.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(v.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||Ua(this.previous(),e))break;U(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Mb.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(nc,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ec,e);try{this.consume(`Expect an opening parenthesis '('`,v.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(v.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(v.RPAREN);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof N&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,v.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(v.RPAREN,v.COMMA))break;U(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Mb.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(V,e);try{this.consume(`Expect an opening bracket '['`,v.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(v.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(v.RBRACKET);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof N&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,v.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(v.COMMA,v.RBRACKET))break;U(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET,v.COLON))break;U(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;U(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Pb(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===v.EOF}advance(){return this.isAtEnd()?g(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?g(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(),b.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(U(this.peek()),this.logError(this.advance(),b.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)U(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(P,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){jc(e).forEach(t=>{t instanceof N&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Ya(this.peek())||Za(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Js&&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(Js,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===v.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(ic,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Xs&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof ic?`'*'`:`specifier list`;return Xa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(v.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(Ys,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,v.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(v.IDENTIFIER,v.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof N&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an element name`);if(Ja(this.peek())){e.asKeyword=this.advance();try{if(!this.check(v.IDENTIFIER,v.QUOTED_STRING))throw this.logError(this.peek(),b.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(F,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(v.COLON,v.LBRACE,v.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(Ja(this.peek()))if(e.as=this.advance(),this.check(v.COLON,v.LBRACE,v.LBRACKET))this.logError(this.peek(),b.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(v.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 ':'`,v.LBRACE,v.COLON))return t();try{if(this.match(v.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof F?(U(t),this.logError(t,b.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(F,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(F,e);try{this.consume(`Expect an identifier`,v.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 ':'`,v.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 F?this.errors.push(new x(b.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(F,e)}expression(){let e={args:[]},t=()=>Dc(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(z,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();){Wa(this.previous())||this.logError(n,b.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()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.RBRACKET,v.RPAREN,v.COMMA,v.COLON].includes(e)}commaExpression(){let e=this.check(v.COMMA)?this.nodeFactory.create(sc,{prevToken:this.previous()}):this.normalExpression();if(!this.check(v.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(sc,{prevToken:this.previous()}));break}if(this.check(v.COMMA)){t.elementList.push(this.nodeFactory.create(sc,{prevToken:this.previous()}));continue}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(tc,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(v.COMMA));return this.nodeFactory.create(tc,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.LBRACE,v.RBRACKET,v.LBRACKET,v.RPAREN,v.LPAREN,v.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===v.LPAREN){let{left:r}=Vb(n);if(r<e||Ua(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(H,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(H,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===v.LBRACKET){if(Wa(this.previous()))break;try{t=this.nodeFactory.create(cc,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(cc,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Ba(n)){let r=n,i=Vb(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(Qs,{expression:t,op:r})}else{let n=Lb(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(R,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(R,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Ba(this.peek())){let t={};t.op=this.peek();let n=zb(t.op);if(n.right===null)throw this.logError(t.op,b.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(sc,{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(L,t),e.handlerContext)):e}e=this.nodeFactory.create(L,t)}else if(e=this.extractOperand(),e instanceof sc)throw new $(this.peek(),this.nodeFactory.create(sc,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(v.WILDCARD)?this.wildcardExpression():this.check(v.NUMERIC_LITERAL,v.STRING_LITERAL,v.COLOR_LITERAL,v.QUOTED_STRING,v.IDENTIFIER)?this.primaryExpression():this.check(v.FUNCTION_EXPRESSION)?this.functionExpression():this.check(v.LBRACKET)?this.listExpression():this.check(v.LBRACE)?this.blockExpression():this.check(v.LPAREN)?this.tupleExpression():(this.peek().kind===v.EOF?this.logError(this.peek(),b.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),b.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(sc,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,v.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create($s,e),t.handlerContext):t}return this.nodeFactory.create($s,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(ic,{token:this.previous()})}canBeField(){return this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.COLON}primaryExpression(){if(this.match(v.COLOR_LITERAL,v.STRING_LITERAL,v.NUMERIC_LITERAL))return this.nodeFactory.create(oc,{expression:this.nodeFactory.create(rc,{literal:this.previous()})});if(this.match(v.QUOTED_STRING,v.IDENTIFIER))return this.nodeFactory.create(oc,{expression:this.nodeFactory.create(ac,{variable:this.previous()})});throw this.logError(this.peek(),b.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(v.COLON,v.RBRACKET,v.COMMA)){let t=this.peek();this.logError(t,b.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(Zs,{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(I,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(v.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(I,e)}attributeValue(){let e;try{e=this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.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!==v.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(v.COLON,v.COMMA,v.RBRACKET);)try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(Zs,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(Zs,{identifiers:e})}logError(e,t,n){this.errors.push(new x(t,n,e))}},Ib={"+":{left:9,right:10},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"->":{left:7,right:8},"<-":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function Lb(e){return Ib[e.value]||{left:null,right:null}}var Rb={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"->":{left:null,right:15},"<-":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function zb(e){return Rb[e.value]||{left:null,right:null}}var Bb={"(":{left:14,right:null}};function Vb(e){return Bb[e.value]||{left:null,right:null}}function Hb(e){let t=this.getSource(e);return new jb(t??``,e).lex().chain(n=>new Fb(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function Ub(){let e=Sg(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 Wb(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof Ws?Yh.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 Gb(e,n,r){let i;if(e instanceof Ts)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Ts))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 Kb(e){let t=e.originalSymbol;return Cg(this).map(n=>n.filter(n=>n instanceof Us&&n.originalSymbol===t&&n!==e))}function qb(){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=>{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(w(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof ec&&T(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ns(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 jc(e))t instanceof N&&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 Es&&t.isKind(M.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 Jb(e){return this.resolutionIndex().parents.get(e.intern())??[]}function Yb(e){return this.resolutionIndex().references.get(e.intern())??[]}function Xb(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function Zb(e){let t=e.originalSymbol;return Cg(this).map(n=>n.filter(n=>n instanceof Ws&&n.originalSymbol===t&&n!==e))}function Qb(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 $b(e,t){if((e.schema&&e.schema.length>0?e.schema:`public`)!==(t.schema&&t.schema.length>0?t.schema:`public`)||e.table!==t.table)return!1;let n=e.fields??[],r=t.fields??[];return n.length===r.length?n.every((e,t)=>e===r[t]):!1}function ex(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=xg(e);if(t.length===0)return{schema:y,table:``};if(t.length===1)return{schema:y,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 tx(e,n,r,i,a=M.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,M.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function nx(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function rx(e,t){if(!e||!(e instanceof F))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function ix(e,t,n){let r=!gg(t),i=!gg(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 ax(e,t,n,r,i,a){return n===i&&r===a?!1:tx(e,t,i,a)!==void 0}function ox(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 nx(n.substring(i,a))===t?{start:i,end:e.end}:null}function sx(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function cx(e,t,n,r,i){let a=[],o=new Set,s=sx(r);for(let r of e){if(nx(i.substring(r.start,r.end))!==n)continue;let e=ox(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 lx(e,n,r){let i=ex(n),a=ex(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=tx(this,e,o,s);if(!u||u instanceof Us||ax(this,e,o,s,c,l))return new Map;if(u instanceof Ws&&u.useSpecifierDeclaration instanceof Ys&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return ux(this,e,n,u,c,l)}return dx(this,u,o,s,c,l)}function ux(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=ix(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,Qb(o,c)]])}function dx(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof F))return new Map;let c=s.filepath;if(!c)return new Map;let l=ix(i,a,rx(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:sx(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 cx([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,Qb(r,n))}return m}function fx(e,t){let n=gx(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof I?hs(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof F){let n=_x(e,t);if(n)return{kind:`body`,declaration:n}}}function px(e,t){let n=gx(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof F){let n=e.body;if(n&&!(n instanceof z))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function mx(e,t,n,r){if(n===null)return hx(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=fx(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return px(e,i)}function hx(e,t,n){let r=fx(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function gx(e){if(e instanceof z)return e.args.find(e=>e instanceof V);if(e instanceof F){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof z)return t.args.find(e=>e instanceof V)}}function _x(e,t){let n=e.body;if(!(!n||Po(e)||n instanceof z)){for(let e of n.body)if(e instanceof F&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function vx(e,t){let n=xx(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:wg(t)}}function yx(e){let t=xx(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function bx(e,t){if(xx(e)||!(e instanceof F))return;let n=Sx(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${wg(t)}\n`};let r=e.body;if(r instanceof z){let n=r.args.find(e=>e instanceof V);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${wg(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${wg(t)}]`}}}function xx(e){if(!(e instanceof F))return;let t=e.body;if(t&&!(t instanceof z))for(let e of t.body){if(!(e instanceof F)||!e.isKind(r.Note))continue;let t=Cx(e);if(t)return{kind:qs.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof z?t.args.find(e=>e instanceof V):void 0);if(n)return wx(n)}function Sx(e){let t=e.body;if(!(!t||t instanceof z)&&t.blockCloseBrace)return t.blockCloseBrace.start}function Cx(e){let t=e.body;if(t instanceof z)return t.callee??void 0;if(t instanceof B&&t.body[0]instanceof z)return t.body[0].callee??void 0}function wx(e){let t=S(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:qs.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function Tx(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let i=new Fb(e,n.getValue(),new Ks,To).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations){if(!(e instanceof F)||!e.isKind(r.Dep))continue;let n=[],i=e.body;if(i instanceof z){if(i.callee instanceof R){let e=Nx(i.callee);e&&n.push(e)}}else if(i){for(let e of i.body)if(e instanceof z&&e.callee instanceof R){let t=Nx(e.callee);t&&n.push(t)}}t.push({startIndex:e.start,endIndex:e.end,declaration:e,edges:n})}return t}function Ex(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let a=new Fb(e,n.getValue(),new Ks,To).parse();if(a.getErrors().length>0)return t;let o=a.getValue().ast;for(let n of o.declarations){if(!(n instanceof F)||!n.isKind(r.Table))continue;let a=n.name?O(n.name)??[]:[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[a.length-2]:void 0,c=n.body;if(!(!c||c instanceof z))for(let n of c.body){if(!(n instanceof z)||!n.callee)continue;let r=O(n.callee)?.at(-1);if(!r)continue;let a={schema:s,table:o,fields:[r]},c=hx(n,i.Dep,e);if(c)for(let e of Bx(n,a))t.push({edge:e,stripStart:c.start,stripEnd:c.end})}}return t}function Dx(e,t){return`Dep [color: ${t}] {\n ${Fx(e.upstream)} -> ${Fx(e.downstream)}\n}`}function Ox(e,t,n){let r=this.getSource(e)??``,i=n??Tx(r),a=Ex(r),o=[];for(let e of t)o.push(...Vx(r,e,i,a));return o.sort((e,t)=>t.start-e.start),{newDbml:Qb(r,o,!0),edits:o}}function kx(e){return e&&e.length>0?e:y}function Ax(e,t){if(e.length===0)return;if(!t){let t=e[e.length-1];return{schema:e.length>1?e[e.length-2]:void 0,table:t,fields:[]}}let n=[e[e.length-1]],r=e[e.length-2];return{schema:e.length>2?e[e.length-3]:void 0,table:r,fields:n}}function jx(e,t){return $b(e.upstream,t.upstream)&&$b(e.downstream,t.downstream)}function Mx(e,t){return e.edges.some(e=>jx(e,t))}function Nx(e){let t=e.op?.value;if(t!==`->`&&t!==`<-`)return;let n=e.leftExpression,r=e.rightExpression;if(!n||!r)return;let i=t===`<-`?r:n,a=t===`<-`?n:r,o=O(i),s=O(a);if(!o||!s)return;let c=o.length>1&&s.length>1,l=Ax(o,c),u=Ax(s,c);if(!(!l||!u))return{upstream:l,downstream:u}}function Px(e){if(e.name instanceof Zs)return as(e.name)?.toLowerCase()}function Fx(e){let t=kx(e.schema),n=[];t!==`public`&&n.push(_g(t)),n.push(_g(e.table));for(let t of e.fields??[])n.push(_g(t));return n.join(`.`)}function Ix(e,t){return e.find(e=>Mx(e,t))}function Lx(e,t,n){let r=[];if(e.color!==void 0){let a=mx(t.declaration,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=yx(t.declaration);e&&r.push(e)}else if(e.note!==void 0){let n=vx(t.declaration,e.note)??bx(t.declaration,e.note);n&&r.push(n)}return r}function Rx(e,t,n,r){let i=Ix(n,t.edge);if(i)return Lx(t,i,e);let a=Dx(t.edge,t.color??``),o={start:e.length,end:e.length,newText:`
|
|
21
|
+
`;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()||!Ao(this.peek()))return this.errors.push(new x(b.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`,Va.create(v.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]}}},Mb=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),Nb=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 g(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 v.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case v.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case v.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case v.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},Pb=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}},Fb=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Nb,this.useSpecifierList=this.contextStack.withContextDo(Mb.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(Xs,e);try{this.consume(`Expect an opening brace '{'`,v.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(v.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof Ys&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(v.IDENTIFIER)&&Xa(this.peek()))break;!Ha(this.previous())&&!this.check(v.RBRACE)&&this.logError(this.peek(),b.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,v.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(v.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||this.check(v.STRING_LITERAL)||this.check(v.IDENTIFIER)&&Xa(e)||Ua(this.previous(),e))break;U(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===v.EOF?this.logError(e,b.UNEXPECTED_EOF,`Unexpected EOF`):U(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ja(e)||this.check(v.COLON,v.LBRACE,v.LBRACKET))break;U(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COLON,v.LBRACE,v.LBRACKET))break;U(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Mb.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(B,e);try{this.consume(`Expect an opening brace '{'`,v.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(v.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 '}'`,v.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(v.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||Ua(this.previous(),e))break;U(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Mb.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(nc,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ec,e);try{this.consume(`Expect an opening parenthesis '('`,v.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(v.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(v.RPAREN);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof N&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,v.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(v.RPAREN,v.COMMA))break;U(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Mb.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(V,e);try{this.consume(`Expect an opening bracket '['`,v.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(v.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(v.RBRACKET);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof N&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,v.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(v.COMMA,v.RBRACKET))break;U(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET,v.COLON))break;U(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;U(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Pb(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===v.EOF}advance(){return this.isAtEnd()?g(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?g(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(),b.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(U(this.peek()),this.logError(this.advance(),b.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)U(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(P,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){jc(e).forEach(t=>{t instanceof N&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Ya(this.peek())||Za(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Js&&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(Js,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===v.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(ic,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Xs&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof ic?`'*'`:`specifier list`;return Xa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(v.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(Ys,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,v.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(v.IDENTIFIER,v.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof N&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an element name`);if(Ja(this.peek())){e.asKeyword=this.advance();try{if(!this.check(v.IDENTIFIER,v.QUOTED_STRING))throw this.logError(this.peek(),b.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(F,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(v.COLON,v.LBRACE,v.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(Ja(this.peek()))if(e.as=this.advance(),this.check(v.COLON,v.LBRACE,v.LBRACKET))this.logError(this.peek(),b.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(v.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 ':'`,v.LBRACE,v.COLON))return t();try{if(this.match(v.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof F?(U(t),this.logError(t,b.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(F,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(F,e);try{this.consume(`Expect an identifier`,v.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 ':'`,v.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 F?this.errors.push(new x(b.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(F,e)}expression(){let e={args:[]},t=()=>Dc(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(z,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();){Wa(this.previous())||this.logError(n,b.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()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.RBRACKET,v.RPAREN,v.COMMA,v.COLON].includes(e)}commaExpression(){let e=this.check(v.COMMA)?this.nodeFactory.create(sc,{prevToken:this.previous()}):this.normalExpression();if(!this.check(v.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(sc,{prevToken:this.previous()}));break}if(this.check(v.COMMA)){t.elementList.push(this.nodeFactory.create(sc,{prevToken:this.previous()}));continue}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(tc,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(v.COMMA));return this.nodeFactory.create(tc,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.LBRACE,v.RBRACKET,v.LBRACKET,v.RPAREN,v.LPAREN,v.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===v.LPAREN){let{left:r}=Vb(n);if(r<e||Ua(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(H,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(H,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===v.LBRACKET){if(Wa(this.previous()))break;try{t=this.nodeFactory.create(cc,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(cc,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Ba(n)){let r=n,i=Vb(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(Qs,{expression:t,op:r})}else{let n=Lb(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(R,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(R,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Ba(this.peek())){let t={};t.op=this.peek();let n=zb(t.op);if(n.right===null)throw this.logError(t.op,b.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(sc,{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(L,t),e.handlerContext)):e}e=this.nodeFactory.create(L,t)}else if(e=this.extractOperand(),e instanceof sc)throw new $(this.peek(),this.nodeFactory.create(sc,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(v.WILDCARD)?this.wildcardExpression():this.check(v.NUMERIC_LITERAL,v.STRING_LITERAL,v.COLOR_LITERAL,v.QUOTED_STRING,v.IDENTIFIER)?this.primaryExpression():this.check(v.FUNCTION_EXPRESSION)?this.functionExpression():this.check(v.LBRACKET)?this.listExpression():this.check(v.LBRACE)?this.blockExpression():this.check(v.LPAREN)?this.tupleExpression():(this.peek().kind===v.EOF?this.logError(this.peek(),b.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),b.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(sc,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,v.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create($s,e),t.handlerContext):t}return this.nodeFactory.create($s,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(ic,{token:this.previous()})}canBeField(){return this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.COLON}primaryExpression(){if(this.match(v.COLOR_LITERAL,v.STRING_LITERAL,v.NUMERIC_LITERAL))return this.nodeFactory.create(oc,{expression:this.nodeFactory.create(rc,{literal:this.previous()})});if(this.match(v.QUOTED_STRING,v.IDENTIFIER))return this.nodeFactory.create(oc,{expression:this.nodeFactory.create(ac,{variable:this.previous()})});throw this.logError(this.peek(),b.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(v.COLON,v.RBRACKET,v.COMMA)){let t=this.peek();this.logError(t,b.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(Zs,{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(I,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(v.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(I,e)}attributeValue(){let e;try{e=this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.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!==v.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(v.COLON,v.COMMA,v.RBRACKET);)try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(Zs,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(Zs,{identifiers:e})}logError(e,t,n){this.errors.push(new x(t,n,e))}},Ib={"+":{left:9,right:10},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"->":{left:7,right:8},"<-":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function Lb(e){return Ib[e.value]||{left:null,right:null}}var Rb={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"->":{left:null,right:15},"<-":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function zb(e){return Rb[e.value]||{left:null,right:null}}var Bb={"(":{left:14,right:null}};function Vb(e){return Bb[e.value]||{left:null,right:null}}function Hb(e){let t=this.getSource(e);return new jb(t??``,e).lex().chain(n=>new Fb(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function Ub(){let e=Sg(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 Wb(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof Ws?Yh.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 Gb(e,n,r){let i;if(e instanceof Ts)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Ts))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 Kb(e){let t=e.originalSymbol;return Cg(this).map(n=>n.filter(n=>n instanceof Us&&n.originalSymbol===t&&n!==e))}function qb(){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=>{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(w(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof ec&&T(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ns(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 jc(e))t instanceof N&&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 Es&&t.isKind(M.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 Jb(e){return this.resolutionIndex().parents.get(e.intern())??[]}function Yb(e){return this.resolutionIndex().references.get(e.intern())??[]}function Xb(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function Zb(e){let t=e.originalSymbol;return Cg(this).map(n=>n.filter(n=>n instanceof Ws&&n.originalSymbol===t&&n!==e))}function Qb(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 $b(e,t){if((e.schemaName&&e.schemaName.length>0?e.schemaName:`public`)!==(t.schemaName&&t.schemaName.length>0?t.schemaName:`public`)||e.tableName!==t.tableName)return!1;let n=e.fieldNames??[],r=t.fieldNames??[];return n.length===r.length?n.every((e,t)=>e===r[t]):!1}function ex(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=xg(e);if(t.length===0)return{schema:y,table:``};if(t.length===1)return{schema:y,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 tx(e,n,r,i,a=M.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,M.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function nx(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function rx(e,t){if(!e||!(e instanceof F))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function ix(e,t,n){let r=!gg(t),i=!gg(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 ax(e,t,n,r,i,a){return n===i&&r===a?!1:tx(e,t,i,a)!==void 0}function ox(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 nx(n.substring(i,a))===t?{start:i,end:e.end}:null}function sx(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function cx(e,t,n,r,i){let a=[],o=new Set,s=sx(r);for(let r of e){if(nx(i.substring(r.start,r.end))!==n)continue;let e=ox(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 lx(e,n,r){let i=ex(n),a=ex(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=tx(this,e,o,s);if(!u||u instanceof Us||ax(this,e,o,s,c,l))return new Map;if(u instanceof Ws&&u.useSpecifierDeclaration instanceof Ys&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return ux(this,e,n,u,c,l)}return dx(this,u,o,s,c,l)}function ux(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=ix(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,Qb(o,c)]])}function dx(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof F))return new Map;let c=s.filepath;if(!c)return new Map;let l=ix(i,a,rx(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:sx(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 cx([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,Qb(r,n))}return m}function fx(e,t){let n=gx(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof I?hs(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof F){let n=_x(e,t);if(n)return{kind:`body`,declaration:n}}}function px(e,t){let n=gx(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof F){let n=e.body;if(n&&!(n instanceof z))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function mx(e,t,n,r){if(n===null)return hx(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=fx(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return px(e,i)}function hx(e,t,n){let r=fx(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function gx(e){if(e instanceof z)return e.args.find(e=>e instanceof V);if(e instanceof F){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof z)return t.args.find(e=>e instanceof V)}}function _x(e,t){let n=e.body;if(!(!n||Po(e)||n instanceof z)){for(let e of n.body)if(e instanceof F&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function vx(e,t){let n=xx(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:wg(t)}}function yx(e){let t=xx(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function bx(e,t){if(xx(e)||!(e instanceof F))return;let n=Sx(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${wg(t)}\n`};let r=e.body;if(r instanceof z){let n=r.args.find(e=>e instanceof V);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${wg(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${wg(t)}]`}}}function xx(e){if(!(e instanceof F))return;let t=e.body;if(t&&!(t instanceof z))for(let e of t.body){if(!(e instanceof F)||!e.isKind(r.Note))continue;let t=Cx(e);if(t)return{kind:qs.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof z?t.args.find(e=>e instanceof V):void 0);if(n)return wx(n)}function Sx(e){let t=e.body;if(!(!t||t instanceof z)&&t.blockCloseBrace)return t.blockCloseBrace.start}function Cx(e){let t=e.body;if(t instanceof z)return t.callee??void 0;if(t instanceof B&&t.body[0]instanceof z)return t.body[0].callee??void 0}function wx(e){let t=S(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:qs.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function Tx(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let i=new Fb(e,n.getValue(),new Ks,To).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations){if(!(e instanceof F)||!e.isKind(r.Dep))continue;let n=[],i=e.body;if(i instanceof z){if(i.callee instanceof R){let e=Nx(i.callee);e&&n.push(e)}}else if(i){for(let e of i.body)if(e instanceof z&&e.callee instanceof R){let t=Nx(e.callee);t&&n.push(t)}}t.push({startIndex:e.start,endIndex:e.end,declaration:e,edges:n})}return t}function Ex(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let a=new Fb(e,n.getValue(),new Ks,To).parse();if(a.getErrors().length>0)return t;let o=a.getValue().ast;for(let n of o.declarations){if(!(n instanceof F)||!n.isKind(r.Table))continue;let a=n.name?O(n.name)??[]:[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[a.length-2]:void 0,c=n.body;if(!(!c||c instanceof z))for(let n of c.body){if(!(n instanceof z)||!n.callee)continue;let r=O(n.callee)?.at(-1);if(!r)continue;let a={schemaName:s,tableName:o,fieldNames:[r]},c=hx(n,i.Dep,e);if(c)for(let e of Bx(n,a))t.push({edge:e,stripStart:c.start,stripEnd:c.end})}}return t}function Dx(e,t){return`Dep [color: ${t}] {\n ${Fx(e.upstream)} -> ${Fx(e.downstream)}\n}`}function Ox(e,t,n){let r=this.getSource(e)??``,i=n??Tx(r),a=Ex(r),o=[];for(let e of t)o.push(...Vx(r,e,i,a));return o.sort((e,t)=>t.start-e.start),{newDbml:Qb(r,o,!0),edits:o}}function kx(e){return e&&e.length>0?e:y}function Ax(e,t){if(e.length===0)return;if(!t){let t=e[e.length-1];return{schemaName:e.length>1?e[e.length-2]:null,tableName:t,fieldNames:[]}}let n=[e[e.length-1]],r=e[e.length-2];return{schemaName:e.length>2?e[e.length-3]:null,tableName:r,fieldNames:n}}function jx(e,t){return $b(e.upstream,t.upstream)&&$b(e.downstream,t.downstream)}function Mx(e,t){return e.edges.some(e=>jx(e,t))}function Nx(e){let t=e.op?.value;if(t!==`->`&&t!==`<-`)return;let n=e.leftExpression,r=e.rightExpression;if(!n||!r)return;let i=t===`<-`?r:n,a=t===`<-`?n:r,o=O(i),s=O(a);if(!o||!s)return;let c=o.length>1&&s.length>1,l=Ax(o,c),u=Ax(s,c);if(!(!l||!u))return{upstream:l,downstream:u}}function Px(e){if(e.name instanceof Zs)return as(e.name)?.toLowerCase()}function Fx(e){let t=kx(e.schemaName),n=[];t!==`public`&&n.push(_g(t)),n.push(_g(e.tableName));for(let t of e.fieldNames??[])n.push(_g(t));return n.join(`.`)}function Ix(e,t){return e.find(e=>Mx(e,t))}function Lx(e,t,n){let r=[];if(e.color!==void 0){let a=mx(t.declaration,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=yx(t.declaration);e&&r.push(e)}else if(e.note!==void 0){let n=vx(t.declaration,e.note)??bx(t.declaration,e.note);n&&r.push(n)}return r}function Rx(e,t,n,r){let i=Ix(n,t.edge);if(i)return Lx(t,i,e);let a=Dx(t.edge,t.color??``),o={start:e.length,end:e.length,newText:`
|
|
22
22
|
|
|
23
23
|
`+a+`
|
|
24
|
-
`},s=r.find(e=>jx(e.edge,t.edge));return s?[{start:s.stripStart,end:s.stripEnd,newText:``},o]:[o]}function zx(e,t,n){let r=e.color===void 0&&e.note===void 0;return Lx({...e,color:r?null:e.color},t,n)}function Bx(e,t){let n=e.args.find(e=>e instanceof V);if(!n)return[];let r=[];for(let e of n.elementList){if(Px(e)!==i.Dep)continue;let n=e.value;if(!(n instanceof L)||!n.expression)continue;let a=n.op?.value;if(a!==`->`&&a!==`<-`)continue;let o=O(n.expression);if(!o)continue;let s=Ax(o,o.length>1);s&&r.push(a===`->`?{upstream:t,downstream:s}:{upstream:s,downstream:t})}return r}function Vx(e,t,n,r){switch(t.operation){case`create`:return Rx(e,t,n,r);case`update`:{let r=Ix(n,t.edge);return r?Lx(t,r,e):[]}case`remove`:{let r=Ix(n,t.edge);return r?zx(t,r,e):[]}default:return[]}}function Hx(e,t,n,r){let i=this.getSource(e)??``;if(t.kind===`dep`)return Wx(i,t,n,r);if(t.kind===`ref`)return Gx(i,t,n,r);let a=Ux(this,e,t);if(!a)return i;let o=mx(a,n,r,i);return o?Qb(i,[o]):i}function Ux(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case M.Column:{let i=tx(e,t,r,n.table,M.Table);return i?e.lookupMembers(i,M.Column,n.column)?.declaration:void 0}case M.Table:return tx(e,t,r,n.table)?.declaration;case M.Enum:case M.StickyNote:case M.TableGroup:return tx(e,t,r,n.name,n.kind)?.declaration;case M.Schema:return tx(e,t,n.schema,``,M.Schema)?.declaration;default:return}}function Wx(e,t,n,r){let i=Tx(e).find(e=>e.edges.some(e=>$b(e.upstream,t.upstream)&&$b(e.downstream,t.downstream)));if(!i)return e;let{declaration:a}=i,{body:o}=a;if(o instanceof z){let t=mx(a,n,r,e);if(t)return Qb(e,[t]);let i=mx(o,n,r,e);return i?Qb(e,[i]):e}let s=mx(a,n,r,e);return s?Qb(e,[s]):e}function Gx(e,t,n,r){let i=Jx(e,t);if(!i)return e;let a=mx(i,n,r,e);return a?Qb(e,[a]):e}function Kx(e){if(e.length!==0)return e.length===1?{
|
|
24
|
+
`},s=r.find(e=>jx(e.edge,t.edge));return s?[{start:s.stripStart,end:s.stripEnd,newText:``},o]:[o]}function zx(e,t,n){let r=e.color===void 0&&e.note===void 0;return Lx({...e,color:r?null:e.color},t,n)}function Bx(e,t){let n=e.args.find(e=>e instanceof V);if(!n)return[];let r=[];for(let e of n.elementList){if(Px(e)!==i.Dep)continue;let n=e.value;if(!(n instanceof L)||!n.expression)continue;let a=n.op?.value;if(a!==`->`&&a!==`<-`)continue;let o=O(n.expression);if(!o)continue;let s=Ax(o,o.length>1);s&&r.push(a===`->`?{upstream:t,downstream:s}:{upstream:s,downstream:t})}return r}function Vx(e,t,n,r){switch(t.operation){case`create`:return Rx(e,t,n,r);case`update`:{let r=Ix(n,t.edge);return r?Lx(t,r,e):[]}case`remove`:{let r=Ix(n,t.edge);return r?zx(t,r,e):[]}default:return[]}}function Hx(e,t,n,r){let i=this.getSource(e)??``;if(t.kind===`dep`)return Wx(i,t,n,r);if(t.kind===`ref`)return Gx(i,t,n,r);let a=Ux(this,e,t);if(!a)return i;let o=mx(a,n,r,i);return o?Qb(i,[o]):i}function Ux(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case M.Column:{let i=tx(e,t,r,n.table,M.Table);return i?e.lookupMembers(i,M.Column,n.column)?.declaration:void 0}case M.Table:return tx(e,t,r,n.table)?.declaration;case M.Enum:case M.StickyNote:case M.TableGroup:return tx(e,t,r,n.name,n.kind)?.declaration;case M.Schema:return tx(e,t,n.schema,``,M.Schema)?.declaration;default:return}}function Wx(e,t,n,r){let i=Tx(e).find(e=>e.edges.some(e=>$b(e.upstream,t.upstream)&&$b(e.downstream,t.downstream)));if(!i)return e;let{declaration:a}=i,{body:o}=a;if(o instanceof z){let t=mx(a,n,r,e);if(t)return Qb(e,[t]);let i=mx(o,n,r,e);return i?Qb(e,[i]):e}let s=mx(a,n,r,e);return s?Qb(e,[s]):e}function Gx(e,t,n,r){let i=Jx(e,t);if(!i)return e;let a=mx(i,n,r,e);return a?Qb(e,[a]):e}function Kx(e){if(e.length!==0)return e.length===1?{tableName:e[0]}:e.length===2?{tableName:e[0],fieldNames:[e[1]]}:{schemaName:e[0],tableName:e[1],fieldNames:e.slice(2)}}function qx(e,t){let n=e.leftExpression?O(e.leftExpression):null,r=e.rightExpression?O(e.rightExpression):null;if(!n||!r)return!1;let i=Kx(n),a=Kx(r);if(!i||!a)return!1;let[o,s]=t.endpoints;return $b(i,o)&&$b(a,s)||$b(i,s)&&$b(a,o)}function Jx(e,t){let n=new jb(e,To).lex();if(n.getErrors().length>0)return;let i=new Fb(e,n.getValue(),new Ks,To).parse();if(i.getErrors().length>0)return;let a=i.getValue().ast;for(let e of a.declarations){if(!(e instanceof F)||!e.isKind(r.Ref))continue;let n=e.body;if(n instanceof z&&n.callee instanceof R){if(qx(n.callee,t))return n;continue}if(n&&!(n instanceof z)){for(let e of n.body)if(e instanceof z&&e.callee instanceof R&&qx(e.callee,t))return e}}}function Yx(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let i=new Fb(e,n.getValue(),new Ks,To).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?O(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function Xx(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function Zx(e,t){e.push(` ${t} { * }`)}function Qx(e){return e==null?`null`:e.length===0?`empty`:`items`}function $x(e,t){let n=`DiagramView ${_g(e)} {`,r=e=>_g(e.name),i=t?.tables?.map(e=>{let t=_g(e.name);return e.schemaName===`public`?t:`${_g(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:Qx(t.tables),tableGroups:Qx(t.tableGroups),schemas:Qx(t.schemas),stickyNotes:Qx(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`&&Xx(d,`Tables`,i),c.tableGroups===`items`&&Xx(d,`TableGroups`,a),c.schemas===`items`&&Xx(d,`Schemas`,o)):u&&Zx(d,`Tables`),c.stickyNotes===`items`?Xx(d,`Notes`,s):c.stickyNotes===`empty`&&Zx(d,`Notes`),d.push(`}`),d.join(`
|
|
25
25
|
`)}function eS(e,t,n){let r=this.getSource(e)??``,i=n??Yx(r),a=[];for(let e of t){let t=tS(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:Qb(r,a,!0),edits:a}}function tS(e,t,n){switch(t.operation){case`create`:return nS(e,t,n);case`update`:return rS(e,t,n);case`delete`:return iS(e,t,n);default:return[]}}function nS(e,t,n){if(n.find(e=>e.name===t.name))return rS(e,t,n);let r=`
|
|
26
26
|
|
|
27
27
|
`+$x(t.name,t.visibleEntities)+`
|
package/dist/dbml-parse.mjs
CHANGED
|
@@ -15461,8 +15461,8 @@ function Qb(e, t, n = !1) {
|
|
|
15461
15461
|
//#endregion
|
|
15462
15462
|
//#region src/compiler/queries/transform/utils.ts
|
|
15463
15463
|
function $b(e, t) {
|
|
15464
|
-
if ((e.
|
|
15465
|
-
let n = e.
|
|
15464
|
+
if ((e.schemaName && e.schemaName.length > 0 ? e.schemaName : "public") !== (t.schemaName && t.schemaName.length > 0 ? t.schemaName : "public") || e.tableName !== t.tableName) return !1;
|
|
15465
|
+
let n = e.fieldNames ?? [], r = t.fieldNames ?? [];
|
|
15466
15466
|
return n.length === r.length ? n.every((e, t) => e === r[t]) : !1;
|
|
15467
15467
|
}
|
|
15468
15468
|
function ex(e) {
|
|
@@ -15851,9 +15851,9 @@ function Ex(e) {
|
|
|
15851
15851
|
let r = O(n.callee)?.at(-1);
|
|
15852
15852
|
if (!r) continue;
|
|
15853
15853
|
let a = {
|
|
15854
|
-
|
|
15855
|
-
|
|
15856
|
-
|
|
15854
|
+
schemaName: s,
|
|
15855
|
+
tableName: o,
|
|
15856
|
+
fieldNames: [r]
|
|
15857
15857
|
}, c = hx(n, i.Dep, e);
|
|
15858
15858
|
if (c) for (let e of Bx(n, a)) t.push({
|
|
15859
15859
|
edge: e,
|
|
@@ -15883,16 +15883,16 @@ function Ax(e, t) {
|
|
|
15883
15883
|
if (!t) {
|
|
15884
15884
|
let t = e[e.length - 1];
|
|
15885
15885
|
return {
|
|
15886
|
-
|
|
15887
|
-
|
|
15888
|
-
|
|
15886
|
+
schemaName: e.length > 1 ? e[e.length - 2] : null,
|
|
15887
|
+
tableName: t,
|
|
15888
|
+
fieldNames: []
|
|
15889
15889
|
};
|
|
15890
15890
|
}
|
|
15891
15891
|
let n = [e[e.length - 1]], r = e[e.length - 2];
|
|
15892
15892
|
return {
|
|
15893
|
-
|
|
15894
|
-
|
|
15895
|
-
|
|
15893
|
+
schemaName: e.length > 2 ? e[e.length - 3] : null,
|
|
15894
|
+
tableName: r,
|
|
15895
|
+
fieldNames: n
|
|
15896
15896
|
};
|
|
15897
15897
|
}
|
|
15898
15898
|
function jx(e, t) {
|
|
@@ -15918,9 +15918,9 @@ function Px(e) {
|
|
|
15918
15918
|
if (e.name instanceof Zs) return as(e.name)?.toLowerCase();
|
|
15919
15919
|
}
|
|
15920
15920
|
function Fx(e) {
|
|
15921
|
-
let t = kx(e.
|
|
15922
|
-
t !== "public" && n.push(_g(t)), n.push(_g(e.
|
|
15923
|
-
for (let t of e.
|
|
15921
|
+
let t = kx(e.schemaName), n = [];
|
|
15922
|
+
t !== "public" && n.push(_g(t)), n.push(_g(e.tableName));
|
|
15923
|
+
for (let t of e.fieldNames ?? []) n.push(_g(t));
|
|
15924
15924
|
return n.join(".");
|
|
15925
15925
|
}
|
|
15926
15926
|
function Ix(e, t) {
|
|
@@ -16045,13 +16045,13 @@ function Gx(e, t, n, r) {
|
|
|
16045
16045
|
return a ? Qb(e, [a]) : e;
|
|
16046
16046
|
}
|
|
16047
16047
|
function Kx(e) {
|
|
16048
|
-
if (e.length !== 0) return e.length === 1 ? {
|
|
16049
|
-
|
|
16050
|
-
|
|
16048
|
+
if (e.length !== 0) return e.length === 1 ? { tableName: e[0] } : e.length === 2 ? {
|
|
16049
|
+
tableName: e[0],
|
|
16050
|
+
fieldNames: [e[1]]
|
|
16051
16051
|
} : {
|
|
16052
|
-
|
|
16053
|
-
|
|
16054
|
-
|
|
16052
|
+
schemaName: e[0],
|
|
16053
|
+
tableName: e[1],
|
|
16054
|
+
fieldNames: e.slice(2)
|
|
16055
16055
|
};
|
|
16056
16056
|
}
|
|
16057
16057
|
function qx(e, t) {
|
|
@@ -3,9 +3,9 @@ import { ElementDeclarationNode } from '../../../core/types/nodes';
|
|
|
3
3
|
import { default as Compiler } from '../../index';
|
|
4
4
|
import { TextEdit } from './applyTextEdits';
|
|
5
5
|
export interface DepEndpointRef {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
schemaName?: string | null;
|
|
7
|
+
tableName: string;
|
|
8
|
+
fieldNames?: string[];
|
|
9
9
|
}
|
|
10
10
|
export interface DepSyncEdge {
|
|
11
11
|
upstream: DepEndpointRef;
|
|
@@ -24,9 +24,9 @@ export interface EnumIdentifier {
|
|
|
24
24
|
name: string;
|
|
25
25
|
}
|
|
26
26
|
export interface EndpointRef {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
schemaName?: string | null;
|
|
28
|
+
tableName: string;
|
|
29
|
+
fieldNames?: string[];
|
|
30
30
|
}
|
|
31
31
|
export interface RefIdentifier {
|
|
32
32
|
kind?: typeof MetadataKind.Ref;
|
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": "9.0.0-alpha.
|
|
4
|
+
"version": "9.0.0-alpha.11",
|
|
5
5
|
"description": "DBML parser v2",
|
|
6
6
|
"author": "Holistics <dev@holistics.io>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=18"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "da99890d362342d38ec4044620962d0ebaddb2ee"
|
|
54
54
|
}
|