core-3nweb-client-lib 0.43.17 → 0.43.19

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (C) 2016 - 2018, 2020, 2022, 2025 3NSoft Inc.
2
+ Copyright (C) 2016 - 2018, 2020, 2022, 2025 - 2026 3NSoft Inc.
3
3
 
4
4
  This program is free software: you can redistribute it and/or modify it under
5
5
  the terms of the GNU General Public License as published by the Free Software
@@ -1281,9 +1281,7 @@ declare namespace web3n.files {
1281
1281
  * Returns a state of on-disk cache of an item in fs.
1282
1282
  * @param version
1283
1283
  */
1284
- isRemoteVersionOnDisk(
1285
- path: string, version: number
1286
- ): Promise<'partial'|'complete'|'none'>;
1284
+ isRemoteVersionOnDisk(path: string, version: number): Promise<'partial'|'complete'|'none'>;
1287
1285
 
1288
1286
  /**
1289
1287
  * This downloads bytes onto disk, skipping decryption, as item's content isn't read here.
@@ -1301,7 +1299,7 @@ declare namespace web3n.files {
1301
1299
  adoptRemote(path: string, opts?: OptionsToAdopteRemote): Promise<void>;
1302
1300
 
1303
1301
  /**
1304
- * Calculates diff between current local and remote states of folder at given path.
1302
+ * Calculates diff between current and remote states of folder at given path.
1305
1303
  * @param path
1306
1304
  * @param remoteVersion
1307
1305
  */
@@ -1331,33 +1329,97 @@ declare namespace web3n.files {
1331
1329
  */
1332
1330
  getRemoteFileItem(path: string, remoteItemName: string, remoteVersion?: number): Promise<ReadonlyFile>;
1333
1331
 
1332
+ /**
1333
+ * Returns child folder from remote version of a folder.
1334
+ * @param path of folder
1335
+ * @param remoteItemName
1336
+ * @param remoteVersion of folder. Default is current remote.
1337
+ */
1334
1338
  getRemoteFolderItem(path: string, remoteItemName: string, remoteVersion?: number): Promise<ReadonlyFS>;
1335
1339
 
1340
+ // XXX method to work around demaged files
1341
+ // reloadFromServer(path: string): Promise<SyncStatus>;
1342
+
1336
1343
  }
1337
1344
 
1338
1345
  /**
1339
- *
1346
+ * Difference between two versions of folder node.
1347
+ * Folder items that same in both versions are not included.
1340
1348
  */
1341
1349
  interface FolderDiff {
1350
+ /**
1351
+ * Current version against which this diff is done.
1352
+ */
1342
1353
  currentVersion: number;
1354
+
1355
+ /**
1356
+ * Flag indicating if current version is local, i.e. never uploaded.
1357
+ */
1343
1358
  isCurrentLocal: boolean;
1359
+
1360
+ /**
1361
+ * Remote version against which this diff is done.
1362
+ */
1344
1363
  remoteVersion?: number;
1364
+
1365
+ /**
1366
+ * Flag indicating if remote version is archived.
1367
+ * If remote is archived/delete, it has nothing inside, and with this implicit
1368
+ * understanding there is no need to have other data fields populated here.
1369
+ */
1345
1370
  isRemoteArchived: boolean;
1371
+
1372
+ /**
1373
+ * Items present only in current version.
1374
+ */
1346
1375
  inCurrent?: ListingEntry[];
1376
+
1377
+ /**
1378
+ * Items present only in remote version.
1379
+ */
1347
1380
  inRemote?: ListingEntry[];
1348
1381
 
1349
- // XXX
1350
- // differentNames?: ;
1382
+ /**
1383
+ * Different names are for items that are same nodes but have different names
1384
+ * in local and remote branches.
1385
+ */
1386
+ differentNames?: {
1387
+ localName: string;
1388
+ remoteName: string;
1389
+ }[];
1390
+
1391
+ /**
1392
+ * Different keys identifies items that have different encryption keys in
1393
+ * local and remote branches. Keys may be changed, hence, given situation
1394
+ * should be reflected.
1395
+ */
1396
+ differentKeys?: string[];
1351
1397
 
1398
+ /**
1399
+ * Name overlaps are items with same name, but different node objects underneath.
1400
+ */
1352
1401
  nameOverlaps?: string[];
1402
+
1403
+ /**
1404
+ * Creation time should always be same.
1405
+ * But there is no way to enforce it, hence, we have this field.
1406
+ */
1353
1407
  ctime: {
1354
1408
  remote?: Date;
1355
1409
  current: Date;
1356
1410
  };
1411
+
1412
+ /**
1413
+ * Modification time most probably be different between versions.
1414
+ */
1357
1415
  mtime: {
1358
1416
  remote?: Date;
1359
1417
  current: Date;
1360
1418
  };
1419
+
1420
+ /**
1421
+ * Difference between xattrs. Same xattrs in both versions are not included.
1422
+ */
1361
1423
  xattrs?: {
1362
1424
  inCurrent?: { name: string; value: any; }[];
1363
1425
  inRemote?: { name: string; value: any; }[];
@@ -1391,7 +1453,8 @@ declare namespace web3n.files {
1391
1453
 
1392
1454
  /**
1393
1455
  * This method is for resolving conflicts on folders.
1394
- * It adopts some folder items, and not the whole folder state.
1456
+ * It adopts given folder item, that is present in remote version and is missing in local version.
1457
+ * Returns new local version.
1395
1458
  * @param path
1396
1459
  * @param remoteItemName
1397
1460
  * @param opts
@@ -1400,6 +1463,15 @@ declare namespace web3n.files {
1400
1463
  path: string, remoteItemName: string, opts?: OptionsToAdoptRemoteItem
1401
1464
  ): Promise<number>;
1402
1465
 
1466
+ /**
1467
+ * This method is for resolving conflicts on folders.
1468
+ * It adopts all folder items, that are present in remote version and are missing in local version.
1469
+ * Returns new local version, if there were remote items to adopt and their were added to local state.
1470
+ * @param path
1471
+ * @param opts
1472
+ */
1473
+ adoptAllRemoteItems(path: string, opts?: OptionsToAdoptAllRemoteItems): Promise<number|undefined>;
1474
+
1403
1475
  }
1404
1476
 
1405
1477
  interface OptionsToAdoptRemoteItem {
@@ -1422,6 +1494,22 @@ declare namespace web3n.files {
1422
1494
  newItemName?: string;
1423
1495
  }
1424
1496
 
1497
+ interface OptionsToAdoptAllRemoteItems {
1498
+ /**
1499
+ * Folder's local version. If not given, current local version is used.
1500
+ */
1501
+ localVersion?: number;
1502
+ /**
1503
+ * Folder's remote version. If not given, current remote version is used.
1504
+ */
1505
+ remoteVersion?: number;
1506
+ /**
1507
+ * Postfix to add to remote item names that have overlapping names with existing local items.
1508
+ * If there are name overlaps and postfix isn't given, then exception is thrown.
1509
+ */
1510
+ postfixForNameOverlaps?: string;
1511
+ }
1512
+
1425
1513
  interface FSEvent {
1426
1514
  path: string;
1427
1515
  }
@@ -4,7 +4,6 @@ import { Caller, CoreSideServices } from "../ipc-via-protobuf/connector";
4
4
  import { FileMsg } from "./file";
5
5
  type FS = web3n.files.FS;
6
6
  type FSItem = web3n.files.FSItem;
7
- type OptionsToAdoptRemoteItem = web3n.files.OptionsToAdoptRemoteItem;
8
7
  export declare function makeFSCaller(caller: Caller, fsMsg: FSMsg): FS;
9
8
  export declare function exposeFSService(fs: FS, expServices: CoreSideServices): FSMsg;
10
9
  export interface FSMsg {
@@ -38,12 +37,4 @@ export declare namespace fsItem {
38
37
  function exposeFSItem(expServices: CoreSideServices, item: FSItem): FSItemMsg;
39
38
  function fsItemFromMsg(caller: Caller, msg: FSItemMsg): FSItem;
40
39
  }
41
- interface OptionsToAdoptRemoteItemMsg {
42
- localVersion?: Value<number>;
43
- remoteVersion?: Value<number>;
44
- replaceLocalItem?: Value<boolean>;
45
- newItemName?: Value<string>;
46
- }
47
- export declare function optionsToAdoptRemoteItemToMsg(opts: OptionsToAdoptRemoteItem | undefined): OptionsToAdoptRemoteItemMsg | undefined;
48
- export declare function optionsToAdoptRemoteItemFromMsg(msg: OptionsToAdoptRemoteItemMsg | undefined): OptionsToAdoptRemoteItem | undefined;
49
40
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2020, 2022, 2025 3NSoft Inc.
3
+ Copyright (C) 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
@@ -19,8 +19,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.fsItem = exports.fsMsgType = void 0;
20
20
  exports.makeFSCaller = makeFSCaller;
21
21
  exports.exposeFSService = exposeFSService;
22
- exports.optionsToAdoptRemoteItemToMsg = optionsToAdoptRemoteItemToMsg;
23
- exports.optionsToAdoptRemoteItemFromMsg = optionsToAdoptRemoteItemFromMsg;
24
22
  const protobuf_msg_1 = require("../ipc-via-protobuf/protobuf-msg");
25
23
  const protobuf_type_1 = require("../lib-client/protobuf-type");
26
24
  const fs_proto_1 = require("../protos/fs.proto");
@@ -117,6 +115,7 @@ function makeFSCaller(caller, fsMsg) {
117
115
  fs.v.sync.startUpload = vsStartUpload.makeCaller(caller, vsPath);
118
116
  fs.v.sync.upload = vsUpload.makeCaller(caller, vsPath);
119
117
  fs.v.sync.adoptRemoteFolderItem = vsAdoptRemoteFolderItem.makeCaller(caller, vsPath);
118
+ fs.v.sync.adoptAllRemoteItems = vsAdoptAllRemoteItems.makeCaller(caller, vsPath);
120
119
  }
121
120
  }
122
121
  }
@@ -200,6 +199,7 @@ function exposeFSService(fs, expServices) {
200
199
  implExp.v.sync.startUpload = vsStartUpload.wrapService(fs.v.sync.startUpload);
201
200
  implExp.v.sync.upload = vsUpload.wrapService(fs.v.sync.upload);
202
201
  implExp.v.sync.adoptRemoteFolderItem = vsAdoptRemoteFolderItem.wrapService(fs.v.sync.adoptRemoteFolderItem);
202
+ implExp.v.sync.adoptAllRemoteItems = vsAdoptAllRemoteItems.wrapService(fs.v.sync.adoptAllRemoteItems);
203
203
  }
204
204
  }
205
205
  }
@@ -1930,35 +1930,35 @@ var vsUpload;
1930
1930
  vsUpload.makeCaller = makeCaller;
1931
1931
  })(vsUpload || (vsUpload = {}));
