core-3nweb-client-lib 0.27.3 → 0.27.4

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 (45) hide show
  1. package/build/api-defs/files.d.ts +52 -19
  2. package/build/core/asmail/config/index.d.ts +2 -2
  3. package/build/core/asmail/config/index.js +2 -2
  4. package/build/core/asmail/config/invitations-anon.d.ts +10 -24
  5. package/build/core/asmail/config/invitations-anon.js +43 -31
  6. package/build/core/asmail/config/published-intro-key.d.ts +11 -22
  7. package/build/core/asmail/config/published-intro-key.js +47 -38
  8. package/build/core/asmail/inbox/index.js +1 -1
  9. package/build/core/asmail/index.d.ts +1 -1
  10. package/build/core/asmail/index.js +2 -2
  11. package/build/core/asmail/keyring/correspondent-keys.d.ts +2 -2
  12. package/build/core/asmail/keyring/correspondent-keys.js +1 -1
  13. package/build/core/asmail/keyring/index.d.ts +9 -29
  14. package/build/core/asmail/keyring/index.js +82 -69
  15. package/build/core/index.js +1 -2
  16. package/build/core/sign-in.js +1 -1
  17. package/build/core/storage/synced/obj-files.d.ts +2 -0
  18. package/build/core/storage/synced/obj-files.js +18 -1
  19. package/build/core/storage/synced/obj-status.d.ts +1 -0
  20. package/build/core/storage/synced/obj-status.js +10 -0
  21. package/build/core/storage/synced/storage.js +4 -21
  22. package/build/ipc-via-protobuf/file.d.ts +7 -0
  23. package/build/ipc-via-protobuf/file.js +60 -27
  24. package/build/ipc-via-protobuf/fs.js +55 -38
  25. package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +5 -10
  26. package/build/lib-client/3nstorage/xsp-fs/file-node.js +43 -45
  27. package/build/lib-client/3nstorage/xsp-fs/file.d.ts +7 -6
  28. package/build/lib-client/3nstorage/xsp-fs/file.js +12 -18
  29. package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +5 -0
  30. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +7 -1
  31. package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +18 -17
  32. package/build/lib-client/3nstorage/xsp-fs/fs.js +17 -18
  33. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +11 -2
  34. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +56 -5
  35. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  36. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  37. package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +5 -2
  38. package/build/lib-client/objs-on-disk/obj-on-disk.js +16 -1
  39. package/build/lib-common/objs-on-disk/file-layout.js +1 -1
  40. package/build/protos/asmail.proto.js +5943 -4348
  41. package/build/protos/file.proto.js +874 -0
  42. package/build/protos/fs.proto.js +7014 -5419
  43. package/package.json +1 -1
  44. package/protos/file.proto +23 -7
  45. package/protos/fs.proto +27 -13
@@ -32,6 +32,7 @@ const pipe_1 = require("../../../lib-common/byte-streaming/pipe");
32
32
  const buffer_utils_1 = require("../../../lib-common/buffer-utils");
33
33
  const rxjs_1 = require("rxjs");
34
34
  const operators_1 = require("rxjs/operators");
35
+ const node_in_fs_1 = require("./node-in-fs");
35
36
  const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
