Consume as Typed Data: Reading the Document as a Model
Each example builds on the one before it — read the ladder in order, or jump to the rung you need. Every shipped artifact is regression-checked against the real CLI and library output.
- CONSUME-AS-DATA-01: Open the read() door for typed frontmatter — contract.read returns a typed Doc whose frontmatter fields you pull with no separate types file.
- CONSUME-AS-DATA-02: Read one section’s prose two ways — The same SectionView is reachable by camelCase key and by the exact .section(name) accessor.
- CONSUME-AS-DATA-03: Walk a SectionView’s content surface — A SectionView exposes name, pos, anchors, text(scope), tables/table and lists, with absent optionals reading as undefined.
- CONSUME-AS-DATA-04: Iterate a TableView’s typed rows — A section whose sole content is a table promotes to a TableView you iterate as typed rows.
- CONSUME-AS-DATA-05: Target rows with column / find / rowPos — TableView offers column(name), find(pred), and rowPos(i) for column slices, predicate lookups, and per-row source positions.
- CONSUME-AS-DATA-06: Name two tables in one section — A section’s content record yields several independently-named TableViews, each its own typed view.
- CONSUME-AS-DATA-07: Look blocks up by anchor — doc.byAnchor(id) and section-scoped byAnchor resolve any ^anchor to a kind-discriminated BlockView, declared or not.
- CONSUME-AS-DATA-08: Traverse nested subsections — SectionView.sections is itself a dual-key group of the nested H3 subsections.
- CONSUME-AS-DATA-09: Collect tolerated extra sections — Sections outside the contract (via gap()/allowUnknown) partition into doc.body.unknown as a positional SectionView[].
- CONSUME-AS-DATA-10: Contrast validate() with read() — validate() returns {findings, doc, tree} and never throws, while read() hands back a typed Doc or throws ContractError on error-level findings.
- CONSUME-AS-DATA-11: Read a real task into typed data — One contract reads a live Task end-to-end — frontmatter, a TableView, a list, and absent optionals — then does work with the typed result.