mon-entreprise/source/engine/index.js

39 lines
979 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])
let enrichYaml = string => yaml.safeLoad(string).map(enrichRule)
2018-09-24 15:14:40 +00:00
export default {
evaluate: (targetNames, nestedSituation, rulesConfig) => {
let rules = rulesConfig
? do {
let { base, extra } = rulesConfig
parseAll([
...(base ? enrichYaml(base) : rulesFr),
...(extra ? enrichYaml(extra) : [])
])
}
: defaultRules
return analyseMany(rules, targetNames)(
2018-09-24 15:14:40 +00:00
nestedSituationToStateSelector(nestedSituation)
)
}
2018-09-24 15:14:40 +00:00
}