36
37
  function splitPathIntoParts(path) {
37
38
  return path_1.posix.resolve('/', path).split('/').filter(part => !!part);
@@ -550,38 +551,36 @@ class V {
550
551
  const node = await this.get(path);
551
552
  return node.updateXAttrs(changes);
552
553
  }
553
- async getXAttr(path, xaName) {
554
+ async getXAttr(path, xaName, flags) {
554
555
  const node = await this.get(path);
555
- const attr = node.getXAttr(xaName);
556
- return { attr, version: node.version };
556
+ return await node.getXAttr(xaName, flags);
557
557
  }
558
- async listXAttrs(path) {
558
+ async listXAttrs(path, flags) {
559
559
  const node = await this.get(path);
560
- return {
561
- lst: node.listXAttrs(),
562
- version: node.version
563
- };
560
+ return node.listXAttrs(flags);
564
561
  }
565
- async listFolder(path) {
562
+ async listFolder(path, flags) {
566
563
  const root = this.getRootIfNotClosed(path);
567
564
  const folder = await root.getFolderInThisSubTree(splitPathIntoParts(path), false).catch(setExcPath(path));
568
- return folder.list();
565
+ return ((0, node_in_fs_1.shouldReadCurrentVersion)(flags) ?
566
+ folder.list() :
567
+ folder.listNonCurrent(flags));
569
568
  }
570
569
  async writeBytes(path, bytes, flags = WRITE_NONEXCL_FLAGS) {
571
570
  this.ensureIsWritable();
572
571
  const f = await this.getOrCreateFile(path, flags);
573
572
  return f.save(bytes);
574
573
  }
575
- async readBytes(path, start, end) {
574
+ async readBytes(path, start, end, flags) {
576
575
  const file = await this.getOrCreateFile(path, {});
577
- return await file.readBytes(start, end);
576
+ return await file.readBytes(start, end, flags);
578
577
  }
579
578
  writeTxtFile(path, txt, flags = WRITE_NONEXCL_FLAGS) {
580
579
  const bytes = buffer_utils_1.utf8.pack(txt);
581
580
  return this.writeBytes(path, bytes, flags);
582
581
  }
583
- async readTxtFile(path) {
584
- const { bytes, version } = await this.readBytes(path);
582
+ async readTxtFile(path, flags) {
583
+ const { bytes, version } = await this.readBytes(path, undefined, undefined, flags);
585
584
  try {
586
585
  const txt = (bytes ? buffer_utils_1.utf8.open(bytes) : '');
587
586
  return { txt, version };
@@ -594,8 +593,8 @@ class V {
594
593
  const txt = JSON.stringify(json);
595
594
  return this.writeTxtFile(path, txt, flags);
596
595
  }
597
- async readJSONFile(path) {
598
- const { txt, version } = await this.readTxtFile(path);
596
+ async readJSONFile(path, flags) {
597
+ const { txt, version } = await this.readTxtFile(path, flags);
599
598
  try {
600
599
  const json = JSON.parse(txt);
601
600
  return { json, version };
@@ -609,9 +608,9 @@ class V {
609
608
  const f = await this.getOrCreateFile(path, flags);
610
609
  return f.writeSink(flags.truncate, flags.currentVersion);
611
610
  }
612
- async getByteSource(path) {
611
+ async getByteSource(path, flags) {
613
612
  const f = await this.getOrCreateFile(path, {});
614
- return f.readSrc();
613
+ return f.readSrc(flags);
615
614
  }
616
615
  }
617
616
  Object.freeze(V.prototype);
@@ -9,6 +9,7 @@ declare type XAttrsChanges = web3n.files.XAttrsChanges;
9
9
  declare type SyncStatus = web3n.files.SyncStatus;
10
10
  declare type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
11
11
  declare type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
12
+ declare type VersionedReadFlags = web3n.files.VersionedReadFlags;
12
13
  export declare abstract class NodeInFS<P extends NodePersistance> implements Node {
13
14
  protected readonly storage: Storage;
14
15
  readonly type: NodeType;
@@ -24,6 +25,7 @@ export declare abstract class NodeInFS<P extends NodePersistance> implements Nod
24
25
  protected setCurrentVersion(newVersion: number): void;
25
26
  readonly isInSyncedStorage: boolean;
26
27
  protected constructor(storage: Storage, type: NodeType, name: string, objId: string, currentVersion: number, parentId: string | undefined);
28
+ protected getObjSrcOfVersion(flags: VersionedReadFlags | undefined): Promise<ObjSource>;
27
29
  private updatedXAttrs;
28
30
  protected setUpdatedParams(version: number, attrs: CommonAttrs | undefined, xattrs: XAttrs | undefined): void;
29
31
  protected getParamsForUpdate(changes: XAttrsChanges | undefined): {
@@ -32,8 +34,14 @@ export declare abstract class NodeInFS<P extends NodePersistance> implements Nod
32
34
  xattrs?: XAttrs;
33
35
  };
34
36
  updateXAttrs(changes: XAttrsChanges): Promise<number>;
35
- getXAttr(xaName: string): any;
36
- listXAttrs(): string[];
37
+ getXAttr(xaName: string, flags: VersionedReadFlags | undefined): Promise<{
38
+ attr: any;
39
+ version: number;
40
+ }>;
41
+ listXAttrs(flags: VersionedReadFlags | undefined): Promise<{
42
+ lst: string[];
43
+ version: number;
44
+ }>;
37
45
  getAttrs(): CommonAttrs;
38
46
  listVersions(): Promise<{
39
47
  current?: number;
@@ -77,4 +85,5 @@ export declare abstract class NodeInFS<P extends NodePersistance> implements Nod
77
85
  upload(opts: OptionsToUploadLocal | undefined): Promise<void>;
78
86
  protected uploadHeaderChange(localVersion: number, uploadVersion: number): Promise<UploadHeaderChange | undefined>;
79
87
  }
88
+ export declare function shouldReadCurrentVersion(flags: VersionedReadFlags | undefined): boolean;
80
89
  export {};
@@ -16,7 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.NodeInFS = void 0;
19
+ exports.shouldReadCurrentVersion = exports.NodeInFS = void 0;
20
20
  /**
21
21
  * Everything in this module is assumed to be inside of a file system
22
22
  * reliance set.
@@ -58,6 +58,19 @@ class NodeInFS {
58
58
  }
59
59
  this.currentVersion = newVersion;
60
60
  }
61
+ getObjSrcOfVersion(flags) {
62
+ if (flags) {
63
+ const { remoteVersion, archivedVersion } = flags;
64
+ if (remoteVersion) {
65
+ const store = this.syncedStorage();
66
+ return store.getObjSrcOfRemoteVersion(this.objId, remoteVersion);
67
+ }
68
+ else if (archivedVersion) {
69
+ return this.storage.getObjSrc(this.objId, archivedVersion, true);
70
+ }
71
+ }
72
+ return this.storage.getObjSrc(this.objId);
73
+ }
61
74
  updatedXAttrs(changes) {
62
75
  return (this.xattrs ?
63
76
  (changes ? this.xattrs.makeUpdated(changes) : this.xattrs) :
@@ -90,11 +103,39 @@ class NodeInFS {
90
103
  return this.version;
91
104
  });
92
105
  }
93
- getXAttr(xaName) {
94
- return (this.xattrs ? this.xattrs.get(xaName) : undefined);
106
+ async getXAttr(xaName, flags) {
107
+ if (shouldReadCurrentVersion(flags)) {
108
+ return {
109
+ attr: (this.xattrs ? this.xattrs.get(xaName) : undefined),
110
+ version: this.version
111
+ };
112
+ }
113
+ else {
114
+ const src = await this.getObjSrcOfVersion(flags);
115
+ const payload = await this.crypto.readonlyPayload(src);
116
+ const xattrs = await payload.getXAttrs();
117
+ return {
118
+ attr: xattrs.get(xaName),
119
+ version: src.version
120
+ };
121
+ }
95
122
  }
96
- listXAttrs() {
97
- return (this.xattrs ? this.xattrs.list() : []);
123
+ async listXAttrs(flags) {
124
+ if (shouldReadCurrentVersion(flags)) {
125
+ return {
126
+ lst: (this.xattrs ? this.xattrs.list() : []),
127
+ version: this.version
128
+ };
129
+ }
130
+ else {
131
+ const src = await this.getObjSrcOfVersion(flags);
132
+ const payload = await this.crypto.readonlyPayload(src);
133
+ const xattrs = await payload.getXAttrs();
134
+ return {
135
+ lst: xattrs.list(),
136
+ version: src.version
137
+ };
138
+ }
98
139
  }
99
140
  getAttrs() {
100
141
  return this.attrs;
@@ -388,4 +429,14 @@ function copyWithPathIfRemoteEvent(e, path) {
388
429
  return e;
389
430
  }
390
431
  }
432
+ function shouldReadCurrentVersion(flags) {
433
+ if (flags) {
434
+ const { archivedVersion, remoteVersion } = flags;
435
+ if (archivedVersion || remoteVersion) {
436
+ return false;
437
+ }
438
+ }
439
+ return true;
440
+ }
441
+ exports.shouldReadCurrentVersion = shouldReadCurrentVersion;
391
442
  Object.freeze(exports);