node-convict
node-convict copied to clipboard
Cannot use dot in keys when using Object format
I have a case where an URL is a key in an object that is a default value for a setting. Something like this:
export const conf = convict({
npmrc: {
doc: "Config for installing plugin packages.",
format: "Object",
default: {
registries: {
"@foo": "https://npm.foo.com/",
},
authTokens: {
"https://npm.foo.com/": {
type: "Bearer",
token: "XXXX",
},
},
},
}
}
This fails to validate with this error:
Error: cannot find configuration param 'npmrc.authTokens.https://npm.foo.com/'
at walk (/XXXserver.js:74759:15)
at flatten (/XXX/server.js:74405:15)
at validate (/XXX/server.js:74449:24)
at Object.validate (/XXX/server.js:74911:20)
I guess it is becuase convict supports dot notation in the string sent to get()
which gets confusing when the keys also have dots. Is there a workaround for this so we can use URLs as keys?
I'm having this problem with String type as well. It looks like this isn't specific to Objects.
Sorry @jonaskello, no workaround that I know of.
The way convict parses all the objects is too complicated. This part is getting hard to maintain. The problem you are mentioning is a proof of it. A very good part of convict is the thorough tests which provide the needed cover and confidence when we modiy convict. A good thing would be to rewrite the whole parsing of objects. Taking advantage of ES6 features like the Map data structure, instead of using plain Objects, would be the way to go.
This is hitting us pretty hard as the end-user is putting in config vals, not ourselves.
Wrapping in [...]
seems to protect against this, at least preventing crashing.
#354 ;)