1- """Shared enums and validation helpers used across the application."""
1+ """Shared enums and validation helpers used across the application.
2+
3+ NOTE: This file is maintained in `repo-utils-shared/src/app/utils/types.py`
4+ and should be synchronized across repositories using the sync script.
5+ Do not modify it directly in individual repositories.
6+ """
27
38from enum import Enum
4- from typing import Any
9+ from typing import Any , TypedDict
510
611
712class OutputMode (str , Enum ):
@@ -16,51 +21,73 @@ class OutputMode(str, Enum):
1621
1722
1823class PollerType (str , Enum ):
19- """Defines the domain of the poller for routing/ behavior."""
24+ """Defines the domain of the poller for routing and behavior."""
2025
2126 STOCK = "stock"
2227 SENTIMENT = "sentiment"
2328 ALT = "alt"
29+ CRYPTO = "crypto"
30+ FUND = "fund"
31+ ANALYSIS = "analysis"
32+ BACKTEST = "backtest"
33+ UI = "ui"
34+
35+
36+ class ValidatedMessage (TypedDict ):
37+ """Validated and enriched message with required structure."""
38+
39+ symbol : str
40+ timestamp : str
41+ data : dict [str , Any ]
2442
2543
2644def validate_dict (data : dict [str , Any ], required_keys : list [str ]) -> bool :
2745 """Check that all required keys are present in the dictionary.
2846
29- Parameters
30- ----------
31- data : dict[str, Any]
32- The dictionary to validate.
33-
34- required_keys : list[str]
35- Keys that must exist in the dictionary.
47+ Args:
48+ data: The dictionary to validate.
49+ required_keys: Keys that must exist in the dictionary.
3650
37- Returns
38- -------
39- bool
51+ Returns:
4052 True if all required keys are present, False otherwise.
41-
4253 """
4354 return all (k in data for k in required_keys )
4455
4556
4657def validate_list_of_dicts (data : Any , required_keys : list [str ]) -> bool :
47- """Validate that the input is a list of dicts, each containing the required
48- keys.
49-
50- Parameters
51- ----------
52- data : Any
53- The object to validate.
58+ """Validate that the input is a list of dicts, each with required keys.
5459
55- required_keys : list[str]
56- Keys that must exist in each dictionary.
60+ Args:
61+ data: The object to validate.
62+ required_keys: Keys that must exist in each dictionary.
5763
58- Returns
59- -------
60- bool
64+ Returns:
6165 True if input is a list of valid dicts, False otherwise.
62-
6366 """
6467 if not isinstance (data , list ):
6568 return False
6669 return all (isinstance (item , dict ) and validate_dict (item , required_keys ) for item in data )
70+
71+
72+ def is_valid_payload (data : Any ) -> bool :
73+ """Perform basic schema validation for a generic payload.
74+
75+ Args:
76+ data: The input data to validate.
77+
78+ Returns:
79+ True if the input is a dict with minimum expected structure.
80+ """
81+ return isinstance (data , dict ) and "symbol" in data and "timestamp" in data
82+
83+
84+ def is_valid_batch (data : Any ) -> bool :
85+ """Validate a batch of payloads.
86+
87+ Args:
88+ data: The input to validate.
89+
90+ Returns:
91+ True if input is a list of valid payload dictionaries.
92+ """
93+ return validate_list_of_dicts (data , ["symbol" , "timestamp" ])
0 commit comments