apify-client 3.0.0-beta.57 → 3.0.0-beta.59

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.
@@ -297,7 +297,7 @@ export declare class ActorClient extends ResourceClient {
297
297
  /**
298
298
  * Fields that can be updated when modifying an Actor.
299
299
  */
300
- export type ActorUpdateOptions = Partial<Pick<ActorResource, 'name' | 'description' | 'isPublic' | 'isDeprecated' | 'seoTitle' | 'seoDescription' | 'title' | 'versions' | 'categories' | 'defaultRunOptions' | 'actorStandby' | 'actorPermissionLevel' | 'taggedBuilds'>>;
300
+ export type ActorUpdateOptions = Partial<Pick<ActorResource, 'name' | 'description' | 'isPublic' | 'isDeprecated' | 'seoTitle' | 'seoDescription' | 'title' | 'versions' | 'categories' | 'defaultRunOptions' | 'actorStandby' | 'actorPermissionLevel' | 'taggedBuilds' | 'pricingInfos' | 'exampleRunInput'>>;
301
301
  /**
302
302
  * Input for an Actor run, as taken by {@link ActorClient.start}, {@link ActorClient.call},
303
303
  * {@link ActorClient.validateInput} and {@link RunClient.metamorph}.
@@ -77,6 +77,8 @@ export declare class KeyValueStoreClient extends ResourceClient {
77
77
  *
78
78
  * @param options - Listing options
79
79
  * @param options.limit - Maximum number of keys to return. Default is 1000.
80
+ * @param options.chunkSize - Maximum number of keys requested per API call when iterating across pages. `limit`
81
+ * then caps the total across all pages.
80
82
  * @param options.exclusiveStartKey - Key to start listing from (for pagination). The listing starts with the next key after this one.
81
83
  * @param options.collection - Filter keys by collection name.
82
84
  * @param options.prefix - Filter keys that start with this prefix.
@@ -287,6 +289,12 @@ export interface KeyValueClientUpdateOptions {
287
289
  */
288
290
  export interface KeyValueClientListKeysOptions extends TimeoutOptions {
289
291
  limit?: number;
292
+ /**
293
+ * Maximum number of keys returned in one API response. When the call is iterated with `for await`, the iterator
294
+ * fetches keys in chunks of this size and yields them one by one, until `limit` is reached or the store has no
295
+ * more keys. Awaiting the call returns only the first chunk.
296
+ */
297
+ chunkSize?: number;
290
298
  exclusiveStartKey?: string;
291
299
  collection?: string;
292
300
  /**
@@ -301,11 +309,11 @@ export interface KeyValueClientListKeysOptions extends TimeoutOptions {
301
309
  /**
302
310
  * Options for creating a public URL to list keys in a Key-Value Store.
303
311
  *
304
- * Extends {@link KeyValueClientListKeysOptions} with URL expiration control, minus `signature` (this
305
- * method produces one).
312
+ * Extends {@link KeyValueClientListKeysOptions} with URL expiration control, minus `chunkSize` (it only sizes a
313
+ * client-side iteration) and `signature` (this method produces one).
306
314
  * @since Added in 2.16.0
307
315
  */
308
- export interface KeyValueClientCreateKeysUrlOptions extends Omit<KeyValueClientListKeysOptions, 'signature'> {
316
+ export interface KeyValueClientCreateKeysUrlOptions extends Omit<KeyValueClientListKeysOptions, 'chunkSize' | 'signature'> {
309
317
  expiresInSecs?: number;
310
318
  }
311
319
  /**
@@ -5,9 +5,10 @@ import { ResourceClient } from '../base/resource_client.js';
5
5
  import * as schemas from '../schemas.js';
6
6
  import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
7
7
  import { runtime } from '#runtime';
8
- import { anyObjectSchema, applyQueryParamsToUrl, catchNotFoundOrThrow, isBuffer, isStream, parseArgument, parseResponse, } from '../utils.js';
8
+ import { anyObjectSchema, applyQueryParamsToUrl, catchNotFoundOrThrow, isBuffer, isStream, minForLimitParam, parseArgument, parseResponse, } from '../utils.js';
9
9
  const listKeysOptionsSchema = z.strictObject({
10
10
  limit: z.number().min(0).optional(),
11
+ chunkSize: z.number().positive().optional(),
11
12
  exclusiveStartKey: z.string().optional(),
12
13
  collection: z.string().optional(),
13
14
  prefix: z.string().optional(),
@@ -15,7 +16,8 @@ const listKeysOptionsSchema = z.strictObject({
15
16
  ...timeoutOptionsShape,
16
17
  });
17
18
  const nonEmptyKeySchema = z.string().min(1);
18
- // `signature` is left out - this method produces one. The options type omits it to match.
19
+ // `chunkSize` (client-side only) and `signature` (which this method produces) are left out. The options type omits
20
+ // both to match.
19
21
  const createKeysPublicUrlOptionsSchema = z.strictObject({
20
22
  limit: z.number().min(0).optional(),
21
23
  exclusiveStartKey: z.string().optional(),
@@ -135,6 +137,8 @@ export class KeyValueStoreClient extends ResourceClient {
135
137
  *
136
138
  * @param options - Listing options
137
139
  * @param options.limit - Maximum number of keys to return. Default is 1000.
140
+ * @param options.chunkSize - Maximum number of keys requested per API call when iterating across pages. `limit`
141
+ * then caps the total across all pages.
138
142
  * @param options.exclusiveStartKey - Key to start listing from (for pagination). The listing starts with the next key after this one.
139
143
  * @param options.collection - Filter keys by collection name.
140
144
  * @param options.prefix - Filter keys that start with this prefix.
@@ -164,7 +168,8 @@ export class KeyValueStoreClient extends ResourceClient {
164
168
  * ```
165
169
  */
166
170
  listKeys(options = {}) {
167
- const { timeoutSecs = 'medium', signal, ...parsed } = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
171
+ // `chunkSize` only sizes the page requests; it is not an API parameter, so it must not reach the query string.
172
+ const { chunkSize, timeoutSecs = 'medium', signal, ...parsed } = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
168
173
  const getPaginatedList = async (kvsListOptions = {}) => {
169
174
  const response = await this.httpClient.call({
170
175
  url: this.buildUrl('keys'),
@@ -175,7 +180,7 @@ export class KeyValueStoreClient extends ResourceClient {
175
180
  });
176
181
  return parseResponse(response, schemas.ListOfKeys());
177
182
  };
178
- const paginatedListPromise = getPaginatedList(parsed);
183
+ const paginatedListPromise = getPaginatedList({ ...parsed, limit: minForLimitParam(parsed.limit, chunkSize) });
179
184
  async function* asyncGenerator() {
180
185
  let currentPage = await paginatedListPromise;
181
186
  yield* currentPage.items;
@@ -188,7 +193,7 @@ export class KeyValueStoreClient extends ResourceClient {
188
193
  ) {
189
194
  const newOptions = {
190
195
  ...parsed,
191
- limit: remainingItems,
196
+ limit: minForLimitParam(remainingItems, chunkSize),
192
197
  exclusiveStartKey: currentPage.nextExclusiveStartKey,
193
198
  };
194
199
  currentPage = await getPaginatedList(newOptions);
@@ -301,6 +301,8 @@ export declare class RequestQueueClient extends ResourceClient {
301
301
  * queue contents.
302
302
  *
303
303
  * @param options - Pagination options
304
+ * @param options.chunkSize - Maximum number of requests fetched per API call when iterating across pages. `limit`
305
+ * then caps the total across all pages.
304
306
  * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
305
307
  * @returns List of requests with pagination information
306
308
  * @see https://docs.apify.com/api/v2/request-queue-requests-get
@@ -383,6 +385,12 @@ export type RequestQueueListRequestsFilter = 'locked' | 'pending';
383
385
  */
384
386
  export interface RequestQueueClientListRequestsOptions extends TimeoutOptions {
385
387
  limit?: number;
388
+ /**
389
+ * Maximum number of requests returned in one API response. When the call is iterated with `for await`, the iterator
390
+ * fetches requests in chunks of this size and yields them one by one, until `limit` is reached or the RQ is
391
+ * exhausted. Awaiting the call returns only the first chunk.
392
+ */
393
+ chunkSize?: number;
386
394
  /**
387
395
  * @since Added in 2.23.2
388
396
  */
@@ -5,7 +5,7 @@ import { ResourceClient } from '../base/resource_client.js';
5
5
  import { ResponseValidationError } from '../response_validation_error.js';
6
6
  import * as schemas from '../schemas.js';
7
7
  import { optionalSignalSchema, optionalTimeoutSchema, timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
8
- import { anyObjectSchema, catchNotFoundOrThrow, isNonArrayObject, parseArgument, parseResponse, RequestQueuePaginationIterator, sleep, splitIntoJsonArrayBatches, utf8ByteLength, } from '../utils.js';
8
+ import { anyObjectSchema, catchNotFoundOrThrow, isNonArrayObject, minForLimitParam, parseArgument, parseResponse, RequestQueuePaginationIterator, sleep, splitIntoJsonArrayBatches, utf8ByteLength, } from '../utils.js';
9
9
  const DEFAULT_PARALLEL_BATCH_ADD_REQUESTS = 5;
10
10
  const DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS = 3;
11
11
  const DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS = 500;
@@ -39,6 +39,7 @@ const prolongRequestLockOptionsSchema = z.strictObject({
39
39
  const requestFilterSchema = z.array(z.enum(['locked', 'pending'])).min(1);
40
40
  const listRequestsOptionsSchema = z.strictObject({
41
41
  limit: z.number().min(0).optional(),
42
+ chunkSize: z.number().positive().optional(),
42
43
  cursor: z.string().optional(),
43
44
  filter: requestFilterSchema.optional(),
44
45
  ...timeoutOptionsShape,
@@ -622,15 +623,17 @@ export class RequestQueueClient extends ResourceClient {
622
623
  * queue contents.
623
624
  *
624
625
  * @param options - Pagination options
626
+ * @param options.chunkSize - Maximum number of requests fetched per API call when iterating across pages. `limit`
627
+ * then caps the total across all pages.
625
628
  * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
626
629
  * @returns List of requests with pagination information
627
630
  * @see https://docs.apify.com/api/v2/request-queue-requests-get
628
631
  * @since Added in 2.5.1
629
632
  */
630
633
  listRequests(options = {}) {
631
- // `timeoutSecs` and `signal` apply to every page request; they are not API parameters, so they must not reach
632
- // the query string.
633
- const { timeoutSecs, signal, ...parsed } = parseArgument(options, listRequestsOptionsSchema, 'RequestQueueClientListRequestsOptions');
634
+ // `chunkSize` only sizes the page requests, and `timeoutSecs` and `signal` apply to every one of them; none of
635
+ // them is an API parameter, so they must not reach the query string.
636
+ const { chunkSize, timeoutSecs, signal, ...parsed } = parseArgument(options, listRequestsOptionsSchema, 'RequestQueueClientListRequestsOptions');
634
637
  const pageTimeout = this.#resolveTimeout(timeoutSecs, 'medium');
635
638
  const getPaginatedList = async (rqListOptions = {}) => {
636
639
  const response = await this.httpClient.call({
@@ -646,7 +649,7 @@ export class RequestQueueClient extends ResourceClient {
646
649
  });
647
650
  return parseResponse(response, schemas.ListOfRequests());
648
651
  };
649
- const paginatedListPromise = getPaginatedList(parsed);
652
+ const paginatedListPromise = getPaginatedList({ ...parsed, limit: minForLimitParam(parsed.limit, chunkSize) });
650
653
  async function* asyncGenerator() {
651
654
  let currentPage = await paginatedListPromise;
652
655
  yield* currentPage.items;
@@ -659,7 +662,7 @@ export class RequestQueueClient extends ResourceClient {
659
662
  ) {
660
663
  const newOptions = {
661
664
  ...parsed,
662
- limit: remainingItems,
665
+ limit: minForLimitParam(remainingItems, chunkSize),
663
666
  cursor: currentPage.nextCursor,
664
667
  };
665
668
  currentPage = await getPaginatedList(newOptions);
package/dist/utils.d.ts CHANGED
@@ -149,6 +149,12 @@ export interface PaginationOptions {
149
149
  * */
150
150
  chunkSize?: number;
151
151
  }
152
+ /**
153
+ * The smaller of two page limits, for the `limit` query parameter. The API treats a `limit` of 0 as unset, so 0 here
154
+ * means no limit and loses to any other value.
155
+ * @internal
156
+ */
157
+ export declare function minForLimitParam(a: number | undefined, b: number | undefined): number | undefined;
152
158
  /**
153
159
  * Schema shape of {@link PaginationOptions}, to spread into every paginating client's list schema. One
154
160
  * copy stops it drifting from the interface.
package/dist/utils.js CHANGED
@@ -288,6 +288,22 @@ export class RequestQueuePaginationIterator {
288
288
  }
289
289
  }
290
290
  }
291
+ /**
292
+ * The smaller of two page limits, for the `limit` query parameter. The API treats a `limit` of 0 as unset, so 0 here
293
+ * means no limit and loses to any other value.
294
+ * @internal
295
+ */
296
+ export function minForLimitParam(a, b) {
297
+ if (a === 0)
298
+ a = undefined;
299
+ if (b === 0)
300
+ b = undefined;
301
+ if (a === undefined)
302
+ return b;
303
+ if (b === undefined)
304
+ return a;
305
+ return Math.min(a, b);
306
+ }
291
307
  /**
292
308
  * Schema shape of {@link PaginationOptions}, to spread into every paginating client's list schema. One
293
309
  * copy stops it drifting from the interface.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.57",
3
+ "version": "3.0.0-beta.59",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.13.0"