core-3nweb-client-lib 0.30.5 → 0.31.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2020, 2022, 2024 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,67 +18,21 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.exposeMailerIdCAP = exposeMailerIdCAP;
20
20
  exports.makeMailerIdCaller = makeMailerIdCaller;
21
- const connector_1 = require("../../ipc-via-protobuf/connector");
22
- const protobuf_type_1 = require("../../lib-client/protobuf-type");
23
- const mailerid_proto_1 = require("../../protos/mailerid.proto");
24
- const protobuf_msg_1 = require("../../ipc-via-protobuf/protobuf-msg");
21
+ const caller_side_wrap_1 = require("../../core-ipc/json-ipc-wrapping/caller-side-wrap");
22
+ const service_side_wrap_1 = require("../../core-ipc/json-ipc-wrapping/service-side-wrap");
25
23
  function exposeMailerIdCAP(cap) {
26
24
  return {
27
- getUserId: getUserId.wrapService(cap.getUserId),
28
- login: login.wrapService(cap.login)
25
+ getUserId: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'getUserId'),
26
+ login: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'login')
29
27
  };
30
28
  }
29
+ function callMailerId(caller, objPath, method) {
30
+ return (0, caller_side_wrap_1.makeReqRepObjCaller)(caller, objPath, method);
31
+ }
31
32
  function makeMailerIdCaller(caller, objPath) {
32
33
  return {
33
- getUserId: getUserId.makeCaller(caller, objPath),
34
- login: login.makeCaller(caller, objPath)
34
+ getUserId: callMailerId(caller, objPath, 'getUserId'),
35
+ login: callMailerId(caller, objPath, 'login')
35
36
  };
36
37
  }
37
- var getUserId;
38
- (function (getUserId) {
39
- function wrapService(fn) {
40
- return () => {
41
- const promise = fn()
42
- .then(userId => (0, protobuf_msg_1.encodeToUtf8)(userId));
43
- return { promise };
44
- };
45
- }
46
- getUserId.wrapService = wrapService;
47
- function makeCaller(caller, objPath) {
48
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'getUserId');
49
- return () => caller.startPromiseCall(path, undefined)
50
- .then(buf => {
51
- if (!buf) {
52
- throw (0, connector_1.makeIPCException)({ missingBodyBytes: true });
53
- }
54
- return (0, protobuf_msg_1.decodeFromUtf8)(buf);
55
- });
56
- }
57
- getUserId.makeCaller = makeCaller;
58
- })(getUserId || (getUserId = {}));
59
- Object.freeze(getUserId);
60
- var login;
61
- (function (login) {
62
- const requestType = protobuf_type_1.ProtoType.for(mailerid_proto_1.mailerid.LoginRequestBody);
63
- const replyType = protobuf_type_1.ProtoType.for(mailerid_proto_1.mailerid.LoginReplyBody);
64
- function wrapService(fn) {
65
- return bytes => {
66
- const { serviceUrl } = requestType.unpack(bytes);
67
- const promise = fn(serviceUrl)
68
- .then(sessionId => replyType.pack({ sessionId }));
69
- return { promise };
70
- };
71
- }
72
- login.wrapService = wrapService;
73
- function makeCaller(caller, objPath) {
74
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'login');
75
- return async (serviceUrl) => {
76
- const req = requestType.pack({ serviceUrl });
77
- const buf = await caller.startPromiseCall(path, req);
78
- return replyType.unpack(buf).sessionId;
79
- };
80
- }
81
- login.makeCaller = makeCaller;
82
- })(login || (login = {}));
83
- Object.freeze(getUserId);
84
38
  Object.freeze(exports);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2020, 2022, 2024 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
@@ -20,306 +20,116 @@ exports.wrapSignInCAP = wrapSignInCAP;
20
20
  exports.makeSignInCaller = makeSignInCaller;
21
21
  exports.wrapSignUpCAP = wrapSignUpCAP;
22
22
  exports.makeSignUpCaller = makeSignUpCaller;
23
- const protobuf_msg_1 = require("../../ipc-via-protobuf/protobuf-msg");
24
- const rxjs_1 = require("rxjs");
25
- const operators_1 = require("rxjs/operators");
26
23
  const deferred_1 = require("../../lib-common/processes/deferred");
