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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2017, 2019 -
|
|
3
|
+
Copyright (C) 2015 - 2017, 2019 - 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -16,17 +16,18 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.PerAppStorage = exports.reverseDomain = exports.
|
|
19
|
+
exports.PerAppStorage = exports.reverseDomain = exports.Storages = void 0;
|
|
20
20
|
const fs_1 = require("../../lib-client/3nstorage/xsp-fs/fs");
|
|
21
21
|
const storage_1 = require("./synced/storage");
|
|
22
22
|
const storage_2 = require("./local/storage");
|
|
23
23
|
const file_1 = require("../../lib-common/exceptions/file");
|
|
24
24
|
const fs_collection_1 = require("../../lib-client/fs-collection");
|
|
25
25
|
const async_iter_1 = require("../../lib-common/async-iter");
|
|
26
|
-
const device_fs_1 = require("../../lib-client/local-files/device-fs");
|
|
27
26
|
const path_1 = require("path");
|
|
28
27
|
const fs = require("../../lib-common/async-fs-node");
|
|
29
28
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
29
|
+
const system_folders_1 = require("./system-folders");
|
|
30
|
+
const apps_data_1 = require("./system-folders/apps-data");
|
|
30
31
|
function makeBadAppNameExc(appName) {
|
|
31
32
|
return {
|
|
32
33
|
runtimeException: true,
|
|
@@ -74,58 +75,39 @@ const SYNCED_STORAGE_DIR = 'synced';
|
|
|
74
75
|
*/
|
|
75
76
|
async function readRootKeyDerivParamsFromCache(folder) {
|
|
76
77
|
try {
|
|
77
|
-
const str = await fs.readFile(path_1.join(folder, KD_PARAMS_FILE_NAME), { encoding: 'utf8' });
|
|
78
|
+
const str = await fs.readFile((0, path_1.join)(folder, KD_PARAMS_FILE_NAME), { encoding: 'utf8' });
|
|
78
79
|
return JSON.parse(str);
|
|
79
80
|
}
|
|
80
81
|
catch (err) {
|
|
81
82
|
if (err.notFound) {
|
|
82
83
|
return undefined;
|
|
83
84
|
}
|
|
84
|
-
throw error_1.errWithCause(err, `Can't read and parse content of obj status file ${KD_PARAMS_FILE_NAME} in folder ${folder}`);
|
|
85
|
+
throw (0, error_1.errWithCause)(err, `Can't read and parse content of obj status file ${KD_PARAMS_FILE_NAME} in folder ${folder}`);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* @param fs
|
|
91
|
-
* @param getFromServer
|
|
92
|
-
*/
|
|
93
|
-
async function getRootKeyDerivParams(folder, getFromServer) {
|
|
94
|
-
let params = await readRootKeyDerivParamsFromCache(folder);
|
|
95
|
-
if (!params) {
|
|
96
|
-
params = await getFromServer();
|
|
97
|
-
await fs.writeFile(path_1.join(folder, KD_PARAMS_FILE_NAME), JSON.stringify(params), { encoding: 'utf8' });
|
|
98
|
-
}
|
|
88
|
+
async function getAndCacheRootKeyDerivParamsFromServer(folder, getFromServer) {
|
|
89
|
+
const params = await getFromServer();
|
|
90
|
+
await saveRootKeyDerivParamsToDisk(folder, params);
|
|
99
91
|
return params;
|
|
100
92
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
apps: 'Apps Code',
|
|
104
|
-
packages: 'App&Lib Packs',
|
|
105
|
-
sharedLibs: 'Shared Libs',
|
|
106
|
-
userFiles: 'User Files'
|
|
107
|
-
};
|
|
108
|
-
Object.freeze(exports.sysFolders);
|
|
109
|
-
/**
|
|
110
|
-
* This function creates initial folder structure in a given root.
|
|
111
|
-
* @param root
|
|
112
|
-
*/
|
|
113
|
-
async function initSysFolders(root) {
|
|
114
|
-
for (const sysFolder of Object.values(exports.sysFolders)) {
|
|
115
|
-
await root.makeFolder(sysFolder);
|
|
116
|
-
}
|
|
93
|
+
async function saveRootKeyDerivParamsToDisk(folder, params) {
|
|
94
|
+
await fs.writeFile((0, path_1.join)(folder, KD_PARAMS_FILE_NAME), JSON.stringify(params), { encoding: 'utf8' });
|
|
117
95
|
}
|
|
118
|
-
exports.initSysFolders = initSysFolders;
|
|
119
96
|
class StorageAndFS {
|
|
120
97
|
constructor(storage) {
|
|
121
98
|
this.storage = storage;
|
|
122
99
|
this.rootFS = undefined;
|
|
100
|
+
this.syncedAppDataRoots = undefined;
|
|
123
101
|
Object.seal(this);
|
|
124
102
|
}
|
|
125
103
|
static async existing(storage, key) {
|
|
104
|
+
var _a;
|
|
126
105
|
const s = new StorageAndFS(storage);
|
|
127
106
|
try {
|
|
128
107
|
s.rootFS = await fs_1.XspFS.fromExistingRoot(s.storage, key);
|
|
108
|
+
if ((_a = s.rootFS.v) === null || _a === void 0 ? void 0 : _a.sync) {
|
|
109
|
+
s.syncedAppDataRoots = await apps_data_1.AppDataFolders.make(s.rootFS);
|
|
110
|
+
}
|
|
129
111
|
return s;
|
|
130
112
|
}
|
|
131
113
|
catch (err) {
|
|
@@ -137,47 +119,45 @@ class StorageAndFS {
|
|
|
137
119
|
}
|
|
138
120
|
}
|
|
139
121
|
}
|
|
140
|
-
static async
|
|
122
|
+
static async makeNew(storage, key) {
|
|
123
|
+
var _a;
|
|
141
124
|
const s = new StorageAndFS(storage);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
catch (err) {
|
|
147
|
-
if (err.objNotFound) {
|
|
148
|
-
s.rootFS = await fs_1.XspFS.makeNewRoot(s.storage, key);
|
|
149
|
-
await initSysFolders(s.rootFS);
|
|
150
|
-
return s;
|
|
151
|
-
}
|
|
152
|
-
else if (err.failedCipherVerification) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
throw err;
|
|
157
|
-
}
|
|
125
|
+
s.rootFS = await fs_1.XspFS.makeNewRoot(s.storage, key);
|
|
126
|
+
await (0, system_folders_1.initSysFolders)(s.rootFS);
|
|
127
|
+
if ((_a = s.rootFS.v) === null || _a === void 0 ? void 0 : _a.sync) {
|
|
128
|
+
s.syncedAppDataRoots = await apps_data_1.AppDataFolders.make(s.rootFS);
|
|
158
129
|
}
|
|
130
|
+
return s;
|
|
159
131
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
132
|
+
/**
|
|
133
|
+
* This creates app data folder.
|
|
134
|
+
* Folder objects are uploaded, if this is a synced storage.
|
|
135
|
+
* @param appFolder
|
|
136
|
+
*/
|
|
137
|
+
async makeAppFS(appFolder) {
|
|
138
|
+
if (('string' !== typeof appFolder) || (appFolder.length === 0)
|
|
139
|
+
|| (appFolder.indexOf('/') >= 0)
|
|
140
|
+
|| (appFolder === '.') || (appFolder === '..')) {
|
|
164
141
|
throw makeBadAppNameExc(appFolder);
|
|
165
142
|
}
|
|
166
143
|
if (!this.rootFS) {
|
|
167
144
|
throw new Error('Storage is not initialized.');
|
|
168
145
|
}
|
|
169
|
-
|
|
146
|
+
const appDataFS = await (this.syncedAppDataRoots ?
|
|
147
|
+
this.syncedAppDataRoots.getOrMake(appFolder) :
|
|
148
|
+
this.rootFS.writableSubRoot(`${system_folders_1.sysFolders.appData}/${appFolder}`));
|
|
149
|
+
return appDataFS;
|
|
170
150
|
}
|
|
171
151
|
userFS() {
|
|
172
|
-
return this.rootFS.writableSubRoot(
|
|
152
|
+
return this.rootFS.writableSubRoot(system_folders_1.sysFolders.userFiles);
|
|
173
153
|
}
|
|
174
154
|
async sysFSs() {
|
|
175
155
|
const folders = [
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
156
|
+
system_folders_1.sysFolders.appData, system_folders_1.sysFolders.apps,
|
|
157
|
+
system_folders_1.sysFolders.packages,
|
|
158
|
+
system_folders_1.sysFolders.sharedLibs
|
|
179
159
|
];
|
|
180
|
-
const c = fs_collection_1.makeFSCollection();
|
|
160
|
+
const c = (0, fs_collection_1.makeFSCollection)();
|
|
181
161
|
for (let fsName of folders) {
|
|
182
162
|
await c.set(fsName, {
|
|
183
163
|
isFolder: true,
|
|
@@ -187,15 +167,20 @@ class StorageAndFS {
|
|
|
187
167
|
return c;
|
|
188
168
|
}
|
|
189
169
|
async close() {
|
|
170
|
+
var _a;
|
|
190
171
|
if (!this.rootFS) {
|
|
191
172
|
return;
|
|
192
173
|
}
|
|
174
|
+
(_a = this.syncedAppDataRoots) === null || _a === void 0 ? void 0 : _a.stopSync();
|
|
193
175
|
await this.rootFS.close();
|
|
194
176
|
await this.storage.close();
|
|
177
|
+
this.syncedAppDataRoots = undefined;
|
|
195
178
|
this.rootFS = undefined;
|
|
196
179
|
this.storage = undefined;
|
|
197
180
|
}
|
|
198
181
|
}
|
|
182
|
+
Object.freeze(StorageAndFS.prototype);
|
|
183
|
+
Object.freeze(StorageAndFS);
|
|
199
184
|
class Storages {
|
|
200
185
|
constructor(cryptor, storageDirForUser) {
|
|
201
186
|
this.cryptor = cryptor;
|
|
@@ -266,34 +251,36 @@ class Storages {
|
|
|
266
251
|
return;
|
|
267
252
|
}
|
|
268
253
|
const key = await keyGen(params);
|
|
269
|
-
this.local = await StorageAndFS.existing(await storage_2.LocalStorage.makeAndStart(path_1.join(storageDir, LOCAL_STORAGE_DIR), this.storageGetterForLocalStorage, this.cryptor, logError), key);
|
|
254
|
+
this.local = await StorageAndFS.existing(await storage_2.LocalStorage.makeAndStart((0, path_1.join)(storageDir, LOCAL_STORAGE_DIR), this.storageGetterForLocalStorage, this.cryptor, logError), key);
|
|
270
255
|
if (!this.local) {
|
|
271
256
|
return;
|
|
272
257
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
258
|
+
const { syncedStore, setupRemoteAndStartObjProcs } = await storage_1.SyncedStore.makeAndStartWithoutRemote((0, path_1.join)(storageDir, SYNCED_STORAGE_DIR), user, this.storageGetterForSyncedStorage, this.cryptor, () => resolver(user), makeNet(), logError);
|
|
259
|
+
this.synced = await StorageAndFS.existing(syncedStore, key);
|
|
260
|
+
key.fill(0);
|
|
261
|
+
if (!this.synced) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
return setupRemoteAndStartObjProcs;
|
|
265
|
+
}
|
|
266
|
+
async initFromRemote(user, getSigner, generateKey, makeNet, resolver, logError) {
|
|
267
|
+
const storageDir = this.storageDirForUser(user);
|
|
268
|
+
const { startObjProcs, syncedStore } = await storage_1.SyncedStore.makeAndStart((0, path_1.join)(storageDir, SYNCED_STORAGE_DIR), user, getSigner, this.storageGetterForSyncedStorage, this.cryptor, () => resolver(user), makeNet(), logError);
|
|
269
|
+
const params = await getAndCacheRootKeyDerivParamsFromServer(storageDir, syncedStore.getRootKeyDerivParamsFromServer);
|
|
270
|
+
const key = await generateKey(params);
|
|
271
|
+
this.synced = await StorageAndFS.existing(syncedStore, key);
|
|
272
|
+
this.local = await StorageAndFS.makeNew(await storage_2.LocalStorage.makeAndStart((0, path_1.join)(storageDir, LOCAL_STORAGE_DIR), this.storageGetterForLocalStorage, this.cryptor, logError), key);
|
|
273
|
+
key.fill(0);
|
|
274
|
+
startObjProcs();
|
|
275
|
+
return (!!this.synced && !!this.local);
|
|
286
276
|
}
|
|
287
|
-
async
|
|
277
|
+
async initFreshForNewUser(user, getSigner, params, key, makeNet, resolver, logError) {
|
|
288
278
|
const storageDir = this.storageDirForUser(user);
|
|
289
|
-
const { startObjProcs, syncedStore } = await storage_1.SyncedStore.makeAndStart(path_1.join(storageDir, SYNCED_STORAGE_DIR), user, getSigner, this.storageGetterForSyncedStorage, this.cryptor, () => resolver(user), makeNet, logError);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const key = ((typeof keyOrGen === 'function') ?
|
|
293
|
-
await keyOrGen(params) : keyOrGen);
|
|
294
|
-
this.synced = await StorageAndFS.newOrExisting(syncedStore, key);
|
|
295
|
-
this.local = await StorageAndFS.newOrExisting(await storage_2.LocalStorage.makeAndStart(path_1.join(storageDir, LOCAL_STORAGE_DIR), this.storageGetterForLocalStorage, this.cryptor, logError), key);
|
|
279
|
+
const { startObjProcs, syncedStore } = await storage_1.SyncedStore.makeAndStart((0, path_1.join)(storageDir, SYNCED_STORAGE_DIR), user, getSigner, this.storageGetterForSyncedStorage, this.cryptor, () => resolver(user), makeNet(), logError);
|
|
280
|
+
this.synced = await StorageAndFS.makeNew(syncedStore, key);
|
|
281
|
+
this.local = await StorageAndFS.makeNew(await storage_2.LocalStorage.makeAndStart((0, path_1.join)(storageDir, LOCAL_STORAGE_DIR), this.storageGetterForLocalStorage, this.cryptor, logError), key);
|
|
296
282
|
key.fill(0);
|
|
283
|
+
await saveRootKeyDerivParamsToDisk(storageDir, params);
|
|
297
284
|
startObjProcs();
|
|
298
285
|
return (!!this.synced && !!this.local);
|
|
299
286
|
}
|
|
@@ -316,7 +303,7 @@ class Storages {
|
|
|
316
303
|
fs = await this.local.userFS();
|
|
317
304
|
}
|
|
318
305
|
else if (type === 'device') {
|
|
319
|
-
fs = await userFilesOnDevice();
|
|
306
|
+
fs = await (0, system_folders_1.userFilesOnDevice)();
|
|
320
307
|
}
|
|
321
308
|
else {
|
|
322
309
|
throw new Error(`Unknown storage type ${type}`);
|
|
@@ -342,7 +329,7 @@ class Storages {
|
|
|
342
329
|
};
|
|
343
330
|
}
|
|
344
331
|
else if (type === 'device') {
|
|
345
|
-
return sysFilesOnDevice();
|
|
332
|
+
return (0, system_folders_1.sysFilesOnDevice)();
|
|
346
333
|
}
|
|
347
334
|
else {
|
|
348
335
|
throw new Error(`Unknown storage type ${type}`);
|
|
@@ -372,33 +359,6 @@ class Storages {
|
|
|
372
359
|
exports.Storages = Storages;
|
|
373
360
|
Object.freeze(Storages.prototype);
|
|
374
361
|
Object.freeze(Storages);
|
|
375
|
-
async function userFilesOnDevice() {
|
|
376
|
-
if (process.platform === 'win32') {
|
|
377
|
-
return device_fs_1.DeviceFS.makeWritable(process.env.USERPROFILE);
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
return device_fs_1.DeviceFS.makeWritable(process.env.HOME);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
exports.userFilesOnDevice = userFilesOnDevice;
|
|
384
|
-
async function sysFilesOnDevice() {
|
|
385
|
-
const c = fs_collection_1.makeFSCollection();
|
|
386
|
-
if (process.platform === 'win32') {
|
|
387
|
-
const sysDrive = process.env.SystemDrive;
|
|
388
|
-
await c.set(sysDrive, {
|
|
389
|
-
isFolder: true,
|
|
390
|
-
item: await device_fs_1.DeviceFS.makeWritable(sysDrive)
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
await c.set('', {
|
|
395
|
-
isFolder: true,
|
|
396
|
-
item: await device_fs_1.DeviceFS.makeWritable('/')
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
return { isCollection: true, item: c };
|
|
400
|
-
}
|
|
401
|
-
exports.sysFilesOnDevice = sysFilesOnDevice;
|
|
402
362
|
function reverseDomain(domain) {
|
|
403
363
|
return domain.split('.').reverse().join('.');
|
|
404
364
|
}
|
|
@@ -456,8 +416,7 @@ class PerAppStorage {
|
|
|
456
416
|
if (typeof appFolder !== 'string') {
|
|
457
417
|
throw makeBadAppNameExc(appFolder);
|
|
458
418
|
}
|
|
459
|
-
if (CORE_APPS_PREFIX
|
|
460
|
-
appFolder.substring(0, CORE_APPS_PREFIX.length)) {
|
|
419
|
+
if (appFolder.startsWith(CORE_APPS_PREFIX)) {
|
|
461
420
|
throw makeNotAllowedToOpenAppFSExc(appFolder);
|
|
462
421
|
}
|
|
463
422
|
if (!this.policy.canOpenAppFS(appFolder, type)) {
|
|
@@ -523,10 +482,10 @@ async function applyPolicyToFS(fs, policy, path) {
|
|
|
523
482
|
async function applyPolicyToFSCollection(c, policy, path) {
|
|
524
483
|
if (path === undefined) {
|
|
525
484
|
if (policy === 'w') {
|
|
526
|
-
return fs_collection_1.readonlyWrapFSCollection(c);
|
|
485
|
+
return (0, fs_collection_1.readonlyWrapFSCollection)(c);
|
|
527
486
|
}
|
|
528
487
|
else {
|
|
529
|
-
const roFSs = fs_collection_1.makeFSCollection();
|
|
488
|
+
const roFSs = (0, fs_collection_1.makeFSCollection)();
|
|
530
489
|
for (const v of (await c.getAll())) {
|
|
531
490
|
const fs = v[1].item;
|
|
532
491
|
if (!v[1].isFolder || !fs || !fs.listFolder) {
|
|
@@ -535,15 +494,15 @@ async function applyPolicyToFSCollection(c, policy, path) {
|
|
|
535
494
|
v[1].item = await v[1].item.readonlySubRoot('/');
|
|
536
495
|
await roFSs.set(v[0], v[1]);
|
|
537
496
|
}
|
|
538
|
-
return fs_collection_1.readonlyWrapFSCollection(roFSs);
|
|
497
|
+
return (0, fs_collection_1.readonlyWrapFSCollection)(roFSs);
|
|
539
498
|
}
|
|
540
499
|
}
|
|
541
500
|
if (path.startsWith('/')) {
|
|
542
501
|
path = path.substring(1);
|
|
543
502
|
}
|
|
544
|
-
const nameAndItem = await async_iter_1.asyncFind(await c.entries(), async (v) => path.startsWith(v[0]));
|
|
503
|
+
const nameAndItem = await (0, async_iter_1.asyncFind)(await c.entries(), async (v) => path.startsWith(v[0]));
|
|
545
504
|
if (!nameAndItem) {
|
|
546
|
-
throw file_1.makeFileException(
|
|
505
|
+
throw (0, file_1.makeFileException)('notFound', path);
|
|
547
506
|
}
|
|
548
507
|
const [name, item] = nameAndItem;
|
|
549
508
|
path = path.substring(name.length);
|
|
@@ -19,4 +19,6 @@ export declare class GC {
|
|
|
19
19
|
constructor(rmObjFromCache: (obj: LocalObj) => void, rmObjFolder: (objId: string) => Promise<void>);
|
|
20
20
|
scheduleCollection: (obj: LocalObj) => void;
|
|
21
21
|
private objCollecting;
|
|
22
|
+
private collectIn;
|
|
23
|
+
private checkAndRemoveWholeObjFolder;
|
|
22
24
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2016 - 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -20,6 +20,7 @@ exports.GC = void 0;
|
|
|
20
20
|
const fs = require("../../../lib-common/async-fs-node");
|
|
21
21
|
const synced_1 = require("../../../lib-common/processes/synced");
|
|
22
22
|
const path_1 = require("path");
|
|
23
|
+
const utils_1 = require("../common/utils");
|
|
23
24
|
class GC {
|
|
24
25
|
constructor(rmObjFromCache, rmObjFolder) {
|
|
25
26
|
this.rmObjFromCache = rmObjFromCache;
|
|
@@ -49,54 +50,65 @@ class GC {
|
|
|
49
50
|
if (this.wip.size === 0) {
|
|
50
51
|
[this.wip, this.scheduled] = [this.scheduled, this.wip];
|
|
51
52
|
}
|
|
52
|
-
const obj = getAndRemoveOneFrom(this.wip);
|
|
53
|
+
const obj = (0, utils_1.getAndRemoveOneFrom)(this.wip);
|
|
53
54
|
if (!obj) {
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// if object is set archived, and there is nothing in it worth keeping,
|
|
59
|
-
// whole folder can be removed
|
|
60
|
-
if (obj.isArchived()) {
|
|
61
|
-
if (nonGarbage.size === 0) {
|
|
62
|
-
this.rmObjFromCache(obj);
|
|
63
|
-
if (obj.objId) {
|
|
64
|
-
await this.rmObjFolder(obj.objId);
|
|
65
|
-
}
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// for all other cases, we remove version files that are not worth
|
|
70
|
-
// keeping.
|
|
71
|
-
const lst = await fs.readdir(obj.objFolder);
|
|
72
|
-
const rmProcs = [];
|
|
73
|
-
for (const f of lst) {
|
|
74
|
-
const ver = parseInt(f);
|
|
75
|
-
if (isNaN(ver) || nonGarbage.has(ver)
|
|
76
|
-
|| (gcMaxVer && (ver >= gcMaxVer))) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
rmProcs.push(fs.unlink(path_1.join(obj.objFolder, f)).catch(noop));
|
|
80
|
-
}
|
|
81
|
-
if (rmProcs.length > 0) {
|
|
82
|
-
await Promise.all(rmProcs);
|
|
57
|
+
try {
|
|
58
|
+
await this.collectIn(obj);
|
|
83
59
|
}
|
|
60
|
+
catch (err) { }
|
|
84
61
|
return this.objCollecting();
|
|
85
62
|
};
|
|
86
63
|
Object.seal(this);
|
|
87
64
|
}
|
|
65
|
+
async collectIn(obj) {
|
|
66
|
+
const nonGarbage = obj.statusObj().getNonGarbageVersions();
|
|
67
|
+
if (!(await this.checkAndRemoveWholeObjFolder(obj, nonGarbage))) {
|
|
68
|
+
await removeGarbageFiles(obj, nonGarbage);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async checkAndRemoveWholeObjFolder(obj, { nonGarbage }) {
|
|
72
|
+
// if object is set archived, and there is nothing in it worth keeping,
|
|
73
|
+
// whole folder can be removed
|
|
74
|
+
if (obj.objId
|
|
75
|
+
&& obj.statusObj().isArchived()
|
|
76
|
+
&& (nonGarbage.size === 0)) {
|
|
77
|
+
this.rmObjFromCache(obj);
|
|
78
|
+
await this.rmObjFolder(obj.objId);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
88
85
|
}
|
|
89
86
|
exports.GC = GC;
|
|
90
87
|
Object.freeze(GC.prototype);
|
|
91
88
|
Object.freeze(GC);
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
async function removeGarbageFiles(obj, nonGarbage) {
|
|
90
|
+
const lst = await fs.readdir(obj.objFolder);
|
|
91
|
+
const rmProcs = [];
|
|
92
|
+
for (const f of lst) {
|
|
93
|
+
if (canGC(f, nonGarbage)) {
|
|
94
|
+
rmProcs.push(fs.unlink((0, path_1.join)(obj.objFolder, f)).catch(utils_1.noop));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (rmProcs.length > 0) {
|
|
98
|
+
await Promise.all(rmProcs);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function canGC(f, { gcMaxVer, nonGarbage }) {
|
|
102
|
+
const ver = parseInt(f);
|
|
103
|
+
if (isNaN(ver)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
else if (!nonGarbage.has(ver)
|
|
107
|
+
&& (!gcMaxVer || (ver < gcMaxVer))) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return false;
|
|
97
112
|
}
|
|
98
|
-
set.delete(value);
|
|
99
|
-
return value;
|
|
100
113
|
}
|
|
101
|
-
function noop() { }
|
|
102
114
|
Object.freeze(exports);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ObjId } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
1
|
+
import { LocalObjStatus, ObjId } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
2
2
|
import { ObjSource, Subscribe } from 'xsp-files';
|
|
3
3
|
import { GC } from './obj-files-gc';
|
|
4
|
+
import { ObjStatus } from './obj-status';
|
|
4
5
|
import { LogError } from '../../../lib-client/logging/log-to-file';
|
|
5
6
|
export declare class ObjFiles {
|
|
6
7
|
private readonly folders;
|
|
@@ -29,12 +30,8 @@ export declare class LocalObj {
|
|
|
29
30
|
getObjSrc(version: number): Promise<ObjSource>;
|
|
30
31
|
private objSegsGetterFromDisk;
|
|
31
32
|
saveNewVersion(version: number, encSub: Subscribe): Promise<void>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
getNonGarbageVersions(): {
|
|
35
|
-
gcMaxVer?: number;
|
|
36
|
-
nonGarbage: Set<number>;
|
|
37
|
-
};
|
|
33
|
+
localStatus(): LocalObjStatus;
|
|
34
|
+
statusObj(): ObjStatus;
|
|
38
35
|
removeCurrentVersion(): Promise<void>;
|
|
39
36
|
removeArchivedVersion(version: number): Promise<void>;
|
|
40
37
|
}
|
|
@@ -28,7 +28,7 @@ class ObjFiles {
|
|
|
28
28
|
constructor(folders, logError) {
|
|
29
29
|
this.folders = folders;
|
|
30
30
|
this.logError = logError;
|
|
31
|
-
this.objs = timed_cache_1.makeTimedCache(60 * 1000);
|
|
31
|
+
this.objs = (0, timed_cache_1.makeTimedCache)(60 * 1000);
|
|
32
32
|
this.folderAccessSyncProc = new synced_1.NamedProcs();
|
|
33
33
|
this.gc = new obj_files_gc_1.GC(obj => {
|
|
34
34
|
if (this.objs.get(obj.objId) === obj) {
|
|
@@ -99,7 +99,7 @@ class LocalObj {
|
|
|
99
99
|
this.objFolder = objFolder;
|
|
100
100
|
this.status = status;
|
|
101
101
|
this.scheduleGC = scheduleGC;
|
|
102
|
-
this.verObjs = timed_cache_1.makeTimedCache(60 * 1000);
|
|
102
|
+
this.verObjs = (0, timed_cache_1.makeTimedCache)(60 * 1000);
|
|
103
103
|
this.objSegsGetterFromDisk = async (ver, ofs, len) => {
|
|
104
104
|
let obj = this.verObjs.get(ver);
|
|
105
105
|
if (!obj) {
|
|
@@ -120,7 +120,7 @@ class LocalObj {
|
|
|
120
120
|
return new LocalObj(objId, objFolder, status, scheduleGC);
|
|
121
121
|
}
|
|
122
122
|
path(version) {
|
|
123
|
-
return path_1.join(this.objFolder, `${version}.v`);
|
|
123
|
+
return (0, path_1.join)(this.objFolder, `${version}.v`);
|
|
124
124
|
}
|
|
125
125
|
async getObjSrc(version) {
|
|
126
126
|
let obj = this.verObjs.get(version);
|
|
@@ -152,14 +152,11 @@ class LocalObj {
|
|
|
152
152
|
await this.status.setNewCurrentVersion(version, obj.getBaseVersion());
|
|
153
153
|
this.scheduleGC(this);
|
|
154
154
|
}
|
|
155
|
-
|
|
156
|
-
return this.status
|
|
155
|
+
localStatus() {
|
|
156
|
+
return this.status;
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
return this.status
|
|
160
|
-
}
|
|
161
|
-
getNonGarbageVersions() {
|
|
162
|
-
return this.status.getNonGarbageVersions();
|
|
158
|
+
statusObj() {
|
|
159
|
+
return this.status;
|
|
163
160
|
}
|
|
164
161
|
async removeCurrentVersion() {
|
|
165
162
|
await this.status.removeCurrentVersion(this.verObjs);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjId } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
1
|
+
import { LocalObjStatus, ObjId } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
2
2
|
import { VersionsInfo } from '../common/obj-info-file';
|
|
3
3
|
import { LogError } from '../../../lib-client/logging/log-to-file';
|
|
4
4
|
export interface ObjStatusInfo {
|
|
@@ -6,7 +6,7 @@ export interface ObjStatusInfo {
|
|
|
6
6
|
isArchived?: boolean;
|
|
7
7
|
versions: VersionsInfo;
|
|
8
8
|
}
|
|
9
|
-
export declare class ObjStatus {
|
|
9
|
+
export declare class ObjStatus implements LocalObjStatus {
|
|
10
10
|
private readonly objFolder;
|
|
11
11
|
private readonly status;
|
|
12
12
|
private readonly logError;
|
|
@@ -17,13 +17,19 @@ export declare class ObjStatus {
|
|
|
17
17
|
private triggerSaveProc;
|
|
18
18
|
isArchived(): boolean;
|
|
19
19
|
getCurrentVersionOrThrow(): number;
|
|
20
|
-
getNonGarbageVersions():
|
|
21
|
-
gcMaxVer?: number;
|
|
22
|
-
nonGarbage: Set<number>;
|
|
23
|
-
};
|
|
20
|
+
getNonGarbageVersions(): NonGarbage;
|
|
24
21
|
setNewCurrentVersion(newVersion: number, baseVer: number | undefined): Promise<void>;
|
|
25
22
|
removeCurrentVersion(verObjs: ContainerWithDelete<number>): Promise<void>;
|
|
26
23
|
removeArchivedVersion(version: number, verObjs: ContainerWithDelete<number>): Promise<void>;
|
|
24
|
+
archiveCurrentVersion(): Promise<void>;
|
|
25
|
+
listVersions(): {
|
|
26
|
+
current?: number;
|
|
27
|
+
archived?: number[];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface NonGarbage {
|
|
31
|
+
gcMaxVer?: number;
|
|
32
|
+
nonGarbage: Set<number>;
|
|
27
33
|
}
|
|
28
34
|
interface ContainerWithDelete<T> {
|
|
29
35
|
delete(key: T): void;
|
|
@@ -19,15 +19,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.ObjStatus = void 0;
|
|
20
20
|
const path_1 = require("path");
|
|
21
21
|
const exceptions_1 = require("../../../lib-client/3nstorage/exceptions");
|
|
22
|
-
const json_saving_1 = require("../common/json-saving");
|
|
23
22
|
const obj_info_file_1 = require("../common/obj-info-file");
|
|
23
|
+
const json_saving_1 = require("../common/json-saving");
|
|
24
|
+
const obj_info_file_2 = require("../common/obj-info-file");
|
|
25
|
+
const assert_1 = require("../../../lib-common/assert");
|
|
24
26
|
const STATUS_FILE_NAME = 'status';
|
|
25
27
|
class ObjStatus {
|
|
26
28
|
constructor(objFolder, status, logError) {
|
|
27
29
|
this.objFolder = objFolder;
|
|
28
30
|
this.status = status;
|
|
29
31
|
this.logError = logError;
|
|
30
|
-
this.saveProc = new json_saving_1.JSONSavingProc(path_1.join(this.objFolder, STATUS_FILE_NAME), () => this.status);
|
|
32
|
+
this.saveProc = new json_saving_1.JSONSavingProc((0, path_1.join)(this.objFolder, STATUS_FILE_NAME), () => this.status);
|
|
31
33
|
Object.freeze(this);
|
|
32
34
|
}
|
|
33
35
|
static async readFrom(objFolder, objId, logError) {
|
|
@@ -61,17 +63,17 @@ class ObjStatus {
|
|
|
61
63
|
}
|
|
62
64
|
getNonGarbageVersions() {
|
|
63
65
|
return {
|
|
64
|
-
nonGarbage:
|
|
66
|
+
nonGarbage: (0, obj_info_file_2.nonGarbageVersionsIn)(this.status.versions),
|
|
65
67
|
gcMaxVer: this.status.versions.current
|
|
66
68
|
};
|
|
67
69
|
}
|
|
68
70
|
async setNewCurrentVersion(newVersion, baseVer) {
|
|
69
|
-
|
|
71
|
+
(0, obj_info_file_2.setCurrentVersionIn)(this.status.versions, newVersion, baseVer);
|
|
70
72
|
await this.triggerSaveProc();
|
|
71
73
|
}
|
|
72
74
|
async removeCurrentVersion(verObjs) {
|
|
73
75
|
this.status.isArchived = true;
|
|
74
|
-
const current =
|
|
76
|
+
const current = (0, obj_info_file_2.rmCurrentVersionIn)(this.status.versions);
|
|
75
77
|
if (typeof current === 'number') {
|
|
76
78
|
verObjs.delete(current);
|
|
77
79
|
}
|
|
@@ -79,23 +81,36 @@ class ObjStatus {
|
|
|
79
81
|
}
|
|
80
82
|
async removeArchivedVersion(version, verObjs) {
|
|
81
83
|
verObjs.delete(version);
|
|
82
|
-
|
|
84
|
+
(0, obj_info_file_2.rmArchVersionFrom)(this.status.versions, version);
|
|
85
|
+
await this.triggerSaveProc();
|
|
86
|
+
}
|
|
87
|
+
async archiveCurrentVersion() {
|
|
88
|
+
const versions = this.status.versions;
|
|
89
|
+
(0, assert_1.assert)(!!versions.current);
|
|
90
|
+
(0, obj_info_file_1.addArchived)(versions, versions.current);
|
|
83
91
|
await this.triggerSaveProc();
|
|
84
92
|
}
|
|
93
|
+
listVersions() {
|
|
94
|
+
const archived = this.status.versions.archived;
|
|
95
|
+
return {
|
|
96
|
+
current: this.status.versions.current,
|
|
97
|
+
archived: (archived ? archived.slice() : [])
|
|
98
|
+
};
|
|
99
|
+
}
|
|
85
100
|
}
|
|
86
101
|
exports.ObjStatus = ObjStatus;
|
|
87
102
|
Object.freeze(ObjStatus.prototype);
|
|
88
103
|
Object.freeze(ObjStatus);
|
|
89
104
|
async function readAndCheckStatus(objFolder, objId) {
|
|
90
|
-
const status = await
|
|
105
|
+
const status = await (0, obj_info_file_2.readJSONInfoFileIn)(objFolder, STATUS_FILE_NAME);
|
|
91
106
|
if (!status) {
|
|
92
|
-
throw exceptions_1.makeStorageException({
|
|
107
|
+
throw (0, exceptions_1.makeStorageException)({
|
|
93
108
|
message: `Obj status file is not found in obj folder ${objFolder}`
|
|
94
109
|
});
|
|
95
110
|
}
|
|
96
111
|
// XXX we may do some checks and sanitization here
|
|
97
112
|
if (objId !== status.objId) {
|
|
98
|
-
throw exceptions_1.makeStorageException({ message: `Invalid objId in status file for obj ${objId}, in folder ${objFolder}.\nInvalid content:\n${JSON.stringify(status, null, 2)}` });
|
|
113
|
+
throw (0, exceptions_1.makeStorageException)({ message: `Invalid objId in status file for obj ${objId}, in folder ${objFolder}.\nInvalid content:\n${JSON.stringify(status, null, 2)}` });
|
|
99
114
|
}
|
|
100
115
|
return status;
|
|
101
116
|
}
|