1932
1932
  Object.freeze(vsUpload);
1933
- function optionsToAdoptRemoteItemToMsg(opts) {
1934
- if (!opts) {
1935
- return;
1936
- }
1937
- return {
1938
- localVersion: (0, protobuf_msg_1.toOptVal)(opts.localVersion),
1939
- remoteVersion: (0, protobuf_msg_1.toOptVal)(opts.remoteVersion),
1940
- replaceLocalItem: (0, protobuf_msg_1.toOptVal)(opts.replaceLocalItem),
1941
- newItemName: (0, protobuf_msg_1.toOptVal)(opts.newItemName)
1942
- };
1943
- }
1944
- function optionsToAdoptRemoteItemFromMsg(msg) {
1945
- if (!msg) {
1946
- return;
1947
- }
1948
- return {
1949
- localVersion: (0, protobuf_msg_1.valOfOptInt)(msg.localVersion),
1950
- remoteVersion: (0, protobuf_msg_1.valOfOptInt)(msg.remoteVersion),
1951
- replaceLocalItem: (0, protobuf_msg_1.valOfOpt)(msg.replaceLocalItem),
1952
- newItemName: (0, protobuf_msg_1.valOfOpt)(msg.newItemName)
1953
- };
1954
- }
1955
1933
  var vsAdoptRemoteFolderItem;
