core-3nweb-client-lib 0.20.0 → 0.20.4

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.
@@ -254,7 +254,7 @@ declare namespace web3n.asmail {
254
254
 
255
255
  interface InboxException extends RuntimeException {
256
256
  type: "inbox";
257
- msgId?: string;
257
+ msgId: string;
258
258
  msgNotFound?: true;
259
259
  objNotFound?: true;
260
260
  objId?: string;
@@ -1,7 +1,6 @@
1
- import { ExposedObj, Caller, ExposedServices, ExposedFn } from "../ipc-via-protobuf/connector";
1
+ import { Caller, ExposedServices } from "../ipc-via-protobuf/connector";
2
+ import { CapExposer, MakeCapClient } from "./generic";
2
3
  declare type W3N = web3n.caps.common.W3N;
3
- export declare type CapExposer = (cap: any, coreSide: ExposedServices) => ExposedObj<any> | ExposedFn;
4
- export declare type MakeCapClient = (clientSide: Caller, objPath: string[]) => any;
5
4
  export declare function exposeW3N<T extends W3N>(coreSide: ExposedServices, w3n: T, extraCAPs?: {
6
5
  [cap in keyof T]: CapExposer;
7
6
  }): void;
@@ -22,58 +22,28 @@ const log_cap_1 = require("../ipc-via-protobuf/log-cap");
22
22
  const asmail_cap_1 = require("../ipc-via-protobuf/asmail-cap");
23
23
  const storage_cap_1 = require("../ipc-via-protobuf/storage-cap");
24
24
  const mailerid_1 = require("../ipc-via-protobuf/mailerid");
25
- const assert_1 = require("../lib-common/assert");
25
+ const generic_1 = require("./generic");
26
26
  function exposeW3N(coreSide, w3n, extraCAPs) {
27
- const expW3N = {};
28
- if (w3n.log) {
29
- expW3N.log = log_cap_1.exposeLogger(w3n.log);
30
- }
31
- if (w3n.mailerid) {
32
- expW3N.mailerid = mailerid_1.exposeMailerIdCAP(w3n.mailerid);
33
- }
34
- if (w3n.mail) {
35
- expW3N.mail = asmail_cap_1.exposeASMailCAP(w3n.mail, coreSide);
36
- }
37
- if (w3n.storage) {
38
- expW3N.storage = storage_cap_1.exposeStorageCAP(w3n.storage, coreSide);
39
- }
40
- if (extraCAPs) {
41
- for (const [capName, expose] of Object.entries(extraCAPs)) {
42
- assert_1.assert(typeof expose === 'function');
43
- const cap = w3n[capName];
44
- if (cap) {
45
- expW3N[capName] = expose(cap, coreSide);
46
- }
47
- }
48
- }
49
- coreSide.exposeW3NService(expW3N);
27
+ const commonCAPsExposures = {
28
+ log: log_cap_1.exposeLogger,
29
+ mail: asmail_cap_1.exposeASMailCAP,
30
+ mailerid: mailerid_1.exposeMailerIdCAP,
31
+ storage: storage_cap_1.exposeStorageCAP,
32
+ };
33
+ generic_1.exposeCAPs(coreSide, w3n, commonCAPsExposures, extraCAPs);
50
34
  }
51
35
  exports.exposeW3N = exposeW3N;
36
+ // This is not used, but it ensures that some require runs, providing function
37
+ // for protobuf-something.
38
+ const unused = connector_1.W3N_NAME;
52
39
  function makeW3Nclient(clientSide, extraCAPs) {
53
- const objPath = [connector_1.W3N_NAME];
54
- const lstOfCAPs = clientSide.listObj(objPath);
55
- const w3n = {};
56
- for (const cap of lstOfCAPs) {
57
- const capObjPath = objPath.concat(cap);
58
- if (cap === 'log') {
59
- w3n.log = log_cap_1.makeLogCaller(clientSide, capObjPath);
60
- }
61
- else if (cap === 'mailerid') {
62
- w3n.mailerid = mailerid_1.makeMailerIdCaller(clientSide, capObjPath);
63
- }
64
- else if (cap === 'mail') {
65
- w3n.mail = asmail_cap_1.makeASMailCaller(clientSide, capObjPath);
66
- }
67
- else if (cap === 'storage') {
68
- w3n.storage = storage_cap_1.makeStorageCaller(clientSide, capObjPath);
69
- }
70
- else if (extraCAPs && extraCAPs[cap]) {
71
- const makeCap = extraCAPs[cap];
72
- assert_1.assert(typeof makeCap === 'function');
73
- w3n[cap] = makeCap(clientSide, capObjPath);
74
- }
75
- }
76
- return w3n;
40
+ const mainCAPs = {
41
+ log: log_cap_1.makeLogCaller,
42
+ mail: asmail_cap_1.makeASMailCaller,
43
+ mailerid: mailerid_1.makeMailerIdCaller,
44
+ storage: storage_cap_1.makeStorageCaller,
45
+ };
46
+ return generic_1.makeClientSide(clientSide, mainCAPs, extraCAPs);
77
47
  }
78
48
  exports.makeW3Nclient = makeW3Nclient;
79
49
  Object.freeze(exports);
@@ -0,0 +1,16 @@
1
+ import { ExposedObj, ExposedFn, ExposedServices, Caller } from "../ipc-via-protobuf/connector";
2
+ export declare type CapExposer = (cap: any, coreSide: ExposedServices) => ExposedObj<any> | ExposedFn;
3
+ export declare type MakeCapClient = (clientSide: Caller, objPath: string[]) => any;
4
+ export declare function addCAPsInExposure<T extends object>(expW3N: ExposedObj<T>, coreSide: ExposedServices, w3n: T, capExposures: {
5
+ [cap in keyof T]: CapExposer;
6
+ }): void;
7
+ export declare function exposeCAPs<T extends W3N, W3N extends object>(coreSide: ExposedServices, w3n: T, mainCAPs: {
8
+ [cap in keyof W3N]: CapExposer;
9
+ }, extraCAPs?: {
10
+ [cap in keyof T]: CapExposer;
11
+ }): void;
12
+ export declare function makeClientSide<T extends W3N, W3N extends object>(clientSide: Caller, mainCAPs: {
13
+ [cap in keyof W3N]: MakeCapClient;
14
+ }, extraCAPs?: {
15
+ [cap in keyof T]: MakeCapClient;
16
+ }): T;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2021 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.makeClientSide = exports.exposeCAPs = exports.addCAPsInExposure = void 0;
20
+ const connector_1 = require("../ipc-via-protobuf/connector");
21
+ const assert_1 = require("../lib-common/assert");
22
+ function addCAPsInExposure(expW3N, coreSide, w3n, capExposures) {
23
+ for (const [capName, expose] of Object.entries(capExposures)) {
24
+ assert_1.assert(typeof expose === 'function');
25
+ assert_1.assert(!expW3N[capName], `Capability ${capName} is already exposed, and we specifically have no shadowing.`);
26
+ const cap = w3n[capName];
27
+ if (cap) {
28
+ expW3N[capName] = expose(cap, coreSide);
29
+ }
30
+ }
31
+ }
32
+ exports.addCAPsInExposure = addCAPsInExposure;
33
+ function exposeCAPs(coreSide, w3n, mainCAPs, extraCAPs) {
34
+ const expW3N = {};
35
+ addCAPsInExposure(expW3N, coreSide, w3n, mainCAPs);
36
+ if (extraCAPs) {
37
+ addCAPsInExposure(expW3N, coreSide, w3n, extraCAPs);
38
+ }
39
+ coreSide.exposeW3NService(expW3N);
40
+ }
41
+ exports.exposeCAPs = exposeCAPs;
42
+ function makeClientSide(clientSide, mainCAPs, extraCAPs) {
43
+ const objPath = [connector_1.W3N_NAME];
44
+ const lstOfCAPs = clientSide.listObj(objPath);
45
+ const w3n = {};
46
+ for (const cap of lstOfCAPs) {
47
+ const capObjPath = objPath.concat(cap);
48
+ if (mainCAPs[cap]) {
49
+ const makeCap = mainCAPs[cap];
50
+ assert_1.assert(typeof makeCap === 'function');
51
+ w3n[cap] = makeCap(clientSide, capObjPath);
52
+ }
53
+ else if (extraCAPs && extraCAPs[cap]) {
54
+ const makeCap = extraCAPs[cap];
55
+ assert_1.assert(typeof makeCap === 'function');
56
+ w3n[cap] = makeCap(clientSide, capObjPath);
57
+ }
58
+ }
59
+ return w3n;
60
+ }
61
+ exports.makeClientSide = makeClientSide;
62
+ Object.freeze(exports);
@@ -1,5 +1,10 @@
1
1
  import { ExposedServices, Caller } from "../ipc-via-protobuf/connector";
2
+ import { CapExposer, MakeCapClient } from "./generic";
2
3
  declare type W3N = web3n.startup.W3N;
3
- export declare function exposeStartupW3N(coreSide: ExposedServices, w3n: W3N): void;
4
- export declare function makeStartupW3Nclient(clientSide: Caller): W3N;
4
+ export declare function exposeStartupW3N<T extends W3N>(coreSide: ExposedServices, w3n: T, extraCAPs?: {
5
+ [cap in keyof T]: CapExposer;
6
+ }): void;
7
+ export declare function makeStartupW3Nclient<T extends W3N>(clientSide: Caller, extraCAPs?: {
8
+ [cap in keyof T]: MakeCapClient;
9
+ }): W3N;
5
10
  export {};
@@ -20,28 +20,26 @@ exports.makeStartupW3Nclient = exports.exposeStartupW3N = void 0;
20
20
  const connector_1 = require("../ipc-via-protobuf/connector");
21
21
  const log_cap_1 = require("../ipc-via-protobuf/log-cap");
22
22
  const startup_cap_1 = require("../ipc-via-protobuf/startup-cap");
23
- function exposeStartupW3N(coreSide, w3n) {
24
- const expW3N = {
25
- signIn: startup_cap_1.wrapSignInCAP(w3n.signIn),
26
- signUp: startup_cap_1.wrapSignUpCAP(w3n.signUp)
23
+ const generic_1 = require("./generic");
24
+ function exposeStartupW3N(coreSide, w3n, extraCAPs) {
25
+ const startupCAPsExposures = {
26
+ signIn: startup_cap_1.wrapSignInCAP,
27
+ signUp: startup_cap_1.wrapSignUpCAP,
28
+ log: log_cap_1.exposeLogger,
27
29
  };
28
- if (w3n.log) {
29
- expW3N.log = log_cap_1.exposeLogger(w3n.log);
30
- }
31
- coreSide.exposeW3NService(expW3N);
30
+ generic_1.exposeCAPs(coreSide, w3n, startupCAPsExposures, extraCAPs);
32
31
  }
33
32
  exports.exposeStartupW3N = exposeStartupW3N;
34
- function makeStartupW3Nclient(clientSide) {
35
- const objPath = [connector_1.W3N_NAME];
36
- const lstOfCAPs = clientSide.listObj(objPath);
37
- const w3n = {
38
- signIn: startup_cap_1.makeSignInCaller(clientSide, objPath.concat('signIn')),
39
- signUp: startup_cap_1.makeSignUpCaller(clientSide, objPath.concat('signUp'))
33
+ // This is not used, but it ensures that some require runs, providing function
34
+ // for protobuf-something.
35
+ const unused = connector_1.W3N_NAME;
36
+ function makeStartupW3Nclient(clientSide, extraCAPs) {
37
+ const mainCAPs = {
38
+ log: log_cap_1.makeLogCaller,
39
+ signIn: startup_cap_1.makeSignInCaller,
40
+ signUp: startup_cap_1.makeSignUpCaller,
40
41
  };
41
- if (lstOfCAPs.includes('log')) {
42
- w3n.log = log_cap_1.makeLogCaller(clientSide, objPath.concat('log'));
43
- }
44
- return w3n;
42
+ return generic_1.makeClientSide(clientSide, mainCAPs, extraCAPs);
45
43
  }
46
44
  exports.makeStartupW3Nclient = makeStartupW3Nclient;
47
45
  Object.freeze(exports);
@@ -113,7 +113,7 @@ class ServicesSideImpl {
113
113
  this.exposedObjs.drop(path[0]);
114
114
  }
115
115
  else {
116
- throw connector_1.makeIPCException({ invalidPath: true });
116
+ throw connector_1.makeIPCException({ invalidPath: true, path });
117
117
  }
118
118
  }
119
119
  processListObj(fnCallNum, path) {
@@ -29,8 +29,8 @@ function makeProtobufTypeFrom(protoFile, typeName) {
29
29
  catch (err) {
30
30
  // we won't get here if referenced module exists, but metro packager
31
31
  // in LiqudCore needs static path require
32
- require('./proto-defs');
33
- return protobuf_loader_1.ProtoType.makeFrom(__dirname, protoFile, typeName);
32
+ const fallback = require('./proto-defs');
33
+ return protobuf_loader_1.ProtoType.makeFrom(__dirname, protoFile, typeName, fallback);
34
34
  }
35
35
  }
36
36
  exports.makeProtobufTypeFrom = makeProtobufTypeFrom;
@@ -29,7 +29,7 @@ const jsWorkerFName = 'worker-js.js';
29
29
  const wasmWorkerFName = 'worker-wasm.js';
30
30
  function workerScriptFor(impl) {
31
31
  // There is a bug with electrons 12, 13, that doesn't let
32
- // worker_thread read this file from asar pack, even though main thread
32
+ // worker_thread read files from asar pack, even though main thread
33
33
  // makes call from here.
34
34
  // Therefore, in case this runs from asar pack, we should switch to
35
35
  // unpacked in path that is given to worker thread.
@@ -306,8 +306,8 @@ function makeProtobufType(type) {
306
306
  catch (err) {
307
307
  // we won't get here if referenced module exists, but metro packager
308
308
  // in LiqudCore needs static path require
309
- require('./proto-defs');
310
- return protobuf_loader_1.ProtoType.makeFrom(__dirname, protoFile, typeName);
309
+ const fallback = require('./proto-defs');
310
+ return protobuf_loader_1.ProtoType.makeFrom(__dirname, protoFile, typeName, fallback);
311
311
  }
312
312
  }
313
313
  exports.makeInWorkerWasmCryptor = (logErr, logWarning, maxThreads) => {