core-3nweb-client-lib 0.43.7 → 0.43.9

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.
Files changed (39) hide show
  1. package/build/api-defs/files.d.ts +82 -4
  2. package/build/core/storage/synced/obj-files.d.ts +1 -0
  3. package/build/core/storage/synced/obj-files.js +16 -0
  4. package/build/core/storage/synced/obj-status.d.ts +1 -0
  5. package/build/core/storage/synced/obj-status.js +18 -0
  6. package/build/core/storage/synced/storage.d.ts +6 -2
  7. package/build/core/storage/synced/storage.js +12 -17
  8. package/build/core/storage/synced/upsyncer.d.ts +10 -1
  9. package/build/core/storage/synced/upsyncer.js +72 -9
  10. package/build/core-ipc/file.d.ts +27 -4
  11. package/build/core-ipc/file.js +90 -94
  12. package/build/core-ipc/fs.js +68 -132
  13. package/build/lib-client/fs-utils/files.js +6 -0
  14. package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +1 -0
  15. package/build/lib-client/objs-on-disk/obj-on-disk.js +8 -1
  16. package/build/lib-client/xsp-fs/common.d.ts +13 -21
  17. package/build/lib-client/xsp-fs/common.js +4 -16
  18. package/build/lib-client/xsp-fs/file-node.d.ts +3 -2
  19. package/build/lib-client/xsp-fs/file-node.js +17 -11
  20. package/build/lib-client/xsp-fs/file.d.ts +5 -0
  21. package/build/lib-client/xsp-fs/file.js +26 -13
  22. package/build/lib-client/xsp-fs/folder-node.d.ts +7 -1
  23. package/build/lib-client/xsp-fs/folder-node.js +18 -10
  24. package/build/lib-client/xsp-fs/fs.d.ts +5 -0
  25. package/build/lib-client/xsp-fs/fs.js +33 -26
  26. package/build/lib-client/xsp-fs/link-node.d.ts +3 -0
  27. package/build/lib-client/xsp-fs/link-node.js +5 -1
  28. package/build/lib-client/xsp-fs/node-in-fs.d.ts +20 -6
  29. package/build/lib-client/xsp-fs/node-in-fs.js +69 -14
  30. package/build/lib-client/xsp-fs/node-persistence.d.ts +1 -0
  31. package/build/lib-client/xsp-fs/node-persistence.js +4 -0
  32. package/build/lib-common/big-endian.js +2 -2
  33. package/build/lib-common/processes/labelled-exec-pools.js +1 -3
  34. package/build/protos/asmail.proto.js +1614 -1588
  35. package/build/protos/file.proto.js +1258 -541
  36. package/build/protos/fs.proto.js +1459 -1433
  37. package/package.json +4 -4
  38. package/protos/file.proto +31 -15
  39. package/protos/fs.proto +13 -22
@@ -145,8 +145,53 @@ class NodeInFS {
145
145
  };
146
146
  }
147
147
  }
