json-expression-eval
Version:
json serializable rule engine / boolean expression evaluator
28 lines • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.evaluateEngineConsequence = void 0;
const helpers_1 = require("./helpers");
const evaluateEngineConsequence = async (context, consequence) => {
let messageParts;
if (typeof consequence.message === 'string') {
messageParts = [consequence.message];
}
else {
messageParts = consequence.message;
}
return {
message: messageParts.map((msgPart) => {
if (typeof msgPart === 'string') {
return msgPart;
}
const { value, exists } = (0, helpers_1.getFromPath)(context, msgPart.ref);
if (!exists) {
throw new Error(`Invalid consequence ref - unknown context key ${msgPart.ref}`);
}
return String(value);
}).join(' '),
custom: consequence.custom,
};
};
exports.evaluateEngineConsequence = evaluateEngineConsequence;
//# sourceMappingURL=engineConsequenceEvaluator.js.map