womm-cli 4.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. womm/__init__.py +53 -0
  2. womm/__main__.py +48 -0
  3. womm/_version.py +10 -0
  4. womm/assets/copier/meta/copier.yml +15 -0
  5. womm/assets/copier/meta/template/README.md.jinja +32 -0
  6. womm/assets/copier/meta/template/copier.yml.jinja +13 -0
  7. womm/assets/copier/meta/template/template/.gitkeep +0 -0
  8. womm/assets/copier/official/javascript/copier.yml +104 -0
  9. womm/assets/copier/official/javascript/template/.gitignore.jinja +35 -0
  10. womm/assets/copier/official/javascript/template/.nvmrc.jinja +1 -0
  11. womm/assets/copier/official/javascript/template/.prettierignore.jinja +10 -0
  12. womm/assets/copier/official/javascript/template/README.md.jinja +81 -0
  13. womm/assets/copier/official/javascript/template/biome.json.jinja +54 -0
  14. womm/assets/copier/official/javascript/template/eslint.config.mjs.jinja +51 -0
  15. womm/assets/copier/official/javascript/template/index.html.jinja +12 -0
  16. womm/assets/copier/official/javascript/template/package.json.jinja +88 -0
  17. womm/assets/copier/official/javascript/template/prettier.config.mjs.jinja +8 -0
  18. womm/assets/copier/official/javascript/template/src/App.jsx.jinja +10 -0
  19. womm/assets/copier/official/javascript/template/src/App.tsx.jinja +10 -0
  20. womm/assets/copier/official/javascript/template/src/App.vue.jinja +18 -0
  21. womm/assets/copier/official/javascript/template/src/index.jsx.jinja +10 -0
  22. womm/assets/copier/official/javascript/template/src/index.tsx.jinja +11 -0
  23. womm/assets/copier/official/javascript/template/src/main.js.jinja +21 -0
  24. womm/assets/copier/official/javascript/template/src/main.ts.jinja +21 -0
  25. womm/assets/copier/official/javascript/template/tsconfig.json.jinja +35 -0
  26. womm/assets/copier/official/javascript/template/vite.config.mjs.jinja +10 -0
  27. womm/assets/copier/official/javascript/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +63 -0
  28. womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.js.jinja +12 -0
  29. womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.ts.jinja +12 -0
  30. womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +4 -0
  31. womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +27 -0
  32. womm/assets/copier/official/python/copier.yml +107 -0
  33. womm/assets/copier/official/python/template/.gitignore.jinja +40 -0
  34. womm/assets/copier/official/python/template/.pre-commit-config.yaml.jinja +19 -0
  35. womm/assets/copier/official/python/template/.python-version.jinja +1 -0
  36. womm/assets/copier/official/python/template/README.md.jinja +83 -0
  37. womm/assets/copier/official/python/template/pyproject.toml.jinja +114 -0
  38. womm/assets/copier/official/python/template/{% if framework == 'django' %}manage.py{% endif %}.jinja +23 -0
  39. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/__init__.py.jinja +3 -0
  40. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/asgi.py.jinja +9 -0
  41. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/__init__.py.jinja +0 -0
  42. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/apps.py.jinja +10 -0
  43. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/models.py.jinja +1 -0
  44. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/views.py.jinja +8 -0
  45. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/py.typed +0 -0
  46. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/settings.py.jinja +81 -0
  47. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/urls.py.jinja +11 -0
  48. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/wsgi.py.jinja +9 -0
  49. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/__init__.py.jinja +3 -0
  50. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/asgi.py.jinja +9 -0
  51. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/__init__.py.jinja +0 -0
  52. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/apps.py.jinja +10 -0
  53. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/models.py.jinja +1 -0
  54. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/views.py.jinja +8 -0
  55. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/py.typed +0 -0
  56. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/settings.py.jinja +81 -0
  57. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/urls.py.jinja +11 -0
  58. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/wsgi.py.jinja +9 -0
  59. womm/assets/copier/official/python/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +78 -0
  60. womm/assets/copier/official/python/template/{% if with_tests %}tests{% endif %}/test_smoke.py.jinja +16 -0
  61. womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +8 -0
  62. womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +28 -0
  63. womm/bin/refresh_env.cmd +130 -0
  64. womm/cli.py +111 -0
  65. womm/commands/__init__.py +30 -0
  66. womm/commands/core/__init__.py +29 -0
  67. womm/commands/core/doctor.py +52 -0
  68. womm/commands/core/path.py +337 -0
  69. womm/commands/project/__init__.py +31 -0
  70. womm/commands/project/create.py +128 -0
  71. womm/commands/project/setup.py +438 -0
  72. womm/commands/project/template.py +160 -0
  73. womm/commands/system/__init__.py +31 -0
  74. womm/commands/system/context/__init__.py +82 -0
  75. womm/commands/system/context/backup.py +344 -0
  76. womm/commands/system/context/inventory.py +111 -0
  77. womm/commands/system/context/registration.py +290 -0
  78. womm/commands/system/deps.py +165 -0
  79. womm/commands/system/system.py +130 -0
  80. womm/exceptions/__init__.py +69 -0
  81. womm/exceptions/common/__init__.py +55 -0
  82. womm/exceptions/common/command_service.py +91 -0
  83. womm/exceptions/common/file_service.py +60 -0
  84. womm/exceptions/common/security_service.py +44 -0
  85. womm/exceptions/common/validation_service.py +70 -0
  86. womm/exceptions/context/__init__.py +27 -0
  87. womm/exceptions/context/context_service.py +55 -0
  88. womm/exceptions/project/__init__.py +29 -0
  89. womm/exceptions/project/project_service.py +59 -0
  90. womm/exceptions/system/__init__.py +25 -0
  91. womm/exceptions/system/system_service.py +53 -0
  92. womm/interfaces/__init__.py +71 -0
  93. womm/interfaces/context/__init__.py +34 -0
  94. womm/interfaces/context/menu_interface.py +686 -0
  95. womm/interfaces/context/registry_interface.py +562 -0
  96. womm/interfaces/context/script_detector_interface.py +208 -0
  97. womm/interfaces/context/script_registrar.py +264 -0
  98. womm/interfaces/core/__init__.py +26 -0
  99. womm/interfaces/core/doctor_interface.py +102 -0
  100. womm/interfaces/dependencies/__init__.py +28 -0
  101. womm/interfaces/dependencies/deps_interface.py +160 -0
  102. womm/interfaces/project/__init__.py +36 -0
  103. womm/interfaces/project/create_interface.py +162 -0
  104. womm/interfaces/project/detection_interface.py +181 -0
  105. womm/interfaces/project/manager_interface.py +99 -0
  106. womm/interfaces/project/setup_interface.py +477 -0
  107. womm/interfaces/project/template_store_interface.py +196 -0
  108. womm/interfaces/system/__init__.py +32 -0
  109. womm/interfaces/system/detector_interface.py +84 -0
  110. womm/interfaces/system/environment_interface.py +110 -0
  111. womm/interfaces/system/path_interface.py +570 -0
  112. womm/services/__init__.py +70 -0
  113. womm/services/common/__init__.py +33 -0
  114. womm/services/common/base_validation_service.py +450 -0
  115. womm/services/common/command_runner_service.py +647 -0
  116. womm/services/common/file_scanner_service.py +483 -0
  117. womm/services/common/security_validator_service.py +348 -0
  118. womm/services/context/__init__.py +37 -0
  119. womm/services/context/backup_entries.py +148 -0
  120. womm/services/context/parameters.py +515 -0
  121. womm/services/context/registry_paths.py +56 -0
  122. womm/services/context/registry_service.py +573 -0
  123. womm/services/context/validation_service.py +691 -0
  124. womm/services/dependencies/__init__.py +29 -0
  125. womm/services/dependencies/probe.py +102 -0
  126. womm/services/project/__init__.py +48 -0
  127. womm/services/project/copier_project_creation_service.py +111 -0
  128. womm/services/project/destination_guard.py +96 -0
  129. womm/services/project/detection_service.py +354 -0
  130. womm/services/project/env_utils.py +333 -0
  131. womm/services/project/javascript_environment_service.py +348 -0
  132. womm/services/project/python_environment_service.py +245 -0
  133. womm/services/project/setup_profile_resolver.py +146 -0
  134. womm/services/project/template_store_service.py +344 -0
  135. womm/services/project/validation_service.py +418 -0
  136. womm/services/system/__init__.py +32 -0
  137. womm/services/system/detector_service.py +704 -0
  138. womm/services/system/environment_service.py +494 -0
  139. womm/services/system/path_service.py +642 -0
  140. womm/shared/__init__.py +30 -0
  141. womm/shared/configs/__init__.py +51 -0
  142. womm/shared/configs/context/__init__.py +43 -0
  143. womm/shared/configs/context/context_config.py +125 -0
  144. womm/shared/configs/context/context_file_types_config.py +159 -0
  145. womm/shared/configs/context/context_limits_config.py +187 -0
  146. womm/shared/configs/context/context_paths_config.py +115 -0
  147. womm/shared/configs/context/context_types_config.py +65 -0
  148. womm/shared/configs/context/script_config.py +219 -0
  149. womm/shared/configs/dependencies/__init__.py +32 -0
  150. womm/shared/configs/dependencies/runtime_config.py +46 -0
  151. womm/shared/configs/dependencies/runtime_package_manager_config.py +48 -0
  152. womm/shared/configs/logging_config.py +89 -0
  153. womm/shared/configs/project/__init__.py +33 -0
  154. womm/shared/configs/project/project_config.py +109 -0
  155. womm/shared/configs/project/project_structure_config.py +88 -0
  156. womm/shared/configs/project/python_project_config.py +165 -0
  157. womm/shared/configs/security/__init__.py +26 -0
  158. womm/shared/configs/security/security_patterns_config.py +242 -0
  159. womm/shared/configs/system/__init__.py +28 -0
  160. womm/shared/configs/system/system_detector_config.py +210 -0
  161. womm/shared/configs/system/system_environment_config.py +101 -0
  162. womm/shared/models/__init__.py +13 -0
  163. womm/shared/models/template_source.py +65 -0
  164. womm/shared/paths.py +192 -0
  165. womm/shared/results/__init__.py +138 -0
  166. womm/shared/results/base.py +85 -0
  167. womm/shared/results/command_results.py +61 -0
  168. womm/shared/results/context_results.py +345 -0
  169. womm/shared/results/dependency_results.py +110 -0
  170. womm/shared/results/doctor_results.py +41 -0
  171. womm/shared/results/file_results.py +97 -0
  172. womm/shared/results/project_results.py +163 -0
  173. womm/shared/results/security_results.py +128 -0
  174. womm/shared/results/system_results.py +268 -0
  175. womm/shared/results/template_results.py +43 -0
  176. womm/shared/runtime.py +36 -0
  177. womm/ui/__init__.py +31 -0
  178. womm/ui/common/__init__.py +39 -0
  179. womm/ui/common/interactive_menu.py +246 -0
  180. womm/ui/common/logging.py +184 -0
  181. womm/ui/common/prompts.py +93 -0
  182. womm/ui/context/__init__.py +31 -0
  183. womm/ui/context/display.py +485 -0
  184. womm/ui/context/menu_display.py +189 -0
  185. womm/ui/context/wizard.py +557 -0
  186. womm/ui/project/__init__.py +42 -0
  187. womm/ui/project/create/create_completion_summaries.py +55 -0
  188. womm/ui/project/project_wizard.py +174 -0
  189. womm/ui/project/setup/setup_completion_summaries.py +111 -0
  190. womm/ui/project/templates/template_store_display.py +128 -0
  191. womm/ui/system/__init__.py +60 -0
  192. womm/ui/system/display.py +531 -0
  193. womm/ui/system/path_display.py +387 -0
  194. womm/utils/__init__.py +23 -0
  195. womm/utils/common/__init__.py +49 -0
  196. womm/utils/common/file_scanner_utils.py +110 -0
  197. womm/utils/common/path_resolver_utils.py +127 -0
  198. womm/utils/common/safe_fs_utils.py +135 -0
  199. womm/utils/context/__init__.py +54 -0
  200. womm/utils/context/core_utils.py +345 -0
  201. womm/utils/context/icon_utils.py +259 -0
  202. womm/utils/project/__init__.py +106 -0
  203. womm/utils/project/asset_utils.py +154 -0
  204. womm/utils/project/core_utils.py +391 -0
  205. womm/utils/project/file_utils.py +494 -0
  206. womm/utils/project/platform_utils.py +170 -0
  207. womm/utils/project/validation_utils.py +273 -0
  208. womm/utils/security/__init__.py +46 -0
  209. womm/utils/security/security_validation_utils.py +258 -0
  210. womm/utils/system/__init__.py +69 -0
  211. womm/utils/system/detector_utils.py +299 -0
  212. womm/utils/system/environment_utils.py +172 -0
  213. womm/utils/system/path_utils.py +101 -0
  214. womm_cli-4.0.0.dist-info/METADATA +203 -0
  215. womm_cli-4.0.0.dist-info/RECORD +218 -0
  216. womm_cli-4.0.0.dist-info/WHEEL +4 -0
  217. womm_cli-4.0.0.dist-info/entry_points.txt +2 -0
  218. womm_cli-4.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,450 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # BASE VALIDATION SERVICE - Generic Validation Logic
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ Base validation service providing common validation patterns.
9
+
10
+ This module provides a centralized, generic validation service that handles
11
+ common validation logic used across the application (path validation, config
12
+ validation, structure validation, etc.).
13
+
14
+ All specialized validation services should extend this base class to reuse
15
+ common functionality and maintain consistent validation behavior.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ # ///////////////////////////////////////////////////////////////
21
+ # IMPORTS
22
+ # ///////////////////////////////////////////////////////////////
23
+ # Standard library imports
24
+ import logging
25
+ import re
26
+ from pathlib import Path
27
+ from typing import Any
28
+
29
+ # Local imports
30
+ from ...shared.results import ValidationResult
31
+
32
+ # ///////////////////////////////////////////////////////////////
33
+ # LOGGER SETUP
34
+ # ///////////////////////////////////////////////////////////////
35
+
36
+ logger = logging.getLogger(__name__)
37
+
38
+ # ///////////////////////////////////////////////////////////////
39
+ # MAIN CLASS
40
+ # ///////////////////////////////////////////////////////////////
41
+
42
+
43
+ class BaseValidationService:
44
+ """
45
+ Base validation service providing common validation patterns.
46
+
47
+ This class provides reusable validation methods that can be used by
48
+ specialized validation services. It handles common patterns like:
49
+ - Path validation (existence, permissions, etc.)
50
+ - Structure validation (keys, types, required fields)
51
+ - Configuration validation (valid values, constraints)
52
+ - String validation (non-empty, patterns, etc.)
53
+
54
+ All methods return ValidationResult for consistent error handling.
55
+
56
+ Note: This is a utility class with only static methods and should not be instantiated.
57
+ """
58
+
59
+ # ///////////////////////////////////////////////////////////////
60
+ # PATH VALIDATION METHODS
61
+ # ///////////////////////////////////////////////////////////////
62
+
63
+ @staticmethod
64
+ def validate_path_exists(
65
+ path: str | Path, path_type: str = "file"
66
+ ) -> ValidationResult:
67
+ """
68
+ Validate that a path exists.
69
+
70
+ Args:
71
+ path: Path to validate
72
+ path_type: Type of path ("file", "directory", or "any")
73
+
74
+ Returns:
75
+ ValidationResult with success/failure status
76
+
77
+ Note:
78
+ - path_type="file" checks if file exists
79
+ - path_type="directory" checks if directory exists
80
+ - path_type="any" checks if either exists
81
+ """
82
+ try:
83
+ path_obj = Path(path)
84
+
85
+ if not path_obj.exists():
86
+ return ValidationResult(
87
+ success=False,
88
+ error=f"{path_type.capitalize()} does not exist: {path}",
89
+ )
90
+
91
+ if path_type == "file" and not path_obj.is_file():
92
+ return ValidationResult(
93
+ success=False,
94
+ error=f"Path is not a file: {path}",
95
+ )
96
+
97
+ if path_type == "directory" and not path_obj.is_dir():
98
+ return ValidationResult(
99
+ success=False,
100
+ error=f"Path is not a directory: {path}",
101
+ )
102
+
103
+ return ValidationResult(success=True)
104
+
105
+ except (OSError, TypeError, ValueError) as e:
106
+ logger.error(f"Error validating path existence: {e}")
107
+ return ValidationResult(
108
+ success=False,
109
+ error=f"Error validating path: {e!s}",
110
+ )
111
+
112
+ @staticmethod
113
+ def validate_path_readable(path: str | Path) -> ValidationResult:
114
+ """
115
+ Validate that a path is readable.
116
+
117
+ Args:
118
+ path: Path to validate
119
+
120
+ Returns:
121
+ ValidationResult with success/failure status
122
+ """
123
+ try:
124
+ path_obj = Path(path)
125
+
126
+ if not path_obj.exists():
127
+ return ValidationResult(
128
+ success=False,
129
+ error=f"Path does not exist: {path}",
130
+ )
131
+
132
+ if not path_obj.is_file():
133
+ return ValidationResult(
134
+ success=False,
135
+ error=f"Path is not a file: {path}",
136
+ )
137
+
138
+ if not path_obj.stat().st_mode & 0o400:
139
+ return ValidationResult(
140
+ success=False,
141
+ error=f"Path is not readable: {path}",
142
+ )
143
+
144
+ return ValidationResult(success=True)
145
+
146
+ except (OSError, TypeError, ValueError) as e:
147
+ logger.error(f"Error validating path readability: {e}")
148
+ return ValidationResult(
149
+ success=False,
150
+ error=f"Error validating path: {e!s}",
151
+ )
152
+
153
+ @staticmethod
154
+ def validate_path_writable(path: str | Path) -> ValidationResult:
155
+ """
156
+ Validate that a path is writable.
157
+
158
+ Args:
159
+ path: Path to validate
160
+
161
+ Returns:
162
+ ValidationResult with success/failure status
163
+ """
164
+ try:
165
+ path_obj = Path(path)
166
+ # An existing directory is checked directly; anything else (existing
167
+ # file or path yet to be created) is checked through its container.
168
+ container = path_obj if path_obj.is_dir() else path_obj.parent
169
+
170
+ if not container.exists():
171
+ return ValidationResult(
172
+ success=False,
173
+ error=f"Parent directory does not exist: {container}",
174
+ )
175
+
176
+ if not container.stat().st_mode & 0o200:
177
+ return ValidationResult(
178
+ success=False,
179
+ error=f"Parent directory is not writable: {container}",
180
+ )
181
+
182
+ return ValidationResult(success=True)
183
+
184
+ except (OSError, TypeError, ValueError) as e:
185
+ logger.error(f"Error validating path writeability: {e}")
186
+ return ValidationResult(
187
+ success=False,
188
+ error=f"Error validating path: {e!s}",
189
+ )
190
+
191
+ # ///////////////////////////////////////////////////////////////
192
+ # STRING VALIDATION METHODS
193
+ # ///////////////////////////////////////////////////////////////
194
+
195
+ @staticmethod
196
+ def validate_non_empty_string(
197
+ value: str, field_name: str = "value"
198
+ ) -> ValidationResult:
199
+ """
200
+ Validate that a string is not empty.
201
+
202
+ Args:
203
+ value: String to validate
204
+ field_name: Name of field for error messages
205
+
206
+ Returns:
207
+ ValidationResult with success/failure status
208
+ """
209
+ if not isinstance(value, str):
210
+ return ValidationResult(
211
+ success=False,
212
+ error=f"{field_name} must be a string, got {type(value).__name__}",
213
+ )
214
+
215
+ if not value or not value.strip():
216
+ return ValidationResult(
217
+ success=False,
218
+ error=f"{field_name} cannot be empty",
219
+ )
220
+
221
+ return ValidationResult(success=True)
222
+
223
+ @staticmethod
224
+ def validate_string_pattern(
225
+ value: str, pattern: str, field_name: str = "value"
226
+ ) -> ValidationResult:
227
+ """
228
+ Validate that a string matches a pattern.
229
+
230
+ Args:
231
+ value: String to validate
232
+ pattern: Regex pattern to match
233
+ field_name: Name of field for error messages
234
+
235
+ Returns:
236
+ ValidationResult with success/failure status
237
+ """
238
+ try:
239
+ if not re.match(pattern, value):
240
+ return ValidationResult(
241
+ success=False,
242
+ error=f"{field_name} does not match required pattern",
243
+ )
244
+
245
+ return ValidationResult(success=True)
246
+
247
+ except (re.error, TypeError) as e:
248
+ logger.error(f"Error validating string pattern: {e}")
249
+ return ValidationResult(
250
+ success=False,
251
+ error=f"Error validating {field_name}: {e!s}",
252
+ )
253
+
254
+ # ///////////////////////////////////////////////////////////////
255
+ # STRUCTURE VALIDATION METHODS
256
+ # ///////////////////////////////////////////////////////////////
257
+
258
+ @staticmethod
259
+ def validate_dict_structure(
260
+ data: dict, required_keys: list[str], field_name: str = "data"
261
+ ) -> ValidationResult:
262
+ """
263
+ Validate that a dictionary has required keys.
264
+
265
+ Args:
266
+ data: Dictionary to validate
267
+ required_keys: List of required keys
268
+ field_name: Name of field for error messages
269
+
270
+ Returns:
271
+ ValidationResult with success/failure status
272
+ """
273
+ if not isinstance(data, dict):
274
+ return ValidationResult(
275
+ success=False,
276
+ error=f"{field_name} must be a dictionary",
277
+ )
278
+
279
+ missing_keys = [key for key in required_keys if key not in data]
280
+
281
+ if missing_keys:
282
+ return ValidationResult(
283
+ success=False,
284
+ error=f"Missing required keys in {field_name}: {', '.join(missing_keys)}",
285
+ )
286
+
287
+ return ValidationResult(success=True)
288
+
289
+ @staticmethod
290
+ def validate_dict_value_types(
291
+ data: dict, type_schema: dict[str, type], field_name: str = "data"
292
+ ) -> ValidationResult:
293
+ """
294
+ Validate that dictionary values have correct types.
295
+
296
+ Args:
297
+ data: Dictionary to validate
298
+ type_schema: Dict mapping keys to expected types
299
+ field_name: Name of field for error messages
300
+
301
+ Returns:
302
+ ValidationResult with success/failure status
303
+
304
+ Example:
305
+ schema = {"name": str, "age": int, "active": bool}
306
+ result = validate_dict_value_types(data, schema)
307
+ """
308
+ if not isinstance(data, dict):
309
+ return ValidationResult(
310
+ success=False,
311
+ error=f"{field_name} must be a dictionary",
312
+ )
313
+
314
+ for key, expected_type in type_schema.items():
315
+ if key in data:
316
+ value = data[key]
317
+ if not isinstance(value, expected_type):
318
+ actual_type = type(value).__name__
319
+ expected_name = expected_type.__name__
320
+ return ValidationResult(
321
+ success=False,
322
+ error=(
323
+ f"Field '{key}' in {field_name} has type {actual_type}, expected {expected_name}"
324
+ ),
325
+ )
326
+
327
+ return ValidationResult(success=True)
328
+
329
+ # ///////////////////////////////////////////////////////////////
330
+ # RANGE VALIDATION METHODS
331
+ # ///////////////////////////////////////////////////////////////
332
+
333
+ @staticmethod
334
+ def validate_value_in_range(
335
+ value: int | float,
336
+ min_val: int | float | None,
337
+ max_val: int | float | None,
338
+ field_name: str = "value",
339
+ ) -> ValidationResult:
340
+ """
341
+ Validate that a numeric value is within a range.
342
+
343
+ Args:
344
+ value: Value to validate
345
+ min_val: Minimum allowed value (None for no minimum)
346
+ max_val: Maximum allowed value (None for no maximum)
347
+ field_name: Name of field for error messages
348
+
349
+ Returns:
350
+ ValidationResult with success/failure status
351
+ """
352
+ if min_val is not None and value < min_val:
353
+ return ValidationResult(
354
+ success=False,
355
+ error=f"{field_name} must be >= {min_val}, got {value}",
356
+ )
357
+
358
+ if max_val is not None and value > max_val:
359
+ return ValidationResult(
360
+ success=False,
361
+ error=f"{field_name} must be <= {max_val}, got {value}",
362
+ )
363
+
364
+ return ValidationResult(success=True)
365
+
366
+ @staticmethod
367
+ def validate_value_in_list(
368
+ value: Any, allowed_values: list[Any], field_name: str = "value"
369
+ ) -> ValidationResult:
370
+ """
371
+ Validate that a value is in allowed list.
372
+
373
+ Args:
374
+ value: Value to validate
375
+ allowed_values: List of allowed values
376
+ field_name: Name of field for error messages
377
+
378
+ Returns:
379
+ ValidationResult with success/failure status
380
+ """
381
+ if value not in allowed_values:
382
+ return ValidationResult(
383
+ success=False,
384
+ error=f"{field_name} must be one of {allowed_values}, got {value}",
385
+ )
386
+
387
+ return ValidationResult(success=True)
388
+
389
+ # ///////////////////////////////////////////////////////////////
390
+ # COMBINATION VALIDATION METHODS
391
+ # ///////////////////////////////////////////////////////////////
392
+
393
+ @staticmethod
394
+ def validate_all(
395
+ validations: list[ValidationResult],
396
+ ) -> ValidationResult:
397
+ """
398
+ Combine multiple validation results.
399
+
400
+ Args:
401
+ validations: List of ValidationResult objects
402
+
403
+ Returns:
404
+ ValidationResult with combined status and all error messages
405
+
406
+ Note:
407
+ Returns success only if ALL validations passed.
408
+ Error messages are combined with newlines.
409
+ """
410
+ failed_validations = [v for v in validations if not v.success]
411
+
412
+ if not failed_validations:
413
+ return ValidationResult(success=True)
414
+
415
+ error_messages = [v.error for v in failed_validations if v.error]
416
+ combined_message = "\n".join(error_messages)
417
+
418
+ return ValidationResult(
419
+ success=False,
420
+ error=combined_message,
421
+ )
422
+
423
+ @staticmethod
424
+ def validate_any(
425
+ validations: list[ValidationResult],
426
+ ) -> ValidationResult:
427
+ """
428
+ Require at least one validation to pass.
429
+
430
+ Args:
431
+ validations: List of ValidationResult objects
432
+
433
+ Returns:
434
+ ValidationResult with combined status
435
+
436
+ Note:
437
+ Returns success if ANY validation passed.
438
+ """
439
+ passed_validations = [v for v in validations if v.success]
440
+
441
+ if passed_validations:
442
+ return ValidationResult(success=True)
443
+
444
+ error_messages = [v.error for v in validations if v.error]
445
+ combined_message = " OR ".join(error_messages)
446
+
447
+ return ValidationResult(
448
+ success=False,
449
+ error=combined_message,
450
+ )