docs/library.mdtype: Reference

One type per spec concern.

The OKF4net namespace mirrors the spec: Bundle (§3), ConceptId (§2), OkfDocument/Frontmatter (§4), links (§5, §8), IndexGenerator (§6), ChangeLog (§7), BundleValidator (§9). Zero third-party dependencies — the YAML subset and link scanner are the library's own.

##

At a glance

load · validate · traverse
using OKF4net;

var bundle = Bundle.Load("./my_bundle");           // §3 — permissive walk
var report = BundleValidator.Validate(bundle);      // §9 — diagnostics
Console.WriteLine(report.IsConformant
    ? $"conformant with OKF v{OkfSpec.Version}" : $"{report.ErrorCount} error(s)");

var id = ConceptId.Parse("tables/orders");        // §2
foreach (var link in bundle.LinksFrom(id))          // §5
    Console.WriteLine($"{id} -> {link.Target} (exists: {link.Exists})");
foreach (var back in bundle.Backlinks(id))
    Console.WriteLine($"cited by {back}");
##

Bundle

§3 — a directory of concepts

Bundle.Load walks the tree, parses every concept, and builds the cross-link graph. It is permissive: a bad file lands in ParseErrors and never aborts the load.

MemberDescription
Load(string root) → BundleWalk a directory and build the graph. Throws BundleLoadException only when the root itself is unreadable.
Root → stringThe bundle's root path.
Concepts → IReadOnlyList<Concept>All parsed concepts, in component-wise walk order.
Count → int · IsEmpty → boolNumber of concepts.
Get(ConceptId) → Concept?Look up one concept; null if absent.
Contains(ConceptId) → boolWhether the id resolves.
LinksFrom(ConceptId) → IReadOnlyList<ResolvedLink>Outgoing links, each flagged Exists.
Backlinks(ConceptId) → IReadOnlyList<ConceptId>Concepts that link to this one.
BrokenLinks() → IReadOnlyList<(ConceptId, string)>Every edge to a missing concept.
IndexFiles · LogFiles → IReadOnlyList<string>Reserved index.md / log.md paths found.
ParseErrors → IReadOnlyList<(string Path, string Error)>Files that failed to parse, with why.
ConceptRecord: Id, Path, Document.
##

ConceptId

§2 — id ↔ path

A concept id is the file path with .md removed, as ordered segments. Sortable and value-equal.

MemberDescription
Parse(string) → ConceptIdParse "tables/orders"; throws ConceptIdException on an invalid segment.
TryParse(string, out ConceptId?) → boolNon-throwing parse.
FromPath(root, path) → ConceptIdDerive an id from a file path under a bundle root.
ToPath(root) → stringInverse: the .md file path under a root.
Segments → IReadOnlyList<string>The path components.
Name → string · Parent → ConceptId?Last segment; id of the containing directory.
ValidateSegment(string)Throw if a single segment is not spec-legal.
##

OkfDocument & Frontmatter

§4 — one concept

Frontmatter keeps the full ordered mapping and layers typed getters on top, so producer-defined keys survive round-trips. Two validation levels: ValidateConformance() enforces only §9 (non-empty type); Validate() is the stricter producer check (type, title, description, timestamp).

OkfDocumentDescription
Parse(string) → OkfDocumentParse frontmatter + body; throws DocumentParseException.
TryParse(string, out doc, out error) → boolNon-throwing parse.
Serialize() → stringRe-emit; preserves key order and unknown keys.
Validate() · ValidateConformance()Producer check / §9 check; throw DocumentValidationException.
Links() → IReadOnlyList<ConceptLink>Markdown links in the body.
Citations() → IReadOnlyList<Citation>Numbered citations in the body.
Frontmatter → Frontmatter · Body → stringThe two halves of the document.
FrontmatterDescription
Type · Title · Description · Resource · Timestamp → string?Typed getters over the mapping.
Tags → IReadOnlyList<string>The tags sequence, or empty.
ExtensionKeys → IReadOnlyList<string>Producer-defined keys beyond the reserved set.
AsMapping() → YamlMappingThe underlying ordered mapping.
Set(string, YamlValue) · FromMapping(YamlMapping)Mutate a key / wrap an existing mapping.
##

The YAML subset

Yaml — frontmatter only

A documented subset: scalars, sequences, shallow maps, block and flow styles, |/> block scalars. It rejects anchors, tags, and multi-document streams with clear errors — frontmatter never needs them.

MemberDescription
YamlValue.Parse(string) → YamlValueParse the subset; throws YamlParseException (with a line number).
YamlEmitter.Emit(YamlValue) → stringSerialize back to the same subset.
AsString() · AsBool() · AsSequence() · AsMapping()Typed views; null if the node is another kind.
ToYamlString() → stringEmit a single value.
YamlMapping: Get · ContainsKey · Entries · Keys · CountOrder-preserving map access.
##

IndexGenerator & ChangeLog

§6, §7 — reserved files
MemberDescription
IndexGenerator.RegenerateIndexes(root) → IReadOnlyList<string>Write every index.md; returns the paths written.
RegenerateIndexesWith(root, Synthesize)Same, with a custom description synthesizer.
BuildIndexText(entries) → stringRender one listing without touching disk.
IndexEntry(Type, Title, Link, Description)One row of a generated index.
ChangeLog: Days · Title · ToMarkdown() · InvalidDates()Parse / render a log.md (§7); IsIsoDate(s) validates a date.
LogDay(Date, Entries) · LogEntry(Kind, Text)A day's block and one entry.
##

Validation

§9 — conformance
MemberDescription
BundleValidator.Validate(Bundle) → ValidationReportRun the §9 conformance check.
ValidationReport.IsConformant → boolTrue when there are no Error diagnostics.
Diagnostics → IReadOnlyList<Diagnostic>Every finding; Of(severity) filters.
ErrorCount · WarningCount → intTallies by severity.
Diagnostic(Severity, Path, Concept, Message)One finding; ToString() is the CLI line.
SeverityEnum: Error, Warning, Info.
OkfSpec.Version → stringThe implemented spec version ("0.1").
##

Errors

one base exception

Every library exception derives from OkfException, so one catch covers the surface. Loading is permissive, so most day-to-day work throws nothing — failures accumulate in ParseErrors instead.

ExceptionThrown by
OkfExceptionBase type for all of the below.
ConceptIdExceptionConceptId.Parse / ValidateSegment.
BundleLoadExceptionBundle.Load, when the root is unreadable.
DocumentParseExceptionOkfDocument.Parse.
DocumentValidationExceptionValidate / ValidateConformance.
YamlParseExceptionThe YAML subset parser (carries a Line).

cli.md — the same engine as a binary · getting-started.md