apify-client 3.0.0-beta.85 → 3.0.0-beta.87

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.
@@ -4,7 +4,7 @@ import { ResourceClient } from '../base/resource_client.js';
4
4
  import * as schemas from '../schemas.js';
5
5
  import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
6
6
  import { runtime } from '#runtime';
7
- import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, SCANNED_COUNT, } from '../utils.js';
7
+ import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, } from '../utils.js';
8
8
  /**
9
9
  * Supported formats for downloading dataset items.
10
10
  */
@@ -356,21 +356,17 @@ export class DatasetClient extends ResourceClient {
356
356
  }
357
357
  #createPaginationList(response, userProvidedDesc) {
358
358
  const descHeader = response.headers['x-apify-pagination-desc'];
359
- const page = {
359
+ return {
360
360
  items: response.data,
361
361
  total: Number(response.headers['x-apify-pagination-total']),
362
362
  offset: Number(response.headers['x-apify-pagination-offset']),
363
363
  // `x-apify-pagination-count` reports the rows scanned, which filters and `unwind` can leave above or below
364
- // the items returned.
365
- count: response.data.length,
364
+ // the items returned. It is derived from the dataset's item count, which lags a fresh push, so it can also
365
+ // fall below the items returned on an unfiltered page.
366
+ count: Math.max(Number(response.headers['x-apify-pagination-count'] ?? 0), response.data.length),
366
367
  limit: Number(response.headers['x-apify-pagination-limit']), // API returns 999999999999 when no limit is used
367
368
  // TODO: Replace this once https://github.com/apify/apify-core/issues/3503 is solved
368
369
  desc: typeof descHeader === 'string' ? JSON.parse(descHeader) : userProvidedDesc,
369
370
  };
370
- const scannedCount = response.headers['x-apify-pagination-count'];
371
- if (scannedCount === undefined)
372
- return page;
373
- // The offset iterator paginates by the scanned number, so it travels with the page outside its public shape.
374
- return Object.defineProperty(page, SCANNED_COUNT, { value: Number(scannedCount) });
375
371
  }
376
372
  }
@@ -5,7 +5,7 @@ import { ResourceClient } from '../base/resource_client.js';
5
5
  import * as schemas from '../schemas.js';
6
6
  import { optionalSignalSchema, optionalTimeoutSchema, timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
7
7
  import { runtime } from '#runtime';
8
- import { anyObjectSchema, paginationOptionsShape, parseArgument, parseResponse, SCANNED_COUNT } from '../utils.js';
8
+ import { anyObjectSchema, paginationOptionsShape, parseArgument, parseResponse } from '../utils.js';
9
9
  import { DatasetClient } from './dataset.js';
10
10
  import { KeyValueStoreClient } from './key_value_store.js';
11
11
  import { LogClient, LoggerActorRedirect, StreamedLog } from './log.js';
@@ -537,7 +537,7 @@ export class RunClient extends ResourceClient {
537
537
  yield* page.items;
538
538
  // Only an empty page marks the end, as filters can shorten a full one. A page that `clean`, `skipEmpty` or
539
539
  // `unwind` emptied past a lagging `itemCount` reports no scanned rows either, so a plain read checks.
540
- const isEmpty = page.items.length === 0 && !page[SCANNED_COUNT];
540
+ const isEmpty = page.count === 0;
541
541
  if (isEmpty &&
542
542
  (!(clean || skipEmpty || unwind?.length) ||
543
543
  (await datasetClient.listItems({ offset: position, limit: 1, timeoutSecs, signal })).items
package/dist/utils.d.ts CHANGED
@@ -177,7 +177,12 @@ export interface PaginatedResponse<Data> {
177
177
  * @template Data - The type of items in the list
178
178
  */
179
179
  export interface PaginatedList<Data> extends PaginatedResponse<Data> {
180
- /** Count of dataset entries returned in this set. */
180
+ /**
181
+ * Number of entries on this page. On a page from {@link DatasetClient.listItems}, the number of dataset rows the
182
+ * API scanned for it, or the number of items returned when that is larger. Filters (`clean`, `skipEmpty`) can
183
+ * leave it above `items.length`. The next page starts at `offset + Math.min(count, limit)`; the cap matters only
184
+ * with `unwind`, which can return more items than the rows scanned.
185
+ */
181
186
  count: number;
182
187
  /** Position of the first returned entry in the dataset. */
183
188
  offset: number;
@@ -186,16 +191,6 @@ export interface PaginatedList<Data> extends PaginatedResponse<Data> {
186
191
  /** Should the results be in descending order. */
187
192
  desc: boolean;
188
193
  }
189
- /**
190
- * Key under which a page of dataset items carries the number of rows the API scanned to produce it, as a
191
- * non-enumerable property that stays out of the page's public shape. The API applies `offset` and `limit` to the
192
- * dataset's rows first and shapes the result afterwards: filters (`clean`, `skipEmpty`, `skipHidden`) drop items and
193
- * `unwind` splits or drops them, so `items.length` can land on either side of the rows scanned. The
194
- * `x-apify-pagination-count` header reports the scanned number, and the offset iterator advances and terminates by it
195
- * alone. A page without the property falls back to `items.length`.
196
- * @internal
197
- */
198
- export declare const SCANNED_COUNT: unique symbol;
199
194
  /**
200
195
  * Type representing both a Promise of a paginated list and an async iterable.
201
196
  *
package/dist/utils.js CHANGED
@@ -315,16 +315,6 @@ export const paginationOptionsShape = {
315
315
  offset: z.number().min(0).optional(),
316
316
  chunkSize: z.number().positive().optional(),
317
317
  };
318
- /**
319
- * Key under which a page of dataset items carries the number of rows the API scanned to produce it, as a
320
- * non-enumerable property that stays out of the page's public shape. The API applies `offset` and `limit` to the
321
- * dataset's rows first and shapes the result afterwards: filters (`clean`, `skipEmpty`, `skipHidden`) drop items and
322
- * `unwind` splits or drops them, so `items.length` can land on either side of the rows scanned. The
323
- * `x-apify-pagination-count` header reports the scanned number, and the offset iterator advances and terminates by it
324
- * alone. A page without the property falls back to `items.length`.
325
- * @internal
326
- */
327
- export const SCANNED_COUNT = Symbol('scannedCount');
328
318
  export function cast(input) {
329
319
  return input;
330
320
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.85",
3
+ "version": "3.0.0-beta.87",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.13.0"