Class: AppModel

lib/compiler/atlas/AppModel.AppModel(optionsopt)

The application's semantic model.

Built as a by-product of compilation — nothing here re-parses a file the compiler has already read — and serialized beside the bundle rather than into it.

Constructor

new AppModel(optionsopt)

Creates an empty model.

Parameters:
Name Type Attributes Description
options object <optional>

Model options.

Properties
Name Type Attributes Description
requireNodes boolean <optional>

Drop an edge naming a node that does not exist. True for a whole-application model, where a dangling edge would print as a relationship to nothing. False for a per-unit fragment, which is built in isolation and legitimately names nodes that only exist once it is merged.

Source:

Members

__edgeKeys :Set:.<string:>

Type:
  • Set:.<string:>
Source:

__in :Map:.<string:, Array:.<object:>>|null

Type:
  • Map:.<string:, Array:.<object:>> | null
Source:

__out :Map:.<string:, Array:.<object:>>|null

Adjacency indexes, invalidated whenever an edge is added.

Type:
  • Map:.<string:, Array:.<object:>> | null
Source:

__unresolvedKeys :Set:.<string:>

Type:
  • Set:.<string:>
Source:

edges :Array:.<object:>

Every edge, in insertion order. Deduplicated by AppModel#edgeKey.

Type:
  • Array:.<object:>
Source:

errors :Array:.<{phase:: string:, code:: string:, message:: string:}>

Phases that failed while the model was being built.

A query command analyses a project that may not compile — that is often exactly why it is being run — so a phase is allowed to fail without losing the rest of the model. What failed is recorded here so the answer can say which part of the project is missing from it.

Type:
  • Array:.<{phase:: string:, code:: string:, message:: string:}>
Source:

nodes :Map:.<string:, object:>

Nodes by id.

Type:
  • Map:.<string:, object:>
Source:

requireNodes :boolean

Whether an edge requires both of its endpoints to exist.

Type:
  • boolean
Source:

unresolved :Array:.<object:>

Relationships analysis could not resolve.

Type:
  • Array:.<object:>
Source:

Methods

addEdge(edge) → {boolean}

Adds an edge between two nodes.

An edge naming a node that does not exist is dropped rather than creating a phantom: every query walks this graph, and a dangling target would print as a relationship to nothing.

Parameters:
Name Type Description
edge object

{from, to, kind, confidence, loc?, path?, via?}.

Source:
Returns:

True when the edge was stored.

Type
boolean

addNode(node) → {object}

Adds a node, merging into an existing one with the same id.

Merging matters because a node can be discovered twice from two directions — a bridge is created when it is analysed and referenced again when a component imports it — and the second sighting must not erase the first one's location or metadata.

Parameters:
Name Type Description
node object

The node. Must carry id and kind.

Source:
Returns:

The stored node.

Type
object

addUnresolved(entry) → {boolean}

Records something analysis could not resolve.

Parameters:
Name Type Description
entry object

{reason, expr, owner?, loc?, name?}.

Source:
Returns:

True when the entry was stored.

Type
boolean

counts() → {Object:.<string:, number:>}

A count of each node kind, for the avenx atlas summary.

Source:
Returns:

Counts keyed by kind.

Type
Object:.<string:, number:>

edgeKey(edge) → {string}

The deduplication key for an edge.

Location is part of the key so two distinct call sites of the same action stay two edges — avenx impact prints them as separate lines, which is the point.

Parameters:
Name Type Description
edge object

The edge.

Source:
Returns:

The key.

Type
string

getNode(id) → {object|undefined}

Looks a node up by id.

Parameters:
Name Type Description
id string

The node id.

Source:
Returns:

The node.

Type
object | undefined

hasNode(id) → {boolean}

Whether a node id is present.

Parameters:
Name Type Description
id string

The node id.

Source:
Returns:

True when the node exists.

Type
boolean

incoming(id) → {Array:.<object:>}

Edges entering a node — what depends on it.

Parameters:
Name Type Description
id string

The node id.

Source:
Returns:

The edges.

Type
Array:.<object:>

merge(fragment) → {void}

Merges a fragment produced against another model into this one.

Node and edge ids are absolute, so a fragment built in isolation slots in without rewriting. This model's own edge rules apply during the merge, which is what lets a fragment be captured leniently and still be checked when it lands.

Parameters:
Name Type Description
fragment Object

What to merge.

Source:
Returns:
Type
void

nodesOfKind(kind) → {Array:.<object:>}

Every node of a given kind.

Parameters:
Name Type Description
kind string

One of AtlasNodeKind.

Source:
Returns:

The nodes, ordered by id.

Type
Array:.<object:>

outgoing(id) → {Array:.<object:>}

Edges leaving a node — what it depends on.

Parameters:
Name Type Description
id string

The node id.

Source:
Returns:

The edges.

Type
Array:.<object:>

toJSON() → {object}

Serializes the model.

Nodes, edges and unresolved entries are sorted rather than emitted in discovery order, so two builds of unchanged sources produce byte-identical output and the artifact can be diffed in review.

Source:
Returns:

The serializable model.

Type
object

unresolvedFor(owner) → {Array:.<object:>}

The unresolved entries recorded against one owner.

Parameters:
Name Type Description
owner string

An owner node id.

Source:
Returns:

The entries.

Type
Array:.<object:>