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
@@ -27,23 +27,40 @@ const service_locator_1 = require("../service-locator");
27
27
  const keyGen = require("../key-derivation");
28
28
  const exceptions_1 = require("./exceptions");
29
29
  const ws_ipc_1 = require("../../lib-common/ipc/ws-ipc");
30
+ const assert_1 = require("../../lib-common/assert");
31
+ function toInitServiceUriGetter(net, mainUrlGetter) {
32
+ return async () => {
33
+ const serviceUrl = await mainUrlGetter();
34
+ const info = await (0, service_locator_1.storageInfoAt)(net, serviceUrl);
35
+ if (!info.owner) {
36
+ throw new Error(`Missing owner service url in 3NStorage information at ${serviceUrl}`);
37
+ }
38
+ return info.owner;
39
+ };
40
+ }
30
41
  class StorageOwner extends user_with_mid_session_1.ServiceUser {
31
- constructor(user, getSigner, mainUrlGetter, net) {
42
+ constructor(user, getSigner, getInitServiceURI, net) {
32
43
  super(user, {
33
44
  login: api.midLogin.MID_URL_PART,
34
45
  logout: api.closeSession.URL_END,
35
46
  canBeRedirected: true
36
- }, getSigner, async () => {
37
- const serviceUrl = await mainUrlGetter();
38
- const info = await service_locator_1.storageInfoAt(this.net, serviceUrl);
39
- if (!info.owner) {
40
- throw new Error(`Missing owner service url in 3NStorage information at ${serviceUrl}`);
41
- }
42
- return info.owner;
43
- }, net);
47
+ }, getSigner, getInitServiceURI, net);
44
48
  this.maxChunkSize = undefined;
45
49
  Object.seal(this);
46
50
  }
51
+ static make(user, getSigner, mainUrlGetter, net) {
52
+ const srvUriGetter = toInitServiceUriGetter(net, mainUrlGetter);
53
+ const remote = new StorageOwner(user, getSigner, srvUriGetter, net);
54
+ return remote;
55
+ }
56
+ static makeBeforeMidSetup(user, mainUrlGetter, net) {
57
+ const srvUriGetter = toInitServiceUriGetter(net, mainUrlGetter);
58
+ const remote = new StorageOwner(user, undefined, srvUriGetter, net);
59
+ return {
60
+ remote,
61
+ setMid: getSigner => remote.setGetterOfSigner(getSigner)
62
+ };
63
+ }
47
64
  async getKeyDerivParams() {
48
65
  const rep = await this.doBodylessSessionRequest({
49
66
  appPath: api.keyDerivParams.URL_END,
@@ -51,11 +68,11 @@ class StorageOwner extends user_with_mid_session_1.ServiceUser {
51
68
  responseType: 'json'
52
69
  });
53
70
  if (rep.status !== api.sessionParams.SC.ok) {
54
- throw request_utils_1.makeException(rep, 'Unexpected status');
71
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
55
72
  }
56
73
  const keyDerivParams = rep.data;
57
74
  if (!keyGen.checkParams(rep.data)) {
58
- throw request_utils_1.makeException(rep, 'Malformed response');
75
+ throw (0, request_utils_1.makeException)(rep, 'Malformed response');
59
76
  }
60
77
  return keyDerivParams;
61
78
  }
@@ -66,11 +83,11 @@ class StorageOwner extends user_with_mid_session_1.ServiceUser {
66
83
  responseType: 'json'
67
84
  });
68
85
  if (rep.status !== api.sessionParams.SC.ok) {
69
- throw request_utils_1.makeException(rep, 'Unexpected status');
86
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
70
87
  }
71
88
  if ((typeof rep.data.maxChunkSize !== 'number') ||
72
89
  (rep.data.maxChunkSize < 64 * 1024)) {
73
- throw request_utils_1.makeException(rep, 'Malformed response');
90
+ throw (0, request_utils_1.makeException)(rep, 'Malformed response');
74
91
  }
75
92
  this.maxChunkSize = rep.data.maxChunkSize;
76
93
  }
@@ -98,10 +115,10 @@ class StorageOwner extends user_with_mid_session_1.ServiceUser {
98
115
  return;
99
116
  }
100
117
  else if (rep.status === api.cancelTransaction.SC.missing) {
101
- throw exceptions_1.makeUnknownTransactionExc(objId);
118
+ throw (0, exceptions_1.makeUnknownTransactionExc)(objId);
102
119
  }
