harperdb
Version:
HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.
75 lines (74 loc) • 2.67 kB
TypeScript
import { EventEmitter } from 'events';
export interface Config {
[key: string]: ConfigValue;
}
export type ConfigValue = undefined | null | string | number | boolean | Array<ConfigValue> | Config;
export type OptionsWatcherEventMap = {
ready: [config?: ConfigValue];
change: [key: string[], value: ConfigValue, config: ConfigValue];
remove: [];
error: [error: unknown];
close: [];
};
export declare class OptionsWatcherConfigFileError extends Error {
constructor(configFilePath: string, error: unknown);
}
export declare class UninitializedOptionsWatcherError extends Error {
constructor();
}
export declare class InvariantUninitializedOptionsWatcherError extends Error {
constructor();
}
export declare class InvalidValueTypeError extends Error {
constructor(keys: string[], value: unknown);
}
export declare class KeyDoesNotExistError extends Error {
constructor(keys: string[], key: string);
}
export declare class CannotSetPropertyError extends Error {
constructor(keys: string[]);
}
/**
* Watches a YAML configuration file for changes and provides methods to access the configuration.
*
* @emits ready - When the configuration file is initially loaded and values are available
* @emits change - When any value in the configuration changes (with key, new value, and full config)
* @emits remove - When the configuration file is removed or the extension is removed from the config
* @emits error - When an error occurs reading or parsing the file
* @emits close - When the watcher is closed
*/
export declare class OptionsWatcher extends EventEmitter<OptionsWatcherEventMap> {
#private;
ready: Promise<any[]>;
constructor(name: string, filePath: string, logger?: any);
/**
* Closes the underlying file watcher, emits the `close` event, and removes any listeners on the OptionsWatcher instance
*/
close(): this;
/**
* Get a value from the configuration using an array of strings representing the key.
*
* For example, if the configuration is:
* ```yaml
* foo:
* bar:
* baz: 42
* ```
* Then `get(['foo','bar','baz'])` will return `42`.
*
* If the key does not exist, `undefined` will be returned.
* @param key an array of strings representing the key.
* @returns
*/
get(key: string[]): ConfigValue | undefined;
/**
* Get the entire configuration object.
*
* @returns A deep clone of the entire configuration object.
*/
getAll(): ConfigValue | undefined;
/**
* Get the entire root configuration object from the config file.
*/
getRoot(): Config | undefined;
}