node-convict
node-convict copied to clipboard
Implementation of a new feature: support loading of map like objects
Implementation of a new feature: support loading of map like objects
For example:
var config = {
myMap: {
someArbitraryKey: { schemaBoundProp: 'asdf', anotherSchemaBoundProp: 'qwer'},
anotherArbitraryKey: { schemaBoundProp: 'zxcv', anotherSchemaBoundProp: 'vbnm'}
}
}
convict.addFormat({
name: `map`,
validate: function (theMap, schema) {
if (typeof theMap !== 'object' || theMap == null) {
throw new Error('must be an non-empty (map like) object')
}
// iterate each key in the map
for (const key of Object.keys(theMap)) {
// perform validation on the key's value against the child schema
convict(schema.children).load(theMap[key]).validate()
}
}
})
const schema = {
myMap: {
doc: 'this is a key value map, where the value object can be validated by a child schema',
default: {},
format: 'map',
children: {
schemaBoundProp: {
doc: 'a property of the value object',
default: null,
format: String
},
anotherSchemaBoundProp: {
doc: 'a property of the value object',
default: null,
format: String
}
}
}
}
convict(schema).load(config).validate()
CHANGES made -> one line change to the overlay function
Coverage remained the same at 93.151% when pulling 59eb1e5bed5ed27a60752a11bcc95d5a8e243d11 on avxhi93:master into bdd8a4e55a236c2ccb2a2d6062c9ac3ddec34af6 on mozilla:master.
@A-312, @madarche can I have the attention of one of you guys to accept this pull request, please.
This would be a great feature, please do accept it 👍
Is there any reason this is not merged ?
@A-312, @madarche still not merged :(