103
120
  else {
104
- throw request_utils_1.makeException(rep, 'Unexpected status');
121
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
105
122
  }
106
123
  }
107
124
  /**
@@ -128,13 +145,13 @@ class StorageOwner extends user_with_mid_session_1.ServiceUser {
128
145
  });
129
146
  if (rep.status === api.currentObj.SC.okGet) {
130
147
  if (!(rep.data instanceof Uint8Array)) {
131
- throw request_utils_1.makeException(rep, `Malformed response: body is not binary`);
148
+ throw (0, request_utils_1.makeException)(rep, `Malformed response: body is not binary`);
132
149
  }
133
- const version = request_utils_1.extractIntHeader(rep, api.HTTP_HEADER.objVersion);
134
- const segsTotalLen = request_utils_1.extractIntHeader(rep, api.HTTP_HEADER.objSegmentsLength);
135
- const headerLen = request_utils_1.extractIntHeader(rep, api.HTTP_HEADER.objHeaderLength);
150
+ const version = (0, request_utils_1.extractIntHeader)(rep, api.HTTP_HEADER.objVersion);
151
+ const segsTotalLen = (0, request_utils_1.extractIntHeader)(rep, api.HTTP_HEADER.objSegmentsLength);
152
+ const headerLen = (0, request_utils_1.extractIntHeader)(rep, api.HTTP_HEADER.objHeaderLength);
136
153
  if (rep.data.length > (headerLen + segsTotalLen)) {
137
- throw request_utils_1.makeException(rep, `Malformed response: body is too long`);
154
+ throw (0, request_utils_1.makeException)(rep, `Malformed response: body is too long`);
138
155
  }
139
156
  return {
140
157
  version, segsTotalLen,
@@ -143,10 +160,10 @@ class StorageOwner extends user_with_mid_session_1.ServiceUser {
143
160
  };
144
161
  }
145
162
  else if (rep.status === api.currentObj.SC.unknownObj) {
146
- throw exceptions_1.makeObjNotFoundExc(objId, undefined, true);
163
+ throw (0, exceptions_1.makeObjNotFoundExc)(objId, true);
147
164
  }
148
165
  else {
149
- throw request_utils_1.makeException(rep, 'Unexpected status');
166
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
150
167
  }
151
168
  }
152
169
  /**
@@ -173,15 +190,15 @@ class StorageOwner extends user_with_mid_session_1.ServiceUser {
173
190
  });
174
191
  if (rep.status === api.currentObj.SC.okGet) {
175
192
  if (!(rep.data instanceof Uint8Array)) {
176
- throw request_utils_1.makeException(rep, `Malformed response: body is not binary`);
193
+ throw (0, request_utils_1.makeException)(rep, `Malformed response: body is not binary`);
177
194
  }
178
195
  return rep.data;
179
196
  }
180
197
  else if (rep.status === api.currentObj.SC.unknownObj) {
181
- throw exceptions_1.makeObjNotFoundExc(objId, undefined, true);
198
+ throw (0, exceptions_1.makeObjNotFoundExc)(objId, true);
182
199
  }
183
200
  else {
184
- throw request_utils_1.makeException(rep, 'Unexpected status');
201
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
185
202
  }
186
203
  }
187
204
  /**
@@ -190,50 +207,117 @@ class StorageOwner extends user_with_mid_session_1.ServiceUser {
190
207
  * complete, or to a transaction id, which must be used for subsequent
191
208
  * request(s).
192
209
  * @param objId is object's id, with null value for root object
193
- * @param bytes are bytes to upload
194
210
  * @param fstReq is options object for the first request
195
211
  * @param followReq is options object for subsequent request(s)
212
+ * @param bytes is an object with header, diff and segs bytes to upload
196
213
  */
