@crawlee/core 4.0.0-beta.20 → 4.0.0-beta.201

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