@crawlee/core 4.0.0-beta.17 → 4.0.0-beta.171

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 (270) hide show
  1. package/README.md +14 -14
  2. package/byte_utils.d.ts +17 -0
  3. package/byte_utils.js +42 -0
  4. package/configuration.d.ts +96 -223
  5. package/configuration.js +170 -222
  6. package/debug.d.ts +36 -0
  7. package/debug.js +70 -0
  8. package/errors.d.ts +40 -19
  9. package/errors.js +53 -28
  10. package/events/event_manager.d.ts +35 -9
  11. package/events/event_manager.js +12 -13
  12. package/events/index.d.ts +1 -1
  13. package/events/index.js +0 -1
  14. package/events/local_event_manager.d.ts +15 -3
  15. package/events/local_event_manager.js +39 -13
  16. package/events/system_info.d.ts +38 -0
  17. package/events/system_info.js +1 -0
  18. package/index.d.ts +7 -11
  19. package/index.js +8 -10
  20. package/internal.d.ts +8 -0
  21. package/internal.js +9 -0
  22. package/iterables.d.ts +79 -0
  23. package/iterables.js +134 -0
  24. package/log.d.ts +77 -1
  25. package/log.js +134 -1
  26. package/memory-storage/consts.d.ts +4 -0
  27. package/memory-storage/consts.js +4 -0
  28. package/memory-storage/index.d.ts +1 -0
  29. package/memory-storage/index.js +1 -0
  30. package/memory-storage/memory-storage.d.ts +44 -0
  31. package/memory-storage/memory-storage.js +160 -0
  32. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  33. package/memory-storage/resource-clients/common/base-client.js +6 -0
  34. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  35. package/memory-storage/resource-clients/dataset.js +106 -0
  36. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  37. package/memory-storage/resource-clients/key-value-store.js +199 -0
  38. package/memory-storage/resource-clients/request-queue.d.ts +77 -0
  39. package/memory-storage/resource-clients/request-queue.js +414 -0
  40. package/memory-storage/utils.d.ts +16 -0
  41. package/memory-storage/utils.js +41 -0
  42. package/owned_or_injected.d.ts +58 -0
  43. package/owned_or_injected.js +98 -0
  44. package/package.json +18 -19
  45. package/proxy_configuration.d.ts +22 -128
  46. package/proxy_configuration.js +32 -144
  47. package/recoverable_state.d.ts +84 -51
  48. package/recoverable_state.js +175 -72
  49. package/request.d.ts +60 -17
  50. package/request.js +130 -69
  51. package/serialization.d.ts +0 -1
  52. package/serialization.js +15 -15
  53. package/service_locator.d.ts +165 -0
  54. package/service_locator.js +253 -0
  55. package/storages/batched_adds.d.ts +37 -0
  56. package/storages/batched_adds.js +73 -0
  57. package/storages/dataset.d.ts +114 -56
  58. package/storages/dataset.js +292 -149
  59. package/storages/index.d.ts +7 -9
  60. package/storages/index.js +5 -9
  61. package/storages/key_value_store.d.ts +186 -48
  62. package/storages/key_value_store.js +452 -170
  63. package/storages/key_value_store_codec.d.ts +32 -0
  64. package/storages/key_value_store_codec.js +113 -0
  65. package/storages/request_dedup_cache.d.ts +22 -0
  66. package/storages/request_dedup_cache.js +48 -0
  67. package/storages/request_list.d.ts +54 -129
  68. package/storages/request_list.js +272 -245
  69. package/storages/request_loader.d.ts +133 -0
  70. package/storages/request_loader.js +36 -0
  71. package/storages/request_manager.d.ts +109 -0
  72. package/storages/request_manager.js +1 -0
  73. package/storages/request_manager_tandem.d.ts +55 -23
  74. package/storages/request_manager_tandem.js +139 -57
  75. package/storages/request_queue.d.ts +286 -48
  76. package/storages/request_queue.js +757 -218
  77. package/storages/storage_instance_manager.d.ts +87 -0
  78. package/storages/storage_instance_manager.js +256 -0
  79. package/storages/storage_stats.d.ts +48 -0
  80. package/storages/storage_stats.js +29 -0
  81. package/storages/transaction.d.ts +260 -0
  82. package/storages/transaction.js +287 -0
  83. package/storages/utils.d.ts +59 -11
  84. package/storages/utils.js +75 -15
  85. package/system-info/cpu-info.d.ts +67 -0
  86. package/system-info/cpu-info.js +216 -0
  87. package/system-info/memory-info.d.ts +31 -0
  88. package/system-info/memory-info.js +115 -0
  89. package/system-info/ps-tree.d.ts +17 -0
  90. package/system-info/ps-tree.js +144 -0
  91. package/system-info/runtime.d.ts +14 -0
  92. package/system-info/runtime.js +80 -0
  93. package/typedefs.d.ts +0 -6
  94. package/typedefs.js +0 -1
  95. package/url.d.ts +9 -0
  96. package/url.js +11 -0
  97. package/validators.d.ts +23 -18
  98. package/validators.js +14 -18
  99. package/autoscaling/autoscaled_pool.d.ts +0 -300
  100. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  101. package/autoscaling/autoscaled_pool.js +0 -533
  102. package/autoscaling/autoscaled_pool.js.map +0 -1
  103. package/autoscaling/index.d.ts +0 -4
  104. package/autoscaling/index.d.ts.map +0 -1
  105. package/autoscaling/index.js +0 -4
  106. package/autoscaling/index.js.map +0 -1
  107. package/autoscaling/snapshotter.d.ts +0 -189
  108. package/autoscaling/snapshotter.d.ts.map +0 -1
  109. package/autoscaling/snapshotter.js +0 -285
  110. package/autoscaling/snapshotter.js.map +0 -1
  111. package/autoscaling/system_status.d.ts +0 -181
  112. package/autoscaling/system_status.d.ts.map +0 -1
  113. package/autoscaling/system_status.js +0 -169
  114. package/autoscaling/system_status.js.map +0 -1
  115. package/configuration.d.ts.map +0 -1
  116. package/configuration.js.map +0 -1
  117. package/cookie_utils.d.ts +0 -43
  118. package/cookie_utils.d.ts.map +0 -1
  119. package/cookie_utils.js +0 -111
  120. package/cookie_utils.js.map +0 -1
  121. package/crawlers/context_pipeline.d.ts +0 -61
  122. package/crawlers/context_pipeline.d.ts.map +0 -1
  123. package/crawlers/context_pipeline.js +0 -99
  124. package/crawlers/context_pipeline.js.map +0 -1
  125. package/crawlers/crawler_commons.d.ts +0 -195
  126. package/crawlers/crawler_commons.d.ts.map +0 -1
  127. package/crawlers/crawler_commons.js +0 -108
  128. package/crawlers/crawler_commons.js.map +0 -1
  129. package/crawlers/crawler_utils.d.ts +0 -10
  130. package/crawlers/crawler_utils.d.ts.map +0 -1
  131. package/crawlers/crawler_utils.js +0 -12
  132. package/crawlers/crawler_utils.js.map +0 -1
  133. package/crawlers/error_snapshotter.d.ts +0 -60
  134. package/crawlers/error_snapshotter.d.ts.map +0 -1
  135. package/crawlers/error_snapshotter.js +0 -118
  136. package/crawlers/error_snapshotter.js.map +0 -1
  137. package/crawlers/error_tracker.d.ts +0 -55
  138. package/crawlers/error_tracker.d.ts.map +0 -1
  139. package/crawlers/error_tracker.js +0 -309
  140. package/crawlers/error_tracker.js.map +0 -1
  141. package/crawlers/index.d.ts +0 -7
  142. package/crawlers/index.d.ts.map +0 -1
  143. package/crawlers/index.js +0 -7
  144. package/crawlers/index.js.map +0 -1
  145. package/crawlers/internals/types.d.ts +0 -8
  146. package/crawlers/internals/types.d.ts.map +0 -1
  147. package/crawlers/internals/types.js +0 -2
  148. package/crawlers/internals/types.js.map +0 -1
  149. package/crawlers/statistics.d.ts +0 -204
  150. package/crawlers/statistics.d.ts.map +0 -1
  151. package/crawlers/statistics.js +0 -346
  152. package/crawlers/statistics.js.map +0 -1
  153. package/enqueue_links/enqueue_links.d.ts +0 -249
  154. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  155. package/enqueue_links/enqueue_links.js +0 -269
  156. package/enqueue_links/enqueue_links.js.map +0 -1
  157. package/enqueue_links/index.d.ts +0 -3
  158. package/enqueue_links/index.d.ts.map +0 -1
  159. package/enqueue_links/index.js +0 -3
  160. package/enqueue_links/index.js.map +0 -1
  161. package/enqueue_links/shared.d.ts +0 -73
  162. package/enqueue_links/shared.d.ts.map +0 -1
  163. package/enqueue_links/shared.js +0 -212
  164. package/enqueue_links/shared.js.map +0 -1
  165. package/errors.d.ts.map +0 -1
  166. package/errors.js.map +0 -1
  167. package/events/event_manager.d.ts.map +0 -1
  168. package/events/event_manager.js.map +0 -1
  169. package/events/index.d.ts.map +0 -1
  170. package/events/index.js.map +0 -1
  171. package/events/local_event_manager.d.ts.map +0 -1
  172. package/events/local_event_manager.js.map +0 -1
  173. package/http_clients/base-http-client.d.ts +0 -140
  174. package/http_clients/base-http-client.d.ts.map +0 -1
  175. package/http_clients/base-http-client.js +0 -40
  176. package/http_clients/base-http-client.js.map +0 -1
  177. package/http_clients/form-data-like.d.ts +0 -67
  178. package/http_clients/form-data-like.d.ts.map +0 -1
  179. package/http_clients/form-data-like.js +0 -5
  180. package/http_clients/form-data-like.js.map +0 -1
  181. package/http_clients/got-scraping-http-client.d.ts +0 -20
  182. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  183. package/http_clients/got-scraping-http-client.js +0 -85
  184. package/http_clients/got-scraping-http-client.js.map +0 -1
  185. package/http_clients/index.d.ts +0 -3
  186. package/http_clients/index.d.ts.map +0 -1
  187. package/http_clients/index.js +0 -3
  188. package/http_clients/index.js.map +0 -1
  189. package/index.d.ts.map +0 -1
  190. package/index.js.map +0 -1
  191. package/log.d.ts.map +0 -1
  192. package/log.js.map +0 -1
  193. package/proxy_configuration.d.ts.map +0 -1
  194. package/proxy_configuration.js.map +0 -1
  195. package/recoverable_state.d.ts.map +0 -1
  196. package/recoverable_state.js.map +0 -1
  197. package/request.d.ts.map +0 -1
  198. package/request.js.map +0 -1
  199. package/router.d.ts +0 -134
  200. package/router.d.ts.map +0 -1
  201. package/router.js +0 -164
  202. package/router.js.map +0 -1
  203. package/serialization.d.ts.map +0 -1
  204. package/serialization.js.map +0 -1
  205. package/session_pool/consts.d.ts +0 -4
  206. package/session_pool/consts.d.ts.map +0 -1
  207. package/session_pool/consts.js +0 -4
  208. package/session_pool/consts.js.map +0 -1
  209. package/session_pool/errors.d.ts +0 -8
  210. package/session_pool/errors.d.ts.map +0 -1
  211. package/session_pool/errors.js +0 -12
  212. package/session_pool/errors.js.map +0 -1
  213. package/session_pool/events.d.ts +0 -3
  214. package/session_pool/events.d.ts.map +0 -1
  215. package/session_pool/events.js +0 -3
  216. package/session_pool/events.js.map +0 -1
  217. package/session_pool/index.d.ts +0 -6
  218. package/session_pool/index.d.ts.map +0 -1
  219. package/session_pool/index.js +0 -6
  220. package/session_pool/index.js.map +0 -1
  221. package/session_pool/session.d.ts +0 -203
  222. package/session_pool/session.d.ts.map +0 -1
  223. package/session_pool/session.js +0 -278
  224. package/session_pool/session.js.map +0 -1
  225. package/session_pool/session_pool.d.ts +0 -258
  226. package/session_pool/session_pool.d.ts.map +0 -1
  227. package/session_pool/session_pool.js +0 -387
  228. package/session_pool/session_pool.js.map +0 -1
  229. package/storages/access_checking.d.ts +0 -13
  230. package/storages/access_checking.d.ts.map +0 -1
  231. package/storages/access_checking.js +0 -14
  232. package/storages/access_checking.js.map +0 -1
  233. package/storages/dataset.d.ts.map +0 -1
  234. package/storages/dataset.js.map +0 -1
  235. package/storages/index.d.ts.map +0 -1
  236. package/storages/index.js.map +0 -1
  237. package/storages/key_value_store.d.ts.map +0 -1
  238. package/storages/key_value_store.js.map +0 -1
  239. package/storages/request_list.d.ts.map +0 -1
  240. package/storages/request_list.js.map +0 -1
  241. package/storages/request_list_adapter.d.ts +0 -58
  242. package/storages/request_list_adapter.d.ts.map +0 -1
  243. package/storages/request_list_adapter.js +0 -81
  244. package/storages/request_list_adapter.js.map +0 -1
  245. package/storages/request_manager_tandem.d.ts.map +0 -1
  246. package/storages/request_manager_tandem.js.map +0 -1
  247. package/storages/request_provider.d.ts +0 -371
  248. package/storages/request_provider.d.ts.map +0 -1
  249. package/storages/request_provider.js +0 -585
  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 +0 -245
  258. package/storages/sitemap_request_list.d.ts.map +0 -1
  259. package/storages/sitemap_request_list.js +0 -430
  260. package/storages/sitemap_request_list.js.map +0 -1
  261. package/storages/storage_manager.d.ts +0 -58
  262. package/storages/storage_manager.d.ts.map +0 -1
  263. package/storages/storage_manager.js +0 -105
  264. package/storages/storage_manager.js.map +0 -1
  265. package/storages/utils.d.ts.map +0 -1
  266. package/storages/utils.js.map +0 -1
  267. package/typedefs.d.ts.map +0 -1
  268. package/typedefs.js.map +0 -1
  269. package/validators.d.ts.map +0 -1
  270. 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