1956
1934
  (function (vsAdoptRemoteFolderItem) {
1957
1935
  const requestType = protobuf_type_1.ProtoType.for(fs_proto_1.fs.AdoptRemoteFolderItemRequestBody);
1936
+ function optionsFromMsg(msg) {
1937
+ if (!msg) {
1938
+ return;
1939
+ }
1940
+ return {
1941
+ localVersion: (0, protobuf_msg_1.valOfOptInt)(msg.localVersion),
1942
+ remoteVersion: (0, protobuf_msg_1.valOfOptInt)(msg.remoteVersion),
1943
+ replaceLocalItem: (0, protobuf_msg_1.valOfOpt)(msg.replaceLocalItem),
1944
+ newItemName: (0, protobuf_msg_1.valOfOpt)(msg.newItemName)
1945
+ };
1946
+ }
1947
+ function optionsToMsg(opts) {
1948
+ if (!opts) {
1949
+ return;
1950
+ }
1951
+ return {
1952
+ localVersion: (0, protobuf_msg_1.toOptVal)(opts.localVersion),
1953
+ remoteVersion: (0, protobuf_msg_1.toOptVal)(opts.remoteVersion),
1954
+ replaceLocalItem: (0, protobuf_msg_1.toOptVal)(opts.replaceLocalItem),
1955
+ newItemName: (0, protobuf_msg_1.toOptVal)(opts.newItemName)
1956
+ };
1957
+ }
1958
1958
  function wrapService(fn) {
1959
1959
  return buf => {
1960
1960
  const { path, itemName, opts } = requestType.unpack(buf);
1961
- const promise = fn(path, itemName, optionsToAdoptRemoteItemFromMsg(opts))
1961
+ const promise = fn(path, itemName, optionsFromMsg(opts))
1962
1962
  .then(protobuf_msg_1.packInt);
1963
1963
  return { promise };
1964
1964
  };
@@ -1968,13 +1968,55 @@ var vsAdoptRemoteFolderItem;
1968
1968
  const ipcPath = (0, protobuf_msg_1.methodPathFor)(objPath, 'adoptRemoteFolderItem');
1969
1969
  return (path, itemName, opts) => caller
1970
1970
  .startPromiseCall(ipcPath, requestType.pack({
1971
- path, itemName, opts: optionsToAdoptRemoteItemToMsg(opts)
1971
+ path, itemName, opts: optionsToMsg(opts)
1972
1972
  }))
1973
1973
  .then(protobuf_msg_1.unpackInt);
1974
1974
  }
1975
1975
  vsAdoptRemoteFolderItem.makeCaller = makeCaller;
1976
1976
  })(vsAdoptRemoteFolderItem || (vsAdoptRemoteFolderItem = {}));
