@crawlee/core 4.0.0-beta.9 → 4.0.0-beta.91

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 (263) hide show
  1. package/README.md +17 -13
  2. package/autoscaling/autoscaled_pool.d.ts +66 -153
  3. package/autoscaling/autoscaled_pool.js +95 -251
  4. package/autoscaling/client_load_signal.d.ts +59 -0
  5. package/autoscaling/client_load_signal.js +73 -0
  6. package/autoscaling/concurrency_system.d.ts +283 -0
  7. package/autoscaling/concurrency_system.js +350 -0
  8. package/autoscaling/cpu_load_signal.d.ts +44 -0
  9. package/autoscaling/cpu_load_signal.js +46 -0
  10. package/autoscaling/event_loop_load_signal.d.ts +54 -0
  11. package/autoscaling/event_loop_load_signal.js +60 -0
  12. package/autoscaling/index.d.ts +6 -1
  13. package/autoscaling/index.js +6 -1
  14. package/autoscaling/load_signal.d.ts +99 -0
  15. package/autoscaling/load_signal.js +103 -0
  16. package/autoscaling/memory_load_signal.d.ts +56 -0
  17. package/autoscaling/memory_load_signal.js +106 -0
  18. package/autoscaling/snapshotter.d.ts +61 -163
  19. package/autoscaling/snapshotter.js +45 -263
  20. package/autoscaling/system_status.d.ts +63 -83
  21. package/autoscaling/system_status.js +90 -120
  22. package/configuration.d.ts +90 -223
  23. package/configuration.js +164 -222
  24. package/cookie_utils.d.ts +4 -3
  25. package/cookie_utils.js +20 -13
  26. package/crawlers/context_pipeline.d.ts +70 -0
  27. package/crawlers/context_pipeline.js +122 -0
  28. package/crawlers/crawler_commons.d.ts +76 -33
  29. package/crawlers/crawler_commons.js +15 -24
  30. package/crawlers/crawler_utils.d.ts +2 -3
  31. package/crawlers/crawler_utils.js +1 -2
  32. package/crawlers/error_snapshotter.d.ts +3 -3
  33. package/crawlers/error_snapshotter.js +2 -3
  34. package/crawlers/error_tracker.d.ts +2 -2
  35. package/crawlers/error_tracker.js +0 -1
  36. package/crawlers/index.d.ts +1 -2
  37. package/crawlers/index.js +1 -2
  38. package/crawlers/internals/types.d.ts +7 -0
  39. package/crawlers/internals/types.js +1 -0
  40. package/crawlers/statistics.d.ts +28 -23
  41. package/crawlers/statistics.js +38 -34
  42. package/debug.d.ts +36 -0
  43. package/debug.js +70 -0
  44. package/enqueue_links/enqueue_links.d.ts +44 -22
  45. package/enqueue_links/enqueue_links.js +51 -30
  46. package/enqueue_links/index.d.ts +0 -1
  47. package/enqueue_links/index.js +0 -1
  48. package/enqueue_links/shared.d.ts +25 -9
  49. package/enqueue_links/shared.js +69 -38
  50. package/errors.d.ts +53 -4
  51. package/errors.js +70 -5
  52. package/events/event_manager.d.ts +34 -8
  53. package/events/event_manager.js +8 -10
  54. package/events/index.d.ts +0 -1
  55. package/events/index.js +0 -1
  56. package/events/local_event_manager.d.ts +15 -3
  57. package/events/local_event_manager.js +37 -11
  58. package/index.d.ts +6 -3
  59. package/index.js +5 -2
  60. package/log.d.ts +82 -3
  61. package/log.js +102 -1
  62. package/memory-storage/consts.d.ts +4 -0
  63. package/memory-storage/consts.js +4 -0
  64. package/memory-storage/index.d.ts +1 -0
  65. package/memory-storage/index.js +1 -0
  66. package/memory-storage/memory-storage.d.ts +46 -0
  67. package/memory-storage/memory-storage.js +136 -0
  68. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  69. package/memory-storage/resource-clients/common/base-client.js +6 -0
  70. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  71. package/memory-storage/resource-clients/dataset.js +113 -0
  72. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  73. package/memory-storage/resource-clients/key-value-store.js +203 -0
  74. package/memory-storage/resource-clients/request-queue.d.ts +96 -0
  75. package/memory-storage/resource-clients/request-queue.js +421 -0
  76. package/memory-storage/utils.d.ts +17 -0
  77. package/memory-storage/utils.js +42 -0
  78. package/owned_or_injected.d.ts +60 -0
  79. package/owned_or_injected.js +98 -0
  80. package/package.json +12 -10
  81. package/proxy_configuration.d.ts +29 -152
  82. package/proxy_configuration.js +21 -173
  83. package/recoverable_state.d.ts +120 -0
  84. package/recoverable_state.js +143 -0
  85. package/request.d.ts +85 -15
  86. package/request.js +107 -28
  87. package/router.d.ts +144 -19
  88. package/router.js +125 -30
  89. package/serialization.d.ts +0 -1
  90. package/serialization.js +1 -2
  91. package/service_locator.d.ts +156 -0
  92. package/service_locator.js +238 -0
  93. package/session_pool/consts.d.ts +1 -2
  94. package/session_pool/consts.js +1 -2
  95. package/session_pool/errors.d.ts +0 -1
  96. package/session_pool/errors.js +0 -1
  97. package/session_pool/fingerprint.d.ts +9 -0
  98. package/session_pool/fingerprint.js +30 -0
  99. package/session_pool/index.d.ts +0 -2
  100. package/session_pool/index.js +0 -2
  101. package/session_pool/session.d.ts +37 -75
  102. package/session_pool/session.js +49 -102
  103. package/session_pool/session_pool.d.ts +85 -90
  104. package/session_pool/session_pool.js +131 -120
  105. package/storages/access_checking.d.ts +1 -2
  106. package/storages/access_checking.js +5 -2
  107. package/storages/dataset.d.ts +103 -54
  108. package/storages/dataset.js +174 -132
  109. package/storages/index.d.ts +8 -7
  110. package/storages/index.js +6 -7
  111. package/storages/key_value_store.d.ts +167 -39
  112. package/storages/key_value_store.js +274 -127
  113. package/storages/key_value_store_codec.d.ts +32 -0
  114. package/storages/key_value_store_codec.js +113 -0
  115. package/storages/request_dedup_cache.d.ts +23 -0
  116. package/storages/request_dedup_cache.js +48 -0
  117. package/storages/request_list.d.ts +54 -98
  118. package/storages/request_list.js +99 -75
  119. package/storages/request_loader.d.ts +96 -0
  120. package/storages/request_loader.js +1 -0
  121. package/storages/request_manager.d.ts +33 -0
  122. package/storages/request_manager.js +1 -0
  123. package/storages/request_manager_tandem.d.ts +106 -0
  124. package/storages/request_manager_tandem.js +197 -0
  125. package/storages/request_queue.d.ts +290 -47
  126. package/storages/request_queue.js +629 -215
  127. package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +28 -24
  128. package/storages/{sitemap_request_list.js → sitemap_request_loader.js} +49 -47
  129. package/storages/storage_instance_manager.d.ts +90 -0
  130. package/storages/storage_instance_manager.js +258 -0
  131. package/storages/storage_stats.d.ts +48 -0
  132. package/storages/storage_stats.js +29 -0
  133. package/storages/utils.d.ts +54 -9
  134. package/storages/utils.js +64 -13
  135. package/system-info/cpu-info.d.ts +67 -0
  136. package/system-info/cpu-info.js +216 -0
  137. package/system-info/memory-info.d.ts +31 -0
  138. package/system-info/memory-info.js +115 -0
  139. package/system-info/ps-tree.d.ts +17 -0
  140. package/system-info/ps-tree.js +144 -0
  141. package/system-info/runtime.d.ts +14 -0
  142. package/system-info/runtime.js +80 -0
  143. package/typedefs.d.ts +0 -6
  144. package/typedefs.js +0 -1
  145. package/validators.d.ts +8 -1
  146. package/validators.js +10 -3
  147. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  148. package/autoscaling/autoscaled_pool.js.map +0 -1
  149. package/autoscaling/index.d.ts.map +0 -1
  150. package/autoscaling/index.js.map +0 -1
  151. package/autoscaling/snapshotter.d.ts.map +0 -1
  152. package/autoscaling/snapshotter.js.map +0 -1
  153. package/autoscaling/system_status.d.ts.map +0 -1
  154. package/autoscaling/system_status.js.map +0 -1
  155. package/configuration.d.ts.map +0 -1
  156. package/configuration.js.map +0 -1
  157. package/cookie_utils.d.ts.map +0 -1
  158. package/cookie_utils.js.map +0 -1
  159. package/crawlers/crawler_commons.d.ts.map +0 -1
  160. package/crawlers/crawler_commons.js.map +0 -1
  161. package/crawlers/crawler_extension.d.ts +0 -12
  162. package/crawlers/crawler_extension.d.ts.map +0 -1
  163. package/crawlers/crawler_extension.js +0 -14
  164. package/crawlers/crawler_extension.js.map +0 -1
  165. package/crawlers/crawler_utils.d.ts.map +0 -1
  166. package/crawlers/crawler_utils.js.map +0 -1
  167. package/crawlers/error_snapshotter.d.ts.map +0 -1
  168. package/crawlers/error_snapshotter.js.map +0 -1
  169. package/crawlers/error_tracker.d.ts.map +0 -1
  170. package/crawlers/error_tracker.js.map +0 -1
  171. package/crawlers/index.d.ts.map +0 -1
  172. package/crawlers/index.js.map +0 -1
  173. package/crawlers/statistics.d.ts.map +0 -1
  174. package/crawlers/statistics.js.map +0 -1
  175. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  176. package/enqueue_links/enqueue_links.js.map +0 -1
  177. package/enqueue_links/index.d.ts.map +0 -1
  178. package/enqueue_links/index.js.map +0 -1
  179. package/enqueue_links/shared.d.ts.map +0 -1
  180. package/enqueue_links/shared.js.map +0 -1
  181. package/errors.d.ts.map +0 -1
  182. package/errors.js.map +0 -1
  183. package/events/event_manager.d.ts.map +0 -1
  184. package/events/event_manager.js.map +0 -1
  185. package/events/index.d.ts.map +0 -1
  186. package/events/index.js.map +0 -1
  187. package/events/local_event_manager.d.ts.map +0 -1
  188. package/events/local_event_manager.js.map +0 -1
  189. package/http_clients/base-http-client.d.ts +0 -134
  190. package/http_clients/base-http-client.d.ts.map +0 -1
  191. package/http_clients/base-http-client.js +0 -33
  192. package/http_clients/base-http-client.js.map +0 -1
  193. package/http_clients/form-data-like.d.ts +0 -67
  194. package/http_clients/form-data-like.d.ts.map +0 -1
  195. package/http_clients/form-data-like.js +0 -5
  196. package/http_clients/form-data-like.js.map +0 -1
  197. package/http_clients/got-scraping-http-client.d.ts +0 -15
  198. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  199. package/http_clients/got-scraping-http-client.js +0 -69
  200. package/http_clients/got-scraping-http-client.js.map +0 -1
  201. package/http_clients/index.d.ts +0 -3
  202. package/http_clients/index.d.ts.map +0 -1
  203. package/http_clients/index.js +0 -3
  204. package/http_clients/index.js.map +0 -1
  205. package/index.d.ts.map +0 -1
  206. package/index.js.map +0 -1
  207. package/log.d.ts.map +0 -1
  208. package/log.js.map +0 -1
  209. package/proxy_configuration.d.ts.map +0 -1
  210. package/proxy_configuration.js.map +0 -1
  211. package/request.d.ts.map +0 -1
  212. package/request.js.map +0 -1
  213. package/router.d.ts.map +0 -1
  214. package/router.js.map +0 -1
  215. package/serialization.d.ts.map +0 -1
  216. package/serialization.js.map +0 -1
  217. package/session_pool/consts.d.ts.map +0 -1
  218. package/session_pool/consts.js.map +0 -1
  219. package/session_pool/errors.d.ts.map +0 -1
  220. package/session_pool/errors.js.map +0 -1
  221. package/session_pool/events.d.ts +0 -3
  222. package/session_pool/events.d.ts.map +0 -1
  223. package/session_pool/events.js +0 -3
  224. package/session_pool/events.js.map +0 -1
  225. package/session_pool/index.d.ts.map +0 -1
  226. package/session_pool/index.js.map +0 -1
  227. package/session_pool/session.d.ts.map +0 -1
  228. package/session_pool/session.js.map +0 -1
  229. package/session_pool/session_pool.d.ts.map +0 -1
  230. package/session_pool/session_pool.js.map +0 -1
  231. package/storages/access_checking.d.ts.map +0 -1
  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_provider.d.ts +0 -307
  242. package/storages/request_provider.d.ts.map +0 -1
  243. package/storages/request_provider.js +0 -555
  244. package/storages/request_provider.js.map +0 -1
  245. package/storages/request_queue.d.ts.map +0 -1
  246. package/storages/request_queue.js.map +0 -1
  247. package/storages/request_queue_v2.d.ts +0 -87
  248. package/storages/request_queue_v2.d.ts.map +0 -1
  249. package/storages/request_queue_v2.js +0 -438
  250. package/storages/request_queue_v2.js.map +0 -1
  251. package/storages/sitemap_request_list.d.ts.map +0 -1
  252. package/storages/sitemap_request_list.js.map +0 -1
  253. package/storages/storage_manager.d.ts +0 -58
  254. package/storages/storage_manager.d.ts.map +0 -1
  255. package/storages/storage_manager.js +0 -105
  256. package/storages/storage_manager.js.map +0 -1
  257. package/storages/utils.d.ts.map +0 -1
  258. package/storages/utils.js.map +0 -1
  259. package/tsconfig.build.tsbuildinfo +0 -1
  260. package/typedefs.d.ts.map +0 -1
  261. package/typedefs.js.map +0 -1
  262. package/validators.d.ts.map +0 -1
  263. 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 */
