@crawlee/core 4.0.0-beta.27 → 4.0.0-beta.270
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 +15 -15
- package/byte-utils.d.ts +17 -0
- package/byte-utils.js +42 -0
- package/configuration.d.ts +77 -235
- package/configuration.js +159 -227
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/errors.d.ts +45 -18
- package/errors.js +58 -27
- package/events/event-manager.d.ts +78 -0
- package/events/{event_manager.js → event-manager.js} +12 -13
- package/events/index.d.ts +3 -3
- package/events/index.js +2 -3
- package/events/local-event-manager.d.ts +32 -0
- package/events/local-event-manager.js +101 -0
- package/events/system-info.d.ts +38 -0
- package/events/system-info.js +1 -0
- package/index.d.ts +9 -12
- package/index.js +10 -11
- package/internal.d.ts +8 -0
- package/internal.js +9 -0
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +77 -1
- package/log.js +134 -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 +43 -0
- package/memory-storage/memory-storage.js +158 -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 +35 -0
- package/memory-storage/resource-clients/dataset.js +108 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +54 -0
- package/memory-storage/resource-clients/key-value-store.js +179 -0
- package/memory-storage/resource-clients/request-queue.d.ts +55 -0
- package/memory-storage/resource-clients/request-queue.js +413 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned-or-injected.d.ts +58 -0
- package/owned-or-injected.js +98 -0
- package/package.json +23 -23
- package/proxy-configuration.d.ts +118 -0
- package/proxy-configuration.js +141 -0
- package/recoverable-state.d.ts +177 -0
- package/recoverable-state.js +268 -0
- package/request.d.ts +48 -101
- package/request.js +139 -249
- package/serialization.d.ts +0 -1
- package/serialization.js +18 -18
- package/service-locator.d.ts +168 -0
- package/service-locator.js +255 -0
- package/storages/batched-adds.d.ts +39 -0
- package/storages/batched-adds.js +81 -0
- package/storages/dataset.d.ts +105 -58
- package/storages/dataset.js +292 -150
- package/storages/index.d.ts +11 -12
- package/storages/index.js +7 -12
- package/storages/key-value-store-codec.d.ts +32 -0
- package/storages/key-value-store-codec.js +108 -0
- package/storages/{key_value_store.d.ts → key-value-store.d.ts} +169 -72
- package/storages/key-value-store.js +767 -0
- package/storages/request-dedup-cache.d.ts +20 -0
- package/storages/request-dedup-cache.js +48 -0
- package/storages/{request_list.d.ts → request-list.d.ts} +33 -173
- package/storages/{request_list.js → request-list.js} +276 -255
- package/storages/request-loader.d.ts +127 -0
- package/storages/request-loader.js +34 -0
- package/storages/request-manager-tandem.d.ts +82 -0
- package/storages/request-manager-tandem.js +200 -0
- package/storages/request-manager.d.ts +119 -0
- package/storages/request-manager.js +1 -0
- package/storages/{request_provider.d.ts → request-queue.d.ts} +127 -159
- package/storages/request-queue.js +871 -0
- package/storages/storage-instance-manager.d.ts +86 -0
- package/storages/storage-instance-manager.js +256 -0
- package/storages/storage-stats.d.ts +48 -0
- package/storages/storage-stats.js +29 -0
- package/storages/transaction.d.ts +270 -0
- package/storages/transaction.js +296 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +76 -16
- 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/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +23 -18
- package/validators.js +14 -18
- package/autoscaling/autoscaled_pool.d.ts +0 -300
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js +0 -533
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts +0 -4
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js +0 -4
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts +0 -189
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js +0 -285
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts +0 -181
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js +0 -169
- 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 +0 -43
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js +0 -111
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts +0 -61
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js +0 -99
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts +0 -191
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js +0 -108
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts +0 -60
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js +0 -118
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts +0 -55
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js +0 -309
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts +0 -7
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js +0 -7
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts +0 -8
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js +0 -2
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts +0 -213
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js +0 -349
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts +0 -254
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js +0 -268
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts +0 -3
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js +0 -3
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts +0 -84
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js +0 -219
- 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 +0 -52
- 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 +0 -27
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js +0 -75
- package/events/local_event_manager.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 +0 -169
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js +0 -247
- package/proxy_configuration.js.map +0 -1
- package/recoverable_state.d.ts +0 -123
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js +0 -140
- package/recoverable_state.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts +0 -134
- package/router.d.ts.map +0 -1
- package/router.js +0 -164
- 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 +0 -4
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js +0 -4
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts +0 -8
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js +0 -12
- 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 +0 -6
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js +0 -6
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts +0 -186
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js +0 -278
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts +0 -258
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js +0 -387
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- 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 +0 -512
- 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_list_adapter.d.ts +0 -58
- package/storages/request_list_adapter.d.ts.map +0 -1
- package/storages/request_list_adapter.js +0 -81
- package/storages/request_list_adapter.js.map +0 -1
- package/storages/request_manager_tandem.d.ts +0 -68
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js +0 -124
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -591
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts +0 -128
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js +0 -320
- 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 +0 -250
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -431
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -62
- 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/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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fixed-size, direct-mapped cache for `uniqueKey`-based request deduplication.
|
|
3
|
+
*
|
|
4
|
+
* `RequestProvider.requestCache` only remembers the first batch of requests, so repeated
|
|
5
|
+
* `addRequestsBatched()` calls with overlapping URLs re-submit already-enqueued requests
|
|
6
|
+
* (https://github.com/apify/crawlee/issues/3120). This is a separate, cheaper cache we can populate on
|
|
7
|
+
* every batch: a fixed number of slots indexed by a hash of the request's cache key, storing the
|
|
8
|
+
* server-assigned `requestId`. Memory is capped by the slot count regardless of the working set size;
|
|
9
|
+
* a hash collision just overwrites a slot, causing an occasional cache miss (a harmless re-submission)
|
|
10
|
+
* but never a false hit — so a genuinely new request is never dropped.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare class RequestDeduplicationCache {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(size?: number);
|
|
17
|
+
get(cacheKey: string): string | null;
|
|
18
|
+
add(cacheKey: string, requestId: string): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fixed-size, direct-mapped cache for `uniqueKey`-based request deduplication.
|
|
3
|
+
*
|
|
4
|
+
* `RequestProvider.requestCache` only remembers the first batch of requests, so repeated
|
|
5
|
+
* `addRequestsBatched()` calls with overlapping URLs re-submit already-enqueued requests
|
|
6
|
+
* (https://github.com/apify/crawlee/issues/3120). This is a separate, cheaper cache we can populate on
|
|
7
|
+
* every batch: a fixed number of slots indexed by a hash of the request's cache key, storing the
|
|
8
|
+
* server-assigned `requestId`. Memory is capped by the slot count regardless of the working set size;
|
|
9
|
+
* a hash collision just overwrites a slot, causing an occasional cache miss (a harmless re-submission)
|
|
10
|
+
* but never a false hit — so a genuinely new request is never dropped.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export class RequestDeduplicationCache {
|
|
15
|
+
#keys;
|
|
16
|
+
#ids;
|
|
17
|
+
#size;
|
|
18
|
+
// The slot count is the same for every queue, so it's a fixed default rather than a per-consumer option.
|
|
19
|
+
constructor(size = 1_000_000) {
|
|
20
|
+
this.#size = size;
|
|
21
|
+
this.#keys = new Array(size);
|
|
22
|
+
this.#ids = new Array(size);
|
|
23
|
+
}
|
|
24
|
+
get(cacheKey) {
|
|
25
|
+
const index = this.#indexOf(cacheKey);
|
|
26
|
+
return this.#keys[index] === cacheKey ? this.#ids[index] : null;
|
|
27
|
+
}
|
|
28
|
+
add(cacheKey, requestId) {
|
|
29
|
+
const index = this.#indexOf(cacheKey);
|
|
30
|
+
this.#keys[index] = cacheKey;
|
|
31
|
+
this.#ids[index] = requestId;
|
|
32
|
+
}
|
|
33
|
+
clear() {
|
|
34
|
+
this.#keys = new Array(this.#size);
|
|
35
|
+
this.#ids = new Array(this.#size);
|
|
36
|
+
}
|
|
37
|
+
// A cheap FNV-1a hash of the cache key — avoids pulling in a dedicated hashing dependency.
|
|
38
|
+
#indexOf(cacheKey) {
|
|
39
|
+
/* eslint-disable no-bitwise */
|
|
40
|
+
let hash = 0x811c9dc5;
|
|
41
|
+
for (let i = 0; i < cacheKey.length; i++) {
|
|
42
|
+
hash ^= cacheKey.charCodeAt(i);
|
|
43
|
+
hash = Math.imul(hash, 0x01000193);
|
|
44
|
+
}
|
|
45
|
+
return (hash >>> 0) % this.#size;
|
|
46
|
+
/* eslint-enable no-bitwise */
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,69 +1,14 @@
|
|
|
1
|
-
import type { BaseHttpClient
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
1
|
+
import type { BaseHttpClient } from '@crawlee/http-client';
|
|
2
|
+
import type { Dictionary } from '@crawlee/types';
|
|
3
|
+
import type { Configuration } from '../configuration.js';
|
|
4
|
+
import type { IProxyConfiguration } from '../proxy-configuration.js';
|
|
5
|
+
import { Request, type RequestOptions, type Source } from '../request.js';
|
|
6
|
+
import type { IRequestLoader, RequestLoaderStatus } from './request-loader.js';
|
|
7
|
+
import type { IRequestManager } from './request-manager.js';
|
|
5
8
|
/** @internal */
|
|
6
9
|
export declare const STATE_PERSISTENCE_KEY = "REQUEST_LIST_STATE";
|
|
7
10
|
/** @internal */
|
|
8
11
|
export declare const REQUESTS_PERSISTENCE_KEY = "REQUEST_LIST_REQUESTS";
|
|
9
|
-
/**
|
|
10
|
-
* Represents a static list of URLs to crawl.
|
|
11
|
-
*/
|
|
12
|
-
export interface IRequestList {
|
|
13
|
-
/**
|
|
14
|
-
* Returns the total number of unique requests present in the list.
|
|
15
|
-
*/
|
|
16
|
-
length(): number;
|
|
17
|
-
/**
|
|
18
|
-
* Returns `true` if all requests were already handled and there are no more left.
|
|
19
|
-
*/
|
|
20
|
-
isFinished(): Promise<boolean>;
|
|
21
|
-
/**
|
|
22
|
-
* Resolves to `true` if the next call to {@link IRequestList.fetchNextRequest} function
|
|
23
|
-
* would return `null`, otherwise it resolves to `false`.
|
|
24
|
-
* Note that even if the list is empty, there might be some pending requests currently being processed.
|
|
25
|
-
*/
|
|
26
|
-
isEmpty(): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Returns number of handled requests.
|
|
29
|
-
*/
|
|
30
|
-
handledCount(): number;
|
|
31
|
-
/**
|
|
32
|
-
* Persists the current state of the `IRequestList` into the default {@link KeyValueStore}.
|
|
33
|
-
* The state is persisted automatically in regular intervals, but calling this method manually
|
|
34
|
-
* is useful in cases where you want to have the most current state available after you pause
|
|
35
|
-
* or stop fetching its requests. For example after you pause or abort a crawl. Or just before
|
|
36
|
-
* a server migration.
|
|
37
|
-
*/
|
|
38
|
-
persistState(): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Gets the next {@link Request} to process. First, the function gets a request previously reclaimed
|
|
41
|
-
* using the {@link RequestList.reclaimRequest} function, if there is any.
|
|
42
|
-
* Otherwise it gets the next request from sources.
|
|
43
|
-
*
|
|
44
|
-
* The function's `Promise` resolves to `null` if there are no more
|
|
45
|
-
* requests to process.
|
|
46
|
-
*/
|
|
47
|
-
fetchNextRequest(): Promise<Request | null>;
|
|
48
|
-
/**
|
|
49
|
-
* Can be used to iterate over the `RequestList` instance in a `for await .. of` loop.
|
|
50
|
-
* Provides an alternative for the repeated use of `fetchNextRequest`.
|
|
51
|
-
*/
|
|
52
|
-
[Symbol.asyncIterator](): AsyncGenerator<Request>;
|
|
53
|
-
/**
|
|
54
|
-
* Reclaims request to the list if its processing failed.
|
|
55
|
-
* The request will become available in the next `this.fetchNextRequest()`.
|
|
56
|
-
*/
|
|
57
|
-
reclaimRequest(request: Request): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Marks request as handled after successful processing.
|
|
60
|
-
*/
|
|
61
|
-
markRequestHandled(request: Request): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
inProgress: Set<string>;
|
|
66
|
-
}
|
|
67
12
|
export interface RequestListOptions {
|
|
68
13
|
/**
|
|
69
14
|
* An array of sources of URLs for the {@link RequestList}. It can be either an array of strings,
|
|
@@ -143,7 +88,7 @@ export interface RequestListOptions {
|
|
|
143
88
|
* Takes advantage of the internal address rotation and authentication process.
|
|
144
89
|
* If undefined, the `requestsFromUrl` requests will be made without proxy.
|
|
145
90
|
*/
|
|
146
|
-
proxyConfiguration?:
|
|
91
|
+
proxyConfiguration?: IProxyConfiguration;
|
|
147
92
|
/**
|
|
148
93
|
* Identifies the key in the default key-value store under which `RequestList` periodically stores its
|
|
149
94
|
* state (i.e. which URLs were crawled and which not).
|
|
@@ -182,7 +127,8 @@ export interface RequestListOptions {
|
|
|
182
127
|
* ```
|
|
183
128
|
*
|
|
184
129
|
* Note that the preferred (and simpler) way to persist the state of crawling of the `RequestList`
|
|
185
|
-
* is to use the `stateKeyPrefix` parameter instead.
|
|
130
|
+
* is to use the `stateKeyPrefix` parameter instead. When both are set, a record persisted under
|
|
131
|
+
* {@link RequestListOptions.persistStateKey} takes precedence over this option.
|
|
186
132
|
*/
|
|
187
133
|
state?: RequestListState;
|
|
188
134
|
/**
|
|
@@ -202,7 +148,7 @@ export interface RequestListOptions {
|
|
|
202
148
|
*/
|
|
203
149
|
keepDuplicateUrls?: boolean;
|
|
204
150
|
/** @internal */
|
|
205
|
-
|
|
151
|
+
configuration?: Configuration;
|
|
206
152
|
/**
|
|
207
153
|
* The HTTP client to be used to download `requestsFromUrl` URLs.
|
|
208
154
|
*
|
|
@@ -232,8 +178,8 @@ export interface RequestListOptions {
|
|
|
232
178
|
* > In practical terms, such a combination can be useful when there is a large number of initial URLs,
|
|
233
179
|
* > but more URLs would be added dynamically by the crawler.
|
|
234
180
|
*
|
|
235
|
-
* `RequestList` has an internal state where it stores information about which requests were already handled
|
|
236
|
-
* which are in progress
|
|
181
|
+
* `RequestList` has an internal state where it stores information about which requests were already handled
|
|
182
|
+
* and which are in progress. The state may be automatically persisted to the default
|
|
237
183
|
* {@link KeyValueStore} by setting the `persistStateKey` option so that if the Node.js process is restarted,
|
|
238
184
|
* the crawling can continue where it left off. The automated persisting is launched upon receiving the `persistState`
|
|
239
185
|
* event that is periodically emitted by {@link EventManager}.
|
|
@@ -271,93 +217,40 @@ export interface RequestListOptions {
|
|
|
271
217
|
* ```
|
|
272
218
|
* @category Sources
|
|
273
219
|
*/
|
|
274
|
-
export declare class RequestList implements
|
|
275
|
-
private
|
|
220
|
+
export declare class RequestList implements IRequestLoader {
|
|
221
|
+
#private;
|
|
276
222
|
/**
|
|
277
223
|
* Array of all requests from all sources, in the order as they appeared in sources.
|
|
278
224
|
* All requests in the array have distinct uniqueKey!
|
|
279
225
|
* @internal
|
|
280
226
|
*/
|
|
281
|
-
requests: (Request | RequestOptions)[];
|
|
282
|
-
/** Index to the next item in requests array to fetch. All previous requests are either handled or in progress. */
|
|
283
|
-
private nextIndex;
|
|
284
|
-
/** Dictionary, key is Request.uniqueKey, value is corresponding index in the requests array. */
|
|
285
|
-
private uniqueKeyToIndex;
|
|
227
|
+
readonly requests: (Request | RequestOptions)[];
|
|
286
228
|
/**
|
|
287
229
|
* Set of `uniqueKey`s of requests that were returned by fetchNextRequest().
|
|
288
230
|
* @internal
|
|
289
231
|
*/
|
|
290
|
-
inProgress: Set<string>;
|
|
291
|
-
/**
|
|
292
|
-
* Set of `uniqueKey`s of requests for which reclaimRequest() was called.
|
|
293
|
-
* @internal
|
|
294
|
-
*/
|
|
295
|
-
reclaimed: Set<string>;
|
|
296
|
-
/**
|
|
297
|
-
* Starts as true because until we handle the first request, the list is effectively persisted by doing nothing.
|
|
298
|
-
* @internal
|
|
299
|
-
*/
|
|
300
|
-
isStatePersisted: boolean;
|
|
232
|
+
get inProgress(): Set<string>;
|
|
301
233
|
/**
|
|
302
234
|
* Starts as false because we don't know yet and sources might change in the meantime (eg. download from live list).
|
|
303
235
|
* @internal
|
|
304
236
|
*/
|
|
305
237
|
areRequestsPersisted: boolean;
|
|
306
|
-
private isLoading;
|
|
307
|
-
private isInitialized;
|
|
308
|
-
private persistStateKey?;
|
|
309
|
-
private persistRequestsKey?;
|
|
310
|
-
private initialState?;
|
|
311
|
-
private store?;
|
|
312
|
-
private keepDuplicateUrls;
|
|
313
|
-
private sources;
|
|
314
|
-
private sourcesFunction?;
|
|
315
|
-
private proxyConfiguration?;
|
|
316
|
-
private events;
|
|
317
|
-
private httpClient?;
|
|
318
238
|
/**
|
|
319
239
|
* To create new instance of `RequestList` we need to use `RequestList.open()` factory method.
|
|
320
240
|
* @param options All `RequestList` configuration options
|
|
321
241
|
* @internal
|
|
322
242
|
*/
|
|
323
243
|
private constructor();
|
|
324
|
-
/**
|
|
325
|
-
* Loads all remote sources of URLs and potentially starts periodic state persistence.
|
|
326
|
-
* This function must be called before you can start using the instance in a meaningful way.
|
|
327
|
-
*/
|
|
328
|
-
private initialize;
|
|
329
|
-
/**
|
|
330
|
-
* Adds previously persisted Requests, as retrieved from the key-value store.
|
|
331
|
-
* This needs to be done in a memory efficient way. We should update the input
|
|
332
|
-
* to a Stream once apify-client supports streams.
|
|
333
|
-
*/
|
|
334
|
-
protected _addPersistedRequests(persistedRequests: Buffer): Promise<void>;
|
|
335
|
-
/**
|
|
336
|
-
* Add Requests from both options.sources and options.sourcesFunction.
|
|
337
|
-
* This function is called only when persisted sources were not loaded.
|
|
338
|
-
* We need to avoid keeping both sources and requests in memory
|
|
339
|
-
* to reduce memory footprint with very large sources.
|
|
340
|
-
*/
|
|
341
|
-
protected _addRequestsFromSources(): Promise<void>;
|
|
342
244
|
/**
|
|
343
245
|
* @inheritDoc
|
|
344
246
|
*/
|
|
345
247
|
persistState(): Promise<void>;
|
|
346
248
|
/**
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*/
|
|
351
|
-
protected _persistRequests(): Promise<void>;
|
|
352
|
-
/**
|
|
353
|
-
* Restores RequestList state from a state object.
|
|
354
|
-
*/
|
|
355
|
-
protected _restoreState(state?: RequestListState): void;
|
|
356
|
-
/**
|
|
357
|
-
* Attempts to load state and requests using the `RequestList` configuration
|
|
358
|
-
* and returns a tuple of [state, requests] where each may be null if not loaded.
|
|
249
|
+
* Removes the `PERSIST_STATE` event listener registered during initialization and persists
|
|
250
|
+
* the current state one last time. Call this when you are done with the `RequestList` to avoid
|
|
251
|
+
* leaking the listener (and the requests it retains) on the shared event manager.
|
|
359
252
|
*/
|
|
360
|
-
|
|
253
|
+
teardown(): Promise<void>;
|
|
361
254
|
/**
|
|
362
255
|
* Returns an object representing the internal state of the `RequestList` instance.
|
|
363
256
|
* Note that the object's fields can change in future releases.
|
|
@@ -366,11 +259,7 @@ export declare class RequestList implements IRequestList {
|
|
|
366
259
|
/**
|
|
367
260
|
* @inheritDoc
|
|
368
261
|
*/
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* @inheritDoc
|
|
372
|
-
*/
|
|
373
|
-
isFinished(): Promise<boolean>;
|
|
262
|
+
checkReadiness(): Promise<RequestLoaderStatus>;
|
|
374
263
|
/**
|
|
375
264
|
* @inheritDoc
|
|
376
265
|
*/
|
|
@@ -379,51 +268,28 @@ export declare class RequestList implements IRequestList {
|
|
|
379
268
|
* @inheritDoc
|
|
380
269
|
*/
|
|
381
270
|
[Symbol.asyncIterator](): AsyncGenerator<Request<Dictionary>, void, unknown>;
|
|
382
|
-
private ensureRequest;
|
|
383
271
|
/**
|
|
384
272
|
* @inheritDoc
|
|
385
273
|
*/
|
|
386
|
-
|
|
274
|
+
markRequestAsHandled(request: Request): Promise<void>;
|
|
387
275
|
/**
|
|
388
|
-
*
|
|
389
|
-
*/
|
|
390
|
-
reclaimRequest(request: Request): Promise<void>;
|
|
391
|
-
/**
|
|
392
|
-
* Adds all fetched requests from a URL from a remote resource.
|
|
393
|
-
*/
|
|
394
|
-
protected _addFetchedRequests(source: InternalSource, fetchedRequests: RequestOptions[]): Promise<void>;
|
|
395
|
-
protected _getPersistedState<T>(key: string): Promise<T>;
|
|
396
|
-
/**
|
|
397
|
-
* Fetches URLs from requestsFromUrl and returns them in format of list of requests
|
|
398
|
-
*/
|
|
399
|
-
protected _fetchRequestsFromUrl(source: InternalSource): Promise<RequestOptions[]>;
|
|
400
|
-
/**
|
|
401
|
-
* Adds given request.
|
|
402
|
-
* If the `source` parameter is a string or plain object and not an instance
|
|
403
|
-
* of a `Request`, then the function creates a `Request` instance.
|
|
404
|
-
*/
|
|
405
|
-
protected _addRequest(source: RequestListSource): void;
|
|
406
|
-
/**
|
|
407
|
-
* Helper function that validates unique key.
|
|
408
|
-
* Throws an error if uniqueKey is not a non-empty string.
|
|
276
|
+
* Returns the total number of unique requests present in the `RequestList`.
|
|
409
277
|
*/
|
|
410
|
-
|
|
278
|
+
getTotalCount(): Promise<number>;
|
|
411
279
|
/**
|
|
412
|
-
*
|
|
280
|
+
* Returns the number of pending requests in the `RequestList`.
|
|
413
281
|
*/
|
|
414
|
-
|
|
282
|
+
getPendingCount(): Promise<number>;
|
|
415
283
|
/**
|
|
416
|
-
*
|
|
284
|
+
* Combines this list with a request manager (a {@link RequestQueue} by default) into a
|
|
285
|
+
* {@link RequestManagerTandem}, allowing requests to be added and reclaimed while still
|
|
286
|
+
* being read from this list first.
|
|
417
287
|
*/
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Returns the total number of unique requests present in the `RequestList`.
|
|
421
|
-
*/
|
|
422
|
-
length(): number;
|
|
288
|
+
toTandem(requestManager?: IRequestManager): Promise<IRequestManager>;
|
|
423
289
|
/**
|
|
424
290
|
* @inheritDoc
|
|
425
291
|
*/
|
|
426
|
-
|
|
292
|
+
getHandledCount(): Promise<number>;
|
|
427
293
|
/**
|
|
428
294
|
* Opens a request list and returns a promise resolving to an instance
|
|
429
295
|
* of the {@link RequestList} class that is already initialized.
|
|
@@ -478,10 +344,6 @@ export declare class RequestList implements IRequestList {
|
|
|
478
344
|
* options and the `sources` parameter supersedes the {@link RequestListOptions.sources} option.
|
|
479
345
|
*/
|
|
480
346
|
static open(listNameOrOptions: string | null | RequestListOptions, sources?: RequestListSource[], options?: RequestListOptions): Promise<RequestList>;
|
|
481
|
-
/**
|
|
482
|
-
* @internal wraps public utility for mocking purposes
|
|
483
|
-
*/
|
|
484
|
-
private _downloadListOfUrls;
|
|
485
347
|
}
|
|
486
348
|
/**
|
|
487
349
|
* Represents state of a {@link RequestList}. It can be used to resume a {@link RequestList} which has been previously processed.
|
|
@@ -507,7 +369,5 @@ export interface RequestListState {
|
|
|
507
369
|
/** Array of request keys representing those that being processed at the moment. */
|
|
508
370
|
inProgress: string[];
|
|
509
371
|
}
|
|
510
|
-
type RequestListSource = string | Source;
|
|
372
|
+
export type RequestListSource = string | Source;
|
|
511
373
|
export type RequestListSourcesFunction = () => Promise<RequestListSource[]>;
|
|
512
|
-
export {};
|
|
513
|
-
//# sourceMappingURL=request_list.d.ts.map
|