@crawlee/core 4.0.0-beta.5 → 4.0.0-beta.50

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 (177) hide show
  1. package/README.md +9 -5
  2. package/autoscaling/autoscaled_pool.d.ts +3 -5
  3. package/autoscaling/autoscaled_pool.d.ts.map +1 -1
  4. package/autoscaling/autoscaled_pool.js +3 -9
  5. package/autoscaling/autoscaled_pool.js.map +1 -1
  6. package/autoscaling/snapshotter.d.ts +3 -13
  7. package/autoscaling/snapshotter.d.ts.map +1 -1
  8. package/autoscaling/snapshotter.js +18 -29
  9. package/autoscaling/snapshotter.js.map +1 -1
  10. package/autoscaling/system_status.d.ts +0 -3
  11. package/autoscaling/system_status.d.ts.map +1 -1
  12. package/autoscaling/system_status.js +2 -3
  13. package/autoscaling/system_status.js.map +1 -1
  14. package/configuration.d.ts +85 -227
  15. package/configuration.d.ts.map +1 -1
  16. package/configuration.js +159 -223
  17. package/configuration.js.map +1 -1
  18. package/cookie_utils.d.ts +1 -1
  19. package/cookie_utils.d.ts.map +1 -1
  20. package/cookie_utils.js +8 -8
  21. package/cookie_utils.js.map +1 -1
  22. package/crawlers/context_pipeline.d.ts +71 -0
  23. package/crawlers/context_pipeline.d.ts.map +1 -0
  24. package/crawlers/context_pipeline.js +123 -0
  25. package/crawlers/context_pipeline.js.map +1 -0
  26. package/crawlers/crawler_commons.d.ts +19 -27
  27. package/crawlers/crawler_commons.d.ts.map +1 -1
  28. package/crawlers/crawler_commons.js +12 -20
  29. package/crawlers/crawler_commons.js.map +1 -1
  30. package/crawlers/crawler_utils.js +1 -1
  31. package/crawlers/crawler_utils.js.map +1 -1
  32. package/crawlers/error_snapshotter.d.ts +3 -2
  33. package/crawlers/error_snapshotter.d.ts.map +1 -1
  34. package/crawlers/error_snapshotter.js +2 -2
  35. package/crawlers/error_snapshotter.js.map +1 -1
  36. package/crawlers/error_tracker.d.ts +2 -1
  37. package/crawlers/error_tracker.d.ts.map +1 -1
  38. package/crawlers/error_tracker.js.map +1 -1
  39. package/crawlers/index.d.ts +1 -1
  40. package/crawlers/index.d.ts.map +1 -1
  41. package/crawlers/index.js +1 -1
  42. package/crawlers/index.js.map +1 -1
  43. package/crawlers/internals/types.d.ts +8 -0
  44. package/crawlers/internals/types.d.ts.map +1 -0
  45. package/crawlers/internals/types.js +2 -0
  46. package/crawlers/internals/types.js.map +1 -0
  47. package/crawlers/statistics.d.ts +15 -15
  48. package/crawlers/statistics.d.ts.map +1 -1
  49. package/crawlers/statistics.js +21 -18
  50. package/crawlers/statistics.js.map +1 -1
  51. package/enqueue_links/enqueue_links.d.ts +32 -18
  52. package/enqueue_links/enqueue_links.d.ts.map +1 -1
  53. package/enqueue_links/enqueue_links.js +45 -24
  54. package/enqueue_links/enqueue_links.js.map +1 -1
  55. package/enqueue_links/shared.d.ts +25 -8
  56. package/enqueue_links/shared.d.ts.map +1 -1
  57. package/enqueue_links/shared.js +69 -37
  58. package/enqueue_links/shared.js.map +1 -1
  59. package/errors.d.ts +30 -0
  60. package/errors.d.ts.map +1 -1
  61. package/errors.js +44 -0
  62. package/errors.js.map +1 -1
  63. package/events/event_manager.d.ts +8 -5
  64. package/events/event_manager.d.ts.map +1 -1
  65. package/events/event_manager.js +7 -9
  66. package/events/event_manager.js.map +1 -1
  67. package/events/local_event_manager.d.ts +14 -4
  68. package/events/local_event_manager.d.ts.map +1 -1
  69. package/events/local_event_manager.js +33 -39
  70. package/events/local_event_manager.js.map +1 -1
  71. package/index.d.ts +3 -2
  72. package/index.d.ts.map +1 -1
  73. package/index.js +2 -1
  74. package/index.js.map +1 -1
  75. package/log.d.ts +82 -2
  76. package/log.d.ts.map +1 -1
  77. package/log.js +102 -0
  78. package/log.js.map +1 -1
  79. package/package.json +9 -10
  80. package/proxy_configuration.d.ts +14 -148
  81. package/proxy_configuration.d.ts.map +1 -1
  82. package/proxy_configuration.js +19 -167
  83. package/proxy_configuration.js.map +1 -1
  84. package/recoverable_state.d.ts +121 -0
  85. package/recoverable_state.d.ts.map +1 -0
  86. package/recoverable_state.js +142 -0
  87. package/recoverable_state.js.map +1 -0
  88. package/request.d.ts +74 -8
  89. package/request.d.ts.map +1 -1
  90. package/request.js +87 -18
  91. package/request.js.map +1 -1
  92. package/router.d.ts.map +1 -1
  93. package/router.js.map +1 -1
  94. package/serialization.js +1 -1
  95. package/serialization.js.map +1 -1
  96. package/service_locator.d.ts +162 -0
  97. package/service_locator.d.ts.map +1 -0
  98. package/service_locator.js +247 -0
  99. package/service_locator.js.map +1 -0
  100. package/session_pool/session.d.ts +9 -31
  101. package/session_pool/session.d.ts.map +1 -1
  102. package/session_pool/session.js +17 -21
  103. package/session_pool/session.js.map +1 -1
  104. package/session_pool/session_pool.d.ts +51 -57
  105. package/session_pool/session_pool.d.ts.map +1 -1
  106. package/session_pool/session_pool.js +86 -79
  107. package/session_pool/session_pool.js.map +1 -1
  108. package/storages/dataset.d.ts +63 -19
  109. package/storages/dataset.d.ts.map +1 -1
  110. package/storages/dataset.js +86 -22
  111. package/storages/dataset.js.map +1 -1
  112. package/storages/index.d.ts +2 -0
  113. package/storages/index.d.ts.map +1 -1
  114. package/storages/index.js +2 -0
  115. package/storages/index.js.map +1 -1
  116. package/storages/key_value_store.d.ts +79 -10
  117. package/storages/key_value_store.d.ts.map +1 -1
  118. package/storages/key_value_store.js +104 -23
  119. package/storages/key_value_store.js.map +1 -1
  120. package/storages/request_list.d.ts +9 -9
  121. package/storages/request_list.d.ts.map +1 -1
  122. package/storages/request_list.js +13 -8
  123. package/storages/request_list.js.map +1 -1
  124. package/storages/request_list_adapter.d.ts +58 -0
  125. package/storages/request_list_adapter.d.ts.map +1 -0
  126. package/storages/request_list_adapter.js +81 -0
  127. package/storages/request_list_adapter.js.map +1 -0
  128. package/storages/request_manager_tandem.d.ts +68 -0
  129. package/storages/request_manager_tandem.d.ts.map +1 -0
  130. package/storages/request_manager_tandem.js +124 -0
  131. package/storages/request_manager_tandem.js.map +1 -0
  132. package/storages/request_provider.d.ts +86 -23
  133. package/storages/request_provider.d.ts.map +1 -1
  134. package/storages/request_provider.js +114 -74
  135. package/storages/request_provider.js.map +1 -1
  136. package/storages/request_queue.d.ts +1 -3
  137. package/storages/request_queue.d.ts.map +1 -1
  138. package/storages/request_queue.js +2 -4
  139. package/storages/request_queue.js.map +1 -1
  140. package/storages/request_queue_v2.d.ts +3 -3
  141. package/storages/request_queue_v2.d.ts.map +1 -1
  142. package/storages/request_queue_v2.js +4 -5
  143. package/storages/request_queue_v2.js.map +1 -1
  144. package/storages/sitemap_request_list.d.ts +5 -5
  145. package/storages/sitemap_request_list.d.ts.map +1 -1
  146. package/storages/sitemap_request_list.js +10 -7
  147. package/storages/sitemap_request_list.js.map +1 -1
  148. package/storages/storage_manager.d.ts +22 -17
  149. package/storages/storage_manager.d.ts.map +1 -1
  150. package/storages/storage_manager.js +58 -52
  151. package/storages/storage_manager.js.map +1 -1
  152. package/storages/utils.d.ts.map +1 -1
  153. package/storages/utils.js +6 -5
  154. package/storages/utils.js.map +1 -1
  155. package/typedefs.d.ts +1 -1
  156. package/typedefs.d.ts.map +1 -1
  157. package/crawlers/crawler_extension.d.ts +0 -12
  158. package/crawlers/crawler_extension.d.ts.map +0 -1
  159. package/crawlers/crawler_extension.js +0 -14
  160. package/crawlers/crawler_extension.js.map +0 -1
  161. package/http_clients/base-http-client.d.ts +0 -134
  162. package/http_clients/base-http-client.d.ts.map +0 -1
  163. package/http_clients/base-http-client.js +0 -33
  164. package/http_clients/base-http-client.js.map +0 -1
  165. package/http_clients/form-data-like.d.ts +0 -67
  166. package/http_clients/form-data-like.d.ts.map +0 -1
  167. package/http_clients/form-data-like.js +0 -5
  168. package/http_clients/form-data-like.js.map +0 -1
  169. package/http_clients/got-scraping-http-client.d.ts +0 -15
  170. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  171. package/http_clients/got-scraping-http-client.js +0 -69
  172. package/http_clients/got-scraping-http-client.js.map +0 -1
  173. package/http_clients/index.d.ts +0 -3
  174. package/http_clients/index.d.ts.map +0 -1
  175. package/http_clients/index.js +0 -3
  176. package/http_clients/index.js.map +0 -1
  177. package/tsconfig.build.tsbuildinfo +0 -1
@@ -1,153 +1,57 @@
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
+ /** @default 1_000 */
28
+ systemInfoIntervalMillis: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>>>;
29
+ /** @default 'INPUT' */
30
+ inputKey: ConfigField<z.ZodDefault<z.ZodString>>;
31
+ /** @default true */
32
+ headless: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
33
+ /** @default false */
34
+ xvfb: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
35
+ chromeExecutablePath: ConfigField<z.ZodOptional<z.ZodString>>;
36
+ defaultBrowserPath: ConfigField<z.ZodOptional<z.ZodString>>;
37
+ /** @default false */
38
+ disableBrowserSandbox: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
39
+ logLevel: ConfigField<z.ZodOptional<z.ZodPipe<z.ZodTransform<{} | null | undefined, unknown>, z.ZodEnum<typeof LogLevel>>>>;
40
+ /** @default true */
41
+ persistStorage: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
42
+ containerized: ConfigField<z.ZodOptional<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>>>;
43
+ };
44
+ export type FieldsInput<F extends Record<string, ConfigField>> = {
45
+ [K in keyof F]?: z.output<F[K]['schema']>;
46
+ };
47
+ export type FieldsOutput<F extends Record<string, ConfigField>> = {
48
+ [K in keyof F]: z.output<F[K]['schema']>;
49
+ };
50
+ export type ConfigurationInput = FieldsInput<typeof crawleeConfigFields>;
51
+ export type ResolvedConfigValues = FieldsOutput<typeof crawleeConfigFields>;
52
+ /** @deprecated Use {@link ConfigurationInput} instead. */
53
+ export type ConfigurationOptions = ConfigurationInput;
54
+ export interface Configuration extends ResolvedConfigValues {
151
55
  }
