luci-base: amend rpc to handle objects in param

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 <newtwen+github@gmail.com>
This commit is contained in:
Paul Donald
2026-01-08 18:12:40 +01:00
parent 05f90a2044
commit fddc70391f

View 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 ];