core-3nweb-client-lib 0.26.1 → 0.27.3

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 (211) hide show
  1. package/build/api-defs/asmail.d.ts +1 -1
  2. package/build/api-defs/files.d.ts +281 -75
  3. package/build/core/app-files.js +7 -7
  4. package/build/core/asmail/config/common.js +2 -2
  5. package/build/core/asmail/config/index.js +2 -2
  6. package/build/core/asmail/config/published-intro-key.js +1 -1
  7. package/build/core/asmail/delivery/common.js +7 -7
  8. package/build/core/asmail/delivery/index.js +5 -5
  9. package/build/core/asmail/delivery/msg.js +4 -4
  10. package/build/core/asmail/delivery/per-recipient-wip.js +1 -1
  11. package/build/core/asmail/inbox/attachments/fs.d.ts +2 -1
  12. package/build/core/asmail/inbox/attachments/fs.js +9 -4
  13. package/build/core/asmail/inbox/cached-msgs.js +1 -1
  14. package/build/core/asmail/inbox/inbox-events.js +4 -4
  15. package/build/core/asmail/inbox/index.js +10 -10
  16. package/build/core/asmail/inbox/msg-downloader.js +1 -1
  17. package/build/core/asmail/inbox/msg-indexing.js +1 -1
  18. package/build/core/asmail/inbox/msg-on-disk.js +5 -5
  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 +2 -1
  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 +2 -2
  31. package/build/core/asmail/sending-params/params-from-others.js +1 -1
  32. package/build/core/id-manager/index.d.ts +43 -0
  33. package/build/core/{id-manager.js → id-manager/index.js} +36 -114
  34. package/build/core/id-manager/key-storage.d.ts +21 -0
  35. package/build/core/id-manager/key-storage.js +96 -0
  36. package/build/core/index.d.ts +2 -1
  37. package/build/core/index.js +31 -33
  38. package/build/core/sign-in.d.ts +1 -2
  39. package/build/core/sign-in.js +8 -17
  40. package/build/core/sign-up.d.ts +2 -0
  41. package/build/core/sign-up.js +11 -10
  42. package/build/core/storage/common/json-saving.js +2 -2
  43. package/build/core/storage/common/obj-info-file.d.ts +12 -4
  44. package/build/core/storage/common/obj-info-file.js +66 -34
  45. package/build/core/storage/common/utils.d.ts +2 -0
  46. package/build/core/storage/common/utils.js +32 -0
  47. package/build/core/storage/index.d.ts +5 -17
  48. package/build/core/storage/index.js +78 -119
  49. package/build/core/storage/local/obj-files-gc.d.ts +2 -0
  50. package/build/core/storage/local/obj-files-gc.js +49 -37
  51. package/build/core/storage/local/obj-files.d.ts +4 -7
  52. package/build/core/storage/local/obj-files.js +7 -10
  53. package/build/core/storage/local/obj-status.d.ts +12 -6
  54. package/build/core/storage/local/obj-status.js +24 -9
  55. package/build/core/storage/local/storage.d.ts +10 -7
  56. package/build/core/storage/local/storage.js +29 -18
  57. package/build/core/storage/synced/downloader.js +1 -1
  58. package/build/core/storage/synced/obj-files-gc.d.ts +1 -0
  59. package/build/core/storage/synced/obj-files-gc.js +76 -39
  60. package/build/core/storage/synced/obj-files.d.ts +50 -36
  61. package/build/core/storage/synced/obj-files.js +201 -162
  62. package/build/core/storage/synced/obj-status.d.ts +99 -86
  63. package/build/core/storage/synced/obj-status.js +520 -251
  64. package/build/core/storage/synced/remote-events.d.ts +11 -12
  65. package/build/core/storage/synced/remote-events.js +73 -56
  66. package/build/core/storage/synced/storage.d.ts +24 -10
  67. package/build/core/storage/synced/storage.js +147 -47
  68. package/build/core/storage/synced/upload-header-file.d.ts +4 -0
  69. package/build/core/storage/synced/upload-header-file.js +64 -0
  70. package/build/core/storage/synced/upsyncer.d.ts +12 -7
  71. package/build/core/storage/synced/upsyncer.js +210 -280
  72. package/build/core/storage/system-folders/apps-data.d.ts +16 -0
  73. package/build/core/storage/system-folders/apps-data.js +110 -0
  74. package/build/core/storage/system-folders/index.d.ts +18 -0
  75. package/build/core/storage/system-folders/index.js +77 -0
  76. package/build/core-ipc/common-caps.js +3 -3
  77. package/build/core-ipc/generic.js +8 -8
  78. package/build/core-ipc/startup-caps.js +2 -2
  79. package/build/cryptors.js +6 -2
  80. package/build/ipc-via-protobuf/asmail-cap.js +58 -57
  81. package/build/ipc-via-protobuf/bytes.js +16 -17
  82. package/build/ipc-via-protobuf/connector-clients-side.d.ts +1 -0
  83. package/build/ipc-via-protobuf/connector-clients-side.js +14 -15
  84. package/build/ipc-via-protobuf/connector-services-side.js +10 -10
  85. package/build/ipc-via-protobuf/connector.js +4 -4
  86. package/build/ipc-via-protobuf/file.d.ts +48 -12
  87. package/build/ipc-via-protobuf/file.js +474 -126
  88. package/build/ipc-via-protobuf/fs.d.ts +8 -0
  89. package/build/ipc-via-protobuf/fs.js +577 -142
  90. package/build/ipc-via-protobuf/log-cap.js +2 -2
  91. package/build/ipc-via-protobuf/mailerid.js +3 -3
  92. package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
  93. package/build/ipc-via-protobuf/protobuf-msg.js +11 -7
  94. package/build/ipc-via-protobuf/startup-cap.js +21 -21
  95. package/build/ipc-via-protobuf/storage-cap.js +12 -12
  96. package/build/ipc.js +7 -2
  97. package/build/lib-client/3nstorage/exceptions.d.ts +16 -1
  98. package/build/lib-client/3nstorage/exceptions.js +21 -3
  99. package/build/lib-client/3nstorage/service.d.ts +21 -3
  100. package/build/lib-client/3nstorage/service.js +128 -46
  101. package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
  102. package/build/lib-client/3nstorage/util/file-based-json.js +3 -2
  103. package/build/lib-client/3nstorage/util/for-arrays.d.ts +1 -0
  104. package/build/lib-client/3nstorage/util/for-arrays.js +32 -0
  105. package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
  106. package/build/lib-client/3nstorage/xsp-fs/common.d.ts +44 -19
  107. package/build/lib-client/3nstorage/xsp-fs/common.js +30 -19
  108. package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +1 -0
  109. package/build/lib-client/3nstorage/xsp-fs/file-node.js +17 -13
  110. package/build/lib-client/3nstorage/xsp-fs/file.d.ts +31 -6
  111. package/build/lib-client/3nstorage/xsp-fs/file.js +73 -25
  112. package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +4 -4
  113. package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +32 -13
  114. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +752 -192
  115. package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +35 -4
  116. package/build/lib-client/3nstorage/xsp-fs/fs.js +236 -119
  117. package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +1 -0
  118. package/build/lib-client/3nstorage/xsp-fs/link-node.js +7 -2
  119. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +30 -29
  120. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +232 -127
  121. package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -1
  122. package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +17 -18
  123. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +3 -3
  124. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +53 -53
  125. package/build/lib-client/3nweb-signup.js +4 -4
  126. package/build/lib-client/asmail/recipient.js +15 -15
  127. package/build/lib-client/asmail/sender.js +22 -22
  128. package/build/lib-client/asmail/service-config.js +3 -3
  129. package/build/lib-client/cryptor/cryptor-in-worker.js +18 -16
  130. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  131. package/build/lib-client/cryptor/cryptor.js +4 -2
  132. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  133. package/build/lib-client/cryptor/in-proc-js.js +1 -1
  134. package/build/lib-client/cryptor/in-proc-wasm.js +6 -6
  135. package/build/lib-client/cryptor/worker-js.js +2 -2
  136. package/build/lib-client/cryptor/worker-wasm.js +2 -2
  137. package/build/lib-client/files-select.js +1 -1
  138. package/build/lib-client/files.d.ts +1 -1
  139. package/build/lib-client/files.js +71 -6
  140. package/build/lib-client/fs-collection.js +1 -1
  141. package/build/lib-client/fs-sync-utils.d.ts +5 -0
  142. package/build/lib-client/fs-sync-utils.js +61 -0
  143. package/build/lib-client/fs-view.d.ts +14 -0
  144. package/build/lib-client/fs-view.js +33 -0
  145. package/build/lib-client/key-derivation.js +1 -1
  146. package/build/lib-client/local-files/dev-file-sink.js +9 -9
  147. package/build/lib-client/local-files/dev-file-src.js +2 -2
  148. package/build/lib-client/local-files/device-fs.d.ts +1 -1
  149. package/build/lib-client/local-files/device-fs.js +56 -54
  150. package/build/lib-client/logging/log-to-file.d.ts +1 -1
  151. package/build/lib-client/logging/log-to-file.js +7 -7
  152. package/build/lib-client/mailer-id/login.js +7 -7
  153. package/build/lib-client/mailer-id/provisioner.js +12 -12
  154. package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -3
  155. package/build/lib-client/objs-on-disk/obj-folders.js +31 -31
  156. package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +13 -2
  157. package/build/lib-client/objs-on-disk/obj-on-disk.js +24 -9
  158. package/build/lib-client/request-utils.d.ts +1 -0
  159. package/build/lib-client/request-utils.js +13 -13
  160. package/build/lib-client/server-events.d.ts +3 -3
  161. package/build/lib-client/server-events.js +9 -8
  162. package/build/lib-client/service-locator.js +10 -10
  163. package/build/lib-client/user-with-mid-session.d.ts +2 -1
  164. package/build/lib-client/user-with-mid-session.js +14 -8
  165. package/build/lib-client/user-with-pkl-session.js +25 -25
  166. package/build/lib-client/ws-utils.js +2 -2
  167. package/build/lib-common/async-cryptor-wrap.js +4 -4
  168. package/build/lib-common/async-fs-node.d.ts +5 -3
  169. package/build/lib-common/async-fs-node.js +17 -17
  170. package/build/lib-common/byte-streaming/pipe.js +1 -1
  171. package/build/lib-common/byte-streaming/wrapping.js +13 -13
  172. package/build/lib-common/canonical-address.js +1 -1
  173. package/build/lib-common/exceptions/error.d.ts +1 -0
  174. package/build/lib-common/exceptions/error.js +7 -6
  175. package/build/lib-common/exceptions/file.d.ts +4 -2
  176. package/build/lib-common/exceptions/file.js +24 -54
  177. package/build/lib-common/ipc/generic-ipc.js +5 -4
  178. package/build/lib-common/ipc/ws-ipc.js +2 -2
  179. package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
  180. package/build/lib-common/objs-on-disk/file-layout.d.ts +19 -0
  181. package/build/lib-common/objs-on-disk/file-layout.js +130 -12
  182. package/build/lib-common/objs-on-disk/obj-file.d.ts +13 -2
  183. package/build/lib-common/objs-on-disk/obj-file.js +96 -35
  184. package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
  185. package/build/lib-common/objs-on-disk/utils.js +3 -3
  186. package/build/lib-common/objs-on-disk/v1-obj-file-format.js +14 -14
  187. package/build/lib-common/processes/labelled-exec-pools.d.ts +1 -1
  188. package/build/lib-common/processes/labelled-exec-pools.js +1 -1
  189. package/build/lib-common/processes/pressure.js +2 -2
  190. package/build/lib-common/processes/synced.js +1 -1
  191. package/build/lib-common/processes/timeout.js +2 -2
  192. package/build/lib-common/random-node.js +7 -7
  193. package/build/lib-common/service-api/3nstorage/owner.d.ts +101 -42
  194. package/build/lib-common/service-api/3nstorage/owner.js +83 -40
  195. package/build/lib-common/service-api/asmail/delivery.js +2 -2
  196. package/build/lib-common/service-api/asmail/retrieval.js +1 -1
  197. package/build/lib-common/timed-cache.d.ts +1 -0
  198. package/build/lib-common/timed-non-weak-cache.d.ts +1 -0
  199. package/build/lib-common/timed-non-weak-cache.js +11 -0
  200. package/build/lib-common/utils-for-observables.js +4 -4
  201. package/build/lib-common/weak-cache.d.ts +1 -0
  202. package/build/lib-common/weak-cache.js +12 -1
  203. package/build/lib-index.d.ts +2 -1
  204. package/build/lib-index.js +10 -7
  205. package/build/protos/asmail.proto.js +12955 -7496
  206. package/build/protos/file.proto.js +4867 -2744
  207. package/build/protos/fs.proto.js +9227 -3768
  208. package/package.json +7 -5
  209. package/protos/file.proto +91 -19
  210. package/protos/fs.proto +107 -8
  211. package/build/core/id-manager.d.ts +0 -46
