Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Forest

Use either global or instance pattern.

Global Pattern

For using global, init must be called, otherwise will return undefined error when calling other methods.

Example

const Forest = require('forest')
Forest.init(token, host)

const data = Forest.getKeyValue('some-conf')

Instance Pattern

Example

const Forest = require('forest')
const forestInstance = Forest.createInstance(token, host)

const data = forestInstance.getKeyValue('some-conf')

Hierarchy

  • Forest

Index

Constructors

constructor

Methods

getBool

  • getBool(key: string): boolean
  • get value from the key on stored object. No cast is done. Returns false if no value is found.

    Parameters

    • key: string

    Returns boolean

getValue

  • getValue(key: string): any
  • get value from the key on stored object. No cast is done. Returns undefined if no value is found.

    Parameters

    • key: string

    Returns any

isExist

  • isExist(key: string): boolean
  • check if value exist from the key on stored object. Returns false if no value is found.

    Parameters

    • key: string

    Returns boolean

parseBool

  • parseBool(key: string): boolean
  • get value from the key on stored object. value is considered true if truthy, and false if falsey Returns false if no value is found.

    Parameters

    • key: string

    Returns boolean

Static createInstance

  • initializes a forest instance. please note that if config is not given, the default kv engine is 'kv'

    Parameters

    • token: string
    • host: string = ...
    • Optional config: ForestConfig

    Returns ForestInstance

Static getArray

  • getArray(key: string): any[]
  • get value from the key on stored object. Result value is considered array. No cast is done. Returns empty array if no value is found.

    Parameters

    • key: string

    Returns any[]

Static getAsClass

  • getAsClass<T>(_class: T): T
  • get value from the key on stored object. Result value is considered the given class. No cast is done. Returned value is undefined if no value is found getAsClass does not create instance. It just maps the value for typing support

    Type parameters

    • T

    Parameters

    • _class: T

    Returns T

Static getKeyValue

  • getKeyValue<T>(key: string): Promise<T>
  • gets the resource from a kv engine

    Type parameters

    • T = any

    Parameters

    • key: string

    Returns Promise<T>

Static getNumber

  • getNumber(key: string): number
  • get value from the key on stored object. Result value is considered number. No cast is done. Returns 0 if no value is found.

    Parameters

    • key: string

    Returns number

Static getNumberArray

  • getNumberArray(key: string): number[]
  • get value from the key on stored object. Result value is considered number array. No cast is done. Returns empty array if no value is found.

    Parameters

    • key: string

    Returns number[]

Static getString

  • getString(key: string): string
  • get value from the key on stored object. Result value is considered string. No cast is done. Returns empty string if no value is found.

    Parameters

    • key: string

    Returns string

Static getStringArray

  • getStringArray(key: string): string[]
  • get value from the key on stored object. Result value is considered string array. No cast is done. Returns empty array if no value is found.

    Parameters

    • key: string

    Returns string[]

Static init

  • init(token: string, host?: string, config?: ForestConfig): void
  • initializes global forest instance. please note that if config is not given, the default kv engine is 'kv'

    Parameters

    • token: string
    • host: string = ...
    • Optional config: ForestConfig

    Returns void

Static manageKeyValue

  • manageKeyValue(key: string): Promise<void>
  • Fetch key value from vault, stores the object in memory, and primes it for getString, getNumber, etc methods

    Parameters

    • key: string

    Returns Promise<void>

Static parseNumber

  • parseNumber(key: string): number
  • get value from the key on stored object and attempt to parse it. Returns 0 if no value is found or cannot be parsed.

    Parameters

    • key: string

    Returns number

Static parseString

  • parseString(key: string): string
  • get value from the key on stored object and attempt to parse it. Returns empty string if no value is found.

    Parameters

    • key: string

    Returns string

Generated using TypeDoc