hypha-debugger 0.1.7 → 0.1.8

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.
@@ -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}) { return fn(${paramList}); }`)(fn);
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;