Add NeonClient2 package and update NeonClient import

This commit is contained in:
2024-01-17 15:51:42 -05:00
parent c13ea6b435
commit c2e42d62d6
14 changed files with 1584 additions and 204 deletions
+36
View File
@@ -0,0 +1,36 @@
import inspect
from typing import List, Dict, Any, Union, Optional
from pydantic import BaseModel
def squash(obj):
new_obj = {}
for k, v in obj.items():
if isinstance(v, dict):
new_obj.update(squash(v))
else:
if v:
new_obj[k] = v
def validate_obj_model(parameter_name: str, model: BaseModel):
"""A decorator that validates the 'obj' argument against the specified model."""
def decorator(func):
def wrapper(*args, **kwargs):
# Get the 'obj' argument.
obj = kwargs.get(parameter_name)
# If the 'obj' argument is not provided, raise an exception.
if obj is None:
raise ValueError(f"Missing required argument '{parameter_name}'.")
# Validate the 'obj' argument against the specified model.
model.model_validate(obj)
# Call the wrapped function.
return func(*args, **kwargs)
return wrapper
return decorator