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

export library internal methods #3530

Open
lastlink opened this issue Sep 29, 2022 · 2 comments
Open

export library internal methods #3530

lastlink opened this issue Sep 29, 2022 · 2 comments
Labels
Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request

Comments

@lastlink
Copy link

lastlink commented Sep 29, 2022

Would like to use mermaid internals from the npm module such as detectDirective from utils.ts as well as have the parsers exposed in an ala cart mode. So far it only looks like the mermaidAPI.ts methods are exposed.

My purpose is that I'm trying to create an erdiagram to sql exporter and would like to use mermaid js methods directly for serializing a markdown files and extracting models before the svg is generated.

it's looking like I might have to use mermaid.js as a git submodule b/c the methods aren't exposed in the npm package.

I'm having progress breaking out part, currently stuck on the jison lexer (which I believe I could get the erDiagram models that I need for serializing the sql create table statements).

Current Progress: (done)

  • imported some things directly from git submodule
    • some things I had to copy, typescript format slightly and remove unneeded dependencies and fix build errors
    • jison parser I had to grab from the build
  • verify text if valid mermaid
  • determine it's an ermodel
  • success on getting erdiagram diagram,
    • igoring renderer and styles
    • subset of erDb
    • got jison parser working
      • I grabbed the jison parser export directly from the mermaid dist\mermaid.core.mjs build and required it.
      • guide newDiagram helped to remember to map erDb back to yy var in parser
      • example
      export interface DiagramDefinition {
        db: any;
        parser: any;
      }
      
      export const registerDiagram = (
        id: string,
        diagram: DiagramDefinition,
        detector: DiagramDetector
      ) => {
        if (diagrams[id]) {
          log.warn(`Diagram ${id} already registered.`);
        }
        diagram.parser.yy = diagram.db;
        diagrams[id] = diagram;
        addDetector(id, detector);
      };
      registerDiagram(
          "er",
          {
            parser: parser,
            db: erDb,
          },
          erDetector
        );
      
      // implementation
      var r = diag.parser.parse(md);
      var entities = diag.db.getEntities();
      var relationships = diag.db.getRelationships();
@lastlink lastlink added Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request labels Sep 29, 2022
@lastlink
Copy link
Author

maybe related to
#2456

@lastlink lastlink changed the title export utils methods export library internal methods Sep 30, 2022
@nharsch
Copy link

nharsch commented Oct 27, 2022

+1

@lastlink I have a similar use case, I'm generating Mermaid ERD diagrams to represent data relationships in CSV files: https://github.com/nharsch/mermaid-erd-generator
I'm looking into migrating this from python -> JS (maybe ClojureScript) and using the mermaid library parsers directly in order to getEntities getRelationships, etc. That way I could generate SQL output given an ERD string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants