@dbml/parse 7.0.0-alpha.0 → 7.0.0-alpha.1

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.
Files changed (26) hide show
  1. package/dist/__tests__/examples/wildcard/wildcard.test.d.ts +1 -0
  2. package/dist/dbml-parse.js +17 -15
  3. package/dist/dbml-parse.mjs +355 -313
  4. package/dist/src/compiler/index.d.ts +7 -2
  5. package/dist/src/compiler/queries/transform/applyTextEdits.d.ts +1 -1
  6. package/dist/src/compiler/queries/transform/index.d.ts +1 -0
  7. package/dist/src/compiler/queries/transform/syncDiagramView.d.ts +11 -2
  8. package/dist/src/core/analyzer/validator/elementValidators/checks.d.ts +5 -2
  9. package/dist/src/core/analyzer/validator/elementValidators/custom.d.ts +5 -2
  10. package/dist/src/core/analyzer/validator/elementValidators/diagramView.d.ts +9 -3
  11. package/dist/src/core/analyzer/validator/elementValidators/enum.d.ts +5 -2
  12. package/dist/src/core/analyzer/validator/elementValidators/indexes.d.ts +5 -2
  13. package/dist/src/core/analyzer/validator/elementValidators/note.d.ts +5 -2
  14. package/dist/src/core/analyzer/validator/elementValidators/project.d.ts +5 -2
  15. package/dist/src/core/analyzer/validator/elementValidators/records.d.ts +5 -2
  16. package/dist/src/core/analyzer/validator/elementValidators/ref.d.ts +5 -2
  17. package/dist/src/core/analyzer/validator/elementValidators/table.d.ts +5 -2
  18. package/dist/src/core/analyzer/validator/elementValidators/tableGroup.d.ts +5 -2
  19. package/dist/src/core/analyzer/validator/elementValidators/tablePartial.d.ts +5 -2
  20. package/dist/src/core/analyzer/validator/types.d.ts +5 -2
  21. package/dist/src/core/interpreter/types.d.ts +3 -5
  22. package/dist/src/core/lexer/tokens.d.ts +2 -1
  23. package/dist/src/core/parser/nodes.d.ts +7 -0
  24. package/dist/src/core/parser/utils.d.ts +1 -0
  25. package/dist/src/index.d.ts +2 -2
  26. package/package.json +2 -2
@@ -985,7 +985,7 @@ function unzip(r) {
985
985
  }
986
986
  var zip_default = _baseRest_default(unzip);
987
987
  let SyntaxTokenKind = /* @__PURE__ */ function(r) {
988
- return r.SPACE = "<space>", r.TAB = "<tab>", r.NEWLINE = "<newline>", r.COMMA = "<comma>", r.LPAREN = "<lparen>", r.RPAREN = "<rparen>", r.LBRACE = "<lbrace>", r.RBRACE = "<rbrace>", r.LBRACKET = "<lbracket>", r.RBRACKET = "<rbracket>", r.LANGLE = "<langle>", r.RANGLE = "<rangle>", r.OP = "<op>", r.EOF = "<eof>", r.NUMERIC_LITERAL = "<number>", r.STRING_LITERAL = "<string>", r.COLOR_LITERAL = "<color>", r.FUNCTION_EXPRESSION = "<function-expression>", r.QUOTED_STRING = "<variable>", r.IDENTIFIER = "<identifier>", r.SEMICOLON = "<semicolon>", r.COLON = "<colon>", r.SINGLE_LINE_COMMENT = "<single-line-comment>", r.MULTILINE_COMMENT = "<multiline-comment>", r;
988
+ return r.SPACE = "<space>", r.TAB = "<tab>", r.NEWLINE = "<newline>", r.COMMA = "<comma>", r.LPAREN = "<lparen>", r.RPAREN = "<rparen>", r.LBRACE = "<lbrace>", r.RBRACE = "<rbrace>", r.LBRACKET = "<lbracket>", r.RBRACKET = "<rbracket>", r.LANGLE = "<langle>", r.RANGLE = "<rangle>", r.OP = "<op>", r.EOF = "<eof>", r.NUMERIC_LITERAL = "<number>", r.STRING_LITERAL = "<string>", r.COLOR_LITERAL = "<color>", r.FUNCTION_EXPRESSION = "<function-expression>", r.QUOTED_STRING = "<variable>", r.IDENTIFIER = "<identifier>", r.SEMICOLON = "<semicolon>", r.COLON = "<colon>", r.SINGLE_LINE_COMMENT = "<single-line-comment>", r.MULTILINE_COMMENT = "<multiline-comment>", r.WILDCARD = "<wildcard>", r;
989
989
  }({});
