UNPKG

2.44 kBTypeScriptView Raw
1import { ConfigParams } from 'pip-services3-commons-node';
2import { IReconfigurable } from 'pip-services3-commons-node';
3import { INotifiable } from 'pip-services3-commons-node';
4import { IConfigReader } from './IConfigReader';
5/**
6 * Config reader that stores configuration in memory.
7 *
8 * The reader supports parameterization using Handlebars
9 * template engine: [[https://handlebarsjs.com]]
10 *
11 * ### Configuration parameters ###
12 *
13 * The configuration parameters are the configuration template
14 *
15 * @see [[IConfigReader]]
16 *
17 * ### Example ####
18 *
19 * let config = ConfigParams.fromTuples(
20 * "connection.host", "{{SERVICE_HOST}}",
21 * "connection.port", "{{SERVICE_PORT}}{{^SERVICE_PORT}}8080{{/SERVICE_PORT}}"
22 * );
23 *
24 * let configReader = new MemoryConfigReader();
25 * configReader.configure(config);
26 *
27 * let parameters = ConfigParams.fromValue(process.env);
28 *
29 * configReader.readConfig("123", parameters, (err, config) => {
30 * // Possible result: connection.host=10.1.1.100;connection.port=8080
31 * });
32 *
33 */
34export declare class MemoryConfigReader implements IConfigReader, IReconfigurable {
35 protected _config: ConfigParams;
36 /**
37 * Creates a new instance of config reader.
38 *
39 * @param config (optional) component configuration parameters
40 */
41 constructor(config?: ConfigParams);
42 /**
43 * Configures component by passing configuration parameters.
44 *
45 * @param config configuration parameters to be set.
46 */
47 configure(config: ConfigParams): void;
48 /**
49 * Reads configuration and parameterize it with given values.
50 *
51 * @param correlationId (optional) transaction id to trace execution through call chain.
52 * @param parameters values to parameters the configuration or null to skip parameterization.
53 * @param callback callback function that receives configuration or error.
54 */
55 readConfig(correlationId: string, parameters: ConfigParams, callback: (err: any, config: ConfigParams) => void): void;
56 /**
57 * Adds a listener that will be notified when configuration is changed
58 * @param listener a listener to be added.
59 */
60 addChangeListener(listener: INotifiable): void;
61 /**
62 * Remove a previously added change listener.
63 * @param listener a listener to be removed.
64 */
65 removeChangeListener(listener: INotifiable): void;
66}