@crawlee/core 4.0.0-beta.1 → 4.0.0-beta.100

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.
Files changed (269) hide show
  1. package/README.md +17 -13
  2. package/autoscaling/autoscaled_pool.d.ts +69 -156
  3. package/autoscaling/autoscaled_pool.js +97 -252
  4. package/autoscaling/client_load_signal.d.ts +59 -0
  5. package/autoscaling/client_load_signal.js +73 -0
  6. package/autoscaling/concurrency_system.d.ts +283 -0
  7. package/autoscaling/concurrency_system.js +350 -0
  8. package/autoscaling/cpu_load_signal.d.ts +44 -0
  9. package/autoscaling/cpu_load_signal.js +46 -0
  10. package/autoscaling/event_loop_load_signal.d.ts +54 -0
  11. package/autoscaling/event_loop_load_signal.js +60 -0
  12. package/autoscaling/index.d.ts +6 -1
  13. package/autoscaling/index.js +6 -1
  14. package/autoscaling/load_signal.d.ts +99 -0
  15. package/autoscaling/load_signal.js +103 -0
  16. package/autoscaling/memory_load_signal.d.ts +56 -0
  17. package/autoscaling/memory_load_signal.js +106 -0
  18. package/autoscaling/snapshotter.d.ts +61 -163
  19. package/autoscaling/snapshotter.js +45 -270
  20. package/autoscaling/system_status.d.ts +63 -83
  21. package/autoscaling/system_status.js +90 -120
  22. package/autoscaling/weighted_avg.d.ts +5 -0
  23. package/autoscaling/weighted_avg.js +14 -0
  24. package/byte_utils.d.ts +17 -0
  25. package/byte_utils.js +42 -0
  26. package/configuration.d.ts +96 -230
  27. package/configuration.js +170 -226
  28. package/cookie_utils.d.ts +4 -3
  29. package/cookie_utils.js +22 -13
  30. package/crawlers/context_pipeline.d.ts +70 -0
  31. package/crawlers/context_pipeline.js +122 -0
  32. package/crawlers/crawler_commons.d.ts +96 -40
  33. package/crawlers/crawler_commons.js +15 -24
  34. package/crawlers/error_snapshotter.d.ts +3 -3
  35. package/crawlers/error_snapshotter.js +2 -3
  36. package/crawlers/error_tracker.d.ts +2 -2
  37. package/crawlers/error_tracker.js +0 -1
  38. package/crawlers/index.d.ts +1 -3
  39. package/crawlers/index.js +1 -3
  40. package/crawlers/internals/types.d.ts +7 -0
  41. package/crawlers/internals/types.js +1 -0
  42. package/crawlers/statistics.d.ts +28 -23
  43. package/crawlers/statistics.js +38 -34
  44. package/debug.d.ts +36 -0
  45. package/debug.js +70 -0
  46. package/enqueue_links/enqueue_links.d.ts +59 -68
  47. package/enqueue_links/enqueue_links.js +57 -62
  48. package/enqueue_links/index.d.ts +0 -1
  49. package/enqueue_links/index.js +0 -1
  50. package/enqueue_links/shared.d.ts +39 -26
  51. package/enqueue_links/shared.js +89 -67
  52. package/errors.d.ts +53 -4
  53. package/errors.js +70 -5
  54. package/events/event_manager.d.ts +34 -8
  55. package/events/event_manager.js +8 -10
  56. package/events/index.d.ts +0 -1
  57. package/events/index.js +0 -1
  58. package/events/local_event_manager.d.ts +15 -5
  59. package/events/local_event_manager.js +37 -40
  60. package/index.d.ts +6 -4
  61. package/index.js +5 -3
  62. package/iterables.d.ts +79 -0
  63. package/iterables.js +134 -0
  64. package/log.d.ts +82 -3
  65. package/log.js +102 -1
  66. package/memory-storage/consts.d.ts +4 -0
  67. package/memory-storage/consts.js +4 -0
  68. package/memory-storage/index.d.ts +1 -0
  69. package/memory-storage/index.js +1 -0
  70. package/memory-storage/memory-storage.d.ts +46 -0
  71. package/memory-storage/memory-storage.js +136 -0
  72. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  73. package/memory-storage/resource-clients/common/base-client.js +6 -0
  74. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  75. package/memory-storage/resource-clients/dataset.js +113 -0
  76. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  77. package/memory-storage/resource-clients/key-value-store.js +203 -0
  78. package/memory-storage/resource-clients/request-queue.d.ts +96 -0
  79. package/memory-storage/resource-clients/request-queue.js +421 -0
  80. package/memory-storage/utils.d.ts +16 -0
  81. package/memory-storage/utils.js +41 -0
  82. package/owned_or_injected.d.ts +60 -0
  83. package/owned_or_injected.js +98 -0
  84. package/package.json +13 -12
  85. package/proxy_configuration.d.ts +29 -152
  86. package/proxy_configuration.js +21 -173
  87. package/recoverable_state.d.ts +120 -0
  88. package/recoverable_state.js +143 -0
  89. package/request.d.ts +85 -17
  90. package/request.js +107 -36
  91. package/router.d.ts +194 -19
  92. package/router.js +177 -32
  93. package/serialization.d.ts +0 -1
  94. package/serialization.js +1 -2
  95. package/service_locator.d.ts +156 -0
  96. package/service_locator.js +244 -0
  97. package/session_pool/consts.d.ts +1 -2
  98. package/session_pool/consts.js +1 -2
  99. package/session_pool/errors.d.ts +0 -1
  100. package/session_pool/errors.js +0 -1
  101. package/session_pool/fingerprint.d.ts +9 -0
  102. package/session_pool/fingerprint.js +30 -0
  103. package/session_pool/index.d.ts +0 -2
  104. package/session_pool/index.js +0 -2
  105. package/session_pool/session.d.ts +37 -75
  106. package/session_pool/session.js +49 -102
  107. package/session_pool/session_pool.d.ts +85 -90
  108. package/session_pool/session_pool.js +131 -120
  109. package/storages/access_checking.d.ts +1 -2
  110. package/storages/access_checking.js +5 -2
  111. package/storages/dataset.d.ts +103 -54
  112. package/storages/dataset.js +174 -132
  113. package/storages/index.d.ts +8 -7
  114. package/storages/index.js +6 -7
  115. package/storages/key_value_store.d.ts +167 -39
  116. package/storages/key_value_store.js +274 -127
  117. package/storages/key_value_store_codec.d.ts +32 -0
  118. package/storages/key_value_store_codec.js +113 -0
  119. package/storages/request_dedup_cache.d.ts +23 -0
  120. package/storages/request_dedup_cache.js +48 -0
  121. package/storages/request_list.d.ts +54 -98
  122. package/storages/request_list.js +99 -75
  123. package/storages/request_loader.d.ts +96 -0
  124. package/storages/request_loader.js +1 -0
  125. package/storages/request_manager.d.ts +33 -0
  126. package/storages/request_manager.js +1 -0
  127. package/storages/request_manager_tandem.d.ts +106 -0
  128. package/storages/request_manager_tandem.js +197 -0
  129. package/storages/request_queue.d.ts +287 -47
  130. package/storages/request_queue.js +620 -215
  131. package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +38 -46
  132. package/storages/{sitemap_request_list.js → sitemap_request_loader.js} +58 -65
  133. package/storages/storage_instance_manager.d.ts +88 -0
  134. package/storages/storage_instance_manager.js +256 -0
  135. package/storages/storage_stats.d.ts +48 -0
  136. package/storages/storage_stats.js +29 -0
  137. package/storages/utils.d.ts +54 -9
  138. package/storages/utils.js +64 -13
  139. package/system-info/cpu-info.d.ts +67 -0
  140. package/system-info/cpu-info.js +216 -0
  141. package/system-info/memory-info.d.ts +31 -0
  142. package/system-info/memory-info.js +115 -0
  143. package/system-info/ps-tree.d.ts +17 -0
  144. package/system-info/ps-tree.js +144 -0
  145. package/system-info/runtime.d.ts +14 -0
  146. package/system-info/runtime.js +80 -0
  147. package/typedefs.d.ts +0 -6
  148. package/typedefs.js +0 -1
  149. package/validators.d.ts +8 -1
  150. package/validators.js +10 -3
  151. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  152. package/autoscaling/autoscaled_pool.js.map +0 -1
  153. package/autoscaling/index.d.ts.map +0 -1
  154. package/autoscaling/index.js.map +0 -1
  155. package/autoscaling/snapshotter.d.ts.map +0 -1
  156. package/autoscaling/snapshotter.js.map +0 -1
  157. package/autoscaling/system_status.d.ts.map +0 -1
  158. package/autoscaling/system_status.js.map +0 -1
  159. package/configuration.d.ts.map +0 -1
  160. package/configuration.js.map +0 -1
  161. package/cookie_utils.d.ts.map +0 -1
  162. package/cookie_utils.js.map +0 -1
  163. package/crawlers/crawler_commons.d.ts.map +0 -1
  164. package/crawlers/crawler_commons.js.map +0 -1
  165. package/crawlers/crawler_extension.d.ts +0 -12
  166. package/crawlers/crawler_extension.d.ts.map +0 -1
  167. package/crawlers/crawler_extension.js +0 -14
  168. package/crawlers/crawler_extension.js.map +0 -1
  169. package/crawlers/crawler_utils.d.ts +0 -10
  170. package/crawlers/crawler_utils.d.ts.map +0 -1
  171. package/crawlers/crawler_utils.js +0 -12
  172. package/crawlers/crawler_utils.js.map +0 -1
  173. package/crawlers/error_snapshotter.d.ts.map +0 -1
  174. package/crawlers/error_snapshotter.js.map +0 -1
  175. package/crawlers/error_tracker.d.ts.map +0 -1
  176. package/crawlers/error_tracker.js.map +0 -1
  177. package/crawlers/index.d.ts.map +0 -1
  178. package/crawlers/index.js.map +0 -1
  179. package/crawlers/statistics.d.ts.map +0 -1
  180. package/crawlers/statistics.js.map +0 -1
  181. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  182. package/enqueue_links/enqueue_links.js.map +0 -1
  183. package/enqueue_links/index.d.ts.map +0 -1
  184. package/enqueue_links/index.js.map +0 -1
  185. package/enqueue_links/shared.d.ts.map +0 -1
  186. package/enqueue_links/shared.js.map +0 -1
  187. package/errors.d.ts.map +0 -1
  188. package/errors.js.map +0 -1
  189. package/events/event_manager.d.ts.map +0 -1
  190. package/events/event_manager.js.map +0 -1
  191. package/events/index.d.ts.map +0 -1
  192. package/events/index.js.map +0 -1
  193. package/events/local_event_manager.d.ts.map +0 -1
  194. package/events/local_event_manager.js.map +0 -1
  195. package/http_clients/base-http-client.d.ts +0 -134
  196. package/http_clients/base-http-client.d.ts.map +0 -1
  197. package/http_clients/base-http-client.js +0 -33
  198. package/http_clients/base-http-client.js.map +0 -1
  199. package/http_clients/form-data-like.d.ts +0 -67
  200. package/http_clients/form-data-like.d.ts.map +0 -1
  201. package/http_clients/form-data-like.js +0 -5
  202. package/http_clients/form-data-like.js.map +0 -1
  203. package/http_clients/got-scraping-http-client.d.ts +0 -15
  204. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  205. package/http_clients/got-scraping-http-client.js +0 -69
  206. package/http_clients/got-scraping-http-client.js.map +0 -1
  207. package/http_clients/index.d.ts +0 -3
  208. package/http_clients/index.d.ts.map +0 -1
  209. package/http_clients/index.js +0 -3
  210. package/http_clients/index.js.map +0 -1
  211. package/index.d.ts.map +0 -1
  212. package/index.js.map +0 -1
  213. package/log.d.ts.map +0 -1
  214. package/log.js.map +0 -1
  215. package/proxy_configuration.d.ts.map +0 -1
  216. package/proxy_configuration.js.map +0 -1
  217. package/request.d.ts.map +0 -1
  218. package/request.js.map +0 -1
  219. package/router.d.ts.map +0 -1
  220. package/router.js.map +0 -1
  221. package/serialization.d.ts.map +0 -1
  222. package/serialization.js.map +0 -1
  223. package/session_pool/consts.d.ts.map +0 -1
  224. package/session_pool/consts.js.map +0 -1
  225. package/session_pool/errors.d.ts.map +0 -1
  226. package/session_pool/errors.js.map +0 -1
  227. package/session_pool/events.d.ts +0 -3
  228. package/session_pool/events.d.ts.map +0 -1
  229. package/session_pool/events.js +0 -3
  230. package/session_pool/events.js.map +0 -1
  231. package/session_pool/index.d.ts.map +0 -1
  232. package/session_pool/index.js.map +0 -1
  233. package/session_pool/session.d.ts.map +0 -1
  234. package/session_pool/session.js.map +0 -1
  235. package/session_pool/session_pool.d.ts.map +0 -1
  236. package/session_pool/session_pool.js.map +0 -1
  237. package/storages/access_checking.d.ts.map +0 -1
  238. package/storages/access_checking.js.map +0 -1
  239. package/storages/dataset.d.ts.map +0 -1
  240. package/storages/dataset.js.map +0 -1
  241. package/storages/index.d.ts.map +0 -1
  242. package/storages/index.js.map +0 -1
  243. package/storages/key_value_store.d.ts.map +0 -1
  244. package/storages/key_value_store.js.map +0 -1
  245. package/storages/request_list.d.ts.map +0 -1
  246. package/storages/request_list.js.map +0 -1
  247. package/storages/request_provider.d.ts +0 -307
  248. package/storages/request_provider.d.ts.map +0 -1
  249. package/storages/request_provider.js +0 -555
  250. package/storages/request_provider.js.map +0 -1
  251. package/storages/request_queue.d.ts.map +0 -1
  252. package/storages/request_queue.js.map +0 -1
  253. package/storages/request_queue_v2.d.ts +0 -87
  254. package/storages/request_queue_v2.d.ts.map +0 -1
  255. package/storages/request_queue_v2.js +0 -438
  256. package/storages/request_queue_v2.js.map +0 -1
  257. package/storages/sitemap_request_list.d.ts.map +0 -1
  258. package/storages/sitemap_request_list.js.map +0 -1
  259. package/storages/storage_manager.d.ts +0 -58
  260. package/storages/storage_manager.d.ts.map +0 -1
  261. package/storages/storage_manager.js +0 -105
  262. package/storages/storage_manager.js.map +0 -1
  263. package/storages/utils.d.ts.map +0 -1
  264. package/storages/utils.js.map +0 -1
  265. package/tsconfig.build.tsbuildinfo +0 -1
  266. package/typedefs.d.ts.map +0 -1
  267. package/typedefs.js.map +0 -1
  268. package/validators.d.ts.map +0 -1
  269. package/validators.js.map +0 -1
