XanthamTree — the runtime façade
XanthamTree is the entry point most generators want to start from. It owns
the file-load, decode, freeze, and (lazily) the arena interning steps, and
exposes them through a small set of frozen lookups.
Constructing a tree
The simplest case takes a path to a Xantham JSON file:
let tree = Runtime.create "./schema.json"
For more control over decoder behaviour (compression, sanitization, health
check), use createWith and adjust the Decoder.Settings:
let custom =
"./schema.json"
|> Runtime.createWith (fun s ->
{ s with
Decoder =
{ s.Decoder with
Compress = false
Sanitize = true
PerformHealthCheck = true } })
Runtime.Settings.Create and Runtime.Settings.Init are the two underlying
factory methods — Init produces defaults; Create lets you transform them.
What's on the tree
Each member is a FrozenDictionary or FrozenSet, so lookups are allocation-
free and thread-safe.
Member |
Purpose |
|---|---|
|
Every structural |
|
Every |
|
All declarations, grouped by their source module path. |
|
Look up a function export by any of its overloaded signature keys. |
|
The set of |
|
Predicate convenience for |
The deprecated tree.TopLevelExports is preserved for backward compatibility;
prefer ExportMap keyed by your source module.
Coding a key
tree.Codify key takes any TypeKey and returns a CodeKey that tags the
key with the kind of construct it identifies:
let codeKey = tree.Codify (Xantham.TypeKey.createWith 59)
match codeKey with
| Xantham.Decoder.CodeKey.CodeKey.Export exp ->
printfn "exported declaration: %A" exp
| Xantham.Decoder.CodeKey.CodeKey.Type typ ->
printfn "structural type: %A" typ
This avoids re-walking the underlying TsType / TsExportDeclaration every
time a generator needs to dispatch on category. See
Code Keys for the full taxonomy.
Crossing into the resolved graph
When a generator wants to walk types as a graph rather than as flat maps, ask the tree for its arena interner. The first call materialises the entire export shell; subsequent calls return the cached value:
let interner = tree.GetArenaInterner()
See ArenaInterner for what the resolved graph looks like and when to prefer it over raw maps.
Building a dependency graph
tree.GetDependencyGraph() returns a Graph over the type/export maps with
conditional Check/Extends branches excluded from the edge set. See
Dependency Graph.
let graph = tree.GetDependencyGraph()
<summary> Create a <see cref="T:XanthamTree" /> from the given Xantham JSON file path using default decoder settings. </summary>
<param name="fileName">Path to the input JSON file.</param>
<summary> Create a <see cref="T:XanthamTree" /> from the given Xantham JSON file path with a transformation function applied to the default <see cref="T:Settings" />. </summary>
<param name="fn">Transform applied to the default settings.</param>
<param name="fileName">Path to the input JSON file.</param>
<summary> Decoder-layer settings controlling how the input JSON is read. </summary>
module TypeKey from Xantham
--------------------
type TypeKey = System.Int32
<summary> A unique identifier for a type. </summary>
<summary> Discriminated unions tagging a <c>TypeKey</c> with the kind of construct it identifies. Used by consumers (e.g. generators) that need to dispatch on the structural kind of a type or export without re-walking the full <c>TsType</c>/<c>TsExportDeclaration</c>. </summary>
<summary> Outer envelope distinguishing whether a <c>TypeKey</c> identifies an exported declaration (<see cref="T:ExportCodeKey" />) or a structural type (<see cref="T:TypeCodeKey" />). </summary>
<category index="2">Code Key Tagging</category>
<summary> The key identifies an exported declaration. </summary>
<summary> The key identifies a structural type only. </summary>