apify-client 3.0.0-beta.6 → 3.0.0-beta.8
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.
- package/dist/bundle.js +13 -13
- package/dist/bundle.js.map +1 -1
- package/dist/generated/schemas.d.ts +53 -53
- package/dist/generated/schemas.js +17 -17
- package/dist/resource_clients/actor_collection.d.ts +0 -2
- package/dist/resource_clients/actor_env_var_collection.d.ts +8 -17
- package/dist/resource_clients/actor_env_var_collection.js +7 -8
- package/dist/resource_clients/actor_version_collection.d.ts +8 -16
- package/dist/resource_clients/actor_version_collection.js +7 -8
- package/dist/resource_clients/request_queue.d.ts +0 -7
- package/dist/resource_clients/request_queue.js +6 -15
- package/dist/utils.d.ts +4 -11
- package/dist/utils.js +4 -18
- package/package.json +1 -1
|
@@ -346,11 +346,6 @@ export type RequestQueueListRequestsFilter = 'locked' | 'pending';
|
|
|
346
346
|
*/
|
|
347
347
|
export interface RequestQueueClientListRequestsOptions {
|
|
348
348
|
limit?: number;
|
|
349
|
-
/**
|
|
350
|
-
* Using id of request that does not exist in request queue leads to unpredictable results.
|
|
351
|
-
* @deprecated Use `cursor` for pagination instead.
|
|
352
|
-
*/
|
|
353
|
-
exclusiveStartId?: string;
|
|
354
349
|
/**
|
|
355
350
|
* @since Added in 2.23.2
|
|
356
351
|
*/
|
|
@@ -367,8 +362,6 @@ export interface RequestQueueClientListRequestsOptions {
|
|
|
367
362
|
export interface RequestQueueClientPaginateRequestsOptions {
|
|
368
363
|
limit?: number;
|
|
369
364
|
maxPageLimit?: number;
|
|
370
|
-
/** @deprecated Use `cursor` for pagination instead. */
|
|
371
|
-
exclusiveStartId?: string;
|
|
372
365
|
/**
|
|
373
366
|
* @since Added in 2.23.2
|
|
374
367
|
*/
|
|
@@ -4,7 +4,7 @@ import log from '@apify/log';
|
|
|
4
4
|
import { MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS } from '../base/resource_client.js';
|
|
5
5
|
import { ResponseValidationError } from '../response_validation_error.js';
|
|
6
6
|
import * as schemas from '../schemas.js';
|
|
7
|
-
import { anyObjectSchema, cast, catchNotFoundOrThrow, isNonArrayObject,
|
|
7
|
+
import { anyObjectSchema, cast, catchNotFoundOrThrow, isNonArrayObject, parseArgument, parseDateFields, parseResponse, RequestQueuePaginationIterator, sliceArrayByByteLength, } from '../utils.js';
|
|
8
8
|
const DEFAULT_PARALLEL_BATCH_ADD_REQUESTS = 5;
|
|
9
9
|
const DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS = 3;
|
|
10
10
|
const DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS = 500;
|
|
@@ -35,23 +35,17 @@ const prolongRequestLockOptionsSchema = z.strictObject({
|
|
|
35
35
|
forefront: z.boolean().optional(),
|
|
36
36
|
});
|
|
37
37
|
const requestFilterSchema = z.array(z.enum(['locked', 'pending'])).min(1);
|
|
38
|
-
const listRequestsOptionsSchema = z
|
|
39
|
-
.strictObject({
|
|
38
|
+
const listRequestsOptionsSchema = z.strictObject({
|
|
40
39
|
limit: z.number().min(0).optional(),
|
|
41
|
-
exclusiveStartId: z.string().optional(),
|
|
42
40
|
cursor: z.string().optional(),
|
|
43
41
|
filter: requestFilterSchema.optional(),
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const paginateRequestsOptionsSchema = z
|
|
47
|
-
.strictObject({
|
|
42
|
+
});
|
|
43
|
+
const paginateRequestsOptionsSchema = z.strictObject({
|
|
48
44
|
limit: z.number().min(0).optional(),
|
|
49
45
|
maxPageLimit: z.number().default(DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT),
|
|
50
|
-
exclusiveStartId: z.string().optional(),
|
|
51
46
|
cursor: z.string().optional(),
|
|
52
47
|
filter: requestFilterSchema.optional(),
|
|
53
|
-
})
|
|
54
|
-
.refine(...mutuallyExclusive('exclusiveStartId', 'cursor'));
|
|
48
|
+
});
|
|
55
49
|
/**
|
|
56
50
|
* Client for managing a specific Request queue.
|
|
57
51
|
*
|
|
@@ -589,8 +583,6 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
589
583
|
const newOptions = {
|
|
590
584
|
...parsed,
|
|
591
585
|
limit: remainingItems,
|
|
592
|
-
// remove original exclusiveStartId, if there was any, and use cursor-based pagination
|
|
593
|
-
exclusiveStartId: undefined,
|
|
594
586
|
cursor: currentPage.nextCursor,
|
|
595
587
|
};
|
|
596
588
|
currentPage = await getPaginatedList(newOptions);
|
|
@@ -644,11 +636,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
644
636
|
* @since Added in 2.5.1
|
|
645
637
|
*/
|
|
646
638
|
paginateRequests(options = {}) {
|
|
647
|
-
const { limit,
|
|
639
|
+
const { limit, cursor, filter, maxPageLimit } = parseArgument(options, paginateRequestsOptionsSchema, 'RequestQueueClientPaginateRequestsOptions');
|
|
648
640
|
return new RequestQueuePaginationIterator({
|
|
649
641
|
getPage: async (pageOptions) => this.listRequests({ ...pageOptions, filter }),
|
|
650
642
|
limit,
|
|
651
|
-
exclusiveStartId,
|
|
652
643
|
cursor,
|
|
653
644
|
maxPageLimit,
|
|
654
645
|
});
|
package/dist/utils.d.ts
CHANGED
|
@@ -30,8 +30,9 @@ export interface MaybeData<R> {
|
|
|
30
30
|
/**
|
|
31
31
|
* Turns a JSON API response into the value a resource method returns: unwraps the `data` envelope, converts the
|
|
32
32
|
* date fields and validates the result against `schema`, one of the schemas generated from the OpenAPI
|
|
33
|
-
* specification. The validated copy is what callers get, so it is
|
|
34
|
-
*
|
|
33
|
+
* specification. The validated copy is what callers get, so it is the schema's output -- unknown fields and unknown
|
|
34
|
+
* enum values included, since the schemas let both through, and URL fields normalized, since `z.url()` hands back
|
|
35
|
+
* the parsed URL's serialization.
|
|
35
36
|
*
|
|
36
37
|
* Throws {@link ResponseValidationError} when the response does not match the specification.
|
|
37
38
|
* @internal
|
|
@@ -86,13 +87,12 @@ export declare function getVersionData(): {
|
|
|
86
87
|
version: string;
|
|
87
88
|
};
|
|
88
89
|
/**
|
|
89
|
-
* Helper class to create async iterators from paginated list endpoints
|
|
90
|
+
* Helper class to create async iterators from paginated list endpoints.
|
|
90
91
|
*/
|
|
91
92
|
export declare class RequestQueuePaginationIterator {
|
|
92
93
|
private readonly maxPageLimit;
|
|
93
94
|
private readonly getPage;
|
|
94
95
|
private readonly limit?;
|
|
95
|
-
private readonly exclusiveStartId?;
|
|
96
96
|
private readonly cursor?;
|
|
97
97
|
constructor(options: RequestQueuePaginationIteratorOptions);
|
|
98
98
|
[Symbol.asyncIterator](): AsyncIterator<RequestQueueClientListRequestsResult>;
|
|
@@ -108,7 +108,6 @@ export interface RequestQueuePaginationIteratorOptions {
|
|
|
108
108
|
maxPageLimit: number;
|
|
109
109
|
getPage: (opts: RequestQueueClientListRequestsOptions) => Promise<RequestQueueClientListRequestsResult>;
|
|
110
110
|
limit?: number;
|
|
111
|
-
exclusiveStartId?: string;
|
|
112
111
|
cursor?: string;
|
|
113
112
|
}
|
|
114
113
|
/**
|
|
@@ -195,12 +194,6 @@ export type DistributiveOptional<T, K extends keyof T> = T extends any ? Omit<T,
|
|
|
195
194
|
* Adds query parameters to a given URL based on the provided options object.
|
|
196
195
|
*/
|
|
197
196
|
export declare function applyQueryParamsToUrl(url: URL, options?: Record<string, string | number | boolean | string[] | undefined>): URL;
|
|
198
|
-
/**
|
|
199
|
-
* Builds a `[check, message]` pair to spread into `.refine()`, asserting that at most one of `keys`
|
|
200
|
-
* is present. Pass the options interface as `T`, so that a misspelled key is a type error.
|
|
201
|
-
* @internal
|
|
202
|
-
*/
|
|
203
|
-
export declare const mutuallyExclusive: <T extends object>(...keys: (keyof T & string)[]) => [(value: T) => boolean, string];
|
|
204
197
|
/**
|
|
205
198
|
* Percent-encodes a caller-supplied URL path segment so it cannot restructure the request path.
|
|
206
199
|
*
|
package/dist/utils.js
CHANGED
|
@@ -29,8 +29,9 @@ const { localeError } = z.locales.en();
|
|
|
29
29
|
/**
|
|
30
30
|
* Turns a JSON API response into the value a resource method returns: unwraps the `data` envelope, converts the
|
|
31
31
|
* date fields and validates the result against `schema`, one of the schemas generated from the OpenAPI
|
|
32
|
-
* specification. The validated copy is what callers get, so it is
|
|
33
|
-
*
|
|
32
|
+
* specification. The validated copy is what callers get, so it is the schema's output -- unknown fields and unknown
|
|
33
|
+
* enum values included, since the schemas let both through, and URL fields normalized, since `z.url()` hands back
|
|
34
|
+
* the parsed URL's serialization.
|
|
34
35
|
*
|
|
35
36
|
* Throws {@link ResponseValidationError} when the response does not match the specification.
|
|
36
37
|
* @internal
|
|
@@ -231,25 +232,21 @@ export function getVersionData() {
|
|
|
231
232
|
return packageJson;
|
|
232
233
|
}
|
|
233
234
|
/**
|
|
234
|
-
* Helper class to create async iterators from paginated list endpoints
|
|
235
|
+
* Helper class to create async iterators from paginated list endpoints.
|
|
235
236
|
*/
|
|
236
237
|
export class RequestQueuePaginationIterator {
|
|
237
238
|
maxPageLimit;
|
|
238
239
|
getPage;
|
|
239
240
|
limit;
|
|
240
|
-
exclusiveStartId;
|
|
241
241
|
cursor;
|
|
242
242
|
constructor(options) {
|
|
243
243
|
this.maxPageLimit = options.maxPageLimit;
|
|
244
244
|
this.limit = options.limit;
|
|
245
|
-
this.exclusiveStartId = options.exclusiveStartId;
|
|
246
245
|
this.cursor = options.cursor;
|
|
247
246
|
this.getPage = options.getPage;
|
|
248
247
|
}
|
|
249
248
|
async *[Symbol.asyncIterator]() {
|
|
250
249
|
let nextCursor = this.cursor;
|
|
251
|
-
// allow using exclusiveStartId for the first page, but then we'll delete it to avoid using it for any later page
|
|
252
|
-
let nextExclusiveStartId = this.exclusiveStartId;
|
|
253
250
|
let iterateItemCount = 0;
|
|
254
251
|
while (true) {
|
|
255
252
|
const pageLimit = this.limit
|
|
@@ -258,7 +255,6 @@ export class RequestQueuePaginationIterator {
|
|
|
258
255
|
const page = await this.getPage({
|
|
259
256
|
limit: pageLimit,
|
|
260
257
|
cursor: nextCursor,
|
|
261
|
-
exclusiveStartId: nextExclusiveStartId,
|
|
262
258
|
});
|
|
263
259
|
// There are no more pages to iterate
|
|
264
260
|
if (page.items.length === 0)
|
|
@@ -269,7 +265,6 @@ export class RequestQueuePaginationIterator {
|
|
|
269
265
|
if ((this.limit && iterateItemCount >= this.limit) || !page.nextCursor)
|
|
270
266
|
return;
|
|
271
267
|
nextCursor = page.nextCursor;
|
|
272
|
-
nextExclusiveStartId = undefined; // see comment above - delete it for any page after the first one, and paginate with cursor
|
|
273
268
|
}
|
|
274
269
|
}
|
|
275
270
|
}
|
|
@@ -309,15 +304,6 @@ export function applyQueryParamsToUrl(url, options) {
|
|
|
309
304
|
}
|
|
310
305
|
return url;
|
|
311
306
|
}
|
|
312
|
-
/**
|
|
313
|
-
* Builds a `[check, message]` pair to spread into `.refine()`, asserting that at most one of `keys`
|
|
314
|
-
* is present. Pass the options interface as `T`, so that a misspelled key is a type error.
|
|
315
|
-
* @internal
|
|
316
|
-
*/
|
|
317
|
-
export const mutuallyExclusive = (...keys) => [
|
|
318
|
-
(value) => keys.filter((key) => typeof value[key] !== 'undefined').length <= 1,
|
|
319
|
-
`At most one of the following fields is allowed: ${keys.join(', ')}`,
|
|
320
|
-
];
|
|
321
307
|
const pathSegmentSchema = z
|
|
322
308
|
.string()
|
|
323
309
|
.nonempty()
|