hypha-rpc 0.20.66 → 0.20.67
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 +91 -12
- 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 +91 -12
- package/dist/hypha-rpc-websocket.mjs.map +1 -1
- package/package.json +1 -1
- package/src/rpc.js +21 -3
- package/src/utils/schema.js +66 -6
- package/src/websocket-client.js +2 -2
- package/tests/utils_test.js +69 -0
- package/report.html +0 -39
|
@@ -58,6 +58,8 @@ function indexObject(obj, is) {
|
|
|
58
58
|
else return indexObject(obj[is[0]], is.slice(1));
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
// Simple fallback schema generation - no docstring parsing for JS
|
|
62
|
+
|
|
61
63
|
function _get_schema(obj, name = null, skipContext = false) {
|
|
62
64
|
if (Array.isArray(obj)) {
|
|
63
65
|
return obj.map((v, i) => _get_schema(v, null, skipContext));
|
|
@@ -78,10 +80,23 @@ function _get_schema(obj, name = null, skipContext = false) {
|
|
|
78
80
|
if (schema.parameters && schema.parameters.properties) {
|
|
79
81
|
delete schema.parameters.properties["context"];
|
|
80
82
|
}
|
|
83
|
+
if (schema.parameters && schema.parameters.required) {
|
|
84
|
+
const contextIndex = schema.parameters.required.indexOf("context");
|
|
85
|
+
if (contextIndex > -1) {
|
|
86
|
+
schema.parameters.required.splice(contextIndex, 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
81
89
|
}
|
|
82
90
|
return { type: "function", function: schema };
|
|
83
91
|
} else {
|
|
84
|
-
return
|
|
92
|
+
// Simple fallback for JavaScript - just return basic function schema with name
|
|
93
|
+
const funcName = name || obj.name || "function";
|
|
94
|
+
return {
|
|
95
|
+
type: "function",
|
|
96
|
+
function: {
|
|
97
|
+
name: funcName,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
85
100
|
}
|
|
86
101
|
} else if (typeof obj === "number") {
|
|
87
102
|
return { type: "number" };
|
|
@@ -696,7 +711,10 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
696
711
|
|
|
697
712
|
service.config["workspace"] = context["ws"];
|
|
698
713
|
// allow access for the same workspace
|
|
699
|
-
if (
|
|
714
|
+
if (
|
|
715
|
+
service.config.visibility == "public" ||
|
|
716
|
+
service.config.visibility == "unlisted"
|
|
717
|
+
) {
|
|
700
718
|
return service;
|
|
701
719
|
}
|
|
702
720
|
|
|
@@ -849,7 +867,7 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
849
867
|
require_context = api.config.require_context;
|
|
850
868
|
if (api.config.run_in_executor) run_in_executor = true;
|
|
851
869
|
const visibility = api.config.visibility || "protected";
|
|
852
|
-
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(["protected", "public"].includes(visibility));
|
|
870
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(["protected", "public", "unlisted"].includes(visibility));
|
|
853
871
|
this._annotate_service_methods(
|
|
854
872
|
api,
|
|
855
873
|
api["id"],
|
|
@@ -2799,11 +2817,44 @@ function isAsyncGenerator(obj) {
|
|
|
2799
2817
|
|
|
2800
2818
|
__webpack_require__.r(__webpack_exports__);
|
|
2801
2819
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2802
|
-
/* harmony export */ schemaFunction: () => (/* binding */ schemaFunction)
|
|
2820
|
+
/* harmony export */ schemaFunction: () => (/* binding */ schemaFunction),
|
|
2821
|
+
/* harmony export */ z: () => (/* binding */ z)
|
|
2803
2822
|
/* harmony export */ });
|
|
2804
2823
|
/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.js */ "./src/utils/index.js");
|
|
2805
2824
|
|
|
2806
2825
|
|
|
2826
|
+
// Schema builder utility inspired by Zod for consistent API with Python
|
|
2827
|
+
const z = {
|
|
2828
|
+
object: (properties) => ({
|
|
2829
|
+
type: "object",
|
|
2830
|
+
properties,
|
|
2831
|
+
required: Object.keys(properties).filter(
|
|
2832
|
+
(key) => !properties[key]._optional,
|
|
2833
|
+
),
|
|
2834
|
+
}),
|
|
2835
|
+
|
|
2836
|
+
string: () => ({ type: "string", _optional: false }),
|
|
2837
|
+
number: () => ({ type: "number", _optional: false }),
|
|
2838
|
+
integer: () => ({ type: "integer", _optional: false }),
|
|
2839
|
+
boolean: () => ({ type: "boolean", _optional: false }),
|
|
2840
|
+
array: (items) => ({ type: "array", items, _optional: false }),
|
|
2841
|
+
|
|
2842
|
+
// Make field optional
|
|
2843
|
+
optional: (schema) => ({ ...schema, _optional: true }),
|
|
2844
|
+
};
|
|
2845
|
+
|
|
2846
|
+
// Add description method to schema types
|
|
2847
|
+
["string", "number", "integer", "boolean", "array"].forEach((type) => {
|
|
2848
|
+
z[type] = () => {
|
|
2849
|
+
const schema = {
|
|
2850
|
+
type: type === "integer" ? "integer" : type,
|
|
2851
|
+
_optional: false,
|
|
2852
|
+
};
|
|
2853
|
+
schema.describe = (description) => ({ ...schema, description });
|
|
2854
|
+
return schema;
|
|
2855
|
+
};
|
|
2856
|
+
});
|
|
2857
|
+
|
|
2807
2858
|
function schemaFunction(
|
|
2808
2859
|
func,
|
|
2809
2860
|
{ schema_type = "auto", name = null, description = null, parameters = null },
|
|
@@ -2812,15 +2863,43 @@ function schemaFunction(
|
|
|
2812
2863
|
throw Error("func should be a function");
|
|
2813
2864
|
}
|
|
2814
2865
|
(0,_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(schema_type === "auto", "schema_type should be auto");
|
|
2815
|
-
|
|
2866
|
+
|
|
2867
|
+
// If no name provided, try to get it from function
|
|
2868
|
+
const funcName = name || func.name;
|
|
2869
|
+
(0,_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(funcName, "name should not be null");
|
|
2870
|
+
|
|
2871
|
+
// If parameters is a z.object result, convert it properly
|
|
2872
|
+
let processedParameters = parameters;
|
|
2873
|
+
if (
|
|
2874
|
+
parameters &&
|
|
2875
|
+
typeof parameters === "object" &&
|
|
2876
|
+
parameters.type === "object"
|
|
2877
|
+
) {
|
|
2878
|
+
processedParameters = {
|
|
2879
|
+
type: "object",
|
|
2880
|
+
properties: parameters.properties || {},
|
|
2881
|
+
required: parameters.required || [],
|
|
2882
|
+
};
|
|
2883
|
+
|
|
2884
|
+
// Clean up internal _optional flags
|
|
2885
|
+
for (const [key, schema] of Object.entries(
|
|
2886
|
+
processedParameters.properties,
|
|
2887
|
+
)) {
|
|
2888
|
+
if (schema._optional !== undefined) {
|
|
2889
|
+
delete schema._optional;
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2816
2894
|
(0,_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
2817
|
-
|
|
2818
|
-
"parameters should be an object",
|
|
2895
|
+
processedParameters && processedParameters.type === "object",
|
|
2896
|
+
"parameters should be an object schema",
|
|
2819
2897
|
);
|
|
2898
|
+
|
|
2820
2899
|
func.__schema__ = {
|
|
2821
|
-
name:
|
|
2822
|
-
description: description,
|
|
2823
|
-
parameters:
|
|
2900
|
+
name: funcName,
|
|
2901
|
+
description: description || "",
|
|
2902
|
+
parameters: processedParameters,
|
|
2824
2903
|
};
|
|
2825
2904
|
return func;
|
|
2826
2905
|
}
|
|
@@ -5428,7 +5507,7 @@ class WebsocketRPCConnection {
|
|
|
5428
5507
|
// Check if the message is a reconnection token
|
|
5429
5508
|
if (parsedData.type === "reconnection_token") {
|
|
5430
5509
|
this._reconnection_token = parsedData.reconnection_token;
|
|
5431
|
-
console.log("Reconnection token received");
|
|
5510
|
+
// console.log("Reconnection token received");
|
|
5432
5511
|
} else {
|
|
5433
5512
|
console.log("Received message from the server:", parsedData);
|
|
5434
5513
|
}
|
|
@@ -5465,7 +5544,7 @@ class WebsocketRPCConnection {
|
|
|
5465
5544
|
if (this._websocket && this._websocket.readyState === WebSocket.OPEN) {
|
|
5466
5545
|
const refreshMessage = JSON.stringify({ type: "refresh_token" });
|
|
5467
5546
|
this._websocket.send(refreshMessage);
|
|
5468
|
-
console.log("Requested refresh token");
|
|
5547
|
+
// console.log("Requested refresh token");
|
|
5469
5548
|
}
|
|
5470
5549
|
}
|
|
5471
5550
|
|