@dbml/parse 10.1.0 → 10.1.1-alpha.0
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 +11 -11
- package/dist/dbml-parse.mjs +310 -341
- package/dist/src/compiler/index.d.ts +1 -1
- package/dist/src/compiler/queries/transform/syncDep.d.ts +1 -1
- package/dist/src/compiler/queries/transform/utils/dep.d.ts +26 -0
- package/dist/src/compiler/queries/transform/utils/index.d.ts +1 -2
- package/package.json +2 -2
package/dist/dbml-parse.js
CHANGED
|
@@ -22,21 +22,21 @@ 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()&&Df(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();break;default:break}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&&Tf(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Tf(this.peek());)this.advance();if(this.isAtEnd()||!Df(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&&!Df(this.peek()))return this.addToken(_.NUMERIC_LITERAL);if(!t&&!Tf(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||Df(this.peek()));)this.advance();let e=this.createToken(_.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new w(C.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&Df(this.peek());)this.advance();let e=this.createToken(_.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&Df(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()||!Df(this.peek()))return this.errors.push(new w(C.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]}}},FS=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),IS=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;break;default:break}}},LS=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}},RS=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new IS,this.useSpecifierList=this.contextStack.withContextDo(FS.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(hm,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 mm&&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(),C.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,C.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(FS.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(U,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(FS.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(xm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ym,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(FS.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(W,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 LS(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(),C.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(),C.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){Fm(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 pm&&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(pm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===_.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(wm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof hm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof wm?`'*'`:`specifier list`;return Qa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(_.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(mm,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(),C.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(),C.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(),C.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,C.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 w(C.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=()=>jm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(H,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,C.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(Dm,{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(Dm,{prevToken:this.previous()}));break}if(this.check(_.COMMA)){t.elementList.push(this.nodeFactory.create(Dm,{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(bm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(_.COMMA));return this.nodeFactory.create(bm,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}=JS(n);if(r<e||Wa(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(Sm,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Sm,{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(Om,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Om,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Va(n)){let r=n,i=JS(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(_m,{expression:t,op:r})}else{let n=WS(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(V,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(V,{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=KS(t.op);if(n.right===null)throw this.logError(t.op,C.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Dm,{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 Dm)throw new $(this.peek(),this.nodeFactory.create(Dm,{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(),C.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),C.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Dm,{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(vm,e),t.handlerContext):t}return this.nodeFactory.create(vm,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(wm,{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(Em,{expression:this.nodeFactory.create(Cm,{literal:this.previous()})});if(this.match(_.QUOTED_STRING,_.IDENTIFIER))return this.nodeFactory.create(Em,{expression:this.nodeFactory.create(Tm,{variable:this.previous()})});throw this.logError(this.peek(),C.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,C.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(gm,{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(gm,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(gm,{identifiers:e})}logError(e,t,n){this.errors.push(new w(t,n,e))}},zS=e=>({left:e,right:e+1}),BS=e=>({left:null,right:e}),VS=e=>({left:e,right:null}),HS={left:null,right:null},US={".":zS(16),"/":zS(11),"%":zS(11),"+":zS(9),"=":zS(2),"==":zS(4),"!=":zS(4),"-":zS(9),"-?":zS(9),"?-":zS(9),"?-?":zS(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`].map(e=>[e,zS(7)]))};function WS(e){return US[e.value]??HS}var GS=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`,`!`,`~`].map(e=>[e,BS(15)]));function KS(e){return GS[e.value]??HS}var qS={"(":VS(14)};function JS(e){return qS[e.value]??HS}function YS(e){let t=this.getSource(e);return new PS(t??``,e).lex().chain(n=>new RS(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function XS(){let e=W_(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 ZS(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof lm?o_.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 QS(e,n,r){let i;if(e instanceof Wp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Wp))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 $S(e){let t=e.originalSymbol;return G_(this).map(n=>n.filter(n=>n instanceof cm&&n.originalSymbol===t&&n!==e))}function eC(){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 Zm){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);return}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(D(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof ym&&O(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=rp(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 Fm(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 Gp&&t.isKind(F.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 tC(e){return this.resolutionIndex().parents.get(e.intern())??[]}function nC(e){return this.resolutionIndex().references.get(e.intern())??[]}function rC(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function iC(e){let t=e.originalSymbol;return G_(this).map(n=>n.filter(n=>n instanceof lm&&n.originalSymbol===t&&n!==e))}function aC(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 oC(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 Gm&&cC(e,t,r)){if(t.declaration instanceof z){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(H);if(!r)continue;let a=Og(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=lp(t.declaration)[0];if(e instanceof H)return{kind:`standalone`,node:e}}}}function sC(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0?!0:t.length===r.length?t.every((e,t)=>e.name===r[t]):!1}function cC(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 sC(r,i,s)&&sC(a,o,c)||sC(r,i,c)&&sC(a,o,s)}function lC(e){return e&&e.length>0?e:v}function uC(e,t){if(lC(e.schemaName)!==lC(t.schemaName)||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 dC(e,t){if(lC(e.schemaName)!==lC(t.schemaName)||e.tableName!==t.tableName)return!1;let n=t.fieldNames??[];if(n.length===0)return!0;let r=e.fieldNames??[];return r.length===n.length?r.every((e,t)=>e===n[t]):!1}function fC(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=U_(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 pC(e,n,r,i,a=F.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,F.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function mC(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function hC(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(R_(e.schemaName)),t.push(R_(e.tableName));for(let n of e.fieldNames??[])t.push(R_(n));return t.join(`.`)}function gC(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function _C(e,t){if(!e||!(e instanceof R))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function vC(e,t,n){let r=!L_(t),i=!L_(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 yC(e,t,n,r,i,a){return n===i&&r===a?!1:pC(e,t,i,a)!==void 0}function bC(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 mC(n.substring(i,a))===t?{start:i,end:e.end}:null}function xC(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function SC(e,t,n,r,i){let a=[],o=new Set,s=xC(r);for(let r of e){if(mC(i.substring(r.start,r.end))!==n)continue;let e=bC(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 CC(e,n,r){let i=fC(n),a=fC(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=pC(this,e,o,s);if(!u||u instanceof cm||yC(this,e,o,s,c,l))return new Map;if(u instanceof lm&&u.useSpecifierDeclaration instanceof mm&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return wC(this,e,n,u,c,l)}return TC(this,u,o,s,c,l)}function wC(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=vC(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,aC(o,c)]])}function TC(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=vC(i,a,_C(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:xC(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 SC([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,aC(r,n))}return m}function EC(e,t){let n=kC(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:K_(t)}}function DC(e){let t=kC(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function OC(e,t){if(kC(e)||!(e instanceof R))return;let n=AC(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${K_(t)}\n`};let r=e.body;if(r instanceof H){let n=r.args.find(e=>e instanceof W);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${K_(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${K_(t)}]`}}}function kC(e){if(!(e instanceof R))return;let t=e.body;if(t&&!(t instanceof H))for(let e of t.body){if(!(e instanceof R)||!e.isKind(r.Note))continue;let t=jC(e);if(t)return{kind:fm.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof H?t.args.find(e=>e instanceof W):void 0);if(n)return MC(n)}function AC(e){let t=e.body;if(!(!t||t instanceof H)&&t.blockCloseBrace)return t.blockCloseBrace.start}function jC(e){let t=e.body;if(t instanceof H)return t.callee??void 0;if(t instanceof U&&t.body[0]instanceof H)return t.body[0].callee??void 0}function MC(e){let t=T(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:fm.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function NC(e,t,n){let r=this.getSource(e)??``,i=this.parseFile(e).getValue().ast,a=n??IC(i),o=LC(r,i),s=[];for(let e of t)s.push(...WC(r,e,a,o));return s.sort((e,t)=>t.start-e.start),{newDbml:aC(r,s,!0),edits:s}}function PC(e){let t=new PS(e,Do).lex();if(t.getErrors().length>0)return[];let n=new RS(e,t.getValue(),new dm,Do).parse();return n.getErrors().length>0?[]:IC(n.getValue().ast)}function FC(e,t){return`Dep [color: ${t}] {\n ${hC(e.upstream)} -> ${hC(e.downstream)}\n}`}function IC(e){let t=[];for(let n of e.declarations){if(!(n instanceof R)||!n.isKind(r.Dep))continue;let e=[],i=n.body;if(i instanceof H){if(i.callee instanceof V){let t=RC(i.callee);t&&e.push(t)}}else if(i){for(let t of i.body)if(t instanceof H&&t.callee instanceof V){let n=RC(t.callee);n&&e.push(n)}}t.push({startIndex:n.start,endIndex:n.end,declaration:n,edges:e})}return t}function LC(e,t){let n=[];for(let a of t.declarations){if(!(a instanceof R)||!a.isKind(r.Table))continue;let t=a.name?j(a.name)??[]:[];if(t.length===0)continue;let o=t[t.length-1],s=t.length>1?t[t.length-2]:void 0,c=a.body;if(!(!c||c instanceof H))for(let t of c.body){if(!(t instanceof H)||!t.callee)continue;let r=j(t.callee)?.at(-1);if(!r)continue;let a={schemaName:s,tableName:o,fieldNames:[r]},c=Og(t,i.Dep,e);if(c)for(let e of BC(t,a))n.push({edge:e,fullStart:c.start,fullEnd:c.end})}}return n}function RC(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=j(i),s=j(a);if(!o||!s)return;let c=o.length>1&&s.length>1,l=zC(o,c),u=zC(s,c);if(!(!l||!u))return{upstream:l,downstream:u}}function zC(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 BC(e,t){let n=e.args.find(e=>e instanceof W);if(!n)return[];let r=[];for(let e of n.elementList){if(gp(e)!==i.Dep)continue;let n=e.value;if(!(n instanceof B)||!n.expression)continue;let a=n.op?.value;if(a!==`->`&&a!==`<-`)continue;let o=j(n.expression);if(!o)continue;let s=zC(o,o.length>1);s&&r.push(a===`->`?{upstream:t,downstream:s}:{upstream:s,downstream:t})}return r}function VC(e,t){return dC(e.upstream,t.upstream)&&dC(e.downstream,t.downstream)}function HC(e,t){return e.edges.some(e=>VC(e,t))}function UC(e,t){return e.find(e=>HC(e,t))}function WC(e,t,n,r){switch(t.operation){case`create`:return KC(e,t,n,r);case`update`:{let r=UC(n,t.edge);return r?GC(t,r,e):[]}case`remove`:{let r=UC(n,t.edge);return r?GC({...t,color:void 0,note:void 0},r,e):[]}default:return[]}}function GC(e,t,n){let r=[];if(e.color!==void 0){let a=Dg(t.declaration,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=DC(t.declaration);e&&r.push(e)}else if(e.note!==void 0){let n=EC(t.declaration,e.note)??OC(t.declaration,e.note);n&&r.push(n)}return r}function KC(e,t,n,r){let i=UC(n,t.edge);if(i)return GC(t,i,e);let a=FC(t.edge,t.color??``),o={start:e.length,end:e.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()||!Df(this.peek()))return this.errors.push(new w(C.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]}}},FS=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),IS=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;break;default:break}}},LS=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}},RS=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new IS,this.useSpecifierList=this.contextStack.withContextDo(FS.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(hm,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 mm&&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(),C.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,C.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(FS.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(U,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(FS.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(xm,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ym,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(FS.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(W,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 LS(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(),C.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(),C.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){Fm(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 pm&&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(pm,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===_.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(wm,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof hm&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof wm?`'*'`:`specifier list`;return Qa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(_.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),C.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(mm,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(),C.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(),C.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(),C.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,C.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 w(C.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=()=>jm(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(H,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,C.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(Dm,{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(Dm,{prevToken:this.previous()}));break}if(this.check(_.COMMA)){t.elementList.push(this.nodeFactory.create(Dm,{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(bm,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(_.COMMA));return this.nodeFactory.create(bm,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}=JS(n);if(r<e||Wa(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(Sm,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Sm,{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(Om,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(Om,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Va(n)){let r=n,i=JS(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(_m,{expression:t,op:r})}else{let n=WS(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(V,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(V,{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=KS(t.op);if(n.right===null)throw this.logError(t.op,C.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(Dm,{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 Dm)throw new $(this.peek(),this.nodeFactory.create(Dm,{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(),C.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),C.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(Dm,{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(vm,e),t.handlerContext):t}return this.nodeFactory.create(vm,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(wm,{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(Em,{expression:this.nodeFactory.create(Cm,{literal:this.previous()})});if(this.match(_.QUOTED_STRING,_.IDENTIFIER))return this.nodeFactory.create(Em,{expression:this.nodeFactory.create(Tm,{variable:this.previous()})});throw this.logError(this.peek(),C.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,C.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(gm,{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(gm,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(gm,{identifiers:e})}logError(e,t,n){this.errors.push(new w(t,n,e))}},zS=e=>({left:e,right:e+1}),BS=e=>({left:null,right:e}),VS=e=>({left:e,right:null}),HS={left:null,right:null},US={".":zS(16),"/":zS(11),"%":zS(11),"+":zS(9),"=":zS(2),"==":zS(4),"!=":zS(4),"-":zS(9),"-?":zS(9),"?-":zS(9),"?-?":zS(9),...Object.fromEntries([`<`,`<=`,`>`,`>=`,`<>`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`].map(e=>[e,zS(7)]))};function WS(e){return US[e.value]??HS}var GS=Object.fromEntries([`+`,`-`,`<`,`>`,`<>`,`-?`,`?-`,`?-?`,`?>`,`>?`,`?<`,`<?`,`?>?`,`?<?`,`?<>`,`<>?`,`?<>?`,`->`,`<-`,`!`,`~`].map(e=>[e,BS(15)]));function KS(e){return GS[e.value]??HS}var qS={"(":VS(14)};function JS(e){return qS[e.value]??HS}function YS(e){let t=this.getSource(e);return new PS(t??``,e).lex().chain(n=>new RS(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function XS(){let e=W_(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 ZS(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof lm?o_.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 QS(e,n,r){let i;if(e instanceof Wp)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Wp))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 $S(e){let t=e.originalSymbol;return G_(this).map(n=>n.filter(n=>n instanceof cm&&n.originalSymbol===t&&n!==e))}function eC(){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 Zm){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);return}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(D(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof ym&&O(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=rp(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 Fm(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 Gp&&t.isKind(F.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 tC(e){return this.resolutionIndex().parents.get(e.intern())??[]}function nC(e){return this.resolutionIndex().references.get(e.intern())??[]}function rC(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function iC(e){let t=e.originalSymbol;return G_(this).map(n=>n.filter(n=>n instanceof lm&&n.originalSymbol===t&&n!==e))}function aC(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 oC(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 Gm&&cC(e,t,r)){if(t.declaration instanceof z){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(H);if(!r)continue;let a=Og(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=lp(t.declaration)[0];if(e instanceof H)return{kind:`standalone`,node:e}}}}function sC(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0?!0:t.length===r.length?t.every((e,t)=>e.name===r[t]):!1}function cC(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 sC(r,i,s)&&sC(a,o,c)||sC(r,i,c)&&sC(a,o,s)}function lC(e,t,n){let r=hC(e,t,pC(n.schemaName),n.tableName,F.Table);return{table:r,columns:(n.fieldNames??[]).map(t=>r?e.lookupMembers(r,F.Column,t):void 0)}}function uC(e,t){let n=e?.originalSymbol.declaration;return!!n&&n===t?.originalSymbol.declaration}function dC(e,t,n){return!uC(e,n.table)||t.length!==n.columns.length?!1:t.every((e,t)=>uC(e,n.columns[t]))}function fC(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=lC(e,n,r.upstream),c=lC(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 Km))continue;let n=t.upstreamTables(e),r=t.upstreamColumns(e),a=t.downstreamTables(e),o=t.downstreamColumns(e);if(!n.some((e,t)=>dC(n[t],r[t]??[],s)&&dC(a[t],o[t]??[],c)))continue;if(t.declaration instanceof R)return{kind:`block`,declaration:t.declaration};let u=t.declaration.parentOfKind(H);if(!u)continue;let d=Og(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 pC(e){return e&&e.length>0?e:v}function mC(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=U_(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 hC(e,n,r,i,a=F.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,F.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function gC(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function _C(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(R_(e.schemaName)),t.push(R_(e.tableName));for(let n of e.fieldNames??[])t.push(R_(n));return t.join(`.`)}function vC(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function yC(e,t){if(!e||!(e instanceof R))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function bC(e,t,n){let r=!L_(t),i=!L_(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 xC(e,t,n,r,i,a){return n===i&&r===a?!1:hC(e,t,i,a)!==void 0}function SC(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 gC(n.substring(i,a))===t?{start:i,end:e.end}:null}function CC(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function wC(e,t,n,r,i){let a=[],o=new Set,s=CC(r);for(let r of e){if(gC(i.substring(r.start,r.end))!==n)continue;let e=SC(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 TC(e,n,r){let i=mC(n),a=mC(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=hC(this,e,o,s);if(!u||u instanceof cm||xC(this,e,o,s,c,l))return new Map;if(u instanceof lm&&u.useSpecifierDeclaration instanceof mm&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return EC(this,e,n,u,c,l)}return DC(this,u,o,s,c,l)}function EC(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=bC(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,aC(o,c)]])}function DC(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=bC(i,a,yC(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:CC(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 wC([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,aC(r,n))}return m}function OC(e,t,n,r){if(t.kind===`dep`)return jC(this,e,t,n,r);if(t.kind===`ref`)return MC(this,e,t,n,r);let i=AC(this,e,t);if(!i)return[];let a=Dg(i,n,r,this.getSource(e)??``);return a?[a]:[]}function kC(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:aC(i,a)}function AC(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case F.Column:{let i=hC(e,t,r,n.table,F.Table);return i?e.lookupMembers(i,F.Column,n.column)?.declaration:void 0}case F.Table:return hC(e,t,r,n.table)?.declaration;case F.Enum:case F.StickyNote:case F.TableGroup:return hC(e,t,r,n.name,n.kind)?.declaration;case F.Schema:return hC(e,t,n.schema,``,F.Schema)?.declaration;default:return}}function jC(e,t,n,r,i){let a=e.getSource(t)??``,o=fC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=_C(n.upstream),t=_C(n.downstream),s=vC(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
|
-
`+
|
|
28
|
-
`}
|
|
29
|
-
|
|
30
|
-
`+l+`
|
|
31
|
-
`}]}let{declaration:c}=s,{body:l}=c;if(l instanceof H){let e=Dg(c,r,i,a);if(e)return[e];let t=Dg(l,r,i,a);return t?[t]:[]}let u=Dg(c,r,i,a);return u?[u]:[]}function ZC(e,t,n,r,i){let a=e.getSource(t)??``,o=oC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=hC(n.endpoints[0]),t=hC(n.endpoints[1]),s=gC(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:`
|
|
27
|
+
`+c+`
|
|
28
|
+
`}]}let{declaration:s}=o,{body:c}=s;if(c instanceof H){let e=Dg(s,r,i,a);if(e)return[e];let t=Dg(c,r,i,a);return t?[t]:[]}let l=Dg(s,r,i,a);return l?[l]:[]}function MC(e,t,n,r,i){let a=e.getSource(t)??``,o=oC(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=_C(n.endpoints[0]),t=_C(n.endpoints[1]),s=vC(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:`
|
|
32
29
|
|
|
33
30
|
`+c+`
|
|
34
|
-
`}]}let s=Dg(o.node,r,i,a);return s?[s]:[]}function
|
|
35
|
-
`)}function
|
|
31
|
+
`}]}let s=Dg(o.node,r,i,a);return s?[s]:[]}function NC(e){let t=[],n=new PS(e,Do).lex();if(n.getErrors().length>0)return t;let i=new RS(e,n.getValue(),new dm,Do).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?j(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function PC(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function FC(e,t){e.push(` ${t} { * }`)}function IC(e){return e==null?`null`:e.length===0?`empty`:`items`}function LC(e,t){let n=`DiagramView ${R_(e)} {`,r=e=>R_(e.name),i=t?.tables?.map(e=>{let t=R_(e.name);return e.schemaName===`public`?t:`${R_(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:IC(t.tables),tableGroups:IC(t.tableGroups),schemas:IC(t.schemas),stickyNotes:IC(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`&&PC(d,`Tables`,i),c.tableGroups===`items`&&PC(d,`TableGroups`,a),c.schemas===`items`&&PC(d,`Schemas`,o)):u&&FC(d,`Tables`),c.stickyNotes===`items`?PC(d,`Notes`,s):c.stickyNotes===`empty`&&FC(d,`Notes`),d.push(`}`),d.join(`
|
|
32
|
+
`)}function RC(e,t,n){let r=this.getSource(e)??``,i=n??NC(r),a=[];for(let e of t){let t=zC(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:aC(r,a,!0),edits:a}}function zC(e,t,n){switch(t.operation){case`create`:return BC(e,t,n);case`update`:return VC(e,t,n);case`delete`:return HC(e,t,n);default:return[]}}function BC(e,t,n){if(n.find(e=>e.name===t.name))return VC(e,t,n);let r=`
|
|
36
33
|
|
|
37
|
-
`+
|
|
38
|
-
`;return[{start:e.length,end:e.length,newText:r}]}function
|
|
34
|
+
`+LC(t.name,t.visibleEntities)+`
|
|
35
|
+
`;return[{start:e.length,end:e.length,newText:r}]}function VC(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=LC(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function HC(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]===`
|
|
39
36
|
`;){i--,i>0&&e[i-1]===`\r`&&i--;let t=e.lastIndexOf(`
|
|
40
37
|
`,i-1)+1;if(e.substring(t,i).trim()!==``){i=r.startIndex,i>0&&e[i-1]===`
|
|
41
38
|
`&&(i--,i>0&&e[i-1]===`\r`&&i--);break}}return a<e.length&&e[a]===`\r`&&a++,a<e.length&&e[a]===`
|
|
42
|
-
`&&a++,[{start:i,end:a,newText:``}]}
|
|
39
|
+
`&&a++,[{start:i,end:a,newText:``}]}function UC(e,t){let n=KC(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:K_(t)}}function WC(e){let t=KC(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function GC(e,t){if(KC(e)||!(e instanceof R))return;let n=qC(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${K_(t)}\n`};let r=e.body;if(r instanceof H){let n=r.args.find(e=>e instanceof W);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${K_(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${K_(t)}]`}}}function KC(e){if(!(e instanceof R))return;let t=e.body;if(t&&!(t instanceof H))for(let e of t.body){if(!(e instanceof R)||!e.isKind(r.Note))continue;let t=JC(e);if(t)return{kind:fm.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof H?t.args.find(e=>e instanceof W):void 0);if(n)return YC(n)}function qC(e){let t=e.body;if(!(!t||t instanceof H)&&t.blockCloseBrace)return t.blockCloseBrace.start}function JC(e){let t=e.body;if(t instanceof H)return t.callee??void 0;if(t instanceof U&&t.body[0]instanceof H)return t.body[0].callee??void 0}function YC(e){let t=T(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:fm.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function XC(e,t){let n=this.getSource(e)??``,r=[];for(let i of t)r.push(...nw(this,e,n,i));return r.sort((e,t)=>t.start-e.start),{newDbml:aC(n,r,!0),edits:r}}function ZC(e){let t=new PS(e,Do).lex();if(t.getErrors().length>0)return[];let n=new RS(e,t.getValue(),new dm,Do).parse();return n.getErrors().length>0?[]:$C(n.getValue().ast)}function QC(e,t){return`Dep [color: ${t}] {\n ${_C(e.upstream)} -> ${_C(e.downstream)}\n}`}function $C(e){let t=[];for(let n of e.declarations){if(!(n instanceof R)||!n.isKind(r.Dep))continue;let e=[],i=n.body;if(i instanceof H){if(i.callee instanceof V){let t=ew(i.callee);t&&e.push(t)}}else if(i){for(let t of i.body)if(t instanceof H&&t.callee instanceof V){let n=ew(t.callee);n&&e.push(n)}}t.push({startIndex:n.start,endIndex:n.end,declaration:n,edges:e})}return t}function ew(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=j(i),s=j(a);if(!o||!s)return;let c=o.length>1&&s.length>1,l=tw(o,c),u=tw(s,c);if(!(!l||!u))return{upstream:l,downstream:u}}function tw(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 nw(e,t,n,r){let i=fC(e,t,r.edge);switch(r.operation){case`create`:return iw(n,r,i);case`update`:return i?.kind===`block`?rw(r,i.declaration,n):[];case`remove`:return i?.kind===`block`?rw({...r,color:void 0,note:void 0},i.declaration,n):[];default:return[]}}function rw(e,t,n){let r=[];if(e.color!==void 0){let a=Dg(t,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=WC(t);e&&r.push(e)}else if(e.note!==void 0){let n=UC(t,e.note)??GC(t,e.note);n&&r.push(n)}return r}function iw(e,t,n){if(n?.kind===`block`)return rw(t,n.declaration,e);let r=QC(t.edge,t.color??``),i={start:e.length,end:e.length,newText:`
|
|
40
|
+
|
|
41
|
+
`+r+`
|
|
42
|
+
`};return n?.kind===`inline`?[{start:n.fullStart,end:n.fullEnd,newText:``},i]:[i]}var aw=Symbol(`COMPUTING`),ow=class{constructor(e){this.layout=e,this.nodeIdGenerator=new dm,this.symbolIdGenerator=new Up,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(YS),this.parseProject=this.globalQuery(XS),this.validateNode=this.localQuery(yy),this.validateFile=this.localQuery(NS),this.nodeFullname=this.localQuery(xy),this.nodeAlias=this.localQuery(Sy),this.nodeSettings=this.localQuery(by),this.canonicalName=this.globalQuery(mS),this.bindNode=this.globalQuery(Ev),this.bindFile=this.globalQuery(kS),this.bindProject=this.globalQuery(AS),this.interpretSymbol=this.globalQuery(Ov),this.interpretMetadata=this.globalQuery(kv),this.interpretFile=this.globalQuery(jS),this.interpretProject=this.globalQuery(MS),this.nodeSymbol=this.globalQuery(Cv),this.nodeMetadata=this.globalQuery(Dv),this.symbolMembers=this.globalQuery(wv),this.symbolMembersLookupMap=this.globalQuery(ZS),this.lookupMembers=this.globalQuery(QS),this.nodeReferee=this.globalQuery(Tv),this.resolutionIndex=this.globalQuery(eC),this.symbolReferences=this.globalQuery(nC),this.symbolParent=this.globalQuery(tC),this.symbolMetadata=this.globalQuery(rC),this.symbolAliases=this.globalQuery($S),this.symbolUses=this.globalQuery(iC),this.fileDependencies=this.localQuery(_S),this.reachableFiles=this.globalQuery(yS),this.usableMembers=this.globalQuery(l_),this.nodeAtPosition=this.localQuery(OS),this.renameTable=TC.bind(this),this.updateElementSetting=kC.bind(this),this.updateElementSettingEdit=OC.bind(this),this.syncDiagramView=RC.bind(this),this.syncDep=XC.bind(this),this.token={invalidStream:this.localQuery(DS),flatStream:this.localQuery(ES)},this.parse={source:e=>this.getSource(e)||``,ast:(e=Do)=>bS.call(this,e),errors:(e=Do)=>xS.call(this,e),warnings:(e=Do)=>SS.call(this,e),tokens:(e=Do)=>CS.call(this,e),rawDb:(e=Do)=>wS.call(this,e),publicSymbolTable:(e=Do)=>TS.call(this,e)},this.container={stack:this.localQuery(lS),token:this.localQuery(uS),element:this.localQuery(dS),scope:this.localQuery(fS),scopeKind:this.localQuery(pS)}}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 vS(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?fh(n[0]):n.map(e=>fh(e)).join(`\0`),a=r.get(i);if(a){if(a===aw)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,aw);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?fh(n[0]):n.map(e=>fh(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===aw)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,aw);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}initMonacoServices(e){let t=e?.autocompletion?.triggerCharacters??[];return{definitionProvider:new Mb(this),referenceProvider:new Pb(this),autocompletionProvider:new Dx(this,{triggerCharacters:t}),diagnosticsProvider:new Nb(this),codeActionProvider:new jb(this)}}},sw=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}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(xo.from)}getEntrypoints(){return[...this.files.keys()].map(xo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=Om,exports.AttributeNode=z,exports.BlockExpressionNode=U,exports.CARDINALITY_MANY=cf,exports.CARDINALITY_MAYBE=of,exports.CARDINALITY_ONE=af,exports.CARDINALITY_SOME=sf,exports.CallExpressionNode=Sm,exports.CommaExpressionNode=bm,exports.CompileError=w,exports.CompileErrorCode=C,exports.Compiler=ow,exports.CompletionItemInsertTextRule=Y,exports.CompletionItemKind=J,exports.DBMLCodeActionProvider=jb,exports.DBMLCompletionItemProvider=Dx,exports.DBMLDefinitionProvider=Mb,exports.DBMLDiagnosticsProvider=Nb,exports.DBMLReferencesProvider=Pb,exports.DEFAULT_ENTRY=Do,exports.ElementDeclarationNode=R,exports.ElementKind=r,exports.EmptyNode=Dm,exports.FALSY_VALUES=wp,exports.Filepath=xo,exports.FunctionApplicationNode=H,exports.FunctionExpressionNode=vm,exports.GroupExpressionNode=xm,exports.IdentifierStreamNode=gm,exports.InfixExpressionNode=V,exports.ListExpressionNode=W,exports.LiteralNode=Cm,exports.MarkerSeverity=Ob,exports.MemoryProjectLayout=sw,exports.MetadataKind=Um,exports.PostfixExpressionNode=_m,exports.PrefixExpressionNode=B,exports.PrimaryExpressionNode=Em,exports.ProgramNode=L,exports.ScopeKind=Q,exports.SymbolKind=F,exports.SyntaxNode=I,exports.SyntaxNodeIdGenerator=dm,exports.SyntaxNodeKind=fm,exports.SyntaxToken=Ha,exports.SyntaxTokenKind=_,exports.TRUTHY_VALUES=Cp,exports.TupleExpressionNode=ym,exports.UNHANDLED=t,exports.Uri=_b,exports.UseDeclarationNode=pm,exports.UseSpecifierListNode=hm,exports.UseSpecifierNode=mm,exports.VariableNode=Tm,exports.WildcardNode=wm,exports.addDoubleQuoteIfNeeded=R_,exports.dbmlLanguageConfig=sS,exports.dbmlMonarchTokensProvider=cS,exports.escapeString=V_,exports.extractNumericLiteral=pp,exports.extractSignedNumber=bp,exports.findDepBlocks=ZC,exports.findDiagramViewBlocks=NC,exports.formatRecordValue=H_,exports.getMultiplicities=df,exports.getRecordValueType=Wo,exports.getRelationshipOp=_f,exports.isBinaryType=Vo,exports.isBooleanType=zo,exports.isDateTimeType=Ho,exports.isEmptyStringLiteral=vp,exports.isEndpointManySide=pf,exports.isEndpointOneSide=ff,exports.isEndpointOptional=mf,exports.isEndpointRequired=hf,exports.isFloatType=Lo,exports.isFunctionExpression=yp,exports.isIntegerType=Io,exports.isNullish=_p,exports.isNumericType=Ro,exports.isOp=Ba,exports.isOpToken=Va,exports.isSerialType=Uo,exports.isStringType=Bo,exports.isTriviaToken=za,exports.isValidIdentifier=L_,exports.makeCardinalityOptional=vf,exports.makeCardinalityRequired=yf,exports.makeRelationshipRequired=gf,exports.normalizeQualifiedName=z_,exports.normalizeTypeName=Fo,exports.parseCardinality=rf,exports.splitQualifiedIdentifier=U_,exports.tryExtractBoolean=Tp,exports.tryExtractDateTime=jp,exports.tryExtractEnum=Ep,exports.tryExtractInteger=Sp,exports.tryExtractNumeric=xp,exports.tryExtractString=Dp,exports.unescapeString=B_,exports.validateForeignKeys=bg,exports.validatePrimaryKey=ug,exports.validateUnique=gg;
|
package/dist/dbml-parse.mjs
CHANGED
|
@@ -16491,23 +16491,56 @@ function cC(e, t, n) {
|
|
|
16491
16491
|
return sC(r, i, s) && sC(a, o, c) || sC(r, i, c) && sC(a, o, s);
|
|
16492
16492
|
}
|
|
16493
16493
|
//#endregion
|
|
16494
|
+
//#region src/compiler/queries/transform/utils/dep.ts
|
|
16495
|
+
function lC(e, t, n) {
|
|
16496
|
+
let r = hC(e, t, pC(n.schemaName), n.tableName, F.Table);
|
|
16497
|
+
return {
|
|
16498
|
+
table: r,
|
|
16499
|
+
columns: (n.fieldNames ?? []).map((t) => r ? e.lookupMembers(r, F.Column, t) : void 0)
|
|
16500
|
+
};
|
|
16501
|
+
}
|
|
16502
|
+
function uC(e, t) {
|
|
16503
|
+
let n = e?.originalSymbol.declaration;
|
|
16504
|
+
return !!n && n === t?.originalSymbol.declaration;
|
|
16505
|
+
}
|
|
16506
|
+
function dC(e, t, n) {
|
|
16507
|
+
return !uC(e, n.table) || t.length !== n.columns.length ? !1 : t.every((e, t) => uC(e, n.columns[t]));
|
|
16508
|
+
}
|
|
16509
|
+
function fC(e, n, r) {
|
|
16510
|
+
let a = e.parseFile(n).getValue().ast, o = e.nodeSymbol(a).getFiltered(t);
|
|
16511
|
+
if (!o) return;
|
|
16512
|
+
let s = lC(e, n, r.upstream), c = lC(e, n, r.downstream);
|
|
16513
|
+
if (!s.table || !c.table) return;
|
|
16514
|
+
let l = e.getSource(n) ?? "";
|
|
16515
|
+
for (let t of e.symbolMetadata(o)) {
|
|
16516
|
+
if (!(t instanceof Km)) continue;
|
|
16517
|
+
let n = t.upstreamTables(e), r = t.upstreamColumns(e), a = t.downstreamTables(e), o = t.downstreamColumns(e);
|
|
16518
|
+
if (!n.some((e, t) => dC(n[t], r[t] ?? [], s) && dC(a[t], o[t] ?? [], c))) continue;
|
|
16519
|
+
if (t.declaration instanceof R) return {
|
|
16520
|
+
kind: "block",
|
|
16521
|
+
declaration: t.declaration
|
|
16522
|
+
};
|
|
16523
|
+
let u = t.declaration.parentOfKind(H);
|
|
16524
|
+
if (!u) continue;
|
|
16525
|
+
let d = Og(u, i.Dep, l);
|
|
16526
|
+
if (!d) continue;
|
|
16527
|
+
let f = t.declaration.value;
|
|
16528
|
+
if (!(f instanceof B)) continue;
|
|
16529
|
+
let p = f.op?.value;
|
|
16530
|
+
if (p) return {
|
|
16531
|
+
kind: "inline",
|
|
16532
|
+
op: p,
|
|
16533
|
+
fullStart: d.start,
|
|
16534
|
+
fullEnd: d.end
|
|
16535
|
+
};
|
|
16536
|
+
}
|
|
16537
|
+
}
|
|
16538
|
+
//#endregion
|
|
16494
16539
|
//#region src/compiler/queries/transform/utils/index.ts
|
|
16495
|
-
function
|
|
16540
|
+
function pC(e) {
|
|
16496
16541
|
return e && e.length > 0 ? e : v;
|
|
16497
16542
|
}
|
|
16498
|
-
function
|
|
16499
|
-
if (lC(e.schemaName) !== lC(t.schemaName) || e.tableName !== t.tableName) return !1;
|
|
16500
|
-
let n = e.fieldNames ?? [], r = t.fieldNames ?? [];
|
|
16501
|
-
return n.length === r.length ? n.every((e, t) => e === r[t]) : !1;
|
|
16502
|
-
}
|
|
16503
|
-
function dC(e, t) {
|
|
16504
|
-
if (lC(e.schemaName) !== lC(t.schemaName) || e.tableName !== t.tableName) return !1;
|
|
16505
|
-
let n = t.fieldNames ?? [];
|
|
16506
|
-
if (n.length === 0) return !0;
|
|
16507
|
-
let r = e.fieldNames ?? [];
|
|
16508
|
-
return r.length === n.length ? r.every((e, t) => e === n[t]) : !1;
|
|
16509
|
-
}
|
|
16510
|
-
function fC(e) {
|
|
16543
|
+
function mC(e) {
|
|
16511
16544
|
if (typeof e != "string") return {
|
|
16512
16545
|
schema: e.schema ?? "public",
|
|
16513
16546
|
table: e.table
|
|
@@ -16531,33 +16564,33 @@ function fC(e) {
|
|
|
16531
16564
|
table: n
|
|
16532
16565
|
};
|
|
16533
16566
|
}
|
|
16534
|
-
function
|
|
16567
|
+
function hC(e, n, r, i, a = F.Table) {
|
|
16535
16568
|
let o = e.parseFile(n).getValue().ast, s = e.nodeSymbol(o).getFiltered(t);
|
|
16536
16569
|
if (!s) return;
|
|
16537
16570
|
if (r === "public") return e.lookupMembers(s, a, i) ?? void 0;
|
|
16538
16571
|
let c = e.lookupMembers(s, F.Schema, r);
|
|
16539
16572
|
if (c) return e.lookupMembers(c, a, i) ?? void 0;
|
|
16540
16573
|
}
|
|
16541
|
-
function
|
|
16574
|
+
function gC(e) {
|
|
16542
16575
|
return e.startsWith("\"") && e.endsWith("\"") && e.length >= 2 ? e.slice(1, -1) : e;
|
|
16543
16576
|
}
|
|
16544
|
-
function
|
|
16577
|
+
function _C(e) {
|
|
16545
16578
|
let t = [];
|
|
16546
16579
|
e.schemaName && e.schemaName !== "public" && t.push(R_(e.schemaName)), t.push(R_(e.tableName));
|
|
16547
16580
|
for (let n of e.fieldNames ?? []) t.push(R_(n));
|
|
16548
16581
|
return t.join(".");
|
|
16549
16582
|
}
|
|
16550
|
-
function
|
|
16583
|
+
function vC(e, t) {
|
|
16551
16584
|
return t === void 0 ? e : t === null ? "" : `${e}: ${t}`;
|
|
16552
16585
|
}
|
|
16553
16586
|
//#endregion
|
|
16554
16587
|
//#region src/compiler/queries/transform/renameTable.ts
|
|
16555
|
-
function
|
|
16588
|
+
function yC(e, t) {
|
|
16556
16589
|
if (!e || !(e instanceof R)) return !1;
|
|
16557
16590
|
let n = e.name;
|
|
16558
16591
|
return n ? t.substring(n.start, n.end).includes("\"") : !1;
|
|
16559
16592
|
}
|
|
16560
|
-
function
|
|
16593
|
+
function bC(e, t, n) {
|
|
16561
16594
|
let r = !L_(t), i = !L_(e), a = n || r, o = n || i;
|
|
16562
16595
|
return {
|
|
16563
16596
|
schema: e,
|
|
@@ -16568,10 +16601,10 @@ function vC(e, t, n) {
|
|
|
16568
16601
|
shouldQuoteTable: a
|
|
16569
16602
|
};
|
|
16570
16603
|
}
|
|
16571
|
-
function
|
|
16572
|
-
return n === i && r === a ? !1 :
|
|
16604
|
+
function xC(e, t, n, r, i, a) {
|
|
16605
|
+
return n === i && r === a ? !1 : hC(e, t, i, a) !== void 0;
|
|
16573
16606
|
}
|
|
16574
|
-
function
|
|
16607
|
+
function SC(e, t, n) {
|
|
16575
16608
|
let r = e.start - 1;
|
|
16576
16609
|
for (; r >= 0 && /\s/.test(n[r]);) r--;
|
|
16577
16610
|
if (r < 0 || n[r] !== ".") return null;
|
|
@@ -16586,19 +16619,19 @@ function bC(e, t, n) {
|
|
|
16586
16619
|
for (a = r + 1; r >= 0 && /[a-zA-Z0-9_]/.test(n[r]);) r--;
|
|
16587
16620
|
i = r + 1;
|
|
16588
16621
|
}
|
|
16589
|
-
return
|
|
16622
|
+
return gC(n.substring(i, a)) === t ? {
|
|
16590
16623
|
start: i,
|
|
16591
16624
|
end: e.end
|
|
16592
16625
|
} : null;
|
|
16593
16626
|
}
|
|
16594
|
-
function
|
|
16627
|
+
function CC(e) {
|
|
16595
16628
|
return e.schema === "public" ? e.formattedTable : `${e.formattedSchema}.${e.formattedTable}`;
|
|
16596
16629
|
}
|
|
16597
|
-
function
|
|
16598
|
-
let a = [], o = /* @__PURE__ */ new Set(), s =
|
|
16630
|
+
function wC(e, t, n, r, i) {
|
|
16631
|
+
let a = [], o = /* @__PURE__ */ new Set(), s = CC(r);
|
|
16599
16632
|
for (let r of e) {
|
|
16600
|
-
if (
|
|
16601
|
-
let e =
|
|
16633
|
+
if (gC(i.substring(r.start, r.end)) !== n) continue;
|
|
16634
|
+
let e = SC(r, t, i) ?? {
|
|
16602
16635
|
start: r.start,
|
|
16603
16636
|
end: r.end
|
|
16604
16637
|
}, c = `${e.start}-${e.end}`;
|
|
@@ -16610,19 +16643,19 @@ function SC(e, t, n, r, i) {
|
|
|
16610
16643
|
}
|
|
16611
16644
|
return a;
|
|
16612
16645
|
}
|
|
16613
|
-
function
|
|
16614
|
-
let i =
|
|
16615
|
-
if (!u || u instanceof cm ||
|
|
16646
|
+
function TC(e, n, r) {
|
|
16647
|
+
let i = mC(n), a = mC(r), o = i.schema, s = i.table, c = a.schema, l = a.table, u = hC(this, e, o, s);
|
|
16648
|
+
if (!u || u instanceof cm || xC(this, e, o, s, c, l)) return /* @__PURE__ */ new Map();
|
|
16616
16649
|
if (u instanceof lm && u.useSpecifierDeclaration instanceof mm && u.useSpecifierDeclaration.alias) {
|
|
16617
16650
|
let n = u.useSpecifierDeclaration;
|
|
16618
|
-
if (this.nodeAlias(n).getFiltered(t) === s) return
|
|
16651
|
+
if (this.nodeAlias(n).getFiltered(t) === s) return EC(this, e, n, u, c, l);
|
|
16619
16652
|
}
|
|
16620
|
-
return
|
|
16653
|
+
return DC(this, u, o, s, c, l);
|
|
16621
16654
|
}
|
|
16622
|
-
function
|
|
16655
|
+
function EC(e, t, n, r, i, a) {
|
|
16623
16656
|
let o = e.getSource(t) ?? "";
|
|
16624
16657
|
if (!n.alias) return /* @__PURE__ */ new Map();
|
|
16625
|
-
let s =
|
|
16658
|
+
let s = bC(i, a, o.substring(n.alias.start, n.alias.end).includes("\"")), c = [];
|
|
16626
16659
|
c.push({
|
|
16627
16660
|
start: n.alias.start,
|
|
16628
16661
|
end: n.alias.end,
|
|
@@ -16636,12 +16669,12 @@ function wC(e, t, n, r, i, a) {
|
|
|
16636
16669
|
});
|
|
16637
16670
|
return new Map([[t.absolute, aC(o, c)]]);
|
|
16638
16671
|
}
|
|
16639
|
-
function
|
|
16672
|
+
function DC(e, t, n, r, i, a) {
|
|
16640
16673
|
let o = t.originalSymbol, s = o.declaration;
|
|
16641
16674
|
if (!s || !(s instanceof R)) return /* @__PURE__ */ new Map();
|
|
16642
16675
|
let c = s.filepath;
|
|
16643
16676
|
if (!c) return /* @__PURE__ */ new Map();
|
|
16644
|
-
let l =
|
|
16677
|
+
let l = bC(i, a, yC(s, e.getSource(c) ?? "")), u = /* @__PURE__ */ new Map(), d = (e, t) => {
|
|
16645
16678
|
let n = e.absolute, r = u.get(n);
|
|
16646
16679
|
r || (r = {
|
|
16647
16680
|
fp: e,
|
|
@@ -16651,13 +16684,13 @@ function TC(e, t, n, r, i, a) {
|
|
|
16651
16684
|
f && d(c, {
|
|
16652
16685
|
start: f.start,
|
|
16653
16686
|
end: f.end,
|
|
16654
|
-
newText:
|
|
16687
|
+
newText: CC(l)
|
|
16655
16688
|
});
|
|
16656
16689
|
let p = e.symbolReferences(o);
|
|
16657
16690
|
for (let t of p) {
|
|
16658
16691
|
if (t === f) continue;
|
|
16659
16692
|
let i = t.filepath, a = e.getSource(i) ?? "";
|
|
16660
|
-
for (let e of
|
|
16693
|
+
for (let e of wC([t], n, r, l, a)) d(i, e);
|
|
16661
16694
|
}
|
|
16662
16695
|
let m = /* @__PURE__ */ new Map();
|
|
16663
16696
|
for (let { fp: t, edits: n } of u.values()) {
|
|
@@ -16667,26 +16700,204 @@ function TC(e, t, n, r, i, a) {
|
|
|
16667
16700
|
return m;
|
|
16668
16701
|
}
|
|
16669
16702
|
//#endregion
|
|
16703
|
+
//#region src/compiler/queries/transform/updateElementSetting.ts
|
|
16704
|
+
function OC(e, t, n, r) {
|
|
16705
|
+
if (t.kind === "dep") return jC(this, e, t, n, r);
|
|
16706
|
+
if (t.kind === "ref") return MC(this, e, t, n, r);
|
|
16707
|
+
let i = AC(this, e, t);
|
|
16708
|
+
if (!i) return [];
|
|
16709
|
+
let a = Dg(i, n, r, this.getSource(e) ?? "");
|
|
16710
|
+
return a ? [a] : [];
|
|
16711
|
+
}
|
|
16712
|
+
function kC(e, t, n, r) {
|
|
16713
|
+
let i = this.getSource(e) ?? "", a = this.updateElementSettingEdit(e, t, n, r);
|
|
16714
|
+
return a.length === 0 ? i : aC(i, a);
|
|
16715
|
+
}
|
|
16716
|
+
function AC(e, t, n) {
|
|
16717
|
+
let r = ("schema" in n ? n.schema : void 0) ?? "public";
|
|
16718
|
+
switch (n.kind) {
|
|
16719
|
+
case F.Column: {
|
|
16720
|
+
let i = hC(e, t, r, n.table, F.Table);
|
|
16721
|
+
return i ? e.lookupMembers(i, F.Column, n.column)?.declaration : void 0;
|
|
16722
|
+
}
|
|
16723
|
+
case F.Table: return hC(e, t, r, n.table)?.declaration;
|
|
16724
|
+
case F.Enum:
|
|
16725
|
+
case F.StickyNote:
|
|
16726
|
+
case F.TableGroup: return hC(e, t, r, n.name, n.kind)?.declaration;
|
|
16727
|
+
case F.Schema: return hC(e, t, n.schema, "", F.Schema)?.declaration;
|
|
16728
|
+
default: return;
|
|
16729
|
+
}
|
|
16730
|
+
}
|
|
16731
|
+
function jC(e, t, n, r, i) {
|
|
16732
|
+
let a = e.getSource(t) ?? "", o = fC(e, t, n);
|
|
16733
|
+
if (!o) return [];
|
|
16734
|
+
if (o.kind === "inline") {
|
|
16735
|
+
if (i === null) return [];
|
|
16736
|
+
let e = _C(n.upstream), t = _C(n.downstream), s = vC(r, i), c = s ? `Dep [${s}] {\n ${e} -> ${t}\n}` : `Dep {\n ${e} -> ${t}\n}`;
|
|
16737
|
+
return [{
|
|
16738
|
+
start: o.fullStart,
|
|
16739
|
+
end: o.fullEnd,
|
|
16740
|
+
newText: ""
|
|
16741
|
+
}, {
|
|
16742
|
+
start: a.length,
|
|
16743
|
+
end: a.length,
|
|
16744
|
+
newText: "\n\n" + c + "\n"
|
|
16745
|
+
}];
|
|
16746
|
+
}
|
|
16747
|
+
let { declaration: s } = o, { body: c } = s;
|
|
16748
|
+
if (c instanceof H) {
|
|
16749
|
+
let e = Dg(s, r, i, a);
|
|
16750
|
+
if (e) return [e];
|
|
16751
|
+
let t = Dg(c, r, i, a);
|
|
16752
|
+
return t ? [t] : [];
|
|
16753
|
+
}
|
|
16754
|
+
let l = Dg(s, r, i, a);
|
|
16755
|
+
return l ? [l] : [];
|
|
16756
|
+
}
|
|
16757
|
+
function MC(e, t, n, r, i) {
|
|
16758
|
+
let a = e.getSource(t) ?? "", o = oC(e, t, n);
|
|
16759
|
+
if (!o) return [];
|
|
16760
|
+
if (o.kind === "inline") {
|
|
16761
|
+
if (i === null) return [];
|
|
16762
|
+
let e = _C(n.endpoints[0]), t = _C(n.endpoints[1]), s = vC(r, i), c = s ? `Ref: ${e} ${o.op} ${t} [${s}]` : `Ref: ${e} ${o.op} ${t}`;
|
|
16763
|
+
return [{
|
|
16764
|
+
start: o.fullStart,
|
|
16765
|
+
end: o.fullEnd,
|
|
16766
|
+
newText: ""
|
|
16767
|
+
}, {
|
|
16768
|
+
start: a.length,
|
|
16769
|
+
end: a.length,
|
|
16770
|
+
newText: "\n\n" + c + "\n"
|
|
16771
|
+
}];
|
|
16772
|
+
}
|
|
16773
|
+
let s = Dg(o.node, r, i, a);
|
|
16774
|
+
return s ? [s] : [];
|
|
16775
|
+
}
|
|
16776
|
+
//#endregion
|
|
16777
|
+
//#region src/compiler/queries/transform/syncDiagramView.ts
|
|
16778
|
+
function NC(e) {
|
|
16779
|
+
let t = [], n = new PS(e, Do).lex();
|
|
16780
|
+
if (n.getErrors().length > 0) return t;
|
|
16781
|
+
let i = new RS(e, n.getValue(), new dm(), Do).parse();
|
|
16782
|
+
if (i.getErrors().length > 0) return t;
|
|
16783
|
+
let a = i.getValue().ast;
|
|
16784
|
+
for (let e of a.declarations) if (e.isKind(r.DiagramView)) {
|
|
16785
|
+
let n = e.name ? j(e.name) ?? [] : [], r = n.length > 0 ? n[n.length - 1] : "";
|
|
16786
|
+
t.push({
|
|
16787
|
+
name: r,
|
|
16788
|
+
startIndex: e.start,
|
|
16789
|
+
endIndex: e.end
|
|
16790
|
+
});
|
|
16791
|
+
}
|
|
16792
|
+
return t;
|
|
16793
|
+
}
|
|
16794
|
+
function PC(e, t, n) {
|
|
16795
|
+
e.push(` ${t} {`), n.forEach((t) => e.push(` ${t}`)), e.push(" }");
|
|
16796
|
+
}
|
|
16797
|
+
function FC(e, t) {
|
|
16798
|
+
e.push(` ${t} { * }`);
|
|
16799
|
+
}
|
|
16800
|
+
function IC(e) {
|
|
16801
|
+
return e == null ? "null" : e.length === 0 ? "empty" : "items";
|
|
16802
|
+
}
|
|
16803
|
+
function LC(e, t) {
|
|
16804
|
+
let n = `DiagramView ${R_(e)} {`, r = (e) => R_(e.name), i = t?.tables?.map((e) => {
|
|
16805
|
+
let t = R_(e.name);
|
|
16806
|
+
return e.schemaName === "public" ? t : `${R_(e.schemaName)}.${t}`;
|
|
16807
|
+
}) ?? [], a = t?.tableGroups?.map(r) ?? [], o = t?.schemas?.map(r) ?? [], s = t?.stickyNotes?.map(r) ?? [];
|
|
16808
|
+
if (!t) return `${n}\n}`;
|
|
16809
|
+
let c = {
|
|
16810
|
+
tables: IC(t.tables),
|
|
16811
|
+
tableGroups: IC(t.tableGroups),
|
|
16812
|
+
schemas: IC(t.schemas),
|
|
16813
|
+
stickyNotes: IC(t.stickyNotes)
|
|
16814
|
+
};
|
|
16815
|
+
if (Object.values(c).every((e) => e === "null")) return `${n}\n}`;
|
|
16816
|
+
if (Object.values(c).every((e) => e === "empty")) return `${n}\n *\n}`;
|
|
16817
|
+
let l = c.tables === "items" || c.tableGroups === "items" || c.schemas === "items", u = c.tables === "empty" && c.tableGroups === "empty" && c.schemas === "empty", d = [n];
|
|
16818
|
+
return l ? (c.tables === "items" && PC(d, "Tables", i), c.tableGroups === "items" && PC(d, "TableGroups", a), c.schemas === "items" && PC(d, "Schemas", o)) : u && FC(d, "Tables"), c.stickyNotes === "items" ? PC(d, "Notes", s) : c.stickyNotes === "empty" && FC(d, "Notes"), d.push("}"), d.join("\n");
|
|
16819
|
+
}
|
|
16820
|
+
function RC(e, t, n) {
|
|
16821
|
+
let r = this.getSource(e) ?? "", i = n ?? NC(r), a = [];
|
|
16822
|
+
for (let e of t) {
|
|
16823
|
+
let t = zC(r, e, i);
|
|
16824
|
+
a.push(...t);
|
|
16825
|
+
}
|
|
16826
|
+
return a.sort((e, t) => t.start - e.start), {
|
|
16827
|
+
newDbml: aC(r, a, !0),
|
|
16828
|
+
edits: a
|
|
16829
|
+
};
|
|
16830
|
+
}
|
|
16831
|
+
function zC(e, t, n) {
|
|
16832
|
+
switch (t.operation) {
|
|
16833
|
+
case "create": return BC(e, t, n);
|
|
16834
|
+
case "update": return VC(e, t, n);
|
|
16835
|
+
case "delete": return HC(e, t, n);
|
|
16836
|
+
default: return [];
|
|
16837
|
+
}
|
|
16838
|
+
}
|
|
16839
|
+
function BC(e, t, n) {
|
|
16840
|
+
if (n.find((e) => e.name === t.name)) return VC(e, t, n);
|
|
16841
|
+
let r = "\n\n" + LC(t.name, t.visibleEntities) + "\n";
|
|
16842
|
+
return [{
|
|
16843
|
+
start: e.length,
|
|
16844
|
+
end: e.length,
|
|
16845
|
+
newText: r
|
|
16846
|
+
}];
|
|
16847
|
+
}
|
|
16848
|
+
function VC(e, t, n) {
|
|
16849
|
+
let r = n.find((e) => e.name === t.name);
|
|
16850
|
+
if (!r) return [];
|
|
16851
|
+
let i = [];
|
|
16852
|
+
if (t.newName || t.visibleEntities) {
|
|
16853
|
+
let e = LC(t.newName || t.name, t.visibleEntities);
|
|
16854
|
+
i.push({
|
|
16855
|
+
start: r.startIndex,
|
|
16856
|
+
end: r.endIndex,
|
|
16857
|
+
newText: e
|
|
16858
|
+
});
|
|
16859
|
+
}
|
|
16860
|
+
return i;
|
|
16861
|
+
}
|
|
16862
|
+
function HC(e, t, n) {
|
|
16863
|
+
let r = n.find((e) => e.name === t.name);
|
|
16864
|
+
if (!r) return [];
|
|
16865
|
+
let i = r.startIndex, a = r.endIndex;
|
|
16866
|
+
for (; i > 0 && e[i - 1] === "\n";) {
|
|
16867
|
+
i--, i > 0 && e[i - 1] === "\r" && i--;
|
|
16868
|
+
let t = e.lastIndexOf("\n", i - 1) + 1;
|
|
16869
|
+
if (e.substring(t, i).trim() !== "") {
|
|
16870
|
+
i = r.startIndex, i > 0 && e[i - 1] === "\n" && (i--, i > 0 && e[i - 1] === "\r" && i--);
|
|
16871
|
+
break;
|
|
16872
|
+
}
|
|
16873
|
+
}
|
|
16874
|
+
return a < e.length && e[a] === "\r" && a++, a < e.length && e[a] === "\n" && a++, [{
|
|
16875
|
+
start: i,
|
|
16876
|
+
end: a,
|
|
16877
|
+
newText: ""
|
|
16878
|
+
}];
|
|
16879
|
+
}
|
|
16880
|
+
//#endregion
|
|
16670
16881
|
//#region src/core/utils/note.ts
|
|
16671
|
-
function
|
|
16672
|
-
let n =
|
|
16882
|
+
function UC(e, t) {
|
|
16883
|
+
let n = KC(e);
|
|
16673
16884
|
if (n) return {
|
|
16674
16885
|
start: n.noteValueStart,
|
|
16675
16886
|
end: n.noteValueEnd,
|
|
16676
16887
|
newText: K_(t)
|
|
16677
16888
|
};
|
|
16678
16889
|
}
|
|
16679
|
-
function
|
|
16680
|
-
let t =
|
|
16890
|
+
function WC(e) {
|
|
16891
|
+
let t = KC(e);
|
|
16681
16892
|
if (t) return {
|
|
16682
16893
|
start: t.fullNoteStart,
|
|
16683
16894
|
end: t.fullNoteEnd,
|
|
16684
16895
|
newText: ""
|
|
16685
16896
|
};
|
|
16686
16897
|
}
|
|
16687
|
-
function
|
|
16688
|
-
if (
|
|
16689
|
-
let n =
|
|
16898
|
+
function GC(e, t) {
|
|
16899
|
+
if (KC(e) || !(e instanceof R)) return;
|
|
16900
|
+
let n = qC(e);
|
|
16690
16901
|
if (n !== void 0) return {
|
|
16691
16902
|
start: n,
|
|
16692
16903
|
end: n,
|
|
@@ -16710,12 +16921,12 @@ function OC(e, t) {
|
|
|
16710
16921
|
};
|
|
16711
16922
|
}
|
|
16712
16923
|
}
|
|
16713
|
-
function
|
|
16924
|
+
function KC(e) {
|
|
16714
16925
|
if (!(e instanceof R)) return;
|
|
16715
16926
|
let t = e.body;
|
|
16716
16927
|
if (t && !(t instanceof H)) for (let e of t.body) {
|
|
16717
16928
|
if (!(e instanceof R) || !e.isKind(r.Note)) continue;
|
|
16718
|
-
let t =
|
|
16929
|
+
let t = JC(e);
|
|
16719
16930
|
if (t) return {
|
|
16720
16931
|
kind: fm.ELEMENT_DECLARATION,
|
|
16721
16932
|
noteValueStart: t.start,
|
|
@@ -16725,18 +16936,18 @@ function kC(e) {
|
|
|
16725
16936
|
};
|
|
16726
16937
|
}
|
|
16727
16938
|
let n = e.attributeList ?? (t instanceof H ? t.args.find((e) => e instanceof W) : void 0);
|
|
16728
|
-
if (n) return
|
|
16939
|
+
if (n) return YC(n);
|
|
16729
16940
|
}
|
|
16730
|
-
function
|
|
16941
|
+
function qC(e) {
|
|
16731
16942
|
let t = e.body;
|
|
16732
16943
|
if (!(!t || t instanceof H) && t.blockCloseBrace) return t.blockCloseBrace.start;
|
|
16733
16944
|
}
|
|
16734
|
-
function
|
|
16945
|
+
function JC(e) {
|
|
16735
16946
|
let t = e.body;
|
|
16736
16947
|
if (t instanceof H) return t.callee ?? void 0;
|
|
16737
16948
|
if (t instanceof U && t.body[0] instanceof H) return t.body[0].callee ?? void 0;
|
|
16738
16949
|
}
|
|
16739
|
-
function
|
|
16950
|
+
function YC(e) {
|
|
16740
16951
|
let t = T(e).getValue()[i.Note];
|
|
16741
16952
|
if (!t?.length) return;
|
|
16742
16953
|
let n = t[0];
|
|
@@ -16752,36 +16963,36 @@ function MC(e) {
|
|
|
16752
16963
|
}
|
|
16753
16964
|
//#endregion
|
|
16754
16965
|
//#region src/compiler/queries/transform/syncDep.ts
|
|
16755
|
-
function
|
|
16756
|
-
let
|
|
16757
|
-
for (let
|
|
16758
|
-
return
|
|
16759
|
-
newDbml: aC(
|
|
16760
|
-
edits:
|
|
16966
|
+
function XC(e, t) {
|
|
16967
|
+
let n = this.getSource(e) ?? "", r = [];
|
|
16968
|
+
for (let i of t) r.push(...nw(this, e, n, i));
|
|
16969
|
+
return r.sort((e, t) => t.start - e.start), {
|
|
16970
|
+
newDbml: aC(n, r, !0),
|
|
16971
|
+
edits: r
|
|
16761
16972
|
};
|
|
16762
16973
|
}
|
|
16763
|
-
function
|
|
16974
|
+
function ZC(e) {
|
|
16764
16975
|
let t = new PS(e, Do).lex();
|
|
16765
16976
|
if (t.getErrors().length > 0) return [];
|
|
16766
16977
|
let n = new RS(e, t.getValue(), new dm(), Do).parse();
|
|
16767
|
-
return n.getErrors().length > 0 ? [] :
|
|
16978
|
+
return n.getErrors().length > 0 ? [] : $C(n.getValue().ast);
|
|
16768
16979
|
}
|
|
16769
|
-
function
|
|
16770
|
-
return `Dep [color: ${t}] {\n ${
|
|
16980
|
+
function QC(e, t) {
|
|
16981
|
+
return `Dep [color: ${t}] {\n ${_C(e.upstream)} -> ${_C(e.downstream)}\n}`;
|
|
16771
16982
|
}
|
|
16772
|
-
function
|
|
16983
|
+
function $C(e) {
|
|
16773
16984
|
let t = [];
|
|
16774
16985
|
for (let n of e.declarations) {
|
|
16775
16986
|
if (!(n instanceof R) || !n.isKind(r.Dep)) continue;
|
|
16776
16987
|
let e = [], i = n.body;
|
|
16777
16988
|
if (i instanceof H) {
|
|
16778
16989
|
if (i.callee instanceof V) {
|
|
16779
|
-
let t =
|
|
16990
|
+
let t = ew(i.callee);
|
|
16780
16991
|
t && e.push(t);
|
|
16781
16992
|
}
|
|
16782
16993
|
} else if (i) {
|
|
16783
16994
|
for (let t of i.body) if (t instanceof H && t.callee instanceof V) {
|
|
16784
|
-
let n =
|
|
16995
|
+
let n = ew(t.callee);
|
|
16785
16996
|
n && e.push(n);
|
|
16786
16997
|
}
|
|
16787
16998
|
}
|
|
@@ -16794,45 +17005,20 @@ function IC(e) {
|
|
|
16794
17005
|
}
|
|
16795
17006
|
return t;
|
|
16796
17007
|
}
|
|
16797
|
-
function
|
|
16798
|
-
let n = [];
|
|
16799
|
-
for (let a of t.declarations) {
|
|
16800
|
-
if (!(a instanceof R) || !a.isKind(r.Table)) continue;
|
|
16801
|
-
let t = a.name ? j(a.name) ?? [] : [];
|
|
16802
|
-
if (t.length === 0) continue;
|
|
16803
|
-
let o = t[t.length - 1], s = t.length > 1 ? t[t.length - 2] : void 0, c = a.body;
|
|
16804
|
-
if (!(!c || c instanceof H)) for (let t of c.body) {
|
|
16805
|
-
if (!(t instanceof H) || !t.callee) continue;
|
|
16806
|
-
let r = j(t.callee)?.at(-1);
|
|
16807
|
-
if (!r) continue;
|
|
16808
|
-
let a = {
|
|
16809
|
-
schemaName: s,
|
|
16810
|
-
tableName: o,
|
|
16811
|
-
fieldNames: [r]
|
|
16812
|
-
}, c = Og(t, i.Dep, e);
|
|
16813
|
-
if (c) for (let e of BC(t, a)) n.push({
|
|
16814
|
-
edge: e,
|
|
16815
|
-
fullStart: c.start,
|
|
16816
|
-
fullEnd: c.end
|
|
16817
|
-
});
|
|
16818
|
-
}
|
|
16819
|
-
}
|
|
16820
|
-
return n;
|
|
16821
|
-
}
|
|
16822
|
-
function RC(e) {
|
|
17008
|
+
function ew(e) {
|
|
16823
17009
|
let t = e.op?.value;
|
|
16824
17010
|
if (t !== "->" && t !== "<-") return;
|
|
16825
17011
|
let n = e.leftExpression, r = e.rightExpression;
|
|
16826
17012
|
if (!n || !r) return;
|
|
16827
17013
|
let i = t === "<-" ? r : n, a = t === "<-" ? n : r, o = j(i), s = j(a);
|
|
16828
17014
|
if (!o || !s) return;
|
|
16829
|
-
let c = o.length > 1 && s.length > 1, l =
|
|
17015
|
+
let c = o.length > 1 && s.length > 1, l = tw(o, c), u = tw(s, c);
|
|
16830
17016
|
if (!(!l || !u)) return {
|
|
16831
17017
|
upstream: l,
|
|
16832
17018
|
downstream: u
|
|
16833
17019
|
};
|
|
16834
17020
|
}
|
|
16835
|
-
function
|
|
17021
|
+
function tw(e, t) {
|
|
16836
17022
|
if (e.length === 0) return;
|
|
16837
17023
|
if (!t) {
|
|
16838
17024
|
let t = e[e.length - 1];
|
|
@@ -16849,269 +17035,52 @@ function zC(e, t) {
|
|
|
16849
17035
|
fieldNames: n
|
|
16850
17036
|
};
|
|
16851
17037
|
}
|
|
16852
|
-
function
|
|
16853
|
-
let
|
|
16854
|
-
|
|
16855
|
-
|
|
16856
|
-
|
|
16857
|
-
|
|
16858
|
-
|
|
16859
|
-
|
|
16860
|
-
|
|
16861
|
-
|
|
16862
|
-
let o = j(n.expression);
|
|
16863
|
-
if (!o) continue;
|
|
16864
|
-
let s = zC(o, o.length > 1);
|
|
16865
|
-
s && r.push(a === "->" ? {
|
|
16866
|
-
upstream: t,
|
|
16867
|
-
downstream: s
|
|
16868
|
-
} : {
|
|
16869
|
-
upstream: s,
|
|
16870
|
-
downstream: t
|
|
16871
|
-
});
|
|
16872
|
-
}
|
|
16873
|
-
return r;
|
|
16874
|
-
}
|
|
16875
|
-
function VC(e, t) {
|
|
16876
|
-
return dC(e.upstream, t.upstream) && dC(e.downstream, t.downstream);
|
|
16877
|
-
}
|
|
16878
|
-
function HC(e, t) {
|
|
16879
|
-
return e.edges.some((e) => VC(e, t));
|
|
16880
|
-
}
|
|
16881
|
-
function UC(e, t) {
|
|
16882
|
-
return e.find((e) => HC(e, t));
|
|
16883
|
-
}
|
|
16884
|
-
function WC(e, t, n, r) {
|
|
16885
|
-
switch (t.operation) {
|
|
16886
|
-
case "create": return KC(e, t, n, r);
|
|
16887
|
-
case "update": {
|
|
16888
|
-
let r = UC(n, t.edge);
|
|
16889
|
-
return r ? GC(t, r, e) : [];
|
|
16890
|
-
}
|
|
16891
|
-
case "remove": {
|
|
16892
|
-
let r = UC(n, t.edge);
|
|
16893
|
-
return r ? GC({
|
|
16894
|
-
...t,
|
|
16895
|
-
color: void 0,
|
|
16896
|
-
note: void 0
|
|
16897
|
-
}, r, e) : [];
|
|
16898
|
-
}
|
|
17038
|
+
function nw(e, t, n, r) {
|
|
17039
|
+
let i = fC(e, t, r.edge);
|
|
17040
|
+
switch (r.operation) {
|
|
17041
|
+
case "create": return iw(n, r, i);
|
|
17042
|
+
case "update": return i?.kind === "block" ? rw(r, i.declaration, n) : [];
|
|
17043
|
+
case "remove": return i?.kind === "block" ? rw({
|
|
17044
|
+
...r,
|
|
17045
|
+
color: void 0,
|
|
17046
|
+
note: void 0
|
|
17047
|
+
}, i.declaration, n) : [];
|
|
16899
17048
|
default: return [];
|
|
16900
17049
|
}
|
|
16901
17050
|
}
|
|
16902
|
-
function
|
|
17051
|
+
function rw(e, t, n) {
|
|
16903
17052
|
let r = [];
|
|
16904
17053
|
if (e.color !== void 0) {
|
|
16905
|
-
let a = Dg(t
|
|
17054
|
+
let a = Dg(t, i.Color, e.color, n);
|
|
16906
17055
|
a && r.push(a);
|
|
16907
17056
|
}
|
|
16908
17057
|
if (e.note === null) {
|
|
16909
|
-
let e =
|
|
17058
|
+
let e = WC(t);
|
|
16910
17059
|
e && r.push(e);
|
|
16911
17060
|
} else if (e.note !== void 0) {
|
|
16912
|
-
let n =
|
|
17061
|
+
let n = UC(t, e.note) ?? GC(t, e.note);
|
|
16913
17062
|
n && r.push(n);
|
|
16914
17063
|
}
|
|
16915
17064
|
return r;
|
|
16916
17065
|
}
|
|
16917
|
-
function KC(e, t, n, r) {
|
|
16918
|
-
let i = UC(n, t.edge);
|
|
16919
|
-
if (i) return GC(t, i, e);
|
|
16920
|
-
let a = FC(t.edge, t.color ?? ""), o = {
|
|
16921
|
-
start: e.length,
|
|
16922
|
-
end: e.length,
|
|
16923
|
-
newText: "\n\n" + a + "\n"
|
|
16924
|
-
}, s = r.find((e) => VC(e.edge, t.edge));
|
|
16925
|
-
return s ? [{
|
|
16926
|
-
start: s.fullStart,
|
|
16927
|
-
end: s.fullEnd,
|
|
16928
|
-
newText: ""
|
|
16929
|
-
}, o] : [o];
|
|
16930
|
-
}
|
|
16931
|
-
//#endregion
|
|
16932
|
-
//#region src/compiler/queries/transform/updateElementSetting.ts
|
|
16933
|
-
function qC(e, t, n, r) {
|
|
16934
|
-
if (t.kind === "dep") return XC(this, e, t, n, r);
|
|
16935
|
-
if (t.kind === "ref") return ZC(this, e, t, n, r);
|
|
16936
|
-
let i = YC(this, e, t);
|
|
16937
|
-
if (!i) return [];
|
|
16938
|
-
let a = Dg(i, n, r, this.getSource(e) ?? "");
|
|
16939
|
-
return a ? [a] : [];
|
|
16940
|
-
}
|
|
16941
|
-
function JC(e, t, n, r) {
|
|
16942
|
-
let i = this.getSource(e) ?? "", a = this.updateElementSettingEdit(e, t, n, r);
|
|
16943
|
-
return a.length === 0 ? i : aC(i, a);
|
|
16944
|
-
}
|
|
16945
|
-
function YC(e, t, n) {
|
|
16946
|
-
let r = ("schema" in n ? n.schema : void 0) ?? "public";
|
|
16947
|
-
switch (n.kind) {
|
|
16948
|
-
case F.Column: {
|
|
16949
|
-
let i = pC(e, t, r, n.table, F.Table);
|
|
16950
|
-
return i ? e.lookupMembers(i, F.Column, n.column)?.declaration : void 0;
|
|
16951
|
-
}
|
|
16952
|
-
case F.Table: return pC(e, t, r, n.table)?.declaration;
|
|
16953
|
-
case F.Enum:
|
|
16954
|
-
case F.StickyNote:
|
|
16955
|
-
case F.TableGroup: return pC(e, t, r, n.name, n.kind)?.declaration;
|
|
16956
|
-
case F.Schema: return pC(e, t, n.schema, "", F.Schema)?.declaration;
|
|
16957
|
-
default: return;
|
|
16958
|
-
}
|
|
16959
|
-
}
|
|
16960
|
-
function XC(e, t, n, r, i) {
|
|
16961
|
-
let a = e.getSource(t) ?? "", o = e.parseFile(t).getValue().ast, s = IC(o).find((e) => e.edges.some((e) => uC(e.upstream, n.upstream) && uC(e.downstream, n.downstream)));
|
|
16962
|
-
if (!s) {
|
|
16963
|
-
if (i === null) return [];
|
|
16964
|
-
let e = LC(a, o).find((e) => dC(e.edge.upstream, n.upstream) && dC(e.edge.downstream, n.downstream));
|
|
16965
|
-
if (!e) return [];
|
|
16966
|
-
let t = hC(n.upstream), s = hC(n.downstream), c = gC(r, i), l = c ? `Dep [${c}] {\n ${t} -> ${s}\n}` : `Dep {\n ${t} -> ${s}\n}`;
|
|
16967
|
-
return [{
|
|
16968
|
-
start: e.fullStart,
|
|
16969
|
-
end: e.fullEnd,
|
|
16970
|
-
newText: ""
|
|
16971
|
-
}, {
|
|
16972
|
-
start: a.length,
|
|
16973
|
-
end: a.length,
|
|
16974
|
-
newText: "\n\n" + l + "\n"
|
|
16975
|
-
}];
|
|
16976
|
-
}
|
|
16977
|
-
let { declaration: c } = s, { body: l } = c;
|
|
16978
|
-
if (l instanceof H) {
|
|
16979
|
-
let e = Dg(c, r, i, a);
|
|
16980
|
-
if (e) return [e];
|
|
16981
|
-
let t = Dg(l, r, i, a);
|
|
16982
|
-
return t ? [t] : [];
|
|
16983
|
-
}
|
|
16984
|
-
let u = Dg(c, r, i, a);
|
|
16985
|
-
return u ? [u] : [];
|
|
16986
|
-
}
|
|
16987
|
-
function ZC(e, t, n, r, i) {
|
|
16988
|
-
let a = e.getSource(t) ?? "", o = oC(e, t, n);
|
|
16989
|
-
if (!o) return [];
|
|
16990
|
-
if (o.kind === "inline") {
|
|
16991
|
-
if (i === null) return [];
|
|
16992
|
-
let e = hC(n.endpoints[0]), t = hC(n.endpoints[1]), s = gC(r, i), c = s ? `Ref: ${e} ${o.op} ${t} [${s}]` : `Ref: ${e} ${o.op} ${t}`;
|
|
16993
|
-
return [{
|
|
16994
|
-
start: o.fullStart,
|
|
16995
|
-
end: o.fullEnd,
|
|
16996
|
-
newText: ""
|
|
16997
|
-
}, {
|
|
16998
|
-
start: a.length,
|
|
16999
|
-
end: a.length,
|
|
17000
|
-
newText: "\n\n" + c + "\n"
|
|
17001
|
-
}];
|
|
17002
|
-
}
|
|
17003
|
-
let s = Dg(o.node, r, i, a);
|
|
17004
|
-
return s ? [s] : [];
|
|
17005
|
-
}
|
|
17006
|
-
//#endregion
|
|
17007
|
-
//#region src/compiler/queries/transform/syncDiagramView.ts
|
|
17008
|
-
function QC(e) {
|
|
17009
|
-
let t = [], n = new PS(e, Do).lex();
|
|
17010
|
-
if (n.getErrors().length > 0) return t;
|
|
17011
|
-
let i = new RS(e, n.getValue(), new dm(), Do).parse();
|
|
17012
|
-
if (i.getErrors().length > 0) return t;
|
|
17013
|
-
let a = i.getValue().ast;
|
|
17014
|
-
for (let e of a.declarations) if (e.isKind(r.DiagramView)) {
|
|
17015
|
-
let n = e.name ? j(e.name) ?? [] : [], r = n.length > 0 ? n[n.length - 1] : "";
|
|
17016
|
-
t.push({
|
|
17017
|
-
name: r,
|
|
17018
|
-
startIndex: e.start,
|
|
17019
|
-
endIndex: e.end
|
|
17020
|
-
});
|
|
17021
|
-
}
|
|
17022
|
-
return t;
|
|
17023
|
-
}
|
|
17024
|
-
function $C(e, t, n) {
|
|
17025
|
-
e.push(` ${t} {`), n.forEach((t) => e.push(` ${t}`)), e.push(" }");
|
|
17026
|
-
}
|
|
17027
|
-
function ew(e, t) {
|
|
17028
|
-
e.push(` ${t} { * }`);
|
|
17029
|
-
}
|
|
17030
|
-
function tw(e) {
|
|
17031
|
-
return e == null ? "null" : e.length === 0 ? "empty" : "items";
|
|
17032
|
-
}
|
|
17033
|
-
function nw(e, t) {
|
|
17034
|
-
let n = `DiagramView ${R_(e)} {`, r = (e) => R_(e.name), i = t?.tables?.map((e) => {
|
|
17035
|
-
let t = R_(e.name);
|
|
17036
|
-
return e.schemaName === "public" ? t : `${R_(e.schemaName)}.${t}`;
|
|
17037
|
-
}) ?? [], a = t?.tableGroups?.map(r) ?? [], o = t?.schemas?.map(r) ?? [], s = t?.stickyNotes?.map(r) ?? [];
|
|
17038
|
-
if (!t) return `${n}\n}`;
|
|
17039
|
-
let c = {
|
|
17040
|
-
tables: tw(t.tables),
|
|
17041
|
-
tableGroups: tw(t.tableGroups),
|
|
17042
|
-
schemas: tw(t.schemas),
|
|
17043
|
-
stickyNotes: tw(t.stickyNotes)
|
|
17044
|
-
};
|
|
17045
|
-
if (Object.values(c).every((e) => e === "null")) return `${n}\n}`;
|
|
17046
|
-
if (Object.values(c).every((e) => e === "empty")) return `${n}\n *\n}`;
|
|
17047
|
-
let l = c.tables === "items" || c.tableGroups === "items" || c.schemas === "items", u = c.tables === "empty" && c.tableGroups === "empty" && c.schemas === "empty", d = [n];
|
|
17048
|
-
return l ? (c.tables === "items" && $C(d, "Tables", i), c.tableGroups === "items" && $C(d, "TableGroups", a), c.schemas === "items" && $C(d, "Schemas", o)) : u && ew(d, "Tables"), c.stickyNotes === "items" ? $C(d, "Notes", s) : c.stickyNotes === "empty" && ew(d, "Notes"), d.push("}"), d.join("\n");
|
|
17049
|
-
}
|
|
17050
|
-
function rw(e, t, n) {
|
|
17051
|
-
let r = this.getSource(e) ?? "", i = n ?? QC(r), a = [];
|
|
17052
|
-
for (let e of t) {
|
|
17053
|
-
let t = iw(r, e, i);
|
|
17054
|
-
a.push(...t);
|
|
17055
|
-
}
|
|
17056
|
-
return a.sort((e, t) => t.start - e.start), {
|
|
17057
|
-
newDbml: aC(r, a, !0),
|
|
17058
|
-
edits: a
|
|
17059
|
-
};
|
|
17060
|
-
}
|
|
17061
17066
|
function iw(e, t, n) {
|
|
17062
|
-
|
|
17063
|
-
|
|
17064
|
-
case "update": return ow(e, t, n);
|
|
17065
|
-
case "delete": return sw(e, t, n);
|
|
17066
|
-
default: return [];
|
|
17067
|
-
}
|
|
17068
|
-
}
|
|
17069
|
-
function aw(e, t, n) {
|
|
17070
|
-
if (n.find((e) => e.name === t.name)) return ow(e, t, n);
|
|
17071
|
-
let r = "\n\n" + nw(t.name, t.visibleEntities) + "\n";
|
|
17072
|
-
return [{
|
|
17067
|
+
if (n?.kind === "block") return rw(t, n.declaration, e);
|
|
17068
|
+
let r = QC(t.edge, t.color ?? ""), i = {
|
|
17073
17069
|
start: e.length,
|
|
17074
17070
|
end: e.length,
|
|
17075
|
-
newText: r
|
|
17076
|
-
}
|
|
17077
|
-
|
|
17078
|
-
|
|
17079
|
-
|
|
17080
|
-
if (!r) return [];
|
|
17081
|
-
let i = [];
|
|
17082
|
-
if (t.newName || t.visibleEntities) {
|
|
17083
|
-
let e = nw(t.newName || t.name, t.visibleEntities);
|
|
17084
|
-
i.push({
|
|
17085
|
-
start: r.startIndex,
|
|
17086
|
-
end: r.endIndex,
|
|
17087
|
-
newText: e
|
|
17088
|
-
});
|
|
17089
|
-
}
|
|
17090
|
-
return i;
|
|
17091
|
-
}
|
|
17092
|
-
function sw(e, t, n) {
|
|
17093
|
-
let r = n.find((e) => e.name === t.name);
|
|
17094
|
-
if (!r) return [];
|
|
17095
|
-
let i = r.startIndex, a = r.endIndex;
|
|
17096
|
-
for (; i > 0 && e[i - 1] === "\n";) {
|
|
17097
|
-
i--, i > 0 && e[i - 1] === "\r" && i--;
|
|
17098
|
-
let t = e.lastIndexOf("\n", i - 1) + 1;
|
|
17099
|
-
if (e.substring(t, i).trim() !== "") {
|
|
17100
|
-
i = r.startIndex, i > 0 && e[i - 1] === "\n" && (i--, i > 0 && e[i - 1] === "\r" && i--);
|
|
17101
|
-
break;
|
|
17102
|
-
}
|
|
17103
|
-
}
|
|
17104
|
-
return a < e.length && e[a] === "\r" && a++, a < e.length && e[a] === "\n" && a++, [{
|
|
17105
|
-
start: i,
|
|
17106
|
-
end: a,
|
|
17071
|
+
newText: "\n\n" + r + "\n"
|
|
17072
|
+
};
|
|
17073
|
+
return n?.kind === "inline" ? [{
|
|
17074
|
+
start: n.fullStart,
|
|
17075
|
+
end: n.fullEnd,
|
|
17107
17076
|
newText: ""
|
|
17108
|
-
}];
|
|
17077
|
+
}, i] : [i];
|
|
17109
17078
|
}
|
|
17110
17079
|
//#endregion
|
|
17111
17080
|
//#region src/compiler/index.ts
|
|
17112
|
-
var
|
|
17081
|
+
var aw = Symbol("COMPUTING"), ow = class {
|
|
17113
17082
|
constructor(e) {
|
|
17114
|
-
this.layout = e, this.nodeIdGenerator = new dm(), this.symbolIdGenerator = new Up(), 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(YS), this.parseProject = this.globalQuery(XS), this.validateNode = this.localQuery(yy), this.validateFile = this.localQuery(NS), this.nodeFullname = this.localQuery(xy), this.nodeAlias = this.localQuery(Sy), this.nodeSettings = this.localQuery(by), this.canonicalName = this.globalQuery(mS), this.bindNode = this.globalQuery(Ev), this.bindFile = this.globalQuery(kS), this.bindProject = this.globalQuery(AS), this.interpretSymbol = this.globalQuery(Ov), this.interpretMetadata = this.globalQuery(kv), this.interpretFile = this.globalQuery(jS), this.interpretProject = this.globalQuery(MS), this.nodeSymbol = this.globalQuery(Cv), this.nodeMetadata = this.globalQuery(Dv), this.symbolMembers = this.globalQuery(wv), this.symbolMembersLookupMap = this.globalQuery(ZS), this.lookupMembers = this.globalQuery(QS), this.nodeReferee = this.globalQuery(Tv), this.resolutionIndex = this.globalQuery(eC), this.symbolReferences = this.globalQuery(nC), this.symbolParent = this.globalQuery(tC), this.symbolMetadata = this.globalQuery(rC), this.symbolAliases = this.globalQuery($S), this.symbolUses = this.globalQuery(iC), this.fileDependencies = this.localQuery(_S), this.reachableFiles = this.globalQuery(yS), this.usableMembers = this.globalQuery(l_), this.nodeAtPosition = this.localQuery(OS), this.renameTable =
|
|
17083
|
+
this.layout = e, this.nodeIdGenerator = new dm(), this.symbolIdGenerator = new Up(), 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(YS), this.parseProject = this.globalQuery(XS), this.validateNode = this.localQuery(yy), this.validateFile = this.localQuery(NS), this.nodeFullname = this.localQuery(xy), this.nodeAlias = this.localQuery(Sy), this.nodeSettings = this.localQuery(by), this.canonicalName = this.globalQuery(mS), this.bindNode = this.globalQuery(Ev), this.bindFile = this.globalQuery(kS), this.bindProject = this.globalQuery(AS), this.interpretSymbol = this.globalQuery(Ov), this.interpretMetadata = this.globalQuery(kv), this.interpretFile = this.globalQuery(jS), this.interpretProject = this.globalQuery(MS), this.nodeSymbol = this.globalQuery(Cv), this.nodeMetadata = this.globalQuery(Dv), this.symbolMembers = this.globalQuery(wv), this.symbolMembersLookupMap = this.globalQuery(ZS), this.lookupMembers = this.globalQuery(QS), this.nodeReferee = this.globalQuery(Tv), this.resolutionIndex = this.globalQuery(eC), this.symbolReferences = this.globalQuery(nC), this.symbolParent = this.globalQuery(tC), this.symbolMetadata = this.globalQuery(rC), this.symbolAliases = this.globalQuery($S), this.symbolUses = this.globalQuery(iC), this.fileDependencies = this.localQuery(_S), this.reachableFiles = this.globalQuery(yS), this.usableMembers = this.globalQuery(l_), this.nodeAtPosition = this.localQuery(OS), this.renameTable = TC.bind(this), this.updateElementSetting = kC.bind(this), this.updateElementSettingEdit = OC.bind(this), this.syncDiagramView = RC.bind(this), this.syncDep = XC.bind(this), this.token = {
|
|
17115
17084
|
invalidStream: this.localQuery(DS),
|
|
17116
17085
|
flatStream: this.localQuery(ES)
|
|
17117
17086
|
}, this.parse = {
|
|
@@ -17153,10 +17122,10 @@ var cw = Symbol("COMPUTING"), lw = class {
|
|
|
17153
17122
|
r || (r = /* @__PURE__ */ new Map(), this.globalCache.set(t, r));
|
|
17154
17123
|
let i = n.length === 0 ? "" : n.length === 1 ? fh(n[0]) : n.map((e) => fh(e)).join("\0"), a = r.get(i);
|
|
17155
17124
|
if (a) {
|
|
17156
|
-
if (a ===
|
|
17125
|
+
if (a === aw) throw Error(`Cycle detected in query: ${e.name}(${i})`);
|
|
17157
17126
|
return a;
|
|
17158
17127
|
}
|
|
17159
|
-
r.set(i,
|
|
17128
|
+
r.set(i, aw);
|
|
17160
17129
|
try {
|
|
17161
17130
|
let t = e.apply(this, n);
|
|
17162
17131
|
return r.set(i, t), t;
|
|
@@ -17178,10 +17147,10 @@ var cw = Symbol("COMPUTING"), lw = class {
|
|
|
17178
17147
|
let c = s.get(t);
|
|
17179
17148
|
if (c || (c = /* @__PURE__ */ new Map(), s.set(t, c)), c.has(o)) {
|
|
17180
17149
|
let t = c.get(o);
|
|
17181
|
-
if (t ===
|
|
17150
|
+
if (t === aw) throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);
|
|
17182
17151
|
return t;
|
|
17183
17152
|
}
|
|
17184
|
-
c.set(o,
|
|
17153
|
+
c.set(o, aw);
|
|
17185
17154
|
try {
|
|
17186
17155
|
let t = e.apply(this, n);
|
|
17187
17156
|
return c.set(o, t), t;
|
|
@@ -17200,7 +17169,7 @@ var cw = Symbol("COMPUTING"), lw = class {
|
|
|
17200
17169
|
codeActionProvider: new jb(this)
|
|
17201
17170
|
};
|
|
17202
17171
|
}
|
|
17203
|
-
},
|
|
17172
|
+
}, sw = class e {
|
|
17204
17173
|
constructor(e = {}) {
|
|
17205
17174
|
this.files = e instanceof Map ? new Map(e) : new Map(Object.entries(e));
|
|
17206
17175
|
}
|
|
@@ -17244,4 +17213,4 @@ var cw = Symbol("COMPUTING"), lw = class {
|
|
|
17244
17213
|
}
|
|
17245
17214
|
};
|
|
17246
17215
|
//#endregion
|
|
17247
|
-
export { Om as ArrayNode, z as AttributeNode, U as BlockExpressionNode, cf as CARDINALITY_MANY, of as CARDINALITY_MAYBE, af as CARDINALITY_ONE, sf as CARDINALITY_SOME, Sm as CallExpressionNode, bm as CommaExpressionNode, w as CompileError, C as CompileErrorCode,
|
|
17216
|
+
export { Om as ArrayNode, z as AttributeNode, U as BlockExpressionNode, cf as CARDINALITY_MANY, of as CARDINALITY_MAYBE, af as CARDINALITY_ONE, sf as CARDINALITY_SOME, Sm as CallExpressionNode, bm as CommaExpressionNode, w as CompileError, C as CompileErrorCode, ow as Compiler, Y as CompletionItemInsertTextRule, J as CompletionItemKind, jb as DBMLCodeActionProvider, Dx as DBMLCompletionItemProvider, Mb as DBMLDefinitionProvider, Nb as DBMLDiagnosticsProvider, Pb as DBMLReferencesProvider, Do as DEFAULT_ENTRY, R as ElementDeclarationNode, r as ElementKind, Dm as EmptyNode, wp as FALSY_VALUES, xo as Filepath, H as FunctionApplicationNode, vm as FunctionExpressionNode, xm as GroupExpressionNode, gm as IdentifierStreamNode, V as InfixExpressionNode, W as ListExpressionNode, Cm as LiteralNode, Ob as MarkerSeverity, sw as MemoryProjectLayout, Um as MetadataKind, _m as PostfixExpressionNode, B as PrefixExpressionNode, Em as PrimaryExpressionNode, L as ProgramNode, Q as ScopeKind, F as SymbolKind, I as SyntaxNode, dm as SyntaxNodeIdGenerator, fm as SyntaxNodeKind, Ha as SyntaxToken, _ as SyntaxTokenKind, Cp as TRUTHY_VALUES, ym as TupleExpressionNode, t as UNHANDLED, _b as Uri, pm as UseDeclarationNode, hm as UseSpecifierListNode, mm as UseSpecifierNode, Tm as VariableNode, wm as WildcardNode, R_ as addDoubleQuoteIfNeeded, sS as dbmlLanguageConfig, cS as dbmlMonarchTokensProvider, V_ as escapeString, pp as extractNumericLiteral, bp as extractSignedNumber, ZC as findDepBlocks, NC as findDiagramViewBlocks, H_ as formatRecordValue, df as getMultiplicities, Wo as getRecordValueType, _f as getRelationshipOp, Vo as isBinaryType, zo as isBooleanType, Ho as isDateTimeType, vp as isEmptyStringLiteral, pf as isEndpointManySide, ff as isEndpointOneSide, mf as isEndpointOptional, hf as isEndpointRequired, Lo as isFloatType, yp as isFunctionExpression, Io as isIntegerType, _p as isNullish, Ro as isNumericType, Ba as isOp, Va as isOpToken, Uo as isSerialType, Bo as isStringType, za as isTriviaToken, L_ as isValidIdentifier, vf as makeCardinalityOptional, yf as makeCardinalityRequired, gf as makeRelationshipRequired, z_ as normalizeQualifiedName, Fo as normalizeTypeName, rf as parseCardinality, U_ as splitQualifiedIdentifier, Tp as tryExtractBoolean, jp as tryExtractDateTime, Ep as tryExtractEnum, Sp as tryExtractInteger, xp as tryExtractNumeric, Dp as tryExtractString, B_ as unescapeString, bg as validateForeignKeys, ug as validatePrimaryKey, gg as validateUnique };
|
|
@@ -78,7 +78,7 @@ export default class Compiler {
|
|
|
78
78
|
newDbml: string;
|
|
79
79
|
edits: import('.').TextEdit[];
|
|
80
80
|
};
|
|
81
|
-
syncDep: (filepath: Filepath, operations: import('..').DepSyncOperation[]
|
|
81
|
+
syncDep: (filepath: Filepath, operations: import('..').DepSyncOperation[]) => {
|
|
82
82
|
newDbml: string;
|
|
83
83
|
edits: import('.').TextEdit[];
|
|
84
84
|
};
|
|
@@ -35,7 +35,7 @@ export interface InlineDep {
|
|
|
35
35
|
* Synchronizes `Dep` blocks in the DBML source at `filepath`.
|
|
36
36
|
* Applies create/update/remove operations and returns the rewritten source.
|
|
37
37
|
*/
|
|
38
|
-
export declare function syncDep(this: Compiler, filepath: Filepath, operations: DepSyncOperation[]
|
|
38
|
+
export declare function syncDep(this: Compiler, filepath: Filepath, operations: DepSyncOperation[]): {
|
|
39
39
|
newDbml: string;
|
|
40
40
|
edits: TextEdit[];
|
|
41
41
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ElementDeclarationNode } from '../../../../core/types/nodes';
|
|
2
|
+
import { Filepath } from '../../../../core/types/filepath';
|
|
3
|
+
import { default as Compiler } from '../../../index';
|
|
4
|
+
import { DepIdentifier } from '../types';
|
|
5
|
+
export interface InlineDepDefinition {
|
|
6
|
+
kind: 'inline';
|
|
7
|
+
op: string;
|
|
8
|
+
fullStart: number;
|
|
9
|
+
fullEnd: number;
|
|
10
|
+
}
|
|
11
|
+
export interface BlockDepDefinition {
|
|
12
|
+
kind: 'block';
|
|
13
|
+
declaration: ElementDeclarationNode;
|
|
14
|
+
}
|
|
15
|
+
export type DepDefinition = InlineDepDefinition | BlockDepDefinition;
|
|
16
|
+
/**
|
|
17
|
+
* Finds the `Dep` block or inline `[dep: …]` setting that carries the edge `target` names.
|
|
18
|
+
*
|
|
19
|
+
* Matching runs on resolved table and column symbols, the way {@link findRefDefinition} does.
|
|
20
|
+
* The endpoints' source text cannot be compared instead: `a.b` is `schema.table` or
|
|
21
|
+
* `table.field` depending on what `a` resolves to, so a mixed-level edge such as
|
|
22
|
+
* `a.x -> b` is not describable without the symbol table.
|
|
23
|
+
*
|
|
24
|
+
* A target with no field names matches only an edge with no columns on that side.
|
|
25
|
+
*/
|
|
26
|
+
export declare function findDepDefinition(compiler: Compiler, filepath: Filepath, target: DepIdentifier): DepDefinition | undefined;
|
|
@@ -4,9 +4,8 @@ import { default as Compiler } from '../../../index';
|
|
|
4
4
|
import { EndpointRef } from '../types';
|
|
5
5
|
export type { ElementIdentifier } from '../types';
|
|
6
6
|
export { findRefDefinition, type InlineRef, type StandaloneRef } from './ref';
|
|
7
|
+
export { findDepDefinition, type DepDefinition, type InlineDepDefinition, type BlockDepDefinition, } from './dep';
|
|
7
8
|
export declare function normalizeSchema(schema?: string | null): string;
|
|
8
|
-
export declare function endpointsEqual(left: EndpointRef, right: EndpointRef): boolean;
|
|
9
|
-
export declare function endpointMatches(candidate: EndpointRef, target: EndpointRef): boolean;
|
|
10
9
|
export declare function normalizeTableName(input: string | {
|
|
11
10
|
schema?: string;
|
|
12
11
|
table: string;
|
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.1.0",
|
|
4
|
+
"version": "10.1.1-alpha.0",
|
|
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": "e0ed6604c3d42902004bcfb5b22791d3f364d759"
|
|
55
55
|
}
|