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

feat(tools): add graph and graph search #614

Merged
merged 6 commits into from
Mar 8, 2023

Conversation

mttrbrts
Copy link
Member

@mttrbrts mttrbrts commented Feb 28, 2023

Adds utilities to allow navigation of the dependency tree of a model as a graph. This allows for more advanced operations like "tree-shaking" (see findConnectedGraph), and finding unused imports (not implemented in this PR).

const visitor = new ConcertoGraphVisitor();
const graph = new DirectedGraph();
modelManager.accept(visitor, { graph });

// Find the maximal subgraph starting from 'ChangeOfAddress'
const connectedGraph = graph.findConnectedGraph('[email protected]');

const filteredModelManager = modelManager
  .filter(declaration => 
    connectedGraph.hasVertex(declaration.getFullyQualifiedName())
  );

Changes

  • Adds filter functions to BaseModelManager and ModelFile to allow filtering declarations based on the graph.
  • Adds ConcertoGraphVisitor and DirectedGraph to concerto-tools, and tests
  • Adds new Declaration type to concerto-core. This is a new Class between ClassDeclaration/ScalarDeclaration and Decorated. This allows us to refactor common functions in the base class. This better matches the metamodel, will allow for better docs, better usage in TypeScript clients, and better extensibility to aggregate types in the future. We use this new type in the definition of the filter function.
  • Also fixes and extends TypeScript types.

Flags

  • While refactoring ClassDeclaration/ScalarDeclaration, I noticed that ScalarDeclaration has several functions that should only appear on ClassDeclaration. I've marked them as @deprecated.

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

@mttrbrts mttrbrts requested a review from a team February 28, 2023 13:57
@mttrbrts mttrbrts marked this pull request as draft February 28, 2023 21:13
@mttrbrts mttrbrts marked this pull request as ready for review March 7, 2023 12:42
Copy link
Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

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

Awesome.

packages/concerto-core/test/introspect/declaration.js Outdated Show resolved Hide resolved
(() => {
testClass.getSuperType();
}).should.throw('Scalars do not have super types.');
should.equal(testClass.getSuperType(), null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why return null here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I'm adding a test to increase coverage which reflects the current implementation.

This is one of the now deprecated functions. It should go away in the next major release, IMO

Signed-off-by: Matt Roberts <[email protected]>
@mttrbrts mttrbrts requested a review from dselman March 8, 2023 14:00
Copy link
Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

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

@mttrbrts mttrbrts enabled auto-merge (squash) March 8, 2023 14:10
@mttrbrts mttrbrts merged commit 19087d6 into accordproject:main Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants