core-3nweb-client-lib 0.53.5 → 0.53.6

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.
@@ -352,9 +352,9 @@ class SyncedObj {
352
352
  this.scheduleSelfGC();
353
353
  }
354
354
  dropCachedLocalObjVersionsLessOrEqual(version) {
355
- for (const version of this.localVers.keys()) {
356
- if (version <= version) {
357
- this.localVers.delete(version);
355
+ for (const localVersion of this.localVers.keys()) {
356
+ if (localVersion <= version) {
357
+ this.localVers.delete(localVersion);
358
358
  }
359
359
  }
360
360
  }
@@ -323,41 +323,40 @@ class FolderNode extends node_in_fs_1.NodeInFS {
323
323
  }
324
324
  const deferred = (0, deferred_1.defer)();
325
325
  const nodeSet = this.storage.nodes.setPromise(info.objId, deferred.promise);
326
- try {
327
- let node;
326
+ (async () => {
328
327
  if (info.isFile) {
329
- node = await file_node_1.FileNode.makeForExisting(this.storage, this.objId, info.name, info.objId, info.key);
328
+ return await file_node_1.FileNode.makeForExisting(this.storage, this.objId, info.name, info.objId, info.key);
330
329
  }
331
330
  else if (info.isFolder) {
332
331
  const src = await this.storage.getObjSrc(info.objId);
333
- node = await FolderNode.readNodeFromObjBytes(this.storage, info.name, info.objId, src, info.key);
332
+ return await FolderNode.readNodeFromObjBytes(this.storage, info.name, info.objId, src, info.key);
334
333
  }
335
334
  else if (info.isLink) {
336
- node = await link_node_1.LinkNode.makeForExisting(this.storage, this.objId, info.name, info.objId, info.key);
335
+ return await link_node_1.LinkNode.makeForExisting(this.storage, this.objId, info.name, info.objId, info.key);
337
336
  }
338
337
  else {
339
338
  throw new Error(`Unknown type of fs node`);
340
339
  }
341
- deferred.resolve(node);
342
- return nodeSet;
343
- }
344
- catch (exc) {
340
+ })().then((node) => deferred.resolve(node), async (exc) => {
345
341
  if (exc.failedCipherVerification) {
346
342
  exc = (0, file_1.makeFileException)('ioError', `${this.name}/${info.name}`, exc);
347
343
  }
348
344
  else if (exc.objNotFound) {
349
345
  if (fromCurrentNodes) {
350
- await this.fixMissingChildAndThrow(exc, info);
346
+ try {
347
+ await this.fixMissingChildAndThrow(exc, info);
348
+ }
349
+ catch (exc) {
350
+ deferred.reject(exc);
351
+ return;
352
+ }
351
353
  }
352
354
  else {
353
355
  try {
354
356
  const node = await this.getNonLocal(info);
355
357
  if (node) {
356
358
  deferred.resolve(node);
357
- return nodeSet;
358
- }
359
- else {
360
- throw exc;
359
+ return;
361
360
  }
362
361
  }
363
362
  catch (exc2) {
@@ -366,8 +365,8 @@ class FolderNode extends node_in_fs_1.NodeInFS {
366
365
  }
367
366
  }
368
367
  deferred.reject((0, error_1.errWithCause)(exc, `Failed to instantiate fs node '${this.name}/${info.name}'`));
369
- return nodeSet;
370
- }
368
+ });
369
+ return nodeSet;
371
370
  }
372
371
  async getNonLocal(info) {
373
372
  var _a;
@@ -644,17 +644,15 @@ class ObjIdToPathMap {
644
644
  Object.seal(this);
645
645
  }
646
646
  async fillFromTree(root) {
647
- const listOfAll = await recursiveIdAndPathList(root, '.', this.maxDepth);
648
- for (const [objId, path, depth] of listOfAll) {
649
- this.map.set(objId, { path, depth });
650
- }
647
+ const rootItem = { depth: 0, nameInParent: '.' };
648
+ this.map.set(root.objId, rootItem);
649
+ await recursivelyAddIntoMap(this.map, root, rootItem, this.maxDepth, 1);
651
650
  }
652
- getPathCorrectingTreeMap({ event, objId, parentObjId, childObjId }) {
653
- let pathAndDepth = this.map.get(objId);
654
- if (pathAndDepth) {
655
- const { path, depth } = pathAndDepth;
656
- this.updateFoundObjMapOnEvent(objId, path, depth, childObjId, event);
657
- return path;
651
+ getPathAndIfNeededCorrectTreeMap({ event, objId, parentObjId, childObjId }) {
652
+ let pathMapItem = this.map.get(objId);
653
+ if (pathMapItem) {
654
+ this.updateFoundObjMapOnEvent(objId, pathMapItem, childObjId, event);
655
+ return pathOfMapItem(pathMapItem);
658
656
  }
659
657
  if (event.type === 'removed') {
660
658
  return;
@@ -666,66 +664,88 @@ class ObjIdToPathMap {
666
664
  if (!parent) {
667
665
  return;
668
666
  }
669
- if ((this.maxDepth !== undefined)
670
- && (this.maxDepth <= parent.depth)) {
667
+ if ((this.maxDepth !== undefined) && (this.maxDepth <= parent.depth)) {
671
668
  return;
672
669
  }
673
- const path = `${parent.path}/${event.path}`;
674
- this.map.set(objId, { path, depth: parent.depth + 1 });
675
- return path;
670
+ const item = { nameInParent: event.path, parent, depth: parent.depth + 1 };
671
+ this.map.set(objId, item);
672
+ return pathOfMapItem(item);
676
673
  }
677
- updateFoundObjMapOnEvent(objId, path, depth, childObjId, event) {
674
+ updateFoundObjMapOnEvent(objId, objPathItem, childObjId, event) {
678
675
  if (event.type === 'removed') {
679
- this.map.delete(objId);
676
+ recursivelyRemoveFromMap(this.map, objId, objPathItem);
680
677
  return;
681
678
  }
682
- if ((this.maxDepth !== undefined) && (this.maxDepth <= depth)) {
679
+ if ((this.maxDepth !== undefined) && (this.maxDepth <= objPathItem.depth)) {
683
680
  return;
684
681
  }
685
682
  if (event.type === 'entry-renaming') {
686
683
  const childEntry = this.map.get(childObjId);
687
684
  if (childEntry) {
688
- childEntry.path === `${path}/${event.newName}`;
685
+ childEntry.nameInParent === event.newName;
689
686
  }
690
687
  }
691
688
  else if (event.type === 'entry-removal') {
692
689
  const childEntry = this.map.get(childObjId);
693
- if (childEntry && (childEntry.path === `${path}/${event.name}`)) {
690
+ if (childEntry && (childEntry.nameInParent === event.name)) {
694
691
  this.map.delete(childObjId);
695
692
  }
696
693
  }
697
694
  else if (event.type === 'entry-addition') {
698
- this.map.set(childObjId, { path: `${path}/${event.entry.name}`, depth: depth + 1 });
695
+ const childEntry = {
696
+ parent: objPathItem, nameInParent: event.entry.name, depth: objPathItem.depth + 1
697
+ };
698
+ this.map.set(objId, childEntry);
699
+ // XXX if childEntry is a folder with its own children, subtree should be added
700
+ // if (event.entry.isFolder && (!this.maxDepth || (childEntry.depth < this.maxDepth))) {
701
+ // await recursivelyAddIntoMap(this.map, childNode, childEntry, this.maxDepth, childEntry.depth+1);
702
+ // }
699
703
  }
700
704
  }
701
705
  copyWithLongPath(nodeEvent) {
702
- const path = this.getPathCorrectingTreeMap(nodeEvent);
706
+ const path = this.getPathAndIfNeededCorrectTreeMap(nodeEvent);
703
707
  return (path ? shallowCopyWithPath(nodeEvent.event, path) : undefined);
704
708
  }
705
709
  }
706
710
  Object.freeze(ObjIdToPathMap.prototype);
707
711
  Object.freeze(ObjIdToPathMap);
708
- async function recursiveIdAndPathList(folder, path, maxDepth, depth = 0) {
709
- const { lst } = folder.list();
710
- const idAndPaths = [
711
- [folder.objId, path, depth]
712
- ];
713
- if ((maxDepth !== undefined) && (depth === maxDepth)) {
714
- return idAndPaths;
715
- }
712
+ async function recursivelyAddIntoMap(map, parentNode, parent, maxDepth, depth) {
713
+ const { lst } = parentNode.list();
716
714
  for (const item of lst) {
717
- const childPath = `${path}/${item.name}`;
715
+ const childItem = { depth, parent, nameInParent: item.name };
718
716
  if (item.isFile || item.isLink) {
719
- const { objId } = folder.getCurrentNodeInfo(item.name);
720
- idAndPaths.push([objId, childPath, depth + 1]);
717
+ const { objId } = parentNode.getCurrentNodeInfo(item.name);
718
+ map.set(objId, childItem);
721
719
  }
722
720
  else if (item.isFolder) {
723
- const child = await folder.getFolder(item.name);
724
- const childLst = await recursiveIdAndPathList(child, childPath, maxDepth, depth + 1);
725
- idAndPaths.push(...childLst);
721
+ const child = await parentNode.getFolder(item.name);
722
+ map.set(child.objId, childItem);
723
+ if ((maxDepth === undefined) || (depth < maxDepth)) {
724
+ await recursivelyAddIntoMap(map, child, childItem, maxDepth, depth + 1);
725
+ }
726
+ }
727
+ }
728
+ }
729
+ function recursivelyRemoveFromMap(map, objId, objItem) {
730
+ map.delete(objId);
731
+ const childrenToRm = [];
732
+ for (const [childId, childItem] of map.entries()) {
733
+ if (childItem.parent === objItem) {
734
+ childrenToRm.push([childId, childItem]);
726
735
  }
727
736
  }
728
- return idAndPaths;
737
+ for (const [childId, childItem] of childrenToRm) {
738
+ recursivelyRemoveFromMap(map, childId, childItem);
739
+ }
740
+ }
741
+ function pathOfMapItem(item) {
742
+ if (item.parent) {
743
+ const prefix = pathOfMapItem(item.parent);
744
+ return `${prefix}/${item.nameInParent}`;
745
+ }
746
+ else {
747
+ return item.nameInParent;
748
+ }
729
749
  }
730
750
  function shallowCopyWithPath(event, path) {
731
751
  const shallowCopy = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.53.5",
3
+ "version": "0.53.6",
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",