@crawlee/core 4.0.0-beta.15 → 4.0.0-beta.150

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 (287) hide show
  1. package/README.md +14 -14
  2. package/autoscaling/autoscaled_pool.d.ts +73 -177
  3. package/autoscaling/autoscaled_pool.js +182 -329
  4. package/autoscaling/concurrency_system.d.ts +268 -0
  5. package/autoscaling/concurrency_system.js +364 -0
  6. package/autoscaling/cpu_load_signal.d.ts +43 -0
  7. package/autoscaling/cpu_load_signal.js +47 -0
  8. package/autoscaling/event_loop_load_signal.d.ts +51 -0
  9. package/autoscaling/event_loop_load_signal.js +60 -0
  10. package/autoscaling/index.d.ts +6 -1
  11. package/autoscaling/index.js +6 -1
  12. package/autoscaling/load_signal.d.ts +98 -0
  13. package/autoscaling/load_signal.js +103 -0
  14. package/autoscaling/memory_load_signal.d.ts +47 -0
  15. package/autoscaling/memory_load_signal.js +106 -0
  16. package/autoscaling/snapshotter.d.ts +58 -163
  17. package/autoscaling/snapshotter.js +45 -263
  18. package/autoscaling/storage_backend_load_signal.d.ts +56 -0
  19. package/autoscaling/storage_backend_load_signal.js +73 -0
  20. package/autoscaling/system_status.d.ts +67 -89
  21. package/autoscaling/system_status.js +92 -122
  22. package/autoscaling/weighted_avg.d.ts +5 -0
  23. package/autoscaling/weighted_avg.js +14 -0
  24. package/byte_utils.d.ts +17 -0
  25. package/byte_utils.js +42 -0
  26. package/configuration.d.ts +96 -223
  27. package/configuration.js +170 -222
  28. package/cookie_utils.d.ts +3 -2
  29. package/cookie_utils.js +18 -7
  30. package/crawlers/context_pipeline.d.ts +10 -1
  31. package/crawlers/context_pipeline.js +31 -8
  32. package/crawlers/crawler_commons.d.ts +90 -126
  33. package/crawlers/crawler_commons.js +1 -108
  34. package/crawlers/error_snapshotter.d.ts +2 -5
  35. package/crawlers/error_snapshotter.js +7 -8
  36. package/crawlers/error_tracker.d.ts +0 -1
  37. package/crawlers/error_tracker.js +0 -1
  38. package/crawlers/index.d.ts +1 -3
  39. package/crawlers/index.js +0 -3
  40. package/crawlers/internals/types.d.ts +0 -1
  41. package/crawlers/internals/types.js +0 -1
  42. package/crawlers/statistics.d.ts +187 -64
  43. package/crawlers/statistics.js +354 -165
  44. package/debug.d.ts +36 -0
  45. package/debug.js +70 -0
  46. package/enqueue_links/enqueue_links.d.ts +61 -154
  47. package/enqueue_links/enqueue_links.js +40 -232
  48. package/enqueue_links/index.d.ts +0 -1
  49. package/enqueue_links/index.js +0 -1
  50. package/enqueue_links/shared.d.ts +55 -28
  51. package/enqueue_links/shared.js +116 -69
  52. package/errors.d.ts +72 -4
  53. package/errors.js +89 -5
  54. package/events/event_manager.d.ts +35 -9
  55. package/events/event_manager.js +12 -13
  56. package/events/index.d.ts +0 -1
  57. package/events/index.js +0 -1
  58. package/events/local_event_manager.d.ts +15 -3
  59. package/events/local_event_manager.js +39 -13
  60. package/http.d.ts +9 -0
  61. package/http.js +28 -0
  62. package/index.d.ts +7 -5
  63. package/index.js +8 -4
  64. package/iterables.d.ts +79 -0
  65. package/iterables.js +134 -0
  66. package/log.d.ts +77 -1
  67. package/log.js +104 -1
  68. package/memory-storage/consts.d.ts +4 -0
  69. package/memory-storage/consts.js +4 -0
  70. package/memory-storage/index.d.ts +1 -0
  71. package/memory-storage/index.js +1 -0
  72. package/memory-storage/memory-storage.d.ts +44 -0
  73. package/memory-storage/memory-storage.js +160 -0
  74. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  75. package/memory-storage/resource-clients/common/base-client.js +6 -0
  76. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  77. package/memory-storage/resource-clients/dataset.js +106 -0
  78. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  79. package/memory-storage/resource-clients/key-value-store.js +199 -0
  80. package/memory-storage/resource-clients/request-queue.d.ts +77 -0
  81. package/memory-storage/resource-clients/request-queue.js +407 -0
  82. package/memory-storage/utils.d.ts +16 -0
  83. package/memory-storage/utils.js +41 -0
  84. package/owned_or_injected.d.ts +58 -0
  85. package/owned_or_injected.js +98 -0
  86. package/package.json +13 -12
  87. package/proxy_configuration.d.ts +22 -128
  88. package/proxy_configuration.js +32 -144
  89. package/recoverable_state.d.ts +83 -51
  90. package/recoverable_state.js +163 -72
  91. package/request.d.ts +57 -16
  92. package/request.js +130 -69
  93. package/router.d.ts +193 -21
  94. package/router.js +188 -43
  95. package/serialization.d.ts +0 -1
  96. package/serialization.js +15 -15
  97. package/service_locator.d.ts +165 -0
  98. package/service_locator.js +253 -0
  99. package/session_pool/consts.d.ts +1 -2
  100. package/session_pool/consts.js +1 -2
  101. package/session_pool/errors.d.ts +0 -1
  102. package/session_pool/errors.js +0 -1
  103. package/session_pool/fingerprint.d.ts +9 -0
  104. package/session_pool/fingerprint.js +30 -0
  105. package/session_pool/index.d.ts +0 -2
  106. package/session_pool/index.js +0 -2
  107. package/session_pool/session.d.ts +39 -89
  108. package/session_pool/session.js +102 -159
  109. package/session_pool/session_pool.d.ts +67 -91
  110. package/session_pool/session_pool.js +196 -187
  111. package/storages/batched_adds.d.ts +37 -0
  112. package/storages/batched_adds.js +73 -0
  113. package/storages/dataset.d.ts +109 -56
  114. package/storages/dataset.js +284 -149
  115. package/storages/index.d.ts +9 -9
  116. package/storages/index.js +7 -9
  117. package/storages/key_value_store.d.ts +183 -48
  118. package/storages/key_value_store.js +444 -171
  119. package/storages/key_value_store_codec.d.ts +32 -0
  120. package/storages/key_value_store_codec.js +113 -0
  121. package/storages/request_dedup_cache.d.ts +22 -0
  122. package/storages/request_dedup_cache.js +48 -0
  123. package/storages/request_list.d.ts +53 -115
  124. package/storages/request_list.js +194 -167
  125. package/storages/request_loader.d.ts +133 -0
  126. package/storages/request_loader.js +36 -0
  127. package/storages/request_manager.d.ts +109 -0
  128. package/storages/request_manager.js +1 -0
  129. package/storages/request_manager_tandem.d.ts +55 -23
  130. package/storages/request_manager_tandem.js +139 -57
  131. package/storages/request_queue.d.ts +286 -48
  132. package/storages/request_queue.js +757 -218
  133. package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +43 -91
  134. package/storages/sitemap_request_loader.js +439 -0
  135. package/storages/storage_instance_manager.d.ts +87 -0
  136. package/storages/storage_instance_manager.js +256 -0
  137. package/storages/storage_stats.d.ts +48 -0
  138. package/storages/storage_stats.js +29 -0
  139. package/storages/throttling_request_manager.d.ts +222 -0
  140. package/storages/throttling_request_manager.js +780 -0
  141. package/storages/transaction.d.ts +252 -0
  142. package/storages/transaction.js +251 -0
  143. package/storages/utils.d.ts +59 -11
  144. package/storages/utils.js +75 -15
  145. package/system-info/cpu-info.d.ts +67 -0
  146. package/system-info/cpu-info.js +216 -0
  147. package/system-info/memory-info.d.ts +31 -0
  148. package/system-info/memory-info.js +115 -0
  149. package/system-info/ps-tree.d.ts +17 -0
  150. package/system-info/ps-tree.js +144 -0
  151. package/system-info/runtime.d.ts +14 -0
  152. package/system-info/runtime.js +80 -0
  153. package/typedefs.d.ts +0 -6
  154. package/typedefs.js +0 -1
  155. package/url.d.ts +9 -0
  156. package/url.js +11 -0
  157. package/validators.d.ts +22 -18
  158. package/validators.js +13 -18
  159. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  160. package/autoscaling/autoscaled_pool.js.map +0 -1
  161. package/autoscaling/index.d.ts.map +0 -1
  162. package/autoscaling/index.js.map +0 -1
  163. package/autoscaling/snapshotter.d.ts.map +0 -1
  164. package/autoscaling/snapshotter.js.map +0 -1
  165. package/autoscaling/system_status.d.ts.map +0 -1
  166. package/autoscaling/system_status.js.map +0 -1
  167. package/configuration.d.ts.map +0 -1
  168. package/configuration.js.map +0 -1
  169. package/cookie_utils.d.ts.map +0 -1
  170. package/cookie_utils.js.map +0 -1
  171. package/crawlers/context_pipeline.d.ts.map +0 -1
  172. package/crawlers/context_pipeline.js.map +0 -1
  173. package/crawlers/crawler_commons.d.ts.map +0 -1
  174. package/crawlers/crawler_commons.js.map +0 -1
  175. package/crawlers/crawler_utils.d.ts +0 -10
  176. package/crawlers/crawler_utils.d.ts.map +0 -1
  177. package/crawlers/crawler_utils.js +0 -12
  178. package/crawlers/crawler_utils.js.map +0 -1
  179. package/crawlers/error_snapshotter.d.ts.map +0 -1
  180. package/crawlers/error_snapshotter.js.map +0 -1
  181. package/crawlers/error_tracker.d.ts.map +0 -1
  182. package/crawlers/error_tracker.js.map +0 -1
  183. package/crawlers/index.d.ts.map +0 -1
  184. package/crawlers/index.js.map +0 -1
  185. package/crawlers/internals/types.d.ts.map +0 -1
  186. package/crawlers/internals/types.js.map +0 -1
  187. package/crawlers/statistics.d.ts.map +0 -1
  188. package/crawlers/statistics.js.map +0 -1
  189. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  190. package/enqueue_links/enqueue_links.js.map +0 -1
  191. package/enqueue_links/index.d.ts.map +0 -1
  192. package/enqueue_links/index.js.map +0 -1
  193. package/enqueue_links/shared.d.ts.map +0 -1
  194. package/enqueue_links/shared.js.map +0 -1
  195. package/errors.d.ts.map +0 -1
  196. package/errors.js.map +0 -1
  197. package/events/event_manager.d.ts.map +0 -1
  198. package/events/event_manager.js.map +0 -1
  199. package/events/index.d.ts.map +0 -1
  200. package/events/index.js.map +0 -1
  201. package/events/local_event_manager.d.ts.map +0 -1
  202. package/events/local_event_manager.js.map +0 -1
  203. package/http_clients/base-http-client.d.ts +0 -140
  204. package/http_clients/base-http-client.d.ts.map +0 -1
  205. package/http_clients/base-http-client.js +0 -40
  206. package/http_clients/base-http-client.js.map +0 -1
  207. package/http_clients/form-data-like.d.ts +0 -67
  208. package/http_clients/form-data-like.d.ts.map +0 -1
  209. package/http_clients/form-data-like.js +0 -5
  210. package/http_clients/form-data-like.js.map +0 -1
  211. package/http_clients/got-scraping-http-client.d.ts +0 -20
  212. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  213. package/http_clients/got-scraping-http-client.js +0 -85
  214. package/http_clients/got-scraping-http-client.js.map +0 -1
  215. package/http_clients/index.d.ts +0 -3
  216. package/http_clients/index.d.ts.map +0 -1
  217. package/http_clients/index.js +0 -3
  218. package/http_clients/index.js.map +0 -1
  219. package/index.d.ts.map +0 -1
  220. package/index.js.map +0 -1
  221. package/log.d.ts.map +0 -1
  222. package/log.js.map +0 -1
  223. package/proxy_configuration.d.ts.map +0 -1
  224. package/proxy_configuration.js.map +0 -1
  225. package/recoverable_state.d.ts.map +0 -1
  226. package/recoverable_state.js.map +0 -1
  227. package/request.d.ts.map +0 -1
  228. package/request.js.map +0 -1
  229. package/router.d.ts.map +0 -1
  230. package/router.js.map +0 -1
  231. package/serialization.d.ts.map +0 -1
  232. package/serialization.js.map +0 -1
  233. package/session_pool/consts.d.ts.map +0 -1
  234. package/session_pool/consts.js.map +0 -1
  235. package/session_pool/errors.d.ts.map +0 -1
  236. package/session_pool/errors.js.map +0 -1
  237. package/session_pool/events.d.ts +0 -3
  238. package/session_pool/events.d.ts.map +0 -1
  239. package/session_pool/events.js +0 -3
  240. package/session_pool/events.js.map +0 -1
  241. package/session_pool/index.d.ts.map +0 -1
  242. package/session_pool/index.js.map +0 -1
  243. package/session_pool/session.d.ts.map +0 -1
  244. package/session_pool/session.js.map +0 -1
  245. package/session_pool/session_pool.d.ts.map +0 -1
  246. package/session_pool/session_pool.js.map +0 -1
  247. package/storages/access_checking.d.ts +0 -13
  248. package/storages/access_checking.d.ts.map +0 -1
  249. package/storages/access_checking.js +0 -14
  250. package/storages/access_checking.js.map +0 -1
  251. package/storages/dataset.d.ts.map +0 -1
  252. package/storages/dataset.js.map +0 -1
  253. package/storages/index.d.ts.map +0 -1
  254. package/storages/index.js.map +0 -1
  255. package/storages/key_value_store.d.ts.map +0 -1
  256. package/storages/key_value_store.js.map +0 -1
  257. package/storages/request_list.d.ts.map +0 -1
  258. package/storages/request_list.js.map +0 -1
  259. package/storages/request_list_adapter.d.ts +0 -58
  260. package/storages/request_list_adapter.d.ts.map +0 -1
  261. package/storages/request_list_adapter.js +0 -81
  262. package/storages/request_list_adapter.js.map +0 -1
  263. package/storages/request_manager_tandem.d.ts.map +0 -1
  264. package/storages/request_manager_tandem.js.map +0 -1
  265. package/storages/request_provider.d.ts +0 -371
  266. package/storages/request_provider.d.ts.map +0 -1
  267. package/storages/request_provider.js +0 -585
  268. package/storages/request_provider.js.map +0 -1
  269. package/storages/request_queue.d.ts.map +0 -1
  270. package/storages/request_queue.js.map +0 -1
  271. package/storages/request_queue_v2.d.ts +0 -87
  272. package/storages/request_queue_v2.d.ts.map +0 -1
  273. package/storages/request_queue_v2.js +0 -438
  274. package/storages/request_queue_v2.js.map +0 -1
  275. package/storages/sitemap_request_list.d.ts.map +0 -1
  276. package/storages/sitemap_request_list.js +0 -430
  277. package/storages/sitemap_request_list.js.map +0 -1
  278. package/storages/storage_manager.d.ts +0 -58
  279. package/storages/storage_manager.d.ts.map +0 -1
  280. package/storages/storage_manager.js +0 -105
  281. package/storages/storage_manager.js.map +0 -1
  282. package/storages/utils.d.ts.map +0 -1
  283. package/storages/utils.js.map +0 -1
  284. package/typedefs.d.ts.map +0 -1
  285. package/typedefs.js.map +0 -1
  286. package/validators.d.ts.map +0 -1
  287. package/validators.js.map +0 -1
