hypha-debugger 0.1.7 → 0.1.9
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-debugger.js +27 -1
- package/dist/hypha-debugger.js.map +1 -1
- package/dist/hypha-debugger.min.js +2 -2
- package/dist/hypha-debugger.min.js.map +1 -1
- package/dist/hypha-debugger.mjs +27 -1
- package/dist/hypha-debugger.mjs.map +1 -1
- package/dist/utils/wrap-fn.d.ts +4 -0
- package/package.json +1 -1
package/dist/hypha-debugger.js
CHANGED
|
@@ -11259,6 +11259,10 @@
|
|
|
11259
11259
|
* This helper uses new Function() to create a wrapper whose parameter names
|
|
11260
11260
|
* are taken from the function's __schema__ property, so hypha-rpc always sees
|
|
11261
11261
|
* the real parameter names regardless of minification.
|
|
11262
|
+
*
|
|
11263
|
+
* Additionally, it handles the case where hypha-rpc passes kwargs as a single
|
|
11264
|
+
* object argument (e.g. `fn({url: "..."})` instead of `fn("...")`). The
|
|
11265
|
+
* wrapper detects this and destructures the kwargs object automatically.
|
|
11262
11266
|
*/
|
|
11263
11267
|
function wrapFn(fn) {
|
|
11264
11268
|
const schema = fn.__schema__;
|
|
@@ -11268,8 +11272,23 @@
|
|
|
11268
11272
|
if (paramNames.length === 0) {
|
|
11269
11273
|
return fn;
|
|
11270
11274
|
}
|
|
11275
|
+
// Create a wrapper that:
|
|
11276
|
+
// 1. Has correct, unminified parameter names (for hypha-rpc getParamNames)
|
|
11277
|
+
// 2. Detects when kwargs are passed as a single object and destructures them
|
|
11271
11278
|
const paramList = paramNames.join(", ");
|
|
11272
|
-
const wrapper = new Function("fn", `return async function(${paramList}) {
|
|
11279
|
+
const wrapper = new Function("fn", "paramNames", `return async function(${paramList}) {
|
|
11280
|
+
// Detect kwargs-as-object: single argument that is a plain object
|
|
11281
|
+
// whose keys match schema parameter names
|
|
11282
|
+
if (arguments.length === 1 && ${paramList} != null && typeof ${paramList} === "object" && !Array.isArray(${paramList}) && !(${paramList} instanceof Date)) {
|
|
11283
|
+
var _kw = ${paramList};
|
|
11284
|
+
var _firstKey = Object.keys(_kw)[0];
|
|
11285
|
+
if (_firstKey && paramNames.indexOf(_firstKey) !== -1) {
|
|
11286
|
+
var _args = paramNames.map(function(n) { return _kw[n]; });
|
|
11287
|
+
return fn.apply(null, _args);
|
|
11288
|
+
}
|
|
11289
|
+
}
|
|
11290
|
+
return fn(${paramList});
|
|
11291
|
+
}`)(fn, paramNames);
|
|
11273
11292
|
if (schema)
|
|
11274
11293
|
wrapper.__schema__ = schema;
|
|
11275
11294
|
return wrapper;
|
|
@@ -14059,6 +14078,13 @@
|
|
|
14059
14078
|
this.cursor = new AICursor();
|
|
14060
14079
|
}
|
|
14061
14080
|
try {
|
|
14081
|
+
// Polyfill Promise.prototype.finally if missing (needed by hypha-rpc
|
|
14082
|
+
// in some older environments / polyfilled Promise implementations)
|
|
14083
|
+
if (typeof Promise.prototype.finally !== "function") {
|
|
14084
|
+
Promise.prototype.finally = function (cb) {
|
|
14085
|
+
return this.then((value) => Promise.resolve(cb()).then(() => value), (reason) => Promise.resolve(cb()).then(() => { throw reason; }));
|
|
14086
|
+
};
|
|
14087
|
+
}
|
|
14062
14088
|
// Get the connectToServer function
|
|
14063
14089
|
const connect = this.getConnectToServer();
|
|
14064
14090
|
// Connect to Hypha server
|