All files / mod/config config.d.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                           
declare namespace VersedConfig {
  /**
   * Define a config that is reading from environment variable
   */
  function env(name: string, defaultValue: ConfigValue): ConfigValueGetter;
  /**
   * Define a config that is reading from secret
   */
  function secret(name: string, defaultValue: ConfigValue): ConfigValueGetter;
  /**
   * Define a config that is reading from dynamic source (e.g. redis)
   * If the version increased, the defaultValue will update to the dynamic source
   */
  function dynamic(version: number, name: string, defaultValue: ConfigValue): ConfigValueGetter;
 
  /**
   * Set a delegate to handle dynamic config retrieval
   */
  function setDelegate(delegate: DynamicGetterDelegate): Promise<void>;
 
  // =====================================================================
  // Types below
 
  type ConfigValue = any;
 
  type ConfigValueGetter = {
    get(): ConfigValue;
  };
 
  // Delegate
  type DefinedDynamicMap = {
    [key: string]: DefinedDynamic;
  };
  type DefinedDynamic = {
    defaultValue: ConfigValue;
    version: number;
  };
  interface DynamicGetterDelegate {
    init(definedDynamic: DefinedDynamicMap): Promise<void>;
    onDefine(version: number, name: string, defaultValue: ConfigValue): void;
    get(name: string, defaultValue: ConfigValue): ConfigValue;
  }
}
 
export = VersedConfig;