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.
- package/build/api-defs/asmail.d.ts +1 -1
- package/build/api-defs/files.d.ts +281 -75
- package/build/core/app-files.js +7 -7
- package/build/core/asmail/config/common.js +2 -2
- package/build/core/asmail/config/index.js +2 -2
- package/build/core/asmail/config/published-intro-key.js +1 -1
- package/build/core/asmail/delivery/common.js +7 -7
- package/build/core/asmail/delivery/index.js +5 -5
- package/build/core/asmail/delivery/msg.js +4 -4
- package/build/core/asmail/delivery/per-recipient-wip.js +1 -1
- package/build/core/asmail/inbox/attachments/fs.d.ts +2 -1
- package/build/core/asmail/inbox/attachments/fs.js +9 -4
- package/build/core/asmail/inbox/cached-msgs.js +1 -1
- package/build/core/asmail/inbox/inbox-events.js +4 -4
- package/build/core/asmail/inbox/index.js +10 -10
- package/build/core/asmail/inbox/msg-downloader.js +1 -1
- package/build/core/asmail/inbox/msg-indexing.js +1 -1
- package/build/core/asmail/inbox/msg-on-disk.js +5 -5
- package/build/core/asmail/index.d.ts +3 -3
- package/build/core/asmail/index.js +13 -8
- package/build/core/asmail/key-verification.js +5 -5
- package/build/core/asmail/keyring/common.js +7 -6
- package/build/core/asmail/keyring/correspondent-keys.js +8 -7
- package/build/core/asmail/keyring/id-to-email-map.js +2 -1
- package/build/core/asmail/keyring/index.d.ts +7 -8
- package/build/core/asmail/keyring/index.js +15 -14
- package/build/core/asmail/keyring/keyring-storage.js +2 -1
- package/build/core/asmail/msg/opener.js +3 -3
- package/build/core/asmail/msg/packer.js +13 -13
- package/build/core/asmail/sending-params/own-params.js +2 -2
- package/build/core/asmail/sending-params/params-from-others.js +1 -1
- package/build/core/id-manager/index.d.ts +43 -0
- package/build/core/{id-manager.js → id-manager/index.js} +36 -114
- package/build/core/id-manager/key-storage.d.ts +21 -0
- package/build/core/id-manager/key-storage.js +96 -0
- package/build/core/index.d.ts +2 -1
- package/build/core/index.js +31 -33
- package/build/core/sign-in.d.ts +1 -2
- package/build/core/sign-in.js +8 -17
- package/build/core/sign-up.d.ts +2 -0
- package/build/core/sign-up.js +11 -10
- package/build/core/storage/common/json-saving.js +2 -2
- package/build/core/storage/common/obj-info-file.d.ts +12 -4
- package/build/core/storage/common/obj-info-file.js +66 -34
- package/build/core/storage/common/utils.d.ts +2 -0
- package/build/core/storage/common/utils.js +32 -0
- package/build/core/storage/index.d.ts +5 -17
- package/build/core/storage/index.js +78 -119
- package/build/core/storage/local/obj-files-gc.d.ts +2 -0
- package/build/core/storage/local/obj-files-gc.js +49 -37
- package/build/core/storage/local/obj-files.d.ts +4 -7
- package/build/core/storage/local/obj-files.js +7 -10
- package/build/core/storage/local/obj-status.d.ts +12 -6
- package/build/core/storage/local/obj-status.js +24 -9
- package/build/core/storage/local/storage.d.ts +10 -7
- package/build/core/storage/local/storage.js +29 -18
- package/build/core/storage/synced/downloader.js +1 -1
- package/build/core/storage/synced/obj-files-gc.d.ts +1 -0
- package/build/core/storage/synced/obj-files-gc.js +76 -39
- package/build/core/storage/synced/obj-files.d.ts +50 -36
- package/build/core/storage/synced/obj-files.js +201 -162
- package/build/core/storage/synced/obj-status.d.ts +99 -86
- package/build/core/storage/synced/obj-status.js +520 -251
- package/build/core/storage/synced/remote-events.d.ts +11 -12
- package/build/core/storage/synced/remote-events.js +73 -56
- package/build/core/storage/synced/storage.d.ts +24 -10
- package/build/core/storage/synced/storage.js +147 -47
- package/build/core/storage/synced/upload-header-file.d.ts +4 -0
- package/build/core/storage/synced/upload-header-file.js +64 -0
- package/build/core/storage/synced/upsyncer.d.ts +12 -7
- package/build/core/storage/synced/upsyncer.js +210 -280
- package/build/core/storage/system-folders/apps-data.d.ts +16 -0
- package/build/core/storage/system-folders/apps-data.js +110 -0
- package/build/core/storage/system-folders/index.d.ts +18 -0
- package/build/core/storage/system-folders/index.js +77 -0
- package/build/core-ipc/common-caps.js +3 -3
- package/build/core-ipc/generic.js +8 -8
- package/build/core-ipc/startup-caps.js +2 -2
- package/build/cryptors.js +6 -2
- package/build/ipc-via-protobuf/asmail-cap.js +58 -57
- package/build/ipc-via-protobuf/bytes.js +16 -17
- package/build/ipc-via-protobuf/connector-clients-side.d.ts +1 -0
- package/build/ipc-via-protobuf/connector-clients-side.js +14 -15
- package/build/ipc-via-protobuf/connector-services-side.js +10 -10
- package/build/ipc-via-protobuf/connector.js +4 -4
- package/build/ipc-via-protobuf/file.d.ts +48 -12
- package/build/ipc-via-protobuf/file.js +474 -126
- package/build/ipc-via-protobuf/fs.d.ts +8 -0
- package/build/ipc-via-protobuf/fs.js +577 -142
- package/build/ipc-via-protobuf/log-cap.js +2 -2
- package/build/ipc-via-protobuf/mailerid.js +3 -3
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
- package/build/ipc-via-protobuf/protobuf-msg.js +11 -7
- package/build/ipc-via-protobuf/startup-cap.js +21 -21
- package/build/ipc-via-protobuf/storage-cap.js +12 -12
- package/build/ipc.js +7 -2
- package/build/lib-client/3nstorage/exceptions.d.ts +16 -1
- package/build/lib-client/3nstorage/exceptions.js +21 -3
- package/build/lib-client/3nstorage/service.d.ts +21 -3
- package/build/lib-client/3nstorage/service.js +128 -46
- package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
- package/build/lib-client/3nstorage/util/file-based-json.js +3 -2
- package/build/lib-client/3nstorage/util/for-arrays.d.ts +1 -0
- package/build/lib-client/3nstorage/util/for-arrays.js +32 -0
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +44 -19
- package/build/lib-client/3nstorage/xsp-fs/common.js +30 -19
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +17 -13
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +31 -6
- package/build/lib-client/3nstorage/xsp-fs/file.js +73 -25
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +4 -4
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +32 -13
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +752 -192
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +35 -4
- package/build/lib-client/3nstorage/xsp-fs/fs.js +236 -119
- package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/link-node.js +7 -2
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +30 -29
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +232 -127
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +17 -18
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +3 -3
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +53 -53
- package/build/lib-client/3nweb-signup.js +4 -4
- package/build/lib-client/asmail/recipient.js +15 -15
- package/build/lib-client/asmail/sender.js +22 -22
- package/build/lib-client/asmail/service-config.js +3 -3
- package/build/lib-client/cryptor/cryptor-in-worker.js +18 -16
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.js +4 -2
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-js.js +1 -1
- package/build/lib-client/cryptor/in-proc-wasm.js +6 -6
- package/build/lib-client/cryptor/worker-js.js +2 -2
- package/build/lib-client/cryptor/worker-wasm.js +2 -2
- package/build/lib-client/files-select.js +1 -1
- package/build/lib-client/files.d.ts +1 -1
- package/build/lib-client/files.js +71 -6
- package/build/lib-client/fs-collection.js +1 -1
- package/build/lib-client/fs-sync-utils.d.ts +5 -0
- package/build/lib-client/fs-sync-utils.js +61 -0
- package/build/lib-client/fs-view.d.ts +14 -0
- package/build/lib-client/fs-view.js +33 -0
- package/build/lib-client/key-derivation.js +1 -1
- package/build/lib-client/local-files/dev-file-sink.js +9 -9
- package/build/lib-client/local-files/dev-file-src.js +2 -2
- package/build/lib-client/local-files/device-fs.d.ts +1 -1
- package/build/lib-client/local-files/device-fs.js +56 -54
- package/build/lib-client/logging/log-to-file.d.ts +1 -1
- package/build/lib-client/logging/log-to-file.js +7 -7
- package/build/lib-client/mailer-id/login.js +7 -7
- package/build/lib-client/mailer-id/provisioner.js +12 -12
- package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -3
- package/build/lib-client/objs-on-disk/obj-folders.js +31 -31
- package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +13 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +24 -9
- package/build/lib-client/request-utils.d.ts +1 -0
- package/build/lib-client/request-utils.js +13 -13
- package/build/lib-client/server-events.d.ts +3 -3
- package/build/lib-client/server-events.js +9 -8
- package/build/lib-client/service-locator.js +10 -10
- package/build/lib-client/user-with-mid-session.d.ts +2 -1
- package/build/lib-client/user-with-mid-session.js +14 -8
- package/build/lib-client/user-with-pkl-session.js +25 -25
- package/build/lib-client/ws-utils.js +2 -2
- package/build/lib-common/async-cryptor-wrap.js +4 -4
- package/build/lib-common/async-fs-node.d.ts +5 -3
- package/build/lib-common/async-fs-node.js +17 -17
- package/build/lib-common/byte-streaming/pipe.js +1 -1
- package/build/lib-common/byte-streaming/wrapping.js +13 -13
- package/build/lib-common/canonical-address.js +1 -1
- package/build/lib-common/exceptions/error.d.ts +1 -0
- package/build/lib-common/exceptions/error.js +7 -6
- package/build/lib-common/exceptions/file.d.ts +4 -2
- package/build/lib-common/exceptions/file.js +24 -54
- package/build/lib-common/ipc/generic-ipc.js +5 -4
- package/build/lib-common/ipc/ws-ipc.js +2 -2
- package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
- package/build/lib-common/objs-on-disk/file-layout.d.ts +19 -0
- package/build/lib-common/objs-on-disk/file-layout.js +130 -12
- package/build/lib-common/objs-on-disk/obj-file.d.ts +13 -2
- package/build/lib-common/objs-on-disk/obj-file.js +96 -35
- package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
- package/build/lib-common/objs-on-disk/utils.js +3 -3
- package/build/lib-common/objs-on-disk/v1-obj-file-format.js +14 -14
- package/build/lib-common/processes/labelled-exec-pools.d.ts +1 -1
- package/build/lib-common/processes/labelled-exec-pools.js +1 -1
- package/build/lib-common/processes/pressure.js +2 -2
- package/build/lib-common/processes/synced.js +1 -1
- package/build/lib-common/processes/timeout.js +2 -2
- package/build/lib-common/random-node.js +7 -7
- package/build/lib-common/service-api/3nstorage/owner.d.ts +101 -42
- package/build/lib-common/service-api/3nstorage/owner.js +83 -40
- package/build/lib-common/service-api/asmail/delivery.js +2 -2
- package/build/lib-common/service-api/asmail/retrieval.js +1 -1
- package/build/lib-common/timed-cache.d.ts +1 -0
- package/build/lib-common/timed-non-weak-cache.d.ts +1 -0
- package/build/lib-common/timed-non-weak-cache.js +11 -0
- package/build/lib-common/utils-for-observables.js +4 -4
- package/build/lib-common/weak-cache.d.ts +1 -0
- package/build/lib-common/weak-cache.js +12 -1
- package/build/lib-index.d.ts +2 -1
- package/build/lib-index.js +10 -7
- package/build/protos/asmail.proto.js +12955 -7496
- package/build/protos/file.proto.js +4867 -2744
- package/build/protos/fs.proto.js +9227 -3768
- package/package.json +7 -5
- package/protos/file.proto +91 -19
- package/protos/fs.proto +107 -8
- package/build/core/id-manager.d.ts +0 -46
|
@@ -17,356 +17,286 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.UpSyncer = void 0;
|
|
20
|
-
const operators_1 = require("rxjs/operators");
|
|
21
20
|
const labelled_exec_pools_1 = require("../../../lib-common/processes/labelled-exec-pools");
|
|
21
|
+
const exceptions_1 = require("../../../lib-client/3nstorage/exceptions");
|
|
22
22
|
const assert_1 = require("../../../lib-common/assert");
|
|
23
|
+
const deferred_1 = require("../../../lib-common/processes/deferred");
|
|
24
|
+
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
23
25
|
const MAX_CHUNK_SIZE = 512 * 1024;
|
|
24
26
|
const MAX_FAST_UPLOAD = 2 * 1024 * 1024;
|
|
25
|
-
function executorLabelFor(info) {
|
|
26
|
-
let uploadSize = 0;
|
|
27
|
-
if (info.header) {
|
|
28
|
-
uploadSize += info.header;
|
|
29
|
-
}
|
|
30
|
-
for (const seg of info.segs) {
|
|
31
|
-
uploadSize += seg.len;
|
|
32
|
-
}
|
|
33
|
-
return ((uploadSize <= MAX_FAST_UPLOAD) ? 'fast' : 'long');
|
|
34
|
-
}
|
|
35
|
-
function addEventToInfo(info, writeEv) {
|
|
36
|
-
for (const w of writeEv) {
|
|
37
|
-
if (w.isHeader) {
|
|
38
|
-
info.header = w.bytes.length;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
mergeSections(info.segs, w);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function mergeSections(segs, w) {
|
|
46
|
-
const wStart = w.ofs;
|
|
47
|
-
const wLen = w.bytes.length;
|
|
48
|
-
for (let i = 0; i < segs.length; i += 1) {
|
|
49
|
-
const section = segs[i];
|
|
50
|
-
const sectionEnd = section.ofs + section.len;
|
|
51
|
-
if (sectionEnd < wStart) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (sectionEnd === wStart) {
|
|
55
|
-
section.len += wLen;
|
|
56
|
-
}
|
|
57
|
-
else if (section.ofs <= wStart) {
|
|
58
|
-
const maxOverlap = section.len - (wStart - section.ofs);
|
|
59
|
-
if (maxOverlap < wLen) {
|
|
60
|
-
section.len += wLen - maxOverlap;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else if ((wStart + wLen) === section.ofs) {
|
|
64
|
-
section.ofs = wStart;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
segs.splice(i, 0, { ofs: wStart, len: wLen });
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
segs.push({ ofs: wStart, len: wLen });
|
|
72
|
-
}
|
|
73
27
|
class UpSyncer {
|
|
74
|
-
constructor(remoteStorage, logError
|
|
28
|
+
constructor(remoteStorage, logError) {
|
|
75
29
|
this.remoteStorage = remoteStorage;
|
|
76
30
|
this.logError = logError;
|
|
77
|
-
this.broadcastUpSyncEvent = broadcastUpSyncEvent;
|
|
78
|
-
this.uploads = new Map();
|
|
79
31
|
this.execPools = new labelled_exec_pools_1.LabelledExecPools([
|
|
80
32
|
{ label: 'long', maxProcs: 1 },
|
|
81
33
|
{ label: 'fast', maxProcs: 1 }
|
|
82
34
|
], logError);
|
|
83
35
|
Object.seal(this);
|
|
84
36
|
}
|
|
85
|
-
getOrMakeUploadsFor(obj) {
|
|
86
|
-
let uploads = this.uploads.get(obj);
|
|
87
|
-
if (!uploads) {
|
|
88
|
-
uploads = new ObjUpSync(obj, this.remoteStorage, this.execPools, this.logError, this.broadcastUpSyncEvent);
|
|
89
|
-
this.uploads.set(obj, uploads);
|
|
90
|
-
}
|
|
91
|
-
return uploads;
|
|
92
|
-
}
|
|
93
37
|
start() {
|
|
94
38
|
this.execPools.start();
|
|
95
39
|
}
|
|
96
40
|
async stop() {
|
|
97
41
|
await this.execPools.stop(); // implicitly cancels all upsync tasks
|
|
98
|
-
this.uploads.clear();
|
|
99
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates an rxjs operator to tap saving process, starting upload while
|
|
45
|
+
* writing is ongoing.
|
|
46
|
+
*/
|
|
100
47
|
tapFileWrite(obj, isNew, newVersion, baseVersion) {
|
|
101
|
-
|
|
102
|
-
|
|
48
|
+
throw new Error('UpSyncer.tapFileWrite() not implemented');
|
|
49
|
+
// const objUploads = this.getOrMakeUploadsFor(obj);
|
|
50
|
+
// return objUploads.tapFileWrite(isNew, newVersion, baseVersion);
|
|
103
51
|
}
|
|
104
52
|
async removeCurrentVersionOf(obj) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.execPools.add(objUploads);
|
|
53
|
+
try {
|
|
54
|
+
await this.remoteStorage.deleteObj(obj.objId);
|
|
108
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();
|
|
64
|
+
}
|
|
65
|
+
async uploadFromDisk(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createOnRemote) {
|
|
66
|
+
const task = await UploadTask.for(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createOnRemote, this.remoteStorage, this.execPools);
|
|
67
|
+
this.execPools.add(task);
|
|
68
|
+
await task.completion();
|
|
109
69
|
}
|
|
110
70
|
}
|
|
111
71
|
exports.UpSyncer = UpSyncer;
|
|
112
72
|
Object.freeze(UpSyncer.prototype);
|
|
113
73
|
Object.freeze(UpSyncer);
|
|
114
|
-
class
|
|
115
|
-
constructor(
|
|
116
|
-
this.obj = obj;
|
|
74
|
+
class UploadTask {
|
|
75
|
+
constructor(remoteStorage, objId, objStatus, src, execPools, info, uploadHeader) {
|
|
117
76
|
this.remoteStorage = remoteStorage;
|
|
77
|
+
this.objId = objId;
|
|
78
|
+
this.objStatus = objStatus;
|
|
79
|
+
this.src = src;
|
|
118
80
|
this.execPools = execPools;
|
|
119
|
-
this.
|
|
120
|
-
this.
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
123
|
-
this.runningProc = undefined;
|
|
81
|
+
this.info = info;
|
|
82
|
+
this.uploadHeader = uploadHeader;
|
|
83
|
+
this.uploadCompletion = (0, deferred_1.defer)();
|
|
84
|
+
this.execLabel = executorLabelFor(this.info.needUpload);
|
|
124
85
|
Object.seal(this);
|
|
125
86
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
baseVersion,
|
|
133
|
-
needUpload: {
|
|
134
|
-
segs: []
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
if (isObjNew) {
|
|
138
|
-
uploadInfo.createObj = true;
|
|
139
|
-
}
|
|
140
|
-
return operators_1.tap(writeEv => {
|
|
141
|
-
addEventToInfo(uploadInfo.needUpload, writeEv);
|
|
142
|
-
}, async (err) => {
|
|
143
|
-
// XXX cancel in-tap upload, when it will be added.
|
|
144
|
-
// Something should be done in case there is a transaction that
|
|
145
|
-
// needs cancelling.
|
|
146
|
-
await this.cancelTransactionIfOpen(uploadInfo);
|
|
147
|
-
await this.logError(err);
|
|
148
|
-
}, () => {
|
|
149
|
-
uploadInfo.needUpload.allByteOnDisk = true;
|
|
150
|
-
this.enqueueTask(uploadInfo);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
enqueueTask(task) {
|
|
154
|
-
this.obj.sync().queueTask(task);
|
|
155
|
-
if (this.neededExecutor()) {
|
|
156
|
-
this.execPools.add(this);
|
|
87
|
+
static async for(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createObj, remoteStorage, execPools) {
|
|
88
|
+
const src = await obj.getObjSrcFromLocalAndSyncedBranch(localVersion);
|
|
89
|
+
let needUpload;
|
|
90
|
+
if (syncedBase) {
|
|
91
|
+
const { diff, newSegsPackOrder } = await obj.diffForUploadOf(localVersion);
|
|
92
|
+
needUpload = await diffVerUpload(src, uploadHeader, diff, newSegsPackOrder);
|
|
157
93
|
}
|
|
158
94
|
else {
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
95
|
+
needUpload = await wholeVerUpload(src, uploadHeader, createObj);
|
|
96
|
+
}
|
|
97
|
+
const info = {
|
|
98
|
+
type: 'new-version',
|
|
99
|
+
localVersion,
|
|
100
|
+
uploadVersion,
|
|
101
|
+
baseVersion: syncedBase,
|
|
102
|
+
needUpload
|
|
103
|
+
};
|
|
104
|
+
const objStatus = obj.statusObj();
|
|
105
|
+
await objStatus.recordUploadStart(info);
|
|
106
|
+
return new UploadTask(remoteStorage, obj.objId, objStatus, src, execPools, info, uploadHeader);
|
|
169
107
|
}
|
|
170
108
|
neededExecutor() {
|
|
171
|
-
|
|
172
|
-
if (!task) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (task.type !== 'upload') {
|
|
176
|
-
return 'fast';
|
|
177
|
-
}
|
|
178
|
-
if (!task.needUpload) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
return executorLabelFor(task.needUpload);
|
|
182
|
-
}
|
|
183
|
-
removeArchivedVersion(version) {
|
|
184
|
-
this.enqueueTask({
|
|
185
|
-
type: 'removal',
|
|
186
|
-
archivedVersions: version
|
|
187
|
-
});
|
|
109
|
+
return (!this.info.needUpload ? undefined : this.execLabel);
|
|
188
110
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
this.isCancelled = true;
|
|
192
|
-
await ((_a = this.runningProc) === null || _a === void 0 ? void 0 : _a.catch(noop));
|
|
111
|
+
completion() {
|
|
112
|
+
return this.uploadCompletion.promise;
|
|
193
113
|
}
|
|
194
114
|
async process() {
|
|
195
|
-
if (this.
|
|
115
|
+
if (!this.info.needUpload) {
|
|
196
116
|
return;
|
|
197
117
|
}
|
|
198
|
-
let task = undefined;
|
|
199
118
|
try {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
119
|
+
const upload = this.info.needUpload;
|
|
120
|
+
if (upload.type === 'ordered-diff') {
|
|
121
|
+
if (upload.transactionId) {
|
|
122
|
+
await this.continueOrderedDiffUpload(upload);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
await this.startOrderedDiffUpload(upload);
|
|
204
126
|
}
|
|
205
127
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (task.type === 'upload') {
|
|
214
|
-
this.runningProc = this.processUpload(task);
|
|
215
|
-
}
|
|
216
|
-
else if (task.type === 'removal') {
|
|
217
|
-
this.runningProc = this.processRemoval(task);
|
|
218
|
-
}
|
|
219
|
-
else if (task.type === 'archiving') {
|
|
220
|
-
this.runningProc = this.processArchival(task);
|
|
128
|
+
else if (upload.type === 'ordered-whole') {
|
|
129
|
+
if (upload.transactionId) {
|
|
130
|
+
await this.continueOrderedUpload(upload);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
await this.startOrderedUpload(upload);
|
|
134
|
+
}
|
|
221
135
|
}
|
|
222
136
|
else {
|
|
223
|
-
throw new Error(`
|
|
224
|
-
}
|
|
225
|
-
try {
|
|
226
|
-
await this.runningProc;
|
|
137
|
+
throw new Error(`Unimplemented ${upload.type} upload`);
|
|
227
138
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
catch (err) {
|
|
233
|
-
await this.logError(err, `From ObjUpSync.process task ${task.type}`);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
async processArchival(task) {
|
|
237
|
-
// XXX tell server to archive current version
|
|
238
|
-
await this.logError(`Archival of current version is not implemented, yet.`);
|
|
239
|
-
await this.recordTaskCompletion(task);
|
|
240
|
-
}
|
|
241
|
-
async processRemoval(task) {
|
|
242
|
-
if (task.currentVersion) {
|
|
243
|
-
if (this.obj.objId) {
|
|
244
|
-
await this.remoteStorage.deleteObj(this.obj.objId);
|
|
139
|
+
await this.objStatus.recordUploadInterimState(this.info);
|
|
140
|
+
if (this.info.needUpload) {
|
|
141
|
+
this.execPools.add(this);
|
|
245
142
|
}
|
|
246
143
|
else {
|
|
247
|
-
|
|
144
|
+
this.uploadCompletion.resolve();
|
|
248
145
|
}
|
|
249
146
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
147
|
+
catch (exc) {
|
|
148
|
+
this.info.needUpload = undefined;
|
|
149
|
+
this.uploadCompletion.reject((0, exceptions_1.makeFSSyncException)(`obj-upload`, {
|
|
150
|
+
message: `Fail to upload local version ${this.info.uploadVersion}`,
|
|
151
|
+
localVersion: this.info.uploadVersion,
|
|
152
|
+
cause: exc
|
|
153
|
+
}));
|
|
154
|
+
await this.objStatus.recordUploadCancellation(this.info);
|
|
253
155
|
}
|
|
254
|
-
await this.recordTaskCompletion(task);
|
|
255
|
-
this.obj.scheduleSelfGC();
|
|
256
156
|
}
|
|
257
|
-
async
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
157
|
+
async startOrderedUpload(upload) {
|
|
158
|
+
const maxSegs = this.maxUploadChunk() - upload.header;
|
|
159
|
+
(0, assert_1.assert)(maxSegs > 1);
|
|
160
|
+
const segsToUpload = Math.min(upload.segsLeft, maxSegs);
|
|
161
|
+
const header = await this.headerToUpload();
|
|
162
|
+
let segs = undefined;
|
|
163
|
+
if (segsToUpload > 0) {
|
|
164
|
+
await this.src.segSrc.seek(upload.segsOfs);
|
|
165
|
+
segs = await this.src.segSrc.read(segsToUpload);
|
|
166
|
+
}
|
|
167
|
+
(0, assert_1.assert)(!!segs && (segs.length === segsToUpload));
|
|
168
|
+
const ver = this.info.uploadVersion;
|
|
169
|
+
if (segsToUpload === upload.segsLeft) {
|
|
170
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, { ver, last: true }, undefined, { header, segs });
|
|
171
|
+
this.info.needUpload = undefined;
|
|
267
172
|
}
|
|
268
173
|
else {
|
|
269
|
-
await this.
|
|
174
|
+
upload.transactionId = await this.remoteStorage.saveNewObjVersion(this.objId, { ver }, undefined, { header, segs });
|
|
175
|
+
if (!upload.transactionId) {
|
|
176
|
+
// XXX should this be runtime exception saying that remote acts badly ?
|
|
177
|
+
throw new Error(`Server didn't start obj saving transaction`);
|
|
178
|
+
}
|
|
179
|
+
upload.header = undefined;
|
|
180
|
+
upload.segsOfs += segsToUpload;
|
|
181
|
+
upload.segsLeft -= segsToUpload;
|
|
270
182
|
}
|
|
271
183
|
}
|
|
272
|
-
async
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
await this.remoteStorage.cancelTransaction(this.obj.objId, txnId)
|
|
278
|
-
.catch((exc) => {
|
|
279
|
-
if (!exc.unknownTransaction) {
|
|
280
|
-
throw exc;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
184
|
+
async headerToUpload() {
|
|
185
|
+
return (this.uploadHeader ?
|
|
186
|
+
this.uploadHeader : await this.src.readHeader());
|
|
283
187
|
}
|
|
284
|
-
async
|
|
285
|
-
const
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
await this.uploadWholeVersion(!!uploadInfo.createObj, uploadInfo.version, header, segs);
|
|
294
|
-
uploadInfo.needUpload = undefined;
|
|
295
|
-
await this.recordTaskCompletion(uploadInfo);
|
|
188
|
+
async startOrderedDiffUpload(upload) {
|
|
189
|
+
const diff = buffer_utils_1.utf8.pack(JSON.stringify(upload.diff));
|
|
190
|
+
const maxSegs = this.maxUploadChunk() - upload.header - diff.length;
|
|
191
|
+
(0, assert_1.assert)(maxSegs > 1);
|
|
192
|
+
const header = await this.headerToUpload();
|
|
193
|
+
const ver = this.info.uploadVersion;
|
|
194
|
+
if (upload.newSegsLeft.length === 0) {
|
|
195
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, { ver, last: true }, undefined, { header, diff });
|
|
196
|
+
this.info.needUpload = undefined;
|
|
296
197
|
}
|
|
297
198
|
else {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this.execPools.add(this);
|
|
199
|
+
upload.transactionId = await this.remoteStorage.saveNewObjVersion(this.objId, { ver }, undefined, { header, diff });
|
|
200
|
+
if (!upload.transactionId) {
|
|
201
|
+
// XXX should this be runtime exception saying that remote acts badly ?
|
|
202
|
+
throw new Error(`Server didn't start obj saving transaction`);
|
|
203
|
+
}
|
|
204
|
+
upload.header = undefined;
|
|
305
205
|
}
|
|
306
206
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
};
|
|
311
|
-
if (create) {
|
|
312
|
-
opts.create = true;
|
|
313
|
-
}
|
|
314
|
-
const bytes = (segs ? [header, segs] : [header]);
|
|
315
|
-
await this.remoteStorage.saveNewObjVersion(this.obj.objId, bytes, opts, undefined);
|
|
207
|
+
maxUploadChunk() {
|
|
208
|
+
return (this.remoteStorage.maxChunkSize ?
|
|
209
|
+
this.remoteStorage.maxChunkSize : MAX_CHUNK_SIZE);
|
|
316
210
|
}
|
|
317
|
-
async
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
211
|
+
async continueOrderedUpload(upload) {
|
|
212
|
+
const segsToUpload = Math.min(upload.segsLeft, this.maxUploadChunk());
|
|
213
|
+
await this.src.segSrc.seek(upload.segsOfs);
|
|
214
|
+
const segs = await this.src.segSrc.read(segsToUpload);
|
|
215
|
+
(0, assert_1.assert)(!!segs && (segs.length === segsToUpload));
|
|
216
|
+
const ofs = upload.segsOfs;
|
|
217
|
+
const trans = upload.transactionId;
|
|
218
|
+
if (segsToUpload === upload.segsLeft) {
|
|
219
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, undefined, { ofs, trans, last: true }, { segs });
|
|
220
|
+
this.info.needUpload = undefined;
|
|
323
221
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
222
|
+
else {
|
|
223
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, undefined, { ofs, trans }, { segs });
|
|
224
|
+
upload.segsOfs += segsToUpload;
|
|
225
|
+
upload.segsLeft -= segsToUpload;
|
|
327
226
|
}
|
|
328
|
-
return txnId;
|
|
329
227
|
}
|
|
330
|
-
async
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
await src.segSrc.
|
|
336
|
-
|
|
337
|
-
if (
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
await this.remoteStorage.saveNewObjVersion(this.obj.objId, segs, undefined, opts);
|
|
349
|
-
uploadInfo.needUpload = undefined;
|
|
350
|
-
await this.recordTaskCompletion(uploadInfo);
|
|
228
|
+
async continueOrderedDiffUpload(upload) {
|
|
229
|
+
const maxSegs = this.maxUploadChunk();
|
|
230
|
+
const segInfo = upload.newSegsLeft[0];
|
|
231
|
+
(0, assert_1.assert)(!!segInfo);
|
|
232
|
+
const len = Math.min(maxSegs, segInfo.len);
|
|
233
|
+
const segs = await this.src.segSrc.read(len);
|
|
234
|
+
(0, assert_1.assert)(!!segs && (segs.length === len));
|
|
235
|
+
if (segInfo.len > len) {
|
|
236
|
+
upload.newSegsLeft.splice(1, 0, {
|
|
237
|
+
len: segInfo.len - len,
|
|
238
|
+
thisVerOfs: segInfo.thisVerOfs + len
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
const ofs = segInfo.thisVerOfs;
|
|
242
|
+
const trans = upload.transactionId;
|
|
243
|
+
if (upload.newSegsLeft.length === 1) {
|
|
244
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, undefined, { ofs, trans, last: true }, { segs });
|
|
245
|
+
this.info.needUpload = undefined;
|
|
351
246
|
}
|
|
352
247
|
else {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
trans: uploadInfo.transactionId
|
|
356
|
-
};
|
|
357
|
-
await this.remoteStorage.saveNewObjVersion(this.obj.objId, segs, undefined, opts);
|
|
358
|
-
if (segs.length === section.len) {
|
|
359
|
-
uploadInfo.needUpload.segs.splice(0, 1);
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
section.ofs += segs.length;
|
|
363
|
-
section.len -= segs.length;
|
|
364
|
-
}
|
|
365
|
-
this.execPools.add(this);
|
|
248
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, undefined, { ofs, trans }, { segs });
|
|
249
|
+
upload.newSegsLeft.splice(0, 1);
|
|
366
250
|
}
|
|
367
251
|
}
|
|
252
|
+
cancel() {
|
|
253
|
+
// XXX
|
|
254
|
+
throw new Error("UploadTask.cancel() not implemented.");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
Object.freeze(UploadTask.prototype);
|
|
258
|
+
Object.freeze(UploadTask);
|
|
259
|
+
async function wholeVerUpload(src, uploadHeader, createObj) {
|
|
260
|
+
const header = await expectedHeaderLen(src, uploadHeader);
|
|
261
|
+
const segsSize = (await src.segSrc.getSize()).size;
|
|
262
|
+
return {
|
|
263
|
+
type: 'ordered-whole',
|
|
264
|
+
createObj,
|
|
265
|
+
header,
|
|
266
|
+
segsOfs: 0,
|
|
267
|
+
segsLeft: segsSize
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
async function diffVerUpload(src, uploadHeader, diff, newSegsPackOrder) {
|
|
271
|
+
const header = await expectedHeaderLen(src, uploadHeader);
|
|
272
|
+
return {
|
|
273
|
+
type: 'ordered-diff',
|
|
274
|
+
diff,
|
|
275
|
+
newSegsLeft: newSegsPackOrder,
|
|
276
|
+
header
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
async function expectedHeaderLen(src, uploadHeader) {
|
|
280
|
+
return (uploadHeader ?
|
|
281
|
+
uploadHeader.length : (await src.readHeader()).length);
|
|
282
|
+
}
|
|
283
|
+
function uploadSize(info) {
|
|
284
|
+
if (info.type === 'ordered-whole') {
|
|
285
|
+
return info.header + info.segsLeft;
|
|
286
|
+
}
|
|
287
|
+
else if (info.type === 'ordered-diff') {
|
|
288
|
+
let uploadSize = info.header;
|
|
289
|
+
for (const { len } of info.newSegsLeft) {
|
|
290
|
+
uploadSize += len;
|
|
291
|
+
}
|
|
292
|
+
return uploadSize;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
throw new Error(`Unimplemented upload type ${info.type}`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function executorLabelFor(info) {
|
|
299
|
+
return ((uploadSize(info) <= MAX_FAST_UPLOAD) ? 'fast' : 'long');
|
|
368
300
|
}
|
|
369
|
-
Object.freeze(ObjUpSync.prototype);
|
|
370
|
-
Object.freeze(ObjUpSync);
|
|
371
301
|
function noop() { }
|
|
372
302
|
Object.freeze(exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare type WritableFS = web3n.files.WritableFS;
|
|
2
|
+
export declare class AppDataFolders {
|
|
3
|
+
private readonly fs;
|
|
4
|
+
private writingSync;
|
|
5
|
+
private syncFolderProc;
|
|
6
|
+
private constructor();
|
|
7
|
+
static make(rootFS: WritableFS): Promise<AppDataFolders>;
|
|
8
|
+
getOrMake(folder: string): Promise<WritableFS>;
|
|
9
|
+
private syncP;
|
|
10
|
+
private makeSyncedFolder;
|
|
11
|
+
private syncBeforeChange;
|
|
12
|
+
private uploadAfterCreationOf;
|
|
13
|
+
private startSyncProc;
|
|
14
|
+
stopSync(): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|