core-3nweb-client-lib 0.44.4 → 0.44.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.
@@ -98,8 +98,7 @@ function wrapWritableFileSyncAPI(sImpl) {
98
98
  return Object.freeze(w);
99
99
  }
100
100
  function addParamsAndFreezeFileWrap(w, fImpl) {
101
- w.getLinkParams =
102
- fImpl.getLinkParams.bind(fImpl);
101
+ w.getLinkParams = fImpl.getLinkParams.bind(fImpl);
103
102
  return Object.freeze(w);
104
103
  }
105
104
  function wrapReadonlyFile(fImpl) {
@@ -73,6 +73,7 @@ export interface ObjDownloader {
73
73
  getSegs: (objId: ObjId, version: number, start: number, end: number) => Promise<Uint8Array>;
74
74
  splitSegsDownloads: (start: number, end: number) => Section[];
75
75
  schedule: (download: Download) => void;
76
+ whenConnected: () => Promise<void>;
76
77
  }
77
78
  export interface InitDownloadParts {
78
79
  layout: Layout;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2018 - 2020, 2022, 2025 3NSoft Inc.
3
+ Copyright (C) 2018 - 2020, 2022, 2025 - 2026 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -423,7 +423,12 @@ class Download {
423
423
  this.inBkgrnd.runData.currentDownload.deferred.resolve(bytes);
424
424
  }
425
425
  catch (exc) {
426
- this.inBkgrnd.runData.currentDownload.deferred.reject(exc);
426
+ if (exc.type === 'connect') {
427
+ await this.downloader.whenConnected();
428
+ }
429
+ else {
430
+ this.inBkgrnd.runData.currentDownload.deferred.reject(exc);
431
+ }
427
432
  }
428
433
  finally {
429
434
  this.inBkgrnd.runData.currentDownload = undefined;
@@ -27,6 +27,7 @@ export declare class FileObject implements WritableFile, Linkable {
27
27
  static makeExisting(node: FileNode, writable: boolean): WritableFile | ReadonlyFile;
28
28
  static makeForNotExisiting(name: string, makeNode: () => Promise<FileNode>, isInSyncedStorage: boolean): WritableFile;
29
29
  static makeFileFromLinkParams(storage: Storage, params: LinkParameters<FileLinkParams>): Promise<WritableFile | ReadonlyFile>;
30
+ static makeFromRemoteVersion(remote: FileNode): Promise<ReadonlyFile>;
30
31
  getLinkParams(): Promise<LinkParameters<FileLinkParams>>;
31
32
  stat(): Promise<Stats>;
32
33
  updateXAttrs(changes: XAttrsChanges): Promise<void>;
@@ -47,6 +47,24 @@ class FileObject {
47
47
  const node = await file_node_1.FileNode.makeFromLinkParams(storage, params.params);
48
48
  return FileObject.makeExisting(node, !params.readonly);
49
49
  }
50
+ static async makeFromRemoteVersion(remote) {
51
+ const f = new FileObject(remote.name, false, remote, undefined, false, true);
52
+ const versionFlags = { remoteVersion: remote.version };
53
+ const wrap = {
54
+ writable: false,
55
+ isNew: false,
56
+ name: f.name,
57
+ getByteSource: () => f.v.getByteSource(versionFlags).then(({ src }) => src),
58
+ readJSON: () => f.v.readJSON(versionFlags).then(({ json }) => json),
59
+ readTxt: () => f.v.readTxt(versionFlags).then(({ txt }) => txt),
60
+ readBytes: (start, end) => f.v.readBytes(start, end, versionFlags).then(({ bytes }) => bytes),
61
+ stat: f.stat.bind(f),
62
+ watch: f.watch.bind(f),
63
+ getXAttr: f.getXAttr.bind(f),
64
+ listXAttrs: f.listXAttrs.bind(f),
65
+ };
66
+ return Object.freeze(wrap);
67
+ }
50
68
  async getLinkParams() {
51
69
  const node = await this.v.getNode();
52
70
  const linkParams = node.getParamsForLink();
@@ -387,7 +387,7 @@ class FolderNode extends node_in_fs_1.NodeInFS {
387
387
  node = await file_node_1.FileNode.readNodeFromObjBytes(storage, undefined, name, objId, src, key);
388
388
  }
389
389
  else if (info.isFolder) {
390
- node = await FolderNode.readNodeFromObjBytes(storage, undefined, objId, src, key);
390
+ node = await FolderNode.readNodeFromObjBytes(storage, name, objId, src, key);
391
391
  }
392
392
  else if (info.isLink) {
393
393
  node = await link_node_1.LinkNode.readNodeFromObjBytes(storage, undefined, name, objId, src, key);
@@ -818,6 +818,19 @@ class S {
818
818
  throw (0, common_1.setPathInExc)(exc, path);
819
819
  }
820
820
  }
821
+ // XXX WIP
822
+ // async compareLocalAndRemoteFileItems(
823
+ // path: string, itemName: string, remoteVersion?: number
824
+ // ): Promise<FileDiff> {
825
+ // const folderNode = await this.getFolderNode(path);
826
+ // const localChild = (await folderNode.getFile(itemName))!;
827
+ // const remoteChild = await folderNode.getRemoteItemNode(itemName, remoteVersion);
828
+ // if (remoteChild.type === 'file') {
829
+ // return await localChild.compareWithRemote(remoteChild);
830
+ // } else {
831
+ // throw makeFileException('notFile', `${path}/${itemName}`);
832
+ // }
833
+ // }
821
834
  async adoptRemoteFolderItem(path, itemName, opts) {
822
835
  const node = await this.getFolderNode(path);
823
836
  try {
@@ -846,7 +859,7 @@ class S {
846
859
  const folderNode = await this.getFolderNode(path);
847
860
  const remoteChild = await folderNode.getRemoteItemNode(remoteItemName, remoteVersion);
848
861
  if (remoteChild.type === 'file') {
849
- return (0, files_1.wrapReadonlyFile)(file_2.FileObject.makeExisting(remoteChild, false));
862
+ return file_2.FileObject.makeFromRemoteVersion(remoteChild);
850
863
  }
851
864
  else {
852
865
  throw (0, file_1.makeFileException)('notFile', `${path}/${remoteItemName}`);
@@ -13,7 +13,8 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
15
  You should have received a copy of the GNU General Public License along with
16
- this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.asyncIteration = asyncIteration;
19
20
  exports.asyncFind = asyncFind;
@@ -0,0 +1,7 @@
1
+ export declare class AwaitableState {
2
+ private deferredStateSetPoint;
3
+ constructor();
4
+ setState(): void;
5
+ clearState(): void;
6
+ whenStateIsSet(): Promise<void>;
7
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2017 3NSoft Inc.
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU General Public License as published by the Free Software
7
+ Foundation, either version 3 of the License, or (at your option) any later
8
+ version.
9
+
10
+ This program is distributed in the hope that it will be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License along with
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.AwaitableState = void 0;
20
+ const deferred_1 = require("./processes/deferred");
21
+ class AwaitableState {
22
+ constructor() {
23
+ this.deferredStateSetPoint = (0, deferred_1.defer)();
24
+ Object.seal(this);
25
+ }
26
+ setState() {
27
+ if (this.deferredStateSetPoint) {
28
+ this.deferredStateSetPoint.resolve();
29
+ this.deferredStateSetPoint = undefined;
30
+ }
31
+ }
32
+ clearState() {
33
+ if (!this.deferredStateSetPoint) {
34
+ this.deferredStateSetPoint = (0, deferred_1.defer)();
35
+ }
36
+ }
37
+ async whenStateIsSet() {
38
+ var _a;
39
+ return (_a = this.deferredStateSetPoint) === null || _a === void 0 ? void 0 : _a.promise;
40
+ }
41
+ }
42
+ exports.AwaitableState = AwaitableState;
43
+ Object.freeze(exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.44.4",
3
+ "version": "0.44.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",