@crawlee/core 4.0.0-beta.23 → 4.0.0-beta.230
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 +15 -15
- package/byte-utils.d.ts +17 -0
- package/byte-utils.js +42 -0
- package/configuration.d.ts +77 -235
- package/configuration.js +157 -227
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/errors.d.ts +45 -18
- package/errors.js +58 -27
- package/events/event-manager.d.ts +78 -0
- package/events/{event_manager.js → event-manager.js} +12 -13
- package/events/index.d.ts +3 -3
- package/events/index.js +2 -3
- package/events/local-event-manager.d.ts +32 -0
- package/events/local-event-manager.js +101 -0
- package/events/system-info.d.ts +38 -0
- package/events/system-info.js +1 -0
- package/index.d.ts +9 -12
- package/index.js +10 -11
- 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 +43 -0
- package/memory-storage/memory-storage.js +158 -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 +35 -0
- package/memory-storage/resource-clients/dataset.js +105 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +54 -0
- package/memory-storage/resource-clients/key-value-store.js +179 -0
- package/memory-storage/resource-clients/request-queue.d.ts +55 -0
- package/memory-storage/resource-clients/request-queue.js +413 -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 +20 -20
- package/proxy-configuration.d.ts +118 -0
- package/proxy-configuration.js +141 -0
- package/recoverable-state.d.ts +177 -0
- package/recoverable-state.js +268 -0
- package/request.d.ts +48 -93
- package/request.js +112 -230
- package/serialization.d.ts +0 -1
- package/serialization.js +18 -18
- package/service-locator.d.ts +168 -0
- package/service-locator.js +255 -0
- package/storages/batched-adds.d.ts +37 -0
- package/storages/batched-adds.js +73 -0
- package/storages/dataset.d.ts +105 -58
- package/storages/dataset.js +292 -150
- package/storages/index.d.ts +11 -12
- package/storages/index.js +7 -12
- package/storages/key-value-store-codec.d.ts +32 -0
- package/storages/key-value-store-codec.js +108 -0
- package/storages/{key_value_store.d.ts → key-value-store.d.ts} +169 -72
- package/storages/key-value-store.js +767 -0
- package/storages/request-dedup-cache.d.ts +20 -0
- package/storages/request-dedup-cache.js +48 -0
- package/storages/{request_list.d.ts → request-list.d.ts} +33 -173
- package/storages/{request_list.js → request-list.js} +276 -255
- package/storages/request-loader.d.ts +127 -0
- package/storages/request-loader.js +36 -0
- package/storages/request-manager-tandem.d.ts +82 -0
- package/storages/request-manager-tandem.js +200 -0
- package/storages/request-manager.d.ts +119 -0
- package/storages/request-manager.js +1 -0
- package/storages/{request_provider.d.ts → request-queue.d.ts} +128 -159
- package/storages/request-queue.js +870 -0
- package/storages/storage-instance-manager.d.ts +86 -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 +270 -0
- package/storages/transaction.js +296 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +76 -16
- 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 -191
- 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 -213
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js +0 -349
- 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 +0 -52
- 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 +0 -27
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js +0 -75
- package/events/local_event_manager.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 +0 -169
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js +0 -247
- package/proxy_configuration.js.map +0 -1
- package/recoverable_state.d.ts +0 -123
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js +0 -140
- 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 -186
- 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 +0 -512
- 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 +0 -68
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js +0 -124
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -591
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts +0 -128
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js +0 -320
- 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 -250
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -431
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -62
- 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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical write path for key-value store records.
|
|
3
|
+
*
|
|
4
|
+
* When a content type is provided, the value passes through unchanged — it is the caller's
|
|
5
|
+
* responsibility to supply a String/Buffer/Stream (the frontend validates this).
|
|
6
|
+
*
|
|
7
|
+
* When no content type is provided, it is inferred from the value's shape:
|
|
8
|
+
* - Buffer / typed array / ArrayBuffer / stream → `application/octet-stream` (passthrough)
|
|
9
|
+
* - `string` → `text/plain; charset=utf-8` (passthrough)
|
|
10
|
+
* - anything else → `application/json; charset=utf-8` (serialized via `jsonStringifyExtended`)
|
|
11
|
+
*
|
|
12
|
+
* Does NOT drain streams — that is storage mechanics and stays in the storage backend.
|
|
13
|
+
*
|
|
14
|
+
* Backend-independent.
|
|
15
|
+
*/
|
|
16
|
+
export declare function serializeValue(value: unknown, contentType?: string): {
|
|
17
|
+
value: Buffer | ArrayBuffer | ArrayBufferView | string | NodeJS.ReadableStream | ReadableStream;
|
|
18
|
+
contentType: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Parses a Buffer or ArrayBuffer using the provided content type header.
|
|
22
|
+
*
|
|
23
|
+
* - application/json is returned as a parsed object.
|
|
24
|
+
* - application/*xml and text/* are returned as strings.
|
|
25
|
+
* - everything else is returned as original body.
|
|
26
|
+
*
|
|
27
|
+
* If the header includes a charset, the body will be stringified only
|
|
28
|
+
* if the charset represents a known encoding to Node.js or Browser.
|
|
29
|
+
*
|
|
30
|
+
* Backend-independent — this is the canonical read path for the {@link KeyValueStore} frontend.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseValue(body: Buffer | ArrayBuffer | string, contentTypeHeader: string | null): string | Buffer | ArrayBuffer | Record<string, unknown>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { isTypeValid, parse as parseContentType } from 'content-type';
|
|
2
|
+
import JSON5 from 'json5';
|
|
3
|
+
import { jsonStringifyExtended } from '@apify/utilities';
|
|
4
|
+
import { isBuffer, isStream } from '../byte-utils.js';
|
|
5
|
+
const CONTENT_TYPE_JSON = 'application/json';
|
|
6
|
+
const STRINGIFIABLE_CONTENT_TYPE_RXS = [new RegExp(`^${CONTENT_TYPE_JSON}$`, 'i'), /^application\/.*xml$/i, /^text\//i];
|
|
7
|
+
/**
|
|
8
|
+
* Canonical write path for key-value store records.
|
|
9
|
+
*
|
|
10
|
+
* When a content type is provided, the value passes through unchanged — it is the caller's
|
|
11
|
+
* responsibility to supply a String/Buffer/Stream (the frontend validates this).
|
|
12
|
+
*
|
|
13
|
+
* When no content type is provided, it is inferred from the value's shape:
|
|
14
|
+
* - Buffer / typed array / ArrayBuffer / stream → `application/octet-stream` (passthrough)
|
|
15
|
+
* - `string` → `text/plain; charset=utf-8` (passthrough)
|
|
16
|
+
* - anything else → `application/json; charset=utf-8` (serialized via `jsonStringifyExtended`)
|
|
17
|
+
*
|
|
18
|
+
* Does NOT drain streams — that is storage mechanics and stays in the storage backend.
|
|
19
|
+
*
|
|
20
|
+
* Backend-independent.
|
|
21
|
+
*/
|
|
22
|
+
export function serializeValue(value, contentType) {
|
|
23
|
+
if (contentType !== null && contentType !== undefined) {
|
|
24
|
+
return { value: value, contentType };
|
|
25
|
+
}
|
|
26
|
+
if (isStream(value) || isBuffer(value)) {
|
|
27
|
+
return {
|
|
28
|
+
value,
|
|
29
|
+
contentType: 'application/octet-stream',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'string') {
|
|
33
|
+
return { value, contentType: 'text/plain; charset=utf-8' };
|
|
34
|
+
}
|
|
35
|
+
let serialized;
|
|
36
|
+
try {
|
|
37
|
+
// Format JSON to simplify debugging, the overheads with compression is negligible
|
|
38
|
+
serialized = jsonStringifyExtended(value, null, 2);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
const error = e;
|
|
42
|
+
// Give more meaningful error message
|
|
43
|
+
if (error.message?.includes('Invalid string length')) {
|
|
44
|
+
error.message = 'Object is too large';
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`The "value" parameter cannot be stringified to JSON: ${error.message}`);
|
|
47
|
+
}
|
|
48
|
+
if (serialized === undefined) {
|
|
49
|
+
throw new Error('The "value" parameter was stringified to JSON and returned undefined. ' +
|
|
50
|
+
"Make sure you're not trying to stringify an undefined value.");
|
|
51
|
+
}
|
|
52
|
+
return { value: serialized, contentType: 'application/json; charset=utf-8' };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parses a Buffer or ArrayBuffer using the provided content type header.
|
|
56
|
+
*
|
|
57
|
+
* - application/json is returned as a parsed object.
|
|
58
|
+
* - application/*xml and text/* are returned as strings.
|
|
59
|
+
* - everything else is returned as original body.
|
|
60
|
+
*
|
|
61
|
+
* If the header includes a charset, the body will be stringified only
|
|
62
|
+
* if the charset represents a known encoding to Node.js or Browser.
|
|
63
|
+
*
|
|
64
|
+
* Backend-independent — this is the canonical read path for the {@link KeyValueStore} frontend.
|
|
65
|
+
*/
|
|
66
|
+
export function parseValue(body, contentTypeHeader) {
|
|
67
|
+
// No content type at all → we have no basis for interpretation; hand back the raw value.
|
|
68
|
+
if (contentTypeHeader === null)
|
|
69
|
+
return body;
|
|
70
|
+
const result = parseContentType(contentTypeHeader);
|
|
71
|
+
// Unparseable header → keep the original value rather than a mangled string.
|
|
72
|
+
if (!isTypeValid(result.type))
|
|
73
|
+
return body;
|
|
74
|
+
const contentType = result.type;
|
|
75
|
+
const charset = result.parameters.charset;
|
|
76
|
+
// If we can't successfully interpret it, we return the original value rather than mangling it.
|
|
77
|
+
if (!areDataStringifiable(contentType, charset))
|
|
78
|
+
return body;
|
|
79
|
+
// Decode raw bytes using the resolved charset. An already-decoded string passes through (callers
|
|
80
|
+
// may hand us one directly), avoiding a needless re-encode round-trip.
|
|
81
|
+
const dataString = typeof body === 'string' ? body : isomorphicBufferToString(body, charset);
|
|
82
|
+
return contentType === CONTENT_TYPE_JSON ? JSON5.parse(dataString) : dataString;
|
|
83
|
+
}
|
|
84
|
+
function isomorphicBufferToString(buffer, encoding) {
|
|
85
|
+
if (buffer.constructor.name !== ArrayBuffer.name) {
|
|
86
|
+
return buffer.toString(encoding);
|
|
87
|
+
}
|
|
88
|
+
// In Node, wrap the ArrayBuffer in a Buffer so the resolved charset is honored (the caller already
|
|
89
|
+
// checked it via `Buffer.isEncoding`). Only the browser, which lacks Buffer, is limited to UTF-8.
|
|
90
|
+
if (typeof Buffer !== 'undefined') {
|
|
91
|
+
return Buffer.from(buffer).toString(encoding);
|
|
92
|
+
}
|
|
93
|
+
const decoder = new TextDecoder(encoding);
|
|
94
|
+
return decoder.decode(new Uint8Array(buffer));
|
|
95
|
+
}
|
|
96
|
+
function isCharsetStringifiable(charset) {
|
|
97
|
+
if (!charset)
|
|
98
|
+
return true; // hope that it's utf-8
|
|
99
|
+
return Buffer.isEncoding(charset);
|
|
100
|
+
}
|
|
101
|
+
function isContentTypeStringifiable(contentType) {
|
|
102
|
+
if (!contentType)
|
|
103
|
+
return false; // keep buffer
|
|
104
|
+
return STRINGIFIABLE_CONTENT_TYPE_RXS.some((rx) => rx.test(contentType));
|
|
105
|
+
}
|
|
106
|
+
function areDataStringifiable(contentType, charset) {
|
|
107
|
+
return isContentTypeStringifiable(contentType) && isCharsetStringifiable(charset);
|
|
108
|
+
}
|
|
@@ -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
|
|
@@ -26,8 +20,6 @@ export declare const maybeStringify: <T>(value: T, options: {
|
|
|
26
20
|
* To access the default key-value store directly, you can use the
|
|
27
21
|
* {@link KeyValueStore.getValue} and {@link KeyValueStore.setValue} convenience functions.
|
|
28
22
|
*
|
|
29
|
-
* To access the input, you can also use the {@link KeyValueStore.getInput} convenience function.
|
|
30
|
-
*
|
|
31
23
|
* `KeyValueStore` stores its data on a local disk.
|
|
32
24
|
*
|
|
33
25
|
* If the `CRAWLEE_STORAGE_DIR` environment variable is set, the data is stored in
|
|
@@ -35,15 +27,14 @@ export declare const maybeStringify: <T>(value: T, options: {
|
|
|
35
27
|
* ```
|
|
36
28
|
* {CRAWLEE_STORAGE_DIR}/key_value_stores/{STORE_ID}/{INDEX}.{EXT}
|
|
37
29
|
* ```
|
|
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.
|
|
30
|
+
* Note that `{STORE_ID}` is the name or ID of the key-value store. The default key-value store has ID: `default`.
|
|
40
31
|
* The `{KEY}` is the key of the record and `{EXT}` corresponds to the MIME content type of the data value.
|
|
41
32
|
*
|
|
42
33
|
* **Example usage:**
|
|
43
34
|
*
|
|
44
35
|
* ```javascript
|
|
45
36
|
* // Get crawler input from the default key-value store.
|
|
46
|
-
* const input = await KeyValueStore.
|
|
37
|
+
* const input = await KeyValueStore.getValue('INPUT');
|
|
47
38
|
* // Get some value from the default key-value store.
|
|
48
39
|
* const otherValue = await KeyValueStore.getValue('my-key');
|
|
49
40
|
*
|
|
@@ -67,18 +58,20 @@ export declare const maybeStringify: <T>(value: T, options: {
|
|
|
67
58
|
* @category Result Stores
|
|
68
59
|
*/
|
|
69
60
|
export declare class KeyValueStore {
|
|
70
|
-
|
|
61
|
+
#private;
|
|
62
|
+
readonly configuration: Configuration;
|
|
71
63
|
readonly id: string;
|
|
72
64
|
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;
|
|
65
|
+
readonly backend: KeyValueStoreBackend;
|
|
78
66
|
/**
|
|
79
67
|
* @internal
|
|
80
68
|
*/
|
|
81
|
-
constructor(options: KeyValueStoreOptions,
|
|
69
|
+
constructor(options: KeyValueStoreOptions, configuration?: Configuration);
|
|
70
|
+
/**
|
|
71
|
+
* Backend-independent usage counters tracked for this key-value store (read / write / delete /
|
|
72
|
+
* list operations issued to the underlying storage backend). Counted per backend call.
|
|
73
|
+
*/
|
|
74
|
+
get stats(): KeyValueStoreStats;
|
|
82
75
|
/**
|
|
83
76
|
* Gets a value from the key-value store.
|
|
84
77
|
*
|
|
@@ -143,6 +136,33 @@ export declare class KeyValueStore {
|
|
|
143
136
|
* on the MIME content type of the record, or the default value if the key is missing from the store.
|
|
144
137
|
*/
|
|
145
138
|
getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
139
|
+
/**
|
|
140
|
+
* Reads a record from the key-value store without parsing the value.
|
|
141
|
+
*
|
|
142
|
+
* Use this when you need the raw bytes and the content type — for example, to run your own
|
|
143
|
+
* parser (`simdjson`, a custom XML library, etc.) or to forward the bytes verbatim.
|
|
144
|
+
*
|
|
145
|
+
* There is no symmetric `setRecord` method, because {@link KeyValueStore.setValue} already
|
|
146
|
+
* passes a `Buffer` (or `string` / `Stream`) through unchanged when an explicit `contentType`
|
|
147
|
+
* is provided. To write pre-serialized bytes, call
|
|
148
|
+
* `setValue(key, buffer, { contentType: 'application/json; charset=utf-8' })`.
|
|
149
|
+
*
|
|
150
|
+
* Returns `null` if the record does not exist.
|
|
151
|
+
*
|
|
152
|
+
* **Example usage:**
|
|
153
|
+
* ```javascript
|
|
154
|
+
* const store = await KeyValueStore.open();
|
|
155
|
+
* const record = await store.getRecord('huge.json');
|
|
156
|
+
* if (record) {
|
|
157
|
+
* const data = simdjson.parse(record.value);
|
|
158
|
+
* }
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @param key
|
|
162
|
+
* Unique key of the record. It can be at most 256 characters long and only consist
|
|
163
|
+
* of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
|
|
164
|
+
*/
|
|
165
|
+
getRecord(key: string): Promise<KeyValueStoreRawRecord | null>;
|
|
146
166
|
/**
|
|
147
167
|
* Tests whether a record with the given key exists in the key-value store without retrieving its value.
|
|
148
168
|
*
|
|
@@ -151,7 +171,6 @@ export declare class KeyValueStore {
|
|
|
151
171
|
*/
|
|
152
172
|
recordExists(key: string): Promise<boolean>;
|
|
153
173
|
getAutoSavedValue<T extends Dictionary = Dictionary>(key: string, defaultValue?: T): Promise<T>;
|
|
154
|
-
private ensurePersistStateEvent;
|
|
155
174
|
/**
|
|
156
175
|
* Saves or deletes a record in the key-value store.
|
|
157
176
|
* The function returns a promise that resolves once the record has been saved or deleted.
|
|
@@ -196,18 +215,25 @@ export declare class KeyValueStore {
|
|
|
196
215
|
* @param [options] Record options.
|
|
197
216
|
*/
|
|
198
217
|
setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
|
|
218
|
+
/** @internal */
|
|
219
|
+
commitJournalEntries(entries: JournalEntry[]): Promise<void>;
|
|
199
220
|
/**
|
|
200
221
|
* Removes the key-value store either from the Apify cloud storage or from the local directory,
|
|
201
222
|
* depending on the mode of operation.
|
|
202
223
|
*/
|
|
203
224
|
drop(): Promise<void>;
|
|
225
|
+
/**
|
|
226
|
+
* Removes all records from the store but keeps the store itself, along with its
|
|
227
|
+
* {@link KeyValueStore.id|`id`} and {@link KeyValueStore.name|`name`}.
|
|
228
|
+
*/
|
|
229
|
+
purge(): Promise<void>;
|
|
204
230
|
/** @internal */
|
|
205
231
|
clearCache(): void;
|
|
206
232
|
/**
|
|
207
233
|
* Iterates over key-value store keys, yielding each in turn to an `iteratee` function.
|
|
208
234
|
* Each invocation of `iteratee` is called with three arguments: `(key, index, info)`, where `key`
|
|
209
235
|
* is the record key, `index` is a zero-based index of the key in the current iteration
|
|
210
|
-
*
|
|
236
|
+
* and `info` is an object that contains a single property `size`
|
|
211
237
|
* indicating size of the record in bytes.
|
|
212
238
|
*
|
|
213
239
|
* If the `iteratee` function returns a Promise then it is awaited before the next call.
|
|
@@ -225,11 +251,97 @@ export declare class KeyValueStore {
|
|
|
225
251
|
* @param [options] All `forEachKey()` parameters.
|
|
226
252
|
*/
|
|
227
253
|
forEachKey(iteratee: KeyConsumer, options?: KeyValueStoreIteratorOptions): Promise<void>;
|
|
228
|
-
|
|
254
|
+
/**
|
|
255
|
+
* Returns key-value store keys.
|
|
256
|
+
*
|
|
257
|
+
* When awaited (`await store.keys()`), returns all keys as a flat `string[]` array.
|
|
258
|
+
* When used as an async iterable (`for await...of`), iterates over all keys across pages
|
|
259
|
+
* without loading everything into memory at once.
|
|
260
|
+
*
|
|
261
|
+
* **Example usage:**
|
|
262
|
+
* ```javascript
|
|
263
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
264
|
+
*
|
|
265
|
+
* // Iterate over all keys (memory-efficient for large stores)
|
|
266
|
+
* for await (const key of keyValueStore.keys()) {
|
|
267
|
+
* console.log(key);
|
|
268
|
+
* }
|
|
269
|
+
*
|
|
270
|
+
* // Or fetch all keys at once
|
|
271
|
+
* const allKeys = await keyValueStore.keys();
|
|
272
|
+
* console.log(allKeys);
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @param options Options for the iteration.
|
|
276
|
+
*/
|
|
277
|
+
keys(options?: KeyValueStoreIteratorOptions): AsyncIterable<string> & Promise<string[]>;
|
|
278
|
+
/**
|
|
279
|
+
* Returns key-value store values.
|
|
280
|
+
*
|
|
281
|
+
* When awaited (`await store.values()`), returns all values as a flat `T[]` array.
|
|
282
|
+
* When used as an async iterable (`for await...of`), iterates over all values across pages
|
|
283
|
+
* without loading everything into memory at once.
|
|
284
|
+
*
|
|
285
|
+
* **Example usage:**
|
|
286
|
+
* ```javascript
|
|
287
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
288
|
+
*
|
|
289
|
+
* // Iterate over all values (memory-efficient for large stores)
|
|
290
|
+
* for await (const value of keyValueStore.values()) {
|
|
291
|
+
* console.log(value);
|
|
292
|
+
* }
|
|
293
|
+
*
|
|
294
|
+
* // Or fetch all values at once
|
|
295
|
+
* const allValues = await keyValueStore.values();
|
|
296
|
+
* console.log(allValues);
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @param options Options for the iteration.
|
|
300
|
+
*/
|
|
301
|
+
values<T = unknown>(options?: KeyValueStoreIteratorOptions): AsyncIterable<T> & Promise<T[]>;
|
|
302
|
+
/**
|
|
303
|
+
* Returns key-value store entries (key-value pairs).
|
|
304
|
+
*
|
|
305
|
+
* When awaited (`await store.entries()`), returns all entries as a flat `[key, value][]` array.
|
|
306
|
+
* When used as an async iterable (`for await...of`), iterates over all entries across pages
|
|
307
|
+
* without loading everything into memory at once.
|
|
308
|
+
*
|
|
309
|
+
* **Example usage:**
|
|
310
|
+
* ```javascript
|
|
311
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
312
|
+
*
|
|
313
|
+
* // Iterate over all entries (memory-efficient for large stores)
|
|
314
|
+
* for await (const [key, value] of keyValueStore.entries()) {
|
|
315
|
+
* console.log(`${key}: ${value}`);
|
|
316
|
+
* }
|
|
317
|
+
*
|
|
318
|
+
* // Or fetch all entries at once
|
|
319
|
+
* const allEntries = await keyValueStore.entries();
|
|
320
|
+
* console.log(allEntries);
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @param options Options for the iteration.
|
|
324
|
+
*/
|
|
325
|
+
entries<T = unknown>(options?: KeyValueStoreIteratorOptions): AsyncIterable<[string, T]> & Promise<[string, T][]>;
|
|
326
|
+
/**
|
|
327
|
+
* Default async iterator for the key-value store, iterating over entries (key-value pairs).
|
|
328
|
+
* Allows using the store directly in a `for await...of` loop.
|
|
329
|
+
*
|
|
330
|
+
* **Example usage:**
|
|
331
|
+
* ```javascript
|
|
332
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
333
|
+
* for await (const [key, value] of keyValueStore) {
|
|
334
|
+
* console.log(`${key}: ${value}`);
|
|
335
|
+
* }
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
[Symbol.asyncIterator]<T = unknown>(): AsyncGenerator<[string, T], void, undefined>;
|
|
229
339
|
/**
|
|
230
340
|
* Returns a file URL for the given key.
|
|
231
341
|
*
|
|
232
|
-
*
|
|
342
|
+
* The URL is derived from the key, so it is also returned for a record that does not exist (yet) —
|
|
343
|
+
* including one written earlier in an uncommitted storage transaction. Returns `undefined` only when
|
|
344
|
+
* the storage has no file URLs at all (e.g. the in-memory storage).
|
|
233
345
|
*
|
|
234
346
|
* @param key The key of the record to generate the public URL for.
|
|
235
347
|
*/
|
|
@@ -243,12 +355,13 @@ export declare class KeyValueStore {
|
|
|
243
355
|
*
|
|
244
356
|
* For more details and code examples, see the {@link KeyValueStore} class.
|
|
245
357
|
*
|
|
246
|
-
* @param [
|
|
247
|
-
* ID or name of the key-value store to be opened. If
|
|
248
|
-
*
|
|
358
|
+
* @param [identifier]
|
|
359
|
+
* ID or name of the key-value store to be opened. If a string is provided, it will first be
|
|
360
|
+
* looked up as an ID; if no such storage exists, it will be treated as a name.
|
|
361
|
+
* If `null` or `undefined`, the function returns the default key-value store associated with the crawler run.
|
|
249
362
|
* @param [options] Storage manager options.
|
|
250
363
|
*/
|
|
251
|
-
static open(
|
|
364
|
+
static open(identifier?: string | StorageIdentifier | null, options?: StorageOpenOptions): Promise<KeyValueStore>;
|
|
252
365
|
/**
|
|
253
366
|
* Gets a value from the default {@link KeyValueStore} associated with the current crawler run.
|
|
254
367
|
*
|
|
@@ -307,6 +420,19 @@ export declare class KeyValueStore {
|
|
|
307
420
|
* @ignore
|
|
308
421
|
*/
|
|
309
422
|
static getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
423
|
+
/**
|
|
424
|
+
* Reads a record from the default {@link KeyValueStore} associated with the current crawler run
|
|
425
|
+
* without parsing the value.
|
|
426
|
+
*
|
|
427
|
+
* This is just a convenient shortcut for {@link KeyValueStore.getRecord}. Returns `null` if the
|
|
428
|
+
* record does not exist.
|
|
429
|
+
*
|
|
430
|
+
* @param key
|
|
431
|
+
* Unique key of the record. It can be at most 256 characters long and only consist
|
|
432
|
+
* of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
|
|
433
|
+
* @ignore
|
|
434
|
+
*/
|
|
435
|
+
static getRecord(key: string): Promise<KeyValueStoreRawRecord | null>;
|
|
310
436
|
/**
|
|
311
437
|
* Tests whether a record with the given key exists in the default {@link KeyValueStore} associated with the current crawler run.
|
|
312
438
|
* @param key The queried record key.
|
|
@@ -346,26 +472,6 @@ export declare class KeyValueStore {
|
|
|
346
472
|
* @ignore
|
|
347
473
|
*/
|
|
348
474
|
static setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
|
|
349
|
-
/**
|
|
350
|
-
* 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}.
|
|
353
|
-
*
|
|
354
|
-
* Note that the `getInput()` function does not cache the value read from the key-value store.
|
|
355
|
-
* If you need to use the input multiple times in your crawler,
|
|
356
|
-
* it is far more efficient to read it once and store it locally.
|
|
357
|
-
*
|
|
358
|
-
* For more information, see {@link KeyValueStore.open}
|
|
359
|
-
* and {@link KeyValueStore.getValue}.
|
|
360
|
-
*
|
|
361
|
-
* @returns
|
|
362
|
-
* Returns a promise that resolves to an object, string
|
|
363
|
-
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
364
|
-
* on the MIME content type of the record, or `null`
|
|
365
|
-
* if the record is missing.
|
|
366
|
-
* @ignore
|
|
367
|
-
*/
|
|
368
|
-
static getInput<T = Dictionary | string | Buffer>(): Promise<T | null>;
|
|
369
475
|
}
|
|
370
476
|
/**
|
|
371
477
|
* User-function used in the {@link KeyValueStore.forEachKey} method.
|
|
@@ -381,38 +487,29 @@ export interface KeyConsumer {
|
|
|
381
487
|
size: number;
|
|
382
488
|
}): Awaitable<void>;
|
|
383
489
|
}
|
|
490
|
+
/** @internal */
|
|
384
491
|
export interface KeyValueStoreOptions {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
492
|
+
/** Resolved metadata for the key-value store, as returned by the backend's `getMetadata()`. */
|
|
493
|
+
metadata: KeyValueStoreInfo;
|
|
494
|
+
backend: KeyValueStoreBackend;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* A raw, unparsed key-value store record as returned by {@link KeyValueStore.getRecord}: the
|
|
498
|
+
* verbatim bytes plus the content type, with parsing left to the caller.
|
|
499
|
+
*/
|
|
500
|
+
export interface KeyValueStoreRawRecord {
|
|
501
|
+
value: Buffer | ArrayBuffer;
|
|
502
|
+
contentType: string | null;
|
|
389
503
|
}
|
|
390
504
|
export interface RecordOptions {
|
|
391
505
|
/**
|
|
392
506
|
* Specifies a custom MIME content type of the record.
|
|
393
507
|
*/
|
|
394
508
|
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
509
|
}
|
|
404
510
|
export interface KeyValueStoreIteratorOptions {
|
|
405
|
-
/**
|
|
406
|
-
* All keys up to this one (including) are skipped from the result.
|
|
407
|
-
*/
|
|
408
|
-
exclusiveStartKey?: string;
|
|
409
511
|
/**
|
|
410
512
|
* If set, only keys that start with this prefix are returned.
|
|
411
513
|
*/
|
|
412
514
|
prefix?: string;
|
|
413
|
-
/**
|
|
414
|
-
* Collection name to use for listing keys.
|
|
415
|
-
*/
|
|
416
|
-
collection?: string;
|
|
417
515
|
}
|
|
418
|
-
//# sourceMappingURL=key_value_store.d.ts.map
|