2018-08-16 08:05:00 +00:00
|
|
|
// This file exports the functions of the public computing library
|
|
|
|
import { analyseMany, parseAll } from './traverse.js'
|
2018-09-24 16:27:43 +00:00
|
|
|
import {
|
|
|
|
rulesFr,
|
|
|
|
collectDefaults,
|
|
|
|
nestedSituationToPathMap,
|
|
|
|
enrichRule
|
|
|
|
} from './rules'
|
|
|
|
import yaml from 'js-yaml'
|
2018-08-15 09:39:10 +00:00
|
|
|
|
2018-09-24 16:27:43 +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 {
|
2018-09-24 16:27:43 +00:00
|
|
|
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 16:27:43 +00:00
|
|
|
)
|
|
|
|
}
|
2018-09-24 15:14:40 +00:00
|
|
|
}
|