27
- const protobuf_type_1 = require("../../lib-client/protobuf-type");
28
- const startup_proto_1 = require("../../protos/startup.proto");
24
+ const service_side_wrap_1 = require("../../core-ipc/json-ipc-wrapping/service-side-wrap");
25
+ const caller_side_wrap_1 = require("../../core-ipc/json-ipc-wrapping/caller-side-wrap");
29
26
  function wrapSignInCAP(cap) {
30
27
  return {
31
- completeLoginAndLocalSetup: completeLoginAndLocalSetup.wrapService(cap.completeLoginAndLocalSetup),
32
- getUsersOnDisk: getUsersOnDisk.wrapService(cap.getUsersOnDisk),
33
- startLoginToRemoteStorage: startLoginToRemoteStorage.wrapService(cap.startLoginToRemoteStorage),
34
- useExistingStorage: useExistingStorage.wrapService(cap.useExistingStorage)
28
+ completeLoginAndLocalSetup: (0, service_side_wrap_1.wrapObservingFunc)(undefined, (obs, pass) => {
29
+ cap.completeLoginAndLocalSetup(pass, p => { var _a; return (_a = obs.next) === null || _a === void 0 ? void 0 : _a.call(obs, { p }); })
30
+ .then(decrResult => {
31
+ var _a, _b;
32
+ (_a = obs.next) === null || _a === void 0 ? void 0 : _a.call(obs, { p: 100, decrResult });
33
+ (_b = obs.complete) === null || _b === void 0 ? void 0 : _b.call(obs);
34
+ }, err => { var _a; return (_a = obs.error) === null || _a === void 0 ? void 0 : _a.call(obs, err); });
35
+ return noop;
36
+ }),
37
+ getUsersOnDisk: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'getUsersOnDisk'),
38
+ startLoginToRemoteStorage: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'startLoginToRemoteStorage'),
39
+ useExistingStorage: (0, service_side_wrap_1.wrapObservingFunc)(undefined, (obs, addr, pass) => {
40
+ cap.useExistingStorage(addr, pass, p => { var _a; return (_a = obs.next) === null || _a === void 0 ? void 0 : _a.call(obs, { p }); })
41
+ .then(decrResult => {
42
+ var _a, _b;
43
+ (_a = obs.next) === null || _a === void 0 ? void 0 : _a.call(obs, { p: 100, decrResult });
44
+ (_b = obs.complete) === null || _b === void 0 ? void 0 : _b.call(obs);
45
+ }, err => { var _a; return (_a = obs.error) === null || _a === void 0 ? void 0 : _a.call(obs, err); });
46
+ return noop;
47
+ })
35
48
  };
36
49
  }
37
50
  function makeSignInCaller(caller, objPath) {
38
51
  return {
39
- completeLoginAndLocalSetup: completeLoginAndLocalSetup.makeCaller(caller, objPath),
40
- getUsersOnDisk: getUsersOnDisk.makeCaller(caller, objPath),
41
- startLoginToRemoteStorage: startLoginToRemoteStorage.makeCaller(caller, objPath),
42
- useExistingStorage: useExistingStorage.makeCaller(caller, objPath)
52
+ completeLoginAndLocalSetup: (() => {
53
+ const obsFn = (0, caller_side_wrap_1.makeObservableFuncCaller)(caller, objPath.concat('completeLoginAndLocalSetup'));
54
+ return (pass, progressCB) => {
55
+ const { obs, promise } = completionAndObsOfProgress(progressCB);
56
+ obsFn(obs, pass);
57
+ return promise;
58
+ };
59
+ })(),
60
+ getUsersOnDisk: callSignIn(caller, objPath, 'getUsersOnDisk'),
61
+ startLoginToRemoteStorage: callSignIn(caller, objPath, 'startLoginToRemoteStorage'),
62
+ useExistingStorage: (() => {
63
+ const obsFn = (0, caller_side_wrap_1.makeObservableFuncCaller)(caller, objPath.concat('useExistingStorage'));
64
+ return (addr, pass, progressCB) => {
65
+ const { obs, promise } = completionAndObsOfProgress(progressCB);
66
+ obsFn(obs, addr, pass);
67
+ return promise;
68
+ };
69
+ })()
70
+ };
71
+ }
72
+ function callSignIn(caller, objPath, method) {
73
+ return (0, caller_side_wrap_1.makeReqRepObjCaller)(caller, objPath, method);
74
+ }
75
+ function completionAndObsOfProgress(progressCB) {
76
+ let completion = (0, deferred_1.defer)();
77
+ // let doneRes: boolean|undefined;
78
+ const obs = {
79
+ next: ({ p, decrResult }) => {
80
+ if (typeof decrResult === 'boolean') {
81
+ completion === null || completion === void 0 ? void 0 : completion.resolve(decrResult);
82
+ completion = undefined;
83
+ }
84
+ else {
85
+ progressCB(p);
86
+ }
87
+ },
88
+ complete: () => completion === null || completion === void 0 ? void 0 : completion.reject(new Error()),
89
+ error: err => completion === null || completion === void 0 ? void 0 : completion.reject(err)
90
+ };
91
+ return {
92
+ obs,
93
+ promise: completion.promise
43
94
  };
44
95
  }