990
990
  function isTriviaToken(r) {
991
991
  switch (r.kind) {
@@ -1002,7 +1002,6 @@ function isOp(r) {
1002
1002
  switch (r) {
1003
1003
  case "+":
1004
1004
  case "-":
1005
- case "*":
1006
1005
  case "/":
1007
1006
  case "%":
1008
1007
  case "<":
@@ -1073,7 +1072,7 @@ var SyntaxNodeIdGenerator = class {
1073
1072
  }
1074
1073
  };
1075
1074
  let SyntaxNodeKind = /* @__PURE__ */ function(r) {
1076
- return r.PROGRAM = "<program>", r.ELEMENT_DECLARATION = "<element-declaration>", r.ATTRIBUTE = "<attribute>", r.IDENTIFIER_STREAM = "<identifer-stream>", r.LITERAL = "<literal>", r.VARIABLE = "<variable>", r.PREFIX_EXPRESSION = "<prefix-expression>", r.INFIX_EXPRESSION = "<infix-expression>", r.POSTFIX_EXPRESSION = "<postfix-expression>", r.FUNCTION_EXPRESSION = "<function-expression>", r.FUNCTION_APPLICATION = "<function-application>", r.BLOCK_EXPRESSION = "<block-expression>", r.LIST_EXPRESSION = "<list-expression>", r.TUPLE_EXPRESSION = "<tuple-expression>", r.CALL_EXPRESSION = "<call-expression>", r.PRIMARY_EXPRESSION = "<primary-expression>", r.GROUP_EXPRESSION = "<group-expression>", r.COMMA_EXPRESSION = "<comma-expression>", r.EMPTY = "<dummy>", r.ARRAY = "<array>", r;
1075
+ return r.PROGRAM = "<program>", r.ELEMENT_DECLARATION = "<element-declaration>", r.ATTRIBUTE = "<attribute>", r.IDENTIFIER_STREAM = "<identifer-stream>", r.LITERAL = "<literal>", r.VARIABLE = "<variable>", r.PREFIX_EXPRESSION = "<prefix-expression>", r.INFIX_EXPRESSION = "<infix-expression>", r.POSTFIX_EXPRESSION = "<postfix-expression>", r.FUNCTION_EXPRESSION = "<function-expression>", r.FUNCTION_APPLICATION = "<function-application>", r.BLOCK_EXPRESSION = "<block-expression>", r.LIST_EXPRESSION = "<list-expression>", r.TUPLE_EXPRESSION = "<tuple-expression>", r.CALL_EXPRESSION = "<call-expression>", r.PRIMARY_EXPRESSION = "<primary-expression>", r.GROUP_EXPRESSION = "<group-expression>", r.COMMA_EXPRESSION = "<comma-expression>", r.WILDCARD = "<wildcard>", r.EMPTY = "<dummy>", r.ARRAY = "<array>", r;
1077
1076
  }({});
1078
1077
  var ProgramNode = class extends SyntaxNode {
1079
1078
  constructor({ body: r = [], eof: j, source: M }, N) {
@@ -1173,6 +1172,10 @@ var ProgramNode = class extends SyntaxNode {
1173
1172
  constructor({ literal: r }, j) {
1174
1173
  super(j, SyntaxNodeKind.LITERAL, [r]), this.literal = r;
1175
1174
  }
1175
+ }, WildcardNode = class extends SyntaxNode {
1176
+ constructor({ token: r }, j) {
1177
+ super(j, SyntaxNodeKind.WILDCARD, [r]), this.token = r;
1178
+ }
1176
1179
  }, VariableNode = class extends SyntaxNode {
1177
1180
  constructor({ variable: r }, j) {
1178
1181
  super(j, SyntaxNodeKind.VARIABLE, [r]), this.variable = r;
@@ -1378,19 +1381,22 @@ var CustomValidator = class {
1378
1381
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
1379
1382
  }
1380
1383
  validate() {
1381
- return [
1382
- ...this.validateContext(),
1383
- ...this.validateName(this.declarationNode.name),
1384
- ...this.validateAlias(this.declarationNode.alias),
1385
- ...this.validateSettingList(this.declarationNode.attributeList),
1386
- ...this.validateBody(this.declarationNode.body)
1387
- ];
1384
+ return {
1385
+ errors: [
1386
+ ...this.validateContext(),
1387
+ ...this.validateName(this.declarationNode.name),
1388
+ ...this.validateAlias(this.declarationNode.alias),
1389
+ ...this.validateSettingList(this.declarationNode.attributeList),
1390
+ ...this.validateBody(this.declarationNode.body)
1391
+ ],
1392
+ warnings: []
1393
+ };
1388
1394
  }
1389
1395
  validateContext() {
1390
1396
  return this.declarationNode.parent instanceof ProgramNode || getElementKind(this.declarationNode.parent).unwrap_or(void 0) !== ElementKind.Project ? [new CompileError(CompileErrorCode.INVALID_CUSTOM_CONTEXT, "A Custom element can only appear in a Project", this.declarationNode)] : [];
1391
1397
  }
1392
1398
  validateName(r) {
1393
- return r ? [new CompileError(CompileErrorCode.UNEXPECTED_NAME, "A Custom element shouldn't have a name", r)] : [];
1399
+ return r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a Custom element name", r)] : r ? [new CompileError(CompileErrorCode.UNEXPECTED_NAME, "A Custom element shouldn't have a name", r)] : [];
1394
1400
  }
1395
1401
  validateAlias(r) {
1396
1402
  return r ? [new CompileError(CompileErrorCode.UNEXPECTED_NAME, "A Custom element shouldn't have an alias", r)] : [];
@@ -1492,20 +1498,23 @@ var SymbolTable = class {
1492
1498
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
1493
1499
  }
1494
1500
  validate() {
1495
- return [
1496
- ...this.validateContext(),
1497
- ...this.validateName(this.declarationNode.name),
1498
- ...this.validateAlias(this.declarationNode.alias),
1499
- ...this.validateSettingList(this.declarationNode.attributeList),
1500
- ...this.registerElement(),
1501
- ...this.validateBody(this.declarationNode.body)
1502
- ];
1501
+ return {
1502
+ errors: [
1503
+ ...this.validateContext(),
1504
+ ...this.validateName(this.declarationNode.name),
1505
+ ...this.validateAlias(this.declarationNode.alias),
1506
+ ...this.validateSettingList(this.declarationNode.attributeList),
1507
+ ...this.registerElement(),
1508
+ ...this.validateBody(this.declarationNode.body)
1509
+ ],
1510
+ warnings: []
1511
+ };
1503
1512
  }
1504
1513
  validateContext() {
1505
1514
  return this.declarationNode.parent instanceof ElementDeclarationNode ? [new CompileError(CompileErrorCode.INVALID_PROJECT_CONTEXT, "An Enum can only appear top-level", this.declarationNode)] : [];
1506
1515
  }
1507
1516
  validateName(r) {
1508
- return r ? isValidName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "An Enum name must be of the form <enum> or <schema>.<enum>", r)] : [new CompileError(CompileErrorCode.NAME_NOT_FOUND, "An Enum must have a name", this.declarationNode)];
1517
+ return r ? r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as an Enum name", r)] : isValidName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "An Enum name must be of the form <enum> or <schema>.<enum>", r)] : [new CompileError(CompileErrorCode.NAME_NOT_FOUND, "An Enum must have a name", this.declarationNode)];
1509
1518
  }
1510
1519
  validateAlias(r) {
1511
1520
  return r ? [new CompileError(CompileErrorCode.UNEXPECTED_ALIAS, "An Enum shouldn't have an alias", r)] : [];
@@ -1556,7 +1565,7 @@ var SymbolTable = class {
1556
1565
  return M;
1557
1566
  }
1558
1567
  validateSubElements(r) {
1559
- return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : []));
1568
+ return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : []));
1560
1569
  }
1561
1570
  registerField(r) {
1562
1571
  if (r.callee && isExpressionAVariableNode(r.callee)) {
@@ -1576,13 +1585,16 @@ var SymbolTable = class {
1576
1585
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
1577
1586
  }
1578
1587
  validate() {
1579
- return [
1580
- ...this.validateContext(),
1581
- ...this.validateName(this.declarationNode.name),
1582
- ...this.validateAlias(this.declarationNode.alias),
1583
- ...this.validateSettingList(this.declarationNode.attributeList),
1584
- ...this.validateBody(this.declarationNode.body)
1585
- ];
1588
+ return {
1589
+ errors: [
1590
+ ...this.validateContext(),
1591
+ ...this.validateName(this.declarationNode.name),
1592
+ ...this.validateAlias(this.declarationNode.alias),
1593
+ ...this.validateSettingList(this.declarationNode.attributeList),
1594
+ ...this.validateBody(this.declarationNode.body)
1595
+ ],
1596
+ warnings: []
1597
+ };
1586
1598
  }
1587
1599
  validateContext() {
1588
1600
  let r = new CompileError(CompileErrorCode.INVALID_INDEXES_CONTEXT, "An Indexes can only appear inside a Table or a TablePartial", this.declarationNode);
@@ -1591,7 +1603,7 @@ var SymbolTable = class {
1591
1603
  return j && [ElementKind.Table, ElementKind.TablePartial].includes(j) ? [] : [r];
1592
1604
  }
1593
1605
  validateName(r) {
1594
- return r ? [new CompileError(CompileErrorCode.UNEXPECTED_NAME, "An Indexes shouldn't have a name", r)] : [];
1606
+ return r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as an Indexes name", r)] : r ? [new CompileError(CompileErrorCode.UNEXPECTED_NAME, "An Indexes shouldn't have a name", r)] : [];
1595
1607
  }
1596
1608
  validateAlias(r) {
1597
1609
  return r ? [new CompileError(CompileErrorCode.UNEXPECTED_ALIAS, "An Indexes shouldn't have an alias", r)] : [];
@@ -1643,20 +1655,23 @@ var SymbolTable = class {
1643
1655
  return M;
1644
1656
  }
1645
1657
  validateSubElements(r) {
1646
- return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : []));
1658
+ return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : []));
1647
1659
  }
1648
1660
  }, NoteValidator = class {
1649
1661
  constructor(r, j, M) {
1650
1662
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
1651
1663
  }
1652
1664
  validate() {
1653
- return [
1654
- ...this.validateContext(),
1655
- ...this.validateName(this.declarationNode.name),
1656
- ...this.validateAlias(this.declarationNode.alias),
1657
- ...this.validateSettingList(this.declarationNode.attributeList),
1658
- ...this.validateBody(this.declarationNode.body)
1659
- ];
1665
+ return {
1666
+ errors: [
1667
+ ...this.validateContext(),
1668
+ ...this.validateName(this.declarationNode.name),
1669
+ ...this.validateAlias(this.declarationNode.alias),
1670
+ ...this.validateSettingList(this.declarationNode.attributeList),
1671
+ ...this.validateBody(this.declarationNode.body)
1672
+ ],
1673
+ warnings: []
1674
+ };
1660
1675
  }
1661
1676
  validateContext() {
1662
1677
  return !(this.declarationNode.parent instanceof ProgramNode) && ![
@@ -1669,6 +1684,7 @@ var SymbolTable = class {
1669
1684
  validateName(r) {
1670
1685
  if (!(this.declarationNode.parent instanceof ProgramNode)) return r ? [new CompileError(CompileErrorCode.UNEXPECTED_NAME, "A Note shouldn't have a name", r)] : [];
1671
1686
  if (!r) return [new CompileError(CompileErrorCode.INVALID_NAME, "Sticky note must have a name", this.declarationNode)];
1687
+ if (r instanceof WildcardNode) return [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a Note name", r)];
1672
1688
  let j = destructureComplexVariable(r);
1673
1689
  if (!j.isOk()) return [new CompileError(CompileErrorCode.INVALID_NAME, "Invalid name for sticky note ", this.declarationNode)];
1674
1690
  let M = j.unwrap().join("."), N = createStickyNoteSymbolIndex(M);
@@ -1691,26 +1707,29 @@ var SymbolTable = class {
1691
1707
  return r.length === 0 ? [new CompileError(CompileErrorCode.EMPTY_NOTE, "A Note must have a content", this.declarationNode)] : (r.length > 1 && r.slice(1).forEach((r) => j.push(new CompileError(CompileErrorCode.NOTE_CONTENT_REDEFINED, "A Note can only contain one string", r))), isExpressionAQuotedString(r[0].callee) || j.push(new CompileError(CompileErrorCode.INVALID_NOTE, "A Note content must be a quoted string", r[0])), r[0].args.length > 0 && j.push(...r[0].args.map((r) => new CompileError(CompileErrorCode.INVALID_NOTE, "A Note can only contain one quoted string", r))), j);
1692
1708
  }
1693
1709
  validateSubElements(r) {
1694
- return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : []));
1710
+ return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : []));
1695
1711
  }
1696
1712
  }, ProjectValidator = class {
1697
1713
  constructor(r, j, M) {
1698
1714
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
1699
1715
  }
1700
1716
  validate() {
1701
- return [
1702
- ...this.validateContext(),
1703
- ...this.validateName(this.declarationNode.name),
1704
- ...this.validateAlias(this.declarationNode.alias),
1705
- ...this.validateSettingList(this.declarationNode.attributeList),
1706
- ...this.validateBody(this.declarationNode.body)
1707
- ];
1717
+ return {
1718
+ errors: [
1719
+ ...this.validateContext(),
1720
+ ...this.validateName(this.declarationNode.name),
1721
+ ...this.validateAlias(this.declarationNode.alias),
1722
+ ...this.validateSettingList(this.declarationNode.attributeList),
1723
+ ...this.validateBody(this.declarationNode.body)
1724
+ ],
1725
+ warnings: []
1726
+ };
1708
1727
  }
1709
1728
  validateContext() {
1710
1729
  return this.declarationNode.parent instanceof ElementDeclarationNode ? [new CompileError(CompileErrorCode.INVALID_PROJECT_CONTEXT, "A Project can only appear top-level", this.declarationNode)] : [];
1711
1730
  }
1712
1731
  validateName(r) {
1713
- return r ? isSimpleName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A Project's name is optional or must be an identifier or a quoted identifer", r)] : [];
1732
+ return r ? r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a Project name", r)] : isSimpleName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A Project's name is optional or must be an identifier or a quoted identifer", r)] : [];
1714
1733
  }
1715
1734
  validateAlias(r) {
1716
1735
  return r ? [new CompileError(CompileErrorCode.UNEXPECTED_ALIAS, "A Project shouldn't have an alias", r)] : [];
@@ -1725,26 +1744,29 @@ var SymbolTable = class {
1725
1744
  return [...j.map((r) => new CompileError(CompileErrorCode.INVALID_PROJECT_FIELD, "A Project can not have inline fields", r)), ...this.validateSubElements(M)];
1726
1745
  }
1727
1746
  validateSubElements(r) {
1728
- return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : []));
1747
+ return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : []));
1729
1748
  }
1730
1749
  }, RefValidator = class {
1731
1750
  constructor(r, j, M) {
1732
1751
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
1733
1752
  }
1734
1753
  validate() {
1735
- return [
1736
- ...this.validateContext(),
1737
- ...this.validateName(this.declarationNode.name),
1738
- ...this.validateAlias(this.declarationNode.alias),
1739
- ...this.validateSettingList(this.declarationNode.attributeList),
1740
- ...this.validateBody(this.declarationNode.body)
1741
- ];
1754
+ return {
1755
+ errors: [
1756
+ ...this.validateContext(),
1757
+ ...this.validateName(this.declarationNode.name),
1758
+ ...this.validateAlias(this.declarationNode.alias),
1759
+ ...this.validateSettingList(this.declarationNode.attributeList),
1760
+ ...this.validateBody(this.declarationNode.body)
1761
+ ],
1762
+ warnings: []
1763
+ };
1742
1764
  }
1743
1765
  validateContext() {
1744
1766
  return this.declarationNode.parent instanceof ProgramNode ? [] : [new CompileError(CompileErrorCode.INVALID_REF_CONTEXT, "A Ref must appear top-level", this.declarationNode)];
1745
1767
  }
1746
1768
  validateName(r) {
1747
- return r ? isSimpleName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A Ref's name is optional or must be an identifier or a quoted identifer", r)] : [];
1769
+ return r ? r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a Ref name", r)] : isSimpleName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A Ref's name is optional or must be an identifier or a quoted identifer", r)] : [];
1748
1770
  }
