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
|
@@ -82,7 +82,7 @@ class LinkNode extends node_in_fs_1.NodeInFS {
|
|
|
82
82
|
if (!name || !objId || !parentId) {
|
|
83
83
|
throw new Error("Bad link parameter(s) given");
|
|
84
84
|
}
|
|
85
|
-
this.crypto = new LinkPersistance(xsp_files_1.idToHeaderNonce(this.objId), key, this.storage.cryptor);
|
|
85
|
+
this.crypto = new LinkPersistance((0, xsp_files_1.idToHeaderNonce)(this.objId), key, this.storage.cryptor);
|
|
86
86
|
Object.seal(this);
|
|
87
87
|
}
|
|
88
88
|
static async makeForNew(storage, parentId, name, key) {
|
|
@@ -92,12 +92,17 @@ class LinkNode extends node_in_fs_1.NodeInFS {
|
|
|
92
92
|
return link;
|
|
93
93
|
}
|
|
94
94
|
static async makeForExisting(storage, parentId, name, objId, key) {
|
|
95
|
-
const src = await storage.
|
|
95
|
+
const src = await storage.getObjSrc(objId);
|
|
96
96
|
const link = new LinkNode(storage, name, objId, src.version, parentId, key);
|
|
97
97
|
const { params, attrs, xattrs } = await link.crypto.read(src);
|
|
98
98
|
link.setUpdatedState(params, src.version, attrs, xattrs);
|
|
99
|
+
link.setCurrentStateFrom(src);
|
|
99
100
|
return link;
|
|
100
101
|
}
|
|
102
|
+
async setCurrentStateFrom(src) {
|
|
103
|
+
const { params, attrs, xattrs } = await this.crypto.read(src);
|
|
104
|
+
this.setUpdatedState(params, src.version, attrs, xattrs);
|
|
105
|
+
}
|
|
101
106
|
setUpdatedState(params, version, attrs, xattrs) {
|
|
102
107
|
this.linkParams = params;
|
|
103
108
|
super.setUpdatedParams(version, attrs, xattrs);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Node, NodeType, Storage,
|
|
1
|
+
import { FSChangeSrc, Node, NodeType, Storage, SyncedStorage, UploadHeaderChange } from './common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { CommonAttrs, XAttrs } from './attrs';
|
|
4
4
|
import { NodePersistance } from './node-persistence';
|
|
5
|
-
import {
|
|
5
|
+
import { ObjSource } from 'xsp-files';
|
|
6
6
|
export declare type FSEvent = web3n.files.FolderEvent | web3n.files.FileEvent;
|
|
7
|
+
declare type RemoteEvent = web3n.files.RemoteEvent;
|
|
7
8
|
declare type XAttrsChanges = web3n.files.XAttrsChanges;
|
|
8
|
-
declare type
|
|
9
|
+
declare type SyncStatus = web3n.files.SyncStatus;
|
|
10
|
+
declare type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
|
|
11
|
+
declare type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
|
|
9
12
|
export declare abstract class NodeInFS<P extends NodePersistance> implements Node {
|
|
10
13
|
protected readonly storage: Storage;
|
|
11
14
|
readonly type: NodeType;
|
|
@@ -19,7 +22,7 @@ export declare abstract class NodeInFS<P extends NodePersistance> implements Nod
|
|
|
19
22
|
private writeProc;
|
|
20
23
|
get version(): number;
|
|
21
24
|
protected setCurrentVersion(newVersion: number): void;
|
|
22
|
-
|
|
25
|
+
readonly isInSyncedStorage: boolean;
|
|
23
26
|
protected constructor(storage: Storage, type: NodeType, name: string, objId: string, currentVersion: number, parentId: string | undefined);
|
|
24
27
|
private updatedXAttrs;
|
|
25
28
|
protected setUpdatedParams(version: number, attrs: CommonAttrs | undefined, xattrs: XAttrs | undefined): void;
|
|
@@ -32,17 +35,13 @@ export declare abstract class NodeInFS<P extends NodePersistance> implements Nod
|
|
|
32
35
|
getXAttr(xaName: string): any;
|
|
33
36
|
listXAttrs(): string[];
|
|
34
37
|
getAttrs(): CommonAttrs;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* this node from storage. Make sure to call it inside access synchronization
|
|
43
|
-
* construct.
|
|
44
|
-
*/
|
|
45
|
-
protected delete(remoteEvent?: boolean): Promise<void>;
|
|
38
|
+
listVersions(): Promise<{
|
|
39
|
+
current?: number;
|
|
40
|
+
archived?: number[];
|
|
41
|
+
}>;
|
|
42
|
+
archiveCurrent(version?: number): Promise<number>;
|
|
43
|
+
removeNonFolderObj(src: FSChangeSrc): Promise<void>;
|
|
44
|
+
protected removeThisNodeAsLeaf(src: FSChangeSrc): Promise<void>;
|
|
46
45
|
/**
|
|
47
46
|
* This method runs node changing function in an exclusive manner.
|
|
48
47
|
* Returned promise resolves to whatever change function returns.
|
|
@@ -56,24 +55,26 @@ export declare abstract class NodeInFS<P extends NodePersistance> implements Nod
|
|
|
56
55
|
* new current version, when change has been successful.
|
|
57
56
|
*/
|
|
58
57
|
protected doChange<T>(awaitPrevChange: boolean, change: () => Promise<T>): Promise<T>;
|
|
59
|
-
|
|
60
|
-
* This method is called on conflict with remote version. This method
|
|
61
|
-
* is called at ordered point in time requiring no further synchronization.
|
|
62
|
-
* @param remoteVersion is an object version on server
|
|
63
|
-
*/
|
|
64
|
-
protected doOnConflict(remoteVersion: number): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* This non-synchronized method resolves conflict with remote version.
|
|
67
|
-
* @param remoteVersion
|
|
68
|
-
*/
|
|
69
|
-
protected doOnExternalChange(remoteVersion: number): Promise<void>;
|
|
70
|
-
protected broadcastEvent(event: FSEvent, complete?: boolean): void;
|
|
58
|
+
protected broadcastEvent(event: FSEvent, complete?: boolean, childObjId?: string): void;
|
|
71
59
|
/**
|
|
72
60
|
* This is a lazily initialized field, when there is an external entity
|
|
73
61
|
* that wants to see this node's events.
|
|
74
62
|
*/
|
|
75
63
|
private events;
|
|
76
|
-
get event$(): Observable<FSEvent>;
|
|
77
|
-
|
|
64
|
+
get event$(): Observable<FSEvent | RemoteEvent>;
|
|
65
|
+
protected syncedStorage(): SyncedStorage;
|
|
66
|
+
syncStatus(): Promise<SyncStatus>;
|
|
67
|
+
updateStatusInfo(): Promise<SyncStatus>;
|
|
68
|
+
isSyncedVersionOnDisk(version: number): Promise<'partial' | 'complete' | 'none'>;
|
|
69
|
+
download(version: number): Promise<void>;
|
|
70
|
+
protected abstract setCurrentStateFrom(src: ObjSource): Promise<void>;
|
|
71
|
+
adoptRemote(opts: OptionsToAdopteRemote | undefined): Promise<void>;
|
|
72
|
+
protected needUpload(localVersion: number | undefined): Promise<{
|
|
73
|
+
localVersion: number;
|
|
74
|
+
uploadVersion: number;
|
|
75
|
+
createOnRemote: boolean;
|
|
76
|
+
} | undefined>;
|
|
77
|
+
upload(opts: OptionsToUploadLocal | undefined): Promise<void>;
|
|
78
|
+
protected uploadHeaderChange(localVersion: number, uploadVersion: number): Promise<UploadHeaderChange | undefined>;
|
|
78
79
|
}
|
|
79
80
|
export {};
|
|
@@ -22,11 +22,14 @@ exports.NodeInFS = void 0;
|
|
|
22
22
|
* reliance set.
|
|
23
23
|
*/
|
|
24
24
|
const synced_1 = require("../../../lib-common/processes/synced");
|
|
25
|
+
const common_1 = require("./common");
|
|
25
26
|
const file_1 = require("../../../lib-common/exceptions/file");
|
|
26
27
|
const error_1 = require("../../../lib-common/exceptions/error");
|
|
28
|
+
const exceptions_1 = require("../exceptions");
|
|
27
29
|
const rxjs_1 = require("rxjs");
|
|
28
30
|
const operators_1 = require("rxjs/operators");
|
|
29
31
|
const attrs_1 = require("./attrs");
|
|
32
|
+
const assert_1 = require("../../../lib-common/assert");
|
|
30
33
|
class NodeInFS {
|
|
31
34
|
constructor(storage, type, name, objId, currentVersion, parentId) {
|
|
32
35
|
this.storage = storage;
|
|
@@ -39,12 +42,12 @@ class NodeInFS {
|
|
|
39
42
|
this.attrs = undefined;
|
|
40
43
|
this.xattrs = undefined;
|
|
41
44
|
this.writeProc = undefined;
|
|
42
|
-
this.remoteEvents = undefined;
|
|
43
45
|
/**
|
|
44
46
|
* This is a lazily initialized field, when there is an external entity
|
|
45
47
|
* that wants to see this node's events.
|
|
46
48
|
*/
|
|
47
49
|
this.events = undefined;
|
|
50
|
+
this.isInSyncedStorage = (0, common_1.isSyncedStorage)(this.storage);
|
|
48
51
|
}
|
|
49
52
|
get version() {
|
|
50
53
|
return this.currentVersion;
|
|
@@ -80,7 +83,7 @@ class NodeInFS {
|
|
|
80
83
|
}
|
|
81
84
|
return this.doChange(true, async () => {
|
|
82
85
|
const { xattrs, newVersion } = this.getParamsForUpdate(changes);
|
|
83
|
-
const base = await this.storage.
|
|
86
|
+
const base = await this.storage.getObjSrc(this.objId);
|
|
84
87
|
const sub = await this.crypto.writeXAttrs(xattrs, newVersion, base);
|
|
85
88
|
await this.storage.saveObj(this.objId, newVersion, sub);
|
|
86
89
|
this.setUpdatedParams(newVersion, undefined, xattrs);
|
|
@@ -96,87 +99,55 @@ class NodeInFS {
|
|
|
96
99
|
getAttrs() {
|
|
97
100
|
return this.attrs;
|
|
98
101
|
}
|
|
99
|
-
async
|
|
100
|
-
this.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// in the event, and if so, wait for completion of that process to either ignore
|
|
110
|
-
// remote event, or to set conflict, or whatever
|
|
111
|
-
// XXX should we use here synced storage methods here?
|
|
112
|
-
// This method is called only in synced storage.
|
|
113
|
-
// XXX detect if there is a conflict
|
|
114
|
-
// need obj status info here
|
|
115
|
-
// if (conflict) {
|
|
116
|
-
// await this.doOnConflict();
|
|
117
|
-
// } else {
|
|
118
|
-
// await this.doOnExternalChange();
|
|
119
|
-
// }
|
|
102
|
+
async listVersions() {
|
|
103
|
+
return (await this.storage.status(this.objId)).listVersions();
|
|
104
|
+
}
|
|
105
|
+
async archiveCurrent(version) {
|
|
106
|
+
if (this.isInSyncedStorage) {
|
|
107
|
+
const storage = this.syncedStorage();
|
|
108
|
+
const status = await storage.status(this.objId);
|
|
109
|
+
const { state, synced } = status.syncStatus();
|
|
110
|
+
if (state !== 'synced') {
|
|
111
|
+
throw (0, exceptions_1.makeFSSyncException)(this.name, { notSynced: true });
|
|
120
112
|
}
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
if (version) {
|
|
114
|
+
if (synced.latest !== version) {
|
|
115
|
+
throw (0, exceptions_1.makeFSSyncException)(this.name, { versionMismatch: true });
|
|
116
|
+
}
|
|
123
117
|
}
|
|
124
118
|
else {
|
|
125
|
-
|
|
119
|
+
version = synced.latest;
|
|
126
120
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!this.remoteEvents) {
|
|
131
|
-
this.remoteEvents = [];
|
|
132
|
-
}
|
|
133
|
-
this.remoteEvents.push(event);
|
|
134
|
-
if (this.remoteEvents.length > 1) {
|
|
135
|
-
// XXX attempt to compress events
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
getBufferedEvent() {
|
|
139
|
-
if (!this.remoteEvents) {
|
|
140
|
-
return;
|
|
121
|
+
await storage.archiveVersionOnServer(this.objId, version);
|
|
122
|
+
await status.archiveCurrentVersion();
|
|
123
|
+
return version;
|
|
141
124
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
125
|
+
else {
|
|
126
|
+
if (version) {
|
|
127
|
+
if (this.currentVersion !== version) {
|
|
128
|
+
throw (0, file_1.makeFileException)('versionMismatch', this.name);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
version = this.currentVersion;
|
|
133
|
+
}
|
|
134
|
+
const status = await this.storage.status(this.objId);
|
|
135
|
+
await status.archiveCurrentVersion();
|
|
136
|
+
return version;
|
|
145
137
|
}
|
|
146
|
-
return event;
|
|
147
138
|
}
|
|
148
|
-
|
|
149
|
-
|
|
139
|
+
removeNonFolderObj(src) {
|
|
140
|
+
(0, assert_1.assert)(this.type !== 'folder');
|
|
141
|
+
return this.doChange(true, () => this.removeThisNodeAsLeaf(src));
|
|
150
142
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this.broadcastEvent({
|
|
154
|
-
type: 'sync-upload',
|
|
155
|
-
path: this.name,
|
|
156
|
-
current: this.version,
|
|
157
|
-
uploaded: task.version
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* This non-synchronized method deletes object from storage, and detaches
|
|
163
|
-
* this node from storage. Make sure to call it inside access synchronization
|
|
164
|
-
* construct.
|
|
165
|
-
*/
|
|
166
|
-
async delete(remoteEvent) {
|
|
167
|
-
if (remoteEvent) {
|
|
168
|
-
// XXX
|
|
169
|
-
throw Error(`Removal from remote side is not implemented, yet.`);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
await this.storage.removeObj(this.objId);
|
|
173
|
-
}
|
|
143
|
+
async removeThisNodeAsLeaf(src) {
|
|
144
|
+
await this.storage.removeObj(this.objId);
|
|
174
145
|
this.storage.nodes.delete(this);
|
|
175
146
|
this.currentVersion = -1;
|
|
176
147
|
const event = {
|
|
177
148
|
type: 'removed',
|
|
178
149
|
path: this.name,
|
|
179
|
-
|
|
150
|
+
src
|
|
180
151
|
};
|
|
181
152
|
this.broadcastEvent(event, true);
|
|
182
153
|
}
|
|
@@ -197,90 +168,224 @@ class NodeInFS {
|
|
|
197
168
|
this.writeProc = new synced_1.SingleProc();
|
|
198
169
|
}
|
|
199
170
|
if (!awaitPrevChange && this.writeProc.isProcessing()) {
|
|
200
|
-
throw file_1.makeFileException(
|
|
171
|
+
throw (0, file_1.makeFileException)('concurrentUpdate', this.name + ` type ${this.type}`);
|
|
201
172
|
}
|
|
202
|
-
const res = await this.writeProc.startOrChain(() => {
|
|
173
|
+
const res = await this.writeProc.startOrChain(async () => {
|
|
203
174
|
if (this.currentVersion < 0) {
|
|
204
|
-
throw file_1.makeFileException(
|
|
175
|
+
throw (0, file_1.makeFileException)('notFound', this.name, `Object is marked removed`);
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const res = await change();
|
|
179
|
+
return res;
|
|
205
180
|
}
|
|
206
|
-
|
|
207
|
-
.catch((exc) => {
|
|
181
|
+
catch (exc) {
|
|
208
182
|
if (!exc.runtimeException) {
|
|
209
|
-
throw error_1.errWithCause(exc, `Cannot save changes to ${this.type} ${this.name}, version ${this.version}`);
|
|
183
|
+
throw (0, error_1.errWithCause)(exc, `Cannot save changes to ${this.type} ${this.name}, version ${this.version}`);
|
|
210
184
|
}
|
|
211
185
|
if (exc.type === 'storage') {
|
|
212
186
|
if (exc.concurrentTransaction) {
|
|
213
|
-
throw file_1.makeFileException(
|
|
187
|
+
throw (0, file_1.makeFileException)('concurrentUpdate', this.name, exc);
|
|
214
188
|
}
|
|
215
189
|
else if (exc.objNotFound) {
|
|
216
|
-
throw file_1.makeFileException(
|
|
190
|
+
throw (0, file_1.makeFileException)('notFound', this.name, exc);
|
|
217
191
|
}
|
|
218
192
|
}
|
|
219
|
-
|
|
220
|
-
|
|
193
|
+
else if ((exc.type === 'file')
|
|
194
|
+
|| (exc.type === 'fs-sync')) {
|
|
195
|
+
throw exc;
|
|
196
|
+
}
|
|
197
|
+
throw (0, file_1.makeFileException)('ioError', this.name, exc);
|
|
198
|
+
}
|
|
221
199
|
});
|
|
222
200
|
return res;
|
|
223
201
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
throw new Error('Unimplemented, yet');
|
|
232
|
-
// OLD CODE BELOW
|
|
233
|
-
// if (remoteVersion < this.version) { return; }
|
|
234
|
-
// await (this.storage as SyncedStorage).setCurrentSyncedVersion(
|
|
235
|
-
// this.objId, remoteVersion);
|
|
236
|
-
// this.setCurrentVersion(remoteVersion);
|
|
202
|
+
broadcastEvent(event, complete, childObjId) {
|
|
203
|
+
if (this.events && complete) {
|
|
204
|
+
this.events.sink.next(event);
|
|
205
|
+
this.events.sink.complete();
|
|
206
|
+
this.events = undefined;
|
|
207
|
+
}
|
|
208
|
+
this.storage.broadcastNodeEvent(this.objId, this.parentId, childObjId, event);
|
|
237
209
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
210
|
+
get event$() {
|
|
211
|
+
if (!this.events) {
|
|
212
|
+
const sink = new rxjs_1.Subject();
|
|
213
|
+
const out = sink.asObservable().pipe((0, operators_1.share)());
|
|
214
|
+
const storeSub = this.storage.getNodeEvents()
|
|
215
|
+
.pipe((0, operators_1.filter)(({ objId }) => (this.objId === objId)), (0, operators_1.map)(({ event }) => copyWithPathIfRemoteEvent(event, this.name)))
|
|
216
|
+
.subscribe({
|
|
217
|
+
next: event => sink.next(event),
|
|
218
|
+
complete: () => {
|
|
219
|
+
var _a;
|
|
220
|
+
sink.complete();
|
|
221
|
+
if (((_a = this.events) === null || _a === void 0 ? void 0 : _a.sink) === sink) {
|
|
222
|
+
this.events = undefined;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
error: err => {
|
|
226
|
+
var _a;
|
|
227
|
+
sink.error(err);
|
|
228
|
+
if (((_a = this.events) === null || _a === void 0 ? void 0 : _a.sink) === sink) {
|
|
229
|
+
this.events = undefined;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
this.events = { sink, out, storeSub };
|
|
245
234
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
235
|
+
return this.events.out;
|
|
236
|
+
}
|
|
237
|
+
syncedStorage() {
|
|
238
|
+
if (!this.isInSyncedStorage) {
|
|
239
|
+
throw new Error(`Storage is not synced`);
|
|
250
240
|
}
|
|
251
|
-
this.
|
|
252
|
-
const event = {
|
|
253
|
-
type: 'file-change',
|
|
254
|
-
path: this.name,
|
|
255
|
-
isRemote: true
|
|
256
|
-
};
|
|
257
|
-
this.broadcastEvent(event);
|
|
241
|
+
return this.storage;
|
|
258
242
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
243
|
+
async syncStatus() {
|
|
244
|
+
const storage = this.syncedStorage();
|
|
245
|
+
const status = (await storage.status(this.objId)).syncStatus();
|
|
246
|
+
if (this.parentId) {
|
|
247
|
+
const parent = storage.nodes.get(this.parentId);
|
|
248
|
+
if (parent) {
|
|
249
|
+
status.existsInSyncedParent =
|
|
250
|
+
await parent.childExistsInSyncedVersion(this.objId);
|
|
251
|
+
}
|
|
263
252
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
253
|
+
return status;
|
|
254
|
+
}
|
|
255
|
+
async updateStatusInfo() {
|
|
256
|
+
const storage = this.syncedStorage();
|
|
257
|
+
const status = await storage.updateStatusInfo(this.objId);
|
|
258
|
+
return status;
|
|
259
|
+
}
|
|
260
|
+
isSyncedVersionOnDisk(version) {
|
|
261
|
+
const storage = this.syncedStorage();
|
|
262
|
+
return storage.isRemoteVersionOnDisk(this.objId, version);
|
|
263
|
+
}
|
|
264
|
+
async download(version) {
|
|
265
|
+
const storage = this.syncedStorage();
|
|
266
|
+
return storage.download(this.objId, version);
|
|
267
|
+
}
|
|
268
|
+
adoptRemote(opts) {
|
|
269
|
+
return this.doChange(true, async () => {
|
|
270
|
+
const storage = this.syncedStorage();
|
|
271
|
+
try {
|
|
272
|
+
const adopted = await storage.adoptRemote(this.objId, opts);
|
|
273
|
+
if (!adopted) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const src = await this.storage.getObjSrc(this.objId, adopted);
|
|
277
|
+
await this.setCurrentStateFrom(src);
|
|
278
|
+
const event = {
|
|
279
|
+
type: 'file-change',
|
|
280
|
+
src: 'sync',
|
|
281
|
+
path: this.name,
|
|
282
|
+
newVersion: this.version
|
|
283
|
+
};
|
|
284
|
+
this.broadcastEvent(event);
|
|
285
|
+
}
|
|
286
|
+
catch (exc) {
|
|
287
|
+
throw (0, common_1.setPathInExc)(exc, this.name);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
async needUpload(localVersion) {
|
|
292
|
+
const { local, remote, synced } = await this.syncStatus();
|
|
293
|
+
if (localVersion) {
|
|
294
|
+
if (localVersion !== this.currentVersion) {
|
|
295
|
+
throw (0, exceptions_1.makeFSSyncException)(this.name, {
|
|
296
|
+
versionMismatch: true,
|
|
297
|
+
localVersion: this.currentVersion,
|
|
298
|
+
message: `Given local version ${localVersion} is not equal to current version ${this.currentVersion}`
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (!local || (local.latest !== localVersion)) {
|
|
302
|
+
throw (0, exceptions_1.makeFSSyncException)(this.name, {
|
|
303
|
+
versionMismatch: true,
|
|
304
|
+
message: `No local version ${localVersion} to upload`
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
if (!local || !this.currentVersion) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
localVersion = this.currentVersion;
|
|
313
|
+
}
|
|
314
|
+
if (remote) {
|
|
315
|
+
if (remote.latest) {
|
|
316
|
+
const uploadVersion = remote.latest + 1;
|
|
317
|
+
return { createOnRemote: false, localVersion, uploadVersion };
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
throw (0, exceptions_1.makeFSSyncException)(this.name, {
|
|
321
|
+
versionMismatch: true,
|
|
322
|
+
removedOnServer: true
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else if (synced) {
|
|
327
|
+
if (synced.latest) {
|
|
328
|
+
const uploadVersion = synced.latest + 1;
|
|
329
|
+
return { createOnRemote: false, localVersion, uploadVersion };
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
throw (0, exceptions_1.makeFSSyncException)(this.name, {
|
|
333
|
+
versionMismatch: true,
|
|
334
|
+
removedOnServer: true
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
const uploadVersion = 1;
|
|
340
|
+
return { createOnRemote: true, localVersion, uploadVersion };
|
|
268
341
|
}
|
|
269
342
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
this.
|
|
343
|
+
async upload(opts) {
|
|
344
|
+
try {
|
|
345
|
+
const toUpload = await this.needUpload(opts === null || opts === void 0 ? void 0 : opts.localVersion);
|
|
346
|
+
if (!toUpload) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const { localVersion, createOnRemote, uploadVersion } = toUpload;
|
|
350
|
+
const uploadHeader = await this.uploadHeaderChange(localVersion, uploadVersion);
|
|
351
|
+
const storage = this.syncedStorage();
|
|
352
|
+
await storage.upload(this.objId, localVersion, uploadVersion, uploadHeader, createOnRemote);
|
|
353
|
+
await this.doChange(true, async () => {
|
|
354
|
+
storage.dropCachedLocalObjVersionsLessOrEqual(this.objId, localVersion);
|
|
355
|
+
if (this.currentVersion === localVersion) {
|
|
356
|
+
this.currentVersion = uploadVersion;
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
catch (exc) {
|
|
361
|
+
throw (0, common_1.setPathInExc)(exc, this.name);
|
|
273
362
|
}
|
|
274
|
-
return this.events.asObservable().pipe(operators_1.share());
|
|
275
363
|
}
|
|
276
|
-
async
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
return this.storage.getObjSyncInfo(this.objId);
|
|
364
|
+
async uploadHeaderChange(localVersion, uploadVersion) {
|
|
365
|
+
if (localVersion === uploadVersion) {
|
|
366
|
+
return;
|
|
280
367
|
}
|
|
368
|
+
const currentSrc = await this.storage.getObjSrc(this.objId, localVersion);
|
|
369
|
+
const localHeader = await currentSrc.readHeader();
|
|
370
|
+
const uploadHeader = await this.crypto.reencryptHeader(localHeader, uploadVersion);
|
|
371
|
+
return { localHeader, localVersion, uploadHeader, uploadVersion };
|
|
281
372
|
}
|
|
282
373
|
}
|
|
283
374
|
exports.NodeInFS = NodeInFS;
|
|
284
375
|
Object.freeze(NodeInFS.prototype);
|
|
285
376
|
Object.freeze(NodeInFS);
|
|
377
|
+
function copyWithPathIfRemoteEvent(e, path) {
|
|
378
|
+
switch (e.type) {
|
|
379
|
+
case 'remote-change':
|
|
380
|
+
return { type: e.type, path, newVersion: e.newVersion };
|
|
381
|
+
case 'remote-removal':
|
|
382
|
+
return { type: e.type, path };
|
|
383
|
+
case 'remote-version-archival':
|
|
384
|
+
return { type: e.type, path, archivedVersion: e.archivedVersion };
|
|
385
|
+
case 'remote-arch-ver-removal':
|
|
386
|
+
return { type: e.type, path, removedArchVer: e.removedArchVer };
|
|
387
|
+
default:
|
|
388
|
+
return e;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
286
391
|
Object.freeze(exports);
|
|
@@ -32,7 +32,7 @@ export declare abstract class NodePersistance {
|
|
|
32
32
|
sinkPromise: Promise<FileByteSink>;
|
|
33
33
|
sub: Subscribe;
|
|
34
34
|
}>;
|
|
35
|
-
reencryptHeader
|
|
35
|
+
reencryptHeader(initHeader: Uint8Array, newVersion: number): Promise<Uint8Array>;
|
|
36
36
|
}
|
|
37
37
|
declare type FileByteSource = web3n.files.FileByteSource;
|
|
38
38
|
declare type FileByteSink = web3n.files.FileByteSink;
|