45
96
  function wrapSignUpCAP(cap) {
46
97
  return {
47
- setSignUpServer: setSignUpServer.wrapService(cap.setSignUpServer),
48
- getAvailableDomains: getAvailableDomains.wrapService(cap.getAvailableDomains),
49
- getAvailableAddresses: getAvailableAddresses.wrapService(cap.getAvailableAddresses),
50
- addUser: addUser.wrapService(cap.addUser),
51
- createUserParams: createUserParams.wrapService(cap.createUserParams),
52
- isActivated: isActivated.wrapService(cap.isActivated)
98
+ setSignUpServer: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'setSignUpServer'),
99
+ getAvailableDomains: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'getAvailableDomains'),
100
+ getAvailableAddresses: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'getAvailableAddresses'),
101
+ addUser: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'addUser'),
102
+ createUserParams: (0, service_side_wrap_1.wrapObservingFunc)(undefined, (obs, pass) => {
103
+ cap.createUserParams(pass, p => { var _a; return (_a = obs.next) === null || _a === void 0 ? void 0 : _a.call(obs, p); })
104
+ .then(() => { var _a; return (_a = obs.complete) === null || _a === void 0 ? void 0 : _a.call(obs); }, err => { var _a; return (_a = obs.error) === null || _a === void 0 ? void 0 : _a.call(obs, err); });
105
+ return noop;
106
+ }),
107
+ isActivated: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'isActivated')
53
108
  };
54
109
  }
110
+ function noop() { }
111
+ function callSignUp(caller, objPath, method) {
112
+ return (0, caller_side_wrap_1.makeReqRepObjCaller)(caller, objPath, method);
113
+ }
55
114
  function makeSignUpCaller(caller, objPath) {
56
115
  return {
57
- setSignUpServer: setSignUpServer.makeCaller(caller, objPath),
58
- getAvailableDomains: getAvailableDomains.makeCaller(caller, objPath),
59
- getAvailableAddresses: getAvailableAddresses.makeCaller(caller, objPath),
60
- addUser: addUser.makeCaller(caller, objPath),
61
- createUserParams: createUserParams.makeCaller(caller, objPath),
62
- isActivated: isActivated.makeCaller(caller, objPath)
116
+ setSignUpServer: callSignUp(caller, objPath, 'setSignUpServer'),
117
+ getAvailableDomains: callSignUp(caller, objPath, 'getAvailableDomains'),
118
+ getAvailableAddresses: callSignUp(caller, objPath, 'getAvailableAddresses'),
119
+ addUser: callSignUp(caller, objPath, 'addUser'),
120
+ createUserParams: (() => {
121
+ const obsFn = (0, caller_side_wrap_1.makeObservableFuncCaller)(caller, objPath.concat('createUserParams'));
122
+ return (pass, progressCB) => {
123
+ const completion = (0, deferred_1.defer)();
124
+ obsFn({
125
+ next: p => progressCB(p),
126
+ complete: () => completion.resolve(),
127
+ error: err => completion.reject(err)
128
+ }, pass);
129
+ return completion.promise;
130
+ };
131
+ })(),
132
+ isActivated: callSignUp(caller, objPath, 'isActivated')
63
133
  };
64
134
  }