1749
1771
  validateAlias(r) {
1750
1772
  return r ? [new CompileError(CompileErrorCode.UNEXPECTED_ALIAS, "A Ref shouldn't have an alias", r)] : [];
@@ -1803,7 +1825,7 @@ var SymbolTable = class {
1803
1825
  return M;
1804
1826
  }
1805
1827
  validateSubElements(r) {
1806
- return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : []));
1828
+ return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : []));
1807
1829
  }
1808
1830
  };
1809
1831
  function isValidPolicy(r) {
@@ -1824,20 +1846,23 @@ var TableValidator = class {
1824
1846
  this.declarationNode = r, this.symbolFactory = M, this.publicSymbolTable = j;
1825
1847
  }
1826
1848
  validate() {
1827
- return [
1828
- ...this.validateContext(),
1829
- ...this.validateName(this.declarationNode.name),
1830
- ...this.validateAlias(this.declarationNode.alias),
1831
- ...this.validateSettingList(this.declarationNode.attributeList),
1832
- ...this.registerElement(),
1833
- ...this.validateBody(this.declarationNode.body)
1834
- ];
1849
+ return {
1850
+ errors: [
1851
+ ...this.validateContext(),
1852
+ ...this.validateName(this.declarationNode.name),
1853
+ ...this.validateAlias(this.declarationNode.alias),
1854
+ ...this.validateSettingList(this.declarationNode.attributeList),
1855
+ ...this.registerElement(),
1856
+ ...this.validateBody(this.declarationNode.body)
1857
+ ],
1858
+ warnings: []
1859
+ };
1835
1860
  }
1836
1861
  validateContext() {
1837
1862
  return this.declarationNode.parent instanceof ElementDeclarationNode ? [new CompileError(CompileErrorCode.INVALID_TABLE_CONTEXT, "Table must appear top-level", this.declarationNode)] : [];
1838
1863
  }
1839
1864
  validateName(r) {
1840
- return r ? r instanceof ArrayNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Invalid array as Table name, maybe you forget to add a space between the name and the setting list?", r)] : isValidName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A Table name must be of the form <table> or <schema>.<table>", r)] : [new CompileError(CompileErrorCode.NAME_NOT_FOUND, "A Table must have a name", this.declarationNode)];
1865
+ return r ? r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a Table name", r)] : r instanceof ArrayNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Invalid array as Table name, maybe you forget to add a space between the name and the setting list?", r)] : isValidName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A Table name must be of the form <table> or <schema>.<table>", r)] : [new CompileError(CompileErrorCode.NAME_NOT_FOUND, "A Table must have a name", this.declarationNode)];
1841
1866
  }
1842
1867
  validateAlias(r) {
1843
1868
  return r ? isValidAlias(r) ? [] : [new CompileError(CompileErrorCode.INVALID_ALIAS, "Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes", r)] : [];
@@ -1997,7 +2022,7 @@ var TableValidator = class {
1997
2022
  }), N;
1998
2023
  }
1999
2024
  validateSubElements(r) {
2000
- let j = r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : [])), M = r.filter((r) => r.type?.value.toLowerCase() === "note");
2025
+ let j = r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : [])), M = r.filter((r) => r.type?.value.toLowerCase() === "note");
2001
2026
  return M.length > 1 && j.push(...M.map((r) => new CompileError(CompileErrorCode.NOTE_REDEFINED, "Duplicate notes are defined", r))), j;
2002
2027
  }
2003
2028
  };
@@ -2009,20 +2034,23 @@ var TableGroupValidator = class {
2009
2034
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
2010
2035
  }
2011
2036
  validate() {
2012
- return [
2013
- ...this.validateContext(),
2014
- ...this.validateName(this.declarationNode.name),
2015
- ...this.validateAlias(this.declarationNode.alias),
2016
- ...this.validateSettingList(this.declarationNode.attributeList),
2017
- ...this.registerElement(),
2018
- ...this.validateBody(this.declarationNode.body)
2019
- ];
2037
+ return {
2038
+ errors: [
2039
+ ...this.validateContext(),
2040
+ ...this.validateName(this.declarationNode.name),
2041
+ ...this.validateAlias(this.declarationNode.alias),
2042
+ ...this.validateSettingList(this.declarationNode.attributeList),
2043
+ ...this.registerElement(),
2044
+ ...this.validateBody(this.declarationNode.body)
2045
+ ],
2046
+ warnings: []
2047
+ };
2020
2048
  }
2021
2049
  validateContext() {
2022
2050
  return this.declarationNode.parent instanceof ElementDeclarationNode ? [new CompileError(CompileErrorCode.INVALID_TABLEGROUP_CONTEXT, "TableGroup must appear top-level", this.declarationNode)] : [];
2023
2051
  }
2024
2052
  validateName(r) {
2025
- return r ? isSimpleName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A TableGroup name must be a single identifier", r)] : [new CompileError(CompileErrorCode.NAME_NOT_FOUND, "A TableGroup must have a name", this.declarationNode)];
2053
+ return r ? r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a TableGroup name", r)] : isSimpleName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A TableGroup name must be a single identifier", r)] : [new CompileError(CompileErrorCode.NAME_NOT_FOUND, "A TableGroup must have a name", this.declarationNode)];
2026
2054
  }
2027
2055
  validateAlias(r) {
2028
2056
  return r ? [new CompileError(CompileErrorCode.UNEXPECTED_ALIAS, "A TableGroup shouldn't have an alias", r)] : [];
@@ -2074,7 +2102,7 @@ var TableGroupValidator = class {
2074
2102
  });
2075
2103
  }
2076
2104
  validateSubElements(r) {
2077
- let j = r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : [])), M = r.filter((r) => r.type?.value.toLowerCase() === "note");
2105
+ let j = r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : [])), M = r.filter((r) => r.type?.value.toLowerCase() === "note");
2078
2106
  return M.length > 1 && j.push(...M.map((r) => new CompileError(CompileErrorCode.NOTE_REDEFINED, "Duplicate notes are defined", r))), j;
2079
2107
  }
2080
2108
  registerField(r) {
@@ -2095,20 +2123,23 @@ var TableGroupValidator = class {
2095
2123
  this.declarationNode = r, this.symbolFactory = M, this.publicSymbolTable = j;
2096
2124
  }
2097
2125
  validate() {
2098
- return [
2099
- ...this.validateContext(),
2100
- ...this.validateName(this.declarationNode.name),
2101
- ...this.validateAlias(this.declarationNode.alias),
2102
- ...this.validateSettingList(this.declarationNode.attributeList),
2103
- ...this.registerElement(),
2104
- ...this.validateBody(this.declarationNode.body)
2105
- ];
2126
+ return {
2127
+ errors: [
2128
+ ...this.validateContext(),
2129
+ ...this.validateName(this.declarationNode.name),
2130
+ ...this.validateAlias(this.declarationNode.alias),
2131
+ ...this.validateSettingList(this.declarationNode.attributeList),
2132
+ ...this.registerElement(),
2133
+ ...this.validateBody(this.declarationNode.body)
2134
+ ],
2135
+ warnings: []
2136
+ };
2106
2137
  }
2107
2138
  validateContext() {
2108
2139
  return this.declarationNode.parent instanceof ElementDeclarationNode ? [new CompileError(CompileErrorCode.INVALID_TABLE_PARTIAL_CONTEXT, "TablePartial must appear top-level", this.declarationNode)] : [];
2109
2140
  }
2110
2141
  validateName(r) {
2111
- return r ? isSimpleName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A TablePartial name must be an identifier or a quoted identifer", r)] : [new CompileError(CompileErrorCode.NAME_NOT_FOUND, "A TablePartial must have a name", this.declarationNode)];
2142
+ return r ? r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a TablePartial name", r)] : isSimpleName(r) ? [] : [new CompileError(CompileErrorCode.INVALID_NAME, "A TablePartial name must be an identifier or a quoted identifer", r)] : [new CompileError(CompileErrorCode.NAME_NOT_FOUND, "A TablePartial must have a name", this.declarationNode)];
2112
2143
  }
2113
2144
  validateAlias(r) {
2114
2145
  return r ? [new CompileError(CompileErrorCode.UNEXPECTED_ALIAS, "A TablePartial shouldn't have an alias", r)] : [];
@@ -2244,7 +2275,7 @@ var TableGroupValidator = class {
2244
2275
  }), P;
2245
2276
  }
2246
2277
  validateSubElements(r) {
2247
- let j = r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : [])), M = r.filter((r) => r.type?.value.toLowerCase() === ElementKind.Note);
2278
+ let j = r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : [])), M = r.filter((r) => r.type?.value.toLowerCase() === ElementKind.Note);
2248
2279
  return M.length > 1 && j.push(...M.map((r) => new CompileError(CompileErrorCode.NOTE_REDEFINED, "Duplicate notes are defined", r))), j;
2249
2280
  }
