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

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 +5 -6
  3. package/autoscaling/autoscaled_pool.js +12 -11
  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 +35 -72
  17. package/autoscaling/snapshotter.js +78 -181
  18. package/autoscaling/system_status.d.ts +21 -36
  19. package/autoscaling/system_status.js +46 -84
  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 +22 -17
  39. package/crawlers/statistics.js +30 -26
  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 +14 -149
  76. package/proxy_configuration.js +19 -168
  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 +117 -15
  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 +35 -73
  96. package/session_pool/session.js +46 -99
  97. package/session_pool/session_pool.d.ts +71 -72
  98. package/session_pool/session_pool.js +111 -100
  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 +38 -82
  112. package/storages/request_list.js +65 -41
  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 +303 -46
  120. package/storages/request_queue.js +629 -214
  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 +8 -1
  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,9 @@
1
+ import type { BaseHttpClient } from '@crawlee/types';
1
2
  import { type ParseSitemapOptions } from '@crawlee/utils';
2
- import { Configuration } from '../configuration.js';
3
3
  import type { GlobInput, RegExpInput } from '../enqueue_links/shared.js';
4
4
  import { Request } from '../request.js';
5
- import type { IRequestList } from './request_list.js';
5
+ import type { IRequestLoader } from './request_loader.js';
6
+ import type { IRequestManager } from './request_manager.js';
6
7
  interface UrlConstraints {
7
8
  /**
8
9
  * An array of glob pattern strings or plain objects
@@ -13,7 +14,7 @@ interface UrlConstraints {
13
14
  * The matching is always case-insensitive.
14
15
  * If you need case-sensitive matching, use `regexps` property directly.
15
16
  *
16
- * If `globs` is an empty array or `undefined`, and `regexps` are also not defined, then the `SitemapRequestList`
17
+ * If `globs` is an empty array or `undefined`, and `regexps` are also not defined, then the `SitemapRequestLoader`
17
18
  * includes all the URLs from the sitemap.
18
19
  */
19
20
  globs?: readonly GlobInput[];
@@ -33,12 +34,12 @@ interface UrlConstraints {
33
34
  *
34
35
  * The plain objects must include at least the `regexp` property, which holds the regular expression.
35
36
  *
36
- * If `regexps` is an empty array or `undefined`, and `globs` are also not defined, then the `SitemapRequestList`
37
+ * If `regexps` is an empty array or `undefined`, and `globs` are also not defined, then the `SitemapRequestLoader`
37
38
  * includes all the URLs from the sitemap.
38
39
  */
39
40
  regexps?: readonly RegExpInput[];
40
41
  }
41
- export interface SitemapRequestListOptions extends UrlConstraints {
42
+ export interface SitemapRequestLoaderOptions extends UrlConstraints {
42
43
  /**
43
44
  * List of sitemap URLs to parse.
44
45
  */
@@ -81,27 +82,25 @@ export interface SitemapRequestListOptions extends UrlConstraints {
81
82
  */
82
83
  parseSitemapOptions?: Omit<ParseSitemapOptions, 'emitNestedSitemaps' | 'maxDepth'>;
83
84
  /**
84
- * Crawlee configuration
85
+ * Custom HTTP client to be used for sitemap loading.
85
86
  */
86
- config?: Configuration;
87
+ httpClient?: BaseHttpClient;
87
88
  }
88
89
  /**
89
90
  * A list of URLs to crawl parsed from a sitemap.
90
91
  *
91
92
  * The loading of the sitemap is performed in the background so that crawling can start before the sitemap is fully loaded.
92
93
  */
93
- export declare class SitemapRequestList implements IRequestList {
94
+ export declare class SitemapRequestLoader implements IRequestLoader {
94
95
  /**
95
96
  * Set of URLs that were returned by `fetchNextRequest()` and not marked as handled yet.
96
97
  * @internal
97
98
  */
98
99
  inProgress: Set<string>;
99
- /** Set of URLs for which `reclaimRequest()` was called. */
100
- private reclaimed;
101
100
  /**
102
101
  * Map of returned Request objects that have not been marked as handled yet.
103
102
  *
104
- * We use this to persist custom user fields on the in-progress (or reclaimed) requests.
103
+ * We use this to persist custom user fields on the in-progress requests.
105
104
  */
106
105
  private requestData;
107
106
  /**
@@ -132,7 +131,7 @@ export declare class SitemapRequestList implements IRequestList {
132
131
  /**
133
132
  * Proxy URL to be used for sitemap loading.
134
133
  */
135
- private proxyUrl;
134
+ private proxyUrl?;
136
135
  /**
137
136
  * Logger instance.
138
137
  */
@@ -190,15 +189,25 @@ export declare class SitemapRequestList implements IRequestList {
190
189
  /**
191
190
  * Open a sitemap and start processing it.
192
191
  *
193
- * Resolves to a new instance of `SitemapRequestList`, which **might not be fully loaded yet** - i.e. the sitemap might still be loading in the background.
192
+ * Resolves to a new instance of `SitemapRequestLoader`, which **might not be fully loaded yet** - i.e. the sitemap might still be loading in the background.
194
193
  *
195
194
  * Track the loading progress using the `isSitemapFullyLoaded` property.
196
195
  */
197
- static open(options: SitemapRequestListOptions): Promise<SitemapRequestList>;
196
+ static open(options: SitemapRequestLoaderOptions): Promise<SitemapRequestLoader>;
198
197
  /**
199
198
  * @inheritDoc
200
199
  */
201
- length(): number;
200
+ getTotalCount(): Promise<number>;
201
+ /**
202
+ * @inheritDoc
203
+ */
204
+ getPendingCount(): Promise<number>;
205
+ /**
206
+ * Combines this list with a request manager (a {@link RequestQueue} by default) into a
207
+ * {@link RequestManagerTandem}, allowing requests to be added and reclaimed while still
208
+ * being read from this list first.
209
+ */
210
+ toTandem(requestManager?: IRequestManager): Promise<IRequestManager>;
202
211
  /**
203
212
  * @inheritDoc
204
213
  */
@@ -210,7 +219,7 @@ export declare class SitemapRequestList implements IRequestList {
210
219
  /**
211
220
  * @inheritDoc
212
221
  */
213
- handledCount(): number;
222
+ getHandledCount(): Promise<number>;
214
223
  /**
215
224
  * @inheritDoc
216
225
  */
@@ -224,11 +233,7 @@ export declare class SitemapRequestList implements IRequestList {
224
233
  * @inheritDoc
225
234
  */
226
235
  // @ts-ignore optional peer dependency or compatibility with es2022
227
- [Symbol.asyncIterator](): AsyncGenerator<Request<import("@crawlee/utils").Dictionary>, void, unknown>;
228
- /**
229
- * @inheritDoc
230
- */
231
- reclaimRequest(request: Request): Promise<void>;
236
+ [Symbol.asyncIterator](): AsyncGenerator<Request<import("@crawlee/types").Dictionary>, void, unknown>;
232
237
  /**
233
238
  * Aborts the internal sitemap loading, stops the processing of the sitemap contents and drops all the pending URLs.
234
239
  *
@@ -238,8 +243,7 @@ export declare class SitemapRequestList implements IRequestList {
238
243
  /**
239
244
  * @inheritDoc
240
245
  */
241
- markRequestHandled(request: Request): Promise<void>;
242
- private ensureInProgressAndNotReclaimed;
246
+ markRequestAsHandled(request: Request): Promise<void>;
247
+ private ensureInProgress;
243
248
  }
244
249
  export {};
245
- //# sourceMappingURL=sitemap_request_list.d.ts.map
@@ -2,31 +2,28 @@ import { Transform } from 'node:stream';
2
2
  import { parseSitemap } from '@crawlee/utils';
3
3
  import { minimatch } from 'minimatch';
4
4
  import ow from 'ow';
5
- import defaultLog from '@apify/log';
6
- import { Configuration } from '../configuration.js';
7
5
  import { constructGlobObjectsFromGlobs, constructRegExpObjectsFromRegExps } from '../enqueue_links/shared.js';
8
6
  import { Request } from '../request.js';
7
+ import { serviceLocator } from '../service_locator.js';
9
8
  import { KeyValueStore } from './key_value_store.js';
10
9
  import { purgeDefaultStorages } from './utils.js';
11
10
  /** @internal */
12
- const STATE_PERSISTENCE_KEY = 'SITEMAP_REQUEST_LIST_STATE';
11
+ const STATE_PERSISTENCE_KEY = 'SITEMAP_REQUEST_LOADER_STATE';
13
12
  /**
14
13
  * A list of URLs to crawl parsed from a sitemap.
15
14
  *
16
15
  * The loading of the sitemap is performed in the background so that crawling can start before the sitemap is fully loaded.
17
16
  */
18
- export class SitemapRequestList {
17
+ export class SitemapRequestLoader {
19
18
  /**
20
19
  * Set of URLs that were returned by `fetchNextRequest()` and not marked as handled yet.
21
20
  * @internal
22
21
  */
23
22
  inProgress = new Set();
24
- /** Set of URLs for which `reclaimRequest()` was called. */
25
- reclaimed = new Set();
26
23
  /**
27
24
  * Map of returned Request objects that have not been marked as handled yet.
28
25
  *
29
- * We use this to persist custom user fields on the in-progress (or reclaimed) requests.
26
+ * We use this to persist custom user fields on the in-progress requests.
30
27
  */
31
28
  requestData = new Map();
32
29
  /**
@@ -74,7 +71,7 @@ export class SitemapRequestList {
74
71
  /**
75
72
  * Logger instance.
76
73
  */
77
- log = defaultLog.child({ prefix: 'SitemapRequestList' });
74
+ log;
78
75
  urlExcludePatternObjects = [];
79
76
  urlPatternObjects = [];
80
77
  /** EventManager used to handle persistence */
@@ -96,7 +93,8 @@ export class SitemapRequestList {
96
93
  config: ow.optional.object,
97
94
  persistenceOptions: ow.optional.object,
98
95
  }));
99
- const { globs, exclude, regexps, config = Configuration.getGlobalConfig() } = options;
96
+ const { globs, exclude, regexps } = options;
97
+ this.log = serviceLocator.getLogger().child({ prefix: 'SitemapRequestLoader' });
100
98
  if (exclude?.length) {
101
99
  for (const excl of exclude) {
102
100
  if (typeof excl === 'string' || 'glob' in excl) {
@@ -118,7 +116,7 @@ export class SitemapRequestList {
118
116
  this.proxyUrl = options.proxyUrl;
119
117
  this.urlQueueStream = this.createNewStream(options.maxBufferSize ?? 200);
120
118
  this.sitemapParsingProgress.pendingSitemapUrls = new Set(options.sitemapUrls);
121
- this.events = config.getEventManager();
119
+ this.events = serviceLocator.getEventManager();
122
120
  this.persistState = this.persistState.bind(this);
123
121
  }
124
122
  /**
@@ -248,17 +246,20 @@ export class SitemapRequestList {
248
246
  /**
249
247
  * Open a sitemap and start processing it.
250
248
  *
251
- * Resolves to a new instance of `SitemapRequestList`, which **might not be fully loaded yet** - i.e. the sitemap might still be loading in the background.
249
+ * Resolves to a new instance of `SitemapRequestLoader`, which **might not be fully loaded yet** - i.e. the sitemap might still be loading in the background.
252
250
  *
253
251
  * Track the loading progress using the `isSitemapFullyLoaded` property.
254
252
  */
255
253
  static async open(options) {
256
- const requestList = new SitemapRequestList({
257
- ...options,
254
+ const { httpClient, ...restOptions } = options;
255
+ const requestList = new SitemapRequestLoader({
256
+ ...restOptions,
258
257
  persistStateKey: options.persistStateKey ?? STATE_PERSISTENCE_KEY,
259
258
  });
260
259
  await requestList.restoreState();
261
- void requestList.load({ parseSitemapOptions: options.parseSitemapOptions });
260
+ void requestList.load({
261
+ parseSitemapOptions: { logger: serviceLocator.getLogger(), ...options.parseSitemapOptions, httpClient },
262
+ });
262
263
  if (requestList.persistenceOptions.enable) {
263
264
  requestList.events.on("persistState" /* EventType.PERSIST_STATE */, requestList.persistState);
264
265
  }
@@ -275,8 +276,28 @@ export class SitemapRequestList {
275
276
  /**
276
277
  * @inheritDoc
277
278
  */
278
- length() {
279
- return this.urlQueueStream.readableLength + this.handledUrlCount - this.inProgress.size - this.reclaimed.size;
279
+ async getTotalCount() {
280
+ // Total known so far = not-yet-fetched (still buffered in the stream) + in-progress (fetched but not
281
+ // yet handled) + already handled.
282
+ return this.urlQueueStream.readableLength + this.inProgress.size + this.handledUrlCount;
283
+ }
284
+ /**
285
+ * @inheritDoc
286
+ */
287
+ async getPendingCount() {
288
+ // Pending = everything not yet handled = not-yet-fetched + in-progress.
289
+ return this.urlQueueStream.readableLength + this.inProgress.size;
290
+ }
291
+ /**
292
+ * Combines this list with a request manager (a {@link RequestQueue} by default) into a
293
+ * {@link RequestManagerTandem}, allowing requests to be added and reclaimed while still
294
+ * being read from this list first.
295
+ */
296
+ async toTandem(requestManager) {
297
+ // Import here to avoid circular imports.
298
+ const { RequestManagerTandem } = await import('./request_manager_tandem.js');
299
+ const { RequestQueue } = await import('./request_queue.js');
300
+ return new RequestManagerTandem(this, requestManager ?? (await RequestQueue.open()));
280
301
  }
281
302
  /**
282
303
  * @inheritDoc
@@ -288,12 +309,12 @@ export class SitemapRequestList {
288
309
  * @inheritDoc
289
310
  */
290
311
  async isEmpty() {
291
- return this.reclaimed.size === 0 && this.urlQueueStream.readableLength === 0;
312
+ return this.urlQueueStream.readableLength === 0;
292
313
  }
293
314
  /**
294
315
  * @inheritDoc
295
316
  */
296
- handledCount() {
317
+ async getHandledCount() {
297
318
  return this.handledUrlCount;
298
319
  }
299
320
  /**
@@ -328,8 +349,8 @@ export class SitemapRequestList {
328
349
  inProgressSitemapUrl: this.sitemapParsingProgress.inProgressSitemapUrl,
329
350
  inProgressEntries: Array.from(this.sitemapParsingProgress.inProgressEntries),
330
351
  },
331
- urlQueue,
332
- reclaimed: [...this.inProgress, ...this.reclaimed], // In-progress and reclaimed requests will be both retried if state is restored
352
+ // Re-queue in-progress requests to the front so they are retried if the state is restored.
353
+ urlQueue: [...this.inProgress, ...urlQueue],
333
354
  requestData: Array.from(this.requestData.entries()),
334
355
  abortLoading: this.abortLoading,
335
356
  closed: this.closed,
@@ -345,7 +366,6 @@ export class SitemapRequestList {
345
366
  if (state === null) {
346
367
  return;
347
368
  }
348
- this.reclaimed = new Set(state.reclaimed);
349
369
  this.sitemapParsingProgress = {
350
370
  pendingSitemapUrls: new Set(state.sitemapParsingProgress.pendingSitemapUrls),
351
371
  inProgressSitemapUrl: state.sitemapParsingProgress.inProgressSitemapUrl,
@@ -362,17 +382,12 @@ export class SitemapRequestList {
362
382
  * @inheritDoc
363
383
  */
364
384
  async fetchNextRequest() {
365
- // Try to return a reclaimed request first
366
- let nextUrl = this.reclaimed.values().next().value;
367
- if (nextUrl) {
368
- this.reclaimed.delete(nextUrl);
385
+ const nextUrl = await this.readNextUrl();
386
+ if (!nextUrl) {
387
+ return null;
369
388
  }
370
- else {
371
- // Otherwise read next url from the stream
372
- nextUrl = await this.readNextUrl();
373
- if (!nextUrl) {
374
- return null;
375
- }
389
+ // A restored in-progress request already has its Request data; don't overwrite it.
390
+ if (!this.requestData.has(nextUrl)) {
376
391
  this.requestData.set(nextUrl, new Request({ url: nextUrl }));
377
392
  }
378
393
  this.inProgress.add(nextUrl);
@@ -389,14 +404,6 @@ export class SitemapRequestList {
389
404
  yield request;
390
405
  }
391
406
  }
392
- /**
393
- * @inheritDoc
394
- */
395
- async reclaimRequest(request) {
396
- this.ensureInProgressAndNotReclaimed(request.url);
397
- this.reclaimed.add(request.url);
398
- this.inProgress.delete(request.url);
399
- }
400
407
  /**
401
408
  * Aborts the internal sitemap loading, stops the processing of the sitemap contents and drops all the pending URLs.
402
409
  *
@@ -412,19 +419,15 @@ export class SitemapRequestList {
412
419
  /**
413
420
  * @inheritDoc
414
421
  */
415
- async markRequestHandled(request) {
422
+ async markRequestAsHandled(request) {
416
423
  this.handledUrlCount += 1;
417
- this.ensureInProgressAndNotReclaimed(request.url);
424
+ this.ensureInProgress(request.url);
418
425
  this.inProgress.delete(request.url);
419
426
  this.requestData.delete(request.url);
420
427
  }
421
- ensureInProgressAndNotReclaimed(url) {
428
+ ensureInProgress(url) {
422
429
  if (!this.inProgress.has(url)) {
423
430
  throw new Error(`The request is not being processed (url: ${url})`);
424
431
  }
425
- if (this.reclaimed.has(url)) {
426
- throw new Error(`The request was already reclaimed (url: ${url})`);
427
- }
428
432
  }
429
433
  }
430
- //# sourceMappingURL=sitemap_request_list.js.map
@@ -0,0 +1,91 @@
1
+ import type { DatasetBackend, KeyValueStoreBackend, RequestQueueBackend, StorageBackend, StorageIdentifier } from '@crawlee/types';
2
+ import type { Constructor } from '../typedefs.js';
3
+ export type { StorageIdentifier } from '@crawlee/types';
4
+ /**
5
+ * Matches an `IStorage` – a storage "frontend" (Dataset, KeyValueStore, RequestQueue).
6
+ */
7
+ export interface IStorage {
8
+ id: string;
9
+ name?: string;
10
+ }
11
+ type Hashable = string;
12
+ /**
13
+ * Unified manager for opening and caching storage instances (Dataset, KeyValueStore, RequestQueue).
14
+ *
15
+ * A single instance manages all storage types. Instances are cached by
16
+ * `(storageClass, id/name/alias, backendCacheKey)` so the same storage is never opened twice.
17
+ *
18
+ * The manager itself does not resolve identifiers — callers pass explicit `id`, `name`, or `alias` (at most one),
19
+ * and a pre-bound `backendOpener` promise. When none of `id`, `name`, `alias` are provided, the manager automatically
20
+ * assigns a reserved default alias.
21
+ *
22
+ * @ignore
23
+ */
24
+ export declare class StorageInstanceManager {
25
+ private readonly cache;
26
+ private readonly openerLocks;
27
+ /**
28
+ * Open (or retrieve from cache) a storage instance.
29
+ *
30
+ * @param cls The storage class constructor (e.g. `Dataset`, `KeyValueStore`, `RequestQueue`).
31
+ * @param id Storage ID (mutually exclusive with `name` and `alias`).
32
+ * @param name Storage name (mutually exclusive with `id` and `alias`).
33
+ * @param alias Run-scoped alias (mutually exclusive with `id` and `name`).
34
+ * Automatically assigned when no identifier is provided.
35
+ * @param backendOpener A **lazy** factory that creates the sub-backend.
36
+ * Only called on a cache miss.
37
+ * @param backendCacheKey Opaque key identifying the storage backend, so that the same logical
38
+ * storage opened through different clients is cached separately.
39
+ */
40
+ openStorage<TStorage extends IStorage>(cls: Constructor<TStorage>, { id, name, alias, backendOpener, backendCacheKey, }: (ExplicitStorageIdentifier | DefaultStorageIdentifier) & {
41
+ backendOpener: () => Promise<DatasetBackend | KeyValueStoreBackend | RequestQueueBackend>;
42
+ backendCacheKey: Hashable;
43
+ }): Promise<TStorage>;
44
+ /**
45
+ * Remove a storage instance from the cache (called from `storage.drop()`).
46
+ */
47
+ removeFromCache(instance: IStorage): void;
48
+ /**
49
+ * Clear the entire cache. Also calls `clearCache()` on any cached KeyValueStore
50
+ * instances (duck-typed to avoid importing KeyValueStore and circular dependencies).
51
+ * Called during service locator reset.
52
+ */
53
+ clearCache(): void;
54
+ }
55
+ /**
56
+ * A storage identifier where exactly one of `id`, `name`, or `alias` is specified.
57
+ * Produced by {@link resolveStorageIdentifier} from ambiguous user input.
58
+ */
59
+ export type ExplicitStorageIdentifier = {
60
+ id: string;
61
+ name?: never;
62
+ alias?: never;
63
+ } | {
64
+ id?: never;
65
+ name: string;
66
+ alias?: never;
67
+ } | {
68
+ id?: never;
69
+ name?: never;
70
+ alias: string;
71
+ };
72
+ /**
73
+ * Represents the case where no identifier was provided — the caller wants the default storage.
74
+ */
75
+ export interface DefaultStorageIdentifier {
76
+ id?: never;
77
+ name?: never;
78
+ alias?: never;
79
+ }
80
+ /**
81
+ * Decompose a user-provided `identifier` (the `Dataset.open()` / `KeyValueStore.open()` /
82
+ * `RequestQueue.open()` argument) into separate `id`, `name`, and `alias` fields that
83
+ * the `StorageInstanceManager` and `StorageBackend.create*Client` expect.
84
+ *
85
+ * - `null` / `undefined` / `{}` → default storage alias
86
+ * - `string` → resolved via `storageExists` (ID-first, then name)
87
+ * - `{ id }` → `{ id }`
88
+ * - `{ name }` → `{ name }`
89
+ * - `{ alias }` → `{ alias }`
90
+ */
91
+ export declare function resolveStorageIdentifier(identifier: string | StorageIdentifier | null | undefined, storageBackend: StorageBackend, storageType: 'Dataset' | 'KeyValueStore' | 'RequestQueue'): Promise<ExplicitStorageIdentifier>;