@fvlab/configurationstore v1.0.6
configurationStore
Simple interface for storing settings or document storage using your whatever backend you want to implement. Global configurations will be stored under /internal/global/ and user-specific configurations will be stored under /internal/user/<userId>. The paths can be configured by passing optional arguments to the constructor.
There is a MockConfigurationStore class to use as placeholder until you get the intended configuration store setup. It stores configuration in memory.
Implementing a configuration store
Implement the IConfigurationStore or extend the BaseConfigurationStore class. Implement at least the following:
setData<T>(settingsPath: string, value: T): Promise<T>Overwrites the endpoint in the database. If path does not exist it should be created.
updateData<T>(settingsPath: string, value: T): Promise<T>Adds the value to the endpoint without overwriting existing data. If path does not exist it should be created
getData<T>(settingsPath: string, defaultValue?: T): Promise<T>Gets the value of the specified endpoint. If endpoint does not exist, it should be created with the
defaultValue
class YourConfigurationStore extends BaseConfigurationStore {
...
}
const settings = new YourConfigurationStore(...);
...Retrieve values by key or get it's default value if a value doesn't exist for the key.
return settings.getGlobalData('someKey', 'default value')
.then(globalValue => ...);return settings.getUserData('someOtherKey', 'default value')
.then(userValue => ...);Set the key-value pair, overwriting the endpoint.
return settings.setGlobalData('someKey', 'some value')
.then(globalValue => ...);return settings.setUserData('someOtherKey', 'some value')
.then(userValue => ...);Update the endpoint with some value, without overwriting existing data
return settings.updateGlobalData('someKey', 'some value')
.then(globalValue => ...);return settings.updateUserData('someKey', 'some value')
.then(userValue => ...);