@crawlee/core 4.0.0-beta.4 → 4.0.0-beta.41
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 +9 -5
- package/autoscaling/autoscaled_pool.d.ts +3 -5
- package/autoscaling/autoscaled_pool.d.ts.map +1 -1
- package/autoscaling/autoscaled_pool.js +3 -9
- package/autoscaling/autoscaled_pool.js.map +1 -1
- package/autoscaling/snapshotter.d.ts +3 -13
- package/autoscaling/snapshotter.d.ts.map +1 -1
- package/autoscaling/snapshotter.js +18 -29
- 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 +5 -78
- package/configuration.d.ts.map +1 -1
- package/configuration.js +6 -102
- 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 +8 -8
- package/cookie_utils.js.map +1 -1
- package/crawlers/context_pipeline.d.ts +71 -0
- package/crawlers/context_pipeline.d.ts.map +1 -0
- package/crawlers/context_pipeline.js +123 -0
- package/crawlers/context_pipeline.js.map +1 -0
- package/crawlers/crawler_commons.d.ts +15 -23
- 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 +15 -15
- package/crawlers/statistics.d.ts.map +1 -1
- package/crawlers/statistics.js +21 -18
- 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 +41 -23
- 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 +35 -0
- package/errors.js.map +1 -1
- package/events/event_manager.d.ts +8 -5
- package/events/event_manager.d.ts.map +1 -1
- package/events/event_manager.js +7 -9
- 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 +33 -39
- 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 +82 -2
- package/log.d.ts.map +1 -1
- package/log.js +102 -0
- package/log.js.map +1 -1
- package/package.json +6 -7
- package/proxy_configuration.d.ts +17 -94
- package/proxy_configuration.d.ts.map +1 -1
- package/proxy_configuration.js +18 -54
- package/proxy_configuration.js.map +1 -1
- package/recoverable_state.d.ts +121 -0
- package/recoverable_state.d.ts.map +1 -0
- package/recoverable_state.js +137 -0
- package/recoverable_state.js.map +1 -0
- package/request.d.ts +48 -6
- package/request.d.ts.map +1 -1
- package/request.js +62 -16
- package/request.js.map +1 -1
- package/service_locator.d.ts +162 -0
- package/service_locator.d.ts.map +1 -0
- package/service_locator.js +247 -0
- package/service_locator.js.map +1 -0
- package/session_pool/session.d.ts +9 -31
- package/session_pool/session.d.ts.map +1 -1
- package/session_pool/session.js +17 -21
- package/session_pool/session.js.map +1 -1
- package/session_pool/session_pool.d.ts +27 -54
- package/session_pool/session_pool.d.ts.map +1 -1
- package/session_pool/session_pool.js +54 -69
- package/session_pool/session_pool.js.map +1 -1
- package/storages/dataset.d.ts +53 -3
- package/storages/dataset.d.ts.map +1 -1
- package/storages/dataset.js +78 -6
- 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 +71 -1
- package/storages/key_value_store.d.ts.map +1 -1
- package/storages/key_value_store.js +95 -12
- 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 +11 -8
- 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 +76 -9
- package/storages/request_provider.d.ts.map +1 -1
- package/storages/request_provider.js +92 -54
- package/storages/request_provider.js.map +1 -1
- package/storages/request_queue.d.ts +1 -3
- package/storages/request_queue.d.ts.map +1 -1
- package/storages/request_queue.js +2 -4
- 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 +10 -7
- 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
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
import type { Cookie as CookieObject, Dictionary } from '@crawlee/types';
|
|
2
|
-
import type { Cookie
|
|
1
|
+
import type { Cookie as CookieObject, Dictionary, ISession, ProxyInfo, SessionState } from '@crawlee/types';
|
|
2
|
+
import type { Cookie } from 'tough-cookie';
|
|
3
3
|
import { CookieJar } from 'tough-cookie';
|
|
4
|
-
import type {
|
|
5
|
-
import type { ResponseLike } from '../cookie_utils.js';
|
|
6
|
-
/**
|
|
7
|
-
* Persistable {@link Session} state.
|
|
8
|
-
*/
|
|
9
|
-
export interface SessionState {
|
|
10
|
-
id: string;
|
|
11
|
-
cookieJar: SerializedCookieJar;
|
|
12
|
-
userData: object;
|
|
13
|
-
errorScore: number;
|
|
14
|
-
maxErrorScore: number;
|
|
15
|
-
errorScoreDecrement: number;
|
|
16
|
-
usageCount: number;
|
|
17
|
-
maxUsageCount: number;
|
|
18
|
-
expiresAt: string;
|
|
19
|
-
createdAt: string;
|
|
20
|
-
}
|
|
4
|
+
import type { CrawleeLogger } from '../log.js';
|
|
21
5
|
export interface SessionOptions {
|
|
22
6
|
/** Id of session used for generating fingerprints. It is used as proxy session name. */
|
|
23
7
|
id?: string;
|
|
@@ -60,9 +44,10 @@ export interface SessionOptions {
|
|
|
60
44
|
maxUsageCount?: number;
|
|
61
45
|
/** SessionPool instance. Session will emit the `sessionRetired` event on this instance. */
|
|
62
46
|
sessionPool?: import('./session_pool.js').SessionPool;
|
|
63
|
-
log?:
|
|
47
|
+
log?: CrawleeLogger;
|
|
64
48
|
errorScore?: number;
|
|
65
49
|
cookieJar?: CookieJar;
|
|
50
|
+
proxyInfo?: ProxyInfo;
|
|
66
51
|
}
|
|
67
52
|
/**
|
|
68
53
|
* Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions.
|
|
@@ -70,7 +55,7 @@ export interface SessionOptions {
|
|
|
70
55
|
* Session internal state can be enriched with custom user data for example some authorization tokens and specific headers in general.
|
|
71
56
|
* @category Scaling
|
|
72
57
|
*/
|
|
73
|
-
export declare class Session {
|
|
58
|
+
export declare class Session implements ISession {
|
|
74
59
|
readonly id: string;
|
|
75
60
|
private maxAgeSecs;
|
|
76
61
|
userData: Dictionary;
|
|
@@ -82,6 +67,7 @@ export declare class Session {
|
|
|
82
67
|
private _maxUsageCount;
|
|
83
68
|
private sessionPool;
|
|
84
69
|
private _errorScore;
|
|
70
|
+
private _proxyInfo?;
|
|
85
71
|
private _cookieJar;
|
|
86
72
|
private log;
|
|
87
73
|
get errorScore(): number;
|
|
@@ -92,6 +78,7 @@ export declare class Session {
|
|
|
92
78
|
get createdAt(): Date;
|
|
93
79
|
get maxUsageCount(): number;
|
|
94
80
|
get cookieJar(): CookieJar;
|
|
81
|
+
get proxyInfo(): ProxyInfo | undefined;
|
|
95
82
|
/**
|
|
96
83
|
* Session configuration.
|
|
97
84
|
*/
|
|
@@ -140,15 +127,6 @@ export declare class Session {
|
|
|
140
127
|
* Should be used when the session has been used unsuccessfully. For example because of timeouts.
|
|
141
128
|
*/
|
|
142
129
|
markBad(): void;
|
|
143
|
-
/**
|
|
144
|
-
* With certain status codes: `401`, `403` or `429` we can be certain
|
|
145
|
-
* that the target website is blocking us. This function helps to do this conveniently
|
|
146
|
-
* by retiring the session when such code is received. Optionally, the default status
|
|
147
|
-
* codes can be extended in the second parameter.
|
|
148
|
-
* @param statusCode HTTP status code.
|
|
149
|
-
* @returns Whether the session was retired.
|
|
150
|
-
*/
|
|
151
|
-
retireOnBlockedStatusCodes(statusCode: number): boolean;
|
|
152
130
|
/**
|
|
153
131
|
* Saves cookies from an HTTP response to be used with the session.
|
|
154
132
|
* It expects an object with a `headers` property that's either an `Object`
|
|
@@ -156,7 +134,7 @@ export declare class Session {
|
|
|
156
134
|
*
|
|
157
135
|
* It then parses and saves the cookies from the `set-cookie` header, if available.
|
|
158
136
|
*/
|
|
159
|
-
setCookiesFromResponse(response:
|
|
137
|
+
setCookiesFromResponse(response: Response): void;
|
|
160
138
|
/**
|
|
161
139
|
* Saves an array with cookie objects to be used with the session.
|
|
162
140
|
* The objects should be in the format that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session_pool/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session_pool/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE5G,OAAO,KAAK,EAAE,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3,7 +3,7 @@ import ow from 'ow';
|
|
|
3
3
|
import { CookieJar } from 'tough-cookie';
|
|
4
4
|
import { cryptoRandomObjectId } from '@apify/utilities';
|
|
5
5
|
import { browserPoolCookieToToughCookie, getCookiesFromResponse, getDefaultCookieExpirationDate, toughCookieToBrowserPoolCookie, } from '../cookie_utils.js';
|
|
6
|
-
import {
|
|
6
|
+
import { serviceLocator } from '../service_locator.js';
|
|
7
7
|
import { EVENT_SESSION_RETIRED } from './events.js';
|
|
8
8
|
/**
|
|
9
9
|
* Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions.
|
|
@@ -23,6 +23,7 @@ export class Session {
|
|
|
23
23
|
_maxUsageCount;
|
|
24
24
|
sessionPool;
|
|
25
25
|
_errorScore;
|
|
26
|
+
_proxyInfo;
|
|
26
27
|
_cookieJar;
|
|
27
28
|
log;
|
|
28
29
|
get errorScore() {
|
|
@@ -49,6 +50,9 @@ export class Session {
|
|
|
49
50
|
get cookieJar() {
|
|
50
51
|
return this._cookieJar;
|
|
51
52
|
}
|
|
53
|
+
get proxyInfo() {
|
|
54
|
+
return this._proxyInfo;
|
|
55
|
+
}
|
|
52
56
|
/**
|
|
53
57
|
* Session configuration.
|
|
54
58
|
*/
|
|
@@ -57,6 +61,7 @@ export class Session {
|
|
|
57
61
|
sessionPool: ow.object.instanceOf(EventEmitter),
|
|
58
62
|
id: ow.optional.string,
|
|
59
63
|
cookieJar: ow.optional.object,
|
|
64
|
+
proxyInfo: ow.optional.object,
|
|
60
65
|
maxAgeSecs: ow.optional.number,
|
|
61
66
|
userData: ow.optional.object,
|
|
62
67
|
maxErrorScore: ow.optional.number,
|
|
@@ -68,10 +73,11 @@ export class Session {
|
|
|
68
73
|
maxUsageCount: ow.optional.number,
|
|
69
74
|
log: ow.optional.object,
|
|
70
75
|
}));
|
|
71
|
-
const { sessionPool, id = `session_${cryptoRandomObjectId(10)}`, cookieJar = new CookieJar(), maxAgeSecs = 3000, userData = {}, maxErrorScore = 3, errorScoreDecrement = 0.5, createdAt = new Date(), usageCount = 0, errorScore = 0, maxUsageCount = 50, log =
|
|
76
|
+
const { sessionPool, id = `session_${cryptoRandomObjectId(10)}`, cookieJar = new CookieJar(), proxyInfo = undefined, maxAgeSecs = 3000, userData = {}, maxErrorScore = 3, errorScoreDecrement = 0.5, createdAt = new Date(), usageCount = 0, errorScore = 0, maxUsageCount = 50, log = serviceLocator.getLogger(), } = options;
|
|
72
77
|
const { expiresAt = getDefaultCookieExpirationDate(maxAgeSecs) } = options;
|
|
73
78
|
this.log = log.child({ prefix: 'Session' });
|
|
74
79
|
this._cookieJar = cookieJar.setCookie ? cookieJar : CookieJar.fromJSON(JSON.stringify(cookieJar));
|
|
80
|
+
this._proxyInfo = proxyInfo;
|
|
75
81
|
this.id = id;
|
|
76
82
|
this.maxAgeSecs = maxAgeSecs;
|
|
77
83
|
this.userData = userData;
|
|
@@ -133,6 +139,7 @@ export class Session {
|
|
|
133
139
|
return {
|
|
134
140
|
id: this.id,
|
|
135
141
|
cookieJar: this.cookieJar.toJSON(),
|
|
142
|
+
proxyInfo: this._proxyInfo,
|
|
136
143
|
userData: this.userData,
|
|
137
144
|
maxErrorScore: this.maxErrorScore,
|
|
138
145
|
errorScoreDecrement: this.errorScoreDecrement,
|
|
@@ -166,22 +173,6 @@ export class Session {
|
|
|
166
173
|
this._usageCount += 1;
|
|
167
174
|
this._maybeSelfRetire();
|
|
168
175
|
}
|
|
169
|
-
/**
|
|
170
|
-
* With certain status codes: `401`, `403` or `429` we can be certain
|
|
171
|
-
* that the target website is blocking us. This function helps to do this conveniently
|
|
172
|
-
* by retiring the session when such code is received. Optionally, the default status
|
|
173
|
-
* codes can be extended in the second parameter.
|
|
174
|
-
* @param statusCode HTTP status code.
|
|
175
|
-
* @returns Whether the session was retired.
|
|
176
|
-
*/
|
|
177
|
-
retireOnBlockedStatusCodes(statusCode) {
|
|
178
|
-
// eslint-disable-next-line dot-notation -- accessing private property
|
|
179
|
-
const isBlocked = this.sessionPool['blockedStatusCodes'].includes(statusCode);
|
|
180
|
-
if (isBlocked) {
|
|
181
|
-
this.retire();
|
|
182
|
-
}
|
|
183
|
-
return isBlocked;
|
|
184
|
-
}
|
|
185
176
|
/**
|
|
186
177
|
* Saves cookies from an HTTP response to be used with the session.
|
|
187
178
|
* It expects an object with a `headers` property that's either an `Object`
|
|
@@ -192,7 +183,7 @@ export class Session {
|
|
|
192
183
|
setCookiesFromResponse(response) {
|
|
193
184
|
try {
|
|
194
185
|
const cookies = getCookiesFromResponse(response).filter((c) => c);
|
|
195
|
-
this._setCookies(cookies,
|
|
186
|
+
this._setCookies(cookies, response.url);
|
|
196
187
|
}
|
|
197
188
|
catch (e) {
|
|
198
189
|
const err = e;
|
|
@@ -238,7 +229,12 @@ export class Session {
|
|
|
238
229
|
* Sets a cookie within this session for the specific URL.
|
|
239
230
|
*/
|
|
240
231
|
setCookie(rawCookie, url) {
|
|
241
|
-
|
|
232
|
+
try {
|
|
233
|
+
this.cookieJar.setCookieSync(rawCookie, url);
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
this.log.warning('Could not set cookie.', { url, error: e.message });
|
|
237
|
+
}
|
|
242
238
|
}
|
|
243
239
|
/**
|
|
244
240
|
* Sets cookies.
|
|
@@ -256,7 +252,7 @@ export class Session {
|
|
|
256
252
|
}
|
|
257
253
|
// if invalid cookies are provided just log the exception. No need to retry the request automatically.
|
|
258
254
|
if (errorMessages.length) {
|
|
259
|
-
this.log.
|
|
255
|
+
this.log.warning('Could not set cookies.', { errorMessages });
|
|
260
256
|
}
|
|
261
257
|
}
|
|
262
258
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session_pool/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAA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configuration } from '../configuration.js';
|
|
4
2
|
import type { PersistenceOptions } from '../crawlers/statistics.js';
|
|
5
3
|
import type { EventManager } from '../events/event_manager.js';
|
|
4
|
+
import type { CrawleeLogger } from '../log.js';
|
|
6
5
|
import { KeyValueStore } from '../storages/key_value_store.js';
|
|
7
6
|
import type { SessionOptions } from './session.js';
|
|
8
7
|
import { Session } from './session.js';
|
|
@@ -34,19 +33,13 @@ export interface SessionPoolOptions {
|
|
|
34
33
|
*/
|
|
35
34
|
persistStateKey?: string;
|
|
36
35
|
/**
|
|
37
|
-
* Custom function that should return `Session` instance.
|
|
36
|
+
* Custom function that should return a `Session` instance, or a promise resolving to such instance.
|
|
38
37
|
* Any error thrown from this function will terminate the process.
|
|
39
38
|
* Function receives `SessionPool` instance as a parameter
|
|
40
39
|
*/
|
|
41
40
|
createSessionFunction?: CreateSession;
|
|
42
|
-
/**
|
|
43
|
-
* Specifies which response status codes are considered as blocked.
|
|
44
|
-
* Session connected to such request will be marked as retired.
|
|
45
|
-
* @default [401, 403, 429]
|
|
46
|
-
*/
|
|
47
|
-
blockedStatusCodes?: number[];
|
|
48
41
|
/** @internal */
|
|
49
|
-
log?:
|
|
42
|
+
log?: CrawleeLogger;
|
|
50
43
|
/**
|
|
51
44
|
* Control how and when to persist the state of the session pool.
|
|
52
45
|
*/
|
|
@@ -58,20 +51,8 @@ export interface SessionPoolOptions {
|
|
|
58
51
|
* When some session is marked as blocked, it is removed and new one is created instead (the pool never returns an unusable session).
|
|
59
52
|
* Learn more in the {@doclink guides/session-management | Session management guide}.
|
|
60
53
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* Session pool is already integrated into crawlers, and it can significantly improve your scraper
|
|
64
|
-
* performance with just 2 lines of code.
|
|
65
|
-
*
|
|
66
|
-
* **Example usage:**
|
|
67
|
-
*
|
|
68
|
-
* ```javascript
|
|
69
|
-
* const crawler = new CheerioCrawler({
|
|
70
|
-
* useSessionPool: true,
|
|
71
|
-
* persistCookiesPerSession: true,
|
|
72
|
-
* // ...
|
|
73
|
-
* })
|
|
74
|
-
* ```
|
|
54
|
+
* Session pool is already integrated into crawlers and is always active.
|
|
55
|
+
* All public methods are lazy-initialized — the pool initializes itself on first use.
|
|
75
56
|
*
|
|
76
57
|
* You can configure the pool with many options. See the {@link SessionPoolOptions}.
|
|
77
58
|
* Session pool is by default persisted in default {@link KeyValueStore}.
|
|
@@ -81,7 +62,7 @@ export interface SessionPoolOptions {
|
|
|
81
62
|
* **Advanced usage:**
|
|
82
63
|
*
|
|
83
64
|
* ```javascript
|
|
84
|
-
* const sessionPool =
|
|
65
|
+
* const sessionPool = new SessionPool({
|
|
85
66
|
* maxPoolSize: 25,
|
|
86
67
|
* sessionOptions:{
|
|
87
68
|
* maxAgeSecs: 10,
|
|
@@ -118,39 +99,35 @@ export interface SessionPoolOptions {
|
|
|
118
99
|
* @category Scaling
|
|
119
100
|
*/
|
|
120
101
|
export declare class SessionPool extends EventEmitter {
|
|
121
|
-
|
|
122
|
-
protected log: Log;
|
|
102
|
+
protected log: CrawleeLogger;
|
|
123
103
|
protected maxPoolSize: number;
|
|
124
104
|
protected createSessionFunction: CreateSession;
|
|
125
|
-
protected keyValueStore
|
|
105
|
+
protected keyValueStore?: KeyValueStore;
|
|
126
106
|
protected sessions: Session[];
|
|
127
107
|
protected sessionMap: Map<string, Session>;
|
|
128
108
|
protected sessionOptions: SessionOptions;
|
|
129
109
|
protected persistStateKeyValueStoreId?: string;
|
|
130
110
|
protected persistStateKey: string;
|
|
131
|
-
protected _listener
|
|
111
|
+
protected _listener?: () => Promise<void>;
|
|
132
112
|
protected events: EventManager;
|
|
133
|
-
protected readonly blockedStatusCodes: number[];
|
|
134
113
|
protected persistenceOptions: PersistenceOptions;
|
|
135
|
-
|
|
114
|
+
private initPromise?;
|
|
136
115
|
private queue;
|
|
137
|
-
|
|
138
|
-
* @internal
|
|
139
|
-
*/
|
|
140
|
-
constructor(options?: SessionPoolOptions, config?: Configuration);
|
|
116
|
+
constructor(options?: SessionPoolOptions);
|
|
141
117
|
/**
|
|
142
118
|
* Gets count of usable sessions in the pool.
|
|
143
119
|
*/
|
|
144
|
-
|
|
120
|
+
usableSessionsCount(): Promise<number>;
|
|
145
121
|
/**
|
|
146
122
|
* Gets count of retired sessions in the pool.
|
|
147
123
|
*/
|
|
148
|
-
|
|
124
|
+
retiredSessionsCount(): Promise<number>;
|
|
149
125
|
/**
|
|
150
126
|
* Starts periodic state persistence and potentially loads SessionPool state from {@link KeyValueStore}.
|
|
151
|
-
*
|
|
127
|
+
* Called automatically on first use of any public method.
|
|
152
128
|
*/
|
|
153
|
-
|
|
129
|
+
protected ensureInitialized(): Promise<void>;
|
|
130
|
+
private setupPool;
|
|
154
131
|
/**
|
|
155
132
|
* Adds a new session to the session pool. The pool automatically creates sessions up to the maximum size of the pool,
|
|
156
133
|
* but this allows you to add more sessions once the max pool size is reached.
|
|
@@ -158,6 +135,13 @@ export declare class SessionPool extends EventEmitter {
|
|
|
158
135
|
* @param [options] The configuration options for the session being added to the session pool.
|
|
159
136
|
*/
|
|
160
137
|
addSession(options?: Session | SessionOptions): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Adds a new session to the session pool. The pool automatically creates sessions up to the maximum size of the pool,
|
|
140
|
+
* but this allows you to add more sessions once the max pool size is reached.
|
|
141
|
+
* This also allows you to add session with overridden session options (e.g. with specific session id).
|
|
142
|
+
* @param [options] The configuration options for the session being added to the session pool.
|
|
143
|
+
*/
|
|
144
|
+
newSession(sessionOptions?: SessionOptions): Promise<Session>;
|
|
161
145
|
/**
|
|
162
146
|
* Gets session.
|
|
163
147
|
* If there is space for new session, it creates and returns new session.
|
|
@@ -177,12 +161,12 @@ export declare class SessionPool extends EventEmitter {
|
|
|
177
161
|
* Returns an object representing the internal state of the `SessionPool` instance.
|
|
178
162
|
* Note that the object's fields can change in future releases.
|
|
179
163
|
*/
|
|
180
|
-
getState(): {
|
|
164
|
+
getState(): Promise<{
|
|
181
165
|
usableSessionsCount: number;
|
|
182
166
|
retiredSessionsCount: number;
|
|
183
167
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
184
|
-
sessions: import("
|
|
185
|
-
}
|
|
168
|
+
sessions: import("@crawlee/types").SessionState[];
|
|
169
|
+
}>;
|
|
186
170
|
/**
|
|
187
171
|
* Persists the current state of the `SessionPool` into the default {@link KeyValueStore}.
|
|
188
172
|
* The state is persisted automatically in regular intervals.
|
|
@@ -194,10 +178,6 @@ export declare class SessionPool extends EventEmitter {
|
|
|
194
178
|
* This function should be called after you are done with using the `SessionPool` instance.
|
|
195
179
|
*/
|
|
196
180
|
teardown(): Promise<void>;
|
|
197
|
-
/**
|
|
198
|
-
* SessionPool should not work before initialization.
|
|
199
|
-
*/
|
|
200
|
-
protected _throwIfNotInitialized(): void;
|
|
201
181
|
/**
|
|
202
182
|
* Removes retired `Session` instances from `SessionPool`.
|
|
203
183
|
*/
|
|
@@ -220,7 +200,7 @@ export declare class SessionPool extends EventEmitter {
|
|
|
220
200
|
*/
|
|
221
201
|
protected _defaultCreateSessionFunction(sessionPool: SessionPool, options?: {
|
|
222
202
|
sessionOptions?: SessionOptions;
|
|
223
|
-
}): Session
|
|
203
|
+
}): Promise<Session>;
|
|
224
204
|
/**
|
|
225
205
|
* Creates new session and adds it to the pool.
|
|
226
206
|
* @returns Newly created `Session` instance.
|
|
@@ -240,12 +220,5 @@ export declare class SessionPool extends EventEmitter {
|
|
|
240
220
|
* If the state was persisted it loads the `SessionPool` from the persisted state.
|
|
241
221
|
*/
|
|
242
222
|
protected _maybeLoadSessionPool(): Promise<void>;
|
|
243
|
-
/**
|
|
244
|
-
* Opens a SessionPool and returns a promise resolving to an instance
|
|
245
|
-
* of the {@link SessionPool} class that is already initialized.
|
|
246
|
-
*
|
|
247
|
-
* For more details and code examples, see the {@link SessionPool} class.
|
|
248
|
-
*/
|
|
249
|
-
static open(options?: SessionPoolOptions, config?: Configuration): Promise<SessionPool>;
|
|
250
223
|
}
|
|
251
224
|
//# sourceMappingURL=session_pool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session_pool.d.ts","sourceRoot":"","sources":["../../src/session_pool/session_pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"session_pool.d.ts","sourceRoot":"","sources":["../../src/session_pool/session_pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;;OAGG;IACH,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACzG;AAED,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,kEAAkE;IAClE,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC,6EAA6E;IAC7E,2BAA2B,CAAC,EAAE,MAAM,CAAC;IAErC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,aAAa,CAAC;IAEtC,gBAAgB;IAChB,GAAG,CAAC,EAAE,aAAa,CAAC;IAEpB;;OAEG;IACH,kBA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