Coverage for src / lexigram / contracts / auth / store.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
1"""User store protocols.
3Segregated interfaces for user data access following ISP.
4"""
6from __future__ import annotations
8from typing import TYPE_CHECKING, Protocol, runtime_checkable
10if TYPE_CHECKING:
11 from lexigram.contracts.auth.user import UserProtocol
14@runtime_checkable
15class UserReaderProtocol(Protocol):
16 """Protocol for reading user data.
18 Use for query-only operations (CQRS query side).
19 """
21 async def get_by_id(self, user_id: str) -> UserProtocol | None:
22 """Get user by ID.
24 Args:
25 user_id: User identifier.
27 Returns:
28 User if found, None otherwise.
29 """
30 ...
32 async def get_by_email(self, email: str) -> UserProtocol | None:
33 """Get user by email.
35 Args:
36 email: User email address.
38 Returns:
39 User if found, None otherwise.
40 """
41 ...
43 async def get_by_username(self, username: str) -> UserProtocol | None:
44 """Get user by username.
46 Args:
47 username: Username to look up.
49 Returns:
50 User if found, None otherwise.
51 """
52 ...
54 async def list_users(
55 self,
56 skip: int = 0,
57 limit: int = 100,
58 ) -> list[UserProtocol]:
59 """List users with pagination.
61 Args:
62 skip: Number of records to skip.
63 limit: Maximum records to return.
65 Returns:
66 List of users.
67 """
68 ...
70 async def count_users(self) -> int:
71 """Count total users.
73 Returns:
74 Total user count.
75 """
76 ...
79@runtime_checkable
80class UserWriterProtocol(Protocol):
81 """Protocol for writing user data.
83 Use for command-only operations (CQRS command side).
84 """
86 async def create(self, user: UserProtocol) -> UserProtocol:
87 """Create a new user.
89 Args:
90 user: User to create.
92 Returns:
93 Created user.
94 """
95 ...
97 async def update(self, user: UserProtocol) -> UserProtocol:
98 """Update an existing user.
100 Args:
101 user: User to update.
103 Returns:
104 Updated user.
105 """
106 ...
108 async def delete(self, user_id: str) -> bool:
109 """Delete a user.
111 Args:
112 user_id: User identifier.
114 Returns:
115 True if deleted, False if not found.
116 """
117 ...
120@runtime_checkable
121class UserStoreProtocol(UserReaderProtocol, UserWriterProtocol, Protocol):
122 """Combined user store protocol for read/write operations.
124 This protocol combines UserReaderProtocol and UserWriterProtocol for convenience
125 in implementations that provide both read and write capabilities.
126 """
129__all__ = [
130 "UserReaderProtocol",
131 "UserStoreProtocol",
132 "UserWriterProtocol",
133]