Coverage for src/prosemark/domain/compile/models.py: 100%
26 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-09-28 19:17 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-09-28 19:17 +0000
1"""Domain models for compile functionality.
3This module contains the core data structures used in the compilation process,
4following the domain-driven design principles.
5"""
7from dataclasses import dataclass
9from prosemark.domain.models import NodeId
12@dataclass(frozen=True)
13class CompileRequest:
14 """Request to compile a node and its subtree.
16 Attributes:
17 node_id: The root node to start compilation from
18 include_empty: Whether to include empty nodes (default: False)
20 """
22 node_id: NodeId
23 include_empty: bool = False
26@dataclass(frozen=True)
27class CompileResult:
28 """Result of compiling a subtree.
30 Attributes:
31 content: The concatenated plain text content
32 node_count: Number of nodes included in compilation
33 total_nodes: Total nodes traversed (including skipped)
34 skipped_empty: Number of empty nodes skipped
36 """
38 content: str
39 node_count: int
40 total_nodes: int
41 skipped_empty: int
43 def __post_init__(self) -> None:
44 """Validate the result data."""
45 if self.node_count < 0:
46 raise ValueError('node_count must be non-negative')
47 if self.total_nodes < self.node_count:
48 raise ValueError('total_nodes must be >= node_count')
49 if self.skipped_empty < 0:
50 raise ValueError('skipped_empty must be non-negative')
51 if self.skipped_empty > self.total_nodes - self.node_count:
52 raise ValueError('skipped_empty cannot exceed traversed - included nodes')
55@dataclass(frozen=True)
56class NodeContent:
57 """Represents the content of a single node during traversal.
59 Attributes:
60 id: Node identifier
61 content: The text content of the node
62 children: List of child node IDs
64 """
66 id: NodeId
67 content: str
68 children: list[NodeId]