UNPKG

ravendb

Version:
111 lines 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeSeriesIncludesToken = void 0; const QueryToken_js_1 = require("./QueryToken.js"); const StringUtil_js_1 = require("../../../Utility/StringUtil.js"); const DateUtil_js_1 = require("../../../Utility/DateUtil.js"); const index_js_1 = require("../../../Exceptions/index.js"); class TimeSeriesIncludesToken extends QueryToken_js_1.QueryToken { _sourcePath; _range; constructor(sourcePath, range) { super(); this._range = range; this._sourcePath = sourcePath; } static create(sourcePath, range) { return new TimeSeriesIncludesToken(sourcePath, range); } addAliasToPath(alias) { this._sourcePath = StringUtil_js_1.StringUtil.isNullOrEmpty(this._sourcePath) ? alias : alias + "." + this._sourcePath; } writeTo(writer) { writer .append("timeseries("); if (!StringUtil_js_1.StringUtil.isNullOrEmpty(this._sourcePath)) { writer .append(this._sourcePath) .append(", "); } if (!StringUtil_js_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, index_js_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, index_js_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, index_js_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_js_1.DateUtil.utc.stringify(range.from)) .append("'") .append(", "); } else { writer .append("null,"); } if (range.to) { writer .append("'") .append(DateUtil_js_1.DateUtil.utc.stringify(range.to)) .append("'"); } else { writer .append("null"); } } } exports.TimeSeriesIncludesToken = TimeSeriesIncludesToken; //# sourceMappingURL=TimeSeriesIncludesToken.js.map