65
- var setSignUpServer;
66
- (function (setSignUpServer) {
67
- const requestType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.SetSignUpServerRequestBody);
68
- function wrapService(fn) {
69
- return buf => {
70
- const { serviceUrl } = requestType.unpack(buf);
71
- const promise = fn(serviceUrl);
72
- return { promise };
73
- };
74
- }
75
- setSignUpServer.wrapService = wrapService;
76
- function makeCaller(caller, objPath) {
77
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'setSignUpServer');
78
- return serviceUrl => caller
79
- .startPromiseCall(path, requestType.pack({ serviceUrl }));
80
- }
81
- setSignUpServer.makeCaller = makeCaller;
82
- })(setSignUpServer || (setSignUpServer = {}));
83
- Object.freeze(getAvailableAddresses);
84
- var getAvailableDomains;
85
- (function (getAvailableDomains) {
86
- const requestType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.GetAvailableDomainsRequestBody);
87
- function wrapService(fn) {
88
- return buf => {
89
- const { token } = requestType.unpack(buf);
90
- const promise = fn((0, protobuf_msg_1.valOfOpt)(token))
91
- .then(domains => protobuf_msg_1.strArrValType.pack({ values: domains }));
92
- return { promise };
93
- };
94
- }
95
- getAvailableDomains.wrapService = wrapService;
96
- function makeCaller(caller, objPath) {
97
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'getAvailableDomains');
98
- return token => caller
99
- .startPromiseCall(path, requestType.pack({ token: (0, protobuf_msg_1.toOptVal)(token) }))
100
- .then(buf => (0, protobuf_msg_1.fixArray)(protobuf_msg_1.strArrValType.unpack(buf).values));
101
- }
102
- getAvailableDomains.makeCaller = makeCaller;
103
- })(getAvailableDomains || (getAvailableDomains = {}));
104
- var getAvailableAddresses;
105
- (function (getAvailableAddresses) {
106
- const requestType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.GetAvailableAddressesRequestBody);
107
- function wrapService(fn) {
108
- return buf => {
109
- const { name, token } = requestType.unpack(buf);
110
- const promise = fn(name, (0, protobuf_msg_1.valOfOpt)(token))
111
- .then(addresses => protobuf_msg_1.strArrValType.pack({ values: addresses }));
112
- return { promise };
113
- };
114
- }
115
- getAvailableAddresses.wrapService = wrapService;
116
- function makeCaller(caller, objPath) {
117
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'getAvailableAddresses');
118
- return (name, token) => caller
119
- .startPromiseCall(path, requestType.pack({ name, token: (0, protobuf_msg_1.toOptVal)(token) }))
120
- .then(buf => (0, protobuf_msg_1.fixArray)(protobuf_msg_1.strArrValType.unpack(buf).values));
121
- }
122
- getAvailableAddresses.makeCaller = makeCaller;
123
- })(getAvailableAddresses || (getAvailableAddresses = {}));
124
- Object.freeze(getAvailableAddresses);
125
- var addUser;
126
- (function (addUser) {
127
- const requestType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.AddUserRequestBody);
128
- function wrapService(fn) {
129
- return buf => {
130
- const { userId, token } = requestType.unpack(buf);
131
- const promise = fn(userId, (0, protobuf_msg_1.valOfOpt)(token))
132
- .then(wasAdded => protobuf_msg_1.boolValType.pack((0, protobuf_msg_1.toVal)(wasAdded)));
133
- return { promise };
134
- };
135
- }
136
- addUser.wrapService = wrapService;
137
- function makeCaller(caller, objPath) {
138
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'addUser');
139
- return (userId, token) => caller
140
- .startPromiseCall(path, requestType.pack({ userId, token: (0, protobuf_msg_1.toOptVal)(token) }))
141
- .then(buf => protobuf_msg_1.boolValType.unpack(buf).value);
142
- }
143
- addUser.makeCaller = makeCaller;
144
- })(addUser || (addUser = {}));
145
- Object.freeze(addUser);
146
- var isActivated;
147
- (function (isActivated_1) {
148
- const requestType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.IsActivatedRequestBody);
149
- function wrapService(fn) {
150
- return buf => {
151
- const { userId } = requestType.unpack(buf);
152
- const promise = fn(userId)
153
- .then(isActivated => protobuf_msg_1.boolValType.pack((0, protobuf_msg_1.toVal)(isActivated)));
154
- return { promise };
155
- };
156
- }
157
- isActivated_1.wrapService = wrapService;
158
- function makeCaller(caller, objPath) {
159
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'isActivated');
160
- return userId => caller
161
- .startPromiseCall(path, requestType.pack({ userId }))
162
- .then(buf => protobuf_msg_1.boolValType.unpack(buf).value);
163
- }
164
- isActivated_1.makeCaller = makeCaller;
165
- })(isActivated || (isActivated = {}));
166
- Object.freeze(isActivated);
167
- const reqWithPassType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.PassOnlyRequestBody);
168
- var createUserParams;
169
- (function (createUserParams) {
170
- function wrapService(fn) {
171
- return buf => {
172
- const { pass } = reqWithPassType.unpack(buf);
173
- const s = new rxjs_1.Subject();
174
- const obs = s.asObservable().pipe((0, operators_1.map)(v => progressValueType.pack(v)));
175
- fn(pass, p => s.next({ p }))
176
- .then(() => s.complete(), err => s.error(err));
177
- return { obs };
178
- };
179
- }
180
- createUserParams.wrapService = wrapService;
181
- function makeCaller(caller, objPath) {
182
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'createUserParams');
183
- return (pass, progressCB) => {
184
- const s = new rxjs_1.Subject();
185
- const completion = (0, deferred_1.defer)();
186
- s.subscribe({
187
- next: buf => {
188
- const { p } = progressValueType.unpack(buf);
189
- progressCB(p);
190
- },
191
- complete: () => completion.resolve(),
192
- error: err => completion.reject(err)
193
- });
194
- caller.startObservableCall(path, reqWithPassType.pack({ pass }), s);
195
- return completion.promise;
196
- };
197
- }
198
- createUserParams.makeCaller = makeCaller;
199
- })(createUserParams || (createUserParams = {}));
200
- Object.freeze(createUserParams);
201
- var getUsersOnDisk;
202
- (function (getUsersOnDisk) {
203
- function wrapService(fn) {
204
- return () => {
205
- const promise = fn()
206
- .then(users => protobuf_msg_1.strArrValType.pack({ values: users }));
207
- return { promise };
208
- };
209
- }
210
- getUsersOnDisk.wrapService = wrapService;
211
- function makeCaller(caller, objPath) {
212
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'getUsersOnDisk');
213
- return () => caller
214
- .startPromiseCall(path, undefined)
215
- .then(buf => (0, protobuf_msg_1.fixArray)(protobuf_msg_1.strArrValType.unpack(buf).values));
216
- }
217
- getUsersOnDisk.makeCaller = makeCaller;
218
- })(getUsersOnDisk || (getUsersOnDisk = {}));
219
- Object.freeze(getUsersOnDisk);
220
- var startLoginToRemoteStorage;
221
- (function (startLoginToRemoteStorage) {
222
- const requestType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.StartLoginToRemoteStorageRequestBody);
223
- function wrapService(fn) {
224
- return buf => {
225
- const { address } = requestType.unpack(buf);
226
- const promise = fn(address)
227
- .then(started => protobuf_msg_1.boolValType.pack((0, protobuf_msg_1.toVal)(started)));
228
- return { promise };
229
- };
230
- }
231
- startLoginToRemoteStorage.wrapService = wrapService;
232
- function makeCaller(caller, objPath) {
233
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'startLoginToRemoteStorage');
234
- return address => caller
235
- .startPromiseCall(path, requestType.pack({ address }))
236
- .then(buf => protobuf_msg_1.boolValType.unpack(buf).value);
237
- }
238
- startLoginToRemoteStorage.makeCaller = makeCaller;
239
- })(startLoginToRemoteStorage || (startLoginToRemoteStorage = {}));
240
- Object.freeze(startLoginToRemoteStorage);
241
- const progressValueType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.ProgressValue);
242
- var completeLoginAndLocalSetup;
243
- (function (completeLoginAndLocalSetup) {
244
- function wrapService(fn) {
245
- return buf => {
246
- const { pass } = reqWithPassType.unpack(buf);
247
- const s = new rxjs_1.Subject();
248
- const obs = s.asObservable().pipe((0, operators_1.map)(v => progressValueType.pack(v)));
249
- fn(pass, p => s.next({ p }))
250
- .then(ok => {
251
- s.next({ decrResult: (0, protobuf_msg_1.toVal)(ok), p: 100 });
252
- s.complete();
253
- }, err => s.error(err));
254
- return { obs };
255
- };
256
- }
257
- completeLoginAndLocalSetup.wrapService = wrapService;
258
- function makeCaller(caller, objPath) {
259
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'completeLoginAndLocalSetup');
260
- return (pass, progressCB) => {
261
- const s = new rxjs_1.Subject();
262
- const completion = (0, deferred_1.defer)();
263
- s.subscribe({
264
- next: buf => {
265
- const { decrResult, p } = progressValueType.unpack(buf);
266
- if (typeof (0, protobuf_msg_1.valOfOpt)(decrResult) === 'boolean') {
267
- completion.resolve((0, protobuf_msg_1.valOfOpt)(decrResult));
268
- }
269
- else {
270
- progressCB(p);
271
- }
272
- },
273
- complete: () => completion.resolve(),
274
- error: err => completion.reject(err)
275
- });
276
- caller.startObservableCall(path, reqWithPassType.pack({ pass }), s);
277
- return completion.promise;
278
- };
279
- }
280
- completeLoginAndLocalSetup.makeCaller = makeCaller;
281
- })(completeLoginAndLocalSetup || (completeLoginAndLocalSetup = {}));
282
- Object.freeze(completeLoginAndLocalSetup);
283
- var useExistingStorage;
284
- (function (useExistingStorage) {
285
- const requestType = protobuf_type_1.ProtoType.for(startup_proto_1.startup.UseExistingStorageRequestBody);
286
- function wrapService(fn) {
287
- return buf => {
288
- const { pass, address } = requestType.unpack(buf);
289
- const s = new rxjs_1.Subject();
290
- const obs = s.asObservable().pipe((0, operators_1.map)(v => progressValueType.pack(v)));
291
- fn(address, pass, p => s.next({ p }))
292
- .then(ok => {
293
- s.next({ decrResult: (0, protobuf_msg_1.toVal)(ok), p: 100 });
294
- s.complete();
295
- }, err => s.error(err));
296
- return { obs };
297
- };
298
- }
299
- useExistingStorage.wrapService = wrapService;
300
- function makeCaller(caller, objPath) {
301
- const path = (0, protobuf_msg_1.methodPathFor)(objPath, 'useExistingStorage');
302
- return (address, pass, progressCB) => {
303
- const s = new rxjs_1.Subject();
304
- const completion = (0, deferred_1.defer)();
305
- s.subscribe({
306
- next: buf => {
307
- const { decrResult, p } = progressValueType.unpack(buf);
308
- if (typeof (0, protobuf_msg_1.valOfOpt)(decrResult) === 'boolean') {
309
- completion.resolve((0, protobuf_msg_1.valOfOpt)(decrResult));
310
- }
311
- else {
312
- progressCB(p);
313
- }
314
- },
315
- complete: () => completion.resolve(),
316
- error: err => completion.reject(err)
317
- });
318
- caller.startObservableCall(path, requestType.pack({ address, pass }), s);
319
- return completion.promise;
320
- };
321
- }
322
- useExistingStorage.makeCaller = makeCaller;
323
- })(useExistingStorage || (useExistingStorage = {}));
324
- Object.freeze(useExistingStorage);
325
135
  Object.freeze(exports);
