@altostra/core
Version:
Core library for shared types and logic
88 lines (87 loc) • 3.12 kB
TypeScript
import type { Configuration, ConfigurationKey, ConfigurationValue, SettingsType } from "./Common";
import type { WrapperFactorParams } from "./Privates";
import type { SettingsManager } from "./SettingsManager";
/**
* A class that provides configuration settings
*/
export declare class Settings<T extends object> {
/**
* Gets the settings manager associated with this Settings instance
*/
readonly manager: SettingsManager<T>;
/**
* Gets the path the setting are stored in
*/
readonly path?: string | undefined;
/**
* Gets an object contains the current settings
*/
readonly settings: Configuration<T>;
/**
* Gets the settings type
*/
readonly type: SettingsType;
private readonly _isOverride;
private readonly _deleteKey;
private readonly _settingsData;
private readonly _internalSettings;
private readonly _keys;
private readonly _getNamespace;
private readonly _refreshSettings;
/**
* Returns a value that indicated the origin of value in the provided key
* @param key The key to check
* @returns One of the following values:
* 'default' if setting is not stored in global config nor in project config
* 'global' if setting is stored in global config but not in project config
* 'project' if setting is stored in project config and not overridden by the global config
* 'global-override' is setting is stored in global config with override settings
*/
readonly getSettingType: (key: ConfigurationKey<T>) => SettingsType;
/**
* Internal usage.
* Use SettingsManager to create Settings instance
*/
constructor(
/**
* Gets the settings manager associated with this Settings instance
*/
manager: SettingsManager<T>, wrapperParams: WrapperFactorParams<T>,
/**
* Gets the path the setting are stored in
*/
path?: string | undefined);
/**
* Gets or sets the current active configuration (namespace)
*/
get activeConfig(): string;
set activeConfig(configNamespace: string);
/**
* Gets the value stored in the specified key
* @param key The settings key to get value for
* @returns The value that is set for the provided key
*/
get<TKey extends ConfigurationKey<T>>(key: TKey): ConfigurationValue<T, TKey>;
/**
* Sets a value for the specified key
* @param key The settings key to get value in
* @param value The value to set
* @param setOverrideTo Optional value that indicated if the key should override project settings
*/
set<TKey extends ConfigurationKey<T>>(key: TKey, value: ConfigurationValue<T, TKey>, setOverrideTo?: boolean): ConfigurationValue<T, TKey>;
isOverride(namespace: string, key: ConfigurationKey<T>): boolean;
getSettingConfiguration(key: ConfigurationKey<T>): string;
/**
* Deletes a setting key from the current configuration
* @param key The key to delete
*/
delete(key: keyof T): void;
/**
* Saves the configuration to its store
*/
save(): Promise<void>;
/**
* Reloads configuration from its store
*/
refresh(): Promise<void>;
}