finalsa-common-models 2.1.1__tar.gz → 2.1.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: finalsa-common-models
3
- Version: 2.1.1
3
+ Version: 2.1.3
4
4
  Summary: Common models for Finalsa
5
5
  Project-URL: Homepage, https://github.com/finalsa/finalsa-common-models
6
6
  Author-email: Luis Jimenez <luis@finalsa.com>
@@ -1,6 +1,7 @@
1
1
  from typing import Any, Dict, Generic, Optional, Sequence, TypeVar
2
2
 
3
3
  from pydantic import BaseModel, ConfigDict, Field, model_validator
4
+ from orjson import loads
4
5
 
5
6
 
6
7
  ItemT = TypeVar("ItemT")
@@ -22,6 +23,17 @@ class PaginationRequest(BaseModel):
22
23
  description="DynamoDB ExclusiveStartKey encoded in the request.",
23
24
  )
24
25
 
26
+ @classmethod
27
+ def from_request(cls, request: Any) -> "PaginationRequest":
28
+ """Parse query params into PaginationRequest. Handles JSON-encoded 'from' param."""
29
+ params = request.query_params
30
+ data = {}
31
+ if limit := params.get("limit"):
32
+ data["limit"] = int(limit)
33
+ if from_param := params.get("from"):
34
+ data["exclusive_start_key"] = loads(from_param)
35
+ return cls(**data, **request.path_params)
36
+
25
37
 
26
38
  class PaginationMeta(BaseModel):
27
39
  """Generic metadata that can be attached to a paginated response."""
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "finalsa-common-models"
3
- version = "2.1.1"
3
+ version = "2.1.3"
4
4
  description = "Common models for Finalsa"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"