UNPKG

@configurator/ravendb

Version:
105 lines 3.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeSeriesIncludesToken = void 0; const QueryToken_1 = require("./QueryToken"); const StringUtil_1 = require("../../../Utility/StringUtil"); const DateUtil_1 = require("../../../Utility/DateUtil"); const Exceptions_1 = require("../../../Exceptions"); class TimeSeriesIncludesToken extends QueryToken_1.QueryToken { constructor(sourcePath, range) { super(); this._range = range; this._sourcePath = sourcePath; } static create(sourcePath, range) { return new TimeSeriesIncludesToken(sourcePath, range); } addAliasToPath(alias) { this._sourcePath = StringUtil_1.StringUtil.isNullOrEmpty(this._sourcePath) ? alias : alias + "." + this._sourcePath; } writeTo(writer) { writer .append("timeseries("); if (!StringUtil_1.StringUtil.isNullOrEmpty(this._sourcePath)) { writer .append(this._sourcePath) .append(", "); } if (!StringUtil_1.StringUtil.isNullOrEmpty(this._range.name)) { writer .append("'") .append(this._range.name) .append("'") .append(", "); } if ("count" in this._range) { TimeSeriesIncludesToken._writeCountRangeTo(writer, this._range); } else if ("time" in this._range) { TimeSeriesIncludesToken._writeTimeRangeTo(writer, this._range); } else if ("from" in this._range && "to" in this._range) { TimeSeriesIncludesToken._writeRangeTo(writer, this._range); } else { (0, Exceptions_1.throwError)("InvalidArgumentException", "Not supported time range type: " + this._range); } writer .append(")"); } static _writeTimeRangeTo(writer, range) { switch (range.type) { case "Last": writer .append("last("); break; default: (0, Exceptions_1.throwError)("InvalidArgumentException", "Not supported time range type: " + range.type); } writer .append(range.time.value) .append(", '") .append(range.time.unit) .append("')"); } static _writeCountRangeTo(writer, range) { switch (range.type) { case "Last": writer .append("last("); break; default: (0, Exceptions_1.throwError)("InvalidArgumentException", "Not supported time range type: " + range.type); } writer .append(range.count) .append(")"); } static _writeRangeTo(writer, range) { if (range.from) { writer .append("'") .append(DateUtil_1.DateUtil.utc.stringify(range.from)) .append("'") .append(", "); } else { writer .append("null,"); } if (range.to) { writer .append("'") .append(DateUtil_1.DateUtil.utc.stringify(range.to)) .append("'"); } else { writer .append("null"); } } } exports.TimeSeriesIncludesToken = TimeSeriesIncludesToken; //# sourceMappingURL=TimeSeriesIncludesToken.js.map