apify-client 3.0.0-beta.16 → 3.0.0-beta.17
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/apify_api_error.d.ts +4 -19
- package/dist/apify_api_error.js +10 -25
- package/dist/apify_client.d.ts +1 -1
- package/dist/apify_client.js +24 -24
- package/dist/bundle.js +7 -7
- package/dist/bundle.js.map +1 -1
- package/dist/http_client.d.ts +1 -55
- package/dist/http_client.js +32 -33
- package/dist/resource_clients/dataset.d.ts +1 -1
- package/dist/resource_clients/dataset.js +2 -2
- package/dist/resource_clients/log.d.ts +1 -16
- package/dist/resource_clients/log.js +31 -31
- package/dist/resource_clients/request_queue.d.ts +1 -7
- package/dist/resource_clients/request_queue.js +33 -33
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/utils.d.ts +1 -4
- package/dist/utils.js +14 -14
- package/package.json +1 -1
|
@@ -82,8 +82,8 @@ const paginateRequestsOptionsSchema = z.strictObject({
|
|
|
82
82
|
* @see https://docs.apify.com/platform/storage/request-queue
|
|
83
83
|
*/
|
|
84
84
|
export class RequestQueueClient extends ResourceClient {
|
|
85
|
-
clientKey;
|
|
86
|
-
timeoutSecs;
|
|
85
|
+
#clientKey;
|
|
86
|
+
#timeoutSecs;
|
|
87
87
|
/**
|
|
88
88
|
* @hidden
|
|
89
89
|
*/
|
|
@@ -92,20 +92,20 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
92
92
|
resourcePath: 'request-queues',
|
|
93
93
|
...options,
|
|
94
94
|
});
|
|
95
|
-
this
|
|
96
|
-
this
|
|
95
|
+
this.#clientKey = userOptions.clientKey;
|
|
96
|
+
this.#timeoutSecs = userOptions.timeoutSecs;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Picks the timeout of a request: an explicit per-call `timeoutSecs` as is, otherwise the method's default
|
|
100
100
|
* tier, capped at the queue-wide `timeoutSecs` when one was given.
|
|
101
101
|
*/
|
|
102
|
-
resolveTimeout(timeoutSecs, defaultTier) {
|
|
102
|
+
#resolveTimeout(timeoutSecs, defaultTier) {
|
|
103
103
|
if (timeoutSecs !== undefined)
|
|
104
104
|
return timeoutSecs;
|
|
105
|
-
if (this
|
|
105
|
+
if (this.#timeoutSecs === undefined)
|
|
106
106
|
return defaultTier;
|
|
107
107
|
const tierSecs = this.httpClient.timeoutMillis[defaultTier] / 1000;
|
|
108
|
-
return tierSecs <= this
|
|
108
|
+
return tierSecs <= this.#timeoutSecs ? defaultTier : this.#timeoutSecs;
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* Gets the Request queue object from the Apify API.
|
|
@@ -117,7 +117,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
117
117
|
*/
|
|
118
118
|
async get(options = {}) {
|
|
119
119
|
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
120
|
-
return this.getResource(schemas.RequestQueue(), {}, this
|
|
120
|
+
return this.getResource(schemas.RequestQueue(), {}, this.#resolveTimeout(timeoutSecs, 'short'));
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* Updates the Request queue with specified fields.
|
|
@@ -131,7 +131,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
131
131
|
async update(newFields, options = {}) {
|
|
132
132
|
parseArgument(newFields, anyObjectSchema);
|
|
133
133
|
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
134
|
-
return this.updateResource(schemas.RequestQueue(), newFields, this
|
|
134
|
+
return this.updateResource(schemas.RequestQueue(), newFields, this.#resolveTimeout(timeoutSecs, 'short'));
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Deletes the Request queue.
|
|
@@ -142,7 +142,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
142
142
|
*/
|
|
143
143
|
async delete(options = {}) {
|
|
144
144
|
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
145
|
-
return this.deleteResource(this
|
|
145
|
+
return this.deleteResource(this.#resolveTimeout(timeoutSecs, 'short'));
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Lists requests from the beginning of the queue (head).
|
|
@@ -161,10 +161,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
161
161
|
const response = await this.httpClient.call({
|
|
162
162
|
url: this.buildUrl('head'),
|
|
163
163
|
method: 'GET',
|
|
164
|
-
timeoutSecs: this
|
|
164
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
165
165
|
params: this.buildParams({
|
|
166
166
|
limit: parsed.limit,
|
|
167
|
-
clientKey: this
|
|
167
|
+
clientKey: this.#clientKey,
|
|
168
168
|
}),
|
|
169
169
|
});
|
|
170
170
|
return parseResponse(response, schemas.RequestQueueHead());
|
|
@@ -208,11 +208,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
208
208
|
const response = await this.httpClient.call({
|
|
209
209
|
url: this.buildUrl('head/lock'),
|
|
210
210
|
method: 'POST',
|
|
211
|
-
timeoutSecs: this
|
|
211
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
212
212
|
params: this.buildParams({
|
|
213
213
|
limit: parsed.limit,
|
|
214
214
|
lockSecs: parsed.lockSecs,
|
|
215
|
-
clientKey: this
|
|
215
|
+
clientKey: this.#clientKey,
|
|
216
216
|
}),
|
|
217
217
|
});
|
|
218
218
|
return parseResponse(response, schemas.LockedRequestQueueHead());
|
|
@@ -262,11 +262,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
262
262
|
const response = await this.httpClient.call({
|
|
263
263
|
url: this.buildUrl('requests'),
|
|
264
264
|
method: 'POST',
|
|
265
|
-
timeoutSecs: this
|
|
265
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
266
266
|
data: request,
|
|
267
267
|
params: this.buildParams({
|
|
268
268
|
forefront: parsed.forefront,
|
|
269
|
-
clientKey: this
|
|
269
|
+
clientKey: this.#clientKey,
|
|
270
270
|
}),
|
|
271
271
|
});
|
|
272
272
|
return parseResponse(response, schemas.RequestRegistration());
|
|
@@ -282,11 +282,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
282
282
|
const response = await this.httpClient.call({
|
|
283
283
|
url: this.buildUrl('requests/batch'),
|
|
284
284
|
method: 'POST',
|
|
285
|
-
timeoutSecs: this
|
|
285
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
286
286
|
data: requests,
|
|
287
287
|
params: this.buildParams({
|
|
288
288
|
forefront: parsed.forefront,
|
|
289
|
-
clientKey: this
|
|
289
|
+
clientKey: this.#clientKey,
|
|
290
290
|
}),
|
|
291
291
|
});
|
|
292
292
|
return parseResponse(response, schemas.BatchAddResult());
|
|
@@ -444,10 +444,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
444
444
|
const response = await this.httpClient.call({
|
|
445
445
|
url: this.buildUrl('requests/batch'),
|
|
446
446
|
method: 'DELETE',
|
|
447
|
-
timeoutSecs: this
|
|
447
|
+
timeoutSecs: this.#resolveTimeout(timeoutSecs, 'short'),
|
|
448
448
|
data: requests,
|
|
449
449
|
params: this.buildParams({
|
|
450
|
-
clientKey: this
|
|
450
|
+
clientKey: this.#clientKey,
|
|
451
451
|
}),
|
|
452
452
|
});
|
|
453
453
|
return parseResponse(response, schemas.BatchDeleteResult());
|
|
@@ -467,7 +467,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
467
467
|
const requestOpts = {
|
|
468
468
|
url: this.buildUrl(['requests', id]),
|
|
469
469
|
method: 'GET',
|
|
470
|
-
timeoutSecs: this
|
|
470
|
+
timeoutSecs: this.#resolveTimeout(timeoutSecs, 'short'),
|
|
471
471
|
params: this.buildParams(),
|
|
472
472
|
};
|
|
473
473
|
try {
|
|
@@ -495,11 +495,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
495
495
|
const response = await this.httpClient.call({
|
|
496
496
|
url: this.buildUrl(['requests', request.id]),
|
|
497
497
|
method: 'PUT',
|
|
498
|
-
timeoutSecs: this
|
|
498
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
499
499
|
data: request,
|
|
500
500
|
params: this.buildParams({
|
|
501
501
|
forefront: parsed.forefront,
|
|
502
|
-
clientKey: this
|
|
502
|
+
clientKey: this.#clientKey,
|
|
503
503
|
}),
|
|
504
504
|
});
|
|
505
505
|
return parseResponse(response, schemas.RequestRegistration());
|
|
@@ -517,9 +517,9 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
517
517
|
await this.httpClient.call({
|
|
518
518
|
url: this.buildUrl(['requests', id]),
|
|
519
519
|
method: 'DELETE',
|
|
520
|
-
timeoutSecs: this
|
|
520
|
+
timeoutSecs: this.#resolveTimeout(timeoutSecs, 'short'),
|
|
521
521
|
params: this.buildParams({
|
|
522
|
-
clientKey: this
|
|
522
|
+
clientKey: this.#clientKey,
|
|
523
523
|
}),
|
|
524
524
|
});
|
|
525
525
|
}
|
|
@@ -555,11 +555,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
555
555
|
const response = await this.httpClient.call({
|
|
556
556
|
url: this.buildUrl(['requests', id, 'lock']),
|
|
557
557
|
method: 'PUT',
|
|
558
|
-
timeoutSecs: this
|
|
558
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
559
559
|
params: this.buildParams({
|
|
560
560
|
forefront: parsed.forefront,
|
|
561
561
|
lockSecs: parsed.lockSecs,
|
|
562
|
-
clientKey: this
|
|
562
|
+
clientKey: this.#clientKey,
|
|
563
563
|
}),
|
|
564
564
|
});
|
|
565
565
|
return parseResponse(response, schemas.RequestLockInfo());
|
|
@@ -583,10 +583,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
583
583
|
await this.httpClient.call({
|
|
584
584
|
url: this.buildUrl(['requests', id, 'lock']),
|
|
585
585
|
method: 'DELETE',
|
|
586
|
-
timeoutSecs: this
|
|
586
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
587
587
|
params: this.buildParams({
|
|
588
588
|
forefront: parsed.forefront,
|
|
589
|
-
clientKey: this
|
|
589
|
+
clientKey: this.#clientKey,
|
|
590
590
|
}),
|
|
591
591
|
});
|
|
592
592
|
}
|
|
@@ -605,7 +605,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
605
605
|
listRequests(options = {}) {
|
|
606
606
|
// `timeoutSecs` times every page request; it is not an API parameter, so it must not reach the query string.
|
|
607
607
|
const { timeoutSecs, ...parsed } = parseArgument(options, listRequestsOptionsSchema, 'RequestQueueClientListRequestsOptions');
|
|
608
|
-
const pageTimeout = this
|
|
608
|
+
const pageTimeout = this.#resolveTimeout(timeoutSecs, 'medium');
|
|
609
609
|
const getPaginatedList = async (rqListOptions = {}) => {
|
|
610
610
|
const response = await this.httpClient.call({
|
|
611
611
|
url: this.buildUrl('requests'),
|
|
@@ -614,7 +614,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
614
614
|
params: this.buildParams({
|
|
615
615
|
...rqListOptions,
|
|
616
616
|
filter: rqListOptions.filter ? rqListOptions.filter.join(',') : undefined,
|
|
617
|
-
clientKey: this
|
|
617
|
+
clientKey: this.#clientKey,
|
|
618
618
|
}),
|
|
619
619
|
});
|
|
620
620
|
return parseResponse(response, schemas.ListOfRequests());
|
|
@@ -663,9 +663,9 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
663
663
|
const response = await this.httpClient.call({
|
|
664
664
|
url: this.buildUrl('requests/unlock'),
|
|
665
665
|
method: 'POST',
|
|
666
|
-
timeoutSecs: this
|
|
666
|
+
timeoutSecs: this.#resolveTimeout(timeoutSecs, 'long'),
|
|
667
667
|
params: this.buildParams({
|
|
668
|
-
clientKey: this
|
|
668
|
+
clientKey: this.#clientKey,
|
|
669
669
|
}),
|
|
670
670
|
});
|
|
671
671
|
return parseResponse(response, schemas.UnlockRequestsResult());
|
package/dist/statistics.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare class Statistics {
|
|
2
|
+
#private;
|
|
2
3
|
/**
|
|
3
4
|
* Number of Apify client function calls
|
|
4
5
|
*/
|
|
@@ -13,10 +14,4 @@ export declare class Statistics {
|
|
|
13
14
|
*/
|
|
14
15
|
rateLimitErrors: number[];
|
|
15
16
|
addRateLimitError(attempt: number): void;
|
|
16
|
-
/**
|
|
17
|
-
* Removes the necessity to pre-initialize array with correct
|
|
18
|
-
* number of zeroes by dynamically filling the empty indexes
|
|
19
|
-
* when necessary.
|
|
20
|
-
*/
|
|
21
|
-
private _fillBlanksWithZeroes;
|
|
22
17
|
}
|
package/dist/statistics.js
CHANGED
|
@@ -20,7 +20,7 @@ export class Statistics {
|
|
|
20
20
|
// attempt is never 0,
|
|
21
21
|
// but we don't want index 0 empty
|
|
22
22
|
const index = attempt - 1;
|
|
23
|
-
this
|
|
23
|
+
this.#fillBlanksWithZeroes(index);
|
|
24
24
|
this.rateLimitErrors[index]++;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -28,7 +28,7 @@ export class Statistics {
|
|
|
28
28
|
* number of zeroes by dynamically filling the empty indexes
|
|
29
29
|
* when necessary.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
#fillBlanksWithZeroes(inclusiveIndex) {
|
|
32
32
|
if (this.rateLimitErrors.length <= inclusiveIndex) {
|
|
33
33
|
for (let k = 0; k <= inclusiveIndex; k++) {
|
|
34
34
|
if (typeof this.rateLimitErrors[k] !== 'number') {
|
package/dist/utils.d.ts
CHANGED
|
@@ -108,10 +108,7 @@ export declare function getVersionData(): {
|
|
|
108
108
|
* Helper class to create async iterators from paginated list endpoints.
|
|
109
109
|
*/
|
|
110
110
|
export declare class RequestQueuePaginationIterator {
|
|
111
|
-
private
|
|
112
|
-
private readonly getPage;
|
|
113
|
-
private readonly limit?;
|
|
114
|
-
private readonly cursor?;
|
|
111
|
+
#private;
|
|
115
112
|
constructor(options: RequestQueuePaginationIteratorOptions);
|
|
116
113
|
[Symbol.asyncIterator](): AsyncIterator<RequestQueueClientListRequestsResult>;
|
|
117
114
|
}
|
package/dist/utils.js
CHANGED
|
@@ -314,24 +314,24 @@ export function getVersionData() {
|
|
|
314
314
|
* Helper class to create async iterators from paginated list endpoints.
|
|
315
315
|
*/
|
|
316
316
|
export class RequestQueuePaginationIterator {
|
|
317
|
-
maxPageLimit;
|
|
318
|
-
getPage;
|
|
319
|
-
limit;
|
|
320
|
-
cursor;
|
|
317
|
+
#maxPageLimit;
|
|
318
|
+
#getPage;
|
|
319
|
+
#limit;
|
|
320
|
+
#cursor;
|
|
321
321
|
constructor(options) {
|
|
322
|
-
this
|
|
323
|
-
this
|
|
324
|
-
this
|
|
325
|
-
this
|
|
322
|
+
this.#maxPageLimit = options.maxPageLimit;
|
|
323
|
+
this.#limit = options.limit;
|
|
324
|
+
this.#cursor = options.cursor;
|
|
325
|
+
this.#getPage = options.getPage;
|
|
326
326
|
}
|
|
327
327
|
async *[Symbol.asyncIterator]() {
|
|
328
|
-
let nextCursor = this
|
|
328
|
+
let nextCursor = this.#cursor;
|
|
329
329
|
let iterateItemCount = 0;
|
|
330
330
|
while (true) {
|
|
331
|
-
const pageLimit = this
|
|
332
|
-
? Math.min(this
|
|
333
|
-
: this
|
|
334
|
-
const page = await this
|
|
331
|
+
const pageLimit = this.#limit
|
|
332
|
+
? Math.min(this.#maxPageLimit, this.#limit - iterateItemCount)
|
|
333
|
+
: this.#maxPageLimit;
|
|
334
|
+
const page = await this.#getPage({
|
|
335
335
|
limit: pageLimit,
|
|
336
336
|
cursor: nextCursor,
|
|
337
337
|
});
|
|
@@ -341,7 +341,7 @@ export class RequestQueuePaginationIterator {
|
|
|
341
341
|
yield page;
|
|
342
342
|
iterateItemCount += page.items.length;
|
|
343
343
|
// Limit reached stopping to iterate
|
|
344
|
-
if ((this
|
|
344
|
+
if ((this.#limit && iterateItemCount >= this.#limit) || !page.nextCursor)
|
|
345
345
|
return;
|
|
346
346
|
nextCursor = page.nextCursor;
|
|
347
347
|
}
|