From fdf9988af1b6b920a17c305043f39badd0017b1a Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 28 Nov 2023 19:07:10 +0530 Subject: [PATCH 1/6] feat #5042: Add `flowchart.maxEdges` config. --- packages/mermaid/src/config.type.ts | 5 +++++ packages/mermaid/src/diagrams/flowchart/flowDb.js | 7 +++---- packages/mermaid/src/schemas/config.schema.yaml | 6 ++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/mermaid/src/config.type.ts b/packages/mermaid/src/config.type.ts index 402d9a4d8..34cc3b565 100644 --- a/packages/mermaid/src/config.type.ts +++ b/packages/mermaid/src/config.type.ts @@ -1431,6 +1431,11 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig { * */ htmlLabels?: boolean; + /** + * Defines the maximum number of edges that can be drawn in a graph. + * + */ + maxEdges?: number; /** * Defines the spacing between nodes on the same level * diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.js b/packages/mermaid/src/diagrams/flowchart/flowDb.js index 9a693aabf..aaaa6cd8c 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.js +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.js @@ -12,7 +12,6 @@ import { setDiagramTitle, getDiagramTitle, } from '../common/commonDb.js'; -import errorDiagram from '../error/errorDiagram.js'; const MERMAID_DOM_ID_PREFIX = 'flowchart-'; let vertexCounter = 0; @@ -92,7 +91,6 @@ export const addVertex = function (_id, textObj, type, style, classes, dir, prop if (txt[0] === '"' && txt[txt.length - 1] === '"') { txt = txt.substring(1, txt.length - 1); } - vertices[id].text = txt; } else { if (vertices[id].text === undefined) { @@ -160,11 +158,11 @@ export const addSingleLink = function (_start, _end, type) { if (edge?.length > 10) { edge.length = 10; } - if (edges.length < 280) { + if (edges.length < (config.flowchart.maxEdges ?? 500)) { log.info('abc78 pushing edge...'); edges.push(edge); } else { - throw new Error('Too many edges'); + throw new Error(`Edge limit exceeded. Increase config.flowchart.maxEdges to allow more edges.`); } }; export const addLink = function (_start, _end, type) { @@ -460,6 +458,7 @@ export const clear = function (ver = 'gen-1') { tooltips = {}; firstGraphFlag = true; version = ver; + config = getConfig(); commonClear(); }; export const setGen = (ver) => { diff --git a/packages/mermaid/src/schemas/config.schema.yaml b/packages/mermaid/src/schemas/config.schema.yaml index 2791c32d4..30d6a6024 100644 --- a/packages/mermaid/src/schemas/config.schema.yaml +++ b/packages/mermaid/src/schemas/config.schema.yaml @@ -1900,6 +1900,12 @@ $defs: # JSON Schema definition (maybe we should move these to a separate file) Flag for setting whether or not a html tag should be used for rendering labels on the edges. type: boolean default: true + maxEdges: + description: | + Defines the maximum number of edges that can be drawn in a graph. + type: integer + default: 500 + minimum: 0 nodeSpacing: description: | Defines the spacing between nodes on the same level From 3b7cabee4b45263939d34e573f4b7ffebd9f2b91 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 7 Dec 2023 10:39:10 +0530 Subject: [PATCH 2/6] chore: Add maxEdges to secure list --- packages/mermaid/src/schemas/config.schema.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mermaid/src/schemas/config.schema.yaml b/packages/mermaid/src/schemas/config.schema.yaml index 30d6a6024..027cf9ff7 100644 --- a/packages/mermaid/src/schemas/config.schema.yaml +++ b/packages/mermaid/src/schemas/config.schema.yaml @@ -156,7 +156,7 @@ properties: in the current `currentConfig`. This prevents malicious graph directives from overriding a site's default security. - default: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize'] + default: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize', 'maxEdges'] type: array items: type: string From 9b34adf2c9b8ee02f54de876dee5e9cb9b3c9d0d Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 7 Dec 2023 10:49:20 +0530 Subject: [PATCH 3/6] refactor: Move maxEdges out of flowchart config. --- packages/mermaid/src/diagrams/flowchart/flowDb.js | 10 ++++++++-- packages/mermaid/src/schemas/config.schema.yaml | 12 ++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.js b/packages/mermaid/src/diagrams/flowchart/flowDb.js index aaaa6cd8c..899345b6e 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.js +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.js @@ -158,11 +158,17 @@ export const addSingleLink = function (_start, _end, type) { if (edge?.length > 10) { edge.length = 10; } - if (edges.length < (config.flowchart.maxEdges ?? 500)) { + if (edges.length < (config.maxEdges ?? 500)) { log.info('abc78 pushing edge...'); edges.push(edge); } else { - throw new Error(`Edge limit exceeded. Increase config.flowchart.maxEdges to allow more edges.`); + throw new Error( + `Edge limit exceeded. ${edges.length} edges found, but the limit is ${config.maxEdges}. + +Initialize mermaid with maxEdges set to a higher number to allow more edges. +You cannot set this config via configuration inside the diagram as it is a secure config. +You have to call mermaid.initialize.` + ); } }; export const addLink = function (_start, _end, type) { diff --git a/packages/mermaid/src/schemas/config.schema.yaml b/packages/mermaid/src/schemas/config.schema.yaml index 027cf9ff7..f39dbe918 100644 --- a/packages/mermaid/src/schemas/config.schema.yaml +++ b/packages/mermaid/src/schemas/config.schema.yaml @@ -74,6 +74,12 @@ properties: description: The maximum allowed size of the users text diagram type: number default: 50000 + maxEdges: + description: | + Defines the maximum number of edges that can be drawn in a graph. + type: integer + default: 500 + minimum: 0 darkMode: type: boolean default: false @@ -1900,12 +1906,6 @@ $defs: # JSON Schema definition (maybe we should move these to a separate file) Flag for setting whether or not a html tag should be used for rendering labels on the edges. type: boolean default: true - maxEdges: - description: | - Defines the maximum number of edges that can be drawn in a graph. - type: integer - default: 500 - minimum: 0 nodeSpacing: description: | Defines the spacing between nodes on the same level From 69f31097e76d79ff6fd20a68650114e3c5acd357 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 7 Dec 2023 10:55:12 +0530 Subject: [PATCH 4/6] refactor: Move maxEdges out of flowchart config. --- packages/mermaid/src/config.type.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/mermaid/src/config.type.ts b/packages/mermaid/src/config.type.ts index 34cc3b565..a5bc22f6f 100644 --- a/packages/mermaid/src/config.type.ts +++ b/packages/mermaid/src/config.type.ts @@ -68,6 +68,11 @@ export interface MermaidConfig { * The maximum allowed size of the users text diagram */ maxTextSize?: number; + /** + * Defines the maximum number of edges that can be drawn in a graph. + * + */ + maxEdges?: number; darkMode?: boolean; htmlLabels?: boolean; /** @@ -1431,11 +1436,6 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig { * */ htmlLabels?: boolean; - /** - * Defines the maximum number of edges that can be drawn in a graph. - * - */ - maxEdges?: number; /** * Defines the spacing between nodes on the same level * From 5a26edf6c0a824d49bb4b7cd17ad6269522d361c Mon Sep 17 00:00:00 2001 From: Justin Greywolf Date: Sun, 10 Dec 2023 17:01:36 -0800 Subject: [PATCH 5/6] Update generics docs --- docs/syntax/classDiagram.md | 4 ++-- packages/mermaid/src/docs/syntax/classDiagram.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/syntax/classDiagram.md b/docs/syntax/classDiagram.md index 2f2c3da88..6e24470f7 100644 --- a/docs/syntax/classDiagram.md +++ b/docs/syntax/classDiagram.md @@ -240,9 +240,9 @@ class BankAccount{ #### Generic Types -Members can be defined using generic types, such as `List`, for fields, parameters, and return types by enclosing the type within `~` (**tilde**). **Nested** type declarations such as `List>` are supported. +Generics can be representated as part of a class definition, and for class members/return types. In order to denote an item as generic, you enclose that type within `~` (**tilde**). **Nested** type declarations such as `List>` are supported, though generics that include a comma are currently not supported. (such as `List>`) -Generics can be represented as part of a class definition and also in the parameters or the return value of a method/function: +> _note_ when a generic is used within a class definition, the generic type is NOT considered part of the class name. i.e.: for any syntax which required you to reference the class name, you need to drop the type part of the definition. This also means that mermaid does not currently support having two classes with the same name, but different generic types. ```mermaid-example classDiagram diff --git a/packages/mermaid/src/docs/syntax/classDiagram.md b/packages/mermaid/src/docs/syntax/classDiagram.md index f02ae67be..ad1a5034e 100644 --- a/packages/mermaid/src/docs/syntax/classDiagram.md +++ b/packages/mermaid/src/docs/syntax/classDiagram.md @@ -143,9 +143,9 @@ class BankAccount{ #### Generic Types -Members can be defined using generic types, such as `List`, for fields, parameters, and return types by enclosing the type within `~` (**tilde**). **Nested** type declarations such as `List>` are supported. +Generics can be representated as part of a class definition, and for class members/return types. In order to denote an item as generic, you enclose that type within `~` (**tilde**). **Nested** type declarations such as `List>` are supported, though generics that include a comma are currently not supported. (such as `List>`) -Generics can be represented as part of a class definition and also in the parameters or the return value of a method/function: +> _note_ when a generic is used within a class definition, the generic type is NOT considered part of the class name. i.e.: for any syntax which required you to reference the class name, you need to drop the type part of the definition. This also means that mermaid does not currently support having two classes with the same name, but different generic types. ```mermaid-example classDiagram From f1a10d11c38296f7045d3c9d3265996d9ddc93c9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 11 Dec 2023 01:09:36 +0000 Subject: [PATCH 6/6] chore(deps): update all minor dependencies --- docker-compose.yml | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e2484bdc5..65acab37e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.9' services: mermaid: - image: node:18.18.2-alpine3.18 + image: node:18.19.0-alpine3.18 stdin_open: true tty: true working_dir: /mermaid diff --git a/package.json b/package.json index 5fd67895b..818ac5b46 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "10.2.4", "description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.", "type": "module", - "packageManager": "pnpm@8.11.0", + "packageManager": "pnpm@8.12.0", "keywords": [ "diagram", "markdown", @@ -123,7 +123,7 @@ "vitest": "^0.34.0" }, "volta": { - "node": "18.18.2" + "node": "18.19.0" }, "nyc": { "report-dir": "coverage/cypress"