mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
68.75k stars 6.08k forks source link

fix: move from objects to Maps #5468

Closed Yash-Singh1 closed 1 month ago

Yash-Singh1 commented 2 months ago

:bookmark_tabs: Summary

Switches from objects to Maps in places where the keys accepted are user inputs.

Resolves #5451

:straight_ruler: Design Decisions

Describe the way your implementation works or what design decisions you made if applicable.

This is a breaking change for v11 since it changes the structure of the databases and as such can break code that relies on the db, e.g.

https://github.com/excalidraw/mermaid-to-excalidraw/blob/d0b00dc63eeabd5e92ca3997650f47bf4901cb2c/src/parser/flowchart.ts#L226

Why?

The main reason for this change was so that we wouldn't have to validate for constructor and __proto__ (#5451) everytime we have to modify or get a property on the database objects. Another good reason would be that objects in JavaScript are generally designed to work like dynamic structs, where the JIT compiler would store the shape of the object and rereference that shape everytime that object is passed around. However, when we have a "map" with user-generated keys, Maps work better because they are designed for that purpose.

:clipboard: Tasks

Make sure you

netlify[bot] commented 2 months ago

Deploy Preview for mermaid-js ready!

Name Link
Latest commit 00eaebeac8a960ebb640c4a5e35929dc3e078fe4
Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/6644119193947100088ea8b7
Deploy Preview https://deploy-preview-5468--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.

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 0.50251% with 396 lines in your changes are missing coverage. Please review.

Project coverage is 5.73%. Comparing base (0326d89) to head (00eaebe).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468/graphs/tree.svg?width=650&height=150&src=pr&token=BaET4V1BdM&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js)](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) ```diff @@ Coverage Diff @@ ## develop #5468 +/- ## ========================================== - Coverage 5.74% 5.73% -0.01% ========================================== Files 277 278 +1 Lines 41967 41991 +24 Branches 515 490 -25 ========================================== Hits 2409 2409 - Misses 39558 39582 +24 ``` | [Flag](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) | Coverage Δ | | |---|---|---| | [unit](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) | `5.73% <0.50%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) | Coverage Δ | | |---|---|---| | [packages/mermaid/src/diagrams/gantt/ganttDb.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fgantt%2FganttDb.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvZ2FudHQvZ2FudHREYi5qcw==) | `77.47% <66.66%> (ø)` | | | [packages/mermaid/src/diagrams/sequence/svgDraw.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fsequence%2FsvgDraw.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvc2VxdWVuY2Uvc3ZnRHJhdy5qcw==) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/class/classTypes.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fclass%2FclassTypes.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvY2xhc3MvY2xhc3NUeXBlcy50cw==) | `0.00% <0.00%> (ø)` | | | [...ckages/mermaid/src/diagrams/gantt/ganttRenderer.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fgantt%2FganttRenderer.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvZ2FudHQvZ2FudHRSZW5kZXJlci5qcw==) | `0.00% <0.00%> (ø)` | | | [...ages/mermaid-flowchart-elk/src/flowRenderer-elk.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid-flowchart-elk%2Fsrc%2FflowRenderer-elk.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC1mbG93Y2hhcnQtZWxrL3NyYy9mbG93UmVuZGVyZXItZWxrLmpz) | `0.00% <0.00%> (ø)` | | | [...ckages/mermaid/src/diagrams/class/classRenderer.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fclass%2FclassRenderer.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvY2xhc3MvY2xhc3NSZW5kZXJlci5qcw==) | `0.00% <0.00%> (ø)` | | | [...ges/mermaid/src/diagrams/flowchart/flowRenderer.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fflowchart%2FflowRenderer.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvZmxvd2NoYXJ0L2Zsb3dSZW5kZXJlci5qcw==) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/pie/pieRenderer.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fpie%2FpieRenderer.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvcGllL3BpZVJlbmRlcmVyLnRz) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/er/erRenderer.js](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fer%2FerRenderer.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvZXIvZXJSZW5kZXJlci5qcw==) | `0.00% <0.00%> (ø)` | | | [packages/mermaid/src/diagrams/pie/pieDb.ts](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree&filepath=packages%2Fmermaid%2Fsrc%2Fdiagrams%2Fpie%2FpieDb.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js#diff-cGFja2FnZXMvbWVybWFpZC9zcmMvZGlhZ3JhbXMvcGllL3BpZURiLnRz) | `0.00% <0.00%> (ø)` | | | ... and [17 more](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js) | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/mermaid-js/mermaid/pull/5468/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mermaid-js)
sidharthv96 commented 2 months ago

@Yash-Singh1 were you able to fix the tests? Keeping this PR open for long will create more conflicts for you.

Yash-Singh1 commented 2 months ago

Hi @sidharthv96, sorry for the late reply, I was busy with exams. I just fixed the e2e tests.

sidharthv96 commented 2 months ago

No worries @Yash-Singh1! Hope they went well :) Let's wait for a review from someone else as well, as the size is big.

sidharthv96 commented 1 month ago

Merging this now, as both the review comments are non blockers, and can be done in a follow up PR.

mermaid-bot[bot] commented 1 month ago

@Yash-Singh1, Thank you for the contribution! You are now eligible for a year of Premium account on MermaidChart. Sign up with your GitHub account to activate.