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.
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(...);
...return settings.getGlobalData('someKey', 'default value')
.then(globalValue => ...);return settings.getUserData('someOtherKey', 'default value')
.then(userValue => ...);return settings.setGlobalData('someKey', 'some value')
.then(globalValue => ...);return settings.setUserData('someOtherKey', 'some value')
.then(userValue => ...);return settings.updateGlobalData('someKey', 'some value')
.then(globalValue => ...);return settings.updateUserData('someKey', 'some value')
.then(userValue => ...);