Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JsonConfigReader

Config reader that reads configuration from JSON file.

The reader supports parameterization using Handlebar template engine.

Configuration parameters

  • path: path to configuration file
  • parameters: this entire section is used as template parameters
  • ...
see

IConfigReader

see

FileConfigReader

Example

======== config.json ======
{ "key1": "{{KEY1_VALUE}}", "key2": "{{KEY2_VALUE}}" }
===========================

let configReader = new JsonConfigReader("config.json");

let parameters = ConfigParams.fromTuples("KEY1_VALUE", 123, "KEY2_VALUE", "ABC");
configReader.readConfig("123", parameters, (err, config) => {
    // Result: key1=123;key2=ABC
});

Hierarchy

Implements

  • any

Index

Constructors

constructor

  • Creates a new instance of the config reader.

    Parameters

    • Default value path: string = null

      (optional) a path to configuration file.

    Returns JsonConfigReader

Methods

addChangeListener

  • addChangeListener(listener: INotifiable): void
  • Adds a listener that will be notified when configuration is changed

    Parameters

    • listener: INotifiable

      a listener to be added.

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

getPath

  • getPath(): string
  • Get the path to configuration file..

    Returns string

    the path to configuration file.

Protected parameterize

  • parameterize(config: string, parameters: ConfigParams): string
  • Parameterized configuration template given as string with dynamic parameters.

    The method uses Handlebars template engine.

    Parameters

    • config: string

      a string with configuration template to be parameterized

    • parameters: ConfigParams

      dynamic parameters to inject into the template

    Returns string

    a parameterized configuration string.

readConfig

  • readConfig(correlationId: string, parameters: ConfigParams, callback: function): void
  • Reads configuration and parameterize it with given values.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • parameters: ConfigParams

      values to parameters the configuration

    • callback: function

      callback function that receives configuration or error.

        • (err: any, config: ConfigParams): void
        • Parameters

          • err: any
          • config: ConfigParams

          Returns void

    Returns void

readObject

  • readObject(correlationId: string, parameters: ConfigParams): any
  • Reads configuration file, parameterizes its content and converts it into JSON object.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • parameters: ConfigParams

      values to parameters the configuration.

    Returns any

    a JSON object with configuration.

removeChangeListener

  • removeChangeListener(listener: INotifiable): void
  • Remove a previously added change listener.

    Parameters

    • listener: INotifiable

      a listener to be removed.

    Returns void

setPath

  • setPath(path: string): void
  • Set the path to configuration file.

    Parameters

    • path: string

      a new path to configuration file.

    Returns void

Static readConfig

  • readConfig(correlationId: string, path: string, parameters: ConfigParams): ConfigParams
  • Reads configuration from a file, parameterize it with given values and returns a new ConfigParams object.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • path: string
    • parameters: ConfigParams

      values to parameters the configuration.

    Returns ConfigParams

Static readObject

  • readObject(correlationId: string, path: string, parameters: ConfigParams): any
  • Reads configuration file, parameterizes its content and converts it into JSON object.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • path: string
    • parameters: ConfigParams

      values to parameters the configuration.

    Returns any

    a JSON object with configuration.

Generated using TypeDoc