99from typing import Self
1010
1111# pylint: disable=no-name-in-module
12- from frequenz .api .common .v1 .pagination .pagination_info_pb2 import PaginationInfo
13- from frequenz .api .common .v1 .pagination .pagination_params_pb2 import PaginationParams
12+ from frequenz .api .common .v1 .pagination .pagination_info_pb2 import (
13+ PaginationInfo as PBPaginationInfo ,
14+ )
15+ from frequenz .api .common .v1 .pagination .pagination_params_pb2 import (
16+ PaginationParams as PBPaginationParams ,
17+ )
18+ from frequenz .api .common .v1alpha8 .pagination .pagination_info_pb2 import (
19+ PaginationInfo as PBPaginationInfoAlpha8 ,
20+ )
21+ from typing_extensions import deprecated
1422
1523# pylint: enable=no-name-in-module
1624
1725
26+ @deprecated (
27+ "Params is deprecated, use "
28+ "frequenz.api.common.v1.pagination.pagination_params_pb2.PaginationParams"
29+ " from the API directly instead." ,
30+ )
1831@dataclass (frozen = True , kw_only = True )
1932class Params :
2033 """Parameters for paginating list requests."""
@@ -26,7 +39,7 @@ class Params:
2639 """The token identifying a specific page of the list results."""
2740
2841 @classmethod
29- def from_proto (cls , pagination_params : PaginationParams ) -> Self :
42+ def from_proto (cls , pagination_params : PBPaginationParams ) -> Self :
3043 """Convert a protobuf Params to PaginationParams object.
3144
3245 Args:
@@ -39,18 +52,21 @@ def from_proto(cls, pagination_params: PaginationParams) -> Self:
3952 page_token = pagination_params .page_token ,
4053 )
4154
42- def to_proto (self ) -> PaginationParams :
55+ def to_proto (self ) -> PBPaginationParams :
4356 """Convert a Params object to protobuf PaginationParams.
4457
4558 Returns:
4659 Protobuf message corresponding to the Params object.
4760 """
48- return PaginationParams (
61+ return PBPaginationParams (
4962 page_size = self .page_size ,
5063 page_token = self .page_token ,
5164 )
5265
5366
67+ @deprecated (
68+ "Info is deprecated, use PaginationInfo instead." ,
69+ )
5470@dataclass (frozen = True , kw_only = True )
5571class Info :
5672 """Information about the pagination of a list request."""
@@ -62,7 +78,7 @@ class Info:
6278 """The token identifying the next page of results."""
6379
6480 @classmethod
65- def from_proto (cls , pagination_info : PaginationInfo ) -> Self :
81+ def from_proto (cls , pagination_info : PBPaginationInfo ) -> Self :
6682 """Convert a protobuf PBPaginationInfo to Info object.
6783
6884 Args:
@@ -75,13 +91,62 @@ def from_proto(cls, pagination_info: PaginationInfo) -> Self:
7591 next_page_token = pagination_info .next_page_token ,
7692 )
7793
78- def to_proto (self ) -> PaginationInfo :
94+ def to_proto (self ) -> PBPaginationInfo :
7995 """Convert a Info object to protobuf PBPaginationInfo.
8096
8197 Returns:
8298 Protobuf message corresponding to the Info object.
8399 """
84- return PaginationInfo (
100+ return PBPaginationInfo (
101+ total_items = self .total_items ,
102+ next_page_token = self .next_page_token ,
103+ )
104+
105+
106+ @dataclass (frozen = True , kw_only = True )
107+ class PaginationInfo :
108+ """Information about the pagination of a list request."""
109+
110+ total_items : int
111+ """The total number of items that match the request."""
112+
113+ next_page_token : str | None = None
114+ """The token identifying the next page of results."""
115+
116+ @classmethod
117+ def from_proto (
118+ cls , pagination_info : PBPaginationInfoAlpha8 | PBPaginationInfo
119+ ) -> Self :
120+ """Convert a protobuf PBPaginationInfo to Info object.
121+
122+ Args:
123+ pagination_info: Info to convert.
124+ Returns:
125+ Info object corresponding to the protobuf message.
126+ """
127+ return cls (
128+ total_items = pagination_info .total_items ,
129+ next_page_token = pagination_info .next_page_token ,
130+ )
131+
132+ def to_proto_v1alpha8 (self ) -> PBPaginationInfoAlpha8 :
133+ """Convert a Info object to protobuf PBPaginationInfo.
134+
135+ Returns:
136+ Protobuf message corresponding to the Info object.
137+ """
138+ return PBPaginationInfoAlpha8 (
139+ total_items = self .total_items ,
140+ next_page_token = self .next_page_token ,
141+ )
142+
143+ def to_proto (self ) -> PBPaginationInfo :
144+ """Convert a Info object to protobuf PBPaginationInfo.
145+
146+ Returns:
147+ Protobuf message corresponding to the Info object.
148+ """
149+ return PBPaginationInfo (
85150 total_items = self .total_items ,
86151 next_page_token = self .next_page_token ,
87152 )
0 commit comments