197
- async saveNewObjVersion(objId, bytes, fstReq, followReq) {
214
+ async saveNewObjVersion(objId, fstReq, followReq, { header, diff, segs }) {
198
215
  let appPath;
199
216
  if (fstReq) {
217
+ (0, assert_1.assert)(!!header);
218
+ const { ver, last } = fstReq;
219
+ const reqOpts = {
220
+ ver, last,
221
+ header: header.length,
222
+ diff: (diff ? diff.length : undefined)
223
+ };
200
224
  appPath = (objId ?
201
- api.currentObj.firstPutReqUrlEnd(objId, fstReq) :
202
- api.currentRootObj.firstPutReqUrlEnd(fstReq));
225
+ api.currentObj.firstPutReqUrlEnd(objId, reqOpts) :
226
+ api.currentRootObj.firstPutReqUrlEnd(reqOpts));
203
227
  }
204
228
  else if (followReq) {
229
+ const { ofs, trans, last } = followReq;
230
+ // XXX segs argument will introduce difference between these two
231
+ const reqOpts = {
232
+ ofs, trans, last
233
+ };
205
234
  appPath = (objId ?
206
- api.currentObj.secondPutReqUrlEnd(objId, followReq) :
207
- api.currentRootObj.secondPutReqUrlEnd(followReq));
235
+ api.currentObj.secondPutReqUrlEnd(objId, reqOpts) :
236
+ api.currentRootObj.secondPutReqUrlEnd(reqOpts));
208
237
  }
209
238
  else {
210
239
  throw new Error(`Missing request options`);
211
240
  }
241
+ // ordering body bytes in accordance with protocol expectation
242
+ const bytes = [];
243
+ if (diff) {
244
+ bytes.push(diff);
245
+ }
246
+ if (header) {
247
+ bytes.push(header);
248
+ }
249
+ if (segs) {
250
+ if (Array.isArray(segs)) {
251
+ bytes.push(...segs);
252
+ }
253
+ else {
254
+ bytes.push(segs);
255
+ }
256
+ }
212
257
  const rep = await this.doBinarySessionRequest({ appPath, method: 'PUT', responseType: 'json' }, bytes);
213
258
  if (rep.status === api.currentObj.SC.okPut) {
214
259
  return rep.data.transactionId;
215
260
  }
216
261
  else if (rep.status === api.currentObj.SC.objAlreadyExists) {
217
- throw exceptions_1.makeObjExistsExc(objId, undefined, true);
262
+ throw (0, exceptions_1.makeObjExistsExc)(objId, undefined, true);
218
263
  }
219
264
  else if (rep.status === api.currentObj.SC.unknownObj) {
220
- throw exceptions_1.makeObjNotFoundExc(objId, undefined, true);
265
+ throw (0, exceptions_1.makeObjNotFoundExc)(objId, true);
221
266
  }
222
267
  else if (rep.status === api.currentObj.SC.concurrentTransaction) {
223
- throw exceptions_1.makeConcurrentTransExc(objId);
268
+ throw (0, exceptions_1.makeConcurrentTransExc)(objId);
224
269
  }
225
270
  else if (rep.status === api.currentObj.SC.unknownTransaction) {
226
- throw exceptions_1.makeUnknownTransactionExc(objId);
271
+ throw (0, exceptions_1.makeUnknownTransactionExc)(objId);
227
272
  }
228
273
  else if (rep.status === api.currentObj.SC.mismatchedObjVer) {
229
274
  const curVer = rep.current_version;
230
275
  if (!Number.isInteger(curVer)) {
231
276
  throw new Error(`Got non-integer current object version value from a version mismatch reply ${curVer}`);
232
277
  }
233
- throw exceptions_1.makeVersionMismatchExc(objId, curVer);
278
+ throw (0, exceptions_1.makeVersionMismatchExc)(objId, curVer);
279
+ }
280
+ else {
281
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
282
+ }
283
+ }
284
+ async archiveObjVersion(objId, currentVer) {
285
+ const rep = await this.doBodylessSessionRequest({
286
+ appPath: (objId ?
287
+ api.archiveObj.postAndDelReqUrlEnd(objId, currentVer) :
288
+ api.archiveRoot.postAndDelReqUrlEnd(currentVer)),
289
+ method: 'POST'
290
+ });
291
+ if (rep.status === api.archiveObj.SC.okPost) {
292
+ return;
293
+ }
294
+ else if (rep.status === api.currentObj.SC.unknownObj) {
295
+ throw (0, exceptions_1.makeObjNotFoundExc)(objId, true);
296
+ }
297
+ else if (rep.status === api.currentObj.SC.unknownObjVer) {
298
+ throw (0, exceptions_1.makeObjVersionNotFoundExc)(objId, currentVer, true);
234
299
  }
235
300
  else {
236
- throw request_utils_1.makeException(rep, 'Unexpected status');
301
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
302
+ }
303
+ }
304
+ async getObjStatus(objId) {
305
+ const rep = await this.doBodylessSessionRequest({
306
+ appPath: (objId ?
307
+ api.objStatus.getReqUrlEnd(objId) :
308
+ api.rootStatus.getReqUrlEnd()),
309
+ method: 'GET',
310
+ responseType: 'json'
311
+ });
312
+ if (rep.status === api.objStatus.SC.ok) {
313
+ // XXX we may want to add sanity check(s)
314
+ return rep.data;
315
+ }
316
+ else if (rep.status === api.objStatus.SC.unknownObj) {
317
+ throw (0, exceptions_1.makeObjNotFoundExc)(objId, true);
318
+ }
319
+ else {
320
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
237
321
  }
238
322
  }
