core-3nweb-client-lib 0.41.5 → 0.41.6
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.
- package/build/core-ipc/json-ipc-wrapping/caller-side-wrap.d.ts +6 -7
- package/build/core-ipc/json-ipc-wrapping/caller-side-wrap.js +20 -26
- package/build/core-ipc/json-ipc-wrapping/json-n-binary.d.ts +5 -5
- package/build/core-ipc/json-ipc-wrapping/json-n-binary.js +39 -58
- package/build/core-ipc/json-ipc-wrapping/service-side-wrap.d.ts +6 -7
- package/build/core-ipc/json-ipc-wrapping/service-side-wrap.js +15 -23
- package/package.json +1 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Caller } from "../../ipc-via-protobuf/connector";
|
|
1
|
+
import { Caller, EnvelopeBody } from "../../ipc-via-protobuf/connector";
|
|
2
|
+
import { FindObjectRef, FindReferencedObj } from "./json-n-binary";
|
|
2
3
|
type Observer<T> = web3n.Observer<T>;
|
|
3
|
-
interface PassedDatum {
|
|
4
|
-
bytes?: Uint8Array;
|
|
5
|
-
passedByReference?: any[];
|
|
6
|
-
}
|
|
7
4
|
export interface TransformOpts {
|
|
8
|
-
unpackReply?: ((reply:
|
|
9
|
-
packRequest?: ((args: any[]) =>
|
|
5
|
+
unpackReply?: ((reply: EnvelopeBody) => any) | 'noop';
|
|
6
|
+
packRequest?: ((args: any[]) => EnvelopeBody) | 'noop';
|
|
7
|
+
findRefOf?: FindObjectRef;
|
|
8
|
+
findReferencedObj?: FindReferencedObj;
|
|
10
9
|
}
|
|
11
10
|
export declare function makeReqRepFuncCaller<F extends Function>(clientSide: Caller, path: string[], transforms?: TransformOpts): F;
|
|
12
11
|
export declare function makeReqRepObjCaller<T, M extends keyof T>(clientSide: Caller, objPath: string[], method: M, transforms?: TransformOpts): T[M];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2022 -
|
|
3
|
+
Copyright (C) 2022 - 2025 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
|
|
@@ -21,50 +21,44 @@ exports.makeReqRepObjCaller = makeReqRepObjCaller;
|
|
|
21
21
|
exports.makeObservableFuncCaller = makeObservableFuncCaller;
|
|
22
22
|
const rxjs_1 = require("rxjs");
|
|
23
23
|
const json_n_binary_1 = require("./json-n-binary");
|
|
24
|
-
function replyFromPassedDatum(
|
|
25
|
-
if (!
|
|
24
|
+
function replyFromPassedDatum(bytes, transforms) {
|
|
25
|
+
if (!bytes) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
30
|
-
return [
|
|
28
|
+
if (transforms === null || transforms === void 0 ? void 0 : transforms.unpackReply) {
|
|
29
|
+
if (transforms.unpackReply === 'noop') {
|
|
30
|
+
return [bytes];
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
return
|
|
33
|
+
return transforms.unpackReply(bytes);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
|
-
|
|
38
|
-
return (bytes ? (0, json_n_binary_1.deserializeArgs)(bytes, passedByReference)[0] : undefined);
|
|
37
|
+
return (bytes ? (0, json_n_binary_1.deserializeArgs)(bytes, transforms === null || transforms === void 0 ? void 0 : transforms.findReferencedObj)[0] : undefined);
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
function argsToPassedDatum(args,
|
|
40
|
+
function argsToPassedDatum(args, transforms) {
|
|
42
41
|
if (args === undefined) {
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
|
-
if (
|
|
46
|
-
if (
|
|
44
|
+
if (transforms === null || transforms === void 0 ? void 0 : transforms.packRequest) {
|
|
45
|
+
if (transforms.packRequest === 'noop') {
|
|
47
46
|
if (!ArrayBuffer.isView(args[0])) {
|
|
48
47
|
throw new Error(`Method returned non-binary, while no serialization is set`);
|
|
49
48
|
}
|
|
50
|
-
return
|
|
49
|
+
return args[0];
|
|
51
50
|
}
|
|
52
|
-
return
|
|
51
|
+
return transforms.packRequest(args);
|
|
53
52
|
}
|
|
54
53
|
else {
|
|
55
|
-
return (0, json_n_binary_1.serializeArgs)(args);
|
|
54
|
+
return (0, json_n_binary_1.serializeArgs)(args, transforms === null || transforms === void 0 ? void 0 : transforms.findRefOf);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
function makeReqRepFuncCaller(clientSide, path, transforms) {
|
|
59
58
|
return (async (...args) => {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
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);
|
|
59
|
+
const bytes = argsToPassedDatum(args, transforms);
|
|
60
|
+
const reply = await clientSide.startPromiseCall(path, bytes);
|
|
61
|
+
return replyFromPassedDatum(reply, transforms);
|
|
68
62
|
});
|
|
69
63
|
}
|
|
70
64
|
function makeReqRepObjCaller(clientSide, objPath, method, transforms) {
|
|
@@ -72,15 +66,15 @@ function makeReqRepObjCaller(clientSide, objPath, method, transforms) {
|
|
|
72
66
|
}
|
|
73
67
|
function makeObservableFuncCaller(clientSide, path, transforms) {
|
|
74
68
|
return (obs, ...args) => {
|
|
75
|
-
const
|
|
69
|
+
const bytes = argsToPassedDatum(args, transforms);
|
|
76
70
|
const s = new rxjs_1.Subject();
|
|
77
|
-
const unsub = clientSide.startObservableCall(path,
|
|
71
|
+
const unsub = clientSide.startObservableCall(path, bytes, s);
|
|
78
72
|
s.subscribe({
|
|
79
73
|
next: data => {
|
|
80
74
|
if (!obs.next) {
|
|
81
75
|
return;
|
|
82
76
|
}
|
|
83
|
-
const ev = replyFromPassedDatum(
|
|
77
|
+
const ev = replyFromPassedDatum(data, transforms);
|
|
84
78
|
obs.next(ev);
|
|
85
79
|
},
|
|
86
80
|
complete: () => { var _a; return (_a = obs.complete) === null || _a === void 0 ? void 0 : _a.call(obs); },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare function deserializeArgs(bytes: Uint8Array,
|
|
1
|
+
import { ObjectReference } from '../../ipc-via-protobuf/protobuf-msg';
|
|
2
|
+
export type FindObjectRef = (o: any) => ObjectReference<any> | undefined;
|
|
3
|
+
export type FindReferencedObj = (ref: ObjectReference<any>) => any;
|
|
4
|
+
export declare function serializeArgs(args: any[], findRefOf?: FindObjectRef): Buffer;
|
|
5
|
+
export declare function deserializeArgs(bytes: Uint8Array, findReferencedObj?: FindReferencedObj): any[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2022 - 2023 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2022 - 2023, 2025 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
|
|
@@ -22,13 +22,12 @@ const protobuf_type_1 = require("../../lib-client/protobuf-type");
|
|
|
22
22
|
const json_utils_1 = require("../../lib-common/json-utils");
|
|
23
23
|
const json_ipc_proto_1 = require("../../protos/json-ipc.proto");
|
|
24
24
|
const valuesType = protobuf_type_1.ProtoType.for(json_ipc_proto_1.json_ipc.ValuesSequence);
|
|
25
|
-
function serializeArgs(args) {
|
|
26
|
-
const
|
|
27
|
-
return
|
|
25
|
+
function serializeArgs(args, findRefOf) {
|
|
26
|
+
const seq = argsToValuesSequence(args, findRefOf);
|
|
27
|
+
return valuesType.pack(seq);
|
|
28
28
|
}
|
|
29
|
-
function argsToValuesSequence(args) {
|
|
29
|
+
function argsToValuesSequence(args, findRefOf) {
|
|
30
30
|
const seq = { values: [] };
|
|
31
|
-
const passedByReference = [];
|
|
32
31
|
for (const arg of args) {
|
|
33
32
|
if (arg && (typeof arg === 'object')) {
|
|
34
33
|
if (ArrayBuffer.isView(arg)) {
|
|
@@ -37,13 +36,19 @@ function argsToValuesSequence(args) {
|
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
else if (arg._isObjectFromCore) {
|
|
40
|
-
|
|
39
|
+
if (!findRefOf) {
|
|
40
|
+
throw new Error(`Function to find reference for object from core is not given`);
|
|
41
|
+
}
|
|
42
|
+
const objRef = findRefOf(arg);
|
|
43
|
+
if (!objRef) {
|
|
44
|
+
throw new Error(`Reference for object from core wasn't found`);
|
|
45
|
+
}
|
|
41
46
|
seq.values.push({
|
|
42
|
-
transferred: {
|
|
47
|
+
transferred: { objLocation: [], objRef }
|
|
43
48
|
});
|
|
44
49
|
}
|
|
45
50
|
else {
|
|
46
|
-
seq.values.push(turnToJsonExtractingBinaryAndTransferable(arg,
|
|
51
|
+
seq.values.push(turnToJsonExtractingBinaryAndTransferable(arg, findRefOf));
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
else {
|
|
@@ -52,24 +57,10 @@ function argsToValuesSequence(args) {
|
|
|
52
57
|
});
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
|
-
return
|
|
56
|
-
seq,
|
|
57
|
-
passedByReference: ((passedByReference.length > 0) ?
|
|
58
|
-
passedByReference : undefined)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function addToArray(arr, o) {
|
|
62
|
-
let foundIndex = arr.indexOf(o);
|
|
63
|
-
if (foundIndex < 0) {
|
|
64
|
-
arr.push(o);
|
|
65
|
-
return arr.length - 1;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
return foundIndex;
|
|
69
|
-
}
|
|
60
|
+
return seq;
|
|
70
61
|
}
|
|
71
|
-
function turnToJsonExtractingBinaryAndTransferable(arg,
|
|
72
|
-
const parts = extractNonJsonableFrom(arg,
|
|
62
|
+
function turnToJsonExtractingBinaryAndTransferable(arg, findRefOf) {
|
|
63
|
+
const parts = extractNonJsonableFrom(arg, findRefOf);
|
|
73
64
|
if (parts) {
|
|
74
65
|
const { copy, binaryInJson, transferredInJson } = parts;
|
|
75
66
|
return {
|
|
@@ -83,7 +74,7 @@ function turnToJsonExtractingBinaryAndTransferable(arg, passedByReference) {
|
|
|
83
74
|
return { json: JSON.stringify(arg) };
|
|
84
75
|
}
|
|
85
76
|
}
|
|
86
|
-
function extractNonJsonableFrom(arg,
|
|
77
|
+
function extractNonJsonableFrom(arg, findRefOf) {
|
|
87
78
|
const nonJsonLocations = findAllNonJsonable(arg);
|
|
88
79
|
if (!nonJsonLocations) {
|
|
89
80
|
return;
|
|
@@ -95,8 +86,14 @@ function extractNonJsonableFrom(arg, passedByReference) {
|
|
|
95
86
|
const nonJson = getValueAtObjLocation(arg, objLocation);
|
|
96
87
|
setNewValueAtObjLocation(copy, objLocation, null);
|
|
97
88
|
if (nonJson._isObjectFromCore) {
|
|
98
|
-
|
|
99
|
-
|
|
89
|
+
if (!findRefOf) {
|
|
90
|
+
throw new Error(`Function to find reference for object from core is not given`);
|
|
91
|
+
}
|
|
92
|
+
const objRef = findRefOf(arg);
|
|
93
|
+
if (!objRef) {
|
|
94
|
+
throw new Error(`Reference for object from core wasn't found`);
|
|
95
|
+
}
|
|
96
|
+
transferredInJson.push({ objLocation, objRef });
|
|
100
97
|
}
|
|
101
98
|
else {
|
|
102
99
|
binaryInJson.push({ arr: nonJson, objLocation });
|
|
@@ -155,17 +152,7 @@ function setNewValueAtObjLocation(o, objLocation, newValue) {
|
|
|
155
152
|
o[objLocation[0]] = newValue;
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
function
|
|
159
|
-
const value = o[objLocation[0]];
|
|
160
|
-
if (objLocation.length > 1) {
|
|
161
|
-
return getInitAndSetNewValueAt(value, objLocation.slice(1), newValue);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
o[objLocation[0]] = newValue;
|
|
165
|
-
return value;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function deserializeArgs(bytes, passedByReference) {
|
|
155
|
+
function deserializeArgs(bytes, findReferencedObj) {
|
|
169
156
|
const values = valuesType.unpack(bytes);
|
|
170
157
|
const args = [];
|
|
171
158
|
for (const val of values.values) {
|
|
@@ -174,15 +161,21 @@ function deserializeArgs(bytes, passedByReference) {
|
|
|
174
161
|
args.push(arr.arr);
|
|
175
162
|
}
|
|
176
163
|
else if (transferred) {
|
|
177
|
-
|
|
164
|
+
if (!findReferencedObj) {
|
|
165
|
+
throw new Error(`Function to find referenced object is not given`);
|
|
166
|
+
}
|
|
167
|
+
args.push(findReferencedObj(transferred.objRef));
|
|
178
168
|
}
|
|
179
169
|
else if ((typeof json === 'string') && (json.length > 0)) {
|
|
180
170
|
const arg = JSON.parse(json);
|
|
181
171
|
if (binaryInJson) {
|
|
182
172
|
attachBinaryArrays(arg, binaryInJson);
|
|
183
173
|
}
|
|
184
|
-
if (transferredInJson) {
|
|
185
|
-
|
|
174
|
+
if (Array.isArray(transferredInJson) && (transferredInJson.length > 0)) {
|
|
175
|
+
if (!findReferencedObj) {
|
|
176
|
+
throw new Error(`Function to find referenced object is not given`);
|
|
177
|
+
}
|
|
178
|
+
attachTransferred(arg, transferredInJson, findReferencedObj);
|
|
186
179
|
}
|
|
187
180
|
args.push(arg);
|
|
188
181
|
}
|
|
@@ -197,20 +190,8 @@ function attachBinaryArrays(arg, binaryInJson) {
|
|
|
197
190
|
setNewValueAtObjLocation(arg, objLocation, arr);
|
|
198
191
|
}
|
|
199
192
|
}
|
|
200
|
-
function
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
throw new Error(`need better error`);
|
|
204
|
-
}
|
|
205
|
-
const o = passedByReference[indexInPassed];
|
|
206
|
-
if (!o || !o._isObjectFromCore) {
|
|
207
|
-
// XXX throw error here
|
|
208
|
-
throw new Error(`need better error`);
|
|
209
|
-
}
|
|
210
|
-
return o;
|
|
211
|
-
}
|
|
212
|
-
function attachTransferred(arg, transferredInJson, passedByReference) {
|
|
213
|
-
for (const { indexInPassed, objLocation } of transferredInJson) {
|
|
214
|
-
setNewValueAtObjLocation(arg, objLocation, getTransferred(indexInPassed, passedByReference));
|
|
193
|
+
function attachTransferred(arg, transferredInJson, findReferencedObj) {
|
|
194
|
+
for (const { objRef, objLocation } of transferredInJson) {
|
|
195
|
+
setNewValueAtObjLocation(arg, objLocation, findReferencedObj(objRef));
|
|
215
196
|
}
|
|
216
197
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { ExposedFn } from "../../ipc-via-protobuf/connector";
|
|
1
|
+
import { EnvelopeBody, ExposedFn } from "../../ipc-via-protobuf/connector";
|
|
2
|
+
import { FindObjectRef, FindReferencedObj } from "./json-n-binary";
|
|
2
3
|
type Observer<T> = web3n.Observer<T>;
|
|
3
|
-
interface PassedDatum {
|
|
4
|
-
bytes?: Uint8Array;
|
|
5
|
-
passedByReference?: any[];
|
|
6
|
-
}
|
|
7
4
|
export type HandleObservingCall<TEvent> = (obs: Observer<TEvent>, ...requestArgs: any[]) => (() => void);
|
|
8
5
|
export type HandleReqReplyCall = (...requestArgs: any[]) => Promise<any>;
|
|
9
6
|
export interface TransformOpts {
|
|
10
|
-
unpackRequest?: ((req:
|
|
11
|
-
packReply?: ((reply: any) =>
|
|
7
|
+
unpackRequest?: ((req: EnvelopeBody) => any[]) | 'noop';
|
|
8
|
+
packReply?: ((reply: any) => EnvelopeBody) | 'noop';
|
|
9
|
+
findRefOf?: FindObjectRef;
|
|
10
|
+
findReferencedObj?: FindReferencedObj;
|
|
12
11
|
}
|
|
13
12
|
export declare function wrapReqReplySrvMethod<T extends object, M extends keyof T>(srv: T, method: M, transforms?: TransformOpts): ExposedFn;
|
|
14
13
|
export declare function wrapReqReplyFunc(srv: object, func: HandleReqReplyCall, transforms?: TransformOpts): ExposedFn;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2022 -
|
|
3
|
+
Copyright (C) 2022 - 2025 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
|
|
@@ -37,7 +37,7 @@ function wrapReqReplyFunc(srvOrFn, funcOrTransforms, transforms) {
|
|
|
37
37
|
func = funcOrTransforms;
|
|
38
38
|
}
|
|
39
39
|
return buf => {
|
|
40
|
-
const args =
|
|
40
|
+
const args = argsFromPassedDatum(buf, transforms);
|
|
41
41
|
let promise = (args ?
|
|
42
42
|
func.call(srv, ...args) :
|
|
43
43
|
func.call(srv));
|
|
@@ -53,42 +53,34 @@ function wrapReqReplyFunc(srvOrFn, funcOrTransforms, transforms) {
|
|
|
53
53
|
return { promise };
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
function resultToBuffer(data, transforms) {
|
|
60
|
-
const sequencePack = toPassedDatum(data, transforms === null || transforms === void 0 ? void 0 : transforms.packReply);
|
|
61
|
-
return sequencePack === null || sequencePack === void 0 ? void 0 : sequencePack.bytes;
|
|
62
|
-
}
|
|
63
|
-
function argsFromPassedDatum(data, unpack) {
|
|
64
|
-
if (!data) {
|
|
56
|
+
function argsFromPassedDatum(bytes, transforms) {
|
|
57
|
+
if (!bytes) {
|
|
65
58
|
return;
|
|
66
59
|
}
|
|
67
|
-
if (
|
|
68
|
-
if (
|
|
69
|
-
return [
|
|
60
|
+
if (transforms === null || transforms === void 0 ? void 0 : transforms.unpackRequest) {
|
|
61
|
+
if (transforms.unpackRequest === 'noop') {
|
|
62
|
+
return [bytes];
|
|
70
63
|
}
|
|
71
64
|
else {
|
|
72
|
-
return
|
|
65
|
+
return transforms.unpackRequest(bytes);
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
68
|
else {
|
|
76
|
-
|
|
77
|
-
return (bytes ? (0, json_n_binary_1.deserializeArgs)(bytes, passedByReference) : undefined);
|
|
69
|
+
return (bytes ? (0, json_n_binary_1.deserializeArgs)(bytes) : undefined);
|
|
78
70
|
}
|
|
79
71
|
}
|
|
80
|
-
function
|
|
72
|
+
function resultToBuffer(data, transforms) {
|
|
81
73
|
if (data === undefined) {
|
|
82
74
|
return;
|
|
83
75
|
}
|
|
84
|
-
if (
|
|
85
|
-
if (
|
|
76
|
+
if (transforms === null || transforms === void 0 ? void 0 : transforms.packReply) {
|
|
77
|
+
if (transforms.packReply === 'noop') {
|
|
86
78
|
if (!ArrayBuffer.isView(data)) {
|
|
87
79
|
throw new Error(`Method returned non-binary, while no serialization is set`);
|
|
88
80
|
}
|
|
89
|
-
return
|
|
81
|
+
return data;
|
|
90
82
|
}
|
|
91
|
-
return
|
|
83
|
+
return transforms.packReply(data);
|
|
92
84
|
}
|
|
93
85
|
else {
|
|
94
86
|
return (0, json_n_binary_1.serializeArgs)([data]);
|
|
@@ -107,7 +99,7 @@ function wrapObservingFunc(srvOrFn, funcOrTransforms, transforms) {
|
|
|
107
99
|
func = funcOrTransforms;
|
|
108
100
|
}
|
|
109
101
|
return buf => {
|
|
110
|
-
const args =
|
|
102
|
+
const args = argsFromPassedDatum(buf, transforms);
|
|
111
103
|
const s = new rxjs_1.Subject();
|
|
112
104
|
const obs = s.asObservable().pipe((0, rxjs_1.map)(ev => resultToBuffer(ev, transforms)));
|
|
113
105
|
const onCancel = (args ?
|