core-3nweb-client-lib 0.53.8 → 0.53.10

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.
@@ -509,7 +509,12 @@ class ObjStatus {
509
509
  }
510
510
  }
511
511
  async adoptRemoteVersion(version) {
512
- var _a;
512
+ var _a, _b;
513
+ if (((_a = this.upload) === null || _a === void 0 ? void 0 : _a.type) === 'removal') {
514
+ // uploads should have be cancelled before this is called (need a check),
515
+ // yet, outstanding removal was noted
516
+ this.upload == undefined;
517
+ }
513
518
  const { local, remote } = this.status;
514
519
  if (this.stateIndicator !== 'behind') {
515
520
  if (this.stateIndicator === 'synced') {
@@ -526,7 +531,7 @@ class ObjStatus {
526
531
  }
527
532
  if (version) {
528
533
  if ((remote.current === version)
529
- || ((_a = remote.archived) === null || _a === void 0 ? void 0 : _a.includes(version))) {
534
+ || ((_b = remote.archived) === null || _b === void 0 ? void 0 : _b.includes(version))) {
530
535
  this.status.synced = { version, base: remote.diffToBase[version] };
531
536
  }
532
537
  else {
@@ -83,9 +83,6 @@ class UpSyncer {
83
83
  await obj.saveUploadHeaderFile(uploadHeader);
84
84
  }
85
85
  const task = await UploadTask.for(obj, localVersion, uploadVersion, uploadHeader === null || uploadHeader === void 0 ? void 0 : uploadHeader.uploadHeader, syncedBase, createOnRemote, uploadTaskId, eventSink, this.remoteStorage, async () => {
86
- if (this.tasksByIds.delete(task.taskId)) {
87
- this.tasksByObjIds.delete(task.objId);
88
- }
89
86
  await obj.recordUploadCompletion(localVersion, uploadVersion, (uploadHeader ? {
90
87
  newHeader: uploadHeader.uploadHeader,
91
88
  originalHeader: uploadHeader.localHeader
@@ -97,7 +94,11 @@ class UpSyncer {
97
94
  this.tasksByIds.set(uploadTaskId, task);
98
95
  this.tasksByObjIds.set(task.objId, task);
99
96
  const completion = task.completion();
100
- completion.catch(noop);
97
+ completion.finally(() => {
98
+ if (this.tasksByIds.delete(task.taskId)) {
99
+ this.tasksByObjIds.delete(task.objId);
100
+ }
101
+ }).catch(noop);
101
102
  this.execPools.add(task);
102
103
  return { completion, uploadTaskId };
103
104
  });
@@ -59,6 +59,7 @@ export declare class Download {
59
59
  private readonly downloader;
60
60
  saveSegs?: ObjVersionFile["saveSegs"] | undefined;
61
61
  segsNotInVersionFiles?: ObjOnDisk["segsNotInVersionFiles"] | undefined;
62
+ private downloadPrep;
62
63
  private readonly segsAsapRequest;
63
64
  private initDataRequest;
64
65
  private inBkgrnd;
@@ -185,8 +185,8 @@ class ObjOnDisk {
185
185
  thisVerOfs,
186
186
  baseVerOfs
187
187
  });
188
- thisVerOfs += len;
189
- baseVerOfs += len;
188
+ thisVerOfs += chunkFromBase.len;
189
+ baseVerOfs += chunkFromBase.len;
190
190
  }
191
191
  }
192
192
  return segsInfo;
@@ -262,6 +262,7 @@ class Download {
262
262
  this.downloader = downloader;
263
263
  this.saveSegs = saveSegs;
264
264
  this.segsNotInVersionFiles = segsNotInVersionFiles;
265
+ this.downloadPrep = undefined;
265
266
  this.segsAsapRequest = [];
266
267
  this.initDataRequest = undefined;
267
268
  this.inBkgrnd = undefined;
@@ -304,32 +305,47 @@ class Download {
304
305
  }
305
306
  async downloadAllInBackground(eventSink) {
306
307
  if (!this.segsNotInVersionFiles) {
307
- throw new Error(`segsThatNeedDownload is not initialized`);
308
+ throw new Error(`segsNotInVersionFiles is not initialized`);
308
309
  }
309
310
  if (this.inBkgrnd) {
310
311
  return this.inBkgrnd.downloadTaskId;
311
312
  }
312
- const chunks = await this.segsNotInVersionFiles();
313
- if (chunks.length === 0) {
314
- return;
313
+ else if (this.downloadPrep) {
314
+ return this.downloadPrep.promise;
315
315
  }
316
- this.inBkgrnd = {
317
- downloadTaskId: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
318
- eventSink,
319
- totalBytesToDownload: chunks.reduce((total, chunk) => (total + chunk.len), 0)
320
- };
321
- eventSink({
322
- type: 'download-started',
323
- downloadTaskId: this.inBkgrnd.downloadTaskId,
324
- path: '',
325
- version: this.version,
326
- totalBytesToDownload: this.inBkgrnd.totalBytesToDownload
316
+ this.downloadPrep = (0, deferred_1.defer)();
317
+ (async () => {
318
+ const chunks = await this.segsNotInVersionFiles();
319
+ if (chunks.length === 0) {
320
+ return;
321
+ }
322
+ this.inBkgrnd = {
323
+ downloadTaskId: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
324
+ eventSink,
325
+ totalBytesToDownload: chunks.reduce((total, chunk) => (total + chunk.len), 0)
326
+ };
327
+ eventSink({
328
+ type: 'download-started',
329
+ downloadTaskId: this.inBkgrnd.downloadTaskId,
330
+ path: '',
331
+ version: this.version,
332
+ totalBytesToDownload: this.inBkgrnd.totalBytesToDownload
333
+ });
334
+ if (this.segsAsapRequest.length === 0) {
335
+ this.inBkgrnd.chunks = chunks;
336
+ }
337
+ this.downloader.schedule(this);
338
+ return this.inBkgrnd.downloadTaskId;
339
+ })().then(taskId => {
340
+ var _a;
341
+ (_a = this.downloadPrep) === null || _a === void 0 ? void 0 : _a.resolve(taskId);
342
+ this.downloadPrep = undefined;
343
+ }, err => {
344
+ var _a;
345
+ (_a = this.downloadPrep) === null || _a === void 0 ? void 0 : _a.reject(err);
346
+ this.downloadPrep = undefined;
327
347
  });
328
- if (this.segsAsapRequest.length === 0) {
329
- this.inBkgrnd.chunks = chunks;
330
- }
331
- this.downloader.schedule(this);
332
- return this.inBkgrnd.downloadTaskId;
348
+ return this.downloadPrep.promise;
333
349
  }
334
350
  nextActionType() {
335
351
  if (this.initDataRequest) {
@@ -1091,9 +1091,10 @@ class FolderNode extends node_in_fs_1.NodeInFS {
1091
1091
  }
1092
1092
  if (renamed) {
1093
1093
  for (const { local, remote, renamedIn } of renamed) {
1094
- if (renamedIn === 'r') {
1094
+ if ((renamedIn === 'r') || (renamedIn === 'l&r')) {
1095
1095
  const node = nodes[local];
1096
1096
  (0, assert_1.assert)(!!node);
1097
+ delete nodes[local];
1097
1098
  node.name = remote;
1098
1099
  nodes[node.name] = node;
1099
1100
  events.push({
@@ -1101,9 +1102,6 @@ class FolderNode extends node_in_fs_1.NodeInFS {
1101
1102
  childObjId: node.objId
1102
1103
  });
1103
1104
  }
1104
- else if (renamedIn === 'l&r') {
1105
- // XXX use mtime to suggest which name to adopt -- TODO
1106
- }
1107
1105
  }
1108
1106
  }
1109
1107
  if (added === null || added === void 0 ? void 0 : added.inRemote) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.53.8",
3
+ "version": "0.53.10",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",