@@ -179,6 +179,33 @@ class PathsCursorParameters(BaseModel):
179179 partial : bool
180180
181181
182+ def _init_pagination (
183+ cursor : GenericCursor | None ,
184+ * ,
185+ filter_by_project_ids : list [ProjectID ] | None ,
186+ filter_by_file_prefix : Path | None ,
187+ is_partial_prefix : bool ,
188+ ) -> PathsCursorParameters :
189+ if cursor :
190+ return PathsCursorParameters .model_validate_json (cursor )
191+ return PathsCursorParameters (
192+ offset = 0 ,
193+ file_prefix = filter_by_file_prefix ,
194+ project_ids = filter_by_project_ids ,
195+ partial = is_partial_prefix ,
196+ )
197+
198+
199+ def _create_next_cursor (
200+ total : TotalChildren , limit : int , cursor_params : PathsCursorParameters
201+ ) -> GenericCursor | None :
202+ if cursor_params .offset + limit < total :
203+ return cursor_params .model_copy (
204+ update = {"offset" : cursor_params .offset + limit }
205+ ).model_dump_json ()
206+ return None
207+
208+
182209async def list_child_paths (
183210 conn : AsyncConnection ,
184211 * ,
@@ -192,15 +219,12 @@ async def list_child_paths(
192219 e.g. when no filter is used, these are top level objects
193220 """
194221
195- if cursor :
196- cursor_params = PathsCursorParameters .model_validate_json (cursor )
197- else :
198- cursor_params = PathsCursorParameters (
199- offset = 0 ,
200- file_prefix = filter_by_file_prefix ,
201- project_ids = filter_by_project_ids ,
202- partial = is_partial_prefix ,
203- )
222+ cursor_params = _init_pagination (
223+ cursor ,
224+ filter_by_project_ids = filter_by_project_ids ,
225+ filter_by_file_prefix = filter_by_file_prefix ,
226+ is_partial_prefix = is_partial_prefix ,
227+ )
204228
205229 if cursor_params .file_prefix :
206230 prefix_levels = len (cursor_params .file_prefix .parts ) - 1
@@ -299,12 +323,8 @@ async def list_child_paths(
299323 )
300324 async for row in await conn .stream (files_query )
301325 ]
302- next_cursor = None
303- if cursor_params .offset + limit < total_count :
304- next_cursor = cursor_params .model_copy (
305- update = {"offset" : cursor_params .offset + limit }
306- ).model_dump_json ()
307- return items , next_cursor , total_count
326+
327+ return items , _create_next_cursor (total_count , limit , cursor_params ), total_count
308328
309329
310330async def list_fmds (
0 commit comments