ravendb
Version:
RavenDB client for Node.js
127 lines • 4.74 kB
JavaScript
import { TimeSeriesDetails } from "./TimeSeriesDetails.js";
import { TypeUtil } from "../../../Utility/TypeUtil.js";
import { throwError } from "../../../Exceptions/index.js";
import { StringUtil } from "../../../Utility/StringUtil.js";
import { DateUtil } from "../../../Utility/DateUtil.js";
import { CaseInsensitiveKeysMap } from "../../../Primitives/CaseInsensitiveKeysMap.js";
import { GetTimeSeriesCommand, reviveTimeSeriesRangeResult } from "./GetTimeSeriesOperation.js";
import { RavenCommand } from "../../../Http/RavenCommand.js";
import { StringBuilder } from "../../../Utility/StringBuilder.js";
export class GetMultipleTimeSeriesOperation {
_docId;
_ranges;
_start;
_pageSize;
_includes;
_returnFullResults;
constructor(docId, ranges, start, pageSize, includes, returnFullResults) {
if (!ranges) {
throwError("InvalidArgumentException", "Ranges cannot be null");
}
if (StringUtil.isNullOrEmpty(docId)) {
throwError("InvalidArgumentException", "DocId cannot be null or empty");
}
this._docId = docId;
this._start = start ?? 0;
this._pageSize = pageSize ?? 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);
}
}
export class GetMultipleTimeSeriesCommand extends RavenCommand {
_conventions;
_docId;
_ranges;
_start;
_pageSize;
_includes;
_returnFullResults;
constructor(conventions, docId, ranges, start, pageSize, includes, returnFullResults) {
super();
if (!docId) {
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(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.MAX_INT32) {
pathBuilder
.append("&pageSize=")
.append(this._pageSize.toString());
}
if (this._returnFullResults) {
pathBuilder
.append("&full=true");
}
if (!this._ranges.length) {
throwError("InvalidArgumentException", "Ranges cannot be null or empty");
}
for (const range of this._ranges) {
if (StringUtil.isNullOrEmpty(range.name)) {
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.utc.stringify(range.from) : "")
.append("&to=")
.append(range.to ? DateUtil.utc.stringify(range.to) : "");
}
if (this._includes) {
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();
this.result.id = results.Id;
this.result.values = CaseInsensitiveKeysMap.create();
for (const [key, value] of Object.entries(results.Values)) {
const mapped = value.map(x => reviveTimeSeriesRangeResult(GetTimeSeriesCommand.mapToLocalObject(x)));
this.result.values.set(key, mapped);
}
return body;
}
get isReadRequest() {
return true;
}
}
//# sourceMappingURL=GetMultipleTimeSeriesOperation.js.map