core-3nweb-client-lib 0.20.3 → 0.20.7

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,11 +1,6 @@
1
- import { ExposedObj, Caller, ExposedServices, ExposedFn } from "../ipc-via-protobuf/connector";
1
+ import { Caller, ExposedServices } from "../ipc-via-protobuf/connector";
2
+ import { ClientCAPsWraps, CAPsExposures, TypeDifference } 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
- export declare function exposeW3N<T extends W3N>(coreSide: ExposedServices, w3n: T, extraCAPs?: {
6
- [cap in keyof T]: CapExposer;
7
- }): void;
8
- export declare function makeW3Nclient<T extends W3N>(clientSide: Caller, extraCAPs?: {
9
- [cap in keyof T]: MakeCapClient;
10
- }): T;
4
+ export declare function exposeW3N<T extends W3N>(coreSide: ExposedServices, w3n: T, extraCAPs?: CAPsExposures<TypeDifference<T, W3N>>): void;
5
+ export declare function makeW3Nclient<T extends W3N>(clientSide: Caller, extraCAPs?: ClientCAPsWraps<TypeDifference<T, W3N>>): T;
11
6
  export {};
@@ -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,13 @@
1
+ import { ExposedObj, ExposedFn, ExposedServices, Caller } from "../ipc-via-protobuf/connector";
2
+ export declare type CAPsExposures<T> = {
3
+ [cap in keyof Required<T>]: (cap: any, coreSide: ExposedServices) => ExposedObj<any> | ExposedFn;
4
+ };
5
+ export declare type TypeDifference<T extends TExc, TExc extends object> = {
6
+ [cap in Exclude<keyof T, keyof TExc>]: T[cap];
7
+ };
8
+ export declare function exposeCAPs<T extends W3N, W3N extends object>(coreSide: ExposedServices, w3n: T, mainCAPs: CAPsExposures<W3N>, extraCAPs: CAPsExposures<TypeDifference<T, W3N>> | undefined): void;
9
+ export declare type MakeCapClient = (clientSide: Caller, objPath: string[]) => any;
10
+ export declare type ClientCAPsWraps<T> = {
11
+ [cap in keyof Required<T>]: MakeCapClient;
12
+ };
13
+ export declare function makeClientSide<T extends W3N, W3N extends object>(clientSide: Caller, mainCAPs: ClientCAPsWraps<W3N>, extraCAPs: ClientCAPsWraps<TypeDifference<T, W3N>> | undefined): T;
@@ -0,0 +1,63 @@
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 = void 0;
20
+ const connector_1 = require("../ipc-via-protobuf/connector");
21
+ const assert_1 = require("../lib-common/assert");
22
+ function exposeCAPs(coreSide, w3n, mainCAPs, extraCAPs) {
23
+ const expW3N = {};
24
+ addCAPsInExposure(expW3N, coreSide, w3n, mainCAPs);
25
+ if (extraCAPs) {
26
+ addCAPsInExposure(expW3N, coreSide, w3n, extraCAPs);
27
+ }
28
+ coreSide.exposeW3NService(expW3N);
29
+ }
30
+ exports.exposeCAPs = exposeCAPs;
31
+ function addCAPsInExposure(expW3N, coreSide, w3n, capExposures) {
32
+ for (const capName in capExposures) {
33
+ const expose = capExposures[capName];
34
+ assert_1.assert(typeof expose === 'function');
35
+ assert_1.assert(!expW3N[capName], `Capability ${capName} is already exposed, and we specifically have no shadowing.`);
36
+ const cap = w3n[capName];
37
+ if (cap) {
38
+ expW3N[capName] = expose(cap, coreSide);
39
+ }
40
+ }
41
+ }
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) {
54
+ assert_1.assert(!!exposeCAPs);
55
+ const makeCap = extraCAPs[cap];
56
+ assert_1.assert(typeof makeCap === 'function');
57
+ w3n[cap] = makeCap(clientSide, capObjPath);
58
+ }
59
+ }
60
+ return w3n;
61
+ }
62
+ exports.makeClientSide = makeClientSide;
63
+ Object.freeze(exports);
@@ -1,5 +1,6 @@
1
1
  import { ExposedServices, Caller } from "../ipc-via-protobuf/connector";
2
+ import { ClientCAPsWraps, CAPsExposures, TypeDifference } 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?: CAPsExposures<TypeDifference<T, W3N>>): void;
5
+ export declare function makeStartupW3Nclient<T extends W3N>(clientSide: Caller, extraCAPs?: ClientCAPsWraps<TypeDifference<T, W3N>>): W3N;
5
6
  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);