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,26 +1,29 @@
|
|
|
1
|
-
import { Storage, NodesContainer, StorageGetter, ObjId, NodeEvent } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
1
|
+
import { Storage, NodesContainer, StorageGetter, ObjId, NodeEvent, LocalObjStatus } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
2
2
|
import { LogError } from '../../../lib-client/logging/log-to-file';
|
|
3
3
|
import { AsyncSBoxCryptor, Subscribe, ObjSource } from 'xsp-files';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
5
|
declare type FolderEvent = web3n.files.FolderEvent;
|
|
6
6
|
declare type FileEvent = web3n.files.FileEvent;
|
|
7
|
+
declare type FSType = web3n.files.FSType;
|
|
7
8
|
export declare class LocalStorage implements Storage {
|
|
8
9
|
private readonly files;
|
|
9
10
|
private readonly getStorages;
|
|
10
11
|
readonly cryptor: AsyncSBoxCryptor;
|
|
11
|
-
|
|
12
|
-
readonly type
|
|
12
|
+
readonly logError: LogError;
|
|
13
|
+
readonly type = "local";
|
|
13
14
|
readonly versioned = true;
|
|
14
15
|
readonly nodes: NodesContainer;
|
|
16
|
+
readonly connect: undefined;
|
|
15
17
|
private readonly events;
|
|
16
18
|
private constructor();
|
|
17
19
|
static makeAndStart(path: string, getStorages: StorageGetter, cryptor: AsyncSBoxCryptor, logError: LogError): Promise<Storage>;
|
|
18
20
|
getNodeEvents(): Observable<NodeEvent>;
|
|
19
|
-
broadcastNodeEvent(objId: ObjId, parentObjId: ObjId | undefined, event: FolderEvent | FileEvent): void;
|
|
20
|
-
storageForLinking(type:
|
|
21
|
+
broadcastNodeEvent(objId: ObjId, parentObjId: ObjId | undefined, childObjId: ObjId | undefined, event: FolderEvent | FileEvent): void;
|
|
22
|
+
storageForLinking(type: FSType, location?: string): Storage;
|
|
23
|
+
private getObjOrThrow;
|
|
24
|
+
status(objId: ObjId): Promise<LocalObjStatus>;
|
|
21
25
|
generateNewObjId(): Promise<string>;
|
|
22
|
-
|
|
23
|
-
getObj(objId: ObjId): Promise<ObjSource>;
|
|
26
|
+
getObjSrc(objId: ObjId, version?: number): Promise<ObjSource>;
|
|
24
27
|
saveObj(objId: string, version: number, encSub: Subscribe): Promise<void>;
|
|
25
28
|
removeObj(objId: string): Promise<void>;
|
|
26
29
|
close(): Promise<void>;
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.LocalStorage = void 0;
|
|
19
20
|
const common_1 = require("../../../lib-client/3nstorage/xsp-fs/common");
|
|
@@ -32,19 +33,20 @@ class LocalStorage {
|
|
|
32
33
|
this.type = 'local';
|
|
33
34
|
this.versioned = true;
|
|
34
35
|
this.nodes = new common_1.NodesContainer();
|
|
36
|
+
this.connect = undefined;
|
|
35
37
|
this.events = new utils_for_observables_1.Broadcast();
|
|
36
38
|
Object.seal(this);
|
|
37
39
|
}
|
|
38
40
|
static async makeAndStart(path, getStorages, cryptor, logError) {
|
|
39
41
|
const files = await obj_files_1.ObjFiles.makeFor(path, logError);
|
|
40
42
|
const s = new LocalStorage(files, getStorages, cryptor, logError);
|
|
41
|
-
return common_1.wrapStorageImplementation(s);
|
|
43
|
+
return (0, common_1.wrapStorageImplementation)(s);
|
|
42
44
|
}
|
|
43
45
|
getNodeEvents() {
|
|
44
46
|
return this.events.event$;
|
|
45
47
|
}
|
|
46
|
-
broadcastNodeEvent(objId, parentObjId, event) {
|
|
47
|
-
this.events.next({ objId, parentObjId, event });
|
|
48
|
+
broadcastNodeEvent(objId, parentObjId, childObjId, event) {
|
|
49
|
+
this.events.next({ objId, parentObjId, childObjId, event });
|
|
48
50
|
}
|
|
49
51
|
storageForLinking(type, location) {
|
|
50
52
|
if ((type === 'local') || (type === 'synced')) {
|
|
@@ -57,8 +59,22 @@ class LocalStorage {
|
|
|
57
59
|
throw new Error(`Getting ${type} storage is not implemented in local storage.`);
|
|
58
60
|
}
|
|
59
61
|
}
|
|
62
|
+
async getObjOrThrow(objId, allowArchived = false) {
|
|
63
|
+
const obj = await this.files.findObj(objId);
|
|
64
|
+
if (!obj
|
|
65
|
+
|| (!allowArchived && obj.statusObj().isArchived())) {
|
|
66
|
+
throw (0, exceptions_1.makeObjNotFoundExc)(objId);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return obj;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async status(objId) {
|
|
73
|
+
const obj = await this.getObjOrThrow(objId);
|
|
74
|
+
return obj.localStatus();
|
|
75
|
+
}
|
|
60
76
|
async generateNewObjId() {
|
|
61
|
-
const nonce = await random_node_1.bytes(ecma_nacl_1.secret_box.NONCE_LENGTH);
|
|
77
|
+
const nonce = await (0, random_node_1.bytes)(ecma_nacl_1.secret_box.NONCE_LENGTH);
|
|
62
78
|
const id = buffer_utils_1.base64urlSafe.pack(nonce);
|
|
63
79
|
if (this.nodes.reserveId(id)) {
|
|
64
80
|
return id;
|
|
@@ -67,35 +83,30 @@ class LocalStorage {
|
|
|
67
83
|
return this.generateNewObjId();
|
|
68
84
|
}
|
|
69
85
|
}
|
|
70
|
-
async
|
|
71
|
-
const obj = await this.
|
|
72
|
-
if (!
|
|
73
|
-
|
|
86
|
+
async getObjSrc(objId, version) {
|
|
87
|
+
const obj = await this.getObjOrThrow(objId);
|
|
88
|
+
if (!version) {
|
|
89
|
+
version = obj.statusObj().getCurrentVersionOrThrow();
|
|
74
90
|
}
|
|
75
|
-
return obj;
|
|
76
|
-
}
|
|
77
|
-
async getObj(objId) {
|
|
78
|
-
const obj = await this.getObjNonArchOrThrow(objId);
|
|
79
|
-
const currentVer = obj.getCurrentVersionOrThrow();
|
|
80
|
-
return obj.getObjSrc(currentVer);
|
|
91
|
+
return obj.getObjSrc(version);
|
|
81
92
|
}
|
|
82
93
|
async saveObj(objId, version, encSub) {
|
|
83
94
|
const obj = await this.files.findObj(objId);
|
|
84
95
|
if (version === 1) {
|
|
85
96
|
if (obj) {
|
|
86
|
-
throw exceptions_1.makeObjExistsExc(objId);
|
|
97
|
+
throw (0, exceptions_1.makeObjExistsExc)(objId);
|
|
87
98
|
}
|
|
88
99
|
await this.files.saveFirstVersion(objId, encSub);
|
|
89
100
|
}
|
|
90
101
|
else {
|
|
91
102
|
if (!obj) {
|
|
92
|
-
throw exceptions_1.makeObjNotFoundExc(objId);
|
|
103
|
+
throw (0, exceptions_1.makeObjNotFoundExc)(objId);
|
|
93
104
|
}
|
|
94
105
|
await obj.saveNewVersion(version, encSub);
|
|
95
106
|
}
|
|
96
107
|
}
|
|
97
108
|
async removeObj(objId) {
|
|
98
|
-
const obj = await this.
|
|
109
|
+
const obj = await this.getObjOrThrow(objId);
|
|
99
110
|
await obj.removeCurrentVersion();
|
|
100
111
|
}
|
|
101
112
|
async close() {
|
|
@@ -17,9 +17,12 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.GC = void 0;
|
|
20
|
+
const obj_files_1 = require("./obj-files");
|
|
20
21
|
const synced_1 = require("../../../lib-common/processes/synced");
|
|
21
22
|
const fs = require("../../../lib-common/async-fs-node");
|
|
22
23
|
const path_1 = require("path");
|
|
24
|
+
const utils_1 = require("../common/utils");
|
|
25
|
+
const upload_header_file_1 = require("./upload-header-file");
|
|
23
26
|
class GC {
|
|
24
27
|
constructor(sync, rmObjFromCache, rmObjFolder) {
|
|
25
28
|
this.sync = sync;
|
|
@@ -54,11 +57,11 @@ class GC {
|
|
|
54
57
|
if (this.wip.size === 0) {
|
|
55
58
|
[this.wip, this.scheduled] = [this.scheduled, this.wip];
|
|
56
59
|
}
|
|
57
|
-
const obj = getAndRemoveOneFrom(this.wip);
|
|
60
|
+
const obj = (0, utils_1.getAndRemoveOneFrom)(this.wip);
|
|
58
61
|
if (!obj) {
|
|
59
62
|
return;
|
|
60
63
|
}
|
|
61
|
-
await this.sync(obj.objId, () => this.collectIn(obj).catch(noop));
|
|
64
|
+
await this.sync(obj.objId, () => this.collectIn(obj).catch(utils_1.noop));
|
|
62
65
|
return this.objCollecting();
|
|
63
66
|
};
|
|
64
67
|
Object.seal(this);
|
|
@@ -67,52 +70,86 @@ class GC {
|
|
|
67
70
|
this.isStopped = true;
|
|
68
71
|
}
|
|
69
72
|
async collectIn(obj) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// whole folder can be removed
|
|
74
|
-
if ((nonGarbage.size === 0)
|
|
75
|
-
&& obj.isArchived() && obj.sync().isSyncDone()) {
|
|
76
|
-
if (!obj.isStatusFileSaved()) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
this.rmObjFromCache(obj);
|
|
80
|
-
if (obj.objId) {
|
|
81
|
-
await this.rmObjFolder(obj.objId);
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
// for all other cases, we remove version files that are not worth
|
|
86
|
-
// keeping.
|
|
87
|
-
const lst = await fs.readdir(obj.objFolder).catch(noop);
|
|
88
|
-
if (!lst) {
|
|
89
|
-
return;
|
|
73
|
+
const nonGarbage = obj.statusObj().getNonGarbageVersions();
|
|
74
|
+
if (!(await this.checkAndRemoveWholeObjFolder(obj, nonGarbage))) {
|
|
75
|
+
await removeGarbageFiles(obj, nonGarbage);
|
|
90
76
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
77
|
+
}
|
|
78
|
+
async checkAndRemoveWholeObjFolder(obj, { local, remote }) {
|
|
79
|
+
if (obj.objId
|
|
80
|
+
&& obj.statusObj().isArchived()
|
|
81
|
+
&& !needsUpsyncOfRemoval(obj)
|
|
82
|
+
&& (!local || (local.nonGarbage.size === 0))
|
|
83
|
+
&& (remote.nonGarbage.size === 0)) {
|
|
84
|
+
this.rmObjFromCache(obj);
|
|
85
|
+
await this.rmObjFolder(obj.objId);
|
|
86
|
+
return true;
|
|
99
87
|
}
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
else {
|
|
89
|
+
return false;
|
|
102
90
|
}
|
|
103
91
|
}
|
|
104
92
|
}
|
|
105
93
|
exports.GC = GC;
|
|
106
94
|
Object.freeze(GC.prototype);
|
|
107
95
|
Object.freeze(GC);
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
96
|
+
function needsUpsyncOfRemoval(obj) {
|
|
97
|
+
const s = obj.statusObj();
|
|
98
|
+
return !(s.neverUploaded() || (s.syncStatus().state === 'synced'));
|
|
99
|
+
}
|
|
100
|
+
function canRemove(f, { local, remote, uploadVersion }) {
|
|
101
|
+
if (f.endsWith(obj_files_1.UNSYNCED_FILE_NAME_EXT)) {
|
|
102
|
+
const verStr = f.slice(0, f.length - 1 - obj_files_1.UNSYNCED_FILE_NAME_EXT.length);
|
|
103
|
+
return (local ? canGC(verStr, local) : true);
|
|
104
|
+
}
|
|
105
|
+
else if (f.endsWith(obj_files_1.REMOTE_FILE_NAME_EXT)) {
|
|
106
|
+
const verStr = f.slice(0, f.length - 1 - obj_files_1.REMOTE_FILE_NAME_EXT.length);
|
|
107
|
+
return canGC(verStr, remote);
|
|
108
|
+
}
|
|
109
|
+
else if (!!uploadVersion
|
|
110
|
+
&& f.endsWith(upload_header_file_1.UPLOAD_HEADER_FILE_NAME_EXT)) {
|
|
111
|
+
const verStr = f.slice(0, f.length - 1 - upload_header_file_1.UPLOAD_HEADER_FILE_NAME_EXT.length);
|
|
112
|
+
return canGCUploadHeader(verStr, uploadVersion);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function canGC(verStr, nonGC) {
|
|
119
|
+
const ver = parseInt(verStr);
|
|
120
|
+
if (isNaN(ver)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
else if (!nonGC.nonGarbage.has(ver)
|
|
124
|
+
&& (!nonGC.gcMaxVer || (ver < nonGC.gcMaxVer))) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function canGCUploadHeader(verStr, uploadVersion) {
|
|
132
|
+
const ver = parseInt(verStr);
|
|
133
|
+
if (isNaN(ver)) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return (ver === uploadVersion);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function removeGarbageFiles(obj, nonGarbage) {
|
|
141
|
+
const lst = await fs.readdir(obj.objFolder).catch(utils_1.noop);
|
|
142
|
+
if (!lst) {
|
|
112
143
|
return;
|
|
113
144
|
}
|
|
114
|
-
|
|
115
|
-
|
|
145
|
+
const rmProcs = [];
|
|
146
|
+
for (const f of lst) {
|
|
147
|
+
if (canRemove(f, nonGarbage)) {
|
|
148
|
+
rmProcs.push(fs.unlink((0, path_1.join)(obj.objFolder, f)).catch(utils_1.noop));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (rmProcs.length > 0) {
|
|
152
|
+
await Promise.all(rmProcs);
|
|
153
|
+
}
|
|
116
154
|
}
|
|
117
|
-
function noop() { }
|
|
118
155
|
Object.freeze(exports);
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import { ObjId } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
2
|
+
import { ObjId, SyncedObjStatus } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
3
3
|
import { InitDownloadParts } from '../../../lib-client/objs-on-disk/obj-on-disk';
|
|
4
4
|
import { ObjSource, Subscribe } from 'xsp-files';
|
|
5
5
|
import { Downloader } from './downloader';
|
|
6
6
|
import { FileWrite } from '../../../lib-client/objs-on-disk/file-writing-proc';
|
|
7
7
|
import { GC } from './obj-files-gc';
|
|
8
|
-
import {
|
|
8
|
+
import { ObjStatus } from './obj-status';
|
|
9
9
|
import { LogError } from '../../../lib-client/logging/log-to-file';
|
|
10
|
+
import { DiffInfo } from '../../../lib-common/service-api/3nstorage/owner';
|
|
11
|
+
import { FiniteChunk } from '../../../lib-common/objs-on-disk/file-layout';
|
|
12
|
+
import { StorageOwner as RemoteStorage } from '../../../lib-client/3nstorage/service';
|
|
13
|
+
import { UploadHeaderChange } from '../../../lib-client/3nstorage/xsp-fs/common';
|
|
14
|
+
export declare const UNSYNCED_FILE_NAME_EXT = "unsynced";
|
|
15
|
+
export declare const REMOTE_FILE_NAME_EXT = "v";
|
|
16
|
+
/**
|
|
17
|
+
* File system has nodes. Each node may have data in one or many objects of
|
|
18
|
+
* storage. SyncedObj allows to work with files of storage object, even when
|
|
19
|
+
* file system node no longer exists. ObjFiles is a holder and factory of
|
|
20
|
+
* SyncedObj's.
|
|
21
|
+
*/
|
|
10
22
|
export declare class ObjFiles {
|
|
11
23
|
private readonly folders;
|
|
12
|
-
private readonly downloader;
|
|
13
24
|
private readonly logError;
|
|
14
25
|
private readonly objs;
|
|
15
26
|
private readonly sync;
|
|
27
|
+
private readonly downloader;
|
|
16
28
|
private readonly gc;
|
|
17
29
|
private constructor();
|
|
18
|
-
static makeFor(path: string,
|
|
30
|
+
static makeFor(path: string, remote: RemoteStorage, logError: LogError): Promise<ObjFiles>;
|
|
31
|
+
private canMoveObjToDeeperCache;
|
|
19
32
|
findObj(objId: ObjId): Promise<SyncedObj | undefined>;
|
|
33
|
+
getObjInCache(objId: ObjId): SyncedObj | undefined;
|
|
20
34
|
private makeObj;
|
|
21
35
|
private removeFailedNewObj;
|
|
22
36
|
makeByDownloadingCurrentVersion(objId: ObjId): Promise<SyncedObj>;
|
|
@@ -24,7 +38,8 @@ export declare class ObjFiles {
|
|
|
24
38
|
fileWrite$: Observable<FileWrite[]>;
|
|
25
39
|
newObj: SyncedObj;
|
|
26
40
|
}>;
|
|
27
|
-
|
|
41
|
+
findObjsToRemoveOnRemote(): Observable<ObjId>;
|
|
42
|
+
scheduleGC(obj: SyncedObj): void;
|
|
28
43
|
}
|
|
29
44
|
export declare type SynchronizerOnObjId = <T>(objId: ObjId, action: () => Promise<T>) => Promise<T>;
|
|
30
45
|
export declare class SyncedObj {
|
|
@@ -33,46 +48,45 @@ export declare class SyncedObj {
|
|
|
33
48
|
private readonly status;
|
|
34
49
|
private readonly downloader;
|
|
35
50
|
private readonly scheduleGC;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* object's versions. Versions here can be either synced, or unsynced.
|
|
39
|
-
*/
|
|
40
|
-
private readonly verObjs;
|
|
41
|
-
/**
|
|
42
|
-
* These are conflicting versions, coming from a server. Of course, universal
|
|
43
|
-
* truth is spread by server, but in situations of parallel changes, local
|
|
44
|
-
* version allows things to work, while conflicting version from server
|
|
45
|
-
* should be adopted by conflict resolution process. In other words, these
|
|
46
|
-
* versions are not for common use.
|
|
47
|
-
*/
|
|
48
|
-
private readonly remoteConflictVerObjs;
|
|
51
|
+
private readonly remoteVers;
|
|
52
|
+
private readonly localVers;
|
|
49
53
|
private constructor();
|
|
50
54
|
static forExistingObj(objId: ObjId, objFolder: string, downloader: Downloader, scheduleGC: GC['scheduleCollection'], logError: LogError): Promise<SyncedObj>;
|
|
51
55
|
static forDownloadedObj(objId: ObjId, objFolder: string, downloader: Downloader, scheduleGC: GC['scheduleCollection'], version: number, parts: InitDownloadParts, logError: LogError): Promise<SyncedObj>;
|
|
52
56
|
static forNewObj(objId: ObjId, objFolder: string, downloader: Downloader, scheduleGC: GC['scheduleCollection'], logError: LogError): Promise<SyncedObj>;
|
|
53
|
-
sync(): UpSyncStatus;
|
|
54
57
|
scheduleSelfGC(): void;
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
private
|
|
58
|
+
private localVerPath;
|
|
59
|
+
private remoteVerPath;
|
|
60
|
+
getObjSrcFromLocalAndSyncedBranch(version: number): Promise<ObjSource>;
|
|
61
|
+
getObjSrcFromRemoteAndSyncedBranch(version: number): Promise<ObjSource>;
|
|
62
|
+
private instanceOfLocalObjVer;
|
|
63
|
+
private instanceOfRemoteObjVer;
|
|
64
|
+
private readonly localAndSyncedObjSegsGetterFromDisk;
|
|
65
|
+
private readonly remoteObjSegsGetterFromDisk;
|
|
60
66
|
saveNewVersion(version: number, encSub: Subscribe): Promise<{
|
|
61
67
|
fileWrite$: Observable<FileWrite[]>;
|
|
62
68
|
baseVer?: number;
|
|
63
69
|
}>;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
isRemoteVersionGreaterOrEqualTo(newRemoteVersion: number): boolean;
|
|
67
|
-
isDeletedOnRemote(): boolean;
|
|
70
|
+
combineLocalBaseIfPresent(version: number): Promise<number | undefined>;
|
|
71
|
+
saveUploadHeaderFile(uploadHeader: UploadHeaderChange): Promise<void>;
|
|
68
72
|
private setUnsyncedCurrentVersion;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
/**
|
|
74
|
+
* This renames/moves version file from local to remote.
|
|
75
|
+
* Removes upload info from status, updating enumerations of local and
|
|
76
|
+
* synced versions.
|
|
77
|
+
*/
|
|
78
|
+
recordUploadCompletion(localVersion: number, uploadVersion: number, headerChange: {
|
|
79
|
+
newHeader: Uint8Array;
|
|
80
|
+
originalHeader: Uint8Array;
|
|
81
|
+
} | undefined): Promise<void>;
|
|
82
|
+
dropCachedLocalObjVersionsLessOrEqual(version: number): void;
|
|
83
|
+
removeLocalVersionFilesLessThan(version: number): Promise<void>;
|
|
72
84
|
removeCurrentVersion(): Promise<void>;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
85
|
+
diffForUploadOf(version: number): Promise<{
|
|
86
|
+
diff: DiffInfo;
|
|
87
|
+
newSegsPackOrder: FiniteChunk[];
|
|
88
|
+
}>;
|
|
89
|
+
syncStatus(): SyncedObjStatus;
|
|
90
|
+
statusObj(): ObjStatus;
|
|
91
|
+
recordRemovalUploadAndGC(): Promise<void>;
|
|
78
92
|
}
|