239
323
  /**
@@ -245,29 +329,27 @@ class StorageOwner extends user_with_mid_session_1.ServiceUser {
245
329
  */
246
330
  async deleteObj(objId) {
247
331
  const rep = await this.doBodylessSessionRequest({
248
- appPath: api.currentObj.getReqUrlEnd(objId),
332
+ appPath: api.currentObj.delReqUrlEnd(objId),
249
333
  method: 'DELETE'
250
334
  });
251
- if (rep.status === api.currentObj.SC.okDelete) {
335
+ if ((rep.status === api.currentObj.SC.okDelete)
336
+ || (rep.status === api.currentObj.SC.unknownObj)) {
252
337
  return;
253
338
  }
254
339
  else if (rep.status === api.currentObj.SC.concurrentTransaction) {
255
- throw exceptions_1.makeConcurrentTransExc(objId);
256
- }
257
- else if (rep.status === api.currentObj.SC.unknownObj) {
258
- throw exceptions_1.makeObjNotFoundExc(objId, undefined, true);
340
+ throw (0, exceptions_1.makeConcurrentTransExc)(objId);
259
341
  }
260
342
  else {
261
- throw request_utils_1.makeException(rep, 'Unexpected status');
343
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
262
344
  }
263
345
  }
264
346
  async openEventSource() {
265
347
  const rep = await this.openWS(api.wsEventChannel.URL_END);
266
348
  if (rep.status === api.wsEventChannel.SC.ok) {
267
- return ws_ipc_1.makeSubscriber(rep.data, undefined);
349
+ return (0, ws_ipc_1.makeSubscriber)(rep.data, undefined);
268
350
  }
269
351
  else {
270
- throw request_utils_1.makeException(rep, 'Unexpected status');
352
+ throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
271
353
  }
272
354
  }
273
355
  }
@@ -1,10 +1,11 @@
1
1
  declare type WritableFile = web3n.files.WritableFile;
2
2
  declare type FileEvent = web3n.files.FileEvent;
