Global $n$-compact Validation Engine

Class

TreeIndexer

TreeIndexer provides a configurable way to traverse a tree of LogicConcept nodes and collect matching nodes into indexes.

It can

  • collect all nodes in the document satisfying a custom selector
  • store the results in either an Array or Set (depending on if order matters and duplicates are allowed)
  • transform the selected nodes before collecting them with a custom proc
  • traverse the tree in either Depth-first, or Post-order order

Constructor

new TreeIndexer(root)

Create a TreeIndexer.

Parameters

Source

Methods

define(key, options)

Define a new index.

Parameters

  • key string

    Unique key for the index.

  • options Object

    Configuration options for the index.

    Properties

    • selector function <optional>

      Function to decide if a node matches the index.

    • transform function <optional>

      Function to transform the matching node's value.

    • type 'Array' | 'Set' <optional>

      Whether to store results in an Array or Set.

    • order 'Depth' | 'Post' <optional>

      Tree traversal order to use.

Source

delete(…keys)

Delete one or more index cache entries. If no keys are given, clears the entire cache.

Parameters

  • keys string <repeatable>

    The index keys to delete.

Source

get(key) → {Array|Set}

Retrieve all indexed values for a specific key, using cached data if available. Triggers a fresh update if the cache is empty.

Parameters

  • key string

    The index key.

Returns

  • Array Set

    The set or array of indexed values.

Source

show()

Print a string representation of the current cache state. Intended for debugging or inspection in Lode. It doesn't actually return a string.

Source

update(key) → {Array|Set}

Traverse the tree and update the cache for a single index key.

Parameters

  • key string

    The index key to update.

Returns

  • Array Set

    The result of the index computation.

Throws

Will throw an error if the key is not defined.

Source

updateAll()

Update all indexes, traversing the tree only once per order type. Clears and rebuilds the entire cache.

Source