@@ -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
@@ -18,10 +18,13 @@
18
18
 
19
19
  declare namespace web3n.files {
20
20
 
21
- interface FileException extends RuntimeException {
21
+ interface FileException extends RuntimeException, FileExceptionFlag {
22
22
  type: 'file';
23
23
  code: string|undefined;
24
24
  path: string;
25
+ }
26
+
27
+ interface FileExceptionFlag {
25
28
  notFound?: true;
26
29
  alreadyExists?: true;
27
30
  notDirectory?: true;
@@ -48,18 +51,30 @@ declare namespace web3n.files {
48
51
  alreadyExists: 'EEXIST';
49
52
  notDirectory: 'ENOTDIR';
50
53
  notFile: 'ENOTFILE';
51
- notLink: 'not-link';
52
54
  isDirectory: 'EISDIR';
53
55
  notEmpty: 'ENOTEMPTY';
54
56
  endOfFile: 'EEOF';
55
57
  opNotPermitted: 'EPERM';
56
58
  busy: 'EBUSY';
57
59
  ioError: 'EIO';
58
- concurrentUpdate: 'concurrent-update';
59
- parsingError: 'parsing-error';
60
60
  notImplemented: 'ENOSYS';
61
- isEndless: 'is-endless';
62
- storageClosed: 'storage-closed';
61
+ }
62
+
63
+ interface FSSyncException extends RuntimeException {
64
+ type: 'fs-sync';
65
+ path: string;
66
+ localVersion?: number;
67
+ remoteVersion?: number;
68
+ alreadyUploading?: true;
69
+ versionNotFound?: true;
70
+ childNeverUploaded?: true;
71
+ childName?: string;
72
+ removedOnServer?: true;
73
+ versionMismatch?: true;
74
+ conflict?: true;
75
+ notSynced?: true;
76
+ remoteIsArchived?: true;
77
+ remoteFolderItemNotFound?: true;
63
78
  }
64
79
 
65
80
  /**
@@ -126,18 +141,39 @@ declare namespace web3n.files {
126
141
  */
127
142
  version?: number;
128
143
 
129
- /**
130
- * This tells object's latest sync state.
131
- * If such information cannot be provided, this field will be absent.
132
- */
133
- sync?: {
134
- state: SyncState;
135
- latest?: number;
136
- conflictingRemote?: number[];
137
- remote?: number;
138
- deletedOnRemote?: true;
139
- };
144
+ }
140
145
 
146
+ /**
147
+ * Sync status contains info about possible version branches with possible
148
+ * states:
149
+ * 1. unsynced - have local branch, and possibly synced one.
150
+ * Local version(s) should be uploaded to get into synced state.
151
+ * 2. synced - have only synced branch.
152
+ * 3. behind - have both synced and remote branches.
153
+ * Should explicitly advance to newer version to get into synced state.
154
+ * 4. conflicting - have conflicting local and remote branches, with possible
155
+ * common synced history branch.
156
+ * Conflict gets fixed by uploading some local version with value greater
157
+ * than remote's latest. Making this version is a custom magic of
158
+ * conflict resolution that you do for your app.
159
+ */
160
+ interface SyncStatus {
161
+ state: SyncState;
162
+ synced?: SyncVersionsBranch;
163
+ local?: LocalVersion;
164
+ remote?: SyncVersionsBranch;
165
+ existsInSyncedParent?: boolean;
166
+ }
167
+
168
+ interface LocalVersion {
169
+ latest?: number;
170
+ isArchived?: boolean;
171
+ }
172
+
173
+ interface SyncVersionsBranch {
174
+ latest?: number;
175
+ archived?: number[];
176
+ isArchived?: boolean;
141
177
  }
142
178
 
143
179
  type SyncState = 'synced' | 'behind' | 'unsynced' | 'conflicting';
@@ -328,7 +364,7 @@ declare namespace web3n.files {
328
364
  */
329
365
  getByteSource(): Promise<FileByteSource>;
330
366
 
331
- watch(observer: Observer<FileEvent>): () => void;
367
+ watch(observer: Observer<FileEvent|RemoteEvent>): () => void;
332
368
 
333
369
  }
334
370
 
@@ -398,8 +434,9 @@ declare namespace web3n.files {
398
434
  * greater than file length, all available bytes are read. If parameter
399
435
  * is missing, read will be done to file's end.
400
436
  */
401
- readBytes(start?: number, end?: number):
402
- Promise<{ bytes: Uint8Array|undefined; version: number; }>;
437
+ readBytes(
438
+ start?: number, end?: number
439
+ ): Promise<{ bytes: Uint8Array|undefined; version: number; }>;
403
440
 
404
441
  /**
405
442
  * This returns a promise, resolvable to text, read from file, assuming
@@ -418,6 +455,10 @@ declare namespace web3n.files {
418
455
  */
419
456
  getByteSource(): Promise<{ src: FileByteSource; version: number; }>;
420
457
 
458
+ listVersions(): Promise<{ current?: number; archived?: number[]; }>;
459
+
460
+ sync?: ReadonlyFileSyncAPI;
461
+
421
462
  }
422
463
 
423
464
  interface WritableFileVersionedAPI extends ReadonlyFileVersionedAPI {
@@ -460,8 +501,9 @@ declare namespace web3n.files {
460
501
  * When current version is given, an error is thrown, if file version at
461
502
  * the moment of writing is different.
462
503
  */
463
- getByteSink(truncateFile?: boolean, currentVersion?: number):
464
- Promise<{ sink: FileByteSink; version: number; }>;
504
+ getByteSink(
505
+ truncateFile?: boolean, currentVersion?: number
506
+ ): Promise<{ sink: FileByteSink; version: number; }>;
465
507
 
466
508
  /**
467
509
  * This returns a promise, resolvable to new file's version when copying
@@ -469,7 +511,48 @@ declare namespace web3n.files {
469
511
  * @param file which content will be copied into this file
470
512
  */
471
513
  copy(file: File): Promise<number>;
472
-
514
+
515
+ archiveCurrent(version?: number): Promise<number>;
516
+
517
+ sync?: WritableFileSyncAPI;
518
+
519
+ }
520
+
521
+ interface ReadonlyFileSyncAPI {
522
+
523
+ /**
524
+ * Returns synchronization status of this object, as is currently known
525
+ * here without checking remote server.
526
+ */
527
+ status(): Promise<SyncStatus>;
528
+
529
+ updateStatusInfo(): Promise<SyncStatus>;
530
+
531
+ isRemoteVersionOnDisk(
532
+ version: number
533
+ ): Promise<'partial'|'complete'|'none'>;
534
+
535
+ download(version: number): Promise<void>;
536
+
537
+ adoptRemote(opts?: OptionsToAdopteRemote): Promise<void>;
538
+
539
+ }
540
+
541
+ interface OptionsToAdopteRemote {
542
+ dropLocalVer?: boolean;
543
+ remoteVersion?: number;
544
+ download?: boolean;
545
+ }
546
+
547
+ interface WritableFileSyncAPI extends ReadonlyFileSyncAPI {
548
+
549
+ upload(opts?: OptionsToUploadLocal): Promise<void>;
550
+
551
+ }
552
+
553
+ interface OptionsToUploadLocal {
554
+ localVersion?: number;
555
+ uploadVersion?: number;
473
556
  }
474
557
 
475
558
  type FSType = 'device' | 'synced' | 'local' | 'share' | 'asmail-msg';
@@ -498,8 +581,9 @@ declare namespace web3n.files {
498
581
  * throwing of an exception, when folder does not exist. Default value is
499
582
  * false.
500
583
  */
501
- checkFolderPresence(path: string, throwIfMissing?: boolean):
502
- Promise<boolean>;
584
+ checkFolderPresence(
585
+ path: string, throwIfMissing?: boolean
586
+ ): Promise<boolean>;
503
587
 
504
588
  /**
505
589
  * This returns a promise, resolvable to true, if file exists, and to
@@ -509,8 +593,9 @@ declare namespace web3n.files {
509
593
  * throwing of an exception, when file does not exist. Default value is
510
594
  * false.
511
595
  */
512
- checkFilePresence(path: string, throwIfMissing?: boolean):
513
- Promise<boolean>;
596
+ checkFilePresence(
597
+ path: string, throwIfMissing?: boolean
598
+ ): Promise<boolean>;
514
599
 
515
600
  /**
516
601
  * This returns a promise, resolvable to true, if link exists, and to
@@ -520,8 +605,9 @@ declare namespace web3n.files {
520
605
  * throwing of an exception, when link does not exist. Default value is
521
606
  * false.
522
607
  */
523
- checkLinkPresence(path: string, throwIfMissing?: boolean):
524
- Promise<boolean>;
608
+ checkLinkPresence(
609
+ path: string, throwIfMissing?: boolean
610
+ ): Promise<boolean>;
525
611
 
526
612
  /**
527
613
  * This returns a promise, resolvable to stats of an entity at a given
@@ -546,12 +632,18 @@ declare namespace web3n.files {
546
632
 
547
633
  readLink(path: string): Promise<SymLink>;
548
634
 
549
- watchFolder(path: string, observer: Observer<FolderEvent>): () => void;
635
+ watchFolder(
636
+ path: string, observer: Observer<FolderEvent|RemoteEvent>
637
+ ): () => void;
550
638
 
551
- watchFile(path: string, observer: Observer<FileEvent>): () => void;
639
+ watchFile(
640
+ path: string, observer: Observer<FileEvent|RemoteEvent>
641
+ ): () => void;
552
642
 
553
- watchTree(path: string, observer: Observer<FolderEvent|FileEvent>):
554
- () => void;
643
+ watchTree(
644
+ path: string, depth: number|undefined,
645
+ observer: Observer<FolderEvent|FileEvent|RemoteEvent>
646
+ ): () => void;
555
647
 
556
648
  close(): Promise<void>;
557
649
 
@@ -593,8 +685,9 @@ declare namespace web3n.files {
593
685
  * greater than file length, all available bytes are read. If parameter
594
686
  * is missing, read will be done to file's end.
595
687
  */
596
- readBytes(path: string, start?: number, end?: number):
597
- Promise<Uint8Array|undefined>;
688
+ readBytes(
689
+ path: string, start?: number, end?: number
690
+ ): Promise<Uint8Array|undefined>;
598
691
 
599
692
  /**
600
693
  * This returns a promise, resolvable to bytes source with seek, which
@@ -619,8 +712,9 @@ declare namespace web3n.files {
619
712
  * @param path
620
713
  * @param criteria
621
714
  */
622
- select(path: string, criteria: SelectCriteria):
623
- Promise<{ items: FSCollection; completion: Promise<void>; }>;
715
+ select(
716
+ path: string, criteria: SelectCriteria
717
+ ): Promise<{ items: FSCollection; completion: Promise<void>; }>;
624
718
 
625
719
  }
626
720
 
@@ -752,8 +846,9 @@ declare namespace web3n.files {
752
846
  * @param overwrite is a flag that with a true value allows
753
847
  * overwrite of existing dst file. Default value is false.
754
848
  */
755
- copyFile(src: string, dst: string, overwrite?: boolean):
756
- Promise<void>;
849
+ copyFile(
850
+ src: string, dst: string, overwrite?: boolean
851
+ ): Promise<void>;
757
852
 
758
853
  /**
759
854
  * This returns a promise, resolvable when folder has been recursively
@@ -764,8 +859,9 @@ declare namespace web3n.files {
764
859
  * merge into existing folder and files overwriting inside. Default
765
860
  * value is false.
766
861
  */
767
- copyFolder(src: string, dst: string, mergeAndOverwrite?: boolean):
768
- Promise<void>;
862
+ copyFolder(
863
+ src: string, dst: string, mergeAndOverwrite?: boolean
864
+ ): Promise<void>;
769
865
 
770
866
  /**
771
867
  * This returns a promise, resolvable when file has been saved.
@@ -785,8 +881,9 @@ declare namespace web3n.files {
785
881
  * merge into existing folder and files overwriting inside. Default
786
882
  * value is false.
787
883
  */
788
- saveFolder(folder: FS, dst: string, mergeAndOverwrite?: boolean):
789
- Promise<void>;
884
+ saveFolder(
885
+ folder: FS, dst: string, mergeAndOverwrite?: boolean
886
+ ): Promise<void>;
790
887
 
791
888
  /**
792
889
  * This returns a promise, resolvable when file has been removed
@@ -830,8 +927,9 @@ declare namespace web3n.files {
830
927
  * @param flags are optional flags. Default flags are create=true,
831
928
  * exclusive=false.
832
929
  */
833
- writeBytes(path: string, bytes: Uint8Array, flags?: FileFlags):
834
- Promise<void>;
930
+ writeBytes(
931
+ path: string, bytes: Uint8Array, flags?: FileFlags
932
+ ): Promise<void>;
835
933
 
836
934
  /**
837
935
  * This returns a promise, resolvable to byte sink with seek
@@ -887,8 +985,9 @@ declare namespace web3n.files {
887
985
 
888
986
  interface ReadonlyFSVersionedAPI {
889
987
 
890
- getXAttr(path: string, xaName: string):
891
- Promise<{ attr: any; version: number; }>;
988
+ getXAttr(
989
+ path: string, xaName: string
990
+ ): Promise<{ attr: any; version: number; }>;
892
991
 
893
992
  listXAttrs(path: string): Promise<{ lst: string[]; version: number; }>;
894
993
 
@@ -897,8 +996,9 @@ declare namespace web3n.files {
897
996
  * for entries in the folder, and a folder's version.
898
997
  * @param path of a folder that should be listed
899
998
  */
900
- listFolder(path: string):
901
- Promise<{ lst: ListingEntry[]; version: number; }>;
999
+ listFolder(
1000
+ path: string
1001
+ ): Promise<{ lst: ListingEntry[]; version: number; }>;
902
1002
 
903
1003
  /**
904
1004
  * This returns a promise, resolvable to json, read from file, and a
@@ -925,16 +1025,24 @@ declare namespace web3n.files {
925
1025
  * greater than file length, all available bytes are read. If parameter
926
1026
  * is missing, read will be done to file's end.
927
1027
  */
928
- readBytes(path: string, start?: number, end?: number):
929
- Promise<{ bytes: Uint8Array|undefined; version: number; }>;
1028
+ readBytes(
1029
+ path: string, start?: number, end?: number
1030
+ ): Promise<{ bytes: Uint8Array|undefined; version: number; }>;
930
1031
 
931
1032
  /**
932
1033
  * This returns a promise, resolvable to bytes source with seek, which
933
1034
  * allows random reads, and a file version
934
1035
  * @param path of a file from which to read bytes
935
1036
  */
936
- getByteSource(path: string):
937
- Promise<{ src: FileByteSource; version: number; }>;
1037
+ getByteSource(
1038
+ path: string
1039
+ ): Promise<{ src: FileByteSource; version: number; }>;
1040
+
1041
+ listVersions(
1042
+ path: string
1043
+ ): Promise<{ current?: number; archived?: number[]; }>;
1044
+
1045
+ sync?: ReadonlyFSSyncAPI;
938
1046
 
939
1047
  }
940
1048
 
@@ -956,8 +1064,9 @@ declare namespace web3n.files {
956
1064
  * @param flags are optional flags. Default flags are create=true,
957
1065
  * exclusive=false.
958
1066
  */
959
- writeJSONFile(path: string, json: any, flags?: VersionedFileFlags):
960
- Promise<number>;
1067
+ writeJSONFile(
1068
+ path: string, json: any, flags?: VersionedFileFlags
1069
+ ): Promise<number>;
961
1070
 
962
1071
  /**
963
1072
  * This returns a promise, resolvable to new file's version when file is
@@ -967,8 +1076,9 @@ declare namespace web3n.files {
967
1076
  * @param flags are optional flags. Default flags are create=true,
968
1077
  * exclusive=false.
969
1078
  */
970
- writeTxtFile(path: string, txt: string, flags?: VersionedFileFlags):
971
- Promise<number>;
1079
+ writeTxtFile(
1080
+ path: string, txt: string, flags?: VersionedFileFlags
1081
+ ): Promise<number>;
972
1082
 
973
1083
  /**
974
1084
  * This returns a promise, resolvable to new file's version when file is
@@ -978,8 +1088,9 @@ declare namespace web3n.files {
978
1088
  * @param flags are optional flags. Default flags are create=true,
979
1089
  * exclusive=false.
980
1090
  */
981
- writeBytes(path: string, bytes: Uint8Array, flags?: VersionedFileFlags):
982
- Promise<number>;
1091
+ writeBytes(
1092
+ path: string, bytes: Uint8Array, flags?: VersionedFileFlags
1093
+ ): Promise<number>;
983
1094
 
984
1095
  /**
985
1096
  * This returns a promise, resolvable to byte sink with seek, and a file
@@ -988,53 +1099,148 @@ declare namespace web3n.files {
988
1099
  * @param flags are optional flags. Default flags are create=true,
989
1100
  * exclusive=false, truncate=true.
990
1101
  */
991
- getByteSink(path: string, flags?: VersionedFileFlags):
992
- Promise<{ sink: FileByteSink; version: number; }>;
1102
+ getByteSink(
1103
+ path: string, flags?: VersionedFileFlags
1104
+ ): Promise<{ sink: FileByteSink; version: number; }>;
993
1105
 
1106
+ archiveCurrent(path: string, version?: number): Promise<number>;
1107
+
1108
+ sync?: WritableFSSyncAPI;
1109
+
1110
+ }
1111
+
1112
+ interface ReadonlyFSSyncAPI {
1113
+
1114
+ /**
1115
+ * Returns synchronization status of this object, as is currently known
1116
+ * here without checking remote server.
1117
+ */
1118
+ status(path: string): Promise<SyncStatus>;
1119
+
1120
+ updateStatusInfo(path: string): Promise<SyncStatus>;
1121
+
1122
+ isRemoteVersionOnDisk(
1123
+ path: string, version: number
1124
+ ): Promise<'partial'|'complete'|'none'>;
1125
+
1126
+ download(path: string, version: number): Promise<void>;
1127
+
1128
+ adoptRemote(path: string, opts?: OptionsToAdopteRemote): Promise<void>;
1129
+
1130
+ diffCurrentAndRemoteFolderVersions(
1131
+ path: string, remoteVersion?: number
1132
+ ): Promise<FolderDiff|undefined>;
1133
+
1134
+ }
1135
+
1136
+ interface FolderDiff {
1137
+ currentVersion: number;
1138
+ isCurrentLocal: boolean;
1139
+ remoteVersion?: number;
1140
+ isRemoteArchived: boolean;
1141
+ inCurrent?: ListingEntry[];
1142
+ inRemote?: ListingEntry[];
1143
+ nameOverlaps?: string[];
1144
+ ctime: {
1145
+ remote?: Date;
1146
+ current: Date;
1147
+ };
1148
+ mtime: {
1149
+ remote?: Date;
1150
+ current: Date;
1151
+ };
1152
+ xattrs?: {
1153
+ inCurrent?: { name: string; value: any; }[];
1154
+ inRemote?: { name: string; value: any; }[];
1155
+ nameOverlaps?: string[];
1156
+ };
1157
+ }
1158
+
1159
+ interface WritableFSSyncAPI extends ReadonlyFSSyncAPI {
1160
+
1161
+ upload(path: string, opts?: OptionsToUploadLocal): Promise<void>;
1162
+
1163
+ adoptRemoteFolderItem(
1164
+ path: string, itemName: string, opts?: OptionsToAdoptRemoteItem
1165
+ ): Promise<number>;
1166
+
1167
+ }
1168
+
1169
+ interface OptionsToAdoptRemoteItem {
1170
+ localVersion?: number;
1171
+ remoteVersion?: number;
994
1172
  }
995
1173
 
996
1174
  interface FSEvent {
997
- type: string;
998
1175
  path: string;
999
- isRemote?: boolean;
1000
- newVersion?: number;
1001
1176
  }
1002
1177
 
1003
- interface RemovedEvent extends FSEvent {
1178
+ interface FSChangeEvent {
1179
+ path: string;
1180
+ src: 'local'|'sync';
1181
+ }
1182
+
1183
+ interface RemovedEvent extends FSChangeEvent {
1004
1184
  type: 'removed';
1005
1185
  }
1006
1186
 
1007
- interface SyncUploadEvent extends FSEvent {
1008
- type: 'sync-upload';
1009
- uploaded: number;
1010
- current: number;
1187
+ interface VersionChangeOnUpload extends FSChangeEvent {
1188
+ type: 'version-change-on-upload';
1189
+ src: 'sync';
1190
+ newVersion: number;
1011
1191
  }
1012
1192
 
1013
1193
  type FolderEvent = EntryRemovalEvent | EntryAdditionEvent |
1014
- EntryRenamingEvent | RemovedEvent | SyncUploadEvent;
1194
+ EntryRenamingEvent | RemovedEvent | VersionChangeOnUpload;
1015
1195
 
1016
- interface EntryRemovalEvent extends FSEvent {
1196
+ interface EntryRemovalEvent extends FSChangeEvent {
1017
1197
  type: 'entry-removal';
1018
1198
  name: string;
1019
1199
  moveLabel?: number;
1200
+ newVersion?: number;
1020
1201
  }
1021
1202
 
1022
- interface EntryAdditionEvent extends FSEvent {
1203
+ interface EntryAdditionEvent extends FSChangeEvent {
1023
1204
  type: 'entry-addition';
1024
1205
  entry: ListingEntry;
1025
1206
  moveLabel?: number;
1207
+ newVersion?: number;
1026
1208
  }
1027
1209
 
1028
- interface EntryRenamingEvent extends FSEvent {
1210
+ interface EntryRenamingEvent extends FSChangeEvent {
1029
1211
  type: 'entry-renaming';
1030
1212
  oldName: string;
1031
1213
  newName: string;
1214
+ newVersion?: number;
1032
1215
  }
1033
1216
 
1034
- type FileEvent = FileChangeEvent | RemovedEvent | SyncUploadEvent;
1217
+ type FileEvent = FileChangeEvent | RemovedEvent | VersionChangeOnUpload;
1035
1218
 
1036
- interface FileChangeEvent extends FSEvent {
1219
+ interface FileChangeEvent extends FSChangeEvent {
1037
1220
  type: 'file-change';
1221
+ newVersion?: number;
1222
+ }
1223
+
1224
+ type RemoteEvent = RemoteVersionArchivalEvent | RemoteArchVerRemovalEvent |
1225
+ RemoteRemovalEvent | RemoteChangeEvent;
1226
+
1227
+ interface RemoteVersionArchivalEvent extends FSEvent {
1228
+ type: 'remote-version-archival';
1229
+ archivedVersion: number;
1230
+ }
1231
+
1232
+ interface RemoteArchVerRemovalEvent extends FSEvent {
1233
+ type: 'remote-arch-ver-removal';
1234
+ removedArchVer: number;
1235
+ }
1236
+
1237
+ interface RemoteRemovalEvent extends FSEvent {
1238
+ type: 'remote-removal';
1239
+ }
1240
+
1241
+ interface RemoteChangeEvent extends FSEvent {
1242
+ type: 'remote-change';
1243
+ newVersion: number;
1038
1244
  }
1039
1245
 
1040
1246
  }
@@ -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();
@@ -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,