@crawlee/core 4.0.0-beta.7 → 4.0.0-beta.70

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