package/debug.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import type { IncomingMessage } from 'node:http';
2
+ import type { Dictionary } from '@crawlee/types';
3
+ import type { Request } from './request.js';
4
+ interface BrowserResponseLike {
5
+ status(): number;
6
+ }
7
+ /**
8
+ * Creates a standardized debug info from request and response. This info is usually added to dataset under the hidden `#debug` field.
9
+ *
10
+ * @param request [Request](https://sdk.apify.com/docs/api/request) object.
11
+ * @param [response]
12
+ * Puppeteer [`Response`](https://pptr.dev/#?product=Puppeteer&version=v1.11.0&show=api-class-response)
13
+ * or NodeJS [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_serverresponse).
14
+ * @param [additionalFields] Object containing additional fields to be added.
15
+ *
16
+ * @internal
17
+ */
18
+ export declare function createRequestDebugInfo(request: Request, response?: IncomingMessage | Partial<BrowserResponseLike>, additionalFields?: Dictionary): Dictionary;
19
+ /**
20
+ * Returns a human-readable label for an unknown value,
21
+ * suitable for embedding in error messages and log output.
22
+ *
23
+ * Returns `constructor.name` when available (e.g. `"Configuration"`, `"Number"`),
24
+ * otherwise falls back to `util.inspect` (e.g. for `null`, `undefined`).
25
+ *
26
+ * @internal
27
+ */
28
+ export declare function inspectValue(value: unknown): string;
29
+ /**
30
+ * Returns the type of a value as a lowercase string, with `Date`, `Buffer` and `RegExp` reported
31
+ * by their constructor name. Used for building validation error messages.
32
+ *
33
+ * @internal
34
+ */
35
+ export declare function getObjectType(value: unknown): string;
36
+ export {};
package/debug.js ADDED
@@ -0,0 +1,70 @@
1
+ import { inspect } from 'node:util';
2
+ import { parseArgument, schemas } from './validators.js';
3
+ /**
4
+ * Creates a standardized debug info from request and response. This info is usually added to dataset under the hidden `#debug` field.
5
+ *
6
+ * @param request [Request](https://sdk.apify.com/docs/api/request) object.
7
+ * @param [response]
8
+ * Puppeteer [`Response`](https://pptr.dev/#?product=Puppeteer&version=v1.11.0&show=api-class-response)
9
+ * or NodeJS [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_serverresponse).
10
+ * @param [additionalFields] Object containing additional fields to be added.
11
+ *
12
+ * @internal
13
+ */
14
+ export function createRequestDebugInfo(request, response = {}, additionalFields = {}) {
15
+ parseArgument(request, schemas.anyObject);
16
+ parseArgument(response, schemas.anyObject);
17
+ parseArgument(additionalFields, schemas.anyObject);
18
+ return {
19
+ requestId: request.id,
20
+ url: request.url,
21
+ loadedUrl: request.loadedUrl,
22
+ method: request.method,
23
+ retryCount: request.retryCount,
24
+ errorMessages: request.errorMessages,
25
+ // Puppeteer response has .status() function and NodeJS response, statusCode property.
26
+ statusCode: 'status' in response && response.status instanceof Function
27
+ ? response.status()
28
+ : response.statusCode,
29
+ ...additionalFields,
30
+ };
31
+ }
32
+ /**
33
+ * Returns a human-readable label for an unknown value,
34
+ * suitable for embedding in error messages and log output.
35
+ *
36
+ * Returns `constructor.name` when available (e.g. `"Configuration"`, `"Number"`),
37
+ * otherwise falls back to `util.inspect` (e.g. for `null`, `undefined`).
38
+ *
39
+ * @internal
40
+ */
41
+ export function inspectValue(value) {
42
+ if (typeof value === 'object' && value !== null && value.constructor?.name) {
43
+ return value.constructor.name;
44
+ }
45
+ return inspect(value, {
46
+ depth: 0,
47
+ compact: true,
48
+ maxStringLength: 64,
49
+ breakLength: Infinity,
50
+ colors: false,
51
+ });
52
+ }
53
+ /**
54
+ * Returns the type of a value as a lowercase string, with `Date`, `Buffer` and `RegExp` reported
55
+ * by their constructor name. Used for building validation error messages.
56
+ *
57
+ * @internal
58
+ */
59
+ export function getObjectType(value) {
60
+ const simple = typeof value;
61
+ if (['string', 'number', 'boolean', 'bigint'].includes(simple)) {
62
+ return simple;
63
+ }
64
+ const objectType = Object.prototype.toString.call(value);
65
+ const type = /\[object (\w+)]/.exec(objectType)[1];
66
+ if (type === 'Uint8Array') {
67
+ return 'Buffer';
68
+ }
69
+ return ['Date', 'Buffer', 'RegExp'].includes(type) ? type : type.toLowerCase();
70
+ }
@@ -1,98 +1,76 @@
1
- import type { BatchAddRequestsResult, Dictionary } from '@crawlee/types';
2
- import { type RobotsTxtFile } from '@crawlee/utils';
3
- import type { SetRequired } from 'type-fest';
4
- import type { Request } from '../request.js';
5
- import type { AddRequestsBatchedOptions, AddRequestsBatchedResult, RequestProvider, RequestQueueOperationOptions } from '../storages/request_provider.js';
6
- import type { GlobInput, PseudoUrlInput, RegExpInput, RequestTransform, SkippedRequestCallback } from './shared.js';
7
- export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
1
+ import type { Dictionary } from '@crawlee/types';
2
+ import { EnqueueStrategy } from '@crawlee/utils';
3
+ import type { RequestQueueOperationOptions } from '../storages/request_queue.js';
4
+ import type { RequestTransform, SkippedRequestCallback, UrlPatternInput, UrlPatternObject } from './shared.js';
5
+ /**
6
+ * Options shared by the `extractLinks()` context helper across crawler types.
7
+ */
8
+ export interface ExtractLinksOptions {
9
+ /** A CSS selector matching links to be extracted. */
10
+ selector?: string;
11
+ /**
12
+ * A base URL that will be used to resolve relative URLs when using Cheerio. Ignored when using Puppeteer,
13
+ * since the relative URL resolution is done inside the browser automatically.
14
+ */
15
+ baseUrl?: string;
16
+ }
17
+ /**
18
+ * Options accepted by the `enqueueUrls()` context helper exposed by `BasicCrawler`.
19
+ */
20
+ export interface EnqueueUrlsOptions extends RequestQueueOperationOptions {
8
21
  /** Limit the amount of actually enqueued URLs to this number. Useful for testing across the entire crawling scope. */
9
22
  limit?: number;
10
- /** An array of URLs to enqueue. */
11
- urls?: readonly string[];
12
- /** A request queue to which the URLs will be enqueued. */
13
- requestQueue?: RequestProvider;
14
- /** A CSS selector matching links to be enqueued. */
15
- selector?: string;
16
23
  /** Sets {@link Request.userData} for newly enqueued requests. */
17
24
  userData?: Dictionary;
18
25
  /**
19
26
  * Sets {@link Request.label} for newly enqueued requests.
20
27
  *
21
- * Note that the request options specified in `globs`, `regexps`, or `pseudoUrls` objects
22
- * have priority over this option.
28
+ * Can be overwritten by `transformRequestFunction`.
23
29
  */
24
30
  label?: string;
31
+ /** Sets {@link Request.sessionId} for newly enqueued requests. */
32
+ sessionId?: string;
25
33
  /**
26
34
  * If set to `true`, tells the crawler to skip navigation and process the request directly.
27
35
  * @default false
28
36
  */
29
37
  skipNavigation?: boolean;
30
38
  /**
31
- * A base URL that will be used to resolve relative URLs when using Cheerio. Ignored when using Puppeteer,
32
- * since the relative URL resolution is done inside the browser automatically.
39
+ * A base URL that will be used to resolve relative URLs.
33
40
  */
34
41
  baseUrl?: string;
35
42
  /**
36
- * An array of glob pattern strings or plain objects
37
- * containing glob pattern strings matching the URLs to be enqueued.
38
- *
39
- * The plain objects must include at least the `glob` property, which holds the glob pattern string.
40
- * All remaining keys will be used as request options for the corresponding enqueued {@link Request} objects.
41
- *
42
- * The matching is always case-insensitive.
43
- * If you need case-sensitive matching, use `regexps` property directly.
44
- *
45
- * If `globs` is an empty array or `undefined`, and `regexps` are also not defined, then the function
46
- * enqueues the links with the same subdomain.
47
- */
48
- globs?: readonly GlobInput[];
49
- /**
50
- * An array of glob pattern strings, regexp patterns or plain objects
51
- * containing patterns matching URLs that will **never** be enqueued.
43
+ * An array of URL patterns that URLs must match to be enqueued.
52
44
  *
53
- * The plain objects must include either the `glob` property or the `regexp` property.
45
+ * Accepts glob pattern strings, `{ glob: string }` objects, `RegExp` instances, or `{ regexp: RegExp }` objects.
54
46
  *
55
47
  * Glob matching is always case-insensitive.
56
- * If you need case-sensitive matching, provide a regexp.
57
- */
58
- exclude?: readonly (GlobInput | RegExpInput)[];
59
- /**
60
- * An array of regular expressions or plain objects
61
- * containing regular expressions matching the URLs to be enqueued.
48
+ * If you need case-sensitive matching, use a `RegExp`.
62
49
  *
63
- * The plain objects must include at least the `regexp` property, which holds the regular expression.
64
- * All remaining keys will be used as request options for the corresponding enqueued {@link Request} objects.
50
+ * The patterns are combined with the {@link EnqueueUrlsOptions.strategy|`strategy`} using AND logic - a URL
51
+ * must match at least one `include` pattern **and** satisfy the strategy to be enqueued. To match URLs across
52
+ * hostnames, pass an explicit {@link EnqueueStrategy.All} strategy.
65
53
  *
66
- * If `regexps` is an empty array or `undefined`, and `globs` are also not defined, then the function
67
- * enqueues the links with the same subdomain.
54
+ * If `undefined`, the links are enqueued based on the {@link EnqueueUrlsOptions.strategy|`strategy`} alone.
55
+ * Passing an empty array is not allowed.
68
56
  */
69
- regexps?: readonly RegExpInput[];
57
+ include?: readonly UrlPatternInput[];
70
58
  /**
71
- * *NOTE:* In future versions of SDK the options will be removed.
72
- * Please use `globs` or `regexps` instead.
73
- *
74
- * An array of {@link PseudoUrl} strings or plain objects
75
- * containing {@link PseudoUrl} strings matching the URLs to be enqueued.
76
- *
77
- * The plain objects must include at least the `purl` property, which holds the pseudo-URL string.
78
- * All remaining keys will be used as request options for the corresponding enqueued {@link Request} objects.
79
- *
80
- * With a pseudo-URL string, the matching is always case-insensitive.
81
- * If you need case-sensitive matching, use `regexps` property directly.
59
+ * An array of URL patterns. Matching URLs will **not** be enqueued.
82
60
  *
83
- * If `pseudoUrls` is an empty array or `undefined`, then the function
84
- * enqueues the links with the same subdomain.
61
+ * Accepts glob pattern strings, `{ glob: string }` objects, `RegExp` instances, or `{ regexp: RegExp }` objects.
85
62
  *
86
- * @deprecated prefer using `globs` or `regexps` instead
63
+ * Glob matching is always case-insensitive.
64
+ * If you need case-sensitive matching, use a `RegExp`.
87
65
  */
88
- pseudoUrls?: readonly PseudoUrlInput[];
66
+ exclude?: readonly UrlPatternInput[];
89
67
  /**
90
- * Just before a new {@link Request} is constructed and enqueued to the {@link RequestQueue}, this function can be used
91
- * to remove it or modify its contents such as `userData`, `payload` or, most importantly `uniqueKey`. This is useful
68
+ * After request options are filtered by `include`/`exclude` patterns, this function can be used
69
+ * to remove them or modify their contents such as `userData`, `payload` or, most importantly `uniqueKey`. This is useful
92
70
  * when you need to enqueue multiple `Requests` to the queue that share the same URL, but differ in methods or payloads,
93
71
  * or to dynamically update or create `userData`.
94
72
  *
95
- * For example: by adding `keepUrlFragment: true` to the `request` object, URL fragments will not be removed
73
+ * For example: by adding `keepUrlFragment: true` to the request options, URL fragments will not be removed
96
74
  * when `uniqueKey` is computed.
97
75
  *
98
76
  * **Example:**
@@ -106,8 +84,13 @@ export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
106
84
  * }
107
85
  * ```
108
86
  *
109
- * Note that the request options specified in `globs`, `regexps`, or `pseudoUrls` objects
110
- * have priority over this function. Some request options returned by `transformRequestFunction` may be overwritten by pattern-based options from `globs`, `regexps`, or `pseudoUrls`.
87
+ * Note that `transformRequestFunction` has the highest priority and can overwrite
88
+ * the global `label` option.
89
+ *
90
+ * The function receives a {@link RequestOptions} object and can return either:
91
+ * - The modified {@link RequestOptions} object
92
+ * - `'unchanged'` to keep the original options as-is
93
+ * - A falsy value or `'skip'` to exclude the request from the queue
111
94
  */
112
95
  transformRequestFunction?: RequestTransform;
113
96
  /**
@@ -128,17 +111,12 @@ export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
128
111
  *
129
112
  * @default EnqueueStrategy.SameHostname
130
113
  */
131
- strategy?: EnqueueStrategy | 'all' | 'same-domain' | 'same-hostname' | 'same-origin';
114
+ strategy?: EnqueueStrategyOption;
132
115
  /**
133
116
  * By default, only the first batch (1000) of found requests will be added to the queue before resolving the call.
134
117
  * You can use this option to wait for adding all of them.
135
118
  */
136
119
  waitForAllRequestsToBeAdded?: boolean;
137
- /**
138
- * RobotsTxtFile instance for the current request that triggered the `enqueueLinks`.
139
- * If provided, disallowed URLs will be ignored.
140
- */
141
- robotsTxtFile?: Pick<RobotsTxtFile, 'isAllowed'>;
142
120
  /**
143
121
  * When a request is skipped for some reason, you can use this callback to act on it.
144
122
  * This is currently fired for requests skipped
@@ -148,86 +126,11 @@ export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
148
126
  */
149
127
  onSkippedRequest?: SkippedRequestCallback;
150
128
  }
