88from dataclasses import dataclass
99from typing import Self
1010
11+ from typing_extensions import deprecated
12+
1113# 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
14+ from frequenz .api .common .v1 .pagination .pagination_info_pb2 import (
15+ PaginationInfo as PBPaginationInfo ,
16+ )
17+ from frequenz .api .common .v1 .pagination .pagination_params_pb2 import (
18+ PaginationParams as PBPaginationParams ,
19+ )
20+ from frequenz .api .common .v1alpha8 .pagination .pagination_info_pb2 import (
21+ PaginationInfo as PBPaginationInfoAlpha8 ,
22+ )
23+ from frequenz .api .common .v1alpha8 .pagination .pagination_params_pb2 import (
24+ PaginationParams as PBPaginationParamsAlpha8 ,
25+ )
1426
1527# pylint: enable=no-name-in-module
1628
1729
30+ @deprecated (
31+ "Params is deprecated, use PaginationParams instead." ,
32+ )
1833@dataclass (frozen = True , kw_only = True )
1934class Params :
2035 """Parameters for paginating list requests."""
@@ -26,7 +41,7 @@ class Params:
2641 """The token identifying a specific page of the list results."""
2742
2843 @classmethod
29- def from_proto (cls , pagination_params : PaginationParams ) -> Self :
44+ def from_proto (cls , pagination_params : PBPaginationParams ) -> Self :
3045 """Convert a protobuf Params to PaginationParams object.
3146
3247 Args:
@@ -39,18 +54,21 @@ def from_proto(cls, pagination_params: PaginationParams) -> Self:
3954 page_token = pagination_params .page_token ,
4055 )
4156
42- def to_proto (self ) -> PaginationParams :
57+ def to_proto (self ) -> PBPaginationParams :
4358 """Convert a Params object to protobuf PaginationParams.
4459
4560 Returns:
4661 Protobuf message corresponding to the Params object.
4762 """
48- return PaginationParams (
63+ return PBPaginationParams (
4964 page_size = self .page_size ,
5065 page_token = self .page_token ,
5166 )
5267
5368
69+ @deprecated (
70+ "Info is deprecated, use PaginationInfo instead." ,
71+ )
5472@dataclass (frozen = True , kw_only = True )
5573class Info :
5674 """Information about the pagination of a list request."""
@@ -62,7 +80,79 @@ class Info:
6280 """The token identifying the next page of results."""
6381
6482 @classmethod
65- def from_proto (cls , pagination_info : PaginationInfo ) -> Self :
83+ def from_proto (cls , pagination_info : PBPaginationInfo ) -> Self :
84+ """Convert a protobuf PBPaginationInfo to Info object.
85+
86+ Args:
87+ pagination_info: Info to convert.
88+ Returns:
89+ Info object corresponding to the protobuf message.
90+ """
91+ return cls (
92+ total_items = pagination_info .total_items ,
93+ next_page_token = pagination_info .next_page_token ,
94+ )
95+
96+ def to_proto (self ) -> PBPaginationInfo :
97+ """Convert a Info object to protobuf PBPaginationInfo.
98+
99+ Returns:
100+ Protobuf message corresponding to the Info object.
101+ """
102+ return PBPaginationInfo (
103+ total_items = self .total_items ,
104+ next_page_token = self .next_page_token ,
105+ )
106+
107+
108+ @dataclass (frozen = True , kw_only = True )
109+ class PaginationParams :
110+ """Parameters for paginating list requests."""
111+
112+ page_size : int
113+ """The maximum number of results to be returned per request."""
114+
115+ page_token : str
116+ """The token identifying a specific page of the list results."""
117+
118+ @classmethod
119+ def from_proto (cls , pagination_params : PBPaginationParamsAlpha8 ) -> Self :
120+ """Convert a protobuf PaginationParams to python PaginationParams object.
121+
122+ Args:
123+ pagination_params: Params to convert.
124+ Returns:
125+ Params object corresponding to the protobuf message.
126+ """
127+ return cls (
128+ page_size = pagination_params .page_size ,
129+ page_token = pagination_params .page_token ,
130+ )
131+
132+ def to_proto (self ) -> PBPaginationParamsAlpha8 :
133+ """Convert a Params object to protobuf PaginationParams.
134+
135+ Returns:
136+ Protobuf message corresponding to the Params object.
137+ """
138+ return PBPaginationParamsAlpha8 (
139+ page_size = self .page_size ,
140+ page_token = self .page_token ,
141+ )
142+
143+
144+ @dataclass (frozen = True , kw_only = True )
145+ class PaginationInfo :
146+ """Information about the pagination of a list request."""
147+
148+ total_items : int
149+ """The total number of items that match the request."""
150+
151+ next_page_token : str | None = None
152+ """The token identifying the next page of results."""
153+
154+ @classmethod
155+ def from_proto (cls , pagination_info : PBPaginationInfoAlpha8 ) -> Self :
66156 """Convert a protobuf PBPaginationInfo to Info object.
67157
68158 Args:
@@ -75,13 +165,13 @@ def from_proto(cls, pagination_info: PaginationInfo) -> Self:
75165 next_page_token = pagination_info .next_page_token ,
76166 )
77167
78- def to_proto (self ) -> PaginationInfo :
168+ def to_proto (self ) -> PBPaginationInfoAlpha8 :
79169 """Convert a Info object to protobuf PBPaginationInfo.
80170
81171 Returns:
82172 Protobuf message corresponding to the Info object.
83173 """
84- return PaginationInfo (
174+ return PBPaginationInfoAlpha8 (
85175 total_items = self .total_items ,
86176 next_page_token = self .next_page_token ,
87177 )
0 commit comments