UNPKG

@configurator/ravendb

Version:
113 lines 4.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetMultipleTimeSeriesCommand = exports.GetMultipleTimeSeriesOperation = void 0; const TimeSeriesDetails_1 = require("./TimeSeriesDetails"); const TypeUtil_1 = require("../../../Utility/TypeUtil"); const Exceptions_1 = require("../../../Exceptions"); const StringUtil_1 = require("../../../Utility/StringUtil"); const DateUtil_1 = require("../../../Utility/DateUtil"); const CaseInsensitiveKeysMap_1 = require("../../../Primitives/CaseInsensitiveKeysMap"); const GetTimeSeriesOperation_1 = require("./GetTimeSeriesOperation"); const RavenCommand_1 = require("../../../Http/RavenCommand"); const StringBuilder_1 = require("../../../Utility/StringBuilder"); class GetMultipleTimeSeriesOperation { constructor(docId, ranges, start, pageSize, includes) { if (!ranges) { (0, Exceptions_1.throwError)("InvalidArgumentException", "Ranges cannot be null"); } if (StringUtil_1.StringUtil.isNullOrEmpty(docId)) { (0, Exceptions_1.throwError)("InvalidArgumentException", "DocId cannot be null or empty"); } this._docId = docId; this._start = start ?? 0; this._pageSize = pageSize ?? TypeUtil_1.TypeUtil.MAX_INT32; this._ranges = ranges; this._includes = includes; } get resultType() { return "CommandResult"; } getCommand(store, conventions, httpCache) { return new GetMultipleTimeSeriesCommand(conventions, this._docId, this._ranges, this._start, this._pageSize, this._includes); } } exports.GetMultipleTimeSeriesOperation = GetMultipleTimeSeriesOperation; class GetMultipleTimeSeriesCommand extends RavenCommand_1.RavenCommand { constructor(conventions, docId, ranges, start, pageSize, includes) { super(); if (!docId) { (0, Exceptions_1.throwError)("InvalidArgumentException", "DocId cannot be null"); } this._conventions = conventions; this._docId = docId; this._ranges = ranges; this._start = start; this._pageSize = pageSize; this._includes = includes; } createRequest(node) { const pathBuilder = new StringBuilder_1.StringBuilder(node.url); pathBuilder .append("/databases/") .append(node.database) .append("/timeseries/ranges") .append("?docId=") .append(this._urlEncode(this._docId)); if (this._start > 0) { pathBuilder .append("&start=") .append(this._start.toString()); } if (this._pageSize < TypeUtil_1.TypeUtil.MAX_INT32) { pathBuilder .append("&pageSize=") .append(this._pageSize.toString()); } if (!this._ranges.length) { (0, Exceptions_1.throwError)("InvalidArgumentException", "Ranges cannot be null or empty"); } for (const range of this._ranges) { if (StringUtil_1.StringUtil.isNullOrEmpty(range.name)) { (0, Exceptions_1.throwError)("InvalidArgumentException", "Missing name argument in TimeSeriesRange. Name cannot be null or empty"); } pathBuilder .append("&name=") .append(range.name || "") .append("&from=") .append(range.from ? DateUtil_1.DateUtil.utc.stringify(range.from) : "") .append("&to=") .append(range.to ? DateUtil_1.DateUtil.utc.stringify(range.to) : ""); } if (this._includes) { GetTimeSeriesOperation_1.GetTimeSeriesCommand.addIncludesToRequest(pathBuilder, this._includes); } const uri = pathBuilder.toString(); return { uri, method: "GET" }; } async setResponseAsync(bodyStream, fromCache) { if (!bodyStream) { return; } let body = null; const results = await this._pipeline() .parseJsonSync() .collectBody(b => body = b) .process(bodyStream); this.result = new TimeSeriesDetails_1.TimeSeriesDetails(); this.result.id = results.Id; this.result.values = CaseInsensitiveKeysMap_1.CaseInsensitiveKeysMap.create(); for (const [key, value] of Object.entries(results.Values)) { const mapped = value.map(x => (0, GetTimeSeriesOperation_1.reviveTimeSeriesRangeResult)(GetTimeSeriesOperation_1.GetTimeSeriesCommand.mapToLocalObject(x, this._conventions), this._conventions)); this.result.values.set(key, mapped); } return body; } get isReadRequest() { return true; } } exports.GetMultipleTimeSeriesCommand = GetMultipleTimeSeriesCommand; //# sourceMappingURL=GetMultipleTimeSeriesOperation.js.map