vatly-api-python 0.1.0a2__py3-none-any.whl

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.
vatly/pagination.py ADDED
@@ -0,0 +1,29 @@
1
+ from typing import Any, Generic, TypeVar
2
+ from urllib.parse import parse_qs, urlparse
3
+
4
+ from pydantic import BaseModel, ConfigDict
5
+
6
+ from .models import PaginationLinks
7
+
8
+ T = TypeVar("T")
9
+
10
+
11
+ class Page(BaseModel, Generic[T]):
12
+ model_config = ConfigDict(extra="allow")
13
+ data: list[T]
14
+ count: int
15
+ links: PaginationLinks
16
+
17
+
18
+ def next_params(page: Page[Any], params: dict[str, Any], seen: set[str]) -> dict[str, Any] | None:
19
+ if page.links.next is None:
20
+ return None
21
+ cursor = parse_qs(urlparse(page.links.next.href).query).get("startingAfter", [None])[0]
22
+ if not cursor or cursor in seen:
23
+ raise VatlyPaginationError("Invalid or repeated pagination cursor")
24
+ seen.add(cursor)
25
+ return {k: v for k, v in {**params, "startingAfter": cursor}.items() if k != "endingBefore"}
26
+
27
+
28
+ class VatlyPaginationError(ValueError):
29
+ pass
vatly/py.typed ADDED
@@ -0,0 +1 @@
1
+ # PEP 561: this package includes inline type information.