@crawlee/core 4.0.0-beta.18 → 4.0.0-beta.180

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/README.md +14 -14
  2. package/byte_utils.d.ts +17 -0
  3. package/byte_utils.js +42 -0
  4. package/configuration.d.ts +90 -226
  5. package/configuration.js +164 -225
  6. package/debug.d.ts +36 -0
  7. package/debug.js +70 -0
  8. package/errors.d.ts +40 -19
  9. package/errors.js +53 -28
  10. package/events/event_manager.d.ts +35 -9
  11. package/events/event_manager.js +12 -13
  12. package/events/index.d.ts +1 -1
  13. package/events/index.js +0 -1
  14. package/events/local_event_manager.d.ts +15 -3
  15. package/events/local_event_manager.js +39 -13
  16. package/events/system_info.d.ts +38 -0
  17. package/events/system_info.js +1 -0
  18. package/index.d.ts +7 -11
  19. package/index.js +8 -10
  20. package/internal.d.ts +8 -0
  21. package/internal.js +9 -0
  22. package/iterables.d.ts +79 -0
  23. package/iterables.js +134 -0
  24. package/log.d.ts +77 -1
  25. package/log.js +134 -1
  26. package/memory-storage/consts.d.ts +4 -0
  27. package/memory-storage/consts.js +4 -0
  28. package/memory-storage/index.d.ts +1 -0
  29. package/memory-storage/index.js +1 -0
  30. package/memory-storage/memory-storage.d.ts +44 -0
  31. package/memory-storage/memory-storage.js +160 -0
  32. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  33. package/memory-storage/resource-clients/common/base-client.js +6 -0
  34. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  35. package/memory-storage/resource-clients/dataset.js +106 -0
  36. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  37. package/memory-storage/resource-clients/key-value-store.js +199 -0
  38. package/memory-storage/resource-clients/request-queue.d.ts +77 -0
  39. package/memory-storage/resource-clients/request-queue.js +414 -0
  40. package/memory-storage/utils.d.ts +16 -0
  41. package/memory-storage/utils.js +41 -0
  42. package/owned_or_injected.d.ts +58 -0
  43. package/owned_or_injected.js +98 -0
  44. package/package.json +18 -19
  45. package/proxy_configuration.d.ts +22 -128
  46. package/proxy_configuration.js +32 -144
  47. package/recoverable_state.d.ts +85 -51
  48. package/recoverable_state.js +178 -72
  49. package/request.d.ts +60 -17
  50. package/request.js +130 -69
  51. package/serialization.d.ts +0 -1
  52. package/serialization.js +15 -15
  53. package/service_locator.d.ts +165 -0
  54. package/service_locator.js +254 -0
  55. package/storages/batched_adds.d.ts +37 -0
  56. package/storages/batched_adds.js +73 -0
  57. package/storages/dataset.d.ts +114 -56
  58. package/storages/dataset.js +292 -149
  59. package/storages/index.d.ts +7 -9
  60. package/storages/index.js +5 -9
  61. package/storages/key_value_store.d.ts +187 -50
  62. package/storages/key_value_store.js +453 -172
  63. package/storages/key_value_store_codec.d.ts +32 -0
  64. package/storages/key_value_store_codec.js +113 -0
  65. package/storages/request_dedup_cache.d.ts +22 -0
  66. package/storages/request_dedup_cache.js +48 -0
  67. package/storages/request_list.d.ts +54 -129
  68. package/storages/request_list.js +272 -245
  69. package/storages/request_loader.d.ts +127 -0
  70. package/storages/request_loader.js +36 -0
  71. package/storages/request_manager.d.ts +109 -0
  72. package/storages/request_manager.js +1 -0
  73. package/storages/request_manager_tandem.d.ts +50 -23
  74. package/storages/request_manager_tandem.js +132 -57
  75. package/storages/request_queue.d.ts +286 -48
  76. package/storages/request_queue.js +757 -218
  77. package/storages/storage_instance_manager.d.ts +87 -0
  78. package/storages/storage_instance_manager.js +256 -0
  79. package/storages/storage_stats.d.ts +48 -0
  80. package/storages/storage_stats.js +29 -0
  81. package/storages/transaction.d.ts +260 -0
  82. package/storages/transaction.js +287 -0
  83. package/storages/utils.d.ts +59 -11
  84. package/storages/utils.js +75 -15
  85. package/system-info/cpu-info.d.ts +67 -0
  86. package/system-info/cpu-info.js +216 -0
  87. package/system-info/memory-info.d.ts +31 -0
  88. package/system-info/memory-info.js +115 -0
  89. package/system-info/ps-tree.d.ts +17 -0
  90. package/system-info/ps-tree.js +144 -0
  91. package/system-info/runtime.d.ts +14 -0
  92. package/system-info/runtime.js +80 -0
  93. package/typedefs.d.ts +0 -6
  94. package/typedefs.js +0 -1
  95. package/url.d.ts +9 -0
  96. package/url.js +11 -0
  97. package/validators.d.ts +23 -18
  98. package/validators.js +14 -18
  99. package/autoscaling/autoscaled_pool.d.ts +0 -300
  100. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  101. package/autoscaling/autoscaled_pool.js +0 -533
  102. package/autoscaling/autoscaled_pool.js.map +0 -1
  103. package/autoscaling/index.d.ts +0 -4
  104. package/autoscaling/index.d.ts.map +0 -1
  105. package/autoscaling/index.js +0 -4
  106. package/autoscaling/index.js.map +0 -1
  107. package/autoscaling/snapshotter.d.ts +0 -189
  108. package/autoscaling/snapshotter.d.ts.map +0 -1
  109. package/autoscaling/snapshotter.js +0 -285
  110. package/autoscaling/snapshotter.js.map +0 -1
  111. package/autoscaling/system_status.d.ts +0 -181
  112. package/autoscaling/system_status.d.ts.map +0 -1
  113. package/autoscaling/system_status.js +0 -169
  114. package/autoscaling/system_status.js.map +0 -1
  115. package/configuration.d.ts.map +0 -1
  116. package/configuration.js.map +0 -1
  117. package/cookie_utils.d.ts +0 -43
  118. package/cookie_utils.d.ts.map +0 -1
  119. package/cookie_utils.js +0 -111
  120. package/cookie_utils.js.map +0 -1
  121. package/crawlers/context_pipeline.d.ts +0 -61
  122. package/crawlers/context_pipeline.d.ts.map +0 -1
  123. package/crawlers/context_pipeline.js +0 -99
  124. package/crawlers/context_pipeline.js.map +0 -1
  125. package/crawlers/crawler_commons.d.ts +0 -195
  126. package/crawlers/crawler_commons.d.ts.map +0 -1
  127. package/crawlers/crawler_commons.js +0 -108
  128. package/crawlers/crawler_commons.js.map +0 -1
  129. package/crawlers/crawler_utils.d.ts +0 -10
  130. package/crawlers/crawler_utils.d.ts.map +0 -1
  131. package/crawlers/crawler_utils.js +0 -12
  132. package/crawlers/crawler_utils.js.map +0 -1
  133. package/crawlers/error_snapshotter.d.ts +0 -60
  134. package/crawlers/error_snapshotter.d.ts.map +0 -1
  135. package/crawlers/error_snapshotter.js +0 -118
  136. package/crawlers/error_snapshotter.js.map +0 -1
  137. package/crawlers/error_tracker.d.ts +0 -55
  138. package/crawlers/error_tracker.d.ts.map +0 -1
  139. package/crawlers/error_tracker.js +0 -309
  140. package/crawlers/error_tracker.js.map +0 -1
  141. package/crawlers/index.d.ts +0 -7
  142. package/crawlers/index.d.ts.map +0 -1
  143. package/crawlers/index.js +0 -7
  144. package/crawlers/index.js.map +0 -1
  145. package/crawlers/internals/types.d.ts +0 -8
  146. package/crawlers/internals/types.d.ts.map +0 -1
  147. package/crawlers/internals/types.js +0 -2
  148. package/crawlers/internals/types.js.map +0 -1
  149. package/crawlers/statistics.d.ts +0 -204
  150. package/crawlers/statistics.d.ts.map +0 -1
  151. package/crawlers/statistics.js +0 -346
  152. package/crawlers/statistics.js.map +0 -1
  153. package/enqueue_links/enqueue_links.d.ts +0 -249
  154. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  155. package/enqueue_links/enqueue_links.js +0 -269
  156. package/enqueue_links/enqueue_links.js.map +0 -1
  157. package/enqueue_links/index.d.ts +0 -3
  158. package/enqueue_links/index.d.ts.map +0 -1
  159. package/enqueue_links/index.js +0 -3
  160. package/enqueue_links/index.js.map +0 -1
  161. package/enqueue_links/shared.d.ts +0 -73
  162. package/enqueue_links/shared.d.ts.map +0 -1
  163. package/enqueue_links/shared.js +0 -212
  164. package/enqueue_links/shared.js.map +0 -1
  165. package/errors.d.ts.map +0 -1
  166. package/errors.js.map +0 -1
  167. package/events/event_manager.d.ts.map +0 -1
  168. package/events/event_manager.js.map +0 -1
  169. package/events/index.d.ts.map +0 -1
  170. package/events/index.js.map +0 -1
  171. package/events/local_event_manager.d.ts.map +0 -1
  172. package/events/local_event_manager.js.map +0 -1
  173. package/http_clients/base-http-client.d.ts +0 -91
  174. package/http_clients/base-http-client.d.ts.map +0 -1
  175. package/http_clients/base-http-client.js +0 -44
  176. package/http_clients/base-http-client.js.map +0 -1
  177. package/http_clients/form-data-like.d.ts +0 -67
  178. package/http_clients/form-data-like.d.ts.map +0 -1
  179. package/http_clients/form-data-like.js +0 -5
  180. package/http_clients/form-data-like.js.map +0 -1
  181. package/http_clients/got-scraping-http-client.d.ts +0 -20
  182. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  183. package/http_clients/got-scraping-http-client.js +0 -102
  184. package/http_clients/got-scraping-http-client.js.map +0 -1
  185. package/http_clients/index.d.ts +0 -3
  186. package/http_clients/index.d.ts.map +0 -1
  187. package/http_clients/index.js +0 -3
  188. package/http_clients/index.js.map +0 -1
  189. package/index.d.ts.map +0 -1
  190. package/index.js.map +0 -1
  191. package/log.d.ts.map +0 -1
  192. package/log.js.map +0 -1
  193. package/proxy_configuration.d.ts.map +0 -1
  194. package/proxy_configuration.js.map +0 -1
  195. package/recoverable_state.d.ts.map +0 -1
  196. package/recoverable_state.js.map +0 -1
  197. package/request.d.ts.map +0 -1
  198. package/request.js.map +0 -1
  199. package/router.d.ts +0 -134
  200. package/router.d.ts.map +0 -1
  201. package/router.js +0 -164
  202. package/router.js.map +0 -1
  203. package/serialization.d.ts.map +0 -1
  204. package/serialization.js.map +0 -1
  205. package/session_pool/consts.d.ts +0 -4
  206. package/session_pool/consts.d.ts.map +0 -1
  207. package/session_pool/consts.js +0 -4
  208. package/session_pool/consts.js.map +0 -1
  209. package/session_pool/errors.d.ts +0 -8
  210. package/session_pool/errors.d.ts.map +0 -1
  211. package/session_pool/errors.js +0 -12
  212. package/session_pool/errors.js.map +0 -1
  213. package/session_pool/events.d.ts +0 -3
  214. package/session_pool/events.d.ts.map +0 -1
  215. package/session_pool/events.js +0 -3
  216. package/session_pool/events.js.map +0 -1
  217. package/session_pool/index.d.ts +0 -6
  218. package/session_pool/index.d.ts.map +0 -1
  219. package/session_pool/index.js +0 -6
  220. package/session_pool/index.js.map +0 -1
  221. package/session_pool/session.d.ts +0 -203
  222. package/session_pool/session.d.ts.map +0 -1
  223. package/session_pool/session.js +0 -278
  224. package/session_pool/session.js.map +0 -1
  225. package/session_pool/session_pool.d.ts +0 -258
  226. package/session_pool/session_pool.d.ts.map +0 -1
  227. package/session_pool/session_pool.js +0 -387
  228. package/session_pool/session_pool.js.map +0 -1
  229. package/storages/access_checking.d.ts +0 -13
  230. package/storages/access_checking.d.ts.map +0 -1
  231. package/storages/access_checking.js +0 -14
  232. package/storages/access_checking.js.map +0 -1
  233. package/storages/dataset.d.ts.map +0 -1
  234. package/storages/dataset.js.map +0 -1
  235. package/storages/index.d.ts.map +0 -1
  236. package/storages/index.js.map +0 -1
  237. package/storages/key_value_store.d.ts.map +0 -1
  238. package/storages/key_value_store.js.map +0 -1
  239. package/storages/request_list.d.ts.map +0 -1
  240. package/storages/request_list.js.map +0 -1
  241. package/storages/request_list_adapter.d.ts +0 -58
  242. package/storages/request_list_adapter.d.ts.map +0 -1
  243. package/storages/request_list_adapter.js +0 -81
  244. package/storages/request_list_adapter.js.map +0 -1
  245. package/storages/request_manager_tandem.d.ts.map +0 -1
  246. package/storages/request_manager_tandem.js.map +0 -1
  247. package/storages/request_provider.d.ts +0 -371
  248. package/storages/request_provider.d.ts.map +0 -1
  249. package/storages/request_provider.js +0 -585
  250. package/storages/request_provider.js.map +0 -1
  251. package/storages/request_queue.d.ts.map +0 -1
  252. package/storages/request_queue.js.map +0 -1
  253. package/storages/request_queue_v2.d.ts +0 -87
  254. package/storages/request_queue_v2.d.ts.map +0 -1
  255. package/storages/request_queue_v2.js +0 -438
  256. package/storages/request_queue_v2.js.map +0 -1
  257. package/storages/sitemap_request_list.d.ts +0 -245
  258. package/storages/sitemap_request_list.d.ts.map +0 -1
  259. package/storages/sitemap_request_list.js +0 -430
  260. package/storages/sitemap_request_list.js.map +0 -1
  261. package/storages/storage_manager.d.ts +0 -58
  262. package/storages/storage_manager.d.ts.map +0 -1
  263. package/storages/storage_manager.js +0 -105
  264. package/storages/storage_manager.js.map +0 -1
  265. package/storages/utils.d.ts.map +0 -1
  266. package/storages/utils.js.map +0 -1
  267. package/typedefs.d.ts.map +0 -1
  268. package/typedefs.js.map +0 -1
  269. package/validators.d.ts.map +0 -1
  270. package/validators.js.map +0 -1
