diff --git a/lago_python_client/mixins.py b/lago_python_client/mixins.py index 8b6163d..72301fa 100644 --- a/lago_python_client/mixins.py +++ b/lago_python_client/mixins.py @@ -1,4 +1,4 @@ -from typing import Any, Generic, Optional, Type, TypeVar, Union +from typing import Any, Callable, ClassVar, Generic, Optional, Tuple, Type, TypeVar, Union import httpx @@ -36,14 +36,10 @@ class _ClientMixin(Protocol[_PM_co]): - @property - def PARENT_API_RESOURCE(self) -> str: ... - @property - def API_RESOURCE(self) -> str: ... - @property - def RESPONSE_MODEL(self) -> Type[_PM_co]: ... - @property - def ROOT_NAME(self) -> str: ... + API_RESOURCE: ClassVar[str] + RESPONSE_MODEL: ClassVar[Type[_PM_co]] # type: ignore[misc] + ROOT_NAME: ClassVar[str] + @property def api_key(self) -> str: ... @property @@ -52,6 +48,15 @@ def base_url(self) -> str: ... def rate_limit_retry_config(self) -> RateLimitRetryConfig: ... +class _ChildClientMixin(_ClientMixin[_PM_co], Protocol[_PM_co]): + PARENT_API_RESOURCE: ClassVar[str] + + +class _NestedClientMixin(_ClientMixin[_PM_co], Protocol[_PM_co]): + @property + def api_resource(self) -> Callable[..., Tuple[str, ...]]: ... + + class CreateCommandMixin(Generic[_M]): """Client mixin with `create` command.""" @@ -154,7 +159,7 @@ class FindAllChildrenCommandMixin(Generic[_M]): """Client mixin with `find_all` command scoped to a parent resource.""" def find_all( - self: _ClientMixin[_M], + self: _ChildClientMixin[_M], resource_id: str, options: QueryPairs = None, timetour: Optional[httpx.Timeout] = None, @@ -187,7 +192,7 @@ class FindChildCommandMixin(Generic[_M]): """Client mixin with `find` command scoped to a parent resource.""" def find( - self: _ClientMixin[_M], + self: _ChildClientMixin[_M], parent_id: str, child_id: str, options: QueryPairs = None, @@ -220,7 +225,7 @@ class CreateChildCommandMixin(Generic[_M]): """Client mixin with `create` command scoped to a parent resource.""" def create( - self: _ClientMixin[_M], + self: _ChildClientMixin[_M], parent_id: str, input_object: BaseModel, options: QueryPairs = None, @@ -253,7 +258,7 @@ class UpdateChildCommandMixin(Generic[_M]): """Client mixin with `update` command scoped to a parent resource.""" def update( - self: _ClientMixin[_M], + self: _ChildClientMixin[_M], parent_id: str, child_id: str, input_object: BaseModel, @@ -288,7 +293,7 @@ class DestroyChildCommandMixin(Generic[_M]): """Client mixin with `destroy` command scoped to a parent resource.""" def destroy( - self: _ClientMixin[_M], + self: _ChildClientMixin[_M], parent_id: str, child_id: str, options: QueryPairs = None, @@ -385,7 +390,7 @@ class NestedCreateCommandMixin(Generic[_M]): """Client mixin with `create` command.""" def create( - self: _ClientMixin[_M], + self: _NestedClientMixin[_M], *args: Union[str, BaseModel], timeout: Optional[httpx.Timeout] = None, ) -> Optional[_M]: @@ -420,7 +425,7 @@ class NestedUpdateCommandMixin(Generic[_M]): """Client mixin with `update` command.""" def update( - self: _ClientMixin[_M], + self: _NestedClientMixin[_M], *args: Union[str, BaseModel], timeout: Optional[httpx.Timeout] = None, ) -> _M: @@ -454,7 +459,7 @@ class NestedDestroyCommandMixin(Generic[_M]): """Client mixin with `destroy` command.""" def destroy( - self: _ClientMixin[_M], + self: _NestedClientMixin[_M], *args: str, timeout: Optional[httpx.Timeout] = None, ) -> BaseModel: @@ -483,7 +488,7 @@ class NestedFindCommandMixin(Generic[_M]): """Client mixin with `find` command.""" def find( - self: _ClientMixin[_M], + self: _NestedClientMixin[_M], *args: str, timeout: Optional[httpx.Timeout] = None, ) -> _M: @@ -512,7 +517,7 @@ class NestedFindAllCommandMixin(Generic[_M]): """Client mixin with `find_all` command.""" def find_all( - self: _ClientMixin[_M], + self: _NestedClientMixin[_M], *parent_ids: str, options: QueryPairs = None, timeout: Optional[httpx.Timeout] = None,