UNPKG

5.17 kBTypeScriptView Raw
1import { StringValueMap } from '../data/StringValueMap';
2/**
3 * Contains a key-value map with configuration parameters.
4 * All values stored as strings and can be serialized as JSON or string forms.
5 * When retrieved the values can be automatically converted on read using GetAsXXX methods.
6 *
7 * The keys are case-sensitive, so it is recommended to use consistent C-style as: <code>"my_param"</code>
8 *
9 * Configuration parameters can be broken into sections and subsections using dot notation as:
10 * <code>"section1.subsection1.param1"</code>. Using GetSection method all parameters from specified section
11 * can be extracted from a ConfigMap.
12 *
13 * The ConfigParams supports serialization from/to plain strings as:
14 * <code>"key1=123;key2=ABC;key3=2016-09-16T00:00:00.00Z"</code>
15 *
16 * ConfigParams are used to pass configurations to [[IConfigurable]] objects.
17 * They also serve as a basis for more concrete configurations such as [[https://pip-services3-node.github.io/pip-services3-components-node/classes/connect.connectionparams.html ConnectionParams]]
18 * or [[https://pip-services3-node.github.io/pip-services3-components-node/classes/auth.credentialparams.html CredentialParams]] (in the Pip.Services components package).
19 *
20 * @see [[IConfigurable]]
21 * @see [[StringValueMap]]
22 *
23 * ### Example ###
24 *
25 * let config = ConfigParams.fromTuples(
26 * "section1.key1", "AAA",
27 * "section1.key2", 123,
28 * "section2.key1", true
29 * );
30 *
31 * config.getAsString("section1.key1"); // Result: AAA
32 * config.getAsInteger("section1.key1"); // Result: 0
33 *
34 * section1 = config.getSection("section1");
35 * section1.toString(); // Result: key1=AAA;key2=123
36 *
37 */
38export declare class ConfigParams extends StringValueMap {
39 /**
40 * Creates a new ConfigParams and fills it with values.
41 *
42 * @param values (optional) an object to be converted into key-value pairs to initialize this config map.
43 *
44 * @see [[StringValueMap.constructor]]
45 */
46 constructor(values?: any);
47 /**
48 * Gets a list with all 1st level section names.
49 *
50 * @returns a list of section names stored in this ConfigMap.
51 */
52 getSectionNames(): string[];
53 /**
54 * Gets parameters from specific section stored in this ConfigMap.
55 * The section name is removed from parameter keys.
56 *
57 * @param section name of the section to retrieve configuration parameters from.
58 * @returns all configuration parameters that belong to the section named 'section'.
59 */
60 getSection(section: string): ConfigParams;
61 /**
62 * Adds parameters into this ConfigParams under specified section.
63 * Keys for the new parameters are appended with section dot prefix.
64 *
65 * @param section name of the section where add new parameters
66 * @param sectionParams new parameters to be added.
67 */
68 addSection(section: string, sectionParams: ConfigParams): void;
69 /**
70 * Overrides parameters with new values from specified ConfigParams
71 * and returns a new ConfigParams object.
72 *
73 * @param configParams ConfigMap with parameters to override the current values.
74 * @returns a new ConfigParams object.
75 *
76 * @see [[setDefaults]]
77 */
78 override(configParams: ConfigParams): ConfigParams;
79 /**
80 * Set default values from specified ConfigParams and returns a new ConfigParams object.
81 *
82 * @param defaultConfigParams ConfigMap with default parameter values.
83 * @returns a new ConfigParams object.
84 *
85 * @see [[override]]
86 */
87 setDefaults(defaultConfigParams: ConfigParams): ConfigParams;
88 /**
89 * Creates a new ConfigParams object filled with key-value pairs from specified object.
90 *
91 * @param value an object with key-value pairs used to initialize a new ConfigParams.
92 * @returns a new ConfigParams object.
93 */
94 static fromValue(value: any): ConfigParams;
95 /**
96 * Creates a new ConfigParams object filled with provided key-value pairs called tuples.
97 * Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs.
98 *
99 * @param tuples the tuples to fill a new ConfigParams object.
100 * @returns a new ConfigParams object.
101 *
102 * @see [[StringValueMap.fromTuplesArray]]
103 */
104 static fromTuples(...tuples: any[]): ConfigParams;
105 /**
106 * Creates a new ConfigParams object filled with key-value pairs serialized as a string.
107 *
108 * @param line a string with serialized key-value pairs as "key1=value1;key2=value2;..."
109 * Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"
110 * @returns a new ConfigParams object.
111 *
112 * @see [[StringValueMap.fromString]]
113 */
114 static fromString(line: string): ConfigParams;
115 /**
116 * Merges two or more ConfigParams into one. The following ConfigParams override
117 * previously defined parameters.
118 *
119 * @param configs a list of ConfigParams objects to be merged.
120 * @returns a new ConfigParams object.
121 *
122 * @see [[StringValueMap.fromMaps]]
123 */
124 static mergeConfigs(...configs: ConfigParams[]): ConfigParams;
125}