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
@@ -16,7 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.wrapSyncStorageImplementation = exports.wrapStorageImplementation = exports.NodesContainer = void 0;
19
+ exports.setPathInExc = exports.isSyncedStorage = exports.wrapSyncStorageImplementation = exports.wrapStorageImplementation = exports.NodesContainer = void 0;
20
20
  /**
21
21
  * This is a container for file system nodes.
22
22
  *
@@ -98,14 +98,16 @@ function wrapStorageImplementation(impl) {
98
98
  type: impl.type,
99
99
  versioned: impl.versioned,
100
100
  nodes: impl.nodes,
101
+ logError: impl.logError,
101
102
  getNodeEvents: impl.getNodeEvents.bind(impl),
102
103
  broadcastNodeEvent: impl.broadcastNodeEvent.bind(impl),
103
104
  storageForLinking: impl.storageForLinking.bind(impl),
104
105
  generateNewObjId: impl.generateNewObjId.bind(impl),
105
- getObj: impl.getObj.bind(impl),
106
+ getObjSrc: impl.getObjSrc.bind(impl),
106
107
  saveObj: impl.saveObj.bind(impl),
107
108
  close: impl.close.bind(impl),
108
109
  removeObj: impl.removeObj.bind(impl),
110
+ status: impl.status.bind(impl),
109
111
  cryptor: impl.cryptor
110
112
  };
111
113
  return Object.freeze(wrap);
@@ -113,24 +115,33 @@ function wrapStorageImplementation(impl) {
113
115
  exports.wrapStorageImplementation = wrapStorageImplementation;
114
116
  function wrapSyncStorageImplementation(impl) {
115
117
  const storageWrap = wrapStorageImplementation(impl);
116
- const wrap = {
117
- type: storageWrap.type,
118
- versioned: storageWrap.versioned,
119
- close: storageWrap.close,
120
- cryptor: storageWrap.cryptor,
121
- generateNewObjId: storageWrap.generateNewObjId,
122
- getObj: storageWrap.getObj,
123
- nodes: storageWrap.nodes,
124
- getNodeEvents: storageWrap.getNodeEvents,
125
- broadcastNodeEvent: storageWrap.broadcastNodeEvent,
126
- removeObj: storageWrap.removeObj,
127
- saveObj: storageWrap.saveObj,
128
- storageForLinking: storageWrap.storageForLinking,
129
- getRootKeyDerivParamsFromServer: impl.getRootKeyDerivParamsFromServer.bind(impl),
130
- getRemoteConflictObjVersion: impl.getRemoteConflictObjVersion.bind(impl),
131
- getObjSyncInfo: impl.getObjSyncInfo.bind(impl)
132
- };
118
+ const wrap = {};
119
+ for (const [field, value] of Object.entries(storageWrap)) {
120
+ wrap[field] = value;
121
+ }
122
+ wrap.getRootKeyDerivParamsFromServer =
123
+ impl.getRootKeyDerivParamsFromServer.bind(impl);
124
+ wrap.getObjSrcOfRemoteVersion = impl.getObjSrcOfRemoteVersion.bind(impl);
125
+ wrap.archiveVersionOnServer = impl.archiveVersionOnServer.bind(impl);
126
+ wrap.isRemoteVersionOnDisk = impl.isRemoteVersionOnDisk.bind(impl);
127
+ wrap.download = impl.download.bind(impl);
128
+ wrap.upload = impl.upload.bind(impl);
129
+ wrap.uploadObjRemoval = impl.uploadObjRemoval.bind(impl);
130
+ wrap.dropCachedLocalObjVersionsLessOrEqual = impl.dropCachedLocalObjVersionsLessOrEqual.bind(impl);
131
+ wrap.adoptRemote = impl.adoptRemote.bind(impl);
132
+ wrap.updateStatusInfo = impl.updateStatusInfo.bind(impl);
133
133
  return Object.freeze(wrap);
134
134
  }
135
135
  exports.wrapSyncStorageImplementation = wrapSyncStorageImplementation;
136
+ function isSyncedStorage(storage) {
137
+ return !!storage.upload;
138
+ }
139
+ exports.isSyncedStorage = isSyncedStorage;
140
+ function setPathInExc(exc, path) {
141
+ if ((exc.type === 'fs-sync') || (exc.type === 'file')) {
142
+ exc.path = path;
143
+ }
144
+ return exc;
145
+ }
146
+ exports.setPathInExc = setPathInExc;
136
147
  Object.freeze(exports);
@@ -45,6 +45,7 @@ export declare class FileNode extends NodeInFS<FilePersistance> {
45
45
  static makeForExisting(storage: Storage, parentId: string, fileName: string, objId: string, key: Uint8Array): Promise<FileNode>;
46
46
  static makeFromLinkParams(storage: Storage, params: FileLinkParams): Promise<FileNode>;
47
47
  private static initWithAttrs;
48
+ protected setCurrentStateFrom(src: ObjSource): Promise<void>;
48
49
  private setUpdatedState;
49
50
  get size(): number;
50
51
  readSrc(): Promise<{
@@ -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 = deferred_1.defer();
181
- const newSize = deferred_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 {};
@@ -28,46 +28,39 @@ const buffer_utils_1 = require("../../../lib-common/buffer-utils");
28
28
  const pipe_1 = require("../../../lib-common/byte-streaming/pipe");
29
29
  const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
30
30
  class FileObject {
31
- constructor(name, isNew, node, makeOrGetNode, writable) {
31
+ constructor(name, isNew, node, makeOrGetNode, writable, isInSyncedStorage) {
32
32
  this.name = name;
33
33
  this.isNew = isNew;
34
34
  this.writable = writable;
35
- this.v = new V(name, node, makeOrGetNode, writable);
35
+ this.v = new V(name, node, makeOrGetNode, writable, isInSyncedStorage);
36
36
  Object.seal(this);
37
37
  }
38
38
  static makeExisting(node, writable) {
39
- const f = new FileObject(node.name, false, node, undefined, writable);
40
- return (writable ?
41
- 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));
42
41
  }
43
- static makeForNotExisiting(name, makeNode) {
44
- const f = new FileObject(name, true, undefined, makeNode, true);
45
- 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);
46
45
  }
47
46
  static async makeFileFromLinkParams(storage, params) {
48
47
  const node = await file_node_1.FileNode.makeFromLinkParams(storage, params.params);
49
48
  return FileObject.makeExisting(node, !params.readonly);
50
49
  }
51
50
  async getLinkParams() {
52
- if (!this.v.node) {
53
- throw new Error('File does not exist, yet, and cannot be linked.');
54
- }
55
- const linkParams = this.v.node.getParamsForLink();
51
+ const node = await this.v.getNode();
52
+ const linkParams = node.getParamsForLink();
56
53
  linkParams.params.fileName = this.name;
57
54
  linkParams.readonly = !this.writable;
58
55
  return linkParams;
59
56
  }
60
57
  async stat() {
61
- if (!this.v.node) {
62
- throw file_1.makeFileException(file_1.Code.notFound, this.name);
63
- }
64
- const sync = await this.v.node.sync();
65
- const attrs = this.v.node.getAttrs();
58
+ const node = await this.v.getNode();
59
+ const attrs = node.getAttrs();
66
60
  const stat = {
67
61
  writable: this.writable,
68
- size: this.v.node.size,
69
- version: this.v.node.version,
70
- sync,
62
+ size: node.size,
63
+ version: node.version,
71
64
  isFile: true,
72
65
  ctime: new Date(attrs.ctime),
73
66
  mtime: new Date(attrs.mtime),
@@ -90,7 +83,7 @@ class FileObject {
90
83
  throw new Error(`Node for file ${this.name} is not yet initialized`);
91
84
  }
92
85
  const sub = this.v.node.event$
93
- .subscribe(utils_for_observables_1.toRxObserver(observer));
86
+ .subscribe((0, utils_for_observables_1.toRxObserver)(observer));
94
87
  return () => sub.unsubscribe();
95
88
  }
96
89
  async readBytes(start, end) {
@@ -130,11 +123,12 @@ exports.FileObject = FileObject;
130
123
  Object.freeze(FileObject.prototype);
131
124
  Object.freeze(FileObject);
132
125
  class V {
133
- constructor(name, node, makeOrGetNode, writable) {
126
+ constructor(name, node, makeOrGetNode, writable, isInSyncedStorage) {
134
127
  this.name = name;
135
128
  this.node = node;
136
129
  this.makeOrGetNode = makeOrGetNode;
137
130
  this.writable = writable;
131
+ this.sync = (isInSyncedStorage ? new S(this) : undefined);
138
132
  Object.seal(this);
139
133
  }
140
134
  async getNode() {
@@ -144,7 +138,13 @@ class V {
144
138
  }
145
139
  return this.node;
146
140
  }
141
+ ensureIsWritable() {
142
+ if (!this.writable) {
143
+ throw new Error(`File is not writable`);
144
+ }
145
+ }
147
146
  async updateXAttrs(changes) {
147
+ this.ensureIsWritable();
148
148
  const node = await this.getNode();
149
149
  return node.updateXAttrs(changes);
150
150
  }
@@ -172,16 +172,18 @@ class V {
172
172
  return linkParams;
173
173
  }
174
174
  async getByteSink(truncate = true, currentVersion) {
175
+ this.ensureIsWritable();
175
176
  const node = await this.getNode();
176
177
  return node.writeSink(truncate, currentVersion);
177
178
  }
178
179
  async getByteSource() {
179
180
  if (!this.node) {
180
- throw file_1.makeFileException(file_1.Code.notFound, this.name);
181
+ throw (0, file_1.makeFileException)('notFound', this.name);
181
182
  }
182
183
  return this.node.readSrc();
183
184
  }
184
185
  async writeBytes(bytes) {
186
+ this.ensureIsWritable();
185
187
  const node = await this.getNode();
186
188
  return node.save(bytes);
187
189
  }
@@ -194,7 +196,7 @@ class V {
194
196
  }
195
197
  async readBytes(start, end) {
196
198
  if (!this.node) {
197
- throw file_1.makeFileException(file_1.Code.notFound, this.name);
199
+ throw (0, file_1.makeFileException)('notFound', this.name);
198
200
  }
199
201
  return await this.node.readBytes(start, end);
200
202
  }
@@ -207,7 +209,7 @@ class V {
207
209
  const { version, sink } = await this.getByteSink();
208
210
  const src = (file.v ?
209
211
  (await file.v.getByteSource()).src : await file.getByteSource());
210
- await pipe_1.pipe(src, sink);
212
+ await (0, pipe_1.pipe)(src, sink);
211
213
  return version;
212
214
  }
213
215
  async readJSON() {
@@ -215,7 +217,53 @@ class V {
215
217
  const json = JSON.parse(txt);
216
218
  return { json, version };
217
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
+ }
218
229
  }
219
230
  Object.freeze(V.prototype);
220
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);
221
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, NodeType } 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.
@@ -54,6 +58,7 @@ declare class FolderPersistance extends NodePersistance {
54
58
  attrs: CommonAttrs;
55
59
  xattrs?: XAttrs;
56
60
  }>;
61
+ static readFolderContent(objId: string | null, key: Uint8Array, src: ObjSource, cryptor: AsyncSBoxCryptor): Promise<FolderInfo>;
57
62
  }
58
63
  export interface FolderLinkParams {
59
64
  folderName: string;
@@ -68,21 +73,18 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
68
73
  private static readNodeFromObjBytes;
69
74
  static rootFromLinkParams(storage: Storage, params: FolderLinkParams): Promise<FolderNode>;
70
75
  static rootFromJSON(storage: Storage, name: string | undefined, folderJson: FolderInJSON): FolderNode;
76
+ protected setCurrentStateFrom(src: ObjSource): Promise<void>;
77
+ adoptRemote(opts: OptionsToAdopteRemote | undefined): Promise<void>;
78
+ private callRemoveObjOn;
71
79
  list(): {
72
80
  lst: ListingEntry[];
73
81
  version: number;
74
82
  };
75
- listFolders(): string[];
76
- private getNodeInfo;
83
+ childExistsInSyncedVersion(childObjId: string): Promise<boolean>;
84
+ getNodeInfo(name: string, undefOnMissing?: boolean): NodeInfo | undefined;
77
85
  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
- getNode<T extends Node>(type: NodeType | undefined, name: string, undefOnMissing?: boolean): Promise<T | undefined>;
86
+ getNode<T extends NodeInFS<any>>(type: NodeType | undefined, name: string, undefOnMissing?: boolean): Promise<T | undefined>;
87
+ private getOrMakeChildNodeForInfo;
86
88
  getFolder(name: string, undefOnMissing?: boolean): Promise<FolderNode | undefined>;
87
89
  getFile(name: string, undefOnMissing?: boolean): Promise<FileNode | undefined>;
88
90
  getLink(name: string, undefOnMissing?: boolean): Promise<LinkNode | undefined>;
@@ -130,8 +132,25 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
130
132
  */
