adaptive_pipeline_domain/value_objects.rs
1// /////////////////////////////////////////////////////////////////////////////
2// Adaptive Pipeline
3// Copyright (c) 2025 Michael Gardner, A Bit of Help, Inc.
4// SPDX-License-Identifier: BSD-3-Clause
5// See LICENSE file in the project root.
6// /////////////////////////////////////////////////////////////////////////////
7
8//! # Domain Value Objects
9//!
10//! This module contains the domain value objects - immutable objects that
11//! represent concepts without identity. Value objects are defined by their
12//! attributes and enforce business rules through validation.
13//!
14//! ## Value Object Characteristics
15//!
16//! All value objects in this system share these characteristics:
17//!
18//! - **Immutability**: Cannot be modified after creation
19//! - **No Identity**: Equality is based on attributes, not identity
20//! - **Self-Validating**: Enforce business rules during construction
21//! - **Side-Effect Free**: Operations don't modify state
22//! - **Composable**: Can be combined to create more complex concepts
23//!
24//! ## Core Value Objects
25//!
26//! ### Identifiers
27//! Strongly-typed identifiers that prevent mixing different types of IDs:
28//!
29//! - [`PipelineId`]: Unique identifier for pipeline instances
30//! - [`StageId`]: Identifier for individual pipeline stages
31//! - [`FileChunkId`]: Identifier for file chunks in processing
32//! - [`EncryptionKeyId`]: Identifier for encryption keys
33//! - [`UserId`]: Identifier for user accounts and sessions
34//! - [`SessionId`]: Identifier for user sessions
35//! - [`ProcessingContextId`]: Identifier for processing contexts
36//! - [`SecurityContextId`]: Identifier for security contexts
37//! - [`GenericId`]: Generic type-safe identifier system
38//!
39//!
40//! ### File Processing Objects
41//! Objects representing file data and processing concepts:
42//!
43//! - [`FileChunk`]: Immutable file chunk with integrity validation
44//! - [`ChunkMetadata`]: Metadata for tracking and managing file chunks
45//! - [`ChunkSize`]: Type-safe chunk size with validation and optimization
46//! - [`GenericSize`]: Generic size value object with unit conversions
47//!
48//!
49//! ### Algorithm and Configuration Objects
50//! Objects representing processing algorithms and their configurations:
51//!
52//! - [`Algorithm`]: Type-safe algorithm specification with validation
53//! - [`ProcessingStepDescriptor`]: Description of processing steps in pipeline
54//! - [`StageParameters`]: Type-safe parameter management for pipeline stages
55//! - [`StageOrder`]: Ordering and sequencing of pipeline stages
56//! - [`WorkerCount`]: Validated worker count for parallel processing
57//!
58//!
59//! ### File System Objects
60//! Objects representing file paths and permissions with type safety:
61//!
62//! - [`FilePath`]: Type-safe file paths with category-specific validation
63//! - [`FilePermissions`]: Cross-platform file permission management
64//!
65//!
66//! ### Binary Format Objects
67//! Objects representing the structure of processed files:
68//!
69//! - [`FileHeader`]: Binary file format header with integrity verification
70//! - [`ChunkFormat`]: Format specification for chunk serialization
71//! - [`ProcessingStepType`]: Type enumeration for processing steps
72//!
73//!
74//! ### Security Objects
75//! Objects representing security contexts and permissions:
76//!
77//! - [`SecurityContextId`]: Identifier for security contexts with expiration
78//! - [`EncryptionKeyId`]: Type-safe encryption key identifiers
79//! - [`EncryptionBenchmark`]: Performance metrics for encryption algorithms
80//!
81//!
82//! ### Processing Configuration Objects
83//! Objects representing processing parameters and requirements:
84//!
85//! - [`PipelineRequirements`]: Configuration for pipeline performance and
86//! security
87//! - [`StageParameters`]: Type-safe parameters for individual stages
88//! - [`WorkerCount`]: Validated parallel worker configuration
89//!
90//!
91//! ## Validation and Business Rules
92//!
93//! Value objects enforce business rules through validation:
94//!
95//!
96//! ### Validation Benefits
97//!
98//! - **Early Error Detection**: Invalid values caught at construction
99//! - **No Invalid States**: Impossible to create invalid value objects
100//! - **Clear Error Messages**: Descriptive validation errors
101//! - **Type Safety**: Compiler enforces validation requirements
102//!
103//!
104//! ## Composition and Transformation
105//!
106//! Value objects can be composed and transformed safely:
107//!
108//!
109//! ### Transformation Patterns
110//!
111//! - **Immutable Transformations**: Create new value objects instead of
112//! mutating
113//! - **Builder Pattern**: Fluent construction of complex value objects
114//! - **Composition**: Combine simple value objects into complex ones
115//! - **Type Conversion**: Safe conversion between related types
116//!
117//!
118//! ## Serialization and Persistence
119//!
120//! Value objects support serialization for persistence and communication:
121//!
122//!
123//! ### Serialization Features
124//!
125//! - **JSON Support**: All value objects implement `Serialize` and
126//! `Deserialize`
127//! - **Type Safety**: Deserialization validates constraints
128//! - **Cross-Platform**: Consistent representation across languages
129//! - **Version Compatibility**: Serialization format stability
130//!
131//!
132//! ## Testing Value Objects
133//!
134//! Value objects are easily testable due to their immutability:
135//!
136//! ```rust
137//! #[cfg(test)]
138//! mod tests {
139//! use super::*;
140//!
141//! #[test]
142//! fn test_value_object_equality() {
143//! let id1 = String::new("test-pipeline").unwrap();
144//! let id2 = String::new("test-pipeline").unwrap();
145//! let id3 = String::new("other-pipeline").unwrap();
146//!
147//! // Equality based on value, not identity
148//! assert_eq!(id1, id2);
149//! assert_ne!(id1, id3);
150//! }
151//!
152//! #[test]
153//! fn test_value_object_immutability() {
154//! let size = String::new(1024).unwrap();
155//! let doubled = size.multiply(2).unwrap();
156//!
157//! // Original value unchanged
158//! assert_eq!(size.as_bytes(), 1024);
159//! assert_eq!(doubled.as_bytes(), 2048);
160//! }
161//!
162//! #[test]
163//! fn test_value_object_validation() {
164//! // Valid values succeed
165//! assert!(String::new(1024).is_ok());
166//!
167//! // Invalid values fail
168//! assert!(String::new(0).is_err());
169//! }
170//! }
171//! ```
172
173pub mod algorithm;
174pub mod binary_file_format;
175pub mod chunk_metadata;
176pub mod chunk_size;
177pub mod encryption_benchmark;
178pub mod encryption_key_id;
179pub mod file_chunk;
180pub mod file_chunk_id;
181pub mod file_path;
182pub mod file_permissions;
183pub mod generic_id;
184pub mod generic_size;
185pub mod pipeline_id;
186pub mod pipeline_requirements;
187pub mod processing_context_id;
188pub mod processing_step_descriptor;
189pub mod security_context_id;
190pub mod session_id;
191pub mod stage_id;
192pub mod stage_order;
193pub mod stage_parameters;
194pub mod user_id;
195pub mod worker_count;
196
197// Re-export all value object types for convenient access
198pub use algorithm::Algorithm;
199pub use binary_file_format::{ChunkFormat, FileHeader, ProcessingStepType};
200pub use chunk_metadata::ChunkMetadata;
201pub use chunk_size::ChunkSize;
202pub use encryption_benchmark::EncryptionBenchmark;
203pub use encryption_key_id::EncryptionKeyId;
204pub use file_chunk::FileChunk;
205pub use file_chunk_id::FileChunkId;
206pub use file_path::FilePath;
207pub use file_permissions::FilePermissions;
208pub use generic_id::GenericId;
209pub use generic_size::GenericSize;
210pub use pipeline_id::PipelineId;
211pub use pipeline_requirements::PipelineRequirements;
212pub use processing_context_id::ProcessingContextId;
213pub use processing_step_descriptor::ProcessingStepDescriptor;
214pub use security_context_id::SecurityContextId;
215pub use session_id::SessionId;
216pub use stage_id::StageId;
217pub use stage_order::StageOrder;
218pub use stage_parameters::StageParameters;
219pub use user_id::UserId;
220pub use worker_count::WorkerCount;