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
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.wrapSyncStorageImplementation = exports.wrapStorageImplementation = exports.NodesContainer = void 0;
|
|
19
|
+
exports.setPathInExc = exports.isSyncedStorage = exports.wrapSyncStorageImplementation = exports.wrapStorageImplementation = exports.NodesContainer = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* This is a container for file system nodes.
|
|
22
22
|
*
|
|
@@ -98,14 +98,16 @@ function wrapStorageImplementation(impl) {
|
|
|
98
98
|
type: impl.type,
|
|
99
99
|
versioned: impl.versioned,
|
|
100
100
|
nodes: impl.nodes,
|
|
101
|
+
logError: impl.logError,
|
|
101
102
|
getNodeEvents: impl.getNodeEvents.bind(impl),
|
|
102
103
|
broadcastNodeEvent: impl.broadcastNodeEvent.bind(impl),
|
|
103
104
|
storageForLinking: impl.storageForLinking.bind(impl),
|
|
104
105
|
generateNewObjId: impl.generateNewObjId.bind(impl),
|
|
105
|
-
|
|
106
|
+
getObjSrc: impl.getObjSrc.bind(impl),
|
|
106
107
|
saveObj: impl.saveObj.bind(impl),
|
|
107
108
|
close: impl.close.bind(impl),
|
|
108
109
|
removeObj: impl.removeObj.bind(impl),
|
|
110
|
+
status: impl.status.bind(impl),
|
|
109
111
|
cryptor: impl.cryptor
|
|
110
112
|
};
|
|
111
113
|
return Object.freeze(wrap);
|
|
@@ -113,24 +115,33 @@ function wrapStorageImplementation(impl) {
|
|
|
113
115
|
exports.wrapStorageImplementation = wrapStorageImplementation;
|
|
114
116
|
function wrapSyncStorageImplementation(impl) {
|
|
115
117
|
const storageWrap = wrapStorageImplementation(impl);
|
|
116
|
-
const wrap = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
getObjSyncInfo: impl.getObjSyncInfo.bind(impl)
|
|
132
|
-
};
|
|
118
|
+
const wrap = {};
|
|
119
|
+
for (const [field, value] of Object.entries(storageWrap)) {
|
|
120
|
+
wrap[field] = value;
|
|
121
|
+
}
|
|
122
|
+
wrap.getRootKeyDerivParamsFromServer =
|
|
123
|
+
impl.getRootKeyDerivParamsFromServer.bind(impl);
|
|
124
|
+
wrap.getObjSrcOfRemoteVersion = impl.getObjSrcOfRemoteVersion.bind(impl);
|
|
125
|
+
wrap.archiveVersionOnServer = impl.archiveVersionOnServer.bind(impl);
|
|
126
|
+
wrap.isRemoteVersionOnDisk = impl.isRemoteVersionOnDisk.bind(impl);
|
|
127
|
+
wrap.download = impl.download.bind(impl);
|
|
128
|
+
wrap.upload = impl.upload.bind(impl);
|
|
129
|
+
wrap.uploadObjRemoval = impl.uploadObjRemoval.bind(impl);
|
|
130
|
+
wrap.dropCachedLocalObjVersionsLessOrEqual = impl.dropCachedLocalObjVersionsLessOrEqual.bind(impl);
|
|
131
|
+
wrap.adoptRemote = impl.adoptRemote.bind(impl);
|
|
132
|
+
wrap.updateStatusInfo = impl.updateStatusInfo.bind(impl);
|
|
133
133
|
return Object.freeze(wrap);
|
|
134
134
|
}
|
|
135
135
|
exports.wrapSyncStorageImplementation = wrapSyncStorageImplementation;
|
|
136
|
+
function isSyncedStorage(storage) {
|
|
137
|
+
return !!storage.upload;
|
|
138
|
+
}
|
|
139
|
+
exports.isSyncedStorage = isSyncedStorage;
|
|
140
|
+
function setPathInExc(exc, path) {
|
|
141
|
+
if ((exc.type === 'fs-sync') || (exc.type === 'file')) {
|
|
142
|
+
exc.path = path;
|
|
143
|
+
}
|
|
144
|
+
return exc;
|
|
145
|
+
}
|
|
146
|
+
exports.setPathInExc = setPathInExc;
|
|
136
147
|
Object.freeze(exports);
|
|
@@ -45,6 +45,7 @@ export declare class FileNode extends NodeInFS<FilePersistance> {
|
|
|
45
45
|
static makeForExisting(storage: Storage, parentId: string, fileName: string, objId: string, key: Uint8Array): Promise<FileNode>;
|
|
46
46
|
static makeFromLinkParams(storage: Storage, params: FileLinkParams): Promise<FileNode>;
|
|
47
47
|
private static initWithAttrs;
|
|
48
|
+
protected setCurrentStateFrom(src: ObjSource): Promise<void>;
|
|
48
49
|
private setUpdatedState;
|
|
49
50
|
get size(): number;
|
|
50
51
|
readSrc(): Promise<{
|
|
@@ -97,7 +97,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
97
97
|
if (!fileName || !objId) {
|
|
98
98
|
throw new Error("Bad file parameter(s) given");
|
|
99
99
|
}
|
|
100
|
-
this.crypto = new FilePersistance(xsp_files_1.idToHeaderNonce(this.objId), key, this.storage.cryptor);
|
|
100
|
+
this.crypto = new FilePersistance((0, xsp_files_1.idToHeaderNonce)(this.objId), key, this.storage.cryptor);
|
|
101
101
|
Object.seal(this);
|
|
102
102
|
}
|
|
103
103
|
static async makeForNew(storage, parentId, name, key) {
|
|
@@ -123,12 +123,15 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
123
123
|
return file;
|
|
124
124
|
}
|
|
125
125
|
static async initWithAttrs(storage, parentId, fileName, objId, key) {
|
|
126
|
-
const src = await storage.
|
|
126
|
+
const src = await storage.getObjSrc(objId);
|
|
127
127
|
const file = new FileNode(storage, fileName, objId, src.version, parentId, key);
|
|
128
|
-
|
|
129
|
-
file.setUpdatedState(src.version, fileAttrs);
|
|
128
|
+
await file.setCurrentStateFrom(src);
|
|
130
129
|
return file;
|
|
131
130
|
}
|
|
131
|
+
async setCurrentStateFrom(src) {
|
|
132
|
+
const fileAttrs = await this.crypto.getAttrs(src);
|
|
133
|
+
this.setUpdatedState(src.version, fileAttrs);
|
|
134
|
+
}
|
|
132
135
|
setUpdatedState(version, fileAttrs) {
|
|
133
136
|
this.fileSize = fileAttrs.size;
|
|
134
137
|
super.setUpdatedParams(version, fileAttrs.attrs, fileAttrs.xattrs);
|
|
@@ -137,7 +140,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
137
140
|
return this.fileSize;
|
|
138
141
|
}
|
|
139
142
|
async readSrc() {
|
|
140
|
-
const objSrc = await this.storage.
|
|
143
|
+
const objSrc = await this.storage.getObjSrc(this.objId);
|
|
141
144
|
if ((this.storage.type === 'synced') || (this.storage.type === 'local')) {
|
|
142
145
|
const version = objSrc.version;
|
|
143
146
|
if (this.version < version) {
|
|
@@ -157,7 +160,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
162
|
async readBytes(start, end) {
|
|
160
|
-
const objSrc = await this.storage.
|
|
163
|
+
const objSrc = await this.storage.getObjSrc(this.objId);
|
|
161
164
|
if ((this.storage.type === 'synced') || (this.storage.type === 'local')) {
|
|
162
165
|
const version = objSrc.version;
|
|
163
166
|
if (this.version < version) {
|
|
@@ -177,8 +180,8 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
182
|
async writeSink(truncate, currentVersion, changes) {
|
|
180
|
-
const deferredSink = deferred_1.defer();
|
|
181
|
-
const newSize = deferred_1.defer();
|
|
183
|
+
const deferredSink = (0, deferred_1.defer)();
|
|
184
|
+
const newSize = (0, deferred_1.defer)();
|
|
182
185
|
let version = 0; // need to set any value to satisfy compiler
|
|
183
186
|
const completion = this.doChange(false, async () => {
|
|
184
187
|
const { attrs, xattrs, newVersion, sinkPromise, sub } = await this.startMakingSinkInsideChange(truncate, currentVersion, changes);
|
|
@@ -194,12 +197,12 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
194
197
|
}),
|
|
195
198
|
completion
|
|
196
199
|
]);
|
|
197
|
-
assert_1.assert(!!sink);
|
|
200
|
+
(0, assert_1.assert)(!!sink);
|
|
198
201
|
// sink's done should await completion of obj saving, and
|
|
199
202
|
// error in obj saving should cancel sink
|
|
200
203
|
const originalDone = sink.done;
|
|
201
204
|
completion.catch(originalDone);
|
|
202
|
-
assert_1.assert(!Object.isFrozen(sink), `Can't mutate frozen sink`);
|
|
205
|
+
(0, assert_1.assert)(!Object.isFrozen(sink), `Can't mutate frozen sink`);
|
|
203
206
|
sink.done = async (err) => {
|
|
204
207
|
if (err) {
|
|
205
208
|
newSize.resolve(0);
|
|
@@ -218,12 +221,12 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
218
221
|
async startMakingSinkInsideChange(truncate, currentVersion, changes) {
|
|
219
222
|
if ((typeof currentVersion === 'number')
|
|
220
223
|
&& (this.version !== currentVersion)) {
|
|
221
|
-
throw file_1.makeVersionMismatchExc(this.name);
|
|
224
|
+
throw (0, file_1.makeVersionMismatchExc)(this.name);
|
|
222
225
|
}
|
|
223
226
|
const { attrs, xattrs, newVersion } = super.getParamsForUpdate(changes);
|
|
224
227
|
const base = ((truncate || (this.version === 0)) ?
|
|
225
228
|
undefined :
|
|
226
|
-
await this.storage.
|
|
229
|
+
await this.storage.getObjSrc(this.objId));
|
|
227
230
|
const { sinkPromise, sub } = await this.crypto.getFileSink(newVersion, attrs, xattrs, base);
|
|
228
231
|
return { attrs, xattrs, newVersion, sinkPromise, sub };
|
|
229
232
|
}
|
|
@@ -234,6 +237,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
234
237
|
this.broadcastEvent({
|
|
235
238
|
type: 'file-change',
|
|
236
239
|
path: this.name,
|
|
240
|
+
src: 'local',
|
|
237
241
|
newVersion
|
|
238
242
|
});
|
|
239
243
|
}
|
|
@@ -242,7 +246,7 @@ class FileNode extends node_in_fs_1.NodeInFS {
|
|
|
242
246
|
const { attrs, xattrs, newVersion } = super.getParamsForUpdate(changes);
|
|
243
247
|
const encSub = await this.crypto.saveBytes(bytes, newVersion, attrs, xattrs);
|
|
244
248
|
const newSize = Promise.resolve(Array.isArray(bytes) ?
|
|
245
|
-
buffer_utils_1.byteLengthIn(bytes) : bytes.length);
|
|
249
|
+
(0, buffer_utils_1.byteLengthIn)(bytes) : bytes.length);
|
|
246
250
|
await this.savingObjInsideChange(attrs, newSize, xattrs, newVersion, encSub);
|
|
247
251
|
return this.version;
|
|
248
252
|
});
|
|
@@ -10,6 +10,11 @@ declare type Observer<T> = web3n.Observer<T>;
|
|
|
10
10
|
declare type FileByteSource = web3n.files.FileByteSource;
|
|
11
11
|
declare type FileByteSink = web3n.files.FileByteSink;
|
|
12
12
|
declare type XAttrsChanges = web3n.files.XAttrsChanges;
|
|
13
|
+
declare type WritableFileSyncAPI = web3n.files.WritableFileSyncAPI;
|
|
14
|
+
declare type SyncStatus = web3n.files.SyncStatus;
|
|
15
|
+
declare type WritableFileVersionedAPI = web3n.files.WritableFileVersionedAPI;
|
|
16
|
+
declare type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
|
|
17
|
+
declare type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
|
|
13
18
|
export declare class FileObject implements WritableFile, Linkable {
|
|
14
19
|
name: string;
|
|
15
20
|
isNew: boolean;
|
|
@@ -17,7 +22,7 @@ export declare class FileObject implements WritableFile, Linkable {
|
|
|
17
22
|
v: V;
|
|
18
23
|
private constructor();
|
|
19
24
|
static makeExisting(node: FileNode, writable: boolean): WritableFile | ReadonlyFile;
|
|
20
|
-
static makeForNotExisiting(name: string, makeNode: () => Promise<FileNode
|
|
25
|
+
static makeForNotExisiting(name: string, makeNode: () => Promise<FileNode>, isInSyncedStorage: boolean): WritableFile;
|
|
21
26
|
static makeFileFromLinkParams(storage: Storage, params: LinkParameters<FileLinkParams>): Promise<WritableFile | ReadonlyFile>;
|
|
22
27
|
getLinkParams(): Promise<LinkParameters<FileLinkParams>>;
|
|
23
28
|
stat(): Promise<Stats>;
|
|
@@ -35,14 +40,19 @@ export declare class FileObject implements WritableFile, Linkable {
|
|
|
35
40
|
getByteSink(truncate?: boolean): Promise<FileByteSink>;
|
|
36
41
|
copy(file: File): Promise<void>;
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
interface N {
|
|
44
|
+
getNode(): Promise<FileNode>;
|
|
45
|
+
ensureIsWritable(): void;
|
|
46
|
+
}
|
|
47
|
+
declare class V implements WritableFileVersionedAPI, N {
|
|
40
48
|
name: string;
|
|
41
49
|
node: FileNode | undefined;
|
|
42
50
|
private makeOrGetNode;
|
|
43
|
-
writable: boolean;
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
readonly writable: boolean;
|
|
52
|
+
readonly sync: undefined | S;
|
|
53
|
+
constructor(name: string, node: FileNode | undefined, makeOrGetNode: (() => Promise<FileNode>) | undefined, writable: boolean, isInSyncedStorage: boolean);
|
|
54
|
+
getNode(): Promise<FileNode>;
|
|
55
|
+
ensureIsWritable(): void;
|
|
46
56
|
updateXAttrs(changes: XAttrsChanges): Promise<number>;
|
|
47
57
|
getXAttr(xaName: string): Promise<{
|
|
48
58
|
attr: any;
|
|
@@ -77,5 +87,20 @@ declare class V implements WritableFileVersionedAPI {
|
|
|
77
87
|
json: T;
|
|
78
88
|
version: number;
|
|
79
89
|
}>;
|
|
90
|
+
archiveCurrent(version?: number): Promise<number>;
|
|
91
|
+
listVersions(): Promise<{
|
|
92
|
+
current?: number;
|
|
93
|
+
archived?: number[];
|
|
94
|
+
}>;
|
|
95
|
+
}
|
|
96
|
+
declare class S implements WritableFileSyncAPI {
|
|
97
|
+
private readonly n;
|
|
98
|
+
constructor(n: N);
|
|
99
|
+
upload(opts?: OptionsToUploadLocal): Promise<void>;
|
|
100
|
+
status(): Promise<SyncStatus>;
|
|
101
|
+
updateStatusInfo(): Promise<SyncStatus>;
|
|
102
|
+
isRemoteVersionOnDisk(version: number): Promise<'complete' | 'partial' | 'none'>;
|
|
103
|
+
download(version: number): Promise<void>;
|
|
104
|
+
adoptRemote(opts?: OptionsToAdopteRemote): Promise<void>;
|
|
80
105
|
}
|
|
81
106
|
export {};
|
|
@@ -28,46 +28,39 @@ const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
|
28
28
|
const pipe_1 = require("../../../lib-common/byte-streaming/pipe");
|
|
29
29
|
const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
|
|
30
30
|
class FileObject {
|
|
31
|
-
constructor(name, isNew, node, makeOrGetNode, writable) {
|
|
31
|
+
constructor(name, isNew, node, makeOrGetNode, writable, isInSyncedStorage) {
|
|
32
32
|
this.name = name;
|
|
33
33
|
this.isNew = isNew;
|
|
34
34
|
this.writable = writable;
|
|
35
|
-
this.v = new V(name, node, makeOrGetNode, writable);
|
|
35
|
+
this.v = new V(name, node, makeOrGetNode, writable, isInSyncedStorage);
|
|
36
36
|
Object.seal(this);
|
|
37
37
|
}
|
|
38
38
|
static makeExisting(node, writable) {
|
|
39
|
-
const f = new FileObject(node.name, false, node, undefined, writable);
|
|
40
|
-
return (writable ?
|
|
41
|
-
files_1.wrapWritableFile(f) : files_1.wrapReadonlyFile(f));
|
|
39
|
+
const f = new FileObject(node.name, false, node, undefined, writable, node.isInSyncedStorage);
|
|
40
|
+
return (writable ? (0, files_1.wrapWritableFile)(f) : (0, files_1.wrapReadonlyFile)(f));
|
|
42
41
|
}
|
|
43
|
-
static makeForNotExisiting(name, makeNode) {
|
|
44
|
-
const f = new FileObject(name, true, undefined, makeNode, true);
|
|
45
|
-
return files_1.wrapWritableFile(f);
|
|
42
|
+
static makeForNotExisiting(name, makeNode, isInSyncedStorage) {
|
|
43
|
+
const f = new FileObject(name, true, undefined, makeNode, true, isInSyncedStorage);
|
|
44
|
+
return (0, files_1.wrapWritableFile)(f);
|
|
46
45
|
}
|
|
47
46
|
static async makeFileFromLinkParams(storage, params) {
|
|
48
47
|
const node = await file_node_1.FileNode.makeFromLinkParams(storage, params.params);
|
|
49
48
|
return FileObject.makeExisting(node, !params.readonly);
|
|
50
49
|
}
|
|
51
50
|
async getLinkParams() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
const linkParams = this.v.node.getParamsForLink();
|
|
51
|
+
const node = await this.v.getNode();
|
|
52
|
+
const linkParams = node.getParamsForLink();
|
|
56
53
|
linkParams.params.fileName = this.name;
|
|
57
54
|
linkParams.readonly = !this.writable;
|
|
58
55
|
return linkParams;
|
|
59
56
|
}
|
|
60
57
|
async stat() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
const sync = await this.v.node.sync();
|
|
65
|
-
const attrs = this.v.node.getAttrs();
|
|
58
|
+
const node = await this.v.getNode();
|
|
59
|
+
const attrs = node.getAttrs();
|
|
66
60
|
const stat = {
|
|
67
61
|
writable: this.writable,
|
|
68
|
-
size:
|
|
69
|
-
version:
|
|
70
|
-
sync,
|
|
62
|
+
size: node.size,
|
|
63
|
+
version: node.version,
|
|
71
64
|
isFile: true,
|
|
72
65
|
ctime: new Date(attrs.ctime),
|
|
73
66
|
mtime: new Date(attrs.mtime),
|
|
@@ -90,7 +83,7 @@ class FileObject {
|
|
|
90
83
|
throw new Error(`Node for file ${this.name} is not yet initialized`);
|
|
91
84
|
}
|
|
92
85
|
const sub = this.v.node.event$
|
|
93
|
-
.subscribe(utils_for_observables_1.toRxObserver(observer));
|
|
86
|
+
.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
|
|
94
87
|
return () => sub.unsubscribe();
|
|
95
88
|
}
|
|
96
89
|
async readBytes(start, end) {
|
|
@@ -130,11 +123,12 @@ exports.FileObject = FileObject;
|
|
|
130
123
|
Object.freeze(FileObject.prototype);
|
|
131
124
|
Object.freeze(FileObject);
|
|
132
125
|
class V {
|
|
133
|
-
constructor(name, node, makeOrGetNode, writable) {
|
|
126
|
+
constructor(name, node, makeOrGetNode, writable, isInSyncedStorage) {
|
|
134
127
|
this.name = name;
|
|
135
128
|
this.node = node;
|
|
136
129
|
this.makeOrGetNode = makeOrGetNode;
|
|
137
130
|
this.writable = writable;
|
|
131
|
+
this.sync = (isInSyncedStorage ? new S(this) : undefined);
|
|
138
132
|
Object.seal(this);
|
|
139
133
|
}
|
|
140
134
|
async getNode() {
|
|
@@ -144,7 +138,13 @@ class V {
|
|
|
144
138
|
}
|
|
145
139
|
return this.node;
|
|
146
140
|
}
|
|
141
|
+
ensureIsWritable() {
|
|
142
|
+
if (!this.writable) {
|
|
143
|
+
throw new Error(`File is not writable`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
147
146
|
async updateXAttrs(changes) {
|
|
147
|
+
this.ensureIsWritable();
|
|
148
148
|
const node = await this.getNode();
|
|
149
149
|
return node.updateXAttrs(changes);
|
|
150
150
|
}
|
|
@@ -172,16 +172,18 @@ class V {
|
|
|
172
172
|
return linkParams;
|
|
173
173
|
}
|
|
174
174
|
async getByteSink(truncate = true, currentVersion) {
|
|
175
|
+
this.ensureIsWritable();
|
|
175
176
|
const node = await this.getNode();
|
|
176
177
|
return node.writeSink(truncate, currentVersion);
|
|
177
178
|
}
|
|
178
179
|
async getByteSource() {
|
|
179
180
|
if (!this.node) {
|
|
180
|
-
throw file_1.makeFileException(
|
|
181
|
+
throw (0, file_1.makeFileException)('notFound', this.name);
|
|
181
182
|
}
|
|
182
183
|
return this.node.readSrc();
|
|
183
184
|
}
|
|
184
185
|
async writeBytes(bytes) {
|
|
186
|
+
this.ensureIsWritable();
|
|
185
187
|
const node = await this.getNode();
|
|
186
188
|
return node.save(bytes);
|
|
187
189
|
}
|
|
@@ -194,7 +196,7 @@ class V {
|
|
|
194
196
|
}
|
|
195
197
|
async readBytes(start, end) {
|
|
196
198
|
if (!this.node) {
|
|
197
|
-
throw file_1.makeFileException(
|
|
199
|
+
throw (0, file_1.makeFileException)('notFound', this.name);
|
|
198
200
|
}
|
|
199
201
|
return await this.node.readBytes(start, end);
|
|
200
202
|
}
|
|
@@ -207,7 +209,7 @@ class V {
|
|
|
207
209
|
const { version, sink } = await this.getByteSink();
|
|
208
210
|
const src = (file.v ?
|
|
209
211
|
(await file.v.getByteSource()).src : await file.getByteSource());
|
|
210
|
-
await pipe_1.pipe(src, sink);
|
|
212
|
+
await (0, pipe_1.pipe)(src, sink);
|
|
211
213
|
return version;
|
|
212
214
|
}
|
|
213
215
|
async readJSON() {
|
|
@@ -215,7 +217,53 @@ class V {
|
|
|
215
217
|
const json = JSON.parse(txt);
|
|
216
218
|
return { json, version };
|
|
217
219
|
}
|
|
220
|
+
async archiveCurrent(version) {
|
|
221
|
+
this.ensureIsWritable();
|
|
222
|
+
const node = await this.getNode();
|
|
223
|
+
return node.archiveCurrent(version);
|
|
224
|
+
}
|
|
225
|
+
async listVersions() {
|
|
226
|
+
const node = await this.getNode();
|
|
227
|
+
return node.listVersions();
|
|
228
|
+
}
|
|
218
229
|
}
|
|
219
230
|
Object.freeze(V.prototype);
|
|
220
231
|
Object.freeze(V);
|
|
232
|
+
class S {
|
|
233
|
+
constructor(n) {
|
|
234
|
+
this.n = n;
|
|
235
|
+
Object.freeze(this);
|
|
236
|
+
}
|
|
237
|
+
async upload(opts) {
|
|
238
|
+
this.n.ensureIsWritable();
|
|
239
|
+
const node = await this.n.getNode();
|
|
240
|
+
const uploadVersion = await node.upload(opts);
|
|
241
|
+
return uploadVersion;
|
|
242
|
+
}
|
|
243
|
+
async status() {
|
|
244
|
+
const node = await this.n.getNode();
|
|
245
|
+
const status = await node.syncStatus();
|
|
246
|
+
return status;
|
|
247
|
+
}
|
|
248
|
+
async updateStatusInfo() {
|
|
249
|
+
const node = await this.n.getNode();
|
|
250
|
+
const status = await node.updateStatusInfo();
|
|
251
|
+
return status;
|
|
252
|
+
}
|
|
253
|
+
async isRemoteVersionOnDisk(version) {
|
|
254
|
+
const node = await this.n.getNode();
|
|
255
|
+
const isOnDisk = await node.isSyncedVersionOnDisk(version);
|
|
256
|
+
return isOnDisk;
|
|
257
|
+
}
|
|
258
|
+
async download(version) {
|
|
259
|
+
const node = await this.n.getNode();
|
|
260
|
+
await node.download(version);
|
|
261
|
+
}
|
|
262
|
+
async adoptRemote(opts) {
|
|
263
|
+
const node = await this.n.getNode();
|
|
264
|
+
await node.adoptRemote(opts);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
Object.freeze(S.prototype);
|
|
268
|
+
Object.freeze(S);
|
|
221
269
|
Object.freeze(exports);
|
|
@@ -64,14 +64,14 @@ var formatV1;
|
|
|
64
64
|
o: nodeInfo.objId
|
|
65
65
|
};
|
|
66
66
|
const jsonBytes = buffer_utils_1.utf8.pack(JSON.stringify(json));
|
|
67
|
-
assert_1.assert(jsonBytes.length < 0xffffffff);
|
|
67
|
+
(0, assert_1.assert)(jsonBytes.length < 0xffffffff);
|
|
68
68
|
bytes.push(numberToBytes(jsonBytes.length));
|
|
69
69
|
bytes.push(jsonBytes);
|
|
70
70
|
return bytes;
|
|
71
71
|
}
|
|
72
72
|
function numberToBytes(x) {
|
|
73
73
|
const arr = Buffer.allocUnsafe(4);
|
|
74
|
-
big_endian_1.packUintTo4Bytes(x, arr, 0);
|
|
74
|
+
(0, big_endian_1.packUintTo4Bytes)(x, arr, 0);
|
|
75
75
|
return arr;
|
|
76
76
|
}
|
|
77
77
|
function parse(bytes) {
|
|
@@ -92,9 +92,9 @@ var formatV1;
|
|
|
92
92
|
if (bytes.length < (xsp_files_1.KEY_LENGTH + 4)) {
|
|
93
93
|
throw parsingException(`Cannot deserialize node key from bytes`);
|
|
94
94
|
}
|
|
95
|
-
const key = buffer_utils_1.makeUint8ArrayCopy(bytes.subarray(0, xsp_files_1.KEY_LENGTH));
|
|
95
|
+
const key = (0, buffer_utils_1.makeUint8ArrayCopy)(bytes.subarray(0, xsp_files_1.KEY_LENGTH));
|
|
96
96
|
bytes = bytes.subarray(xsp_files_1.KEY_LENGTH);
|
|
97
|
-
const jsonBytesLen = big_endian_1.uintFrom4Bytes(bytes);
|
|
97
|
+
const jsonBytesLen = (0, big_endian_1.uintFrom4Bytes)(bytes);
|
|
98
98
|
bytes = bytes.subarray(4);
|
|
99
99
|
try {
|
|
100
100
|
const json = JSON.parse(buffer_utils_1.utf8.open(bytes.subarray(0, jsonBytesLen)));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Storage,
|
|
1
|
+
import { Storage, NodeType } from './common';
|
|
2
2
|
import { NodeInFS } from './node-in-fs';
|
|
3
3
|
import { FileNode } from './file-node';
|
|
4
4
|
import { LinkNode } from './link-node';
|
|
@@ -8,6 +8,10 @@ import { CommonAttrs, XAttrs } from './attrs';
|
|
|
8
8
|
import { NodePersistance } from './node-persistence';
|
|
9
9
|
declare type ListingEntry = web3n.files.ListingEntry;
|
|
10
10
|
declare type XAttrsChanges = web3n.files.XAttrsChanges;
|
|
11
|
+
declare type FolderDiff = web3n.files.FolderDiff;
|
|
12
|
+
declare type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
|
|
13
|
+
declare type OptionsToAdoptRemoteItem = web3n.files.OptionsToAdoptRemoteItem;
|
|
14
|
+
declare type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
|
|
11
15
|
export interface NodeInfo {
|
|
12
16
|
/**
|
|
13
17
|
* This is a usual file name.
|
|
@@ -54,6 +58,7 @@ declare class FolderPersistance extends NodePersistance {
|
|
|
54
58
|
attrs: CommonAttrs;
|
|
55
59
|
xattrs?: XAttrs;
|
|
56
60
|
}>;
|
|
61
|
+
static readFolderContent(objId: string | null, key: Uint8Array, src: ObjSource, cryptor: AsyncSBoxCryptor): Promise<FolderInfo>;
|
|
57
62
|
}
|
|
58
63
|
export interface FolderLinkParams {
|
|
59
64
|
folderName: string;
|
|
@@ -68,21 +73,18 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
|
|
|
68
73
|
private static readNodeFromObjBytes;
|
|
69
74
|
static rootFromLinkParams(storage: Storage, params: FolderLinkParams): Promise<FolderNode>;
|
|
70
75
|
static rootFromJSON(storage: Storage, name: string | undefined, folderJson: FolderInJSON): FolderNode;
|
|
76
|
+
protected setCurrentStateFrom(src: ObjSource): Promise<void>;
|
|
77
|
+
adoptRemote(opts: OptionsToAdopteRemote | undefined): Promise<void>;
|
|
78
|
+
private callRemoveObjOn;
|
|
71
79
|
list(): {
|
|
72
80
|
lst: ListingEntry[];
|
|
73
81
|
version: number;
|
|
74
82
|
};
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
childExistsInSyncedVersion(childObjId: string): Promise<boolean>;
|
|
84
|
+
getNodeInfo(name: string, undefOnMissing?: boolean): NodeInfo | undefined;
|
|
77
85
|
hasChild(childName: string, throwIfMissing?: boolean): boolean;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* @return either node (promise for node), or a deferred, which promise has
|
|
81
|
-
* been registered under a given id, and, therefore, has to be resolved with
|
|
82
|
-
* node.
|
|
83
|
-
*/
|
|
84
|
-
private getNodeOrArrangePromise;
|
|
85
|
-
getNode<T extends Node>(type: NodeType | undefined, name: string, undefOnMissing?: boolean): Promise<T | undefined>;
|
|
86
|
+
getNode<T extends NodeInFS<any>>(type: NodeType | undefined, name: string, undefOnMissing?: boolean): Promise<T | undefined>;
|
|
87
|
+
private getOrMakeChildNodeForInfo;
|
|
86
88
|
getFolder(name: string, undefOnMissing?: boolean): Promise<FolderNode | undefined>;
|
|
87
89
|
getFile(name: string, undefOnMissing?: boolean): Promise<FileNode | undefined>;
|
|
88
90
|
getLink(name: string, undefOnMissing?: boolean): Promise<LinkNode | undefined>;
|
|
@@ -130,8 +132,25 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
|
|
|
130
132
|
*/
|
|
131
133
|
isEmpty(): boolean;
|
|
132
134
|
private getAllNodes;
|
|
133
|
-
|
|
135
|
+
private removeFolderObj;
|
|
136
|
+
private callRemoveObjOnAll;
|
|
137
|
+
private removeChildrenObjsInSyncedStorage;
|
|
138
|
+
private uploadRemovalOfObjs;
|
|
134
139
|
getParamsForLink(): LinkParameters<FolderLinkParams>;
|
|
135
|
-
|
|
140
|
+
upload(opts: OptionsToUploadLocal | undefined): Promise<void>;
|
|
141
|
+
private uploadRemovalOf;
|
|
142
|
+
private listRemovedInTreeToUploadRm;
|
|
143
|
+
protected needUpload(localVersion: number | undefined): Promise<{
|
|
144
|
+
localVersion: number;
|
|
145
|
+
uploadVersion: number;
|
|
146
|
+
createOnRemote: boolean;
|
|
147
|
+
} | undefined>;
|
|
148
|
+
private getNodesRemovedBetweenVersions;
|
|
149
|
+
adoptRemoteFolderItem(itemName: string, opts: OptionsToAdoptRemoteItem | undefined): Promise<number>;
|
|
150
|
+
private addRemoteChild;
|
|
151
|
+
private replaceLocalChildWithRemote;
|
|
152
|
+
diffCurrentAndRemote(remoteVersion: number | undefined): Promise<FolderDiff | undefined>;
|
|
153
|
+
private diffWithArchivedRemote;
|
|
154
|
+
private diffWithRemote;
|
|
136
155
|
}
|
|
137
156
|
export {};
|