From 1108b3b69e7b7ba7af805433006560e01a7c1847 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 14:55:07 +0000 Subject: [PATCH 1/6] feat: sync with Apify OpenAPI spec updates and use the long timeout for Actor version uploads Document the Store search semantics and the deprecated sortBy, and send Actor version create and update requests with the Long timeout tier. --- CHANGELOG.md | 13 +++++++++++++ Cargo.toml | 2 +- README.md | 4 ++-- docs/README.md | 2 +- docs/actors.md | 3 ++- docs/misc.md | 7 +++++++ src/clients/actor_version.rs | 5 ++++- src/clients/actor_version_collection.rs | 5 ++++- src/clients/store_collection.rs | 17 +++++++++++----- tests/store.rs | 17 ++++++++++++++++ tests/unit_timeouts.rs | 26 +++++++++++++++++++++++++ 11 files changed, 89 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6d3e59..8c8dd5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to the Rust Apify API client are documented here. The format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres to [Semantic Versioning](https://semver.org/). +## [0.19.0] - 2026-11-27 + +### Changed +- Synced with the Apify OpenAPI spec. `GET /v2/store` ranks the results of a `search` by relevance + and returns a single page of at most 100 items, `sortBy` is deprecated and ignored, and + `category` takes comma-separated category IDs. Documented it on `StoreListOptions` and in the + docs. The Store listing items keep the new `stats` shape and `isVerified` in `extra`. The spec + also adds the `APIFY_AI` run origin, marks eight response fields as nullable, and adds the `409` + response to creating an Actor and the `401` response to getting a build. These need no code + change. +- `ActorVersionCollectionClient::create` and `ActorVersionClient::update` use the `Long` timeout + tier by default, since a version can carry its source files. + ## [0.18.0] - 2026-11-20 ### Added diff --git a/Cargo.toml b/Cargo.toml index 8f39189..e6cb32b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "apify-client" -version = "0.18.0" +version = "0.19.0" authors = ["Apify Technologies "] description = "Rust client for the Apify API (https://apify.com)." license = "Apache-2.0" diff --git a/README.md b/README.md index 806784f..1ef751e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ It provides a resource-oriented, async interface that follows the ```toml [dependencies] -apify-client = "0.18" +apify-client = "0.19" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } serde_json = "1" # for the `serde_json::Value` responses used in the Quick start ``` @@ -49,7 +49,7 @@ instead, disable the default features and name `rustls`. The `"zstd"` entry keep so drop it if you do not need it: ```toml -apify-client = { version = "0.18", default-features = false, features = ["rustls", "zstd"] } +apify-client = { version = "0.19", default-features = false, features = ["rustls", "zstd"] } ``` The `rustls` feature requires `rustls-webpki` 0.103.16 or newer and `webpki-roots` 1.0.10 or diff --git a/docs/README.md b/docs/README.md index 515f1ee..e75fb3c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -31,7 +31,7 @@ Add the crate and an async runtime: ```toml [dependencies] -apify-client = "0.18" +apify-client = "0.19" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } ``` diff --git a/docs/actors.md b/docs/actors.md index 75ec001..d7e0f6b 100644 --- a/docs/actors.md +++ b/docs/actors.md @@ -407,4 +407,5 @@ when it is `None`. Creating a version needs `versionNumber` and `sourceType` in the body, and so does every item of the `versions` array in an Actor create or update body. The writable source types are `SOURCE_FILES`, `GIT_REPO`, `TARBALL` and `GITHUB_GIST`; `SOURCE_CODE` can be read but not sent. -Updating a version needs no required field. +Updating a version needs no required field. `create` and `update` use the `Long` timeout tier by +default, since a version can carry its source files; set another one with `with_timeout`. diff --git a/docs/misc.md b/docs/misc.md index 5f7b1b1..27aa7af 100644 --- a/docs/misc.md +++ b/docs/misc.md @@ -14,6 +14,13 @@ `limit` means a single page's size for `list`, but a cap on the *total* number of items yielded for `iterate` (see below). +With `search`, the API ranks the results by relevance and returns a single page of at most 100 +items: `offset` is ignored, a larger `limit` is reduced to 100, and there is no second page. Without +it, a page has at most 1000 items. `sort_by` is deprecated: the API accepts it and ignores it, so +sort the results on the client if you need a different order. `category` takes one or more +category IDs separated by commas, such as `AI_AND_ML`; an Actor must match all of them, and an +unknown category makes the API answer with a `400` error. + `StoreActorIterator` is a type alias for `ListIterator` (the shared iterator returned by every collection's `iterate`), re-exported at the crate root alongside `ListIterator` itself. Its `next()` is `async` and fallible — it returns diff --git a/src/clients/actor_version.rs b/src/clients/actor_version.rs index 80a9ad8..1a9ef3f 100644 --- a/src/clients/actor_version.rs +++ b/src/clients/actor_version.rs @@ -32,8 +32,11 @@ impl ActorVersionClient { } /// Updates the version with the given fields. + /// + /// The request uses the `Long` timeout tier by default, since the version can carry its + /// source files. Set another one with [`with_timeout`](Self::with_timeout). pub async fn update(&self, new_fields: &T) -> ApifyClientResult { - update_resource(&self.ctx, None, new_fields, Timeout::Short).await + update_resource(&self.ctx, None, new_fields, Timeout::Long).await } /// Deletes the version. diff --git a/src/clients/actor_version_collection.rs b/src/clients/actor_version_collection.rs index 42efa26..7f8782f 100644 --- a/src/clients/actor_version_collection.rs +++ b/src/clients/actor_version_collection.rs @@ -41,7 +41,10 @@ impl ActorVersionCollectionClient { } /// Creates a new Actor version. + /// + /// The request uses the `Long` timeout tier by default, since the version can carry its + /// source files. Set another one with [`with_timeout`](Self::with_timeout). pub async fn create(&self, version: &T) -> ApifyClientResult { - create_resource(&self.ctx, &QueryParams::new(), version, Timeout::Short).await + create_resource(&self.ctx, &QueryParams::new(), version, Timeout::Long).await } } diff --git a/src/clients/store_collection.rs b/src/clients/store_collection.rs index 13d3d9f..8bc5849 100644 --- a/src/clients/store_collection.rs +++ b/src/clients/store_collection.rs @@ -18,18 +18,25 @@ pub type StoreActorIterator = ListIterator; /// Options for searching the Apify Store. #[derive(Debug, Default, Clone)] pub struct StoreListOptions { - /// Number of items to skip. + /// Number of items to skip. The API ignores it when `search` is used. pub offset: Option, - /// Item limit. Its meaning depends on the method: for [`StoreCollectionClient::list`] it is a + /// Item limit. The default and the maximum are 1000. When `search` is used, they are 100, and + /// a larger value is reduced to 100. Its meaning depends on the method: for [`StoreCollectionClient::list`] it is a /// single page's size (the maximum items that one call returns); for /// [`StoreCollectionClient::iterate`] it is a cap on the *total* number of items yielded across /// all pages. See each method's docs. pub limit: Option, - /// Full-text search query. + /// Search query. With it, the API ranks the results by relevance and returns a single page of + /// at most 100 items: `offset` is ignored and there is no second page. To narrow the results, + /// use `category`, `username` or `pricing_model`. pub search: Option, - /// Sort key (e.g. `popularity`, `newest`). + /// Deprecated and ignored by the API, which accepts it for backward compatibility. Results + /// are ordered by relevance when `search` is used, and by Store position otherwise. Sort the + /// results on the client if you need a different order. pub sort_by: Option, - /// Filter by category. + /// Filter by category. Accepts one or more category IDs separated by commas, case-insensitive + /// (for example `AI_AND_ML`). An Actor must match all of the listed categories. An unknown + /// category makes the API answer with a `400` error. pub category: Option, /// Filter by owner username. pub username: Option, diff --git a/tests/store.rs b/tests/store.rs index 549fa0e..cf0efb2 100644 --- a/tests/store.rs +++ b/tests/store.rs @@ -58,3 +58,20 @@ async fn list_store_with_input_schema() { assert!(!page.items.is_empty(), "the Store lists Actors"); assert!(page.items.len() <= 3); } + +/// Simple GET: the deprecated `sort_by` is accepted by the Store endpoint, which ignores it, so +/// the order of the result is not asserted. +#[tokio::test(flavor = "multi_thread")] +async fn list_store_accepts_the_deprecated_sort_by() { + let client = require_client!(); + let page = client + .store() + .list(StoreListOptions { + limit: Some(10), + sort_by: Some("popularity".to_string()), + ..Default::default() + }) + .await + .expect("listing the store with the deprecated sort_by should succeed"); + assert!(!page.items.is_empty(), "the Store lists Actors"); +} diff --git a/tests/unit_timeouts.rs b/tests/unit_timeouts.rs index bc4d442..b385906 100644 --- a/tests/unit_timeouts.rs +++ b/tests/unit_timeouts.rs @@ -56,6 +56,32 @@ async fn listing_uses_the_medium_tier() { assert_eq!(backend.last_timeout(), Duration::from_secs(30)); } +#[tokio::test] +async fn creating_and_updating_an_actor_version_use_the_long_tier() { + let backend = MockBackend::new(vec![ + ok_data(json!({ "versionNumber": "0.1" })), + ok_data(json!({ "versionNumber": "0.1" })), + ]); + let client = client_with(backend.clone(), 0); + let body = json!({ "versionNumber": "0.1", "sourceType": "SOURCE_FILES" }); + client + .actor("a") + .versions() + .create(&body) + .await + .expect("create version"); + client + .actor("a") + .version("0.1") + .update(&body) + .await + .expect("update version"); + assert_eq!( + backend.timeouts(), + vec![Duration::from_secs(360), Duration::from_secs(360)] + ); +} + #[tokio::test] async fn dataset_items_use_the_long_tier() { let backend = MockBackend::new(vec![MockOutcome::Status(200, b"[]".to_vec())]); From af15f96dd8d35d18875c0601bc183f03491fc5e1 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 15:03:16 +0000 Subject: [PATCH 2/6] fix: stop iterating a Store search after its single page Mark StoreListOptions::sort_by deprecated, align the Store option docs with the spec, and shorten the changelog entry. --- CHANGELOG.md | 13 ++++++------- docs/misc.md | 8 +++++--- src/clients/store_collection.rs | 30 ++++++++++++++++++++++++------ tests/store.rs | 19 +++++++++++++++++++ tests/unit_http.rs | 31 ++++++++++++++++++++++++++++++- 5 files changed, 84 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c8dd5c..2dbb28e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,13 @@ to [Semantic Versioning](https://semver.org/). ## [0.19.0] - 2026-11-27 +### Fixed +- `StoreCollectionClient::iterate` with `search` fetches the single page the API returns and + stops, instead of repeating the same Actors. + ### Changed -- Synced with the Apify OpenAPI spec. `GET /v2/store` ranks the results of a `search` by relevance - and returns a single page of at most 100 items, `sortBy` is deprecated and ignored, and - `category` takes comma-separated category IDs. Documented it on `StoreListOptions` and in the - docs. The Store listing items keep the new `stats` shape and `isVerified` in `extra`. The spec - also adds the `APIFY_AI` run origin, marks eight response fields as nullable, and adds the `409` - response to creating an Actor and the `401` response to getting a build. These need no code - change. +- Documented the Store search, `limit`, `category` and `sort_by` semantics on `StoreListOptions` and + in the docs, and deprecated `StoreListOptions::sort_by`, which the API ignores. - `ActorVersionCollectionClient::create` and `ActorVersionClient::update` use the `Long` timeout tier by default, since a version can carry its source files. diff --git a/docs/misc.md b/docs/misc.md index 27aa7af..5978d40 100644 --- a/docs/misc.md +++ b/docs/misc.md @@ -10,13 +10,14 @@ | `iterate(options)` | `StoreListOptions` | `StoreActorIterator` | Lazy, page-fetching iterator. | `StoreListOptions`: `offset`, `limit`, `search`, `sort_by`, `category`, `username`, -`pricing_model`, `include_unrunnable_actors`, `allows_agentic_users`, `response_format`. +`pricing_model`, `include_unrunnable_actors`, `allows_agentic_users`, `response_format`, +`include_input_schema`. `limit` means a single page's size for `list`, but a cap on the *total* number of items yielded for `iterate` (see below). With `search`, the API ranks the results by relevance and returns a single page of at most 100 items: `offset` is ignored, a larger `limit` is reduced to 100, and there is no second page. Without -it, a page has at most 1000 items. `sort_by` is deprecated: the API accepts it and ignores it, so +it, a page has at most 1000 items, or 10 with `include_input_schema`. `sort_by` is deprecated: the API accepts it and ignores it, so sort the results on the client if you need a different order. `category` takes one or more category IDs separated by commas, such as `AI_AND_ML`; an Actor must match all of them, and an unknown category makes the API answer with a `400` error. @@ -41,7 +42,8 @@ while let Some(actor) = iter.next().await? { ``` `options.limit` caps the total number of Actors the iterator yields (unset iterates the whole -Store). The per-request page size is separate: call `.with_chunk_size(n)` on the returned +Store). With `search`, the API returns a single page and ignores `offset`, so the iterator fetches +that one page of at most 100 Actors and stops; `with_chunk_size` has no effect then. The per-request page size is separate: call `.with_chunk_size(n)` on the returned `StoreActorIterator` to fetch `n` Actors per API call (when unset, the API's default page size is used). If you set a large `limit` cap, also set `with_chunk_size` so the first request does not ask for the entire cap at once — for example, `client.store().iterate(opts).with_chunk_size(50)`: diff --git a/src/clients/store_collection.rs b/src/clients/store_collection.rs index 8bc5849..f4ee47d 100644 --- a/src/clients/store_collection.rs +++ b/src/clients/store_collection.rs @@ -21,18 +21,20 @@ pub struct StoreListOptions { /// Number of items to skip. The API ignores it when `search` is used. pub offset: Option, /// Item limit. The default and the maximum are 1000. When `search` is used, they are 100, and - /// a larger value is reduced to 100. Its meaning depends on the method: for [`StoreCollectionClient::list`] it is a - /// single page's size (the maximum items that one call returns); for + /// a larger value is reduced to 100. With `include_input_schema`, they are 10. Its meaning + /// depends on the method: for [`StoreCollectionClient::list`] it is a single page's size (the + /// maximum items that one call returns); for /// [`StoreCollectionClient::iterate`] it is a cap on the *total* number of items yielded across /// all pages. See each method's docs. pub limit: Option, /// Search query. With it, the API ranks the results by relevance and returns a single page of /// at most 100 items: `offset` is ignored and there is no second page. To narrow the results, - /// use `category`, `username` or `pricing_model`. + /// use `category`, `username`, or `pricing_model`. pub search: Option, /// Deprecated and ignored by the API, which accepts it for backward compatibility. Results /// are ordered by relevance when `search` is used, and by Store position otherwise. Sort the /// results on the client if you need a different order. + #[deprecated(note = "the API ignores `sortBy`: sort the results on the client")] pub sort_by: Option, /// Filter by category. Accepts one or more category IDs separated by commas, case-insensitive /// (for example `AI_AND_ML`). An Actor must match all of the listed categories. An unknown @@ -42,9 +44,12 @@ pub struct StoreListOptions { pub username: Option, /// Filter by pricing model: `FREE`, `PRICE_PER_DATASET_ITEM` or `PAY_PER_EVENT`. pub pricing_model: Option, - /// Include Actors that the current user cannot run (e.g. needing a missing integration). + /// By default, results exclude Actors that are not safe to run automatically, such as Actors + /// from developers who have not passed KYC or full-permission Actors without a large user + /// base. Set to `true` to bypass this safety filtering and include all Actors. pub include_unrunnable_actors: Option, - /// Filter to Actors that allow agentic (x402/Skyfire) users. + /// If `true`, returns only Actors that allow agentic users. If `false`, returns only Actors + /// that do not allow agentic users. pub allows_agentic_users: Option, /// Response format requested from the API (`full` or `agent`, the API default is `full`). pub response_format: Option, @@ -90,10 +95,23 @@ impl StoreCollectionClient { /// [`list`](Self::list) where `limit` is a single page's size. Set the per-page fetch size /// with [`with_chunk_size`](crate::ListIterator::with_chunk_size); see /// [`ListIterator`] for details. + /// + /// With `options.search`, the API returns a single page of at most 100 Actors and ignores + /// `offset`, so the iterator fetches that one page and stops. `with_chunk_size` has no effect + /// then, and `options.limit` is sent as given. pub fn iterate(&self, options: StoreListOptions) -> StoreActorIterator { - list_iterator!(self, options, list) + if options.search.is_none() { + return list_iterator!(self, options, list); + } + let client = self.clone(); + ListIterator::new_single_page(Box::new(move |_offset, _page_limit| { + let client = client.clone(); + let options = options.clone(); + Box::pin(async move { client.list(options).await }) + })) } + #[allow(deprecated)] // `sort_by` is deprecated, but it is still sent as the caller set it. fn build_params(&self, options: &StoreListOptions) -> QueryParams { let mut params = QueryParams::new(); params diff --git a/tests/store.rs b/tests/store.rs index cf0efb2..600d168 100644 --- a/tests/store.rs +++ b/tests/store.rs @@ -62,6 +62,7 @@ async fn list_store_with_input_schema() { /// Simple GET: the deprecated `sort_by` is accepted by the Store endpoint, which ignores it, so /// the order of the result is not asserted. #[tokio::test(flavor = "multi_thread")] +#[allow(deprecated)] // The test covers the deprecated option. async fn list_store_accepts_the_deprecated_sort_by() { let client = require_client!(); let page = client @@ -75,3 +76,21 @@ async fn list_store_accepts_the_deprecated_sort_by() { .expect("listing the store with the deprecated sort_by should succeed"); assert!(!page.items.is_empty(), "the Store lists Actors"); } + +/// Convenience: iterating a search fetches its single page and ends, without repeating Actors. +#[tokio::test(flavor = "multi_thread")] +async fn iterate_store_search_ends_with_unique_actors() { + let client = require_client!(); + let mut iter = client.store().iterate(StoreListOptions { + search: Some("web scraper".to_string()), + ..Default::default() + }); + let mut ids = std::collections::HashSet::new(); + let mut seen = 0; + while let Some(actor) = iter.next().await.expect("iterate the store search") { + seen += 1; + assert!(ids.insert(actor.id), "an Actor was yielded twice"); + } + assert!(seen > 0, "the search yields at least one Actor"); + assert!(seen <= 100, "a search returns at most 100 Actors"); +} diff --git a/tests/unit_http.rs b/tests/unit_http.rs index c8e05b4..b7f0039 100644 --- a/tests/unit_http.rs +++ b/tests/unit_http.rs @@ -10,7 +10,7 @@ use std::time::Duration; use apify_client::{ ActorCallOptions, ActorStartOptions, ApifyClient, ApifyClientError, LastRunOptions, - LogRedirect, RequestCompression, TaskStartOptions, WaitForResources, + LogRedirect, RequestCompression, StoreListOptions, TaskStartOptions, WaitForResources, }; use common::mock_backend::{client_with, MockBackend, MockOutcome}; use futures_util::StreamExt; @@ -1699,6 +1699,35 @@ async fn iterate_steps_by_the_count_the_api_reports_when_it_exceeds_the_items_re assert!(urls[2].contains("offset=6"), "{urls:?}"); } +/// With `search` the API returns one page and ignores `offset`, so the iterator stops after it +/// instead of requesting the same Actors again. +#[tokio::test] +async fn iterating_a_store_search_fetches_a_single_page() { + let backend = MockBackend::new(vec![MockOutcome::Status( + 200, + br#"{"data":{"total":2,"count":2,"items":[{"id":"a"},{"id":"b"}]}}"#.to_vec(), + )]); + let client = client_with(backend.clone(), 0); + + let actors = client + .store() + .iterate(StoreListOptions { + search: Some("scraper".to_string()), + limit: Some(10), + ..Default::default() + }) + .collect_all() + .await + .expect("ok"); + + let ids: Vec<&str> = actors.iter().map(|actor| actor.id.as_str()).collect(); + assert_eq!(ids, ["a", "b"]); + let urls = backend.urls(); + assert_eq!(urls.len(), 1, "{urls:?}"); + assert!(urls[0].contains("search=scraper"), "{urls:?}"); + assert!(urls[0].contains("limit=10"), "{urls:?}"); +} + /// A streaming call retries an error status until the response starts, like a buffered call. #[tokio::test] async fn a_stream_is_retried_on_an_error_status_until_the_response_starts() { From 3799284e0fc399339340853f27a77033da23cecf Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 15:09:29 +0000 Subject: [PATCH 3/6] fix: keep paging a Store iteration with an empty search Only a non-empty search takes the single-page path. Update the pagination docs and the Store docs to match. --- CHANGELOG.md | 2 +- docs/misc.md | 20 ++++++++++-------- src/clients/pagination.rs | 11 ++++++---- src/clients/store_collection.rs | 15 +++++++++----- tests/unit_http.rs | 36 +++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dbb28e..16d2570 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ to [Semantic Versioning](https://semver.org/). stops, instead of repeating the same Actors. ### Changed -- Documented the Store search, `limit`, `category` and `sort_by` semantics on `StoreListOptions` and +- Documented the Store search, `limit`, `category`, and `sort_by` semantics on `StoreListOptions` and in the docs, and deprecated `StoreListOptions::sort_by`, which the API ignores. - `ActorVersionCollectionClient::create` and `ActorVersionClient::update` use the `Long` timeout tier by default, since a version can carry its source files. diff --git a/docs/misc.md b/docs/misc.md index 5978d40..8b1a71e 100644 --- a/docs/misc.md +++ b/docs/misc.md @@ -15,12 +15,13 @@ `limit` means a single page's size for `list`, but a cap on the *total* number of items yielded for `iterate` (see below). -With `search`, the API ranks the results by relevance and returns a single page of at most 100 -items: `offset` is ignored, a larger `limit` is reduced to 100, and there is no second page. Without -it, a page has at most 1000 items, or 10 with `include_input_schema`. `sort_by` is deprecated: the API accepts it and ignores it, so -sort the results on the client if you need a different order. `category` takes one or more -category IDs separated by commas, such as `AI_AND_ML`; an Actor must match all of them, and an -unknown category makes the API answer with a `400` error. +With a non-empty `search`, the API ranks the results by relevance and returns a single page of at +most 100 items: `offset` is ignored, a larger `limit` is reduced to 100, and there is no second +page. Without it, a page has at most 1000 items, or 10 with `include_input_schema`. `sort_by` is +deprecated: the API accepts it and ignores it, so sort the results on the client if you need a +different order. `category` takes one or more category IDs separated by commas, such as +`AI_AND_ML`; an Actor must match all of them, and an unknown category makes the API answer with a +`400` error. `StoreActorIterator` is a type alias for `ListIterator` (the shared iterator returned by every collection's `iterate`), re-exported at the crate root alongside `ListIterator` @@ -42,8 +43,7 @@ while let Some(actor) = iter.next().await? { ``` `options.limit` caps the total number of Actors the iterator yields (unset iterates the whole -Store). With `search`, the API returns a single page and ignores `offset`, so the iterator fetches -that one page of at most 100 Actors and stops; `with_chunk_size` has no effect then. The per-request page size is separate: call `.with_chunk_size(n)` on the returned +Store). The per-request page size is separate: call `.with_chunk_size(n)` on the returned `StoreActorIterator` to fetch `n` Actors per API call (when unset, the API's default page size is used). If you set a large `limit` cap, also set `with_chunk_size` so the first request does not ask for the entire cap at once — for example, `client.store().iterate(opts).with_chunk_size(50)`: @@ -59,6 +59,10 @@ while let Some(actor) = iter.next().await? { # } ``` +With a non-empty `search`, the API returns a single page and ignores `offset`, so the iterator +fetches that one page of at most 100 Actors and stops; `with_chunk_size` has no effect then. An +empty `search` is the same as none. + `ActorStoreListItem` (from `apify_client::models`) is the element type yielded by both `list` and the iterator. Its fields: diff --git a/src/clients/pagination.rs b/src/clients/pagination.rs index 6a52bf5..1690b77 100644 --- a/src/clients/pagination.rs +++ b/src/clients/pagination.rs @@ -30,7 +30,8 @@ type PageFetcher = Box) -> PageFuture + Send + Syn /// Collections whose listing does not fit this shape build their iterator directly instead: /// the run listing takes a separate `filter` argument, dataset items use `list_items::`, and /// the listings that are not paginated (an Actor's versions and a version's env vars) use -/// `single_page_iterator!`. +/// `single_page_iterator!`. The Store listing uses this macro, except for a search, which +/// returns one page and ignores `offset`, so it builds a single-page iterator itself. macro_rules! list_iterator { ($self:expr, $options:expr, $list:ident) => {{ let client = $self.clone(); @@ -124,8 +125,9 @@ pub struct ListIterator { remaining: Option, /// Page size to request per fetch; `None` = let the API choose its default page size. chunk_size: Option, - /// When `true`, the underlying endpoint is not offset-paginated: the first fetch returns the - /// whole result set, so the iterator stops after it rather than requesting a second page. + /// When `true`, the underlying endpoint is not offset-paginated, or ignores `offset` (a Store + /// search): the first fetch returns the whole result set, so the iterator stops after it + /// rather than requesting a second page. single_page: bool, /// Set once the listing has been fully consumed. exhausted: bool, @@ -148,7 +150,8 @@ impl ListIterator { } /// Builds an iterator over an endpoint that is **not** offset-paginated (it returns every - /// item in one response, e.g. an Actor version's environment variables). `fetch` is called + /// item in one response, e.g. an Actor version's environment variables) or that ignores + /// `offset` for the request at hand (a Store search). `fetch` is called /// exactly once; the iterator does not attempt a second page, so it does not depend on the /// endpoint reporting a page `limit` and cannot refetch the same items. pub(crate) fn new_single_page(fetch: PageFetcher) -> Self { diff --git a/src/clients/store_collection.rs b/src/clients/store_collection.rs index f4ee47d..b7cf59a 100644 --- a/src/clients/store_collection.rs +++ b/src/clients/store_collection.rs @@ -27,7 +27,7 @@ pub struct StoreListOptions { /// [`StoreCollectionClient::iterate`] it is a cap on the *total* number of items yielded across /// all pages. See each method's docs. pub limit: Option, - /// Search query. With it, the API ranks the results by relevance and returns a single page of + /// Search query. With a non-empty one, the API ranks the results by relevance and returns a single page of /// at most 100 items: `offset` is ignored and there is no second page. To narrow the results, /// use `category`, `username`, or `pricing_model`. pub search: Option, @@ -96,11 +96,16 @@ impl StoreCollectionClient { /// with [`with_chunk_size`](crate::ListIterator::with_chunk_size); see /// [`ListIterator`] for details. /// - /// With `options.search`, the API returns a single page of at most 100 Actors and ignores - /// `offset`, so the iterator fetches that one page and stops. `with_chunk_size` has no effect - /// then, and `options.limit` is sent as given. + /// With a non-empty `options.search`, the API returns a single page of at most 100 Actors and + /// ignores `offset`, so the iterator fetches that one page and stops. `with_chunk_size` has no + /// effect then, and `options.limit` is sent as given. pub fn iterate(&self, options: StoreListOptions) -> StoreActorIterator { - if options.search.is_none() { + // The API treats an empty search as no search, and pages through the Store as usual. + if !options + .search + .as_deref() + .is_some_and(|search| !search.is_empty()) + { return list_iterator!(self, options, list); } let client = self.clone(); diff --git a/tests/unit_http.rs b/tests/unit_http.rs index b7f0039..dcf607d 100644 --- a/tests/unit_http.rs +++ b/tests/unit_http.rs @@ -1728,6 +1728,42 @@ async fn iterating_a_store_search_fetches_a_single_page() { assert!(urls[0].contains("limit=10"), "{urls:?}"); } +/// The API treats an empty `search` as no search and pages through the Store, so the iterator +/// keeps paging instead of stopping after the first page. +#[tokio::test] +async fn iterating_an_empty_store_search_pages_normally() { + let backend = MockBackend::new(vec![ + MockOutcome::Status( + 200, + br#"{"data":{"total":4,"count":2,"items":[{"id":"a"},{"id":"b"}]}}"#.to_vec(), + ), + MockOutcome::Status( + 200, + br#"{"data":{"total":4,"count":2,"items":[{"id":"c"},{"id":"d"}]}}"#.to_vec(), + ), + MockOutcome::Status( + 200, + br#"{"data":{"total":4,"count":0,"items":[]}}"#.to_vec(), + ), + ]); + let client = client_with(backend.clone(), 0); + + let actors = client + .store() + .iterate(StoreListOptions { + search: Some(String::new()), + ..Default::default() + }) + .with_chunk_size(2) + .collect_all() + .await + .expect("ok"); + + assert_eq!(actors.len(), 4); + let urls = backend.urls(); + assert!(urls[1].contains("offset=2"), "{urls:?}"); +} + /// A streaming call retries an error status until the response starts, like a buffered call. #[tokio::test] async fn a_stream_is_retried_on_an_error_status_until_the_response_starts() { From 3ad816f4638313714a047043b19fecb18504ce55 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 15:14:05 +0000 Subject: [PATCH 4/6] refactor: reuse single_page_iterator for a Store search and tidy the docs Say non-empty search in the Store option docs and the changelog, and simplify the search check. --- CHANGELOG.md | 8 +++---- src/clients/pagination.rs | 17 ++++++++++++-- src/clients/store_collection.rs | 39 +++++++++++++-------------------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16d2570..ed5145a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,12 @@ to [Semantic Versioning](https://semver.org/). ## [0.19.0] - 2026-11-27 ### Fixed -- `StoreCollectionClient::iterate` with `search` fetches the single page the API returns and - stops, instead of repeating the same Actors. +- `StoreCollectionClient::iterate` with a non-empty `search` fetches the single page the API + returns and stops, instead of repeating the same Actors. ### Changed -- Documented the Store search, `limit`, `category`, and `sort_by` semantics on `StoreListOptions` and - in the docs, and deprecated `StoreListOptions::sort_by`, which the API ignores. +- Documented the Store search, `limit`, `category`, and `sort_by` semantics on `StoreListOptions` + and in the docs, and deprecated `StoreListOptions::sort_by`, which the API ignores. - `ActorVersionCollectionClient::create` and `ActorVersionClient::update` use the `Long` timeout tier by default, since a version can carry its source files. diff --git a/src/clients/pagination.rs b/src/clients/pagination.rs index 1690b77..e5aec6f 100644 --- a/src/clients/pagination.rs +++ b/src/clients/pagination.rs @@ -30,8 +30,8 @@ type PageFetcher = Box) -> PageFuture + Send + Syn /// Collections whose listing does not fit this shape build their iterator directly instead: /// the run listing takes a separate `filter` argument, dataset items use `list_items::`, and /// the listings that are not paginated (an Actor's versions and a version's env vars) use -/// `single_page_iterator!`. The Store listing uses this macro, except for a search, which -/// returns one page and ignores `offset`, so it builds a single-page iterator itself. +/// `single_page_iterator!`. The Store listing uses this macro, except for a non-empty search, +/// which returns one page and ignores `offset`, so it uses `single_page_iterator!` as well. macro_rules! list_iterator { ($self:expr, $options:expr, $list:ident) => {{ let client = $self.clone(); @@ -66,6 +66,19 @@ macro_rules! single_page_iterator { }, )) }}; + // A listing that takes options and ignores `offset` for some of them: `list(options)` is + // called exactly once with the caller's options as given. + ($self:expr, $options:expr, $list:ident) => {{ + let client = $self.clone(); + let options = $options; + $crate::clients::pagination::ListIterator::new_single_page(Box::new( + move |_offset, _page_limit| { + let client = client.clone(); + let options = options.clone(); + Box::pin(async move { client.$list(options).await }) + }, + )) + }}; } pub(crate) use single_page_iterator; diff --git a/src/clients/store_collection.rs b/src/clients/store_collection.rs index b7cf59a..9b9815c 100644 --- a/src/clients/store_collection.rs +++ b/src/clients/store_collection.rs @@ -1,7 +1,7 @@ //! Client for browsing the Apify Store (`/v2/store`). use crate::clients::base::{list_resource, ResourceContext}; -use crate::clients::pagination::{list_iterator, ListIterator}; +use crate::clients::pagination::{list_iterator, single_page_iterator, ListIterator}; use crate::common::{PaginationList, QueryParams}; use crate::error::ApifyClientResult; use crate::http_client::HttpClient; @@ -18,22 +18,22 @@ pub type StoreActorIterator = ListIterator; /// Options for searching the Apify Store. #[derive(Debug, Default, Clone)] pub struct StoreListOptions { - /// Number of items to skip. The API ignores it when `search` is used. + /// Number of items to skip. The API ignores it when a non-empty `search` is used. pub offset: Option, - /// Item limit. The default and the maximum are 1000. When `search` is used, they are 100, and - /// a larger value is reduced to 100. With `include_input_schema`, they are 10. Its meaning - /// depends on the method: for [`StoreCollectionClient::list`] it is a single page's size (the - /// maximum items that one call returns); for + /// Item limit. The default and the maximum are 1000. When a non-empty `search` is used, + /// they are 100, and a larger value is reduced to 100. With `include_input_schema`, they are + /// 10. Its meaning depends on the method: for [`StoreCollectionClient::list`] it is a single + /// page's size (the maximum items that one call returns); for /// [`StoreCollectionClient::iterate`] it is a cap on the *total* number of items yielded across /// all pages. See each method's docs. pub limit: Option, - /// Search query. With a non-empty one, the API ranks the results by relevance and returns a single page of - /// at most 100 items: `offset` is ignored and there is no second page. To narrow the results, - /// use `category`, `username`, or `pricing_model`. + /// Search query. With a non-empty query, the API ranks the results by relevance and returns a + /// single page of at most 100 items: `offset` is ignored and there is no second page. To + /// narrow the results, use `category`, `username`, or `pricing_model`. pub search: Option, /// Deprecated and ignored by the API, which accepts it for backward compatibility. Results - /// are ordered by relevance when `search` is used, and by Store position otherwise. Sort the - /// results on the client if you need a different order. + /// are ordered by relevance when a non-empty `search` is used, and by Store position + /// otherwise. Sort the results on the client if you need a different order. #[deprecated(note = "the API ignores `sortBy`: sort the results on the client")] pub sort_by: Option, /// Filter by category. Accepts one or more category IDs separated by commas, case-insensitive @@ -100,20 +100,11 @@ impl StoreCollectionClient { /// ignores `offset`, so the iterator fetches that one page and stops. `with_chunk_size` has no /// effect then, and `options.limit` is sent as given. pub fn iterate(&self, options: StoreListOptions) -> StoreActorIterator { - // The API treats an empty search as no search, and pages through the Store as usual. - if !options - .search - .as_deref() - .is_some_and(|search| !search.is_empty()) - { - return list_iterator!(self, options, list); + // The API treats an empty search as no search and pages through the Store as usual. + match options.search.as_deref() { + Some(search) if !search.is_empty() => single_page_iterator!(self, options, list), + _ => list_iterator!(self, options, list), } - let client = self.clone(); - ListIterator::new_single_page(Box::new(move |_offset, _page_limit| { - let client = client.clone(); - let options = options.clone(); - Box::pin(async move { client.list(options).await }) - })) } #[allow(deprecated)] // `sort_by` is deprecated, but it is still sent as the caller set it. From 5a6d22b99cb79c409f1c66fdb0c9268760a56298 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 15:16:56 +0000 Subject: [PATCH 5/6] docs: describe both arms of single_page_iterator --- src/clients/pagination.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/clients/pagination.rs b/src/clients/pagination.rs index e5aec6f..ff361f0 100644 --- a/src/clients/pagination.rs +++ b/src/clients/pagination.rs @@ -53,9 +53,11 @@ macro_rules! list_iterator { } pub(crate) use list_iterator; -/// Generates the body of the `iterate()` method of a collection whose endpoint is not -/// offset-paginated: it has a no-argument `list()` method and returns every item in one response. -/// The resulting [`ListIterator`] calls `list` exactly once and then completes. +/// Generates the body of the `iterate()` method of a collection that is read in a single request. +/// Without more arguments, the endpoint is not offset-paginated and the collection has a +/// no-argument `list()` method. With `options` and a list method name, the call is the paginated +/// `list(options)`, made for a request that ignores `offset`, such as a Store search. The +/// resulting [`ListIterator`] calls `list` exactly once and then completes. macro_rules! single_page_iterator { ($self:expr) => {{ let client = $self.clone(); @@ -66,8 +68,6 @@ macro_rules! single_page_iterator { }, )) }}; - // A listing that takes options and ignores `offset` for some of them: `list(options)` is - // called exactly once with the caller's options as given. ($self:expr, $options:expr, $list:ident) => {{ let client = $self.clone(); let options = $options; @@ -138,9 +138,9 @@ pub struct ListIterator { remaining: Option, /// Page size to request per fetch; `None` = let the API choose its default page size. chunk_size: Option, - /// When `true`, the underlying endpoint is not offset-paginated, or ignores `offset` (a Store - /// search): the first fetch returns the whole result set, so the iterator stops after it - /// rather than requesting a second page. + /// When `true`, the underlying endpoint is not offset-paginated, or ignores `offset` for the + /// request (a Store search): the first fetch returns the only page, so the iterator stops + /// after it rather than requesting a second page. single_page: bool, /// Set once the listing has been fully consumed. exhausted: bool, @@ -164,9 +164,9 @@ impl ListIterator { /// Builds an iterator over an endpoint that is **not** offset-paginated (it returns every /// item in one response, e.g. an Actor version's environment variables) or that ignores - /// `offset` for the request at hand (a Store search). `fetch` is called - /// exactly once; the iterator does not attempt a second page, so it does not depend on the - /// endpoint reporting a page `limit` and cannot refetch the same items. + /// `offset` for the request at hand (a Store search). `fetch` is called exactly once; the + /// iterator does not attempt a second page, so it does not depend on the endpoint reporting a + /// page `limit` and cannot refetch the same items. pub(crate) fn new_single_page(fetch: PageFetcher) -> Self { Self { single_page: true, From 53e9aa37a474c5777f801a774c39c923b6f1e57e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 15:19:13 +0000 Subject: [PATCH 6/6] docs: clarify the single-page branch of the list iterator --- src/clients/pagination.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/clients/pagination.rs b/src/clients/pagination.rs index ff361f0..e39c2a5 100644 --- a/src/clients/pagination.rs +++ b/src/clients/pagination.rs @@ -55,9 +55,10 @@ pub(crate) use list_iterator; /// Generates the body of the `iterate()` method of a collection that is read in a single request. /// Without more arguments, the endpoint is not offset-paginated and the collection has a -/// no-argument `list()` method. With `options` and a list method name, the call is the paginated -/// `list(options)`, made for a request that ignores `offset`, such as a Store search. The -/// resulting [`ListIterator`] calls `list` exactly once and then completes. +/// no-argument `list()` method. With `options` and a list method name, it calls `$list(options)` +/// once with the options as given (no `offset` or `limit` override), for a request that ignores +/// `offset`, such as a Store search. The resulting [`ListIterator`] calls `list` exactly once and +/// then completes. macro_rules! single_page_iterator { ($self:expr) => {{ let client = $self.clone(); @@ -238,7 +239,7 @@ impl ListIterator { // Only a page that scanned nothing, or the caller's cap, ends the walk, which costs one // extra request at the end. if self.single_page { - // Non-paginated endpoint: everything came back in one response. + // Single-page listing: the first fetch is the only page. self.exhausted = true; } else if scanned == 0 { self.exhausted = true;