core-3nweb-client-lib 0.43.20 → 0.44.0

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.
@@ -92,6 +92,7 @@ function wrapWritableFileSyncAPI(sImpl) {
92
92
  startUpload: sImpl.startUpload.bind(sImpl),
93
93
  upload: sImpl.upload.bind(sImpl),
94
94
  adoptRemote: sImpl.adoptRemote.bind(sImpl),
95
+ diffCurrentAndRemoteVersions: sImpl.diffCurrentAndRemoteVersions.bind(sImpl),
95
96
  };
96
97
  return Object.freeze(w);
97
98
  }
@@ -143,6 +144,7 @@ function wrapReadonlyFileSyncAPI(sImpl) {
143
144
  startDownload: sImpl.startDownload.bind(sImpl),
144
145
  isRemoteVersionOnDisk: sImpl.isRemoteVersionOnDisk.bind(sImpl),
145
146
  adoptRemote: sImpl.adoptRemote.bind(sImpl),
147
+ diffCurrentAndRemoteVersions: sImpl.diffCurrentAndRemoteVersions.bind(sImpl),
146
148
  };
147
149
  return Object.freeze(w);
148
150
  }
@@ -241,11 +243,12 @@ function wrapWritableFSSyncAPI(sImpl) {
241
243
  startUpload: sImpl.startUpload.bind(sImpl),
242
244
  upload: sImpl.upload.bind(sImpl),
243
245
  adoptRemoteFolderItem: sImpl.adoptRemoteFolderItem.bind(sImpl),
244
- adoptAllRemoteItems: sImpl.adoptAllRemoteItems.bind(sImpl),
245
246
  statRemoteItem: sImpl.statRemoteItem.bind(sImpl),
246
247
  listRemoteFolderItem: sImpl.listRemoteFolderItem.bind(sImpl),
247
248
  getRemoteFileItem: sImpl.getRemoteFileItem.bind(sImpl),
248
249
  getRemoteFolderItem: sImpl.getRemoteFolderItem.bind(sImpl),
250
+ diffCurrentAndRemoteFileVersions: sImpl.diffCurrentAndRemoteFileVersions.bind(sImpl),
251
+ mergeFolderCurrentAndRemoteVersions: sImpl.mergeFolderCurrentAndRemoteVersions.bind(sImpl),
249
252
  };
250
253
  return Object.freeze(w);
251
254
  }
@@ -309,6 +312,7 @@ function wrapReadonlyFSSyncAPI(sImpl) {
309
312
  getRemoteFileItem: sImpl.getRemoteFileItem.bind(sImpl),
310
313
  getRemoteFolderItem: sImpl.getRemoteFolderItem.bind(sImpl),
311
314
  diffCurrentAndRemoteFolderVersions: sImpl.diffCurrentAndRemoteFolderVersions.bind(sImpl),
315
+ diffCurrentAndRemoteFileVersions: sImpl.diffCurrentAndRemoteFileVersions.bind(sImpl),
312
316
  };
313
317
  return Object.freeze(w);
314
318
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015 - 2016, 2019, 2022 3NSoft Inc.
3
+ Copyright (C) 2015 - 2016, 2019, 2022, 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
@@ -13,6 +13,7 @@ type FileByteSink = web3n.files.FileByteSink;
13
13
  type XAttrsChanges = web3n.files.XAttrsChanges;
14
14
  type VersionedReadFlags = web3n.files.VersionedReadFlags;
15
15
  type Stats = web3n.files.Stats;
