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