@dbml/parse 8.2.4 → 8.2.5

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.
@@ -14705,49 +14705,31 @@ function findDiagramViewBlocks(r) {
14705
14705
  }
14706
14706
  return j;
14707
14707
  }
14708
- function emitTablesBlock(r, j) {
14709
- let M = j.map((r) => {
14710
- let j = addDoubleQuoteIfNeeded(r.name);
14711
- return r.schemaName === "public" ? j : `${addDoubleQuoteIfNeeded(r.schemaName)}.${j}`;
14712
- });
14713
- r.push(" Tables {"), M.forEach((j) => r.push(` ${j}`)), r.push(" }");
14714
- }
14715
- function emitTableGroupsBlock(r, j) {
14716
- r.push(" TableGroups {"), j.forEach((j) => r.push(` ${addDoubleQuoteIfNeeded(j.name)}`)), r.push(" }");
14708
+ function emitListSubBlock(r, j, M) {
14709
+ r.push(` ${j} {`), M.forEach((j) => r.push(` ${j}`)), r.push(" }");
14717
14710
  }
14718
- function emitSchemasBlock(r, j) {
14719
- r.push(" Schemas {"), j.forEach((j) => r.push(` ${addDoubleQuoteIfNeeded(j.name)}`)), r.push(" }");
14711
+ function emitWildcardSubBlock(r, j) {
14712
+ r.push(` ${j} { * }`);
14720
14713
  }
14721
- function emitNotesBlock(r, j) {
14722
- r.push(" Notes {"), j.forEach((j) => r.push(` ${addDoubleQuoteIfNeeded(j.name)}`)), r.push(" }");
14714
+ function classifyDim(r) {
14715
+ return r == null ? "null" : r.length === 0 ? "empty" : "items";
14723
14716
  }
14724
14717
  function generateDiagramViewBlock(r, j) {
14725
- let M = `DiagramView ${addDoubleQuoteIfNeeded(r)} {`;
14718
+ let M = `DiagramView ${addDoubleQuoteIfNeeded(r)} {`, N = (r) => addDoubleQuoteIfNeeded(r.name), P = j?.tables?.map((r) => {
14719
+ let j = addDoubleQuoteIfNeeded(r.name);
14720
+ return r.schemaName === "public" ? j : `${addDoubleQuoteIfNeeded(r.schemaName)}.${j}`;
14721
+ }) ?? [], F = j?.tableGroups?.map(N) ?? [], I = j?.schemas?.map(N) ?? [], L = j?.stickyNotes?.map(N) ?? [];
14726
14722
  if (!j) return `${M}\n}`;
14727
- let { tables: N, tableGroups: P, schemas: F, stickyNotes: I } = j, L = N === null, R = P === null, z = F === null;
14728
- if (L && R && z && I === null) return `${M}\n}`;
14729
- if (L || R || z) {
14730
- let r = !L && N.length > 0, j = !R && P.length > 0, B = !z && F.length > 0;
14731
- if (!(r || j || B)) {
14732
- if (I && I.length > 0) {
14733
- let r = [M];
14734
- return emitNotesBlock(r, I), r.push("}"), r.join("\n");
14735
- }
14736
- return `${M}\n Notes { * }\n}`;
14737
- }
14738
- let V = [M];
14739
- return r && emitTablesBlock(V, N), j && emitTableGroupsBlock(V, P), B && emitSchemasBlock(V, F), I && I.length > 0 && emitNotesBlock(V, I), V.push("}"), V.join("\n");
14740
- }
14741
- let B = N, V = P, H = F, U = B.length === 0 && V.length === 0 && H.length === 0, W = I != null && I.length > 0;
14742
- if (U) {
14743
- if (W) {
14744
- let r = [M, " Tables { * }"];
14745
- return emitNotesBlock(r, I), r.push("}"), r.join("\n");
14746
- }
14747
- return `${M}\n *\n}`;
14748
- }
14749
- let G = [M];
14750
- return B.length > 0 && emitTablesBlock(G, B), V.length > 0 && emitTableGroupsBlock(G, V), H.length > 0 && emitSchemasBlock(G, H), W && emitNotesBlock(G, I), G.push("}"), G.join("\n");
14723
+ let R = {
14724
+ tables: classifyDim(j.tables),
14725
+ tableGroups: classifyDim(j.tableGroups),
14726
+ schemas: classifyDim(j.schemas),
14727
+ stickyNotes: classifyDim(j.stickyNotes)
14728
+ };
14729
+ if (Object.values(R).every((r) => r === "null")) return `${M}\n}`;
14730
+ if (Object.values(R).every((r) => r === "empty")) return `${M}\n *\n}`;
14731
+ let z = R.tables === "items" || R.tableGroups === "items" || R.schemas === "items", B = R.tables === "empty" && R.tableGroups === "empty" && R.schemas === "empty", V = [M];
14732
+ return z ? (R.tables === "items" && emitListSubBlock(V, "Tables", P), R.tableGroups === "items" && emitListSubBlock(V, "TableGroups", F), R.schemas === "items" && emitListSubBlock(V, "Schemas", I)) : B && emitWildcardSubBlock(V, "Tables"), R.stickyNotes === "items" ? emitListSubBlock(V, "Notes", L) : R.stickyNotes === "empty" && emitWildcardSubBlock(V, "Notes"), V.push("}"), V.join("\n");
14751
14733
  }
14752
14734
  function syncDiagramView(r, j, M) {
14753
14735
  let N = this.getSource(r) ?? "", P = M ?? findDiagramViewBlocks(N), F = [];
@@ -27,12 +27,8 @@ export interface DiagramViewBlock {
27
27
  endIndex: number;
28
28
  }
29
29
  /**
30
- * Returns the start/end byte positions of every DiagramView block in `source`.
31
- *
32
- * Returns an empty array on any lex or parse error - callers cannot
33
- * distinguish "no DiagramView blocks present" from "malformed DBML" based on
34
- * the return value alone. If you need to detect malformed input, lex/parse
35
- * the source separately and check for errors before calling this function.
30
+ * Returns the position of every DiagramView block in `source`
31
+ * Note that onany lex or parse errors, we return [], as there's no reliable way to detect diagram views from malformed DBML
36
32
  */
37
33
  export declare function findDiagramViewBlocks(source: string): DiagramViewBlock[];
38
34
  /**
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": "8.2.4",
4
+ "version": "8.2.5",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -46,5 +46,5 @@
46
46
  "engines": {
47
47
  "node": ">=18"
48
48
  },
49
- "gitHead": "a8358e7ca39ab47272ee59a1915709d8f0f82f06"
49
+ "gitHead": "4593cadfa6fc22c3fad2acbdefb839e118aa0c53"
50
50
  }