Methods
add(config, type, nameopt) → {string}
Adds a new section of the given type to the given configuration, optionally named according to the given name.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
string | The name of the configuration to add the section to. |
|
type |
string | The type of the section to add. |
|
name |
string |
<optional> |
The name of the section to add. If the name is omitted, an anonymous section will be added instead. |
Returns:
Returns the section ID of the newly added section which is equivalent to the given name for non-anonymous sections.
- Type
- string
apply(timeoutopt) → {Promise.<number>}
Instructs the remote ubus
UCI api to commit all saved changes with
rollback protection and attempts to confirm the pending commit
operation to cancel the rollback timer.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
timeout |
number |
<optional> |
10 | Override the confirmation timeout after which a rollback is triggered. |
Returns:
Returns a promise resolving/rejecting with the ubus
RPC status code.
- Type
- Promise.<number>
changes() → {Promise.<Object.<string, Array.<LuCI.uci.ChangeRecord>>>}
Fetches uncommitted UCI changes from the remote ubus
RPC api.
Returns:
Returns a promise resolving to an object containing the configuration names as keys and arrays of related change records as values.
- Type
- Promise.<Object.<string, Array.<LuCI.uci.ChangeRecord>>>
createSID(config) → {string}
Generates a new, unique section ID for the given configuration.
Note that the generated ID is temporary, it will get replaced by an
identifier in the form cfgXXXXXX
once the configuration is saved
by the remote ubus
UCI api.
Parameters:
Name | Type | Description |
---|---|---|
config |
string | The configuration to generate the new section ID for. |
Returns:
A newly generated, unique section ID in the form newXXXXXX
where X
denotes a hexadecimal digit.
- Type
- string
get(config, sid, optionopt) → {null|string|Array.<string>|LuCI.uci.SectionObject}
Gets the value of the given option within the specified section of the given configuration or the entire section object if the option name is omitted.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
string | The name of the configuration to read the value from. |
|
sid |
string | The name or ID of the section to read. |
|
option |
string |
<optional> |
The option name to read the value from. If the option name is
omitted or |
Returns:
- Returns a string containing the option value in case of a plain UCI option.
- Returns an array of strings containing the option values in
case of
option
pointing to an UCI list. - Returns a
section object
if theoption
argument has been omitted or isnull
. - Returns
null
if the config, section or option has not been found or if the corresponding configuration is not loaded.
- Type
- null | string | Array.<string> | LuCI.uci.SectionObject
get_first(config, typeopt, optionopt) → {null|string|Array.<string>|LuCI.uci.SectionObject}
Gets the value of the given option or the entire section object of the first found section of the specified type or the first found section of the entire configuration if no type is specfied.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
string | The name of the configuration to read the value from. |
|
type |
string |
<optional> |
The type of the first section to find. If it is |
option |
string |
<optional> |
The option name to read the value from. If the option name is
omitted or |
Returns:
- Returns a string containing the option value in case of a plain UCI option.
- Returns an array of strings containing the option values in
case of
option
pointing to an UCI list. - Returns a
section object
if theoption
argument has been omitted or isnull
. - Returns
null
if the config, section or option has not been found or if the corresponding configuration is not loaded.
- Type
- null | string | Array.<string> | LuCI.uci.SectionObject
load(config) → {Promise.<Array.<string>>}
Loads the given UCI configurations from the remote ubus
api.
Loaded configurations are cached and only loaded once. Subsequent load operations of the same configurations will return the cached data.
To force reloading a configuration, it has to be unloaded with
uci.unload()
first.
Parameters:
Name | Type | Description |
---|---|---|
config |
string | Array.<string> | The name of the configuration or an array of configuration names to load. |
Returns:
Returns a promise resolving to the names of the configurations that have been successfully loaded.
- Type
- Promise.<Array.<string>>
move(config, sid1, sid2opt, afteropt) → {boolean}
Move the first specified section within the given configuration before or after the second specified section.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
config |
string | The configuration to move the section within. |
||
sid1 |
string | The ID of the section to move within the configuration. |
||
sid2 |
string |
<optional> |
The ID of the target section for the move operation. If the
When the |
|
after |
boolean |
<optional> |
false | When If |
Returns:
Returns true
when the section was successfully moved, or false
when either the section specified by sid1
or by sid2
is not found.
- Type
- boolean
remove(config, sid)
Removes the section with the given ID from the given configuration.
Parameters:
Name | Type | Description |
---|---|---|
config |
string | The name of the configuration to remove the section from. |
sid |
string | The ID of the section to remove. |
resolveSID(config, sid) → {string|null}
Resolves a given section ID in extended notation to the internal section ID value.
Parameters:
Name | Type | Description |
---|---|---|
config |
string | The configuration to resolve the section ID for. |
sid |
string | The section ID to resolve. If the ID is in the form |
Returns:
Returns the resolved section ID or the original given ID if it was
not in extended notation. Returns null
when an extended ID could
not be resolved to existing section ID.
- Type
- string | null
save() → {Array.<string>}
Submits all local configuration changes to the remove ubus
api,
adds, removes and reorders remote sections as needed and reloads
all loaded configurations to resynchronize the local state with
the remote configuration values.
Returns:
Returns a promise resolving to an array of configuration names which have been reloaded by the save operation.
- Type
- Array.<string>
sections(config, typeopt, cbopt) → {Array.<LuCI.uci.SectionObject>}
Enumerates the sections of the given configuration, optionally filtered by type.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
string | The name of the configuration to enumerate the sections for. |
|
type |
string |
<optional> |
Enumerate only sections of the given type. If omitted, enumerate all sections. |
cb |
LuCI.uci~sectionsFn |
<optional> |
An optional callback to invoke for each enumerated section. |
Returns:
Returns a sorted array of the section objects within the given configuration, filtered by type of a type has been specified.
- Type
- Array.<LuCI.uci.SectionObject>
set(config, sid, option, value)
Sets the value of the given option within the specified section of the given configuration.
If either config, section or option is null, or if option
begins
with a dot, the function will do nothing.
Parameters:
Name | Type | Description |
---|---|---|
config |
string | The name of the configuration to set the option value in. |
sid |
string | The name or ID of the section to set the option value in. |
option |
string | The option name to set the value for. |
value |
null | string | Array.<string> | The option value to set. If the value is |
set_first(config, typeopt, option, value)
Sets the value of the given option within the first found section of the given configuration matching the specified type or within the first section of the entire config when no type has is specified.
If either config, type or option is null, or if option
begins
with a dot, the function will do nothing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
string | The name of the configuration to set the option value in. |
|
type |
string |
<optional> |
The type of the first section to find. If it is |
option |
string | The option name to set the value for. |
|
value |
null | string | Array.<string> | The option value to set. If the value is |
unload(config)
Unloads the given UCI configurations from the local cache.
Parameters:
Name | Type | Description |
---|---|---|
config |
string | Array.<string> | The name of the configuration or an array of configuration names to unload. |
unset(config, sid, option)
Remove the given option within the specified section of the given configuration.
This function is a convenience wrapper around
uci.set(config, section, option, null)
.
Parameters:
Name | Type | Description |
---|---|---|
config |
string | The name of the configuration to remove the option from. |
sid |
string | The name or ID of the section to remove the option from. |
option |
string | The name of the option to remove. |
unset_first(config, typeopt, option)
Removes the given option within the first found section of the given configuration matching the specified type or within the first section of the entire config when no type has is specified.
This function is a convenience wrapper around
uci.set_first(config, type, option, null)
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
string | The name of the configuration to set the option value in. |
|
type |
string |
<optional> |
The type of the first section to find. If it is |
option |
string | The option name to set the value for. |
Type Definitions
ChangeRecord
An UCI change record is a plain array containing the change operation name as first element, the affected section ID as second argument and an optional third and fourth argument whose meanings depend on the operation.
Type:
- Array.<string>
Properties:
Name | Type | Description |
---|---|---|
0 |
string | The operation name - may be one of |
1 |
string | The section ID targeted by the operation. |
2 |
string | The meaning of the third element depends on the operation.
|
4 |
string | The meaning of the fourth element depends on the operation.
|
SectionObject
A section object represents the options and their corresponding values enclosed within a configuration section, as well as some additional meta data such as sort indexes and internal ID.
Any internal metadata fields are prefixed with a dot which is isn't an allowed character for normal option names.
Type:
- Object.<string, (boolean|number|string|Array.<string>)>
Properties:
Name | Type | Description |
---|---|---|
.anonymous |
boolean | The |
.index |
number | The |
.name |
string | The |
.type |
string | The |
* |
string | Array.<string> | A section object may contain an arbitrary number of further properties representing the uci option enclosed in the section. All option property names will be in the form |
sectionsFn(section, sid)
The sections callback is invoked for each section found within the given configuration and receives the section object and its associated name as arguments.
Parameters:
Name | Type | Description |
---|---|---|
section |
LuCI.uci.SectionObject | The section object. |
sid |
string | The name or ID of the section. |