@super-protocol/sdk-js 0.15.1 → 0.15.2-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/build/providers/storage/ChunksDownloadDecorator.d.ts +1 -1
- package/build/providers/storage/IStorageProvider.d.ts +1 -1
- package/build/providers/storage/StorageAdapter.d.ts +3 -3
- package/build/providers/storage/StorageAdapter.js +19 -14
- package/build/providers/storage/StorageContentWriter.d.ts +9 -2
- package/build/providers/storage/StorageContentWriter.js +11 -10
- package/build/providers/storage/StorageKeyValueAdapter.d.ts +5 -2
- package/build/providers/storage/StorageKeyValueAdapter.js +15 -10
- package/build/providers/storage/StorageMetadataReader.d.ts +2 -1
- package/build/providers/storage/StorageMetadataReader.js +7 -5
- package/build/providers/storage/StorjAdapter.d.ts +1 -1
- package/build/providers/storage/StorjAdapter.js +15 -4
- package/package.json +1 -1
|
@@ -32,5 +32,5 @@ export declare class DownloadDecorator implements IStorageProvider {
|
|
|
32
32
|
deleteObject(remotePath: string): Promise<void>;
|
|
33
33
|
listObjects(remotePath: string): Promise<StorageObject[]>;
|
|
34
34
|
getObjectSize(remotePath: string): Promise<number>;
|
|
35
|
-
getLastModified(remotePath: string): Promise<Date>;
|
|
35
|
+
getLastModified(remotePath: string): Promise<Date | null>;
|
|
36
36
|
}
|
|
@@ -11,5 +11,5 @@ export default interface IStorageProvider {
|
|
|
11
11
|
deleteObject(remotePath: string): Promise<void>;
|
|
12
12
|
listObjects(remotePath: string): Promise<StorageObject[]>;
|
|
13
13
|
getObjectSize(remotePath: string): Promise<number>;
|
|
14
|
-
getLastModified(remotePath: string): Promise<Date>;
|
|
14
|
+
getLastModified(remotePath: string): Promise<Date | null>;
|
|
15
15
|
}
|
|
@@ -11,17 +11,17 @@ export interface StorageAdapterConfig {
|
|
|
11
11
|
objectDeletedFlag: string;
|
|
12
12
|
readMetadataConcurrency?: number;
|
|
13
13
|
performance?: Performance;
|
|
14
|
+
showLogs?: boolean;
|
|
14
15
|
}
|
|
15
16
|
export declare enum CacheEvents {
|
|
16
|
-
INSTANCES_CHANGED = "
|
|
17
|
+
INSTANCES_CHANGED = "INSTANCES_CHANGED",
|
|
17
18
|
KEY_DELETED = "KEY_DELETED"
|
|
18
19
|
}
|
|
19
20
|
export default class StorageAdapter<V extends object> {
|
|
20
|
-
private readonly logger
|
|
21
|
+
private readonly logger?;
|
|
21
22
|
private readonly storageKeyValueAdapter;
|
|
22
23
|
private readonly cache;
|
|
23
24
|
private readonly encryptionKeys;
|
|
24
|
-
private readonly deleted;
|
|
25
25
|
private readonly contentWriter;
|
|
26
26
|
private readonly metadataReader;
|
|
27
27
|
private readonly instanceId;
|
|
@@ -46,29 +46,29 @@ const logger_1 = __importDefault(require("../../logger"));
|
|
|
46
46
|
const PubSub_1 = __importDefault(require("../../utils/PubSub"));
|
|
47
47
|
var CacheEvents;
|
|
48
48
|
(function (CacheEvents) {
|
|
49
|
-
CacheEvents["INSTANCES_CHANGED"] = "
|
|
49
|
+
CacheEvents["INSTANCES_CHANGED"] = "INSTANCES_CHANGED";
|
|
50
50
|
CacheEvents["KEY_DELETED"] = "KEY_DELETED";
|
|
51
51
|
})(CacheEvents = exports.CacheEvents || (exports.CacheEvents = {}));
|
|
52
52
|
const DEFAULT_READ_METADATA_CONCUREENCY = 16;
|
|
53
53
|
class StorageAdapter {
|
|
54
54
|
constructor(storageAccess, config) {
|
|
55
55
|
this.encryptionKeys = new Map(); // key -> encryption key (base64)
|
|
56
|
-
this.deleted = new Set();
|
|
57
56
|
this.timeout = null;
|
|
58
57
|
this.queues = new Map();
|
|
59
58
|
this.isUpdating = new Map();
|
|
60
59
|
this.pubSub = new PubSub_1.default();
|
|
61
60
|
this.eventName = "storage-adapter";
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const { readInterval, writeInterval, lruCache, objectDeletedFlag, readMetadataConcurrency, performance, showLogs = true, } = config;
|
|
62
|
+
this.logger = showLogs ? logger_1.default.child({ class: StorageAdapter.name }) : null;
|
|
64
63
|
this.performance = performance;
|
|
65
64
|
this.instanceId = this.generateHash();
|
|
66
65
|
this.readInterval = readInterval;
|
|
67
|
-
this.storageKeyValueAdapter = new StorageKeyValueAdapter_1.default(storageAccess);
|
|
66
|
+
this.storageKeyValueAdapter = new StorageKeyValueAdapter_1.default(storageAccess, { showLogs });
|
|
68
67
|
this.cache = new lru_cache_1.LRUCache(lruCache);
|
|
69
68
|
this.metadataReader = new StorageMetadataReader_1.default({
|
|
70
69
|
storageKeyValueAdapter: this.storageKeyValueAdapter,
|
|
71
70
|
objectDeletedFlag,
|
|
71
|
+
showLogs,
|
|
72
72
|
});
|
|
73
73
|
this.contentWriter = new StorageContentWriter_1.default({
|
|
74
74
|
interval: writeInterval,
|
|
@@ -76,6 +76,7 @@ class StorageAdapter {
|
|
|
76
76
|
instanceId: this.instanceId,
|
|
77
77
|
objectDeletedFlag,
|
|
78
78
|
performance: this.performance,
|
|
79
|
+
showLogs,
|
|
79
80
|
});
|
|
80
81
|
this.queueReadMetadata = new p_queue_1.default({
|
|
81
82
|
concurrency: readMetadataConcurrency || DEFAULT_READ_METADATA_CONCUREENCY,
|
|
@@ -123,8 +124,9 @@ class StorageAdapter {
|
|
|
123
124
|
return this.encryptionKeys.get(key) || null;
|
|
124
125
|
}
|
|
125
126
|
set(key, value, encryptionKeyBuffer) {
|
|
127
|
+
var _a;
|
|
126
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
if (this.
|
|
129
|
+
if (((_a = this.contentWriter.storageWrites.get(key)) === null || _a === void 0 ? void 0 : _a.type) === StorageContentWriter_1.ContentWriterType.NEEDS_DELETE) {
|
|
128
130
|
throw new Error("Object has been deleted");
|
|
129
131
|
}
|
|
130
132
|
const encryptionKey = this.getEnryptionKey(key, encryptionKeyBuffer);
|
|
@@ -143,8 +145,8 @@ class StorageAdapter {
|
|
|
143
145
|
this.cache.set(key, instances);
|
|
144
146
|
}
|
|
145
147
|
delete(key) {
|
|
148
|
+
var _a;
|
|
146
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
this.deleted.add(key);
|
|
148
150
|
this.cache.delete(key);
|
|
149
151
|
this.isUpdating.delete(key);
|
|
150
152
|
const encryptionKey = this.getEnryptionKey(key);
|
|
@@ -153,18 +155,19 @@ class StorageAdapter {
|
|
|
153
155
|
this.encryptionKeys.delete(key);
|
|
154
156
|
}
|
|
155
157
|
else {
|
|
156
|
-
this.logger.error(`Encryption key for key ${key} is not set`);
|
|
158
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`Encryption key for key ${key} is not set`);
|
|
157
159
|
}
|
|
158
160
|
this.clearQueue(key);
|
|
159
161
|
});
|
|
160
162
|
}
|
|
161
163
|
// the first value is always the current instance, if key exists
|
|
162
164
|
get(key, encryptionKeyBuffer) {
|
|
163
|
-
var _a;
|
|
165
|
+
var _a, _b;
|
|
164
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
167
|
if (!encryptionKeyBuffer)
|
|
166
168
|
throw new Error("Encryption key required");
|
|
167
|
-
if (this.
|
|
169
|
+
if (((_a = this.contentWriter.storageWrites.get(key)) === null || _a === void 0 ? void 0 : _a.type) === StorageContentWriter_1.ContentWriterType.NEEDS_DELETE ||
|
|
170
|
+
!(yield this.has(key))) {
|
|
168
171
|
return null;
|
|
169
172
|
}
|
|
170
173
|
const encryptionKey = this.getEnryptionKey(key, encryptionKeyBuffer);
|
|
@@ -180,7 +183,7 @@ class StorageAdapter {
|
|
|
180
183
|
const map = this.cache.get(key);
|
|
181
184
|
if (!(map === null || map === void 0 ? void 0 : map.size))
|
|
182
185
|
return null;
|
|
183
|
-
const currentInstance = ((
|
|
186
|
+
const currentInstance = ((_b = map.get(this.instanceId)) === null || _b === void 0 ? void 0 : _b.value) || null;
|
|
184
187
|
const otherInstances = Array.from(map.entries()).reduce((acc, [instanceId, instance]) => {
|
|
185
188
|
return instanceId !== this.instanceId ? [...acc, (instance === null || instance === void 0 ? void 0 : instance.value) || null] : acc;
|
|
186
189
|
}, []);
|
|
@@ -222,7 +225,7 @@ class StorageAdapter {
|
|
|
222
225
|
}
|
|
223
226
|
this.setByInstance(key, instanseId, Object.assign(Object.assign({}, instance), { value: file }));
|
|
224
227
|
})
|
|
225
|
-
.catch((err) => this.logger.error({ err }, "Error fetching content")));
|
|
228
|
+
.catch((err) => { var _a; return (_a = this.logger) === null || _a === void 0 ? void 0 : _a.error({ err }, "Error fetching content"); }));
|
|
226
229
|
}
|
|
227
230
|
});
|
|
228
231
|
yield Promise.all(promises);
|
|
@@ -239,8 +242,10 @@ class StorageAdapter {
|
|
|
239
242
|
}
|
|
240
243
|
}
|
|
241
244
|
checkUpdates(key) {
|
|
245
|
+
var _a, _b;
|
|
242
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
-
if (this.isUpdating.get(key) ||
|
|
247
|
+
if (this.isUpdating.get(key) ||
|
|
248
|
+
((_a = this.contentWriter.storageWrites.get(key)) === null || _a === void 0 ? void 0 : _a.type) === StorageContentWriter_1.ContentWriterType.NEEDS_DELETE) {
|
|
244
249
|
return;
|
|
245
250
|
}
|
|
246
251
|
this.isUpdating.set(key, true);
|
|
@@ -275,7 +280,7 @@ class StorageAdapter {
|
|
|
275
280
|
}
|
|
276
281
|
}
|
|
277
282
|
catch (err) {
|
|
278
|
-
this.logger.error({ err }, "Error checking updates");
|
|
283
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error({ err }, "Error checking updates");
|
|
279
284
|
return;
|
|
280
285
|
}
|
|
281
286
|
finally {
|
|
@@ -9,22 +9,28 @@ export interface StorageContentWriterConfig<V extends object> {
|
|
|
9
9
|
writeContentConcurrency?: number;
|
|
10
10
|
cacheExpirationTs?: number;
|
|
11
11
|
performance?: Performance;
|
|
12
|
+
showLogs?: boolean;
|
|
12
13
|
}
|
|
13
14
|
export declare enum ContentWriterType {
|
|
14
15
|
NEEDS_UPLOAD = "NEEDS_UPLOAD",
|
|
15
16
|
NEEDS_DELETE = "NEEDS_DELETE"
|
|
16
17
|
}
|
|
18
|
+
interface StorageWriteRecord {
|
|
19
|
+
type: ContentWriterType;
|
|
20
|
+
index: number;
|
|
21
|
+
encryptionKey: string;
|
|
22
|
+
}
|
|
17
23
|
export default class StorageContentWriter<K extends string, V extends object> {
|
|
18
24
|
private timeout;
|
|
19
25
|
private readonly INTERVAL;
|
|
20
26
|
private readonly storageKeyValueAdapter;
|
|
21
|
-
private readonly logger
|
|
22
|
-
private readonly storageWrites;
|
|
27
|
+
private readonly logger?;
|
|
23
28
|
private readonly instanceId;
|
|
24
29
|
private readonly cacheExpirationTs;
|
|
25
30
|
private readonly objectDeletedFlag;
|
|
26
31
|
private readonly queueWriteContent;
|
|
27
32
|
private readonly performance?;
|
|
33
|
+
readonly storageWrites: Map<K, StorageWriteRecord>;
|
|
28
34
|
constructor(config: StorageContentWriterConfig<V>);
|
|
29
35
|
private actualizeCacheDelete;
|
|
30
36
|
private actualizeCacheUpload;
|
|
@@ -37,3 +43,4 @@ export default class StorageContentWriter<K extends string, V extends object> {
|
|
|
37
43
|
clear(): void;
|
|
38
44
|
shutdown(cache: LRUCache<K, Map<string, CacheRecord<V>>>): Promise<void>;
|
|
39
45
|
}
|
|
46
|
+
export {};
|
|
@@ -26,8 +26,8 @@ class StorageContentWriter {
|
|
|
26
26
|
constructor(config) {
|
|
27
27
|
this.timeout = null;
|
|
28
28
|
this.storageWrites = new Map();
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const { writeContentConcurrency, interval, storageKeyValueAdapter, instanceId, objectDeletedFlag, cacheExpirationTs, performance, showLogs = true, } = config || {};
|
|
30
|
+
this.logger = showLogs ? logger_1.default.child({ class: StorageContentWriter.name }) : null;
|
|
31
31
|
this.performance = performance;
|
|
32
32
|
this.INTERVAL = interval;
|
|
33
33
|
this.cacheExpirationTs = cacheExpirationTs || DEFAULT_CACHE_EXPIRATION_TS;
|
|
@@ -49,12 +49,12 @@ class StorageContentWriter {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
actualizeCacheUpload(key, encryptionKey, cache) {
|
|
52
|
-
var _a;
|
|
52
|
+
var _a, _b, _c;
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
54
|
const instances = cache.get(key);
|
|
55
55
|
const instance = instances === null || instances === void 0 ? void 0 : instances.get(this.instanceId);
|
|
56
56
|
if (!instances || !instance) {
|
|
57
|
-
|
|
57
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error({
|
|
58
58
|
key,
|
|
59
59
|
instancesSize: instances === null || instances === void 0 ? void 0 : instances.size,
|
|
60
60
|
value: instance,
|
|
@@ -62,19 +62,20 @@ class StorageContentWriter {
|
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if (instance.value) {
|
|
65
|
-
const startUpload = (
|
|
65
|
+
const startUpload = (_b = this.performance) === null || _b === void 0 ? void 0 : _b.now();
|
|
66
66
|
yield this.storageKeyValueAdapter.set(`${key}/${this.instanceId}`, instance.value, encryptionKey);
|
|
67
67
|
if (this.performance && startUpload !== undefined) {
|
|
68
68
|
const finishUpload = this.performance.now();
|
|
69
|
-
|
|
69
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`Uploading took ${(finishUpload - startUpload).toFixed(1)} ms`);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
yield this.deleteOutdatedInstances(key, instances);
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
actualizeCache(cache) {
|
|
76
|
+
var _a;
|
|
76
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const logger = this.logger.child({ method: this.actualizeCache.name });
|
|
78
|
+
const logger = (_a = this.logger) === null || _a === void 0 ? void 0 : _a.child({ method: this.actualizeCache.name });
|
|
78
79
|
if (this.storageWrites.size) {
|
|
79
80
|
Array.from(this.storageWrites.entries()).forEach(([key, { type, index, encryptionKey }]) => {
|
|
80
81
|
this.queueWriteContent.add(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -96,7 +97,7 @@ class StorageContentWriter {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
catch (err) {
|
|
99
|
-
logger.error({
|
|
100
|
+
logger === null || logger === void 0 ? void 0 : logger.error({
|
|
100
101
|
err,
|
|
101
102
|
size: this.storageWrites.size,
|
|
102
103
|
}, `Error storage writing ${key}`);
|
|
@@ -104,7 +105,7 @@ class StorageContentWriter {
|
|
|
104
105
|
}));
|
|
105
106
|
});
|
|
106
107
|
yield this.queueWriteContent.onIdle();
|
|
107
|
-
logger.info({ size: this.storageWrites.size }, "Success storage writing");
|
|
108
|
+
logger === null || logger === void 0 ? void 0 : logger.info({ size: this.storageWrites.size }, "Success storage writing");
|
|
108
109
|
}
|
|
109
110
|
});
|
|
110
111
|
}
|
|
@@ -138,7 +139,7 @@ class StorageContentWriter {
|
|
|
138
139
|
.then(() => {
|
|
139
140
|
instances.delete(instanceId);
|
|
140
141
|
})
|
|
141
|
-
.catch((err) => this.logger.error({ err }, "Error deleting outdated instance"))));
|
|
142
|
+
.catch((err) => { var _a; return (_a = this.logger) === null || _a === void 0 ? void 0 : _a.error({ err }, "Error deleting outdated instance"); })));
|
|
142
143
|
});
|
|
143
144
|
}
|
|
144
145
|
startActualizeCacheTimer(cache) {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Encryption } from "@super-protocol/dto-js";
|
|
2
2
|
import StorageAccess from "../../types/storage/StorageAccess";
|
|
3
3
|
import StorageObject from "../../types/storage/StorageObject";
|
|
4
|
+
export interface StorageKeyValueAdapterConfig {
|
|
5
|
+
showLogs?: boolean;
|
|
6
|
+
}
|
|
4
7
|
export default class StorageKeyValueAdapter<V extends object> {
|
|
5
8
|
private readonly storageProvider;
|
|
6
|
-
private readonly logger
|
|
7
|
-
constructor(storageAccess: StorageAccess);
|
|
9
|
+
private readonly logger?;
|
|
10
|
+
constructor(storageAccess: StorageAccess, config?: StorageKeyValueAdapterConfig);
|
|
8
11
|
decrypt(encryption: Encryption, key: string): Promise<V | null>;
|
|
9
12
|
encrypt(data: V | null, key: string): Promise<Encryption>;
|
|
10
13
|
private downloadFromStorage;
|
|
@@ -18,10 +18,11 @@ const getStorageProvider_1 = __importDefault(require("./getStorageProvider"));
|
|
|
18
18
|
const logger_1 = __importDefault(require("../../logger"));
|
|
19
19
|
const Crypto_1 = __importDefault(require("../../crypto/Crypto"));
|
|
20
20
|
class StorageKeyValueAdapter {
|
|
21
|
-
constructor(storageAccess) {
|
|
21
|
+
constructor(storageAccess, config) {
|
|
22
22
|
if (!(storageAccess === null || storageAccess === void 0 ? void 0 : storageAccess.credentials))
|
|
23
23
|
throw new Error("Credentials is empty");
|
|
24
|
-
|
|
24
|
+
const { showLogs = true } = config || {};
|
|
25
|
+
this.logger = showLogs ? logger_1.default.child({ class: StorageKeyValueAdapter.name }) : null;
|
|
25
26
|
this.storageProvider = (0, getStorageProvider_1.default)(storageAccess);
|
|
26
27
|
}
|
|
27
28
|
decrypt(encryption, key) {
|
|
@@ -65,43 +66,46 @@ class StorageKeyValueAdapter {
|
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
storageUpload(key, value, privateKey) {
|
|
69
|
+
var _a, _b;
|
|
68
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
71
|
try {
|
|
70
72
|
const encryptedValue = yield this.encrypt(value, privateKey);
|
|
71
73
|
const buffer = Buffer.from(JSON.stringify(encryptedValue));
|
|
72
74
|
yield this.storageProvider.uploadFile(stream_1.Readable.from(buffer), key, buffer.byteLength);
|
|
73
|
-
this.logger.info({ data: key }, "Success uploading to storage");
|
|
75
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info({ data: key }, "Success uploading to storage");
|
|
74
76
|
}
|
|
75
77
|
catch (err) {
|
|
76
|
-
this.logger.error({ err }, "Error uploading to storage");
|
|
78
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error({ err }, "Error uploading to storage");
|
|
77
79
|
throw err;
|
|
78
80
|
}
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
83
|
storageDelete(key) {
|
|
84
|
+
var _a, _b;
|
|
82
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
86
|
try {
|
|
84
87
|
yield this.storageProvider.deleteObject(key);
|
|
85
|
-
this.logger.info({ data: key }, "Success deleting from storage");
|
|
88
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info({ data: key }, "Success deleting from storage");
|
|
86
89
|
}
|
|
87
90
|
catch (err) {
|
|
88
|
-
this.logger.info({ err }, "Error deleting from storage");
|
|
91
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info({ err }, "Error deleting from storage");
|
|
89
92
|
throw err;
|
|
90
93
|
}
|
|
91
94
|
});
|
|
92
95
|
}
|
|
93
96
|
storageDownload(key, privateKey) {
|
|
97
|
+
var _a, _b;
|
|
94
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
99
|
try {
|
|
96
100
|
const downloaded = yield this.downloadFromStorage(key);
|
|
97
|
-
this.logger.info({ key }, "Success download data from storage");
|
|
101
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info({ key }, "Success download data from storage");
|
|
98
102
|
if (!downloaded)
|
|
99
103
|
return null;
|
|
100
104
|
const decryptedValue = yield this.decrypt(JSON.parse(downloaded), privateKey);
|
|
101
105
|
return decryptedValue;
|
|
102
106
|
}
|
|
103
107
|
catch (err) {
|
|
104
|
-
this.logger.info({
|
|
108
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info({
|
|
105
109
|
err,
|
|
106
110
|
key,
|
|
107
111
|
}, "Error download data from storage");
|
|
@@ -110,17 +114,18 @@ class StorageKeyValueAdapter {
|
|
|
110
114
|
});
|
|
111
115
|
}
|
|
112
116
|
storageListFiles(key) {
|
|
117
|
+
var _a, _b;
|
|
113
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
119
|
try {
|
|
115
120
|
const listObjects = yield this.storageProvider.listObjects(key);
|
|
116
|
-
this.logger.trace({
|
|
121
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace({
|
|
117
122
|
data: listObjects,
|
|
118
123
|
key,
|
|
119
124
|
}, "Success list objects from storage");
|
|
120
125
|
return listObjects.filter((obj) => !obj.isFolder);
|
|
121
126
|
}
|
|
122
127
|
catch (err) {
|
|
123
|
-
this.logger.info({
|
|
128
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info({
|
|
124
129
|
err,
|
|
125
130
|
key,
|
|
126
131
|
}, "Error list objects from storage");
|
|
@@ -8,9 +8,10 @@ export interface InstancesUpdates {
|
|
|
8
8
|
export interface StorageMetadataReaderConfig<V extends object> {
|
|
9
9
|
storageKeyValueAdapter: StorageKeyValueAdapter<V>;
|
|
10
10
|
objectDeletedFlag: string;
|
|
11
|
+
showLogs?: boolean;
|
|
11
12
|
}
|
|
12
13
|
export default class StorageMetadataReader<K extends string, V extends object> {
|
|
13
|
-
private readonly logger
|
|
14
|
+
private readonly logger?;
|
|
14
15
|
private readonly storageKeyValueAdapter;
|
|
15
16
|
private readonly objectDeletedFlag;
|
|
16
17
|
constructor(config: StorageMetadataReaderConfig<V>);
|
|
@@ -15,9 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const logger_1 = __importDefault(require("../../logger"));
|
|
16
16
|
class StorageMetadataReader {
|
|
17
17
|
constructor(config) {
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
18
|
+
const { showLogs = true, objectDeletedFlag, storageKeyValueAdapter } = config;
|
|
19
|
+
this.logger = showLogs ? logger_1.default.child({ class: StorageMetadataReader.name }) : null;
|
|
20
|
+
this.storageKeyValueAdapter = storageKeyValueAdapter;
|
|
21
|
+
this.objectDeletedFlag = objectDeletedFlag;
|
|
21
22
|
}
|
|
22
23
|
listInstances(key) {
|
|
23
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -27,6 +28,7 @@ class StorageMetadataReader {
|
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
fetchInstancesUpdates(key, currentInstances) {
|
|
31
|
+
var _a, _b;
|
|
30
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
33
|
const result = {
|
|
32
34
|
updated: new Map(),
|
|
@@ -49,14 +51,14 @@ class StorageMetadataReader {
|
|
|
49
51
|
result.deleted.add(instanceId);
|
|
50
52
|
}
|
|
51
53
|
});
|
|
52
|
-
this.logger.trace({
|
|
54
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace({
|
|
53
55
|
updated: result.updated.size,
|
|
54
56
|
deleted: result.deleted.size,
|
|
55
57
|
}, "Check result");
|
|
56
58
|
return result;
|
|
57
59
|
}
|
|
58
60
|
catch (error) {
|
|
59
|
-
this.logger.error({ error }, "Error fetching remote copy");
|
|
61
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error({ error }, "Error fetching remote copy");
|
|
60
62
|
return result;
|
|
61
63
|
}
|
|
62
64
|
});
|
|
@@ -4,7 +4,7 @@ import { StorageAdapterConfig, CacheEvents } from "./StorageAdapter";
|
|
|
4
4
|
export type StorjConfig = StorageAdapterConfig;
|
|
5
5
|
export default class StorjAdapter<V extends object> {
|
|
6
6
|
private storageAdapter;
|
|
7
|
-
private readonly logger
|
|
7
|
+
private readonly logger?;
|
|
8
8
|
constructor(storageAccess: StorageAccess, config: StorjConfig);
|
|
9
9
|
subscribe(cb: (props: {
|
|
10
10
|
type: CacheEvents;
|
|
@@ -16,7 +16,8 @@ const logger_1 = __importDefault(require("../../logger"));
|
|
|
16
16
|
const StorageAdapter_1 = __importDefault(require("./StorageAdapter"));
|
|
17
17
|
class StorjAdapter {
|
|
18
18
|
constructor(storageAccess, config) {
|
|
19
|
-
|
|
19
|
+
const { showLogs = true } = config || {};
|
|
20
|
+
this.logger = showLogs ? logger_1.default.child({ class: StorjAdapter.name }) : null;
|
|
20
21
|
this.storageAdapter = new StorageAdapter_1.default(storageAccess, config);
|
|
21
22
|
this.storageAdapter.run();
|
|
22
23
|
}
|
|
@@ -27,8 +28,10 @@ class StorjAdapter {
|
|
|
27
28
|
get(key, encryptionKey) {
|
|
28
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
30
|
return this.storageAdapter.get(key, encryptionKey).catch((err) => {
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const message = ((_a = err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || "";
|
|
33
|
+
if (message.includes("object not found") || message.includes("object has been deleted")) {
|
|
34
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info({ key }, "Object not found");
|
|
32
35
|
return null;
|
|
33
36
|
}
|
|
34
37
|
throw err;
|
|
@@ -42,7 +45,15 @@ class StorjAdapter {
|
|
|
42
45
|
}
|
|
43
46
|
set(key, value, encryptionKey) {
|
|
44
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
return this.storageAdapter.set(key, value, encryptionKey)
|
|
48
|
+
return this.storageAdapter.set(key, value, encryptionKey).catch((err) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const message = ((_a = err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || "";
|
|
51
|
+
if (message.includes("object has been deleted")) {
|
|
52
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info({ key }, "Object has been deleted");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
throw err;
|
|
56
|
+
});
|
|
46
57
|
});
|
|
47
58
|
}
|
|
48
59
|
del(key) {
|