@crawlee/core 4.0.0-beta.99 → 4.0.0-rc.1
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 +1 -1
- package/configuration.d.ts +16 -47
- package/configuration.js +13 -25
- package/debug.js +4 -4
- package/errors.d.ts +28 -38
- package/errors.js +33 -47
- package/events/event_manager.d.ts +2 -2
- package/events/event_manager.js +7 -6
- package/events/index.d.ts +1 -0
- package/events/local_event_manager.d.ts +1 -8
- package/events/local_event_manager.js +13 -13
- package/events/system_info.d.ts +38 -0
- package/index.d.ts +2 -8
- package/index.js +4 -8
- package/internal.d.ts +8 -0
- package/internal.js +9 -0
- package/log.d.ts +10 -11
- package/log.js +52 -20
- package/memory-storage/memory-storage.d.ts +15 -18
- package/memory-storage/memory-storage.js +80 -58
- package/memory-storage/resource-clients/dataset.d.ts +1 -6
- package/memory-storage/resource-clients/dataset.js +23 -31
- package/memory-storage/resource-clients/key-value-store.d.ts +1 -10
- package/memory-storage/resource-clients/key-value-store.js +43 -67
- package/memory-storage/resource-clients/request-queue.d.ts +1 -42
- package/memory-storage/resource-clients/request-queue.js +109 -117
- package/owned_or_injected.d.ts +1 -3
- package/owned_or_injected.js +17 -17
- package/package.json +17 -20
- package/proxy_configuration.d.ts +21 -26
- package/proxy_configuration.js +35 -25
- package/recoverable_state.d.ts +104 -47
- package/recoverable_state.js +199 -74
- package/request.d.ts +20 -107
- package/request.js +78 -244
- package/serialization.js +17 -16
- package/service_locator.d.ts +22 -10
- package/service_locator.js +59 -48
- package/storages/batched_adds.d.ts +37 -0
- package/storages/batched_adds.js +73 -0
- package/storages/dataset.d.ts +13 -8
- package/storages/dataset.js +149 -40
- package/storages/index.d.ts +4 -4
- package/storages/index.js +2 -4
- package/storages/key_value_store.d.ts +16 -35
- package/storages/key_value_store.js +223 -110
- package/storages/key_value_store_codec.js +6 -11
- package/storages/request_dedup_cache.d.ts +1 -4
- package/storages/request_dedup_cache.js +15 -15
- package/storages/request_list.d.ts +9 -104
- package/storages/request_list.js +236 -233
- package/storages/request_loader.d.ts +49 -18
- package/storages/request_loader.js +36 -1
- package/storages/request_manager.d.ts +86 -0
- package/storages/request_manager_tandem.d.ts +14 -38
- package/storages/request_manager_tandem.js +67 -64
- package/storages/request_queue.d.ts +23 -50
- package/storages/request_queue.js +371 -226
- package/storages/storage_instance_manager.d.ts +2 -4
- package/storages/storage_instance_manager.js +21 -21
- package/storages/storage_stats.d.ts +1 -1
- package/storages/storage_stats.js +4 -4
- package/storages/transaction.d.ts +270 -0
- package/storages/transaction.js +296 -0
- package/storages/utils.d.ts +6 -3
- package/storages/utils.js +11 -2
- package/system-info/runtime.js +7 -7
- package/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +23 -25
- package/validators.js +14 -25
- package/autoscaling/autoscaled_pool.d.ts +0 -213
- package/autoscaling/autoscaled_pool.js +0 -378
- package/autoscaling/client_load_signal.d.ts +0 -59
- package/autoscaling/client_load_signal.js +0 -73
- package/autoscaling/concurrency_system.d.ts +0 -283
- package/autoscaling/concurrency_system.js +0 -350
- package/autoscaling/cpu_load_signal.d.ts +0 -44
- package/autoscaling/cpu_load_signal.js +0 -46
- package/autoscaling/event_loop_load_signal.d.ts +0 -54
- package/autoscaling/event_loop_load_signal.js +0 -60
- package/autoscaling/index.d.ts +0 -9
- package/autoscaling/index.js +0 -9
- package/autoscaling/load_signal.d.ts +0 -99
- package/autoscaling/load_signal.js +0 -103
- package/autoscaling/memory_load_signal.d.ts +0 -56
- package/autoscaling/memory_load_signal.js +0 -106
- package/autoscaling/snapshotter.d.ts +0 -87
- package/autoscaling/snapshotter.js +0 -67
- package/autoscaling/system_status.d.ts +0 -161
- package/autoscaling/system_status.js +0 -139
- package/autoscaling/weighted_avg.d.ts +0 -5
- package/autoscaling/weighted_avg.js +0 -14
- package/cookie_utils.d.ts +0 -44
- package/cookie_utils.js +0 -122
- package/crawlers/context_pipeline.d.ts +0 -70
- package/crawlers/context_pipeline.js +0 -122
- package/crawlers/crawler_commons.d.ts +0 -257
- package/crawlers/crawler_commons.js +0 -107
- package/crawlers/error_snapshotter.d.ts +0 -59
- package/crawlers/error_snapshotter.js +0 -117
- package/crawlers/error_tracker.d.ts +0 -54
- package/crawlers/error_tracker.js +0 -308
- package/crawlers/index.d.ts +0 -5
- package/crawlers/index.js +0 -5
- package/crawlers/internals/types.d.ts +0 -7
- package/crawlers/statistics.d.ts +0 -209
- package/crawlers/statistics.js +0 -350
- package/enqueue_links/enqueue_links.d.ts +0 -264
- package/enqueue_links/enqueue_links.js +0 -271
- package/enqueue_links/index.d.ts +0 -2
- package/enqueue_links/index.js +0 -2
- package/enqueue_links/shared.d.ts +0 -83
- package/enqueue_links/shared.js +0 -221
- package/router.d.ts +0 -309
- package/router.js +0 -309
- package/session_pool/consts.d.ts +0 -3
- package/session_pool/consts.js +0 -3
- package/session_pool/errors.d.ts +0 -7
- package/session_pool/errors.js +0 -11
- package/session_pool/fingerprint.d.ts +0 -9
- package/session_pool/fingerprint.js +0 -30
- package/session_pool/index.d.ts +0 -4
- package/session_pool/index.js +0 -4
- package/session_pool/session.d.ts +0 -161
- package/session_pool/session.js +0 -218
- package/session_pool/session_pool.d.ts +0 -246
- package/session_pool/session_pool.js +0 -386
- package/storages/access_checking.d.ts +0 -12
- package/storages/access_checking.js +0 -17
- package/storages/sitemap_request_loader.d.ts +0 -249
- package/storages/sitemap_request_loader.js +0 -432
- /package/{crawlers/internals/types.js → events/system_info.js} +0 -0
package/service_locator.js
CHANGED
|
@@ -39,16 +39,16 @@ import { StorageInstanceManager } from './storages/storage_instance_manager.js';
|
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
export class ServiceLocator {
|
|
42
|
-
configuration;
|
|
43
|
-
eventManager;
|
|
44
|
-
storageBackend;
|
|
45
|
-
logger;
|
|
42
|
+
#configuration;
|
|
43
|
+
#eventManager;
|
|
44
|
+
#storageBackend;
|
|
45
|
+
#logger;
|
|
46
46
|
/**
|
|
47
47
|
* Unified storage instance manager for Dataset, KeyValueStore, and RequestQueue.
|
|
48
48
|
* Shared across all ServiceLocator instances (global singleton), matching crawlee-python.
|
|
49
49
|
* Per-crawler isolation is achieved via `clientCacheKey`, not separate manager instances.
|
|
50
50
|
*/
|
|
51
|
-
static storageInstanceManager;
|
|
51
|
+
static #storageInstanceManager;
|
|
52
52
|
/**
|
|
53
53
|
* Creates a new ServiceLocator instance.
|
|
54
54
|
*
|
|
@@ -58,61 +58,70 @@ export class ServiceLocator {
|
|
|
58
58
|
* @param logger Optional logger instance to use
|
|
59
59
|
*/
|
|
60
60
|
constructor(configuration, eventManager, storageBackend, logger) {
|
|
61
|
-
this
|
|
62
|
-
this
|
|
63
|
-
this
|
|
64
|
-
this
|
|
61
|
+
this.#configuration = configuration;
|
|
62
|
+
this.#eventManager = eventManager;
|
|
63
|
+
this.#storageBackend = storageBackend;
|
|
64
|
+
this.#logger = logger;
|
|
65
|
+
}
|
|
66
|
+
/** @internal */
|
|
67
|
+
getServicesIfSet() {
|
|
68
|
+
return {
|
|
69
|
+
configuration: this.#configuration,
|
|
70
|
+
eventManager: this.#eventManager,
|
|
71
|
+
storageBackend: this.#storageBackend,
|
|
72
|
+
logger: this.#logger,
|
|
73
|
+
};
|
|
65
74
|
}
|
|
66
75
|
getConfiguration() {
|
|
67
|
-
if (!this
|
|
76
|
+
if (!this.#configuration) {
|
|
68
77
|
this.getLogger().debug('No configuration set, implicitly creating and using default Configuration.');
|
|
69
|
-
this
|
|
78
|
+
this.#configuration = new Configuration();
|
|
70
79
|
}
|
|
71
|
-
return this
|
|
80
|
+
return this.#configuration;
|
|
72
81
|
}
|
|
73
82
|
setConfiguration(configuration) {
|
|
74
83
|
// Same instance, no need to do anything
|
|
75
|
-
if (this
|
|
84
|
+
if (this.#configuration === configuration) {
|
|
76
85
|
return;
|
|
77
86
|
}
|
|
78
87
|
// Already have a different configuration that was retrieved
|
|
79
|
-
if (this
|
|
80
|
-
throw new ServiceConflictError('Configuration', configuration, this
|
|
88
|
+
if (this.#configuration) {
|
|
89
|
+
throw new ServiceConflictError('Configuration', configuration, this.#configuration);
|
|
81
90
|
}
|
|
82
|
-
this
|
|
91
|
+
this.#configuration = configuration;
|
|
83
92
|
}
|
|
84
93
|
getEventManager() {
|
|
85
|
-
if (!this
|
|
94
|
+
if (!this.#eventManager) {
|
|
86
95
|
this.getLogger().debug('No event manager set, implicitly creating and using default LocalEventManager.');
|
|
87
|
-
if (!this
|
|
96
|
+
if (!this.#configuration) {
|
|
88
97
|
this.getLogger().warning('Implicit creation of event manager will implicitly set configuration as side effect. ' +
|
|
89
98
|
'It is advised to explicitly first set the configuration instead.');
|
|
90
99
|
}
|
|
91
|
-
this
|
|
100
|
+
this.#eventManager = LocalEventManager.fromConfiguration(this.getConfiguration());
|
|
92
101
|
}
|
|
93
|
-
return this
|
|
102
|
+
return this.#eventManager;
|
|
94
103
|
}
|
|
95
104
|
setEventManager(eventManager) {
|
|
96
105
|
// Same instance, no need to do anything
|
|
97
|
-
if (this
|
|
106
|
+
if (this.#eventManager === eventManager) {
|
|
98
107
|
return;
|
|
99
108
|
}
|
|
100
109
|
// Already have a different event manager that was retrieved
|
|
101
|
-
if (this
|
|
102
|
-
throw new ServiceConflictError('EventManager', eventManager, this
|
|
110
|
+
if (this.#eventManager) {
|
|
111
|
+
throw new ServiceConflictError('EventManager', eventManager, this.#eventManager);
|
|
103
112
|
}
|
|
104
|
-
this
|
|
113
|
+
this.#eventManager = eventManager;
|
|
105
114
|
}
|
|
106
115
|
getStorageBackend() {
|
|
107
|
-
if (!this
|
|
116
|
+
if (!this.#storageBackend) {
|
|
108
117
|
this.getLogger().debug('No storage backend set, implicitly creating and using the default storage backend ' +
|
|
109
118
|
'(FileSystemStorageBackend when persistStorage is enabled, MemoryStorageBackend otherwise).');
|
|
110
|
-
if (!this
|
|
119
|
+
if (!this.#configuration) {
|
|
111
120
|
this.getLogger().warning('Implicit creation of storage backend will implicitly set configuration as side effect. ' +
|
|
112
121
|
'It is advised to explicitly first set the configuration instead.');
|
|
113
122
|
}
|
|
114
123
|
const configuration = this.getConfiguration();
|
|
115
|
-
this
|
|
124
|
+
this.#storageBackend = configuration.persistStorage
|
|
116
125
|
? new FileSystemStorageBackend({
|
|
117
126
|
localDataDirectory: configuration.storageDir,
|
|
118
127
|
logger: this.getLogger().child({ prefix: 'FileSystemStorageBackend' }),
|
|
@@ -121,50 +130,52 @@ export class ServiceLocator {
|
|
|
121
130
|
logger: this.getLogger().child({ prefix: 'MemoryStorageBackend' }),
|
|
122
131
|
});
|
|
123
132
|
}
|
|
124
|
-
return this
|
|
133
|
+
return this.#storageBackend;
|
|
125
134
|
}
|
|
126
135
|
setStorageBackend(storageBackend) {
|
|
127
136
|
// Same instance, no need to do anything
|
|
128
|
-
if (this
|
|
137
|
+
if (this.#storageBackend === storageBackend) {
|
|
129
138
|
return;
|
|
130
139
|
}
|
|
131
140
|
// Already have a different storage backend that was retrieved
|
|
132
|
-
if (this
|
|
133
|
-
throw new ServiceConflictError('StorageBackend', storageBackend, this
|
|
141
|
+
if (this.#storageBackend) {
|
|
142
|
+
throw new ServiceConflictError('StorageBackend', storageBackend, this.#storageBackend);
|
|
134
143
|
}
|
|
135
|
-
this
|
|
144
|
+
this.#storageBackend = storageBackend;
|
|
136
145
|
}
|
|
137
146
|
getLogger() {
|
|
138
|
-
if (!this
|
|
139
|
-
this
|
|
147
|
+
if (!this.#logger) {
|
|
148
|
+
this.#logger = new ApifyLogAdapter(log);
|
|
140
149
|
}
|
|
141
|
-
return this
|
|
150
|
+
return this.#logger;
|
|
142
151
|
}
|
|
143
152
|
setLogger(logger) {
|
|
144
|
-
if (this
|
|
153
|
+
if (this.#logger === logger) {
|
|
145
154
|
return;
|
|
146
155
|
}
|
|
147
|
-
if (this
|
|
148
|
-
throw new ServiceConflictError('Logger', logger, this
|
|
156
|
+
if (this.#logger) {
|
|
157
|
+
throw new ServiceConflictError('Logger', logger, this.#logger);
|
|
149
158
|
}
|
|
150
|
-
this
|
|
159
|
+
this.#logger = logger;
|
|
151
160
|
}
|
|
152
161
|
getChildLog(prefix) {
|
|
153
162
|
return this.getLogger().child({ prefix });
|
|
154
163
|
}
|
|
164
|
+
/** @internal */
|
|
155
165
|
getStorageInstanceManager() {
|
|
156
|
-
if (!ServiceLocator
|
|
157
|
-
ServiceLocator
|
|
166
|
+
if (!ServiceLocator.#storageInstanceManager) {
|
|
167
|
+
ServiceLocator.#storageInstanceManager = new StorageInstanceManager();
|
|
158
168
|
}
|
|
159
|
-
return ServiceLocator
|
|
169
|
+
return ServiceLocator.#storageInstanceManager;
|
|
160
170
|
}
|
|
171
|
+
/** @internal */
|
|
161
172
|
reset() {
|
|
162
|
-
this
|
|
163
|
-
this
|
|
164
|
-
this
|
|
165
|
-
this
|
|
166
|
-
ServiceLocator
|
|
167
|
-
ServiceLocator
|
|
173
|
+
this.#configuration = undefined;
|
|
174
|
+
this.#eventManager = undefined;
|
|
175
|
+
this.#storageBackend = undefined;
|
|
176
|
+
this.#logger = undefined;
|
|
177
|
+
ServiceLocator.#storageInstanceManager?.clearCache();
|
|
178
|
+
ServiceLocator.#storageInstanceManager = undefined;
|
|
168
179
|
}
|
|
169
180
|
}
|
|
170
181
|
/**
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ProcessedRequest } from '@crawlee/types';
|
|
2
|
+
import type { Source } from '../request.js';
|
|
3
|
+
import type { AddRequestsBatchedResult } from './request_queue.js';
|
|
4
|
+
export interface DrainRequestBatchesOptions<TItem extends Source> {
|
|
5
|
+
/**
|
|
6
|
+
* The requests to add, already normalized by the caller. Consumed lazily: an unbounded or expensive
|
|
7
|
+
* iterable is only pulled from as far as the batching (and any `maxNewRequests` budget) requires.
|
|
8
|
+
*/
|
|
9
|
+
items: AsyncGenerator<TItem>;
|
|
10
|
+
batchSize: number;
|
|
11
|
+
waitBetweenBatchesMillis: number;
|
|
12
|
+
waitForAllRequestsToBeAdded: boolean;
|
|
13
|
+
maxNewRequests?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Adds a single chunk and reports what it processed.
|
|
16
|
+
*
|
|
17
|
+
* @param isInitial Whether this is the first chunk, which is added before this function returns. Later
|
|
18
|
+
* chunks land in the background, which is why some callers cache only the first.
|
|
19
|
+
*/
|
|
20
|
+
processChunk: (chunk: TItem[], isInitial: boolean) => Promise<ProcessedRequest[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Called with the promise covering every chunk after the first, so the caller can keep its own
|
|
23
|
+
* `isFinished` honest while batches are still landing.
|
|
24
|
+
*/
|
|
25
|
+
trackBackgroundBatches?: (batches: Promise<unknown>) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Drives the chunk-by-chunk half of `addRequestsBatched`: the first chunk is added before returning and the
|
|
29
|
+
* rest continue in the background, paced by `waitBetweenBatchesMillis`.
|
|
30
|
+
*
|
|
31
|
+
* Callers differ only in how a chunk is added and how the input is normalized, so that is all
|
|
32
|
+
* {@link DrainRequestBatchesOptions} asks for - the budget arithmetic, the lazy chunking, the
|
|
33
|
+
* over-limit reporting and the transaction handling are identical for everyone and live here. In
|
|
34
|
+
* particular, every caller has to keep its background chunks out of a transaction they will outlive,
|
|
35
|
+
* so that is read from the ambient transaction rather than asked of the caller.
|
|
36
|
+
*/
|
|
37
|
+
export declare function drainRequestBatches<TItem extends Source>(options: DrainRequestBatchesOptions<TItem>): Promise<AddRequestsBatchedResult>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
2
|
+
import { chunkedAsyncIterable, peekableAsyncIterable } from '../iterables.js';
|
|
3
|
+
import { activeStorageTransaction, withDirectStorageAccess } from './transaction.js';
|
|
4
|
+
/**
|
|
5
|
+
* Drives the chunk-by-chunk half of `addRequestsBatched`: the first chunk is added before returning and the
|
|
6
|
+
* rest continue in the background, paced by `waitBetweenBatchesMillis`.
|
|
7
|
+
*
|
|
8
|
+
* Callers differ only in how a chunk is added and how the input is normalized, so that is all
|
|
9
|
+
* {@link DrainRequestBatchesOptions} asks for - the budget arithmetic, the lazy chunking, the
|
|
10
|
+
* over-limit reporting and the transaction handling are identical for everyone and live here. In
|
|
11
|
+
* particular, every caller has to keep its background chunks out of a transaction they will outlive,
|
|
12
|
+
* so that is read from the ambient transaction rather than asked of the caller.
|
|
13
|
+
*/
|
|
14
|
+
export async function drainRequestBatches(options) {
|
|
15
|
+
const { items, batchSize, waitBetweenBatchesMillis, waitForAllRequestsToBeAdded, maxNewRequests, processChunk, trackBackgroundBatches, } = options;
|
|
16
|
+
const deferred = activeStorageTransaction()?.policy.requestQueue === 'deferred';
|
|
17
|
+
let remainingBudget = maxNewRequests ?? Infinity;
|
|
18
|
+
const requestsOverLimit = [];
|
|
19
|
+
// Never hand a chunk more than the budget allows, so an over-large final batch cannot overshoot.
|
|
20
|
+
const effectiveChunkSize = maxNewRequests !== undefined ? () => Math.min(batchSize, remainingBudget) : batchSize;
|
|
21
|
+
const chunks = peekableAsyncIterable(chunkedAsyncIterable(items, effectiveChunkSize));
|
|
22
|
+
const chunksIterator = chunks[Symbol.asyncIterator]();
|
|
23
|
+
const addChunk = async (chunk, isInitial) => {
|
|
24
|
+
const processedRequests = await processChunk(chunk, isInitial);
|
|
25
|
+
if (maxNewRequests !== undefined) {
|
|
26
|
+
remainingBudget -= processedRequests.filter((request) => !request.wasAlreadyPresent).length;
|
|
27
|
+
}
|
|
28
|
+
return processedRequests;
|
|
29
|
+
};
|
|
30
|
+
const buildResult = async (addedRequests, waitForAll) => {
|
|
31
|
+
if (maxNewRequests !== undefined) {
|
|
32
|
+
// `chunkedAsyncIterable` stops pulling once the budget-derived chunk size hits zero, so whatever
|
|
33
|
+
// is left is still sitting in `items` rather than in a chunk we have seen.
|
|
34
|
+
for await (const item of items) {
|
|
35
|
+
requestsOverLimit.push(item);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { addedRequests, waitForAllRequestsToBeAdded: waitForAll, requestsOverLimit };
|
|
39
|
+
};
|
|
40
|
+
const initialChunk = await chunksIterator.peek();
|
|
41
|
+
if (initialChunk === undefined) {
|
|
42
|
+
return buildResult([], Promise.resolve([]));
|
|
43
|
+
}
|
|
44
|
+
const addedRequests = await addChunk(initialChunk, true);
|
|
45
|
+
await chunksIterator.next();
|
|
46
|
+
if ((await chunksIterator.peek()) === undefined) {
|
|
47
|
+
return buildResult(addedRequests, Promise.resolve([]));
|
|
48
|
+
}
|
|
49
|
+
const processRemainingChunks = async () => {
|
|
50
|
+
const added = [];
|
|
51
|
+
for await (const chunk of chunks) {
|
|
52
|
+
added.push(...(await addChunk(chunk, false)));
|
|
53
|
+
// Under `deferred` no chunk performs backend I/O, so pacing them would only stall the handler.
|
|
54
|
+
await sleep(deferred ? 0 : waitBetweenBatchesMillis);
|
|
55
|
+
}
|
|
56
|
+
return added;
|
|
57
|
+
};
|
|
58
|
+
// With a budget we must drain everything before we can report what went over it; under `deferred` a
|
|
59
|
+
// writer that finishes after commit would have nowhere to put its journal entries.
|
|
60
|
+
const awaitsRemainder = waitForAllRequestsToBeAdded || maxNewRequests !== undefined || deferred;
|
|
61
|
+
// An un-awaited writer outlives the transaction scope it inherits, so it must not record into a
|
|
62
|
+
// transaction that may already be closed. It writes directly - its write-through additions were never
|
|
63
|
+
// going to be rolled back anyway - which means the requests it adds are not journaled.
|
|
64
|
+
// See `StorageTransactionView.enqueuedUrls`.
|
|
65
|
+
const remainder = awaitsRemainder ? processRemainingChunks() : withDirectStorageAccess(processRemainingChunks);
|
|
66
|
+
// The caller is not obliged to await `remainder`, so give it a handler of its own - an unhandled
|
|
67
|
+
// rejection here would otherwise take the process down.
|
|
68
|
+
trackBackgroundBatches?.(remainder.catch(() => { }));
|
|
69
|
+
if (awaitsRemainder) {
|
|
70
|
+
addedRequests.push(...(await remainder));
|
|
71
|
+
}
|
|
72
|
+
return buildResult(addedRequests, remainder);
|
|
73
|
+
}
|
package/storages/dataset.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Awaitable, DatasetBackend, DatasetInfo, Dictionary } from '@crawlee/types';
|
|
2
2
|
import { Configuration } from '../configuration.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { JournalEntry } from './transaction.js';
|
|
4
4
|
import type { DatasetStats } from './storage_stats.js';
|
|
5
5
|
import type { StorageOpenOptions } from './utils.js';
|
|
6
6
|
import type { StorageIdentifier } from './storage_instance_manager.js';
|
|
@@ -139,12 +139,11 @@ export interface DatasetExportToOptions extends DatasetExportOptions {
|
|
|
139
139
|
* @category Result Stores
|
|
140
140
|
*/
|
|
141
141
|
export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
142
|
+
#private;
|
|
142
143
|
readonly configuration: Configuration;
|
|
143
|
-
id: string;
|
|
144
|
-
name?: string;
|
|
145
|
-
backend
|
|
146
|
-
log: CrawleeLogger;
|
|
147
|
-
private readonly statsTracker;
|
|
144
|
+
readonly id: string;
|
|
145
|
+
readonly name?: string;
|
|
146
|
+
private readonly backend;
|
|
148
147
|
/**
|
|
149
148
|
* @internal
|
|
150
149
|
*/
|
|
@@ -170,6 +169,8 @@ export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
|
170
169
|
* Returns {@link DatasetContent} object holding the items in the dataset based on the provided parameters.
|
|
171
170
|
*/
|
|
172
171
|
getData(options?: DatasetDataOptions): Promise<DatasetContent<Data>>;
|
|
172
|
+
/** @internal */
|
|
173
|
+
commitJournalEntries(entries: JournalEntry[]): Promise<void>;
|
|
173
174
|
/**
|
|
174
175
|
* Returns all the data from the dataset. This will iterate through the whole dataset
|
|
175
176
|
* via the `listItems()` client method, which gives you only paginated results.
|
|
@@ -312,8 +313,6 @@ export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
|
312
313
|
* @param [options] An object containing extra options for `reduce()`
|
|
313
314
|
*/
|
|
314
315
|
reduce<T>(iteratee: DatasetReducer<T, Data>, memo: T, options?: DatasetIteratorOptions): Promise<T>;
|
|
315
|
-
private fetchEntryPages;
|
|
316
|
-
private fetchPages;
|
|
317
316
|
/**
|
|
318
317
|
* Returns dataset items.
|
|
319
318
|
*
|
|
@@ -380,6 +379,11 @@ export declare class Dataset<Data extends Dictionary = Dictionary> {
|
|
|
380
379
|
* depending on the mode of operation.
|
|
381
380
|
*/
|
|
382
381
|
drop(): Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Removes all items from the dataset but keeps the dataset itself, along with its
|
|
384
|
+
* {@link Dataset.id|`id`} and {@link Dataset.name|`name`}.
|
|
385
|
+
*/
|
|
386
|
+
purge(): Promise<void>;
|
|
383
387
|
/**
|
|
384
388
|
* Opens a dataset and returns a promise resolving to an instance of the {@link Dataset} class.
|
|
385
389
|
*
|
|
@@ -458,6 +462,7 @@ export interface DatasetReducer<T, Data> {
|
|
|
458
462
|
*/
|
|
459
463
|
(memo: T, item: Data, index: number): Awaitable<T>;
|
|
460
464
|
}
|
|
465
|
+
/** @internal */
|
|
461
466
|
export interface DatasetOptions {
|
|
462
467
|
/** Resolved metadata for the dataset, as returned by the backend's `getMetadata()`. */
|
|
463
468
|
metadata: DatasetInfo;
|