@crawlee/core 4.0.0-beta.3 → 4.0.0-beta.30
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 +5 -1
- package/autoscaling/autoscaled_pool.d.ts +1 -3
- package/autoscaling/autoscaled_pool.d.ts.map +1 -1
- package/autoscaling/autoscaled_pool.js +1 -7
- package/autoscaling/autoscaled_pool.js.map +1 -1
- package/autoscaling/snapshotter.d.ts +0 -10
- package/autoscaling/snapshotter.d.ts.map +1 -1
- package/autoscaling/snapshotter.js +15 -28
- package/autoscaling/snapshotter.js.map +1 -1
- package/autoscaling/system_status.d.ts +0 -3
- package/autoscaling/system_status.d.ts.map +1 -1
- package/autoscaling/system_status.js +2 -3
- package/autoscaling/system_status.js.map +1 -1
- package/configuration.d.ts +4 -77
- package/configuration.d.ts.map +1 -1
- package/configuration.js +5 -101
- package/configuration.js.map +1 -1
- package/cookie_utils.d.ts +1 -1
- package/cookie_utils.d.ts.map +1 -1
- package/cookie_utils.js +4 -6
- package/cookie_utils.js.map +1 -1
- package/crawlers/context_pipeline.d.ts +61 -0
- package/crawlers/context_pipeline.d.ts.map +1 -0
- package/crawlers/context_pipeline.js +99 -0
- package/crawlers/context_pipeline.js.map +1 -0
- package/crawlers/crawler_commons.d.ts +12 -20
- package/crawlers/crawler_commons.d.ts.map +1 -1
- package/crawlers/crawler_commons.js +0 -8
- package/crawlers/crawler_commons.js.map +1 -1
- package/crawlers/error_snapshotter.d.ts +3 -2
- package/crawlers/error_snapshotter.d.ts.map +1 -1
- package/crawlers/error_snapshotter.js +2 -2
- package/crawlers/error_snapshotter.js.map +1 -1
- package/crawlers/error_tracker.d.ts +2 -1
- package/crawlers/error_tracker.d.ts.map +1 -1
- package/crawlers/error_tracker.js.map +1 -1
- package/crawlers/index.d.ts +1 -1
- package/crawlers/index.d.ts.map +1 -1
- package/crawlers/index.js +1 -1
- package/crawlers/index.js.map +1 -1
- package/crawlers/internals/types.d.ts +8 -0
- package/crawlers/internals/types.d.ts.map +1 -0
- package/crawlers/internals/types.js +2 -0
- package/crawlers/internals/types.js.map +1 -0
- package/crawlers/statistics.d.ts +13 -13
- package/crawlers/statistics.d.ts.map +1 -1
- package/crawlers/statistics.js +20 -16
- package/crawlers/statistics.js.map +1 -1
- package/enqueue_links/enqueue_links.d.ts +30 -18
- package/enqueue_links/enqueue_links.d.ts.map +1 -1
- package/enqueue_links/enqueue_links.js +39 -21
- package/enqueue_links/enqueue_links.js.map +1 -1
- package/enqueue_links/shared.d.ts +24 -7
- package/enqueue_links/shared.d.ts.map +1 -1
- package/enqueue_links/shared.js +66 -37
- package/enqueue_links/shared.js.map +1 -1
- package/errors.d.ts +18 -0
- package/errors.d.ts.map +1 -1
- package/errors.js +29 -0
- package/errors.js.map +1 -1
- package/events/event_manager.d.ts +7 -4
- package/events/event_manager.d.ts.map +1 -1
- package/events/event_manager.js +5 -7
- package/events/event_manager.js.map +1 -1
- package/events/local_event_manager.d.ts +14 -4
- package/events/local_event_manager.d.ts.map +1 -1
- package/events/local_event_manager.js +26 -37
- package/events/local_event_manager.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.d.ts.map +1 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/log.d.ts +4 -2
- package/log.d.ts.map +1 -1
- package/log.js.map +1 -1
- package/package.json +6 -7
- package/proxy_configuration.d.ts +16 -93
- package/proxy_configuration.d.ts.map +1 -1
- package/proxy_configuration.js +15 -51
- package/proxy_configuration.js.map +1 -1
- package/recoverable_state.d.ts +122 -0
- package/recoverable_state.d.ts.map +1 -0
- package/recoverable_state.js +138 -0
- package/recoverable_state.js.map +1 -0
- package/request.d.ts +39 -5
- package/request.d.ts.map +1 -1
- package/request.js +52 -12
- package/request.js.map +1 -1
- package/service_locator.d.ts +139 -0
- package/service_locator.d.ts.map +1 -0
- package/service_locator.js +252 -0
- package/service_locator.js.map +1 -0
- package/session_pool/session.d.ts +7 -20
- package/session_pool/session.d.ts.map +1 -1
- package/session_pool/session.js +16 -4
- package/session_pool/session.js.map +1 -1
- package/session_pool/session_pool.d.ts +12 -7
- package/session_pool/session_pool.d.ts.map +1 -1
- package/session_pool/session_pool.js +22 -11
- package/session_pool/session_pool.js.map +1 -1
- package/storages/dataset.d.ts +7 -0
- package/storages/dataset.d.ts.map +1 -1
- package/storages/dataset.js +14 -4
- package/storages/dataset.js.map +1 -1
- package/storages/index.d.ts +2 -0
- package/storages/index.d.ts.map +1 -1
- package/storages/index.js +2 -0
- package/storages/index.js.map +1 -1
- package/storages/key_value_store.d.ts +13 -1
- package/storages/key_value_store.d.ts.map +1 -1
- package/storages/key_value_store.js +16 -10
- package/storages/key_value_store.js.map +1 -1
- package/storages/request_list.d.ts +9 -9
- package/storages/request_list.d.ts.map +1 -1
- package/storages/request_list.js +10 -6
- package/storages/request_list.js.map +1 -1
- package/storages/request_list_adapter.d.ts +58 -0
- package/storages/request_list_adapter.d.ts.map +1 -0
- package/storages/request_list_adapter.js +81 -0
- package/storages/request_list_adapter.js.map +1 -0
- package/storages/request_manager_tandem.d.ts +68 -0
- package/storages/request_manager_tandem.d.ts.map +1 -0
- package/storages/request_manager_tandem.js +124 -0
- package/storages/request_manager_tandem.js.map +1 -0
- package/storages/request_provider.d.ts +74 -7
- package/storages/request_provider.d.ts.map +1 -1
- package/storages/request_provider.js +89 -52
- package/storages/request_provider.js.map +1 -1
- package/storages/request_queue.d.ts +1 -1
- package/storages/request_queue.d.ts.map +1 -1
- package/storages/request_queue.js +2 -2
- package/storages/request_queue.js.map +1 -1
- package/storages/request_queue_v2.d.ts +3 -3
- package/storages/request_queue_v2.d.ts.map +1 -1
- package/storages/request_queue_v2.js +4 -5
- package/storages/request_queue_v2.js.map +1 -1
- package/storages/sitemap_request_list.d.ts +5 -5
- package/storages/sitemap_request_list.d.ts.map +1 -1
- package/storages/sitemap_request_list.js +6 -5
- package/storages/sitemap_request_list.js.map +1 -1
- package/storages/storage_manager.d.ts +10 -8
- package/storages/storage_manager.d.ts.map +1 -1
- package/storages/storage_manager.js +12 -22
- package/storages/storage_manager.js.map +1 -1
- package/storages/utils.d.ts.map +1 -1
- package/storages/utils.js +4 -3
- package/storages/utils.js.map +1 -1
- package/typedefs.d.ts +1 -1
- package/typedefs.d.ts.map +1 -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/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/tsconfig.build.tsbuildinfo +0 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { KeyValueStore, serviceLocator } from '@crawlee/core';
|
|
2
|
+
import log from '@apify/log';
|
|
3
|
+
/**
|
|
4
|
+
* A class for managing persistent recoverable state using a plain JavaScript object.
|
|
5
|
+
*
|
|
6
|
+
* This class facilitates state persistence to a `KeyValueStore`, allowing data to be saved and retrieved
|
|
7
|
+
* across migrations or restarts. It manages the loading, saving, and resetting of state data,
|
|
8
|
+
* with optional persistence capabilities.
|
|
9
|
+
*
|
|
10
|
+
* The state is represented by a plain JavaScript object that can be serialized to and deserialized from JSON.
|
|
11
|
+
* The class automatically hooks into the event system to persist state when needed.
|
|
12
|
+
*/
|
|
13
|
+
export class RecoverableState {
|
|
14
|
+
defaultState;
|
|
15
|
+
state = null;
|
|
16
|
+
persistenceEnabled;
|
|
17
|
+
persistStateKey;
|
|
18
|
+
persistStateKvsName;
|
|
19
|
+
persistStateKvsId;
|
|
20
|
+
keyValueStore = null;
|
|
21
|
+
log;
|
|
22
|
+
serialize;
|
|
23
|
+
deserialize;
|
|
24
|
+
/**
|
|
25
|
+
* Initialize a new recoverable state object.
|
|
26
|
+
*
|
|
27
|
+
* @param options Configuration options for the recoverable state
|
|
28
|
+
*/
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.defaultState = options.defaultState;
|
|
31
|
+
this.persistStateKey = options.persistStateKey;
|
|
32
|
+
this.persistenceEnabled = options.persistenceEnabled ?? false;
|
|
33
|
+
this.persistStateKvsName = options.persistStateKvsName;
|
|
34
|
+
this.persistStateKvsId = options.persistStateKvsId;
|
|
35
|
+
this.log = options.logger ?? log.child({ prefix: 'RecoverableState' });
|
|
36
|
+
this.serialize = options.serialize ?? JSON.stringify;
|
|
37
|
+
this.deserialize = options.deserialize ?? JSON.parse;
|
|
38
|
+
this.persistState = this.persistState.bind(this);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initialize the recoverable state.
|
|
42
|
+
*
|
|
43
|
+
* This method must be called before using the recoverable state. It loads the saved state
|
|
44
|
+
* if persistence is enabled and registers the object to listen for PERSIST_STATE events.
|
|
45
|
+
*
|
|
46
|
+
* @returns The loaded state object
|
|
47
|
+
*/
|
|
48
|
+
async initialize() {
|
|
49
|
+
if (this.state !== null && this.state !== undefined) {
|
|
50
|
+
return this.currentValue;
|
|
51
|
+
}
|
|
52
|
+
if (!this.persistenceEnabled) {
|
|
53
|
+
this.state = this.deserialize(this.serialize(this.defaultState));
|
|
54
|
+
return this.currentValue;
|
|
55
|
+
}
|
|
56
|
+
this.keyValueStore = await KeyValueStore.open(this.persistStateKvsName ?? this.persistStateKvsId, {
|
|
57
|
+
config: serviceLocator.getConfiguration(),
|
|
58
|
+
});
|
|
59
|
+
await this.loadSavedState();
|
|
60
|
+
// Register for persist state events
|
|
61
|
+
const eventManager = serviceLocator.getEventManager();
|
|
62
|
+
eventManager.on("persistState" /* EventType.PERSIST_STATE */, this.persistState);
|
|
63
|
+
return this.currentValue;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Clean up resources used by the recoverable state.
|
|
67
|
+
*
|
|
68
|
+
* If persistence is enabled, this method deregisters the object from PERSIST_STATE events
|
|
69
|
+
* and persists the current state one last time.
|
|
70
|
+
*/
|
|
71
|
+
async teardown() {
|
|
72
|
+
if (!this.persistenceEnabled || !this.persistState) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const eventManager = serviceLocator.getEventManager();
|
|
76
|
+
eventManager.off("persistState" /* EventType.PERSIST_STATE */, this.persistState);
|
|
77
|
+
await this.persistState();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the current state.
|
|
81
|
+
*/
|
|
82
|
+
get currentValue() {
|
|
83
|
+
if (this.state === null) {
|
|
84
|
+
throw new Error('Recoverable state has not yet been loaded');
|
|
85
|
+
}
|
|
86
|
+
return this.state;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Reset the state to the default values and clear any persisted state.
|
|
90
|
+
*
|
|
91
|
+
* Resets the current state to the default state and, if persistence is enabled,
|
|
92
|
+
* clears the persisted state from the KeyValueStore.
|
|
93
|
+
*/
|
|
94
|
+
async reset() {
|
|
95
|
+
this.state = this.deserialize(this.serialize(this.defaultState));
|
|
96
|
+
if (this.persistenceEnabled) {
|
|
97
|
+
if (this.keyValueStore === null) {
|
|
98
|
+
throw new Error('Recoverable state has not yet been initialized');
|
|
99
|
+
}
|
|
100
|
+
await this.keyValueStore.setValue(this.persistStateKey, null);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Persist the current state to the KeyValueStore.
|
|
105
|
+
*
|
|
106
|
+
* This method is typically called in response to a PERSIST_STATE event, but can also be called
|
|
107
|
+
* directly when needed.
|
|
108
|
+
*
|
|
109
|
+
* @param eventData Optional data associated with a PERSIST_STATE event
|
|
110
|
+
*/
|
|
111
|
+
async persistState(eventData) {
|
|
112
|
+
this.log.debug(`Persisting state of the RecoverableState (eventData=${JSON.stringify(eventData)}).`);
|
|
113
|
+
if (this.keyValueStore === null || this.state === null) {
|
|
114
|
+
throw new Error('Recoverable state has not yet been initialized');
|
|
115
|
+
}
|
|
116
|
+
if (this.persistenceEnabled) {
|
|
117
|
+
await this.keyValueStore.setValue(this.persistStateKey, this.serialize(this.state), {
|
|
118
|
+
contentType: 'text/plain', // HACK - the result is expected to be JSON, but we do this to avoid the implicit JSON.parse in `KeyValueStore.getValue`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Load the saved state from the KeyValueStore
|
|
124
|
+
*/
|
|
125
|
+
async loadSavedState() {
|
|
126
|
+
if (this.keyValueStore === null) {
|
|
127
|
+
throw new Error('Recoverable state has not yet been initialized');
|
|
128
|
+
}
|
|
129
|
+
const storedState = await this.keyValueStore.getValue(this.persistStateKey);
|
|
130
|
+
if (storedState === null || storedState === undefined) {
|
|
131
|
+
this.state = this.deserialize(this.serialize(this.defaultState));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.state = this.deserialize(storedState);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=recoverable_state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recoverable_state.js","sourceRoot":"","sources":["../src/recoverable_state.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGzE,OAAO,GAAG,MAAM,YAAY,CAAC;AA6D7B;;;;;;;;;GASG;AACH,MAAM,OAAO,gBAAgB;IACR,YAAY,CAAc;IACnC,KAAK,GAAuB,IAAI,CAAC;IACxB,kBAAkB,CAAU;IAC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L,CAAC;CACJ"}
|
package/request.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BinaryLike } from 'node:crypto';
|
|
2
2
|
import type { Dictionary } from '@crawlee/types';
|
|
3
3
|
import type { EnqueueLinksOptions } from './enqueue_links/enqueue_links.js';
|
|
4
|
+
import type { SkippedRequestReason } from './enqueue_links/shared.js';
|
|
4
5
|
import type { AllowedHttpMethods } from './typedefs.js';
|
|
5
6
|
export declare enum RequestState {
|
|
6
7
|
UNPROCESSED = 0,
|
|
@@ -43,7 +44,7 @@ export declare enum RequestState {
|
|
|
43
44
|
* ```
|
|
44
45
|
* @category Sources
|
|
45
46
|
*/
|
|
46
|
-
|
|
47
|
+
declare class CrawleeRequest<UserData extends Dictionary = Dictionary> {
|
|
47
48
|
/** Request ID */
|
|
48
49
|
id?: string;
|
|
49
50
|
/** URL of the web page to crawl. */
|
|
@@ -87,10 +88,25 @@ export declare class Request<UserData extends Dictionary = Dictionary> {
|
|
|
87
88
|
* `Request` parameters including the URL, HTTP method and headers, and others.
|
|
88
89
|
*/
|
|
89
90
|
constructor(options: RequestOptions<UserData>);
|
|
91
|
+
/**
|
|
92
|
+
* Converts the Crawlee Request object to a `fetch` API Request object.
|
|
93
|
+
* @returns The native `fetch` API Request object.
|
|
94
|
+
*/
|
|
95
|
+
intoFetchAPIRequest(): Request;
|
|
90
96
|
/** Tells the crawler processing this request to skip the navigation and process the request directly. */
|
|
91
97
|
get skipNavigation(): boolean;
|
|
92
98
|
/** Tells the crawler processing this request to skip the navigation and process the request directly. */
|
|
93
99
|
set skipNavigation(value: boolean);
|
|
100
|
+
/**
|
|
101
|
+
* Depth of the request in the current crawl tree.
|
|
102
|
+
* Note that this is dependent on the crawler setup and might produce unexpected results when used with multiple crawlers.
|
|
103
|
+
*/
|
|
104
|
+
get crawlDepth(): number;
|
|
105
|
+
/**
|
|
106
|
+
* Depth of the request in the current crawl tree.
|
|
107
|
+
* Note that this is dependent on the crawler setup and might produce unexpected results when used with multiple crawlers.
|
|
108
|
+
*/
|
|
109
|
+
set crawlDepth(value: number);
|
|
94
110
|
/** Indicates the number of times the crawling of the request has rotated the session due to a session or a proxy error. */
|
|
95
111
|
get sessionRotationCount(): number;
|
|
96
112
|
/** Indicates the number of times the crawling of the request has rotated the session due to a session or a proxy error. */
|
|
@@ -107,6 +123,14 @@ export declare class Request<UserData extends Dictionary = Dictionary> {
|
|
|
107
123
|
get state(): RequestState;
|
|
108
124
|
/** Describes the request's current lifecycle state. */
|
|
109
125
|
set state(value: RequestState);
|
|
126
|
+
/**
|
|
127
|
+
* Reason for skipping this request.
|
|
128
|
+
*/
|
|
129
|
+
get skippedReason(): SkippedRequestReason | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Reason for skipping this request.
|
|
132
|
+
*/
|
|
133
|
+
set skippedReason(value: SkippedRequestReason | undefined);
|
|
110
134
|
private get enqueueStrategy();
|
|
111
135
|
private set enqueueStrategy(value);
|
|
112
136
|
/**
|
|
@@ -123,8 +147,6 @@ export declare class Request<UserData extends Dictionary = Dictionary> {
|
|
|
123
147
|
* @param [options]
|
|
124
148
|
*/
|
|
125
149
|
pushErrorMessage(errorOrMessage: unknown, options?: PushErrorMessageOptions): void;
|
|
126
|
-
protected _computeUniqueKey(options: ComputeUniqueKeyOptions): string;
|
|
127
|
-
protected _hashPayload(payload: BinaryLike): string;
|
|
128
150
|
/** @internal */
|
|
129
151
|
static computeUniqueKey({ url, method, payload, keepUrlFragment, useExtendedUniqueKey, }: ComputeUniqueKeyOptions): string;
|
|
130
152
|
/** @internal */
|
|
@@ -203,6 +225,18 @@ export interface RequestOptions<UserData extends Dictionary = Dictionary> {
|
|
|
203
225
|
* @default false
|
|
204
226
|
*/
|
|
205
227
|
skipNavigation?: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Depth of the request in the current crawl tree.
|
|
230
|
+
* Note that this is dependent on the crawler setup and might produce unexpected results when used with multiple crawlers.
|
|
231
|
+
* @default 0
|
|
232
|
+
*/
|
|
233
|
+
crawlDepth?: number;
|
|
234
|
+
/**
|
|
235
|
+
* Reason for skipping this request.
|
|
236
|
+
* This is used to provide more information about why the request was skipped.
|
|
237
|
+
* @internal
|
|
238
|
+
*/
|
|
239
|
+
skippedReason?: SkippedRequestReason;
|
|
206
240
|
/**
|
|
207
241
|
* Maximum number of retries for this request. Allows to override the global `maxRequestRetries` option of `BasicCrawler`.
|
|
208
242
|
*/
|
|
@@ -233,11 +267,11 @@ interface ComputeUniqueKeyOptions {
|
|
|
233
267
|
export type Source = (Partial<RequestOptions> & {
|
|
234
268
|
requestsFromUrl?: string;
|
|
235
269
|
regex?: RegExp;
|
|
236
|
-
}) |
|
|
270
|
+
}) | CrawleeRequest;
|
|
237
271
|
/** @internal */
|
|
238
272
|
export interface InternalSource {
|
|
239
273
|
requestsFromUrl: string;
|
|
240
274
|
regex?: RegExp;
|
|
241
275
|
}
|
|
242
|
-
export {};
|
|
276
|
+
export { CrawleeRequest as Request };
|
|
243
277
|
//# sourceMappingURL=request.d.ts.map
|
package/request.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;A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C1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,cAAc,CAAC;AAE/G,gBAAgB;AAChB,MAAM,WAAW,cAAc;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,OAAO,EAAE,cAAc,IAAI,OAAO,EAAE,CAAC"}
|
package/request.js
CHANGED
|
@@ -24,6 +24,7 @@ const requestOptionalPredicates = {
|
|
|
24
24
|
keepUrlFragment: ow.optional.boolean,
|
|
25
25
|
useExtendedUniqueKey: ow.optional.boolean,
|
|
26
26
|
skipNavigation: ow.optional.boolean,
|
|
27
|
+
crawlDepth: ow.optional.number.greaterThanOrEqual(0),
|
|
27
28
|
state: ow.optional.number.greaterThanOrEqual(0).lessThanOrEqual(6),
|
|
28
29
|
};
|
|
29
30
|
export var RequestState;
|
|
@@ -68,7 +69,7 @@ export var RequestState;
|
|
|
68
69
|
* ```
|
|
69
70
|
* @category Sources
|
|
70
71
|
*/
|
|
71
|
-
|
|
72
|
+
class CrawleeRequest {
|
|
72
73
|
/** Request ID */
|
|
73
74
|
id;
|
|
74
75
|
/** URL of the web page to crawl. */
|
|
@@ -130,7 +131,7 @@ export class Request {
|
|
|
130
131
|
ow(value, `RequestOptions.${prop}`, predicate);
|
|
131
132
|
}
|
|
132
133
|
});
|
|
133
|
-
const { id, url, loadedUrl, uniqueKey, payload, noRetry = false, retryCount = 0, sessionRotationCount = 0, maxRetries, errorMessages = [], headers = {}, userData = {}, label, handledAt, keepUrlFragment = false, useExtendedUniqueKey = false, skipNavigation, enqueueStrategy, } = options;
|
|
134
|
+
const { id, url, loadedUrl, uniqueKey, payload, noRetry = false, retryCount = 0, sessionRotationCount = 0, maxRetries, errorMessages = [], headers = {}, userData = {}, label, handledAt, keepUrlFragment = false, useExtendedUniqueKey = false, skipNavigation, enqueueStrategy, crawlDepth, } = options;
|
|
134
135
|
let { method = 'GET' } = options;
|
|
135
136
|
method = method.toUpperCase();
|
|
136
137
|
if (method === 'GET' && payload)
|
|
@@ -139,7 +140,8 @@ export class Request {
|
|
|
139
140
|
this.url = url;
|
|
140
141
|
this.loadedUrl = loadedUrl;
|
|
141
142
|
this.uniqueKey =
|
|
142
|
-
uniqueKey ||
|
|
143
|
+
uniqueKey ||
|
|
144
|
+
CrawleeRequest.computeUniqueKey({ url, method, payload, keepUrlFragment, useExtendedUniqueKey });
|
|
143
145
|
this.method = method;
|
|
144
146
|
this.payload = payload;
|
|
145
147
|
this.noRetry = noRetry;
|
|
@@ -191,11 +193,24 @@ export class Request {
|
|
|
191
193
|
this.skipNavigation = skipNavigation;
|
|
192
194
|
if (maxRetries != null)
|
|
193
195
|
this.maxRetries = maxRetries;
|
|
196
|
+
if (crawlDepth != null)
|
|
197
|
+
this.userData.__crawlee.crawlDepth ??= crawlDepth;
|
|
194
198
|
// If it's already set, don't override it (for instance when fetching from storage)
|
|
195
199
|
if (enqueueStrategy) {
|
|
196
200
|
this.enqueueStrategy ??= enqueueStrategy;
|
|
197
201
|
}
|
|
198
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Converts the Crawlee Request object to a `fetch` API Request object.
|
|
205
|
+
* @returns The native `fetch` API Request object.
|
|
206
|
+
*/
|
|
207
|
+
intoFetchAPIRequest() {
|
|
208
|
+
return new Request(this.url, {
|
|
209
|
+
method: this.method,
|
|
210
|
+
headers: this.headers,
|
|
211
|
+
body: this.payload,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
199
214
|
/** Tells the crawler processing this request to skip the navigation and process the request directly. */
|
|
200
215
|
get skipNavigation() {
|
|
201
216
|
return this.userData.__crawlee?.skipNavigation ?? false;
|
|
@@ -209,6 +224,21 @@ export class Request {
|
|
|
209
224
|
this.userData.__crawlee.skipNavigation = value;
|
|
210
225
|
}
|
|
211
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Depth of the request in the current crawl tree.
|
|
229
|
+
* Note that this is dependent on the crawler setup and might produce unexpected results when used with multiple crawlers.
|
|
230
|
+
*/
|
|
231
|
+
get crawlDepth() {
|
|
232
|
+
return this.userData.__crawlee?.crawlDepth ?? 0;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Depth of the request in the current crawl tree.
|
|
236
|
+
* Note that this is dependent on the crawler setup and might produce unexpected results when used with multiple crawlers.
|
|
237
|
+
*/
|
|
238
|
+
set crawlDepth(value) {
|
|
239
|
+
this.userData.__crawlee ??= {};
|
|
240
|
+
this.userData.__crawlee.crawlDepth = value;
|
|
241
|
+
}
|
|
212
242
|
/** Indicates the number of times the crawling of the request has rotated the session due to a session or a proxy error. */
|
|
213
243
|
get sessionRotationCount() {
|
|
214
244
|
return this.userData.__crawlee?.sessionRotationCount ?? 0;
|
|
@@ -256,6 +286,23 @@ export class Request {
|
|
|
256
286
|
this.userData.__crawlee.state = value;
|
|
257
287
|
}
|
|
258
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Reason for skipping this request.
|
|
291
|
+
*/
|
|
292
|
+
get skippedReason() {
|
|
293
|
+
return this.userData.__crawlee?.skippedReason;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Reason for skipping this request.
|
|
297
|
+
*/
|
|
298
|
+
set skippedReason(value) {
|
|
299
|
+
if (!this.userData.__crawlee) {
|
|
300
|
+
this.userData.__crawlee = { skippedReason: value };
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
this.userData.__crawlee.skippedReason = value;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
259
306
|
get enqueueStrategy() {
|
|
260
307
|
return this.userData.__crawlee?.enqueueStrategy;
|
|
261
308
|
}
|
|
@@ -317,14 +364,6 @@ export class Request {
|
|
|
317
364
|
}
|
|
318
365
|
this.errorMessages.push(message);
|
|
319
366
|
}
|
|
320
|
-
// TODO: only for better BC, remove in v4
|
|
321
|
-
_computeUniqueKey(options) {
|
|
322
|
-
return Request.computeUniqueKey(options);
|
|
323
|
-
}
|
|
324
|
-
// TODO: only for better BC, remove in v4
|
|
325
|
-
_hashPayload(payload) {
|
|
326
|
-
return Request.hashPayload(payload);
|
|
327
|
-
}
|
|
328
367
|
/** @internal */
|
|
329
368
|
static computeUniqueKey({ url, method = 'GET', payload, keepUrlFragment = false, useExtendedUniqueKey = false, }) {
|
|
330
369
|
const normalizedMethod = method.toUpperCase();
|
|
@@ -337,7 +376,7 @@ export class Request {
|
|
|
337
376
|
}
|
|
338
377
|
return normalizedUrl;
|
|
339
378
|
}
|
|
340
|
-
const payloadHash = payload ?
|
|
379
|
+
const payloadHash = payload ? CrawleeRequest.hashPayload(payload) : '';
|
|
341
380
|
return `${normalizedMethod}(${payloadHash}):${normalizedUrl}`;
|
|
342
381
|
}
|
|
343
382
|
/** @internal */
|
|
@@ -345,4 +384,5 @@ export class Request {
|
|
|
345
384
|
return crypto.createHash('sha256').update(payload).digest('base64').replace(/[+/=]/g, '').substring(0, 8);
|
|
346
385
|
}
|
|
347
386
|
}
|
|
387
|
+
export { CrawleeRequest as Request };
|
|
348
388
|
//# sourceMappingURL=request.js.map
|
package/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,EAAE,MAAM,IAAI,CAAC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,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9G,CAAC;CACJ;AA8ID,OAAO,EAAE,cAAc,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { StorageClient } from '@crawlee/types';
|
|
2
|
+
import { Configuration } from './configuration.js';
|
|
3
|
+
import type { EventManager } from './events/event_manager.js';
|
|
4
|
+
import type { IStorage, StorageManager } from './storages/storage_manager.js';
|
|
5
|
+
import type { Constructor } from './typedefs.js';
|
|
6
|
+
interface ServiceLocatorInterface {
|
|
7
|
+
/**
|
|
8
|
+
* Get the configuration.
|
|
9
|
+
* Creates a default Configuration instance if none has been set.
|
|
10
|
+
*/
|
|
11
|
+
getConfiguration(): Configuration;
|
|
12
|
+
/**
|
|
13
|
+
* Set the configuration.
|
|
14
|
+
*
|
|
15
|
+
* @param configuration The configuration to set
|
|
16
|
+
* @throws {ServiceConflictError} If a different configuration has already been retrieved
|
|
17
|
+
*/
|
|
18
|
+
setConfiguration(configuration: Configuration): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get the event manager.
|
|
21
|
+
* Creates a default LocalEventManager instance if none has been set.
|
|
22
|
+
*/
|
|
23
|
+
getEventManager(): EventManager;
|
|
24
|
+
/**
|
|
25
|
+
* Set the event manager.
|
|
26
|
+
*
|
|
27
|
+
* @param eventManager The event manager to set
|
|
28
|
+
* @throws {ServiceConflictError} If a different event manager has already been retrieved
|
|
29
|
+
*/
|
|
30
|
+
setEventManager(eventManager: EventManager): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get the storage client.
|
|
33
|
+
* Creates a default MemoryStorage instance if none has been set.
|
|
34
|
+
*/
|
|
35
|
+
getStorageClient(): StorageClient;
|
|
36
|
+
/**
|
|
37
|
+
* Set the storage client.
|
|
38
|
+
*
|
|
39
|
+
* @param storageClient The storage client to set
|
|
40
|
+
* @throws {ServiceConflictError} If a different storage client has already been retrieved
|
|
41
|
+
*/
|
|
42
|
+
setStorageClient(storageClient: StorageClient): void;
|
|
43
|
+
getStorageManager(constructor: Constructor<IStorage>): StorageManager | undefined;
|
|
44
|
+
setStorageManager(constructor: Constructor<IStorage>, storageManager: StorageManager): void;
|
|
45
|
+
/**
|
|
46
|
+
* Clears all storage manager caches.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
clearStorageManagerCache(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Resets the service locator to its initial state.
|
|
52
|
+
* Used mainly for testing purposes.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
reset(): void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Service locator for managing the services used by Crawlee.
|
|
59
|
+
*
|
|
60
|
+
* All services are initialized to their default value lazily.
|
|
61
|
+
*
|
|
62
|
+
* There are two primary usage patterns:
|
|
63
|
+
*
|
|
64
|
+
* **1. Global service locator (for default services):**
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { serviceLocator, BasicCrawler } from 'crawlee';
|
|
67
|
+
*
|
|
68
|
+
* // Optionally configure global services before creating crawlers
|
|
69
|
+
* serviceLocator.setStorageClient(myCustomClient);
|
|
70
|
+
*
|
|
71
|
+
* // Crawler uses global services
|
|
72
|
+
* const crawler = new BasicCrawler({ ... });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* **2. Per-crawler services (recommended for isolation):**
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { BasicCrawler, Configuration, LocalEventManager } from 'crawlee';
|
|
78
|
+
* import { MemoryStorage } from '@crawlee/memory-storage';
|
|
79
|
+
*
|
|
80
|
+
* const crawler = new BasicCrawler({
|
|
81
|
+
* requestHandler: async ({ request }) => { ... },
|
|
82
|
+
* configuration: new Configuration({ ... }), // custom config
|
|
83
|
+
* storageClient: new MemoryStorage(), // custom storage
|
|
84
|
+
* eventManager: LocalEventManager.fromConfig(), // custom events
|
|
85
|
+
* });
|
|
86
|
+
* // Crawler has its own isolated ServiceLocator instance
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare class ServiceLocator implements ServiceLocatorInterface {
|
|
90
|
+
private configuration?;
|
|
91
|
+
private eventManager?;
|
|
92
|
+
private storageClient?;
|
|
93
|
+
/**
|
|
94
|
+
* Storage managers for Dataset, KeyValueStore, and RequestQueue.
|
|
95
|
+
* Manages caching and lifecycle of storage instances.
|
|
96
|
+
*/
|
|
97
|
+
private storageManagers;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new ServiceLocator instance.
|
|
100
|
+
*
|
|
101
|
+
* @param configuration Optional configuration instance to use
|
|
102
|
+
* @param eventManager Optional event manager instance to use
|
|
103
|
+
* @param storageClient Optional storage client instance to use
|
|
104
|
+
*/
|
|
105
|
+
constructor(configuration?: Configuration, eventManager?: EventManager, storageClient?: StorageClient);
|
|
106
|
+
getConfiguration(): Configuration;
|
|
107
|
+
setConfiguration(configuration: Configuration): void;
|
|
108
|
+
getEventManager(): EventManager;
|
|
109
|
+
setEventManager(eventManager: EventManager): void;
|
|
110
|
+
getStorageClient(): StorageClient;
|
|
111
|
+
setStorageClient(storageClient: StorageClient): void;
|
|
112
|
+
getStorageManager(constructor: Constructor<IStorage>): StorageManager | undefined;
|
|
113
|
+
setStorageManager(constructor: Constructor<IStorage>, storageManager: StorageManager): void;
|
|
114
|
+
clearStorageManagerCache(): void;
|
|
115
|
+
reset(): void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Wraps all methods on `target` so that any code they invoke will see the given
|
|
119
|
+
* `serviceLocator` via `AsyncLocalStorage`, rather than the global one.
|
|
120
|
+
*
|
|
121
|
+
* Walks the prototype chain and replaces each method on the *instance* (not the prototype)
|
|
122
|
+
* with a wrapper that calls `serviceLocatorStorage.run(serviceLocator, originalMethod)`.
|
|
123
|
+
*
|
|
124
|
+
* The `AsyncLocalStorage` context propagates through the entire sync/async call tree of each
|
|
125
|
+
* wrapped method — including `super` calls, since the prototype methods execute within the
|
|
126
|
+
* context established by the instance-level wrapper.
|
|
127
|
+
*
|
|
128
|
+
* @internal
|
|
129
|
+
* @returns Scope control functions: `run` executes a callback within the scoped context,
|
|
130
|
+
* `enterScope`/`exitScope` allow entering/leaving the scope imperatively (e.g., for constructor bodies).
|
|
131
|
+
*/
|
|
132
|
+
export declare function bindMethodsToServiceLocator(serviceLocator: ServiceLocator, target: {}): {
|
|
133
|
+
run: <T>(fn: () => T) => T;
|
|
134
|
+
enterScope: () => void;
|
|
135
|
+
exitScope: () => void;
|
|
136
|
+
};
|
|
137
|
+
export declare const serviceLocator: ServiceLocatorInterface;
|
|
138
|
+
export {};
|
|
139
|
+
//# sourceMappingURL=service_locator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service_locator.d.ts","sourceRoot":"","sources":["../src/service_locator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,UAAU,uBAAuB;IAC7B;;;OAGG;IACH,gBAAgB,IAAI,aAAa,CAAC;IAElC;;;;;OAKG;IACH,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAErD;;;OAGG;IACH,eAAe,IAAI,YAAY,CAAC;IAEhC;;;;;OAKG;IACH,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAElD;;;OAGG;IACH,gBAAgB,IAAI,aAAa,CAAC;IAElC;;;;;OAKG;IACH,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAErD,iB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