3
+ declare type RemoteEvent = web3n.files.RemoteEvent;
3
4
  export declare abstract class JsonFileProc<T> {
4
5
  private proc;
5
6
  private file;
6
7
  start(file: WritableFile, initVal: T | (() => T) | (() => Promise<T>)): Promise<void>;
7
- protected abstract onFileEvent(ev: FileEvent): Promise<void>;
8
+ protected abstract onFileEvent(ev: FileEvent | RemoteEvent): Promise<void>;
8
9
  close(): Promise<void>;
9
10
  private ensureActive;
10
11
  /**
@@ -13,7 +13,8 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
15
  You should have received a copy of the GNU General Public License along with
16
- this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.JsonFileProc = void 0;
19
20
  const rxjs_1 = require("rxjs");
@@ -38,7 +39,7 @@ class JsonFileProc {
38
39
  await this.file.writeJSON(fstVal);
39
40
  }
40
41
  this.proc = (new rxjs_1.Observable(obs => this.file.watch(obs)))
41
- .pipe(operators_1.mergeMap(ev => this.onFileEvent(ev), 1))
42
+ .pipe((0, operators_1.mergeMap)(ev => this.onFileEvent(ev), 1))
42
43
  .subscribe();
43
44
  }
44
45
  async close() {
@@ -0,0 +1 @@
1
+ export declare function appendArray<T>(arr: T[], elems: T[] | T | undefined): T[];
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2022 3NSoft Inc.
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU General Public License as published by the Free Software
7
+ Foundation, either version 3 of the License, or (at your option) any later
8
+ version.
9
+
10
+ This program is distributed in the hope that it will be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License along with
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.appendArray = void 0;
20
+ function appendArray(arr, elems) {
21
+ if (elems !== undefined) {
22
+ if (Array.isArray(elems)) {
23
+ arr.push(...elems);
24
+ }
25
+ else {
26
+ arr.push(elems);
27
+ }
28
+ }
29
+ return arr;
30
+ }
31
+ exports.appendArray = appendArray;
32
+ Object.freeze(exports);
@@ -37,14 +37,14 @@ class CommonAttrs {
37
37
  if (bytes.length < CommonAttrs.PACK_LEN) {
38
38
  throw parsingException(`byte array is too short`);
39
39
  }
40
- const ctime = big_endian_1.uintFrom6Bytes(bytes, 0);
41
- const mtime = big_endian_1.uintFrom6Bytes(bytes, 6);
40
+ const ctime = (0, big_endian_1.uintFrom6Bytes)(bytes, 0);
41
+ const mtime = (0, big_endian_1.uintFrom6Bytes)(bytes, 6);
42
42
  return new CommonAttrs(ctime, mtime);
43
43
  }
44
44
  pack() {
45
45
  const bytes = Buffer.allocUnsafe(CommonAttrs.PACK_LEN);
46
- big_endian_1.packUintTo6Bytes(this.ctime, bytes, 0);
47
- big_endian_1.packUintTo6Bytes(this.mtime, bytes, 6);
46
+ (0, big_endian_1.packUintTo6Bytes)(this.ctime, bytes, 0);
47
+ (0, big_endian_1.packUintTo6Bytes)(this.mtime, bytes, 6);
48
48
  return bytes;
49
49
  }
50
50
  copy() {
@@ -71,7 +71,7 @@ class XAttrs {
71
71
  for (const bytes of sections) {
72
72
  let i = 0;
73
73
  while (i < bytes.length) {
74
- const { bytesRead, binVal, strVal, jsonVal, xaName } = extAttrs.readNamedAttr(buffer_utils_1.toBuffer(bytes), i);
74
+ const { bytesRead, binVal, strVal, jsonVal, xaName } = extAttrs.readNamedAttr((0, buffer_utils_1.toBuffer)(bytes), i);
75
75
  xattrs.attrs.set(xaName, { binVal, strVal, jsonVal });
76
76
  i += bytesRead;
77
77
  }
@@ -141,7 +141,7 @@ class XAttrs {
141
141
  bytes.push(extAttrs.packNamedBinaryAttr(xaName, v.binVal));
142
142
  }
143
143
  else {
144
- assert_1.assert(v.jsonVal !== undefined);
144
+ (0, assert_1.assert)(v.jsonVal !== undefined);
145
145
  bytes.push(extAttrs.packNamedJsonAttr(xaName, v.jsonVal));
146
146
  }
147
147
  }
@@ -179,7 +179,7 @@ var extAttrs;
179
179
  else if (t.type === NAMED_JSON) {
180
180
  return {
181
181
  bytesRead, xaName,
182
- jsonVal: JSON.parse(buffer_utils_1.toBuffer(bytes).slice(ofs, ofs + contentLen).toString('utf8')),
182
+ jsonVal: JSON.parse((0, buffer_utils_1.toBuffer)(bytes).slice(ofs, ofs + contentLen).toString('utf8')),
183
183
  };
184
184
  }
185
185
  else if (t.type === NAMED_BINARY) {
@@ -208,17 +208,17 @@ var extAttrs;
208
208
  case 1:
209
209
  return bytes[i];
210
210
  case 2:
211
- return big_endian_1.uintFrom2Bytes(bytes, i);
211
+ return (0, big_endian_1.uintFrom2Bytes)(bytes, i);
212
212
  case 3:
213
- return big_endian_1.uintFrom3Bytes(bytes, i);
213
+ return (0, big_endian_1.uintFrom3Bytes)(bytes, i);
214
214
  case 4:
215
- return big_endian_1.uintFrom4Bytes(bytes, i);
215
+ return (0, big_endian_1.uintFrom4Bytes)(bytes, i);
216
216
  default:
217
217
  throw parsingException(`Too many bytes for xattr length`);
218
218
  }
219
219
  }
220
220
  function packNamedStrAttr(name, value) {
221
- assert_1.assert((typeof name === 'string') && (name.length > 0) &&
221
+ (0, assert_1.assert)((typeof name === 'string') && (name.length > 0) &&
222
222
  (typeof value === 'string') && (value.length > 0));
223
223
  const nameBin = Buffer.from(name, 'utf8');
224
224
  const valueBin = Buffer.from(value, 'utf8');
@@ -226,14 +226,14 @@ var extAttrs;
226
226
  }
227
227
  extAttrs.packNamedStrAttr = packNamedStrAttr;
228
228
  function packNamedBinaryAttr(name, value) {
229
- assert_1.assert((typeof name === 'string') && (name.length > 0) &&
229
+ (0, assert_1.assert)((typeof name === 'string') && (name.length > 0) &&
230
230
  (value.length > 0));
231
231
  const nameBin = Buffer.from(name, 'utf8');
232
232
  return packNamedAttr(NAMED_BINARY, nameBin, value);
233
233
  }
234
234
  extAttrs.packNamedBinaryAttr = packNamedBinaryAttr;
235
235
  function packNamedJsonAttr(name, value) {
236
- assert_1.assert((typeof name === 'string') && (name.length > 0) &&
236
+ (0, assert_1.assert)((typeof name === 'string') && (name.length > 0) &&
237
237
  (value !== undefined));
238
238
  const nameBin = Buffer.from(name, 'utf8');
239
239
  const valueBin = Buffer.from(JSON.stringify(value), 'utf8');
@@ -292,16 +292,16 @@ var extAttrs;
292
292
  b[i] = u;
293
293
  break;
294
294
  case 2:
295
- big_endian_1.packUintTo2Bytes(u, b, i);
295
+ (0, big_endian_1.packUintTo2Bytes)(u, b, i);
296
296
  break;
297
297
  case 3:
298
- big_endian_1.packUintTo3Bytes(u, b, i);
298
+ (0, big_endian_1.packUintTo3Bytes)(u, b, i);
299
299
  break;
300
300
  case 4:
301
- big_endian_1.packUintTo4Bytes(u, b, i);
301
+ (0, big_endian_1.packUintTo4Bytes)(u, b, i);
302
302
  break;
303
303
  default:
304
- assert_1.assert(false);
304
+ (0, assert_1.assert)(false);
305
305
  }
306
306
  }
307
307
  // export function pack(xattrs: XAttrs): Buffer {
@@ -1,28 +1,22 @@
1
1
  import { ScryptGenParams } from '../../key-derivation';
2
2
  import { AsyncSBoxCryptor, Subscribe, ObjSource } from 'xsp-files';
3
- import { objChanged, objRemoved } from '../../../lib-common/service-api/3nstorage/owner';
4
3
  import { Observable } from 'rxjs';
5
- import { UpSyncTaskInfo } from '../../../core/storage/synced/obj-status';
4
+ import { LogError } from '../../logging/log-to-file';
6
5
  export { AsyncSBoxCryptor } from 'xsp-files';
7
6
  export { FolderInJSON } from './folder-node';
8
7
  declare type StorageType = web3n.files.FSType;
9
8
  declare type FolderEvent = web3n.files.FolderEvent;
10
9
  declare type FileEvent = web3n.files.FileEvent;
11
- declare type Stats = web3n.files.Stats;
12
- export interface RemoteObjRemovalEvent extends objRemoved.Event {
13
- type: 'remote-delete';
14
- }
15
- export interface RemoteObjChangeEvent extends objChanged.Event {
16
- type: 'remote-change';
17
- }
18
- export declare type RemoteEvent = RemoteObjRemovalEvent | RemoteObjChangeEvent;
10
+ declare type RemoteEvent = web3n.files.RemoteEvent;
11
+ declare type SyncStatus = web3n.files.SyncStatus;
12
+ declare type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
13
+ declare type FSSyncException = web3n.files.FSSyncException;
14
+ declare type FileException = web3n.files.FileException;
15
+ export declare type FSChangeSrc = web3n.files.FSChangeEvent['src'];
19
16
  export interface Node {
20
17
  objId: string;
21
18
  name: string;
22
19
  type: NodeType;
23
- processRemoteEvent: (event: RemoteEvent) => Promise<void>;
24
- broadcastUpSyncEvent(task: UpSyncTaskInfo): void;
25
- localDelete(): Promise<void>;
26
20
  }
27
21
  export declare type NodeType = 'file' | 'link' | 'folder';
28
22
  export declare type ObjId = string | null;
@@ -56,15 +50,17 @@ export declare class NodesContainer {
56
50
  export interface NodeEvent {
57
51
  objId: ObjId;
58
52
  parentObjId?: ObjId;
59
- event: FolderEvent | FileEvent;
53
+ childObjId?: ObjId;
54
+ event: FolderEvent | FileEvent | RemoteEvent;
60
55
  }
61
56
  export interface Storage {
62
57
  readonly type: StorageType;
63
58
  readonly versioned: boolean;
64
59
  readonly cryptor: AsyncSBoxCryptor;
65
60
  readonly nodes: NodesContainer;
61
+ readonly logError: LogError;
66
62
  getNodeEvents(): Observable<NodeEvent>;
67
- broadcastNodeEvent(objId: ObjId, parentObjId: ObjId | undefined, ev: FolderEvent | FileEvent): void;
63
+ broadcastNodeEvent(objId: ObjId, parentObjId: ObjId | undefined, childObjId: ObjId | undefined, ev: NodeEvent['event']): void;
68
64
  /**
69
65
  * This returns a storage of another type, for use by link functionality.
70
66
  * @param type is a type of a requested storage.
@@ -78,9 +74,8 @@ export interface Storage {
78
74
  generateNewObjId(): Promise<string>;
79
75
  /**
80
76
  * This returns a promise, resolvable to source for a requested object.
81
- * @param objId
82
77
  */
83
- getObj(objId: ObjId): Promise<ObjSource>;
78
+ getObjSrc(objId: ObjId, version?: number, allowArchived?: boolean): Promise<ObjSource>;
84
79
  /**
85
80
  * This saves given object, asynchronously.
86
81
  * @param objId
@@ -98,15 +93,45 @@ export interface Storage {
98
93
  * This asynchronously runs closing cleanup.
99
94
  */
100
95
  close(): Promise<void>;
96
+ status(objId: ObjId): Promise<LocalObjStatus>;
97
+ }
98
+ export interface LocalObjStatus {
99
+ archiveCurrentVersion(): Promise<void>;
100
+ listVersions(): {
101
+ current?: number;
102
+ archived?: number[];
103
+ };
101
104
  }
