core-3nweb-client-lib 0.26.1 → 0.27.0
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 +278 -69
- 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.js +5 -1
- 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.js +6 -3
- package/build/core/index.d.ts +2 -1
- package/build/core/index.js +14 -14
- package/build/core/sign-in.js +5 -5
- package/build/core/sign-up.js +9 -9
- 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 +3 -17
- package/build/core/storage/index.js +56 -76
- 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 +9 -6
- 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 +5 -1
- package/build/core/storage/synced/obj-files-gc.js +91 -37
- package/build/core/storage/synced/obj-files.d.ts +42 -36
- package/build/core/storage/synced/obj-files.js +178 -147
- package/build/core/storage/synced/obj-status.d.ts +87 -85
- package/build/core/storage/synced/obj-status.js +463 -259
- 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 +18 -9
- package/build/core/storage/synced/storage.js +108 -48
- 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 +205 -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 +3 -0
- package/build/lib-client/3nstorage/exceptions.js +13 -1
- package/build/lib-client/3nstorage/service.d.ts +16 -2
- package/build/lib-client/3nstorage/service.js +104 -38
- package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
- package/build/lib-client/3nstorage/util/file-based-json.js +1 -1
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +42 -18
- package/build/lib-client/3nstorage/xsp-fs/common.js +29 -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 +24 -11
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +575 -179
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +35 -4
- package/build/lib-client/3nstorage/xsp-fs/fs.js +231 -110
- 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 -24
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +229 -123
- 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.js +7 -7
- 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 +16 -16
- 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.js +4 -0
- 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 +95 -35
- package/build/lib-common/service-api/3nstorage/owner.js +82 -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 +6 -5
- package/protos/file.proto +91 -19
- package/protos/fs.proto +107 -8
|
@@ -17,356 +17,281 @@
|
|
|
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
|
-
|
|
108
|
-
|
|
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
|
+
// }
|
|
59
|
+
}
|
|
60
|
+
async uploadFromDisk(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createOnRemote) {
|
|
61
|
+
const task = await UploadTask.for(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createOnRemote, this.remoteStorage, this.execPools);
|
|
62
|
+
this.execPools.add(task);
|
|
63
|
+
await task.completion();
|
|
109
64
|
}
|
|
110
65
|
}
|
|
111
66
|
exports.UpSyncer = UpSyncer;
|
|
112
67
|
Object.freeze(UpSyncer.prototype);
|
|
113
68
|
Object.freeze(UpSyncer);
|
|
114
|
-
class
|
|
115
|
-
constructor(
|
|
116
|
-
this.obj = obj;
|
|
69
|
+
class UploadTask {
|
|
70
|
+
constructor(remoteStorage, objId, objStatus, src, execPools, info, uploadHeader) {
|
|
117
71
|
this.remoteStorage = remoteStorage;
|
|
72
|
+
this.objId = objId;
|
|
73
|
+
this.objStatus = objStatus;
|
|
74
|
+
this.src = src;
|
|
118
75
|
this.execPools = execPools;
|
|
119
|
-
this.
|
|
120
|
-
this.
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
123
|
-
this.runningProc = undefined;
|
|
76
|
+
this.info = info;
|
|
77
|
+
this.uploadHeader = uploadHeader;
|
|
78
|
+
this.uploadCompletion = (0, deferred_1.defer)();
|
|
79
|
+
this.execLabel = executorLabelFor(this.info.needUpload);
|
|
124
80
|
Object.seal(this);
|
|
125
81
|
}
|
|
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);
|
|
82
|
+
static async for(obj, localVersion, uploadVersion, uploadHeader, syncedBase, createObj, remoteStorage, execPools) {
|
|
83
|
+
const src = await obj.getObjSrcFromLocalAndSyncedBranch(localVersion);
|
|
84
|
+
let needUpload;
|
|
85
|
+
if (syncedBase) {
|
|
86
|
+
const { diff, newSegsPackOrder } = await obj.diffForUploadOf(localVersion);
|
|
87
|
+
needUpload = await diffVerUpload(src, uploadHeader, diff, newSegsPackOrder);
|
|
157
88
|
}
|
|
158
89
|
else {
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async recordTaskCompletion(task) {
|
|
163
|
-
this.taskInProcess = undefined;
|
|
164
|
-
if (task.type === 'upload') {
|
|
165
|
-
await this.obj.markVersionSynced(task.version);
|
|
90
|
+
needUpload = await wholeVerUpload(src, uploadHeader, createObj);
|
|
166
91
|
}
|
|
167
|
-
|
|
168
|
-
|
|
92
|
+
const info = {
|
|
93
|
+
localVersion,
|
|
94
|
+
uploadVersion,
|
|
95
|
+
baseVersion: syncedBase,
|
|
96
|
+
needUpload
|
|
97
|
+
};
|
|
98
|
+
const objStatus = obj.statusObj();
|
|
99
|
+
await objStatus.recordUploadStart(info);
|
|
100
|
+
return new UploadTask(remoteStorage, obj.objId, objStatus, src, execPools, info, uploadHeader);
|
|
169
101
|
}
|
|
170
102
|
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
|
-
});
|
|
103
|
+
return (!this.info.needUpload ? undefined : this.execLabel);
|
|
188
104
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
this.isCancelled = true;
|
|
192
|
-
await ((_a = this.runningProc) === null || _a === void 0 ? void 0 : _a.catch(noop));
|
|
105
|
+
completion() {
|
|
106
|
+
return this.uploadCompletion.promise;
|
|
193
107
|
}
|
|
194
108
|
async process() {
|
|
195
|
-
if (this.
|
|
109
|
+
if (!this.info.needUpload) {
|
|
196
110
|
return;
|
|
197
111
|
}
|
|
198
|
-
let task = undefined;
|
|
199
112
|
try {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
113
|
+
const upload = this.info.needUpload;
|
|
114
|
+
if (upload.type === 'ordered-diff') {
|
|
115
|
+
if (upload.transactionId) {
|
|
116
|
+
await this.continueOrderedDiffUpload(upload);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
await this.startOrderedDiffUpload(upload);
|
|
204
120
|
}
|
|
205
121
|
}
|
|
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);
|
|
122
|
+
else if (upload.type === 'ordered-whole') {
|
|
123
|
+
if (upload.transactionId) {
|
|
124
|
+
await this.continueOrderedUpload(upload);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
await this.startOrderedUpload(upload);
|
|
128
|
+
}
|
|
221
129
|
}
|
|
222
130
|
else {
|
|
223
|
-
throw new Error(`
|
|
224
|
-
}
|
|
225
|
-
try {
|
|
226
|
-
await this.runningProc;
|
|
227
|
-
}
|
|
228
|
-
finally {
|
|
229
|
-
this.runningProc = undefined;
|
|
131
|
+
throw new Error(`Unimplemented ${upload.type} upload`);
|
|
230
132
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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);
|
|
133
|
+
await this.objStatus.recordUploadInterimState(this.info);
|
|
134
|
+
if (this.info.needUpload) {
|
|
135
|
+
this.execPools.add(this);
|
|
245
136
|
}
|
|
246
137
|
else {
|
|
247
|
-
|
|
138
|
+
this.uploadCompletion.resolve();
|
|
248
139
|
}
|
|
249
140
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
141
|
+
catch (exc) {
|
|
142
|
+
this.info.needUpload = undefined;
|
|
143
|
+
this.uploadCompletion.reject((0, exceptions_1.makeFSSyncException)(`obj-upload`, {
|
|
144
|
+
message: `Fail to upload local version ${this.info.uploadVersion}`,
|
|
145
|
+
localVersion: this.info.uploadVersion,
|
|
146
|
+
cause: exc
|
|
147
|
+
}));
|
|
148
|
+
await this.objStatus.recordUploadCancellation(this.info);
|
|
253
149
|
}
|
|
254
|
-
await this.recordTaskCompletion(task);
|
|
255
|
-
this.obj.scheduleSelfGC();
|
|
256
150
|
}
|
|
257
|
-
async
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
151
|
+
async startOrderedUpload(upload) {
|
|
152
|
+
const maxSegs = this.maxUploadChunk() - upload.header;
|
|
153
|
+
(0, assert_1.assert)(maxSegs > 1);
|
|
154
|
+
const segsToUpload = Math.min(upload.segsLeft, maxSegs);
|
|
155
|
+
const header = await this.headerToUpload();
|
|
156
|
+
let segs = undefined;
|
|
157
|
+
if (segsToUpload > 0) {
|
|
158
|
+
await this.src.segSrc.seek(upload.segsOfs);
|
|
159
|
+
segs = await this.src.segSrc.read(segsToUpload);
|
|
160
|
+
}
|
|
161
|
+
(0, assert_1.assert)(!!segs && (segs.length === segsToUpload));
|
|
162
|
+
const ver = this.info.uploadVersion;
|
|
163
|
+
const create = (upload.createObj ? true : undefined);
|
|
164
|
+
if (segsToUpload === upload.segsLeft) {
|
|
165
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, { ver, create, last: true }, undefined, { header, segs });
|
|
166
|
+
this.info.needUpload = undefined;
|
|
267
167
|
}
|
|
268
168
|
else {
|
|
269
|
-
await this.
|
|
169
|
+
upload.transactionId = await this.remoteStorage.saveNewObjVersion(this.objId, { ver, create }, undefined, { header, segs });
|
|
170
|
+
if (!upload.transactionId) {
|
|
171
|
+
// XXX should this be runtime exception saying that remote acts badly ?
|
|
172
|
+
throw new Error(`Server didn't start obj saving transaction`);
|
|
173
|
+
}
|
|
174
|
+
upload.header = undefined;
|
|
175
|
+
upload.segsOfs += segsToUpload;
|
|
176
|
+
upload.segsLeft -= segsToUpload;
|
|
270
177
|
}
|
|
271
178
|
}
|
|
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
|
-
});
|
|
179
|
+
async headerToUpload() {
|
|
180
|
+
return (this.uploadHeader ?
|
|
181
|
+
this.uploadHeader : await this.src.readHeader());
|
|
283
182
|
}
|
|
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);
|
|
183
|
+
async startOrderedDiffUpload(upload) {
|
|
184
|
+
const diff = buffer_utils_1.utf8.pack(JSON.stringify(upload.diff));
|
|
185
|
+
const maxSegs = this.maxUploadChunk() - upload.header - diff.length;
|
|
186
|
+
(0, assert_1.assert)(maxSegs > 1);
|
|
187
|
+
const header = await this.headerToUpload();
|
|
188
|
+
const ver = this.info.uploadVersion;
|
|
189
|
+
if (upload.newSegsLeft.length === 0) {
|
|
190
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, { ver, last: true }, undefined, { header, diff });
|
|
191
|
+
this.info.needUpload = undefined;
|
|
296
192
|
}
|
|
297
193
|
else {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this.execPools.add(this);
|
|
194
|
+
upload.transactionId = await this.remoteStorage.saveNewObjVersion(this.objId, { ver }, undefined, { header, diff });
|
|
195
|
+
if (!upload.transactionId) {
|
|
196
|
+
// XXX should this be runtime exception saying that remote acts badly ?
|
|
197
|
+
throw new Error(`Server didn't start obj saving transaction`);
|
|
198
|
+
}
|
|
199
|
+
upload.header = undefined;
|
|
305
200
|
}
|
|
306
201
|
}
|
|
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);
|
|
202
|
+
maxUploadChunk() {
|
|
203
|
+
return (this.remoteStorage.maxChunkSize ?
|
|
204
|
+
this.remoteStorage.maxChunkSize : MAX_CHUNK_SIZE);
|
|
316
205
|
}
|
|
317
|
-
async
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
206
|
+
async continueOrderedUpload(upload) {
|
|
207
|
+
const segsToUpload = Math.min(upload.segsLeft, this.maxUploadChunk());
|
|
208
|
+
await this.src.segSrc.seek(upload.segsOfs);
|
|
209
|
+
const segs = await this.src.segSrc.read(segsToUpload);
|
|
210
|
+
(0, assert_1.assert)(!!segs && (segs.length === segsToUpload));
|
|
211
|
+
const ofs = upload.segsOfs;
|
|
212
|
+
const trans = upload.transactionId;
|
|
213
|
+
if (segsToUpload === upload.segsLeft) {
|
|
214
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, undefined, { ofs, trans, last: true }, { segs });
|
|
215
|
+
this.info.needUpload = undefined;
|
|
323
216
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
217
|
+
else {
|
|
218
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, undefined, { ofs, trans }, { segs });
|
|
219
|
+
upload.segsOfs += segsToUpload;
|
|
220
|
+
upload.segsLeft -= segsToUpload;
|
|
327
221
|
}
|
|
328
|
-
return txnId;
|
|
329
222
|
}
|
|
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);
|
|
223
|
+
async continueOrderedDiffUpload(upload) {
|
|
224
|
+
const maxSegs = this.maxUploadChunk();
|
|
225
|
+
const segInfo = upload.newSegsLeft[0];
|
|
226
|
+
(0, assert_1.assert)(!!segInfo);
|
|
227
|
+
const len = Math.min(maxSegs, segInfo.len);
|
|
228
|
+
const segs = await this.src.segSrc.read(len);
|
|
229
|
+
(0, assert_1.assert)(!!segs && (segs.length === len));
|
|
230
|
+
if (segInfo.len > len) {
|
|
231
|
+
upload.newSegsLeft.splice(1, 0, {
|
|
232
|
+
len: segInfo.len - len,
|
|
233
|
+
thisVerOfs: segInfo.thisVerOfs + len
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const ofs = segInfo.thisVerOfs;
|
|
237
|
+
const trans = upload.transactionId;
|
|
238
|
+
if (upload.newSegsLeft.length === 1) {
|
|
239
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, undefined, { ofs, trans, last: true }, { segs });
|
|
240
|
+
this.info.needUpload = undefined;
|
|
351
241
|
}
|
|
352
242
|
else {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
243
|
+
await this.remoteStorage.saveNewObjVersion(this.objId, undefined, { ofs, trans }, { segs });
|
|
244
|
+
upload.newSegsLeft.splice(0, 1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
cancel() {
|
|
248
|
+
// XXX
|
|
249
|
+
throw new Error("UploadTask.cancel() not implemented.");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
Object.freeze(UploadTask.prototype);
|
|
253
|
+
Object.freeze(UploadTask);
|
|
254
|
+
async function wholeVerUpload(src, uploadHeader, createObj) {
|
|
255
|
+
const header = await expectedHeaderLen(src, uploadHeader);
|
|
256
|
+
const segsSize = (await src.segSrc.getSize()).size;
|
|
257
|
+
return {
|
|
258
|
+
type: 'ordered-whole',
|
|
259
|
+
createObj,
|
|
260
|
+
header,
|
|
261
|
+
segsOfs: 0,
|
|
262
|
+
segsLeft: segsSize
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
async function diffVerUpload(src, uploadHeader, diff, newSegsPackOrder) {
|
|
266
|
+
const header = await expectedHeaderLen(src, uploadHeader);
|
|
267
|
+
return {
|
|
268
|
+
type: 'ordered-diff',
|
|
269
|
+
diff,
|
|
270
|
+
newSegsLeft: newSegsPackOrder,
|
|
271
|
+
header
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async function expectedHeaderLen(src, uploadHeader) {
|
|
275
|
+
return (uploadHeader ?
|
|
276
|
+
uploadHeader.length : (await src.readHeader()).length);
|
|
277
|
+
}
|
|
278
|
+
function uploadSize(info) {
|
|
279
|
+
if (info.type === 'ordered-whole') {
|
|
280
|
+
return info.header + info.segsLeft;
|
|
281
|
+
}
|
|
282
|
+
else if (info.type === 'ordered-diff') {
|
|
283
|
+
let uploadSize = info.header;
|
|
284
|
+
for (const { len } of info.newSegsLeft) {
|
|
285
|
+
uploadSize += len;
|
|
366
286
|
}
|
|
287
|
+
return uploadSize;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
throw new Error(`Unimplemented upload type ${info.type}`);
|
|
367
291
|
}
|
|
368
292
|
}
|
|
369
|
-
|
|
370
|
-
|
|
293
|
+
function executorLabelFor(info) {
|
|
294
|
+
return ((uploadSize(info) <= MAX_FAST_UPLOAD) ? 'fast' : 'long');
|
|
295
|
+
}
|
|
371
296
|
function noop() { }
|
|
372
297
|
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 {};
|