moonrockz/diagrams/data-tree

Types

DataTree

pub struct DataTree {
  id : String
  root : String
  nodes : ReadOnlyArray[Node]
  highlights : ReadOnlyArray[Highlight]
  title : String?
  accessibility_title : String?
  accessibility_description : String?
} derive(Eq, @moonbitlang/core/debug.Debug)

One immutable structured-data diagram. It does not depend on JSON or YAML.

Source

DataTree::equal

fn DataTree::equal(DataTree, DataTree) -> Bool

Source

DataTree::new

fn DataTree::new(id : String, root : String, nodes : ArrayView[Node], highlights? : ArrayView[Highlight], title? : String, accessibility_title? : String, accessibility_description? : String) -> DataTree

Source

DataTree::not_equal

fn DataTree::not_equal(x : DataTree, y : DataTree) -> Bool

Source

DataTree::to_repr

fn DataTree::to_repr(DataTree) -> @moonbitlang/core/debug.Repr

Source

Highlight

pub struct Highlight {
  targets : ReadOnlyArray[String]
  style : String?
} derive(Eq, @moonbitlang/core/debug.Debug)

A view highlight. Targets are member or node identities. The optional style is inert author metadata; library themes paint every highlight.

Source

Highlight::equal

fn Highlight::equal(Highlight, Highlight) -> Bool

Source

Highlight::new

fn Highlight::new(targets : ArrayView[String], style? : String) -> Highlight

Source

Highlight::not_equal

fn Highlight::not_equal(x : Highlight, y : Highlight) -> Bool

Source

Highlight::to_repr

fn Highlight::to_repr(Highlight) -> @moonbitlang/core/debug.Repr

Source

Index

pub struct Index {
  tree : DataTree
  order : ReadOnlyArray[String]
  // private fields
}

A validated data tree with constant-time lookups. Each node except the root has exactly one owning entry occurrence.

Source

Index::build

fn Index::build(tree : DataTree, limits? : Limits) -> IndexResult

Validate identities, containment, keys, numbers, highlights and limits without recursion. Scalar text is never interpreted as a reference.

Source

Index::container

fn Index::container(self : Index, entry : String) -> String?

The container node that holds a entry occurrence.

Source

Index::depth

fn Index::depth(self : Index, node : String) -> Int?

Source

Index::find_member

fn Index::find_member(self : Index, id : String) -> Member?

Source

Index::node

fn Index::node(self : Index, id : String) -> Node?

Source

Index::owner

fn Index::owner(self : Index, node : String) -> Member?

The entry occurrence that owns a node. The root has none.

Source

IndexResult

pub struct IndexResult {
  index : Index?
  diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}

Source

Key

pub(all) enum Key {
  Name(String)
  Index(Int)
} derive(Eq, @moonbitlang/core/debug.Debug)

The key of one member occurrence: an object member name or an array position.

Source

Key::equal

fn Key::equal(Key, Key) -> Bool

Source

Key::not_equal

fn Key::not_equal(x : Key, y : Key) -> Bool

Source

Key::to_repr

fn Key::to_repr(Key) -> @moonbitlang/core/debug.Repr

Source

Limits

pub struct Limits {
  nodes : Int
  depth : Int
  work : Int
} derive(Eq, @moonbitlang/core/debug.Debug)

Explicit bounds for data-tree validation and indexing.

Source

Limits::equal

fn Limits::equal(Limits, Limits) -> Bool

Source

Limits::new

fn Limits::new(nodes? : Int, depth? : Int, work? : Int) -> Limits

Source

Limits::not_equal

fn Limits::not_equal(x : Limits, y : Limits) -> Bool

Source

Limits::to_repr

fn Limits::to_repr(Limits) -> @moonbitlang/core/debug.Repr

Source

Member

pub struct Member {
  id : String
  key : Key
  value : String
  source : @moonrockz/diagrams.Span?
} derive(Eq, @moonbitlang/core/debug.Debug)

One member occurrence of a container. value names the child node. Repeated names and equal values keep separate member identities.

Source

Member::equal

fn Member::equal(Member, Member) -> Bool

Source

Member::index

fn Member::index(id : String, index : Int, value : String, source? : @moonrockz/diagrams.Span) -> Member

Source

Member::named

fn Member::named(id : String, name : String, value : String, source? : @moonrockz/diagrams.Span) -> Member

Source

Member::not_equal

fn Member::not_equal(x : Member, y : Member) -> Bool

Source

Member::to_repr

fn Member::to_repr(Member) -> @moonbitlang/core/debug.Repr

Source

Node

pub struct Node {
  id : String
  value : Value
  source : @moonrockz/diagrams.Span?
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

Node::array

fn Node::array(id : String, members : ArrayView[Member], source? : @moonrockz/diagrams.Span) -> Node

Source

Node::equal

fn Node::equal(Node, Node) -> Bool

Source

Node::is_container

fn Node::is_container(self : Node) -> Bool

Source

Node::members

fn Node::members(self : Node) -> ReadOnlyArray[Member]

The member occurrences of a container, or an empty array for a scalar.

Source

Node::new

fn Node::new(id : String, value : Value, source? : @moonrockz/diagrams.Span) -> Node

Source

Node::not_equal

fn Node::not_equal(x : Node, y : Node) -> Bool

Source

Node::object

fn Node::object(id : String, members : ArrayView[Member], source? : @moonrockz/diagrams.Span) -> Node

Source

Node::to_repr

fn Node::to_repr(Node) -> @moonbitlang/core/debug.Repr

Source

Value

pub(all) enum Value {
  Object(ReadOnlyArray[Member])
  Array(ReadOnlyArray[Member])
  Text(String)
  Number(String)
  Boolean(Bool)
  Null
} derive(Eq, @moonbitlang/core/debug.Debug)

A typed value. Numbers keep their exact decimal lexeme; no machine floating-point value is computed.

Source

Value::equal

fn Value::equal(Value, Value) -> Bool

Source

Value::not_equal

fn Value::not_equal(x : Value, y : Value) -> Bool

Source

Value::scalar_text

fn Value::scalar_text(self : Value) -> String?

The visible text of a scalar value, or None for a container.

Source

Value::to_repr

fn Value::to_repr(Value) -> @moonbitlang/core/debug.Repr

Source

Values

diagnostic_codes

let diagnostic_codes : ReadOnlyArray[String]

The stable diagnostic codes of data-tree validation.

Source

valid_number

fn valid_number(lexeme : String) -> Bool

True when lexeme is a valid JSON number spelling.

Source

validate

fn validate(tree : DataTree, limits? : Limits) -> ReadOnlyArray[@moonrockz/diagrams.Diagnostic]

Validate a constructed data tree. An empty result means the tree is valid.

Source