@slimio/config
Advanced tools
Comparing version 0.13.0 to 0.14.1
@@ -0,2 +1,4 @@ | ||
"use strict"; | ||
const Config = require("./src/config.class"); | ||
module.exports = Config; |
{ | ||
"name": "@slimio/config", | ||
"version": "0.13.0", | ||
"version": "0.14.1", | ||
"description": "SlimIO Reactive JSON Config loaded", | ||
@@ -8,5 +8,5 @@ "main": "index.js", | ||
"prepublishOnly": "pkg-ok", | ||
"test": "ava --verbose", | ||
"doc": "jsdoc -c ./jsdoc.json -r", | ||
"coverage": "nyc ava", | ||
"test": "cross-env psp && ava --verbose", | ||
"doc": "jsdoc -c ./jsdoc.json -r -R ./README.md -P ./package.json --verbose", | ||
"coverage": "nyc npm test", | ||
"version": "conventional-changelog -i CHANGELOG.md -s", | ||
@@ -21,3 +21,3 @@ "report": "nyc report --reporter=html" | ||
"npm": ">=6.0.0", | ||
"node": ">=10.1.0" | ||
"node": ">=10" | ||
}, | ||
@@ -34,3 +34,3 @@ "nyc": { | ||
"hooks": { | ||
"pre-push": "npm test", | ||
"pre-push": "cross-env eslint index.js src/**.js && npm test", | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
@@ -50,2 +50,7 @@ } | ||
], | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"src" | ||
], | ||
"author": "SlimIO", | ||
@@ -58,27 +63,29 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@commitlint/cli": "^7.4.0", | ||
"@commitlint/config-conventional": "^7.3.1", | ||
"@commitlint/cli": "^8.1.0", | ||
"@commitlint/config-conventional": "^8.1.0", | ||
"@escommunity/minami": "^1.0.0", | ||
"@slimio/eslint-config": "^2.0.3", | ||
"@types/lodash.clonedeep": "^4.5.4", | ||
"@types/lodash.get": "^4.4.4", | ||
"@types/lodash.set": "^4.3.4", | ||
"@types/node": "^10.12.20", | ||
"@slimio/eslint-config": "^3.0.3", | ||
"@slimio/psp": "^0.6.0", | ||
"@types/lodash.clonedeep": "^4.5.6", | ||
"@types/lodash.get": "^4.4.6", | ||
"@types/lodash.set": "^4.3.6", | ||
"@types/zen-observable": "^0.8.0", | ||
"ava": "^1.2.0", | ||
"conventional-changelog-cli": "^2.0.11", | ||
"eslint": "^5.12.1", | ||
"husky": "^1.3.1", | ||
"nyc": "^13.1.0", | ||
"ava": "^2.3.0", | ||
"conventional-changelog-cli": "^2.0.23", | ||
"cross-env": "^5.2.0", | ||
"eslint": "^6.2.1", | ||
"husky": "^3.0.4", | ||
"jsdoc": "^3.6.3", | ||
"nyc": "^14.1.1", | ||
"pkg-ok": "^2.3.1" | ||
}, | ||
"dependencies": { | ||
"@slimio/is": "^1.4.0", | ||
"ajv": "^6.7.0", | ||
"@slimio/is": "^1.5.1", | ||
"ajv": "^6.10.2", | ||
"lodash.clonedeep": "^4.5.0", | ||
"lodash.get": "^4.4.2", | ||
"lodash.set": "^4.3.2", | ||
"node-watch": "^0.6.0", | ||
"zen-observable": "^0.8.13" | ||
"node-watch": "^0.6.3", | ||
"zen-observable": "^0.8.14" | ||
} | ||
} |
# Config | ||
 | ||
 | ||