102
105
  export declare function wrapStorageImplementation(impl: Storage): Storage;
103
106
  export declare type StorageGetter = (type: StorageType, location?: string) => Storage;
104
107
  export interface SyncedStorage extends Storage {
108
+ getObjSrcOfRemoteVersion(objId: ObjId, version: number): Promise<ObjSource>;
109
+ archiveVersionOnServer(objId: ObjId, version: number): Promise<void>;
105
110
  /**
106
111
  * This returns a promise, resolvable to root key generation parameters.
107
112
  */
108
113
  getRootKeyDerivParamsFromServer(): Promise<ScryptGenParams>;
109
- getRemoteConflictObjVersion(objId: ObjId, version: number): Promise<ObjSource>;
110
- getObjSyncInfo(objId: ObjId): Promise<Stats['sync']>;
114
+ adoptRemote(objId: ObjId, opts: OptionsToAdopteRemote | undefined): Promise<number | undefined>;
115
+ updateStatusInfo(objId: ObjId): Promise<SyncStatus>;
116
+ isObjOnDisk(objId: ObjId): Promise<boolean>;
117
+ isRemoteVersionOnDisk(objId: ObjId, version: number): Promise<'partial' | 'complete' | 'none'>;
118
+ download(objId: ObjId, version: number): Promise<void>;
119
+ upload(objId: ObjId, localVersion: number, uploadVersion: number, uploadHeader: UploadHeaderChange | undefined, createOnRemote: boolean): Promise<void>;
120
+ dropCachedLocalObjVersionsLessOrEqual(objId: ObjId, localVersion: number): void;
121
+ uploadObjRemoval(objId: ObjId): Promise<void>;
122
+ status(objId: ObjId): Promise<SyncedObjStatus>;
123
+ }
124
+ export interface SyncedObjStatus extends LocalObjStatus {
125
+ syncStatus(): SyncStatus;
126
+ neverUploaded(): boolean;
127
+ versionBeforeUnsyncedRemoval(): number | undefined;
128
+ }
129
+ export interface UploadHeaderChange {
130
+ localVersion: number;
131
+ uploadVersion: number;
132
+ localHeader: Uint8Array;
133
+ uploadHeader: Uint8Array;
111
134
  }
112
135
  export declare function wrapSyncStorageImplementation(impl: SyncedStorage): SyncedStorage;
136
+ export declare function isSyncedStorage(storage: Storage): boolean;
137
+ export declare function setPathInExc(exc: FSSyncException | FileException, path: string): FSSyncException | FileException;