apify-client 3.0.0-beta.14 → 3.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { createStorageContentSignatureAsync } from '@apify/utilities';
3
3
  import { DEFAULT_TIMEOUT_MILLIS, MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS, } from '../base/resource_client.js';
4
4
  import * as schemas from '../schemas.js';
5
- import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, } from '../utils.js';
5
+ import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, SCANNED_COUNT, } from '../utils.js';
6
6
  // A predicate, not a `z.object()` arm, which would walk and copy every key of every pushed item.
7
7
  const itemSchema = z.custom(isNonArrayObject, 'Expected an object');
8
8
  const listItemsOptionsSchema = z.strictObject({
@@ -350,15 +350,21 @@ export class DatasetClient extends ResourceClient {
350
350
  return createdItemsPublicUrl.toString();
351
351
  }
352
352
  _createPaginationList(response, userProvidedDesc) {
353
- return {
353
+ const page = {
354
354
  items: response.data,
355
355
  total: Number(response.headers['x-apify-pagination-total']),
356
356
  offset: Number(response.headers['x-apify-pagination-offset']),
357
- count: response.data.length, // because x-apify-pagination-count returns invalid values when hidden/empty items are skipped
357
+ // `x-apify-pagination-count` reports the rows scanned, which filters and `unwind` can leave above or below
358
+ // the items returned.
359
+ count: response.data.length,
358
360
  limit: Number(response.headers['x-apify-pagination-limit']), // API returns 999999999999 when no limit is used
359
361
  // TODO: Replace this once https://github.com/apify/apify-core/issues/3503 is solved
360
362
  desc: JSON.parse(response.headers['x-apify-pagination-desc'] ?? userProvidedDesc),
361
363
  };
364
+ // The offset iterator paginates by the scanned number, so it travels with the page outside its public shape.
365
+ return Object.defineProperty(page, SCANNED_COUNT, {
366
+ value: Number(response.headers['x-apify-pagination-count']) || 0,
367
+ });
362
368
  }
363
369
  }
364
370
  /**
package/dist/utils.d.ts CHANGED
@@ -184,6 +184,16 @@ export interface PaginatedList<Data> extends PaginatedResponse<Data> {
184
184
  /** Should the results be in descending order. */
185
185
  desc: boolean;
186
186
  }
187
+ /**
188
+ * Key under which a page of dataset items carries the number of rows the API scanned to produce it, as a
189
+ * non-enumerable property that stays out of the page's public shape. The API applies `offset` and `limit` to the
190
+ * dataset's rows first and shapes the result afterwards: filters (`clean`, `skipEmpty`, `skipHidden`) drop items and
191
+ * `unwind` splits or drops them, so `items.length` can land on either side of the rows scanned. The
192
+ * `x-apify-pagination-count` header reports the scanned number, and the offset iterator advances and terminates by it
193
+ * alone. A page without the property falls back to `items.length`.
194
+ * @internal
195
+ */
196
+ export declare const SCANNED_COUNT: unique symbol;
187
197
  /**
188
198
  * Type representing both a Promise of a paginated list and an async iterable.
189
199
  *
package/dist/utils.js CHANGED
@@ -357,6 +357,16 @@ export const paginationOptionsShape = {
357
357
  offset: z.number().min(0).optional(),
358
358
  chunkSize: z.number().positive().optional(),
359
359
  };
360
+ /**
361
+ * Key under which a page of dataset items carries the number of rows the API scanned to produce it, as a
362
+ * non-enumerable property that stays out of the page's public shape. The API applies `offset` and `limit` to the
363
+ * dataset's rows first and shapes the result afterwards: filters (`clean`, `skipEmpty`, `skipHidden`) drop items and
364
+ * `unwind` splits or drops them, so `items.length` can land on either side of the rows scanned. The
365
+ * `x-apify-pagination-count` header reports the scanned number, and the offset iterator advances and terminates by it
366
+ * alone. A page without the property falls back to `items.length`.
367
+ * @internal
368
+ */
369
+ export const SCANNED_COUNT = Symbol('scannedCount');
360
370
  export function cast(input) {
361
371
  return input;
362
372
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.14",
3
+ "version": "3.0.0-beta.15",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"