Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Change SequenceDB to class based architecture. #6272

Merged
merged 11 commits into from
Feb 20, 2025

Conversation

saurabhg772244
Copy link
Collaborator

📑 Summary

  • Refactors the existing sequenceDb implementation from a functional approach to a class-based architecture to improve code organization, maintainability, and extensibility.
  • Return a new DB object when diagramObject.db is called.
  • Introduces new SequenceDB class to encapsulate database operations and state
  • Migrates existing functions to class methods
  • Maintains existing API interface for backwards compatibility
  • Following functions still uses common DB:
    • apply
    • parseMessage
    • parseBoxData
    • LINETYPE
    • PLACEMENT
    • setDiagramTitle
    • setAccTitle
    • setAccDescription
  • Reason why above functions still uses common DB: Refactor: Change flowDB to class based architecture. #6161 (comment)
  • Added unique IDs for messages during parsing. Previously, IDs were assigned during rendering, which caused issues for diagrams since message operations relied on IDs.
  • Updated unit tests to support unique DB instances instead of shared DB.

Resolves #

📏 Design Decisions

  • The sequenceDb module previously relied on functions and global variables. Consequently, each call to mermaid.parse or mermaid.render resulted in changes to global variables.
  • This behavior caused issues when rendering multiple diagrams using the same Mermaid API, as the database object (DB) for the diagrams would get mixed up.
  • To address this, sequenceDb was refactored into a class-based structure. This change ensures that each diagramObject.db call creates a new instance of the database (DB), preventing conflicts between diagrams.

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Feb 12, 2025

🦋 Changeset detected

Latest commit: 5857953

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mermaid Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the Type: Other Not an enhancement or a bug label Feb 12, 2025
Copy link

netlify bot commented Feb 12, 2025

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 5857953
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/67b5729fe038800008876371
😎 Deploy Preview https://deploy-preview-6272--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Feb 12, 2025

Open in Stackblitz

npm i https://pkg.pr.new/mermaid-js/mermaid@6272
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/layout-elk@6272
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/mermaid-zenuml@6272
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/parser@6272

commit: 5857953

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 0% with 581 lines in your changes missing coverage. Please review.

Project coverage is 4.46%. Comparing base (52532a7) to head (5857953).
Report is 18 commits behind head on develop.

Files with missing lines Patch % Lines
...ckages/mermaid/src/diagrams/sequence/sequenceDb.ts 0.00% 567 Missing ⚠️
...s/mermaid/src/diagrams/sequence/sequenceDiagram.ts 0.00% 14 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #6272   +/-   ##
=======================================
  Coverage     4.46%   4.46%           
=======================================
  Files          385     385           
  Lines        54276   54275    -1     
  Branches       598     598           
=======================================
  Hits          2425    2425           
+ Misses       51851   51850    -1     
Flag Coverage Δ
unit 4.46% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../mermaid/src/diagrams/sequence/sequenceRenderer.ts 0.00% <ø> (ø)
...s/mermaid/src/diagrams/sequence/sequenceDiagram.ts 0.00% <0.00%> (ø)
...ckages/mermaid/src/diagrams/sequence/sequenceDb.ts 0.00% <0.00%> (ø)

Copy link
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The this.setWrap(getConfig().wrap); in the constructor seems to be the only thing I'm a bit nervous about, the rest of the PR seems good to me (as long as the visual regression tests come back green ✔️)

@saurabhg772244
Copy link
Collaborator Author

@aloisklink i think we can refactor it into separate PR

@saurabhg772244 saurabhg772244 marked this pull request as ready for review February 14, 2025 13:09
@sidharthv96
Copy link
Member

@saurabhg772244 please sync with develop, argos should work now.

…saurabh/refactor/convert-sequenceDb-to-class
Copy link

argos-ci bot commented Feb 15, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - Feb 19, 2025, 6:08 AM

@sidharthv96 sidharthv96 added this pull request to the merge queue Feb 20, 2025
Merged via the queue into develop with commit ad2f172 Feb 20, 2025
25 checks passed
@sidharthv96 sidharthv96 deleted the saurabh/refactor/convert-sequenceDb-to-class branch February 20, 2025 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Other Not an enhancement or a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants