@crawlee/core 4.0.0-beta.13 → 4.0.0-beta.130

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 (280) hide show
  1. package/README.md +17 -13
  2. package/autoscaling/autoscaled_pool.d.ts +67 -172
  3. package/autoscaling/autoscaled_pool.js +182 -329
  4. package/autoscaling/concurrency_system.d.ts +268 -0
  5. package/autoscaling/concurrency_system.js +362 -0
  6. package/autoscaling/cpu_load_signal.d.ts +43 -0
  7. package/autoscaling/cpu_load_signal.js +47 -0
  8. package/autoscaling/event_loop_load_signal.d.ts +51 -0
  9. package/autoscaling/event_loop_load_signal.js +60 -0
  10. package/autoscaling/index.d.ts +6 -1
  11. package/autoscaling/index.js +6 -1
  12. package/autoscaling/load_signal.d.ts +100 -0
  13. package/autoscaling/load_signal.js +105 -0
  14. package/autoscaling/memory_load_signal.d.ts +47 -0
  15. package/autoscaling/memory_load_signal.js +106 -0
  16. package/autoscaling/snapshotter.d.ts +58 -163
  17. package/autoscaling/snapshotter.js +45 -263
  18. package/autoscaling/storage_backend_load_signal.d.ts +56 -0
  19. package/autoscaling/storage_backend_load_signal.js +73 -0
  20. package/autoscaling/system_status.d.ts +67 -89
  21. package/autoscaling/system_status.js +92 -122
  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 -223
  27. package/configuration.js +170 -222
  28. package/cookie_utils.d.ts +3 -2
  29. package/cookie_utils.js +18 -7
  30. package/crawlers/context_pipeline.d.ts +10 -1
  31. package/crawlers/context_pipeline.js +31 -8
  32. package/crawlers/crawler_commons.d.ts +90 -129
  33. package/crawlers/crawler_commons.js +1 -116
  34. package/crawlers/error_snapshotter.d.ts +2 -5
  35. package/crawlers/error_snapshotter.js +7 -8
  36. package/crawlers/error_tracker.d.ts +0 -1
  37. package/crawlers/error_tracker.js +0 -1
  38. package/crawlers/index.d.ts +1 -3
  39. package/crawlers/index.js +0 -3
  40. package/crawlers/internals/types.d.ts +0 -1
  41. package/crawlers/internals/types.js +0 -1
  42. package/crawlers/statistics.d.ts +187 -63
  43. package/crawlers/statistics.js +354 -164
  44. package/debug.d.ts +36 -0
  45. package/debug.js +70 -0
  46. package/enqueue_links/enqueue_links.d.ts +68 -154
  47. package/enqueue_links/enqueue_links.js +38 -210
  48. package/enqueue_links/index.d.ts +0 -1
  49. package/enqueue_links/index.js +0 -1
  50. package/enqueue_links/shared.d.ts +52 -26
  51. package/enqueue_links/shared.js +115 -66
  52. package/errors.d.ts +72 -4
  53. package/errors.js +89 -5
  54. package/events/event_manager.d.ts +35 -9
  55. package/events/event_manager.js +12 -13
  56. package/events/index.d.ts +0 -1
  57. package/events/index.js +0 -1
  58. package/events/local_event_manager.d.ts +15 -3
  59. package/events/local_event_manager.js +39 -13
  60. package/http.d.ts +9 -0
  61. package/http.js +28 -0
  62. package/index.d.ts +7 -4
  63. package/index.js +6 -3
  64. package/iterables.d.ts +79 -0
  65. package/iterables.js +134 -0
  66. package/log.d.ts +82 -3
  67. package/log.js +106 -1
  68. package/memory-storage/consts.d.ts +4 -0
  69. package/memory-storage/consts.js +4 -0
  70. package/memory-storage/index.d.ts +1 -0
  71. package/memory-storage/index.js +1 -0
  72. package/memory-storage/memory-storage.d.ts +38 -0
  73. package/memory-storage/memory-storage.js +130 -0
  74. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  75. package/memory-storage/resource-clients/common/base-client.js +6 -0
  76. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  77. package/memory-storage/resource-clients/dataset.js +108 -0
  78. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  79. package/memory-storage/resource-clients/key-value-store.js +201 -0
  80. package/memory-storage/resource-clients/request-queue.d.ts +77 -0
  81. package/memory-storage/resource-clients/request-queue.js +409 -0
  82. package/memory-storage/utils.d.ts +16 -0
  83. package/memory-storage/utils.js +41 -0
  84. package/owned_or_injected.d.ts +58 -0
  85. package/owned_or_injected.js +98 -0
  86. package/package.json +14 -13
  87. package/proxy_configuration.d.ts +24 -132
  88. package/proxy_configuration.js +32 -147
  89. package/recoverable_state.d.ts +155 -0
  90. package/recoverable_state.js +231 -0
  91. package/request.d.ts +80 -16
  92. package/request.js +147 -68
  93. package/router.d.ts +193 -21
  94. package/router.js +188 -43
  95. package/serialization.d.ts +0 -1
  96. package/serialization.js +15 -15
  97. package/service_locator.d.ts +165 -0
  98. package/service_locator.js +253 -0
  99. package/session_pool/consts.d.ts +1 -2
  100. package/session_pool/consts.js +1 -2
  101. package/session_pool/errors.d.ts +0 -1
  102. package/session_pool/errors.js +0 -1
  103. package/session_pool/fingerprint.d.ts +9 -0
  104. package/session_pool/fingerprint.js +30 -0
  105. package/session_pool/index.d.ts +0 -2
  106. package/session_pool/index.js +0 -2
  107. package/session_pool/session.d.ts +35 -88
  108. package/session_pool/session.js +101 -159
  109. package/session_pool/session_pool.d.ts +73 -91
  110. package/session_pool/session_pool.js +172 -165
  111. package/storages/batched_adds.d.ts +37 -0
  112. package/storages/batched_adds.js +73 -0
  113. package/storages/dataset.d.ts +114 -54
  114. package/storages/dataset.js +291 -148
  115. package/storages/index.d.ts +10 -8
  116. package/storages/index.js +8 -8
  117. package/storages/key_value_store.d.ts +185 -42
  118. package/storages/key_value_store.js +445 -169
  119. package/storages/key_value_store_codec.d.ts +32 -0
  120. package/storages/key_value_store_codec.js +113 -0
  121. package/storages/request_dedup_cache.d.ts +22 -0
  122. package/storages/request_dedup_cache.js +48 -0
  123. package/storages/request_list.d.ts +52 -115
  124. package/storages/request_list.js +183 -152
  125. package/storages/request_loader.d.ts +101 -0
  126. package/storages/request_loader.js +1 -0
  127. package/storages/request_manager.d.ts +33 -0
  128. package/storages/request_manager.js +1 -0
  129. package/storages/request_manager_tandem.d.ts +97 -0
  130. package/storages/request_manager_tandem.js +197 -0
  131. package/storages/request_queue.d.ts +290 -47
  132. package/storages/request_queue.js +762 -216
  133. package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +45 -89
  134. package/storages/sitemap_request_loader.js +438 -0
  135. package/storages/storage_instance_manager.d.ts +87 -0
  136. package/storages/storage_instance_manager.js +256 -0
  137. package/storages/storage_stats.d.ts +48 -0
  138. package/storages/storage_stats.js +29 -0
  139. package/storages/throttling_request_manager.d.ts +239 -0
  140. package/storages/throttling_request_manager.js +646 -0
  141. package/storages/transaction.d.ts +252 -0
  142. package/storages/transaction.js +251 -0
  143. package/storages/utils.d.ts +59 -11
  144. package/storages/utils.js +75 -15
  145. package/system-info/cpu-info.d.ts +67 -0
  146. package/system-info/cpu-info.js +216 -0
  147. package/system-info/memory-info.d.ts +31 -0
  148. package/system-info/memory-info.js +115 -0
  149. package/system-info/ps-tree.d.ts +17 -0
  150. package/system-info/ps-tree.js +144 -0
  151. package/system-info/runtime.d.ts +14 -0
  152. package/system-info/runtime.js +80 -0
  153. package/typedefs.d.ts +0 -6
  154. package/typedefs.js +0 -1
  155. package/url.d.ts +9 -0
  156. package/url.js +11 -0
  157. package/validators.d.ts +22 -18
  158. package/validators.js +13 -18
  159. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  160. package/autoscaling/autoscaled_pool.js.map +0 -1
  161. package/autoscaling/index.d.ts.map +0 -1
  162. package/autoscaling/index.js.map +0 -1
  163. package/autoscaling/snapshotter.d.ts.map +0 -1
  164. package/autoscaling/snapshotter.js.map +0 -1
  165. package/autoscaling/system_status.d.ts.map +0 -1
  166. package/autoscaling/system_status.js.map +0 -1
  167. package/configuration.d.ts.map +0 -1
  168. package/configuration.js.map +0 -1
  169. package/cookie_utils.d.ts.map +0 -1
  170. package/cookie_utils.js.map +0 -1
  171. package/crawlers/context_pipeline.d.ts.map +0 -1
  172. package/crawlers/context_pipeline.js.map +0 -1
  173. package/crawlers/crawler_commons.d.ts.map +0 -1
  174. package/crawlers/crawler_commons.js.map +0 -1
  175. package/crawlers/crawler_utils.d.ts +0 -10
  176. package/crawlers/crawler_utils.d.ts.map +0 -1
  177. package/crawlers/crawler_utils.js +0 -12
  178. package/crawlers/crawler_utils.js.map +0 -1
  179. package/crawlers/error_snapshotter.d.ts.map +0 -1
  180. package/crawlers/error_snapshotter.js.map +0 -1
  181. package/crawlers/error_tracker.d.ts.map +0 -1
  182. package/crawlers/error_tracker.js.map +0 -1
  183. package/crawlers/index.d.ts.map +0 -1
  184. package/crawlers/index.js.map +0 -1
  185. package/crawlers/internals/types.d.ts.map +0 -1
  186. package/crawlers/internals/types.js.map +0 -1
  187. package/crawlers/statistics.d.ts.map +0 -1
  188. package/crawlers/statistics.js.map +0 -1
  189. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  190. package/enqueue_links/enqueue_links.js.map +0 -1
  191. package/enqueue_links/index.d.ts.map +0 -1
  192. package/enqueue_links/index.js.map +0 -1
  193. package/enqueue_links/shared.d.ts.map +0 -1
  194. package/enqueue_links/shared.js.map +0 -1
  195. package/errors.d.ts.map +0 -1
  196. package/errors.js.map +0 -1
  197. package/events/event_manager.d.ts.map +0 -1
  198. package/events/event_manager.js.map +0 -1
  199. package/events/index.d.ts.map +0 -1
  200. package/events/index.js.map +0 -1
  201. package/events/local_event_manager.d.ts.map +0 -1
  202. package/events/local_event_manager.js.map +0 -1
  203. package/http_clients/base-http-client.d.ts +0 -140
  204. package/http_clients/base-http-client.d.ts.map +0 -1
  205. package/http_clients/base-http-client.js +0 -40
  206. package/http_clients/base-http-client.js.map +0 -1
  207. package/http_clients/form-data-like.d.ts +0 -67
  208. package/http_clients/form-data-like.d.ts.map +0 -1
  209. package/http_clients/form-data-like.js +0 -5
  210. package/http_clients/form-data-like.js.map +0 -1
  211. package/http_clients/got-scraping-http-client.d.ts +0 -20
  212. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  213. package/http_clients/got-scraping-http-client.js +0 -82
  214. package/http_clients/got-scraping-http-client.js.map +0 -1
  215. package/http_clients/index.d.ts +0 -3
  216. package/http_clients/index.d.ts.map +0 -1
  217. package/http_clients/index.js +0 -3
  218. package/http_clients/index.js.map +0 -1
  219. package/index.d.ts.map +0 -1
  220. package/index.js.map +0 -1
  221. package/log.d.ts.map +0 -1
  222. package/log.js.map +0 -1
  223. package/proxy_configuration.d.ts.map +0 -1
  224. package/proxy_configuration.js.map +0 -1
  225. package/request.d.ts.map +0 -1
  226. package/request.js.map +0 -1
  227. package/router.d.ts.map +0 -1
  228. package/router.js.map +0 -1
  229. package/serialization.d.ts.map +0 -1
  230. package/serialization.js.map +0 -1
  231. package/session_pool/consts.d.ts.map +0 -1
  232. package/session_pool/consts.js.map +0 -1
  233. package/session_pool/errors.d.ts.map +0 -1
  234. package/session_pool/errors.js.map +0 -1
  235. package/session_pool/events.d.ts +0 -3
  236. package/session_pool/events.d.ts.map +0 -1
  237. package/session_pool/events.js +0 -3
  238. package/session_pool/events.js.map +0 -1
  239. package/session_pool/index.d.ts.map +0 -1
  240. package/session_pool/index.js.map +0 -1
  241. package/session_pool/session.d.ts.map +0 -1
  242. package/session_pool/session.js.map +0 -1
  243. package/session_pool/session_pool.d.ts.map +0 -1
  244. package/session_pool/session_pool.js.map +0 -1
  245. package/storages/access_checking.d.ts +0 -13
  246. package/storages/access_checking.d.ts.map +0 -1
  247. package/storages/access_checking.js +0 -14
  248. package/storages/access_checking.js.map +0 -1
  249. package/storages/dataset.d.ts.map +0 -1
  250. package/storages/dataset.js.map +0 -1
  251. package/storages/index.d.ts.map +0 -1
  252. package/storages/index.js.map +0 -1
  253. package/storages/key_value_store.d.ts.map +0 -1
  254. package/storages/key_value_store.js.map +0 -1
  255. package/storages/request_list.d.ts.map +0 -1
  256. package/storages/request_list.js.map +0 -1
  257. package/storages/request_provider.d.ts +0 -308
  258. package/storages/request_provider.d.ts.map +0 -1
  259. package/storages/request_provider.js +0 -555
  260. package/storages/request_provider.js.map +0 -1
  261. package/storages/request_queue.d.ts.map +0 -1
  262. package/storages/request_queue.js.map +0 -1
  263. package/storages/request_queue_v2.d.ts +0 -87
  264. package/storages/request_queue_v2.d.ts.map +0 -1
  265. package/storages/request_queue_v2.js +0 -438
  266. package/storages/request_queue_v2.js.map +0 -1
  267. package/storages/sitemap_request_list.d.ts.map +0 -1
  268. package/storages/sitemap_request_list.js +0 -430
  269. package/storages/sitemap_request_list.js.map +0 -1
  270. package/storages/storage_manager.d.ts +0 -58
  271. package/storages/storage_manager.d.ts.map +0 -1
  272. package/storages/storage_manager.js +0 -105
  273. package/storages/storage_manager.js.map +0 -1
  274. package/storages/utils.d.ts.map +0 -1
  275. package/storages/utils.js.map +0 -1
  276. package/tsconfig.build.tsbuildinfo +0 -1
  277. package/typedefs.d.ts.map +0 -1
  278. package/typedefs.js.map +0 -1
  279. package/validators.d.ts.map +0 -1
  280. package/validators.js.map +0 -1
