@slimio/config
Advanced tools
Comparing version 0.12.0 to 0.13.0
@@ -1,2 +0,2 @@ | ||
## 0.11.0 (2018-11-29) | ||
## 0.13.0 (2019-01-31) | ||
@@ -15,5 +15,27 @@ * chore: accept v0.10.0 ([d42957c](https://github.com/SlimIO/Config/commit/d42957c)) | ||
* chore: update zen-observable to v0.8.11 ([ec5fb19](https://github.com/SlimIO/Config/commit/ec5fb19)) | ||
* chore(npmrc): add new bump rules ([aa78ebc](https://github.com/SlimIO/Config/commit/aa78ebc)) | ||
* chore(package): bump minor version to v0.11.0 ([d0e8026](https://github.com/SlimIO/Config/commit/d0e8026)) | ||
* chore(package): bump minor version to v0.12.0 ([4a4d4e4](https://github.com/SlimIO/Config/commit/4a4d4e4)) | ||
* chore(package): complete keywords ([60025a9](https://github.com/SlimIO/Config/commit/60025a9)) | ||
* chore(package): replace changelog by version ([1bb4e56](https://github.com/SlimIO/Config/commit/1bb4e56)) | ||
* chore(package): update @slimio/is to v1.4.0 ([d3905fe](https://github.com/SlimIO/Config/commit/d3905fe)) | ||
* chore(package): update ajv to v6.6.0 ([08bcdfa](https://github.com/SlimIO/Config/commit/08bcdfa)) | ||
* chore(package): update ajv to v6.6.2 ([b1e73d0](https://github.com/SlimIO/Config/commit/b1e73d0)) | ||
* chore(package): update ajv to v6.7.0 ([49ec00d](https://github.com/SlimIO/Config/commit/49ec00d)) | ||
* chore(package): update ava to v1.2.0 ([ae2e946](https://github.com/SlimIO/Config/commit/ae2e946)) | ||
* chore(package): update commitlint ([00f3b98](https://github.com/SlimIO/Config/commit/00f3b98)) | ||
* chore(package): update dependencies ([422ffa0](https://github.com/SlimIO/Config/commit/422ffa0)) | ||
* chore(package): update devDependencies ([1b37d36](https://github.com/SlimIO/Config/commit/1b37d36)) | ||
* chore(package): update devDependencies ([4caed5e](https://github.com/SlimIO/Config/commit/4caed5e)) | ||
* chore(package): update keywords ([41a67e7](https://github.com/SlimIO/Config/commit/41a67e7)) | ||
* chore(package): update node-watch to v0.5.9 ([a5edad0](https://github.com/SlimIO/Config/commit/a5edad0)) | ||
* chore(package): update node-watch to v0.6.0 ([208051f](https://github.com/SlimIO/Config/commit/208051f)) | ||
* chore(package): update zen-observable to v0.8.13 ([1cc1420](https://github.com/SlimIO/Config/commit/1cc1420)) | ||
* fix: add CHANGELOG.md to .npmignore ([55110d9](https://github.com/SlimIO/Config/commit/55110d9)) | ||
* fix: add exception for .circleci ([16cf922](https://github.com/SlimIO/Config/commit/16cf922)) | ||
* fix: add missing commitlint config ([0525866](https://github.com/SlimIO/Config/commit/0525866)) | ||
* fix: close cleanup interval when .close() is triggered ([6e7b74c](https://github.com/SlimIO/Config/commit/6e7b74c)) | ||
* fix: ignore docs/ directory ([996f112](https://github.com/SlimIO/Config/commit/996f112)) | ||
* fix: setup cleanup interval only when .read() is triggered ([1a12a41](https://github.com/SlimIO/Config/commit/1a12a41)) | ||
* fix: stop watcher callback is configuration is closed ([5228597](https://github.com/SlimIO/Config/commit/5228597)) | ||
* docs: add circleci badge ([bddc80c](https://github.com/SlimIO/Config/commit/bddc80c)) | ||
@@ -25,6 +47,13 @@ * docs: add close event ([058e291](https://github.com/SlimIO/Config/commit/058e291)) | ||
* docs: add static properties doc ([6f3a0d2](https://github.com/SlimIO/Config/commit/6f3a0d2)) | ||
* docs: API v2.0 ([6999657](https://github.com/SlimIO/Config/commit/6999657)) | ||
* docs: improve introduction ([3b3c1a8](https://github.com/SlimIO/Config/commit/3b3c1a8)) | ||
* docs: refactor introduction ([28fbee8](https://github.com/SlimIO/Config/commit/28fbee8)) | ||
* docs(readme): add Greenkeeper badge ([d2c104e](https://github.com/SlimIO/Config/commit/d2c104e)) | ||
* refactor: cleanup d.ts ([c8e712a](https://github.com/SlimIO/Config/commit/c8e712a)) | ||
* refactor: move cleanup in !config.hasBeenRead ([c8446c4](https://github.com/SlimIO/Config/commit/c8446c4)) | ||
* refactor: remove tsconfig ([993af2f](https://github.com/SlimIO/Config/commit/993af2f)) | ||
* refactor(package): replace prepublish by prepublishOnly ([7f38793](https://github.com/SlimIO/Config/commit/7f38793)) | ||
* test: add test for static property STRINGIFY_FACE ([531b414](https://github.com/SlimIO/Config/commit/531b414)) | ||
* test: updata ava to v1.0.0 & fix throws assertions ([9d16ac6](https://github.com/SlimIO/Config/commit/9d16ac6)) | ||
* feat: add CHANGELOG ([d2310b7](https://github.com/SlimIO/Config/commit/d2310b7)) | ||
* feat: add circleci config ([69955b5](https://github.com/SlimIO/Config/commit/69955b5)) | ||
@@ -36,8 +65,2 @@ * feat: add git hook to package.json ([6603ba2](https://github.com/SlimIO/Config/commit/6603ba2)) | ||
* feat: fires close event when .close() is triggered ([2caefc3](https://github.com/SlimIO/Config/commit/2caefc3)) | ||
* fix: add missing commitlint config ([0525866](https://github.com/SlimIO/Config/commit/0525866)) | ||
* fix: close cleanup interval when .close() is triggered ([6e7b74c](https://github.com/SlimIO/Config/commit/6e7b74c)) | ||
* fix: ignore docs/ directory ([996f112](https://github.com/SlimIO/Config/commit/996f112)) | ||
* fix: setup cleanup interval only when .read() is triggered ([1a12a41](https://github.com/SlimIO/Config/commit/1a12a41)) | ||
* fix: stop watcher callback is configuration is closed ([5228597](https://github.com/SlimIO/Config/commit/5228597)) | ||
* test: add test for static property STRINGIFY_FACE ([531b414](https://github.com/SlimIO/Config/commit/531b414)) | ||
* build: Update ajv dependencies ([c6bb2f0](https://github.com/SlimIO/Config/commit/c6bb2f0)) | ||
@@ -76,8 +99,8 @@ * build: update slimio/is dependencies to v1.2.0 ([f04ca79](https://github.com/SlimIO/Config/commit/f04ca79)) | ||
* Add test for new close throw ([f2aa3ac](https://github.com/SlimIO/Config/commit/f2aa3ac)) | ||
* Add tests to cover new constructor exceptions ([1aa76ad](https://github.com/SlimIO/Config/commit/1aa76ad)) | ||
* Add tests to cover new constructor exceptions ([2a652c0](https://github.com/SlimIO/Config/commit/2a652c0)) | ||
* Add tests to cover new constructor exceptions ([1aa76ad](https://github.com/SlimIO/Config/commit/1aa76ad)) | ||
* Add TypeScript definition ([59ec805](https://github.com/SlimIO/Config/commit/59ec805)) | ||
* Add watcherInitialized event ([7ad62d4](https://github.com/SlimIO/Config/commit/7ad62d4)) | ||
* Bump minor version ([5311687](https://github.com/SlimIO/Config/commit/5311687)) | ||
* Bump minor version ([7675a97](https://github.com/SlimIO/Config/commit/7675a97)) | ||
* Bump minor version ([5311687](https://github.com/SlimIO/Config/commit/5311687)) | ||
* Bump minor version according to branch name ([e04d825](https://github.com/SlimIO/Config/commit/e04d825)) | ||
@@ -123,8 +146,8 @@ * Bump minor version according to branch name ([38f70a3](https://github.com/SlimIO/Config/commit/38f70a3)) | ||
* Remove npm package-lock ([6318415](https://github.com/SlimIO/Config/commit/6318415)) | ||
* Remove useless try/catch ([caed79e](https://github.com/SlimIO/Config/commit/caed79e)) | ||
* Remove useless try/catch ([f38d0ee](https://github.com/SlimIO/Config/commit/f38d0ee)) | ||
* Remove useless try/catch ([caed79e](https://github.com/SlimIO/Config/commit/caed79e)) | ||
* Replace by the real export ([171ea85](https://github.com/SlimIO/Config/commit/171ea85)) | ||
* Replace configWrited by configWritten ([d0d6f3c](https://github.com/SlimIO/Config/commit/d0d6f3c)) | ||
* Replace is.Object by is.plainObject ([2d7f267](https://github.com/SlimIO/Config/commit/2d7f267)) | ||
* Replace is.Object by is.plainObject ([22d7e52](https://github.com/SlimIO/Config/commit/22d7e52)) | ||
* Replace is.Object by is.plainObject ([2d7f267](https://github.com/SlimIO/Config/commit/2d7f267)) | ||
* Return this when the method set() is triggered ([77c86de](https://github.com/SlimIO/Config/commit/77c86de)) | ||
@@ -149,4 +172,1 @@ * Rollback observableOf get value ([c0c1459](https://github.com/SlimIO/Config/commit/c0c1459)) | ||
* work on test and update eslint config ([47e78e2](https://github.com/SlimIO/Config/commit/47e78e2)) | ||
@@ -6,8 +6,5 @@ /// <reference types="@types/node" /> | ||
/** | ||
* Config class definition | ||
*/ | ||
declare class Config<T> extends events.EventEmitter { | ||
// Constructor | ||
constructor(configFilePath: string, options?: Config.ConstructorOptions); | ||
constructor(configFilePath: string, options?: Config.Options); | ||
@@ -41,9 +38,4 @@ // Properties | ||
/** | ||
* Config namespace | ||
*/ | ||
declare namespace Config { | ||
// Constructor interface | ||
interface ConstructorOptions { | ||
interface Options { | ||
createOnNoEntry?: boolean; | ||
@@ -55,3 +47,2 @@ writeOnSet?: boolean; | ||
} | ||
} | ||
@@ -58,0 +49,0 @@ |
{ | ||
"name": "@slimio/config", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "SlimIO Reactive JSON Config loaded", | ||
@@ -40,3 +40,8 @@ "main": "index.js", | ||
"JSON", | ||
"Loader" | ||
"Schema", | ||
"Safe", | ||
"Loader", | ||
"observable", | ||
"reactive", | ||
"hotreload" | ||
], | ||
@@ -50,4 +55,4 @@ "author": "SlimIO", | ||
"devDependencies": { | ||
"@commitlint/cli": "^7.2.1", | ||
"@commitlint/config-conventional": "^7.1.2", | ||
"@commitlint/cli": "^7.4.0", | ||
"@commitlint/config-conventional": "^7.3.1", | ||
"@escommunity/minami": "^1.0.0", | ||
@@ -58,8 +63,8 @@ "@slimio/eslint-config": "^2.0.3", | ||
"@types/lodash.set": "^4.3.4", | ||
"@types/node": "^10.12.18", | ||
"@types/node": "^10.12.20", | ||
"@types/zen-observable": "^0.8.0", | ||
"ava": "^1.0.1", | ||
"ava": "^1.2.0", | ||
"conventional-changelog-cli": "^2.0.11", | ||
"eslint": "^5.10.0", | ||
"husky": "^1.3.0", | ||
"eslint": "^5.12.1", | ||
"husky": "^1.3.1", | ||
"nyc": "^13.1.0", | ||
@@ -70,9 +75,9 @@ "pkg-ok": "^2.3.1" | ||
"@slimio/is": "^1.4.0", | ||
"ajv": "^6.6.2", | ||
"ajv": "^6.7.0", | ||
"lodash.clonedeep": "^4.5.0", | ||
"lodash.get": "^4.4.2", | ||
"lodash.set": "^4.3.2", | ||
"node-watch": "^0.5.9", | ||
"zen-observable": "^0.8.11" | ||
"node-watch": "^0.6.0", | ||
"zen-observable": "^0.8.13" | ||
} | ||
} |
# Config | ||
 | ||
[](https://github.com/SlimIO/Config/commit-activity) | ||
@@ -8,3 +9,3 @@ [](https://github.com/SlimIO/Config/blob/master/LICENSE) | ||
SlimIO - Reactive JSON Config loader | ||
SlimIO - Reactive JSON Configuration loader. This package is used in SlimIO core and addons to safely hot reload configuration upon [JSON Schema](https://json-schema.org/). | ||
@@ -64,3 +65,3 @@ ## Features | ||
## Events | ||
Configuration class is extended by a Node.js EventEmitter. The class can trigger several events: | ||
Configuration class is extended by a [Node.js EventEmitter](https://nodejs.org/api/events.html). The class can trigger several events: | ||
@@ -75,5 +76,8 @@ | event name | description | | ||
## API | ||
This section describe how works the methods of **Config** class. For a complete definition, take a look at `index.d.ts` ! | ||
### constructor< T >(configFilePath: string, options?: Config.ConstructorOptions) | ||
Create a new Configuration instance | ||
<details><summary>constructor< T > (configFilePath: string, options?: Config.Options)</summary> | ||
<br /> | ||
Create a new Config Object: | ||
```js | ||
@@ -98,3 +102,7 @@ const cfg = new Config("./path/to/file.json", { | ||
### read(defaultPayload?: T): Promise< this >; | ||
</details> | ||
<details><summary>read (defaultPayload?: T): Promise< this ></summary> | ||
<br /> | ||
Will trigger and read the local configuration (on disk). A default `payload` value can be provided in case the file doesn't exist ! | ||
@@ -115,15 +123,18 @@ | ||
<p align="center"> | ||
<img src="https://i.imgur.com/uMY4DZV.png" height="500"> | ||
</p> | ||
<p align="center"><img src="https://i.imgur.com/uMY4DZV.png" height="500"></p> | ||
### setupAutoReload(): void; | ||
</details> | ||
<details><summary>setupAutoReload (): void</summary> | ||
<br /> | ||
Setup hot reload (with a file watcher). This method is automatically triggered if the Configuration has been created with the option `autoReload` set to true. | ||
We use the package [node-watch](https://www.npmjs.com/package/node-watch) to achieve the hot reload. | ||
</details> | ||
### get< H >(fieldPath: string, depth?: number): H | ||
Get a value from a key (field path). | ||
<details><summary>get< H > (fieldPath: string, depth?: number): H</summary> | ||
<br /> | ||
For example, image a json file with a `foo` field. | ||
Get a value from a key (fieldPath). For example, let take a json payload with a root `foo` field. | ||
```js | ||
@@ -138,4 +149,7 @@ const cfg = new Config("./path/to/file.json"); | ||
If the retrieved value is a JavaScript object, you can limit the depth by setting `depth` option. | ||
</details> | ||
### set< H >(fieldPath: string, fieldValue: H): void; | ||
<details><summary>set< H > (fieldPath: string, fieldValue: H): void</summary> | ||
<br /> | ||
Set a given field in the configuration. | ||
@@ -155,3 +169,7 @@ | ||
### observableOf(fieldPath: string, depth?: number): ObservableLike; | ||
</details> | ||
<details><summary>observableOf (fieldPath: string, depth?: number): ObservableLike</summary> | ||
<br /> | ||
Observe a given configuration key with an Observable Like object! | ||
@@ -174,7 +192,13 @@ | ||
``` | ||
</details> | ||
### writeOnDisk(): Promise< void > | ||
<details><summary>writeOnDisk (): Promise< void ></summary> | ||
<br /> | ||
Write the configuration on the disk. | ||
</details> | ||
### lazyWriteOnDisk(): void | ||
<details><summary>lazyWriteOnDisk (): void</summary> | ||
<br /> | ||
Write the configuration on the disk (only at the next event-loop iteration). Use the event `configWritten` to known when the configuration will be written. | ||
@@ -193,12 +217,18 @@ | ||
### close(): Promise< void > | ||
</details> | ||
<details><summary>close (): Promise< void ></summary> | ||
<br /> | ||
Close (and write on disk) the configuration (it will close the watcher and complete/clean all active observers subscribers). | ||
</details> | ||
## Properties | ||
### Properties | ||
Following properties are **static** members of **Config** class. | ||
### STRINGIFY_SPACE | ||
<details><summary>STRINGIFY_SPACE</summary> | ||
The `STRINGIFY_SPACE` property allow you to redine the espace used internaly for `JSON.stringify` method. The default value is **4**. | ||
</details> | ||
### DEFAULT_SCHEMA | ||
<details><summary>DEFAULT_SCHEMA</summary> | ||
The `DEFAULT_SCHEMA` property allow you to redefine the default schema that should be applied if no schema is provided when constructor is triggered! | ||
@@ -213,1 +243,6 @@ | ||
``` | ||
</details> | ||
## Licence | ||
MIT | ||
49451
239
658
+ Addednode-watch@0.6.4(transitive)
- Removednode-watch@0.5.9(transitive)
Updatedajv@^6.7.0
Updatednode-watch@^0.6.0
Updatedzen-observable@^0.8.13