151
- /**
152
- * The different enqueueing strategies available.
153
- *
154
- * Depending on the strategy you select, we will only check certain parts of the URLs found. Here is a diagram of each URL part and their name:
155
- *
156
- * ```md
157
- * Protocol Domain
158
- * ┌────┐ ┌─────────┐
159
- * https://example.crawlee.dev/...
160
- * │ └─────────────────┤
161
- * │ Hostname │
162
- * │ │
163
- * └─────────────────────────┘
164
- * Origin
165
- *```
166
- *
167
- * - The `Protocol` is usually `http` or `https`
168
- * - The `Domain` represents the path without any possible subdomains to a website. For example, `crawlee.dev` is the domain of `https://example.crawlee.dev/`
169
- * - The `Hostname` is the full path to a website, including any subdomains. For example, `example.crawlee.dev` is the hostname of `https://example.crawlee.dev/`
170
- * - The `Origin` is the combination of the `Protocol` and `Hostname`. For example, `https://example.crawlee.dev` is the origin of `https://example.crawlee.dev/`
171
- */
172
- export declare enum EnqueueStrategy {
173
- /**
174
- * Matches any URLs found
175
- */
176
- All = "all",
177
- /**
178
- * Matches any URLs that have the same hostname.
179
- * For example, `https://wow.example.com/hello` will be matched for a base url of `https://wow.example.com/`, but
180
- * `https://example.com/hello` will not be matched.
181
- *
182
- * > This strategy will match both `http` and `https` protocols regardless of the base URL protocol.
183
- */
184
- SameHostname = "same-hostname",
185
- /**
186
- * Matches any URLs that have the same domain as the base URL.
187
- * For example, `https://wow.an.example.com` and `https://example.com` will both be matched for a base url of
188
- * `https://example.com`.
189
- *
190
- * > This strategy will match both `http` and `https` protocols regardless of the base URL protocol.
191
- */
192
- SameDomain = "same-domain",
193
- /**
194
- * Matches any URLs that have the same hostname and protocol.
195
- * For example, `https://wow.example.com/hello` will be matched for a base url of `https://wow.example.com/`, but
196
- * `http://wow.example.com/hello` will not be matched.
197
- *
198
- * > This strategy will ensure the protocol of the base URL is the same as the protocol of the URL to be enqueued.
199
- */
200
- SameOrigin = "same-origin"
201
- }
202
- /**
203
- * This function enqueues the urls provided to the {@link RequestQueue} provided. If you want to automatically find and enqueue links,
204
- * you should use the context-aware `enqueueLinks` function provided on the crawler contexts.
205
- *
206
- * Optionally, the function allows you to filter the target links' URLs using an array of globs or regular expressions
207
- * and override settings of the enqueued {@link Request} objects.
208
- *
209
- * **Example usage**
210
- *
211
- * ```javascript
212
- * await enqueueLinks({
213
- * urls: aListOfFoundUrls,
214
- * requestQueue,
215
- * selector: 'a.product-detail',
216
- * globs: [
217
- * 'https://www.example.com/handbags/*',
218
- * 'https://www.example.com/purses/*'
219
- * ],
220
- * });
221
- * ```
222
- *
223
- * @param options All `enqueueLinks()` parameters are passed via an options object.
224
- * @returns Promise that resolves to {@link BatchAddRequestsResult} object.
225
- */
226
- export declare function enqueueLinks(options: SetRequired<Omit<EnqueueLinksOptions, 'requestQueue'>, 'urls'> & {
227
- requestQueue: {
228
- addRequestsBatched: (requests: Request<Dictionary>[], options: AddRequestsBatchedOptions) => Promise<AddRequestsBatchedResult>;
229
- };
230
- }): Promise<BatchAddRequestsResult>;
129
+ /** The combined options accepted by a crawler context's `enqueueLinks()` helper: `extractLinks()` + `enqueueUrls()`. */
130
+ export type EnqueueLinksOptions = ExtractLinksOptions & EnqueueUrlsOptions;
131
+ export { EnqueueStrategy };
132
+ /** The `strategy` option accepted by {@link ExtractLinksOptions} and {@link EnqueueUrlsOptions}. */
133
+ export type EnqueueStrategyOption = EnqueueStrategy | 'all' | 'same-domain' | 'same-hostname' | 'same-origin';
231
134
  /**
232
135
  * @internal
233
136
  * This method helps resolve the baseUrl that will be used for filtering in {@link enqueueLinks}.
@@ -236,14 +139,18 @@ export declare function enqueueLinks(options: SetRequired<Omit<EnqueueLinksOptio
236
139
  * request domain, or a redirected one
237
140
  * - In all other cases, we return the domain of the original request as that's the one we need to use for filtering
238
141
  */
239
- export declare function resolveBaseUrlForEnqueueLinksFiltering({ enqueueStrategy, finalRequestUrl, originalRequestUrl, userProvidedBaseUrl, }: ResolveBaseUrl): string | undefined;
142
+ export declare function resolveBaseUrlForEnqueueLinksFiltering({ enqueueStrategy, finalRequestUrl, originalRequestUrl, userProvidedBaseUrl, }: ResolveBaseUrl): string;
240
143
  /**
241
144
  * @internal
242
145
  */
243
146
  export interface ResolveBaseUrl {
244
147
  userProvidedBaseUrl?: string;
245
- enqueueStrategy?: EnqueueLinksOptions['strategy'];
148
+ enqueueStrategy?: EnqueueStrategyOption;
246
149
  originalRequestUrl: string;
247
150
  finalRequestUrl?: string;
248
151
  }
249
- //# sourceMappingURL=enqueue_links.d.ts.map
152
+ /**
153
+ * @internal
154
+ * Builds the glob patterns a URL must match to satisfy the given enqueue `strategy`, anchored at `baseUrl`.
155
+ */
156
+ export declare function buildEnqueueStrategyPatterns(baseUrl: string, strategy: EnqueueStrategyOption): UrlPatternObject[];