@@ -93,10 +90,10 @@ export class SitemapRequestList {
93
90
  globs: ow.optional.array.ofType(ow.any(ow.string, ow.object.hasKeys('glob'))),
94
91
  exclude: ow.optional.array.ofType(ow.any(ow.string, ow.regExp, ow.object.hasKeys('glob'), ow.object.hasKeys('regexp'))),
95
92
  regexps: ow.optional.array.ofType(ow.any(ow.regExp, ow.object.hasKeys('regexp'))),
96
- config: ow.optional.object,
97
93
  persistenceOptions: ow.optional.object,
98
94
  }));
99
- const { globs, exclude, regexps, config = Configuration.getGlobalConfig() } = options;
95
+ const { globs, exclude, regexps } = options;
96
+ this.log = serviceLocator.getLogger().child({ prefix: 'SitemapRequestLoader' });
100
97
  if (exclude?.length) {
101
98
  for (const excl of exclude) {
102
99
  if (typeof excl === 'string' || 'glob' in excl) {
@@ -118,7 +115,7 @@ export class SitemapRequestList {
118
115
  this.proxyUrl = options.proxyUrl;
119
116
  this.urlQueueStream = this.createNewStream(options.maxBufferSize ?? 200);
120
117
  this.sitemapParsingProgress.pendingSitemapUrls = new Set(options.sitemapUrls);
121
- this.events = config.getEventManager();
118
+ this.events = serviceLocator.getEventManager();
122
119
  this.persistState = this.persistState.bind(this);
123
120
  }
124
121
  /**
@@ -248,17 +245,20 @@ export class SitemapRequestList {
248
245
  /**
249
246
  * Open a sitemap and start processing it.
250
247
  *
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.
248
+ * 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
249
  *
253
250
  * Track the loading progress using the `isSitemapFullyLoaded` property.
254
251
  */
255
252
  static async open(options) {
256
- const requestList = new SitemapRequestList({
257
- ...options,
253
+ const { httpClient, ...restOptions } = options;
254
+ const requestList = new SitemapRequestLoader({
255
+ ...restOptions,
258
256
  persistStateKey: options.persistStateKey ?? STATE_PERSISTENCE_KEY,
259
257
  });
260
258
  await requestList.restoreState();
261
- void requestList.load({ parseSitemapOptions: options.parseSitemapOptions });
259
+ void requestList.load({
260
+ parseSitemapOptions: { logger: serviceLocator.getLogger(), ...options.parseSitemapOptions, httpClient },
261
+ });
262
262
  if (requestList.persistenceOptions.enable) {
263
263
  requestList.events.on("persistState" /* EventType.PERSIST_STATE */, requestList.persistState);
264
264
  }
@@ -275,8 +275,28 @@ export class SitemapRequestList {
275
275
  /**
276
276
  * @inheritDoc
277
277
  */
278
- length() {
279
- return this.urlQueueStream.readableLength + this.handledUrlCount - this.inProgress.size - this.reclaimed.size;
278
+ async getTotalCount() {
279
+ // Total known so far = not-yet-fetched (still buffered in the stream) + in-progress (fetched but not
280
+ // yet handled) + already handled.
281
+ return this.urlQueueStream.readableLength + this.inProgress.size + this.handledUrlCount;
282
+ }
283
+ /**
284
+ * @inheritDoc
285
+ */
286
+ async getPendingCount() {
287
+ // Pending = everything not yet handled = not-yet-fetched + in-progress.
288
+ return this.urlQueueStream.readableLength + this.inProgress.size;
289
+ }
290
+ /**
291
+ * Combines this list with a request manager (a {@link RequestQueue} by default) into a
292
+ * {@link RequestManagerTandem}, allowing requests to be added and reclaimed while still
293
+ * being read from this list first.
294
+ */
295
+ async toTandem(requestManager) {
296
+ // Import here to avoid circular imports.
297
+ const { RequestManagerTandem } = await import('./request_manager_tandem.js');
298
+ const { RequestQueue } = await import('./request_queue.js');
299
+ return new RequestManagerTandem(this, requestManager ?? (await RequestQueue.open()));
280
300
  }
281
301
  /**
282
302
  * @inheritDoc
@@ -288,12 +308,12 @@ export class SitemapRequestList {
288
308
  * @inheritDoc
289
309
  */
290
310
  async isEmpty() {
291
- return this.reclaimed.size === 0 && this.urlQueueStream.readableLength === 0;
311
+ return this.urlQueueStream.readableLength === 0;
292
312
  }
293
313
  /**
294
314
  * @inheritDoc
295
315
  */
296
- handledCount() {
316
+ async getHandledCount() {
297
317
  return this.handledUrlCount;
298
318
  }
299
319
  /**
@@ -328,8 +348,8 @@ export class SitemapRequestList {
328
348
  inProgressSitemapUrl: this.sitemapParsingProgress.inProgressSitemapUrl,
329
349
  inProgressEntries: Array.from(this.sitemapParsingProgress.inProgressEntries),
330
350
  },
331
- urlQueue,
332
- reclaimed: [...this.inProgress, ...this.reclaimed], // In-progress and reclaimed requests will be both retried if state is restored
351
+ // Re-queue in-progress requests to the front so they are retried if the state is restored.
352
+ urlQueue: [...this.inProgress, ...urlQueue],
333
353
  requestData: Array.from(this.requestData.entries()),
334
354
  abortLoading: this.abortLoading,
335
355
  closed: this.closed,
@@ -345,7 +365,6 @@ export class SitemapRequestList {
345
365
  if (state === null) {
346
366
  return;
347
367
  }
348
- this.reclaimed = new Set(state.reclaimed);
349
368
  this.sitemapParsingProgress = {
350
369
  pendingSitemapUrls: new Set(state.sitemapParsingProgress.pendingSitemapUrls),
351
370
  inProgressSitemapUrl: state.sitemapParsingProgress.inProgressSitemapUrl,
@@ -362,17 +381,12 @@ export class SitemapRequestList {
362
381
  * @inheritDoc
363
382
  */
364
383
  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);
384
+ const nextUrl = await this.readNextUrl();
385
+ if (!nextUrl) {
386
+ return null;
369
387
  }
370
- else {
371
- // Otherwise read next url from the stream
372
- nextUrl = await this.readNextUrl();
373
- if (!nextUrl) {
374
- return null;
375
- }
388
+ // A restored in-progress request already has its Request data; don't overwrite it.
389
+ if (!this.requestData.has(nextUrl)) {
376
390
  this.requestData.set(nextUrl, new Request({ url: nextUrl }));
377
391
  }
378
392
  this.inProgress.add(nextUrl);
@@ -389,14 +403,6 @@ export class SitemapRequestList {
389
403
  yield request;
390
404
  }
391
405
  }
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
406
  /**
401
407
  * Aborts the internal sitemap loading, stops the processing of the sitemap contents and drops all the pending URLs.
402
408
  *
@@ -412,19 +418,15 @@ export class SitemapRequestList {
412
418
  /**
413
419
  * @inheritDoc
414
420
  */
415
- async markRequestHandled(request) {
421
+ async markRequestAsHandled(request) {
416
422
  this.handledUrlCount += 1;
417
- this.ensureInProgressAndNotReclaimed(request.url);
423
+ this.ensureInProgress(request.url);
418
424
  this.inProgress.delete(request.url);
419
425
  this.requestData.delete(request.url);
420
426
  }
421
- ensureInProgressAndNotReclaimed(url) {
427
+ ensureInProgress(url) {
422
428
  if (!this.inProgress.has(url)) {
423
429
  throw new Error(`The request is not being processed (url: ${url})`);
424
430
  }
425
- if (this.reclaimed.has(url)) {
426
- throw new Error(`The request was already reclaimed (url: ${url})`);
427
- }
428
431
  }
429
432
  }
430
- //# sourceMappingURL=sitemap_request_list.js.map
@@ -0,0 +1,90 @@
1
+ import type { Constructor, DatasetBackend, KeyValueStoreBackend, RequestQueueBackend, StorageBackend, StorageIdentifier } from '@crawlee/types';
2
+ export type { StorageIdentifier } from '@crawlee/types';
3
+ /**
4
+ * Matches an `IStorage` – a storage "frontend" (Dataset, KeyValueStore, RequestQueue).
5
+ */
6
+ export interface IStorage {
7
+ id: string;
8
+ name?: string;
9
+ }
10
+ type Hashable = string;
11
+ /**
12
+ * Unified manager for opening and caching storage instances (Dataset, KeyValueStore, RequestQueue).
13
+ *
14
+ * A single instance manages all storage types. Instances are cached by
15
+ * `(storageClass, id/name/alias, backendCacheKey)` so the same storage is never opened twice.
16
+ *
17
+ * The manager itself does not resolve identifiers — callers pass explicit `id`, `name`, or `alias` (at most one),
18
+ * and a pre-bound `backendOpener` promise. When none of `id`, `name`, `alias` are provided, the manager automatically
19
+ * assigns a reserved default alias.
20
+ *
21
+ * @ignore
22
+ */
23
+ export declare class StorageInstanceManager {
24
+ private readonly cache;
25
+ private readonly openerLocks;
26
+ /**
27
+ * Open (or retrieve from cache) a storage instance.
28
+ *
29
+ * @param cls The storage class constructor (e.g. `Dataset`, `KeyValueStore`, `RequestQueue`).
30
+ * @param id Storage ID (mutually exclusive with `name` and `alias`).
31
+ * @param name Storage name (mutually exclusive with `id` and `alias`).
32
+ * @param alias Run-scoped alias (mutually exclusive with `id` and `name`).
33
+ * Automatically assigned when no identifier is provided.
34
+ * @param backendOpener A **lazy** factory that creates the sub-backend.
35
+ * Only called on a cache miss.
36
+ * @param backendCacheKey Opaque key identifying the storage backend, so that the same logical
37
+ * storage opened through different clients is cached separately.
38
+ */
39
+ openStorage<TStorage extends IStorage>(cls: Constructor<TStorage>, { id, name, alias, backendOpener, backendCacheKey, }: (ExplicitStorageIdentifier | DefaultStorageIdentifier) & {
40
+ backendOpener: () => Promise<DatasetBackend | KeyValueStoreBackend | RequestQueueBackend>;
41
+ backendCacheKey: Hashable;
42
+ }): Promise<TStorage>;
43
+ /**
44
+ * Remove a storage instance from the cache (called from `storage.drop()`).
45
+ */
46
+ removeFromCache(instance: IStorage): void;
47
+ /**
48
+ * Clear the entire cache. Also calls `clearCache()` on any cached KeyValueStore
49
+ * instances (duck-typed to avoid importing KeyValueStore and circular dependencies).
50
+ * Called during service locator reset.
51
+ */
52
+ clearCache(): void;
53
+ }
54
+ /**
55
+ * A storage identifier where exactly one of `id`, `name`, or `alias` is specified.
56
+ * Produced by {@link resolveStorageIdentifier} from ambiguous user input.
57
+ */
58
+ export type ExplicitStorageIdentifier = {
59
+ id: string;
60
+ name?: never;
61
+ alias?: never;
62
+ } | {
63
+ id?: never;
64
+ name: string;
65
+ alias?: never;
66
+ } | {
67
+ id?: never;
68
+ name?: never;
69
+ alias: string;
70
+ };
71
+ /**
72
+ * Represents the case where no identifier was provided — the caller wants the default storage.
73
+ */
74
+ export interface DefaultStorageIdentifier {
75
+ id?: never;
76
+ name?: never;
77
+ alias?: never;
78
+ }
79
+ /**
80
+ * Decompose a user-provided `identifier` (the `Dataset.open()` / `KeyValueStore.open()` /
81
+ * `RequestQueue.open()` argument) into separate `id`, `name`, and `alias` fields that
82
+ * the `StorageInstanceManager` and `StorageBackend.create*Client` expect.
83
+ *
84
+ * - `null` / `undefined` / `{}` → default storage alias
85
+ * - `string` → resolved via `storageExists` (ID-first, then name)
86
+ * - `{ id }` → `{ id }`
87
+ * - `{ name }` → `{ name }`
88
+ * - `{ alias }` → `{ alias }`
89
+ */
90
+ export declare function resolveStorageIdentifier(identifier: string | StorageIdentifier | null | undefined, storageBackend: StorageBackend, storageType: 'Dataset' | 'KeyValueStore' | 'RequestQueue'): Promise<ExplicitStorageIdentifier>;