Skip to content

English__Data Sources__Single Value

Ramirez Vargas, José Pablo edited this page Nov 7, 2024 · 2 revisions

Single Value Data Source

The Single Value data source is just a specialization of the Dictionary data source. This data source accepts a key and a value, and internally creates a dictionary object with a single property (the provided key and value).

How To Use the Single Value Data Source

As with all other data sources, there is a specialized addSingleValue() method in the configuration builder that assists with this job. This function is defined with two overloads:

addSingleValue<NewT extends Record<string, any>>(
    path: string,
    value?: ConfigurationValue,
    hierarchySeparator?: string
): IBuilder<MergeResult<T, NewT>>;

addSingleValue<NewT extends Record<string, any>>(
    dataFn: () => Promise<[string, ConfigurationValue]>,
    hierarchySeparator?: string
): IBuilder<MergeResult<T, NewT>>;

For both overloads, the last parameter (hierarchySeparator) is used to specify the string used inside the key to define the hierarchy of the value.

For the first overload, the first two parameters are used to collect the key and the value, respectively.

For the second overload, the developer provides a function that, once executed, returns a two-value tuple (an array with two elements) where the first value is the key, and the second one is the value. This function approach is the recommended approach when doing any form of conditional configuration if obtaining the key or value will incur in potentially-wasted CPU cycles or RAM.

Data Requirements

Since this is a specialization of the Dictionary data source, all of the data requirements of this ancestor apply here too. Furthermore:

  1. The key is mandatory.
  2. The value must be a scalar (leaf) value.
  3. Filtering cannot be specified. No prefix or predicate function can be specified.

Clone this wiki locally