{"_id":"refreshing-config","_rev":"86-82ba66411ef004be469daa05daefc2c3","name":"refreshing-config","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"refreshing-config","version":"0.1.0","keywords":["config","dynamic","refresh","subscribe","publish"],"author":{"name":"William Bartholomew","email":"willbar@microsoft.com"},"license":"MIT","_id":"refreshing-config@0.1.0","maintainers":[{"name":"microsoft","email":"npmjs@microsoft.com"}],"dist":{"shasum":"9b4a9b061e2f51d27b7e55fefbc6f433e06bd41e","tarball":"https://registry.npmjs.org/refreshing-config/-/refreshing-config-0.1.0.tgz","integrity":"sha512-ghnaKQDCPMw/27g3jdsfkx657BWzFh7i1x2ukDN2NU9ROzVKGkZg54HO7E5V5Clv+suT/FQFwqX9zeDK9FakeA==","signatures":[{"sig":"MEUCIQD8N6HjNkbO3wYdREIm/fWxjXNqXnCUiDsyunNIo4N78gIgdVBd7mQhPIMbka/bPUjhl9XAJC/6MPqwU+Wnr6GN1+k=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"9b4a9b061e2f51d27b7e55fefbc6f433e06bd41e","gitHead":"f9096db3f910d2ddd736382814f0d8bf6190b400","scripts":{"lint":"eslint . --ignore-path .gitignore","test":"mocha","coverage":"istanbul cover _mocha && opener coverage/lcov-report/index.html","prepublish":"npm test && npm run lint"},"_npmUser":{"name":"microsoft","email":"npmjs@microsoft.com"},"deprecated":"This package has been renamed to @microsoft/refreshing-config","_npmVersion":"3.10.8","description":"Configuration library that can dynamically refresh configuration values.","directories":{},"_nodeVersion":"6.9.1","dependencies":{"q":"1.4.1","debug":"2.4.5","moment":"2.17.1","fast-json-patch":"1.1.3"},"devDependencies":{"chai":"3.5.0","clone":"2.1.0","mocha":"3.2.0","sinon":"1.17.6","eslint":"3.12.2","opener":"1.4.2","istanbul":"0.4.5"},"_npmOperationalInternal":{"tmp":"tmp/refreshing-config-0.1.0.tgz_1483128794895_0.8466297800187021","host":"packages-12-west.internal.npmjs.com"}},"0.1.2":{"name":"refreshing-config","version":"0.1.2","keywords":["config","dynamic","refresh","subscribe","publish"],"author":{"name":"William Bartholomew","email":"willbar@microsoft.com"},"license":"MIT","_id":"refreshing-config@0.1.2","maintainers":[{"name":"microsoft","email":"npmjs@microsoft.com"}],"dist":{"shasum":"7ad06c9724fb6206c09c9e6f0abf2f0a413a822e","tarball":"https://registry.npmjs.org/refreshing-config/-/refreshing-config-0.1.2.tgz","integrity":"sha512-KoiVTdZeNq5PGab9Xmgb246zkIU8Xc6Ui7uFjchbHf5NTJB1K+AWLzof+Rm85F2HybUJurLJSJq/xgdwJvJzmQ==","signatures":[{"sig":"MEUCIQCx/+gvbh27nw4yAd4PQXwZUU90/6/kA5K5EvrAbmgXNAIgHYuv4Ghwh4lIpmFB5HLaiZvrFuo+p4eDa/2clTNXAmU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"7ad06c9724fb6206c09c9e6f0abf2f0a413a822e","gitHead":"55a1a6fa40dc82fb4320ad28cce5b263b04b8b46","scripts":{"lint":"eslint . --ignore-path .gitignore","test":"mocha","coverage":"istanbul cover _mocha && opener coverage/lcov-report/index.html","prepublish":"npm test && npm run lint"},"_npmUser":{"name":"microsoft","email":"npmjs@microsoft.com"},"deprecated":"This package has been renamed to @microsoft/refreshing-config","_npmVersion":"3.10.8","description":"Configuration library that can dynamically refresh configuration values.","directories":{},"_nodeVersion":"6.9.1","dependencies":{"q":"1.4.1","debug":"2.4.5","extend":"^3.0.0","moment":"2.17.1","fast-json-patch":"1.1.3"},"devDependencies":{"chai":"3.5.0","clone":"2.1.0","mocha":"3.2.0","sinon":"1.17.6","eslint":"3.12.2","opener":"1.4.2","istanbul":"0.4.5"},"_npmOperationalInternal":{"tmp":"tmp/refreshing-config-0.1.2.tgz_1487718723114_0.2540668200235814","host":"packages-18-east.internal.npmjs.com"}}},"time":{"created":"2016-12-30T20:13:15.154Z","modified":"2026-07-16T15:48:56.050Z","0.1.0":"2016-12-30T20:13:15.154Z","0.1.2":"2017-02-21T23:12:03.837Z"},"author":{"name":"William Bartholomew","email":"willbar@microsoft.com"},"license":"MIT","keywords":["config","dynamic","refresh","subscribe","publish"],"description":"Configuration library that can dynamically refresh configuration values.","maintainers":[{"email":"npmjs@microsoft.com","name":"microsoft1es"},{"email":"microsoft-oss-publishing@microsoft.com","name":"microsoft-oss-releases"},{"email":"ghazan@microsoft.com","name":"ghazan"}],"readme":"![Version](https://img.shields.io/npm/v/refreshing-config.svg)\n![License](https://img.shields.io/github/license/Microsoft/refreshing-config.svg)\n![Downloads](https://img.shields.io/npm/dt/refreshing-config.svg)\n\n# refreshing-config\nConfiguration library that can dynamically refresh configuration values.\n\n# Usage\n1. Construct your configuration store\n2. Instantiate an instance of ```RefreshingConfig``` passing your store to the constructor\n3. Optionally, instantiate your refresh policies and/or change notifiers and add them by calling ```withExtension(extension: object)```\n4. Call ```get(name: string)``` or ```getAll()``` to retrieve configuration values\n5. Call ```set(name: string, value: any)``` or ```delete(name: string)``` to manipulate configuration values\n\nIt is important to note that the configuration values are manipulated in place when they are refreshed so if you have an instance of an object returned from ```get``` or ```getAll``` it may be modified\nwhenever a refresh occurs (this is intentional), if you don't want the values to change you should clone the object and use the clone.\n\n# Stores\nrefreshing-config requires a store that will store the configuration values. We provide a Redis-backed store in https://npmjs.org/package/refreshing-config-redis but you can implement your own store for\nyour configuration backend.\n\n### Writing a store\nStores must implement ```getAll(): IPromise<object>``` and can optionally implement ```set(name: string, value: any): IPromise<any>``` and ```delete(name: string): IPromise<void>```. The ```getAll()```\nfunction should return an object whose keys are the names of the configuration values and the value is the configuration value itself. Stores should support the full set of JavaScript data types.\n\n# Events\nThe following events are emitted from ```RefreshingConfig```:\n* ```set(name, value)```: Emitted when a configuration value has been set in the underlying store where ```name```\nis the name of the configuration value and ```value``` is the new value.\n* ```delete(name)```: Emitted when a configuration value has been deleted where ```name``` is the name\nof the configuration value that was deleted.\n* ```changed(config, patch)```: Emitted when a change is detected in the configuration values after a refresh where\n```config``` is the updated configuration (including unchanged values) and ```patch``` is a JSON patch describing\nthe changes that were detected.\n* ```refresh(config)```: Emitted whenever the configuration is refreshed from the store where ```config```\nis the configuration after the refresh.\n\nThe object returned from ```getAll()``` also has the ```RefreshingConfig``` instance itself in the ```_config``` property. This is\nuseful if you want to pass the configuration object around your application and allowing it to subscribe to updates or otherwise\nmanage the configuration.\n\n# Extensions\nYou can extend refreshing-config's behavior by attaching extensions using ```withExtension```:\n\n```javascript\nconst config = new RefreshingConfig.RefreshingConfig(store)\n  .withExtension(myExtension1)\n  .withExtension(myExtension2);\n```\n\n## Refresh policies\nRefresh policies define when refreshing-config should go back to the store to get updated configuration values. Refresh policies can either be reactive (refreshing-config asks them if it should go back to the store)\nor proactive (they notify refreshing-config that it needs to refresh). If there are multiple refresh policies attached then refreshing-config will go back to the store if **any** of them say a refresh is required.\n\nRefresh policies are bypassed in the following scenarios:\n\n* The read of the first configuration value (to get the initial set of configuration values)\n* After a set or delete (because we know the configuration values are stale)\n\nIf you do not have a refresh policy in place you can explicitly call ```refresh()``` to force a refresh.\n\n### NeverRefreshPolicy (reactive)\nThis is the default policy and will only go to the store when the first setting is read or when we know the values have changed (for example, if ```set``` or ```delete``` is called).\n\n```javascript\nconst config = new RefreshingConfig.RefreshingConfig(store)\n  .withExtension(new RefreshingConfig.RefreshPolicy.NeverRefreshPolicy());\n```\n\n### AlwaysRefreshPolicy (reactive)\nThis policy will go back to the store everytime a configuration value is read.\n\n```javascript\nconst config = new RefreshingConfig.RefreshingConfig(store)\n  .withExtension(new RefreshingConfig.RefreshPolicy.AlwaysRefreshPolicy());\n```\n\n### StaleRefreshPolicy (reactive)\nThis policy will go back to the store if it hasn't been back to the store for the specified number of milliseconds. In this example the store will be accessed at most every 30 seconds:\n\n```javascript\nconst config = new RefreshingConfig.RefreshingConfig(store)\n  .withExtension(new RefreshingConfig.RefreshPolicy.StaleRefreshPolicy(30000));\n```\n\n### IntervalRefreshPolicy (proactive)\nThis policy will proactively refresh the configuration values from the store at the defined interval. In this example the configuration values will be refreshed every 30 seconds.\n\n```javascript\nconst config = new RefreshingConfig.RefreshingConfig(store)\n  .withExtension(new RefreshingConfig.RefreshPolicy.IntervalRefreshPolicy(30000));\n```\n\n### Writing a refresh policy\nA refresh policy must implement either ```shouldRefresh(): boolean``` (for reactive refresh policies) or ```subscribe(subscriber: RefreshingConfig)``` (for proactive refresh policies). Proactive refresh\npolicies should call ```subscriber.refresh()``` whenever they want the configuration values refreshed from the store.\n\n## Change notifiers\nChange notifiers are notified when refreshing-config has modified a configuration value (for example, when ```set``` or ```delete``` is called). This can be used to notify others about the need to refresh config.\nNote that these are not called when configuration values are changed externally in the store, if you want to know about those you should subscribe to the ```changed``` event on ```RefreshingConfig```.\n\nChange notifiers are generally paired with a refresh policy, in this pattern the change notifier is told about the change and communicates it to interested consumers, these consumers consume the notification\nin their refresh policy which then tells the configuration library to retrieve the new values from the store.\n\nThere are no out of the box change notifiers but see https://github.com/Microsoft/refreshing-config-redis to see an example refresh policy/change notifier that use Redis pub/sub to refresh configuration\nvalues automatically when they change.\n\n### Writing a change notifier\nA change notifier must implement the ```publish(operation: string, name: string, value: string)``` method which will be called whenever a ```set``` or ```delete``` is performed. The operation will either\nbe ```set``` or ```delete```, the ```name``` will be the name of the configuration value impacted, and the ```value``` will be the new value (for ```set``` operations).\n\n# Contributing\nPull requests will gladly be considered!\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see\nthe [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com)\nwith any additional questions or comments.","readmeFilename":"README.md"}