+ readonly backend: KeyValueStoreBackend;
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,18 +236,25 @@ 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.
202
244
  */
203
245
  drop(): Promise<void>;
246
+ /**
247
+ * Removes all records from the store but keeps the store itself, along with its
248
+ * {@link KeyValueStore.id|`id`} and {@link KeyValueStore.name|`name`}.
249
+ */
250
+ purge(): Promise<void>;
204
251
  /** @internal */
205
252
  clearCache(): void;
206
253
  /**
207
254
  * Iterates over key-value store keys, yielding each in turn to an `iteratee` function.
208
255
  * Each invocation of `iteratee` is called with three arguments: `(key, index, info)`, where `key`
209
256
  * 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`
257
+ * and `info` is an object that contains a single property `size`
211
258
  * indicating size of the record in bytes.
212
259
  *
213
260
  * If the `iteratee` function returns a Promise then it is awaited before the next call.
@@ -225,11 +272,97 @@ export declare class KeyValueStore {
225
272
  * @param [options] All `forEachKey()` parameters.
226
273
  */
227
274
  forEachKey(iteratee: KeyConsumer, options?: KeyValueStoreIteratorOptions): Promise<void>;
228
- private _forEachKey;
275
+ /**
276
+ * Returns key-value store keys.
277
+ *
278
+ * When awaited (`await store.keys()`), returns all keys as a flat `string[]` array.
279
+ * When used as an async iterable (`for await...of`), iterates over all keys across pages
280
+ * without loading everything into memory at once.
281
+ *
282
+ * **Example usage:**
283
+ * ```javascript
284
+ * const keyValueStore = await KeyValueStore.open();
285
+ *
286
+ * // Iterate over all keys (memory-efficient for large stores)
287
+ * for await (const key of keyValueStore.keys()) {
288
+ * console.log(key);
289
+ * }
290
+ *
291
+ * // Or fetch all keys at once
292
+ * const allKeys = await keyValueStore.keys();
293
+ * console.log(allKeys);
294
+ * ```
295
+ *
296
+ * @param options Options for the iteration.
297
+ */
298
+ keys(options?: KeyValueStoreIteratorOptions): AsyncIterable<string> & Promise<string[]>;
299
+ /**
300
+ * Returns key-value store values.
301
+ *
302
+ * When awaited (`await store.values()`), returns all values as a flat `T[]` array.
303
+ * When used as an async iterable (`for await...of`), iterates over all values across pages
304
+ * without loading everything into memory at once.
305
+ *
306
+ * **Example usage:**
307
+ * ```javascript
308
+ * const keyValueStore = await KeyValueStore.open();
309
+ *
310
+ * // Iterate over all values (memory-efficient for large stores)
311
+ * for await (const value of keyValueStore.values()) {
312
+ * console.log(value);
313
+ * }
314
+ *
315
+ * // Or fetch all values at once
316
+ * const allValues = await keyValueStore.values();
317
+ * console.log(allValues);
318
+ * ```
319
+ *
320
+ * @param options Options for the iteration.
321
+ */
322
+ values<T = unknown>(options?: KeyValueStoreIteratorOptions): AsyncIterable<T> & Promise<T[]>;
323
+ /**
324
+ * Returns key-value store entries (key-value pairs).
325
+ *
326
+ * When awaited (`await store.entries()`), returns all entries as a flat `[key, value][]` array.
327
+ * When used as an async iterable (`for await...of`), iterates over all entries across pages
328
+ * without loading everything into memory at once.
329
+ *
330
+ * **Example usage:**
331
+ * ```javascript
332
+ * const keyValueStore = await KeyValueStore.open();
333
+ *
334
+ * // Iterate over all entries (memory-efficient for large stores)
335
+ * for await (const [key, value] of keyValueStore.entries()) {
336
+ * console.log(`${key}: ${value}`);
337
+ * }
338
+ *
339
+ * // Or fetch all entries at once
340
+ * const allEntries = await keyValueStore.entries();
341
+ * console.log(allEntries);
342
+ * ```
343
+ *
344
+ * @param options Options for the iteration.
345
+ */
346
+ entries<T = unknown>(options?: KeyValueStoreIteratorOptions): AsyncIterable<[string, T]> & Promise<[string, T][]>;
347
+ /**
348
+ * Default async iterator for the key-value store, iterating over entries (key-value pairs).
349
+ * Allows using the store directly in a `for await...of` loop.
350
+ *
351
+ * **Example usage:**
352
+ * ```javascript
353
+ * const keyValueStore = await KeyValueStore.open();
354
+ * for await (const [key, value] of keyValueStore) {
355
+ * console.log(`${key}: ${value}`);
356
+ * }
357
+ * ```
358
+ */
359
+ [Symbol.asyncIterator]<T = unknown>(): AsyncGenerator<[string, T], void, undefined>;
229
360
  /**
230
361
  * Returns a file URL for the given key.
231
362
  *
232
- * If the record does not exist or has no associated file path (i.e., it is not stored as a file), returns `undefined`.
363
+ * The URL is derived from the key, so it is also returned for a record that does not exist (yet) —
364
+ * including one written earlier in an uncommitted storage transaction. Returns `undefined` only when
365
+ * the storage has no file URLs at all (e.g. the in-memory storage).
233
366
  *
234
367
  * @param key The key of the record to generate the public URL for.
235
368
  */
