core-3nweb-client-lib 0.18.5 → 0.19.1

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.
@@ -116,6 +116,7 @@ declare namespace web3n.startup {
116
116
  interface W3N {
117
117
  signIn: startup.SignInService;
118
118
  signUp: startup.SignUpService;
119
+ log?: caps.common.Logger;
119
120
  }
120
121
 
121
122
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (C) 2016 - 2017 3NSoft Inc.
2
+ Copyright (C) 2016 - 2017, 2021 3NSoft Inc.
3
3
 
4
4
  This program is free software: you can redistribute it and/or modify it under
5
5
  the terms of the GNU General Public License as published by the Free Software
@@ -19,7 +19,7 @@
19
19
  * This is a namespace for things used by storage and any file functionality.
20
20
  */
21
21
  declare namespace web3n.storage {
22
-
22
+
23
23
  interface Service {
24
24
 
25
25
  /**
@@ -57,4 +57,13 @@ declare namespace web3n.storage {
57
57
  type StorageType = 'device'|'synced'|'local';
58
58
  type StorageUse = 'user'|'system'|'app';
59
59
 
60
+ interface StorageException extends web3n.RuntimeException {
61
+ type: 'storage';
62
+ appName?: string;
63
+ badAppName?: boolean;
64
+ notAllowedToOpenFS?: boolean;
65
+ storageType?: StorageType;
66
+ storageSegment: StorageUse;
67
+ }
68
+
60
69
  }
@@ -176,7 +176,7 @@ class Msg {
176
176
  return this.progress.allDone;
177
177
  }
178
178
  isSendingNow() {
179
- return !!this.sendingProc.getP();
179
+ return !!this.sendingProc.isProcessing();
180
180
  }
181
181
  deliverySizeLeft() {
182
182
  if (this.progress.allDone) {
@@ -210,7 +210,7 @@ class Msg {
210
210
  return;
211
211
  }
212
212
  this.cancelled = true;
213
- const filesProc = this.progressSavingProc.getP();
213
+ const filesProc = this.progressSavingProc.latestTaskAtThisMoment();
214
214
  if (!filesProc) {
215
215
  return;
216
216
  }
@@ -82,7 +82,7 @@ class WIP {
82
82
  * or if this wip is done, undefined is returned.
83
83
  */
84
84
  startNext() {
85
- let proc = this.proc.getP();
85
+ let proc = this.proc.latestTaskAtThisMoment();
86
86
  if (proc) {
87
87
  return;
88
88
  }
@@ -78,7 +78,7 @@ class InboxOnServer {
78
78
  async removeMsg(msgId) {
79
79
  // check for an already started process
80
80
  const procId = 'removal of ' + msgId;
81
- const promise = this.procs.getP(procId);
81
+ const promise = this.procs.latestTaskAtThisMoment(procId);
82
82
  if (promise) {
83
83
  return promise;
84
84
  }
@@ -194,7 +194,7 @@ class InboxOnServer {
194
194
  }
195
195
  // check for an already started process
196
196
  const procId = 'listing msgs';
197
- const promise = this.procs.getP(procId);
197
+ const promise = this.procs.latestTaskAtThisMoment(procId);
198
198
  if (promise) {
199
199
  return promise;
200
200
  }
@@ -234,7 +234,7 @@ class InboxOnServer {
234
234
  throw `Given message id is not a non-empty string`;
235
235
  }
236
236
  const procId = `get msg #${msgId}`;
237
- const promise = this.procs.getP(procId);
237
+ const promise = this.procs.latestTaskAtThisMoment(procId);
238
238
  if (promise) {
239
239
  return promise;
240
240
  }
@@ -192,7 +192,7 @@ class IdManager {
192
192
  }
193
193
  }
194
194
  async provisionUsingSavedKey() {
195
- let proc = this.provisioningProc.getP();
195
+ let proc = this.provisioningProc.latestTaskAtThisMoment();
196
196
  if (proc) {
197
197
  return proc;
198
198
  }
@@ -22,7 +22,7 @@ export declare class Core {
22
22
  private closingProc;
23
23
  private constructor();
24
24
  static make(conf: CoreConf, makeNet: () => NetClient, makeResolver: ServiceLocatorMaker, makeCryptor: makeCryptor): Core;
25
- start(): {
25
+ start(logCAP?: boolean): {
26
26
  capsForStartup: web3n.startup.W3N;
27
27
  coreInit: Promise<string>;
28
28
  };
@@ -30,6 +30,7 @@ const operators_1 = require("rxjs/operators");
30
30
  const app_files_1 = require("./app-files");
31
31
  const ASMAIL_APP_NAME = 'computer.3nweb.core.asmail';
32
32
  const MAILERID_APP_NAME = 'computer.3nweb.core.mailerid';
33
+ const STARTUP_APP_DOMAIN = 'startup.3nweb.computer';
33
34
  class Core {
34
35
  constructor(makeNet, makeResolver, makeCryptor, appDirs, logger, signUpUrl) {
35
36
  this.makeNet = makeNet;
@@ -111,13 +112,16 @@ class Core {
111
112
  const core = new Core(makeNet, makeResolver, makeCryptor, dirs, logger, conf.signUpUrl);
112
113
  return core;
113
114
  }
114
- start() {
115
+ start(logCAP = false) {
115
116
  const signUp = new sign_up_1.SignUp(this.signUpUrl, this.cryptor.cryptor, this.makeNet, this.appDirs.getUsersOnDisk, this.logger.logError);
116
117
  const signIn = new sign_in_1.SignIn(this.cryptor.cryptor, this.initForExistingUserWithoutCache, this.initForExistingUserWithCache, this.appDirs.getUsersOnDisk, this.logger.logError);
117
118
  const capsForStartup = {
118
119
  signUp: signUp.exposedService(),
119
120
  signIn: signIn.exposedService()
120
121
  };
122
+ if (logCAP) {
123
+ capsForStartup.log = (type, msg, e) => this.logger.appLog(type, STARTUP_APP_DOMAIN, msg, e);
124
+ }
121
125
  Object.freeze(capsForStartup);
122
126
  const initFromSignUp$ = signUp.newUser$
123
127
  .pipe(operators_1.mergeMap(this.initForNewUser, 1));
@@ -1,7 +1,6 @@
1
1
  import { GetSigner } from '../id-manager';
2
2
  import { GenerateKey } from '../sign-in';
3
3
  import { StorageGetter } from '../../lib-client/3nstorage/xsp-fs/common';
4
- import { StorageException as BaseExc } from '../../lib-client/3nstorage/exceptions';
5
4
  import { ServiceLocator } from '../../lib-client/service-locator';
6
5
  import { AsyncSBoxCryptor } from 'xsp-files';
7
6
  import { NetClient } from '../../lib-client/request-utils';
@@ -10,13 +9,6 @@ import { LogError } from '../../lib-client/logging/log-to-file';
10
9
  declare type WritableFS = web3n.files.WritableFS;
11
10
  declare type StorageType = web3n.storage.StorageType;
12
11
  declare type FSItem = web3n.files.FSItem;
13
- export interface StorageException extends BaseExc {
14
- appName?: string;
15
- badAppName?: boolean;
16
- notAllowedToOpenFS?: boolean;
17
- storageType?: StorageType;
18
- storageSegment: 'app' | 'system' | 'user';
19
- }
20
12
  export declare const sysFolders: {
21
13
  appData: string;
22
14
  apps: string;
@@ -39,7 +39,7 @@ class GC {
39
39
  this.scheduled = new Set();
40
40
  this.scheduleCollection = (obj) => {
41
41
  this.scheduled.add(obj);
42
- if (this.gcProc.getP()) {
42
+ if (this.gcProc.isProcessing()) {
43
43
  return;
44
44
  }
45
45
  this.gcProc.start(this.objCollecting);
@@ -42,7 +42,7 @@ class GC {
42
42
  return;
43
43
  }
44
44
  this.scheduled.add(obj);
45
- if (this.gcProc.getP()) {
45
+ if (this.gcProc.isProcessing()) {
46
46
  return;
47
47
  }
48
48
  this.gcProc.start(this.objCollecting);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2020 3NSoft Inc.
3
+ Copyright (C) 2020 - 2021 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,21 +18,30 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.makeStartupW3Nclient = exports.exposeStartupW3N = void 0;
20
20
  const connector_1 = require("../ipc-via-protobuf/connector");
21
+ const log_cap_1 = require("../ipc-via-protobuf/log-cap");
21
22
  const startup_cap_1 = require("../ipc-via-protobuf/startup-cap");
22
23
  function exposeStartupW3N(coreSide, w3n) {
23
24
  const expW3N = {
24
25
  signIn: startup_cap_1.wrapSignInCAP(w3n.signIn),
25
26
  signUp: startup_cap_1.wrapSignUpCAP(w3n.signUp)
26
27
  };
28
+ if (w3n.log) {
29
+ expW3N.log = log_cap_1.exposeLogger(w3n.log);
30
+ }
27
31
  coreSide.exposeW3NService(expW3N);
28
32
  }
29
33
  exports.exposeStartupW3N = exposeStartupW3N;
30
34
  function makeStartupW3Nclient(clientSide) {
31
35
  const objPath = [connector_1.W3N_NAME];
32
- return {
36
+ const lstOfCAPs = clientSide.listObj(objPath);
37
+ const w3n = {
33
38
  signIn: startup_cap_1.makeSignInCaller(clientSide, objPath.concat('signIn')),
34
39
  signUp: startup_cap_1.makeSignUpCaller(clientSide, objPath.concat('signUp'))
35
40
  };
41
+ if (lstOfCAPs.includes('log')) {
42
+ w3n.log = log_cap_1.makeLogCaller(clientSide, objPath.concat('log'));
43
+ }
44
+ return w3n;
36
45
  }
37
46
  exports.makeStartupW3Nclient = makeStartupW3Nclient;
38
47
  Object.freeze(exports);
@@ -41,7 +41,6 @@ export declare abstract class NodeInFS<TCrypto extends NodeCrypto, TAttrs extend
41
41
  protected crypto: TCrypto;
42
42
  protected attrs: AttrsHolder<TAttrs>;
43
43
  private writeProc;
44
- protected get transition(): Promise<any> | undefined;
45
44
  get version(): number;
46
45
  protected setCurrentVersion(newVersion: number): void;
47
46
  private remoteEvents;
@@ -155,12 +155,6 @@ class NodeInFS {
155
155
  */
156
156
  this.events = undefined;
157
157
  }
158
- get transition() {
159
- if (!this.writeProc) {
160
- return;
161
- }
162
- return this.writeProc.getP();
163
- }
164
158
  get version() {
165
159
  return this.currentVersion;
166
160
  }
@@ -274,7 +268,7 @@ class NodeInFS {
274
268
  if (!this.writeProc) {
275
269
  this.writeProc = new processes_1.SingleProc();
276
270
  }
277
- if (!awaitPrevChange && this.writeProc.getP()) {
271
+ if (!awaitPrevChange && this.writeProc.isProcessing()) {
278
272
  throw file_1.makeFileException(file_1.Code.concurrentUpdate, this.name + ` type ${this.type}`);
279
273
  }
280
274
  try {
@@ -42,10 +42,10 @@ class ServerEvents {
42
42
  let detach;
43
43
  let obs = observer;
44
44
  // open server, ensuring only one process running
45
- if (!this.openningServer.getP()) {
45
+ if (!this.openningServer.isProcessing()) {
46
46
  this.openningServer.addStarted(this.subscribeToServer());
47
47
  }
48
- this.openningServer.getP()
48
+ this.openningServer.latestTaskAtThisMoment()
49
49
  .then((server) => {
50
50
  this.setServer(server);
51
51
  if (!obs) {
@@ -106,7 +106,7 @@ class ServerEvents {
106
106
  }
107
107
  }
108
108
  restartObservation(event) {
109
- return rxjs_1.from(processes_1.sleep(this.restartWaitSecs))
109
+ return rxjs_1.from(processes_1.sleep(this.restartWaitSecs * 1000))
110
110
  .pipe(operators_1.mergeMap(() => this.observe(event)));
111
111
  }
112
112
  }
@@ -22,7 +22,8 @@ export declare class NamedProcs {
22
22
  * @return a promise of a process' completion, or undefined, if process with
23
23
  * given id is unknown.
24
24
  */
25
- getP<T>(id: string): Promise<T> | undefined;
25
+ latestTaskAtThisMoment<T>(id: string): Promise<T> | undefined;
26
+ isProcessing(id: string): boolean;
26
27
  /**
27
28
  * This method will add a promise of an already started process.
28
29
  * @param id is a string key of a process
@@ -60,7 +61,8 @@ export declare class SingleProc {
60
61
  private actions;
61
62
  private running;
62
63
  constructor(onGoingIdle?: (() => void) | undefined);
63
- getP<T>(): Promise<T> | undefined;
64
+ isProcessing(): boolean;
65
+ latestTaskAtThisMoment<T>(): Promise<T> | undefined;
64
66
  addStarted<T>(promise: Promise<T>): Promise<T>;
65
67
  start<T>(action: Action<T>): Promise<T>;
66
68
  private runIfIdle;
@@ -41,9 +41,13 @@ class NamedProcs {
41
41
  * @return a promise of a process' completion, or undefined, if process with
42
42
  * given id is unknown.
43
43
  */
44
- getP(id) {
44
+ latestTaskAtThisMoment(id) {
45
45
  const proc = this.processes.get(id);
46
- return (proc ? proc.getP() : undefined);
46
+ return (proc ? proc.latestTaskAtThisMoment() : undefined);
47
+ }
48
+ isProcessing(id) {
49
+ const proc = this.processes.get(id);
50
+ return (proc ? proc.isProcessing() : false);
47
51
  }
48
52
  /**
49
53
  * This method will add a promise of an already started process.
@@ -52,7 +56,7 @@ class NamedProcs {
52
56
  * @return a promise of a process' completion.
53
57
  */
54
58
  addStarted(id, promise) {
55
- if (this.getP(id)) {
59
+ if (this.isProcessing(id)) {
56
60
  throw new Error('Process with id "' + id + '" is already in progress.');
57
61
  }
58
62
  return this.startOrChain(id, () => promise);
@@ -65,7 +69,7 @@ class NamedProcs {
65
69
  * @return a promise of a process' completion.
66
70
  */
67
71
  start(id, action) {
68
- if (this.getP(id)) {
72
+ if (this.isProcessing(id)) {
69
73
  throw new Error('Process with id "' + id + '" is already in progress.');
70
74
  }
71
75
  return this.startOrChain(id, action);
@@ -104,19 +108,22 @@ class SingleProc {
104
108
  this.running = false;
105
109
  Object.seal(this);
106
110
  }
107
- getP() {
111
+ isProcessing() {
112
+ return (this.actions.length > 0);
113
+ }
114
+ latestTaskAtThisMoment() {
108
115
  return ((this.actions.length === 0) ?
109
116
  undefined :
110
117
  this.actions[this.actions.length - 1].deferred.promise);
111
118
  }
112
119
  addStarted(promise) {
113
- if (this.actions.length > 0) {
120
+ if (this.isProcessing()) {
114
121
  throw new Error('Process is already in progress.');
115
122
  }
116
123
  return this.startOrChain(() => promise);
117
124
  }
118
125
  start(action) {
119
- if (this.actions.length > 0) {
126
+ if (this.isProcessing()) {
120
127
  throw new Error('Process is already in progress.');
121
128
  }
122
129
  return this.startOrChain(action);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.18.5",
3
+ "version": "0.19.1",
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",
@@ -34,10 +34,10 @@
34
34
  "xsp-files": "^3.1.10"
35
35
  },
36
36
  "devDependencies": {
37
- "@types/jasmine": "^3.5.11",
37
+ "@types/jasmine": "^3.9.1",
38
38
  "@types/node": "^12.0.4",
39
39
  "@types/ws": "^4.0.0",
40
- "jasmine": "^2.4.1",
40
+ "jasmine": "^3.9.0",
41
41
  "spec-3nweb-server": "^1.3.8",
42
42
  "typescript": "^3.7.3"
43
43
  }