16
+ type FileDiff = web3n.files.FileDiff;
16
17
  interface FileAttrs {
17
18
  attrs: CommonAttrs;
18
19
  size: number;
@@ -60,5 +61,7 @@ export declare class FileNode extends NodeInFS<FilePersistance> {
60
61
  private savingObjInsideChange;
61
62
  save(bytes: Uint8Array | Uint8Array[], changes?: XAttrsChanges): Promise<number>;
62
63
  getParamsForLink(): LinkParameters<FileLinkParams>;
64
+ private readRemoteVersion;
65
+ diffCurrentAndRemote(remoteVersion: number | undefined, compareContentIfSameMTime: boolean): Promise<FileDiff | undefined>;
63
66
  }
64
67
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015 - 2020, 2022, 2025 3NSoft Inc.
3
+ Copyright (C) 2015 - 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
@@ -232,8 +232,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
232
232
  return this.doChange(false, async () => {
233
233
  const { attrs, xattrs, newVersion } = super.getParamsForUpdate(changes);
234
234
  const encSub = await this.crypto.saveBytes(bytes, newVersion, attrs, xattrs);
235
- const newSize = Promise.resolve(Array.isArray(bytes) ?
236
- (0, buffer_utils_1.byteLengthIn)(bytes) : bytes.length);
235
+ const newSize = Promise.resolve(Array.isArray(bytes) ? (0, buffer_utils_1.byteLengthIn)(bytes) : bytes.length);
237
236
  await this.savingObjInsideChange(attrs, newSize, xattrs, newVersion, encSub);
238
237
  return this.version;
239
238
  });
@@ -254,9 +253,62 @@ class FileNode extends node_in_fs_1.NodeInFS {
254
253
  };
255
254
  return linkParams;
256
255
  }
256
+ async readRemoteVersion(remoteVersion) {
257
+ const storage = this.syncedStorage();
258
+ const srcOfRemote = await storage.getObjSrcOfRemoteVersion(this.objId, remoteVersion);
259
+ return await this.crypto.getFileAttrs(srcOfRemote);
260
+ }
261
+ async diffCurrentAndRemote(remoteVersion, compareContentIfSameMTime) {
262
+ const v = await this.getRemoteVersionToDiff(remoteVersion);
263
+ if (!v) {
264
+ return;
265
+ }
266
+ else if (v.rm) {
267
+ return {
268
+ ...v.rmDiff,
269
+ areContentsSame: false
270
+ };
271
+ }
272
+ else {
273
+ const { isCurrentLocal, remoteVersion, syncedVersion } = v;
274
+ const remoteAttrs = await this.readRemoteVersion(remoteVersion);
275
+ const synced = await this.readRemoteVersion(syncedVersion);
276
+ const commonDiff = this.commonDiffWithRemote(isCurrentLocal, remoteVersion, remoteAttrs, syncedVersion, synced);
277
+ const current = await this.readSrc(undefined);
278
+ const remote = await this.readSrc({ remoteVersion });
279
+ const size = {
280
+ current: await remote.src.getSize(),
281
+ remote: await current.src.getSize()
282
+ };
283
+ let areContentsSame = (size.current === size.remote);
284
+ if (areContentsSame && (commonDiff.mtime || compareContentIfSameMTime)) {
285
+ areContentsSame = await areAllBytesEqualIn(current.src, remote.src);
286
+ }
287
+ return {
288
+ ...commonDiff,
289
+ areContentsSame,
290
+ size
291
+ };
292
+ }
293
+ }
257
294
  }
258
295
  exports.FileNode = FileNode;
259
296
  Object.freeze(FileNode.prototype);
260
297
  Object.freeze(FileNode);
261
298
  function noop() { }
299
+ const COMPARE_BUF_SIZE = 64 * 1024;
300
+ async function areAllBytesEqualIn(src1, src2) {
301
+ await src1.seek(0);
302
+ await src2.seek(0);
303
+ let chunk1 = await src1.readNext(COMPARE_BUF_SIZE);
304
+ let chunk2 = await src2.readNext(COMPARE_BUF_SIZE);
305
+ while (chunk1 && chunk2) {
306
+ if (!(0, node_in_fs_1.areBytesEqual)(chunk1, chunk2)) {
307
+ return false;
308
+ }
309
+ chunk1 = await src1.readNext(COMPARE_BUF_SIZE);
310
+ chunk2 = await src2.readNext(COMPARE_BUF_SIZE);
311
+ }
312
+ return true;
313
+ }
262
314
  Object.freeze(exports);
