Module: lib/compiler/atlas/routes

Route and guard discovery, as part of the compiler's model.

Routing is declared, not inferred: initRouter takes an object literal mapping patterns to pages, and guards are classes in known directories. Both are therefore compiler knowledge — but until now the only code that read them was bin/commands/inspect.js, with a regex, at CLI time.

Moving the reading here gives Atlas, inspect and stats one source of truth instead of three scanners that agree by coincidence.

Source:

Methods

(static) addRoutesAndGuards(model, context) → {void}

Adds routes, guards and the relationships between them to the model.

Route nodes are keyed by their normalized pattern rather than by the page they resolve to: two patterns can reach the same page, and avenx impact should list both.

Parameters:
Name Type Description
model object

The AppModel being built.

context object

{srcDir, rootDir}.

Source:
Returns:
Type
void

(static) findGuards(srcDir) → {Array:.<{name:: string:, filePath:: string:}>}

Collects the guard classes a project declares.

Parameters:
Name Type Description
srcDir string

The project source directory.

Source:
Returns:

Declared guards.

Type
Array:.<{name:: string:, filePath:: string:}>

(static) normalizeRoute(pattern) → {string}

Normalizes a route pattern to the form the router matches.

'', '#' and '#/' all mean the root; a leading # is display syntax rather than part of the path.

Parameters:
Name Type Description
pattern string

The declared pattern.

Source:
Returns:

The normalized path.

Type
string

(static) parseRouteTable(source) → {Array:.<object:>}

Reads every initRouter({...}) declaration in a source file.

Handles both accepted forms of a route target: a bare page name, and an object carrying page and guards.

Parameters:
Name Type Description
source string

The file contents.

Source:
Returns:

Route declarations with their offsets.

Type
Array:.<object:>

(static) toClassName(base) → {string}

Converts a file base name to the class name the compiler generates.

Parameters:
Name Type Description
base string

A file base name, e.g. user-profile.

Source:
Returns:

The PascalCase class name.

Type
string

(inner) matchBrace(source, open) → {number}

Finds the offset of the bracket closing the one at open.

Parameters:
Name Type Description
source string

The source text.

open number

Offset of the opening bracket.

Source:
Returns:

Offset of the match, or -1.

Type
number

(inner) splitEntries(body) → {Array:.<{text:: string:, offset:: number:}>}

Splits an object literal's body into its top-level entries.

Parameters:
Name Type Description
body string

The text between the outer braces.

Source:
Returns:

The entries.

Type
Array:.<{text:: string:, offset:: number:}>