@@ -1,245 +0,0 @@
1
- import { type ParseSitemapOptions } from '@crawlee/utils';
2
- import { Configuration } from '../configuration.js';
3
- import type { GlobInput, RegExpInput } from '../enqueue_links/shared.js';
4
- import { Request } from '../request.js';
5
- import type { IRequestList } from './request_list.js';
6
- interface UrlConstraints {
7
- /**
8
- * An array of glob pattern strings or plain objects
9
- * containing glob pattern strings matching the URLs to be enqueued.
10
- *
11
- * The plain objects must include at least the `glob` property, which holds the glob pattern string.
12
- *
13
- * The matching is always case-insensitive.
14
- * If you need case-sensitive matching, use `regexps` property directly.
15
- *
16
- * If `globs` is an empty array or `undefined`, and `regexps` are also not defined, then the `SitemapRequestList`
17
- * includes all the URLs from the sitemap.
18
- */
19
- globs?: readonly GlobInput[];
20
- /**
21
- * An array of glob pattern strings, regexp patterns or plain objects
22
- * containing patterns matching URLs that will **never** be included.
23
- *
24
- * The plain objects must include either the `glob` property or the `regexp` property.
25
- *
26
- * Glob matching is always case-insensitive.
27
- * If you need case-sensitive matching, provide a regexp.
28
- */
29
- exclude?: readonly (GlobInput | RegExp)[];
30
- /**
31
- * An array of regular expressions or plain objects
32
- * containing regular expressions matching the URLs to be enqueued.
33
- *
34
- * The plain objects must include at least the `regexp` property, which holds the regular expression.
35
- *
36
- * If `regexps` is an empty array or `undefined`, and `globs` are also not defined, then the `SitemapRequestList`
37
- * includes all the URLs from the sitemap.
38
- */
39
- regexps?: readonly RegExpInput[];
40
- }
41
- export interface SitemapRequestListOptions extends UrlConstraints {
42
- /**
43
- * List of sitemap URLs to parse.
44
- */
45
- sitemapUrls: string[];
46
- /**
47
- * Proxy URL to be used for sitemap loading.
48
- */
49
- proxyUrl?: string;
50
- /**
51
- * Key for persisting the state of the request list in the `KeyValueStore`.
52
- */
53
- persistStateKey?: string;
54
- /**
55
- * Persistence-related options to control how and when crawler's data gets persisted.
56
- */
57
- persistenceOptions?: {
58
- /**
59
- * Use this flag to disable or enable periodic persistence to key value store.
60
- * @default true
61
- */
62
- enable?: boolean;
63
- };
64
- /**
65
- * Abort signal to be used for sitemap loading.
66
- */
67
- signal?: AbortSignal;
68
- /**
69
- * Timeout for sitemap loading in milliseconds. If both `signal` and `timeoutMillis` are provided, either of them can abort the loading.
70
- */
71
- timeoutMillis?: number;
72
- /**
73
- * Maximum number of buffered URLs for the sitemap loading stream.
74
- * If the buffer is full, the stream will pause until the buffer is drained.
75
- *
76
- * @default 200
77
- */
78
- maxBufferSize?: number;
79
- /**
80
- * Advanced options for the underlying `parseSitemap` call.
81
- */
82
- parseSitemapOptions?: Omit<ParseSitemapOptions, 'emitNestedSitemaps' | 'maxDepth'>;
83
- /**
84
- * Crawlee configuration
85
- */
86
- config?: Configuration;
87
- }
88
- /**
89
- * A list of URLs to crawl parsed from a sitemap.
90
- *
91
- * The loading of the sitemap is performed in the background so that crawling can start before the sitemap is fully loaded.
92
- */
93
- export declare class SitemapRequestList implements IRequestList {
94
- /**
95
- * Set of URLs that were returned by `fetchNextRequest()` and not marked as handled yet.
96
- * @internal
97
- */
98
- inProgress: Set<string>;
99
- /** Set of URLs for which `reclaimRequest()` was called. */
100
- private reclaimed;
101
- /**
102
- * Map of returned Request objects that have not been marked as handled yet.
103
- *
104
- * We use this to persist custom user fields on the in-progress (or reclaimed) requests.
105
- */
106
- private requestData;
107
- /**
108
- * Object for keeping track of the sitemap parsing progress.
109
- */
110
- private sitemapParsingProgress;
111
- /**
112
- * Object stream of URLs parsed from the sitemaps.
113
- * Using `highWaterMark`, this can manage the speed of the sitemap loading.
114
- *
115
- * Fetch the next URL to be processed using `fetchNextRequest()`.
116
- */
117
- private urlQueueStream;
118
- /**
119
- * Indicates whether the request list sitemap loading was aborted.
120
- *
121
- * If the loading was aborted before the sitemaps were fully loaded, the request list might be missing some URLs.
122
- * The `isSitemapFullyLoaded` method can be used to check if the sitemaps were fully loaded.
123
- *
124
- * If the loading is aborted and all the requests are handled, `isFinished()` will return `true`.
125
- */
126
- private abortLoading;
127
- /** Number of URLs that were marked as handled */
128
- private handledUrlCount;
129
- private persistStateKey?;
130
- private store?;
131
- private closed;
132
- /**
133
- * Proxy URL to be used for sitemap loading.
134
- */
135
- private proxyUrl;
136
- /**
137
- * Logger instance.
138
- */
139
- private log;
140
- private urlExcludePatternObjects;
141
- private urlPatternObjects;
142
- /** EventManager used to handle persistence */
143
- private events;
144
- private persistenceOptions;
145
- /** @internal */
146
- private constructor();
147
- /**
148
- * Creates a new object stream with the specified highWaterMark.
149
- * @param highWaterMark High water mark for the stream (the maximum number of objects the stream will buffer).
150
- * @returns A new object stream.
151
- */
152
- private createNewStream;
153
- /**
154
- * Returns a function that checks whether the provided pattern matches the closure URL.
155
- * @param url URL to be checked.
156
- * @returns A matcher function that checks whether the pattern matches the closure URL.
157
- */
158
- private matchesUrl;
159
- /**
160
- * Checks whether the URL matches the `globs` / `regexps` / `exclude` provided in the `options`.
161
- * @param url URL to be checked.
162
- * @returns `true` if the URL matches the patterns, `false` otherwise.
163
- */
164
- private isUrlMatchingPatterns;
165
- /**
166
- * Adds a URL to the queue of parsed URLs.
167
- *
168
- * Blocks if the stream is full until it is drained.
169
- */
170
- private pushNextUrl;
171
- /**
172
- * Reads the next URL from the queue of parsed URLs.
173
- *
174
- * If the stream is empty, blocks until a new URL is pushed.
175
- * @returns The next URL from the queue or `null` if we have read all URLs.
176
- */
177
- private readNextUrl;
178
- /**
179
- * Indicates whether the background processing of sitemap contents has successfully finished.
180
- *
181
- * If this is `false`, the background processing is either still in progress or was aborted.
182
- */
183
- isSitemapFullyLoaded(): boolean;
184
- /**
185
- * Start processing the sitemaps and loading the URLs.
186
- *
187
- * Resolves once all the sitemaps URLs have been fully loaded (sets `isSitemapFullyLoaded` to `true`).
188
- */
189
- private load;
190
- /**
191
- * Open a sitemap and start processing it.
192
- *
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.
194
- *
195
- * Track the loading progress using the `isSitemapFullyLoaded` property.
196
- */
197
- static open(options: SitemapRequestListOptions): Promise<SitemapRequestList>;
198
- /**
199
- * @inheritDoc
200
- */
201
- length(): number;
202
- /**
203
- * @inheritDoc
204
- */
205
- isFinished(): Promise<boolean>;
206
- /**
207
- * @inheritDoc
208
- */
209
- isEmpty(): Promise<boolean>;
210
- /**
211
- * @inheritDoc
212
- */
213
- handledCount(): number;
214
- /**
215
- * @inheritDoc
216
- */
217
- persistState(): Promise<void>;
218
- private restoreState;
219
- /**
220
- * @inheritDoc
221
- */
222
- fetchNextRequest(): Promise<Request | null>;
223
- /**
224
- * @inheritDoc
225
- */
226
- // @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>;
232
- /**
233
- * Aborts the internal sitemap loading, stops the processing of the sitemap contents and drops all the pending URLs.
234
- *
235
- * Calling `fetchNextRequest()` after this method will always return `null`.
236
- */
237
- teardown(): Promise<void>;
238
- /**
239
- * @inheritDoc
240
- */
241
- markRequestHandled(request: Request): Promise<void>;
242
- private ensureInProgressAndNotReclaimed;
243
- }
244
- export {};
245
- //# sourceMappingURL=sitemap_request_list.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sitemap_request_list.d.ts","sourceRoot":"","sources":["../../src/storages/sitemap_request_list.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAOxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAoB,MAAM,4BAA4B,CAAC;AAG3F,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM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;IACG,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzD,OAAO,CAAC,+BAA+B;CAQ1C"}
@@ -1,430 +0,0 @@
1
- import { Transform } from 'node:stream';
2
- import { parseSitemap } from '@crawlee/utils';
3
- import { minimatch } from 'minimatch';
4
- import ow from 'ow';
5
- import defaultLog from '@apify/log';
6
- import { Configuration } from '../configuration.js';
7
- import { constructGlobObjectsFromGlobs, constructRegExpObjectsFromRegExps } from '../enqueue_links/shared.js';
8
- import { Request } from '../request.js';
9
- import { KeyValueStore } from './key_value_store.js';
10
- import { purgeDefaultStorages } from './utils.js';
11
- /** @internal */
12
- const STATE_PERSISTENCE_KEY = 'SITEMAP_REQUEST_LIST_STATE';
13
- /**
14
- * A list of URLs to crawl parsed from a sitemap.
15
- *
16
- * The loading of the sitemap is performed in the background so that crawling can start before the sitemap is fully loaded.
17
- */
18
- export class SitemapRequestList {
19
- /**
20
- * Set of URLs that were returned by `fetchNextRequest()` and not marked as handled yet.
21
- * @internal
22
- */
23
- inProgress = new Set();
24
- /** Set of URLs for which `reclaimRequest()` was called. */
25
- reclaimed = new Set();
26
- /**
27
- * Map of returned Request objects that have not been marked as handled yet.
28
- *
29
- * We use this to persist custom user fields on the in-progress (or reclaimed) requests.
30
- */
31
- requestData = new Map();
32
- /**
33
- * Object for keeping track of the sitemap parsing progress.
34
- */
35
- sitemapParsingProgress = {
36
- /**
37
- * URL of the sitemap that is currently being parsed. `null` if no sitemap is being parsed.
38
- */
39
- inProgressSitemapUrl: null,
40
- /**
41
- * Buffer for URLs from the currently parsed sitemap. Used for tracking partially loaded sitemaps across migrations.
42
- */
43
- inProgressEntries: new Set(),
44
- /**
45
- * Set of sitemap URLs that have not been parsed yet. If the set is empty and `inProgressSitemapUrl` is `null`, the sitemap loading is finished.
46
- */
47
- pendingSitemapUrls: new Set(),
48
- };
49
- /**
50
- * Object stream of URLs parsed from the sitemaps.
51
- * Using `highWaterMark`, this can manage the speed of the sitemap loading.
52
- *
53
- * Fetch the next URL to be processed using `fetchNextRequest()`.
54
- */
55
- urlQueueStream;
56
- /**
57
- * Indicates whether the request list sitemap loading was aborted.
58
- *
59
- * If the loading was aborted before the sitemaps were fully loaded, the request list might be missing some URLs.
60
- * The `isSitemapFullyLoaded` method can be used to check if the sitemaps were fully loaded.
61
- *
62
- * If the loading is aborted and all the requests are handled, `isFinished()` will return `true`.
63
- */
64
- abortLoading = false;
65
- /** Number of URLs that were marked as handled */
66
- handledUrlCount = 0;
67
- persistStateKey;
68
- store;
69
- closed = false;
70
- /**
71
- * Proxy URL to be used for sitemap loading.
72
- */
73
- proxyUrl;
74
- /**
75
- * Logger instance.
76
- */
77
- log = defaultLog.child({ prefix: 'SitemapRequestList' });
78
- urlExcludePatternObjects = [];
79
- urlPatternObjects = [];
80
- /** EventManager used to handle persistence */
81
- events;
82
- persistenceOptions;
83
- /** @internal */
84
- constructor(options) {
85
- ow(options, ow.object.exactShape({
86
- sitemapUrls: ow.array.ofType(ow.string),
87
- proxyUrl: ow.optional.string,
88
- persistStateKey: ow.optional.string,
89
- signal: ow.optional.any(),
90
- timeoutMillis: ow.optional.number,
91
- maxBufferSize: ow.optional.number,
92
- parseSitemapOptions: ow.optional.object,
93
- globs: ow.optional.array.ofType(ow.any(ow.string, ow.object.hasKeys('glob'))),
94
- exclude: ow.optional.array.ofType(ow.any(ow.string, ow.regExp, ow.object.hasKeys('glob'), ow.object.hasKeys('regexp'))),
95
- regexps: ow.optional.array.ofType(ow.any(ow.regExp, ow.object.hasKeys('regexp'))),
96
- config: ow.optional.object,
97
- persistenceOptions: ow.optional.object,
98
- }));
99
- const { globs, exclude, regexps, config = Configuration.getGlobalConfig() } = options;
100
- if (exclude?.length) {
101
- for (const excl of exclude) {
102
- if (typeof excl === 'string' || 'glob' in excl) {
103
- this.urlExcludePatternObjects.push(...constructGlobObjectsFromGlobs([excl]));
104
- }
105
- else if (excl instanceof RegExp || 'regexp' in excl) {
106
- this.urlExcludePatternObjects.push(...constructRegExpObjectsFromRegExps([excl]));
107
- }
108
- }
109
- }
110
- if (globs?.length) {
111
- this.urlPatternObjects.push(...constructGlobObjectsFromGlobs(globs));
112
- }
113
- if (regexps?.length) {
114
- this.urlPatternObjects.push(...constructRegExpObjectsFromRegExps(regexps));
115
- }
116
- this.persistStateKey = options.persistStateKey;
117
- this.persistenceOptions = { enable: true, ...options.persistenceOptions };
118
- this.proxyUrl = options.proxyUrl;
119
- this.urlQueueStream = this.createNewStream(options.maxBufferSize ?? 200);
120
- this.sitemapParsingProgress.pendingSitemapUrls = new Set(options.sitemapUrls);
121
- this.events = config.getEventManager();
122
- this.persistState = this.persistState.bind(this);
123
- }
124
- /**
125
- * Creates a new object stream with the specified highWaterMark.
126
- * @param highWaterMark High water mark for the stream (the maximum number of objects the stream will buffer).
127
- * @returns A new object stream.
128
- */
129
- createNewStream(highWaterMark) {
130
- return new Transform({
131
- objectMode: true,
132
- highWaterMark,
133
- }).pause();
134
- }
135
- /**
136
- * Returns a function that checks whether the provided pattern matches the closure URL.
137
- * @param url URL to be checked.
138
- * @returns A matcher function that checks whether the pattern matches the closure URL.
139
- */
140
- matchesUrl(url) {
141
- return (patternObject) => {
142
- const { regexp, glob } = patternObject;
143
- const matchesRegex = (regexp && url.match(regexp)) || false;
144
- const matchesGlob = (glob && minimatch(url, glob, { nocase: true })) || false;
145
- return Boolean(matchesRegex || matchesGlob);
146
- };
147
- }
148
- /**
149
- * Checks whether the URL matches the `globs` / `regexps` / `exclude` provided in the `options`.
150
- * @param url URL to be checked.
151
- * @returns `true` if the URL matches the patterns, `false` otherwise.
152
- */
153
- isUrlMatchingPatterns(url) {
154
- return (!this.urlExcludePatternObjects.some(this.matchesUrl(url)) &&
155
- (this.urlPatternObjects.length === 0 || this.urlPatternObjects.some(this.matchesUrl(url))));
156
- }
157
- /**
158
- * Adds a URL to the queue of parsed URLs.
159
- *
160
- * Blocks if the stream is full until it is drained.
161
- */
162
- async pushNextUrl(url) {
163
- return new Promise((resolve) => {
164
- if (this.closed || (url && !this.isUrlMatchingPatterns(url))) {
165
- resolve();
166
- return;
167
- }
168
- if (!this.urlQueueStream.push(url)) {
169
- // This doesn't work with the 'drain' event (it's not emitted for some reason).
170
- this.urlQueueStream.once('readdata', () => {
171
- resolve();
172
- });
173
- }
174
- else {
175
- resolve();
176
- }
177
- });
178
- }
179
- /**
180
- * Reads the next URL from the queue of parsed URLs.
181
- *
182
- * If the stream is empty, blocks until a new URL is pushed.
183
- * @returns The next URL from the queue or `null` if we have read all URLs.
184
- */
185
- async readNextUrl() {
186
- return new Promise((resolve) => {
187
- if (this.closed) {
188
- resolve(null);
189
- return;
190
- }
191
- const result = this.urlQueueStream.read();
192
- if (!result && !this.isSitemapFullyLoaded()) {
193
- this.urlQueueStream.once('readable', () => {
194
- const nextUrl = this.urlQueueStream.read();
195
- resolve(nextUrl);
196
- });
197
- }
198
- else {
199
- resolve(result);
200
- }
201
- this.urlQueueStream.emit('readdata');
202
- });
203
- }
204
- /**
205
- * Indicates whether the background processing of sitemap contents has successfully finished.
206
- *
207
- * If this is `false`, the background processing is either still in progress or was aborted.
208
- */
209
- isSitemapFullyLoaded() {
210
- return (this.sitemapParsingProgress.inProgressSitemapUrl === null &&
211
- this.sitemapParsingProgress.pendingSitemapUrls.size === 0);
212
- }
213
- /**
214
- * Start processing the sitemaps and loading the URLs.
215
- *
216
- * Resolves once all the sitemaps URLs have been fully loaded (sets `isSitemapFullyLoaded` to `true`).
217
- */
218
- async load({ parseSitemapOptions, }) {
219
- while (!this.isSitemapFullyLoaded() && !this.abortLoading) {
220
- const sitemapUrl = this.sitemapParsingProgress.inProgressSitemapUrl ??
221
- this.sitemapParsingProgress.pendingSitemapUrls.values().next().value;
222
- try {
223
- for await (const item of parseSitemap([{ type: 'url', url: sitemapUrl }], this.proxyUrl, {
224
- ...parseSitemapOptions,
225
- maxDepth: 0,
226
- emitNestedSitemaps: true,
227
- })) {
228
- if (!item.originSitemapUrl) {
229
- // This is a nested sitemap
230
- this.sitemapParsingProgress.pendingSitemapUrls.add(item.loc);
231
- continue;
232
- }
233
- if (!this.sitemapParsingProgress.inProgressEntries.has(item.loc)) {
234
- await this.pushNextUrl(item.loc);
235
- this.sitemapParsingProgress.inProgressEntries.add(item.loc);
236
- }
237
- }
238
- }
239
- catch (e) {
240
- this.log.error('Error loading sitemap contents:', e);
241
- }
242
- this.sitemapParsingProgress.pendingSitemapUrls.delete(sitemapUrl);
243
- this.sitemapParsingProgress.inProgressEntries.clear();
244
- this.sitemapParsingProgress.inProgressSitemapUrl = null;
245
- }
246
- this.urlQueueStream.end();
247
- }
248
- /**
249
- * Open a sitemap and start processing it.
250
- *
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.
252
- *
253
- * Track the loading progress using the `isSitemapFullyLoaded` property.
254
- */
255
- static async open(options) {
256
- const requestList = new SitemapRequestList({
257
- ...options,
258
- persistStateKey: options.persistStateKey ?? STATE_PERSISTENCE_KEY,
259
- });
260
- await requestList.restoreState();
261
- void requestList.load({ parseSitemapOptions: options.parseSitemapOptions });
262
- if (requestList.persistenceOptions.enable) {
263
- requestList.events.on("persistState" /* EventType.PERSIST_STATE */, requestList.persistState);
264
- }
265
- options?.signal?.addEventListener('abort', () => {
266
- requestList.abortLoading = true;
267
- });
268
- if (options.timeoutMillis) {
269
- setTimeout(() => {
270
- requestList.abortLoading = true;
271
- }, options.timeoutMillis);
272
- }
273
- return requestList;
274
- }
275
- /**
276
- * @inheritDoc
277
- */
278
- length() {
279
- return this.urlQueueStream.readableLength + this.handledUrlCount - this.inProgress.size - this.reclaimed.size;
280
- }
281
- /**
282
- * @inheritDoc
283
- */
284
- async isFinished() {
285
- return ((await this.isEmpty()) && this.inProgress.size === 0 && (this.isSitemapFullyLoaded() || this.abortLoading));
286
- }
287
- /**
288
- * @inheritDoc
289
- */
290
- async isEmpty() {
291
- return this.reclaimed.size === 0 && this.urlQueueStream.readableLength === 0;
292
- }
293
- /**
294
- * @inheritDoc
295
- */
296
- handledCount() {
297
- return this.handledUrlCount;
298
- }
299
- /**
300
- * @inheritDoc
301
- */
302
- async persistState() {
303
- if (this.persistStateKey === undefined) {
304
- return;
305
- }
306
- this.store ??= await KeyValueStore.open();
307
- const urlQueue = [];
308
- while (this.urlQueueStream.readableLength > 0) {
309
- const url = this.urlQueueStream.read();
310
- if (url === null) {
311
- break;
312
- }
313
- urlQueue.push(url);
314
- }
315
- // Create a new stream, as we have read all the URLs from the current one.
316
- // Pushing the urls back to the original stream might not be possible if it has been ended.
317
- const newStream = this.createNewStream(this.urlQueueStream.readableHighWaterMark);
318
- for (const url of urlQueue) {
319
- newStream.push(url);
320
- }
321
- if (this.urlQueueStream.writableEnded) {
322
- newStream.end();
323
- }
324
- this.urlQueueStream = newStream;
325
- await this.store.setValue(this.persistStateKey, {
326
- sitemapParsingProgress: {
327
- pendingSitemapUrls: Array.from(this.sitemapParsingProgress.pendingSitemapUrls),
328
- inProgressSitemapUrl: this.sitemapParsingProgress.inProgressSitemapUrl,
329
- inProgressEntries: Array.from(this.sitemapParsingProgress.inProgressEntries),
330
- },
331
- urlQueue,
332
- reclaimed: [...this.inProgress, ...this.reclaimed], // In-progress and reclaimed requests will be both retried if state is restored
333
- requestData: Array.from(this.requestData.entries()),
334
- abortLoading: this.abortLoading,
335
- closed: this.closed,
336
- });
337
- }
338
- async restoreState() {
339
- await purgeDefaultStorages({ onlyPurgeOnce: true });
340
- if (this.persistStateKey === undefined) {
341
- return;
342
- }
343
- this.store ??= await KeyValueStore.open();
344
- const state = await this.store.getValue(this.persistStateKey);
345
- if (state === null) {
346
- return;
347
- }
348
- this.reclaimed = new Set(state.reclaimed);
349
- this.sitemapParsingProgress = {
350
- pendingSitemapUrls: new Set(state.sitemapParsingProgress.pendingSitemapUrls),
351
- inProgressSitemapUrl: state.sitemapParsingProgress.inProgressSitemapUrl,
352
- inProgressEntries: new Set(state.sitemapParsingProgress.inProgressEntries),
353
- };
354
- this.requestData = new Map(state.requestData ?? []);
355
- for (const url of state.urlQueue) {
356
- this.urlQueueStream.push(url);
357
- }
358
- this.abortLoading = state.abortLoading;
359
- this.closed = state.closed;
360
- }
361
- /**
362
- * @inheritDoc
363
- */
364
- 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);
369
- }
370
- else {
371
- // Otherwise read next url from the stream
372
- nextUrl = await this.readNextUrl();
373
- if (!nextUrl) {
374
- return null;
375
- }
376
- this.requestData.set(nextUrl, new Request({ url: nextUrl }));
377
- }
378
- this.inProgress.add(nextUrl);
379
- return this.requestData.get(nextUrl);
380
- }
381
- /**
382
- * @inheritDoc
383
- */
384
- async *[Symbol.asyncIterator]() {
385
- while (!(await this.isFinished())) {
386
- const request = await this.fetchNextRequest();
387
- if (!request)
388
- break;
389
- yield request;
390
- }
391
- }
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
- /**
401
- * Aborts the internal sitemap loading, stops the processing of the sitemap contents and drops all the pending URLs.
402
- *
403
- * Calling `fetchNextRequest()` after this method will always return `null`.
404
- */
405
- async teardown() {
406
- this.closed = true;
407
- this.abortLoading = true;
408
- this.events.off("persistState" /* EventType.PERSIST_STATE */, this.persistState);
409
- await this.persistState();
410
- this.urlQueueStream.emit('readdata'); // unblocks the potentially waiting `pushNextUrl` call
411
- }
412
- /**
413
- * @inheritDoc
414
- */
415
- async markRequestHandled(request) {
416
- this.handledUrlCount += 1;
417
- this.ensureInProgressAndNotReclaimed(request.url);
418
- this.inProgress.delete(request.url);
419
- this.requestData.delete(request.url);
420
- }
421
- ensureInProgressAndNotReclaimed(url) {
422
- if (!this.inProgress.has(url)) {
423
- throw new Error(`The request is not being processed (url: ${url})`);
424
- }
425
- if (this.reclaimed.has(url)) {
426
- throw new Error(`The request was already reclaimed (url: ${url})`);
427
- }
428
- }
429
- }
430
- //# sourceMappingURL=sitemap_request_list.js.map