core-3nweb-client-lib 0.25.6 → 0.27.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.
Files changed (215) hide show
  1. package/README.md +2 -2
  2. package/build/api-defs/asmail.d.ts +1 -1
  3. package/build/api-defs/files.d.ts +282 -70
  4. package/build/core/app-files.js +7 -7
  5. package/build/core/asmail/config/common.js +4 -4
  6. package/build/core/asmail/config/index.js +2 -2
  7. package/build/core/asmail/config/published-intro-key.js +1 -1
  8. package/build/core/asmail/delivery/common.js +7 -7
  9. package/build/core/asmail/delivery/index.js +7 -6
  10. package/build/core/asmail/delivery/msg.js +8 -7
  11. package/build/core/asmail/delivery/per-recipient-wip.js +3 -3
  12. package/build/core/asmail/inbox/attachments/fs.js +11 -1
  13. package/build/core/asmail/inbox/cached-msgs.js +3 -3
  14. package/build/core/asmail/inbox/inbox-events.js +5 -4
  15. package/build/core/asmail/inbox/index.js +12 -12
  16. package/build/core/asmail/inbox/msg-downloader.js +3 -3
  17. package/build/core/asmail/inbox/msg-indexing.js +4 -4
  18. package/build/core/asmail/inbox/msg-on-disk.js +7 -7
  19. package/build/core/asmail/index.d.ts +3 -3
  20. package/build/core/asmail/index.js +13 -8
  21. package/build/core/asmail/key-verification.js +5 -5
  22. package/build/core/asmail/keyring/common.js +7 -6
  23. package/build/core/asmail/keyring/correspondent-keys.js +8 -7
  24. package/build/core/asmail/keyring/id-to-email-map.js +2 -1
  25. package/build/core/asmail/keyring/index.d.ts +7 -8
  26. package/build/core/asmail/keyring/index.js +15 -14
  27. package/build/core/asmail/keyring/keyring-storage.js +4 -3
  28. package/build/core/asmail/msg/opener.js +3 -3
  29. package/build/core/asmail/msg/packer.js +13 -13
  30. package/build/core/asmail/sending-params/own-params.js +4 -4
  31. package/build/core/asmail/sending-params/params-from-others.js +3 -3
  32. package/build/core/id-manager.js +8 -5
  33. package/build/core/index.d.ts +2 -1
  34. package/build/core/index.js +14 -14
  35. package/build/core/sign-in.d.ts +5 -4
  36. package/build/core/sign-in.js +12 -14
  37. package/build/core/sign-up.d.ts +1 -0
  38. package/build/core/sign-up.js +15 -11
  39. package/build/core/storage/common/json-saving.d.ts +21 -0
  40. package/build/core/storage/common/json-saving.js +82 -0
  41. package/build/core/storage/common/obj-info-file.d.ts +51 -0
  42. package/build/core/storage/common/obj-info-file.js +153 -5
  43. package/build/core/storage/common/utils.d.ts +2 -0
  44. package/build/core/storage/common/utils.js +32 -0
  45. package/build/core/storage/index.d.ts +3 -17
  46. package/build/core/storage/index.js +57 -77
  47. package/build/core/storage/local/obj-files-gc.d.ts +2 -0
  48. package/build/core/storage/local/obj-files-gc.js +53 -39
  49. package/build/core/storage/local/obj-files.d.ts +6 -9
  50. package/build/core/storage/local/obj-files.js +16 -19
  51. package/build/core/storage/local/obj-status.d.ts +20 -30
  52. package/build/core/storage/local/obj-status.js +46 -113
  53. package/build/core/storage/local/storage.d.ts +15 -5
  54. package/build/core/storage/local/storage.js +37 -18
  55. package/build/core/storage/synced/downloader.js +7 -6
  56. package/build/core/storage/synced/obj-files-gc.d.ts +6 -1
  57. package/build/core/storage/synced/obj-files-gc.js +106 -13
  58. package/build/core/storage/synced/obj-files.d.ts +46 -47
  59. package/build/core/storage/synced/obj-files.js +207 -154
  60. package/build/core/storage/synced/obj-status.d.ts +103 -42
  61. package/build/core/storage/synced/obj-status.js +525 -137
  62. package/build/core/storage/synced/remote-events.d.ts +11 -12
  63. package/build/core/storage/synced/remote-events.js +80 -57
  64. package/build/core/storage/synced/storage.d.ts +24 -5
  65. package/build/core/storage/synced/storage.js +123 -38
  66. package/build/core/storage/synced/upload-header-file.d.ts +4 -0
  67. package/build/core/storage/synced/upload-header-file.js +64 -0
  68. package/build/core/storage/synced/upsyncer.d.ts +15 -9
  69. package/build/core/storage/synced/upsyncer.js +219 -246
  70. package/build/core/storage/system-folders/apps-data.d.ts +16 -0
  71. package/build/core/storage/system-folders/apps-data.js +110 -0
  72. package/build/core/storage/system-folders/index.d.ts +18 -0
  73. package/build/core/storage/system-folders/index.js +77 -0
  74. package/build/core-ipc/common-caps.js +3 -3
  75. package/build/core-ipc/generic.js +8 -8
  76. package/build/core-ipc/startup-caps.js +2 -2
  77. package/build/cryptors.js +6 -2
  78. package/build/ipc-via-protobuf/asmail-cap.js +67 -83
  79. package/build/ipc-via-protobuf/bytes.js +16 -17
  80. package/build/ipc-via-protobuf/connector-clients-side.d.ts +3 -0
  81. package/build/ipc-via-protobuf/connector-clients-side.js +62 -25
  82. package/build/ipc-via-protobuf/connector-services-side.js +10 -10
  83. package/build/ipc-via-protobuf/connector.js +4 -4
  84. package/build/ipc-via-protobuf/file.d.ts +48 -12
  85. package/build/ipc-via-protobuf/file.js +476 -120
  86. package/build/ipc-via-protobuf/fs.d.ts +8 -0
  87. package/build/ipc-via-protobuf/fs.js +592 -159
  88. package/build/ipc-via-protobuf/log-cap.js +2 -2
  89. package/build/ipc-via-protobuf/mailerid.js +3 -3
  90. package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
  91. package/build/ipc-via-protobuf/protobuf-msg.js +11 -7
  92. package/build/ipc-via-protobuf/startup-cap.js +23 -23
  93. package/build/ipc-via-protobuf/storage-cap.js +12 -12
  94. package/build/ipc.js +7 -2
  95. package/build/lib-client/3nstorage/exceptions.d.ts +12 -8
  96. package/build/lib-client/3nstorage/exceptions.js +31 -10
  97. package/build/lib-client/3nstorage/service.d.ts +16 -2
  98. package/build/lib-client/3nstorage/service.js +109 -39
  99. package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
  100. package/build/lib-client/3nstorage/util/file-based-json.js +1 -1
  101. package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
  102. package/build/lib-client/3nstorage/xsp-fs/common.d.ts +52 -14
  103. package/build/lib-client/3nstorage/xsp-fs/common.js +31 -16
  104. package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +1 -0
  105. package/build/lib-client/3nstorage/xsp-fs/file-node.js +18 -14
  106. package/build/lib-client/3nstorage/xsp-fs/file.d.ts +31 -6
  107. package/build/lib-client/3nstorage/xsp-fs/file.js +74 -23
  108. package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +4 -4
  109. package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +24 -11
  110. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +599 -189
  111. package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +45 -9
  112. package/build/lib-client/3nstorage/xsp-fs/fs.js +326 -74
  113. package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +1 -0
  114. package/build/lib-client/3nstorage/xsp-fs/link-node.js +7 -2
  115. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +30 -20
  116. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +239 -106
  117. package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -1
  118. package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +18 -19
  119. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +5 -5
  120. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +56 -56
  121. package/build/lib-client/3nweb-signup.js +4 -4
  122. package/build/lib-client/asmail/recipient.js +15 -15
  123. package/build/lib-client/asmail/sender.js +22 -22
  124. package/build/lib-client/asmail/service-config.js +3 -3
  125. package/build/lib-client/cryptor/cryptor-in-worker.js +19 -17
  126. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  127. package/build/lib-client/cryptor/cryptor.js +4 -2
  128. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  129. package/build/lib-client/cryptor/in-proc-js.js +1 -1
  130. package/build/lib-client/cryptor/in-proc-wasm.js +7 -7
  131. package/build/lib-client/cryptor/worker-js.js +2 -2
  132. package/build/lib-client/cryptor/worker-wasm.js +2 -2
  133. package/build/lib-client/files-select.js +1 -1
  134. package/build/lib-client/files.d.ts +1 -1
  135. package/build/lib-client/files.js +71 -4
  136. package/build/lib-client/fs-collection.js +3 -2
  137. package/build/lib-client/fs-sync-utils.d.ts +5 -0
  138. package/build/lib-client/fs-sync-utils.js +61 -0
  139. package/build/lib-client/fs-view.d.ts +14 -0
  140. package/build/lib-client/fs-view.js +33 -0
  141. package/build/lib-client/key-derivation.js +1 -1
  142. package/build/lib-client/local-files/dev-file-sink.js +9 -9
  143. package/build/lib-client/local-files/dev-file-src.js +2 -2
  144. package/build/lib-client/local-files/device-fs.d.ts +1 -1
  145. package/build/lib-client/local-files/device-fs.js +56 -54
  146. package/build/lib-client/logging/log-to-file.d.ts +1 -1
  147. package/build/lib-client/logging/log-to-file.js +11 -11
  148. package/build/lib-client/mailer-id/login.js +7 -7
  149. package/build/lib-client/mailer-id/provisioner.js +12 -12
  150. package/build/lib-client/objs-on-disk/file-writing-proc.js +5 -5
  151. package/build/lib-client/objs-on-disk/obj-folders.js +33 -33
  152. package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +13 -2
  153. package/build/lib-client/objs-on-disk/obj-on-disk.js +24 -9
  154. package/build/lib-client/request-utils.d.ts +1 -0
  155. package/build/lib-client/request-utils.js +14 -14
  156. package/build/lib-client/server-events.d.ts +3 -3
  157. package/build/lib-client/server-events.js +12 -10
  158. package/build/lib-client/service-locator.js +10 -10
  159. package/build/lib-client/user-with-mid-session.js +7 -7
  160. package/build/lib-client/user-with-pkl-session.js +25 -25
  161. package/build/lib-client/ws-utils.js +3 -3
  162. package/build/lib-common/async-cryptor-wrap.js +4 -4
  163. package/build/lib-common/async-fs-node.d.ts +5 -3
  164. package/build/lib-common/async-fs-node.js +19 -18
  165. package/build/lib-common/byte-streaming/pipe.js +1 -1
  166. package/build/lib-common/byte-streaming/wrapping.js +17 -17
  167. package/build/lib-common/canonical-address.js +1 -1
  168. package/build/lib-common/exceptions/error.d.ts +1 -0
  169. package/build/lib-common/exceptions/error.js +7 -6
  170. package/build/lib-common/exceptions/file.js +10 -1
  171. package/build/lib-common/ipc/generic-ipc.js +2 -2
  172. package/build/lib-common/ipc/ws-ipc.js +2 -2
  173. package/build/lib-common/json-utils.js +2 -1
  174. package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
  175. package/build/lib-common/objs-on-disk/file-layout.d.ts +19 -0
  176. package/build/lib-common/objs-on-disk/file-layout.js +130 -12
  177. package/build/lib-common/objs-on-disk/obj-file.d.ts +13 -2
  178. package/build/lib-common/objs-on-disk/obj-file.js +99 -37
  179. package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
  180. package/build/lib-common/objs-on-disk/utils.js +4 -4
  181. package/build/lib-common/objs-on-disk/v1-obj-file-format.js +14 -14
  182. package/build/lib-common/processes/deferred.d.ts +6 -0
  183. package/build/lib-common/processes/deferred.js +30 -0
  184. package/build/lib-common/processes/labelled-exec-pools.d.ts +33 -0
  185. package/build/lib-common/processes/labelled-exec-pools.js +141 -0
  186. package/build/lib-common/processes/pressure.d.ts +7 -0
  187. package/build/lib-common/processes/pressure.js +56 -0
  188. package/build/lib-common/processes/sleep.d.ts +1 -0
  189. package/build/lib-common/processes/sleep.js +26 -0
  190. package/build/lib-common/{processes.d.ts → processes/synced.d.ts} +0 -40
  191. package/build/lib-common/{processes.js → processes/synced.js} +187 -204
  192. package/build/lib-common/processes/timeout.d.ts +1 -0
  193. package/build/lib-common/processes/timeout.js +51 -0
  194. package/build/lib-common/random-node.js +7 -7
  195. package/build/lib-common/service-api/3nstorage/owner.d.ts +100 -39
  196. package/build/lib-common/service-api/3nstorage/owner.js +85 -42
  197. package/build/lib-common/service-api/asmail/delivery.js +2 -2
  198. package/build/lib-common/service-api/asmail/retrieval.js +1 -1
  199. package/build/lib-common/timed-cache.d.ts +1 -0
  200. package/build/lib-common/timed-non-weak-cache.d.ts +1 -0
  201. package/build/lib-common/timed-non-weak-cache.js +11 -0
  202. package/build/lib-common/utils-for-observables.d.ts +15 -1
  203. package/build/lib-common/utils-for-observables.js +70 -19
  204. package/build/lib-common/weak-cache.d.ts +1 -0
  205. package/build/lib-common/weak-cache.js +12 -1
  206. package/build/lib-index.d.ts +2 -1
  207. package/build/lib-index.js +10 -7
  208. package/build/protos/asmail.proto.js +12912 -7127
  209. package/build/protos/file.proto.js +4848 -2399
  210. package/build/protos/fs.proto.js +9230 -3445
  211. package/package.json +8 -7
  212. package/protos/file.proto +91 -11
  213. package/protos/fs.proto +107 -8
  214. package/build/core/storage/synced/upsync-status.d.ts +0 -41
  215. package/build/core/storage/synced/upsync-status.js +0 -158
