@greengreystudio/server-package-settings-manager
v2.1.1
Published
### Installation ``` bash npm install @greengreystudio/server-package-settings-manager ```
Downloads
8
Keywords
Readme
server-package-settings-manager
Installation
npm install @greengreystudio/server-package-settings-manager
Configuration
import { SettingsManager } from '@greengreystudio/server-package-settings-manager';
//... code
const settingsManager = new SettingsManager({
cdnUrl: 'http://cdn.example.com', // required!
version: 'default', // required! version of content
consumer: 'common', // required! default consumer of content
compression: 'json', // required! content compression: gzip or default
expireMs: 60000 // optional. default 60000. interval of reloading manifests
});
// Execute this on start app
// loading manifests and setting update intervals
await settingsManager.init();
fetchSetting
settingsManager.fetchSetting<TypeOfSetting>(name: string, options: {
consumer?: string;
compression?: string;
filter?: Partial<TypeOfSetting>;
find?: Partial<TypeOfSetting>;
})
getSetting
settingsManager.getSetting<TypeOfSetting>(name: string, options: {
consumer?: string;
compression?: string;
filter?: Partial<TypeOfSetting>;
find?: Partial<TypeOfSetting>;
})
Test mocks
import { SettingsManagerMock } from '@greengreystudio/server-package-settings-manager';
// create mock with stubs
const settingsManagerMock = new SettingsManagerMock({
dataStubs: {
items: [
{
id: 0,
name: 'item1'
},
{
id: 1,
name: 'item2'
}
]
}
});
// replace stub
settingsManagerMock.getMockedSettings().replaceSetting({
'items',
{
'0.name': 'newItemName'
}
})
const data = settingsManagerMock.getMockedSettings().fetchSetting('items', { filter: { id: 0 } })
// data:
// {
// id: 0,
// name: 'newItemName'
// }
// reset replaced settings:
settingsManagerMock.getMockedSettings().restoreSetting('items');
// reset all replaced settings:
settingsManagerMock.getMockedSettings().restoreAllSettings();