finos/morphir-elm/8.1.0

NOTE: the latest version is 22.0.2

Formerly Morgan-Stanley/morphir-elm. Search finds this package by either name.

Morphir.Graph.Grapher

The Grapher module analyses a distribution to build a graph for dependency and lineage tracking purposes. The goal is to understand data flow and to automate contribution to the types of products that are commonly used in enterprises. The result of processing is a Graph, which is a collection of Nodes and Edges.

Types

type Node
= Record FQName
| Field FQName Name
| Type FQName
| Function FQName
| Unknown String

Node defines a node in the graph. We capture specific node types for this purpose. The types of constructs that we're interested in tracking are:

  • Record - Represents collection of fields. Corresponds to Morphir.IR.Type.Record
  • Field - Represents a field within a Record.
  • Type - Represents a Type or Type Alias, which we want to track aliases through their hierarchies.
  • Function - Represents a Function.
  • Unknown - Questionable practice, but it's useful to identify relationships we might want to track in the future.
type Verb
= IsA
| Aliases
| Contains
| Uses
| Calls
| Produces
| Parameterizes
| Unions

Verb defines the possible relationships that we're interested in tracking. These are used to define the relationships in the edges of our graph.

  • IsA - Denotes an implementation of a Type by fields, function parameters, and the such.
  • Aliases - Denotes a type alias, for which we want to track the full hierarchy.
  • Contains - Denotes Fields contained in a Record
  • Uses - Denotes use of a type by a Function.
  • Calls - Denotes a Function call within another Function.
  • Produces - Denotes the output of a Function.
  • Parameterizes - Denotes type variable usage.
  • Unions - Denotes the Types utilized in a union type.
type alias Edge =
{ subject : Node
, verb : Verb
, object : Node
}

Defines an edge in the graph as a triple of the subject node, the relationship, and the object node.

= NodeEntry Node
| EdgeEntry Edge

Defines the possible graph entries of Node and Edge.

type alias Graph =

Defines a graph as a collection of nodes and edges.

Processing

Process this distribution into a Graph of its packages.

mapPackageDefinition : PackageName -> Definition ta va -> Graph

Process this package into a Graph of its modules. We take two passes to the IR. The first collects all of the types and the second processes the functions and their relationships to those types.

mapModuleTypes : PackageName -> ModuleName -> Definition ta va -> Graph

Process this module to collect the types used and produced by it.

PackageName
-> ModuleName
-> Definition ta va
-> Dict String Node
-> Graph

Process this module to collect the functions and relationships to types.

mapTypeDefinition : PackageName -> ModuleName -> Name -> Definition ta -> Graph

Process a type since there are a lot of variations.

PackageName
-> ModuleName
-> Name
-> Definition ta va
-> Dict String Node
-> Graph

Process Functions specifically and ignore the rest.

Utilities

Utility for dealing with comparable.

nodeType : Node -> String

Utility to extract the Node type as a String.

verbToString : Verb -> String

Utility for dealing with comparable.

Utility to extract the Fully Qualified Name from a Node. This is required because a Field contains both an FQN and field name.