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