@@ -243,12 +376,13 @@ export declare class KeyValueStore {
243
376
  *
244
377
  * For more details and code examples, see the {@link KeyValueStore} class.
245
378
  *
246
- * @param [storeIdOrName]
247
- * ID or name of the key-value store to be opened. If `null` or `undefined`,
248
- * the function returns the default key-value store associated with the crawler run.
379
+ * @param [identifier]
380
+ * ID or name of the key-value store to be opened. If a string is provided, it will first be
381
+ * looked up as an ID; if no such storage exists, it will be treated as a name.
382
+ * If `null` or `undefined`, the function returns the default key-value store associated with the crawler run.
249
383
  * @param [options] Storage manager options.
250
384
  */
251
- static open(storeIdOrName?: string | null, options?: StorageManagerOptions): Promise<KeyValueStore>;
385
+ static open(identifier?: string | StorageIdentifier | null, options?: StorageOpenOptions): Promise<KeyValueStore>;
252
386
  /**
253
387
  * Gets a value from the default {@link KeyValueStore} associated with the current crawler run.
254
388
  *
@@ -307,6 +441,19 @@ export declare class KeyValueStore {
307
441
  * @ignore
308
442
  */
309
443
  static getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
444
+ /**
445
+ * Reads a record from the default {@link KeyValueStore} associated with the current crawler run
446
+ * without parsing the value.
447
+ *
448
+ * This is just a convenient shortcut for {@link KeyValueStore.getRecord}. Returns `null` if the
449
+ * record does not exist.
450
+ *
451
+ * @param key
452
+ * Unique key of the record. It can be at most 256 characters long and only consist
453
+ * of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
454
+ * @ignore
455
+ */
456
+ static getRecord(key: string): Promise<KeyValueStoreRawRecord | null>;
310
457
  /**
311
458
  * Tests whether a record with the given key exists in the default {@link KeyValueStore} associated with the current crawler run.
312
459
  * @param key The queried record key.
@@ -348,8 +495,9 @@ export declare class KeyValueStore {
348
495
  static setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
349
496
  /**
350
497
  * Gets the crawler input value from the default {@link KeyValueStore} associated with the current crawler run.
351
- * By default, it will try to find root input files (either extension-less, `.json` or `.txt`),
352
- * or alternatively read the input from the default {@link KeyValueStore}.
498
+ *
499
+ * The input is read from the default {@link KeyValueStore} under the configured input key
500
+ * (`CRAWLEE_INPUT_KEY`, default `INPUT`).
353
501
  *
354
502
  * Note that the `getInput()` function does not cache the value read from the key-value store.
355
503
  * If you need to use the input multiple times in your crawler,
@@ -382,37 +530,27 @@ export interface KeyConsumer {
382
530
  }): Awaitable<void>;
383
531
  }
384
532
  export interface KeyValueStoreOptions {
385
- id: string;
386
- name?: string;
387
- client: StorageClient;
388
- storageObject?: Record<string, unknown>;
533
+ /** Resolved metadata for the key-value store, as returned by the backend's `getMetadata()`. */
534
+ metadata: KeyValueStoreInfo;
535
+ backend: KeyValueStoreBackend;
536
+ }
537
+ /**
538
+ * A raw, unparsed key-value store record as returned by {@link KeyValueStore.getRecord}: the
539
+ * verbatim bytes plus the content type, with parsing left to the caller.
540
+ */
541
+ export interface KeyValueStoreRawRecord {
542
+ value: Buffer | ArrayBuffer;
543
+ contentType: string | null;
389
544
  }
390
545
  export interface RecordOptions {
391
546
  /**
392
547
  * Specifies a custom MIME content type of the record.
393
548
  */
394
549
  contentType?: string;
395
- /**
396
- * Specifies a custom timeout for the `set-record` API call, in seconds.
397
- */
398
- timeoutSecs?: number;
399
- /**
400
- * If set to `true`, the `set-record` API call will not be retried if it times out.
401
- */
402
- doNotRetryTimeouts?: boolean;
403
550
  }
404
551
  export interface KeyValueStoreIteratorOptions {
405
- /**
406
- * All keys up to this one (including) are skipped from the result.
407
- */
408
- exclusiveStartKey?: string;
409
552
  /**
410
553
  * If set, only keys that start with this prefix are returned.
411
554
  */
412
555
  prefix?: string;
413
- /**
414
- * Collection name to use for listing keys.
415
- */
416
- collection?: string;
417
556
  }
418
- //# sourceMappingURL=key_value_store.d.ts.map