2250
2281
  }, ChecksValidator = class {
@@ -2252,13 +2283,16 @@ var TableGroupValidator = class {
2252
2283
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
2253
2284
  }
2254
2285
  validate() {
2255
- return [
2256
- ...this.validateContext(),
2257
- ...this.validateName(this.declarationNode.name),
2258
- ...this.validateAlias(this.declarationNode.alias),
2259
- ...this.validateSettingList(this.declarationNode.attributeList),
2260
- ...this.validateBody(this.declarationNode.body)
2261
- ];
2286
+ return {
2287
+ errors: [
2288
+ ...this.validateContext(),
2289
+ ...this.validateName(this.declarationNode.name),
2290
+ ...this.validateAlias(this.declarationNode.alias),
2291
+ ...this.validateSettingList(this.declarationNode.attributeList),
2292
+ ...this.validateBody(this.declarationNode.body)
2293
+ ],
2294
+ warnings: []
2295
+ };
2262
2296
  }
2263
2297
  validateContext() {
2264
2298
  let r = new CompileError(CompileErrorCode.INVALID_CHECKS_CONTEXT, "A Checks can only appear inside a Table or a TablePartial", this.declarationNode);
@@ -2267,7 +2301,7 @@ var TableGroupValidator = class {
2267
2301
  return j && [ElementKind.Table, ElementKind.TablePartial].includes(j) ? [] : [r];
2268
2302
  }
2269
2303
  validateName(r) {
2270
- return r ? [new CompileError(CompileErrorCode.UNEXPECTED_NAME, "A Checks shouldn't have a name", r)] : [];
2304
+ return r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a Checks name", r)] : r ? [new CompileError(CompileErrorCode.UNEXPECTED_NAME, "A Checks shouldn't have a name", r)] : [];
2271
2305
  }
2272
2306
  validateAlias(r) {
2273
2307
  return r ? [new CompileError(CompileErrorCode.UNEXPECTED_ALIAS, "A Checks shouldn't have an alias", r)] : [];
@@ -2304,27 +2338,30 @@ var TableGroupValidator = class {
2304
2338
  return M;
2305
2339
  }
2306
2340
  validateSubElements(r) {
2307
- return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : []));
2341
+ return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : []));
2308
2342
  }
2309
2343
  }, RecordsValidator = class {
2310
2344
  constructor(r, j, M) {
2311
2345
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
2312
2346
  }
2313
2347
  validate() {
2314
- return [
2315
- ...this.validateContext(),
2316
- ...this.validateName(this.declarationNode.name),
2317
- ...this.validateAlias(this.declarationNode.alias),
2318
- ...this.validateSettingList(this.declarationNode.attributeList),
2319
- ...this.validateBody(this.declarationNode.body)
2320
- ];
2348
+ return {
2349
+ errors: [
2350
+ ...this.validateContext(),
2351
+ ...this.validateName(this.declarationNode.name),
2352
+ ...this.validateAlias(this.declarationNode.alias),
2353
+ ...this.validateSettingList(this.declarationNode.attributeList),
2354
+ ...this.validateBody(this.declarationNode.body)
2355
+ ],
2356
+ warnings: []
2357
+ };
2321
2358
  }
2322
2359
  validateContext() {
2323
2360
  let r = this.declarationNode.parent;
2324
2361
  return r instanceof ProgramNode || r instanceof ElementDeclarationNode && getElementKind(r).unwrap_or(void 0) === ElementKind.Table ? [] : [new CompileError(CompileErrorCode.INVALID_RECORDS_CONTEXT, "Records can only appear at top-level or inside a Table", this.declarationNode)];
2325
2362
  }
2326
2363
  validateName(r) {
2327
- return this.declarationNode.parent instanceof ProgramNode ? this.validateTopLevelName(r) : this.validateInsideTableName(r);
2364
+ return r instanceof WildcardNode ? [new CompileError(CompileErrorCode.INVALID_NAME, "Wildcard (*) is not allowed as a Records name", r)] : this.declarationNode.parent instanceof ProgramNode ? this.validateTopLevelName(r) : this.validateInsideTableName(r);
2328
2365
  }
2329
2366
  validateTopLevelName(r) {
2330
2367
  if (!(r instanceof CallExpressionNode)) return [new CompileError(CompileErrorCode.INVALID_RECORDS_NAME, "Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)", r || this.declarationNode.type)];
@@ -2369,25 +2406,24 @@ var TableGroupValidator = class {
2369
2406
  return !1;
2370
2407
  }
2371
2408
  validateSubElements(r) {
2372
- return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate() : []));
2409
+ return r.flatMap((r) => (r.parent = this.declarationNode, r.type ? new (pickValidator(r))(r, this.publicSymbolTable, this.symbolFactory).validate().errors : []));
2373
2410
  }
