core-3nweb-client-lib 0.25.6 → 0.27.0
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/README.md +2 -2
- package/build/api-defs/asmail.d.ts +1 -1
- package/build/api-defs/files.d.ts +282 -70
- package/build/core/app-files.js +7 -7
- package/build/core/asmail/config/common.js +4 -4
- 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 +7 -6
- package/build/core/asmail/delivery/msg.js +8 -7
- package/build/core/asmail/delivery/per-recipient-wip.js +3 -3
- package/build/core/asmail/inbox/attachments/fs.js +11 -1
- package/build/core/asmail/inbox/cached-msgs.js +3 -3
- package/build/core/asmail/inbox/inbox-events.js +5 -4
- package/build/core/asmail/inbox/index.js +12 -12
- package/build/core/asmail/inbox/msg-downloader.js +3 -3
- package/build/core/asmail/inbox/msg-indexing.js +4 -4
- package/build/core/asmail/inbox/msg-on-disk.js +7 -7
- 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 +4 -3
- 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 +4 -4
- package/build/core/asmail/sending-params/params-from-others.js +3 -3
- package/build/core/id-manager.js +8 -5
- package/build/core/index.d.ts +2 -1
- package/build/core/index.js +14 -14
- package/build/core/sign-in.d.ts +5 -4
- package/build/core/sign-in.js +12 -14
- package/build/core/sign-up.d.ts +1 -0
- package/build/core/sign-up.js +15 -11
- package/build/core/storage/common/json-saving.d.ts +21 -0
- package/build/core/storage/common/json-saving.js +82 -0
- package/build/core/storage/common/obj-info-file.d.ts +51 -0
- package/build/core/storage/common/obj-info-file.js +153 -5
- 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 +3 -17
- package/build/core/storage/index.js +57 -77
- package/build/core/storage/local/obj-files-gc.d.ts +2 -0
- package/build/core/storage/local/obj-files-gc.js +53 -39
- package/build/core/storage/local/obj-files.d.ts +6 -9
- package/build/core/storage/local/obj-files.js +16 -19
- package/build/core/storage/local/obj-status.d.ts +20 -30
- package/build/core/storage/local/obj-status.js +46 -113
- package/build/core/storage/local/storage.d.ts +15 -5
- package/build/core/storage/local/storage.js +37 -18
- package/build/core/storage/synced/downloader.js +7 -6
- package/build/core/storage/synced/obj-files-gc.d.ts +6 -1
- package/build/core/storage/synced/obj-files-gc.js +106 -13
- package/build/core/storage/synced/obj-files.d.ts +46 -47
- package/build/core/storage/synced/obj-files.js +207 -154
- package/build/core/storage/synced/obj-status.d.ts +103 -42
- package/build/core/storage/synced/obj-status.js +525 -137
- package/build/core/storage/synced/remote-events.d.ts +11 -12
- package/build/core/storage/synced/remote-events.js +80 -57
- package/build/core/storage/synced/storage.d.ts +24 -5
- package/build/core/storage/synced/storage.js +123 -38
- 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 +15 -9
- package/build/core/storage/synced/upsyncer.js +219 -246
- 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 +67 -83
- package/build/ipc-via-protobuf/bytes.js +16 -17
- package/build/ipc-via-protobuf/connector-clients-side.d.ts +3 -0
- package/build/ipc-via-protobuf/connector-clients-side.js +62 -25
- 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 +476 -120
- package/build/ipc-via-protobuf/fs.d.ts +8 -0
- package/build/ipc-via-protobuf/fs.js +592 -159
- 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 +23 -23
- package/build/ipc-via-protobuf/storage-cap.js +12 -12
- package/build/ipc.js +7 -2
- package/build/lib-client/3nstorage/exceptions.d.ts +12 -8
- package/build/lib-client/3nstorage/exceptions.js +31 -10
- package/build/lib-client/3nstorage/service.d.ts +16 -2
- package/build/lib-client/3nstorage/service.js +109 -39
- package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
- package/build/lib-client/3nstorage/util/file-based-json.js +1 -1
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +52 -14
- package/build/lib-client/3nstorage/xsp-fs/common.js +31 -16
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +18 -14
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +31 -6
- package/build/lib-client/3nstorage/xsp-fs/file.js +74 -23
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +4 -4
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +24 -11
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +599 -189
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +45 -9
- package/build/lib-client/3nstorage/xsp-fs/fs.js +326 -74
- 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 -20
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +239 -106
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +18 -19
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +5 -5
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +56 -56
- 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 +19 -17
- 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 +7 -7
- 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 -4
- package/build/lib-client/fs-collection.js +3 -2
- 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 +11 -11
- 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 +5 -5
- package/build/lib-client/objs-on-disk/obj-folders.js +33 -33
- 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 +14 -14
- package/build/lib-client/server-events.d.ts +3 -3
- package/build/lib-client/server-events.js +12 -10
- package/build/lib-client/service-locator.js +10 -10
- package/build/lib-client/user-with-mid-session.js +7 -7
- package/build/lib-client/user-with-pkl-session.js +25 -25
- package/build/lib-client/ws-utils.js +3 -3
- 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 +19 -18
- package/build/lib-common/byte-streaming/pipe.js +1 -1
- package/build/lib-common/byte-streaming/wrapping.js +17 -17
- 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.js +10 -1
- package/build/lib-common/ipc/generic-ipc.js +2 -2
- package/build/lib-common/ipc/ws-ipc.js +2 -2
- package/build/lib-common/json-utils.js +2 -1
- 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 +99 -37
- package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
- package/build/lib-common/objs-on-disk/utils.js +4 -4
- package/build/lib-common/objs-on-disk/v1-obj-file-format.js +14 -14
- package/build/lib-common/processes/deferred.d.ts +6 -0
- package/build/lib-common/processes/deferred.js +30 -0
- package/build/lib-common/processes/labelled-exec-pools.d.ts +33 -0
- package/build/lib-common/processes/labelled-exec-pools.js +141 -0
- package/build/lib-common/processes/pressure.d.ts +7 -0
- package/build/lib-common/processes/pressure.js +56 -0
- package/build/lib-common/processes/sleep.d.ts +1 -0
- package/build/lib-common/processes/sleep.js +26 -0
- package/build/lib-common/{processes.d.ts → processes/synced.d.ts} +0 -40
- package/build/lib-common/{processes.js → processes/synced.js} +187 -204
- package/build/lib-common/processes/timeout.d.ts +1 -0
- package/build/lib-common/processes/timeout.js +51 -0
- package/build/lib-common/random-node.js +7 -7
- package/build/lib-common/service-api/3nstorage/owner.d.ts +100 -39
- package/build/lib-common/service-api/3nstorage/owner.js +85 -42
- 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.d.ts +15 -1
- package/build/lib-common/utils-for-observables.js +70 -19
- 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 +12912 -7127
- package/build/protos/file.proto.js +4848 -2399
- package/build/protos/fs.proto.js +9230 -3445
- package/package.json +8 -7
- package/protos/file.proto +91 -11
- package/protos/fs.proto +107 -8
- package/build/core/storage/synced/upsync-status.d.ts +0 -41
- package/build/core/storage/synced/upsync-status.js +0 -158
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.ObjFolders = exports.makeAlreadyExistExc = exports.makeNotFoundExc = void 0;
|
|
20
20
|
const fs = require("../../lib-common/async-fs-node");
|
|
21
|
-
const
|
|
21
|
+
const synced_1 = require("../../lib-common/processes/synced");
|
|
22
22
|
const xsp_files_1 = require("xsp-files");
|
|
23
23
|
const assert_1 = require("../../lib-common/assert");
|
|
24
24
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
@@ -74,20 +74,20 @@ class ObjFolders {
|
|
|
74
74
|
/**
|
|
75
75
|
* Process ids here are values of the first section in each folder tree.
|
|
76
76
|
*/
|
|
77
|
-
this.syncProcs = new
|
|
77
|
+
this.syncProcs = new synced_1.NamedProcs();
|
|
78
78
|
this.saveCfg = () => writeCfgTo(this.path, {
|
|
79
79
|
charsInSplit: this.charsInSplit,
|
|
80
80
|
numOfSplits: this.numOfSplits,
|
|
81
81
|
generations: this.generations
|
|
82
82
|
});
|
|
83
|
-
assert_1.assert(Number.isInteger(this.numOfSplits) && (this.numOfSplits > 0) &&
|
|
83
|
+
(0, assert_1.assert)(Number.isInteger(this.numOfSplits) && (this.numOfSplits > 0) &&
|
|
84
84
|
Number.isInteger(this.charsInSplit) && (this.charsInSplit > 0));
|
|
85
|
-
this.accessFolder = path_1.join(this.path, ACCESS_DIR);
|
|
85
|
+
this.accessFolder = (0, path_1.join)(this.path, ACCESS_DIR);
|
|
86
86
|
if (this.generations) {
|
|
87
87
|
if (!canMove) {
|
|
88
88
|
throw new Error(`Missing a can-move predicate when generations are present`);
|
|
89
89
|
}
|
|
90
|
-
this.generationsFolder = path_1.join(this.path, GENERATIONS_DIR);
|
|
90
|
+
this.generationsFolder = (0, path_1.join)(this.path, GENERATIONS_DIR);
|
|
91
91
|
this.rotationsProc = new RotationsProc(this.accessFolder, this.generationsFolder, this.generations, this.syncProcs, canMove, this.saveCfg, this.logError);
|
|
92
92
|
this.rotationsProc.scheduleStart(10 * 60);
|
|
93
93
|
}
|
|
@@ -100,8 +100,8 @@ class ObjFolders {
|
|
|
100
100
|
await writeCfgTo(path, cfg);
|
|
101
101
|
}
|
|
102
102
|
checkCfg(cfg);
|
|
103
|
-
await fs.mkdir(path_1.join(path, ACCESS_DIR)).catch(alreadyExistsOrReThrow);
|
|
104
|
-
await fs.mkdir(path_1.join(path, GENERATIONS_DIR)).catch(alreadyExistsOrReThrow);
|
|
103
|
+
await fs.mkdir((0, path_1.join)(path, ACCESS_DIR)).catch(alreadyExistsOrReThrow);
|
|
104
|
+
await fs.mkdir((0, path_1.join)(path, GENERATIONS_DIR)).catch(alreadyExistsOrReThrow);
|
|
105
105
|
return new ObjFolders(path, cfg.numOfSplits, cfg.charsInSplit, logError, cfg.generations, canMove);
|
|
106
106
|
}
|
|
107
107
|
static async makeSimple(path, logError) {
|
|
@@ -111,7 +111,7 @@ class ObjFolders {
|
|
|
111
111
|
await writeCfgTo(path, cfg);
|
|
112
112
|
}
|
|
113
113
|
checkCfg(cfg);
|
|
114
|
-
await fs.mkdir(path_1.join(path, ACCESS_DIR)).catch(alreadyExistsOrReThrow);
|
|
114
|
+
await fs.mkdir((0, path_1.join)(path, ACCESS_DIR)).catch(alreadyExistsOrReThrow);
|
|
115
115
|
return new ObjFolders(path, cfg.numOfSplits, cfg.charsInSplit, logError);
|
|
116
116
|
}
|
|
117
117
|
idToPathSections(objId) {
|
|
@@ -127,10 +127,10 @@ class ObjFolders {
|
|
|
127
127
|
return path;
|
|
128
128
|
}
|
|
129
129
|
genBucketPath(bucketIndex) {
|
|
130
|
-
return path_1.join(this.generationsFolder, `${bucketIndex}`);
|
|
130
|
+
return (0, path_1.join)(this.generationsFolder, `${bucketIndex}`);
|
|
131
131
|
}
|
|
132
132
|
async findObjFolder(pathSections) {
|
|
133
|
-
const folder = path_1.join(this.accessFolder, ...pathSections);
|
|
133
|
+
const folder = (0, path_1.join)(this.accessFolder, ...pathSections);
|
|
134
134
|
if (await folderExists(folder)) {
|
|
135
135
|
return { folder };
|
|
136
136
|
}
|
|
@@ -138,7 +138,7 @@ class ObjFolders {
|
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
140
|
for (let i = 0; i < this.generations.length; i += 1) {
|
|
141
|
-
const folder = path_1.join(this.genBucketPath(i), ...pathSections);
|
|
141
|
+
const folder = (0, path_1.join)(this.genBucketPath(i), ...pathSections);
|
|
142
142
|
if (await folderExists(folder)) {
|
|
143
143
|
return { folder, genBacket: i };
|
|
144
144
|
}
|
|
@@ -146,7 +146,7 @@ class ObjFolders {
|
|
|
146
146
|
}
|
|
147
147
|
getFolderAccessFor(objId, createIfMissing = false) {
|
|
148
148
|
if (!objId) {
|
|
149
|
-
const folder = path_1.join(this.accessFolder, ROOT_OBJ_DIR);
|
|
149
|
+
const folder = (0, path_1.join)(this.accessFolder, ROOT_OBJ_DIR);
|
|
150
150
|
return this.syncProcs.startOrChain(ROOT_OBJ_DIR, async () => {
|
|
151
151
|
if (await folderExists(folder)) {
|
|
152
152
|
return folder;
|
|
@@ -176,7 +176,7 @@ class ObjFolders {
|
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
178
|
removeFolderOf(objId) {
|
|
179
|
-
assert_1.assert(!!objId, `Root object can't be removed.`);
|
|
179
|
+
(0, assert_1.assert)(!!objId, `Root object can't be removed.`);
|
|
180
180
|
const pathSections = this.idToPathSections(objId);
|
|
181
181
|
return this.syncProcs.startOrChain(pathSections[0], async () => {
|
|
182
182
|
const found = await this.findObjFolder(pathSections);
|
|
@@ -191,10 +191,10 @@ class ObjFolders {
|
|
|
191
191
|
async listRecent() {
|
|
192
192
|
const lst = (await allTreePaths(this.accessFolder, this.numOfSplits, this.logError))
|
|
193
193
|
.map(pathSections => ({
|
|
194
|
-
path: path_1.join(this.accessFolder, ...pathSections),
|
|
194
|
+
path: (0, path_1.join)(this.accessFolder, ...pathSections),
|
|
195
195
|
objId: pathSections.join('')
|
|
196
196
|
}));
|
|
197
|
-
const rootObjPath = path_1.join(this.accessFolder, ROOT_OBJ_DIR);
|
|
197
|
+
const rootObjPath = (0, path_1.join)(this.accessFolder, ROOT_OBJ_DIR);
|
|
198
198
|
if (await fs.existsFolder(rootObjPath)) {
|
|
199
199
|
lst.unshift({ objId: null, path: rootObjPath });
|
|
200
200
|
}
|
|
@@ -219,7 +219,7 @@ class RotationsProc {
|
|
|
219
219
|
this.setNextCacheRotation(secs);
|
|
220
220
|
}
|
|
221
221
|
genBacketPath(backetIndex) {
|
|
222
|
-
return path_1.join(this.generationsFolder, `${backetIndex}`);
|
|
222
|
+
return (0, path_1.join)(this.generationsFolder, `${backetIndex}`);
|
|
223
223
|
}
|
|
224
224
|
setNextCacheRotation(secs) {
|
|
225
225
|
setTimeout(async () => {
|
|
@@ -251,7 +251,7 @@ class RotationsProc {
|
|
|
251
251
|
for (let i = 0; i < objPathSections.length; i += 1) {
|
|
252
252
|
const sections = objPathSections[i];
|
|
253
253
|
const objId = sections.join('');
|
|
254
|
-
const objFolderPath = path_1.join(srcBacket, ...sections);
|
|
254
|
+
const objFolderPath = (0, path_1.join)(srcBacket, ...sections);
|
|
255
255
|
await this.syncProcs.startOrChain(sections[0], async () => {
|
|
256
256
|
if (!(await this.canMove(objId, objFolderPath))) {
|
|
257
257
|
return;
|
|
@@ -266,7 +266,7 @@ class RotationsProc {
|
|
|
266
266
|
const objPathSections = await allTreePaths(srcBacket, this.numOfSplits, this.logError);
|
|
267
267
|
for (let i = 0; i < objPathSections.length; i += 1) {
|
|
268
268
|
const sections = objPathSections[i];
|
|
269
|
-
const srcObjPath = path_1.join(srcBacket, ...sections);
|
|
269
|
+
const srcObjPath = (0, path_1.join)(srcBacket, ...sections);
|
|
270
270
|
await this.syncProcs.startOrChain(sections[0], async () => {
|
|
271
271
|
if (!(await folderExists(srcObjPath))) {
|
|
272
272
|
return;
|
|
@@ -287,7 +287,7 @@ Object.freeze(RotationsProc);
|
|
|
287
287
|
* @param pathSections
|
|
288
288
|
*/
|
|
289
289
|
async function makeTreeExclusively(base, pathSections) {
|
|
290
|
-
assert_1.assert(pathSections.length > 0);
|
|
290
|
+
(0, assert_1.assert)(pathSections.length > 0);
|
|
291
291
|
const treePaths = treePathsFor(base, pathSections);
|
|
292
292
|
const intermediateFolders = treePaths.slice(0, treePaths.length - 1);
|
|
293
293
|
await makeFoldersNonexclusively(intermediateFolders);
|
|
@@ -306,7 +306,7 @@ async function makeTreeExclusively(base, pathSections) {
|
|
|
306
306
|
* @param pathSections
|
|
307
307
|
*/
|
|
308
308
|
async function deleteTree(base, pathSections) {
|
|
309
|
-
assert_1.assert(pathSections.length > 0);
|
|
309
|
+
(0, assert_1.assert)(pathSections.length > 0);
|
|
310
310
|
const treePaths = treePathsFor(base, pathSections);
|
|
311
311
|
const intermediateFolders = treePaths.slice(0, treePaths.length - 1);
|
|
312
312
|
const leafFolder = treePaths[treePaths.length - 1];
|
|
@@ -387,7 +387,7 @@ function treePathsFor(base, pathSections) {
|
|
|
387
387
|
const paths = [];
|
|
388
388
|
let path = base;
|
|
389
389
|
for (let i = 0; i < pathSections.length; i += 1) {
|
|
390
|
-
path = path_1.join(path, pathSections[i]);
|
|
390
|
+
path = (0, path_1.join)(path, pathSections[i]);
|
|
391
391
|
paths.push(path);
|
|
392
392
|
}
|
|
393
393
|
return paths;
|
|
@@ -430,14 +430,14 @@ async function readJSONFile(path) {
|
|
|
430
430
|
return JSON.parse(jsonStr);
|
|
431
431
|
}
|
|
432
432
|
catch (err) {
|
|
433
|
-
throw error_1.errWithCause(err, `Can't parse json file ${path}`);
|
|
433
|
+
throw (0, error_1.errWithCause)(err, `Can't parse json file ${path}`);
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
async function readCfgFrom(path) {
|
|
437
|
-
const cfg = await readJSONFile(path_1.join(path, CONFIG_FILE));
|
|
438
|
-
const accessDir = path_1.join(path, ACCESS_DIR);
|
|
437
|
+
const cfg = await readJSONFile((0, path_1.join)(path, CONFIG_FILE));
|
|
438
|
+
const accessDir = (0, path_1.join)(path, ACCESS_DIR);
|
|
439
439
|
const accessDirFound = await folderExists(accessDir);
|
|
440
|
-
const gensDir = path_1.join(path, GENERATIONS_DIR);
|
|
440
|
+
const gensDir = (0, path_1.join)(path, GENERATIONS_DIR);
|
|
441
441
|
const gensDirFound = await folderExists(gensDir);
|
|
442
442
|
if (cfg === undefined) {
|
|
443
443
|
if (accessDirFound || (gensDirFound)) {
|
|
@@ -455,24 +455,24 @@ async function readCfgFrom(path) {
|
|
|
455
455
|
}
|
|
456
456
|
async function writeCfgTo(path, cfg) {
|
|
457
457
|
try {
|
|
458
|
-
await fs.writeFile(path_1.join(path, CONFIG_FILE), JSON.stringify(cfg), { encoding: 'utf8' });
|
|
458
|
+
await fs.writeFile((0, path_1.join)(path, CONFIG_FILE), JSON.stringify(cfg), { encoding: 'utf8' });
|
|
459
459
|
}
|
|
460
460
|
catch (err) {
|
|
461
461
|
if (!err.notFound) {
|
|
462
462
|
throw err;
|
|
463
463
|
}
|
|
464
464
|
await fs.ensureFolderExists(path);
|
|
465
|
-
await fs.writeFile(path_1.join(path, CONFIG_FILE), JSON.stringify(cfg), { encoding: 'utf8' });
|
|
465
|
+
await fs.writeFile((0, path_1.join)(path, CONFIG_FILE), JSON.stringify(cfg), { encoding: 'utf8' });
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
function checkCfg(cfg, needGens = false) {
|
|
469
|
-
assert_1.assert(Number.isInteger(cfg.numOfSplits) && (cfg.numOfSplits > 0), `Invalid numOfSplits in object folders' configuration: ${cfg.numOfSplits}`);
|
|
470
|
-
assert_1.assert(Number.isInteger(cfg.charsInSplit) && (cfg.charsInSplit > 0), `Invalid charsInSplit in object folders' configuration: ${cfg.charsInSplit}`);
|
|
471
|
-
assert_1.assert(cfg.numOfSplits * cfg.charsInSplit < Math.floor(xsp_files_1.NONCE_LENGTH / 3 * 4), `Invalid splits configuration, expecting too many letters in object id`);
|
|
469
|
+
(0, assert_1.assert)(Number.isInteger(cfg.numOfSplits) && (cfg.numOfSplits > 0), `Invalid numOfSplits in object folders' configuration: ${cfg.numOfSplits}`);
|
|
470
|
+
(0, assert_1.assert)(Number.isInteger(cfg.charsInSplit) && (cfg.charsInSplit > 0), `Invalid charsInSplit in object folders' configuration: ${cfg.charsInSplit}`);
|
|
471
|
+
(0, assert_1.assert)(cfg.numOfSplits * cfg.charsInSplit < Math.floor(xsp_files_1.NONCE_LENGTH / 3 * 4), `Invalid splits configuration, expecting too many letters in object id`);
|
|
472
472
|
if (needGens) {
|
|
473
473
|
const gens = cfg.generations;
|
|
474
|
-
assert_1.assert(Array.isArray(gens), `Invalid generations in object folders' configuration: ${gens}`);
|
|
475
|
-
assert_1.assert(gens.length > 0, `Config must have at least one generation`);
|
|
474
|
+
(0, assert_1.assert)(Array.isArray(gens), `Invalid generations in object folders' configuration: ${gens}`);
|
|
475
|
+
(0, assert_1.assert)(gens.length > 0, `Config must have at least one generation`);
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
478
|
async function allTreePaths(path, numOfSplits, logError) {
|
|
@@ -495,7 +495,7 @@ async function allTreePaths(path, numOfSplits, logError) {
|
|
|
495
495
|
if (f === ROOT_OBJ_DIR) {
|
|
496
496
|
continue;
|
|
497
497
|
}
|
|
498
|
-
const treePaths = await allTreePaths(path_1.join(path, f), numOfSplits - 1, logError);
|
|
498
|
+
const treePaths = await allTreePaths((0, path_1.join)(path, f), numOfSplits - 1, logError);
|
|
499
499
|
for (let j = 0; j < treePaths.length; j += 1) {
|
|
500
500
|
const branch = treePaths[j];
|
|
501
501
|
branch.unshift(f);
|
|
@@ -2,7 +2,8 @@ import { ObjId } from '../3nstorage/xsp-fs/common';
|
|
|
2
2
|
import { ObjSource, Subscribe, Layout } from 'xsp-files';
|
|
3
3
|
import { FileWrite } from './file-writing-proc';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
|
-
import { NotOnDiskFiniteChunk } from '../../lib-common/objs-on-disk/file-layout';
|
|
5
|
+
import { NotOnDiskFiniteChunk, FiniteChunk } from '../../lib-common/objs-on-disk/file-layout';
|
|
6
|
+
import { DiffInfo } from '../../lib-common/service-api/3nstorage/owner';
|
|
6
7
|
export declare type GetBaseSegsOnDisk = (version: number, ofs: number, len: number) => Promise<(Uint8Array | NotOnDiskFiniteChunk)[]>;
|
|
7
8
|
export declare class ObjOnDisk {
|
|
8
9
|
readonly objId: ObjId;
|
|
@@ -11,6 +12,7 @@ export declare class ObjOnDisk {
|
|
|
11
12
|
private readonly downloader;
|
|
12
13
|
private readable;
|
|
13
14
|
private readonly getBaseSegsOnDisk;
|
|
15
|
+
private proxiedHeader;
|
|
14
16
|
private constructor();
|
|
15
17
|
static forExistingFile(objId: ObjId, version: number, path: string, downloader?: ObjDownloader, getBase?: GetBaseSegsOnDisk): Promise<ObjOnDisk>;
|
|
16
18
|
static createFileForExistingVersion(objId: ObjId, version: number, path: string, downloader: ObjDownloader, getBase?: GetBaseSegsOnDisk, initDownload?: InitDownloadParts): Promise<ObjOnDisk>;
|
|
@@ -18,7 +20,11 @@ export declare class ObjOnDisk {
|
|
|
18
20
|
obj: ObjOnDisk;
|
|
19
21
|
write$: Observable<FileWrite[]>;
|
|
20
22
|
}>;
|
|
21
|
-
|
|
23
|
+
moveFileAndProxyThis(newPath: string, objVersionChange: {
|
|
24
|
+
version: number;
|
|
25
|
+
newHeader: Uint8Array;
|
|
26
|
+
originalHeader: Uint8Array;
|
|
27
|
+
} | undefined): Promise<ObjOnDisk>;
|
|
22
28
|
removeFile(): Promise<void>;
|
|
23
29
|
private readHeader;
|
|
24
30
|
private readSegs;
|
|
@@ -27,6 +33,11 @@ export declare class ObjOnDisk {
|
|
|
27
33
|
private downloadAndSaveSegsChunk;
|
|
28
34
|
getSrc(): ObjSource;
|
|
29
35
|
getBaseVersion(): number | undefined;
|
|
36
|
+
absorbImmediateBaseVersion(baseVer: number, path: string): Promise<void>;
|
|
37
|
+
diffFromBase(): {
|
|
38
|
+
diff: DiffInfo;
|
|
39
|
+
newSegsPackOrder: FiniteChunk[];
|
|
40
|
+
};
|
|
30
41
|
}
|
|
31
42
|
export interface ObjDownloader {
|
|
32
43
|
getLayoutWithHeaderAndFirstSegs(objId: ObjId, version: number): Promise<InitDownloadParts>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2018 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2018 - 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -32,6 +32,7 @@ class ObjOnDisk {
|
|
|
32
32
|
this.downloader = downloader;
|
|
33
33
|
this.readable = readable;
|
|
34
34
|
this.getBaseSegsOnDisk = getBaseSegsOnDisk;
|
|
35
|
+
this.proxiedHeader = undefined;
|
|
35
36
|
Object.seal(this);
|
|
36
37
|
}
|
|
37
38
|
static async forExistingFile(objId, version, path, downloader, getBase) {
|
|
@@ -61,20 +62,28 @@ class ObjOnDisk {
|
|
|
61
62
|
const objFile = await obj_file_1.ObjVersionFile.createNew(path);
|
|
62
63
|
const obj = new ObjOnDisk(objId, version, objFile, downloader, false, getBase);
|
|
63
64
|
const write$ = file_writing_proc_1.FileWritingProc.makeFor(objFile, encSub)
|
|
64
|
-
.pipe(operators_1.tap({
|
|
65
|
+
.pipe((0, operators_1.tap)({
|
|
65
66
|
complete: () => {
|
|
66
67
|
obj.readable = true;
|
|
67
68
|
}
|
|
68
|
-
}), utils_for_observables_1.flatTap(undefined, () => objFile.removeFile()), utils_for_observables_1.allowOnlySingleStart());
|
|
69
|
+
}), (0, utils_for_observables_1.flatTap)(undefined, () => objFile.removeFile()), (0, utils_for_observables_1.allowOnlySingleStart)());
|
|
69
70
|
return { obj, write$ };
|
|
70
71
|
}
|
|
71
|
-
async
|
|
72
|
-
|
|
72
|
+
async moveFileAndProxyThis(newPath, objVersionChange) {
|
|
73
|
+
const newObjOnDisk = new ObjOnDisk(this.objId, (objVersionChange ? objVersionChange.version : this.version), this.objFile, this.downloader, this.readable, this.getBaseSegsOnDisk);
|
|
74
|
+
if (objVersionChange) {
|
|
75
|
+
this.proxiedHeader = objVersionChange.originalHeader;
|
|
76
|
+
}
|
|
77
|
+
await this.objFile.moveFile(newPath, objVersionChange === null || objVersionChange === void 0 ? void 0 : objVersionChange.newHeader);
|
|
78
|
+
return newObjOnDisk;
|
|
73
79
|
}
|
|
74
80
|
async removeFile() {
|
|
75
81
|
await this.objFile.removeFile();
|
|
76
82
|
}
|
|
77
83
|
async readHeader() {
|
|
84
|
+
if (this.proxiedHeader) {
|
|
85
|
+
return this.proxiedHeader;
|
|
86
|
+
}
|
|
78
87
|
let h = await this.objFile.readHeader();
|
|
79
88
|
if (h) {
|
|
80
89
|
return h;
|
|
@@ -99,7 +108,7 @@ class ObjOnDisk {
|
|
|
99
108
|
bytes.push(chunkBytes);
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
|
-
return buffer_utils_1.joinByteArrs(bytes);
|
|
111
|
+
return (0, buffer_utils_1.joinByteArrs)(bytes);
|
|
103
112
|
}
|
|
104
113
|
async readSegsOnlyFromDisk(offset, len) {
|
|
105
114
|
const segsLocations = this.objFile.segsLocations(offset, len);
|
|
@@ -166,7 +175,7 @@ class ObjOnDisk {
|
|
|
166
175
|
if (!this.readable) {
|
|
167
176
|
throw new Error(`Version ${this.version} of obj ${this.objId} is not readable, yet`);
|
|
168
177
|
}
|
|
169
|
-
const segSrc = wrapping_1.wrapAndSyncSource(new ByteSourceFromObjOnDisk((ofs, len) => this.readSegs(ofs, len), () => this.objFile.getTotalSegsLen()));
|
|
178
|
+
const segSrc = (0, wrapping_1.wrapAndSyncSource)(new ByteSourceFromObjOnDisk((ofs, len) => this.readSegs(ofs, len), () => this.objFile.getTotalSegsLen()));
|
|
170
179
|
const objSrc = {
|
|
171
180
|
readHeader: () => this.readHeader(),
|
|
172
181
|
segSrc,
|
|
@@ -177,6 +186,12 @@ class ObjOnDisk {
|
|
|
177
186
|
getBaseVersion() {
|
|
178
187
|
return this.objFile.getBaseVersion();
|
|
179
188
|
}
|
|
189
|
+
absorbImmediateBaseVersion(baseVer, path) {
|
|
190
|
+
return this.objFile.absorbImmediateBaseVersion(baseVer, path);
|
|
191
|
+
}
|
|
192
|
+
diffFromBase() {
|
|
193
|
+
return this.objFile.diffFromBase();
|
|
194
|
+
}
|
|
180
195
|
}
|
|
181
196
|
exports.ObjOnDisk = ObjOnDisk;
|
|
182
197
|
Object.freeze(ObjOnDisk.prototype);
|
|
@@ -189,7 +204,7 @@ class ByteSourceFromObjOnDisk {
|
|
|
189
204
|
Object.seal(this);
|
|
190
205
|
}
|
|
191
206
|
async read(len) {
|
|
192
|
-
assert_1.assert((Number.isInteger(len) && (len >= 0)) || (len === undefined), 'Illegal length parameter given: ' + len);
|
|
207
|
+
(0, assert_1.assert)((Number.isInteger(len) && (len >= 0)) || (len === undefined), 'Illegal length parameter given: ' + len);
|
|
193
208
|
const start = this.segsPointer;
|
|
194
209
|
if (len === undefined) {
|
|
195
210
|
const segsLen = this.totalSegsLen();
|
|
@@ -211,7 +226,7 @@ class ByteSourceFromObjOnDisk {
|
|
|
211
226
|
{ size, isEndless: false } : { size: 0, isEndless: true });
|
|
212
227
|
}
|
|
213
228
|
async seek(offset) {
|
|
214
|
-
assert_1.assert(Number.isInteger(offset) && (offset >= 0), 'Illegal offset is given to seek: ' + offset);
|
|
229
|
+
(0, assert_1.assert)(Number.isInteger(offset) && (offset >= 0), 'Illegal offset is given to seek: ' + offset);
|
|
215
230
|
const segsLen = this.totalSegsLen();
|
|
216
231
|
if (segsLen === undefined) {
|
|
217
232
|
this.segsPointer = offset;
|
|
@@ -22,7 +22,7 @@ const https = require("https");
|
|
|
22
22
|
const url_1 = require("url");
|
|
23
23
|
const rxjs_1 = require("rxjs");
|
|
24
24
|
const buffer_utils_1 = require("../lib-common/buffer-utils");
|
|
25
|
-
const
|
|
25
|
+
const deferred_1 = require("../lib-common/processes/deferred");
|
|
26
26
|
const operators_1 = require("rxjs/operators");
|
|
27
27
|
exports.SESSION_ID_HEADER = "X-Session-Id";
|
|
28
28
|
exports.CONTENT_TYPE_HEADER = 'Content-Type';
|
|
@@ -30,7 +30,7 @@ async function processRequest(requester, httpsOpts, opts, reqBody, attempt = 0)
|
|
|
30
30
|
try {
|
|
31
31
|
const req = requester(httpsOpts);
|
|
32
32
|
const resPromise = attachRequestReaders(req, opts);
|
|
33
|
-
req.end(reqBody ? buffer_utils_1.toBuffer(reqBody) : undefined);
|
|
33
|
+
req.end(reqBody ? (0, buffer_utils_1.toBuffer)(reqBody) : undefined);
|
|
34
34
|
const { res, resBody } = await resPromise;
|
|
35
35
|
const rep = formReply(res, resBody, opts);
|
|
36
36
|
return rep;
|
|
@@ -51,7 +51,7 @@ function formHttpsReqOpts(opts, contentType, reqBody) {
|
|
|
51
51
|
if (reqBody && (opts.method !== 'POST') && (opts.method !== 'PUT')) {
|
|
52
52
|
throw new Error(`Cannot have body in ${opts.method} request.`);
|
|
53
53
|
}
|
|
54
|
-
const url = url_1.parse(opts.url);
|
|
54
|
+
const url = (0, url_1.parse)(opts.url);
|
|
55
55
|
const netReqOpts = {
|
|
56
56
|
protocol: url.protocol,
|
|
57
57
|
method: opts.method,
|
|
@@ -78,14 +78,14 @@ function attachRequestReaders(clReq, opts) {
|
|
|
78
78
|
// note that we attach reading of body to response as close as possible to
|
|
79
79
|
// its appearance, so as not to miss any incoming data, which may happen if
|
|
80
80
|
// next tick occurs in between.
|
|
81
|
-
const response$ = rxjs_1.fromEvent(clReq, 'response', (res) => ({ res, resBodyPromise: readAllBytesFrom(res) }))
|
|
82
|
-
.pipe(operators_1.take(1));
|
|
83
|
-
const err$ = rxjs_1.fromEvent(clReq, 'error')
|
|
84
|
-
.pipe(operators_1.map(e => {
|
|
85
|
-
throw http_1.makeConnectionException(opts.url, opts.method, 'Cannot connect', e);
|
|
86
|
-
}), operators_1.takeUntil(response$));
|
|
87
|
-
return rxjs_1.merge(response$, err$)
|
|
88
|
-
.pipe(operators_1.mergeMap(async (resAndBodyProm) => {
|
|
81
|
+
const response$ = (0, rxjs_1.fromEvent)(clReq, 'response', (res) => ({ res, resBodyPromise: readAllBytesFrom(res) }))
|
|
82
|
+
.pipe((0, operators_1.take)(1));
|
|
83
|
+
const err$ = (0, rxjs_1.fromEvent)(clReq, 'error')
|
|
84
|
+
.pipe((0, operators_1.map)(e => {
|
|
85
|
+
throw (0, http_1.makeConnectionException)(opts.url, opts.method, 'Cannot connect', e);
|
|
86
|
+
}), (0, operators_1.takeUntil)(response$));
|
|
87
|
+
return (0, rxjs_1.merge)(response$, err$)
|
|
88
|
+
.pipe((0, operators_1.mergeMap)(async (resAndBodyProm) => {
|
|
89
89
|
const { res, resBodyPromise } = resAndBodyProm;
|
|
90
90
|
const resBody = await resBodyPromise;
|
|
91
91
|
return { res, resBody };
|
|
@@ -109,7 +109,7 @@ function isTimeoutErr(err, opts, currentAttempt) {
|
|
|
109
109
|
}
|
|
110
110
|
async function readAllBytesFrom(stream) {
|
|
111
111
|
const buf = new bytes_fifo_buffer_1.BytesFIFOBuffer();
|
|
112
|
-
const deferred =
|
|
112
|
+
const deferred = (0, deferred_1.defer)();
|
|
113
113
|
stream.on('error', e => deferred.reject(e));
|
|
114
114
|
stream.on('data', chunk => buf.push(chunk));
|
|
115
115
|
stream.on('end', () => deferred.resolve(buf.getBytes(undefined)));
|
|
@@ -131,7 +131,7 @@ function formReply(res, resBody, reqOpts) {
|
|
|
131
131
|
}
|
|
132
132
|
catch (err) {
|
|
133
133
|
if (resContentType === 'application/json') {
|
|
134
|
-
throw http_1.makeHTTPException(reqOpts.url, reqOpts.method, status, `Cannot parse received bytes`, err);
|
|
134
|
+
throw (0, http_1.makeHTTPException)(reqOpts.url, reqOpts.method, status, `Cannot parse received bytes`, err);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -171,7 +171,7 @@ function makeHeaders(headers) {
|
|
|
171
171
|
* @return http exception based on given reply, with an optional message
|
|
172
172
|
*/
|
|
173
173
|
function makeException(rep, errMsg) {
|
|
174
|
-
return http_1.makeHTTPException(rep.url, rep.method, rep.status, errMsg);
|
|
174
|
+
return (0, http_1.makeHTTPException)(rep.url, rep.method, rep.status, errMsg);
|
|
175
175
|
}
|
|
176
176
|
exports.makeException = makeException;
|
|
177
177
|
function extractIntHeader(rep, headerName) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SubscribingClient } from '../lib-common/ipc/generic-ipc';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
export declare class ServerEvents {
|
|
3
|
+
export declare class ServerEvents<N extends string, T> {
|
|
4
4
|
private subscribeToServer;
|
|
5
5
|
private restartWaitSecs;
|
|
6
6
|
private server;
|
|
@@ -8,9 +8,9 @@ export declare class ServerEvents {
|
|
|
8
8
|
constructor(subscribeToServer: () => Promise<SubscribingClient>, restartWaitSecs: number);
|
|
9
9
|
/**
|
|
10
10
|
* This method creates an observable of server's events.
|
|
11
|
-
* @param
|
|
11
|
+
* @param event is an event on server, to which to subscribe.
|
|
12
12
|
*/
|
|
13
|
-
observe
|
|
13
|
+
observe(event: N): Observable<T>;
|
|
14
14
|
private setServer;
|
|
15
15
|
private shouldRestartAfterErr;
|
|
16
16
|
private restartObservation;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017, 2019 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017, 2019, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -13,11 +13,13 @@
|
|
|
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.ServerEvents = void 0;
|
|
19
20
|
const rxjs_1 = require("rxjs");
|
|
20
|
-
const
|
|
21
|
+
const synced_1 = require("../lib-common/processes/synced");
|
|
22
|
+
const sleep_1 = require("../lib-common/processes/sleep");
|
|
21
23
|
const operators_1 = require("rxjs/operators");
|
|
22
24
|
const error_1 = require("../lib-common/exceptions/error");
|
|
23
25
|
class ServerEvents {
|
|
@@ -25,12 +27,12 @@ class ServerEvents {
|
|
|
25
27
|
this.subscribeToServer = subscribeToServer;
|
|
26
28
|
this.restartWaitSecs = restartWaitSecs;
|
|
27
29
|
this.server = undefined;
|
|
28
|
-
this.openningServer = new
|
|
30
|
+
this.openningServer = new synced_1.SingleProc();
|
|
29
31
|
Object.seal(this);
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
34
|
* This method creates an observable of server's events.
|
|
33
|
-
* @param
|
|
35
|
+
* @param event is an event on server, to which to subscribe.
|
|
34
36
|
*/
|
|
35
37
|
observe(event) {
|
|
36
38
|
const event$ = new rxjs_1.Observable(observer => {
|
|
@@ -69,13 +71,13 @@ class ServerEvents {
|
|
|
69
71
|
}
|
|
70
72
|
};
|
|
71
73
|
})
|
|
72
|
-
.pipe(operators_1.catchError(err => {
|
|
74
|
+
.pipe((0, operators_1.catchError)(err => {
|
|
73
75
|
if (this.shouldRestartAfterErr(err)) {
|
|
74
|
-
console.error(error_1.stringifyErr(err));
|
|
76
|
+
console.error((0, error_1.stringifyErr)(err));
|
|
75
77
|
return this.restartObservation(event);
|
|
76
78
|
}
|
|
77
79
|
else {
|
|
78
|
-
return rxjs_1.throwError(err);
|
|
80
|
+
return (0, rxjs_1.throwError)(err);
|
|
79
81
|
}
|
|
80
82
|
}));
|
|
81
83
|
return event$;
|
|
@@ -106,8 +108,8 @@ class ServerEvents {
|
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
restartObservation(event) {
|
|
109
|
-
return rxjs_1.from(
|
|
110
|
-
.pipe(operators_1.mergeMap(() => this.observe(event)));
|
|
111
|
+
return (0, rxjs_1.from)((0, sleep_1.sleep)(this.restartWaitSecs * 1000))
|
|
112
|
+
.pipe((0, operators_1.mergeMap)(() => this.observe(event)));
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
exports.ServerEvents = ServerEvents;
|
|
@@ -21,7 +21,7 @@ const jwkeys_1 = require("../lib-common/jwkeys");
|
|
|
21
21
|
const url_1 = require("url");
|
|
22
22
|
const request_utils_1 = require("./request-utils");
|
|
23
23
|
async function readJSONLocatedAt(client, url) {
|
|
24
|
-
if (url_1.parse(url).protocol !== 'https:') {
|
|
24
|
+
if ((0, url_1.parse)(url).protocol !== 'https:') {
|
|
25
25
|
throw new Error("Url protocol must be https.");
|
|
26
26
|
}
|
|
27
27
|
const rep = await client.doBodylessRequest({
|
|
@@ -31,20 +31,20 @@ async function readJSONLocatedAt(client, url) {
|
|
|
31
31
|
});
|
|
32
32
|
if (rep.status === 200) {
|
|
33
33
|
if (!rep.data) {
|
|
34
|
-
throw request_utils_1.makeException(rep, 'Malformed reply');
|
|
34
|
+
throw (0, request_utils_1.makeException)(rep, 'Malformed reply');
|
|
35
35
|
}
|
|
36
36
|
return rep;
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
throw request_utils_1.makeException(rep, 'Unexpected status');
|
|
39
|
+
throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
function transformPathToCompleteUri(url, path, rep) {
|
|
43
|
-
const uInit = url_1.parse(url);
|
|
43
|
+
const uInit = (0, url_1.parse)(url);
|
|
44
44
|
const protoAndHost = `${uInit.protocol}//${uInit.host}`;
|
|
45
|
-
const uPath = url_1.parse(path);
|
|
45
|
+
const uPath = (0, url_1.parse)(path);
|
|
46
46
|
if (!uPath.path || !uPath.href || !uPath.href.startsWith(uPath.path)) {
|
|
47
|
-
throw request_utils_1.makeException(rep, `Malformed path parameter ${path}`);
|
|
47
|
+
throw (0, request_utils_1.makeException)(rep, `Malformed path parameter ${path}`);
|
|
48
48
|
}
|
|
49
49
|
if (uPath.href.startsWith('/')) {
|
|
50
50
|
return `${protoAndHost}${uPath.href}`;
|
|
@@ -88,15 +88,15 @@ async function mailerIdInfoAt(client, url) {
|
|
|
88
88
|
transform.provisioning = transformPathToCompleteUri(url, json.provisioning, rep);
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
|
-
throw request_utils_1.makeException(rep, 'Malformed reply');
|
|
91
|
+
throw (0, request_utils_1.makeException)(rep, 'Malformed reply');
|
|
92
92
|
}
|
|
93
93
|
if (('object' === typeof json["current-cert"]) &&
|
|
94
|
-
jwkeys_1.isLikeSignedKeyCert(json["current-cert"])) {
|
|
94
|
+
(0, jwkeys_1.isLikeSignedKeyCert)(json["current-cert"])) {
|
|
95
95
|
transform.currentCert = json["current-cert"];
|
|
96
96
|
transform.previousCerts = json["previous-certs"];
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
|
-
throw request_utils_1.makeException(rep, 'Malformed reply');
|
|
99
|
+
throw (0, request_utils_1.makeException)(rep, 'Malformed reply');
|
|
100
100
|
}
|
|
101
101
|
Object.freeze(transform);
|
|
102
102
|
return transform;
|
|
@@ -223,7 +223,7 @@ exports.makeServiceLocator = makeServiceLocator;
|
|
|
223
223
|
*/
|
|
224
224
|
async function getMailerIdInfoFor(resolver, client, address) {
|
|
225
225
|
const serviceURL = await resolver(address);
|
|
226
|
-
const rootAddr = url_1.parse(serviceURL).hostname;
|
|
226
|
+
const rootAddr = (0, url_1.parse)(serviceURL).hostname;
|
|
227
227
|
const info = await mailerIdInfoAt(client, serviceURL);
|
|
228
228
|
return {
|
|
229
229
|
info: info,
|
|
@@ -49,7 +49,7 @@ class ServiceUser {
|
|
|
49
49
|
return this.uri;
|
|
50
50
|
}
|
|
51
51
|
set serviceURI(uriString) {
|
|
52
|
-
const u = url_1.parse(uriString);
|
|
52
|
+
const u = (0, url_1.parse)(uriString);
|
|
53
53
|
if (u.protocol !== 'https:') {
|
|
54
54
|
throw new Error("Url protocol must be https.");
|
|
55
55
|
}
|
|
@@ -86,7 +86,7 @@ class ServiceUser {
|
|
|
86
86
|
async startSession() {
|
|
87
87
|
this.throwOnBadServiceURI();
|
|
88
88
|
// make first call
|
|
89
|
-
const fstReply = await login_1.startMidSession(this.userId, this.net, this.loginUrl);
|
|
89
|
+
const fstReply = await (0, login_1.startMidSession)(this.userId, this.net, this.loginUrl);
|
|
90
90
|
if (fstReply.sessionId) {
|
|
91
91
|
return fstReply.sessionId;
|
|
92
92
|
}
|
|
@@ -94,10 +94,10 @@ class ServiceUser {
|
|
|
94
94
|
throw new Error(`Service ${this.serviceURI} redirects on MailerId login, while redirect is not allowed`);
|
|
95
95
|
}
|
|
96
96
|
// following redirect
|
|
97
|
-
assert_1.assert(!!fstReply.redirect);
|
|
97
|
+
(0, assert_1.assert)(!!fstReply.redirect);
|
|
98
98
|
this.redirectedFrom = this.serviceURI;
|
|
99
99
|
this.serviceURI = fstReply.redirect;
|
|
100
|
-
const sndReply = await login_1.startMidSession(this.userId, this.net, this.loginUrl);
|
|
100
|
+
const sndReply = await (0, login_1.startMidSession)(this.userId, this.net, this.loginUrl);
|
|
101
101
|
if (sndReply.sessionId) {
|
|
102
102
|
return sndReply.sessionId;
|
|
103
103
|
}
|
|
@@ -107,7 +107,7 @@ class ServiceUser {
|
|
|
107
107
|
}
|
|
108
108
|
async authenticateSession(sessionId, midSigner) {
|
|
109
109
|
this.throwOnBadServiceURI();
|
|
110
|
-
await login_1.authenticateMidSession(sessionId, midSigner, this.net, this.loginUrl);
|
|
110
|
+
await (0, login_1.authenticateMidSession)(sessionId, midSigner, this.net, this.loginUrl);
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* This starts and authorizes a new session.
|
|
@@ -156,7 +156,7 @@ class ServiceUser {
|
|
|
156
156
|
this.sessionId = undefined;
|
|
157
157
|
}
|
|
158
158
|
else {
|
|
159
|
-
throw request_utils_1.makeException(rep, 'Unexpected status');
|
|
159
|
+
throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
async callEnsuringLogin(func) {
|
|
@@ -215,7 +215,7 @@ class ServiceUser {
|
|
|
215
215
|
};
|
|
216
216
|
return this.callEnsuringLogin(() => {
|
|
217
217
|
this.prepCallOpts(opts, true);
|
|
218
|
-
return ws_utils_1.openSocket(opts.url, opts.sessionId);
|
|
218
|
+
return (0, ws_utils_1.openSocket)(opts.url, opts.sessionId);
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
}
|