Problem
Complex conversions between internal models and Pydantic models (e.g., AutoSaveConfig) are currently handled through ad-hoc conversion methods scattered across the codebase. This creates maintainability issues and potential inconsistencies.
Proposed Solution
Implement a factory pattern to standardize and simplify conversions between:
- Internal data models and Pydantic models
- TypedDict structures and Pydantic models
- Configuration objects and their various representations
Benefits
- Consistency: Centralized conversion logic reduces code duplication
- Maintainability: Single location for conversion rules makes updates easier
- Type Safety: Factory pattern can ensure proper type validation during conversions
- Extensibility: Easy to add new model types and conversion rules
Implementation Ideas
-
Create a ModelFactory class with methods like:
from_dict() - Convert dict/TypedDict to Pydantic model
to_dict() - Convert Pydantic model to dict
convert() - Convert between different model types
-
Use generic typing to maintain type safety
-
Consider using protocols/interfaces for consistent conversion behavior
Examples of Current Complex Conversions
- AutoSaveConfig conversions in session management
- FilterCondition/FilterConditionDict handling in transformation server
- Result model conversions across server boundaries
Acceptance Criteria
Originally identified in PR review for type safety improvements and test coverage enhancements.
Problem
Complex conversions between internal models and Pydantic models (e.g., AutoSaveConfig) are currently handled through ad-hoc conversion methods scattered across the codebase. This creates maintainability issues and potential inconsistencies.
Proposed Solution
Implement a factory pattern to standardize and simplify conversions between:
Benefits
Implementation Ideas
Create a
ModelFactoryclass with methods like:from_dict()- Convert dict/TypedDict to Pydantic modelto_dict()- Convert Pydantic model to dictconvert()- Convert between different model typesUse generic typing to maintain type safety
Consider using protocols/interfaces for consistent conversion behavior
Examples of Current Complex Conversions
Acceptance Criteria
Originally identified in PR review for type safety improvements and test coverage enhancements.