core-3nweb-client-lib 0.53.7 → 0.53.8
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.
|
@@ -637,7 +637,8 @@ declare namespace web3n.files {
|
|
|
637
637
|
status(skipServerCheck?: boolean): Promise<SyncStatus>;
|
|
638
638
|
|
|
639
639
|
/**
|
|
640
|
-
* Returns a state of on-disk cache
|
|
640
|
+
* Returns a state of on-disk cache of file, also checking on-disk state of base version(s), when
|
|
641
|
+
* given one has it.
|
|
641
642
|
* @param version
|
|
642
643
|
*/
|
|
643
644
|
isRemoteVersionOnDisk(
|
|
@@ -1438,7 +1439,8 @@ declare namespace web3n.files {
|
|
|
1438
1439
|
status(path: string, skipServerCheck?: boolean): Promise<SyncStatus>;
|
|
1439
1440
|
|
|
1440
1441
|
/**
|
|
1441
|
-
* Returns a state of on-disk cache of an item in fs
|
|
1442
|
+
* Returns a state of on-disk cache of an item in fs, also checking on-disk state of base version(s), when
|
|
1443
|
+
* given one has it.
|
|
1442
1444
|
* @param version
|
|
1443
1445
|
*/
|
|
1444
1446
|
isRemoteVersionOnDisk(path: string, version: number): Promise<'partial'|'complete'|'none'>;
|
|
@@ -191,19 +191,19 @@ class SyncedObj {
|
|
|
191
191
|
this.scheduleGC = scheduleGC;
|
|
192
192
|
this.remoteVers = (0, timed_cache_1.makeTimedCache)(60 * 1000);
|
|
193
193
|
this.localVers = (0, timed_cache_1.makeTimedCache)(60 * 1000);
|
|
194
|
-
this.localAndSyncedObjSegsGetterFromDisk = async (v, ofs, len) => {
|
|
194
|
+
this.localAndSyncedObjSegsGetterFromDisk = async (v, ofs, len, infoOnly) => {
|
|
195
195
|
const latestSynced = this.status.latestSyncedVersion();
|
|
196
196
|
if (latestSynced && (latestSynced >= v)) {
|
|
197
|
-
return this.remoteObjSegsGetterFromDisk(v, ofs, len);
|
|
197
|
+
return this.remoteObjSegsGetterFromDisk(v, ofs, len, infoOnly);
|
|
198
198
|
}
|
|
199
199
|
let objVer = this.localVers.get(v);
|
|
200
200
|
if (!objVer) {
|
|
201
201
|
objVer = await obj_on_disk_1.ObjOnDisk.forExistingFile(this.objId, v, this.localVerPath(v), this.downloader, this.localAndSyncedObjSegsGetterFromDisk);
|
|
202
202
|
this.localVers.set(v, objVer);
|
|
203
203
|
}
|
|
204
|
-
return objVer.readSegsOnlyFromDisk(ofs, len);
|
|
204
|
+
return (infoOnly ? objVer.getSegsInfo(ofs, len) : objVer.readSegsOnlyFromDisk(ofs, len));
|
|
205
205
|
};
|
|
206
|
-
this.remoteObjSegsGetterFromDisk = async (v, ofs, len) => {
|
|
206
|
+
this.remoteObjSegsGetterFromDisk = async (v, ofs, len, infoOnly) => {
|
|
207
207
|
let objVer = this.remoteVers.get(v);
|
|
208
208
|
if (!objVer) {
|
|
209
209
|
try {
|
|
@@ -218,7 +218,7 @@ class SyncedObj {
|
|
|
218
218
|
return [{ type: 'new', thisVerOfs: ofs, len }];
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
return objVer.readSegsOnlyFromDisk(ofs, len);
|
|
221
|
+
return (infoOnly ? objVer.getSegsInfo(ofs, len) : objVer.readSegsOnlyFromDisk(ofs, len));
|
|
222
222
|
};
|
|
223
223
|
Object.freeze(this);
|
|
224
224
|
}
|
|
@@ -412,7 +412,8 @@ class SyncedObj {
|
|
|
412
412
|
return 'none';
|
|
413
413
|
}
|
|
414
414
|
const objVer = await this.instanceOfRemoteObjVer(version);
|
|
415
|
-
|
|
415
|
+
const segsNotInVerFiles = await objVer.segsNotInVersionFiles();
|
|
416
|
+
return ((segsNotInVerFiles.length > 0) ? 'partial' : 'complete');
|
|
416
417
|
}
|
|
417
418
|
async getNumOfBytesNeedingDownload(version) {
|
|
418
419
|
if (!this.status.isAmongRemoteOrSynced(version)) {
|
|
@@ -428,11 +429,11 @@ class SyncedObj {
|
|
|
428
429
|
return 'unknown';
|
|
429
430
|
}
|
|
430
431
|
const objVer = await this.instanceOfRemoteObjVer(version);
|
|
431
|
-
return objVer.numOfBytesNeedingDownload();
|
|
432
|
+
return await objVer.numOfBytesNeedingDownload();
|
|
432
433
|
}
|
|
433
434
|
async startDownloadProcess(version, eventSink) {
|
|
434
435
|
const objVer = await this.instanceOfRemoteObjVer(version);
|
|
435
|
-
const downloadTaskId = objVer.startDownloadInBackground(eventSink);
|
|
436
|
+
const downloadTaskId = await objVer.startDownloadInBackground(eventSink);
|
|
436
437
|
return (downloadTaskId ? { downloadTaskId } : undefined);
|
|
437
438
|
}
|
|
438
439
|
}
|
|
@@ -3,9 +3,16 @@ import { ObjSource, Subscribe, Layout } from 'xsp-files';
|
|
|
3
3
|
import { FileWrite } from './file-writing-proc';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
5
|
import { ObjVersionFile } from '../../lib-common/objs-on-disk/obj-version-file';
|
|
6
|
-
import { NotOnDiskFiniteChunk, FiniteChunk } from '../../lib-common/objs-on-disk/file-layout';
|
|
6
|
+
import { NotOnDiskFiniteChunk, BaseSegsChunk, FiniteChunk, OnDiskChunk, NewSegsChunk } from '../../lib-common/objs-on-disk/file-layout';
|
|
7
7
|
import { DiffInfo } from '../../lib-common/service-api/3nstorage/owner';
|
|
8
|
-
export type GetBaseSegsOnDisk = (version: number, ofs: number, len: number) => Promise<(Uint8Array |
|
|
8
|
+
export type GetBaseSegsOnDisk = (version: number, ofs: number, len: number, onlyInfo: boolean) => Promise<(Uint8Array | SegsChunkPlaceInfo)[]>;
|
|
9
|
+
export type SegsChunkPlaceInfo = OnDiskChunk | ChunkInBaseFiles | NewSegsChunk | BaseSegsChunk;
|
|
10
|
+
export interface ChunkInBaseFiles {
|
|
11
|
+
type: 'base-in-files';
|
|
12
|
+
thisVerOfs: number;
|
|
13
|
+
len: number;
|
|
14
|
+
baseVerOfs: number;
|
|
15
|
+
}
|
|
9
16
|
export declare class ObjOnDisk {
|
|
10
17
|
readonly objId: ObjId;
|
|
11
18
|
readonly version: number;
|
|
@@ -32,6 +39,8 @@ export declare class ObjOnDisk {
|
|
|
32
39
|
private readSegs;
|
|
33
40
|
private downloads;
|
|
34
41
|
readSegsOnlyFromDisk(offset: number, len: number): Promise<(Uint8Array | NotOnDiskFiniteChunk)[]>;
|
|
42
|
+
private getBaseSegsOrInfo;
|
|
43
|
+
getSegsInfo(offset: number, len: number): Promise<SegsChunkPlaceInfo[]>;
|
|
35
44
|
private readBaseBytesFromOtherFilesOnDisk;
|
|
36
45
|
getSrc(): ObjSource;
|
|
37
46
|
getBaseVersion(): number | undefined;
|
|
@@ -40,24 +49,23 @@ export declare class ObjOnDisk {
|
|
|
40
49
|
diff: DiffInfo;
|
|
41
50
|
newSegsPackOrder: FiniteChunk[];
|
|
42
51
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
startDownloadInBackground(eventSink: DownloadEventSink): number | undefined;
|
|
52
|
+
segsNotInVersionFiles(): Promise<NotOnDiskFiniteChunk[]>;
|
|
53
|
+
numOfBytesNeedingDownload(): Promise<number>;
|
|
54
|
+
startDownloadInBackground(eventSink: DownloadEventSink): Promise<number | undefined>;
|
|
47
55
|
}
|
|
48
56
|
export declare class Download {
|
|
49
57
|
readonly objId: ObjId;
|
|
50
58
|
readonly version: number;
|
|
51
59
|
private readonly downloader;
|
|
52
60
|
saveSegs?: ObjVersionFile["saveSegs"] | undefined;
|
|
53
|
-
|
|
61
|
+
segsNotInVersionFiles?: ObjOnDisk["segsNotInVersionFiles"] | undefined;
|
|
54
62
|
private readonly segsAsapRequest;
|
|
55
63
|
private initDataRequest;
|
|
56
64
|
private inBkgrnd;
|
|
57
|
-
constructor(objId: ObjId, version: number, downloader: ObjDownloader, saveSegs?: ObjVersionFile["saveSegs"] | undefined,
|
|
65
|
+
constructor(objId: ObjId, version: number, downloader: ObjDownloader, saveSegs?: ObjVersionFile["saveSegs"] | undefined, segsNotInVersionFiles?: ObjOnDisk["segsNotInVersionFiles"] | undefined);
|
|
58
66
|
getInitParts(): Promise<InitDownloadParts>;
|
|
59
67
|
downloadAndSaveSegsChunk(chunk: NotOnDiskFiniteChunk): Promise<Uint8Array>;
|
|
60
|
-
downloadAllInBackground(eventSink: DownloadEventSink): number | undefined
|
|
68
|
+
downloadAllInBackground(eventSink: DownloadEventSink): Promise<number | undefined>;
|
|
61
69
|
nextActionType(): {
|
|
62
70
|
runASAP: boolean;
|
|
63
71
|
} | undefined;
|
|
@@ -39,7 +39,7 @@ class ObjOnDisk {
|
|
|
39
39
|
this.proxiedHeader = undefined;
|
|
40
40
|
if (this.downloadsInProgress) {
|
|
41
41
|
this.downloadsInProgress.saveSegs = this.objFile.saveSegs.bind(this.objFile);
|
|
42
|
-
this.downloadsInProgress.
|
|
42
|
+
this.downloadsInProgress.segsNotInVersionFiles = this.segsNotInVersionFiles.bind(this);
|
|
43
43
|
}
|
|
44
44
|
Object.seal(this);
|
|
45
45
|
}
|
|
@@ -127,7 +127,7 @@ class ObjOnDisk {
|
|
|
127
127
|
if (!this.downloader) {
|
|
128
128
|
throw new Error(`Object ${this.objId}, version ${this.version}, is not on a disk.`);
|
|
129
129
|
}
|
|
130
|
-
this.downloadsInProgress = new Download(this.objId, this.version, this.downloader, this.objFile.saveSegs.bind(this.objFile), this.
|
|
130
|
+
this.downloadsInProgress = new Download(this.objId, this.version, this.downloader, this.objFile.saveSegs.bind(this.objFile), this.segsNotInVersionFiles.bind(this));
|
|
131
131
|
}
|
|
132
132
|
return this.downloadsInProgress;
|
|
133
133
|
}
|
|
@@ -148,7 +148,7 @@ class ObjOnDisk {
|
|
|
148
148
|
}
|
|
149
149
|
return bytesAndChunks;
|
|
150
150
|
}
|
|
151
|
-
async
|
|
151
|
+
async getBaseSegsOrInfo(ofs, len, onlyInfo) {
|
|
152
152
|
const baseVersion = this.objFile.getBaseVersion();
|
|
153
153
|
if (baseVersion === undefined) {
|
|
154
154
|
throw new Error(`File for object ${this.objId}, version ${this.version} points to base, but base is not set`);
|
|
@@ -156,7 +156,43 @@ class ObjOnDisk {
|
|
|
156
156
|
if (!this.getBaseSegsOnDisk) {
|
|
157
157
|
throw new Error(`Object ${this.objId}, version ${this.version} doesn't have a getter of base source`);
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
return await this.getBaseSegsOnDisk(baseVersion, ofs, len, onlyInfo);
|
|
160
|
+
}
|
|
161
|
+
async getSegsInfo(offset, len) {
|
|
162
|
+
const segsLocations = this.objFile.segsLocations(offset, len);
|
|
163
|
+
const segsInfo = [];
|
|
164
|
+
for (const chunk of segsLocations) {
|
|
165
|
+
if (chunk.type !== 'base') {
|
|
166
|
+
segsInfo.push(chunk);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const chunksFromBase = await this.getBaseSegsOrInfo(chunk.baseVerOfs, chunk.len, true);
|
|
170
|
+
let thisVerOfs = chunk.thisVerOfs;
|
|
171
|
+
let baseVerOfs = chunk.baseVerOfs;
|
|
172
|
+
for (const chunkFromBase of chunksFromBase) {
|
|
173
|
+
let isInFiles;
|
|
174
|
+
switch (chunkFromBase.type) {
|
|
175
|
+
case 'base':
|
|
176
|
+
case 'new':
|
|
177
|
+
isInFiles = false;
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
isInFiles = true;
|
|
181
|
+
}
|
|
182
|
+
segsInfo.push({
|
|
183
|
+
type: (isInFiles ? 'base-in-files' : 'base'),
|
|
184
|
+
len: chunkFromBase.len,
|
|
185
|
+
thisVerOfs,
|
|
186
|
+
baseVerOfs
|
|
187
|
+
});
|
|
188
|
+
thisVerOfs += len;
|
|
189
|
+
baseVerOfs += len;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return segsInfo;
|
|
193
|
+
}
|
|
194
|
+
async readBaseBytesFromOtherFilesOnDisk(chunk) {
|
|
195
|
+
const baseBytesAndChunks = await this.getBaseSegsOrInfo(chunk.baseVerOfs, chunk.len, false);
|
|
160
196
|
// now we should convert new->base, adjusting all offsets, cause all those
|
|
161
197
|
// labels are relative to base version, and we need 'em to be relative to
|
|
162
198
|
// this version
|
|
@@ -200,35 +236,32 @@ class ObjOnDisk {
|
|
|
200
236
|
diffFromBase() {
|
|
201
237
|
return this.objFile.diffFromBase();
|
|
202
238
|
}
|
|
203
|
-
|
|
239
|
+
async segsNotInVersionFiles() {
|
|
204
240
|
const totalLen = this.objFile.getTotalSegsLen();
|
|
205
|
-
const
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
doesFileNeedDownload() {
|
|
209
|
-
return (this.segsThatNeedDownload().length !== 0);
|
|
241
|
+
const segsInfo = await this.getSegsInfo(0, totalLen);
|
|
242
|
+
return segsInfo.filter(({ type }) => ((type === 'new') || (type === 'base')));
|
|
210
243
|
}
|
|
211
|
-
numOfBytesNeedingDownload() {
|
|
244
|
+
async numOfBytesNeedingDownload() {
|
|
212
245
|
let totalLen = 0;
|
|
213
|
-
for (const { len } of this.
|
|
246
|
+
for (const { len } of await this.segsNotInVersionFiles()) {
|
|
214
247
|
totalLen += len;
|
|
215
248
|
}
|
|
216
249
|
return totalLen;
|
|
217
250
|
}
|
|
218
|
-
startDownloadInBackground(eventSink) {
|
|
219
|
-
return this.downloads().downloadAllInBackground(eventSink);
|
|
251
|
+
async startDownloadInBackground(eventSink) {
|
|
252
|
+
return await this.downloads().downloadAllInBackground(eventSink);
|
|
220
253
|
}
|
|
221
254
|
}
|
|
222
255
|
exports.ObjOnDisk = ObjOnDisk;
|
|
223
256
|
Object.freeze(ObjOnDisk.prototype);
|
|
224
257
|
Object.freeze(ObjOnDisk);
|
|
225
258
|
class Download {
|
|
226
|
-
constructor(objId, version, downloader, saveSegs,
|
|
259
|
+
constructor(objId, version, downloader, saveSegs, segsNotInVersionFiles) {
|
|
227
260
|
this.objId = objId;
|
|
228
261
|
this.version = version;
|
|
229
262
|
this.downloader = downloader;
|
|
230
263
|
this.saveSegs = saveSegs;
|
|
231
|
-
this.
|
|
264
|
+
this.segsNotInVersionFiles = segsNotInVersionFiles;
|
|
232
265
|
this.segsAsapRequest = [];
|
|
233
266
|
this.initDataRequest = undefined;
|
|
234
267
|
this.inBkgrnd = undefined;
|
|
@@ -269,14 +302,14 @@ class Download {
|
|
|
269
302
|
this.downloader.schedule(this);
|
|
270
303
|
return deferred.promise;
|
|
271
304
|
}
|
|
272
|
-
downloadAllInBackground(eventSink) {
|
|
273
|
-
if (!this.
|
|
305
|
+
async downloadAllInBackground(eventSink) {
|
|
306
|
+
if (!this.segsNotInVersionFiles) {
|
|
274
307
|
throw new Error(`segsThatNeedDownload is not initialized`);
|
|
275
308
|
}
|
|
276
309
|
if (this.inBkgrnd) {
|
|
277
310
|
return this.inBkgrnd.downloadTaskId;
|
|
278
311
|
}
|
|
279
|
-
const chunks = this.
|
|
312
|
+
const chunks = await this.segsNotInVersionFiles();
|
|
280
313
|
if (chunks.length === 0) {
|
|
281
314
|
return;
|
|
282
315
|
}
|
|
@@ -386,7 +419,7 @@ class Download {
|
|
|
386
419
|
return;
|
|
387
420
|
}
|
|
388
421
|
if (!this.inBkgrnd.chunks) {
|
|
389
|
-
this.inBkgrnd.chunks = this.
|
|
422
|
+
this.inBkgrnd.chunks = await this.segsNotInVersionFiles();
|
|
390
423
|
if (this.inBkgrnd.chunks.length === 0) {
|
|
391
424
|
this.completeBkgrnd();
|
|
392
425
|
return;
|
|
@@ -667,14 +667,8 @@ class ObjIdToPathMap {
|
|
|
667
667
|
if ((this.maxDepth !== undefined) && (this.maxDepth <= depthOf(parent))) {
|
|
668
668
|
return;
|
|
669
669
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
item.parent = parent;
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
item = { nameInParent: event.path, parent };
|
|
676
|
-
this.map.set(objId, item);
|
|
677
|
-
}
|
|
670
|
+
const item = { nameInParent: event.path, parent };
|
|
671
|
+
this.map.set(objId, item);
|
|
678
672
|
return pathOfMapItem(item);
|
|
679
673
|
}
|
|
680
674
|
updateFoundObjMapOnEvent(objId, objPathItem, childObjId, event) {
|
|
@@ -688,7 +682,7 @@ class ObjIdToPathMap {
|
|
|
688
682
|
if (event.type === 'entry-renaming') {
|
|
689
683
|
const childEntry = this.map.get(childObjId);
|
|
690
684
|
if (childEntry) {
|
|
691
|
-
childEntry.nameInParent
|
|
685
|
+
childEntry.nameInParent = event.newName;
|
|
692
686
|
}
|
|
693
687
|
}
|
|
694
688
|
else if (event.type === 'entry-removal') {
|
|
@@ -709,7 +703,7 @@ class ObjIdToPathMap {
|
|
|
709
703
|
}
|
|
710
704
|
else {
|
|
711
705
|
const childEntry = { parent: objPathItem, nameInParent: event.entry.name };
|
|
712
|
-
this.map.set(
|
|
706
|
+
this.map.set(childObjId, childEntry);
|
|
713
707
|
// XXX if childEntry is a folder with its own children, subtree should be added
|
|
714
708
|
// if (event.entry.isFolder && (!this.maxDepth || (depthOf(childEntry) < this.maxDepth))) {
|
|
715
709
|
// await recursivelyAddIntoMap(this.map, childNode, childEntry, this.maxDepth, childEntry.depth+1);
|