@nova-odm/expressions
Version:
Composable expression objects for Amazon DynamoDB
41 lines • 1.76 kB
JavaScript
;
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MathematicalExpression = void 0;
var AttributePath_1 = require("./AttributePath");
var FunctionExpression_1 = require("./FunctionExpression");
var MATHEMATICAL_EXPRESSION_TAG = 'AmazonDynamoDbMathematicalExpression';
var EXPECTED_TOSTRING = "[object ".concat(MATHEMATICAL_EXPRESSION_TAG, "]");
/**
* An object representing a DynamoDB function expression.
*/
var MathematicalExpression = /** @class */ (function () {
function MathematicalExpression(lhs, operator, rhs) {
this.lhs = lhs;
this.operator = operator;
this.rhs = rhs;
this[_a] = MATHEMATICAL_EXPRESSION_TAG;
}
MathematicalExpression.prototype.serialize = function (attributes) {
var safeArgs = [this.lhs, this.rhs].map(function (arg) {
if (FunctionExpression_1.FunctionExpression.isFunctionExpression(arg)) {
return arg.serialize(attributes);
}
return AttributePath_1.AttributePath.isAttributePath(arg) || typeof arg === 'string'
? attributes.addName(arg)
: attributes.addValue(arg);
});
return "".concat(safeArgs[0], " ").concat(this.operator, " ").concat(safeArgs[1]);
};
/**
* Evaluate whether the provided value is a MathematicalExpression object.
*/
MathematicalExpression.isMathematicalExpression = function (arg) {
return arg instanceof MathematicalExpression
|| Object.prototype.toString.call(arg) === EXPECTED_TOSTRING;
};
return MathematicalExpression;
}());
exports.MathematicalExpression = MathematicalExpression;
_a = Symbol.toStringTag;
//# sourceMappingURL=MathematicalExpression.js.map