@crawlee/core 4.0.0-beta.8 → 4.0.0-beta.81

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.
Files changed (257) hide show
  1. package/README.md +17 -13
  2. package/autoscaling/autoscaled_pool.d.ts +14 -15
  3. package/autoscaling/autoscaled_pool.js +37 -36
  4. package/autoscaling/client_load_signal.d.ts +25 -0
  5. package/autoscaling/client_load_signal.js +36 -0
  6. package/autoscaling/cpu_load_signal.d.ts +28 -0
  7. package/autoscaling/cpu_load_signal.js +24 -0
  8. package/autoscaling/event_loop_load_signal.d.ts +23 -0
  9. package/autoscaling/event_loop_load_signal.js +35 -0
  10. package/autoscaling/index.d.ts +5 -1
  11. package/autoscaling/index.js +5 -1
  12. package/autoscaling/load_signal.d.ts +99 -0
  13. package/autoscaling/load_signal.js +135 -0
  14. package/autoscaling/memory_load_signal.d.ts +43 -0
  15. package/autoscaling/memory_load_signal.js +102 -0
  16. package/autoscaling/snapshotter.d.ts +29 -91
  17. package/autoscaling/snapshotter.js +65 -204
  18. package/autoscaling/system_status.d.ts +22 -37
  19. package/autoscaling/system_status.js +49 -87
  20. package/configuration.d.ts +88 -228
  21. package/configuration.js +162 -224
  22. package/cookie_utils.d.ts +4 -3
  23. package/cookie_utils.js +20 -13
  24. package/crawlers/context_pipeline.d.ts +70 -0
  25. package/crawlers/context_pipeline.js +122 -0
  26. package/crawlers/crawler_commons.d.ts +20 -30
  27. package/crawlers/crawler_commons.js +12 -21
  28. package/crawlers/crawler_utils.d.ts +2 -3
  29. package/crawlers/crawler_utils.js +1 -2
  30. package/crawlers/error_snapshotter.d.ts +3 -3
  31. package/crawlers/error_snapshotter.js +2 -3
  32. package/crawlers/error_tracker.d.ts +2 -2
  33. package/crawlers/error_tracker.js +0 -1
  34. package/crawlers/index.d.ts +1 -2
  35. package/crawlers/index.js +1 -2
  36. package/crawlers/internals/types.d.ts +7 -0
  37. package/crawlers/internals/types.js +1 -0
  38. package/crawlers/statistics.d.ts +28 -23
  39. package/crawlers/statistics.js +38 -34
  40. package/enqueue_links/enqueue_links.d.ts +44 -22
  41. package/enqueue_links/enqueue_links.js +51 -30
  42. package/enqueue_links/index.d.ts +0 -1
  43. package/enqueue_links/index.js +0 -1
  44. package/enqueue_links/shared.d.ts +25 -9
  45. package/enqueue_links/shared.js +69 -38
  46. package/errors.d.ts +53 -4
  47. package/errors.js +70 -5
  48. package/events/event_manager.d.ts +34 -8
  49. package/events/event_manager.js +8 -10
  50. package/events/index.d.ts +0 -1
  51. package/events/index.js +0 -1
  52. package/events/local_event_manager.d.ts +15 -5
  53. package/events/local_event_manager.js +37 -40
  54. package/index.d.ts +4 -3
  55. package/index.js +3 -2
  56. package/log.d.ts +82 -3
  57. package/log.js +102 -1
  58. package/memory-storage/consts.d.ts +4 -0
  59. package/memory-storage/consts.js +4 -0
  60. package/memory-storage/index.d.ts +1 -0
  61. package/memory-storage/index.js +1 -0
  62. package/memory-storage/memory-storage.d.ts +46 -0
  63. package/memory-storage/memory-storage.js +136 -0
  64. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  65. package/memory-storage/resource-clients/common/base-client.js +6 -0
  66. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  67. package/memory-storage/resource-clients/dataset.js +113 -0
  68. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  69. package/memory-storage/resource-clients/key-value-store.js +203 -0
  70. package/memory-storage/resource-clients/request-queue.d.ts +96 -0
  71. package/memory-storage/resource-clients/request-queue.js +421 -0
  72. package/memory-storage/utils.d.ts +17 -0
  73. package/memory-storage/utils.js +42 -0
  74. package/package.json +12 -10
  75. package/proxy_configuration.d.ts +29 -152
  76. package/proxy_configuration.js +21 -173
  77. package/recoverable_state.d.ts +120 -0
  78. package/recoverable_state.js +141 -0
  79. package/request.d.ts +84 -13
  80. package/request.js +107 -28
  81. package/router.d.ts +118 -16
  82. package/router.js +124 -30
  83. package/serialization.d.ts +0 -1
  84. package/serialization.js +1 -2
  85. package/service_locator.d.ts +156 -0
  86. package/service_locator.js +238 -0
  87. package/session_pool/consts.d.ts +1 -2
  88. package/session_pool/consts.js +1 -2
  89. package/session_pool/errors.d.ts +0 -1
  90. package/session_pool/errors.js +0 -1
  91. package/session_pool/fingerprint.d.ts +9 -0
  92. package/session_pool/fingerprint.js +30 -0
  93. package/session_pool/index.d.ts +0 -2
  94. package/session_pool/index.js +0 -2
  95. package/session_pool/session.d.ts +37 -75
  96. package/session_pool/session.js +49 -102
  97. package/session_pool/session_pool.d.ts +85 -90
  98. package/session_pool/session_pool.js +131 -120
  99. package/storages/access_checking.d.ts +0 -1
  100. package/storages/access_checking.js +5 -2
  101. package/storages/dataset.d.ts +101 -51
  102. package/storages/dataset.js +168 -126
  103. package/storages/index.d.ts +8 -7
  104. package/storages/index.js +6 -7
  105. package/storages/key_value_store.d.ts +165 -36
  106. package/storages/key_value_store.js +269 -122
  107. package/storages/key_value_store_codec.d.ts +32 -0
  108. package/storages/key_value_store_codec.js +113 -0
  109. package/storages/request_dedup_cache.d.ts +23 -0
  110. package/storages/request_dedup_cache.js +48 -0
  111. package/storages/request_list.d.ts +53 -97
  112. package/storages/request_list.js +99 -75
  113. package/storages/request_loader.d.ts +96 -0
  114. package/storages/request_loader.js +1 -0
  115. package/storages/request_manager.d.ts +33 -0
  116. package/storages/request_manager.js +1 -0
  117. package/storages/request_manager_tandem.d.ts +106 -0
  118. package/storages/request_manager_tandem.js +197 -0
  119. package/storages/request_queue.d.ts +290 -47
  120. package/storages/request_queue.js +628 -215
  121. package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +28 -24
  122. package/storages/{sitemap_request_list.js → sitemap_request_loader.js} +49 -46
  123. package/storages/storage_instance_manager.d.ts +91 -0
  124. package/storages/storage_instance_manager.js +258 -0
  125. package/storages/storage_stats.d.ts +48 -0
  126. package/storages/storage_stats.js +29 -0
  127. package/storages/utils.d.ts +51 -6
  128. package/storages/utils.js +60 -9
  129. package/system-info/cpu-info.d.ts +67 -0
  130. package/system-info/cpu-info.js +216 -0
  131. package/system-info/memory-info.d.ts +31 -0
  132. package/system-info/memory-info.js +115 -0
  133. package/system-info/ps-tree.d.ts +17 -0
  134. package/system-info/ps-tree.js +144 -0
  135. package/system-info/runtime.d.ts +14 -0
  136. package/system-info/runtime.js +80 -0
  137. package/typedefs.d.ts +1 -2
  138. package/typedefs.js +0 -1
  139. package/validators.d.ts +8 -1
  140. package/validators.js +10 -3
  141. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  142. package/autoscaling/autoscaled_pool.js.map +0 -1
  143. package/autoscaling/index.d.ts.map +0 -1
  144. package/autoscaling/index.js.map +0 -1
  145. package/autoscaling/snapshotter.d.ts.map +0 -1
  146. package/autoscaling/snapshotter.js.map +0 -1
  147. package/autoscaling/system_status.d.ts.map +0 -1
  148. package/autoscaling/system_status.js.map +0 -1
  149. package/configuration.d.ts.map +0 -1
  150. package/configuration.js.map +0 -1
  151. package/cookie_utils.d.ts.map +0 -1
  152. package/cookie_utils.js.map +0 -1
  153. package/crawlers/crawler_commons.d.ts.map +0 -1
  154. package/crawlers/crawler_commons.js.map +0 -1
  155. package/crawlers/crawler_extension.d.ts +0 -12
  156. package/crawlers/crawler_extension.d.ts.map +0 -1
  157. package/crawlers/crawler_extension.js +0 -14
  158. package/crawlers/crawler_extension.js.map +0 -1
  159. package/crawlers/crawler_utils.d.ts.map +0 -1
  160. package/crawlers/crawler_utils.js.map +0 -1
  161. package/crawlers/error_snapshotter.d.ts.map +0 -1
  162. package/crawlers/error_snapshotter.js.map +0 -1
  163. package/crawlers/error_tracker.d.ts.map +0 -1
  164. package/crawlers/error_tracker.js.map +0 -1
  165. package/crawlers/index.d.ts.map +0 -1
  166. package/crawlers/index.js.map +0 -1
  167. package/crawlers/statistics.d.ts.map +0 -1
  168. package/crawlers/statistics.js.map +0 -1
  169. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  170. package/enqueue_links/enqueue_links.js.map +0 -1
  171. package/enqueue_links/index.d.ts.map +0 -1
  172. package/enqueue_links/index.js.map +0 -1
  173. package/enqueue_links/shared.d.ts.map +0 -1
  174. package/enqueue_links/shared.js.map +0 -1
  175. package/errors.d.ts.map +0 -1
  176. package/errors.js.map +0 -1
  177. package/events/event_manager.d.ts.map +0 -1
  178. package/events/event_manager.js.map +0 -1
  179. package/events/index.d.ts.map +0 -1
  180. package/events/index.js.map +0 -1
  181. package/events/local_event_manager.d.ts.map +0 -1
  182. package/events/local_event_manager.js.map +0 -1
  183. package/http_clients/base-http-client.d.ts +0 -134
  184. package/http_clients/base-http-client.d.ts.map +0 -1
  185. package/http_clients/base-http-client.js +0 -33
  186. package/http_clients/base-http-client.js.map +0 -1
  187. package/http_clients/form-data-like.d.ts +0 -67
  188. package/http_clients/form-data-like.d.ts.map +0 -1
  189. package/http_clients/form-data-like.js +0 -5
  190. package/http_clients/form-data-like.js.map +0 -1
  191. package/http_clients/got-scraping-http-client.d.ts +0 -15
  192. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  193. package/http_clients/got-scraping-http-client.js +0 -69
  194. package/http_clients/got-scraping-http-client.js.map +0 -1
  195. package/http_clients/index.d.ts +0 -3
  196. package/http_clients/index.d.ts.map +0 -1
  197. package/http_clients/index.js +0 -3
  198. package/http_clients/index.js.map +0 -1
  199. package/index.d.ts.map +0 -1
  200. package/index.js.map +0 -1
  201. package/log.d.ts.map +0 -1
  202. package/log.js.map +0 -1
  203. package/proxy_configuration.d.ts.map +0 -1
  204. package/proxy_configuration.js.map +0 -1
  205. package/request.d.ts.map +0 -1
  206. package/request.js.map +0 -1
  207. package/router.d.ts.map +0 -1
  208. package/router.js.map +0 -1
  209. package/serialization.d.ts.map +0 -1
  210. package/serialization.js.map +0 -1
  211. package/session_pool/consts.d.ts.map +0 -1
  212. package/session_pool/consts.js.map +0 -1
  213. package/session_pool/errors.d.ts.map +0 -1
  214. package/session_pool/errors.js.map +0 -1
  215. package/session_pool/events.d.ts +0 -3
  216. package/session_pool/events.d.ts.map +0 -1
  217. package/session_pool/events.js +0 -3
  218. package/session_pool/events.js.map +0 -1
  219. package/session_pool/index.d.ts.map +0 -1
  220. package/session_pool/index.js.map +0 -1
  221. package/session_pool/session.d.ts.map +0 -1
  222. package/session_pool/session.js.map +0 -1
  223. package/session_pool/session_pool.d.ts.map +0 -1
  224. package/session_pool/session_pool.js.map +0 -1
  225. package/storages/access_checking.d.ts.map +0 -1
  226. package/storages/access_checking.js.map +0 -1
  227. package/storages/dataset.d.ts.map +0 -1
  228. package/storages/dataset.js.map +0 -1
  229. package/storages/index.d.ts.map +0 -1
  230. package/storages/index.js.map +0 -1
  231. package/storages/key_value_store.d.ts.map +0 -1
  232. package/storages/key_value_store.js.map +0 -1
  233. package/storages/request_list.d.ts.map +0 -1
  234. package/storages/request_list.js.map +0 -1
  235. package/storages/request_provider.d.ts +0 -307
  236. package/storages/request_provider.d.ts.map +0 -1
  237. package/storages/request_provider.js +0 -555
  238. package/storages/request_provider.js.map +0 -1
  239. package/storages/request_queue.d.ts.map +0 -1
  240. package/storages/request_queue.js.map +0 -1
  241. package/storages/request_queue_v2.d.ts +0 -87
  242. package/storages/request_queue_v2.d.ts.map +0 -1
  243. package/storages/request_queue_v2.js +0 -438
  244. package/storages/request_queue_v2.js.map +0 -1
  245. package/storages/sitemap_request_list.d.ts.map +0 -1
  246. package/storages/sitemap_request_list.js.map +0 -1
  247. package/storages/storage_manager.d.ts +0 -58
  248. package/storages/storage_manager.d.ts.map +0 -1
  249. package/storages/storage_manager.js +0 -105
  250. package/storages/storage_manager.js.map +0 -1
  251. package/storages/utils.d.ts.map +0 -1
  252. package/storages/utils.js.map +0 -1
  253. package/tsconfig.build.tsbuildinfo +0 -1
  254. package/typedefs.d.ts.map +0 -1
  255. package/typedefs.js.map +0 -1
  256. package/validators.d.ts.map +0 -1
  257. package/validators.js.map +0 -1
