core-3nweb-client-lib 0.25.3 → 0.26.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/files.d.ts +23 -20
- package/build/core/asmail/config/common.js +2 -2
- package/build/core/asmail/delivery/index.js +4 -3
- package/build/core/asmail/delivery/msg.js +5 -4
- package/build/core/asmail/delivery/per-recipient-wip.js +2 -2
- package/build/core/asmail/inbox/attachments/fs.js +6 -0
- package/build/core/asmail/inbox/cached-msgs.js +2 -2
- package/build/core/asmail/inbox/inbox-events.js +2 -1
- package/build/core/asmail/inbox/index.js +2 -2
- package/build/core/asmail/inbox/msg-downloader.js +2 -2
- package/build/core/asmail/inbox/msg-indexing.js +3 -3
- package/build/core/asmail/inbox/msg-on-disk.js +2 -2
- package/build/core/asmail/keyring/keyring-storage.js +2 -2
- package/build/core/asmail/sending-params/own-params.js +2 -2
- package/build/core/asmail/sending-params/params-from-others.js +2 -2
- package/build/core/id-manager.js +2 -2
- package/build/core/sign-in.d.ts +5 -4
- package/build/core/sign-in.js +9 -11
- package/build/core/sign-up.d.ts +1 -0
- package/build/core/sign-up.js +7 -3
- 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 +43 -0
- package/build/core/storage/common/obj-info-file.js +119 -3
- package/build/core/storage/index.js +1 -1
- package/build/core/storage/local/obj-files-gc.js +8 -6
- package/build/core/storage/local/obj-files.d.ts +3 -3
- package/build/core/storage/local/obj-files.js +9 -9
- package/build/core/storage/local/obj-status.d.ts +9 -25
- package/build/core/storage/local/obj-status.js +28 -110
- package/build/core/storage/local/storage.d.ts +8 -1
- package/build/core/storage/local/storage.js +10 -2
- package/build/core/storage/synced/downloader.js +6 -5
- package/build/core/storage/synced/obj-files-gc.d.ts +1 -0
- package/build/core/storage/synced/obj-files-gc.js +44 -5
- package/build/core/storage/synced/obj-files.d.ts +13 -20
- package/build/core/storage/synced/obj-files.js +70 -48
- package/build/core/storage/synced/obj-status.d.ts +74 -15
- package/build/core/storage/synced/obj-status.js +291 -107
- package/build/core/storage/synced/remote-events.js +32 -26
- package/build/core/storage/synced/storage.d.ts +11 -1
- package/build/core/storage/synced/storage.js +28 -3
- package/build/core/storage/synced/upsyncer.d.ts +8 -7
- package/build/core/storage/synced/upsyncer.js +211 -163
- package/build/ipc-via-protobuf/asmail-cap.js +17 -34
- package/build/ipc-via-protobuf/connector-clients-side.js +2 -2
- package/build/ipc-via-protobuf/file.js +26 -18
- package/build/ipc-via-protobuf/fs.js +33 -35
- package/build/ipc-via-protobuf/mailerid.js +3 -2
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +2 -0
- package/build/ipc-via-protobuf/protobuf-msg.js +11 -1
- package/build/ipc-via-protobuf/startup-cap.js +5 -5
- package/build/lib-client/3nstorage/exceptions.d.ts +9 -8
- package/build/lib-client/3nstorage/exceptions.js +18 -9
- package/build/lib-client/3nstorage/service.js +10 -6
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +18 -4
- package/build/lib-client/3nstorage/xsp-fs/common.js +6 -1
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +3 -3
- package/build/lib-client/3nstorage/xsp-fs/file.js +4 -1
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +27 -13
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +11 -6
- package/build/lib-client/3nstorage/xsp-fs/fs.js +189 -58
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +4 -0
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +51 -24
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +2 -2
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +2 -2
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +3 -3
- package/build/lib-client/cryptor/cryptor-in-worker.js +4 -4
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-wasm.js +2 -2
- package/build/lib-client/files.js +2 -0
- package/build/lib-client/fs-collection.js +3 -2
- package/build/lib-client/logging/log-to-file.js +6 -14
- package/build/lib-client/objs-on-disk/file-writing-proc.js +2 -2
- package/build/lib-client/objs-on-disk/obj-folders.d.ts +12 -1
- package/build/lib-client/objs-on-disk/obj-folders.js +26 -19
- package/build/lib-client/request-utils.js +2 -2
- package/build/lib-client/server-events.js +4 -3
- package/build/lib-client/ws-utils.js +2 -2
- package/build/lib-common/async-fs-node.d.ts +6 -0
- package/build/lib-common/async-fs-node.js +28 -4
- package/build/lib-common/byte-streaming/wrapping.js +17 -17
- package/build/lib-common/exceptions/file.js +6 -1
- package/build/lib-common/ipc/generic-ipc.js +2 -2
- package/build/lib-common/json-utils.js +2 -1
- package/build/lib-common/objs-on-disk/obj-file.js +4 -3
- package/build/lib-common/objs-on-disk/utils.js +2 -2
- 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/service-api/3nstorage/owner.d.ts +5 -4
- package/build/lib-common/service-api/3nstorage/owner.js +3 -2
- package/build/lib-common/utils-for-observables.d.ts +15 -1
- package/build/lib-common/utils-for-observables.js +68 -17
- package/build/protos/asmail.proto.js +404 -78
- package/build/protos/file.proto.js +370 -44
- package/build/protos/fs.proto.js +404 -78
- package/package.json +4 -4
- package/protos/file.proto +10 -2
- package/protos/fs.proto +2 -2
- package/build/core/storage/synced/upsync-status.d.ts +0 -41
- package/build/core/storage/synced/upsync-status.js +0 -158
|
Binary file
|
|
@@ -22,7 +22,7 @@ const fs_1 = require("fs");
|
|
|
22
22
|
const path_1 = require("path");
|
|
23
23
|
const protobuf_type_1 = require("../protobuf-type");
|
|
24
24
|
const cryptor_proto_1 = require("../../protos/cryptor.proto");
|
|
25
|
-
const
|
|
25
|
+
const deferred_1 = require("../../lib-common/processes/deferred");
|
|
26
26
|
const assert_1 = require("../../lib-common/assert");
|
|
27
27
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
28
28
|
function wasmBytes() {
|
|
@@ -77,7 +77,7 @@ function makeInProcessWasmCryptor() {
|
|
|
77
77
|
}
|
|
78
78
|
catch (err) { }
|
|
79
79
|
}
|
|
80
|
-
deferred =
|
|
80
|
+
deferred = deferred_1.defer();
|
|
81
81
|
if (interim) {
|
|
82
82
|
interimSink = interim;
|
|
83
83
|
}
|
|
@@ -255,6 +255,7 @@ function wrapIntoVersionlessReadonlyFS(fs, type) {
|
|
|
255
255
|
stat: async (path) => {
|
|
256
256
|
const stats = await fs.stat(path);
|
|
257
257
|
delete stats.version;
|
|
258
|
+
delete stats.sync;
|
|
258
259
|
return stats;
|
|
259
260
|
},
|
|
260
261
|
readonlyFile: async (path) => toVersionlessReadonlyFile(await fs.readonlyFile(path)),
|
|
@@ -291,6 +292,7 @@ function toVersionlessReadonlyFile(f) {
|
|
|
291
292
|
stat: async () => {
|
|
292
293
|
const stats = await f.stat();
|
|
293
294
|
delete stats.version;
|
|
295
|
+
delete stats.sync;
|
|
294
296
|
return stats;
|
|
295
297
|
},
|
|
296
298
|
watch: f.watch.bind(f),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017 - 2018 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017 - 2018, 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
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.makeFSCollection = exports.readonlyWrapFSCollection = void 0;
|
|
20
20
|
const rxjs_1 = require("rxjs");
|
|
21
|
+
const utils_for_observables_1 = require("../lib-common/utils-for-observables");
|
|
21
22
|
class FSItemsCollection {
|
|
22
23
|
constructor() {
|
|
23
24
|
this.items = new Map();
|
|
@@ -69,7 +70,7 @@ class FSItemsCollection {
|
|
|
69
70
|
return allItems;
|
|
70
71
|
}
|
|
71
72
|
watch(observer) {
|
|
72
|
-
const sub = this.change$.subscribe(observer);
|
|
73
|
+
const sub = this.change$.subscribe(utils_for_observables_1.toRxObserver(observer));
|
|
73
74
|
return () => sub.unsubscribe();
|
|
74
75
|
}
|
|
75
76
|
wrap() {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.makeLogger = exports.LOGS_FOLDER = void 0;
|
|
20
20
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
21
|
-
const
|
|
21
|
+
const synced_1 = require("../../lib-common/processes/synced");
|
|
22
22
|
const async_fs_node_1 = require("../../lib-common/async-fs-node");
|
|
23
23
|
const path_1 = require("path");
|
|
24
24
|
exports.LOGS_FOLDER = 'logs';
|
|
@@ -63,7 +63,7 @@ ${error_1.stringifyErr(err)}`;
|
|
|
63
63
|
console.error(err2);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
const loggingProc = new
|
|
66
|
+
const loggingProc = new synced_1.SingleProc();
|
|
67
67
|
function appendLog(s, now, appDomain) {
|
|
68
68
|
return loggingProc.startOrChain(async () => {
|
|
69
69
|
const logFile = path_1.join(utilDir, exports.LOGS_FOLDER, logFileName(now, appDomain));
|
|
@@ -114,20 +114,12 @@ ${error_1.stringifyErr(err)}`;
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
function recordUnhandledRejectionsInProcess() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
unhandledRejections.set(p, reason);
|
|
121
|
-
setTimeout(() => {
|
|
122
|
-
if (!unhandledRejections.has(p)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
unhandledRejections.delete(p);
|
|
126
|
-
logError(reason, `Unhandled exception in promise (logged after ${unhandlePromiseRejectionLogWait} milliseconds wait)`).catch(noop);
|
|
127
|
-
}, unhandlePromiseRejectionLogWait).unref();
|
|
117
|
+
process.on('unhandledRejection', (err, p) => {
|
|
118
|
+
console.error(' -- Unhandled rejection of promise:', err);
|
|
119
|
+
logError(err, 'Unhandled rejection of promise');
|
|
128
120
|
});
|
|
129
|
-
process.on('rejectionHandled', p => unhandledRejections.delete(p));
|
|
130
121
|
process.on('uncaughtException', err => {
|
|
122
|
+
console.error(' -- Unhandled exception:', err);
|
|
131
123
|
logError(err, 'Unhandled exception');
|
|
132
124
|
});
|
|
133
125
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.FileWritingProc = void 0;
|
|
20
|
-
const
|
|
20
|
+
const pressure_1 = require("../../lib-common/processes/pressure");
|
|
21
21
|
const rxjs_1 = require("rxjs");
|
|
22
22
|
const operators_1 = require("rxjs/operators");
|
|
23
23
|
const buffer_utils_1 = require("../../lib-common/buffer-utils");
|
|
@@ -27,7 +27,7 @@ const BACKPRESSURE_BUF_SIZE = 5 * 1024 * 1024;
|
|
|
27
27
|
class FileWritingProc {
|
|
28
28
|
constructor(objFile) {
|
|
29
29
|
this.objFile = objFile;
|
|
30
|
-
this.pValve = new
|
|
30
|
+
this.pValve = new pressure_1.PressureValve();
|
|
31
31
|
this.buffer = { segs: [], size: 0 };
|
|
32
32
|
Object.seal(this);
|
|
33
33
|
}
|
|
@@ -8,6 +8,17 @@ export interface Exception extends web3n.RuntimeException {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function makeNotFoundExc(msg: string): Exception;
|
|
10
10
|
export declare function makeAlreadyExistExc(msg: string): Exception;
|
|
11
|
+
export interface GenerationCfg {
|
|
12
|
+
period: number;
|
|
13
|
+
lastDone: number;
|
|
14
|
+
}
|
|
15
|
+
export interface Cfg {
|
|
16
|
+
numOfSplits: number;
|
|
17
|
+
charsInSplit: number;
|
|
18
|
+
}
|
|
19
|
+
export interface CfgWithGens extends Cfg {
|
|
20
|
+
generations: GenerationCfg[];
|
|
21
|
+
}
|
|
11
22
|
export declare type CanMoveObjToDeeperCache = (objId: string, folderPath: string) => Promise<boolean>;
|
|
12
23
|
export declare class ObjFolders {
|
|
13
24
|
private readonly path;
|
|
@@ -27,7 +38,7 @@ export declare class ObjFolders {
|
|
|
27
38
|
static makeSimple(path: string, logError: LogError): Promise<ObjFolders>;
|
|
28
39
|
private readonly saveCfg;
|
|
29
40
|
private idToPathSections;
|
|
30
|
-
private
|
|
41
|
+
private genBucketPath;
|
|
31
42
|
private findObjFolder;
|
|
32
43
|
getFolderAccessFor(objId: ObjId, createIfMissing?: boolean): Promise<string | undefined>;
|
|
33
44
|
removeFolderOf(objId: string): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2016 - 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -13,11 +13,12 @@
|
|
|
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.ObjFolders = exports.makeAlreadyExistExc = exports.makeNotFoundExc = void 0;
|
|
19
20
|
const fs = require("../../lib-common/async-fs-node");
|
|
20
|
-
const
|
|
21
|
+
const synced_1 = require("../../lib-common/processes/synced");
|
|
21
22
|
const xsp_files_1 = require("xsp-files");
|
|
22
23
|
const assert_1 = require("../../lib-common/assert");
|
|
23
24
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
@@ -73,12 +74,14 @@ class ObjFolders {
|
|
|
73
74
|
/**
|
|
74
75
|
* Process ids here are values of the first section in each folder tree.
|
|
75
76
|
*/
|
|
76
|
-
this.syncProcs = new
|
|
77
|
+
this.syncProcs = new synced_1.NamedProcs();
|
|
77
78
|
this.saveCfg = () => writeCfgTo(this.path, {
|
|
78
79
|
charsInSplit: this.charsInSplit,
|
|
79
80
|
numOfSplits: this.numOfSplits,
|
|
80
81
|
generations: this.generations
|
|
81
82
|
});
|
|
83
|
+
assert_1.assert(Number.isInteger(this.numOfSplits) && (this.numOfSplits > 0) &&
|
|
84
|
+
Number.isInteger(this.charsInSplit) && (this.charsInSplit > 0));
|
|
82
85
|
this.accessFolder = path_1.join(this.path, ACCESS_DIR);
|
|
83
86
|
if (this.generations) {
|
|
84
87
|
if (!canMove) {
|
|
@@ -123,8 +126,8 @@ class ObjFolders {
|
|
|
123
126
|
path.push(objId.substring(this.numOfSplits * this.charsInSplit));
|
|
124
127
|
return path;
|
|
125
128
|
}
|
|
126
|
-
|
|
127
|
-
return path_1.join(this.generationsFolder, `${
|
|
129
|
+
genBucketPath(bucketIndex) {
|
|
130
|
+
return path_1.join(this.generationsFolder, `${bucketIndex}`);
|
|
128
131
|
}
|
|
129
132
|
async findObjFolder(pathSections) {
|
|
130
133
|
const folder = path_1.join(this.accessFolder, ...pathSections);
|
|
@@ -135,7 +138,7 @@ class ObjFolders {
|
|
|
135
138
|
return;
|
|
136
139
|
}
|
|
137
140
|
for (let i = 0; i < this.generations.length; i += 1) {
|
|
138
|
-
const folder = path_1.join(this.
|
|
141
|
+
const folder = path_1.join(this.genBucketPath(i), ...pathSections);
|
|
139
142
|
if (await folderExists(folder)) {
|
|
140
143
|
return { folder, genBacket: i };
|
|
141
144
|
}
|
|
@@ -162,7 +165,7 @@ class ObjFolders {
|
|
|
162
165
|
if (found.genBacket === undefined) {
|
|
163
166
|
return found.folder;
|
|
164
167
|
}
|
|
165
|
-
const folder = await move(this.
|
|
168
|
+
const folder = await move(this.genBucketPath(found.genBacket), pathSections, this.accessFolder);
|
|
166
169
|
return folder;
|
|
167
170
|
}
|
|
168
171
|
if (!createIfMissing) {
|
|
@@ -181,20 +184,20 @@ class ObjFolders {
|
|
|
181
184
|
return;
|
|
182
185
|
}
|
|
183
186
|
const backetPath = ((found.genBacket === undefined) ?
|
|
184
|
-
this.accessFolder : this.
|
|
187
|
+
this.accessFolder : this.genBucketPath(found.genBacket));
|
|
185
188
|
await deleteTree(backetPath, pathSections);
|
|
186
189
|
});
|
|
187
190
|
}
|
|
188
191
|
async listRecent() {
|
|
189
|
-
const lst = (await allTreePaths(this.
|
|
192
|
+
const lst = (await allTreePaths(this.accessFolder, this.numOfSplits, this.logError))
|
|
190
193
|
.map(pathSections => ({
|
|
191
|
-
path: path_1.join(this.
|
|
192
|
-
objId: pathSections.join()
|
|
194
|
+
path: path_1.join(this.accessFolder, ...pathSections),
|
|
195
|
+
objId: pathSections.join('')
|
|
193
196
|
}));
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
197
|
+
const rootObjPath = path_1.join(this.accessFolder, ROOT_OBJ_DIR);
|
|
198
|
+
if (await fs.existsFolder(rootObjPath)) {
|
|
199
|
+
lst.unshift({ objId: null, path: rootObjPath });
|
|
200
|
+
}
|
|
198
201
|
return lst;
|
|
199
202
|
}
|
|
200
203
|
}
|
|
@@ -475,19 +478,23 @@ function checkCfg(cfg, needGens = false) {
|
|
|
475
478
|
async function allTreePaths(path, numOfSplits, logError) {
|
|
476
479
|
const lst = await fs.readdir(path)
|
|
477
480
|
.catch(async (exc) => {
|
|
478
|
-
if (
|
|
479
|
-
|
|
481
|
+
if (exc.notFound) {
|
|
482
|
+
return;
|
|
480
483
|
}
|
|
484
|
+
await logError(exc, `Enumerating a split tree of objects, got an error while trying to list directory ${path}`);
|
|
481
485
|
});
|
|
482
486
|
if (!lst) {
|
|
483
487
|
return [];
|
|
484
488
|
}
|
|
485
|
-
if (numOfSplits <=
|
|
489
|
+
if (numOfSplits <= 0) {
|
|
486
490
|
return lst.map(f => [f]);
|
|
487
491
|
}
|
|
488
492
|
const sections = [];
|
|
489
493
|
for (let i = 0; i < lst.length; i += 1) {
|
|
490
494
|
const f = lst[i];
|
|
495
|
+
if (f === ROOT_OBJ_DIR) {
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
491
498
|
const treePaths = await allTreePaths(path_1.join(path, f), numOfSplits - 1, logError);
|
|
492
499
|
for (let j = 0; j < treePaths.length; j += 1) {
|
|
493
500
|
const branch = treePaths[j];
|
|
@@ -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';
|
|
@@ -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 = 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)));
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.ServerEvents = void 0;
|
|
19
19
|
const rxjs_1 = require("rxjs");
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../lib-common/processes/synced");
|
|
21
|
+
const sleep_1 = require("../lib-common/processes/sleep");
|
|
21
22
|
const operators_1 = require("rxjs/operators");
|
|
22
23
|
const error_1 = require("../lib-common/exceptions/error");
|
|
23
24
|
class ServerEvents {
|
|
@@ -25,7 +26,7 @@ class ServerEvents {
|
|
|
25
26
|
this.subscribeToServer = subscribeToServer;
|
|
26
27
|
this.restartWaitSecs = restartWaitSecs;
|
|
27
28
|
this.server = undefined;
|
|
28
|
-
this.openningServer = new
|
|
29
|
+
this.openningServer = new synced_1.SingleProc();
|
|
29
30
|
Object.seal(this);
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
@@ -106,7 +107,7 @@ class ServerEvents {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
restartObservation(event) {
|
|
109
|
-
return rxjs_1.from(
|
|
110
|
+
return rxjs_1.from(sleep_1.sleep(this.restartWaitSecs * 1000))
|
|
110
111
|
.pipe(operators_1.mergeMap(() => this.observe(event)));
|
|
111
112
|
}
|
|
112
113
|
}
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.openSocket = void 0;
|
|
19
19
|
const WebSocket = require("ws");
|
|
20
20
|
const request_utils_1 = require("./request-utils");
|
|
21
|
-
const
|
|
21
|
+
const deferred_1 = require("../lib-common/processes/deferred");
|
|
22
22
|
const http_1 = require("../lib-common/exceptions/http");
|
|
23
23
|
const https_1 = require("https");
|
|
24
24
|
function openSocket(url, sessionId) {
|
|
@@ -28,7 +28,7 @@ function openSocket(url, sessionId) {
|
|
|
28
28
|
const headers = {};
|
|
29
29
|
headers[request_utils_1.SESSION_ID_HEADER] = sessionId;
|
|
30
30
|
const ws = new WebSocket(url, { headers, agent: https_1.globalAgent });
|
|
31
|
-
const opening =
|
|
31
|
+
const opening = deferred_1.defer();
|
|
32
32
|
const initOnError = err => opening.reject(http_1.makeConnectionException(url, undefined, `Cannot open websocket connection due to error: ${err.message}`));
|
|
33
33
|
const onNonOkReply = (req, res) => {
|
|
34
34
|
const errReply = {
|
|
@@ -64,6 +64,12 @@ export declare function writeFromBuf(fd: number, pos: number, buf: Buffer): Prom
|
|
|
64
64
|
* else return value is undefined and should be ignored.
|
|
65
65
|
*/
|
|
66
66
|
export declare function createEmptyFile(filePath: string, fileSize: number, keepFileOpen?: boolean): Promise<number | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* @param path
|
|
69
|
+
* @return a promise, resolvable to true, if given path represents directory,
|
|
70
|
+
* or false, if it does not.
|
|
71
|
+
*/
|
|
72
|
+
export declare function existsFolder(path: string): Promise<boolean>;
|
|
67
73
|
/**
|
|
68
74
|
* @param path
|
|
69
75
|
* @return true, if given path represents directory, or false, if it does not.
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.ensureFolderExists = exports.copyTree = exports.copyFile = exports.streamFromFile = exports.rmDirWithContent = exports.read = exports.streamToExistingFile = exports.append = exports.write = exports.getFolderContentSize = exports.getFileSize = exports.existsFileSync = exports.existsFolderSync = exports.createEmptyFile = exports.writeFromBuf = exports.readToBuf = exports.ftruncate = exports.truncate = exports.rename = exports.unlink = exports.rmdir = exports.readdir = exports.fstat = exports.stat = exports.lstat = exports.readlink = exports.symlink = exports.close = exports.open = exports.mkdir = exports.appendFile = exports.writeFile = exports.readFile = void 0;
|
|
19
|
+
exports.ensureFolderExists = exports.copyTree = exports.copyFile = exports.streamFromFile = exports.rmDirWithContent = exports.read = exports.streamToExistingFile = exports.append = exports.write = exports.getFolderContentSize = exports.getFileSize = exports.existsFileSync = exports.existsFolderSync = exports.existsFolder = exports.createEmptyFile = exports.writeFromBuf = exports.readToBuf = exports.ftruncate = exports.truncate = exports.rename = exports.unlink = exports.rmdir = exports.readdir = exports.fstat = exports.stat = exports.lstat = exports.readlink = exports.symlink = exports.close = exports.open = exports.mkdir = exports.appendFile = exports.writeFile = exports.readFile = void 0;
|
|
20
20
|
const fs = require("fs");
|
|
21
21
|
const fs_1 = require("fs");
|
|
22
22
|
const file_1 = require("./exceptions/file");
|
|
23
|
-
const
|
|
23
|
+
const synced_1 = require("./processes/synced");
|
|
24
|
+
const deferred_1 = require("./processes/deferred");
|
|
24
25
|
const bytes_fifo_buffer_1 = require("./byte-streaming/bytes-fifo-buffer");
|
|
25
26
|
const buffer_utils_1 = require("./buffer-utils");
|
|
26
27
|
const path_1 = require("path");
|
|
@@ -366,6 +367,29 @@ async function createEmptyFile(filePath, fileSize, keepFileOpen) {
|
|
|
366
367
|
}
|
|
367
368
|
}
|
|
368
369
|
exports.createEmptyFile = createEmptyFile;
|
|
370
|
+
/**
|
|
371
|
+
* @param path
|
|
372
|
+
* @return a promise, resolvable to true, if given path represents directory,
|
|
373
|
+
* or false, if it does not.
|
|
374
|
+
*/
|
|
375
|
+
async function existsFolder(path) {
|
|
376
|
+
try {
|
|
377
|
+
const stats = await stat(path);
|
|
378
|
+
if (stats.isDirectory()) {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
throw file_1.makeFileException(file_1.Code.notDirectory, path);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (e) {
|
|
386
|
+
if (e.code === file_1.Code.notFound) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
throw e;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
exports.existsFolder = existsFolder;
|
|
369
393
|
/**
|
|
370
394
|
* @param path
|
|
371
395
|
* @return true, if given path represents directory, or false, if it does not.
|
|
@@ -504,11 +528,11 @@ async function streamToExistingFile(filePath, pos, len, src, bufSize) {
|
|
|
504
528
|
if ((typeof bufSize !== 'number') || (bufSize < 1024)) {
|
|
505
529
|
throw new Error('Illegal buffer size given: ' + bufSize);
|
|
506
530
|
}
|
|
507
|
-
const writeProc = new
|
|
531
|
+
const writeProc = new synced_1.SingleProc();
|
|
508
532
|
let bytesWritten = 0;
|
|
509
533
|
let bytesRead = 0;
|
|
510
534
|
const buf = new bytes_fifo_buffer_1.BytesFIFOBuffer();
|
|
511
|
-
let deferred =
|
|
535
|
+
let deferred = deferred_1.defer();
|
|
512
536
|
let doneReading = false;
|
|
513
537
|
const complete = (err) => {
|
|
514
538
|
if (!deferred) {
|
|
@@ -17,37 +17,37 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.wrapAndSyncFileSource = exports.wrapAndSyncSource = exports.wrapAndSyncFileSink = void 0;
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../processes/synced");
|
|
21
21
|
function wrapAndSyncFileSink(sink) {
|
|
22
|
-
const syncProc = new
|
|
22
|
+
const syncProc = new synced_1.SingleProc();
|
|
23
23
|
const w = {
|
|
24
|
-
done:
|
|
25
|
-
getSize:
|
|
26
|
-
showLayout:
|
|
27
|
-
splice:
|
|
28
|
-
truncate:
|
|
24
|
+
done: synced_1.makeSyncedFunc(syncProc, sink, sink.done),
|
|
25
|
+
getSize: synced_1.makeSyncedFunc(syncProc, sink, sink.getSize),
|
|
26
|
+
showLayout: synced_1.makeSyncedFunc(syncProc, sink, sink.showLayout),
|
|
27
|
+
splice: synced_1.makeSyncedFunc(syncProc, sink, sink.splice),
|
|
28
|
+
truncate: synced_1.makeSyncedFunc(syncProc, sink, sink.truncate)
|
|
29
29
|
};
|
|
30
30
|
return w;
|
|
31
31
|
}
|
|
32
32
|
exports.wrapAndSyncFileSink = wrapAndSyncFileSink;
|
|
33
33
|
function wrapAndSyncSource(src) {
|
|
34
|
-
const syncProc = new
|
|
34
|
+
const syncProc = new synced_1.SingleProc();
|
|
35
35
|
const w = {
|
|
36
|
-
getPosition:
|
|
37
|
-
getSize:
|
|
38
|
-
read:
|
|
39
|
-
seek:
|
|
36
|
+
getPosition: synced_1.makeSyncedFunc(syncProc, src, src.getPosition),
|
|
37
|
+
getSize: synced_1.makeSyncedFunc(syncProc, src, src.getSize),
|
|
38
|
+
read: synced_1.makeSyncedFunc(syncProc, src, src.read),
|
|
39
|
+
seek: synced_1.makeSyncedFunc(syncProc, src, src.seek)
|
|
40
40
|
};
|
|
41
41
|
return w;
|
|
42
42
|
}
|
|
43
43
|
exports.wrapAndSyncSource = wrapAndSyncSource;
|
|
44
44
|
function wrapAndSyncFileSource(src) {
|
|
45
|
-
const syncProc = new
|
|
45
|
+
const syncProc = new synced_1.SingleProc();
|
|
46
46
|
const w = {
|
|
47
|
-
getPosition:
|
|
48
|
-
getSize:
|
|
49
|
-
read:
|
|
50
|
-
seek:
|
|
47
|
+
getPosition: synced_1.makeSyncedFunc(syncProc, src, src.getPosition),
|
|
48
|
+
getSize: synced_1.makeSyncedFunc(syncProc, src, src.getSize),
|
|
49
|
+
read: synced_1.makeSyncedFunc(syncProc, src, src.read),
|
|
50
|
+
seek: synced_1.makeSyncedFunc(syncProc, src, src.seek),
|
|
51
51
|
};
|
|
52
52
|
return w;
|
|
53
53
|
}
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.makeVersionMismatchExc = exports.makeNoAttrsExc = exports.ensureCorrectFS = exports.maskPathInExc = exports.makeFileException = exports.Code = void 0;
|
|
19
20
|
exports.Code = {
|
|
@@ -32,6 +33,7 @@ exports.Code = {
|
|
|
32
33
|
parsingError: 'parsing-error',
|
|
33
34
|
notImplemented: 'ENOSYS',
|
|
34
35
|
isEndless: 'is-endless',
|
|
36
|
+
storageClosed: 'storage-closed',
|
|
35
37
|
};
|
|
36
38
|
Object.freeze(exports.Code);
|
|
37
39
|
function makeFileException(code, path, cause) {
|
|
@@ -87,6 +89,9 @@ function makeFileException(code, path, cause) {
|
|
|
87
89
|
else if (code === exports.Code.isEndless) {
|
|
88
90
|
err.isEndless = true;
|
|
89
91
|
}
|
|
92
|
+
else if (code === exports.Code.storageClosed) {
|
|
93
|
+
err.storageClosed = true;
|
|
94
|
+
}
|
|
90
95
|
return err;
|
|
91
96
|
}
|
|
92
97
|
exports.makeFileException = makeFileException;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.SingleObserverWrap = exports.MultiObserverWrap = exports.makeSubscribingClient = exports.makeEventfulServer = exports.makeRequestServer = exports.makeRequestingClient = void 0;
|
|
19
19
|
const map_of_sets_1 = require("../map-of-sets");
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../processes/synced");
|
|
21
21
|
function toTransferrableError(e) {
|
|
22
22
|
const err = {
|
|
23
23
|
message: e.message,
|
|
@@ -556,7 +556,7 @@ class IpcEventChannels {
|
|
|
556
556
|
* These are all subscribed ipc channels.
|
|
557
557
|
*/
|
|
558
558
|
this.subscribedIpcChannels = new Set();
|
|
559
|
-
this.subscriptionProcs = new
|
|
559
|
+
this.subscriptionProcs = new synced_1.NamedProcs();
|
|
560
560
|
Object.freeze(this);
|
|
561
561
|
}
|
|
562
562
|
subscribeTo(ipcChannel) {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.applyChangesToJSON = exports.deepFind = exports.deepEqual = exports.copy = void 0;
|
|
19
20
|
/**
|
|
@@ -20,7 +20,8 @@ exports.ObjVersionFile = void 0;
|
|
|
20
20
|
const fs = require("../async-fs-node");
|
|
21
21
|
const error_1 = require("../exceptions/error");
|
|
22
22
|
const bytes_equal_1 = require("../bytes-equal");
|
|
23
|
-
const
|
|
23
|
+
const synced_1 = require("../processes/synced");
|
|
24
|
+
const deferred_1 = require("../processes/deferred");
|
|
24
25
|
const buffer_utils_1 = require("../buffer-utils");
|
|
25
26
|
const v1_obj_file_format_1 = require("./v1-obj-file-format");
|
|
26
27
|
const fs_1 = require("fs");
|
|
@@ -30,7 +31,7 @@ class ObjVersionFile {
|
|
|
30
31
|
constructor(path, layout) {
|
|
31
32
|
this.path = path;
|
|
32
33
|
this.layout = layout;
|
|
33
|
-
this.writeProc = new
|
|
34
|
+
this.writeProc = new synced_1.SingleProc();
|
|
34
35
|
Object.seal(this);
|
|
35
36
|
}
|
|
36
37
|
static async forExisting(path) {
|
|
@@ -240,7 +241,7 @@ Object.freeze(ObjVersionFile.prototype);
|
|
|
240
241
|
Object.freeze(ObjVersionFile);
|
|
241
242
|
function noop() { }
|
|
242
243
|
async function pipeBytes(src, sink) {
|
|
243
|
-
const deferred =
|
|
244
|
+
const deferred = deferred_1.defer();
|
|
244
245
|
src.pipe(sink, { end: false });
|
|
245
246
|
src.on('error', (err) => {
|
|
246
247
|
deferred.reject(err);
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.makeNoBaseObjPipe = exports.makeObjPipe = exports.chunksInOrderedStream = exports.streamToObjFile = exports.diffToLayout = void 0;
|
|
20
|
-
const
|
|
20
|
+
const deferred_1 = require("../processes/deferred");
|
|
21
21
|
const file_1 = require("../exceptions/file");
|
|
22
22
|
const assert_1 = require("../assert");
|
|
23
23
|
const bytes_fifo_buffer_1 = require("../byte-streaming/bytes-fifo-buffer");
|
|
@@ -42,7 +42,7 @@ function diffToLayout(diff) {
|
|
|
42
42
|
}
|
|
43
43
|
exports.diffToLayout = diffToLayout;
|
|
44
44
|
async function streamToObjFile(file, content, src, maxBufferLen) {
|
|
45
|
-
let deferred =
|
|
45
|
+
let deferred = deferred_1.defer();
|
|
46
46
|
const contentIter = content.values();
|
|
47
47
|
let chunk = undefined;
|
|
48
48
|
let buf = new bytes_fifo_buffer_1.BytesFIFOBuffer();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2015, 2017, 2019 - 2022 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
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/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.defer = void 0;
|
|
20
|
+
function defer() {
|
|
21
|
+
const d = {};
|
|
22
|
+
d.promise = new Promise((resolve, reject) => {
|
|
23
|
+
d.resolve = resolve;
|
|
24
|
+
d.reject = reject;
|
|
25
|
+
});
|
|
26
|
+
Object.freeze(d);
|
|
27
|
+
return d;
|
|
28
|
+
}
|
|
29
|
+
exports.defer = defer;
|
|
30
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface Task<PoolLabel extends string> {
|
|
2
|
+
neededExecutor(): PoolLabel | undefined;
|
|
3
|
+
process(): Promise<void>;
|
|
4
|
+
cancel(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
declare class ProcessingPool<PoolLabel extends string> {
|
|
7
|
+
readonly label: PoolLabel;
|
|
8
|
+
private readonly maxProcs;
|
|
9
|
+
private readonly logError?;
|
|
10
|
+
private readonly inProcess;
|
|
11
|
+
private readonly queue;
|
|
12
|
+
isRunning: boolean;
|
|
13
|
+
constructor(label: PoolLabel, maxProcs: number, logError?: ((err: any, msg?: string | undefined) => Promise<void>) | undefined);
|
|
14
|
+
add(task: Task<any>): void;
|
|
15
|
+
private processNextQueued;
|
|
16
|
+
pause(): void;
|
|
17
|
+
start(): void;
|
|
18
|
+
private readonly doOnError;
|
|
19
|
+
stop(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare class LabelledExecPools<PoolLabel extends string> {
|
|
22
|
+
private readonly pools;
|
|
23
|
+
private isRunning;
|
|
24
|
+
constructor(setup: {
|
|
25
|
+
label: PoolLabel;
|
|
26
|
+
maxProcs: number;
|
|
27
|
+
}[], logError?: ProcessingPool<PoolLabel>['logError']);
|
|
28
|
+
add(task: Task<PoolLabel>, queueIfNotRunning?: boolean): void;
|
|
29
|
+
start(): void;
|
|
30
|
+
pause(): void;
|
|
31
|
+
stop(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|