@crawlee/memory-storage 3.13.5 → 4.0.0-beta.0
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/background-handler/fs-utils.d.ts +1 -1
- package/background-handler/fs-utils.d.ts.map +1 -1
- package/background-handler/fs-utils.js +17 -23
- package/background-handler/fs-utils.js.map +1 -1
- package/background-handler/index.d.ts +1 -1
- package/background-handler/index.d.ts.map +1 -1
- package/background-handler/index.js +9 -13
- package/background-handler/index.js.map +1 -1
- package/body-parser.js +5 -9
- package/body-parser.js.map +1 -1
- package/cache-helpers.d.ts +4 -4
- package/cache-helpers.d.ts.map +1 -1
- package/cache-helpers.js +43 -49
- package/cache-helpers.js.map +1 -1
- package/consts.js +4 -7
- package/consts.js.map +1 -1
- package/fs/common.js +1 -2
- package/fs/dataset/fs.d.ts +2 -2
- package/fs/dataset/fs.d.ts.map +1 -1
- package/fs/dataset/fs.js +13 -27
- package/fs/dataset/fs.js.map +1 -1
- package/fs/dataset/index.d.ts +1 -1
- package/fs/dataset/index.d.ts.map +1 -1
- package/fs/dataset/index.js +5 -8
- package/fs/dataset/index.js.map +1 -1
- package/fs/dataset/memory.d.ts +1 -1
- package/fs/dataset/memory.d.ts.map +1 -1
- package/fs/dataset/memory.js +2 -13
- package/fs/dataset/memory.js.map +1 -1
- package/fs/key-value-store/fs.d.ts +3 -3
- package/fs/key-value-store/fs.d.ts.map +1 -1
- package/fs/key-value-store/fs.js +27 -62
- package/fs/key-value-store/fs.js.map +1 -1
- package/fs/key-value-store/index.d.ts +2 -2
- package/fs/key-value-store/index.d.ts.map +1 -1
- package/fs/key-value-store/index.js +5 -8
- package/fs/key-value-store/index.js.map +1 -1
- package/fs/key-value-store/memory.d.ts +2 -2
- package/fs/key-value-store/memory.d.ts.map +1 -1
- package/fs/key-value-store/memory.js +2 -13
- package/fs/key-value-store/memory.js.map +1 -1
- package/fs/request-queue/fs.d.ts +3 -3
- package/fs/request-queue/fs.d.ts.map +1 -1
- package/fs/request-queue/fs.js +23 -57
- package/fs/request-queue/fs.js.map +1 -1
- package/fs/request-queue/index.d.ts +2 -2
- package/fs/request-queue/index.d.ts.map +1 -1
- package/fs/request-queue/index.js +5 -8
- package/fs/request-queue/index.js.map +1 -1
- package/fs/request-queue/memory.d.ts +2 -2
- package/fs/request-queue/memory.d.ts.map +1 -1
- package/fs/request-queue/memory.js +3 -19
- package/fs/request-queue/memory.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +1 -4
- package/index.js.map +1 -1
- package/memory-storage.d.ts +3 -3
- package/memory-storage.d.ts.map +1 -1
- package/memory-storage.js +68 -117
- package/memory-storage.js.map +1 -1
- package/package.json +14 -20
- package/resource-clients/common/base-client.d.ts +1 -1
- package/resource-clients/common/base-client.d.ts.map +1 -1
- package/resource-clients/common/base-client.js +2 -11
- package/resource-clients/common/base-client.js.map +1 -1
- package/resource-clients/dataset-collection.d.ts +1 -1
- package/resource-clients/dataset-collection.d.ts.map +1 -1
- package/resource-clients/dataset-collection.js +13 -27
- package/resource-clients/dataset-collection.js.map +1 -1
- package/resource-clients/dataset.d.ts +2 -2
- package/resource-clients/dataset.d.ts.map +1 -1
- package/resource-clients/dataset.js +47 -87
- package/resource-clients/dataset.js.map +1 -1
- package/resource-clients/key-value-store-collection.d.ts +1 -1
- package/resource-clients/key-value-store-collection.d.ts.map +1 -1
- package/resource-clients/key-value-store-collection.js +13 -27
- package/resource-clients/key-value-store-collection.js.map +1 -1
- package/resource-clients/key-value-store.d.ts +2 -2
- package/resource-clients/key-value-store.d.ts.map +1 -1
- package/resource-clients/key-value-store.js +76 -109
- package/resource-clients/key-value-store.js.map +1 -1
- package/resource-clients/request-queue-collection.d.ts +1 -1
- package/resource-clients/request-queue-collection.d.ts.map +1 -1
- package/resource-clients/request-queue-collection.js +13 -27
- package/resource-clients/request-queue-collection.js.map +1 -1
- package/resource-clients/request-queue.d.ts +2 -2
- package/resource-clients/request-queue.d.ts.map +1 -1
- package/resource-clients/request-queue.js +81 -137
- package/resource-clients/request-queue.js.map +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils.js +12 -20
- package/utils.js.map +1 -1
- package/index.mjs +0 -4
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class RequestQueueMemoryEntry {
|
|
5
|
-
constructor() {
|
|
6
|
-
Object.defineProperty(this, "data", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true,
|
|
10
|
-
value: void 0
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(this, "orderNo", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: void 0
|
|
17
|
-
});
|
|
18
|
-
}
|
|
1
|
+
export class RequestQueueMemoryEntry {
|
|
2
|
+
data;
|
|
3
|
+
orderNo;
|
|
19
4
|
async get() {
|
|
20
5
|
return this.data;
|
|
21
6
|
}
|
|
@@ -27,5 +12,4 @@ class RequestQueueMemoryEntry {
|
|
|
27
12
|
// No-op
|
|
28
13
|
}
|
|
29
14
|
}
|
|
30
|
-
exports.RequestQueueMemoryEntry = RequestQueueMemoryEntry;
|
|
31
15
|
//# sourceMappingURL=memory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/fs/request-queue/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/fs/request-queue/memory.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,uBAAuB;IACxB,IAAI,CAAmB;IAExB,OAAO,CAAiB;IAE/B,KAAK,CAAC,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,IAAqB;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAChC,CAAC;IAED,MAAM;QACF,QAAQ;IACZ,CAAC;CACJ"}
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './memory-storage';
|
|
1
|
+
export * from './memory-storage.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
package/index.js
CHANGED
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
package/memory-storage.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type * as storage from '@crawlee/types';
|
|
2
2
|
import type { Dictionary } from '@crawlee/types';
|
|
3
|
-
import { DatasetClient } from './resource-clients/dataset';
|
|
4
|
-
import { KeyValueStoreClient } from './resource-clients/key-value-store';
|
|
5
|
-
import { RequestQueueClient } from './resource-clients/request-queue';
|
|
3
|
+
import { DatasetClient } from './resource-clients/dataset.js';
|
|
4
|
+
import { KeyValueStoreClient } from './resource-clients/key-value-store.js';
|
|
5
|
+
import { RequestQueueClient } from './resource-clients/request-queue.js';
|
|
6
6
|
export interface MemoryStorageOptions {
|
|
7
7
|
/**
|
|
8
8
|
* Path to directory where the data will also be saved.
|
package/memory-storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-storage.d.ts","sourceRoot":"","sources":["../src/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AI,OAAO,CAAC,uBAAuB;IAO3C,OAAO,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC;IAMtF,cAAc,IAAI,OAAO,CAAC,6BAA6B;IAOvD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB;IAMtD,aAAa,IAAI,OAAO,CAAC,4BAA4B;IAOrD,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,OAAO,CAAC,mBAAwB,GAAG,OAAO,CAAC,kBAAkB;IAezF,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,OAAO,CAAC,uBAA4B,GAAG,OAAO,CAAC,IAAI,CAAC;IASrG;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA8C5B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B,OAAO,CAAC,0BAA0B;YA+CpB,gBAAgB;CA0CjC"}
|
package/memory-storage.js
CHANGED
|
@@ -1,92 +1,44 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryStorage = void 0;
|
|
4
1
|
/* eslint-disable import/no-duplicates */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class MemoryStorage {
|
|
2
|
+
import { readdir, rm } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { s } from '@sapphire/shapeshift';
|
|
5
|
+
import { ensureDirSync, move, moveSync, pathExistsSync } from 'fs-extra/esm';
|
|
6
|
+
import { promiseMap } from './background-handler/index.js';
|
|
7
|
+
import { DatasetClient } from './resource-clients/dataset.js';
|
|
8
|
+
import { DatasetCollectionClient } from './resource-clients/dataset-collection.js';
|
|
9
|
+
import { KeyValueStoreClient } from './resource-clients/key-value-store.js';
|
|
10
|
+
import { KeyValueStoreCollectionClient } from './resource-clients/key-value-store-collection.js';
|
|
11
|
+
import { RequestQueueClient } from './resource-clients/request-queue.js';
|
|
12
|
+
import { RequestQueueCollectionClient } from './resource-clients/request-queue-collection.js';
|
|
13
|
+
export class MemoryStorage {
|
|
14
|
+
localDataDirectory;
|
|
15
|
+
datasetsDirectory;
|
|
16
|
+
keyValueStoresDirectory;
|
|
17
|
+
requestQueuesDirectory;
|
|
18
|
+
writeMetadata;
|
|
19
|
+
persistStorage;
|
|
20
|
+
keyValueStoresHandled = [];
|
|
21
|
+
datasetClientsHandled = [];
|
|
22
|
+
requestQueuesHandled = [];
|
|
17
23
|
constructor(options = {}) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "datasetsDirectory", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: void 0
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(this, "keyValueStoresDirectory", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, "requestQueuesDirectory", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(this, "writeMetadata", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: void 0
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(this, "persistStorage", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(this, "keyValueStoresHandled", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true,
|
|
58
|
-
value: []
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(this, "datasetClientsHandled", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
configurable: true,
|
|
63
|
-
writable: true,
|
|
64
|
-
value: []
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(this, "requestQueuesHandled", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: []
|
|
71
|
-
});
|
|
72
|
-
shapeshift_1.s.object({
|
|
73
|
-
localDataDirectory: shapeshift_1.s.string.optional,
|
|
74
|
-
writeMetadata: shapeshift_1.s.boolean.optional,
|
|
75
|
-
persistStorage: shapeshift_1.s.boolean.optional,
|
|
24
|
+
s.object({
|
|
25
|
+
localDataDirectory: s.string().optional(),
|
|
26
|
+
writeMetadata: s.boolean().optional(),
|
|
27
|
+
persistStorage: s.boolean().optional(),
|
|
76
28
|
}).parse(options);
|
|
77
29
|
// v3.0.0 used `crawlee_storage` as the default, we changed this in v3.0.1 to just `storage`,
|
|
78
30
|
// this function handles it without making BC breaks - it respects existing `crawlee_storage`
|
|
79
31
|
// directories, and uses the `storage` only if it's not there.
|
|
80
32
|
const defaultStorageDir = () => {
|
|
81
|
-
if (
|
|
33
|
+
if (pathExistsSync(resolve('./crawlee_storage'))) {
|
|
82
34
|
return './crawlee_storage';
|
|
83
35
|
}
|
|
84
36
|
return './storage';
|
|
85
37
|
};
|
|
86
38
|
this.localDataDirectory = options.localDataDirectory ?? process.env.CRAWLEE_STORAGE_DIR ?? defaultStorageDir();
|
|
87
|
-
this.datasetsDirectory =
|
|
88
|
-
this.keyValueStoresDirectory =
|
|
89
|
-
this.requestQueuesDirectory =
|
|
39
|
+
this.datasetsDirectory = resolve(this.localDataDirectory, 'datasets');
|
|
40
|
+
this.keyValueStoresDirectory = resolve(this.localDataDirectory, 'key_value_stores');
|
|
41
|
+
this.requestQueuesDirectory = resolve(this.localDataDirectory, 'request_queues');
|
|
90
42
|
this.writeMetadata =
|
|
91
43
|
options.writeMetadata ??
|
|
92
44
|
process.env.DEBUG?.includes('*') ??
|
|
@@ -99,38 +51,38 @@ class MemoryStorage {
|
|
|
99
51
|
: true);
|
|
100
52
|
}
|
|
101
53
|
datasets() {
|
|
102
|
-
return new
|
|
54
|
+
return new DatasetCollectionClient({
|
|
103
55
|
baseStorageDirectory: this.datasetsDirectory,
|
|
104
56
|
client: this,
|
|
105
57
|
});
|
|
106
58
|
}
|
|
107
59
|
dataset(id) {
|
|
108
|
-
|
|
109
|
-
return new
|
|
60
|
+
s.string().parse(id);
|
|
61
|
+
return new DatasetClient({ id, baseStorageDirectory: this.datasetsDirectory, client: this });
|
|
110
62
|
}
|
|
111
63
|
keyValueStores() {
|
|
112
|
-
return new
|
|
64
|
+
return new KeyValueStoreCollectionClient({
|
|
113
65
|
baseStorageDirectory: this.keyValueStoresDirectory,
|
|
114
66
|
client: this,
|
|
115
67
|
});
|
|
116
68
|
}
|
|
117
69
|
keyValueStore(id) {
|
|
118
|
-
|
|
119
|
-
return new
|
|
70
|
+
s.string().parse(id);
|
|
71
|
+
return new KeyValueStoreClient({ id, baseStorageDirectory: this.keyValueStoresDirectory, client: this });
|
|
120
72
|
}
|
|
121
73
|
requestQueues() {
|
|
122
|
-
return new
|
|
74
|
+
return new RequestQueueCollectionClient({
|
|
123
75
|
baseStorageDirectory: this.requestQueuesDirectory,
|
|
124
76
|
client: this,
|
|
125
77
|
});
|
|
126
78
|
}
|
|
127
79
|
requestQueue(id, options = {}) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
clientKey:
|
|
131
|
-
timeoutSecs:
|
|
80
|
+
s.string().parse(id);
|
|
81
|
+
s.object({
|
|
82
|
+
clientKey: s.string().optional(),
|
|
83
|
+
timeoutSecs: s.number().optional(),
|
|
132
84
|
}).parse(options);
|
|
133
|
-
return new
|
|
85
|
+
return new RequestQueueClient({
|
|
134
86
|
id,
|
|
135
87
|
baseStorageDirectory: this.requestQueuesDirectory,
|
|
136
88
|
client: this,
|
|
@@ -138,9 +90,9 @@ class MemoryStorage {
|
|
|
138
90
|
});
|
|
139
91
|
}
|
|
140
92
|
async setStatusMessage(message, options = {}) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
isStatusMessageTerminal:
|
|
93
|
+
s.string().parse(message);
|
|
94
|
+
s.object({
|
|
95
|
+
isStatusMessageTerminal: s.boolean().optional(),
|
|
144
96
|
}).parse(options);
|
|
145
97
|
return Promise.resolve();
|
|
146
98
|
}
|
|
@@ -152,32 +104,32 @@ class MemoryStorage {
|
|
|
152
104
|
*/
|
|
153
105
|
async purge() {
|
|
154
106
|
// Key-value stores
|
|
155
|
-
const keyValueStores = await
|
|
107
|
+
const keyValueStores = await readdir(this.keyValueStoresDirectory).catch(() => []);
|
|
156
108
|
const keyValueStorePromises = [];
|
|
157
109
|
for (const keyValueStoreFolder of keyValueStores) {
|
|
158
110
|
if (keyValueStoreFolder.startsWith('__CRAWLEE_TEMPORARY') || keyValueStoreFolder.startsWith('__OLD')) {
|
|
159
|
-
keyValueStorePromises.push((await this.batchRemoveFiles(
|
|
111
|
+
keyValueStorePromises.push((await this.batchRemoveFiles(resolve(this.keyValueStoresDirectory, keyValueStoreFolder)))());
|
|
160
112
|
}
|
|
161
113
|
else if (keyValueStoreFolder === 'default') {
|
|
162
|
-
keyValueStorePromises.push(this.handleDefaultKeyValueStore(
|
|
114
|
+
keyValueStorePromises.push(this.handleDefaultKeyValueStore(resolve(this.keyValueStoresDirectory, keyValueStoreFolder))());
|
|
163
115
|
}
|
|
164
116
|
}
|
|
165
117
|
void Promise.allSettled(keyValueStorePromises);
|
|
166
118
|
// Datasets
|
|
167
|
-
const datasets = await
|
|
119
|
+
const datasets = await readdir(this.datasetsDirectory).catch(() => []);
|
|
168
120
|
const datasetPromises = [];
|
|
169
121
|
for (const datasetFolder of datasets) {
|
|
170
122
|
if (datasetFolder === 'default' || datasetFolder.startsWith('__CRAWLEE_TEMPORARY')) {
|
|
171
|
-
datasetPromises.push((await this.batchRemoveFiles(
|
|
123
|
+
datasetPromises.push((await this.batchRemoveFiles(resolve(this.datasetsDirectory, datasetFolder)))());
|
|
172
124
|
}
|
|
173
125
|
}
|
|
174
126
|
void Promise.allSettled(datasetPromises);
|
|
175
127
|
// Request queues
|
|
176
|
-
const requestQueues = await
|
|
128
|
+
const requestQueues = await readdir(this.requestQueuesDirectory).catch(() => []);
|
|
177
129
|
const requestQueuePromises = [];
|
|
178
130
|
for (const requestQueueFolder of requestQueues) {
|
|
179
131
|
if (requestQueueFolder === 'default' || requestQueueFolder.startsWith('__CRAWLEE_TEMPORARY')) {
|
|
180
|
-
requestQueuePromises.push((await this.batchRemoveFiles(
|
|
132
|
+
requestQueuePromises.push((await this.batchRemoveFiles(resolve(this.requestQueuesDirectory, requestQueueFolder)))());
|
|
181
133
|
}
|
|
182
134
|
}
|
|
183
135
|
void Promise.allSettled(requestQueuePromises);
|
|
@@ -186,23 +138,23 @@ class MemoryStorage {
|
|
|
186
138
|
* This method should be called at the end of the process, to ensure all data is saved.
|
|
187
139
|
*/
|
|
188
140
|
async teardown() {
|
|
189
|
-
const promises = [...
|
|
141
|
+
const promises = [...promiseMap.values()].map(async ({ promise }) => promise);
|
|
190
142
|
await Promise.all(promises);
|
|
191
143
|
}
|
|
192
144
|
handleDefaultKeyValueStore(folder) {
|
|
193
|
-
const storagePathExists =
|
|
194
|
-
const temporaryPath =
|
|
145
|
+
const storagePathExists = pathExistsSync(folder);
|
|
146
|
+
const temporaryPath = resolve(folder, '../__CRAWLEE_MIGRATING_KEY_VALUE_STORE__');
|
|
195
147
|
// For optimization, we want to only attempt to copy a few files from the default key-value store
|
|
196
148
|
const possibleInputKeys = ['INPUT', 'INPUT.json', 'INPUT.bin', 'INPUT.txt'];
|
|
197
149
|
if (storagePathExists) {
|
|
198
150
|
// Create temporary folder to save important files in
|
|
199
|
-
|
|
151
|
+
ensureDirSync(temporaryPath);
|
|
200
152
|
// Go through each file and save the ones that are important
|
|
201
153
|
for (const entity of possibleInputKeys) {
|
|
202
|
-
const originalFilePath =
|
|
203
|
-
const tempFilePath =
|
|
154
|
+
const originalFilePath = resolve(folder, entity);
|
|
155
|
+
const tempFilePath = resolve(temporaryPath, entity);
|
|
204
156
|
try {
|
|
205
|
-
|
|
157
|
+
moveSync(originalFilePath, tempFilePath);
|
|
206
158
|
}
|
|
207
159
|
catch {
|
|
208
160
|
// Ignore
|
|
@@ -210,31 +162,31 @@ class MemoryStorage {
|
|
|
210
162
|
}
|
|
211
163
|
// Remove the original folder and all its content
|
|
212
164
|
let counter = 0;
|
|
213
|
-
let tempPathForOldFolder =
|
|
165
|
+
let tempPathForOldFolder = resolve(folder, `../__OLD_DEFAULT_${counter}__`);
|
|
214
166
|
let done = false;
|
|
215
167
|
while (!done) {
|
|
216
168
|
try {
|
|
217
|
-
|
|
169
|
+
moveSync(folder, tempPathForOldFolder);
|
|
218
170
|
done = true;
|
|
219
171
|
}
|
|
220
172
|
catch {
|
|
221
|
-
tempPathForOldFolder =
|
|
173
|
+
tempPathForOldFolder = resolve(folder, `../__OLD_DEFAULT_${++counter}__`);
|
|
222
174
|
}
|
|
223
175
|
}
|
|
224
176
|
// Replace the temporary folder with the original folder
|
|
225
|
-
|
|
177
|
+
moveSync(temporaryPath, folder);
|
|
226
178
|
// Remove the old folder
|
|
227
179
|
return async () => (await this.batchRemoveFiles(tempPathForOldFolder))();
|
|
228
180
|
}
|
|
229
181
|
return async () => Promise.resolve();
|
|
230
182
|
}
|
|
231
183
|
async batchRemoveFiles(folder, counter = 0) {
|
|
232
|
-
const folderExists =
|
|
184
|
+
const folderExists = pathExistsSync(folder);
|
|
233
185
|
if (folderExists) {
|
|
234
|
-
const temporaryFolder =
|
|
186
|
+
const temporaryFolder = resolve(folder, `../__CRAWLEE_TEMPORARY_${counter}__`);
|
|
235
187
|
try {
|
|
236
188
|
// Rename the old folder to the new one to allow background deletions
|
|
237
|
-
await
|
|
189
|
+
await move(folder, temporaryFolder);
|
|
238
190
|
}
|
|
239
191
|
catch {
|
|
240
192
|
// Folder exists already, try again with an incremented counter
|
|
@@ -242,12 +194,12 @@ class MemoryStorage {
|
|
|
242
194
|
}
|
|
243
195
|
return async () => {
|
|
244
196
|
// Read all files in the folder
|
|
245
|
-
const entries = await
|
|
197
|
+
const entries = await readdir(temporaryFolder);
|
|
246
198
|
let processed = 0;
|
|
247
199
|
let promises = [];
|
|
248
200
|
for (const entry of entries) {
|
|
249
201
|
processed++;
|
|
250
|
-
promises.push(
|
|
202
|
+
promises.push(rm(resolve(temporaryFolder, entry), { force: true }));
|
|
251
203
|
// Every 2000 files, delete them
|
|
252
204
|
if (processed % 2000 === 0) {
|
|
253
205
|
await Promise.allSettled(promises);
|
|
@@ -257,11 +209,10 @@ class MemoryStorage {
|
|
|
257
209
|
// Ensure last promises are handled
|
|
258
210
|
await Promise.allSettled(promises);
|
|
259
211
|
// Delete the folder itself
|
|
260
|
-
await
|
|
212
|
+
await rm(temporaryFolder, { force: true, recursive: true });
|
|
261
213
|
};
|
|
262
214
|
}
|
|
263
215
|
return async () => Promise.resolve();
|
|
264
216
|
}
|
|
265
217
|
}
|
|
266
|
-
exports.MemoryStorage = MemoryStorage;
|
|
267
218
|
//# sourceMappingURL=memory-storage.js.map
|
package/memory-storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-storage.js","sourceRoot":"","sources":["../src/memory-storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory-storage.js","sourceRoot":"","sources":["../src/memory-storage.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO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AChE,CAAC,CAAC;QACN,CAAC;QAED,OAAO,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACzC,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/memory-storage",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
4
4
|
"description": "A simple in-memory storage implementation of the Apify API",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=22.0.0"
|
|
7
7
|
},
|
|
8
|
-
"
|
|
9
|
-
"module": "./index.mjs",
|
|
10
|
-
"types": "./index.d.ts",
|
|
8
|
+
"type": "module",
|
|
11
9
|
"exports": {
|
|
12
|
-
".":
|
|
13
|
-
"import": "./index.mjs",
|
|
14
|
-
"require": "./index.js",
|
|
15
|
-
"types": "./index.d.ts"
|
|
16
|
-
},
|
|
10
|
+
".": "./index.js",
|
|
17
11
|
"./package.json": "./package.json"
|
|
18
12
|
},
|
|
19
13
|
"keywords": [
|
|
@@ -41,23 +35,23 @@
|
|
|
41
35
|
"scripts": {
|
|
42
36
|
"build": "yarn clean && yarn compile && yarn copy",
|
|
43
37
|
"clean": "rimraf ./dist",
|
|
44
|
-
"compile": "tsc -p tsconfig.build.json
|
|
38
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
45
39
|
"copy": "tsx ../../scripts/copy.ts"
|
|
46
40
|
},
|
|
47
41
|
"publishConfig": {
|
|
48
42
|
"access": "public"
|
|
49
43
|
},
|
|
50
44
|
"dependencies": {
|
|
51
|
-
"@apify/log": "^2.
|
|
52
|
-
"@crawlee/types": "
|
|
53
|
-
"@sapphire/async-queue": "^1.5.
|
|
54
|
-
"@sapphire/shapeshift": "^
|
|
55
|
-
"content-type": "^1.0.
|
|
56
|
-
"fs-extra": "^11.
|
|
45
|
+
"@apify/log": "^2.5.18",
|
|
46
|
+
"@crawlee/types": "4.0.0-beta.0",
|
|
47
|
+
"@sapphire/async-queue": "^1.5.5",
|
|
48
|
+
"@sapphire/shapeshift": "^4.0.0",
|
|
49
|
+
"content-type": "^1.0.5",
|
|
50
|
+
"fs-extra": "^11.3.0",
|
|
57
51
|
"json5": "^2.2.3",
|
|
58
|
-
"mime-types": "^
|
|
52
|
+
"mime-types": "^3.0.1",
|
|
59
53
|
"proper-lockfile": "^4.1.2",
|
|
60
|
-
"tslib": "^2.
|
|
54
|
+
"tslib": "^2.8.1"
|
|
61
55
|
},
|
|
62
56
|
"lerna": {
|
|
63
57
|
"command": {
|
|
@@ -66,5 +60,5 @@
|
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
},
|
|
69
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "927bdafa403ff347327158b01d20b817378168a7"
|
|
70
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-client.d.ts","sourceRoot":"","sources":["../../../src/resource-clients/common/base-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"base-client.d.ts","sourceRoot":"","sources":["../../../src/resource-clients/common/base-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,qBAAa,UAAU;IACnB,EAAE,EAAE,MAAM,CAAC;gBAEC,EAAE,EAAE,MAAM;IAItB,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,YAAY,GAAG,KAAK;IAI7D,SAAS,CAAC,qBAAqB,CAAC,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK;CAGnG"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BaseClient = void 0;
|
|
4
|
-
class BaseClient {
|
|
1
|
+
export class BaseClient {
|
|
2
|
+
id;
|
|
5
3
|
constructor(id) {
|
|
6
|
-
Object.defineProperty(this, "id", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true,
|
|
10
|
-
value: void 0
|
|
11
|
-
});
|
|
12
4
|
this.id = id;
|
|
13
5
|
}
|
|
14
6
|
throwOnNonExisting(clientType) {
|
|
@@ -18,5 +10,4 @@ class BaseClient {
|
|
|
18
10
|
throw new Error(`${clientType} with ${keyName}: ${value} already exists.`);
|
|
19
11
|
}
|
|
20
12
|
}
|
|
21
|
-
exports.BaseClient = BaseClient;
|
|
22
13
|
//# sourceMappingURL=base-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-client.js","sourceRoot":"","sources":["../../../src/resource-clients/common/base-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-client.js","sourceRoot":"","sources":["../../../src/resource-clients/common/base-client.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,UAAU;IACnB,EAAE,CAAS;IAEX,YAAY,EAAU;QAClB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;IAES,kBAAkB,CAAC,UAAwB;QACjD,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,aAAa,IAAI,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACzE,CAAC;IAES,qBAAqB,CAAC,UAAwB,EAAE,OAAe,EAAE,KAAa;QACpF,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,SAAS,OAAO,KAAK,KAAK,kBAAkB,CAAC,CAAC;IAC/E,CAAC;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataset-collection.d.ts","sourceRoot":"","sources":["../../src/resource-clients/dataset-collection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAK/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dataset-collection.d.ts","sourceRoot":"","sources":["../../src/resource-clients/dataset-collection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAK/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,MAAM,WAAW,8BAA8B;IAC3C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,aAAa,CAAC;CACzB;AAED,qBAAa,uBAAwB,YAAW,OAAO,CAAC,uBAAuB;IAC3E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,EAAE,oBAAoB,EAAE,MAAM,EAAE,EAAE,8BAA8B;IAKtE,IAAI,IAAI,UAAU,CAAC,OAAO,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAa3D,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;CA6BjE"}
|
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class DatasetCollectionClient {
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { s } from '@sapphire/shapeshift';
|
|
3
|
+
import { scheduleBackgroundTask } from '../background-handler/index.js';
|
|
4
|
+
import { findOrCacheDatasetByPossibleId } from '../cache-helpers.js';
|
|
5
|
+
import { DatasetClient } from './dataset.js';
|
|
6
|
+
export class DatasetCollectionClient {
|
|
7
|
+
datasetsDirectory;
|
|
8
|
+
client;
|
|
10
9
|
constructor({ baseStorageDirectory, client }) {
|
|
11
|
-
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: void 0
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(this, "client", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: void 0
|
|
22
|
-
});
|
|
23
|
-
this.datasetsDirectory = (0, node_path_1.resolve)(baseStorageDirectory);
|
|
10
|
+
this.datasetsDirectory = resolve(baseStorageDirectory);
|
|
24
11
|
this.client = client;
|
|
25
12
|
}
|
|
26
13
|
async list() {
|
|
@@ -36,18 +23,18 @@ class DatasetCollectionClient {
|
|
|
36
23
|
};
|
|
37
24
|
}
|
|
38
25
|
async getOrCreate(name) {
|
|
39
|
-
|
|
26
|
+
s.string().optional().parse(name);
|
|
40
27
|
if (name) {
|
|
41
|
-
const found = await
|
|
28
|
+
const found = await findOrCacheDatasetByPossibleId(this.client, name);
|
|
42
29
|
if (found) {
|
|
43
30
|
return found.toDatasetInfo();
|
|
44
31
|
}
|
|
45
32
|
}
|
|
46
|
-
const newStore = new
|
|
33
|
+
const newStore = new DatasetClient({ name, baseStorageDirectory: this.datasetsDirectory, client: this.client });
|
|
47
34
|
this.client.datasetClientsHandled.push(newStore);
|
|
48
35
|
// Schedule the worker to write to the disk
|
|
49
36
|
const datasetInfo = newStore.toDatasetInfo();
|
|
50
|
-
|
|
37
|
+
scheduleBackgroundTask({
|
|
51
38
|
action: 'update-metadata',
|
|
52
39
|
entityType: 'datasets',
|
|
53
40
|
entityDirectory: newStore.datasetDirectory,
|
|
@@ -59,5 +46,4 @@ class DatasetCollectionClient {
|
|
|
59
46
|
return datasetInfo;
|
|
60
47
|
}
|
|
61
48
|
}
|
|
62
|
-
exports.DatasetCollectionClient = DatasetCollectionClient;
|
|
63
49
|
//# sourceMappingURL=dataset-collection.js.map
|