@@ -1,157 +1,68 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- import type { MemoryStorageOptions } from '@crawlee/memory-storage';
3
- import { MemoryStorage } from '@crawlee/memory-storage';
4
- import type { Dictionary, StorageClient } from '@crawlee/types';
5
- import { LogLevel } from '@apify/log';
6
- import { type EventManager } from './events/event_manager.js';
7
- import type { StorageManager } from './storages/storage_manager.js';
8
- import { type Constructor } from './typedefs.js';
9
- export interface ConfigurationOptions {
10
- /**
11
- * Defines storage client to be used.
12
- * @default {@link MemoryStorage}
13
- */
14
- storageClient?: StorageClient;
15
- /**
16
- * Defines the Event Manager to be used.
17
- * @default {@link EventManager}
18
- */
19
- eventManager?: EventManager;
20
- /**
21
- * Could be used to adjust the storage client behavior
22
- * e.g. {@link MemoryStorageOptions} could be used to adjust the {@link MemoryStorage} behavior.
23
- */
24
- storageClientOptions?: Dictionary;
25
- /**
26
- * Default dataset id.
27
- *
28
- * Alternative to `CRAWLEE_DEFAULT_DATASET_ID` environment variable.
29
- * @default 'default'
30
- */
31
- defaultDatasetId?: string;
32
- /**
33
- * Defines whether to purge the default storage folders before starting the crawler run.
34
- *
35
- * Alternative to `CRAWLEE_PURGE_ON_START` environment variable.
36
- * @default true
37
- */
38
- purgeOnStart?: boolean;
39
- /**
40
- * Default key-value store id.
41
- *
42
- * Alternative to `CRAWLEE_DEFAULT_KEY_VALUE_STORE_ID` environment variable.
43
- * @default 'default'
44
- */
45
- defaultKeyValueStoreId?: string;
46
- /**
47
- * Default request queue id.
48
- *
49
- * Alternative to `CRAWLEE_DEFAULT_REQUEST_QUEUE_ID` environment variable.
50
- * @default 'default'
51
- */
52
- defaultRequestQueueId?: string;
53
- /**
54
- * Sets the ratio, defining the maximum CPU usage.
55
- * When the CPU usage is higher than the provided ratio, the CPU is considered overloaded.
56
- * @default 0.95
57
- */
58
- maxUsedCpuRatio?: number;
59
- /**
60
- * Sets the ratio, defining the amount of system memory that could be used by the {@link AutoscaledPool}.
61
- * When the memory usage is more than the provided ratio, the memory is considered overloaded.
62
- *
63
- * Alternative to `CRAWLEE_AVAILABLE_MEMORY_RATIO` environment variable.
64
- * @default 0.25
65
- */
66
- availableMemoryRatio?: number;
67
- /**
68
- * Sets the amount of system memory in megabytes to be used by the {@link AutoscaledPool}.
69
- * By default, the maximum memory is set to one quarter of total system memory.
70
- *
71
- * Alternative to `CRAWLEE_MEMORY_MBYTES` environment variable.
72
- */
73
- memoryMbytes?: number;
74
- /**
75
- * Defines the interval of emitting the `persistState` event.
76
- *
77
- * Alternative to `CRAWLEE_PERSIST_STATE_INTERVAL_MILLIS` environment variable.
78
- * @default 60_000
79
- */
80
- persistStateIntervalMillis?: number;
81
- /**
82
- Defines the interval of emitting the `systemInfo` event.
83
- @default 1_000
84
- */
85
- systemInfoIntervalMillis?: number;
86
- /**
87
- * Defines the default input key, i.e. the key that is used to get the crawler input value
88
- * from the default {@link KeyValueStore} associated with the current crawler run.
89
- *
90
- * Alternative to `CRAWLEE_INPUT_KEY` environment variable.
91
- * @default 'INPUT'
92
- */
93
- inputKey?: string;
94
- /**
95
- * Defines whether web browsers launched by Crawlee will run in the headless mode.
96
- *
97
- * Alternative to `CRAWLEE_HEADLESS` environment variable.
98
- * @default true
99
- */
100
- headless?: boolean;
101
- /**
102
- * Defines whether to run X virtual framebuffer on the web browsers launched by Crawlee.
103
- *
104
- * Alternative to `CRAWLEE_XVFB` environment variable.
105
- * @default false
106
- */
107
- xvfb?: boolean;
108
- /**
109
- * Defines a path to Chrome executable.
110
- *
111
- * Alternative to `CRAWLEE_CHROME_EXECUTABLE_PATH` environment variable.
112
- */
113
- chromeExecutablePath?: string;
114
- /**
115
- * Defines a path to default browser executable.
116
- *
117
- * Alternative to `CRAWLEE_DEFAULT_BROWSER_PATH` environment variable.
118
- */
119
- defaultBrowserPath?: string;
120
- /**
121
- * Defines whether to disable browser sandbox by adding `--no-sandbox` flag to `launchOptions`.
122
- *
123
- * Alternative to `CRAWLEE_DISABLE_BROWSER_SANDBOX` environment variable.
124
- */
125
- disableBrowserSandbox?: boolean;
126
- /**
127
- * Sets the log level to the given value.
128
- *
129
- * Alternative to `CRAWLEE_LOG_LEVEL` environment variable.
130
- * @default 'INFO'
131
- */
132
- logLevel?: LogLevel | LogLevel[keyof LogLevel];
133
- /**
134
- * Defines whether the storage client used should persist the data it stores.
135
- *
136
- * Alternative to `CRAWLEE_PERSIST_STORAGE` environment variable.
137
- */
138
- persistStorage?: boolean;
139
- /**
140
- * Defines whether to use the systemInfoV2 metric collection experiment.
141
- *
142
- * Alternative to `CRAWLEE_SYSTEM_INFO_V2` environment variable.
143
- */
144
- systemInfoV2?: boolean;
145
- /**
146
- * Used in place of `isContainerized()` when collecting system metrics.
147
- *
148
- * Alternative to `CRAWLEE_CONTAINERIZED` environment variable.
149
- */
150
- containerized?: boolean;
1
+ import { z } from 'zod';
2
+ import { LogLevel } from './log.js';
3
+ export interface ConfigField<T extends z.ZodType = z.ZodType> {
4
+ schema: T;
5
+ envVar?: string | string[];
6
+ }
7
+ export declare function field<T extends z.ZodType>(schema: T, envVar?: string | string[]): ConfigField<T>;
8
+ /** Zod preprocessor treating `'0'` and `'false'` as falsy. */
9
+ export declare const coerceBoolean: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>;
10
+ export declare const coerceNumber: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>;
11
+ export declare const crawleeConfigFields: {
12
+ /** @default 'default' */
13
+ defaultDatasetId: ConfigField<z.ZodDefault<z.ZodString>>;
14
+ /** @default true */
15
+ purgeOnStart: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
16
+ /** @default 'default' */
17
+ defaultKeyValueStoreId: ConfigField<z.ZodDefault<z.ZodString>>;
18
+ /** @default 'default' */
19
+ defaultRequestQueueId: ConfigField<z.ZodDefault<z.ZodString>>;
20
+ /** @default 0.95 */
21
+ maxUsedCpuRatio: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>>>;
22
+ /** @default 0.25 */
23
+ availableMemoryRatio: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>>>;
24
+ memoryMbytes: ConfigField<z.ZodOptional<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>>>;
25
+ /** @default 60_000 */
26
+ persistStateIntervalMillis: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>>>;
27
+ /**
28
+ * Internal safety-net timeout for a single request, in milliseconds. When unset the crawler derives it from
29
+ * the request handler timeout (twice it, and never below 5 minutes).
30
+ */
31
+ internalTimeoutMillis: ConfigField<z.ZodOptional<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>>>;
32
+ /** @default 1_000 */
33
+ systemInfoIntervalMillis: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>>>;
34
+ /** @default 'INPUT' */
35
+ inputKey: ConfigField<z.ZodDefault<z.ZodString>>;
36
+ /** @default true */
37
+ headless: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
38
+ /** @default false */
39
+ xvfb: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
40
+ chromeExecutablePath: ConfigField<z.ZodOptional<z.ZodString>>;
41
+ defaultBrowserPath: ConfigField<z.ZodOptional<z.ZodString>>;
42
+ /** @default false */
43
+ disableBrowserSandbox: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
44
+ logLevel: ConfigField<z.ZodOptional<z.ZodPipe<z.ZodTransform<{} | null | undefined, unknown>, z.ZodEnum<typeof LogLevel>>>>;
45
+ /** @default true */
46
+ persistStorage: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
47
+ /** @default './storage' */
48
+ storageDir: ConfigField<z.ZodDefault<z.ZodString>>;
49
+ containerized: ConfigField<z.ZodOptional<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
50
+ };
51
+ export type FieldsInput<F extends Record<string, ConfigField>> = {
52
+ [K in keyof F]?: z.output<F[K]['schema']>;
53
+ };
54
+ export type FieldsOutput<F extends Record<string, ConfigField>> = {
55
+ [K in keyof F]: z.output<F[K]['schema']>;
56
+ };
57
+ export type ConfigurationInput = FieldsInput<typeof crawleeConfigFields>;
58
+ export type ResolvedConfigValues = FieldsOutput<typeof crawleeConfigFields>;
59
+ /** @deprecated Use {@link ConfigurationInput} instead. */
60
+ export type ConfigurationOptions = ConfigurationInput;
61
+ export interface Configuration extends ResolvedConfigValues {
151
62
  }
152
63
  /**
153
64
  * `Configuration` is a value object holding Crawlee configuration. By default, there is a
154
- * global singleton instance of this class available via `Configuration.getGlobalConfig()`.
65
+ * global singleton instance of this class available via `Configuration.getGlobalConfiguration()`.
155
66
  * Places that depend on a configurable behaviour depend on this class, as they have the global
156
67
  * instance as the default value.
157
68
  *
@@ -160,14 +71,10 @@ export interface ConfigurationOptions {
160
71
  * import { BasicCrawler, Configuration } from 'crawlee';
161
72
  *
162
73
  * // Get the global configuration
163
- * const config = Configuration.getGlobalConfig();
164
- * // Set the 'persistStateIntervalMillis' option
165
- * // of global configuration to 10 seconds
166
- * config.set('persistStateIntervalMillis', 10_000);
167
- *
168
- * // No need to pass the configuration to the crawler,
169
- * // as it's using the global configuration by default
170
- * const crawler = new BasicCrawler();
74
+ * const config = Configuration.getGlobalConfiguration();
75
+ * // Access configuration values directly as properties
76
+ * console.log(config.headless);
77
+ * console.log(config.persistStateIntervalMillis);
171
78
  * ```
172
79
  *
173
80
  * *Using custom configuration:*
@@ -177,15 +84,14 @@ export interface ConfigurationOptions {
177
84
  * // Create a new configuration
178
85
  * const config = new Configuration({ persistStateIntervalMillis: 30_000 });
179
86
  * // Pass the configuration to the crawler
180
- * const crawler = new BasicCrawler({ ... }, config);
87
+ * const crawler = new BasicCrawler({ configuration: config });
181
88
  * ```
182
89
  *
183
- * The configuration provided via environment variables always takes precedence. We can also
184
- * define the `crawlee.json` file in the project root directory which will serve as a baseline,
185
- * so the options provided in constructor will override those. In other words, the precedence is:
90
+ * Configuration is immutable — values are set via the constructor and cannot be changed afterwards.
91
+ * The priority order for resolving values is (highest to lowest):
186
92
  *
187
93
  * ```text
188
- * crawlee.json < constructor options < environment variables
94
+ * constructor options > environment variables > crawlee.json > schema defaults
189
95
  * ```
190
96
  *
191
97
  * ## Supported Configuration Options
@@ -199,99 +105,59 @@ export interface ConfigurationOptions {
199
105
  * `defaultKeyValueStoreId` | `CRAWLEE_DEFAULT_KEY_VALUE_STORE_ID` | `'default'`
200
106
  * `defaultRequestQueueId` | `CRAWLEE_DEFAULT_REQUEST_QUEUE_ID` | `'default'`
201
107
  * `persistStateIntervalMillis` | `CRAWLEE_PERSIST_STATE_INTERVAL_MILLIS` | `60_000`
108
+ * `internalTimeoutMillis` | `CRAWLEE_INTERNAL_TIMEOUT` | -
202
109
  * `purgeOnStart` | `CRAWLEE_PURGE_ON_START` | `true`
203
110
  * `persistStorage` | `CRAWLEE_PERSIST_STORAGE` | `true`
111
+ * `storageDir` | `CRAWLEE_STORAGE_DIR` | `'./storage'`
204
112
  *
205
113
  * ## Advanced Configuration Options
206
114
  *
207
115
  * Key | Environment Variable | Default Value
208
116
  * ---|---|---
209
117
  * `inputKey` | `CRAWLEE_INPUT_KEY` | `'INPUT'`
210
- * `xvfb` | `CRAWLEE_XVFB` | -
118
+ * `xvfb` | `CRAWLEE_XVFB` | `false`
211
119
  * `chromeExecutablePath` | `CRAWLEE_CHROME_EXECUTABLE_PATH` | -
212
120
  * `defaultBrowserPath` | `CRAWLEE_DEFAULT_BROWSER_PATH` | -
213
121
  * `disableBrowserSandbox` | `CRAWLEE_DISABLE_BROWSER_SANDBOX` | -
214
122
  * `availableMemoryRatio` | `CRAWLEE_AVAILABLE_MEMORY_RATIO` | `0.25`
215
- * `systemInfoV2` | `CRAWLEE_SYSTEM_INFO_V2` | false
216
- * `containerized | `CRAWLEE_CONTAINERIZED | -
123
+ * `containerized` | `CRAWLEE_CONTAINERIZED` | -
217
124
  */
218
125
  export declare class Configuration {
219
126
  /**
220
- * Maps environment variables to config keys (e.g. `CRAWLEE_MEMORY_MBYTES` to `memoryMbytes`)
221
- */
222
- protected static ENV_MAP: Dictionary;
223
- protected static BOOLEAN_VARS: string[];
224
- protected static INTEGER_VARS: string[];
225
- protected static COMMA_SEPARATED_LIST_VARS: string[];
226
- protected static DEFAULTS: Dictionary;
227
- /**
228
- * Provides access to the current-instance-scoped Configuration without passing it around in parameters.
229
- * @internal
230
- */
231
- static storage: AsyncLocalStorage<Configuration>;
232
- protected options: Map<keyof ConfigurationOptions, ConfigurationOptions[keyof ConfigurationOptions]>;
233
- protected services: Map<string, unknown>;
234
- /** @internal */
235
- static globalConfig?: Configuration;
236
- // @ts-ignore optional peer dependency or compatibility with es2022
237
- readonly storageManagers: Map<Constructor, StorageManager<import("./storages/storage_manager.js").IStorage>>;
238
- /**
239
- * Creates new `Configuration` instance with provided options. Env vars will have precedence over those.
240
- */
241
- constructor(options?: ConfigurationOptions);
242
- /**
243
- * Returns configured value. First checks the environment variables, then provided configuration,
244
- * fallbacks to the `defaultValue` argument if provided, otherwise uses the default value as described
245
- * in the above section.
246
- */
247
- get<T extends keyof ConfigurationOptions, U extends ConfigurationOptions[T]>(key: T, defaultValue?: U): U;
248
- protected _castEnvValue(key: keyof ConfigurationOptions, value: number | string | boolean): string | number | boolean | string[];
249
- /**
250
- * Sets value for given option. Only affects this `Configuration` instance, the value will not be propagated down to the env var.
251
- * To reset a value, we can omit the `value` argument or pass `undefined` there.
127
+ * Field definitions for this configuration class.
128
+ * Subclasses override this to register additional fields.
252
129
  */
253
- set(key: keyof ConfigurationOptions, value?: any): void;
130
+ protected static fields: Record<string, ConfigField>;
131
+ private resolvedValues;
254
132
  /**
255
- * Sets value for given option. Only affects the global `Configuration` instance, the value will not be propagated down to the env var.
256
- * To reset a value, we can omit the `value` argument or pass `undefined` there.
133
+ * Creates new `Configuration` instance with provided options.
134
+ * Constructor options take precedence over environment variables, which take precedence
135
+ * over crawlee.json values, which take precedence over schema defaults.
257
136
  */
258
- static set(key: keyof ConfigurationOptions, value?: any): void;
137
+ constructor(options?: ConfigurationInput);
259
138
  /**
260
- * Returns cached instance of {@link StorageClient} using options as defined in the environment variables or in
261
- * this {@link Configuration} instance. Only first call of this method will create the client, following calls will
262
- * return the same client instance.
139
+ * Returns the global configuration instance. It will respect the environment variables.
263
140
  *
264
- * Caching works based on the `storageClientOptions`, so calling this method with different options will return
265
- * multiple instances, one for each variant of the options.
266
- * @internal
267
- */
268
- getStorageClient(): StorageClient;
269
- getEventManager(): EventManager;
270
- /**
271
- * Creates an instance of MemoryStorage using options as defined in the environment variables or in this `Configuration` instance.
272
- * @internal
141
+ * Delegates to the global ServiceLocator, making it the single source of truth for service management.
273
142
  */
274
- createMemoryStorage(options?: MemoryStorageOptions): MemoryStorage;
275
- useStorageClient(client: StorageClient): void;
276
- static useStorageClient(client: StorageClient): void;
277
- useEventManager(events: EventManager): void;
143
+ static getGlobalConfiguration(): Configuration;
278
144
  /**
279
- * Returns the global configuration instance. It will respect the environment variables.
145
+ * Resolves all field values once using the priority chain:
146
+ * constructor options > env vars > crawlee.json > schema defaults.
280
147
  */
281
- static getGlobalConfig(): Configuration;
148
+ private static resolveAll;
282
149
  /**
283
- * Gets default {@link StorageClient} instance.
150
+ * Registers getters (and throwing setters) on the instance for each field.
284
151
  */
285
- static getStorageClient(): StorageClient;
152
+ private registerAccessors;
286
153
  /**
287
- * Gets default {@link EventManager} instance.
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.)
288
157
  */
289
- static getEventManager(): EventManager;
158
+ private static readEnvVar;
290
159
  /**
291
- * Resets global configuration instance. The default instance holds configuration based on env vars,
292
- * if we want to change them, we need to first reset the global state. Used mainly for testing purposes.
160
+ * Loads config options from crawlee.json in the current working directory.
293
161
  */
294
- static resetGlobalState(): void;
295
- protected buildOptions(options: ConfigurationOptions): void;
162
+ private static loadFileOptions;
296
163
  }
297
- //# sourceMappingURL=configuration.d.ts.map