@crawlee/core 3.0.3-beta.9 → 3.0.3
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 +1 -1
- package/autoscaling/autoscaled_pool.d.ts +16 -16
- package/autoscaling/autoscaled_pool.js +13 -13
- package/autoscaling/snapshotter.d.ts +1 -1
- package/autoscaling/snapshotter.js +1 -1
- package/autoscaling/system_status.d.ts +12 -12
- package/autoscaling/system_status.js +11 -11
- package/configuration.d.ts +10 -10
- package/configuration.js +4 -4
- package/crawlers/crawler_commons.d.ts +2 -2
- package/crawlers/statistics.d.ts +1 -1
- package/crawlers/statistics.js +1 -1
- package/enqueue_links/enqueue_links.d.ts +14 -13
- package/enqueue_links/enqueue_links.d.ts.map +1 -1
- package/enqueue_links/enqueue_links.js +6 -5
- package/enqueue_links/enqueue_links.js.map +1 -1
- package/enqueue_links/shared.d.ts +2 -2
- package/errors.d.ts +6 -0
- package/errors.d.ts.map +1 -1
- package/errors.js +10 -1
- package/errors.js.map +1 -1
- package/index.mjs +1 -0
- package/package.json +4 -4
- package/proxy_configuration.d.ts +11 -11
- package/proxy_configuration.js +8 -8
- package/request.d.ts +3 -3
- package/request.js +2 -2
- package/session_pool/session.d.ts +1 -1
- package/session_pool/session_pool.d.ts +12 -12
- package/session_pool/session_pool.d.ts.map +1 -1
- package/session_pool/session_pool.js +10 -10
- package/storages/dataset.d.ts +14 -14
- package/storages/dataset.js +8 -8
- package/storages/key_value_store.d.ts +26 -36
- package/storages/key_value_store.d.ts.map +1 -1
- package/storages/key_value_store.js +47 -33
- package/storages/key_value_store.js.map +1 -1
- package/storages/request_list.d.ts +33 -33
- package/storages/request_list.js +23 -23
- package/storages/request_queue.d.ts +25 -25
- package/storages/request_queue.js +23 -23
- package/storages/utils.d.ts +1 -1
- package/storages/utils.js +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAE/C;;GAEG;AACH,qBAAa,aAAc,SAAQ,iBAAiB;CAAG;AAEvD;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;CAAG"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAE/C;;GAEG;AACH,qBAAa,aAAc,SAAQ,iBAAiB;CAAG;AAEvD;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;CAAG;AAEvD;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC5B,OAAO,CAAC,EAAE,MAAM;CAG/B"}
|
package/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MissingRouteError = exports.CriticalError = exports.NonRetryableError = void 0;
|
|
3
|
+
exports.RetryRequestError = exports.MissingRouteError = exports.CriticalError = exports.NonRetryableError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Errors of `NonRetryableError` type will never be retried by the crawler.
|
|
6
6
|
*/
|
|
@@ -19,4 +19,13 @@ exports.CriticalError = CriticalError;
|
|
|
19
19
|
class MissingRouteError extends CriticalError {
|
|
20
20
|
}
|
|
21
21
|
exports.MissingRouteError = MissingRouteError;
|
|
22
|
+
/**
|
|
23
|
+
* Indicates that the request should be retried (while still respecting the maximum number of retries).
|
|
24
|
+
*/
|
|
25
|
+
class RetryRequestError extends Error {
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super(message ?? "Request is being retried at the user's request");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.RetryRequestError = RetryRequestError;
|
|
22
31
|
//# sourceMappingURL=errors.js.map
|
package/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;CAAG;AAA/C,8CAA+C;AAE/C;;GAEG;AACH,MAAa,aAAc,SAAQ,iBAAiB;CAAG;AAAvD,sCAAuD;AAEvD;;GAEG;AACH,MAAa,iBAAkB,SAAQ,aAAa;CAAG;AAAvD,8CAAuD"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;CAAG;AAA/C,8CAA+C;AAE/C;;GAEG;AACH,MAAa,aAAc,SAAQ,iBAAiB;CAAG;AAAvD,sCAAuD;AAEvD;;GAEG;AACH,MAAa,iBAAkB,SAAQ,aAAa;CAAG;AAAvD,8CAAuD;AAEvD;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IACxC,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,IAAI,gDAAgD,CAAC,CAAC;IACvE,CAAC;CACJ;AAJD,8CAIC"}
|
package/index.mjs
CHANGED
|
@@ -31,6 +31,7 @@ export const REQUESTS_PERSISTENCE_KEY = mod.REQUESTS_PERSISTENCE_KEY;
|
|
|
31
31
|
export const Request = mod.Request;
|
|
32
32
|
export const RequestList = mod.RequestList;
|
|
33
33
|
export const RequestQueue = mod.RequestQueue;
|
|
34
|
+
export const RetryRequestError = mod.RetryRequestError;
|
|
34
35
|
export const Router = mod.Router;
|
|
35
36
|
export const STATE_PERSISTENCE_KEY = mod.STATE_PERSISTENCE_KEY;
|
|
36
37
|
export const STORAGE_CONSISTENCY_DELAY_MILLIS = mod.STORAGE_CONSISTENCY_DELAY_MILLIS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/core",
|
|
3
|
-
"version": "3.0.3
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16.0.0"
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"@apify/pseudo_url": "^2.0.0",
|
|
59
59
|
"@apify/timeout": "^0.3.0",
|
|
60
60
|
"@apify/utilities": "^2.0.0",
|
|
61
|
-
"@crawlee/memory-storage": "^3.0.3
|
|
62
|
-
"@crawlee/types": "^3.0.3
|
|
63
|
-
"@crawlee/utils": "^3.0.3
|
|
61
|
+
"@crawlee/memory-storage": "^3.0.3",
|
|
62
|
+
"@crawlee/types": "^3.0.3",
|
|
63
|
+
"@crawlee/utils": "^3.0.3",
|
|
64
64
|
"@types/tough-cookie": "^4.0.2",
|
|
65
65
|
"@vladfrangu/async_event_emitter": "^2.0.0",
|
|
66
66
|
"fs-extra": "^10.1.0",
|
package/proxy_configuration.d.ts
CHANGED
|
@@ -11,14 +11,14 @@ export interface ProxyConfigurationOptions {
|
|
|
11
11
|
/**
|
|
12
12
|
* Custom function that allows you to generate the new proxy URL dynamically. It gets the `sessionId` as a parameter
|
|
13
13
|
* and should always return stringified proxy URL. Can be asynchronous.
|
|
14
|
-
* This function is used to generate the URL when {@
|
|
14
|
+
* This function is used to generate the URL when {@apilink ProxyConfiguration.newUrl} or {@apilink ProxyConfiguration.newProxyInfo} is called.
|
|
15
15
|
*/
|
|
16
16
|
newUrlFunction?: ProxyConfigurationFunction;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* The main purpose of the ProxyInfo object is to provide information
|
|
20
20
|
* about the current proxy connection used by the crawler for the request.
|
|
21
|
-
* Outside of crawlers, you can get this object by calling {@
|
|
21
|
+
* Outside of crawlers, you can get this object by calling {@apilink ProxyConfiguration.newProxyInfo}.
|
|
22
22
|
*
|
|
23
23
|
* **Example usage:**
|
|
24
24
|
*
|
|
@@ -47,7 +47,7 @@ export interface ProxyConfigurationOptions {
|
|
|
47
47
|
*/
|
|
48
48
|
export interface ProxyInfo {
|
|
49
49
|
/**
|
|
50
|
-
* The identifier of used {@
|
|
50
|
+
* The identifier of used {@apilink Session}, if used.
|
|
51
51
|
*/
|
|
52
52
|
sessionId?: string;
|
|
53
53
|
/**
|
|
@@ -75,9 +75,9 @@ export interface ProxyInfo {
|
|
|
75
75
|
* Configures connection to a proxy server with the provided options. Proxy servers are used to prevent target websites from blocking
|
|
76
76
|
* your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
|
|
77
77
|
* them to use the selected proxies for all connections. You can get information about the currently used proxy by inspecting
|
|
78
|
-
* the {@
|
|
78
|
+
* the {@apilink ProxyInfo} property in your crawler's page function. There, you can inspect the proxy's URL and other attributes.
|
|
79
79
|
*
|
|
80
|
-
* If you want to use your own proxies, use the {@
|
|
80
|
+
* If you want to use your own proxies, use the {@apilink ProxyConfigurationOptions.proxyUrls} option. Your list of proxy URLs will
|
|
81
81
|
* be rotated by the configuration if this option is provided.
|
|
82
82
|
*
|
|
83
83
|
* **Example usage:**
|
|
@@ -107,7 +107,7 @@ export declare class ProxyConfiguration {
|
|
|
107
107
|
protected newUrlFunction?: ProxyConfigurationFunction;
|
|
108
108
|
protected log: import("@apify/log").Log;
|
|
109
109
|
/**
|
|
110
|
-
* Creates a {@
|
|
110
|
+
* Creates a {@apilink ProxyConfiguration} instance based on the provided options. Proxy servers are used to prevent target websites from
|
|
111
111
|
* blocking your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
|
|
112
112
|
* them to use the selected proxies for all connections.
|
|
113
113
|
*
|
|
@@ -128,16 +128,16 @@ export declare class ProxyConfiguration {
|
|
|
128
128
|
*/
|
|
129
129
|
constructor(options?: ProxyConfigurationOptions);
|
|
130
130
|
/**
|
|
131
|
-
* This function creates a new {@
|
|
131
|
+
* This function creates a new {@apilink ProxyInfo} info object.
|
|
132
132
|
* It is used by CheerioCrawler and PuppeteerCrawler to generate proxy URLs and also to allow the user to inspect
|
|
133
133
|
* the currently used proxy via the requestHandler parameter `proxyInfo`.
|
|
134
134
|
* Use it if you want to work with a rich representation of a proxy URL.
|
|
135
|
-
* If you need the URL string only, use {@
|
|
135
|
+
* If you need the URL string only, use {@apilink ProxyConfiguration.newUrl}.
|
|
136
136
|
* @param [sessionId]
|
|
137
|
-
* Represents the identifier of user {@
|
|
137
|
+
* Represents the identifier of user {@apilink Session} that can be managed by the {@apilink SessionPool} or
|
|
138
138
|
* you can use the Apify Proxy [Session](https://docs.apify.com/proxy#sessions) identifier.
|
|
139
139
|
* When the provided sessionId is a number, it's converted to a string. Property sessionId of
|
|
140
|
-
* {@
|
|
140
|
+
* {@apilink ProxyInfo} is always returned as a type string.
|
|
141
141
|
*
|
|
142
142
|
* All the HTTP requests going through the proxy with the same session identifier
|
|
143
143
|
* will use the same target proxy server (i.e. the same IP address).
|
|
@@ -148,7 +148,7 @@ export declare class ProxyConfiguration {
|
|
|
148
148
|
/**
|
|
149
149
|
* Returns a new proxy URL based on provided configuration options and the `sessionId` parameter.
|
|
150
150
|
* @param [sessionId]
|
|
151
|
-
* Represents the identifier of user {@
|
|
151
|
+
* Represents the identifier of user {@apilink Session} that can be managed by the {@apilink SessionPool} or
|
|
152
152
|
* you can use the Apify Proxy [Session](https://docs.apify.com/proxy#sessions) identifier.
|
|
153
153
|
* When the provided sessionId is a number, it's converted to a string.
|
|
154
154
|
*
|
package/proxy_configuration.js
CHANGED
|
@@ -8,9 +8,9 @@ const log_1 = tslib_1.__importDefault(require("@apify/log"));
|
|
|
8
8
|
* Configures connection to a proxy server with the provided options. Proxy servers are used to prevent target websites from blocking
|
|
9
9
|
* your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
|
|
10
10
|
* them to use the selected proxies for all connections. You can get information about the currently used proxy by inspecting
|
|
11
|
-
* the {@
|
|
11
|
+
* the {@apilink ProxyInfo} property in your crawler's page function. There, you can inspect the proxy's URL and other attributes.
|
|
12
12
|
*
|
|
13
|
-
* If you want to use your own proxies, use the {@
|
|
13
|
+
* If you want to use your own proxies, use the {@apilink ProxyConfigurationOptions.proxyUrls} option. Your list of proxy URLs will
|
|
14
14
|
* be rotated by the configuration if this option is provided.
|
|
15
15
|
*
|
|
16
16
|
* **Example usage:**
|
|
@@ -34,7 +34,7 @@ const log_1 = tslib_1.__importDefault(require("@apify/log"));
|
|
|
34
34
|
*/
|
|
35
35
|
class ProxyConfiguration {
|
|
36
36
|
/**
|
|
37
|
-
* Creates a {@
|
|
37
|
+
* Creates a {@apilink ProxyConfiguration} instance based on the provided options. Proxy servers are used to prevent target websites from
|
|
38
38
|
* blocking your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
|
|
39
39
|
* them to use the selected proxies for all connections.
|
|
40
40
|
*
|
|
@@ -104,16 +104,16 @@ class ProxyConfiguration {
|
|
|
104
104
|
this.newUrlFunction = newUrlFunction;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
* This function creates a new {@
|
|
107
|
+
* This function creates a new {@apilink ProxyInfo} info object.
|
|
108
108
|
* It is used by CheerioCrawler and PuppeteerCrawler to generate proxy URLs and also to allow the user to inspect
|
|
109
109
|
* the currently used proxy via the requestHandler parameter `proxyInfo`.
|
|
110
110
|
* Use it if you want to work with a rich representation of a proxy URL.
|
|
111
|
-
* If you need the URL string only, use {@
|
|
111
|
+
* If you need the URL string only, use {@apilink ProxyConfiguration.newUrl}.
|
|
112
112
|
* @param [sessionId]
|
|
113
|
-
* Represents the identifier of user {@
|
|
113
|
+
* Represents the identifier of user {@apilink Session} that can be managed by the {@apilink SessionPool} or
|
|
114
114
|
* you can use the Apify Proxy [Session](https://docs.apify.com/proxy#sessions) identifier.
|
|
115
115
|
* When the provided sessionId is a number, it's converted to a string. Property sessionId of
|
|
116
|
-
* {@
|
|
116
|
+
* {@apilink ProxyInfo} is always returned as a type string.
|
|
117
117
|
*
|
|
118
118
|
* All the HTTP requests going through the proxy with the same session identifier
|
|
119
119
|
* will use the same target proxy server (i.e. the same IP address).
|
|
@@ -137,7 +137,7 @@ class ProxyConfiguration {
|
|
|
137
137
|
/**
|
|
138
138
|
* Returns a new proxy URL based on provided configuration options and the `sessionId` parameter.
|
|
139
139
|
* @param [sessionId]
|
|
140
|
-
* Represents the identifier of user {@
|
|
140
|
+
* Represents the identifier of user {@apilink Session} that can be managed by the {@apilink SessionPool} or
|
|
141
141
|
* you can use the Apify Proxy [Session](https://docs.apify.com/proxy#sessions) identifier.
|
|
142
142
|
* When the provided sessionId is a number, it's converted to a string.
|
|
143
143
|
*
|
package/request.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { AllowedHttpMethods } from './typedefs';
|
|
|
10
10
|
* Each `Request` instance has the `uniqueKey` property, which can be either specified
|
|
11
11
|
* manually in the constructor or generated automatically from the URL. Two requests with the same `uniqueKey`
|
|
12
12
|
* are considered as pointing to the same web resource. This behavior applies to all Apify SDK classes,
|
|
13
|
-
* such as {@
|
|
13
|
+
* such as {@apilink RequestList}, {@apilink RequestQueue}, {@apilink PuppeteerCrawler} or {@apilink PlaywrightCrawler}.
|
|
14
14
|
*
|
|
15
15
|
* Example use:
|
|
16
16
|
*
|
|
@@ -40,7 +40,7 @@ export declare class Request<UserData extends Dictionary = Dictionary> {
|
|
|
40
40
|
* An actually loaded URL after redirects, if present. HTTP redirects are guaranteed
|
|
41
41
|
* to be included.
|
|
42
42
|
*
|
|
43
|
-
* When using {@
|
|
43
|
+
* When using {@apilink PuppeteerCrawler} or {@apilink PlaywrightCrawler}, meta tag and JavaScript redirects may,
|
|
44
44
|
* or may not be included, depending on their nature. This generally means that redirects,
|
|
45
45
|
* which happen immediately will most likely be included, but delayed redirects will not.
|
|
46
46
|
*/
|
|
@@ -100,7 +100,7 @@ export declare class Request<UserData extends Dictionary = Dictionary> {
|
|
|
100
100
|
protected _hashPayload(payload: BinaryLike): string;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
-
* Specifies required and optional fields for constructing a {@
|
|
103
|
+
* Specifies required and optional fields for constructing a {@apilink Request}.
|
|
104
104
|
*/
|
|
105
105
|
export interface RequestOptions<UserData extends Dictionary = Dictionary> {
|
|
106
106
|
/** URL of the web page to crawl. It must be a non-empty string. */
|
package/request.js
CHANGED
|
@@ -34,7 +34,7 @@ const requestOptionalPredicates = {
|
|
|
34
34
|
* Each `Request` instance has the `uniqueKey` property, which can be either specified
|
|
35
35
|
* manually in the constructor or generated automatically from the URL. Two requests with the same `uniqueKey`
|
|
36
36
|
* are considered as pointing to the same web resource. This behavior applies to all Apify SDK classes,
|
|
37
|
-
* such as {@
|
|
37
|
+
* such as {@apilink RequestList}, {@apilink RequestQueue}, {@apilink PuppeteerCrawler} or {@apilink PlaywrightCrawler}.
|
|
38
38
|
*
|
|
39
39
|
* Example use:
|
|
40
40
|
*
|
|
@@ -78,7 +78,7 @@ class Request {
|
|
|
78
78
|
* An actually loaded URL after redirects, if present. HTTP redirects are guaranteed
|
|
79
79
|
* to be included.
|
|
80
80
|
*
|
|
81
|
-
* When using {@
|
|
81
|
+
* When using {@apilink PuppeteerCrawler} or {@apilink PlaywrightCrawler}, meta tag and JavaScript redirects may,
|
|
82
82
|
* or may not be included, depending on their nature. This generally means that redirects,
|
|
83
83
|
* which happen immediately will most likely be included, but delayed redirects will not.
|
|
84
84
|
*/
|
|
@@ -5,7 +5,7 @@ import type { IncomingMessage } from 'node:http';
|
|
|
5
5
|
import type { Cookie } from 'tough-cookie';
|
|
6
6
|
import { CookieJar } from 'tough-cookie';
|
|
7
7
|
/**
|
|
8
|
-
* Persistable {@
|
|
8
|
+
* Persistable {@apilink Session} state.
|
|
9
9
|
*/
|
|
10
10
|
export interface SessionState {
|
|
11
11
|
id: string;
|
|
@@ -7,7 +7,7 @@ import type { SessionOptions } from './session';
|
|
|
7
7
|
import { Session } from './session';
|
|
8
8
|
import type { EventManager } from '../events/event_manager';
|
|
9
9
|
/**
|
|
10
|
-
* Factory user-function which creates customized {@
|
|
10
|
+
* Factory user-function which creates customized {@apilink Session} instances.
|
|
11
11
|
*/
|
|
12
12
|
export interface CreateSession {
|
|
13
13
|
/**
|
|
@@ -24,7 +24,7 @@ export interface SessionPoolOptions {
|
|
|
24
24
|
* @default 1000
|
|
25
25
|
*/
|
|
26
26
|
maxPoolSize?: number;
|
|
27
|
-
/** The configuration options for {@
|
|
27
|
+
/** The configuration options for {@apilink Session} instances. */
|
|
28
28
|
sessionOptions?: SessionOptions;
|
|
29
29
|
/** Name or Id of `KeyValueStore` where is the `SessionPool` state stored. */
|
|
30
30
|
persistStateKeyValueStoreId?: string;
|
|
@@ -50,11 +50,11 @@ export interface SessionPoolOptions {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Handles the rotation, creation and persistence of user-like sessions.
|
|
53
|
-
* Creates a pool of {@
|
|
53
|
+
* Creates a pool of {@apilink Session} instances, that are randomly rotated.
|
|
54
54
|
* When some session is marked as blocked, it is removed and new one is created instead (the pool never returns an unusable session).
|
|
55
55
|
* Learn more in the [Session management guide](../../../docs/guides/session-management).
|
|
56
56
|
*
|
|
57
|
-
* You can create one by calling the {@
|
|
57
|
+
* You can create one by calling the {@apilink SessionPool.open} function.
|
|
58
58
|
*
|
|
59
59
|
* Session pool is already integrated into crawlers, and it can significantly improve your scraper
|
|
60
60
|
* performance with just 2 lines of code.
|
|
@@ -69,10 +69,10 @@ export interface SessionPoolOptions {
|
|
|
69
69
|
* })
|
|
70
70
|
* ```
|
|
71
71
|
*
|
|
72
|
-
* You can configure the pool with many options. See the {@
|
|
73
|
-
* Session pool is by default persisted in default {@
|
|
72
|
+
* You can configure the pool with many options. See the {@apilink SessionPoolOptions}.
|
|
73
|
+
* Session pool is by default persisted in default {@apilink KeyValueStore}.
|
|
74
74
|
* If you want to have one pool for all runs you have to specify
|
|
75
|
-
* {@
|
|
75
|
+
* {@apilink SessionPoolOptions.persistStateKeyValueStoreId}.
|
|
76
76
|
*
|
|
77
77
|
* **Advanced usage:**
|
|
78
78
|
*
|
|
@@ -133,8 +133,8 @@ export declare class SessionPool extends EventEmitter {
|
|
|
133
133
|
*/
|
|
134
134
|
get retiredSessionsCount(): number;
|
|
135
135
|
/**
|
|
136
|
-
* Starts periodic state persistence and potentially loads SessionPool state from {@
|
|
137
|
-
* It is called automatically by the {@
|
|
136
|
+
* Starts periodic state persistence and potentially loads SessionPool state from {@apilink KeyValueStore}.
|
|
137
|
+
* It is called automatically by the {@apilink SessionPool.open} function.
|
|
138
138
|
*/
|
|
139
139
|
initialize(): Promise<void>;
|
|
140
140
|
/**
|
|
@@ -165,7 +165,7 @@ export declare class SessionPool extends EventEmitter {
|
|
|
165
165
|
sessions: import("./session").SessionState[];
|
|
166
166
|
};
|
|
167
167
|
/**
|
|
168
|
-
* Persists the current state of the `SessionPool` into the default {@
|
|
168
|
+
* Persists the current state of the `SessionPool` into the default {@apilink KeyValueStore}.
|
|
169
169
|
* The state is persisted automatically in regular intervals.
|
|
170
170
|
*/
|
|
171
171
|
persistState(): Promise<void>;
|
|
@@ -222,9 +222,9 @@ export declare class SessionPool extends EventEmitter {
|
|
|
222
222
|
protected _maybeLoadSessionPool(): Promise<void>;
|
|
223
223
|
/**
|
|
224
224
|
* Opens a SessionPool and returns a promise resolving to an instance
|
|
225
|
-
* of the {@
|
|
225
|
+
* of the {@apilink SessionPool} class that is already initialized.
|
|
226
226
|
*
|
|
227
|
-
* For more details and code examples, see the {@
|
|
227
|
+
* For more details and code examples, see the {@apilink SessionPool} class.
|
|
228
228
|
*/
|
|
229
229
|
static open(options?: SessionPoolOptions): Promise<SessionPool>;
|
|
230
230
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session_pool.d.ts","sourceRoot":"","sources":["../../src/session_pool/session_pool.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;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
11
11
|
/**
|
|
12
12
|
* Handles the rotation, creation and persistence of user-like sessions.
|
|
13
|
-
* Creates a pool of {@
|
|
13
|
+
* Creates a pool of {@apilink Session} instances, that are randomly rotated.
|
|
14
14
|
* When some session is marked as blocked, it is removed and new one is created instead (the pool never returns an unusable session).
|
|
15
15
|
* Learn more in the [Session management guide](../../../docs/guides/session-management).
|
|
16
16
|
*
|
|
17
|
-
* You can create one by calling the {@
|
|
17
|
+
* You can create one by calling the {@apilink SessionPool.open} function.
|
|
18
18
|
*
|
|
19
19
|
* Session pool is already integrated into crawlers, and it can significantly improve your scraper
|
|
20
20
|
* performance with just 2 lines of code.
|
|
@@ -29,10 +29,10 @@ const session_1 = require("./session");
|
|
|
29
29
|
* })
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
|
-
* You can configure the pool with many options. See the {@
|
|
33
|
-
* Session pool is by default persisted in default {@
|
|
32
|
+
* You can configure the pool with many options. See the {@apilink SessionPoolOptions}.
|
|
33
|
+
* Session pool is by default persisted in default {@apilink KeyValueStore}.
|
|
34
34
|
* If you want to have one pool for all runs you have to specify
|
|
35
|
-
* {@
|
|
35
|
+
* {@apilink SessionPoolOptions.persistStateKeyValueStoreId}.
|
|
36
36
|
*
|
|
37
37
|
* **Advanced usage:**
|
|
38
38
|
*
|
|
@@ -191,8 +191,8 @@ class SessionPool extends node_events_1.EventEmitter {
|
|
|
191
191
|
return this.sessions.filter((session) => !session.isUsable()).length;
|
|
192
192
|
}
|
|
193
193
|
/**
|
|
194
|
-
* Starts periodic state persistence and potentially loads SessionPool state from {@
|
|
195
|
-
* It is called automatically by the {@
|
|
194
|
+
* Starts periodic state persistence and potentially loads SessionPool state from {@apilink KeyValueStore}.
|
|
195
|
+
* It is called automatically by the {@apilink SessionPool.open} function.
|
|
196
196
|
*/
|
|
197
197
|
async initialize() {
|
|
198
198
|
this.keyValueStore = await key_value_store_1.KeyValueStore.open(this.persistStateKeyValueStoreId, { config: this.config });
|
|
@@ -266,7 +266,7 @@ class SessionPool extends node_events_1.EventEmitter {
|
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
268
|
/**
|
|
269
|
-
* Persists the current state of the `SessionPool` into the default {@
|
|
269
|
+
* Persists the current state of the `SessionPool` into the default {@apilink KeyValueStore}.
|
|
270
270
|
* The state is persisted automatically in regular intervals.
|
|
271
271
|
*/
|
|
272
272
|
async persistState() {
|
|
@@ -382,9 +382,9 @@ class SessionPool extends node_events_1.EventEmitter {
|
|
|
382
382
|
}
|
|
383
383
|
/**
|
|
384
384
|
* Opens a SessionPool and returns a promise resolving to an instance
|
|
385
|
-
* of the {@
|
|
385
|
+
* of the {@apilink SessionPool} class that is already initialized.
|
|
386
386
|
*
|
|
387
|
-
* For more details and code examples, see the {@
|
|
387
|
+
* For more details and code examples, see the {@apilink SessionPool} class.
|
|
388
388
|
*/
|
|
389
389
|
static async open(options) {
|
|
390
390
|
const sessionPool = new SessionPool(options);
|
package/storages/dataset.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ export interface DatasetIteratorOptions extends Omit<DatasetDataOptions, 'offset
|
|
|
90
90
|
* Typically it is used to store crawling results.
|
|
91
91
|
*
|
|
92
92
|
* Do not instantiate this class directly, use the
|
|
93
|
-
* {@
|
|
93
|
+
* {@apilink Dataset.open} function instead.
|
|
94
94
|
*
|
|
95
95
|
* `Dataset` stores its data either on local disk or in the Apify cloud,
|
|
96
96
|
* depending on whether the `APIFY_LOCAL_STORAGE_DIR` or `APIFY_TOKEN` environment variables are set.
|
|
@@ -107,7 +107,7 @@ export interface DatasetIteratorOptions extends Omit<DatasetDataOptions, 'offset
|
|
|
107
107
|
* If the `APIFY_TOKEN` environment variable is set but `APIFY_LOCAL_STORAGE_DIR` not, the data is stored in the
|
|
108
108
|
* [Apify Dataset](https://docs.apify.com/storage/dataset)
|
|
109
109
|
* cloud storage. Note that you can force usage of the cloud storage also by passing the `forceCloud`
|
|
110
|
-
* option to {@
|
|
110
|
+
* option to {@apilink Dataset.open} function,
|
|
111
111
|
* even if the `APIFY_LOCAL_STORAGE_DIR` variable is set.
|
|
112
112
|
*
|
|
113
113
|
* **Example usage:**
|
|
@@ -166,7 +166,7 @@ export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
|
166
166
|
*/
|
|
167
167
|
pushData(data: Data | Data[]): Promise<void>;
|
|
168
168
|
/**
|
|
169
|
-
* Returns {@
|
|
169
|
+
* Returns {@apilink DatasetContent} object holding the items in the dataset based on the provided parameters.
|
|
170
170
|
*/
|
|
171
171
|
getData(options?: DatasetDataOptions): Promise<PaginatedList<Data>>;
|
|
172
172
|
/**
|
|
@@ -245,13 +245,13 @@ export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
|
245
245
|
*/
|
|
246
246
|
drop(): Promise<void>;
|
|
247
247
|
/**
|
|
248
|
-
* Opens a dataset and returns a promise resolving to an instance of the {@
|
|
248
|
+
* Opens a dataset and returns a promise resolving to an instance of the {@apilink Dataset} class.
|
|
249
249
|
*
|
|
250
250
|
* Datasets are used to store structured data where each object stored has the same attributes,
|
|
251
251
|
* such as online store products or real estate offers.
|
|
252
252
|
* The actual data is stored either on the local filesystem or in the cloud.
|
|
253
253
|
*
|
|
254
|
-
* For more details and code examples, see the {@
|
|
254
|
+
* For more details and code examples, see the {@apilink Dataset} class.
|
|
255
255
|
*
|
|
256
256
|
* @param [datasetIdOrName]
|
|
257
257
|
* ID or name of the dataset to be opened. If `null` or `undefined`,
|
|
@@ -260,9 +260,9 @@ export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
|
260
260
|
*/
|
|
261
261
|
static open<Data extends Dictionary = Dictionary>(datasetIdOrName?: string | null, options?: StorageManagerOptions): Promise<Dataset<Data>>;
|
|
262
262
|
/**
|
|
263
|
-
* Stores an object or an array of objects to the default {@
|
|
263
|
+
* Stores an object or an array of objects to the default {@apilink Dataset} of the current crawler run.
|
|
264
264
|
*
|
|
265
|
-
* This is just a convenient shortcut for {@
|
|
265
|
+
* This is just a convenient shortcut for {@apilink Dataset.pushData}.
|
|
266
266
|
* For example, calling the following code:
|
|
267
267
|
* ```javascript
|
|
268
268
|
* await Dataset.pushData({ myValue: 123 });
|
|
@@ -274,7 +274,7 @@ export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
|
274
274
|
* await dataset.pushData({ myValue: 123 });
|
|
275
275
|
* ```
|
|
276
276
|
*
|
|
277
|
-
* For more information, see {@
|
|
277
|
+
* For more information, see {@apilink Dataset.open} and {@apilink Dataset.pushData}
|
|
278
278
|
*
|
|
279
279
|
* **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
|
|
280
280
|
* otherwise the crawler process might finish before the data are stored!
|
|
@@ -290,8 +290,8 @@ export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
|
290
290
|
*/
|
|
291
291
|
export interface DatasetConsumer<Data> {
|
|
292
292
|
/**
|
|
293
|
-
* @param item Current {@
|
|
294
|
-
* @param index Position of current {@
|
|
293
|
+
* @param item Current {@apilink Dataset} entry being processed.
|
|
294
|
+
* @param index Position of current {@apilink Dataset} entry.
|
|
295
295
|
*/
|
|
296
296
|
(item: Data, index: number): Awaitable<void>;
|
|
297
297
|
}
|
|
@@ -301,8 +301,8 @@ export interface DatasetConsumer<Data> {
|
|
|
301
301
|
export interface DatasetMapper<Data, R> {
|
|
302
302
|
/**
|
|
303
303
|
* User-function used in the `Dataset.map()` API.
|
|
304
|
-
* @param item Current {@
|
|
305
|
-
* @param index Position of current {@
|
|
304
|
+
* @param item Current {@apilink Dataset} entry being processed.
|
|
305
|
+
* @param index Position of current {@apilink Dataset} entry.
|
|
306
306
|
*/
|
|
307
307
|
(item: Data, index: number): Awaitable<R>;
|
|
308
308
|
}
|
|
@@ -312,8 +312,8 @@ export interface DatasetMapper<Data, R> {
|
|
|
312
312
|
export interface DatasetReducer<T, Data> {
|
|
313
313
|
/**
|
|
314
314
|
* @param memo Previous state of the reduction.
|
|
315
|
-
* @param item Current {@
|
|
316
|
-
* @param index Position of current {@
|
|
315
|
+
* @param item Current {@apilink Dataset} entry being processed.
|
|
316
|
+
* @param index Position of current {@apilink Dataset} entry.
|
|
317
317
|
*/
|
|
318
318
|
(memo: T, item: Data, index: number): Awaitable<T>;
|
|
319
319
|
}
|
package/storages/dataset.js
CHANGED
|
@@ -87,7 +87,7 @@ exports.chunkBySize = chunkBySize;
|
|
|
87
87
|
* Typically it is used to store crawling results.
|
|
88
88
|
*
|
|
89
89
|
* Do not instantiate this class directly, use the
|
|
90
|
-
* {@
|
|
90
|
+
* {@apilink Dataset.open} function instead.
|
|
91
91
|
*
|
|
92
92
|
* `Dataset` stores its data either on local disk or in the Apify cloud,
|
|
93
93
|
* depending on whether the `APIFY_LOCAL_STORAGE_DIR` or `APIFY_TOKEN` environment variables are set.
|
|
@@ -104,7 +104,7 @@ exports.chunkBySize = chunkBySize;
|
|
|
104
104
|
* If the `APIFY_TOKEN` environment variable is set but `APIFY_LOCAL_STORAGE_DIR` not, the data is stored in the
|
|
105
105
|
* [Apify Dataset](https://docs.apify.com/storage/dataset)
|
|
106
106
|
* cloud storage. Note that you can force usage of the cloud storage also by passing the `forceCloud`
|
|
107
|
-
* option to {@
|
|
107
|
+
* option to {@apilink Dataset.open} function,
|
|
108
108
|
* even if the `APIFY_LOCAL_STORAGE_DIR` variable is set.
|
|
109
109
|
*
|
|
110
110
|
* **Example usage:**
|
|
@@ -208,7 +208,7 @@ class Dataset {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
211
|
-
* Returns {@
|
|
211
|
+
* Returns {@apilink DatasetContent} object holding the items in the dataset based on the provided parameters.
|
|
212
212
|
*/
|
|
213
213
|
async getData(options = {}) {
|
|
214
214
|
try {
|
|
@@ -343,13 +343,13 @@ class Dataset {
|
|
|
343
343
|
manager.closeStorage(this);
|
|
344
344
|
}
|
|
345
345
|
/**
|
|
346
|
-
* Opens a dataset and returns a promise resolving to an instance of the {@
|
|
346
|
+
* Opens a dataset and returns a promise resolving to an instance of the {@apilink Dataset} class.
|
|
347
347
|
*
|
|
348
348
|
* Datasets are used to store structured data where each object stored has the same attributes,
|
|
349
349
|
* such as online store products or real estate offers.
|
|
350
350
|
* The actual data is stored either on the local filesystem or in the cloud.
|
|
351
351
|
*
|
|
352
|
-
* For more details and code examples, see the {@
|
|
352
|
+
* For more details and code examples, see the {@apilink Dataset} class.
|
|
353
353
|
*
|
|
354
354
|
* @param [datasetIdOrName]
|
|
355
355
|
* ID or name of the dataset to be opened. If `null` or `undefined`,
|
|
@@ -367,9 +367,9 @@ class Dataset {
|
|
|
367
367
|
return manager.openStorage(datasetIdOrName, options.config.getStorageClient());
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
|
-
* Stores an object or an array of objects to the default {@
|
|
370
|
+
* Stores an object or an array of objects to the default {@apilink Dataset} of the current crawler run.
|
|
371
371
|
*
|
|
372
|
-
* This is just a convenient shortcut for {@
|
|
372
|
+
* This is just a convenient shortcut for {@apilink Dataset.pushData}.
|
|
373
373
|
* For example, calling the following code:
|
|
374
374
|
* ```javascript
|
|
375
375
|
* await Dataset.pushData({ myValue: 123 });
|
|
@@ -381,7 +381,7 @@ class Dataset {
|
|
|
381
381
|
* await dataset.pushData({ myValue: 123 });
|
|
382
382
|
* ```
|
|
383
383
|
*
|
|
384
|
-
* For more information, see {@
|
|
384
|
+
* For more information, see {@apilink Dataset.open} and {@apilink Dataset.pushData}
|
|
385
385
|
*
|
|
386
386
|
* **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
|
|
387
387
|
* otherwise the crawler process might finish before the data are stored!
|