Comparing version 0.4.3 to 0.5.0
@@ -1,9 +0,8 @@ | ||
/* | ||
/** | ||
* node-convict | ||
* Configuration management with support for environmental variables, files, and validation. | ||
* | ||
* Configuration management with support for environmental variables, files, | ||
* and validation. | ||
*/ | ||
const cjson = require('cjson'); | ||
const fs = require('fs'); | ||
const validator = require('validator'); | ||
@@ -65,4 +64,4 @@ const moment = require('moment'); | ||
validate(kids, p, previousErrors); | ||
} else if (! (typeof p.default === 'undefined' | ||
&& instance[name] === p.default)) { | ||
} else if (! (typeof p.default === 'undefined' && | ||
instance[name] === p.default)) { | ||
try { | ||
@@ -82,3 +81,4 @@ p._format(instance[name]); | ||
function contains (options, x) { | ||
check(x, 'must be one of the possible values: ' + JSON.stringify(options)).isIn(options); | ||
check(x, 'must be one of the possible values: ' + | ||
JSON.stringify(options)).isIn(options); | ||
} | ||
@@ -88,21 +88,25 @@ | ||
function normalizeSchema (name, o, props, fullName, env, argv) { | ||
if (typeof o === 'object' && !Array.isArray(o) && !('default' in o)) { | ||
function normalizeSchema (name, node, props, fullName, env, argv) { | ||
// If the current schema node is not a config property (has no "default"), recursively normalize it. | ||
if (typeof node === 'object' && !Array.isArray(node) && !('default' in node)) { | ||
props[name] = { | ||
properties: {}, | ||
properties: {} | ||
}; | ||
Object.keys(o).forEach(function(k) { | ||
normalizeSchema(k, o[k], props[name].properties, fullName + "." + k, env, argv); | ||
Object.keys(node).forEach(function(k) { | ||
normalizeSchema(k, node[k], props[name].properties, fullName + "." + | ||
k, env, argv); | ||
}); | ||
return; | ||
} else if (typeof o !== 'object' || Array.isArray(o) || o === null) { | ||
o = { default: o }; | ||
} else if (typeof node !== 'object' || Array.isArray(node) || node === null) { | ||
// Normalize shorthand "value" config properties | ||
node = { default: node }; | ||
} | ||
if (typeof o === 'object') { | ||
var o; | ||
if (typeof node === 'object') { | ||
o = Object.create(node); | ||
props[name] = o; | ||
// associate this property with an environmental variabl | ||
// associate this property with an environmental variable | ||
if (o.env) { | ||
@@ -118,3 +122,4 @@ if (env[o.env]) { | ||
if (argv[o.arg]) { | ||
throw new Error("'" + fullName + "' reuses a command-line argument: " + o.arg); | ||
throw new Error("'" + fullName + "' reuses a command-line argument: " + | ||
o.arg); | ||
} | ||
@@ -132,3 +137,4 @@ argv[o.arg] = fullName; | ||
newFormat = function(x) { | ||
check(Object.prototype.toString.call(x), 'must be of type ' + format.name) | ||
check(Object.prototype.toString.call(x), 'must be of type ' + | ||
format.name) | ||
.equals(Object.prototype.toString.call(new format())); | ||
@@ -141,3 +147,4 @@ }; | ||
if (!types[format]) { | ||
throw new Error("'" + fullName + "' uses an unknown format type: " + format); | ||
throw new Error("'" + fullName + "' uses an unknown format type: " + | ||
format); | ||
} | ||
@@ -156,3 +163,4 @@ | ||
} else if (format && typeof format !== 'function') { | ||
throw new Error("'" + fullName + "': `format` must be a function or a known format type."); | ||
throw new Error("'" + fullName + | ||
"': `format` must be a function or a known format type."); | ||
} | ||
@@ -181,5 +189,6 @@ | ||
} else { | ||
throw new Error("'" + fullName + "' doesn't appear to be a valid schema object: " | ||
+ JSON.stringify(o)) | ||
+ '. Note: schema objects must have a default value.'; | ||
throw new Error("'" + fullName + | ||
"' doesn't appear to be a valid schema object: " + | ||
JSON.stringify(node)) + | ||
'. Note: schema objects must have a default value.'; | ||
} | ||
@@ -341,3 +350,3 @@ } | ||
while (ar.length > 1) { | ||
var k = ar.shift(); | ||
k = ar.shift(); | ||
if (!o[k]) o[k] = {}; | ||
@@ -344,0 +353,0 @@ o = o[k]; |
@@ -5,3 +5,3 @@ { | ||
"description": "Unruly configuration management for nodejs", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/mozilla/node-convict", | ||
@@ -27,4 +27,12 @@ "repository": { | ||
}, | ||
"jshintConfig": { | ||
"unused": "vars", | ||
"undef": true, | ||
"node": true, | ||
"esnext": true, | ||
"mocha": true | ||
}, | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
"test": "mocha -R spec", | ||
"lint": "jshint **/*.json lib/*.js test/*.js" | ||
}, | ||
@@ -31,0 +39,0 @@ "bugs": "https://github.com/mozilla/node-convict/issues", |
@@ -204,1 +204,7 @@ # node-convict [!['Build status'][travis_image_url]][travis_page_url] | ||
## faq | ||
### [How can I define a configuration property as "required" without providing a default value?](https://github.com/mozilla/node-convict/issues/29) | ||
The philosophy was to have production values be the default values. Usually you only want to change defaults for deploy or instance (in aws speak) specific tweaks. However, you can set a default value to `null` and if your format doesn't accept `null` it will throw an error. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
210
2
0
21937
8
392