PureYAML/Sources/Validation/SubjectContext.swift
Mihaela M fc1a6db1dc refactor(validation): fold the tagged validator onto one framework
The tagged-node validator carried its own copy of the validation machinery:
a Tagged.Rule cloning Validation's check type and a Tagged.Context cloning
its context, differing only in subject type. That is the per-layer
duplication the validation idiom exists to prevent (principle 10).

Generalise the type-directed framework over both the subject and the
document: SubjectContext, Check, and AnyCheck now take a Document type
parameter for the validated tree's root. The model layer validates with a
Model.Value document, the tagged layer with a Tagged.Node document, each
truthful rather than forcing one root type to stand in for the other.

The tagged layer keeps only what is genuinely its own: the Node document
type, its built-in check (now Tagged.BuiltinCheck, a Check<Node, Node>), and
its traversal. Tagged.Rule and the tagged Context are removed. The validator
surface is unchanged but validating now takes a Check<Node, Node>.

All 399 tests pass; the coverage gate reconciles to 62 public types.
2026-06-28 10:41:10 +02:00

22 lines
837 B
Swift

public extension PureYAML.Validation {
/// The read-only bundle a type-directed check receives: the whole `document` (for cross-cutting
/// checks), the current `subject` of the check's type, and the `path` to where it sits. `Document`
/// is the type of the validated tree's root, so each layer carries a truthful document: `Model.Value`
/// for the model tree, `Tagged.Node` for the tagged tree.
struct SubjectContext<Subject: Validatable, Document: Sendable>: Sendable {
public var document: Document
public var subject: Subject
public var path: Path
public init(
document: Document,
subject: Subject,
path: Path,
) {
self.document = document
self.subject = subject
self.path = path
}
}
}