1977
1977
  Object.freeze(vsAdoptRemoteFolderItem);
1978
+ var vsAdoptAllRemoteItems;
1979
+ (function (vsAdoptAllRemoteItems) {
1980
+ const requestType = protobuf_type_1.ProtoType.for(fs_proto_1.fs.AdoptAllRemoteFolderItemsRequestBody);
1981
+ function optionsFromMsg(msg) {
1982
+ if (!msg) {
1983
+ return;
1984
+ }
1985
+ return {
1986
+ localVersion: (0, protobuf_msg_1.valOfOptInt)(msg.localVersion),
1987
+ remoteVersion: (0, protobuf_msg_1.valOfOptInt)(msg.remoteVersion),
1988
+ postfixForNameOverlaps: (0, protobuf_msg_1.valOfOpt)(msg.postfixForNameOverlaps),
1989
+ };
1990
+ }
1991
+ function optionsToMsg(opts) {
1992
+ if (!opts) {
1993
+ return;
1994
+ }
1995
+ return {
1996
+ localVersion: (0, protobuf_msg_1.toOptVal)(opts.localVersion),
1997
+ remoteVersion: (0, protobuf_msg_1.toOptVal)(opts.remoteVersion),
1998
+ postfixForNameOverlaps: (0, protobuf_msg_1.toOptVal)(opts.postfixForNameOverlaps),
1999
+ };
2000
+ }
2001
+ const replyType = protobuf_type_1.ProtoType.for(fs_proto_1.fs.AdoptAllRemoteFolderItemsReplyBody);
2002
+ function wrapService(fn) {
2003
+ return buf => {
2004
+ const { path, opts } = requestType.unpack(buf);
2005
+ const promise = fn(path, optionsFromMsg(opts))
2006
+ .then(newVersion => replyType.pack({ newVersion: (0, protobuf_msg_1.toOptVal)(newVersion) }));
2007
+ return { promise };
2008
+ };
2009
+ }
2010
+ vsAdoptAllRemoteItems.wrapService = wrapService;
2011
+ function makeCaller(caller, objPath) {
2012
+ const ipcPath = (0, protobuf_msg_1.methodPathFor)(objPath, 'adoptAllRemoteItems');
2013
+ return (path, opts) => caller
2014
+ .startPromiseCall(ipcPath, requestType.pack({ path, opts: optionsToMsg(opts) }))
2015
+ .then(buf => (0, protobuf_msg_1.valOfOptInt)(replyType.unpack(buf).newVersion));
2016
+ }
2017
+ vsAdoptAllRemoteItems.makeCaller = makeCaller;
2018
+ })(vsAdoptAllRemoteItems || (vsAdoptAllRemoteItems = {}));
2019
+ Object.freeze(vsAdoptAllRemoteItems);
1978
2020
  var vsAdoptRemote;
