@slimio/config
Advanced tools
Comparing version 0.0.0 to 0.0.1
@@ -0,0 +0,0 @@ { |
{ | ||
"name": "@slimio/config", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "SlimIO Reactive JSON Config loaded", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -38,6 +38,7 @@ // Require Node.JS core packages | ||
* @classdesc Reactive JSON Config loader class | ||
* @template T | ||
* | ||
* @property {String} configFile Path to the configuration file | ||
* @property {String} schemaFile Path to the schema configuration file | ||
* @property {Object} payload Configuration content | ||
* @property {T} payload Configuration content | ||
* @property {Boolean} createOnNoEntry | ||
@@ -50,2 +51,3 @@ * @property {Boolean} autoReload | ||
* @property {Number} reloadDelay delay before reloading the configuration file (in millisecond). | ||
* @property {Object} defaultSchema | ||
*/ | ||
@@ -57,6 +59,7 @@ class Config extends Events { | ||
* @param {!String} configFilePath Absolute path to the configuration file | ||
* @param {Object=} [options={}] Config options | ||
* @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 | ||
@@ -93,2 +96,7 @@ * | ||
this.subscriptionObservers = []; | ||
// Assign defaultSchema is exist! | ||
if (Reflect.has(options.defaultSchema)) { | ||
this.defaultSchema = options.defaultSchema; | ||
} | ||
} | ||
@@ -147,4 +155,4 @@ | ||
* @memberof Config# | ||
* @param {Object=} defaultPayload Optional default payload (if the file doesn't exist on the disk). | ||
* @return {Promise<void>} | ||
* @param {T=} defaultPayload Optional default payload (if the file doesn't exist on the disk). | ||
* @return {Promise<this>} | ||
*/ | ||
@@ -186,3 +194,5 @@ async read(defaultPayload) { | ||
} | ||
JSONSchema = Config.DEFAULTSchema; | ||
JSONSchema = is.nullOrUndefined(this.defaultSchema) ? | ||
Config.DEFAULTSchema : | ||
this.defaultSchema; | ||
} | ||
@@ -196,2 +206,4 @@ | ||
} | ||
return this; | ||
} | ||
@@ -212,3 +224,2 @@ | ||
this.watcher = watcher(this.configFile, { delay: this.reloadDelay }, async(evt, name) => { | ||
console.log("%s changed.", name); | ||
await this.read(); | ||
@@ -221,3 +232,3 @@ this.emit("reload"); | ||
* @public | ||
* @template T | ||
* @template H | ||
* @method get | ||
@@ -227,3 +238,3 @@ * @desc Get a given field of the configuration | ||
* @memberof Config# | ||
* @return {T} | ||
* @return {H} | ||
* | ||
@@ -265,3 +276,3 @@ * @throws {Error} | ||
* @public | ||
* @template T | ||
* @template H | ||
* @method get | ||
@@ -271,3 +282,3 @@ * @desc Get a given field of the configuration | ||
* @param {!String} fieldPath Path to the field (separated with dot) | ||
* @param {!T} fieldValue Field value | ||
* @param {!H} fieldValue Field value | ||
* @return {Promise<void>} | ||
@@ -274,0 +285,0 @@ * |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
1532785
47
1314
1
1