Hotfix parameterization

This commit is contained in:
Bán Dénes 2022-01-14 19:28:19 +01:00
parent 488fba0768
commit 47d15c0261
6 changed files with 60 additions and 6 deletions

View file

@ -25,6 +25,7 @@ const process = async (raw, debug=false, logger=()=>{}) => {
logger('Preprocessing input...')
config = prepare.unnest(config)
config = prepare.inherit(config)
config = prepare.parameterize(config)
const results = {}
if (debug) {
results.raw = raw

View file

@ -80,6 +80,13 @@ exports.inherit = config => traverse(config, config, [], (target, key, val, root
})
exports.parameterize = config => traverse(config, config, [], (target, key, val, root, breadcrumbs) => {
// we only care about objects
if (a.type(val)() !== 'object') {
target[key] = val
return
}
let params = val.$params
let args = val.$args
@ -108,7 +115,7 @@ exports.parameterize = config => traverse(config, config, [], (target, key, val,
let str = JSON.stringify(val)
const zip = rows => rows[0].map((_, i) => rows.map(row => row[i]))
for (const [par, arg] of zip([params, args])) {
str = str.replace(new RegExp(`"${par}"`, 'g'), JSON.stringify(arg))
str = str.replace(new RegExp(`${par}`, 'g'), arg)
}
try {
val = JSON.parse(str)