@@ -1,8 +1,13 @@
1
- import type { Dictionary } from '@crawlee/types';
2
- import { Configuration } from '../configuration.js';
3
- import type { Request } from '../request.js';
4
- import type { RequestProviderOptions, RequestQueueOperationInfo } from './request_provider.js';
5
- import { RequestProvider } from './request_provider.js';
1
+ import type { BatchAddRequestsResult, Dictionary, ProcessedRequest, QueueOperationInfo, RequestQueueBackend, RequestQueueInfo } from '@crawlee/types';
2
+ import type { ReadonlyDeep } from 'type-fest';
3
+ import type { CrawleeLogger } from '../log.js';
4
+ import type { IProxyConfiguration } from '../proxy_configuration.js';
5
+ import type { Source } from '../request.js';
6
+ import { Request } from '../request.js';
7
+ import type { IRequestManager, RequestsLike } from './request_manager.js';
8
+ import type { RequestQueueStats } from './storage_stats.js';
9
+ import type { IStorage, StorageIdentifier } from './storage_instance_manager.js';
10
+ import type { StorageOpenOptions } from './utils.js';
6
11
  /**
7
12
  * Represents a queue of URLs to crawl, which is used for deep crawling of websites
8
13
  * where you start with several URLs and then recursively
@@ -21,18 +26,6 @@ import { RequestProvider } from './request_provider.js';
21
26
  * Unlike {@link RequestList}, `RequestQueue` supports dynamic adding and removing of requests.
22
27
  * On the other hand, the queue is not optimized for operations that add or remove a large number of URLs in a batch.
23
28
  *
24
- * `RequestQueue` stores its data either on local disk or in the Apify Cloud,
25
- * depending on whether the `APIFY_LOCAL_STORAGE_DIR` or `APIFY_TOKEN` environment variable is set.
26
- *
27
- * If the `APIFY_LOCAL_STORAGE_DIR` environment variable is set, the queue data is stored in
28
- * that directory in an SQLite database file.
29
- *
30
- * If the `APIFY_TOKEN` environment variable is set but `APIFY_LOCAL_STORAGE_DIR` is not, the data is stored in the
31
- * [Apify Request Queue](https://docs.apify.com/storage/request-queue)
32
- * cloud storage. Note that you can force usage of the cloud storage also by passing the `forceCloud`
33
- * option to {@link RequestQueue.open} function,
34
- * even if the `APIFY_LOCAL_STORAGE_DIR` variable is set.
35
- *
36
29
  * **Example usage:**
37
30
  *
38
31
  * ```javascript
@@ -48,25 +41,104 @@ import { RequestProvider } from './request_provider.js';
48
41
  * await queue.addRequest({ url: 'http://example.com/foo/bar' }, { forefront: true });
49
42
  * ```
50
43
  * @category Sources
51
- *
52
- * @deprecated RequestQueue v1 is deprecated and will be removed in the future. Please use {@link RequestQueue} instead.
53
44
  */
