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
|
@@ -21,109 +21,201 @@ const path_1 = require("path");
|
|
|
21
21
|
const exceptions_1 = require("../../../lib-client/3nstorage/exceptions");
|
|
22
22
|
const json_saving_1 = require("../common/json-saving");
|
|
23
23
|
const obj_info_file_1 = require("../common/obj-info-file");
|
|
24
|
-
const
|
|
24
|
+
const assert_1 = require("../../../lib-common/assert");
|
|
25
|
+
const file_1 = require("../../../lib-common/exceptions/file");
|
|
26
|
+
function makeVersions() {
|
|
27
|
+
return {
|
|
28
|
+
baseToDiff: {},
|
|
29
|
+
diffToBase: {},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function makeObjStatusInfo(objId) {
|
|
33
|
+
return {
|
|
34
|
+
objId,
|
|
35
|
+
remote: makeVersions()
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function syncStateOf({ local, synced, remote }) {
|
|
39
|
+
const syncedIsCurrent = isSyncedCurrentWithRemote(synced, remote);
|
|
40
|
+
if (local) {
|
|
41
|
+
switch (syncedIsCurrent) {
|
|
42
|
+
case undefined:
|
|
43
|
+
case true:
|
|
44
|
+
return ((local.isArchived && (synced === null || synced === void 0 ? void 0 : synced.isArchived)) ?
|
|
45
|
+
'synced' : 'unsynced');
|
|
46
|
+
case false:
|
|
47
|
+
return 'conflicting';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
switch (syncedIsCurrent) {
|
|
52
|
+
case undefined:
|
|
53
|
+
return 'unsynced';
|
|
54
|
+
case true:
|
|
55
|
+
return 'synced';
|
|
56
|
+
case false:
|
|
57
|
+
return 'behind';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function isSyncedCurrentWithRemote(synced, remote) {
|
|
62
|
+
if (synced) {
|
|
63
|
+
return ((synced.version === remote.current)
|
|
64
|
+
&& (synced.isArchived === remote.isArchived));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return (isRemoteEmpty(remote) ? undefined : false);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function isRemoteEmpty(remote) {
|
|
71
|
+
return (0, obj_info_file_1.isEmptyVersions)(remote) && !remote.isArchived;
|
|
72
|
+
}
|
|
73
|
+
function nonGarbageWithMaxVer(v) {
|
|
74
|
+
return {
|
|
75
|
+
gcMaxVer: v.current,
|
|
76
|
+
nonGarbage: (0, obj_info_file_1.nonGarbageVersionsIn)(v)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function identifyNonGarbage(status) {
|
|
80
|
+
var _a;
|
|
81
|
+
let local = undefined;
|
|
82
|
+
let uploadVersion = undefined;
|
|
83
|
+
if (status.local) {
|
|
84
|
+
local = nonGarbageWithMaxVer(status.local);
|
|
85
|
+
}
|
|
86
|
+
if (status.upload) {
|
|
87
|
+
const { localVersion } = status.upload;
|
|
88
|
+
if (status.local.current !== localVersion) {
|
|
89
|
+
(0, obj_info_file_1.addWithBasesTo)(local.nonGarbage, localVersion, status.local);
|
|
90
|
+
}
|
|
91
|
+
if (status.upload.type === 'new-version') {
|
|
92
|
+
uploadVersion = status.upload.uploadVersion;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const remote = nonGarbageWithMaxVer(status.remote);
|
|
96
|
+
if ((_a = status.synced) === null || _a === void 0 ? void 0 : _a.version) {
|
|
97
|
+
remote.nonGarbage.add(status.synced.version);
|
|
98
|
+
if (status.synced.base) {
|
|
99
|
+
(0, obj_info_file_1.addWithBasesTo)(remote.nonGarbage, status.synced.base, status.remote);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { local, remote, uploadVersion };
|
|
103
|
+
}
|
|
25
104
|
exports.STATUS_FILE_NAME = 'status';
|
|
26
105
|
class ObjStatus {
|
|
27
106
|
constructor(objFolder, status, logError) {
|
|
28
107
|
this.objFolder = objFolder;
|
|
29
108
|
this.status = status;
|
|
30
109
|
this.logError = logError;
|
|
31
|
-
this.saveProc = new json_saving_1.JSONSavingProc(path_1.join(this.objFolder, exports.STATUS_FILE_NAME), () => this.status);
|
|
32
|
-
|
|
110
|
+
this.saveProc = new json_saving_1.JSONSavingProc((0, path_1.join)(this.objFolder, exports.STATUS_FILE_NAME), () => this.status);
|
|
111
|
+
this.updateStateIndicator();
|
|
112
|
+
Object.seal(this);
|
|
33
113
|
}
|
|
34
114
|
static async readFrom(objFolder, objId, logError) {
|
|
35
115
|
const status = await readAndCheckStatus(objFolder, objId);
|
|
36
116
|
return new ObjStatus(objFolder, status, logError);
|
|
37
117
|
}
|
|
38
118
|
static async makeNew(objFolder, objId, logError) {
|
|
39
|
-
const status =
|
|
40
|
-
objId,
|
|
41
|
-
sync: {
|
|
42
|
-
state: 'unsynced'
|
|
43
|
-
},
|
|
44
|
-
versions: {
|
|
45
|
-
baseToDiff: {},
|
|
46
|
-
diffToBase: {},
|
|
47
|
-
}
|
|
48
|
-
};
|
|
119
|
+
const status = makeObjStatusInfo(objId);
|
|
49
120
|
const s = new ObjStatus(objFolder, status, logError);
|
|
50
121
|
await s.triggerSaveProc();
|
|
51
122
|
return s;
|
|
52
123
|
}
|
|
53
124
|
static async makeForDownloadedVersion(objFolder, objId, version, currentRemote, logError) {
|
|
54
|
-
const status =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
baseToDiff: {},
|
|
64
|
-
diffToBase: {}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
125
|
+
const status = makeObjStatusInfo(objId);
|
|
126
|
+
status.remote.current = currentRemote;
|
|
127
|
+
status.synced = { version: currentRemote };
|
|
128
|
+
if (currentRemote > version) {
|
|
129
|
+
status.remote.archived = [version];
|
|
130
|
+
}
|
|
131
|
+
else if (currentRemote !== version) {
|
|
132
|
+
throw new Error(`Downloaded version can't be greater than current remote`);
|
|
133
|
+
}
|
|
67
134
|
const s = new ObjStatus(objFolder, status, logError);
|
|
68
135
|
await s.triggerSaveProc();
|
|
69
136
|
return s;
|
|
70
137
|
}
|
|
71
138
|
static async fileShowsObjNotInSyncedState(objFolder, objId) {
|
|
72
139
|
const status = await readAndCheckStatus(objFolder, objId);
|
|
73
|
-
return (status
|
|
140
|
+
return (syncStateOf(status) !== 'synced');
|
|
74
141
|
}
|
|
75
|
-
|
|
76
|
-
|
|
142
|
+
static async fileShowsObjNeedsRemovalOnRemote(objFolder, objId) {
|
|
143
|
+
const status = await readAndCheckStatus(objFolder, objId);
|
|
144
|
+
const upload = status.upload;
|
|
145
|
+
return (((upload === null || upload === void 0 ? void 0 : upload.type) === 'removal') && !upload.isPostponed);
|
|
77
146
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
return this.status.versions.current;
|
|
147
|
+
needsRemovalOnRemote() {
|
|
148
|
+
const upload = this.status.upload;
|
|
149
|
+
return (((upload === null || upload === void 0 ? void 0 : upload.type) === 'removal') && !upload.isPostponed);
|
|
83
150
|
}
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const tasks = this.status.syncTasks;
|
|
89
|
-
if (tasks.current) {
|
|
90
|
-
obj_info_file_1.addWithBasesTo(nonGarbage, nonGarbageVersionInTask(tasks.current), versions);
|
|
91
|
-
}
|
|
92
|
-
for (const t of tasks.queued) {
|
|
93
|
-
obj_info_file_1.addWithBasesTo(nonGarbage, nonGarbageVersionInTask(t), versions);
|
|
94
|
-
}
|
|
151
|
+
async clearPostponeFlagInRemovalOnRemote() {
|
|
152
|
+
const { upload } = this.status;
|
|
153
|
+
if (!upload) {
|
|
154
|
+
return false;
|
|
95
155
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
156
|
+
if (upload.type !== 'removal') {
|
|
157
|
+
throw new Error(`No upload removal in obj status`);
|
|
158
|
+
}
|
|
159
|
+
upload.isPostponed = false;
|
|
160
|
+
await this.triggerSaveProc();
|
|
161
|
+
return true;
|
|
100
162
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
(this.status.sync.remote >= newRemoteVersion) : false);
|
|
163
|
+
updateStateIndicator() {
|
|
164
|
+
this.stateIndicator = syncStateOf(this.status);
|
|
104
165
|
}
|
|
105
|
-
|
|
106
|
-
|
|
166
|
+
isArchived() {
|
|
167
|
+
var _a;
|
|
168
|
+
return !!((_a = this.status.local) === null || _a === void 0 ? void 0 : _a.isArchived);
|
|
107
169
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
170
|
+
getCurrentLocalOrSynced() {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
const state = this.stateIndicator;
|
|
173
|
+
const current = (((state === 'unsynced') || (state === 'conflicting')) ?
|
|
174
|
+
(_a = this.status.local) === null || _a === void 0 ? void 0 : _a.current : (_b = this.status.synced) === null || _b === void 0 ? void 0 : _b.version);
|
|
175
|
+
if (current) {
|
|
176
|
+
return current;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw (0, exceptions_1.makeStorageException)({
|
|
180
|
+
objNotFound: true,
|
|
181
|
+
message: 'Current version is not found'
|
|
182
|
+
});
|
|
183
|
+
}
|
|
111
184
|
}
|
|
112
|
-
|
|
113
|
-
this.status
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
185
|
+
getNonGarbageVersions() {
|
|
186
|
+
return identifyNonGarbage(this.status);
|
|
187
|
+
}
|
|
188
|
+
async removeCurrentVersion() {
|
|
189
|
+
let { local, synced, remote, upload } = this.status;
|
|
190
|
+
if ((synced === null || synced === void 0 ? void 0 : synced.isArchived) || (local === null || local === void 0 ? void 0 : local.isArchived)) {
|
|
191
|
+
return;
|
|
117
192
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (exc.notFound && this.status.isArchived) {
|
|
193
|
+
if (upload) {
|
|
194
|
+
if (upload.type === 'removal') {
|
|
121
195
|
return;
|
|
122
196
|
}
|
|
123
197
|
else {
|
|
124
|
-
throw
|
|
198
|
+
throw (0, file_1.makeFileException)('concurrentUpdate', 'obj-status', `Upload is in progress`);
|
|
125
199
|
}
|
|
126
|
-
}
|
|
200
|
+
}
|
|
201
|
+
if (!remote.isArchived && remote.current) {
|
|
202
|
+
this.status.upload = {
|
|
203
|
+
type: 'removal',
|
|
204
|
+
localVersion: ((local === null || local === void 0 ? void 0 : local.current) || (synced === null || synced === void 0 ? void 0 : synced.version)),
|
|
205
|
+
isPostponed: true
|
|
206
|
+
};
|
|
207
|
+
upload = this.status.upload;
|
|
208
|
+
}
|
|
209
|
+
if (local) {
|
|
210
|
+
local.isArchived = true;
|
|
211
|
+
local.current = undefined;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
this.status.local = makeVersions();
|
|
215
|
+
this.status.local.isArchived = true;
|
|
216
|
+
}
|
|
217
|
+
this.updateStateIndicator();
|
|
218
|
+
await this.triggerSaveProc().catch(skipNotFoundExc);
|
|
127
219
|
}
|
|
128
220
|
async triggerSaveProc(captureErrors = false, logErr = false) {
|
|
129
221
|
try {
|
|
@@ -140,256 +232,433 @@ class ObjStatus {
|
|
|
140
232
|
}
|
|
141
233
|
}
|
|
142
234
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
235
|
+
recordUploadStart(info) {
|
|
236
|
+
var _a;
|
|
237
|
+
if (this.status.upload) {
|
|
238
|
+
const upload = this.status.upload;
|
|
239
|
+
throw (0, exceptions_1.makeFSSyncException)('obj-status', {
|
|
240
|
+
alreadyUploading: true,
|
|
241
|
+
message: `Status already has upload of version ${upload.uploadVersion} and can't start another upload with version ${info.uploadVersion}`
|
|
242
|
+
});
|
|
150
243
|
}
|
|
151
|
-
this.status.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
this.status.sync.state = 'behind';
|
|
155
|
-
}
|
|
244
|
+
if (info.localVersion === ((_a = this.status.local) === null || _a === void 0 ? void 0 : _a.current)) {
|
|
245
|
+
this.status.upload = info;
|
|
246
|
+
return this.triggerSaveProc();
|
|
156
247
|
}
|
|
157
|
-
else
|
|
158
|
-
|
|
248
|
+
else {
|
|
249
|
+
throw (0, exceptions_1.makeFSSyncException)('obj-status', {
|
|
250
|
+
localVersion: info.localVersion,
|
|
251
|
+
versionNotFound: true
|
|
252
|
+
});
|
|
159
253
|
}
|
|
160
|
-
await this.triggerSaveProc();
|
|
161
254
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
255
|
+
recordUploadInterimState(info) {
|
|
256
|
+
var _a;
|
|
257
|
+
if (((_a = this.status.upload) === null || _a === void 0 ? void 0 : _a.type) !== 'new-version') {
|
|
258
|
+
throw new Error(`No new version upload in object status`);
|
|
259
|
+
}
|
|
260
|
+
if (this.status.upload.uploadVersion === info.uploadVersion) {
|
|
261
|
+
this.status.upload = info;
|
|
262
|
+
return this.triggerSaveProc();
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
throw new Error(`Upload versions don't match`);
|
|
170
266
|
}
|
|
171
267
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.status.
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* This method ignores remote conflicting versions.
|
|
179
|
-
* @param version
|
|
180
|
-
*/
|
|
181
|
-
isVersionSynced(version) {
|
|
182
|
-
if (this.status.versions.current === undefined) {
|
|
183
|
-
return false;
|
|
268
|
+
recordUploadCancellation(info) {
|
|
269
|
+
var _a;
|
|
270
|
+
if (((_a = this.status.upload) === null || _a === void 0 ? void 0 : _a.type) !== 'new-version') {
|
|
271
|
+
throw new Error(`No upload in object status`);
|
|
184
272
|
}
|
|
185
|
-
if (this.status.
|
|
186
|
-
|
|
273
|
+
if (this.status.upload.uploadVersion === info.uploadVersion) {
|
|
274
|
+
this.status.upload = undefined;
|
|
275
|
+
return this.triggerSaveProc();
|
|
187
276
|
}
|
|
188
|
-
|
|
189
|
-
|
|
277
|
+
else {
|
|
278
|
+
throw new Error(`Upload versions don't match`);
|
|
190
279
|
}
|
|
191
|
-
return (this.status.sync.latest >= version);
|
|
192
280
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
281
|
+
recordUploadCompletion(localVersion, uploadVersion) {
|
|
282
|
+
const { local, synced, remote, upload } = this.status;
|
|
283
|
+
if (((upload === null || upload === void 0 ? void 0 : upload.type) !== 'new-version')
|
|
284
|
+
|| (upload.uploadVersion !== uploadVersion)) {
|
|
285
|
+
throw new Error(`Upload versions don't match`);
|
|
196
286
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (t.type === 'upload') {
|
|
201
|
-
this.addUploadToQueue(t);
|
|
287
|
+
const syncedBase = upload.baseVersion;
|
|
288
|
+
if (!remote.current || (remote.current <= uploadVersion)) {
|
|
289
|
+
(0, obj_info_file_1.setCurrentVersionIn)(remote, uploadVersion, syncedBase);
|
|
202
290
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
291
|
+
if (synced) {
|
|
292
|
+
synced.version = uploadVersion;
|
|
293
|
+
if (synced.base && (synced.base !== syncedBase)) {
|
|
294
|
+
(0, obj_info_file_1.rmNonArchVersionsIn)(remote, synced.base);
|
|
206
295
|
}
|
|
207
|
-
|
|
208
|
-
this.addRemoveArchivedToQueue(t.archivedVersions);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else if (t.type === 'archiving') {
|
|
212
|
-
this.addArchivalToQueue(t);
|
|
296
|
+
synced.base = syncedBase;
|
|
213
297
|
}
|
|
214
298
|
else {
|
|
215
|
-
|
|
299
|
+
this.status.synced = { version: uploadVersion, base: syncedBase };
|
|
216
300
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (!this.status.syncTasks) {
|
|
220
|
-
this.status.syncTasks = { queued: [u] };
|
|
301
|
+
if (local.current === localVersion) {
|
|
302
|
+
this.status.local = undefined;
|
|
221
303
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
u.createObj = true;
|
|
230
|
-
}
|
|
231
|
-
q[q.length - 1] = u;
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
q.push(u);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
else if (last.type === 'archiving') {
|
|
238
|
-
q.push(u);
|
|
239
|
-
}
|
|
240
|
-
else if ((last.type === 'removal') && last.archivedVersions) {
|
|
241
|
-
q.push(u);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
q.push(u);
|
|
246
|
-
}
|
|
304
|
+
this.status.upload = undefined;
|
|
305
|
+
this.updateStateIndicator();
|
|
306
|
+
return this.triggerSaveProc();
|
|
307
|
+
}
|
|
308
|
+
async recordArchVersionRemoval(version) {
|
|
309
|
+
if ((0, obj_info_file_1.rmArchVersionFrom)(this.status.remote, version)) {
|
|
310
|
+
return this.triggerSaveProc();
|
|
247
311
|
}
|
|
248
|
-
this.triggerSaveProc(true);
|
|
249
312
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const q = this.status.syncTasks.queued;
|
|
254
|
-
const last = lastIn(q);
|
|
255
|
-
if (last) {
|
|
256
|
-
if (last.type === 'archiving') {
|
|
257
|
-
q.push(r);
|
|
258
|
-
}
|
|
259
|
-
else if (last.type === 'upload') {
|
|
260
|
-
if (this.isVersionArchived(last.version)) {
|
|
261
|
-
q.push(r);
|
|
262
|
-
}
|
|
263
|
-
else if (this.status.sync.latest
|
|
264
|
-
|| this.status.syncTasks.current) {
|
|
265
|
-
q[q.length - 1] = r;
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
q.splice(q.length - 1, 1);
|
|
269
|
-
this.addRemoveCurrentToQueue();
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else if (this.status.sync.latest
|
|
275
|
-
|| this.status.syncTasks.current) {
|
|
276
|
-
q.push(r);
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
this.status.syncTasks = undefined;
|
|
280
|
-
}
|
|
313
|
+
async recordVersionArchival(version) {
|
|
314
|
+
if ((0, obj_info_file_1.addArchived)(this.status.remote, version)) {
|
|
315
|
+
return this.triggerSaveProc();
|
|
281
316
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
317
|
+
}
|
|
318
|
+
async recordRemoteRemoval() {
|
|
319
|
+
const { local, synced, remote } = this.status;
|
|
320
|
+
if ((local === null || local === void 0 ? void 0 : local.isArchived) || (synced === null || synced === void 0 ? void 0 : synced.isArchived)) {
|
|
321
|
+
return;
|
|
286
322
|
}
|
|
323
|
+
remote.isArchived = true;
|
|
324
|
+
(0, obj_info_file_1.rmCurrentVersionIn)(remote);
|
|
325
|
+
this.updateStateIndicator();
|
|
326
|
+
return this.triggerSaveProc();
|
|
287
327
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
328
|
+
async recordRemoteRemovalCompletion() {
|
|
329
|
+
var _a;
|
|
330
|
+
const { remote, upload, synced } = this.status;
|
|
331
|
+
if ((_a = this.status.synced) === null || _a === void 0 ? void 0 : _a.isArchived) {
|
|
332
|
+
return;
|
|
292
333
|
}
|
|
293
|
-
|
|
294
|
-
|
|
334
|
+
if ((upload === null || upload === void 0 ? void 0 : upload.type) !== 'removal') {
|
|
335
|
+
throw new Error(`Upload of removal is not in status`);
|
|
295
336
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
337
|
+
(0, obj_info_file_1.rmCurrentVersionIn)(remote);
|
|
338
|
+
remote.isArchived = true;
|
|
339
|
+
if (synced) {
|
|
340
|
+
synced.isArchived = true;
|
|
341
|
+
synced.version = undefined;
|
|
342
|
+
synced.base = undefined;
|
|
301
343
|
}
|
|
302
344
|
else {
|
|
303
|
-
this.status.
|
|
345
|
+
this.status.synced = { isArchived: true };
|
|
304
346
|
}
|
|
305
|
-
this.
|
|
347
|
+
this.status.local = undefined;
|
|
348
|
+
this.status.upload = undefined;
|
|
349
|
+
this.updateStateIndicator();
|
|
350
|
+
return this.triggerSaveProc();
|
|
306
351
|
}
|
|
307
|
-
async
|
|
308
|
-
const
|
|
309
|
-
if (
|
|
352
|
+
async recordRemoteChange(version) {
|
|
353
|
+
const { synced, remote, upload } = this.status;
|
|
354
|
+
if (((upload === null || upload === void 0 ? void 0 : upload.type) === 'new-version')
|
|
355
|
+
&& (upload.uploadVersion === version)) {
|
|
310
356
|
return;
|
|
311
357
|
}
|
|
312
|
-
if (
|
|
313
|
-
return
|
|
358
|
+
if ((synced === null || synced === void 0 ? void 0 : synced.version) && (synced.version >= version)) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
remote.current = version;
|
|
362
|
+
this.updateStateIndicator();
|
|
363
|
+
return this.triggerSaveProc();
|
|
364
|
+
}
|
|
365
|
+
async recordStatusFromServer({ archived, current }) {
|
|
366
|
+
const remote = this.status.remote;
|
|
367
|
+
let changedCurrent = false;
|
|
368
|
+
if (current) {
|
|
369
|
+
if (!remote.current) {
|
|
370
|
+
remote.current = current;
|
|
371
|
+
changedCurrent = true;
|
|
372
|
+
}
|
|
373
|
+
else if (remote.current < current) {
|
|
374
|
+
(0, obj_info_file_1.rmCurrentVersionIn)(remote);
|
|
375
|
+
remote.current = current;
|
|
376
|
+
changedCurrent = true;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else if (remote.current) {
|
|
380
|
+
(0, obj_info_file_1.rmCurrentVersionIn)(remote);
|
|
381
|
+
remote.isArchived = true;
|
|
382
|
+
changedCurrent = true;
|
|
314
383
|
}
|
|
315
|
-
|
|
316
|
-
|
|
384
|
+
const rmArchived = removeArchVersionsNotInList(remote, archived);
|
|
385
|
+
const addedArchived = addArchVersionsFromList(remote, archived);
|
|
386
|
+
if (rmArchived || addedArchived || changedCurrent) {
|
|
387
|
+
this.updateStateIndicator();
|
|
317
388
|
await this.triggerSaveProc();
|
|
318
389
|
}
|
|
319
|
-
return syncTasks.current;
|
|
320
390
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
391
|
+
/**
|
|
392
|
+
* When given object version is a diff on some base, this method returns
|
|
393
|
+
* a whole trace of local base versions up to synced one.
|
|
394
|
+
* Local bases, if present, are return in an array with highest version
|
|
395
|
+
* first.
|
|
396
|
+
* This returns undefined, when given object version is not a diff.
|
|
397
|
+
* @param version that is local, for which we want to get base versions, if
|
|
398
|
+
* it is a diff version.
|
|
399
|
+
*/
|
|
400
|
+
baseOfLocalVersion(version) {
|
|
401
|
+
(0, assert_1.assert)(!!this.status.local);
|
|
402
|
+
const local = this.status.local;
|
|
403
|
+
(0, assert_1.assert)((0, obj_info_file_1.isVersionIn)(version, local));
|
|
404
|
+
let base = local.diffToBase[version];
|
|
405
|
+
if (!base) {
|
|
324
406
|
return;
|
|
325
407
|
}
|
|
326
|
-
if (
|
|
327
|
-
return
|
|
408
|
+
if ((0, obj_info_file_1.isVersionIn)(base, this.status.remote)) {
|
|
409
|
+
return { syncedBase: base };
|
|
410
|
+
}
|
|
411
|
+
const localBases = [];
|
|
412
|
+
do {
|
|
413
|
+
localBases.push(base);
|
|
414
|
+
base = local.diffToBase[base];
|
|
415
|
+
} while (base);
|
|
416
|
+
const lastBase = localBases[localBases.length - 1];
|
|
417
|
+
if ((0, obj_info_file_1.isVersionIn)(lastBase, this.status.remote)) {
|
|
418
|
+
return {
|
|
419
|
+
localBases: localBases.slice(0, localBases.length - 1),
|
|
420
|
+
syncedBase: lastBase
|
|
421
|
+
};
|
|
328
422
|
}
|
|
329
|
-
else
|
|
330
|
-
return
|
|
423
|
+
else {
|
|
424
|
+
return { localBases };
|
|
331
425
|
}
|
|
332
426
|
}
|
|
333
|
-
async
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
throw new Error(`This method is called too early.`);
|
|
427
|
+
async setLocalCurrentVersion(version, baseVer) {
|
|
428
|
+
if (!this.status.local) {
|
|
429
|
+
this.status.local = makeVersions();
|
|
337
430
|
}
|
|
338
|
-
|
|
339
|
-
|
|
431
|
+
(0, obj_info_file_1.setCurrentVersionIn)(this.status.local, version, baseVer);
|
|
432
|
+
this.updateStateIndicator();
|
|
433
|
+
await this.triggerSaveProc();
|
|
434
|
+
}
|
|
435
|
+
listVersions() {
|
|
436
|
+
var _a;
|
|
437
|
+
const { local, synced, remote } = this.status;
|
|
438
|
+
switch (this.stateIndicator) {
|
|
439
|
+
case 'unsynced':
|
|
440
|
+
case 'conflicting':
|
|
441
|
+
(0, assert_1.assert)(!!local);
|
|
442
|
+
return {
|
|
443
|
+
current: local.current,
|
|
444
|
+
archived: ((synced === null || synced === void 0 ? void 0 : synced.version) ?
|
|
445
|
+
versionsToBranch(remote, synced.version, false).archived :
|
|
446
|
+
undefined)
|
|
447
|
+
};
|
|
448
|
+
case 'synced':
|
|
449
|
+
case 'behind':
|
|
450
|
+
(0, assert_1.assert)(!!synced);
|
|
451
|
+
return {
|
|
452
|
+
current: synced.version,
|
|
453
|
+
archived: ((synced === null || synced === void 0 ? void 0 : synced.version) ?
|
|
454
|
+
versionsToBranch(remote, synced.version, false).archived :
|
|
455
|
+
(_a = remote.archived) === null || _a === void 0 ? void 0 : _a.slice())
|
|
456
|
+
};
|
|
457
|
+
default:
|
|
458
|
+
throw new Error(`Unimplemented state ${this.stateIndicator}`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
async archiveCurrentVersion() {
|
|
462
|
+
const { synced, remote } = this.status;
|
|
463
|
+
(0, assert_1.assert)(!!(synced === null || synced === void 0 ? void 0 : synced.version));
|
|
464
|
+
(0, obj_info_file_1.addArchived)(remote, synced.version);
|
|
465
|
+
await this.triggerSaveProc();
|
|
466
|
+
}
|
|
467
|
+
absorbLocalVersionBase(version, localBase) {
|
|
468
|
+
(0, assert_1.assert)(!!this.status.local);
|
|
469
|
+
const local = this.status.local;
|
|
470
|
+
(0, assert_1.assert)(local.diffToBase[version] === localBase);
|
|
471
|
+
const lowerBase = local.diffToBase[localBase];
|
|
472
|
+
if (localBase) {
|
|
473
|
+
local.diffToBase[version] = lowerBase;
|
|
474
|
+
local.baseToDiff[lowerBase] = version;
|
|
340
475
|
}
|
|
341
476
|
else {
|
|
342
|
-
|
|
477
|
+
delete local.diffToBase[version];
|
|
343
478
|
}
|
|
479
|
+
delete local.diffToBase[localBase];
|
|
480
|
+
delete local.baseToDiff[localBase];
|
|
481
|
+
return this.triggerSaveProc();
|
|
344
482
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
483
|
+
latestSyncedVersion() {
|
|
484
|
+
var _a;
|
|
485
|
+
return (_a = this.status.synced) === null || _a === void 0 ? void 0 : _a.version;
|
|
486
|
+
}
|
|
487
|
+
syncStatus() {
|
|
488
|
+
const { remote, synced } = splitVersionsIntoBranches(this.status.remote, this.status.synced);
|
|
489
|
+
return {
|
|
490
|
+
state: this.stateIndicator,
|
|
491
|
+
local: localVersionFromStatus(this.status.local),
|
|
492
|
+
remote,
|
|
493
|
+
synced
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
neverUploaded() {
|
|
497
|
+
const synced = this.status.synced;
|
|
498
|
+
return (!(synced === null || synced === void 0 ? void 0 : synced.version) && !(synced === null || synced === void 0 ? void 0 : synced.isArchived));
|
|
499
|
+
}
|
|
500
|
+
versionBeforeUnsyncedRemoval() {
|
|
501
|
+
var _a;
|
|
502
|
+
if ((this.stateIndicator !== 'synced')
|
|
503
|
+
&& ((_a = this.status.local) === null || _a === void 0 ? void 0 : _a.isArchived)
|
|
504
|
+
&& this.status.upload
|
|
505
|
+
&& (this.status.upload.type === 'removal')) {
|
|
506
|
+
return this.status.upload.localVersion;
|
|
349
507
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
508
|
+
}
|
|
509
|
+
async adoptRemoteVersion(version, dropLocalVer = false) {
|
|
510
|
+
var _a;
|
|
511
|
+
const { local, remote } = this.status;
|
|
512
|
+
if (this.stateIndicator !== 'behind') {
|
|
513
|
+
if (this.stateIndicator === 'synced') {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
else if (!dropLocalVer) {
|
|
517
|
+
throw (0, exceptions_1.makeFSSyncException)('', {
|
|
518
|
+
localVersion: local === null || local === void 0 ? void 0 : local.current,
|
|
519
|
+
remoteVersion: remote.current,
|
|
520
|
+
conflict: true,
|
|
521
|
+
message: `Can't adopt remote version in '${this.stateIndicator}' state`
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (version) {
|
|
526
|
+
if ((remote.current === version)
|
|
527
|
+
|| ((_a = remote.archived) === null || _a === void 0 ? void 0 : _a.includes(version))) {
|
|
528
|
+
this.status.synced = { version, base: remote.diffToBase[version] };
|
|
353
529
|
}
|
|
354
530
|
else {
|
|
355
|
-
|
|
531
|
+
throw (0, exceptions_1.makeFSSyncException)('', {
|
|
532
|
+
remoteVersion: remote.current,
|
|
533
|
+
versionNotFound: true,
|
|
534
|
+
message: `Remote version ${version} is not in status info`
|
|
535
|
+
});
|
|
356
536
|
}
|
|
357
|
-
await this.triggerSaveProc();
|
|
358
537
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
538
|
+
else if (remote.current) {
|
|
539
|
+
version = remote.current;
|
|
540
|
+
this.status.synced = { version, base: remote.diffToBase[version] };
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
throw (0, exceptions_1.makeFSSyncException)('', {
|
|
544
|
+
versionMismatch: true,
|
|
545
|
+
message: `Current remote version is not set in status info`
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
if (local) {
|
|
549
|
+
this.status.local = undefined;
|
|
550
|
+
}
|
|
551
|
+
this.updateStateIndicator();
|
|
552
|
+
await this.triggerSaveProc();
|
|
368
553
|
}
|
|
369
554
|
}
|
|
370
555
|
exports.ObjStatus = ObjStatus;
|
|
371
556
|
Object.freeze(ObjStatus.prototype);
|
|
372
557
|
Object.freeze(ObjStatus);
|
|
373
558
|
async function readAndCheckStatus(objFolder, objId) {
|
|
374
|
-
const status = await obj_info_file_1.readJSONInfoFileIn(objFolder, exports.STATUS_FILE_NAME);
|
|
559
|
+
const status = await (0, obj_info_file_1.readJSONInfoFileIn)(objFolder, exports.STATUS_FILE_NAME);
|
|
375
560
|
if (!status) {
|
|
376
|
-
throw exceptions_1.makeStorageException({
|
|
561
|
+
throw (0, exceptions_1.makeStorageException)({
|
|
377
562
|
message: `Obj status file is not found in obj folder ${objFolder}`
|
|
378
563
|
});
|
|
379
564
|
}
|
|
380
565
|
// XXX we may do some checks and sanitization here
|
|
381
566
|
if (objId !== status.objId) {
|
|
382
|
-
throw exceptions_1.makeStorageException({
|
|
567
|
+
throw (0, exceptions_1.makeStorageException)({
|
|
568
|
+
message: `Invalid objId in status file for obj ${objId}, in folder ${objFolder}.\nInvalid content:\n${JSON.stringify(status, null, 2)}`
|
|
569
|
+
});
|
|
383
570
|
}
|
|
384
571
|
return status;
|
|
385
572
|
}
|
|
386
573
|
exports.readAndCheckStatus = readAndCheckStatus;
|
|
387
|
-
function
|
|
388
|
-
return (
|
|
574
|
+
function localVersionFromStatus(tagged) {
|
|
575
|
+
return (tagged ? {
|
|
576
|
+
latest: tagged.current,
|
|
577
|
+
isArchived: tagged.isArchived
|
|
578
|
+
} : undefined);
|
|
579
|
+
}
|
|
580
|
+
function splitVersionsIntoBranches(remote, synced) {
|
|
581
|
+
if (synced) {
|
|
582
|
+
if (isSyncedCurrentWithRemote(synced, remote)) {
|
|
583
|
+
return {
|
|
584
|
+
synced: versionsToBranch(remote)
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
(0, assert_1.assert)(!!synced.version);
|
|
589
|
+
return {
|
|
590
|
+
synced: versionsToBranch(remote, synced.version, false),
|
|
591
|
+
remote: versionsToBranch(remote, synced.version, true)
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
return (isRemoteEmpty(remote) ? {} : {
|
|
597
|
+
remote: versionsToBranch(remote)
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function versionsToBranch({ current, archived, isArchived }, splitVersion, aboveSplit) {
|
|
602
|
+
if (splitVersion) {
|
|
603
|
+
let splitArchived = undefined;
|
|
604
|
+
if (archived) {
|
|
605
|
+
const indAboveSplit = archived.findIndex(v => (v > splitVersion));
|
|
606
|
+
if (aboveSplit) {
|
|
607
|
+
if (indAboveSplit >= 0) {
|
|
608
|
+
splitArchived = archived.slice(indAboveSplit);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
if (indAboveSplit > 0) {
|
|
613
|
+
splitArchived = archived.slice(0, indAboveSplit);
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
splitArchived = archived.slice();
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return {
|
|
621
|
+
archived: splitArchived,
|
|
622
|
+
latest: (aboveSplit ? current : splitVersion),
|
|
623
|
+
isArchived: isArchived
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
return {
|
|
628
|
+
archived: archived === null || archived === void 0 ? void 0 : archived.slice(),
|
|
629
|
+
latest: current,
|
|
630
|
+
isArchived: isArchived
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function removeArchVersionsNotInList(remote, versionsToKeep) {
|
|
635
|
+
let isAnythingChanged = false;
|
|
636
|
+
if (remote.archived) {
|
|
637
|
+
for (const v of remote.archived) {
|
|
638
|
+
if (!(versionsToKeep === null || versionsToKeep === void 0 ? void 0 : versionsToKeep.includes(v))) {
|
|
639
|
+
(0, obj_info_file_1.rmArchVersionFrom)(remote, v);
|
|
640
|
+
isAnythingChanged = true;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
return isAnythingChanged;
|
|
645
|
+
}
|
|
646
|
+
function addArchVersionsFromList(remote, existingVersions) {
|
|
647
|
+
var _a;
|
|
648
|
+
if (!existingVersions) {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
let isAnythingChanged = false;
|
|
652
|
+
for (const v of existingVersions) {
|
|
653
|
+
if (!((_a = remote.archived) === null || _a === void 0 ? void 0 : _a.includes(v))) {
|
|
654
|
+
(0, obj_info_file_1.addArchived)(remote, v);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return isAnythingChanged;
|
|
389
658
|
}
|
|
390
|
-
function
|
|
391
|
-
if (
|
|
392
|
-
|
|
659
|
+
function skipNotFoundExc(exc) {
|
|
660
|
+
if (!exc.notFound) {
|
|
661
|
+
throw exc;
|
|
393
662
|
}
|
|
394
663
|
}
|
|
395
664
|
Object.freeze(exports);
|