Logo Xantham

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

tree.TypeMap

Every structural TsType decoded from the input, keyed by TypeKey.

tree.KeyExportMap

Every TsExportDeclaration, keyed by TypeKey.

tree.ExportMap

All declarations, grouped by their source module path.

tree.SignatureFunctionMap

Look up a function export by any of its overloaded signature keys.

tree.LibEsExports

The set of TypeKeys belonging to the TS standard library (lib.es*.d.ts).

tree.IsLibEsExport

Predicate convenience for LibEsExports.

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()
namespace Xantham
namespace Xantham.Decoder
val tree: Runtime.XanthamTree
module Runtime from Xantham.Decoder
val create: fileName: string -> Runtime.XanthamTree
<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>
val custom: Runtime.XanthamTree
val createWith: fn: (Runtime.Settings -> Runtime.Settings) -> fileName: string -> Runtime.XanthamTree
<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>
val s: Runtime.Settings
module Decoder from Xantham.Decoder
Runtime.Settings.Decoder: Decoder.Settings
<summary> Decoder-layer settings controlling how the input JSON is read. </summary>
val codeKey: CodeKey.CodeKey
member Runtime.XanthamTree.Codify: key: Xantham.TypeKey -> CodeKey.CodeKey
Multiple items
module TypeKey from Xantham

--------------------
type TypeKey = System.Int32
<summary> A unique identifier for a type. </summary>
val createWith: i: int -> int
module CodeKey from Xantham.Decoder
<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>
type CodeKey = | Export of export: ExportCodeKey | Type of typeCode: TypeCodeKey
<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>
union case CodeKey.CodeKey.Export: export: CodeKey.ExportCodeKey -> CodeKey.CodeKey
<summary> The key identifies an exported declaration. </summary>
val exp: CodeKey.ExportCodeKey
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
union case CodeKey.CodeKey.Type: typeCode: CodeKey.TypeCodeKey -> CodeKey.CodeKey
<summary> The key identifies a structural type only. </summary>
val typ: CodeKey.TypeCodeKey
val interner: ArenaInterner.ArenaInterner
member Runtime.XanthamTree.GetArenaInterner: unit -> ArenaInterner.ArenaInterner
val graph: Types.Graph.Graph
member Runtime.XanthamTree.GetDependencyGraph: unit -> Types.Graph.Graph

Type something to start searching.