54
- declare class RequestQueue extends RequestProvider {
55
- private queryQueueHeadPromise?;
56
- private inProgress;
45
+ export declare class RequestQueue implements IStorage, IRequestManager {
46
+ readonly id: string;
47
+ readonly name?: string;
48
+ readonly backend: RequestQueueBackend;
49
+ private proxyConfiguration?;
50
+ readonly log: CrawleeLogger;
51
+ private requestCache;
57
52
  /**
58
- * @internal
53
+ * Remembers the `requestId` of every request already submitted to the client — including background
54
+ * batches that `requestCache` skips — so overlapping URL sets aren't re-submitted.
55
+ * See {@link RequestDeduplicationCache} for why this is a separate, cheaper cache.
56
+ */
57
+ private requestSeenCache;
58
+ private queuePausedForMigration;
59
+ private inProgressRequestBatchCount;
60
+ /**
61
+ * The largest expected request-processing time (in seconds) seen so far via
62
+ * {@link setExpectedRequestProcessingTimeSecs}. Used to ensure that value is only ever raised, never
63
+ * lowered, before being forwarded to the storage backend.
59
64
  */
60
- constructor(options: RequestProviderOptions, config?: Configuration);
65
+ private expectedRequestProcessingSecs;
66
+ private httpClient?;
67
+ private readonly events;
68
+ private readonly statsTracker;
69
+ /**
70
+ * Backend-independent usage counters tracked for this request queue (write operations and
71
+ * queue-head reads issued to the underlying storage backend). Counted per backend call.
72
+ */
73
+ get stats(): RequestQueueStats;
61
74
  /**
62
75
  * @internal
63
76
  */
64
- inProgressCount(): number;
77
+ constructor(options: RequestQueueOptions);
78
+ /**
79
+ * Returns the total number of requests in the queue (i.e. pending + handled).
80
+ *
81
+ * Survives restarts and actor migrations.
82
+ */
83
+ getTotalCount(): Promise<number>;
84
+ /**
85
+ * Returns the total number of pending requests in the queue.
86
+ *
87
+ * Survives restarts and Actor migrations.
88
+ */
89
+ getPendingCount(): Promise<number>;
90
+ /**
91
+ * Adds a request to the queue.
92
+ *
93
+ * If a request with the same `uniqueKey` property is already present in the queue,
94
+ * it will not be updated. You can find out whether this happened from the resulting
95
+ * {@link QueueOperationInfo} object.
96
+ *
97
+ * To add multiple requests to the queue by extracting links from a webpage,
98
+ * see the {@link enqueueLinks} helper function.
99
+ *
100
+ * @param requestLike {@link Request} object or vanilla object with request data.
101
+ * Note that the function sets the `uniqueKey` and `id` fields to the passed Request.
102
+ * @param [options] Request queue operation options.
103
+ */
104
+ addRequest(requestLike: Source, options?: RequestQueueOperationOptions): Promise<RequestQueueOperationInfo>;
105
+ /**
106
+ * Adds requests to the queue in batches of 25. This method will wait till all the requests are added
107
+ * to the queue before resolving. You should prefer using `queue.addRequestsBatched()` or `crawler.addRequests()`
108
+ * if you don't want to block the processing, as those methods will only wait for the initial 1000 requests,
109
+ * start processing right after that happens, and continue adding more in the background.
110
+ *
111
+ * If a request passed in is already present due to its `uniqueKey` property being the same,
112
+ * it will not be updated. You can find out whether this happened by finding the request in the resulting
113
+ * {@link BatchAddRequestsResult} object.
114
+ *
115
+ * @param requestsLike {@link Request} objects or vanilla objects with request data.
116
+ * Note that the function sets the `uniqueKey` and `id` fields to the passed requests if missing.
117
+ * @param [options] Request queue operation options.
118
+ */
119
+ addRequests(requestsLike: RequestsLike, options?: RequestQueueOperationOptions): Promise<BatchAddRequestsResult>;
120
+ /**
121
+ * Adds requests to the queue in batches. By default, it will resolve after the initial batch is added, and continue
122
+ * adding the rest in the background. You can configure the batch size via `batchSize` option and the sleep time in between
123
+ * the batches via `waitBetweenBatchesMillis`. If you want to wait for all batches to be added to the queue, you can use
124
+ * the `waitForAllRequestsToBeAdded` promise you get in the response object.
125
+ *
126
+ * @param requests The requests to add
127
+ * @param options Options for the request queue
128
+ */
129
+ addRequestsBatched(requests: ReadonlyDeep<RequestsLike>, options?: AddRequestsBatchedOptions): Promise<AddRequestsBatchedResult>;
130
+ /**
131
+ * Gets the request from the queue specified by its `uniqueKey`.
132
+ *
133
+ * @param uniqueKey Unique key of the request.
134
+ * @returns Returns the request object, or `null` if it was not found.
135
+ */
136
+ getRequest<T extends Dictionary = Dictionary>(uniqueKey: string): Promise<Request<T> | null>;
65
137
  /**
66
138
  * Returns a next request in the queue to be processed, or `null` if there are no more pending requests.
67
139
  *
68
140
  * Once you successfully finish processing of the request, you need to call
69
- * {@link RequestQueue.markRequestHandled}
141
+ * {@link RequestQueue.markRequestAsHandled}
70
142
  * to mark the request as handled in the queue. If there was some error in processing the request,
71
143
  * call {@link RequestQueue.reclaimRequest} instead,
72
144
  * so that the queue will give the request to some other consumer in another call to the `fetchNextRequest` function.
@@ -80,32 +152,112 @@ declare class RequestQueue extends RequestProvider {
80
152
  * Returns the request object or `null` if there are no more pending requests.
81
153
  */
82
154
  fetchNextRequest<T extends Dictionary = Dictionary>(): Promise<Request<T> | null>;
83
- protected ensureHeadIsNonEmpty(): Promise<void>;
84
155
  /**
85
- * We always request more items than is in progress to ensure that something falls into head.
86
- *
87
- * @param [ensureConsistency] If true then query for queue head is retried until queueModifiedAt
88
- * is older than queryStartedAt by at least API_PROCESSED_REQUESTS_DELAY_MILLIS to ensure that queue
89
- * head is consistent.
90
- * @default false
91
- * @param [limit] How many queue head items will be fetched.
92
- * @param [iteration] Used when this function is called recursively to limit the recursion.
93
- * @returns Indicates if queue head is consistent (true) or inconsistent (false).
156
+ * Marks a request that was previously returned by the
157
+ * {@link RequestQueue.fetchNextRequest}
158
+ * function as handled after successful processing.
159
+ * Handled requests will never again be returned by the `fetchNextRequest` function.
94
160
  */
95
- protected _ensureHeadIsNonEmpty(ensureConsistency?: boolean, limit?: number, iteration?: number): Promise<boolean>;
96
- isFinished(): Promise<boolean>;
161
+ markRequestAsHandled(request: Request): Promise<RequestQueueOperationInfo | null>;
97
162
  /**
98
163
  * Reclaims a failed request back to the queue, so that it can be returned for processing later again
99
164
  * by another call to {@link RequestQueue.fetchNextRequest}.
100
165
  * The request record in the queue is updated using the provided `request` parameter.
101
166
  * For example, this lets you store the number of retries or error messages for the request.
102
167
  */
103
- reclaimRequest(...args: Parameters<RequestProvider['reclaimRequest']>): Promise<RequestQueueOperationInfo | null>;
168
+ reclaimRequest(request: Request, options?: RequestQueueOperationOptions): Promise<RequestQueueOperationInfo | null>;
169
+ /**
170
+ * Resolves to `true` if the next call to {@link RequestQueue.fetchNextRequest} would return
171
+ * `null`, i.e. there are no pending requests to fetch right now. Otherwise it resolves to `false`.
172
+ *
173
+ * Note that even if the queue is empty, there might be some requests currently being processed
174
+ * (fetched but not yet handled or reclaimed). An empty queue therefore does not mean crawling is
175
+ * finished — those in-progress requests may still be reclaimed, and background tasks may still be
176
+ * adding more requests. To check whether all activity in the queue has finished, use
177
+ * {@link RequestQueue.isFinished}.
178
+ */
179
+ isEmpty(): Promise<boolean>;
180
+ /**
181
+ * Resolves to `true` if all requests were already handled and there are no more left — including no
182
+ * requests currently in progress (fetched but not yet handled or reclaimed, including requests
183
+ * locked by other clients sharing the same queue) and no background add operations still in flight.
184
+ *
185
+ * Due to the nature of distributed storage used by the queue, the function may occasionally return
186
+ * a false negative, but it shall never return a false positive.
187
+ */
188
+ isFinished(): Promise<boolean>;
189
+ /**
190
+ * Tells the queue how long a consumer expects to hold a fetched request before marking it handled
191
+ * or reclaiming it (typically the request-handler timeout plus padding), so that a storage backend
192
+ * that reserves requests via locking does not hand the same request out again while it is still
193
+ * being processed.
194
+ *
195
+ * Several consumers may share one queue (and therefore one client) in a single process, so we only
196
+ * ever raise the reservation duration, never lower it — otherwise a short-lived consumer could cut
197
+ * short the reservation of a long-lived one and have its in-flight request stolen.
198
+ */
199
+ setExpectedRequestProcessingTimeSecs(secs: number): Promise<void>;
200
+ /**
201
+ * Caches information about request to beware of unneeded addRequest() calls.
202
+ */
203
+ private cacheRequest;
204
+ /**
205
+ * Removes the queue either from the Apify Cloud storage or from the local database,
206
+ * depending on the mode of operation.
207
+ */
208
+ drop(): Promise<void>;
209
+ /**
210
+ * Remove all requests from the queue but keep the queue itself, resetting it
211
+ * so it can be reused (e.g. across multiple `crawler.run()` calls).
212
+ */
213
+ purge(): Promise<void>;
104
214
  /**
105
215
  * @inheritdoc
106
216
  */
107
- markRequestHandled(request: Request): Promise<RequestQueueOperationInfo | null>;
108
- protected _reset(): void;
217
+ [Symbol.asyncIterator](): AsyncGenerator<Request<Dictionary>, void, unknown>;
218
+ /**
219
+ * Returns the number of handled requests.
220
+ *
221
+ * This function is just a convenient shortcut for:
222
+ *
223
+ * ```javascript
224
+ * const { handledRequestCount } = await queue.getInfo();
225
+ * ```
226
+ * @inheritdoc
227
+ */
228
+ getHandledCount(): Promise<number>;
229
+ /**
230
+ * Returns an object containing general information about the request queue.
231
+ *
232
+ * **Example:**
233
+ * ```
234
+ * {
235
+ * id: "WkzbQMuFYuamGv3YF",
236
+ * name: "my-queue",
237
+ * createdAt: new Date("2015-12-12T07:34:14.202Z"),
238
+ * modifiedAt: new Date("2015-12-13T08:36:13.202Z"),
239
+ * accessedAt: new Date("2015-12-14T08:36:13.202Z"),
240
+ * totalRequestCount: 25,
241
+ * handledRequestCount: 5,
242
+ * pendingRequestCount: 20,
243
+ * }
244
+ * ```
245
+ *
246
+ * @throws If the underlying storage no longer exists (e.g. it was deleted externally).
247
+ */
248
+ getInfo(): Promise<RequestQueueInfo>;
249
+ /**
250
+ * Fetches URLs from requestsFromUrl and returns them in format of list of requests
251
+ */
252
+ private fetchRequestsFromUrl;
253
+ /**
254
+ * Adds all fetched requests from a URL from a remote resource.
255
+ */
256
+ private addFetchedRequests;
257
+ /**
258
+ * @internal wraps public utility for mocking purposes
259
+ */
260
+ private _downloadListOfUrls;
109
261
  /**
110
262
  * Opens a request queue and returns a promise resolving to an instance
111
263
  * of the {@link RequestQueue} class.
@@ -117,12 +269,103 @@ declare class RequestQueue extends RequestProvider {
117
269
  *
118
270
  * For more details and code examples, see the {@link RequestQueue} class.
119
271
  *
120
- * @param [queueIdOrName]
121
- * ID or name of the request queue to be opened. If `null` or `undefined`,
122
- * the function returns the default request queue associated with the crawler run.
272
+ * @param [identifier]
273
+ * ID or name of the request queue to be opened. If a string is provided, it will first be
274
+ * looked up as an ID; if no such storage exists, it will be treated as a name.
275
+ * If `null` or `undefined`, the function returns the default request queue associated with the crawler run.
123
276
  * @param [options] Open Request Queue options.
124
277
  */
125
- static open(...args: Parameters<typeof RequestProvider.open>): Promise<RequestQueue>;
278
+ static open(identifier?: string | StorageIdentifier | null, options?: StorageOpenOptions): Promise<RequestQueue>;
279
+ }
280
+ export interface RequestQueueOptions {
281
+ /** Resolved metadata for the request queue, as returned by the backend's `getMetadata()`. */
282
+ metadata: RequestQueueInfo;
283
+ backend: RequestQueueBackend;
284
+ /**
285
+ * Used to pass the proxy configuration for the `requestsFromUrl` objects.
286
+ * Takes advantage of the internal address rotation and authentication process.
287
+ * If undefined, the `requestsFromUrl` requests will be made without proxy.
288
+ */
289
+ proxyConfiguration?: IProxyConfiguration;
290
+ }
291
+ export interface RequestQueueOperationOptions {
292
+ /**
293
+ * If set to `true`:
294
+ * - while adding the request to the queue: the request will be added to the foremost position in the queue.
295
+ * - while reclaiming the request: the request will be placed to the beginning of the queue, so that it's returned
296
+ * in the next call to {@link RequestQueue.fetchNextRequest}.
297
+ * By default, it's put to the end of the queue.
298
+ *
299
+ * In case the request is already present in the queue, this option has no effect.
300
+ *
301
+ * If more requests are added with this option at once, their order in the following `fetchNextRequest` call
302
+ * is arbitrary.
303
+ * @default false
304
+ */
305
+ forefront?: boolean;
306
+ /**
307
+ * Should the requests be added to the local LRU cache?
308
+ * @default false
309
+ * @internal
310
+ */
311
+ cache?: boolean;
312
+ }
313
+ /**
314
+ * @internal
315
+ */
316
+ export interface RequestQueueOperationInfo extends QueueOperationInfo {
317
+ uniqueKey: string;
318
+ forefront: boolean;
319
+ }
320
+ export interface AddRequestsBatchedOptions extends RequestQueueOperationOptions {
321
+ /**
322
+ * Whether to wait for all the provided requests to be added, instead of waiting just for the initial batch of up to `batchSize`.
323
+ * @default false
324
+ */
325
+ waitForAllRequestsToBeAdded?: boolean;
326
+ /**
327
+ * @default 1000
328
+ */
329
+ batchSize?: number;
330
+ /**
331
+ * @default 1000
332
+ */
333
+ waitBetweenBatchesMillis?: number;
334
+ /**
335
+ * If set, only this many *actually new* requests (i.e. not already present in the queue) will be added.
336
+ * Once the budget is reached, remaining requests from the iterable will be collected in
337
+ * {@link AddRequestsBatchedResult.requestsOverLimit|`requestsOverLimit`} instead.
338
+ *
339
+ * This is useful in combination with `maxRequestsPerCrawl` to avoid duplicate URLs consuming the budget.
340
+ *
341
+ * **Note:** Setting this option implicitly enables {@link AddRequestsBatchedOptions.waitForAllRequestsToBeAdded|`waitForAllRequestsToBeAdded`},
342
+ * since all batches must complete before leftover requests can be accurately reported.
343
+ */
344
+ maxNewRequests?: number;
345
+ }
346
+ export interface AddRequestsBatchedResult {
347
+ addedRequests: ProcessedRequest[];
348
+ /**
349
+ * A promise which will resolve with the rest of the requests that were added to the queue.
350
+ *
351
+ * Alternatively, we can set {@link AddRequestsBatchedOptions.waitForAllRequestsToBeAdded|`waitForAllRequestsToBeAdded`} to `true`
352
+ * in the {@link BasicCrawler.addRequests|`crawler.addRequests()`} options.
353
+ *
354
+ * **Example:**
355
+ *
356
+ * ```ts
357
+ * // Assuming `requests` is a list of requests.
358
+ * const result = await crawler.addRequests(requests);
359
+ *
360
+ * // If we want to wait for the rest of the requests to be added to the queue:
361
+ * await result.waitForAllRequestsToBeAdded;
362
+ * ```
363
+ */
364
+ waitForAllRequestsToBeAdded: Promise<ProcessedRequest[]>;
365
+ /**
366
+ * Requests from the input that were not added to the queue because the
367
+ * {@link AddRequestsBatchedOptions.maxNewRequests|`maxNewRequests`} budget was reached.
368
+ * Empty when `maxNewRequests` is not set.
369
+ */
370
+ requestsOverLimit?: Source[];
126
371
  }
127
- export { RequestQueue as RequestQueueV1 };
128
- //# sourceMappingURL=request_queue.d.ts.map