1979
2021
  (function (vsAdoptRemote) {
1980
2022
  const requestType = protobuf_type_1.ProtoType.for(fs_proto_1.fs.AdoptRemoteRequestBody);
@@ -2152,6 +2194,8 @@ function folderDiffToMsg(diff) {
2152
2194
  inCurrent: (_a = diff.inCurrent) === null || _a === void 0 ? void 0 : _a.map(lsEntryToMsg),
2153
2195
  inRemote: (_b = diff.inRemote) === null || _b === void 0 ? void 0 : _b.map(lsEntryToMsg),
2154
2196
  nameOverlaps: diff.nameOverlaps,
2197
+ differentKeys: diff.differentKeys,
2198
+ differentNames: diff.differentNames,
2155
2199
  ctime: diffTStoMsg(diff.ctime),
2156
2200
  mtime: diffTStoMsg(diff.mtime),
2157
2201
  xattrs: (diff.xattrs ? {
@@ -2177,20 +2221,19 @@ function folderDiffFromMsg(msg) {
2177
2221
  currentVersion: (0, protobuf_msg_1.fixInt)(msg.currentVersion),
2178
2222
  isCurrentLocal: msg.isCurrentLocal,
2179
2223
  isRemoteArchived: msg.isRemoteArchived,
2180
- inCurrent: ((msg.inCurrent.length > 0) ?
2181
- msg.inCurrent.map(lsEntryFromMsg) : undefined),
2182
- inRemote: ((msg.inRemote.length > 0) ?
2183
- msg.inRemote.map(lsEntryFromMsg) : undefined),
2184
- nameOverlaps: ((msg.nameOverlaps.length > 0) ?
2185
- msg.nameOverlaps : undefined),
2224
+ inCurrent: ((msg.inCurrent && (msg.inCurrent.length > 0)) ? msg.inCurrent.map(lsEntryFromMsg) : undefined),
2225
+ inRemote: ((msg.inRemote && (msg.inRemote.length > 0)) ? msg.inRemote.map(lsEntryFromMsg) : undefined),
2226
+ nameOverlaps: ((msg.nameOverlaps && (msg.nameOverlaps.length > 0)) ? msg.nameOverlaps : undefined),
2227
+ differentKeys: ((msg.differentKeys && (msg.differentKeys.length > 0)) ? msg.differentKeys : undefined),
2228
+ differentNames: ((msg.differentNames && (msg.differentNames.length > 0)) ? msg.differentNames : undefined),
2186
2229
  ctime: diffTSfromMsg(msg.ctime),
2187
2230
  mtime: diffTSfromMsg(msg.mtime),
2188
2231
  xattrs: (msg.xattrs ? {
2189
- inCurrent: ((msg.xattrs.inCurrent.length > 0) ?
2232
+ inCurrent: ((msg.xattrs.inCurrent && (msg.xattrs.inCurrent.length > 0)) ?
2190
2233
  msg.xattrs.inCurrent.map(file.xattrFromMsg) : undefined),
2191
- inRemote: ((msg.xattrs.inRemote.length > 0) ?
2234
+ inRemote: ((msg.xattrs.inRemote && (msg.xattrs.inRemote.length > 0)) ?
2192
2235
  msg.xattrs.inRemote.map(file.xattrFromMsg) : undefined),
2193
- nameOverlaps: ((msg.xattrs.nameOverlaps.length > 0) ?
2236
+ nameOverlaps: ((msg.xattrs.nameOverlaps && (msg.xattrs.nameOverlaps.length > 0)) ?
2194
2237
  msg.xattrs.nameOverlaps : undefined)
2195
2238
  } : undefined)
2196
2239
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2022, 2025 3NSoft Inc.
3
+ Copyright (C) 2016 - 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
@@ -241,6 +241,7 @@ function wrapWritableFSSyncAPI(sImpl) {
241
241
  startUpload: sImpl.startUpload.bind(sImpl),
242
242
  upload: sImpl.upload.bind(sImpl),
243
243
  adoptRemoteFolderItem: sImpl.adoptRemoteFolderItem.bind(sImpl),
244
+ adoptAllRemoteItems: sImpl.adoptAllRemoteItems.bind(sImpl),
244
245
  statRemoteItem: sImpl.statRemoteItem.bind(sImpl),
245
246
  listRemoteFolderItem: sImpl.listRemoteFolderItem.bind(sImpl),
246
247
  getRemoteFileItem: sImpl.getRemoteFileItem.bind(sImpl),
@@ -11,6 +11,7 @@ type XAttrsChanges = web3n.files.XAttrsChanges;
11
11
  type FolderDiff = web3n.files.FolderDiff;
12
12
  type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
13
13
  type OptionsToAdoptRemoteItem = web3n.files.OptionsToAdoptRemoteItem;
14
+ type OptionsToAdoptAllRemoteItems = web3n.files.OptionsToAdoptAllRemoteItems;
14
15
  type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
15
16
  type VersionedReadFlags = web3n.files.VersionedReadFlags;
16
17
  type Stats = web3n.files.Stats;
@@ -96,6 +97,16 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
96
97
  getFile(name: string, undefOnMissing?: boolean): Promise<FileNode | undefined>;
97
98
  getLink(name: string, undefOnMissing?: boolean): Promise<LinkNode | undefined>;
98
99
  private fixMissingChildAndThrow;
100
+ adoptItemsFromRemoteVersion(opts: OptionsToAdoptAllRemoteItems | undefined): Promise<number | undefined>;
101
+ /**
102
+ * If no initial local version given, then this performs like doTransition(change) method.
103
+ * When initial local version is given and check, exceptions are thrown if versions mismatch,
104
+ * or when there is another concurrent process that is already transitioning folder state to new state.
105
+ * This returns value of new local version.
106
+ * @param initLocalVersion
107
+ * @param change
108
+ */
109
+ private doChangeWhileTrackingVersion;
99
110
  /**
100
111
  * This method prepares a transition state, runs given action, and completes
101
112
  * transition to a new version.
@@ -161,6 +172,7 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
161
172
  private getRemoteChildNodeInfo;
162
173
  private addRemoteChild;
163
174
  private replaceLocalChildWithRemote;
175
+ private readRemoteVersion;
164
176
  diffCurrentAndRemote(remoteVersion: number | undefined): Promise<FolderDiff | undefined>;
165
177
  private diffWithArchivedRemote;
166
178
  private diffWithRemote;