core-3nweb-client-lib 0.25.1 → 0.25.5

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.
@@ -29,7 +29,7 @@ function makeServicesSide(sendMsg) {
29
29
  }
30
30
  function makeClientsSide(sendMsg, syncReqToListObj, asyncReqToListObj) {
31
31
  const classFn = require('./connector-clients-side').ClientsSideImpl;
32
- return new classFn(sendMsg, syncReqToListObj);
32
+ return new classFn(sendMsg, syncReqToListObj, asyncReqToListObj);
33
33
  }
34
34
  class ObjectsConnector {
35
35
  constructor(msgSink, msgSrc, sides, listObj, listObjAsync) {
@@ -92,13 +92,13 @@ class ObjectsConnector {
92
92
  if (!this.messagingProc) {
93
93
  return;
94
94
  }
95
+ this.messagingProc.unsubscribe();
95
96
  if (err) {
96
97
  this.msgSink.error(err);
97
98
  }
98
99
  else {
99
100
  this.msgSink.complete();
100
101
  }
101
- this.messagingProc.unsubscribe();
102
102
  this.stop(false, err);
103
103
  }
104
104
  processIncomingMsg(msg) {
@@ -114,20 +114,12 @@ ${error_1.stringifyErr(err)}`;
114
114
  }
115
115
  }
116
116
  function recordUnhandledRejectionsInProcess() {
117
- const unhandlePromiseRejectionLogWait = 200;
118
- const unhandledRejections = new Map();
119
- process.on('unhandledRejection', (reason, p) => {
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.log(' -- 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.log(' -- Unhandled exception:', err);
131
123
  logError(err, 'Unhandled exception');
132
124
  });
133
125
  }
@@ -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 genBacketPath;
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,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.ObjFolders = exports.makeAlreadyExistExc = exports.makeNotFoundExc = void 0;
19
20
  const fs = require("../../lib-common/async-fs-node");
@@ -79,6 +80,8 @@ class ObjFolders {
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
- genBacketPath(backetIndex) {
127
- return path_1.join(this.generationsFolder, `${backetIndex}`);
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.genBacketPath(i), ...pathSections);
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.genBacketPath(found.genBacket), pathSections, this.accessFolder);
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.genBacketPath(found.genBacket));
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.genBacketPath(0), this.numOfSplits, this.logError))
192
+ const lst = (await allTreePaths(this.accessFolder, this.numOfSplits, this.logError))
190
193
  .map(pathSections => ({
191
- path: path_1.join(this.genBacketPath(0), ...pathSections),
192
- objId: pathSections.join()
194
+ path: path_1.join(this.accessFolder, ...pathSections),
195
+ objId: pathSections.join('')
193
196
  }));
194
- lst.unshift({
195
- objId: null,
196
- path: path_1.join(this.accessFolder, ROOT_OBJ_DIR)
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 (!exc.notFound) {
479
- await logError(exc, `Enumerating a split tree of objects, got an error while trying to directory list ${path}`);
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 <= 1) {
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];
@@ -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,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.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");
@@ -366,6 +366,29 @@ async function createEmptyFile(filePath, fileSize, keepFileOpen) {
366
366
  }
367
367
  }
368
368
  exports.createEmptyFile = createEmptyFile;
369
+ /**
370
+ * @param path
371
+ * @return a promise, resolvable to true, if given path represents directory,
372
+ * or false, if it does not.
373
+ */
374
+ async function existsFolder(path) {
375
+ try {
376
+ const stats = await stat(path);
377
+ if (stats.isDirectory()) {
378
+ return true;
379
+ }
380
+ else {
381
+ throw file_1.makeFileException(file_1.Code.notDirectory, path);
382
+ }
383
+ }
384
+ catch (e) {
385
+ if (e.code === file_1.Code.notFound) {
386
+ return false;
387
+ }
388
+ throw e;
389
+ }
390
+ }
391
+ exports.existsFolder = existsFolder;
369
392
  /**
370
393
  * @param path
371
394
  * @return true, if given path represents directory, or false, if it does not.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.25.1",
3
+ "version": "0.25.5",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",