package/README.md CHANGED
@@ -10,9 +10,9 @@ After repository clone, bring down all NodeJS modules, by running in project's f
10
10
  npm ci
11
11
  ```
12
12
 
13
- Tests have some unit and integrated components. Integration test uses 3NWeb spec server. `spec-server` folder with server's code should be present either near this project's folder, or inside of it. Cloned spec server code repository should also be `npm ci`
13
+ Tests have some unit and integrated components. Integration test uses 3NWeb spec server. Integrated tests use server and dns mocking from `spec-3nweb-server`.
14
14
 
15
- Just build is done with
15
+ Build is done with
16
16
  ```
17
17
  npm run build
18
18
  ```
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (C) 2016, 2020 3NSoft Inc.
2
+ Copyright (C) 2016, 2020, 2022 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
@@ -40,6 +40,7 @@ declare namespace web3n.files {
40
40
  attrsNotEnabledInFS?: true;
41
41
  versionMismatch?: true;
42
42
  isEndless?: true;
43
+ storageClosed?: true;
43
44
  }
44
45
 
45
46
  interface exceptionCode {
@@ -58,6 +59,25 @@ declare namespace web3n.files {
58
59
  parsingError: 'parsing-error';
59
60
  notImplemented: 'ENOSYS';
60
61
  isEndless: 'is-endless';
62
+ storageClosed: 'storage-closed';
63
+ versionMismatch: 'version-mismatch';
64
+ }
65
+
66
+ interface FSSyncException extends RuntimeException {
67
+ type: 'fs-sync';
68
+ path: string;
69
+ localVersion?: number;
70
+ remoteVersion?: number;
71
+ alreadyUploading?: true;
72
+ versionNotFound?: true;
73
+ childNeverUploaded?: true;
74
+ childName?: string;
75
+ removedOnServer?: true;
76
+ versionMismatch?: true;
77
+ conflict?: true;
78
+ notSynced?: true;
79
+ remoteIsArchived?: true;
80
+ remoteFolderItemNotFound?: true;
61
81
  }
62
82
 
63
83
  /**
@@ -126,6 +146,41 @@ declare namespace web3n.files {
126
146
 
127
147
  }
128
148
 
149
+ /**
150
+ * Sync status contains info about possible version branches with possible
151
+ * states:
152
+ * 1. unsynced - have local branch, and possibly synced one.
153
+ * Local version(s) should be uploaded to get into synced state.
154
+ * 2. synced - have only synced branch.
155
+ * 3. behind - have both synced and remote branches.
156
+ * Should explicitly advance to newer version to get into synced state.
157
+ * 4. conflicting - have conflicting local and remote branches, with possible
158
+ * common synced history branch.
159
+ * Conflict gets fixed by uploading some local version with value greater
160
+ * than remote's latest. Making this version is a custom magic of
161
+ * conflict resolution that you do for your app.
162
+ */
163
+ interface SyncStatus {
164
+ state: SyncState;
165
+ synced?: SyncVersionsBranch;
166
+ local?: LocalVersion;
167
+ remote?: SyncVersionsBranch;
168
+ existsInSyncedParent?: boolean;
169
+ }
170
+
171
+ interface LocalVersion {
172
+ latest?: number;
173
+ isArchived?: boolean;
174
+ }
175
+
176
+ interface SyncVersionsBranch {
177
+ latest?: number;
178
+ archived?: number[];
179
+ isArchived?: boolean;
180
+ }
181
+
182
+ type SyncState = 'synced' | 'behind' | 'unsynced' | 'conflicting';
183
+
129
184
  interface FileByteSource {
130
185
 
131
186
  /**
@@ -312,7 +367,7 @@ declare namespace web3n.files {
312
367
  */
313
368
  getByteSource(): Promise<FileByteSource>;
314
369
 
315
- watch(observer: Observer<FileEvent>): () => void;
370
+ watch(observer: Observer<FileEvent|RemoteEvent>): () => void;
316
371
 
317
372
  }
318
373
 
@@ -382,8 +437,9 @@ declare namespace web3n.files {
382
437
  * greater than file length, all available bytes are read. If parameter
383
438
  * is missing, read will be done to file's end.
384
439
  */
385
- readBytes(start?: number, end?: number):
386
- Promise<{ bytes: Uint8Array|undefined; version: number; }>;
440
+ readBytes(
441
+ start?: number, end?: number
442
+ ): Promise<{ bytes: Uint8Array|undefined; version: number; }>;
387
443
 
388
444
  /**
389
445
  * This returns a promise, resolvable to text, read from file, assuming
@@ -402,6 +458,10 @@ declare namespace web3n.files {
402
458
  */
403
459
  getByteSource(): Promise<{ src: FileByteSource; version: number; }>;
404
460
 
461
+ listVersions(): Promise<{ current?: number; archived?: number[]; }>;
462
+
463
+ sync?: ReadonlyFileSyncAPI;
464
+
405
465
  }
406
466
 
407
467
  interface WritableFileVersionedAPI extends ReadonlyFileVersionedAPI {
@@ -444,8 +504,9 @@ declare namespace web3n.files {
444
504
  * When current version is given, an error is thrown, if file version at
445
505
  * the moment of writing is different.
446
506
  */
447
- getByteSink(truncateFile?: boolean, currentVersion?: number):
448
- Promise<{ sink: FileByteSink; version: number; }>;
507
+ getByteSink(
508
+ truncateFile?: boolean, currentVersion?: number
509
+ ): Promise<{ sink: FileByteSink; version: number; }>;
449
510
 
450
511
  /**
451
512
  * This returns a promise, resolvable to new file's version when copying
@@ -453,7 +514,48 @@ declare namespace web3n.files {
453
514
  * @param file which content will be copied into this file
454
515
  */
455
516
  copy(file: File): Promise<number>;
456
-
517
+
518
+ archiveCurrent(version?: number): Promise<number>;
519
+
520
+ sync?: WritableFileSyncAPI;
521
+
522
+ }
523
+
524
+ interface ReadonlyFileSyncAPI {
525
+
526
+ /**
527
+ * Returns synchronization status of this object, as is currently known
528
+ * here without checking remote server.
529
+ */
530
+ status(): Promise<SyncStatus>;
531
+
532
+ updateStatusInfo(): Promise<SyncStatus>;
533
+
534
+ isRemoteVersionOnDisk(
535
+ version: number
536
+ ): Promise<'partial'|'complete'|'none'>;
537
+
538
+ download(version: number): Promise<void>;
539
+
540
+ adoptRemote(opts?: OptionsToAdopteRemote): Promise<void>;
541
+
542
+ }
543
+
544
+ interface OptionsToAdopteRemote {
545
+ dropLocalVer?: boolean;
546
+ remoteVersion?: number;
547
+ download?: boolean;
548
+ }
549
+
550
+ interface WritableFileSyncAPI extends ReadonlyFileSyncAPI {
551
+
552
+ upload(opts?: OptionsToUploadLocal): Promise<void>;
553
+
554
+ }
555
+
556
+ interface OptionsToUploadLocal {
557
+ localVersion?: number;
558
+ uploadVersion?: number;
457
559
  }
458
560
 
459
561
  type FSType = 'device' | 'synced' | 'local' | 'share' | 'asmail-msg';
@@ -482,8 +584,9 @@ declare namespace web3n.files {
482
584
  * throwing of an exception, when folder does not exist. Default value is
483
585
  * false.
484
586
  */
485
- checkFolderPresence(path: string, throwIfMissing?: boolean):
486
- Promise<boolean>;
587
+ checkFolderPresence(
588
+ path: string, throwIfMissing?: boolean
589
+ ): Promise<boolean>;
487
590
 
488
591
  /**
489
592
  * This returns a promise, resolvable to true, if file exists, and to
@@ -493,8 +596,9 @@ declare namespace web3n.files {
493
596
  * throwing of an exception, when file does not exist. Default value is
494
597
  * false.
495
598
  */
496
- checkFilePresence(path: string, throwIfMissing?: boolean):
497
- Promise<boolean>;
599
+ checkFilePresence(
600
+ path: string, throwIfMissing?: boolean
601
+ ): Promise<boolean>;
498
602
 
499
603
  /**
500
604
  * This returns a promise, resolvable to true, if link exists, and to
@@ -504,8 +608,9 @@ declare namespace web3n.files {
504
608
  * throwing of an exception, when link does not exist. Default value is
505
609
  * false.
506
610
  */
507
- checkLinkPresence(path: string, throwIfMissing?: boolean):
508
- Promise<boolean>;
611
+ checkLinkPresence(
612
+ path: string, throwIfMissing?: boolean
613
+ ): Promise<boolean>;
509
614
 
510
615
  /**
511
616
  * This returns a promise, resolvable to stats of an entity at a given
@@ -530,12 +635,18 @@ declare namespace web3n.files {
530
635
 
531
636
  readLink(path: string): Promise<SymLink>;
532
637
 
533
- watchFolder(path: string, observer: Observer<FolderEvent>): () => void;
638
+ watchFolder(
639
+ path: string, observer: Observer<FolderEvent|RemoteEvent>
640
+ ): () => void;
534
641
 
535
- watchFile(path: string, observer: Observer<FileEvent>): () => void;
642
+ watchFile(
643
+ path: string, observer: Observer<FileEvent|RemoteEvent>
644
+ ): () => void;
536
645
 
537
- watchTree(path: string, observer: Observer<FolderEvent|FileEvent>):
538
- () => void;
646
+ watchTree(
647
+ path: string, depth: number|undefined,
648
+ observer: Observer<FolderEvent|FileEvent|RemoteEvent>
649
+ ): () => void;
539
650
 
540
651
  close(): Promise<void>;
541
652
 
@@ -577,8 +688,9 @@ declare namespace web3n.files {
577
688
  * greater than file length, all available bytes are read. If parameter
578
689
  * is missing, read will be done to file's end.
579
690
  */
580
- readBytes(path: string, start?: number, end?: number):
581
- Promise<Uint8Array|undefined>;
691
+ readBytes(
692
+ path: string, start?: number, end?: number
693
+ ): Promise<Uint8Array|undefined>;
582
694
 
583
695
  /**
584
696
  * This returns a promise, resolvable to bytes source with seek, which
@@ -603,8 +715,9 @@ declare namespace web3n.files {
603
715
  * @param path
604
716
  * @param criteria
605
717
  */
606
- select(path: string, criteria: SelectCriteria):
607
- Promise<{ items: FSCollection; completion: Promise<void>; }>;
718
+ select(
719
+ path: string, criteria: SelectCriteria
720
+ ): Promise<{ items: FSCollection; completion: Promise<void>; }>;
608
721
 
609
722
  }
610
723
 
@@ -736,8 +849,9 @@ declare namespace web3n.files {
736
849
  * @param overwrite is a flag that with a true value allows
737
850
  * overwrite of existing dst file. Default value is false.
738
851
  */
739
- copyFile(src: string, dst: string, overwrite?: boolean):
740
- Promise<void>;
852
+ copyFile(
853
+ src: string, dst: string, overwrite?: boolean
854
+ ): Promise<void>;
741
855
 
742
856
  /**
743
857
  * This returns a promise, resolvable when folder has been recursively
@@ -748,8 +862,9 @@ declare namespace web3n.files {
748
862
  * merge into existing folder and files overwriting inside. Default
749
863
  * value is false.
750
864
  */
751
- copyFolder(src: string, dst: string, mergeAndOverwrite?: boolean):
752
- Promise<void>;
865
+ copyFolder(
866
+ src: string, dst: string, mergeAndOverwrite?: boolean
867
+ ): Promise<void>;
753
868
 
754
869
  /**
755
870
  * This returns a promise, resolvable when file has been saved.
@@ -769,8 +884,9 @@ declare namespace web3n.files {
769
884
  * merge into existing folder and files overwriting inside. Default
770
885
  * value is false.
771
886
  */
772
- saveFolder(folder: FS, dst: string, mergeAndOverwrite?: boolean):
773
- Promise<void>;
887
+ saveFolder(
888
+ folder: FS, dst: string, mergeAndOverwrite?: boolean
889
+ ): Promise<void>;
774
890
 
775
891
  /**
776
892
  * This returns a promise, resolvable when file has been removed
@@ -814,8 +930,9 @@ declare namespace web3n.files {
814
930
  * @param flags are optional flags. Default flags are create=true,
815
931
  * exclusive=false.
816
932
  */
817
- writeBytes(path: string, bytes: Uint8Array, flags?: FileFlags):
818
- Promise<void>;
933
+ writeBytes(
934
+ path: string, bytes: Uint8Array, flags?: FileFlags
935
+ ): Promise<void>;
819
936
 
820
937
  /**
821
938
  * This returns a promise, resolvable to byte sink with seek
@@ -871,8 +988,9 @@ declare namespace web3n.files {
871
988
 
872
989
  interface ReadonlyFSVersionedAPI {
873
990
 
874
- getXAttr(path: string, xaName: string):
875
- Promise<{ attr: any; version: number; }>;
991
+ getXAttr(
992
+ path: string, xaName: string
993
+ ): Promise<{ attr: any; version: number; }>;
876
994
 
877
995
  listXAttrs(path: string): Promise<{ lst: string[]; version: number; }>;
878
996
 
@@ -881,8 +999,9 @@ declare namespace web3n.files {
881
999
  * for entries in the folder, and a folder's version.
882
1000
  * @param path of a folder that should be listed
883
1001
  */
884
- listFolder(path: string):
885
- Promise<{ lst: ListingEntry[]; version: number; }>;
1002
+ listFolder(
1003
+ path: string
1004
+ ): Promise<{ lst: ListingEntry[]; version: number; }>;
886
1005
 
887
1006
  /**
888
1007
  * This returns a promise, resolvable to json, read from file, and a
@@ -909,16 +1028,24 @@ declare namespace web3n.files {
909
1028
  * greater than file length, all available bytes are read. If parameter
910
1029
  * is missing, read will be done to file's end.
911
1030
  */
912
- readBytes(path: string, start?: number, end?: number):
913
- Promise<{ bytes: Uint8Array|undefined; version: number; }>;
1031
+ readBytes(
1032
+ path: string, start?: number, end?: number
1033
+ ): Promise<{ bytes: Uint8Array|undefined; version: number; }>;
914
1034
 
915
1035
  /**
916
1036
  * This returns a promise, resolvable to bytes source with seek, which
917
1037
  * allows random reads, and a file version
918
1038
  * @param path of a file from which to read bytes
919
1039
  */
920
- getByteSource(path: string):
921
- Promise<{ src: FileByteSource; version: number; }>;
1040
+ getByteSource(
1041
+ path: string
1042
+ ): Promise<{ src: FileByteSource; version: number; }>;
1043
+
1044
+ listVersions(
1045
+ path: string
1046
+ ): Promise<{ current?: number; archived?: number[]; }>;
1047
+
1048
+ sync?: ReadonlyFSSyncAPI;
922
1049
 
923
1050
  }
924
1051
 
@@ -940,8 +1067,9 @@ declare namespace web3n.files {
940
1067
  * @param flags are optional flags. Default flags are create=true,
941
1068
  * exclusive=false.
942
1069
  */
943
- writeJSONFile(path: string, json: any, flags?: VersionedFileFlags):
944
- Promise<number>;
1070
+ writeJSONFile(
1071
+ path: string, json: any, flags?: VersionedFileFlags
1072
+ ): Promise<number>;
945
1073
 
946
1074
  /**
947
1075
  * This returns a promise, resolvable to new file's version when file is
@@ -951,8 +1079,9 @@ declare namespace web3n.files {
951
1079
  * @param flags are optional flags. Default flags are create=true,
952
1080
  * exclusive=false.
953
1081
  */
954
- writeTxtFile(path: string, txt: string, flags?: VersionedFileFlags):
955
- Promise<number>;
1082
+ writeTxtFile(
1083
+ path: string, txt: string, flags?: VersionedFileFlags
1084
+ ): Promise<number>;
956
1085
 
957
1086
  /**
958
1087
  * This returns a promise, resolvable to new file's version when file is
@@ -962,8 +1091,9 @@ declare namespace web3n.files {
962
1091
  * @param flags are optional flags. Default flags are create=true,
963
1092
  * exclusive=false.
964
1093
  */
965
- writeBytes(path: string, bytes: Uint8Array, flags?: VersionedFileFlags):
966
- Promise<number>;
1094
+ writeBytes(
1095
+ path: string, bytes: Uint8Array, flags?: VersionedFileFlags
1096
+ ): Promise<number>;
967
1097
 
968
1098
  /**
969
1099
  * This returns a promise, resolvable to byte sink with seek, and a file
@@ -972,66 +1102,148 @@ declare namespace web3n.files {
972
1102
  * @param flags are optional flags. Default flags are create=true,
973
1103
  * exclusive=false, truncate=true.
974
1104
  */
975
- getByteSink(path: string, flags?: VersionedFileFlags):
976
- Promise<{ sink: FileByteSink; version: number; }>;
1105
+ getByteSink(
1106
+ path: string, flags?: VersionedFileFlags
1107
+ ): Promise<{ sink: FileByteSink; version: number; }>;
1108
+
1109
+ archiveCurrent(path: string, version?: number): Promise<number>;
1110
+
1111
+ sync?: WritableFSSyncAPI;
977
1112
 
978
1113
  }
979
1114
 
980
- interface FSEvent {
981
- type: string;
982
- path: string;
983
- isRemote?: boolean;
984
- newVersion?: number;
1115
+ interface ReadonlyFSSyncAPI {
1116
+
1117
+ /**
1118
+ * Returns synchronization status of this object, as is currently known
1119
+ * here without checking remote server.
1120
+ */
1121
+ status(path: string): Promise<SyncStatus>;
1122
+
1123
+ updateStatusInfo(path: string): Promise<SyncStatus>;
1124
+
1125
+ isRemoteVersionOnDisk(
1126
+ path: string, version: number
1127
+ ): Promise<'partial'|'complete'|'none'>;
1128
+
1129
+ download(path: string, version: number): Promise<void>;
1130
+
1131
+ adoptRemote(path: string, opts?: OptionsToAdopteRemote): Promise<void>;
1132
+
1133
+ diffCurrentAndRemoteFolderVersions(
1134
+ path: string, remoteVersion?: number
1135
+ ): Promise<FolderDiff|undefined>;
1136
+
985
1137
  }
986
1138
 
987
- interface RemovedEvent extends FSEvent {
988
- type: 'removed';
1139
+ interface FolderDiff {
1140
+ currentVersion: number;
1141
+ isCurrentLocal: boolean;
1142
+ remoteVersion?: number;
1143
+ isRemoteArchived: boolean;
1144
+ inCurrent?: ListingEntry[];
1145
+ inRemote?: ListingEntry[];
1146
+ nameOverlaps?: string[];
1147
+ ctime: {
1148
+ remote?: Date;
1149
+ current: Date;
1150
+ };
1151
+ mtime: {
1152
+ remote?: Date;
1153
+ current: Date;
1154
+ };
1155
+ xattrs?: {
1156
+ inCurrent?: { name: string; value: any; }[];
1157
+ inRemote?: { name: string; value: any; }[];
1158
+ nameOverlaps?: string[];
1159
+ };
1160
+ }
1161
+
1162
+ interface WritableFSSyncAPI extends ReadonlyFSSyncAPI {
1163
+
1164
+ upload(path: string, opts?: OptionsToUploadLocal): Promise<void>;
1165
+
1166
+ adoptRemoteFolderItem(
1167
+ path: string, itemName: string, opts?: OptionsToAdoptRemoteItem
1168
+ ): Promise<number>;
1169
+
1170
+ }
1171
+
1172
+ interface OptionsToAdoptRemoteItem {
1173
+ localVersion?: number;
1174
+ remoteVersion?: number;
989
1175
  }
990
1176
 
991
- interface MovedEvent extends FSEvent {
992
- type: 'moved';
1177
+ interface FSEvent {
1178
+ path: string;
993
1179
  }
994
1180
 
995
- interface SyncedEvent extends FSEvent {
996
- type: 'synced';
997
- current: number;
1181
+ interface FSChangeEvent {
1182
+ path: string;
1183
+ src: 'local'|'sync';
998
1184
  }
999
1185
 
1000
- interface UnsyncedEvent extends FSEvent {
1001
- type: 'unsynced';
1002
- lastSynced: number;
1186
+ interface RemovedEvent extends FSChangeEvent {
1187
+ type: 'removed';
1003
1188
  }
1004
1189
 
1005
- interface ConflictEvent extends FSEvent {
1006
- type: 'conflicting';
1007
- remoteVersion: number;
1190
+ interface VersionChangeOnUpload extends FSChangeEvent {
1191
+ type: 'version-change-on-upload';
1192
+ src: 'sync';
1193
+ newVersion: number;
1008
1194
  }
1009
1195
 
1010
1196
  type FolderEvent = EntryRemovalEvent | EntryAdditionEvent |
1011
- EntryRenamingEvent | RemovedEvent | MovedEvent |
1012
- SyncedEvent | UnsyncedEvent | ConflictEvent;
1197
+ EntryRenamingEvent | RemovedEvent | VersionChangeOnUpload;
1013
1198
 
1014
- interface EntryRemovalEvent extends FSEvent {
1199
+ interface EntryRemovalEvent extends FSChangeEvent {
1015
1200
  type: 'entry-removal';
1016
1201
  name: string;
1202
+ moveLabel?: number;
1203
+ newVersion?: number;
1017
1204
  }
1018
1205
 
1019
- interface EntryAdditionEvent extends FSEvent {
1206
+ interface EntryAdditionEvent extends FSChangeEvent {
1020
1207
  type: 'entry-addition';
1021
1208
  entry: ListingEntry;
1209
+ moveLabel?: number;
1210
+ newVersion?: number;
1022
1211
  }
1023
1212
 
1024
- interface EntryRenamingEvent extends FSEvent {
1213
+ interface EntryRenamingEvent extends FSChangeEvent {
1025
1214
  type: 'entry-renaming';
1026
1215
  oldName: string;
1027
1216
  newName: string;
1217
+ newVersion?: number;
1028
1218
  }
1029
1219
 
1030
- type FileEvent = FileChangeEvent | RemovedEvent | MovedEvent |
1031
- SyncedEvent | UnsyncedEvent | ConflictEvent;
1220
+ type FileEvent = FileChangeEvent | RemovedEvent | VersionChangeOnUpload;
1032
1221
 
1033
- interface FileChangeEvent extends FSEvent {
1222
+ interface FileChangeEvent extends FSChangeEvent {
1034
1223
  type: 'file-change';
1224
+ newVersion?: number;
1225
+ }
1226
+
1227
+ type RemoteEvent = RemoteVersionArchivalEvent | RemoteArchVerRemovalEvent |
1228
+ RemoteRemovalEvent | RemoteChangeEvent;
1229
+
1230
+ interface RemoteVersionArchivalEvent extends FSEvent {
1231
+ type: 'remote-version-archival';
1232
+ archivedVersion: number;
1233
+ }
1234
+
1235
+ interface RemoteArchVerRemovalEvent extends FSEvent {
1236
+ type: 'remote-arch-ver-removal';
1237
+ removedArchVer: number;
1238
+ }
1239
+
1240
+ interface RemoteRemovalEvent extends FSEvent {
1241
+ type: 'remote-removal';
1242
+ }
1243
+
1244
+ interface RemoteChangeEvent extends FSEvent {
1245
+ type: 'remote-change';
1246
+ newVersion: number;
1035
1247
  }
1036
1248
 
1037
1249
  }
@@ -33,32 +33,32 @@ const INBOX_DIR = 'inbox';
33
33
  const STORAGE_DIR = 'storage';
34
34
  function appDirs(appDir) {
35
35
  function userDataPath(user) {
36
- return path_1.join(appDir, userIdToFolderName(user));
36
+ return (0, path_1.join)(appDir, userIdToFolderName(user));
37
37
  }
38
38
  ;
39
39
  async function appFS() {
40
- await async_fs_node_1.stat(appDir).catch(async (e) => {
40
+ await (0, async_fs_node_1.stat)(appDir).catch(async (e) => {
41
41
  if (!e.notFound) {
42
42
  throw e;
43
43
  }
44
- await async_fs_node_1.mkdir(appDir).catch((e) => {
44
+ await (0, async_fs_node_1.mkdir)(appDir).catch((e) => {
45
45
  if (e.alreadyExists) {
46
46
  return;
47
47
  }
48
- throw error_1.errWithCause(e, `Cannot create app folder on the disk`);
48
+ throw (0, error_1.errWithCause)(e, `Cannot create app folder on the disk`);
49
49
  });
50
50
  });
51
51
  return device_fs_1.DeviceFS.makeWritable(appDir);
52
52
  }
53
53
  return Object.freeze({
54
54
  getUtilFS() {
55
- return path_1.join(appDir, exports.UTIL_DIR);
55
+ return (0, path_1.join)(appDir, exports.UTIL_DIR);
56
56
  },
57
57
  storagePathFor(user) {
58
- return path_1.join(userDataPath(user), STORAGE_DIR);
58
+ return (0, path_1.join)(userDataPath(user), STORAGE_DIR);
59
59
  },
60
60
  inboxPathFor(user) {
61
- return path_1.join(userDataPath(user), INBOX_DIR);
61
+ return (0, path_1.join)(userDataPath(user), INBOX_DIR);
62
62
  },
63
63
  async getUsersOnDisk() {
64
64
  const rootFS = await appFS();
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.ParamOnFileAndServer = void 0;
19
19
  const json_utils_1 = require("../../../lib-common/json-utils");
20
20
  const file_based_json_1 = require("../../../lib-client/3nstorage/util/file-based-json");
21
- const processes_1 = require("../../../lib-common/processes");
21
+ const synced_1 = require("../../../lib-common/processes/synced");
22
22
  class ParamOnFileAndServer extends file_based_json_1.JsonFileProc {
23
23
  constructor(paramPath, serviceConf) {
24
24
  super();
@@ -27,7 +27,7 @@ class ParamOnFileAndServer extends file_based_json_1.JsonFileProc {
27
27
  // XXX This should be done in a transactional style, with set on server
28
28
  // first. FolderNode with its base class is an example of transactional
29
29
  // mechanism implementation.
30
- this.changesProc = new processes_1.SingleProc();
30
+ this.changesProc = new synced_1.SingleProc();
31
31
  }
32
32
  async start(file) {
33
33
  await super.start(file, async () => {
@@ -55,12 +55,12 @@ class ParamOnFileAndServer extends file_based_json_1.JsonFileProc {
55
55
  throw exc;
56
56
  });
57
57
  const currentVal = this.toServiceJSON();
58
- if (!json_utils_1.deepEqual(infoOnServer, currentVal)) {
58
+ if (!(0, json_utils_1.deepEqual)(infoOnServer, currentVal)) {
59
59
  await this.serviceConf.setParam(this.paramPath, currentVal);
60
60
  }
61
61
  }
62
62
  async onFileEvent(ev) {
63
- if (!ev.isRemote) {
63
+ if (ev.src === 'local') {
64
64
  return;
65
65
  }
66
66
  if (ev.type === 'removed') {
@@ -47,7 +47,7 @@ class ConfigOfASMailServer {
47
47
  }
48
48
  static async makeAndStart(address, getSigner, resolver, net, fs) {
49
49
  try {
50
- file_1.ensureCorrectFS(fs, 'synced', true);
50
+ (0, file_1.ensureCorrectFS)(fs, 'synced', true);
51
51
  const conf = new ConfigOfASMailServer(address, getSigner, resolver, net);
52
52
  await Promise.all([
53
53
  fs.writableFile(ANON_SENDER_INVITES_FILE)
@@ -59,7 +59,7 @@ class ConfigOfASMailServer {
59
59
  return conf;
60
60
  }
61
61
  catch (err) {
62
- throw error_1.errWithCause(err, 'Failed to initialize ConfigOfASMailServer');
62
+ throw (0, error_1.errWithCause)(err, 'Failed to initialize ConfigOfASMailServer');
63
63
  }
64
64
  }
65
65
  }
@@ -80,7 +80,7 @@ class PublishedIntroKey extends common_2.ParamOnFileAndServer {
80
80
  }
81
81
  async makeNewIntroKey() {
82
82
  const signer = await this.getSigner();
83
- const pair = await common_1.generateKeyPair();
83
+ const pair = await (0, common_1.generateKeyPair)();
84
84
  const certs = {
85
85
  pkeyCert: signer.certifyPublicKey(pair.pkey, INTRO_KEY_VALIDITY),
86
86
  userCert: signer.userCert,