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
@@ -23,7 +23,7 @@ exports.FileNode = void 0;
23
23
  */
24
24
  const node_in_fs_1 = require("./node-in-fs");
25
25
  const buffer_utils_1 = require("../../../lib-common/buffer-utils");
26
- const processes_1 = require("../../../lib-common/processes");
26
+ const deferred_1 = require("../../../lib-common/processes/deferred");
27
27
  const xsp_files_1 = require("xsp-files");
28
28
  const assert_1 = require("../../../lib-common/assert");
29
29
  const attrs_1 = require("./attrs");
@@ -97,7 +97,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
97
97
  if (!fileName || !objId) {
98
98
  throw new Error("Bad file parameter(s) given");
99
99
  }
100
- this.crypto = new FilePersistance(xsp_files_1.idToHeaderNonce(this.objId), key, this.storage.cryptor);
100
+ this.crypto = new FilePersistance((0, xsp_files_1.idToHeaderNonce)(this.objId), key, this.storage.cryptor);
101
101
  Object.seal(this);
102
102
  }
103
103
  static async makeForNew(storage, parentId, name, key) {
@@ -123,12 +123,15 @@ class FileNode extends node_in_fs_1.NodeInFS {
123
123
  return file;
124
124
  }
125
125
  static async initWithAttrs(storage, parentId, fileName, objId, key) {
126
- const src = await storage.getObj(objId);
126
+ const src = await storage.getObjSrc(objId);
127
127
  const file = new FileNode(storage, fileName, objId, src.version, parentId, key);
128
- const fileAttrs = await file.crypto.getAttrs(src);
129
- file.setUpdatedState(src.version, fileAttrs);
128
+ await file.setCurrentStateFrom(src);
130
129
  return file;
131
130
  }
131
+ async setCurrentStateFrom(src) {
132
+ const fileAttrs = await this.crypto.getAttrs(src);
133
+ this.setUpdatedState(src.version, fileAttrs);
134
+ }
132
135
  setUpdatedState(version, fileAttrs) {
133
136
  this.fileSize = fileAttrs.size;
134
137
  super.setUpdatedParams(version, fileAttrs.attrs, fileAttrs.xattrs);
@@ -137,7 +140,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
137
140
  return this.fileSize;
138
141
  }
139
142
  async readSrc() {
140
- const objSrc = await this.storage.getObj(this.objId);
143
+ const objSrc = await this.storage.getObjSrc(this.objId);
141
144
  if ((this.storage.type === 'synced') || (this.storage.type === 'local')) {
142
145
  const version = objSrc.version;
143
146
  if (this.version < version) {
@@ -157,7 +160,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
157
160
  }
158
161
  }
159
162
  async readBytes(start, end) {
160
- const objSrc = await this.storage.getObj(this.objId);
163
+ const objSrc = await this.storage.getObjSrc(this.objId);
161
164
  if ((this.storage.type === 'synced') || (this.storage.type === 'local')) {
162
165
  const version = objSrc.version;
163
166
  if (this.version < version) {
@@ -177,8 +180,8 @@ class FileNode extends node_in_fs_1.NodeInFS {
177
180
  }
178
181
  }
179
182
  async writeSink(truncate, currentVersion, changes) {
180
- const deferredSink = processes_1.defer();
181
- const newSize = processes_1.defer();
183
+ const deferredSink = (0, deferred_1.defer)();
184
+ const newSize = (0, deferred_1.defer)();
182
185
  let version = 0; // need to set any value to satisfy compiler
183
186
  const completion = this.doChange(false, async () => {
184
187
  const { attrs, xattrs, newVersion, sinkPromise, sub } = await this.startMakingSinkInsideChange(truncate, currentVersion, changes);
@@ -194,12 +197,12 @@ class FileNode extends node_in_fs_1.NodeInFS {
194
197
  }),
195
198
  completion
196
199
  ]);
197
- assert_1.assert(!!sink);
200
+ (0, assert_1.assert)(!!sink);
198
201
  // sink's done should await completion of obj saving, and
199
202
  // error in obj saving should cancel sink
200
203
  const originalDone = sink.done;
201
204
  completion.catch(originalDone);
202
- assert_1.assert(!Object.isFrozen(sink), `Can't mutate frozen sink`);
205
+ (0, assert_1.assert)(!Object.isFrozen(sink), `Can't mutate frozen sink`);
203
206
  sink.done = async (err) => {
204
207
  if (err) {
205
208
  newSize.resolve(0);
@@ -218,12 +221,12 @@ class FileNode extends node_in_fs_1.NodeInFS {
218
221
  async startMakingSinkInsideChange(truncate, currentVersion, changes) {
219
222
  if ((typeof currentVersion === 'number')
220
223
  && (this.version !== currentVersion)) {
221
- throw file_1.makeVersionMismatchExc(this.name);
224
+ throw (0, file_1.makeVersionMismatchExc)(this.name);
222
225
  }
223
226
  const { attrs, xattrs, newVersion } = super.getParamsForUpdate(changes);
224
227
  const base = ((truncate || (this.version === 0)) ?
225
228
  undefined :
226
- await this.storage.getObj(this.objId));
229
+ await this.storage.getObjSrc(this.objId));
227
230
  const { sinkPromise, sub } = await this.crypto.getFileSink(newVersion, attrs, xattrs, base);
228
231
  return { attrs, xattrs, newVersion, sinkPromise, sub };
229
232
  }
@@ -234,6 +237,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
234
237
  this.broadcastEvent({
235
238
  type: 'file-change',
236
239
  path: this.name,
240
+ src: 'local',
237
241
  newVersion
238
242
  });
239
243
  }
@@ -242,7 +246,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
242
246
  const { attrs, xattrs, newVersion } = super.getParamsForUpdate(changes);
243
247
  const encSub = await this.crypto.saveBytes(bytes, newVersion, attrs, xattrs);
244
248
  const newSize = Promise.resolve(Array.isArray(bytes) ?
245
- buffer_utils_1.byteLengthIn(bytes) : bytes.length);
249
+ (0, buffer_utils_1.byteLengthIn)(bytes) : bytes.length);
246
250
  await this.savingObjInsideChange(attrs, newSize, xattrs, newVersion, encSub);
247
251
  return this.version;
248
252
  });
@@ -10,6 +10,11 @@ declare type Observer<T> = web3n.Observer<T>;
10
10
  declare type FileByteSource = web3n.files.FileByteSource;
11
11
  declare type FileByteSink = web3n.files.FileByteSink;
12
12
  declare type XAttrsChanges = web3n.files.XAttrsChanges;
13
+ declare type WritableFileSyncAPI = web3n.files.WritableFileSyncAPI;
14
+ declare type SyncStatus = web3n.files.SyncStatus;
15
+ declare type WritableFileVersionedAPI = web3n.files.WritableFileVersionedAPI;
16
+ declare type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
17
+ declare type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
13
18
  export declare class FileObject implements WritableFile, Linkable {
14
19
  name: string;
15
20
  isNew: boolean;
@@ -17,7 +22,7 @@ export declare class FileObject implements WritableFile, Linkable {
17
22
  v: V;
18
23
  private constructor();
19
24
  static makeExisting(node: FileNode, writable: boolean): WritableFile | ReadonlyFile;
20
- static makeForNotExisiting(name: string, makeNode: () => Promise<FileNode>): WritableFile;
25
+ static makeForNotExisiting(name: string, makeNode: () => Promise<FileNode>, isInSyncedStorage: boolean): WritableFile;
21
26
  static makeFileFromLinkParams(storage: Storage, params: LinkParameters<FileLinkParams>): Promise<WritableFile | ReadonlyFile>;
22
27
  getLinkParams(): Promise<LinkParameters<FileLinkParams>>;
23
28
  stat(): Promise<Stats>;
@@ -35,14 +40,19 @@ export declare class FileObject implements WritableFile, Linkable {
35
40
  getByteSink(truncate?: boolean): Promise<FileByteSink>;
36
41
  copy(file: File): Promise<void>;
37
42
  }
38
- declare type WritableFileVersionedAPI = web3n.files.WritableFileVersionedAPI;
39
- declare class V implements WritableFileVersionedAPI {
43
+ interface N {
44
+ getNode(): Promise<FileNode>;
45
+ ensureIsWritable(): void;
46
+ }
47
+ declare class V implements WritableFileVersionedAPI, N {
40
48
  name: string;
41
49
  node: FileNode | undefined;
42
50
  private makeOrGetNode;
43
- writable: boolean;
44
- constructor(name: string, node: FileNode | undefined, makeOrGetNode: (() => Promise<FileNode>) | undefined, writable: boolean);
45
- private getNode;
51
+ readonly writable: boolean;
52
+ readonly sync: undefined | S;
53
+ constructor(name: string, node: FileNode | undefined, makeOrGetNode: (() => Promise<FileNode>) | undefined, writable: boolean, isInSyncedStorage: boolean);
54
+ getNode(): Promise<FileNode>;
55
+ ensureIsWritable(): void;
46
56
  updateXAttrs(changes: XAttrsChanges): Promise<number>;
47
57
  getXAttr(xaName: string): Promise<{
48
58
  attr: any;
@@ -77,5 +87,20 @@ declare class V implements WritableFileVersionedAPI {
77
87
  json: T;
78
88
  version: number;
79
89
  }>;
90
+ archiveCurrent(version?: number): Promise<number>;
91
+ listVersions(): Promise<{
92
+ current?: number;
93
+ archived?: number[];
94
+ }>;
95
+ }
96
+ declare class S implements WritableFileSyncAPI {
97
+ private readonly n;
98
+ constructor(n: N);
99
+ upload(opts?: OptionsToUploadLocal): Promise<void>;
100
+ status(): Promise<SyncStatus>;
101
+ updateStatusInfo(): Promise<SyncStatus>;
102
+ isRemoteVersionOnDisk(version: number): Promise<'complete' | 'partial' | 'none'>;
103
+ download(version: number): Promise<void>;
104
+ adoptRemote(opts?: OptionsToAdopteRemote): Promise<void>;
80
105
  }
81
106
  export {};
@@ -26,45 +26,41 @@ const files_1 = require("../../files");
26
26
  const file_node_1 = require("./file-node");
27
27
  const buffer_utils_1 = require("../../../lib-common/buffer-utils");
28
28
  const pipe_1 = require("../../../lib-common/byte-streaming/pipe");
29
+ const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
29
30
  class FileObject {
30
- constructor(name, isNew, node, makeOrGetNode, writable) {
31
+ constructor(name, isNew, node, makeOrGetNode, writable, isInSyncedStorage) {
31
32
  this.name = name;
32
33
  this.isNew = isNew;
33
34
  this.writable = writable;
34
- this.v = new V(name, node, makeOrGetNode, writable);
35
+ this.v = new V(name, node, makeOrGetNode, writable, isInSyncedStorage);
35
36
  Object.seal(this);
36
37
  }
37
38
  static makeExisting(node, writable) {
38
- const f = new FileObject(node.name, false, node, undefined, writable);
39
- return (writable ?
40
- files_1.wrapWritableFile(f) : files_1.wrapReadonlyFile(f));
39
+ const f = new FileObject(node.name, false, node, undefined, writable, node.isInSyncedStorage);
40
+ return (writable ? (0, files_1.wrapWritableFile)(f) : (0, files_1.wrapReadonlyFile)(f));
41
41
  }
42
- static makeForNotExisiting(name, makeNode) {
43
- const f = new FileObject(name, true, undefined, makeNode, true);
44
- return files_1.wrapWritableFile(f);
42
+ static makeForNotExisiting(name, makeNode, isInSyncedStorage) {
43
+ const f = new FileObject(name, true, undefined, makeNode, true, isInSyncedStorage);
44
+ return (0, files_1.wrapWritableFile)(f);
45
45
  }
46
46
  static async makeFileFromLinkParams(storage, params) {
47
47
  const node = await file_node_1.FileNode.makeFromLinkParams(storage, params.params);
48
48
  return FileObject.makeExisting(node, !params.readonly);
49
49
  }
50
50
  async getLinkParams() {
51
- if (!this.v.node) {
52
- throw new Error('File does not exist, yet, and cannot be linked.');
53
- }
54
- const linkParams = this.v.node.getParamsForLink();
51
+ const node = await this.v.getNode();
52
+ const linkParams = node.getParamsForLink();
55
53
  linkParams.params.fileName = this.name;
56
54
  linkParams.readonly = !this.writable;
57
55
  return linkParams;
58
56
  }
59
57
  async stat() {
60
- if (!this.v.node) {
61
- throw file_1.makeFileException(file_1.Code.notFound, this.name);
62
- }
63
- const attrs = this.v.node.getAttrs();
58
+ const node = await this.v.getNode();
59
+ const attrs = node.getAttrs();
64
60
  const stat = {
65
61
  writable: this.writable,
66
- size: this.v.node.size,
67
- version: this.v.node.version,
62
+ size: node.size,
63
+ version: node.version,
68
64
  isFile: true,
69
65
  ctime: new Date(attrs.ctime),
70
66
  mtime: new Date(attrs.mtime),
@@ -87,7 +83,7 @@ class FileObject {
87
83
  throw new Error(`Node for file ${this.name} is not yet initialized`);
88
84
  }
89
85
  const sub = this.v.node.event$
90
- .subscribe(observer);
86
+ .subscribe((0, utils_for_observables_1.toRxObserver)(observer));
91
87
  return () => sub.unsubscribe();
92
88
  }
93
89
  async readBytes(start, end) {
@@ -127,11 +123,12 @@ exports.FileObject = FileObject;
127
123
  Object.freeze(FileObject.prototype);
128
124
  Object.freeze(FileObject);
129
125
  class V {
130
- constructor(name, node, makeOrGetNode, writable) {
126
+ constructor(name, node, makeOrGetNode, writable, isInSyncedStorage) {
131
127
  this.name = name;
132
128
  this.node = node;
133
129
  this.makeOrGetNode = makeOrGetNode;
134
130
  this.writable = writable;
131
+ this.sync = (isInSyncedStorage ? new S(this) : undefined);
135
132
  Object.seal(this);
136
133
  }
137
134
  async getNode() {
@@ -141,7 +138,13 @@ class V {
141
138
  }
142
139
  return this.node;
143
140
  }
141
+ ensureIsWritable() {
142
+ if (!this.writable) {
143
+ throw new Error(`File is not writable`);
144
+ }
145
+ }
144
146
  async updateXAttrs(changes) {
147
+ this.ensureIsWritable();
145
148
  const node = await this.getNode();
146
149
  return node.updateXAttrs(changes);
147
150
  }
@@ -169,16 +172,18 @@ class V {
169
172
  return linkParams;
170
173
  }
171
174
  async getByteSink(truncate = true, currentVersion) {
175
+ this.ensureIsWritable();
172
176
  const node = await this.getNode();
173
177
  return node.writeSink(truncate, currentVersion);
174
178
  }
175
179
  async getByteSource() {
176
180
  if (!this.node) {
177
- throw file_1.makeFileException(file_1.Code.notFound, this.name);
181
+ throw (0, file_1.makeFileException)(file_1.Code.notFound, this.name);
178
182
  }
179
183
  return this.node.readSrc();
180
184
  }
181
185
  async writeBytes(bytes) {
186
+ this.ensureIsWritable();
182
187
  const node = await this.getNode();
183
188
  return node.save(bytes);
184
189
  }
@@ -191,7 +196,7 @@ class V {
191
196
  }
192
197
  async readBytes(start, end) {
193
198
  if (!this.node) {
194
- throw file_1.makeFileException(file_1.Code.notFound, this.name);
199
+ throw (0, file_1.makeFileException)(file_1.Code.notFound, this.name);
195
200
  }
196
201
  return await this.node.readBytes(start, end);
197
202
  }
@@ -204,7 +209,7 @@ class V {
204
209
  const { version, sink } = await this.getByteSink();
205
210
  const src = (file.v ?
206
211
  (await file.v.getByteSource()).src : await file.getByteSource());
207
- await pipe_1.pipe(src, sink);
212
+ await (0, pipe_1.pipe)(src, sink);
208
213
  return version;
209
214
  }
210
215
  async readJSON() {
@@ -212,7 +217,53 @@ class V {
212
217
  const json = JSON.parse(txt);
213
218
  return { json, version };
214
219
  }
220
+ async archiveCurrent(version) {
221
+ this.ensureIsWritable();
222
+ const node = await this.getNode();
223
+ return node.archiveCurrent(version);
224
+ }
225
+ async listVersions() {
226
+ const node = await this.getNode();
227
+ return node.listVersions();
228
+ }
215
229
  }
216
230
  Object.freeze(V.prototype);
217
231
  Object.freeze(V);
232
+ class S {
233
+ constructor(n) {
234
+ this.n = n;
235
+ Object.freeze(this);
236
+ }
237
+ async upload(opts) {
238
+ this.n.ensureIsWritable();
239
+ const node = await this.n.getNode();
240
+ const uploadVersion = await node.upload(opts);
241
+ return uploadVersion;
242
+ }
243
+ async status() {
244
+ const node = await this.n.getNode();
245
+ const status = await node.syncStatus();
246
+ return status;
247
+ }
248
+ async updateStatusInfo() {
249
+ const node = await this.n.getNode();
250
+ const status = await node.updateStatusInfo();
251
+ return status;
252
+ }
253
+ async isRemoteVersionOnDisk(version) {
254
+ const node = await this.n.getNode();
255
+ const isOnDisk = await node.isSyncedVersionOnDisk(version);
256
+ return isOnDisk;
257
+ }
258
+ async download(version) {
259
+ const node = await this.n.getNode();
260
+ await node.download(version);
261
+ }
262
+ async adoptRemote(opts) {
263
+ const node = await this.n.getNode();
264
+ await node.adoptRemote(opts);
265
+ }
266
+ }
267
+ Object.freeze(S.prototype);
268
+ Object.freeze(S);
218
269
  Object.freeze(exports);
@@ -64,14 +64,14 @@ var formatV1;
64
64
  o: nodeInfo.objId
65
65
  };
66
66
  const jsonBytes = buffer_utils_1.utf8.pack(JSON.stringify(json));
67
- assert_1.assert(jsonBytes.length < 0xffffffff);
67
+ (0, assert_1.assert)(jsonBytes.length < 0xffffffff);
68
68
  bytes.push(numberToBytes(jsonBytes.length));
69
69
  bytes.push(jsonBytes);
70
70
  return bytes;
71
71
  }
72
72
  function numberToBytes(x) {
73
73
  const arr = Buffer.allocUnsafe(4);
74
- big_endian_1.packUintTo4Bytes(x, arr, 0);
74
+ (0, big_endian_1.packUintTo4Bytes)(x, arr, 0);
75
75
  return arr;
76
76
  }
77
77
  function parse(bytes) {
@@ -92,9 +92,9 @@ var formatV1;
92
92
  if (bytes.length < (xsp_files_1.KEY_LENGTH + 4)) {
93
93
  throw parsingException(`Cannot deserialize node key from bytes`);
94
94
  }
95
- const key = buffer_utils_1.makeUint8ArrayCopy(bytes.subarray(0, xsp_files_1.KEY_LENGTH));
95
+ const key = (0, buffer_utils_1.makeUint8ArrayCopy)(bytes.subarray(0, xsp_files_1.KEY_LENGTH));
96
96
  bytes = bytes.subarray(xsp_files_1.KEY_LENGTH);
97
- const jsonBytesLen = big_endian_1.uintFrom4Bytes(bytes);
97
+ const jsonBytesLen = (0, big_endian_1.uintFrom4Bytes)(bytes);
98
98
  bytes = bytes.subarray(4);
99
99
  try {
100
100
  const json = JSON.parse(buffer_utils_1.utf8.open(bytes.subarray(0, jsonBytesLen)));
@@ -1,4 +1,4 @@
1
- import { Storage, Node, NodeType } from './common';
1
+ import { Storage, Node, NodeType, FSChangeSrc } from './common';
2
2
  import { NodeInFS } from './node-in-fs';
3
3
  import { FileNode } from './file-node';
4
4
  import { LinkNode } from './link-node';
@@ -8,6 +8,10 @@ import { CommonAttrs, XAttrs } from './attrs';
8
8
  import { NodePersistance } from './node-persistence';
9
9
  declare type ListingEntry = web3n.files.ListingEntry;
10
10
  declare type XAttrsChanges = web3n.files.XAttrsChanges;
11
+ declare type FolderDiff = web3n.files.FolderDiff;
12
+ declare type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
13
+ declare type OptionsToAdoptRemoteItem = web3n.files.OptionsToAdoptRemoteItem;
14
+ declare type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
11
15
  export interface NodeInfo {
12
16
  /**
13
17
  * This is a usual file name.
@@ -68,21 +72,18 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
68
72
  private static readNodeFromObjBytes;
69
73
  static rootFromLinkParams(storage: Storage, params: FolderLinkParams): Promise<FolderNode>;
70
74
  static rootFromJSON(storage: Storage, name: string | undefined, folderJson: FolderInJSON): FolderNode;
75
+ protected setCurrentStateFrom(src: ObjSource): Promise<void>;
76
+ adoptRemote(opts: OptionsToAdopteRemote | undefined): Promise<void>;
71
77
  list(): {
72
78
  lst: ListingEntry[];
73
79
  version: number;
74
80
  };
81
+ childExistsInSyncedVersion(childObjId: string): Promise<boolean>;
75
82
  listFolders(): string[];
76
- private getNodeInfo;
83
+ getNodeInfo(name: string, undefOnMissing?: boolean): NodeInfo | undefined;
77
84
  hasChild(childName: string, throwIfMissing?: boolean): boolean;
78
- /**
79
- * @param objId
80
- * @return either node (promise for node), or a deferred, which promise has
81
- * been registered under a given id, and, therefore, has to be resolved with
82
- * node.
83
- */
84
- private getNodeOrArrangePromise;
85
85
  getNode<T extends Node>(type: NodeType | undefined, name: string, undefOnMissing?: boolean): Promise<T | undefined>;
86
+ private getOrMakeChildNodeForInfo;
86
87
  getFolder(name: string, undefOnMissing?: boolean): Promise<FolderNode | undefined>;
87
88
  getFile(name: string, undefOnMissing?: boolean): Promise<FileNode | undefined>;
88
89
  getLink(name: string, undefOnMissing?: boolean): Promise<LinkNode | undefined>;
@@ -130,8 +131,20 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
130
131
  */
131
132
  isEmpty(): boolean;
132
133
  private getAllNodes;
133
- protected delete(remoteEvent?: boolean): Promise<void>;
134
+ protected delete(src: FSChangeSrc): Promise<void>;
134
135
  getParamsForLink(): LinkParameters<FolderLinkParams>;
135
- protected doOnExternalChange(expectedVersion: number): Promise<void>;
136
+ upload(opts: OptionsToUploadLocal | undefined): Promise<void>;
137
+ protected needUpload(localVersion: number | undefined): Promise<{
138
+ localVersion: number;
139
+ uploadVersion: number;
140
+ createOnRemote: boolean;
141
+ } | undefined>;
142
+ adoptRemoteFolderItem(itemName: string, opts: OptionsToAdoptRemoteItem | undefined): Promise<number>;
143
+ private addRemoteChild;
144
+ private setRemoteNodeInfo;
145
+ private replaceLocalChildWithRemote;
146
+ diffCurrentAndRemote(remoteVersion: number | undefined): Promise<FolderDiff | undefined>;
147
+ private diffWithArchivedRemote;
148
+ private diffWithRemote;
136
149
  }
137
150
  export {};