hypha-rpc 0.20.41 → 0.20.43
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/dist/hypha-rpc-websocket.js +58 -7
- package/dist/hypha-rpc-websocket.js.map +1 -1
- package/dist/hypha-rpc-websocket.min.js +1 -1
- package/dist/hypha-rpc-websocket.min.js.map +1 -1
- package/dist/hypha-rpc-websocket.min.mjs +1 -1
- package/dist/hypha-rpc-websocket.min.mjs.map +1 -1
- package/dist/hypha-rpc-websocket.mjs +58 -7
- package/dist/hypha-rpc-websocket.mjs.map +1 -1
- package/package.json +1 -1
- package/src/rpc.js +7 -7
- package/src/utils/index.js +50 -0
- package/src/websocket-client.js +1 -0
- package/tests/websocket_client_test.js +12 -0
|
@@ -525,14 +525,10 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
525
525
|
|
|
526
526
|
async get_manager_service(config) {
|
|
527
527
|
config = config || {};
|
|
528
|
-
let { timeout, case_conversion } = config;
|
|
529
528
|
(0,_utils__WEBPACK_IMPORTED_MODULE_0__.assert)(this._connection.manager_id, "Manager id is not set");
|
|
530
529
|
const svc = await this.get_remote_service(
|
|
531
530
|
`*/${this._connection.manager_id}:default`,
|
|
532
|
-
|
|
533
|
-
timeout: timeout,
|
|
534
|
-
case_conversion: case_conversion,
|
|
535
|
-
},
|
|
531
|
+
config,
|
|
536
532
|
);
|
|
537
533
|
return svc;
|
|
538
534
|
}
|
|
@@ -569,7 +565,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
569
565
|
);
|
|
570
566
|
}
|
|
571
567
|
async get_remote_service(service_uri, config) {
|
|
572
|
-
let { timeout, case_conversion } = config || {};
|
|
568
|
+
let { timeout, case_conversion, kwargs_expansion } = config || {};
|
|
573
569
|
timeout = timeout === undefined ? this._method_timeout : timeout;
|
|
574
570
|
if (!service_uri && this._connection.manager_id) {
|
|
575
571
|
service_uri = "*/" + this._connection.manager_id;
|
|
@@ -597,12 +593,15 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
597
593
|
_rpromise: true,
|
|
598
594
|
_rdoc: "Get a remote service",
|
|
599
595
|
});
|
|
600
|
-
|
|
596
|
+
let svc = await (0,_utils__WEBPACK_IMPORTED_MODULE_0__.waitFor)(
|
|
601
597
|
method(service_id),
|
|
602
598
|
timeout,
|
|
603
599
|
"Timeout Error: Failed to get remote service: " + service_uri,
|
|
604
600
|
);
|
|
605
601
|
svc.id = `${provider}:${service_id}`;
|
|
602
|
+
if (kwargs_expansion) {
|
|
603
|
+
svc = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.expandKwargs)(svc);
|
|
604
|
+
}
|
|
606
605
|
if (case_conversion)
|
|
607
606
|
return Object.assign(
|
|
608
607
|
new RemoteService(),
|
|
@@ -1817,6 +1816,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1817
1816
|
/* harmony export */ cacheRequirements: () => (/* binding */ cacheRequirements),
|
|
1818
1817
|
/* harmony export */ convertCase: () => (/* binding */ convertCase),
|
|
1819
1818
|
/* harmony export */ dtypeToTypedArray: () => (/* binding */ dtypeToTypedArray),
|
|
1819
|
+
/* harmony export */ expandKwargs: () => (/* binding */ expandKwargs),
|
|
1820
1820
|
/* harmony export */ loadRequirements: () => (/* binding */ loadRequirements),
|
|
1821
1821
|
/* harmony export */ loadRequirementsInWebworker: () => (/* binding */ loadRequirementsInWebworker),
|
|
1822
1822
|
/* harmony export */ loadRequirementsInWindow: () => (/* binding */ loadRequirementsInWindow),
|
|
@@ -1848,6 +1848,56 @@ function toSnakeCase(str) {
|
|
|
1848
1848
|
return str.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
1849
1849
|
}
|
|
1850
1850
|
|
|
1851
|
+
function expandKwargs(obj) {
|
|
1852
|
+
if (typeof obj !== "object" || obj === null) {
|
|
1853
|
+
return obj; // Return the value if obj is not an object
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
const newObj = Array.isArray(obj) ? [] : {};
|
|
1857
|
+
|
|
1858
|
+
for (const key in obj) {
|
|
1859
|
+
if (obj.hasOwnProperty(key)) {
|
|
1860
|
+
const value = obj[key];
|
|
1861
|
+
|
|
1862
|
+
if (typeof value === "function") {
|
|
1863
|
+
newObj[key] = (...args) => {
|
|
1864
|
+
if (args.length === 0) {
|
|
1865
|
+
throw new Error(`Function "${key}" expects at least one argument.`);
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
// Check if the last argument is an object
|
|
1869
|
+
const lastArg = args[args.length - 1];
|
|
1870
|
+
let kwargs = {};
|
|
1871
|
+
|
|
1872
|
+
if (
|
|
1873
|
+
typeof lastArg === "object" &&
|
|
1874
|
+
lastArg !== null &&
|
|
1875
|
+
!Array.isArray(lastArg)
|
|
1876
|
+
) {
|
|
1877
|
+
// Extract kwargs from the last argument
|
|
1878
|
+
kwargs = { ...lastArg, _rkwarg: true };
|
|
1879
|
+
args = args.slice(0, -1); // Remove the last argument from args
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
// Call the original function with positional args followed by kwargs
|
|
1883
|
+
return value(...args, kwargs);
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1886
|
+
// Preserve metadata like __name__ and __schema__
|
|
1887
|
+
newObj[key].__name__ = key;
|
|
1888
|
+
if (value.__schema__) {
|
|
1889
|
+
newObj[key].__schema__ = { ...value.__schema__ };
|
|
1890
|
+
newObj[key].__schema__.name = key;
|
|
1891
|
+
}
|
|
1892
|
+
} else {
|
|
1893
|
+
newObj[key] = expandKwargs(value); // Recursively process nested objects
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
return newObj;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1851
1901
|
function convertCase(obj, caseType) {
|
|
1852
1902
|
if (typeof obj !== "object" || obj === null || !caseType) {
|
|
1853
1903
|
return obj; // Return the value if obj is not an object
|
|
@@ -5036,6 +5086,7 @@ async function connectToServer(config) {
|
|
|
5036
5086
|
const wm = await rpc.get_manager_service({
|
|
5037
5087
|
timeout: config.method_timeout,
|
|
5038
5088
|
case_conversion: "camel",
|
|
5089
|
+
kwargs_expansion: config.kwargs_expansion || false,
|
|
5039
5090
|
});
|
|
5040
5091
|
wm.rpc = rpc;
|
|
5041
5092
|
|