Decoder — JSON to DecodedResult
Decoder is the layer below XanthamTree. It is responsible only for
reading a Xantham JSON file off disk and applying the standard compression
and sanitization passes before producing a DecodedResult.
You usually don't need to call into Decoder directly — XanthamTree does it
for you — but it's exposed for tooling and tests.
The simple path
let result = Decoder.read "./schema.json"
match result with
| Ok decoded ->
printfn
"Loaded %i types and %i exported declarations."
decoded.TypeMap.Count
decoded.ExportTypeMap.Count
| Error e -> eprintfn "Decode failed: %s" e
Decoder.read is a proxy that constructs a default Settings and calls
readWithSettings.
Settings
Decoder.Settings controls the three optional passes the decoder runs:
Field |
Default |
Effect |
|---|---|---|
|
(required) |
Path to the |
|
|
Walks the type map, verifies that every referenced |
|
|
Collapses redundant entries in the type/export maps. |
|
|
Replaces cyclic |
Construct settings with the Create static method:
let settings =
Decoder.Settings.Create(
inputFile = "./schema.json",
performHealthCheck = true,
compress = true,
sanitize = false)
let decoded = Decoder.readWithSettings settings
DecodedResult
The shape returned on success:
TypeMap : Map<TypeKey, TsType>— every structural type in the input.-
ExportTypeMap : Map<TypeKey, TsExportDeclaration>— every exported declaration. -
ExportMap : Map<string, Set<TypeKey>>— exports grouped by source module path. -
TopLevelExports : TypeKey list— exports declared at the top level of the input. -
LibEsExports : TypeKey list— exports that originate from the TS standard library files.
The wire format itself (Schema.EncodedResult) lives in Xantham.Common.
Health check
When enabled, the health check answers the question "are all referenced
TypeKeys present in the type map?". It distinguishes:
- Missing keys — referenced but absent from
TypeMap. -
Found-in-node-store — missing from
TypeMapbut present as an export declaration. Generation is still safe in this case. - Unemitted keys — missing from both. Generation against this dataset is likely to fail.
The report is printed to stdout. The status emojis (✔️ / ❌) are part of
the printed output, not the return value.
<summary> Decode a xantham produced <c>.json</c> file. This is a proxy function that creates a <c>Settings</c> object using the default values and the supplied <c>fileName</c> which is then passed to <c>readWithSettings</c>. </summary>
<summary> All structural types referenced anywhere in the source, keyed by <c>TypeKey</c>. </summary>
<summary> All exported declarations, keyed by <c>TypeKey</c>. </summary>
<summary> Settings for the Decoder. </summary>
<category index="6">Runtime</category>
<summary> Decode a xantham produced <c>.json</c> file with the settings provided. </summary>