@@ -22,12 +22,29 @@ class DynamoDBBaseAccessTokenTable(Model, Generic[ID]):
2222 __tablename__ : str = config .get ("DATABASE_TOKENTABLE_NAME" )
2323
2424 class Meta :
25+ """The required `Meta` definitions for PynamoDB.
26+
27+ Args:
28+ table_name (str): The name of the table.
29+ region (str): The AWS region string where the table should be created.
30+ billing_mode (str): The billing mode to use when creating the table. \
31+ Currently only supports `PAY_PER_REQUEST`.
32+ """
33+
2534 table_name : str = config .get ("DATABASE_TOKENTABLE_NAME" )
2635 region : str = config .get ("DATABASE_REGION" )
2736 billing_mode : str = config .get ("DATABASE_BILLING_MODE" ).value
2837
2938 class CreatedAtIndex (GlobalSecondaryIndex ):
39+ """Enable the `created_at` attribute to be a Global Secondary Index.
40+
41+ Args:
42+ GlobalSecondaryIndex (_type_): The Global Secondary Index base class.
43+ """
44+
3045 class Meta :
46+ """The metadata for the Global Secondary Index."""
47+
3148 index_name : str = "created_at-index"
3249 projection = AllProjection ()
3350
@@ -46,18 +63,29 @@ class Meta:
4663
4764
4865class DynamoDBBaseAccessTokenTableUUID (DynamoDBBaseAccessTokenTable [UUID_ID ]):
66+ """A base class representing `AccessToken` objects with unique IDs.
67+
68+ Args:
69+ DynamoDBBaseAccessTokenTable (_type_): The underlying table object.
70+ """
71+
4972 if TYPE_CHECKING : # pragma: no cover
5073 user_id : UUID_ID
5174 else :
5275 user_id : GUID = GUID (null = False )
5376
5477
5578class DynamoDBAccessTokenDatabase (Generic [AP ], AccessTokenDatabase [AP ]):
56- """Access token database adapter for AWS DynamoDB using aiopynamodb."""
79+ """Access token database adapter for AWS DynamoDB using ` aiopynamodb` ."""
5780
5881 access_token_table : type [AP ]
5982
6083 def __init__ (self , access_token_table : type [AP ]):
84+ """Initialize the Database adapter.
85+
86+ Args:
87+ access_token_table (type[AP]): The table for storing access tokens.
88+ """
6189 self .access_token_table = access_token_table
6290
6391 async def get_by_token (
@@ -66,7 +94,16 @@ async def get_by_token(
6694 max_age : datetime | None = None ,
6795 instant_update : bool = False ,
6896 ) -> AP | None :
69- """Retrieve an access token by token string."""
97+ """Retrieve an access token by it's token string.
98+
99+ Args:
100+ token (str): The actual token string to be looked for.
101+ max_age (datetime | None, optional): The maximum age of an access token. Expired ones will not be returned. Defaults to None.
102+ instant_update (bool, optional): Whether to use consistent reads. Defaults to False.
103+
104+ Returns:
105+ AP | None: The access token, if found.
106+ """
70107 await ensure_tables_exist (self .access_token_table ) # type: ignore
71108
72109 try :
@@ -83,7 +120,18 @@ async def get_by_token(
83120 return None
84121
85122 async def create (self , create_dict : dict [str , Any ] | AP ) -> AP :
86- """Create a new access token and return an instance of AP."""
123+ """Create a new access token.
124+
125+ Args:
126+ create_dict (dict[str, Any] | AP): A dictionary holding the data of the access token.
127+
128+ Raises:
129+ ValueError: If the access token could not be created for whatever reason.
130+ ValueError: If the access token could not be created because the table did not exist.
131+
132+ Returns:
133+ AP: The newly created `AccessToken` object.
134+ """
87135 await ensure_tables_exist (self .access_token_table ) # type: ignore
88136
89137 if isinstance (create_dict , dict ):
@@ -103,7 +151,19 @@ async def create(self, create_dict: dict[str, Any] | AP) -> AP:
103151 return token
104152
105153 async def update (self , access_token : AP , update_dict : dict [str , Any ]) -> AP :
106- """Update an existing access token."""
154+ """Update an existing access token.
155+
156+ Args:
157+ access_token (AP): The `AccessToken` object to be deleted.
158+ update_dict (dict[str, Any]): A dictionary with the changes that should be applied.
159+
160+ Raises:
161+ ValueError: If the access token could not be updated for whatever reason.
162+ ValueError: If the access token could not be updated because the table did not exist.
163+
164+ Returns:
165+ AP: The refreshed `AccessToken` object.
166+ """
107167 await ensure_tables_exist (self .access_token_table ) # type: ignore
108168
109169 try :
@@ -121,7 +181,15 @@ async def update(self, access_token: AP, update_dict: dict[str, Any]) -> AP:
121181 ) from e
122182
123183 async def delete (self , access_token : AP ) -> None :
124- """Delete an access token."""
184+ """Delete an access token.
185+
186+ Args:
187+ access_token (AP): The `AccessToken` object to be deleted.
188+
189+ Raises:
190+ ValueError: If the access token could not be deleted for whatever reason.
191+ ValueError: If the access token could not be deleted because the table did not exist.
192+ """
125193 await ensure_tables_exist (self .access_token_table ) # type: ignore
126194
127195 try :
0 commit comments