@crawlee/core 4.0.0-rc.0 → 4.0.0-rc.1
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/configuration.d.ts +15 -46
- package/configuration.js +8 -20
- package/errors.d.ts +12 -53
- package/errors.js +13 -66
- package/events/index.d.ts +1 -0
- package/events/local_event_manager.d.ts +0 -7
- package/events/local_event_manager.js +8 -8
- package/events/system_info.d.ts +38 -0
- package/index.d.ts +2 -8
- package/index.js +4 -8
- package/internal.d.ts +8 -0
- package/internal.js +9 -0
- package/log.d.ts +10 -11
- package/log.js +53 -25
- package/memory-storage/memory-storage.d.ts +12 -7
- package/memory-storage/memory-storage.js +45 -17
- package/memory-storage/resource-clients/dataset.d.ts +0 -5
- package/memory-storage/resource-clients/dataset.js +17 -20
- package/memory-storage/resource-clients/key-value-store.d.ts +0 -9
- package/memory-storage/resource-clients/key-value-store.js +11 -33
- package/memory-storage/resource-clients/request-queue.d.ts +0 -22
- package/memory-storage/resource-clients/request-queue.js +57 -53
- package/package.json +16 -18
- package/proxy_configuration.d.ts +20 -23
- package/proxy_configuration.js +18 -12
- package/recoverable_state.d.ts +28 -6
- package/recoverable_state.js +51 -14
- package/request.d.ts +18 -104
- package/request.js +41 -220
- package/serialization.js +3 -3
- package/service_locator.d.ts +3 -0
- package/service_locator.js +2 -0
- package/storages/dataset.d.ts +9 -15
- package/storages/dataset.js +22 -14
- package/storages/index.d.ts +3 -4
- package/storages/index.js +1 -4
- package/storages/key_value_store.d.ts +12 -46
- package/storages/key_value_store.js +31 -47
- package/storages/key_value_store_codec.js +6 -11
- package/storages/request_dedup_cache.d.ts +0 -2
- package/storages/request_dedup_cache.js +8 -8
- package/storages/request_list.d.ts +6 -82
- package/storages/request_list.js +175 -179
- package/storages/request_loader.d.ts +48 -22
- package/storages/request_loader.js +36 -1
- package/storages/request_manager.d.ts +86 -0
- package/storages/request_manager_tandem.d.ts +13 -28
- package/storages/request_manager_tandem.js +46 -43
- package/storages/request_queue.d.ts +19 -49
- package/storages/request_queue.js +92 -88
- package/storages/storage_instance_manager.d.ts +1 -2
- package/storages/storage_instance_manager.js +4 -4
- package/storages/transaction.d.ts +27 -9
- package/storages/transaction.js +56 -11
- package/storages/utils.d.ts +2 -2
- package/validators.d.ts +3 -2
- package/validators.js +3 -2
- package/autoscaling/autoscaled_pool.d.ts +0 -195
- package/autoscaling/autoscaled_pool.js +0 -386
- package/autoscaling/concurrency_system.d.ts +0 -268
- package/autoscaling/concurrency_system.js +0 -362
- package/autoscaling/cpu_load_signal.d.ts +0 -43
- package/autoscaling/cpu_load_signal.js +0 -47
- package/autoscaling/event_loop_load_signal.d.ts +0 -51
- package/autoscaling/event_loop_load_signal.js +0 -60
- package/autoscaling/index.d.ts +0 -9
- package/autoscaling/index.js +0 -9
- package/autoscaling/load_signal.d.ts +0 -100
- package/autoscaling/load_signal.js +0 -105
- package/autoscaling/memory_load_signal.d.ts +0 -47
- package/autoscaling/memory_load_signal.js +0 -106
- package/autoscaling/snapshotter.d.ts +0 -84
- package/autoscaling/snapshotter.js +0 -67
- package/autoscaling/storage_backend_load_signal.d.ts +0 -56
- package/autoscaling/storage_backend_load_signal.js +0 -73
- package/autoscaling/system_status.d.ts +0 -159
- package/autoscaling/system_status.js +0 -139
- package/autoscaling/weighted_avg.d.ts +0 -5
- package/autoscaling/weighted_avg.js +0 -14
- package/cookie_utils.d.ts +0 -44
- package/cookie_utils.js +0 -122
- package/crawlers/context_pipeline.d.ts +0 -70
- package/crawlers/context_pipeline.js +0 -122
- package/crawlers/crawler_commons.d.ts +0 -159
- package/crawlers/error_snapshotter.d.ts +0 -57
- package/crawlers/error_snapshotter.js +0 -117
- package/crawlers/error_tracker.d.ts +0 -54
- package/crawlers/error_tracker.js +0 -308
- package/crawlers/index.d.ts +0 -5
- package/crawlers/index.js +0 -4
- package/crawlers/internals/types.d.ts +0 -7
- package/crawlers/internals/types.js +0 -1
- package/crawlers/statistics.d.ts +0 -328
- package/crawlers/statistics.js +0 -536
- package/enqueue_links/enqueue_links.d.ts +0 -156
- package/enqueue_links/enqueue_links.js +0 -78
- package/enqueue_links/index.d.ts +0 -2
- package/enqueue_links/index.js +0 -2
- package/enqueue_links/shared.d.ts +0 -93
- package/enqueue_links/shared.js +0 -239
- package/http.d.ts +0 -9
- package/http.js +0 -28
- package/router.d.ts +0 -306
- package/router.js +0 -309
- package/session_pool/consts.d.ts +0 -3
- package/session_pool/consts.js +0 -3
- package/session_pool/errors.d.ts +0 -7
- package/session_pool/errors.js +0 -11
- package/session_pool/fingerprint.d.ts +0 -9
- package/session_pool/fingerprint.js +0 -30
- package/session_pool/index.d.ts +0 -4
- package/session_pool/index.js +0 -4
- package/session_pool/session.d.ts +0 -150
- package/session_pool/session.js +0 -220
- package/session_pool/session_pool.d.ts +0 -240
- package/session_pool/session_pool.js +0 -394
- package/storages/sitemap_request_loader.d.ts +0 -201
- package/storages/sitemap_request_loader.js +0 -438
- package/storages/throttling_request_manager.d.ts +0 -239
- package/storages/throttling_request_manager.js +0 -646
- /package/{crawlers/crawler_commons.js → events/system_info.js} +0 -0
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) N
|
|
|
34
34
|
|
|
35
35
|
We recommend visiting the [Introduction tutorial](https://crawlee.dev/js/docs/introduction) in Crawlee documentation for more information.
|
|
36
36
|
|
|
37
|
-
> Crawlee requires **Node.js
|
|
37
|
+
> Crawlee requires **Node.js 22.13 or higher**.
|
|
38
38
|
|
|
39
39
|
### With Crawlee CLI
|
|
40
40
|
|
package/configuration.d.ts
CHANGED
|
@@ -6,47 +6,39 @@ export interface ConfigField<T extends z.ZodType = z.ZodType> {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function field<T extends z.ZodType>(schema: T, envVar?: string | string[]): ConfigField<T>;
|
|
8
8
|
/** Zod preprocessor treating `'0'` and `'false'` as falsy. */
|
|
9
|
-
export declare const coerceBoolean: z.ZodPreprocess<z.ZodBoolean>;
|
|
10
|
-
export declare const coerceNumber: z.ZodPreprocess<z.ZodNumber>;
|
|
9
|
+
export declare const coerceBoolean: z.ZodPreprocess<z.ZodBoolean, unknown>;
|
|
10
|
+
export declare const coerceNumber: z.ZodPreprocess<z.ZodNumber, unknown>;
|
|
11
11
|
export declare const crawleeConfigFields: {
|
|
12
|
-
/** @default 'default' */
|
|
13
|
-
defaultDatasetId: ConfigField<z.ZodDefault<z.ZodString>>;
|
|
14
12
|
/** @default true */
|
|
15
|
-
purgeOnStart: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>>;
|
|
16
|
-
/** @default 'default' */
|
|
17
|
-
defaultKeyValueStoreId: ConfigField<z.ZodDefault<z.ZodString>>;
|
|
18
|
-
/** @default 'default' */
|
|
19
|
-
defaultRequestQueueId: ConfigField<z.ZodDefault<z.ZodString>>;
|
|
13
|
+
purgeOnStart: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
|
|
20
14
|
/** @default 0.95 */
|
|
21
|
-
maxUsedCpuRatio: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber>>>;
|
|
15
|
+
maxUsedCpuRatio: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
|
|
22
16
|
/** @default 0.25 */
|
|
23
|
-
availableMemoryRatio: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber>>>;
|
|
24
|
-
memoryMbytes: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodNumber>>>;
|
|
17
|
+
availableMemoryRatio: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
|
|
18
|
+
memoryMbytes: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodNumber, unknown>>>;
|
|
25
19
|
/** @default 60_000 */
|
|
26
|
-
persistStateIntervalMillis: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber>>>;
|
|
20
|
+
persistStateIntervalMillis: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
|
|
27
21
|
/**
|
|
28
22
|
* Internal safety-net timeout for a single request, in milliseconds. When unset the crawler derives it from
|
|
29
23
|
* the request handler timeout (twice it, and never below 5 minutes).
|
|
30
24
|
*/
|
|
31
|
-
internalTimeoutMillis: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodNumber>>>;
|
|
25
|
+
internalTimeoutMillis: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodNumber, unknown>>>;
|
|
32
26
|
/** @default 1_000 */
|
|
33
|
-
systemInfoIntervalMillis: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber>>>;
|
|
34
|
-
/** @default 'INPUT' */
|
|
35
|
-
inputKey: ConfigField<z.ZodDefault<z.ZodString>>;
|
|
27
|
+
systemInfoIntervalMillis: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
|
|
36
28
|
/** @default true */
|
|
37
|
-
headless: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>>;
|
|
29
|
+
headless: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
|
|
38
30
|
/** @default false */
|
|
39
|
-
xvfb: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>>;
|
|
31
|
+
xvfb: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
|
|
40
32
|
chromeExecutablePath: ConfigField<z.ZodOptional<z.ZodString>>;
|
|
41
33
|
defaultBrowserPath: ConfigField<z.ZodOptional<z.ZodString>>;
|
|
42
34
|
/** @default false */
|
|
43
|
-
disableBrowserSandbox: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>>;
|
|
44
|
-
logLevel: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodEnum<typeof LogLevel
|
|
35
|
+
disableBrowserSandbox: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
|
|
36
|
+
logLevel: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodEnum<typeof LogLevel>, unknown>>>;
|
|
45
37
|
/** @default true */
|
|
46
|
-
persistStorage: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>>;
|
|
38
|
+
persistStorage: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
|
|
47
39
|
/** @default './storage' */
|
|
48
40
|
storageDir: ConfigField<z.ZodDefault<z.ZodString>>;
|
|
49
|
-
containerized: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodBoolean>>>;
|
|
41
|
+
containerized: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
|
|
50
42
|
};
|
|
51
43
|
export type FieldsInput<F extends Record<string, ConfigField>> = {
|
|
52
44
|
[K in keyof F]?: z.output<F[K]['schema']>;
|
|
@@ -101,9 +93,6 @@ export interface Configuration extends ResolvedConfigValues {
|
|
|
101
93
|
* `memoryMbytes` | `CRAWLEE_MEMORY_MBYTES` | -
|
|
102
94
|
* `logLevel` | `CRAWLEE_LOG_LEVEL` | -
|
|
103
95
|
* `headless` | `CRAWLEE_HEADLESS` | `true`
|
|
104
|
-
* `defaultDatasetId` | `CRAWLEE_DEFAULT_DATASET_ID` | `'default'`
|
|
105
|
-
* `defaultKeyValueStoreId` | `CRAWLEE_DEFAULT_KEY_VALUE_STORE_ID` | `'default'`
|
|
106
|
-
* `defaultRequestQueueId` | `CRAWLEE_DEFAULT_REQUEST_QUEUE_ID` | `'default'`
|
|
107
96
|
* `persistStateIntervalMillis` | `CRAWLEE_PERSIST_STATE_INTERVAL_MILLIS` | `60_000`
|
|
108
97
|
* `internalTimeoutMillis` | `CRAWLEE_INTERNAL_TIMEOUT` | -
|
|
109
98
|
* `purgeOnStart` | `CRAWLEE_PURGE_ON_START` | `true`
|
|
@@ -114,7 +103,6 @@ export interface Configuration extends ResolvedConfigValues {
|
|
|
114
103
|
*
|
|
115
104
|
* Key | Environment Variable | Default Value
|
|
116
105
|
* ---|---|---
|
|
117
|
-
* `inputKey` | `CRAWLEE_INPUT_KEY` | `'INPUT'`
|
|
118
106
|
* `xvfb` | `CRAWLEE_XVFB` | `false`
|
|
119
107
|
* `chromeExecutablePath` | `CRAWLEE_CHROME_EXECUTABLE_PATH` | -
|
|
120
108
|
* `defaultBrowserPath` | `CRAWLEE_DEFAULT_BROWSER_PATH` | -
|
|
@@ -141,23 +129,4 @@ export declare class Configuration {
|
|
|
141
129
|
* Delegates to the global ServiceLocator, making it the single source of truth for service management.
|
|
142
130
|
*/
|
|
143
131
|
static getGlobalConfiguration(): Configuration;
|
|
144
|
-
/**
|
|
145
|
-
* Resolves all field values once using the priority chain:
|
|
146
|
-
* constructor options > env vars > crawlee.json > schema defaults.
|
|
147
|
-
*/
|
|
148
|
-
private static resolveAll;
|
|
149
|
-
/**
|
|
150
|
-
* Registers getters (and throwing setters) on the instance for each field.
|
|
151
|
-
*/
|
|
152
|
-
private registerAccessors;
|
|
153
|
-
/**
|
|
154
|
-
* Reads the first defined env var value for a field definition.
|
|
155
|
-
* Empty strings are treated as unset, falling through to crawlee.json or schema defaults.
|
|
156
|
-
* (Crawlee v3 coerced `''` to `false`/`0`/`''` per type — v4 drops that for consistency.)
|
|
157
|
-
*/
|
|
158
|
-
private static readEnvVar;
|
|
159
|
-
/**
|
|
160
|
-
* Loads config options from crawlee.json in the current working directory.
|
|
161
|
-
*/
|
|
162
|
-
private static loadFileOptions;
|
|
163
132
|
}
|
package/configuration.js
CHANGED
|
@@ -39,14 +39,8 @@ const logLevelSchema = z.preprocess((val) => {
|
|
|
39
39
|
}, z.enum(LogLevel));
|
|
40
40
|
// --- Crawlee config field definitions ---
|
|
41
41
|
export const crawleeConfigFields = {
|
|
42
|
-
/** @default 'default' */
|
|
43
|
-
defaultDatasetId: field(z.string().default('default'), 'CRAWLEE_DEFAULT_DATASET_ID'),
|
|
44
42
|
/** @default true */
|
|
45
43
|
purgeOnStart: field(coerceBoolean.default(true), 'CRAWLEE_PURGE_ON_START'),
|
|
46
|
-
/** @default 'default' */
|
|
47
|
-
defaultKeyValueStoreId: field(z.string().default('default'), 'CRAWLEE_DEFAULT_KEY_VALUE_STORE_ID'),
|
|
48
|
-
/** @default 'default' */
|
|
49
|
-
defaultRequestQueueId: field(z.string().default('default'), 'CRAWLEE_DEFAULT_REQUEST_QUEUE_ID'),
|
|
50
44
|
/** @default 0.95 */
|
|
51
45
|
maxUsedCpuRatio: field(coerceNumber.default(0.95)),
|
|
52
46
|
/** @default 0.25 */
|
|
@@ -61,8 +55,6 @@ export const crawleeConfigFields = {
|
|
|
61
55
|
internalTimeoutMillis: field(coerceNumber.optional(), 'CRAWLEE_INTERNAL_TIMEOUT'),
|
|
62
56
|
/** @default 1_000 */
|
|
63
57
|
systemInfoIntervalMillis: field(coerceNumber.default(1_000)),
|
|
64
|
-
/** @default 'INPUT' */
|
|
65
|
-
inputKey: field(z.string().default('INPUT'), 'CRAWLEE_INPUT_KEY'),
|
|
66
58
|
/** @default true */
|
|
67
59
|
headless: field(coerceBoolean.default(true), 'CRAWLEE_HEADLESS'),
|
|
68
60
|
/** @default false */
|
|
@@ -119,9 +111,6 @@ export const crawleeConfigFields = {
|
|
|
119
111
|
* `memoryMbytes` | `CRAWLEE_MEMORY_MBYTES` | -
|
|
120
112
|
* `logLevel` | `CRAWLEE_LOG_LEVEL` | -
|
|
121
113
|
* `headless` | `CRAWLEE_HEADLESS` | `true`
|
|
122
|
-
* `defaultDatasetId` | `CRAWLEE_DEFAULT_DATASET_ID` | `'default'`
|
|
123
|
-
* `defaultKeyValueStoreId` | `CRAWLEE_DEFAULT_KEY_VALUE_STORE_ID` | `'default'`
|
|
124
|
-
* `defaultRequestQueueId` | `CRAWLEE_DEFAULT_REQUEST_QUEUE_ID` | `'default'`
|
|
125
114
|
* `persistStateIntervalMillis` | `CRAWLEE_PERSIST_STATE_INTERVAL_MILLIS` | `60_000`
|
|
126
115
|
* `internalTimeoutMillis` | `CRAWLEE_INTERNAL_TIMEOUT` | -
|
|
127
116
|
* `purgeOnStart` | `CRAWLEE_PURGE_ON_START` | `true`
|
|
@@ -132,7 +121,6 @@ export const crawleeConfigFields = {
|
|
|
132
121
|
*
|
|
133
122
|
* Key | Environment Variable | Default Value
|
|
134
123
|
* ---|---|---
|
|
135
|
-
* `inputKey` | `CRAWLEE_INPUT_KEY` | `'INPUT'`
|
|
136
124
|
* `xvfb` | `CRAWLEE_XVFB` | `false`
|
|
137
125
|
* `chromeExecutablePath` | `CRAWLEE_CHROME_EXECUTABLE_PATH` | -
|
|
138
126
|
* `defaultBrowserPath` | `CRAWLEE_DEFAULT_BROWSER_PATH` | -
|
|
@@ -155,9 +143,9 @@ export class Configuration {
|
|
|
155
143
|
*/
|
|
156
144
|
constructor(options = {}) {
|
|
157
145
|
const fields = this.constructor.fields;
|
|
158
|
-
const fileOptions = Configuration
|
|
159
|
-
this.#resolvedValues = Configuration
|
|
160
|
-
this
|
|
146
|
+
const fileOptions = Configuration.#loadFileOptions();
|
|
147
|
+
this.#resolvedValues = Configuration.#resolveAll(fields, options, fileOptions);
|
|
148
|
+
this.#registerAccessors();
|
|
161
149
|
// Set the log level
|
|
162
150
|
const logLevel = this.logLevel;
|
|
163
151
|
if (logLevel != null) {
|
|
@@ -176,7 +164,7 @@ export class Configuration {
|
|
|
176
164
|
* Resolves all field values once using the priority chain:
|
|
177
165
|
* constructor options > env vars > crawlee.json > schema defaults.
|
|
178
166
|
*/
|
|
179
|
-
static resolveAll(fields, userOptions, fileOptions) {
|
|
167
|
+
static #resolveAll(fields, userOptions, fileOptions) {
|
|
180
168
|
const values = {};
|
|
181
169
|
for (const [key, fieldDef] of Object.entries(fields)) {
|
|
182
170
|
// 1. Constructor options (highest priority)
|
|
@@ -185,7 +173,7 @@ export class Configuration {
|
|
|
185
173
|
continue;
|
|
186
174
|
}
|
|
187
175
|
// 2. Environment variables
|
|
188
|
-
const envValue = Configuration
|
|
176
|
+
const envValue = Configuration.#readEnvVar(fieldDef);
|
|
189
177
|
if (envValue != null) {
|
|
190
178
|
values[key] = fieldDef.schema.parse(envValue);
|
|
191
179
|
continue;
|
|
@@ -204,7 +192,7 @@ export class Configuration {
|
|
|
204
192
|
/**
|
|
205
193
|
* Registers getters (and throwing setters) on the instance for each field.
|
|
206
194
|
*/
|
|
207
|
-
registerAccessors() {
|
|
195
|
+
#registerAccessors() {
|
|
208
196
|
const fields = this.constructor.fields;
|
|
209
197
|
const descriptors = {};
|
|
210
198
|
for (const key of Object.keys(fields)) {
|
|
@@ -224,7 +212,7 @@ export class Configuration {
|
|
|
224
212
|
* Empty strings are treated as unset, falling through to crawlee.json or schema defaults.
|
|
225
213
|
* (Crawlee v3 coerced `''` to `false`/`0`/`''` per type — v4 drops that for consistency.)
|
|
226
214
|
*/
|
|
227
|
-
static readEnvVar(fieldDef) {
|
|
215
|
+
static #readEnvVar(fieldDef) {
|
|
228
216
|
if (!fieldDef.envVar)
|
|
229
217
|
return undefined;
|
|
230
218
|
const envVars = Array.isArray(fieldDef.envVar) ? fieldDef.envVar : [fieldDef.envVar];
|
|
@@ -238,7 +226,7 @@ export class Configuration {
|
|
|
238
226
|
/**
|
|
239
227
|
* Loads config options from crawlee.json in the current working directory.
|
|
240
228
|
*/
|
|
241
|
-
static loadFileOptions() {
|
|
229
|
+
static #loadFileOptions() {
|
|
242
230
|
try {
|
|
243
231
|
const file = readFileSync(join(process.cwd(), 'crawlee.json'));
|
|
244
232
|
return JSON.parse(file.toString());
|
package/errors.d.ts
CHANGED
|
@@ -9,11 +9,6 @@ export declare class NonRetryableError extends Error {
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class CriticalError extends NonRetryableError {
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* @ignore
|
|
14
|
-
*/
|
|
15
|
-
export declare class MissingRouteError extends CriticalError {
|
|
16
|
-
}
|
|
17
12
|
/**
|
|
18
13
|
* A schema validation issue, structurally compatible with `StandardSchemaV1.Issue`. Declared here so that
|
|
19
14
|
* error types do not have to depend on `@standard-schema/spec`.
|
|
@@ -45,34 +40,6 @@ export declare class StateValidationError extends Error {
|
|
|
45
40
|
readonly issues: readonly SchemaIssue[];
|
|
46
41
|
constructor(persistStateKey: string, issues: readonly SchemaIssue[]);
|
|
47
42
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Errors of `RetryRequestError` type will always be retried by the crawler.
|
|
50
|
-
*
|
|
51
|
-
* *This error overrides the `maxRequestRetries` option, i.e. the request can be retried indefinitely until it succeeds.*
|
|
52
|
-
*/
|
|
53
|
-
export declare class RetryRequestError extends Error {
|
|
54
|
-
constructor(message?: string);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Thrown when a domain has rate-limited us and the request should simply be attempted again later.
|
|
58
|
-
*
|
|
59
|
-
* The request is reclaimed without recording a failure: it costs neither a retry nor session reputation, because
|
|
60
|
-
* nothing about the request or the session was at fault. A {@link ThrottlingRequestManager} holds it back until
|
|
61
|
-
* the domain's backoff expires, so retries are paced rather than immediate.
|
|
62
|
-
*/
|
|
63
|
-
export declare class RequestThrottledError extends RetryRequestError {
|
|
64
|
-
constructor(message?: string);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Thrown when a domain has rate-limited us for so long that no request has got through, and the crawl is
|
|
68
|
-
* abandoned rather than kept waiting.
|
|
69
|
-
*
|
|
70
|
-
* Waiting longer will not help: at this point the concurrency is too high for the domain, or it has blocked us.
|
|
71
|
-
* The affected requests are deliberately left in their queue, so re-running the crawl without purging storages
|
|
72
|
-
* resumes them once the domain recovers.
|
|
73
|
-
*/
|
|
74
|
-
export declare class PersistentRateLimitError extends CriticalError {
|
|
75
|
-
}
|
|
76
43
|
/**
|
|
77
44
|
* Errors of `SessionError` type retire the session associated with the request and trigger a regular retry.
|
|
78
45
|
*
|
|
@@ -82,22 +49,20 @@ export declare class SessionError extends Error {
|
|
|
82
49
|
constructor(message?: string);
|
|
83
50
|
}
|
|
84
51
|
/**
|
|
85
|
-
*
|
|
52
|
+
* A {@link SessionError} for a session that finished without being blocked, e.g. by reaching its
|
|
53
|
+
* `maxUsageCount` or `maxAgeSecs`. A plain `SessionError` means the session was blocked.
|
|
86
54
|
*/
|
|
87
|
-
export declare class
|
|
88
|
-
constructor(sessionId?: string);
|
|
89
|
-
}
|
|
90
|
-
export declare class ContextPipelineInterruptedError extends Error {
|
|
91
|
-
constructor(message?: string);
|
|
92
|
-
}
|
|
93
|
-
export declare class ContextPipelineInitializationError extends Error {
|
|
94
|
-
constructor(error: unknown, options?: ErrorOptions);
|
|
95
|
-
}
|
|
96
|
-
export declare class ContextPipelineCleanupError extends CriticalError {
|
|
97
|
-
constructor(error: unknown, options?: ErrorOptions);
|
|
55
|
+
export declare class SessionRetiredError extends SessionError {
|
|
98
56
|
}
|
|
99
|
-
|
|
100
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Wraps the failure of a callback registered with {@link StorageTransaction.afterCommit|`afterCommit`}
|
|
59
|
+
* that ran after the request's writes had already been committed.
|
|
60
|
+
*
|
|
61
|
+
* Non-retryable by nature: the writes are durable, so re-running the request handler would duplicate
|
|
62
|
+
* them. A callback that throws a `NonRetryableError` of its own is left alone.
|
|
63
|
+
*/
|
|
64
|
+
export declare class AfterCommitError extends NonRetryableError {
|
|
65
|
+
constructor(cause: unknown);
|
|
101
66
|
}
|
|
102
67
|
/**
|
|
103
68
|
* Thrown when attempting to set a different service instance after one has already been retrieved.
|
|
@@ -105,9 +70,3 @@ export declare class RequestHandlerError extends Error {
|
|
|
105
70
|
export declare class ServiceConflictError extends Error {
|
|
106
71
|
constructor(serviceName: string, newValue: unknown, existingValue: unknown);
|
|
107
72
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Thrown by crawlers when `skipNavigation` is used on a request.
|
|
110
|
-
* Subclasses can catch this error to skip their own navigation-dependent logic.
|
|
111
|
-
*/
|
|
112
|
-
export declare class NavigationSkippedError extends NonRetryableError {
|
|
113
|
-
}
|
package/errors.js
CHANGED
|
@@ -10,11 +10,6 @@ export class NonRetryableError extends Error {
|
|
|
10
10
|
*/
|
|
11
11
|
export class CriticalError extends NonRetryableError {
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* @ignore
|
|
15
|
-
*/
|
|
16
|
-
export class MissingRouteError extends CriticalError {
|
|
17
|
-
}
|
|
18
13
|
function formatIssues(issues) {
|
|
19
14
|
return issues
|
|
20
15
|
.map((issue) => {
|
|
@@ -54,38 +49,6 @@ export class StateValidationError extends Error {
|
|
|
54
49
|
this.issues = issues;
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Errors of `RetryRequestError` type will always be retried by the crawler.
|
|
59
|
-
*
|
|
60
|
-
* *This error overrides the `maxRequestRetries` option, i.e. the request can be retried indefinitely until it succeeds.*
|
|
61
|
-
*/
|
|
62
|
-
export class RetryRequestError extends Error {
|
|
63
|
-
constructor(message) {
|
|
64
|
-
super(message ?? "Request is being retried at the user's request");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Thrown when a domain has rate-limited us and the request should simply be attempted again later.
|
|
69
|
-
*
|
|
70
|
-
* The request is reclaimed without recording a failure: it costs neither a retry nor session reputation, because
|
|
71
|
-
* nothing about the request or the session was at fault. A {@link ThrottlingRequestManager} holds it back until
|
|
72
|
-
* the domain's backoff expires, so retries are paced rather than immediate.
|
|
73
|
-
*/
|
|
74
|
-
export class RequestThrottledError extends RetryRequestError {
|
|
75
|
-
constructor(message) {
|
|
76
|
-
super(message ?? 'Request is being retried later because its domain is rate-limiting us');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Thrown when a domain has rate-limited us for so long that no request has got through, and the crawl is
|
|
81
|
-
* abandoned rather than kept waiting.
|
|
82
|
-
*
|
|
83
|
-
* Waiting longer will not help: at this point the concurrency is too high for the domain, or it has blocked us.
|
|
84
|
-
* The affected requests are deliberately left in their queue, so re-running the crawl without purging storages
|
|
85
|
-
* resumes them once the domain recovers.
|
|
86
|
-
*/
|
|
87
|
-
export class PersistentRateLimitError extends CriticalError {
|
|
88
|
-
}
|
|
89
52
|
/**
|
|
90
53
|
* Errors of `SessionError` type retire the session associated with the request and trigger a regular retry.
|
|
91
54
|
*
|
|
@@ -97,31 +60,21 @@ export class SessionError extends Error {
|
|
|
97
60
|
}
|
|
98
61
|
}
|
|
99
62
|
/**
|
|
100
|
-
*
|
|
63
|
+
* A {@link SessionError} for a session that finished without being blocked, e.g. by reaching its
|
|
64
|
+
* `maxUsageCount` or `maxAgeSecs`. A plain `SessionError` means the session was blocked.
|
|
101
65
|
*/
|
|
102
|
-
export class
|
|
103
|
-
constructor(sessionId) {
|
|
104
|
-
super(`The current SessionPool instance couldn't find a valid session${sessionId ? ` for the following id: ${sessionId}.` : '.'}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
export class ContextPipelineInterruptedError extends Error {
|
|
108
|
-
constructor(message) {
|
|
109
|
-
super(`Request handling was interrupted during context initialization ${message ? ` - ${message}` : ''}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
export class ContextPipelineInitializationError extends Error {
|
|
113
|
-
constructor(error, options) {
|
|
114
|
-
super(undefined, { cause: error, ...options });
|
|
115
|
-
}
|
|
66
|
+
export class SessionRetiredError extends SessionError {
|
|
116
67
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Wraps the failure of a callback registered with {@link StorageTransaction.afterCommit|`afterCommit`}
|
|
70
|
+
* that ran after the request's writes had already been committed.
|
|
71
|
+
*
|
|
72
|
+
* Non-retryable by nature: the writes are durable, so re-running the request handler would duplicate
|
|
73
|
+
* them. A callback that throws a `NonRetryableError` of its own is left alone.
|
|
74
|
+
*/
|
|
75
|
+
export class AfterCommitError extends NonRetryableError {
|
|
76
|
+
constructor(cause) {
|
|
77
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
125
78
|
}
|
|
126
79
|
}
|
|
127
80
|
/**
|
|
@@ -133,9 +86,3 @@ export class ServiceConflictError extends Error {
|
|
|
133
86
|
`Existing value: ${inspectValue(existingValue)}, attempted new value: ${inspectValue(newValue)}.`);
|
|
134
87
|
}
|
|
135
88
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Thrown by crawlers when `skipNavigation` is used on a request.
|
|
138
|
-
* Subclasses can catch this error to skip their own navigation-dependent logic.
|
|
139
|
-
*/
|
|
140
|
-
export class NavigationSkippedError extends NonRetryableError {
|
|
141
|
-
}
|
package/events/index.d.ts
CHANGED
|
@@ -29,11 +29,4 @@ export declare class LocalEventManager extends EventManager {
|
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
31
|
isContainerizedWrapper(): Promise<boolean>;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a SystemInfo object based on local metrics.
|
|
34
|
-
*/
|
|
35
|
-
private createSystemInfo;
|
|
36
|
-
private createCpuInfo;
|
|
37
|
-
private createMemoryInfo;
|
|
38
|
-
private getMemoryInfo;
|
|
39
32
|
}
|
|
@@ -44,7 +44,7 @@ export class LocalEventManager extends EventManager {
|
|
|
44
44
|
* @internal
|
|
45
45
|
*/
|
|
46
46
|
async emitSystemInfoEvent(intervalCallback) {
|
|
47
|
-
const info = await this
|
|
47
|
+
const info = await this.#createSystemInfo({
|
|
48
48
|
maxUsedCpuRatio: serviceLocator.getConfiguration().maxUsedCpuRatio,
|
|
49
49
|
});
|
|
50
50
|
this.events.emit(EventType.SYSTEM_INFO, info);
|
|
@@ -60,14 +60,14 @@ export class LocalEventManager extends EventManager {
|
|
|
60
60
|
/**
|
|
61
61
|
* Creates a SystemInfo object based on local metrics.
|
|
62
62
|
*/
|
|
63
|
-
async createSystemInfo(options) {
|
|
63
|
+
async #createSystemInfo(options) {
|
|
64
64
|
return {
|
|
65
65
|
createdAt: new Date(),
|
|
66
|
-
...(await this
|
|
67
|
-
...(await this
|
|
66
|
+
...(await this.#createCpuInfo(options)),
|
|
67
|
+
...(await this.#createMemoryInfo()),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
async createCpuInfo(options) {
|
|
70
|
+
async #createCpuInfo(options) {
|
|
71
71
|
const { getCurrentCpuTicksV2 } = await import('../system-info/cpu-info.js');
|
|
72
72
|
const usedCpuRatio = await getCurrentCpuTicksV2({
|
|
73
73
|
containerized: await this.isContainerizedWrapper(),
|
|
@@ -78,9 +78,9 @@ export class LocalEventManager extends EventManager {
|
|
|
78
78
|
isCpuOverloaded: usedCpuRatio > options.maxUsedCpuRatio,
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
async createMemoryInfo() {
|
|
81
|
+
async #createMemoryInfo() {
|
|
82
82
|
try {
|
|
83
|
-
const memInfo = await this
|
|
83
|
+
const memInfo = await this.#getMemoryInfo();
|
|
84
84
|
return {
|
|
85
85
|
memTotalBytes: memInfo.totalBytes,
|
|
86
86
|
memCurrentBytes: memInfo.mainProcessBytes + memInfo.childProcessesBytes,
|
|
@@ -91,7 +91,7 @@ export class LocalEventManager extends EventManager {
|
|
|
91
91
|
return {};
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
async getMemoryInfo() {
|
|
94
|
+
async #getMemoryInfo() {
|
|
95
95
|
const { getMemoryInfo } = await import('../system-info/memory-info.js');
|
|
96
96
|
return getMemoryInfo({
|
|
97
97
|
containerized: await this.isContainerizedWrapper(),
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the current status of the system.
|
|
3
|
+
*/
|
|
4
|
+
export interface SystemInfo {
|
|
5
|
+
/** If false, system is being overloaded. */
|
|
6
|
+
isSystemIdle: boolean;
|
|
7
|
+
memInfo: LoadSignalInfo;
|
|
8
|
+
eventLoopInfo: LoadSignalInfo;
|
|
9
|
+
cpuInfo: LoadSignalInfo;
|
|
10
|
+
storageBackendInfo: LoadSignalInfo;
|
|
11
|
+
memTotalBytes?: number;
|
|
12
|
+
memCurrentBytes?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Platform only property
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
cpuCurrentUsage?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Platform only property
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
isCpuOverloaded?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Platform only property
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
createdAt?: Date;
|
|
28
|
+
/**
|
|
29
|
+
* Status of additional load signals beyond the built-in four.
|
|
30
|
+
* Keys are `LoadSignal.name` values, values are overload info.
|
|
31
|
+
*/
|
|
32
|
+
loadSignalInfo?: Record<string, LoadSignalInfo>;
|
|
33
|
+
}
|
|
34
|
+
export interface LoadSignalInfo {
|
|
35
|
+
isOverloaded: boolean;
|
|
36
|
+
limitRatio: number;
|
|
37
|
+
actualRatio: number;
|
|
38
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
export * from './debug.js';
|
|
2
2
|
export * from './errors.js';
|
|
3
|
-
export * from './autoscaling/index.js';
|
|
4
3
|
export * from './configuration.js';
|
|
5
4
|
export * from './service_locator.js';
|
|
6
|
-
export * from './crawlers/index.js';
|
|
7
|
-
export * from './enqueue_links/index.js';
|
|
8
5
|
export * from './events/index.js';
|
|
9
6
|
export * from './log.js';
|
|
10
7
|
export * from './owned_or_injected.js';
|
|
11
8
|
export * from './proxy_configuration.js';
|
|
12
9
|
export * from './request.js';
|
|
13
|
-
export * from './router.js';
|
|
14
10
|
export * from './serialization.js';
|
|
15
|
-
export * from './session_pool/index.js';
|
|
16
11
|
export * from './storages/index.js';
|
|
17
12
|
export * from './memory-storage/index.js';
|
|
18
|
-
export
|
|
19
|
-
export * from './cookie_utils.js';
|
|
20
|
-
export * from './http.js';
|
|
13
|
+
export { ArgumentValidationError, validators } from './validators.js';
|
|
21
14
|
export * from './recoverable_state.js';
|
|
22
15
|
export type { StorageBackend } from '@crawlee/types';
|
|
16
|
+
export { EnqueueStrategy } from '@crawlee/utils';
|
package/index.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
export * from './debug.js';
|
|
2
2
|
export * from './errors.js';
|
|
3
|
-
export * from './autoscaling/index.js';
|
|
4
3
|
export * from './configuration.js';
|
|
5
4
|
export * from './service_locator.js';
|
|
6
|
-
export * from './crawlers/index.js';
|
|
7
|
-
export * from './enqueue_links/index.js';
|
|
8
5
|
export * from './events/index.js';
|
|
9
6
|
export * from './log.js';
|
|
10
7
|
export * from './owned_or_injected.js';
|
|
11
8
|
export * from './proxy_configuration.js';
|
|
12
9
|
export * from './request.js';
|
|
13
|
-
export * from './router.js';
|
|
14
10
|
export * from './serialization.js';
|
|
15
|
-
export * from './session_pool/index.js';
|
|
16
11
|
export * from './storages/index.js';
|
|
17
12
|
export * from './memory-storage/index.js';
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
export
|
|
13
|
+
// Not `export *`: the rest of the module re-exports `@crawlee/utils/internal` symbols, which carry no
|
|
14
|
+
// semver guarantees and must not reach the public surface. Internal consumers import them directly.
|
|
15
|
+
export { ArgumentValidationError, validators } from './validators.js';
|
|
21
16
|
export * from './recoverable_state.js';
|
|
17
|
+
export { EnqueueStrategy } from '@crawlee/utils';
|
package/internal.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './iterables.js';
|
|
2
|
+
export * from './storages/batched_adds.js';
|
|
3
|
+
export { joinRequestSourceStatuses } from './storages/request_loader.js';
|
|
4
|
+
export * from './system-info/cpu-info.js';
|
|
5
|
+
export * from './system-info/memory-info.js';
|
|
6
|
+
export * from './system-info/ps-tree.js';
|
|
7
|
+
export * from './system-info/runtime.js';
|
|
8
|
+
export * from './url.js';
|
package/internal.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Not part of the public API: internals that other Crawlee packages need but that carry no semver guarantees.
|
|
2
|
+
export * from './iterables.js';
|
|
3
|
+
export * from './storages/batched_adds.js';
|
|
4
|
+
export { joinRequestSourceStatuses } from './storages/request_loader.js';
|
|
5
|
+
export * from './system-info/cpu-info.js';
|
|
6
|
+
export * from './system-info/memory-info.js';
|
|
7
|
+
export * from './system-info/ps-tree.js';
|
|
8
|
+
export * from './system-info/runtime.js';
|
|
9
|
+
export * from './url.js';
|
package/log.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CrawleeLogger, CrawleeLoggerOptions } from '@crawlee/types';
|
|
1
|
+
import type { CrawleeLogger, CrawleeLoggerOptions, LogOptions } from '@crawlee/types';
|
|
2
2
|
import type { LoggerOptions } from '@apify/log';
|
|
3
3
|
import log, { Log, Logger, LoggerJson, LoggerText, LogLevel } from '@apify/log';
|
|
4
|
-
export type { CrawleeLogger, CrawleeLoggerOptions };
|
|
4
|
+
export type { CrawleeLogger, CrawleeLoggerOptions, LogOptions };
|
|
5
5
|
/**
|
|
6
6
|
* Abstract base class for custom Crawlee logger implementations.
|
|
7
7
|
*
|
|
@@ -33,8 +33,7 @@ export type { CrawleeLogger, CrawleeLoggerOptions };
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
export declare abstract class BaseCrawleeLogger implements CrawleeLogger {
|
|
36
|
-
private
|
|
37
|
-
private readonly warningsLogged;
|
|
36
|
+
#private;
|
|
38
37
|
constructor(options?: Partial<CrawleeLoggerOptions>);
|
|
39
38
|
/**
|
|
40
39
|
* Core logging method. Subclasses must implement this to dispatch log messages
|
|
@@ -56,14 +55,14 @@ export declare abstract class BaseCrawleeLogger implements CrawleeLogger {
|
|
|
56
55
|
getOptions(): CrawleeLoggerOptions;
|
|
57
56
|
setOptions(options: Partial<CrawleeLoggerOptions>): void;
|
|
58
57
|
child(options: Partial<CrawleeLoggerOptions>): CrawleeLogger;
|
|
59
|
-
error(message: string, data?: Record<string, unknown
|
|
58
|
+
error(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
60
59
|
exception(exception: Error, message: string, data?: Record<string, unknown>): void;
|
|
61
|
-
softFail(message: string, data?: Record<string, unknown
|
|
62
|
-
warning(message: string, data?: Record<string, unknown
|
|
60
|
+
softFail(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
61
|
+
warning(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
63
62
|
warningOnce(message: string): void;
|
|
64
|
-
info(message: string, data?: Record<string, unknown
|
|
65
|
-
debug(message: string, data?: Record<string, unknown
|
|
66
|
-
perf(message: string, data?: Record<string, unknown
|
|
63
|
+
info(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
64
|
+
debug(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
65
|
+
perf(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
67
66
|
deprecated(message: string): void;
|
|
68
67
|
}
|
|
69
68
|
/**
|
|
@@ -73,7 +72,7 @@ export declare abstract class BaseCrawleeLogger implements CrawleeLogger {
|
|
|
73
72
|
* Users who want to use a different logging library should implement {@link BaseCrawleeLogger} directly.
|
|
74
73
|
*/
|
|
75
74
|
export declare class ApifyLogAdapter extends BaseCrawleeLogger {
|
|
76
|
-
private
|
|
75
|
+
#private;
|
|
77
76
|
constructor(apifyLog: Log, options?: Partial<CrawleeLoggerOptions>);
|
|
78
77
|
logWithLevel(level: number, message: string, data?: Record<string, unknown>): void;
|
|
79
78
|
protected createChild(options: Partial<CrawleeLoggerOptions>): CrawleeLogger;
|