core-3nweb-client-lib 0.53.19 → 0.53.20
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.
- package/build/api-defs/files.d.ts +6 -1
- package/build/core/asmail/delivery/index.js +3 -3
- package/build/core/asmail/delivery/per-recipient-wip.js +3 -2
- package/build/core/storage/synced/upsyncer.d.ts +1 -0
- package/build/core/storage/synced/upsyncer.js +19 -14
- package/build/lib-client/request-utils.js +1 -1
- package/build/lib-client/xsp-fs/file.js +3 -1
- package/build/lib-client/xsp-fs/folder-node.js +11 -32
- package/build/lib-client/xsp-fs/fs.js +3 -1
- package/build/lib-client/xsp-fs/node-in-fs.d.ts +1 -1
- package/build/lib-client/xsp-fs/node-in-fs.js +5 -5
- package/build/lib-common-on-node/websocket-from-node.js +1 -1
- package/package.json +1 -1
|
@@ -1209,7 +1209,8 @@ declare namespace web3n.files {
|
|
|
1209
1209
|
syncStatus: ItemSyncStatus;
|
|
1210
1210
|
}
|
|
1211
1211
|
|
|
1212
|
-
type UploadEvent = UploadStartEvent | UploadProgressEvent |
|
|
1212
|
+
type UploadEvent = UploadStartEvent | UploadProgressEvent |
|
|
1213
|
+
UploadDisconnectedEvent | UploadErredEvent | UploadCancelledEvent | UploadDoneEvent;
|
|
1213
1214
|
|
|
1214
1215
|
interface UploadEventBase extends FSEvent {
|
|
1215
1216
|
uploadTaskId: number;
|
|
@@ -1238,6 +1239,10 @@ declare namespace web3n.files {
|
|
|
1238
1239
|
error: any;
|
|
1239
1240
|
}
|
|
1240
1241
|
|
|
1242
|
+
interface UploadCancelledEvent extends UploadEventBase {
|
|
1243
|
+
type: 'upload-cancelled';
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1241
1246
|
interface UploadDoneEvent extends UploadEventBase {
|
|
1242
1247
|
type: 'upload-done';
|
|
1243
1248
|
}
|
|
@@ -102,7 +102,6 @@ class Delivery {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
observeDelivery(id, observer) {
|
|
105
|
-
var _a;
|
|
106
105
|
const msg = this.msgs.get(id);
|
|
107
106
|
if (!msg) {
|
|
108
107
|
if (observer.error) {
|
|
@@ -111,8 +110,9 @@ class Delivery {
|
|
|
111
110
|
return () => { };
|
|
112
111
|
}
|
|
113
112
|
if (msg.isDone()) {
|
|
114
|
-
(
|
|
115
|
-
|
|
113
|
+
(0, sleep_1.sleep)(1)
|
|
114
|
+
.then(() => { var _a; return (_a = observer.next) === null || _a === void 0 ? void 0 : _a.call(observer, (0, json_utils_1.copy)(msg.progress)); })
|
|
115
|
+
.then(() => { var _a; return (_a = observer.complete) === null || _a === void 0 ? void 0 : _a.call(observer); });
|
|
116
116
|
return () => { };
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016 - 2017, 2019 - 2021 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2016 - 2017, 2019 - 2021, 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
|
|
@@ -118,11 +118,12 @@ class WIP {
|
|
|
118
118
|
async cancel() {
|
|
119
119
|
this.state.stage = "cancel";
|
|
120
120
|
return this.proc.startOrChain(async () => {
|
|
121
|
+
var _a;
|
|
121
122
|
if (this.state.stage === undefined) {
|
|
122
123
|
return;
|
|
123
124
|
}
|
|
124
125
|
this.state.stage = undefined;
|
|
125
|
-
if (this.sender.sessionId) {
|
|
126
|
+
if ((_a = this.sender) === null || _a === void 0 ? void 0 : _a.sessionId) {
|
|
126
127
|
await this.sender.cancelDelivery();
|
|
127
128
|
}
|
|
128
129
|
});
|
|
@@ -24,6 +24,7 @@ const obj_status_1 = require("./obj-status");
|
|
|
24
24
|
const deferred_1 = require("../../../lib-common/processes/deferred");
|
|
25
25
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
26
26
|
const synced_1 = require("../../../lib-common/processes/synced");
|
|
27
|
+
const error_1 = require("../../../lib-common/exceptions/error");
|
|
27
28
|
const MAX_CHUNK_SIZE = 512 * 1024;
|
|
28
29
|
const MAX_FAST_UPLOAD = 2 * 1024 * 1024;
|
|
29
30
|
class UpSyncer {
|
|
@@ -33,6 +34,11 @@ class UpSyncer {
|
|
|
33
34
|
this.tasksByObjIds = new Map();
|
|
34
35
|
this.tasksByIds = new Map();
|
|
35
36
|
this.syncedUploadStarts = new synced_1.NamedProcs();
|
|
37
|
+
this.removeTask = (task) => {
|
|
38
|
+
if (this.tasksByIds.delete(task.taskId)) {
|
|
39
|
+
this.tasksByObjIds.delete(task.objId);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
36
42
|
this.execPools = new labelled_exec_pools_1.LabelledExecPools([
|
|
37
43
|
{ label: 'long', maxProcs: 1 },
|
|
38
44
|
{ label: 'fast', maxProcs: 1 }
|
|
@@ -90,17 +96,11 @@ class UpSyncer {
|
|
|
90
96
|
if (localVersion > uploadVersion) {
|
|
91
97
|
await obj.removeLocalVersionFilesLessThan(localVersion);
|
|
92
98
|
}
|
|
93
|
-
});
|
|
99
|
+
}, this.removeTask);
|
|
94
100
|
this.tasksByIds.set(uploadTaskId, task);
|
|
95
101
|
this.tasksByObjIds.set(task.objId, task);
|
|
96
|
-
const completion = task.completion();
|
|
97
|
-
completion.finally(() => {
|
|
98
|
-
if (this.tasksByIds.delete(task.taskId)) {
|
|
99
|
-
this.tasksByObjIds.delete(task.objId);
|
|
100
|
-
}
|
|
101
|
-
}).catch(noop);
|
|
102
102
|
this.execPools.add(task);
|
|
103
|
-
return { completion, uploadTaskId };
|
|
103
|
+
return { completion: task.completion(), uploadTaskId };
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -108,7 +108,7 @@ exports.UpSyncer = UpSyncer;
|
|
|
108
108
|
Object.freeze(UpSyncer.prototype);
|
|
109
109
|
Object.freeze(UpSyncer);
|
|
110
110
|
class UploadTask {
|
|
111
|
-
constructor(taskId, remoteStorage, objId, objStatus, src, info, uploadHeader, doAtCompletion, eventSink, isRestart) {
|
|
111
|
+
constructor(taskId, remoteStorage, objId, objStatus, src, info, uploadHeader, doAtCompletion, rmTask, eventSink, isRestart) {
|
|
112
112
|
this.taskId = taskId;
|
|
113
113
|
this.remoteStorage = remoteStorage;
|
|
114
114
|
this.objId = objId;
|
|
@@ -117,6 +117,7 @@ class UploadTask {
|
|
|
117
117
|
this.info = info;
|
|
118
118
|
this.uploadHeader = uploadHeader;
|
|
119
119
|
this.doAtCompletion = doAtCompletion;
|
|
120
|
+
this.rmTask = rmTask;
|
|
120
121
|
this.eventSink = eventSink;
|
|
121
122
|
this.uploadCompletion = (0, deferred_1.defer)();
|
|
122
123
|
this.execLabel = executorLabelFor(this.info.needUpload);
|
|
@@ -124,14 +125,14 @@ class UploadTask {
|
|
|
124
125
|
this.emitUploadEvent('upload-started', { totalBytesToUpload: this.totalBytesToUpload, isRestart });
|
|
125
126
|
Object.seal(this);
|
|
126
127
|
}
|
|
127
|
-
static async for(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createObj, taskId, eventSink, remoteStorage, doAtCompletion) {
|
|
128
|
+
static async for(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createObj, taskId, eventSink, remoteStorage, doAtCompletion, rmTask) {
|
|
128
129
|
const src = await obj.getObjSrcFromLocalAndSyncedBranch(localVersion);
|
|
129
130
|
const objStatus = obj.statusObj();
|
|
130
131
|
if (objStatus.upload) {
|
|
131
132
|
const info = objStatus.upload;
|
|
132
133
|
if ((info.type === 'new-version')
|
|
133
134
|
&& (info.localVersion === localVersion) && (info.uploadVersion === uploadVersion)) {
|
|
134
|
-
return new UploadTask(taskId, remoteStorage, obj.objId, objStatus, src, info, uploadHeader, doAtCompletion, eventSink, true);
|
|
135
|
+
return new UploadTask(taskId, remoteStorage, obj.objId, objStatus, src, info, uploadHeader, doAtCompletion, rmTask, eventSink, true);
|
|
135
136
|
}
|
|
136
137
|
else {
|
|
137
138
|
let message;
|
|
@@ -164,7 +165,7 @@ class UploadTask {
|
|
|
164
165
|
needUpload
|
|
165
166
|
};
|
|
166
167
|
await objStatus.recordUploadStart(info);
|
|
167
|
-
return new UploadTask(taskId, remoteStorage, obj.objId, objStatus, src, info, uploadHeader, doAtCompletion, eventSink, false);
|
|
168
|
+
return new UploadTask(taskId, remoteStorage, obj.objId, objStatus, src, info, uploadHeader, doAtCompletion, rmTask, eventSink, false);
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
171
|
neededExecutor() {
|
|
@@ -220,6 +221,7 @@ class UploadTask {
|
|
|
220
221
|
else {
|
|
221
222
|
await this.doAtCompletion().finally(() => {
|
|
222
223
|
this.uploadCompletion.resolve();
|
|
224
|
+
this.rmTask(this);
|
|
223
225
|
this.emitUploadEvent('upload-done', {});
|
|
224
226
|
});
|
|
225
227
|
return true;
|
|
@@ -243,10 +245,11 @@ class UploadTask {
|
|
|
243
245
|
uploadVersion: this.info.uploadVersion,
|
|
244
246
|
cause: exc
|
|
245
247
|
}));
|
|
248
|
+
await this.objStatus.recordUploadCancellation(this.info);
|
|
249
|
+
this.rmTask(this);
|
|
246
250
|
this.emitUploadEvent('upload-erred', {
|
|
247
|
-
error: exc
|
|
251
|
+
error: (exc.runtimeException ? exc : (0, error_1.stringifyErr)(exc))
|
|
248
252
|
});
|
|
249
|
-
await this.objStatus.recordUploadCancellation(this.info);
|
|
250
253
|
return true;
|
|
251
254
|
}
|
|
252
255
|
}
|
|
@@ -350,6 +353,8 @@ class UploadTask {
|
|
|
350
353
|
await this.remoteStorage.cancelTransaction(this.objId, transactionId).catch(noop);
|
|
351
354
|
}
|
|
352
355
|
await this.objStatus.recordUploadCancellation(this.info).catch(noop);
|
|
356
|
+
this.rmTask(this);
|
|
357
|
+
this.emitUploadEvent('upload-cancelled', {});
|
|
353
358
|
}
|
|
354
359
|
}
|
|
355
360
|
Object.freeze(UploadTask.prototype);
|
|
@@ -81,7 +81,7 @@ async function attachRequestReaders(clReq, opts) {
|
|
|
81
81
|
// next tick occurs in between.
|
|
82
82
|
const response$ = (0, rxjs_1.fromEvent)(clReq, 'response', (res) => ({ res, resBodyPromise: readAllBytesFrom(res) }))
|
|
83
83
|
.pipe((0, operators_1.take)(1));
|
|
84
|
-
const err$ = (0, rxjs_1.fromEvent)(clReq, 'error', e => (0, http_1.makeConnectionException)(opts.url, opts.method, 'Cannot connect', e))
|
|
84
|
+
const err$ = (0, rxjs_1.merge)((0, rxjs_1.fromEvent)(clReq, 'error', e => (0, http_1.makeConnectionException)(opts.url, opts.method, 'Cannot connect', e)), (0, rxjs_1.fromEvent)(clReq, 'timeout', () => (0, http_1.makeConnectionException)(opts.url, opts.method, 'Cannot connect', TIMEOUT_FLAG)))
|
|
85
85
|
.pipe((0, operators_1.map)(exc => { throw exc; }), (0, operators_1.takeUntil)(response$));
|
|
86
86
|
try {
|
|
87
87
|
const reply = await (0, rxjs_1.lastValueFrom)((0, rxjs_1.merge)(response$, err$)
|
|
@@ -250,7 +250,8 @@ class S {
|
|
|
250
250
|
const node = await this.n.getNode();
|
|
251
251
|
const startedUpload = await node.startUpload(opts, true);
|
|
252
252
|
if (startedUpload) {
|
|
253
|
-
const { uploadTaskId, uploadVersion } = startedUpload;
|
|
253
|
+
const { uploadTaskId, uploadVersion, completion } = startedUpload;
|
|
254
|
+
completion.catch(noop);
|
|
254
255
|
return { uploadTaskId, uploadVersion };
|
|
255
256
|
}
|
|
256
257
|
else {
|
|
@@ -297,4 +298,5 @@ class S {
|
|
|
297
298
|
}
|
|
298
299
|
Object.freeze(S.prototype);
|
|
299
300
|
Object.freeze(S);
|
|
301
|
+
function noop() { }
|
|
300
302
|
Object.freeze(exports);
|
|
@@ -344,13 +344,7 @@ class FolderNode extends node_in_fs_1.NodeInFS {
|
|
|
344
344
|
exc = (0, file_1.makeFileException)('ioError', `${this.name}/${info.name}`, exc);
|
|
345
345
|
}
|
|
346
346
|
else if (exc.objNotFound) {
|
|
347
|
-
if (fromCurrentNodes) {
|
|
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;
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
347
|
+
if (!fromCurrentNodes) {
|
|
354
348
|
try {
|
|
355
349
|
const node = await this.getNonLocal(info);
|
|
356
350
|
if (node) {
|
|
@@ -610,6 +604,8 @@ class FolderNode extends node_in_fs_1.NodeInFS {
|
|
|
610
604
|
this.callRemoveObjOn('local', f);
|
|
611
605
|
}
|
|
612
606
|
async removeChildEntryUnconditionally(name) {
|
|
607
|
+
// XXX this removal of record is done in presence of error, which may lead to non-accessible child obj.
|
|
608
|
+
// Should we label found inconsistency, so that it can be fixed later? Should we have lost&found?
|
|
613
609
|
await this.doTransition(async (state, version) => {
|
|
614
610
|
const child = state.nodes[name];
|
|
615
611
|
if (!child) {
|
|
@@ -1187,9 +1183,10 @@ function addToTransitionState(state, f, key) {
|
|
|
1187
1183
|
function diffNodes(current, remote, synced) {
|
|
1188
1184
|
const currentNodesById = orderByIds(current.nodes);
|
|
1189
1185
|
const syncedNodesById = orderByIds(synced.nodes);
|
|
1190
|
-
const
|
|
1186
|
+
const removedInLocal = [];
|
|
1191
1187
|
const renamed = [];
|
|
1192
|
-
const
|
|
1188
|
+
const addedInLocal = [];
|
|
1189
|
+
const addedInRemote = [];
|
|
1193
1190
|
const rekeyed = [];
|
|
1194
1191
|
const nameOverlaps = [];
|
|
1195
1192
|
for (const remoteNode of Object.values(remote.nodes)) {
|
|
@@ -1228,10 +1225,10 @@ function diffNodes(current, remote, synced) {
|
|
|
1228
1225
|
else {
|
|
1229
1226
|
const syncedNode = syncedNodesById.get(remoteNode.objId);
|
|
1230
1227
|
if (syncedNode) {
|
|
1231
|
-
|
|
1228
|
+
removedInLocal.push(remoteNode.name);
|
|
1232
1229
|
}
|
|
1233
1230
|
else {
|
|
1234
|
-
|
|
1231
|
+
addedInRemote.push(remoteNode.name);
|
|
1235
1232
|
}
|
|
1236
1233
|
if (current.nodes[remoteNode.name]) {
|
|
1237
1234
|
nameOverlaps.push(remoteNode.name);
|
|
@@ -1241,13 +1238,13 @@ function diffNodes(current, remote, synced) {
|
|
|
1241
1238
|
for (const localNode of currentNodesById.values()) {
|
|
1242
1239
|
const syncedNode = syncedNodesById.get(localNode.objId);
|
|
1243
1240
|
if (!syncedNode) {
|
|
1244
|
-
|
|
1241
|
+
addedInLocal.push(localNode.name);
|
|
1245
1242
|
}
|
|
1246
1243
|
}
|
|
1247
1244
|
return {
|
|
1248
|
-
removed:
|
|
1245
|
+
removed: { inLocal: removedInLocal },
|
|
1249
1246
|
renamed: ((renamed.length > 0) ? renamed : undefined),
|
|
1250
|
-
added:
|
|
1247
|
+
added: { inLocal: addedInLocal, inRemote: addedInRemote },
|
|
1251
1248
|
rekeyed: ((rekeyed.length > 0) ? rekeyed : undefined),
|
|
1252
1249
|
nameOverlaps: ((nameOverlaps.length > 0) ? nameOverlaps : undefined),
|
|
1253
1250
|
};
|
|
@@ -1290,22 +1287,4 @@ function identifyChanges(originalNodes, newNodes) {
|
|
|
1290
1287
|
}
|
|
1291
1288
|
return { addedNodes, removedNodes, renamedNodes };
|
|
1292
1289
|
}
|
|
1293
|
-
function reduceEmptyIn(c) {
|
|
1294
|
-
if (c.inLocal.length > 0) {
|
|
1295
|
-
if (c.inRemote.length > 0) {
|
|
1296
|
-
return c;
|
|
1297
|
-
}
|
|
1298
|
-
else {
|
|
1299
|
-
return { inLocal: c.inLocal };
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
else {
|
|
1303
|
-
if (c.inRemote.length > 0) {
|
|
1304
|
-
return { inRemote: c.inRemote };
|
|
1305
|
-
}
|
|
1306
|
-
else {
|
|
1307
|
-
return;
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
1290
|
Object.freeze(exports);
|
|
@@ -785,7 +785,8 @@ class S {
|
|
|
785
785
|
try {
|
|
786
786
|
const startedUpload = await node.startUpload(opts, true);
|
|
787
787
|
if (startedUpload) {
|
|
788
|
-
const { uploadTaskId, uploadVersion } = startedUpload;
|
|
788
|
+
const { uploadTaskId, uploadVersion, completion } = startedUpload;
|
|
789
|
+
completion.catch(noop);
|
|
789
790
|
return { uploadTaskId, uploadVersion };
|
|
790
791
|
}
|
|
791
792
|
else {
|
|
@@ -950,4 +951,5 @@ class S {
|
|
|
950
951
|
}
|
|
951
952
|
Object.freeze(S.prototype);
|
|
952
953
|
Object.freeze(S);
|
|
954
|
+
function noop() { }
|
|
953
955
|
Object.freeze(exports);
|
|
@@ -125,5 +125,5 @@ export declare abstract class NodeInFS<P extends NodePersistance> implements Nod
|
|
|
125
125
|
}
|
|
126
126
|
export declare function shouldReadCurrentVersion(flags: VersionedReadFlags | undefined): boolean;
|
|
127
127
|
export declare function areBytesEqual(b1: Uint8Array, b2: Uint8Array): boolean;
|
|
128
|
-
export declare function versionFromBranch(branch: SyncVersionsBranch, versionInBranch: number | undefined): number | undefined;
|
|
128
|
+
export declare function versionFromBranch(branch: SyncVersionsBranch, versionInBranch: number | undefined, fsItemName: string): number | undefined;
|
|
129
129
|
export {};
|
|
@@ -553,15 +553,15 @@ class NodeInFS {
|
|
|
553
553
|
let isCurrentLocal;
|
|
554
554
|
if (state === 'behind') {
|
|
555
555
|
isCurrentLocal = false;
|
|
556
|
-
remoteVersion = versionFromBranch(remote, remoteVersion);
|
|
556
|
+
remoteVersion = versionFromBranch(remote, remoteVersion, this.name);
|
|
557
557
|
}
|
|
558
558
|
else if (state === 'conflicting') {
|
|
559
559
|
isCurrentLocal = true;
|
|
560
|
-
remoteVersion = versionFromBranch(remote, remoteVersion);
|
|
560
|
+
remoteVersion = versionFromBranch(remote, remoteVersion, this.name);
|
|
561
561
|
}
|
|
562
562
|
else if (state === 'unsynced') {
|
|
563
563
|
isCurrentLocal = true;
|
|
564
|
-
remoteVersion = versionFromBranch(synced, remoteVersion);
|
|
564
|
+
remoteVersion = versionFromBranch(synced, remoteVersion, this.name);
|
|
565
565
|
}
|
|
566
566
|
else {
|
|
567
567
|
return;
|
|
@@ -716,12 +716,12 @@ function areBytesEqual(b1, b2) {
|
|
|
716
716
|
}
|
|
717
717
|
return true;
|
|
718
718
|
}
|
|
719
|
-
function versionFromBranch(branch, versionInBranch) {
|
|
719
|
+
function versionFromBranch(branch, versionInBranch, fsItemName) {
|
|
720
720
|
var _a;
|
|
721
721
|
if (versionInBranch) {
|
|
722
722
|
if ((versionInBranch !== branch.latest)
|
|
723
723
|
&& !((_a = branch.archived) === null || _a === void 0 ? void 0 : _a.includes(versionInBranch))) {
|
|
724
|
-
throw (0, exceptions_1.makeFSSyncException)(
|
|
724
|
+
throw (0, exceptions_1.makeFSSyncException)(fsItemName, {
|
|
725
725
|
versionMismatch: true,
|
|
726
726
|
message: `Unknown version in branch: ${versionInBranch}`
|
|
727
727
|
});
|
|
@@ -167,7 +167,7 @@ function openSocketFromNode(url, sessionId, timeout, getAgent) {
|
|
|
167
167
|
ensureWebSocketUrlOK(url);
|
|
168
168
|
const headers = {};
|
|
169
169
|
headers[request_utils_1.SESSION_ID_HEADER] = sessionId;
|
|
170
|
-
const ws = new WebSocket(url, { headers, agent: (_a = getAgent === null || getAgent === void 0 ? void 0 : getAgent()) !== null && _a !== void 0 ? _a : https_1.globalAgent, timeout });
|
|
170
|
+
const ws = new WebSocket(url, { headers, agent: (_a = getAgent === null || getAgent === void 0 ? void 0 : getAgent()) !== null && _a !== void 0 ? _a : https_1.globalAgent, handshakeTimeout: timeout });
|
|
171
171
|
let opening = (0, deferred_1.defer)();
|
|
172
172
|
const initOnError = (err) => {
|
|
173
173
|
opening === null || opening === void 0 ? void 0 : opening.reject((0, http_1.makeConnectionException)(url, undefined, `WebSocket connection error: ${err.message}`));
|