@crawlee/fs-storage 4.0.0-beta.198 → 4.0.0-beta.200
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/file-system-storage.d.ts +2 -6
- package/file-system-storage.js +26 -26
- package/package.json +4 -4
package/file-system-storage.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface FileSystemStorageOptions {
|
|
|
18
18
|
localDataDirectory: string;
|
|
19
19
|
/**
|
|
20
20
|
* Optional logger for FileSystemStorageBackend warnings.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
21
23
|
*/
|
|
22
24
|
logger?: CrawleeLogger;
|
|
23
25
|
/**
|
|
@@ -47,12 +49,6 @@ export interface FileSystemStorageOptions {
|
|
|
47
49
|
*/
|
|
48
50
|
export declare class FileSystemStorageBackend implements storage.StorageBackend {
|
|
49
51
|
#private;
|
|
50
|
-
readonly localDataDirectory: string;
|
|
51
|
-
readonly datasetsDirectory: string;
|
|
52
|
-
readonly keyValueStoresDirectory: string;
|
|
53
|
-
readonly requestQueuesDirectory: string;
|
|
54
|
-
readonly logger?: CrawleeLogger;
|
|
55
|
-
readonly requestQueueAccess: 'single' | 'shared';
|
|
56
52
|
constructor(options: FileSystemStorageOptions);
|
|
57
53
|
/**
|
|
58
54
|
* Return a cache key that includes the resolved storage directory, so that two
|
package/file-system-storage.js
CHANGED
|
@@ -39,23 +39,23 @@ const ADOPTED_BINARY_CONTENT_TYPE = 'application/octet-stream';
|
|
|
39
39
|
* `teardown` can operate over them), and exposing them through the `@crawlee/types` interfaces.
|
|
40
40
|
*/
|
|
41
41
|
export class FileSystemStorageBackend {
|
|
42
|
-
localDataDirectory;
|
|
43
|
-
datasetsDirectory;
|
|
44
|
-
keyValueStoresDirectory;
|
|
45
|
-
requestQueuesDirectory;
|
|
46
|
-
logger;
|
|
47
|
-
requestQueueAccess;
|
|
42
|
+
#localDataDirectory;
|
|
43
|
+
#datasetsDirectory;
|
|
44
|
+
#keyValueStoresDirectory;
|
|
45
|
+
#requestQueuesDirectory;
|
|
46
|
+
#logger;
|
|
47
|
+
#requestQueueAccess;
|
|
48
48
|
#keyValueStoreBackendCache = [];
|
|
49
49
|
#datasetBackendCache = [];
|
|
50
50
|
#requestQueueBackendCache = [];
|
|
51
51
|
constructor(options) {
|
|
52
52
|
const { logger, requestQueueAccess, localDataDirectory } = parseArgument(options, fileSystemStorageOptionsSchema);
|
|
53
|
-
this
|
|
54
|
-
this
|
|
55
|
-
this
|
|
56
|
-
this
|
|
57
|
-
this
|
|
58
|
-
this
|
|
53
|
+
this.#logger = logger;
|
|
54
|
+
this.#requestQueueAccess = requestQueueAccess;
|
|
55
|
+
this.#localDataDirectory = localDataDirectory;
|
|
56
|
+
this.#datasetsDirectory = resolve(this.#localDataDirectory, 'datasets');
|
|
57
|
+
this.#keyValueStoresDirectory = resolve(this.#localDataDirectory, 'key_value_stores');
|
|
58
|
+
this.#requestQueuesDirectory = resolve(this.#localDataDirectory, 'request_queues');
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Return a cache key that includes the resolved storage directory, so that two
|
|
@@ -63,7 +63,7 @@ export class FileSystemStorageBackend {
|
|
|
63
63
|
* partitions, by including the storage directory in the cache key.
|
|
64
64
|
*/
|
|
65
65
|
getStorageBackendCacheKey() {
|
|
66
|
-
return `FileSystemStorageBackend:${resolve(this
|
|
66
|
+
return `FileSystemStorageBackend:${resolve(this.#localDataDirectory)}`;
|
|
67
67
|
}
|
|
68
68
|
static #resolveStorageKey(options) {
|
|
69
69
|
// No identifier at all means the default storage, which is opened under the reserved alias —
|
|
@@ -86,12 +86,12 @@ export class FileSystemStorageBackend {
|
|
|
86
86
|
if (found) {
|
|
87
87
|
return found;
|
|
88
88
|
}
|
|
89
|
-
const nativeBackend = await (await importNativeModule()).FileSystemDatasetClient.open(id, name, alias, this
|
|
89
|
+
const nativeBackend = await (await importNativeModule()).FileSystemDatasetClient.open(id, name, alias, this.#localDataDirectory);
|
|
90
90
|
const newStore = await DatasetBackend.create({
|
|
91
91
|
name: alias ? undefined : (name ?? cacheKey),
|
|
92
92
|
cacheKey,
|
|
93
93
|
nativeBackend,
|
|
94
|
-
logger: this
|
|
94
|
+
logger: this.#logger,
|
|
95
95
|
});
|
|
96
96
|
this.#datasetBackendCache.push(newStore);
|
|
97
97
|
return newStore;
|
|
@@ -104,14 +104,14 @@ export class FileSystemStorageBackend {
|
|
|
104
104
|
if (found) {
|
|
105
105
|
return found;
|
|
106
106
|
}
|
|
107
|
-
const nativeBackend = await (await importNativeModule()).FileSystemKeyValueStoreClient.open(id, name, alias, this
|
|
107
|
+
const nativeBackend = await (await importNativeModule()).FileSystemKeyValueStoreClient.open(id, name, alias, this.#localDataDirectory,
|
|
108
108
|
// useTestClock — always real wall-clock outside of native tests.
|
|
109
109
|
undefined, this.keyValueStoreAdoptionCandidates({ isDefaultStore: cacheKey === DEFAULT_STORAGE_DIRECTORY }));
|
|
110
110
|
const newStore = await KeyValueStoreBackend.create({
|
|
111
111
|
name: alias ? undefined : (name ?? cacheKey),
|
|
112
112
|
cacheKey,
|
|
113
113
|
nativeBackend,
|
|
114
|
-
logger: this
|
|
114
|
+
logger: this.#logger,
|
|
115
115
|
});
|
|
116
116
|
this.#keyValueStoreBackendCache.push(newStore);
|
|
117
117
|
return newStore;
|
|
@@ -124,14 +124,14 @@ export class FileSystemStorageBackend {
|
|
|
124
124
|
if (found) {
|
|
125
125
|
return found;
|
|
126
126
|
}
|
|
127
|
-
const nativeBackend = await (await importNativeModule()).FileSystemRequestQueueClient.open(id, name, alias, this
|
|
127
|
+
const nativeBackend = await (await importNativeModule()).FileSystemRequestQueueClient.open(id, name, alias, this.#localDataDirectory,
|
|
128
128
|
// useTestClock — always real wall-clock outside of native tests.
|
|
129
|
-
undefined, this
|
|
129
|
+
undefined, this.#requestQueueAccess);
|
|
130
130
|
const newStore = await RequestQueueBackend.create({
|
|
131
131
|
name: alias ? undefined : (name ?? cacheKey),
|
|
132
132
|
cacheKey,
|
|
133
133
|
nativeBackend,
|
|
134
|
-
logger: this
|
|
134
|
+
logger: this.#logger,
|
|
135
135
|
});
|
|
136
136
|
this.#requestQueueBackendCache.push(newStore);
|
|
137
137
|
return newStore;
|
|
@@ -173,15 +173,15 @@ export class FileSystemStorageBackend {
|
|
|
173
173
|
switch (type) {
|
|
174
174
|
case 'Dataset':
|
|
175
175
|
backends = this.#datasetBackendCache;
|
|
176
|
-
baseDir = this
|
|
176
|
+
baseDir = this.#datasetsDirectory;
|
|
177
177
|
break;
|
|
178
178
|
case 'KeyValueStore':
|
|
179
179
|
backends = this.#keyValueStoreBackendCache;
|
|
180
|
-
baseDir = this
|
|
180
|
+
baseDir = this.#keyValueStoresDirectory;
|
|
181
181
|
break;
|
|
182
182
|
case 'RequestQueue':
|
|
183
183
|
backends = this.#requestQueueBackendCache;
|
|
184
|
-
baseDir = this
|
|
184
|
+
baseDir = this.#requestQueuesDirectory;
|
|
185
185
|
break;
|
|
186
186
|
default:
|
|
187
187
|
return false;
|
|
@@ -254,9 +254,9 @@ export class FileSystemStorageBackend {
|
|
|
254
254
|
*/
|
|
255
255
|
async purge() {
|
|
256
256
|
await Promise.all([
|
|
257
|
-
this.#purgeRunScopedStorages(this
|
|
258
|
-
this.#purgeRunScopedStorages(this
|
|
259
|
-
this.#purgeRunScopedStorages(this
|
|
257
|
+
this.#purgeRunScopedStorages(this.#keyValueStoresDirectory, async (alias) => this.createKeyValueStoreBackend({ alias }), async (store, isDefault) => this.purgeKeyValueStore(store, { isDefaultStore: isDefault })),
|
|
258
|
+
this.#purgeRunScopedStorages(this.#datasetsDirectory, async (alias) => this.createDatasetBackend({ alias }), async (store) => store.purge()),
|
|
259
|
+
this.#purgeRunScopedStorages(this.#requestQueuesDirectory, async (alias) => this.createRequestQueueBackend({ alias }), async (store) => store.purge()),
|
|
260
260
|
]);
|
|
261
261
|
}
|
|
262
262
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/fs-storage",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.200",
|
|
4
4
|
"description": "A file-system storage implementation of the Apify API",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@crawlee/fs-storage-native": ">=0.2.2 <0.3",
|
|
46
|
-
"@crawlee/types": "4.0.0-beta.
|
|
47
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
46
|
+
"@crawlee/types": "4.0.0-beta.200",
|
|
47
|
+
"@crawlee/utils": "4.0.0-beta.200",
|
|
48
48
|
"zod": "^4.5.4"
|
|
49
49
|
},
|
|
50
50
|
"lerna": {
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "471663956b78edb995e824dd906776a28cc04535"
|
|
58
58
|
}
|