@crawlee/core 4.0.0-beta.19 → 4.0.0-beta.190
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/byte_utils.d.ts +17 -0
- package/byte_utils.js +42 -0
- package/configuration.d.ts +90 -226
- package/configuration.js +164 -225
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/errors.d.ts +40 -19
- package/errors.js +53 -28
- package/events/event_manager.d.ts +35 -9
- package/events/event_manager.js +12 -13
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/events/local_event_manager.d.ts +15 -3
- package/events/local_event_manager.js +39 -13
- package/events/system_info.d.ts +38 -0
- package/events/system_info.js +1 -0
- package/index.d.ts +7 -11
- package/index.js +8 -10
- package/internal.d.ts +8 -0
- package/internal.js +9 -0
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +77 -1
- package/log.js +134 -1
- package/memory-storage/consts.d.ts +4 -0
- package/memory-storage/consts.js +4 -0
- package/memory-storage/index.d.ts +1 -0
- package/memory-storage/index.js +1 -0
- package/memory-storage/memory-storage.d.ts +44 -0
- package/memory-storage/memory-storage.js +160 -0
- package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
- package/memory-storage/resource-clients/common/base-client.js +6 -0
- package/memory-storage/resource-clients/dataset.d.ts +40 -0
- package/memory-storage/resource-clients/dataset.js +106 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +199 -0
- package/memory-storage/resource-clients/request-queue.d.ts +77 -0
- package/memory-storage/resource-clients/request-queue.js +414 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned_or_injected.d.ts +58 -0
- package/owned_or_injected.js +98 -0
- package/package.json +18 -19
- package/proxy_configuration.d.ts +22 -134
- package/proxy_configuration.js +34 -146
- package/recoverable_state.d.ts +85 -51
- package/recoverable_state.js +178 -72
- package/request.d.ts +48 -93
- package/request.js +116 -217
- package/serialization.d.ts +0 -1
- package/serialization.js +15 -15
- package/service_locator.d.ts +165 -0
- package/service_locator.js +254 -0
- package/storages/batched_adds.d.ts +37 -0
- package/storages/batched_adds.js +73 -0
- package/storages/dataset.d.ts +114 -56
- package/storages/dataset.js +292 -149
- package/storages/index.d.ts +7 -9
- package/storages/index.js +5 -9
- package/storages/key_value_store.d.ts +187 -50
- package/storages/key_value_store.js +453 -172
- package/storages/key_value_store_codec.d.ts +32 -0
- package/storages/key_value_store_codec.js +113 -0
- package/storages/request_dedup_cache.d.ts +22 -0
- package/storages/request_dedup_cache.js +48 -0
- package/storages/request_list.d.ts +54 -129
- package/storages/request_list.js +272 -245
- package/storages/request_loader.d.ts +127 -0
- package/storages/request_loader.js +36 -0
- package/storages/request_manager.d.ts +109 -0
- package/storages/request_manager.js +1 -0
- package/storages/request_manager_tandem.d.ts +50 -23
- package/storages/request_manager_tandem.js +132 -57
- package/storages/request_queue.d.ts +286 -48
- package/storages/request_queue.js +756 -218
- package/storages/storage_instance_manager.d.ts +87 -0
- package/storages/storage_instance_manager.js +256 -0
- package/storages/storage_stats.d.ts +48 -0
- package/storages/storage_stats.js +29 -0
- package/storages/transaction.d.ts +260 -0
- package/storages/transaction.js +287 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +75 -15
- package/system-info/cpu-info.d.ts +67 -0
- package/system-info/cpu-info.js +216 -0
- package/system-info/memory-info.d.ts +31 -0
- package/system-info/memory-info.js +115 -0
- package/system-info/ps-tree.d.ts +17 -0
- package/system-info/ps-tree.js +144 -0
- package/system-info/runtime.d.ts +14 -0
- package/system-info/runtime.js +80 -0
- package/typedefs.d.ts +0 -6
- package/typedefs.js +0 -1
- package/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +23 -18
- package/validators.js +14 -18
- package/autoscaling/autoscaled_pool.d.ts +0 -300
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js +0 -533
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts +0 -4
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js +0 -4
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts +0 -189
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js +0 -285
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts +0 -181
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js +0 -169
- package/autoscaling/system_status.js.map +0 -1
- package/configuration.d.ts.map +0 -1
- package/configuration.js.map +0 -1
- package/cookie_utils.d.ts +0 -43
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js +0 -111
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts +0 -61
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js +0 -99
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts +0 -195
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js +0 -108
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts +0 -60
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js +0 -118
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts +0 -55
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js +0 -309
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts +0 -7
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js +0 -7
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts +0 -8
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js +0 -2
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts +0 -204
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js +0 -346
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts +0 -249
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js +0 -269
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts +0 -3
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js +0 -3
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts +0 -73
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js +0 -212
- package/enqueue_links/shared.js.map +0 -1
- package/errors.d.ts.map +0 -1
- package/errors.js.map +0 -1
- package/events/event_manager.d.ts.map +0 -1
- package/events/event_manager.js.map +0 -1
- package/events/index.d.ts.map +0 -1
- package/events/index.js.map +0 -1
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js.map +0 -1
- package/http_clients/base-http-client.d.ts +0 -91
- package/http_clients/base-http-client.d.ts.map +0 -1
- package/http_clients/base-http-client.js +0 -44
- package/http_clients/base-http-client.js.map +0 -1
- package/http_clients/form-data-like.d.ts +0 -67
- package/http_clients/form-data-like.d.ts.map +0 -1
- package/http_clients/form-data-like.js +0 -5
- package/http_clients/form-data-like.js.map +0 -1
- package/http_clients/got-scraping-http-client.d.ts +0 -20
- package/http_clients/got-scraping-http-client.d.ts.map +0 -1
- package/http_clients/got-scraping-http-client.js +0 -102
- package/http_clients/got-scraping-http-client.js.map +0 -1
- package/http_clients/index.d.ts +0 -3
- package/http_clients/index.d.ts.map +0 -1
- package/http_clients/index.js +0 -3
- package/http_clients/index.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/log.d.ts.map +0 -1
- package/log.js.map +0 -1
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js.map +0 -1
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts +0 -134
- package/router.d.ts.map +0 -1
- package/router.js +0 -164
- package/router.js.map +0 -1
- package/serialization.d.ts.map +0 -1
- package/serialization.js.map +0 -1
- package/session_pool/consts.d.ts +0 -4
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js +0 -4
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts +0 -8
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js +0 -12
- package/session_pool/errors.js.map +0 -1
- package/session_pool/events.d.ts +0 -3
- package/session_pool/events.d.ts.map +0 -1
- package/session_pool/events.js +0 -3
- package/session_pool/events.js.map +0 -1
- package/session_pool/index.d.ts +0 -6
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js +0 -6
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts +0 -203
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js +0 -278
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts +0 -258
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js +0 -387
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- package/storages/access_checking.js.map +0 -1
- package/storages/dataset.d.ts.map +0 -1
- package/storages/dataset.js.map +0 -1
- package/storages/index.d.ts.map +0 -1
- package/storages/index.js.map +0 -1
- package/storages/key_value_store.d.ts.map +0 -1
- package/storages/key_value_store.js.map +0 -1
- package/storages/request_list.d.ts.map +0 -1
- package/storages/request_list.js.map +0 -1
- package/storages/request_list_adapter.d.ts +0 -58
- package/storages/request_list_adapter.d.ts.map +0 -1
- package/storages/request_list_adapter.js +0 -81
- package/storages/request_list_adapter.js.map +0 -1
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts +0 -371
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -585
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js.map +0 -1
- package/storages/request_queue_v2.d.ts +0 -87
- package/storages/request_queue_v2.d.ts.map +0 -1
- package/storages/request_queue_v2.js +0 -438
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts +0 -245
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -430
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -58
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -105
- package/storages/storage_manager.js.map +0 -1
- package/storages/utils.d.ts.map +0 -1
- package/storages/utils.js.map +0 -1
- package/typedefs.d.ts.map +0 -1
- package/typedefs.js.map +0 -1
- package/validators.d.ts.map +0 -1
- package/validators.js.map +0 -1
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import type { Dictionary,
|
|
1
|
+
import type { Awaitable, Dictionary, KeyValueStoreBackend, KeyValueStoreInfo } from '@crawlee/types';
|
|
2
2
|
import { Configuration } from '../configuration.js';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
@@ -35,8 +29,7 @@ export declare const maybeStringify: <T>(value: T, options: {
|
|
|
35
29
|
* ```
|
|
36
30
|
* {CRAWLEE_STORAGE_DIR}/key_value_stores/{STORE_ID}/{INDEX}.{EXT}
|
|
37
31
|
* ```
|
|
38
|
-
* Note that `{STORE_ID}` is the name or ID of the key-value store. The default key-value store has ID: `default
|
|
39
|
-
* unless you override it by setting the `CRAWLEE_DEFAULT_KEY_VALUE_STORE_ID` environment variable.
|
|
32
|
+
* Note that `{STORE_ID}` is the name or ID of the key-value store. The default key-value store has ID: `default`.
|
|
40
33
|
* The `{KEY}` is the key of the record and `{EXT}` corresponds to the MIME content type of the data value.
|
|
41
34
|
*
|
|
42
35
|
* **Example usage:**
|
|
@@ -67,18 +60,20 @@ export declare const maybeStringify: <T>(value: T, options: {
|
|
|
67
60
|
* @category Result Stores
|
|
68
61
|
*/
|
|
69
62
|
export declare class KeyValueStore {
|
|
70
|
-
|
|
63
|
+
#private;
|
|
64
|
+
readonly configuration: Configuration;
|
|
71
65
|
readonly id: string;
|
|
72
66
|
readonly name?: string;
|
|
73
|
-
readonly
|
|
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;
|
|
67
|
+
readonly backend: KeyValueStoreBackend;
|
|
78
68
|
/**
|
|
79
69
|
* @internal
|
|
80
70
|
*/
|
|
81
|
-
constructor(options: KeyValueStoreOptions,
|
|
71
|
+
constructor(options: KeyValueStoreOptions, configuration?: Configuration);
|
|
72
|
+
/**
|
|
73
|
+
* Backend-independent usage counters tracked for this key-value store (read / write / delete /
|
|
74
|
+
* list operations issued to the underlying storage backend). Counted per backend call.
|
|
75
|
+
*/
|
|
76
|
+
get stats(): KeyValueStoreStats;
|
|
82
77
|
/**
|
|
83
78
|
* Gets a value from the key-value store.
|
|
84
79
|
*
|
|
@@ -143,6 +138,48 @@ export declare class KeyValueStore {
|
|
|
143
138
|
* on the MIME content type of the record, or the default value if the key is missing from the store.
|
|
144
139
|
*/
|
|
145
140
|
getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
141
|
+
/**
|
|
142
|
+
* The active transaction's last buffered write per key for this store, derived from its journal.
|
|
143
|
+
* An entry with a `null` value is a tombstone (an in-transaction deletion).
|
|
144
|
+
*/
|
|
145
|
+
private bufferedJournalEntries;
|
|
146
|
+
/**
|
|
147
|
+
* The single transaction-aware record read shared by `getValue`, `getRecord`, `recordExists` and the
|
|
148
|
+
* listing paths: buffered key → serialized through the standard codec (same fidelity as a real
|
|
149
|
+
* round-trip); tombstoned key → `null`; otherwise the backend.
|
|
150
|
+
*
|
|
151
|
+
* The per-key buffered lookup requires the whole journal to be reduced to a last-write-per-key map,
|
|
152
|
+
* which is O(journal). Single-record callers let it default (rebuilt per call); the listing paths,
|
|
153
|
+
* which read many keys, pass a map built once so the read stays O(1) per key instead of O(journal).
|
|
154
|
+
*/
|
|
155
|
+
private readRecord;
|
|
156
|
+
/**
|
|
157
|
+
* Reads a record from the key-value store without parsing the value.
|
|
158
|
+
*
|
|
159
|
+
* Use this when you need the raw bytes and the content type — for example, to run your own
|
|
160
|
+
* parser (`simdjson`, a custom XML library, etc.) or to forward the bytes verbatim.
|
|
161
|
+
*
|
|
162
|
+
* There is no symmetric `setRecord` method, because {@link KeyValueStore.setValue} already
|
|
163
|
+
* passes a `Buffer` (or `string` / `Stream`) through unchanged when an explicit `contentType`
|
|
164
|
+
* is provided. To write pre-serialized bytes, call
|
|
165
|
+
* `setValue(key, buffer, { contentType: 'application/json; charset=utf-8' })`.
|
|
166
|
+
*
|
|
167
|
+
* Returns `null` if the record does not exist.
|
|
168
|
+
*
|
|
169
|
+
* **Example usage:**
|
|
170
|
+
* ```javascript
|
|
171
|
+
* const store = await KeyValueStore.open();
|
|
172
|
+
* const record = await store.getRecord('huge.json');
|
|
173
|
+
* if (record) {
|
|
174
|
+
* const data = simdjson.parse(record.value);
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @param key
|
|
179
|
+
* Unique key of the record. It can be at most 256 characters long and only consist
|
|
180
|
+
* of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
|
|
181
|
+
*/
|
|
182
|
+
getRecord(key: string): Promise<KeyValueStoreRawRecord | null>;
|
|
146
183
|
/**
|
|
147
184
|
* Tests whether a record with the given key exists in the key-value store without retrieving its value.
|
|
148
185
|
*
|
|
@@ -152,6 +189,8 @@ export declare class KeyValueStore {
|
|
|
152
189
|
recordExists(key: string): Promise<boolean>;
|
|
153
190
|
getAutoSavedValue<T extends Dictionary = Dictionary>(key: string, defaultValue?: T): Promise<T>;
|
|
154
191
|
private ensurePersistStateEvent;
|
|
192
|
+
private fetchKeyValuePages;
|
|
193
|
+
private fetchKeyPages;
|
|
155
194
|
/**
|
|
156
195
|
* Saves or deletes a record in the key-value store.
|
|
157
196
|
* The function returns a promise that resolves once the record has been saved or deleted.
|
|
@@ -196,18 +235,25 @@ export declare class KeyValueStore {
|
|
|
196
235
|
* @param [options] Record options.
|
|
197
236
|
*/
|
|
198
237
|
setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
|
|
238
|
+
/** @internal */
|
|
239
|
+
commitJournalEntries(entries: JournalEntry[]): Promise<void>;
|
|
199
240
|
/**
|
|
200
241
|
* Removes the key-value store either from the Apify cloud storage or from the local directory,
|
|
201
242
|
* depending on the mode of operation.
|
|
202
243
|
*/
|
|
203
244
|
drop(): Promise<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Removes all records from the store but keeps the store itself, along with its
|
|
247
|
+
* {@link KeyValueStore.id|`id`} and {@link KeyValueStore.name|`name`}.
|
|
248
|
+
*/
|
|
249
|
+
purge(): Promise<void>;
|
|
204
250
|
/** @internal */
|
|
205
251
|
clearCache(): void;
|
|
206
252
|
/**
|
|
207
253
|
* Iterates over key-value store keys, yielding each in turn to an `iteratee` function.
|
|
208
254
|
* Each invocation of `iteratee` is called with three arguments: `(key, index, info)`, where `key`
|
|
209
255
|
* is the record key, `index` is a zero-based index of the key in the current iteration
|
|
210
|
-
*
|
|
256
|
+
* and `info` is an object that contains a single property `size`
|
|
211
257
|
* indicating size of the record in bytes.
|
|
212
258
|
*
|
|
213
259
|
* If the `iteratee` function returns a Promise then it is awaited before the next call.
|
|
@@ -225,11 +271,97 @@ export declare class KeyValueStore {
|
|
|
225
271
|
* @param [options] All `forEachKey()` parameters.
|
|
226
272
|
*/
|
|
227
273
|
forEachKey(iteratee: KeyConsumer, options?: KeyValueStoreIteratorOptions): Promise<void>;
|
|
228
|
-
|
|
274
|
+
/**
|
|
275
|
+
* Returns key-value store keys.
|
|
276
|
+
*
|
|
277
|
+
* When awaited (`await store.keys()`), returns all keys as a flat `string[]` array.
|
|
278
|
+
* When used as an async iterable (`for await...of`), iterates over all keys across pages
|
|
279
|
+
* without loading everything into memory at once.
|
|
280
|
+
*
|
|
281
|
+
* **Example usage:**
|
|
282
|
+
* ```javascript
|
|
283
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
284
|
+
*
|
|
285
|
+
* // Iterate over all keys (memory-efficient for large stores)
|
|
286
|
+
* for await (const key of keyValueStore.keys()) {
|
|
287
|
+
* console.log(key);
|
|
288
|
+
* }
|
|
289
|
+
*
|
|
290
|
+
* // Or fetch all keys at once
|
|
291
|
+
* const allKeys = await keyValueStore.keys();
|
|
292
|
+
* console.log(allKeys);
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @param options Options for the iteration.
|
|
296
|
+
*/
|
|
297
|
+
keys(options?: KeyValueStoreIteratorOptions): AsyncIterable<string> & Promise<string[]>;
|
|
298
|
+
/**
|
|
299
|
+
* Returns key-value store values.
|
|
300
|
+
*
|
|
301
|
+
* When awaited (`await store.values()`), returns all values as a flat `T[]` array.
|
|
302
|
+
* When used as an async iterable (`for await...of`), iterates over all values across pages
|
|
303
|
+
* without loading everything into memory at once.
|
|
304
|
+
*
|
|
305
|
+
* **Example usage:**
|
|
306
|
+
* ```javascript
|
|
307
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
308
|
+
*
|
|
309
|
+
* // Iterate over all values (memory-efficient for large stores)
|
|
310
|
+
* for await (const value of keyValueStore.values()) {
|
|
311
|
+
* console.log(value);
|
|
312
|
+
* }
|
|
313
|
+
*
|
|
314
|
+
* // Or fetch all values at once
|
|
315
|
+
* const allValues = await keyValueStore.values();
|
|
316
|
+
* console.log(allValues);
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* @param options Options for the iteration.
|
|
320
|
+
*/
|
|
321
|
+
values<T = unknown>(options?: KeyValueStoreIteratorOptions): AsyncIterable<T> & Promise<T[]>;
|
|
322
|
+
/**
|
|
323
|
+
* Returns key-value store entries (key-value pairs).
|
|
324
|
+
*
|
|
325
|
+
* When awaited (`await store.entries()`), returns all entries as a flat `[key, value][]` array.
|
|
326
|
+
* When used as an async iterable (`for await...of`), iterates over all entries across pages
|
|
327
|
+
* without loading everything into memory at once.
|
|
328
|
+
*
|
|
329
|
+
* **Example usage:**
|
|
330
|
+
* ```javascript
|
|
331
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
332
|
+
*
|
|
333
|
+
* // Iterate over all entries (memory-efficient for large stores)
|
|
334
|
+
* for await (const [key, value] of keyValueStore.entries()) {
|
|
335
|
+
* console.log(`${key}: ${value}`);
|
|
336
|
+
* }
|
|
337
|
+
*
|
|
338
|
+
* // Or fetch all entries at once
|
|
339
|
+
* const allEntries = await keyValueStore.entries();
|
|
340
|
+
* console.log(allEntries);
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
343
|
+
* @param options Options for the iteration.
|
|
344
|
+
*/
|
|
345
|
+
entries<T = unknown>(options?: KeyValueStoreIteratorOptions): AsyncIterable<[string, T]> & Promise<[string, T][]>;
|
|
346
|
+
/**
|
|
347
|
+
* Default async iterator for the key-value store, iterating over entries (key-value pairs).
|
|
348
|
+
* Allows using the store directly in a `for await...of` loop.
|
|
349
|
+
*
|
|
350
|
+
* **Example usage:**
|
|
351
|
+
* ```javascript
|
|
352
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
353
|
+
* for await (const [key, value] of keyValueStore) {
|
|
354
|
+
* console.log(`${key}: ${value}`);
|
|
355
|
+
* }
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
[Symbol.asyncIterator]<T = unknown>(): AsyncGenerator<[string, T], void, undefined>;
|
|
229
359
|
/**
|
|
230
360
|
* Returns a file URL for the given key.
|
|
231
361
|
*
|
|
232
|
-
*
|
|
362
|
+
* The URL is derived from the key, so it is also returned for a record that does not exist (yet) —
|
|
363
|
+
* including one written earlier in an uncommitted storage transaction. Returns `undefined` only when
|
|
364
|
+
* the storage has no file URLs at all (e.g. the in-memory storage).
|
|
233
365
|
*
|
|
234
366
|
* @param key The key of the record to generate the public URL for.
|
|
235
367
|
*/
|
|
@@ -243,12 +375,13 @@ export declare class KeyValueStore {
|
|
|
243
375
|
*
|
|
244
376
|
* For more details and code examples, see the {@link KeyValueStore} class.
|
|
245
377
|
*
|
|
246
|
-
* @param [
|
|
247
|
-
* ID or name of the key-value store to be opened. If
|
|
248
|
-
*
|
|
378
|
+
* @param [identifier]
|
|
379
|
+
* ID or name of the key-value store to be opened. If a string is provided, it will first be
|
|
380
|
+
* looked up as an ID; if no such storage exists, it will be treated as a name.
|
|
381
|
+
* If `null` or `undefined`, the function returns the default key-value store associated with the crawler run.
|
|
249
382
|
* @param [options] Storage manager options.
|
|
250
383
|
*/
|
|
251
|
-
static open(
|
|
384
|
+
static open(identifier?: string | StorageIdentifier | null, options?: StorageOpenOptions): Promise<KeyValueStore>;
|
|
252
385
|
/**
|
|
253
386
|
* Gets a value from the default {@link KeyValueStore} associated with the current crawler run.
|
|
254
387
|
*
|
|
@@ -307,6 +440,19 @@ export declare class KeyValueStore {
|
|
|
307
440
|
* @ignore
|
|
308
441
|
*/
|
|
309
442
|
static getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
443
|
+
/**
|
|
444
|
+
* Reads a record from the default {@link KeyValueStore} associated with the current crawler run
|
|
445
|
+
* without parsing the value.
|
|
446
|
+
*
|
|
447
|
+
* This is just a convenient shortcut for {@link KeyValueStore.getRecord}. Returns `null` if the
|
|
448
|
+
* record does not exist.
|
|
449
|
+
*
|
|
450
|
+
* @param key
|
|
451
|
+
* Unique key of the record. It can be at most 256 characters long and only consist
|
|
452
|
+
* of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
|
|
453
|
+
* @ignore
|
|
454
|
+
*/
|
|
455
|
+
static getRecord(key: string): Promise<KeyValueStoreRawRecord | null>;
|
|
310
456
|
/**
|
|
311
457
|
* Tests whether a record with the given key exists in the default {@link KeyValueStore} associated with the current crawler run.
|
|
312
458
|
* @param key The queried record key.
|
|
@@ -348,8 +494,9 @@ export declare class KeyValueStore {
|
|
|
348
494
|
static setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
|
|
349
495
|
/**
|
|
350
496
|
* Gets the crawler input value from the default {@link KeyValueStore} associated with the current crawler run.
|
|
351
|
-
*
|
|
352
|
-
*
|
|
497
|
+
*
|
|
498
|
+
* The input is read from the default {@link KeyValueStore} under the configured input key
|
|
499
|
+
* (`CRAWLEE_INPUT_KEY`, default `INPUT`).
|
|
353
500
|
*
|
|
354
501
|
* Note that the `getInput()` function does not cache the value read from the key-value store.
|
|
355
502
|
* If you need to use the input multiple times in your crawler,
|
|
@@ -382,37 +529,27 @@ export interface KeyConsumer {
|
|
|
382
529
|
}): Awaitable<void>;
|
|
383
530
|
}
|
|
384
531
|
export interface KeyValueStoreOptions {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
532
|
+
/** Resolved metadata for the key-value store, as returned by the backend's `getMetadata()`. */
|
|
533
|
+
metadata: KeyValueStoreInfo;
|
|
534
|
+
backend: KeyValueStoreBackend;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* A raw, unparsed key-value store record as returned by {@link KeyValueStore.getRecord}: the
|
|
538
|
+
* verbatim bytes plus the content type, with parsing left to the caller.
|
|
539
|
+
*/
|
|
540
|
+
export interface KeyValueStoreRawRecord {
|
|
541
|
+
value: Buffer | ArrayBuffer;
|
|
542
|
+
contentType: string | null;
|
|
389
543
|
}
|
|
390
544
|
export interface RecordOptions {
|
|
391
545
|
/**
|
|
392
546
|
* Specifies a custom MIME content type of the record.
|
|
393
547
|
*/
|
|
394
548
|
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
549
|
}
|
|
404
550
|
export interface KeyValueStoreIteratorOptions {
|
|
405
|
-
/**
|
|
406
|
-
* All keys up to this one (including) are skipped from the result.
|
|
407
|
-
*/
|
|
408
|
-
exclusiveStartKey?: string;
|
|
409
551
|
/**
|
|
410
552
|
* If set, only keys that start with this prefix are returned.
|
|
411
553
|
*/
|
|
412
554
|
prefix?: string;
|
|
413
|
-
/**
|
|
414
|
-
* Collection name to use for listing keys.
|
|
415
|
-
*/
|
|
416
|
-
collection?: string;
|
|
417
555
|
}
|
|
418
|
-
//# sourceMappingURL=key_value_store.d.ts.map
|