148
- getAttrs() {
149
- return this.attrs;
148
+ async getStatsAndSize(flags) {
149
+ var _a;
150
+ let attrs;
151
+ let version;
152
+ if (shouldReadCurrentVersion(flags)) {
153
+ attrs = this.attrs;
154
+ version = this.version;
155
+ }
156
+ else {
157
+ const src = await this.getObjSrcOfVersion(flags);
158
+ attrs = await this.crypto.getAttrs(src);
159
+ version = src.version;
160
+ }
161
+ const stats = {
162
+ ctime: new Date(attrs.ctime),
163
+ mtime: new Date(attrs.mtime),
164
+ version,
165
+ writable: false,
166
+ };
167
+ switch (this.type) {
168
+ case 'folder':
169
+ stats.isFolder = true;
170
+ break;
171
+ case 'link':
172
+ stats.isLink = true;
173
+ break;
174
+ case 'file':
175
+ stats.isFile = true;
176
+ break;
177
+ }
178
+ if ((this.storage.type === 'synced')
179
+ || (this.storage.type === 'share')) {
180
+ const syncStatus = await this.syncedStorage().status(this.objId);
181
+ const { synced } = syncStatus.syncStatus();
182
+ if (synced) {
183
+ if (synced.latest && (version > synced.latest)) {
184
+ stats.versionSyncBranch = (((flags === null || flags === void 0 ? void 0 : flags.remoteVersion) === version) ? 'remote' : 'local');
185
+ }
186
+ else if ((version === synced.latest) || ((_a = synced.archived) === null || _a === void 0 ? void 0 : _a.includes(version))) {
187
+ stats.versionSyncBranch = 'synced';
188
+ }
189
+ }
190
+ else {
191
+ stats.versionSyncBranch = (((flags === null || flags === void 0 ? void 0 : flags.remoteVersion) === version) ? 'remote' : 'local');
192
+ }
193
+ }
194
+ return { stats, attrs: (attrs.pack ? undefined : attrs) };
150
195
  }
151
196
  async listVersions() {
152
197
  return (await this.storage.status(this.objId)).listVersions();
@@ -432,29 +477,39 @@ class NodeInFS {
432
477
  }
433
478
  return { createOnRemote: (uploadVersion === 1), localVersion, uploadVersion };
434
479
  }
435
- async upload(opts) {
480
+ async startUpload(opts) {
436
481
  try {
437
482
  const toUpload = await this.needUpload(opts);
438
483
  if (!toUpload) {
439
484
  return;
440
485
  }
441
486
  const { localVersion, createOnRemote, uploadVersion } = toUpload;
442
- const uploadHeader = await this.uploadHeaderChange(localVersion, uploadVersion);
443
- const storage = this.syncedStorage();
444
- await storage.upload(this.objId, localVersion, uploadVersion, uploadHeader, createOnRemote);
445
- return await this.doChange(true, async () => {
446
- storage.dropCachedLocalObjVersionsLessOrEqual(this.objId, localVersion);
447
- if (this.currentVersion === localVersion) {
448
- this.currentVersion = uploadVersion;
449
- }
450
- return uploadVersion;
451
- });
487
+ return await this.startUploadProcess(localVersion, createOnRemote, uploadVersion);
452
488
  }
453
489
  catch (exc) {
454
490
  throw (0, common_1.setPathInExc)(exc, this.name);
455
491
  }
456
492
  }
457
- async uploadHeaderChange(localVersion, uploadVersion) {
493
+ async startUploadProcess(localVersion, createOnRemote, uploadVersion) {
494
+ const uploadHeader = await this.makeHeaderForUploadIfVersionChanges(localVersion, uploadVersion);
495
+ const storage = this.syncedStorage();
496
+ const { completion, uploadTaskId } = await storage.startUpload(this.objId, localVersion, uploadVersion, uploadHeader, createOnRemote, event => {
497
+ event.path = this.name;
498
+ this.broadcastEvent(event);
499
+ });
500
+ return {
501
+ completion: completion.then(() => this.doChange(true, async () => {
502
+ if (this.currentVersion === localVersion) {
503
+ this.currentVersion = uploadVersion;
504
+ }
505
+ })).catch(exc => {
506
+ throw (0, common_1.setPathInExc)(exc, this.name);
507
+ }),
508
+ uploadTaskId,
509
+ uploadVersion
510
+ };
511
+ }
512
+ async makeHeaderForUploadIfVersionChanges(localVersion, uploadVersion) {
458
513
  if (localVersion === uploadVersion) {
459
514
  return;
460
515
  }
@@ -34,6 +34,7 @@ export declare abstract class NodePersistance {
34
34
  sub: Subscribe;
35
35
  }>;
36
36
  reencryptHeader(initHeader: Uint8Array, newVersion: number): Promise<Uint8Array>;
37
+ getAttrs(objSrc: ObjSource): Promise<Attrs>;
37
38
  }
38
39
  type FileByteSource = web3n.files.FileByteSource;
39
40
  type FileByteSink = web3n.files.FileByteSink;
@@ -175,6 +175,10 @@ class NodePersistance {
175
175
  const n = (0, xsp_files_1.calculateNonce)(this.zerothHeaderNonce, newVersion);
176
176
  return this.cryptor.formatWN.pack(headerContent, n, this.key, this.workLabel);
177
177
  }
178
+ async getAttrs(objSrc) {
179
+ const payload = await this.readonlyPayload(objSrc);
180
+ return payload.getAttrs();
181
+ }
178
182
  }
179
183
  exports.NodePersistance = NodePersistance;
180
184
  Object.freeze(NodePersistance.prototype);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2020 3NSoft Inc.
3
+ Copyright (C) 2020, 2025 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
@@ -144,7 +144,7 @@ function uintFrom6Bytes(x, i = 0) {
144
144
  // treating intermediate integer as signed, and pulling sign to resulting
145
145
  // float number. Hence, we need a bit different operation here.
146
146
  const h = (x[i] << 8) | x[i + 1];
147
- const l = (x[i] * 0x1000000) + ((x[i + 3] << 16) | (x[i + 4] << 8) | x[i + 5]);
147
+ const l = (x[i + 2] * 0x1000000) + ((x[i + 3] << 16) | (x[i + 4] << 8) | x[i + 5]);
148
148
  return (h * 0x100000000 + l);
149
149
  }
150
150
  /**
@@ -60,9 +60,7 @@ class ProcessingPool {
60
60
  await this.doOnError(err);
61
61
  }
62
62
  finally {
63
- if (proc) {
64
- this.inProcess.delete(proc);
65
- }
63
+ this.inProcess.delete(proc);
66
64
  }
67
65
  return this.processNextQueued();
68
66
  }