@@ -0,0 +1,14 @@
1
+ import { Caller } from "../../ipc-via-protobuf/connector";
2
+ type Observer<T> = web3n.Observer<T>;
3
+ interface PassedDatum {
4
+ bytes?: Uint8Array;
5
+ passedByReference?: any[];
6
+ }
7
+ export interface TransformOpts {
8
+ unpackReply?: ((reply: PassedDatum | undefined) => any) | 'noop';
9
+ packRequest?: ((args: any[]) => PassedDatum | undefined) | 'noop';
10
+ }
11
+ export declare function makeReqRepFuncCaller<F extends Function>(clientSide: Caller, path: string[], transforms?: TransformOpts): F;
12
+ export declare function makeReqRepObjCaller<T, M extends keyof T>(clientSide: Caller, objPath: string[], method: M, transforms?: TransformOpts): T[M];
13
+ export declare function makeObservableFuncCaller<TEvent>(clientSide: Caller, path: string[], transforms?: TransformOpts): (obs: Observer<TEvent>, ...args: any[]) => (() => void);
14
+ export {};
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2022 - 2024 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.makeReqRepFuncCaller = makeReqRepFuncCaller;
20
+ exports.makeReqRepObjCaller = makeReqRepObjCaller;
21
+ exports.makeObservableFuncCaller = makeObservableFuncCaller;
22
+ const rxjs_1 = require("rxjs");
23
+ const json_n_binary_1 = require("./json-n-binary");
24
+ function replyFromPassedDatum(data, unpack) {
25
+ if (!data) {
26
+ return;
27
+ }
28
+ if (unpack) {
29
+ if (unpack === 'noop') {
30
+ return [data.bytes];
31
+ }
32
+ else {
33
+ return unpack(data);
34
+ }
35
+ }
36
+ else {
37
+ const { bytes, passedByReference } = data;
38
+ return (bytes ? (0, json_n_binary_1.deserializeArgs)(bytes, passedByReference)[0] : undefined);
39
+ }
40
+ }
41
+ function argsToPassedDatum(args, pack) {
42
+ if (args === undefined) {
43
+ return;
44
+ }
45
+ if (pack) {
46
+ if (pack === 'noop') {
47
+ if (!ArrayBuffer.isView(args[0])) {
48
+ throw new Error(`Method returned non-binary, while no serialization is set`);
49
+ }
50
+ return { bytes: args[0] };
51
+ }
52
+ return pack(args);
53
+ }
54
+ else {
55
+ return (0, json_n_binary_1.serializeArgs)(args);
56
+ }
57
+ }
58
+ function makeReqRepFuncCaller(clientSide, path, transforms) {
59
+ return (async (...args) => {
60
+ const req = argsToPassedDatum(args, transforms === null || transforms === void 0 ? void 0 : transforms.packRequest);
61
+ if (req === null || req === void 0 ? void 0 : req.passedByReference) {
62
+ throw new Error(`Passing by reference is notimplemented, yet.`);
63
+ }
64
+ const reply = await clientSide.startPromiseCall(path, req === null || req === void 0 ? void 0 : req.bytes);
65
+ return replyFromPassedDatum({
66
+ bytes: reply
67
+ }, transforms === null || transforms === void 0 ? void 0 : transforms.unpackReply);
68
+ });
69
+ }
70
+ function makeReqRepObjCaller(clientSide, objPath, method, transforms) {
71
+ return makeReqRepFuncCaller(clientSide, objPath.concat(method), transforms);
72
+ }
73
+ function makeObservableFuncCaller(clientSide, path, transforms) {
74
+ return (obs, ...args) => {
75
+ const req = argsToPassedDatum(args, transforms === null || transforms === void 0 ? void 0 : transforms.packRequest);
76
+ const s = new rxjs_1.Subject();
77
+ const unsub = clientSide.startObservableCall(path, req === null || req === void 0 ? void 0 : req.bytes, s);
78
+ s.subscribe({
79
+ next: data => {
80
+ if (!obs.next) {
81
+ return;
82
+ }
83
+ const ev = replyFromPassedDatum({ bytes: data }, transforms === null || transforms === void 0 ? void 0 : transforms.unpackReply);
84
+ obs.next(ev);
85
+ },
86
+ complete: () => { var _a; return (_a = obs.complete) === null || _a === void 0 ? void 0 : _a.call(obs); },
87
+ error: err => { var _a; return (_a = obs.error) === null || _a === void 0 ? void 0 : _a.call(obs, err); }
88
+ });
89
+ return unsub;
90
+ };
91
+ }
@@ -0,0 +1,5 @@
1
+ export declare function serializeArgs(args: any[]): {
2
+ bytes: Uint8Array;
3
+ passedByReference?: any[];
4
+ };
5
+ export declare function deserializeArgs(bytes: Uint8Array, passedByReference: any[] | undefined): any[];