CodeStory.Encoder (CodeStory v0.1.0)

Copy Markdown View Source

Converts a call tree into a JSON-ready plain-data structure.

The tree from CodeStory.narrate/2 is a list of %{module, function, args, return, children} node maps (folded nodes may also carry count:/varies:). encode/2 turns that into a list of plain maps whose values are only strings / numbers / booleans / nil / lists / maps — so JSON.encode!/1 (Elixir 1.18+) or Jason.encode!/1 works without any change.

Compaction is opt-in — the default is a faithful, complete encode:

  • :fold_repeats (default false) — collapse repeated sibling runs via CodeStory.Fold; folded nodes surface count/varies fields.
  • :depth (default :infinity) — cap nesting. At the cap a node encodes children: [] and truncated: <levels hidden> (the data-native mirror of the formatter's … (N more levels) marker).
  • :detail (default :novel) — value verbosity. :novel keeps full values; any other value (:short_story, :outline) uses the compact inspect opts.

Summary

Types

node_map()

@type node_map() :: %{
  :module => module(),
  :function => atom(),
  :args => keyword(),
  :return => any(),
  :children => [node_map()],
  optional(:count) => pos_integer(),
  optional(:varies) => true
}

Functions

encode(tree, opts \\ [])

@spec encode(
  [node_map()],
  keyword()
) :: [map()]