mon-entreprise/source/engine/index.js

31 lines
807 B
JavaScript
Raw Normal View History

2018-08-16 08:05:00 +00:00
// This file exports the functions of the public computing library
import { analyseMany, parseAll } from './traverse.js'
import {
rulesFr,
collectDefaults,
nestedSituationToPathMap,
enrichRule
} from './rules'
import yaml from 'js-yaml'
2018-08-15 09:39:10 +00:00
let defaultRules = parseAll(rulesFr)
2018-08-16 08:05:00 +00:00
// The public evaluation function takes a nested object of input values
let nestedSituationToStateSelector = nestedSituation => dottedName =>
({
...collectDefaults(rulesFr),
...nestedSituationToPathMap(nestedSituation)
}[dottedName])
2018-09-24 15:14:40 +00:00
export default {
evaluate: (targetNames, nestedSituation, rulesYaml) => {
let rules = rulesYaml
? (rules = parseAll(yaml.safeLoad(rulesYaml).map(enrichRule)))
: defaultRules
return analyseMany(rules, targetNames)(
2018-09-24 15:14:40 +00:00
nestedSituationToStateSelector(nestedSituation)
)
}
2018-09-24 15:14:40 +00:00
}