@@ -16,6 +16,8 @@ type WritableFileVersionedAPI = web3n.files.WritableFileVersionedAPI;
16
16
  type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
17
17
  type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
18
18
  type VersionedReadFlags = web3n.files.VersionedReadFlags;
19
+ type OptionsToDiffFileVersions = web3n.files.OptionsToDiffFileVersions;
20
+ type FileDiff = web3n.files.FileDiff;
19
21
  export declare class FileObject implements WritableFile, Linkable {
20
22
  name: string;
21
23
  isNew: boolean;
@@ -110,5 +112,6 @@ declare class S implements WritableFileSyncAPI {
110
112
  downloadTaskId: number;
111
113
  } | undefined>;
112
114
  adoptRemote(opts?: OptionsToAdopteRemote): Promise<void>;
115
+ diffCurrentAndRemoteVersions(opts?: OptionsToDiffFileVersions): Promise<FileDiff | undefined>;
113
116
  }
114
117
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2020, 2022, 2025 3NSoft Inc.
3
+ Copyright (C) 2016 - 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
@@ -269,6 +269,10 @@ class S {
269
269
  const node = await this.n.getNode();
270
270
  await node.adoptRemote(opts);
271
271
  }
272
+ async diffCurrentAndRemoteVersions(opts) {
273
+ const node = await this.n.getNode();
274
+ return await node.diffCurrentAndRemote(opts === null || opts === void 0 ? void 0 : opts.remoteVersion, !!(opts === null || opts === void 0 ? void 0 : opts.compareContentIfSameMTime));
275
+ }
272
276
  }
273
277
  Object.freeze(S.prototype);
274
278
  Object.freeze(S);
@@ -11,10 +11,10 @@ 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;
15
14
  type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
16
15
  type VersionedReadFlags = web3n.files.VersionedReadFlags;
17
16
  type Stats = web3n.files.Stats;
17
+ type OptionsToMergeFolderVersions = web3n.files.OptionsToMergeFolderVersions;
18
18
  export interface NodeInfo {
19
19
  /**
20
20
  * This is a usual file name.
@@ -79,6 +79,9 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
79
79
  getStats(flags?: VersionedReadFlags): Promise<Stats>;
80
80
  protected setCurrentStateFrom(src: ObjSource): Promise<void>;
81
81
  adoptRemote(opts: OptionsToAdopteRemote | undefined): Promise<void>;
82
+ private makeEntryAdditionEvent;
83
+ private makeEntryRemovalEvent;
84
+ private makeEntryRenamingEvent;
82
85
  private callRemoveObjOn;
83
86
  list(): {
84
87
  lst: ListingEntry[];
@@ -97,7 +100,6 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
97
100
  getFile(name: string, undefOnMissing?: boolean): Promise<FileNode | undefined>;
98
101
  getLink(name: string, undefOnMissing?: boolean): Promise<LinkNode | undefined>;
99
102
  private fixMissingChildAndThrow;
100
- adoptItemsFromRemoteVersion(opts: OptionsToAdoptAllRemoteItems | undefined): Promise<number | undefined>;
101
103
  /**
102
104
  * If no initial local version given, then this performs like doTransition(change) method.
103
105
  * When initial local version is given and check, exceptions are thrown if versions mismatch,
@@ -174,9 +176,8 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
174
176
  private replaceLocalChildWithRemote;
175
177
  private readRemoteVersion;
176
178
  diffCurrentAndRemote(remoteVersion: number | undefined): Promise<FolderDiff | undefined>;
177
- private diffWithArchivedRemote;
178
- private diffWithRemote;
179
179
  getRemoteItemNode<T extends NodeInFS<any>>(remoteItemName: string, remoteVersion: number | undefined): Promise<T>;
180
180
  getStorage(): Storage;
181
+ mergeCurrentAndRemoteVersions(opts: OptionsToMergeFolderVersions | undefined): Promise<number | undefined>;
181
182
  }
182
183
  export {};