UNPKG

ravendb

Version:
132 lines 5.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetMultipleTimeSeriesCommand = exports.GetMultipleTimeSeriesOperation = void 0; const TimeSeriesDetails_js_1 = require("./TimeSeriesDetails.js"); const TypeUtil_js_1 = require("../../../Utility/TypeUtil.js"); const index_js_1 = require("../../../Exceptions/index.js"); const StringUtil_js_1 = require("../../../Utility/StringUtil.js"); const DateUtil_js_1 = require("../../../Utility/DateUtil.js"); const CaseInsensitiveKeysMap_js_1 = require("../../../Primitives/CaseInsensitiveKeysMap.js"); const GetTimeSeriesOperation_js_1 = require("./GetTimeSeriesOperation.js"); const RavenCommand_js_1 = require("../../../Http/RavenCommand.js"); const StringBuilder_js_1 = require("../../../Utility/StringBuilder.js"); class GetMultipleTimeSeriesOperation { _docId; _ranges; _start; _pageSize; _includes; _returnFullResults; constructor(docId, ranges, start, pageSize, includes, returnFullResults) { if (!ranges) { (0, index_js_1.throwError)("InvalidArgumentException", "Ranges cannot be null"); } if (StringUtil_js_1.StringUtil.isNullOrEmpty(docId)) { (0, index_js_1.throwError)("InvalidArgumentException", "DocId cannot be null or empty"); } this._docId = docId; this._start = start ?? 0; this._pageSize = pageSize ?? TypeUtil_js_1.TypeUtil.MAX_INT32; this._ranges = ranges; this._includes = includes; this._returnFullResults = returnFullResults; } get resultType() { return "CommandResult"; } getCommand(store, conventions, httpCache) { return new GetMultipleTimeSeriesCommand(conventions, this._docId, this._ranges, this._start, this._pageSize, this._includes, this._returnFullResults); } } exports.GetMultipleTimeSeriesOperation = GetMultipleTimeSeriesOperation; class GetMultipleTimeSeriesCommand extends RavenCommand_js_1.RavenCommand { _conventions; _docId; _ranges; _start; _pageSize; _includes; _returnFullResults; constructor(conventions, docId, ranges, start, pageSize, includes, returnFullResults) { super(); if (!docId) { (0, index_js_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; this._returnFullResults = returnFullResults; } createRequest(node) { const pathBuilder = new StringBuilder_js_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_js_1.TypeUtil.MAX_INT32) { pathBuilder .append("&pageSize=") .append(this._pageSize.toString()); } if (this._returnFullResults) { pathBuilder .append("&full=true"); } if (!this._ranges.length) { (0, index_js_1.throwError)("InvalidArgumentException", "Ranges cannot be null or empty"); } for (const range of this._ranges) { if (StringUtil_js_1.StringUtil.isNullOrEmpty(range.name)) { (0, index_js_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_js_1.DateUtil.utc.stringify(range.from) : "") .append("&to=") .append(range.to ? DateUtil_js_1.DateUtil.utc.stringify(range.to) : ""); } if (this._includes) { GetTimeSeriesOperation_js_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_js_1.TimeSeriesDetails(); this.result.id = results.Id; this.result.values = CaseInsensitiveKeysMap_js_1.CaseInsensitiveKeysMap.create(); for (const [key, value] of Object.entries(results.Values)) { const mapped = value.map(x => (0, GetTimeSeriesOperation_js_1.reviveTimeSeriesRangeResult)(GetTimeSeriesOperation_js_1.GetTimeSeriesCommand.mapToLocalObject(x))); this.result.values.set(key, mapped); } return body; } get isReadRequest() { return true; } } exports.GetMultipleTimeSeriesCommand = GetMultipleTimeSeriesCommand; //# sourceMappingURL=GetMultipleTimeSeriesOperation.js.map