2374
- };
2375
- function isWildcardExpression$2(r) {
2376
- return r && r instanceof PrimaryExpressionNode && r.expression instanceof VariableNode ? r.expression.variable?.value === "*" : !1;
2377
- }
2378
- var DiagramViewValidator = class {
2411
+ }, DiagramViewValidator = class {
2379
2412
  constructor(r, j, M) {
2380
2413
  this.declarationNode = r, this.publicSymbolTable = j, this.symbolFactory = M;
2381
2414
  }
2382
2415
  validate() {
2383
- return [
2416
+ let r = [
2384
2417
  ...this.validateContext(),
2385
2418
  ...this.validateName(this.declarationNode.name),
2386
2419
  ...this.validateAlias(this.declarationNode.alias),
2387
2420
  ...this.validateSettingList(this.declarationNode.attributeList),
2388
- ...this.registerElement(),
2389
- ...this.validateBody(this.declarationNode.body)
2390
- ];
2421
+ ...this.registerElement()
2422
+ ], j = this.validateBody(this.declarationNode.body);
2423
+ return r.push(...j.errors), {
2424
+ errors: r,
2425
+ warnings: j.warnings
2426
+ };
2391
2427
  }
2392
2428
  validateContext() {
2393
2429
  return this.declarationNode.parent instanceof ElementDeclarationNode ? [new CompileError(CompileErrorCode.INVALID_DIAGRAMVIEW_CONTEXT, "DiagramView must appear top-level", this.declarationNode)] : [];
@@ -2418,41 +2454,60 @@ var DiagramViewValidator = class {
2418
2454
  return M;
2419
2455
  }
2420
2456
  validateBody(r) {
2421
- if (!r) return [];
2422
- if (r instanceof FunctionApplicationNode) return [new CompileError(CompileErrorCode.UNEXPECTED_SIMPLE_BODY, "A DiagramView's body must be a block", r)];
2423
- let [j, M] = partition_default(r.body, (r) => r instanceof FunctionApplicationNode);
2424
- return [...this.validateFields(j), ...this.validateSubElements(M)];
2457
+ if (!r) return {
2458
+ errors: [],
2459
+ warnings: []
2460
+ };
2461
+ if (r instanceof FunctionApplicationNode) return {
2462
+ errors: [new CompileError(CompileErrorCode.UNEXPECTED_SIMPLE_BODY, "A DiagramView's body must be a block", r)],
2463
+ warnings: []
2464
+ };
2465
+ let [j, M] = partition_default(r.body, (r) => r instanceof FunctionApplicationNode), N = this.validateSubElements(M);
2466
+ return {
2467
+ errors: [...this.validateFields(j), ...N.errors],
2468
+ warnings: N.warnings
2469
+ };
2425
2470
  }
2426
2471
  validateFields(r) {
2427
2472
  return r.flatMap((r) => {
2428
- if (isWildcardExpression$2(r.callee)) return [];
2473
+ if (isWildcardExpression(r.callee)) return r.args.length > 0 ? r.args.map((r) => new CompileError(CompileErrorCode.INVALID_DIAGRAMVIEW_FIELD, "DiagramView field should only have a single name", r)) : [];
2429
2474
  let j = [];
2430
2475
  return j.push(new CompileError(CompileErrorCode.INVALID_DIAGRAMVIEW_FIELD, "Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.", r)), j;
2431
2476
  });
2432
2477
  }
2433
2478
  validateSubElements(r) {
2434
- let j = [], M = [
2479
+ let j = [], M = [], N = [
2435
2480
  "tables",
2436
2481
  "notes",
2437
2482
  "tablegroups",
2438
2483
  "schemas"
2439
2484
  ];
2440
- for (let N of r) {
2441
- if (N.parent = this.declarationNode, !N.type) continue;
2442
- let r = N.type.value.toLowerCase();
2443
- if (!M.includes(r)) {
2444
- j.push(new CompileError(CompileErrorCode.INVALID_DIAGRAMVIEW_FIELD, `Unknown block type "${N.type.value}" in DiagramView. Allowed: Tables, Notes, TableGroups, Schemas`, N));
2485
+ for (let P of r) {
2486
+ if (P.parent = this.declarationNode, !P.type) continue;
2487
+ let r = P.type.value.toLowerCase();
2488
+ if (!N.includes(r)) {
2489
+ j.push(new CompileError(CompileErrorCode.INVALID_DIAGRAMVIEW_FIELD, `Unknown block type "${P.type.value}" in DiagramView. Allowed: Tables, Notes, TableGroups, Schemas`, P));
2445
2490
  continue;
2446
2491
  }
2447
- j.push(...this.validateSubBlock(N)), j.push(...this.registerSubBlockFields(N));
2492
+ let F = this.validateSubBlock(P);
2493
+ j.push(...F.errors), M.push(...F.warnings);
2448
2494
  }
2449
- return j;
2495
+ return {
2496
+ errors: j,
2497
+ warnings: M
2498
+ };
2450
2499
  }
2451
2500
  validateSubBlock(r) {
2452
- let j = [];
2453
- if (!r.body || !(r.body instanceof BlockExpressionNode)) return j;
2454
- let M = r.body, N = M.body.some((r) => r instanceof FunctionApplicationNode && isWildcardExpression$2(r.callee)), P = M.body.some((r) => r instanceof FunctionApplicationNode && !isWildcardExpression$2(r.callee));
2455
- return N && P && j.push(new CompileWarning(CompileErrorCode.INVALID_DIAGRAMVIEW_FIELD, `Wildcard (*) combined with specific items in ${r.type?.value} block. Specific items will be ignored.`, r)), j;
2501
+ let j = [], M = [];
2502
+ if (!r.body || !(r.body instanceof BlockExpressionNode)) return {
2503
+ errors: j,
2504
+ warnings: M
2505
+ };
2506
+ let N = r.body, P = N.body.some((r) => r instanceof FunctionApplicationNode && isWildcardExpression(r.callee)), F = N.body.some((r) => r instanceof FunctionApplicationNode && !isWildcardExpression(r.callee));
2507
+ return P && F && M.push(new CompileWarning(CompileErrorCode.INVALID_DIAGRAMVIEW_FIELD, `Wildcard (*) combined with specific items in ${r.type?.value} block. Specific items will be ignored.`, r)), j.push(...this.registerSubBlockFields(r)), {
2508
+ errors: j,
2509
+ warnings: M
2510
+ };
2456
2511
  }
2457
2512
  registerSubBlockFields(r) {
2458
2513
  let j = [];
@@ -2460,7 +2515,7 @@ var DiagramViewValidator = class {
2460
2515
  let M = r.body.body.filter((r) => r instanceof FunctionApplicationNode);
2461
2516
  for (let r of M) {
2462
2517
  if (r.callee && isExpressionAVariableNode(r.callee)) {
2463
- if (isWildcardExpression$2(r.callee)) continue;
2518
+ if (isWildcardExpression(r.callee)) continue;
2464
2519
  let M = extractVarNameFromPrimaryVariable(r.callee).unwrap(), N = createDiagramViewFieldSymbolIndex(M), P = this.symbolFactory.create(DiagramViewFieldSymbol, { declaration: r });
2465
2520
  r.symbol = P;
2466
2521
  let F = this.declarationNode.symbol.symbolTable;
@@ -2761,6 +2816,7 @@ function getMemberChain(r) {
2761
2816
  if (r instanceof CallExpressionNode) return filterUndefined(r.callee, r.argumentList);
2762
2817
  if (r instanceof PrimaryExpressionNode) return filterUndefined(r.expression);
2763
2818
  if (r instanceof ArrayNode) return filterUndefined(r.array, r.indexer);
2819
+ if (r instanceof WildcardNode) return filterUndefined(r.token);
2764
2820
  throw r instanceof GroupExpressionNode ? Error("This case is already handled by TupleExpressionNode") : Error("Unreachable - no other possible cases");
2765
2821
  }
2766
2822
  function extractVariableNode(r) {
@@ -2772,6 +2828,9 @@ function isExpressionAQuotedString(r) {
2772
2828
  function isExpressionAVariableNode(r) {
2773
2829
  return r instanceof PrimaryExpressionNode && r.expression instanceof VariableNode && r.expression.variable instanceof SyntaxToken;
2774
2830
  }
2831
+ function isWildcardExpression(r) {
2832
+ return r ? r instanceof WildcardNode : !1;
2833
+ }
2775
2834
  function isExpressionAnIdentifierNode(r) {
2776
2835
  return r instanceof PrimaryExpressionNode && r.expression instanceof VariableNode && r.expression.variable?.kind === SyntaxTokenKind.IDENTIFIER;
2777
2836
  }
@@ -2883,6 +2942,9 @@ var Lexer = class {
2883
2942
  case "/":
2884
2943
  this.match("/") ? this.singleLineComment() : this.match("*") ? this.multilineComment() : this.operator(r);
2885
2944
  break;
2945
+ case "*":
2946
+ this.addToken(SyntaxTokenKind.WILDCARD);
2947
+ break;
2886
2948
  default:
2887
2949
  if (isOp(r)) {
2888
2950
  this.operator(r);
@@ -3531,8 +3593,7 @@ var ParsingContextStack = class {
3531
3593
  }
3532
3594
  leftExpression_bp() {
3533
3595
  let r;
3534
- if (this.check(SyntaxTokenKind.OP) && this.peek().value === "*") this.advance(), r = this.nodeFactory.create(PrimaryExpressionNode, { expression: this.nodeFactory.create(VariableNode, { variable: this.previous() }) });
3535
- else if (isOpToken(this.peek())) {
3596
+ if (isOpToken(this.peek())) {
3536
3597
  let j = {};
3537
3598
  j.op = this.peek();
3538
3599
  let M = prefixBindingPower(j.op);
@@ -3548,7 +3609,7 @@ var ParsingContextStack = class {
3548
3609
  return r;
3549
3610
  }
3550
3611
  extractOperand() {
3551
- return this.check(SyntaxTokenKind.NUMERIC_LITERAL, SyntaxTokenKind.STRING_LITERAL, SyntaxTokenKind.COLOR_LITERAL, SyntaxTokenKind.QUOTED_STRING, SyntaxTokenKind.IDENTIFIER) ? this.primaryExpression() : this.check(SyntaxTokenKind.FUNCTION_EXPRESSION) ? this.functionExpression() : this.check(SyntaxTokenKind.LBRACKET) ? this.listExpression() : this.check(SyntaxTokenKind.LBRACE) ? this.blockExpression() : this.check(SyntaxTokenKind.LPAREN) ? this.tupleExpression() : (this.peek().kind === SyntaxTokenKind.EOF ? this.logError(this.peek(), CompileErrorCode.UNEXPECTED_EOF, "Unexpected EOF") : this.logError(this.peek(), CompileErrorCode.INVALID_OPERAND, `Invalid start of operand "${this.peek().value}"`), this.nodeFactory.create(EmptyNode, { prevToken: this.previous() }));
3612
+ return this.check(SyntaxTokenKind.WILDCARD) ? (this.advance(), this.nodeFactory.create(WildcardNode, { token: this.previous() })) : this.check(SyntaxTokenKind.NUMERIC_LITERAL, SyntaxTokenKind.STRING_LITERAL, SyntaxTokenKind.COLOR_LITERAL, SyntaxTokenKind.QUOTED_STRING, SyntaxTokenKind.IDENTIFIER) ? this.primaryExpression() : this.check(SyntaxTokenKind.FUNCTION_EXPRESSION) ? this.functionExpression() : this.check(SyntaxTokenKind.LBRACKET) ? this.listExpression() : this.check(SyntaxTokenKind.LBRACE) ? this.blockExpression() : this.check(SyntaxTokenKind.LPAREN) ? this.tupleExpression() : (this.peek().kind === SyntaxTokenKind.EOF ? this.logError(this.peek(), CompileErrorCode.UNEXPECTED_EOF, "Unexpected EOF") : this.logError(this.peek(), CompileErrorCode.INVALID_OPERAND, `Invalid start of operand "${this.peek().value}"`), this.nodeFactory.create(EmptyNode, { prevToken: this.previous() }));
3552
3613
  }
3553
3614
  functionExpression() {
3554
3615
  let r = {};
@@ -3609,10 +3670,6 @@ var ParsingContextStack = class {
3609
3670
  left: 9,
3610
3671
  right: 10
3611
3672
  },
3612
- "*": {
3613
- left: 11,
3614
- right: 12
3615
- },
3616
3673
  "-": {
3617
3674
  left: 9,
3618
3675
  right: 10
@@ -3719,14 +3776,14 @@ var Validator = class {
3719
3776
  this.ast = r, this.symbolFactory = j, this.publicSchemaSymbol = this.symbolFactory.create(SchemaSymbol, { symbolTable: new SymbolTable() }), this.ast.symbol = this.publicSchemaSymbol, this.ast.symbol.declaration = this.ast;
3720
3777
  }
3721
3778
  validate() {
3722
- let r = [];
3723
- this.ast.body.forEach((j) => {
3724
- if (j.parent = this.ast, j.type === void 0) return;
3725
- let M = new (pickValidator(j))(j, this.publicSchemaSymbol.symbolTable, this.symbolFactory);
3726
- r.push(...M.validate());
3779
+ let r = [], j = [];
3780
+ this.ast.body.forEach((M) => {
3781
+ if (M.parent = this.ast, M.type === void 0) return;
3782
+ let N = new (pickValidator(M))(M, this.publicSchemaSymbol.symbolTable, this.symbolFactory).validate();
3783
+ r.push(...N.errors), j.push(...N.warnings);
3727
3784
  });
3728
- let j = this.ast.body.filter((r) => getElementKind(r).unwrap_or(void 0) === ElementKind.Project);
3729
- return j.length > 1 && j.forEach((j) => r.push(new CompileError(CompileErrorCode.PROJECT_REDEFINED, "Only one project can exist", j))), new Report(this.ast, r);
3785
+ let M = this.ast.body.filter((r) => getElementKind(r).unwrap_or(void 0) === ElementKind.Project);
3786
+ return M.length > 1 && M.forEach((j) => r.push(new CompileError(CompileErrorCode.PROJECT_REDEFINED, "Only one project can exist", j))), new Report(this.ast, r, j);
3730
3787
  }
3731
3788
  }, ChecksBinder = class {
3732
3789
  constructor(r, j, M) {
@@ -3750,11 +3807,7 @@ var Validator = class {
3750
3807
  bindSubElements(r) {
3751
3808
  return r.flatMap((r) => r.type ? new (pickBinder(r))(r, this.ast, this.symbolFactory).bind() : []);
3752
3809
  }
3753
- };
3754
- function isWildcardExpression$1(r) {
3755
- return r && r instanceof PrimaryExpressionNode && r.expression instanceof VariableNode ? r.expression.variable?.value === "*" : !1;
3756
- }
3757
- var DiagramViewBinder = class {
3810
+ }, DiagramViewBinder = class {
3758
3811
  constructor(r, j, M) {
3759
3812
  this.declarationNode = r, this.ast = j, this.symbolFactory = M;
3760
3813
  }
@@ -3791,7 +3844,7 @@ var DiagramViewBinder = class {
3791
3844
  }
3792
3845
  bindTableReferences(r) {
3793
3846
  let [j] = partition_default(r.body, (r) => r instanceof FunctionApplicationNode);
3794
- return j.flatMap((r) => !r.callee || isWildcardExpression$1(r.callee) ? [] : [r.callee, ...r.args].flatMap(scanNonListNodeForBinding).flatMap((r) => {
3847
+ return j.flatMap((r) => !r.callee || isWildcardExpression(r.callee) ? [] : [r.callee, ...r.args].flatMap(scanNonListNodeForBinding).flatMap((r) => {
3795
3848
  let j = r.variables.pop();
3796
3849
  if (!j) return [];
3797
3850
  let M = r.variables;
@@ -3806,7 +3859,7 @@ var DiagramViewBinder = class {
3806
3859
  }
3807
3860
  bindNoteReferences(r) {
3808
3861
  let [j] = partition_default(r.body, (r) => r instanceof FunctionApplicationNode);
3809
- return j.flatMap((r) => !r.callee || isWildcardExpression$1(r.callee) ? [] : scanNonListNodeForBinding(r.callee).flatMap((r) => {
3862
+ return j.flatMap((r) => !r.callee || isWildcardExpression(r.callee) ? [] : scanNonListNodeForBinding(r.callee).flatMap((r) => {
3810
3863
  let j = r.variables.pop();
3811
3864
  return j ? lookupAndBindInScope(this.ast, [{
3812
3865
  node: j,
@@ -3816,7 +3869,7 @@ var DiagramViewBinder = class {
3816
3869
  }
3817
3870
  bindTableGroupReferences(r) {
3818
3871
  let [j] = partition_default(r.body, (r) => r instanceof FunctionApplicationNode);
3819
- return j.flatMap((r) => !r.callee || isWildcardExpression$1(r.callee) ? [] : scanNonListNodeForBinding(r.callee).flatMap((r) => {
3872
+ return j.flatMap((r) => !r.callee || isWildcardExpression(r.callee) ? [] : scanNonListNodeForBinding(r.callee).flatMap((r) => {
3820
3873
  let j = r.variables.pop();
3821
3874
  if (!j) return [];
3822
3875
  let M = r.variables;
@@ -3831,13 +3884,10 @@ var DiagramViewBinder = class {
3831
3884
  }
3832
3885
  bindSchemaReferences(r) {
3833
3886
  let [j] = partition_default(r.body, (r) => r instanceof FunctionApplicationNode);
3834
- return j.flatMap((r) => !r.callee || isWildcardExpression$1(r.callee) ? [] : scanNonListNodeForBinding(r.callee).flatMap((r) => {
3835
- let j = r.variables.pop();
3836
- return j ? lookupAndBindInScope(this.ast, [{
3837
- node: j,
3838
- kind: SymbolKind.Schema
3839
- }]) : [];
3840
- }));
3887
+ return j.flatMap((r) => !r.callee || isWildcardExpression(r.callee) ? [] : scanNonListNodeForBinding(r.callee).flatMap((r) => lookupAndBindInScope(this.ast, r.variables.map((r) => ({
3888
+ node: r,
3889
+ kind: SymbolKind.Schema
3890
+ })))));
3841
3891
  }
3842
3892
  }, EnumBinder = class {
3843
3893
  constructor(r, j, M) {
@@ -4168,7 +4218,9 @@ function generatePossibleIndexes(r) {
4168
4218
  createEnumFieldSymbolIndex,
4169
4219
  createTableGroupFieldSymbolIndex,
4170
4220
  createTablePartialSymbolIndex,
4171
- createPartialInjectionSymbolIndex
4221
+ createPartialInjectionSymbolIndex,
4222
+ createDiagramViewSymbolIndex,
4223
+ createDiagramViewFieldSymbolIndex
4172
4224
  ].map((j) => j(r));
4173
4225
  }
4174
4226
  function getSymbolKind(r) {
@@ -4183,6 +4235,8 @@ function getSymbolKind(r) {
4183
4235
  if (r instanceof TablePartialInjectedColumnSymbol) return SymbolKind.Column;
4184
4236
  if (r instanceof PartialInjectionSymbol) return SymbolKind.PartialInjection;
4185
4237
  if (r instanceof StickyNoteSymbol) return SymbolKind.Note;
4238
+ if (r instanceof DiagramViewSymbol) return SymbolKind.DiagramView;
4239
+ if (r instanceof DiagramViewFieldSymbol) return SymbolKind.DiagramViewField;
4186
4240
  throw Error("No other possible symbol kind in getSymbolKind");
4187
4241
  }
4188
4242
  var RecordsBinder = class {
@@ -5127,26 +5181,18 @@ var TableInterpreter = class {
5127
5181
  }
5128
5182
  });
5129
5183
  }
5130
- };
5131
- function isWildcardExpression(r) {
5132
- return r && r instanceof PrimaryExpressionNode && r.expression instanceof VariableNode ? r.expression.variable?.value === "*" : !1;
5133
- }
5134
- var DiagramViewInterpreter = class {
5184
+ }, DiagramViewInterpreter = class {
5135
5185
  constructor(r, j) {
5136
- this.declarationNode = r, this.env = j, this.diagramView = {
5137
- visibleEntities: {
5138
- tables: null,
5139
- stickyNotes: null,
5140
- tableGroups: null,
5141
- schemas: null
5142
- },
5143
- _explicitWildcards: /* @__PURE__ */ new Set(),
5144
- _explicitlySet: /* @__PURE__ */ new Set()
5145
- };
5186
+ this.declarationNode = r, this.env = j, this.diagramView = { visibleEntities: {
5187
+ tables: null,
5188
+ stickyNotes: null,
5189
+ tableGroups: null,
5190
+ schemas: null
5191
+ } };
5146
5192
  }
5147
5193
  interpret() {
5148
5194
  let r = [];
5149
- return this.diagramView.token = getTokenPosition(this.declarationNode), this.env.diagramViews || (this.env.diagramViews = /* @__PURE__ */ new Map()), this.env.diagramViews.set(this.declarationNode, this.diagramView), this.declarationNode.name && r.push(...this.interpretName(this.declarationNode.name)), this.declarationNode.body instanceof BlockExpressionNode && r.push(...this.interpretBody(this.declarationNode.body)), r;
5195
+ return this.diagramView.token = getTokenPosition(this.declarationNode), this.env.diagramViews.set(this.declarationNode, this.diagramView), this.env.diagramViewWildcards.set(this.diagramView, /* @__PURE__ */ new Set()), this.env.diagramViewExplicitlySet.set(this.diagramView, /* @__PURE__ */ new Set()), this.declarationNode.name && r.push(...this.interpretName(this.declarationNode.name)), this.declarationNode.body instanceof BlockExpressionNode && r.push(...this.interpretBody(this.declarationNode.body)), r;
5150
5196
  }
5151
5197
  interpretName(r) {
5152
5198
  let j = destructureComplexVariable(r).unwrap_or([]);
@@ -5160,17 +5206,17 @@ var DiagramViewInterpreter = class {
5160
5206
  stickyNotes: [],
5161
5207
  tableGroups: [],
5162
5208
  schemas: []
5163
- }, this.diagramView._explicitWildcards = new Set([
5209
+ }, this.env.diagramViewWildcards.set(this.diagramView, new Set([
5164
5210
  "tables",
5165
5211
  "stickyNotes",
5166
5212
  "tableGroups",
5167
5213
  "schemas"
5168
- ]), this.diagramView._explicitlySet = new Set([
5214
+ ])), this.env.diagramViewExplicitlySet.set(this.diagramView, new Set([
5169
5215
  "tables",
5170
5216
  "stickyNotes",
5171
5217
  "tableGroups",
5172
5218
  "schemas"
5173
- ]), [];
5219
+ ])), [];
5174
5220
  }
5175
5221
  let [j] = partition_default(r.body, (r) => r instanceof ElementDeclarationNode), M = /* @__PURE__ */ new Set();
5176
5222
  for (let r of j) {
@@ -5178,23 +5224,26 @@ var DiagramViewInterpreter = class {
5178
5224
  j && M.add(j), r.body instanceof BlockExpressionNode && this.interpretSubBlock(r.body, j);
5179
5225
  }
5180
5226
  let N = this.diagramView.visibleEntities;
5181
- return (M.has("tables") && N.tables !== null || M.has("tablegroups") && N.tableGroups !== null || M.has("schemas") && N.schemas !== null) && (M.has("tables") || (N.tables = []), M.has("tablegroups") || (N.tableGroups = []), M.has("schemas") || (N.schemas = [])), M.has("tables") && this.diagramView._explicitlySet.add("tables"), M.has("tablegroups") && this.diagramView._explicitlySet.add("tableGroups"), M.has("schemas") && this.diagramView._explicitlySet.add("schemas"), M.has("notes") && this.diagramView._explicitlySet.add("stickyNotes"), [];
5227
+ (M.has("tables") && N.tables !== null || M.has("tablegroups") && N.tableGroups !== null || M.has("schemas") && N.schemas !== null) && (M.has("tables") || (N.tables = []), M.has("tablegroups") || (N.tableGroups = []), M.has("schemas") || (N.schemas = []));
5228
+ let P = this.env.diagramViewExplicitlySet.get(this.diagramView);
5229
+ return M.has("tables") && P.add("tables"), M.has("tablegroups") && P.add("tableGroups"), M.has("schemas") && P.add("schemas"), M.has("notes") && P.add("stickyNotes"), [];
5182
5230
  }
5183
5231
  interpretSubBlock(r, j) {
5184
5232
  if (!j) return;
5185
5233
  if (r.body.some((r) => r instanceof FunctionApplicationNode && isWildcardExpression(r.callee))) {
5234
+ let r = this.env.diagramViewWildcards.get(this.diagramView);
5186
5235
  switch (j) {
5187
5236
  case "tables":
5188
- this.diagramView.visibleEntities.tables = [], this.diagramView._explicitWildcards.add("tables");
5237
+ this.diagramView.visibleEntities.tables = [], r.add("tables");
5189
5238
  break;
5190
5239
  case "notes":
5191
- this.diagramView.visibleEntities.stickyNotes = [], this.diagramView._explicitWildcards.add("stickyNotes");
5240
+ this.diagramView.visibleEntities.stickyNotes = [], r.add("stickyNotes");
5192
5241
  break;
5193
5242
  case "tablegroups":
5194
- this.diagramView.visibleEntities.tableGroups = [], this.diagramView._explicitWildcards.add("tableGroups");
5243
+ this.diagramView.visibleEntities.tableGroups = [], r.add("tableGroups");
5195
5244
  break;
5196
5245
  case "schemas":
5197
- this.diagramView.visibleEntities.schemas = [], this.diagramView._explicitWildcards.add("schemas");
5246
+ this.diagramView.visibleEntities.schemas = [], r.add("schemas");
5198
5247
  break;
5199
5248
  }
5200
5249
  return;
@@ -9342,14 +9391,10 @@ function processColumnInDb(r) {
9342
9391
  }))
9343
9392
  };
9344
9393
  }
9345
- var WILDCARD_EXPAND_ENTITIES = new Set(["tableGroups"]);
9346
9394
  function expandDiagramViewWildcards(r) {
9347
- if (r.diagramViews) for (let j of r.diagramViews.values()) {
9348
- let M = j.visibleEntities, N = j._explicitWildcards, P = j._explicitlySet;
9349
- !N || !P || (WILDCARD_EXPAND_ENTITIES.has("tables") && N.has("tables") && M.tables && M.tables.length === 0 && (P.has("tableGroups") || P.has("schemas") || (M.tables = Array.from(r.tables.values()).map((r) => ({
9350
- name: r.name,
9351
- schemaName: r.schemaName || "public"
9352
- })))), WILDCARD_EXPAND_ENTITIES.has("tableGroups") && N.has("tableGroups") && M.tableGroups && M.tableGroups.length === 0 && (P.has("tables") || P.has("schemas") || (M.tableGroups = Array.from(r.tableGroups.values()).map((r) => ({ name: r.name })))), WILDCARD_EXPAND_ENTITIES.has("stickyNotes") && N.has("stickyNotes") && M.stickyNotes && M.stickyNotes.length === 0 && (M.stickyNotes = Array.from(r.notes.values()).map((r) => ({ name: r.name }))), WILDCARD_EXPAND_ENTITIES.has("schemas") && N.has("schemas") && M.schemas && M.schemas.length === 0 && (P.has("tables") || P.has("tableGroups") || (M.schemas = [...new Set(Array.from(r.tables.values()).map((r) => r.schemaName || "public"))].map((r) => ({ name: r })))), delete j._explicitWildcards, delete j._explicitlySet);
9395
+ for (let j of r.diagramViews.values()) {
9396
+ let M = j.visibleEntities, N = r.diagramViewWildcards.get(j), P = r.diagramViewExplicitlySet.get(j);
9397
+ !N || !P || N.has("tableGroups") && M.tableGroups && M.tableGroups.length === 0 && (P.has("tables") || P.has("schemas") || (M.tableGroups = Array.from(r.tableGroups.values()).map((r) => ({ name: r.name }))));
9353
9398
  }
9354
9399
  }
9355
9400
  function convertEnvToDb(r) {
@@ -9384,7 +9429,7 @@ function convertEnvToDb(r) {
9384
9429
  project: Array.from(r.project.values())[0] || {},
9385
9430
  tablePartials: Array.from(r.tablePartials.values()).map(processColumnInDb),
9386
9431
  records: j,
9387
- diagramViews: r.diagramViews ? Array.from(r.diagramViews.values()) : []
9432
+ diagramViews: Array.from(r.diagramViews.values())
9388
9433
  };
9389
9434
  }
9390
9435
  var Interpreter = class {
@@ -9405,7 +9450,9 @@ var Interpreter = class {
9405
9450
  recordsElements: [],
9406
9451
  cachedMergedTables: /* @__PURE__ */ new Map(),
9407
9452
  source: r.source,
9408
- diagramViews: /* @__PURE__ */ new Map()
9453
+ diagramViews: /* @__PURE__ */ new Map(),
9454
+ diagramViewWildcards: /* @__PURE__ */ new Map(),
9455
+ diagramViewExplicitlySet: /* @__PURE__ */ new Map()
9409
9456
  };
9410
9457
  }
9411
9458
  interpret() {
@@ -9950,7 +9997,7 @@ function suggestInSubField(r, j, M) {
9950
9997
  case ScopeKind.DIAGRAMVIEW: return suggestInDiagramViewField();
9951
9998
  case ScopeKind.CUSTOM: {
9952
9999
  let M = r.container.element(j);
9953
- return M instanceof ElementDeclarationNode && M.parent instanceof ElementDeclarationNode && M.parent.type?.value.toLowerCase() === "diagramview" ? suggestInDiagramViewSubBlock(r, j) : noSuggestions();
10000
+ return M instanceof ElementDeclarationNode && M.parent instanceof ElementDeclarationNode && getElementKind(M.parent).unwrap_or(void 0) === ElementKind.DiagramView ? suggestInDiagramViewSubBlock(r, j) : noSuggestions();
9954
10001
  }
9955
10002
  default: return noSuggestions();
9956
10003
  }
@@ -10102,48 +10149,20 @@ function suggestInDiagramViewSubBlock(r, j) {
10102
10149
  range: void 0
10103
10150
  };
10104
10151
  switch (N) {
10105
- case "tables": return { suggestions: [P, ...addQuoteToSuggestionIfNeeded({ suggestions: [...r.parse.publicSymbolTable().entries()].flatMap(([r]) => {
10106
- let j = destructureIndex(r).unwrap_or(void 0);
10107
- if (j === void 0) return [];
10108
- let { kind: M, name: N } = j;
10109
- return M !== SymbolKind.Table && M !== SymbolKind.Schema ? [] : {
10110
- label: N,
10111
- insertText: N,
10112
- insertTextRules: CompletionItemInsertTextRule.KeepWhitespace,
10113
- kind: pickCompletionItemKind(M),
10114
- range: void 0
10115
- };
10116
- }) }).suggestions] };
10117
- case "tablegroups": return { suggestions: [P, ...addQuoteToSuggestionIfNeeded({ suggestions: [...r.parse.publicSymbolTable().entries()].flatMap(([r]) => {
10118
- let j = destructureIndex(r).unwrap_or(void 0);
10119
- if (j === void 0) return [];
10120
- let { kind: M, name: N } = j;
10121
- return M === SymbolKind.TableGroup ? {
10122
- label: N,
10123
- insertText: N,
10124
- insertTextRules: CompletionItemInsertTextRule.KeepWhitespace,
10125
- kind: pickCompletionItemKind(M),
10126
- range: void 0
10127
- } : [];
10128
- }) }).suggestions] };
10129
- case "schemas": {
10130
- let j = /* @__PURE__ */ new Set(), M = r.parse.ast();
10131
- for (let r of M?.body || []) if (r instanceof ElementDeclarationNode && r.name instanceof InfixExpressionNode && r.name.op?.value === ".") {
10132
- let M = destructureMemberAccessExpression(r.name).unwrap_or([]);
10133
- if (M.length >= 2) {
10134
- let r = extractVariableFromExpression(M[0]).unwrap_or("");
10135
- r && j.add(r);
10136
- }
10137
- }
10138
- return { suggestions: [P, ...[...j].map((r) => ({
10139
- label: r,
10140
- insertText: r,
10152
+ case "tables": return { suggestions: [P, ...suggestNamesInScope(r, j, r.parse.ast(), [SymbolKind.Table, SymbolKind.Schema]).suggestions] };
10153
+ case "tablegroups": return { suggestions: [P, ...suggestNamesInScope(r, j, r.parse.ast(), [SymbolKind.TableGroup]).suggestions] };
10154
+ case "schemas": return { suggestions: [
10155
+ P,
10156
+ {
10157
+ label: DEFAULT_SCHEMA_NAME,
10158
+ insertText: DEFAULT_SCHEMA_NAME,
10141
10159
  insertTextRules: CompletionItemInsertTextRule.KeepWhitespace,
10142
10160
  kind: CompletionItemKind.Module,
10143
10161
  range: void 0
10144
- }))] };
10145
- }
10146
- case "notes": return { suggestions: [P] };
10162
+ },
10163
+ ...suggestNamesInScope(r, j, r.parse.ast(), [SymbolKind.Schema]).suggestions
10164
+ ] };
10165
+ case "notes": return { suggestions: [P, ...suggestNamesInScope(r, j, r.parse.ast(), [SymbolKind.Note]).suggestions] };
10147
10166
  default: return noSuggestions();
10148
10167
  }
10149
10168
  }
@@ -10598,10 +10617,10 @@ function containerScopeKind(r) {
10598
10617
  default: return ScopeKind.CUSTOM;
10599
10618
  }
10600
10619
  }
10601
- function applyTextEdits(r, j) {
10602
- let M = [...j].sort((r, j) => j.start - r.start), N = r;
10603
- for (let { start: r, end: j, newText: P } of M) N = N.substring(0, r) + P + N.substring(j);
10604
- return N;
10620
+ function applyTextEdits(r, j, M = !1) {
10621
+ let N = M ? j : [...j].sort((r, j) => j.start - r.start), P = r;
10622
+ for (let { start: r, end: j, newText: M } of N) P = P.substring(0, r) + M + P.substring(j);
10623
+ return P;
10605
10624
  }
10606
10625
  function normalizeTableName(r) {
10607
10626
  if (typeof r != "string") return {
@@ -10721,6 +10740,97 @@ function renameTable(r, j) {
10721
10740
  for (let r of B.references) M.substring(r.start, r.end).replace(/"/g, "") === L && H.push(r);
10722
10741
  return applyTextEdits(M, findReplacements(H, I, V, M));
10723
10742
  }
10743
+ function findDiagramViewBlocks(r) {
10744
+ let j = [], M = new Lexer(r).lex();
10745
+ if (M.getErrors().length > 0) return j;
10746
+ let N = new Parser(r, M.getValue(), new SyntaxNodeIdGenerator()).parse();
10747
+ if (N.getErrors().length > 0) return j;
10748
+ let P = N.getValue().ast;
10749
+ for (let r of P.body) if (r.type?.value === "DiagramView") {
10750
+ let M = r.name ? destructureComplexVariable(r.name).unwrap_or([]) : [], N = M.length > 0 ? M[M.length - 1] : "";
10751
+ j.push({
10752
+ name: N,
10753
+ startIndex: r.start,
10754
+ endIndex: r.end
10755
+ });
10756
+ }
10757
+ return j;
10758
+ }
10759
+ function needsQuoting(r) {
10760
+ return !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r);
10761
+ }
10762
+ function quoteName(r) {
10763
+ return needsQuoting(r) ? `"${r.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"` : r;
10764
+ }
10765
+ function generateDiagramViewBlock(r, j) {
10766
+ let M = [`DiagramView ${quoteName(r)} {`];
10767
+ if (j?.tables !== void 0 && j.tables !== null) if (j.tables.length === 0) M.push(" Tables { * }");
10768
+ else {
10769
+ let r = j.tables.map((r) => r.schemaName === "public" ? r.name : `${r.schemaName}.${r.name}`);
10770
+ M.push(" Tables {"), r.forEach((r) => M.push(` ${r}`)), M.push(" }");
10771
+ }
10772
+ return j?.stickyNotes !== void 0 && (j.stickyNotes === null || (j.stickyNotes.length === 0 ? M.push(" Notes { * }") : (M.push(" Notes {"), j.stickyNotes.forEach((r) => M.push(` ${r.name}`)), M.push(" }")))), j?.tableGroups !== void 0 && (j.tableGroups === null || (j.tableGroups.length === 0 ? M.push(" TableGroups { * }") : (M.push(" TableGroups {"), j.tableGroups.forEach((r) => M.push(` ${r.name}`)), M.push(" }")))), j?.schemas !== void 0 && (j.schemas === null || (j.schemas.length === 0 ? M.push(" Schemas { * }") : (M.push(" Schemas {"), j.schemas.forEach((r) => M.push(` ${r.name}`)), M.push(" }")))), M.push("}"), M.join("\n");
10773
+ }
10774
+ function syncDiagramView(r, j, M) {
10775
+ let N = M ?? findDiagramViewBlocks(r), P = [];
10776
+ for (let M of j) {
10777
+ let j = applyOperation(r, M, N);
10778
+ P.push(...j);
10779
+ }
10780
+ return P.sort((r, j) => j.start - r.start), {
10781
+ newDbml: applyTextEdits(r, P, !0),
10782
+ edits: P
10783
+ };
10784
+ }
10785
+ function applyOperation(r, j, M) {
10786
+ switch (j.operation) {
10787
+ case "create": return computeCreateEdit(r, j, M);
10788
+ case "update": return computeUpdateEdit(r, j, M);
10789
+ case "delete": return computeDeleteEdit(r, j, M);
10790
+ default: return [];
10791
+ }
10792
+ }
10793
+ function computeCreateEdit(r, j, M) {
10794
+ if (M.find((r) => r.name === j.name)) return computeUpdateEdit(r, j, M);
10795
+ let N = "\n\n" + generateDiagramViewBlock(j.name, j.visibleEntities) + "\n";
10796
+ return [{
10797
+ start: r.length,
10798
+ end: r.length,
10799
+ newText: N
10800
+ }];
10801
+ }
10802
+ function computeUpdateEdit(r, j, M) {
10803
+ let N = M.find((r) => r.name === j.name);
10804
+ if (!N) return [];
10805
+ let P = [];
10806
+ if (j.newName || j.visibleEntities) {
10807
+ let r = generateDiagramViewBlock(j.newName || j.name, j.visibleEntities);
10808
+ P.push({
10809
+ start: N.startIndex,
10810
+ end: N.endIndex,
10811
+ newText: r
10812
+ });
10813
+ }
10814
+ return P;
10815
+ }
10816
+ function computeDeleteEdit(r, j, M) {
10817
+ let N = M.find((r) => r.name === j.name);
10818
+ if (!N) return [];
10819
+ let P = N.startIndex, F = N.endIndex;
10820
+ for (; P > 0 && r[P - 1] === "\n";) {
10821
+ P--, P > 0 && r[P - 1] === "\r" && P--;
10822
+ let j = r.lastIndexOf("\n", P - 1) + 1;
10823
+ if (r.substring(j, P).trim() !== "") {
10824
+ P = N.startIndex, P > 0 && r[P - 1] === "\n" && (P--, P > 0 && r[P - 1] === "\r" && P--);
10825
+ break;
10826
+ }
10827
+ }
10828
+ return F < r.length && r[F] === "\r" && F++, F < r.length && r[F] === "\n" && F++, [{
10829
+ start: P,
10830
+ end: F,
10831
+ newText: ""
10832
+ }];
10833
+ }
10724
10834
  var Compiler = class {
10725
10835
  constructor() {
10726
10836
  this.source = "", this.cache = /* @__PURE__ */ new Map(), this.nodeIdGenerator = new SyntaxNodeIdGenerator(), this.symbolIdGenerator = new NodeSymbolIdGenerator(), this.token = {
@@ -10777,6 +10887,12 @@ var Compiler = class {
10777
10887
  renameTable(r, j) {
10778
10888
  return renameTable.call(this, r, j);
10779
10889
  }
10890
+ syncDiagramView(r, j) {
10891
+ return syncDiagramView(this.parse.source(), r, j);
10892
+ }
10893
+ findDiagramViewBlocks() {
10894
+ return findDiagramViewBlocks(this.parse.source());
10895
+ }
10780
10896
  applyTextEdits(r) {
10781
10897
  return applyTextEdits(this.parse.source(), r);
10782
10898
  }
@@ -10789,78 +10905,4 @@ var Compiler = class {
10789
10905
  };
10790
10906
  }
10791
10907
  };
10792
- function findDiagramViewBlocks(r) {
10793
- let j = [], M = new Lexer(r).lex();
10794
- if (M.getErrors().length > 0) return j;
10795
- let N = new Parser(r, M.getValue(), new SyntaxNodeIdGenerator()).parse();
10796
- if (N.getErrors().length > 0) return j;
10797
- let P = N.getValue().ast;
10798
- for (let r of P.body) if (r.type?.value === "DiagramView") {
10799
- let M = r.name ? destructureComplexVariable(r.name).unwrap_or([]) : [], N = M.length > 0 ? M[M.length - 1] : "";
10800
- j.push({
10801
- name: N,
10802
- startIndex: r.start,
10803
- endIndex: r.end
10804
- });
10805
- }
10806
- return j;
10807
- }
10808
- function needsQuoting(r) {
10809
- return !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r);
10810
- }
10811
- function quoteName(r) {
10812
- return needsQuoting(r) ? `"${r.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"` : r;
10813
- }
10814
- function generateDiagramViewBlock(r, j) {
10815
- let M = [`DiagramView ${quoteName(r)} {`];
10816
- if (j?.tables !== void 0 && j.tables !== null) if (j.tables.length === 0) M.push(" Tables { * }");
10817
- else {
10818
- let r = j.tables.map((r) => r.schemaName === "public" ? r.name : `${r.schemaName}.${r.name}`);
10819
- M.push(" Tables {"), r.forEach((r) => M.push(` ${r}`)), M.push(" }");
10820
- }
10821
- return j?.stickyNotes !== void 0 && (j.stickyNotes === null || (j.stickyNotes.length === 0 ? M.push(" Notes { * }") : (M.push(" Notes {"), j.stickyNotes.forEach((r) => M.push(` ${r.name}`)), M.push(" }")))), j?.tableGroups !== void 0 && (j.tableGroups === null || (j.tableGroups.length === 0 ? M.push(" TableGroups { * }") : (M.push(" TableGroups {"), j.tableGroups.forEach((r) => M.push(` ${r.name}`)), M.push(" }")))), j?.schemas !== void 0 && (j.schemas === null || (j.schemas.length === 0 ? M.push(" Schemas { * }") : (M.push(" Schemas {"), j.schemas.forEach((r) => M.push(` ${r.name}`)), M.push(" }")))), M.push("}"), M.join("\n");
10822
- }
10823
- function syncDiagramView(r, j) {
10824
- let M = r;
10825
- for (let r of j) M = applyOperation(M, r);
10826
- return { newDbml: M };
10827
- }
10828
- function applyOperation(r, j) {
10829
- switch (j.operation) {
10830
- case "create": return applyCreate(r, j);
10831
- case "update": return applyUpdate(r, j, findDiagramViewBlocks(r));
10832
- case "delete": return applyDelete(r, j, findDiagramViewBlocks(r));
10833
- default: return r;
10834
- }
10835
- }
10836
- function applyCreate(r, j) {
10837
- let M = findDiagramViewBlocks(r);
10838
- if (M.find((r) => r.name === j.name)) return applyUpdate(r, j, M);
10839
- let N = generateDiagramViewBlock(j.name, j.visibleEntities);
10840
- return r.trimEnd() + "\n\n" + N + "\n";
10841
- }
10842
- function applyUpdate(r, j, M) {
10843
- let N = M.find((r) => r.name === j.name);
10844
- if (!N) return r;
10845
- let P = [];
10846
- if (j.newName || j.visibleEntities) {
10847
- let r = generateDiagramViewBlock(j.newName || j.name, j.visibleEntities);
10848
- P.push({
10849
- start: N.startIndex,
10850
- end: N.endIndex,
10851
- newText: r
10852
- });
10853
- }
10854
- return applyTextEdits(r, P);
10855
- }
10856
- function applyDelete(r, j, M) {
10857
- let N = M.find((r) => r.name === j.name);
10858
- if (!N) return r;
10859
- let P = r.split("\n"), F = 0, I = P.length - 1, L = 0;
10860
- for (let r = 0; r < P.length; r++) {
10861
- let j = L, M = L + P[r].length;
10862
- j <= N.startIndex && N.startIndex <= M && (F = r), j <= N.endIndex && N.endIndex <= M && (I = r), L = M + 1;
10863
- }
10864
- return [...P.slice(0, F), ...P.slice(I + 1)].join("\n");
10865
- }
10866
- export { CompileError, CompileErrorCode, Compiler, ElementDeclarationNode, ElementKind, FALSY_VALUES, ProgramNode, ScopeKind, SyntaxNode, SyntaxNodeKind, SyntaxToken, SyntaxTokenKind, TRUTHY_VALUES, addDoubleQuoteIfNeeded, dbmlMonarchTokensProvider, escapeString, extractNumericLiteral, extractSignedNumber, formatRecordValue, getLengthTypeParam, getNumericTypeParams, getRecordValueType, isBinaryType, isBooleanType, isDateTimeType, isEmptyStringLiteral, isFloatType, isFunctionExpression, isIntegerType, isNullish, isNumericType, isSerialType, isStringType, isValidIdentifier, normalizeTypeName, services_exports as services, splitQualifiedIdentifier, syncDiagramView, tryExtractBoolean, tryExtractDateTime, tryExtractEnum, tryExtractInteger, tryExtractNumeric, tryExtractString, unescapeString, validateForeignKeys, validatePrimaryKey, validateUnique };
10908
+ export { CompileError, CompileErrorCode, Compiler, ElementDeclarationNode, ElementKind, FALSY_VALUES, ProgramNode, ScopeKind, SyntaxNode, SyntaxNodeKind, SyntaxToken, SyntaxTokenKind, TRUTHY_VALUES, addDoubleQuoteIfNeeded, dbmlMonarchTokensProvider, escapeString, extractNumericLiteral, extractSignedNumber, formatRecordValue, getLengthTypeParam, getNumericTypeParams, getRecordValueType, isBinaryType, isBooleanType, isDateTimeType, isEmptyStringLiteral, isFloatType, isFunctionExpression, isIntegerType, isNullish, isNumericType, isSerialType, isStringType, isValidIdentifier, normalizeTypeName, services_exports as services, splitQualifiedIdentifier, tryExtractBoolean, tryExtractDateTime, tryExtractEnum, tryExtractInteger, tryExtractNumeric, tryExtractString, unescapeString, validateForeignKeys, validatePrimaryKey, validateUnique };