core-3nweb-client-lib 0.53.15 → 0.53.19

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.
@@ -1209,7 +1209,7 @@ declare namespace web3n.files {
1209
1209
  syncStatus: ItemSyncStatus;
1210
1210
  }
1211
1211
 
1212
- type UploadEvent = UploadStartEvent | UploadProgressEvent | UploadDisconnectedEvent | UploadDoneEvent;
1212
+ type UploadEvent = UploadStartEvent | UploadProgressEvent | UploadDisconnectedEvent | UploadErredEvent | UploadDoneEvent;
1213
1213
 
1214
1214
  interface UploadEventBase extends FSEvent {
1215
1215
  uploadTaskId: number;
@@ -1233,6 +1233,11 @@ declare namespace web3n.files {
1233
1233
  type: 'upload-disconnected';
1234
1234
  }
1235
1235
 
1236
+ interface UploadErredEvent extends UploadEventBase {
1237
+ type: 'upload-erred';
1238
+ error: any;
1239
+ }
1240
+
1236
1241
  interface UploadDoneEvent extends UploadEventBase {
1237
1242
  type: 'upload-done';
1238
1243
  }
@@ -25,6 +25,7 @@ const json_utils_1 = require("../../../lib-common/json-utils");
25
25
  const rxjs_1 = require("rxjs");
26
26
  const operators_1 = require("rxjs/operators");
27
27
  const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
28
+ const sleep_1 = require("../../../lib-common/processes/sleep");
28
29
  const SMALL_MSG_SIZE = 1024 * 1024;
29
30
  const MSGS_FOLDER = 'msgs';
30
31
  function idToMsgFolder(id) {
@@ -101,6 +102,7 @@ class Delivery {
101
102
  }
102
103
  }
103
104
  observeDelivery(id, observer) {
105
+ var _a;
104
106
  const msg = this.msgs.get(id);
105
107
  if (!msg) {
106
108
  if (observer.error) {
@@ -109,16 +111,14 @@ class Delivery {
109
111
  return () => { };
110
112
  }
111
113
  if (msg.isDone()) {
112
- if (observer.next) {
113
- observer.next((0, json_utils_1.copy)(msg.progress));
114
- }
115
- if (observer.complete) {
116
- observer.complete();
117
- }
114
+ (_a = observer.next) === null || _a === void 0 ? void 0 : _a.call(observer, (0, json_utils_1.copy)(msg.progress));
115
+ (0, sleep_1.sleep)(1).then(() => { var _a; return (_a = observer.complete) === null || _a === void 0 ? void 0 : _a.call(observer); });
118
116
  return () => { };
119
117
  }
120
- const subToProgress = msg.progress$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
121
- return () => { subToProgress.unsubscribe(); };
118
+ else {
119
+ const subToProgress = msg.progress$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
120
+ return () => { subToProgress.unsubscribe(); };
121
+ }
122
122
  }
123
123
  observeAllDeliveries(observer) {
124
124
  const subToProgress = this.allDeliveries$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
@@ -182,14 +182,10 @@ class Delivery {
182
182
  // start/schedule delivery process, according to message's size
183
183
  if (sendImmediately || (msg.deliverySizeLeft() <= SMALL_MSG_SIZE)) {
184
184
  this.immediateDelivery.add(msg);
185
- msg.sendThisSmallMsgInParallel().then(() => {
186
- if (msg.isDone()) {
187
- this.immediateDelivery.delete(msg);
188
- this.performQueuedDelivery();
189
- }
190
- }, async (err) => {
191
- // XXX add to retries queue with some timestamp
185
+ msg.sendThisSmallMsgInParallel()
186
+ .catch(async (err) => {
192
187
  await this.r.logWarning('Got error when sending a message', err);
188
+ }).finally(() => {
193
189
  this.immediateDelivery.delete(msg);
194
190
  this.performQueuedDelivery();
195
191
  });
@@ -219,7 +215,6 @@ class Delivery {
219
215
  }
220
216
  }
221
217
  }, async (err) => {
222
- // XXX add to retries queue with some timestamp
223
218
  await this.r.logWarning('Got error when sending a message', err);
224
219
  if (msg === this.queuedDelivery[0]) {
225
220
  this.queuedDelivery.shift();
@@ -13,7 +13,6 @@ export declare class Msg {
13
13
  private readonly msgFS;
14
14
  private static readonly progressSavingProcs;
15
15
  private readonly sendingProc;
16
- private completionPromise;
17
16
  private cancelled;
18
17
  private sender;
19
18
  private recipients;
@@ -35,7 +34,6 @@ export declare class Msg {
35
34
  isDone(): boolean;
36
35
  isSendingNow(): boolean;
37
36
  deliverySizeLeft(): number;
38
- getCompletionPromise(): Promise<DeliveryProgress>;
39
37
  /**
40
38
  * Calling this method sets this message as cancelled. When returned promise
41
39
  * completes, it is safe to remove message's folder.
@@ -23,7 +23,6 @@ const common_1 = require("./common");
23
23
  const per_recipient_wip_1 = require("./per-recipient-wip");
24
24
  const rxjs_1 = require("rxjs");
25
25
  const json_utils_1 = require("../../../lib-common/json-utils");
26
- const deferred_1 = require("../../../lib-common/processes/deferred");
27
26
  const MAIN_OBJ_FILE_NAME = 'msg.json';
28
27
  const PROGRESS_INFO_FILE_NAME = 'progress.json';
29
28
  const WIPS_INFO_FILE_NAME = 'wips.json';
@@ -64,7 +63,6 @@ class Msg {
64
63
  this.progress = progress;
65
64
  this.msgFS = msgFS;
66
65
  this.sendingProc = new synced_1.SingleProc();
67
- this.completionPromise = undefined;
68
66
  this.cancelled = false;
69
67
  this.sender = undefined;
70
68
  this.recipients = undefined;
@@ -142,8 +140,7 @@ class Msg {
142
140
  // In recipient's part, awaitingRestart flag ?
143
141
  // retryRecipients ?
144
142
  if (checkIfAllRecipientsDone(this.progress)) {
145
- this.progress.allDone = (hasError(this.progress) ?
146
- 'with-errors' : 'all-ok');
143
+ this.progress.allDone = (hasError(this.progress) ? 'with-errors' : 'all-ok');
147
144
  saveProgress = true;
148
145
  }
149
146
  this.r.notifyMsgProgress(this.id, (0, json_utils_1.copy)(this.progress));
@@ -212,15 +209,6 @@ class Msg {
212
209
  }
213
210
  return sizeLeft;
214
211
  }
215
- getCompletionPromise() {
216
- if (this.isDone()) {
217
- throw new Error(`Message delivery has already completed.`);
218
- }
219
- if (!this.completionPromise) {
220
- this.completionPromise = (0, deferred_1.defer)();
221
- }
222
- return this.completionPromise.promise;
223
- }
224
212
  /**
225
213
  * Calling this method sets this message as cancelled. When returned promise
226
214
  * completes, it is safe to remove message's folder.
@@ -275,16 +263,6 @@ class Msg {
275
263
  }
276
264
  });
277
265
  await Promise.all(wipPromises);
278
- // XXX ???
279
- if (this.completionPromise && this.isDone()) {
280
- this.completionPromise.resolve(this.progress);
281
- this.completionPromise = undefined;
282
- }
283
- }).catch(err => {
284
- if (this.completionPromise) {
285
- this.completionPromise.reject(err);
286
- this.completionPromise = undefined;
287
- }
288
266
  });
289
267
  }
290
268
  /**
@@ -325,16 +303,6 @@ class Msg {
325
303
  if (this.sequentialWIP.isDone()) {
326
304
  this.sequentialWIP = undefined;
327
305
  }
328
- // XXX ???
329
- if (this.completionPromise && this.isDone()) {
330
- this.completionPromise.resolve(this.progress);
331
- this.completionPromise = undefined;
332
- }
333
- }).catch(err => {
334
- if (this.completionPromise) {
335
- this.completionPromise.reject(err);
336
- this.completionPromise = undefined;
337
- }
338
306
  });
339
307
  }
340
308
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2016 - 2020, 2022, 2026 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -139,6 +139,7 @@ class LocalObj {
139
139
  throw new Error(`Version ${version} already exists in object ${this.objId}`);
140
140
  }
141
141
  const fPath = this.path(version);
142
+ // write$ process creates version file, and removes it when error happens
142
143
  const { obj, write$ } = await obj_on_disk_1.ObjOnDisk.createFileForWriteOfNewVersion(this.objId, version, fPath, encSub, undefined, this.objSegsGetterFromDisk);
143
144
  try {
144
145
  await (0, rxjs_1.lastValueFrom)(write$);
@@ -38,7 +38,6 @@ export declare class ObjFiles {
38
38
  fileWrite$: Observable<FileWrite[]>;
39
39
  newObj: SyncedObj;
40
40
  }>;
41
- findObjsToRemoveOnRemote(): Observable<ObjId>;
42
41
  scheduleGC(obj: SyncedObj): void;
43
42
  }
44
43
  export type SynchronizerOnObjId = <T>(objId: ObjId, action: () => Promise<T>) => Promise<T>;
@@ -17,7 +17,6 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.SyncedObj = exports.ObjFiles = exports.REMOTE_FILE_NAME_EXT = exports.UNSYNCED_FILE_NAME_EXT = void 0;
20
- const rxjs_1 = require("rxjs");
21
20
  const synced_1 = require("../../../lib-common/processes/synced");
22
21
  const obj_folders_1 = require("../../../lib-client/objs-on-disk/obj-folders");
23
22
  const fs = require("../../../lib-common/async-fs-node");
@@ -137,24 +136,6 @@ class ObjFiles {
137
136
  .pipe((0, utils_for_observables_1.flatTap)(undefined, err => this.removeFailedNewObj(newObj)));
138
137
  return { fileWrite$, newObj };
139
138
  }
140
- findObjsToRemoveOnRemote() {
141
- return (0, rxjs_1.from)([undefined])
142
- .pipe(
143
- // listing recent folders, exactly once
144
- (0, operators_1.mergeMap)(() => this.folders.listRecent()),
145
- // flatten array and space it in time, to process folders one by one
146
- (0, operators_1.mergeMap)(objsAndPaths => objsAndPaths), (0, operators_1.mergeMap)(async ({ objId, path }) => {
147
- const obj = this.objs.get(objId);
148
- if (obj) {
149
- return (obj.statusObj().needsRemovalOnRemote() ?
150
- objId : undefined);
151
- }
152
- else {
153
- const needsRm = await obj_status_1.ObjStatus.fileShowsObjNeedsRemovalOnRemote(path, objId);
154
- return (needsRm ? objId : undefined);
155
- }
156
- }, 1), (0, operators_1.filter)(objId => (objId !== undefined)));
157
- }
158
139
  scheduleGC(obj) {
159
140
  this.gc.scheduleCollection(obj);
160
141
  }
@@ -293,6 +274,7 @@ class SyncedObj {
293
274
  throw new Error(`Version ${version} already exists in object ${this.objId}`);
294
275
  }
295
276
  const fPath = this.localVerPath(version);
277
+ // write$ process creates version file, and removes it when error happens
296
278
  const { obj, write$ } = await obj_on_disk_1.ObjOnDisk.createFileForWriteOfNewVersion(this.objId, version, fPath, encSub, this.downloader, this.localAndSyncedObjSegsGetterFromDisk);
297
279
  this.localVers.set(version, obj);
298
280
  const fileWrite$ = write$.pipe((0, operators_1.tap)({
@@ -211,20 +211,16 @@ class UploadTask {
211
211
  }
212
212
  await this.objStatus.recordUploadInterimState(this.info);
213
213
  if (this.info.needUpload) {
214
- if (this.eventSink) {
215
- this.emitUploadEvent('upload-progress', {
216
- totalBytesToUpload: this.totalBytesToUpload,
217
- bytesLeftToUpload: (0, obj_status_1.countBytesIn)(this.info)
218
- });
219
- }
214
+ this.emitUploadEvent('upload-progress', {
215
+ totalBytesToUpload: this.totalBytesToUpload,
216
+ bytesLeftToUpload: (0, obj_status_1.countBytesIn)(this.info)
217
+ });
220
218
  return false;
221
219
  }
222
220
  else {
223
221
  await this.doAtCompletion().finally(() => {
224
222
  this.uploadCompletion.resolve();
225
- if (this.eventSink) {
226
- this.emitUploadEvent('upload-done', {});
227
- }
223
+ this.emitUploadEvent('upload-done', {});
228
224
  });
229
225
  return true;
230
226
  }
@@ -247,6 +243,9 @@ class UploadTask {
247
243
  uploadVersion: this.info.uploadVersion,
248
244
  cause: exc
249
245
  }));
246
+ this.emitUploadEvent('upload-erred', {
247
+ error: exc
248
+ });
250
249
  await this.objStatus.recordUploadCancellation(this.info);
251
250
  return true;
252
251
  }
@@ -434,7 +434,7 @@ class MailSender {
434
434
  if (!this.sessionId) {
435
435
  throw new Error(`Delivery session is not opened, and cannot be cancelled.`);
436
436
  }
437
- // XXX make delivery canceling request within session
437
+ // XXX make delivery canceling request within session to protocol
438
438
  }
439
439
  }
440
440
  exports.MailSender = MailSender;
@@ -101,7 +101,6 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
101
101
  getFolder(name: string, undefOnMissing?: boolean): Promise<FolderNode | undefined>;
102
102
  getFile(name: string, undefOnMissing?: boolean): Promise<FileNode | undefined>;
103
103
  getLink(name: string, undefOnMissing?: boolean): Promise<LinkNode | undefined>;
104
- private fixMissingChildAndThrow;
105
104
  /**
106
105
  * If no initial local version given, then this performs like doTransition(change) method.
107
106
  * When initial local version is given and check, exceptions are thrown if versions mismatch,
@@ -303,7 +303,17 @@ class FolderNode extends node_in_fs_1.NodeInFS {
303
303
  throw (0, file_1.makeFileException)('notLink', childInfo.name);
304
304
  }
305
305
  }
306
- return this.getOrMakeChildNodeForInfo(childInfo);
306
+ try {
307
+ return await this.getOrMakeChildNodeForInfo(childInfo);
308
+ }
309
+ catch (exc) {
310
+ if (undefOnMissing && exc.notFound) {
311
+ return;
312
+ }
313
+ else {
314
+ throw exc;
315
+ }
316
+ }
307
317
  }
308
318
  async getOrMakeChildNodeForInfo(info, fromCurrentNodes = true) {
309
319
  const { node, nodePromise } = this.storage.nodes.getNodeOrPromise(info.objId);
@@ -335,13 +345,10 @@ class FolderNode extends node_in_fs_1.NodeInFS {
335
345
  }
336
346
  else if (exc.objNotFound) {
337
347
  if (fromCurrentNodes) {
338
- try {
339
- await this.fixMissingChildAndThrow(exc, info);
340
- }
341
- catch (exc) {
342
- deferred.reject(exc);
343
- return;
344
- }
348
+ // XXX this.fixMissingChildAndThrow() was removing object that has been moved on other device
349
+ // Should we label found inconsistency, sot that it can be fixed later? Should we have lost&found?
350
+ deferred.reject((0, file_1.makeFileException)('notFound', info.name, exc));
351
+ return;
345
352
  }
346
353
  else {
347
354
  try {
@@ -395,19 +402,20 @@ class FolderNode extends node_in_fs_1.NodeInFS {
395
402
  getLink(name, undefOnMissing = false) {
396
403
  return this.getNode('link', name, undefOnMissing);
397
404
  }
398
- async fixMissingChildAndThrow(exc, childInfo) {
399
- await this.doTransition(async (state, version) => {
400
- const presentChild = state.nodes[childInfo.name];
401
- if (!presentChild || (presentChild.objId !== childInfo.objId)) {
402
- return [];
403
- }
404
- delete state.nodes[childInfo.name];
405
- return this.makeEntryRemovalEvent(version, 'local', childInfo);
406
- }).catch(noop);
407
- const fileExc = (0, file_1.makeFileException)('notFound', childInfo.name, exc);
408
- fileExc.inconsistentStateOfFS = true;
409
- throw fileExc;
410
- }
405
+ // XXX apparently this causes a problem on moves received on other devices via sync
406
+ // private async fixMissingChildAndThrow(exc: StorageException, childInfo: NodeInfo): Promise<never> {
407
+ // await this.doTransition(async (state, version) => {
408
+ // const presentChild = state.nodes[childInfo.name];
409
+ // if (!presentChild || (presentChild.objId !== childInfo.objId)) {
410
+ // return [];
411
+ // }
412
+ // delete state.nodes[childInfo.name];
413
+ // return this.makeEntryRemovalEvent(version, 'local', childInfo);
414
+ // }).catch(noop);
415
+ // const fileExc = makeFileException('notFound', childInfo.name, exc);
416
+ // fileExc.inconsistentStateOfFS = true;
417
+ // throw fileExc;
418
+ // }
411
419
  /**
412
420
  * If no initial local version given, then this performs like doTransition(change) method.
413
421
  * When initial local version is given and check, exceptions are thrown if versions mismatch,
@@ -1192,7 +1200,7 @@ function diffNodes(current, remote, synced) {
1192
1200
  }
1193
1201
  else {
1194
1202
  const syncedNode = syncedNodesById.get(remoteNode.objId);
1195
- (0, assert_1.assert)(!!synced);
1203
+ (0, assert_1.assert)(!!syncedNode);
1196
1204
  const localChanged = (syncedNode.name !== localNode.name);
1197
1205
  const remoteChanged = (syncedNode.name !== remoteNode.name);
1198
1206
  renamed.push({
@@ -1206,7 +1214,7 @@ function diffNodes(current, remote, synced) {
1206
1214
  }
1207
1215
  if (!(0, node_in_fs_1.areBytesEqual)(localNode.key, remoteNode.key)) {
1208
1216
  const syncedNode = syncedNodesById.get(remoteNode.objId);
1209
- (0, assert_1.assert)(!!synced);
1217
+ (0, assert_1.assert)(!!syncedNode);
1210
1218
  const localChanged = !(0, node_in_fs_1.areBytesEqual)(localNode.key, syncedNode.key);
1211
1219
  const remoteChanged = !(0, node_in_fs_1.areBytesEqual)(localNode.key, syncedNode.key);
1212
1220
  rekeyed.push({
@@ -345,7 +345,7 @@ async function createNewV1File(path) {
345
345
  const initContent = Buffer.alloc(v1_obj_file_format_1.V1_FILE_START.length + 8, 0);
346
346
  initContent.set(v1_obj_file_format_1.V1_FILE_START);
347
347
  // note that all 8 bytes of layout offset are zeros
348
- await fs.writeFile(path, initContent, { flag: 'wx' });
348
+ await fs.writeFile(path, initContent, { flag: 'w' });
349
349
  }
350
350
  async function recordLayoutOffsetInV1(fd, ofs) {
351
351
  const ofsInBytes = Buffer.allocUnsafe(8);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.53.15",
3
+ "version": "0.53.19",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",