@@ -1,15 +1,9 @@
1
- import type { Dictionary, StorageClient } from '@crawlee/types';
1
+ import type { Awaitable, Dictionary, KeyValueStoreBackend, KeyValueStoreInfo } from '@crawlee/types';
2
2
  import { Configuration } from '../configuration.js';
3
- import type { Awaitable } from '../typedefs.js';
4
- import type { StorageManagerOptions } from './storage_manager.js';
5
- /**
6
- * Helper function to possibly stringify value if options.contentType is not set.
7
- *
8
- * @ignore
9
- */
10
- export declare const maybeStringify: <T>(value: T, options: {
11
- contentType?: string;
12
- }) => T;
3
+ import type { JournalEntry } from './transaction.js';
4
+ import type { KeyValueStoreStats } from './storage_stats.js';
5
+ import type { StorageOpenOptions } from './utils.js';
6
+ import type { StorageIdentifier } from './storage_instance_manager.js';
13
7
  /**
14
8
  * The `KeyValueStore` class represents a key-value store, a simple data storage that is used
15
9
  * for saving and reading data records or files. Each data record is
@@ -67,18 +61,20 @@ export declare const maybeStringify: <T>(value: T, options: {
67
61
  * @category Result Stores
68
62
  */
69
63
  export declare class KeyValueStore {
70
- readonly config: Configuration;
64
+ #private;
65
+ readonly configuration: Configuration;
71
66
  readonly id: string;
72
67
  readonly name?: string;
73
- readonly storageObject?: Record<string, unknown>;
74
- private readonly client;
75
- private persistStateEventStarted;
76
- /** Cache for persistent (auto-saved) values. When we try to set such value, the cache will be updated automatically. */
77
- private readonly cache;
68
+ private readonly backend;
78
69
  /**
79
70
  * @internal
80
71
  */
81
- constructor(options: KeyValueStoreOptions, config?: Configuration);
72
+ constructor(options: KeyValueStoreOptions, configuration?: Configuration);
73
+ /**
74
+ * Backend-independent usage counters tracked for this key-value store (read / write / delete /
75
+ * list operations issued to the underlying storage backend). Counted per backend call.
76
+ */
77
+ get stats(): KeyValueStoreStats;
82
78
  /**
83
79
  * Gets a value from the key-value store.
84
80
  *
@@ -143,6 +139,48 @@ export declare class KeyValueStore {
143
139
  * on the MIME content type of the record, or the default value if the key is missing from the store.
144
140
  */
145
141
  getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
142
+ /**
143
+ * The active transaction's last buffered write per key for this store, derived from its journal.
144
+ * An entry with a `null` value is a tombstone (an in-transaction deletion).
145
+ */
146
+ private bufferedJournalEntries;
147
+ /**
148
+ * The single transaction-aware record read shared by `getValue`, `getRecord`, `recordExists` and the
149
+ * listing paths: buffered key → serialized through the standard codec (same fidelity as a real
150
+ * round-trip); tombstoned key → `null`; otherwise the backend.
151
+ *
152
+ * The per-key buffered lookup requires the whole journal to be reduced to a last-write-per-key map,
153
+ * which is O(journal). Single-record callers let it default (rebuilt per call); the listing paths,
154
+ * which read many keys, pass a map built once so the read stays O(1) per key instead of O(journal).
155
+ */
156
+ private readRecord;
157
+ /**
158
+ * Reads a record from the key-value store without parsing the value.
159
+ *
160
+ * Use this when you need the raw bytes and the content type — for example, to run your own
161
+ * parser (`simdjson`, a custom XML library, etc.) or to forward the bytes verbatim.
162
+ *
163
+ * There is no symmetric `setRecord` method, because {@link KeyValueStore.setValue} already
164
+ * passes a `Buffer` (or `string` / `Stream`) through unchanged when an explicit `contentType`
165
+ * is provided. To write pre-serialized bytes, call
166
+ * `setValue(key, buffer, { contentType: 'application/json; charset=utf-8' })`.
167
+ *
168
+ * Returns `null` if the record does not exist.
169
+ *
170
+ * **Example usage:**
171
+ * ```javascript
172
+ * const store = await KeyValueStore.open();
173
+ * const record = await store.getRecord('huge.json');
174
+ * if (record) {
175
+ * const data = simdjson.parse(record.value);
176
+ * }
177
+ * ```
178
+ *
179
+ * @param key
180
+ * Unique key of the record. It can be at most 256 characters long and only consist
181
+ * of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
182
+ */
183
+ getRecord(key: string): Promise<KeyValueStoreRawRecord | null>;
146
184
  /**
147
185
  * Tests whether a record with the given key exists in the key-value store without retrieving its value.
148
186
  *
@@ -152,6 +190,8 @@ export declare class KeyValueStore {
152
190
  recordExists(key: string): Promise<boolean>;
153
191
  getAutoSavedValue<T extends Dictionary = Dictionary>(key: string, defaultValue?: T): Promise<T>;
154
192
  private ensurePersistStateEvent;
193
+ private fetchKeyValuePages;
194
+ private fetchKeyPages;
155
195
  /**
156
196
  * Saves or deletes a record in the key-value store.
157
197
  * The function returns a promise that resolves once the record has been saved or deleted.
@@ -196,6 +236,8 @@ export declare class KeyValueStore {
196
236
  * @param [options] Record options.
197
237
  */
198
238
  setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
239
+ /** @internal */
240
+ commitJournalEntries(entries: JournalEntry[]): Promise<void>;
199
241
  /**
200
242
  * Removes the key-value store either from the Apify cloud storage or from the local directory,
201
243
  * depending on the mode of operation.
@@ -207,7 +249,7 @@ export declare class KeyValueStore {
207
249
  * Iterates over key-value store keys, yielding each in turn to an `iteratee` function.
208
250
  * Each invocation of `iteratee` is called with three arguments: `(key, index, info)`, where `key`
209
251
  * is the record key, `index` is a zero-based index of the key in the current iteration
210
- * (regardless of `options.exclusiveStartKey`) and `info` is an object that contains a single property `size`
252
+ * and `info` is an object that contains a single property `size`
211
253
  * indicating size of the record in bytes.
212
254
  *
213
255
  * If the `iteratee` function returns a Promise then it is awaited before the next call.
@@ -225,11 +267,99 @@ export declare class KeyValueStore {
225
267
  * @param [options] All `forEachKey()` parameters.
226
268
  */
227
269
  forEachKey(iteratee: KeyConsumer, options?: KeyValueStoreIteratorOptions): Promise<void>;
228
- private _forEachKey;
270
+ /**
271
+ * Returns key-value store keys.
272
+ *
273
+ * When awaited (`await store.keys()`), returns all keys as a flat `string[]` array.
274
+ * When used as an async iterable (`for await...of`), iterates over all keys across pages
275
+ * without loading everything into memory at once.
276
+ *
277
+ * **Example usage:**
278
+ * ```javascript
279
+ * const keyValueStore = await KeyValueStore.open();
280
+ *
281
+ * // Iterate over all keys (memory-efficient for large stores)
282
+ * for await (const key of keyValueStore.keys()) {
283
+ * console.log(key);
284
+ * }
285
+ *
286
+ * // Or fetch all keys at once
287
+ * const allKeys = await keyValueStore.keys();
288
+ * console.log(allKeys);
289
+ * ```
290
+ *
291
+ * @param options Options for the iteration.
292
+ */
293
+ keys(options?: KeyValueStoreIteratorOptions): AsyncIterable<string> & Promise<string[]>;
294
+ /**
295
+ * Returns key-value store values.
296
+ *
297
+ * When awaited (`await store.values()`), returns all values as a flat `T[]` array.
298
+ * When used as an async iterable (`for await...of`), iterates over all values across pages
299
+ * without loading everything into memory at once.
300
+ *
301
+ * **Example usage:**
302
+ * ```javascript
303
+ * const keyValueStore = await KeyValueStore.open();
304
+ *
305
+ * // Iterate over all values (memory-efficient for large stores)
306
+ * for await (const value of keyValueStore.values()) {
307
+ * console.log(value);
308
+ * }
309
+ *
310
+ * // Or fetch all values at once
311
+ * const allValues = await keyValueStore.values();
312
+ * console.log(allValues);
313
+ * ```
314
+ *
315
+ * @param options Options for the iteration.
316
+ */
317
+ values<T = unknown>(options?: KeyValueStoreIteratorOptions): AsyncIterable<T> & Promise<T[]>;
318
+ /**
319
+ * Returns key-value store entries (key-value pairs).
320
+ *
321
+ * When awaited (`await store.entries()`), returns all entries as a flat `[key, value][]` array.
322
+ * When used as an async iterable (`for await...of`), iterates over all entries across pages
323
+ * without loading everything into memory at once.
324
+ *
325
+ * **Example usage:**
326
+ * ```javascript
327
+ * const keyValueStore = await KeyValueStore.open();
328
+ *
329
+ * // Iterate over all entries (memory-efficient for large stores)
330
+ * for await (const [key, value] of keyValueStore.entries()) {
331
+ * console.log(`${key}: ${value}`);
332
+ * }
333
+ *
334
+ * // Or fetch all entries at once
335
+ * const allEntries = await keyValueStore.entries();
336
+ * console.log(allEntries);
337
+ * ```
338
+ *
339
+ * @param options Options for the iteration.
340
+ */
341
+ entries<T = unknown>(options?: KeyValueStoreIteratorOptions): AsyncIterable<[string, T]> & Promise<[string, T][]>;
342
+ /**
343
+ * Default async iterator for the key-value store, iterating over entries (key-value pairs).
344
+ * Allows using the store directly in a `for await...of` loop.
345
+ *
346
+ * **Example usage:**
347
+ * ```javascript
348
+ * const keyValueStore = await KeyValueStore.open();
349
+ * for await (const [key, value] of keyValueStore) {
350
+ * console.log(`${key}: ${value}`);
351
+ * }
352
+ * ```
353
+ */
354
+ [Symbol.asyncIterator]<T = unknown>(): AsyncGenerator<[string, T], void, undefined>;
229
355
  /**
230
356
  * Returns a file URL for the given key.
357
+ *
358
+ * If the record does not exist or has no associated file path (i.e., it is not stored as a file), returns `undefined`.
359
+ *
360
+ * @param key The key of the record to generate the public URL for.
231
361
  */
232
- getPublicUrl(key: string): string;
362
+ getPublicUrl(key: string): Promise<string | undefined>;
233
363
  /**
234
364
  * Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
235
365
  *
@@ -239,12 +369,13 @@ export declare class KeyValueStore {
239
369
  *
240
370
  * For more details and code examples, see the {@link KeyValueStore} class.
241
371
  *
242
- * @param [storeIdOrName]
243
- * ID or name of the key-value store to be opened. If `null` or `undefined`,
244
- * the function returns the default key-value store associated with the crawler run.
372
+ * @param [identifier]
373
+ * ID or name of the key-value store to be opened. If a string is provided, it will first be
374
+ * looked up as an ID; if no such storage exists, it will be treated as a name.
375
+ * If `null` or `undefined`, the function returns the default key-value store associated with the crawler run.
245
376
  * @param [options] Storage manager options.
246
377
  */
247
- static open(storeIdOrName?: string | null, options?: StorageManagerOptions): Promise<KeyValueStore>;
378
+ static open(identifier?: string | StorageIdentifier | null, options?: StorageOpenOptions): Promise<KeyValueStore>;
248
379
  /**
249
380
  * Gets a value from the default {@link KeyValueStore} associated with the current crawler run.
250
381
  *
@@ -303,6 +434,19 @@ export declare class KeyValueStore {
303
434
  * @ignore
304
435
  */
305
436
  static getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
437
+ /**
438
+ * Reads a record from the default {@link KeyValueStore} associated with the current crawler run
439
+ * without parsing the value.
440
+ *
441
+ * This is just a convenient shortcut for {@link KeyValueStore.getRecord}. Returns `null` if the
442
+ * record does not exist.
443
+ *
444
+ * @param key
445
+ * Unique key of the record. It can be at most 256 characters long and only consist
446
+ * of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
447
+ * @ignore
448
+ */
449
+ static getRecord(key: string): Promise<KeyValueStoreRawRecord | null>;
306
450
  /**
307
451
  * Tests whether a record with the given key exists in the default {@link KeyValueStore} associated with the current crawler run.
308
452
  * @param key The queried record key.
@@ -344,8 +488,9 @@ export declare class KeyValueStore {
344
488
  static setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
345
489
  /**
346
490
  * Gets the crawler input value from the default {@link KeyValueStore} associated with the current crawler run.
347
- * By default, it will try to find root input files (either extension-less, `.json` or `.txt`),
348
- * or alternatively read the input from the default {@link KeyValueStore}.
491
+ *
492
+ * The input is read from the default {@link KeyValueStore} under the configured input key
493
+ * (`CRAWLEE_INPUT_KEY`, default `INPUT`).
349
494
  *
350
495
  * Note that the `getInput()` function does not cache the value read from the key-value store.
351
496
  * If you need to use the input multiple times in your crawler,
@@ -378,29 +523,27 @@ export interface KeyConsumer {
378
523
  }): Awaitable<void>;
379
524
  }
380
525
  export interface KeyValueStoreOptions {
381
- id: string;
382
- name?: string;
383
- client: StorageClient;
384
- storageObject?: Record<string, unknown>;
526
+ /** Resolved metadata for the key-value store, as returned by the backend's `getMetadata()`. */
527
+ metadata: KeyValueStoreInfo;
528
+ backend: KeyValueStoreBackend;
529
+ }
530
+ /**
531
+ * A raw, unparsed key-value store record as returned by {@link KeyValueStore.getRecord}: the
532
+ * verbatim bytes plus the content type, with parsing left to the caller.
533
+ */
534
+ export interface KeyValueStoreRawRecord {
535
+ value: Buffer | ArrayBuffer;
536
+ contentType: string | null;
385
537
  }
386
538
  export interface RecordOptions {
387
539
  /**
388
540
  * Specifies a custom MIME content type of the record.
389
541
  */
390
542
  contentType?: string;
391
- /**
392
- * Specifies a custom timeout for the `set-record` API call, in seconds.
393
- */
394
- timeoutSecs?: number;
395
- /**
396
- * If set to `true`, the `set-record` API call will not be retried if it times out.
397
- */
398
- doNotRetryTimeouts?: boolean;
399
543
  }
400
544
  export interface KeyValueStoreIteratorOptions {
401
545
  /**
402
- * All keys up to this one (including) are skipped from the result.
546
+ * If set, only keys that start with this prefix are returned.
403
547
  */
404
- exclusiveStartKey?: string;
548
+ prefix?: string;
405
549
  }
406
- //# sourceMappingURL=key_value_store.d.ts.map