diff --git a/Cargo.lock b/Cargo.lock index cf5e8f7..b47eb5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1133,7 +1133,7 @@ dependencies = [ [[package]] name = "pgstac" version = "0.2.2" -source = "git+https://github.com/stac-utils/stac-rs#94693e3e8e732018769861214e1cab9767c9a674" +source = "git+https://github.com/stac-utils/stac-rs#35bfcd7a175efb0b750f400c258c892b166a1e21" dependencies = [ "serde", "serde_json", @@ -1660,7 +1660,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stac" version = "0.11.1" -source = "git+https://github.com/stac-utils/stac-rs#94693e3e8e732018769861214e1cab9767c9a674" +source = "git+https://github.com/stac-utils/stac-rs#35bfcd7a175efb0b750f400c258c892b166a1e21" dependencies = [ "bytes", "chrono", @@ -1678,7 +1678,7 @@ dependencies = [ [[package]] name = "stac-api" version = "0.7.0" -source = "git+https://github.com/stac-utils/stac-rs#94693e3e8e732018769861214e1cab9767c9a674" +source = "git+https://github.com/stac-utils/stac-rs#35bfcd7a175efb0b750f400c258c892b166a1e21" dependencies = [ "chrono", "cql2", @@ -1698,7 +1698,7 @@ dependencies = [ [[package]] name = "stac-derive" version = "0.2.0" -source = "git+https://github.com/stac-utils/stac-rs#94693e3e8e732018769861214e1cab9767c9a674" +source = "git+https://github.com/stac-utils/stac-rs#35bfcd7a175efb0b750f400c258c892b166a1e21" dependencies = [ "quote", "syn", diff --git a/pgstacrs.pyi b/pgstacrs.pyi index 3d51d3b..66850e8 100644 --- a/pgstacrs.pyi +++ b/pgstacrs.pyi @@ -34,6 +34,7 @@ class Client: sortby: str | list[str] | None = None, filter: str | dict[str, Any] | None = None, query: dict[str, Any] | None = None, + **kwargs: str, ) -> dict[str, Any]: """ Searches the database with STAC API item search. @@ -59,6 +60,7 @@ class Client: query: Additional filtering based on properties. It is recommended to use filter instead, if possible. limit: The page size returned from the server. + kwargs: Any additional arguments to pass down into the search, e.g a pagination token """ async def print_config(self) -> None: diff --git a/src/lib.rs b/src/lib.rs index 145ccfa..c6dd253 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -293,7 +293,7 @@ impl Client { }) } - #[pyo3(signature = (*, collections=None, ids=None, intersects=None, bbox=None, datetime=None, include=None, exclude=None, sortby=None, filter=None, query=None, limit=None))] + #[pyo3(signature = (*, collections=None, ids=None, intersects=None, bbox=None, datetime=None, include=None, exclude=None, sortby=None, filter=None, query=None, limit=None, **kwargs))] fn search<'a>( &self, py: Python<'a>, @@ -308,6 +308,7 @@ impl Client { filter: Option, query: Option>, limit: Option, + kwargs: Option>, ) -> PyResult> { let search = stac_api::python::search( intersects, @@ -321,6 +322,7 @@ impl Client { sortby, filter, query, + kwargs, )?; self.run(py, |pool| async move { let connection = pool.get().await?; diff --git a/tests/test_search.py b/tests/test_search.py index 2bb17b7..1e76229 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,4 +1,5 @@ import copy +import urllib.parse from typing import Any import pytest @@ -219,3 +220,30 @@ async def test_collections( feature_collection = await client.search(collections=["simple-collection"]) assert len(feature_collection["features"]) == 1 + + +async def test_pagination( + client: Client, collection: dict[str, Any], item: dict[str, Any] +) -> None: + version = await client.get_version() + + await client.create_collection(collection) + item["id"] = "first-item" + await client.create_item(item) + second_item = copy.deepcopy(item) + second_item["id"] = "second-item" + await client.create_item(second_item) + + feature_collection = await client.search(limit=1, sortby="id") + + if version.startswith("0.9"): + next_link = next( + (link for link in feature_collection["links"] if link["rel"] == "next") + ) + url = urllib.parse.urlparse(next_link["href"]) + token = url.query.split("=")[1] + elif version.startswith("0.8"): + token = "next:" + feature_collection["next"] + + feature_collection = await client.search(limit=1, sortby="id", token=token) + assert feature_collection["features"][0]["id"] == "second-item"