@discipl/law-reg
Version:
Discipl Law and Regulation Compliance Library
52 lines (39 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LessThanExpressionChecker = void 0;
var _big_util = require("../utils/big_util");
var _baseSubExpressionChecker = require("./baseSubExpressionChecker");
class LessThanExpressionChecker extends _baseSubExpressionChecker.BaseSubExpressionChecker {
async checkSubExpression(fact, ssid, context) {
let lastOperandResult;
for (const op of fact.operands) {
const newContext = this._getContextExplainer().extendContextWithExplanation(context);
const operandResult = await this._getExpressionChecker().checkExpression(op, ssid, newContext);
this.logger.debug('OperandResult in LESS_THAN', operandResult, 'for operand', op);
if (operandResult === undefined) {
this.logger.debug('Resolved LESS_THAN as undefined because one of the operands was undefined');
lastOperandResult = undefined;
break;
} else if (!_big_util.BigUtil.isNumeric(operandResult)) {
this.logger.debug('Resolved LESS_THAN as false because', String(operandResult), 'is not numeric');
lastOperandResult = false;
break;
} else if (lastOperandResult !== undefined && _big_util.BigUtil.lessThan(operandResult, lastOperandResult)) {
this.logger.debug('Resolved LESS_THAN as false, because', String(lastOperandResult), 'is not less than', String(operandResult));
lastOperandResult = false;
break;
} else {
lastOperandResult = operandResult;
}
}
const lessThanResult = lastOperandResult === undefined ? undefined : lastOperandResult !== false;
if (lessThanResult) {
this.logger.debug('Resolved LESS_THAN as', String(lessThanResult));
}
this._getContextExplainer().extendContextExplanationWithResult(context, lessThanResult);
return lessThanResult;
}
}
exports.LessThanExpressionChecker = LessThanExpressionChecker;