core-3nweb-client-lib 0.27.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 (56) hide show
  1. package/build/api-defs/files.d.ts +4 -7
  2. package/build/core/asmail/inbox/attachments/fs.d.ts +2 -1
  3. package/build/core/asmail/inbox/attachments/fs.js +4 -3
  4. package/build/core/asmail/inbox/index.js +1 -1
  5. package/build/core/id-manager/index.d.ts +43 -0
  6. package/build/core/{id-manager.js → id-manager/index.js} +33 -114
  7. package/build/core/id-manager/key-storage.d.ts +21 -0
  8. package/build/core/id-manager/key-storage.js +96 -0
  9. package/build/core/index.js +21 -23
  10. package/build/core/sign-in.d.ts +1 -2
  11. package/build/core/sign-in.js +4 -13
  12. package/build/core/sign-up.d.ts +2 -0
  13. package/build/core/sign-up.js +2 -1
  14. package/build/core/storage/index.d.ts +4 -2
  15. package/build/core/storage/index.js +36 -57
  16. package/build/core/storage/local/storage.d.ts +1 -1
  17. package/build/core/storage/synced/obj-files-gc.d.ts +1 -4
  18. package/build/core/storage/synced/obj-files-gc.js +1 -18
  19. package/build/core/storage/synced/obj-files.d.ts +9 -1
  20. package/build/core/storage/synced/obj-files.js +41 -33
  21. package/build/core/storage/synced/obj-status.d.ts +18 -7
  22. package/build/core/storage/synced/obj-status.js +148 -83
  23. package/build/core/storage/synced/storage.d.ts +7 -2
  24. package/build/core/storage/synced/storage.js +50 -10
  25. package/build/core/storage/synced/upsyncer.d.ts +4 -4
  26. package/build/core/storage/synced/upsyncer.js +12 -6
  27. package/build/lib-client/3nstorage/exceptions.d.ts +13 -1
  28. package/build/lib-client/3nstorage/exceptions.js +9 -3
  29. package/build/lib-client/3nstorage/service.d.ts +6 -1
  30. package/build/lib-client/3nstorage/service.js +31 -15
  31. package/build/lib-client/3nstorage/util/file-based-json.js +2 -1
  32. package/build/lib-client/3nstorage/util/for-arrays.d.ts +1 -0
  33. package/build/lib-client/3nstorage/util/for-arrays.js +32 -0
  34. package/build/lib-client/3nstorage/xsp-fs/common.d.ts +5 -4
  35. package/build/lib-client/3nstorage/xsp-fs/common.js +1 -0
  36. package/build/lib-client/3nstorage/xsp-fs/file.js +2 -2
  37. package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +11 -5
  38. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +232 -68
  39. package/build/lib-client/3nstorage/xsp-fs/fs.js +15 -19
  40. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +4 -9
  41. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +16 -17
  42. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +1 -1
  43. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  44. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  45. package/build/lib-client/local-files/device-fs.js +11 -11
  46. package/build/lib-client/user-with-mid-session.d.ts +2 -1
  47. package/build/lib-client/user-with-mid-session.js +7 -1
  48. package/build/lib-common/async-fs-node.js +8 -8
  49. package/build/lib-common/exceptions/file.d.ts +4 -2
  50. package/build/lib-common/exceptions/file.js +24 -58
  51. package/build/lib-common/ipc/generic-ipc.js +5 -4
  52. package/build/lib-common/objs-on-disk/utils.js +1 -1
  53. package/build/lib-common/service-api/3nstorage/owner.d.ts +8 -5
  54. package/build/lib-common/service-api/3nstorage/owner.js +2 -1
  55. package/package.json +3 -2
  56. package/build/core/id-manager.d.ts +0 -46
@@ -22,6 +22,7 @@ const exceptions_1 = require("../../../lib-client/3nstorage/exceptions");
22
22
  const json_saving_1 = require("../common/json-saving");
23
23
  const obj_info_file_1 = require("../common/obj-info-file");
24
24
  const assert_1 = require("../../../lib-common/assert");