[](https://github.com/SlimIO/Config/commit-activity) | ||
[](https://github.com/SlimIO/Config/blob/master/LICENSE) | ||
 | ||
[](https://snyk.io/test/github/SlimIO/Config?targetFile=package.json) | ||
[](https://circleci.com/gh/SlimIO/Config/tree/master) [](https://greenkeeper.io/) | ||
[](https://travis-ci.com/SlimIO/Config) | ||
[](https://greenkeeper.io/) | ||
@@ -17,2 +19,5 @@ 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/). | ||
## Requirements | ||
Node.js version 10 and upper are required to run this project. **We do not provide support** for previous versions. | ||
## Getting Started | ||
@@ -222,2 +227,4 @@ | ||
<details><summary>STRINGIFY_SPACE</summary> | ||
<br /> | ||
The `STRINGIFY_SPACE` property allow you to redine the espace used internaly for `JSON.stringify` method. The default value is **4**. | ||
@@ -227,2 +234,4 @@ </details> | ||
<details><summary>DEFAULT_SCHEMA</summary> | ||
<br /> | ||
The `DEFAULT_SCHEMA` property allow you to redefine the default schema that should be applied if no schema is provided when constructor is triggered! | ||
@@ -239,4 +248,20 @@ | ||
## Licence | ||
## Dependencies | ||
This project is covered by the SlimIO security policy and undergoes regular security audits. | ||
| Name | Refactoring | Security Risk | Usage | | ||
| --- | --- | --- | --- | | ||
| [ajv](https://github.com/epoberezkin/ajv) | ⚠️ Major | Medium | Validate JSON schema. | | ||
| [@slimio/is](https://github.com/SlimIO/is#readme) | Minor | Low | Type checker | | ||
| [lodash.clonedeep](https://lodash.com/) | Minor | Low | Clone deep Objects | | ||
| [lodash.get](https://lodash.com/) | Minor | Low | Get a value | | ||
| [lodash.set](https://lodash.com/) | Minor | Low | Set a value | | ||
| [node-watch](https://github.com/yuanchuan/node-watch#readme) | Minor | Medium | Watch files update on the system | | ||
| [zen-observable](https://github.com/zenparsing/zen-observable) | Minor | Low | Observable Implementation | | ||
## Contributions Guidelines | ||
TBC | ||
## License | ||
MIT | ||
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
// Require Node.JS core packages | ||
@@ -9,3 +11,4 @@ const { parse, join } = require("path"); | ||
const is = require("@slimio/is"); | ||
const ajv = new (require("ajv"))({ useDefaults: "shared" }); | ||
const _ajv = require("ajv"); | ||
const ajv = new _ajv({ useDefaults: "shared" }); | ||
const get = require("lodash.get"); | ||
@@ -26,16 +29,16 @@ const clonedeep = require("lodash.clonedeep"); | ||
* @classdesc Reactive JSON Config loader class | ||
* @extends events | ||
* @augments events | ||
* @template T | ||
* | ||
* @property {String} configFile Path to the configuration file | ||
* @property {String} schemaFile Path to the schema configuration file | ||
* @property {string} configFile Path to the configuration file | ||
* @property {string} schemaFile Path to the schema configuration file | ||
* @property {T} payload Configuration content | ||
* @property {Boolean} createOnNoEntry | ||
* @property {Boolean} autoReload | ||
* @property {Boolean} writeOnSet | ||
* @property {Boolean} configHasBeenRead Know if the configuration has been read at least one time | ||
* @property {Boolean} autoReloadActivated Know if the autoReload is Enabled or Disabled | ||
* @property {boolean} createOnNoEntry | ||
* @property {boolean} autoReload | ||
* @property {boolean} writeOnSet | ||
* @property {boolean} configHasBeenRead Know if the configuration has been read at least one time | ||
* @property {boolean} autoReloadActivated Know if the autoReload is Enabled or Disabled | ||
* @property {Array<Array.<string, ZenObservable.SubscriptionObserver<any>>>} subscriptionObservers | ||
* @property {Number} reloadDelay delay before reloading the configuration file (in millisecond). | ||
* @property {Object} defaultSchema | ||
* @property {number} reloadDelay delay before reloading the configuration file (in millisecond). | ||
* @property {object} defaultSchema | ||
* | ||
@@ -48,14 +51,13 @@ * @event reload | ||
class Config extends events { | ||
/** | ||
* @version 0.1.0 | ||
* | ||
* @constructor | ||
* @param {!String} configFilePath Absolute path to the configuration file | ||
* @param {Object} [options={}] Config options | ||
* @param {Boolean=} [options.createOnNoEntry=false] Create the configuration file when no entry are detected | ||
* @param {Boolean=} [options.autoReload=false] Enable/Disable hot reload of the configuration file. | ||
* @param {Boolean=} [options.writeOnSet=false] Write configuration on the disk after a set action | ||
* @param {Object=} options.defaultSchema Optional default Schema | ||
* @param {Number=} [options.reloadDelay=1000] Hot reload delay (in milliseconds) | ||
* @class | ||
* @param {!string} configFilePath Absolute path to the configuration file | ||
* @param {object} [options={}] Config options | ||
* @param {boolean} [options.createOnNoEntry=false] Create the configuration file when no entry are detected | ||
* @param {boolean} [options.autoReload=false] Enable/Disable hot reload of the configuration file. | ||
* @param {boolean} [options.writeOnSet=false] Write configuration on the disk after a set action | ||
* @param {object} options.defaultSchema Optional default Schema | ||
* @param {number} [options.reloadDelay=1000] Hot reload delay (in milliseconds) | ||
* | ||
@@ -118,4 +120,5 @@ * @throws {TypeError} | ||
* @memberof Config# | ||
* @member {Object} payload | ||
* @desc Get a payload Object clone (or null if the configuration has not been read yet) | ||
* @member {object} payload | ||
* @description Get a payload Object clone (or null if the configuration has not been read yet) | ||
* @returns {object} | ||
* | ||
@@ -137,5 +140,5 @@ * @example | ||
* @memberof Config# | ||
* @member {Object} payload | ||
* @member {object} payload | ||
* @param {!T} newPayload Newest payload to setup | ||
* @desc Set a new payload Object | ||
* @description Set a new payload Object | ||
* | ||
@@ -186,7 +189,7 @@ * @throws {Error} | ||
* @async | ||
* @method read | ||
* @desc Read the configuration file (And optionaly apply a default payload value if the file doesn't exist) | ||
* @function read | ||
* @description Read the configuration file (And optionaly apply a default payload value if the file doesn't exist) | ||
* @memberof Config# | ||
* @param {T=} defaultPayload Optional default payload (if the file doesn't exist on the disk). | ||
* @return {Promise<this>} | ||
* @param {T} [defaultPayload] Optional default payload (if the file doesn't exist on the disk). | ||
* @returns {Promise<this>} | ||
* | ||
@@ -214,3 +217,3 @@ * @example | ||
let JSONConfig; | ||
/** @type {Object} */ | ||
/** @type {object} */ | ||
let JSONSchema; | ||
@@ -232,2 +235,3 @@ let writeOnDisk = false; | ||
// If NodeJS Code is different from "ENOENTRY", then throw Error (only if createOnNoEntry is equal to false) | ||
// eslint-disable-next-line | ||
if (!this.createOnNoEntry || Reflect.has(err, "code") && err.code !== "ENOENT") { | ||
@@ -306,6 +310,6 @@ throw err; | ||
* @public | ||
* @method setupAutoReload | ||
* @desc Setup configuration autoReload | ||
* @function setupAutoReload | ||
* @description Setup configuration autoReload | ||
* @memberof Config# | ||
* @return {Boolean} | ||
* @returns {boolean} | ||
* | ||
@@ -357,8 +361,8 @@ * @fires watcherInitialized | ||
* @template H | ||
* @method get | ||
* @desc Get a given field of the configuration | ||
* @param {!String} fieldPath Path to the field (separated with dot) | ||
* @param {Number=} [depth=Infinity] Payload depth! | ||
* @function get | ||
* @description Get a given field of the configuration | ||
* @param {!string} fieldPath Path to the field (separated with dot) | ||
* @param {number} [depth=Infinity] Payload depth! | ||
* @memberof Config# | ||
* @return {H} | ||
* @returns {H} | ||
* | ||
@@ -402,8 +406,8 @@ * @throws {Error} | ||
* @template H | ||
* @method observableOf | ||
* @desc Observe a given configuration key with an Observable object! | ||
* @param {!String} fieldPath Path to the field (separated with dot) | ||
* @param {!Number} [depth=Infinity] Retrieved value depth! | ||
* @function observableOf | ||
* @description Observe a given configuration key with an Observable object! | ||
* @param {!string} fieldPath Path to the field (separated with dot) | ||
* @param {!number} [depth=Infinity] Retrieved value depth! | ||
* @memberof Config# | ||
* @return {ZenObservable.ObservableLike<H>} | ||
* @returns {ZenObservable.ObservableLike<H>} | ||
* | ||
@@ -443,2 +447,3 @@ * @example | ||
* Retrieve the field value first | ||
* | ||
* @type {H} | ||
@@ -460,8 +465,8 @@ */ | ||
* @template H | ||
* @method set | ||
* @desc Set a field in the configuration | ||
* @function set | ||
* @description Set a field in the configuration | ||
* @memberof Config# | ||
* @param {!String} fieldPath Path to the field (separated with dot) | ||
* @param {!string} fieldPath Path to the field (separated with dot) | ||
* @param {!H} fieldValue Field value | ||
* @return {this} | ||
* @returns {this} | ||
* | ||
@@ -513,4 +518,4 @@ * @throws {Error} | ||
* @public | ||
* @method writeOnDisk | ||
* @desc Write the configuration on the Disk | ||
* @function writeOnDisk | ||
* @description Write the configuration on the Disk | ||
* @memberof Config# | ||
@@ -547,4 +552,4 @@ * @returns {Promise<void>} | ||
* @public | ||
* @method lazyWriteOnDisk | ||
* @desc lazy Write Configuration (write the configuration at the next loop iteration) | ||
* @function lazyWriteOnDisk | ||
* @description lazy Write Configuration (write the configuration at the next loop iteration) | ||
* @memberof Config# | ||
@@ -584,4 +589,4 @@ * @returns {void} | ||
* @public | ||
* @method close | ||
* @desc Close (and write on disk) the configuration (it will close the watcher and clean all active observers). | ||
* @function close | ||
* @description Close (and write on disk) the configuration (it will close the watcher and clean all active observers). | ||
* @memberof Config# | ||
@@ -624,3 +629,2 @@ * @returns {Promise<void>} | ||
} | ||
} | ||
@@ -627,0 +631,0 @@ |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
/** | ||
@@ -12,5 +14,5 @@ * @namespace utils | ||
* @memberof utils# | ||
* @desc format ajv errors | ||
* @description format ajv errors | ||
* @param {ajv.ErrorObject[]} ajvErrors Array of ajv error Object | ||
* @returns {String} | ||
* @returns {string} | ||
*/ | ||
@@ -34,6 +36,6 @@ function formatAjvErrors(ajvErrors) { | ||
* @memberof utils# | ||
* @desc Limit an given object depth! | ||
* @param {!Object} obj obj | ||
* @param {Number=} [depth=0] depth | ||
* @returns {Object | Array} | ||
* @description Limit an given object depth! | ||
* @param {!object} obj obj | ||
* @param {number} [depth=0] depth | ||
* @returns {object | Array} | ||
*/ | ||
@@ -40,0 +42,0 @@ function limitObjectDepth(obj, depth = 0) { |
51155
665
264
17
Updated@slimio/is@^1.5.1
Updatedajv@^6.10.2
Updatednode-watch@^0.6.3
Updatedzen-observable@^0.8.14