131
133
  isEmpty(): boolean;
132
134
  private getAllNodes;
133
- protected delete(remoteEvent?: boolean): Promise<void>;
135
+ private removeFolderObj;
136
+ private callRemoveObjOnAll;
137
+ private removeChildrenObjsInSyncedStorage;
138
+ private uploadRemovalOfObjs;
134
139
  getParamsForLink(): LinkParameters<FolderLinkParams>;
135
- protected doOnExternalChange(expectedVersion: number): Promise<void>;
140
+ upload(opts: OptionsToUploadLocal | undefined): Promise<void>;
141
+ private uploadRemovalOf;
142
+ private listRemovedInTreeToUploadRm;
143
+ protected needUpload(localVersion: number | undefined): Promise<{
144
+ localVersion: number;
145
+ uploadVersion: number;
146
+ createOnRemote: boolean;
147
+ } | undefined>;
148
+ private getNodesRemovedBetweenVersions;
149
+ adoptRemoteFolderItem(itemName: string, opts: OptionsToAdoptRemoteItem | undefined): Promise<number>;
150
+ private addRemoteChild;
151
+ private replaceLocalChildWithRemote;
152
+ diffCurrentAndRemote(remoteVersion: number | undefined): Promise<FolderDiff | undefined>;
153
+ private diffWithArchivedRemote;
154
+ private diffWithRemote;
136
155
  }
137
156
  export {};