luci-base: amend rpc to handle objects in param
authorPaul Donald <redacted>
Thu, 8 Jan 2026 17:12:40 +0000 (18:12 +0100)
committerPaul Donald <redacted>
Fri, 23 Jan 2026 03:27:51 +0000 (04:27 +0100)
This allows more complex and nested call constructions. Example:

const container_create = rpc.declare({
object: 'frob',
method: 'glob',
params: { foo: { }, bar: { } },
});

Signed-off-by: Paul Donald <redacted>
modules/luci-base/htdocs/luci-static/resources/rpc.js

index 903d9d0b6079f2e50acf127f899d0265903fe9ad..9213b2cd5f5bee59ef6c44491d7562e2d45e5aa6 100644 (file)
@@ -299,9 +299,20 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ {
                                /* build parameter object */
                                let p_off = 0;
                                const params = { };
-                               if (Array.isArray(options.params))
+                               if (Array.isArray(options.params)) {
+                                       // Array style: parameter names are positional
                                        for (p_off = 0; p_off < options.params.length; p_off++)
                                                params[options.params[p_off]] = args[p_off];
+                               } else if (typeof(options.params) === 'object') {
+                                       // Object style: first arg is an object with the parameter keys
+                                       const argObj = args[0];
+                                       if (argObj && typeof(argObj) === 'object') {
+                                               for (let key in options.params)
+                                                       if (key in argObj)
+                                                               params[key] = argObj[key];
+                                       }
+                                       p_off = 1;
+                               }
 
                                /* all remaining arguments are private args */
                                const priv = [ undefined, undefined ];
git clone https://git.99rst.org/PROJECT