152
56
  /**
153
57
  * `Configuration` is a value object holding Crawlee configuration. By default, there is a
@@ -161,13 +65,9 @@ export interface ConfigurationOptions {
161
65
  *
162
66
  * // Get the global configuration
163
67
  * 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();
68
+ * // Access configuration values directly as properties
69
+ * console.log(config.headless);
70
+ * console.log(config.persistStateIntervalMillis);
171
71
  * ```
172
72
  *
173
73
  * *Using custom configuration:*
@@ -177,15 +77,14 @@ export interface ConfigurationOptions {
177
77
  * // Create a new configuration
178
78
  * const config = new Configuration({ persistStateIntervalMillis: 30_000 });
179
79
  * // Pass the configuration to the crawler
180
- * const crawler = new BasicCrawler({ ... }, config);
80
+ * const crawler = new BasicCrawler({ configuration: config });
181
81
  * ```
182
82
  *
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:
83
+ * Configuration is immutable — values are set via the constructor and cannot be changed afterwards.
84
+ * The priority order for resolving values is (highest to lowest):
186
85
  *
187
86
  * ```text
188
- * crawlee.json < constructor options < environment variables
87
+ * constructor options > environment variables > crawlee.json > schema defaults
189
88
  * ```
190
89
  *
191
90
  * ## Supported Configuration Options
@@ -207,91 +106,50 @@ export interface ConfigurationOptions {
207
106
  * Key | Environment Variable | Default Value
208
107
  * ---|---|---
209
108
  * `inputKey` | `CRAWLEE_INPUT_KEY` | `'INPUT'`
210
- * `xvfb` | `CRAWLEE_XVFB` | -
109
+ * `xvfb` | `CRAWLEE_XVFB` | `false`
211
110
  * `chromeExecutablePath` | `CRAWLEE_CHROME_EXECUTABLE_PATH` | -
212
111
  * `defaultBrowserPath` | `CRAWLEE_DEFAULT_BROWSER_PATH` | -
213
112
  * `disableBrowserSandbox` | `CRAWLEE_DISABLE_BROWSER_SANDBOX` | -
214
113
  * `availableMemoryRatio` | `CRAWLEE_AVAILABLE_MEMORY_RATIO` | `0.25`
215
- * `systemInfoV2` | `CRAWLEE_SYSTEM_INFO_V2` | false
216
- * `containerized | `CRAWLEE_CONTAINERIZED | -
114
+ * `containerized` | `CRAWLEE_CONTAINERIZED` | -
217
115
  */