25
+ const file_1 = require("../../../lib-common/exceptions/file");
25
26
  function makeVersions() {
26
27
  return {
27
28
  baseToDiff: {},
@@ -81,12 +82,14 @@ function identifyNonGarbage(status) {
81
82
  let uploadVersion = undefined;
82
83
  if (status.local) {
83
84
  local = nonGarbageWithMaxVer(status.local);
84
- if (status.local.upload) {
85
- const { localVersion } = status.local.upload;
86
- if (status.local.current !== localVersion) {
87
- (0, obj_info_file_1.addWithBasesTo)(local.nonGarbage, localVersion, status.local);
88
- }
89
- uploadVersion = status.local.upload.uploadVersion;
85
+ }
86
+ if (status.upload) {
87
+ const { localVersion } = status.upload;
88
+ if (status.local.current !== localVersion) {
89
+ (0, obj_info_file_1.addWithBasesTo)(local.nonGarbage, localVersion, status.local);
90
+ }
91
+ if (status.upload.type === 'new-version') {
92
+ uploadVersion = status.upload.uploadVersion;
90
93
  }
91
94
  }
92
95
  const remote = nonGarbageWithMaxVer(status.remote);
@@ -136,6 +139,27 @@ class ObjStatus {
136
139
  const status = await readAndCheckStatus(objFolder, objId);
137
140
  return (syncStateOf(status) !== 'synced');
138
141
  }
142
+ static async fileShowsObjNeedsRemovalOnRemote(objFolder, objId) {
143
+ const status = await readAndCheckStatus(objFolder, objId);
144
+ const upload = status.upload;
145
+ return (((upload === null || upload === void 0 ? void 0 : upload.type) === 'removal') && !upload.isPostponed);
146
+ }
147
+ needsRemovalOnRemote() {
148
+ const upload = this.status.upload;
149
+ return (((upload === null || upload === void 0 ? void 0 : upload.type) === 'removal') && !upload.isPostponed);
150
+ }
151
+ async clearPostponeFlagInRemovalOnRemote() {
152
+ const { upload } = this.status;
153
+ if (!upload) {
154
+ return false;
155
+ }
156
+ if (upload.type !== 'removal') {
157
+ throw new Error(`No upload removal in obj status`);
158
+ }
159
+ upload.isPostponed = false;
160
+ await this.triggerSaveProc();
161
+ return true;
162
+ }
139
163
  updateStateIndicator() {
140
164
  this.stateIndicator = syncStateOf(this.status);
141
165
  }
@@ -162,28 +186,36 @@ class ObjStatus {
162
186
  return identifyNonGarbage(this.status);
163
187
  }
164
188
  async removeCurrentVersion() {
165
- let { local, synced } = this.status;
189
+ let { local, synced, remote, upload } = this.status;
166
190
  if ((synced === null || synced === void 0 ? void 0 : synced.isArchived) || (local === null || local === void 0 ? void 0 : local.isArchived)) {
167
191
  return;
168
192
  }
193
+ if (upload) {
194
+ if (upload.type === 'removal') {
195
+ return;
196
+ }
197
+ else {
198
+ throw (0, file_1.makeFileException)('concurrentUpdate', 'obj-status', `Upload is in progress`);
199
+ }
200
+ }
201
+ if (!remote.isArchived && remote.current) {
202
+ this.status.upload = {
203
+ type: 'removal',
204
+ localVersion: ((local === null || local === void 0 ? void 0 : local.current) || (synced === null || synced === void 0 ? void 0 : synced.version)),
205
+ isPostponed: true
206
+ };
207
+ upload = this.status.upload;
208
+ }
169
209
  if (local) {
170
- (0, obj_info_file_1.rmCurrentVersionIn)(local);
210
+ local.isArchived = true;
211
+ local.current = undefined;
171
212
  }
172
213
  else {
173
- local = makeVersions();
214
+ this.status.local = makeVersions();
215
+ this.status.local.isArchived = true;
174
216
  }
175
- local.isArchived = true;
176
217
  this.updateStateIndicator();
177
- ;
178
- await this.triggerSaveProc().catch((exc) => {
179
- var _a;
180
- if (exc.notFound && ((_a = this.status.local) === null || _a === void 0 ? void 0 : _a.isArchived)) {
181
- return;
182
- }
183
- else {
184
- throw exc;
185
- }
186
- });
218
+ await this.triggerSaveProc().catch(skipNotFoundExc);
187
219
  }
188
220
  async triggerSaveProc(captureErrors = false, logErr = false) {
189
221
  try {
@@ -201,16 +233,17 @@ class ObjStatus {
201
233
  }
202
234
  }
203
235
  recordUploadStart(info) {
204
- (0, assert_1.assert)(!!this.status.local);
205
- const local = this.status.local;
206
- if (local.upload) {
236
+ var _a;
237
+ if (this.status.upload) {
238
+ const upload = this.status.upload;
207
239
  throw (0, exceptions_1.makeFSSyncException)('obj-status', {
208
240
  alreadyUploading: true,
209
- message: `Status already has upload of version ${local.upload.uploadVersion} and can't start another upload with version ${info.uploadVersion}`
241
+ message: `Status already has upload of version ${upload.uploadVersion} and can't start another upload with version ${info.uploadVersion}`
210
242
  });
211
243
  }
212
- if (info.localVersion === local.current) {
213
- local.upload = info;
244
+ if (info.localVersion === ((_a = this.status.local) === null || _a === void 0 ? void 0 : _a.current)) {
245
+ this.status.upload = info;
246
+ return this.triggerSaveProc();
214
247
  }
215
248
  else {
216
249
  throw (0, exceptions_1.makeFSSyncException)('obj-status', {
@@ -218,22 +251,58 @@ class ObjStatus {
218
251
  versionNotFound: true
219
252
  });
220
253
  }
221
- return this.triggerSaveProc();
222
254
  }
223
255
  recordUploadInterimState(info) {
224
- (0, assert_1.assert)(!!this.status.local);
225
- const local = this.status.local;
226
- (0, assert_1.assert)(!!local.upload &&
227
- (local.upload.uploadVersion === info.uploadVersion));
228
- local.upload = info;
229
- return this.triggerSaveProc();
256
+ var _a;
257
+ if (((_a = this.status.upload) === null || _a === void 0 ? void 0 : _a.type) !== 'new-version') {
258
+ throw new Error(`No new version upload in object status`);
259
+ }
260
+ if (this.status.upload.uploadVersion === info.uploadVersion) {
261
+ this.status.upload = info;
262
+ return this.triggerSaveProc();
263
+ }
264
+ else {
265
+ throw new Error(`Upload versions don't match`);
266
+ }
230
267
  }
231
268
  recordUploadCancellation(info) {
232
- (0, assert_1.assert)(!!this.status.local);
233
- const local = this.status.local;
234
- (0, assert_1.assert)(!!local.upload &&
235
- (local.upload.uploadVersion === info.uploadVersion));
236
- local.upload = undefined;
269
+ var _a;
270
+ if (((_a = this.status.upload) === null || _a === void 0 ? void 0 : _a.type) !== 'new-version') {
271
+ throw new Error(`No upload in object status`);
272
+ }
273
+ if (this.status.upload.uploadVersion === info.uploadVersion) {
274
+ this.status.upload = undefined;
275
+ return this.triggerSaveProc();
276
+ }
277
+ else {
278
+ throw new Error(`Upload versions don't match`);
279
+ }
280
+ }
281
+ recordUploadCompletion(localVersion, uploadVersion) {
282
+ const { local, synced, remote, upload } = this.status;
283
+ if (((upload === null || upload === void 0 ? void 0 : upload.type) !== 'new-version')
284
+ || (upload.uploadVersion !== uploadVersion)) {
285
+ throw new Error(`Upload versions don't match`);
286
+ }
287
+ const syncedBase = upload.baseVersion;
288
+ if (!remote.current || (remote.current <= uploadVersion)) {
289
+ (0, obj_info_file_1.setCurrentVersionIn)(remote, uploadVersion, syncedBase);
290
+ }
291
+ if (synced) {
292
+ synced.version = uploadVersion;
293
+ if (synced.base && (synced.base !== syncedBase)) {
294
+ (0, obj_info_file_1.rmNonArchVersionsIn)(remote, synced.base);
295
+ }
296
+ synced.base = syncedBase;
297
+ }
298
+ else {
299
+ this.status.synced = { version: uploadVersion, base: syncedBase };
300
+ }
301
+ if (local.current === localVersion) {
302
+ this.status.local = undefined;
303
+ }
304
+ this.status.upload = undefined;
305
+ this.updateStateIndicator();
237
306
  return this.triggerSaveProc();
238
307
  }
239
308
  async recordArchVersionRemoval(version) {
@@ -256,31 +325,40 @@ class ObjStatus {
256
325
  this.updateStateIndicator();
257
326
  return this.triggerSaveProc();
258
327
  }
259
- async recordRemoteChange(version) {
260
- const { local, synced, remote } = this.status;
261
- if (((local === null || local === void 0 ? void 0 : local.upload) && (local.upload.uploadVersion === version))
262
- || ((synced === null || synced === void 0 ? void 0 : synced.version) && (synced.version >= version))) {
328
+ async recordRemoteRemovalCompletion() {
329
+ var _a;
330
+ const { remote, upload, synced } = this.status;
331
+ if ((_a = this.status.synced) === null || _a === void 0 ? void 0 : _a.isArchived) {
263
332
  return;
264
333
  }
265
- remote.current = version;
334
+ if ((upload === null || upload === void 0 ? void 0 : upload.type) !== 'removal') {
335
+ throw new Error(`Upload of removal is not in status`);
336
+ }
337
+ (0, obj_info_file_1.rmCurrentVersionIn)(remote);
338
+ remote.isArchived = true;
339
+ if (synced) {
340
+ synced.isArchived = true;
341
+ synced.version = undefined;
342
+ synced.base = undefined;
343
+ }
344
+ else {
345
+ this.status.synced = { isArchived: true };
346
+ }
347
+ this.status.local = undefined;
348
+ this.status.upload = undefined;
266
349
  this.updateStateIndicator();
267
350
  return this.triggerSaveProc();
268
351
  }
269
- recordSyncOfObjRemoval() {
270
- this.status.local = undefined;
271
- (0, obj_info_file_1.rmCurrentVersionIn)(this.status.remote);
272
- this.status.remote.isArchived = true;
273
- if (this.status.synced) {
274
- this.status.synced.isArchived = true;
275
- this.status.synced.version = undefined;
276
- if (this.status.synced.base) {
277
- (0, obj_info_file_1.rmNonArchVersionsIn)(this.status.remote, this.status.synced.base);
278
- this.status.synced.base = undefined;
279
- }
352
+ async recordRemoteChange(version) {
353
+ const { synced, remote, upload } = this.status;
354
+ if (((upload === null || upload === void 0 ? void 0 : upload.type) === 'new-version')
355
+ && (upload.uploadVersion === version)) {
356
+ return;
280
357
  }
281
- else {
282
- this.status.synced = { isArchived: true };
358
+ if ((synced === null || synced === void 0 ? void 0 : synced.version) && (synced.version >= version)) {
359
+ return;
283
360
  }
361
+ remote.current = version;
284
362
  this.updateStateIndicator();
285
363
  return this.triggerSaveProc();
286
364
  }
@@ -346,33 +424,6 @@ class ObjStatus {
346
424
  return { localBases };
347
425
  }
348
426
  }
349
- markLocalVersionSynced(localVersion, uploadVersion) {
350
- const { local, synced, remote } = this.status;
351
- (0, assert_1.assert)(!!(local === null || local === void 0 ? void 0 : local.upload) &&
352
- ((local === null || local === void 0 ? void 0 : local.upload.uploadVersion) === uploadVersion));
353
- const syncedBase = local.upload.baseVersion;
354
- if (!remote.current || (remote.current <= uploadVersion)) {
355
- (0, obj_info_file_1.setCurrentVersionIn)(remote, uploadVersion, syncedBase);
356
- }
357
- if (synced) {
358
- synced.version = uploadVersion;
359
- if (synced.base && (synced.base !== syncedBase)) {
360
- (0, obj_info_file_1.rmNonArchVersionsIn)(remote, synced.base);
361
- }
362
- synced.base = syncedBase;
363
- }
364
- else {
365
- this.status.synced = { version: uploadVersion, base: syncedBase };
366
- }
367
- if (local.current === localVersion) {
368
- this.status.local = undefined;
369
- }
370
- else {
371
- local.upload = undefined;
372
- }
373
- this.updateStateIndicator();
374
- return this.triggerSaveProc();
375
- }
376
427
  async setLocalCurrentVersion(version, baseVer) {
377
428
  if (!this.status.local) {
378
429
  this.status.local = makeVersions();
@@ -446,6 +497,15 @@ class ObjStatus {
446
497
  const synced = this.status.synced;
447
498
  return (!(synced === null || synced === void 0 ? void 0 : synced.version) && !(synced === null || synced === void 0 ? void 0 : synced.isArchived));
448
499
  }
500
+ versionBeforeUnsyncedRemoval() {
501
+ var _a;
502
+ if ((this.stateIndicator !== 'synced')
503
+ && ((_a = this.status.local) === null || _a === void 0 ? void 0 : _a.isArchived)
504
+ && this.status.upload
505
+ && (this.status.upload.type === 'removal')) {
506
+ return this.status.upload.localVersion;
507
+ }
508
+ }
449
509
  async adoptRemoteVersion(version, dropLocalVer = false) {
450
510
  var _a;
451
511
  const { local, remote } = this.status;
@@ -596,4 +656,9 @@ function addArchVersionsFromList(remote, existingVersions) {
596
656
  }
597
657
  return isAnythingChanged;
598
658
  }
659
+ function skipNotFoundExc(exc) {
660
+ if (!exc.notFound) {
661
+ throw exc;
662
+ }
663
+ }
599
664
  Object.freeze(exports);
@@ -15,7 +15,7 @@ export declare class SyncedStore implements ISyncedStorage {
15
15
  private readonly remoteStorage;
16
16
  private readonly getStorages;
17
17
  readonly cryptor: AsyncSBoxCryptor;
18
- private readonly logError;
18
+ readonly logError: LogError;
19
19
  readonly type: web3n.files.FSType;
20
20
  readonly versioned = true;
21
21
  readonly nodes: NodesContainer;
@@ -27,12 +27,17 @@ export declare class SyncedStore implements ISyncedStorage {
27
27
  syncedStore: ISyncedStorage;
28
28
  startObjProcs: () => void;
29
29
  }>;
30
+ static makeAndStartWithoutRemote(path: string, user: string, getStorages: StorageGetter, cryptor: AsyncSBoxCryptor, remoteServiceUrl: () => Promise<string>, net: NetClient, logError: LogError): Promise<{
31
+ syncedStore: ISyncedStorage;
32
+ setupRemoteAndStartObjProcs: (getSigner: IGetMailerIdSigner) => void;
33
+ }>;
30
34
  getNodeEvents(): Observable<NodeEvent>;
31
35
  broadcastNodeEvent(objId: ObjId, parentObjId: ObjId | undefined, childObjId: ObjId | undefined, event: FolderEvent | FileEvent): void;
32
36
  storageForLinking(type: web3n.files.FSType, location?: string): IStorage;
33
37
  status(objId: ObjId): Promise<SyncedObjStatus>;
34
38
  adoptRemote(objId: ObjId, opts: OptionsToAdopteRemote | undefined): Promise<number | undefined>;
35
39
  updateStatusInfo(objId: ObjId): Promise<SyncStatus>;
40
+ isObjOnDisk(objId: ObjId): Promise<boolean>;
36
41
  isRemoteVersionOnDisk(objId: ObjId, version: number): Promise<'complete' | 'partial' | 'none'>;
37
42
  download(objId: ObjId, version: number): Promise<void>;
38
43
  upload(objId: ObjId, localVersion: number, uploadVersion: number, uploadHeader: UploadHeaderChange | undefined, createOnRemote: boolean): Promise<void>;
@@ -43,7 +48,7 @@ export declare class SyncedStore implements ISyncedStorage {
43
48
  generateNewObjId(): Promise<string>;
44
49
  private objFromDiskOrDownload;
45
50
  private getObjOrThrow;
46
- getObjSrc(objId: ObjId, version?: number): Promise<ObjSource>;
51
+ getObjSrc(objId: ObjId, version?: number, allowArchived?: boolean): Promise<ObjSource>;
47
52
  getObjSrcOfRemoteVersion(objId: ObjId, version: number): Promise<ObjSource>;
48
53
  saveObj(objId: ObjId, version: number, encSub: Subscribe): Promise<void>;
49
54
  removeObj(objId: string): Promise<void>;
@@ -43,10 +43,12 @@ class SyncedStore {
43
43
  Object.seal(this);
44
44
  }
45
45
  static async makeAndStart(path, user, getSigner, getStorages, cryptor, remoteServiceUrl, net, logError) {
46
- const remote = new service_1.StorageOwner(user, getSigner, remoteServiceUrl, net);
46
+ const remote = service_1.StorageOwner.make(user, getSigner, remoteServiceUrl, net);
47
47
  const objFiles = await obj_files_1.ObjFiles.makeFor(path, remote, logError);
48
48
  const s = new SyncedStore(objFiles, remote, getStorages, cryptor, logError);
49
49
  s.uploader.start();
50
+ // XXX ??
51
+ // s.remoteEvents.startAbsorbingRemoteEvents();
50
52
  return {
51
53
  syncedStore: (0, common_1.wrapSyncStorageImplementation)(s),
52
54
  startObjProcs: () => {
@@ -54,6 +56,21 @@ class SyncedStore {
54
56
  }
55
57
  };
56
58
  }
59
+ static async makeAndStartWithoutRemote(path, user, getStorages, cryptor, remoteServiceUrl, net, logError) {
60
+ const { remote, setMid } = service_1.StorageOwner.makeBeforeMidSetup(user, remoteServiceUrl, net);
61
+ const objFiles = await obj_files_1.ObjFiles.makeFor(path, remote, logError);
62
+ const s = new SyncedStore(objFiles, remote, getStorages, cryptor, logError);
63
+ // XXX ??
64
+ // s.remoteEvents.startAbsorbingRemoteEvents();
65
+ return {
66
+ syncedStore: (0, common_1.wrapSyncStorageImplementation)(s),
67
+ setupRemoteAndStartObjProcs: getSigner => {
68
+ setMid(getSigner);
69
+ s.uploader.start();
70
+ s.remoteEvents.startAbsorbingRemoteEvents();
71
+ }
72
+ };
73
+ }
57
74
  getNodeEvents() {
58
75
  return this.events.event$;
59
76
  }
@@ -72,7 +89,7 @@ class SyncedStore {
72
89
  }
73
90
  }
74
91
  async status(objId) {
75
- const obj = await this.getObjOrThrow(objId);
92
+ const obj = await this.getObjOrThrow(objId, true);
76
93
  return obj.syncStatus();
77
94
  }
78
95
  async adoptRemote(objId, opts) {
@@ -81,6 +98,7 @@ class SyncedStore {
81
98
  await objStatus.adoptRemoteVersion(opts === null || opts === void 0 ? void 0 : opts.remoteVersion, opts === null || opts === void 0 ? void 0 : opts.dropLocalVer);
82
99
  if (opts && opts.download) {
83
100
  // XXX this needs implementation
101
+ throw new Error('SyncedStore.adoptRemote() with download option needs implementation, probably using SyncedStore.download().');
84
102
  }
85
103
  this.files.scheduleGC(obj);
86
104
  return objStatus.syncStatus().synced.latest;
@@ -103,16 +121,29 @@ class SyncedStore {
103
121
  throw exc;
104
122
  }
105
123
  }
106
- isRemoteVersionOnDisk(objId, version) {
124
+ async isObjOnDisk(objId) {
125
+ const obj = await this.files.findObj(objId);
126
+ return !!obj;
127
+ }
128
+ async isRemoteVersionOnDisk(objId, version) {
129
+ var _a;
130
+ const obj = await this.getObjOrThrow(objId, true);
131
+ const status = obj.statusObj();
132
+ const { remote } = status.syncStatus();
133
+ if (((remote === null || remote === void 0 ? void 0 : remote.latest) !== version)
134
+ || !((_a = remote.archived) === null || _a === void 0 ? void 0 : _a.includes(version))) {
135
+ throw (0, exceptions_1.makeObjVersionNotFoundExc)(objId, version);
136
+ }
107
137
  // XXX
108
- // - check that given version is synced
109
138
  // - get state of file
110
- // But, should this be renamed to isRemoteVersionOnDisk ?
111
- //
112
139
  throw new Error('SyncedStore.isRemoteVersionOnDisk() not implemented.');
113
140
  }
114
141
  download(objId, version) {
115
- // XXX
142
+ // XXX
143
+ // - check if on disk
144
+ // - download header
145
+ // - want result of DC-296, calculation of diff to download, relative to
146
+ // latest version on the disk, using headers of both versions.
116
147
  throw new Error('SyncedStore.download() not implemented.');
117
148
  }
118
149
  async upload(objId, localVersion, uploadVersion, uploadHeader, createOnRemote) {
@@ -134,7 +165,14 @@ class SyncedStore {
134
165
  if (!objId) {
135
166
  return;
136
167
  }
137
- await this.remoteStorage.deleteObj(objId);
168
+ const obj = await this.getObjOrThrow(objId, true);
169
+ const status = obj.statusObj();
170
+ if (status.neverUploaded()) {
171
+ return;
172
+ }
173
+ if (await status.clearPostponeFlagInRemovalOnRemote()) {
174
+ await this.uploader.removeCurrentVersionOf(obj);
175
+ }
138
176
  }
139
177
  dropCachedLocalObjVersionsLessOrEqual(objId, version) {
140
178
  const obj = this.files.getObjInCache(objId);
@@ -164,6 +202,8 @@ class SyncedStore {
164
202
  if (obj) {
165
203
  return obj;
166
204
  }
205
+ // XXX
206
+ // - can we create object by getting obj status
167
207
  return await this.files.makeByDownloadingCurrentVersion(objId);
168
208
  }
169
209
  async getObjOrThrow(objId, allowArchived = false) {
@@ -175,8 +215,8 @@ class SyncedStore {
175
215
  return obj;
176
216
  }
177
217
  }
178
- async getObjSrc(objId, version) {
179
- const obj = await this.getObjOrThrow(objId);
218
+ async getObjSrc(objId, version, allowArchived = false) {
219
+ const obj = await this.getObjOrThrow(objId, allowArchived);
180
220
  if (!version) {
181
221
  version = obj.statusObj().getCurrentLocalOrSynced();
182
222
  }
@@ -3,7 +3,7 @@ import { SyncedObj } from "./obj-files";
3
3
  import { MonoTypeOperatorFunction } from "rxjs";
4
4
  import { FileWrite } from "../../../lib-client/objs-on-disk/file-writing-proc";
5
5
  import { LogError } from "../../../lib-client/logging/log-to-file";
6
- import { UploadInfo } from "./obj-status";
6
+ import { NewVersionUpload } from "./obj-status";
7
7
  export declare type FileWriteTapOperator = MonoTypeOperatorFunction<FileWrite[]>;
8
8
  export declare class UpSyncer {
9
9
  private readonly remoteStorage;
@@ -21,7 +21,7 @@ export declare class UpSyncer {
21
21
  uploadFromDisk(obj: SyncedObj, localVersion: number, uploadVersion: number, uploadHeader: Uint8Array | undefined, syncedBase: number | undefined, createOnRemote: boolean): Promise<void>;
22
22
  }
23
23
  export interface UploadStatusRecorder {
24
- recordUploadStart(info: UploadInfo): Promise<void>;
25
- recordUploadCancellation(info: UploadInfo): Promise<void>;
26
- recordUploadInterimState(info: UploadInfo): Promise<void>;
24
+ recordUploadStart(info: NewVersionUpload): Promise<void>;
25
+ recordUploadCancellation(info: NewVersionUpload): Promise<void>;
26
+ recordUploadInterimState(info: NewVersionUpload): Promise<void>;
27
27
  }
@@ -50,12 +50,17 @@ class UpSyncer {
50
50
  // return objUploads.tapFileWrite(isNew, newVersion, baseVersion);
51
51
  }
52
52
  async removeCurrentVersionOf(obj) {
53
- throw new Error('UpSyncer.removeCurrentVersionOf() not implemented');
54
- // const objUploads = this.getOrMakeUploadsFor(obj);
55
- // XXX is removal set in this older code? This may need to change anyway
56
- // if (objUploads.neededExecutor()) {
57
- // this.execPools.add(objUploads);
58
- // }
53
+ try {
54
+ await this.remoteStorage.deleteObj(obj.objId);
55
+ }
56
+ catch (exc) {
57
+ // XXX
58
+ // - we need to distinguish errors and put this work somewhere
59
+ // to run when we go online, for example.
60
+ await this.logError(exc, `Uploading of obj removal failed.`);
61
+ return;
62
+ }
63
+ await obj.recordRemovalUploadAndGC();
59
64
  }
60
65
  async uploadFromDisk(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createOnRemote) {
61
66
  const task = await UploadTask.for(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createOnRemote, this.remoteStorage, this.execPools);
@@ -90,6 +95,7 @@ class UploadTask {
90
95
  needUpload = await wholeVerUpload(src, uploadHeader, createObj);
91
96
  }
92
97
  const info = {
98
+ type: 'new-version',
93
99
  localVersion,
94
100
  uploadVersion,
95
101
  baseVersion: syncedBase,
@@ -6,6 +6,7 @@ export interface StorageException extends web3n.RuntimeException {
6
6
  objId?: ObjId;
7
7
  version?: number;
8
8
  objNotFound?: true;
9
+ objVersionNotFound?: true;
9
10
  objExists?: true;
10
11
  concurrentTransaction?: true;
11
12
  unknownTransaction?: true;
@@ -13,8 +14,19 @@ export interface StorageException extends web3n.RuntimeException {
13
14
  currentVersion?: number;
14
15
  storageIsClosed?: true;
15
16
  }
17
+ export interface StorageExceptionFlags {
18
+ remoteStorage?: true;
19
+ objNotFound?: true;
20
+ objVersionNotFound?: true;
21
+ objExists?: true;
22
+ concurrentTransaction?: true;
23
+ unknownTransaction?: true;
24
+ versionMismatch?: true;
25
+ storageIsClosed?: true;
26
+ }
16
27
  export declare function makeStorageException(fields: Partial<StorageException>): StorageException;
17
- export declare function makeObjNotFoundExc(objId: ObjId, version?: number, remoteStorage?: true): StorageException;
28
+ export declare function makeObjNotFoundExc(objId: ObjId, remoteStorage?: true): StorageException;
29
+ export declare function makeObjVersionNotFoundExc(objId: ObjId, version: number, remoteStorage?: true): StorageException;
18
30
  export declare function makeObjExistsExc(objId: ObjId, version?: number, remoteStorage?: true): StorageException;
19
31
  export declare function makeConcurrentTransExc(objId: ObjId): StorageException;
20
32
  export declare function makeUnknownTransactionExc(objId: ObjId): StorageException;
@@ -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.makeFSSyncException = exports.makeStorageIsClosedExc = exports.makeVersionMismatchExc = exports.makeUnknownTransactionExc = exports.makeConcurrentTransExc = exports.makeObjExistsExc = exports.makeObjNotFoundExc = exports.makeStorageException = void 0;
19
+ exports.makeFSSyncException = exports.makeStorageIsClosedExc = exports.makeVersionMismatchExc = exports.makeUnknownTransactionExc = exports.makeConcurrentTransExc = exports.makeObjExistsExc = exports.makeObjVersionNotFoundExc = exports.makeObjNotFoundExc = exports.makeStorageException = void 0;
20
20
  function makeStorageException(fields) {
21
21
  const exc = {
22
22
  runtimeException: true,
@@ -28,12 +28,18 @@ function makeStorageException(fields) {
28
28
  return exc;
29
29
  }
30
30
  exports.makeStorageException = makeStorageException;
31
- function makeObjNotFoundExc(objId, version, remoteStorage) {
31
+ function makeObjNotFoundExc(objId, remoteStorage) {
32
32
  return makeStorageException({
33
- objId, version, objNotFound: true, remoteStorage
33
+ objId, objNotFound: true, remoteStorage
34
34
  });
35
35
  }
36
36
  exports.makeObjNotFoundExc = makeObjNotFoundExc;
37
+ function makeObjVersionNotFoundExc(objId, version, remoteStorage) {
38
+ return makeStorageException({
39
+ objId, version, objVersionNotFound: true, remoteStorage
40
+ });
41
+ }
42
+ exports.makeObjVersionNotFoundExc = makeObjVersionNotFoundExc;
37
43
  function makeObjExistsExc(objId, version, remoteStorage) {
38
44
  return makeStorageException({
39
45
  objId, version, objExists: true, remoteStorage
@@ -11,7 +11,12 @@ export declare type FirstSaveReqOpts = api.PutObjFirstQueryOpts;
11
11
  export declare type FollowingSaveReqOpts = api.PutObjSecondQueryOpts;
12
12
  export declare class StorageOwner extends ServiceUser {
13
13
  maxChunkSize: number | undefined;
14
- constructor(user: string, getSigner: IGetMailerIdSigner, mainUrlGetter: () => Promise<string>, net: NetClient);
14
+ private constructor();
15
+ static make(user: string, getSigner: IGetMailerIdSigner, mainUrlGetter: () => Promise<string>, net: NetClient): StorageOwner;
16
+ static makeBeforeMidSetup(user: string, mainUrlGetter: () => Promise<string>, net: NetClient): {
17
+ remote: StorageOwner;
18
+ setMid: (getSigner: IGetMailerIdSigner) => void;
19
+ };
15
20
  getKeyDerivParams(): Promise<keyGen.ScryptGenParams>;
16
21
  private setSessionParams;
17
22
  /**