218
116
  export declare class Configuration {
219
117
  /**
220
- * Maps environment variables to config keys (e.g. `CRAWLEE_MEMORY_MBYTES` to `memoryMbytes`)
118
+ * Field definitions for this configuration class.
119
+ * Subclasses override this to register additional fields.
221
120
  */
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;
121
+ protected static fields: Record<string, ConfigField>;
122
+ private resolvedValues;
227
123
  /**
228
- * Provides access to the current-instance-scoped Configuration without passing it around in parameters.
229
- * @internal
124
+ * Creates new `Configuration` instance with provided options.
125
+ * Constructor options take precedence over environment variables, which take precedence
126
+ * over crawlee.json values, which take precedence over schema defaults.
230
127
  */
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>>;
128
+ constructor(options?: ConfigurationInput);
238
129
  /**
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.
252
- */
253
- set(key: keyof ConfigurationOptions, value?: any): void;
254
- /**
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.
257
- */
258
- static set(key: keyof ConfigurationOptions, value?: any): void;
259
- /**
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.
130
+ * Returns the global configuration instance. It will respect the environment variables.
263
131
  *
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
132
+ * Delegates to the global ServiceLocator, making it the single source of truth for service management.
267
133
  */
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
273
- */
274
- createMemoryStorage(options?: MemoryStorageOptions): MemoryStorage;
275
- useStorageClient(client: StorageClient): void;
276
- static useStorageClient(client: StorageClient): void;
277
- useEventManager(events: EventManager): void;
134
+ static getGlobalConfig(): Configuration;
278
135
  /**
279
- * Returns the global configuration instance. It will respect the environment variables.
136
+ * Resolves all field values once using the priority chain:
137
+ * constructor options > env vars > crawlee.json > schema defaults.
280
138
  */
281
- static getGlobalConfig(): Configuration;
139
+ private static resolveAll;
282
140
  /**
283
- * Gets default {@link StorageClient} instance.
141
+ * Registers getters (and throwing setters) on the instance for each field.
284
142
  */
285
- static getStorageClient(): StorageClient;
143
+ private registerAccessors;
286
144
  /**
287
- * Gets default {@link EventManager} instance.
145
+ * Reads the first defined env var value for a field definition.
146
+ * Empty strings are treated as unset, falling through to crawlee.json or schema defaults.
147
+ * (Crawlee v3 coerced `''` to `false`/`0`/`''` per type — v4 drops that for consistency.)
288
148
  */
289
- static getEventManager(): EventManager;
149
+ private static readEnvVar;
290
150
  /**
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.
151
+ * Loads config options from crawlee.json in the current working directory.
293
152
  */
294
- static resetGlobalState(): void;
295
- protected buildOptions(options: ConfigurationOptions): void;
153
+ private static loadFileOptions;
296
154
  }
297
155
  //# sourceMappingURL=configuration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAKrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGhE,OAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,KAAK,WAAW,EAAW,MAAM,eAAe,CAA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