ravendb
Version:
RavenDB client for Node.js
108 lines • 3.84 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetRevisionsCommand = void 0;
const TypeUtil_js_1 = require("../../Utility/TypeUtil.js");
const DateUtil_js_1 = require("../../Utility/DateUtil.js");
const GetDocumentsCommand_js_1 = require("./GetDocumentsCommand.js");
const RavenCommand_js_1 = require("../../Http/RavenCommand.js");
const index_js_1 = require("../../Exceptions/index.js");
class GetRevisionsCommand extends RavenCommand_js_1.RavenCommand {
_id;
_start;
_pageSize;
_metadataOnly;
_before;
_changeVector;
_changeVectors;
_conventions;
constructor(conventions, changeVectorOrVectorsOrId, beforeOrMetadataOrStart, pageSize, metadataOnly) {
super();
if (beforeOrMetadataOrStart instanceof Date) {
if (!changeVectorOrVectorsOrId) {
(0, index_js_1.throwError)("InvalidArgumentException", "Id cannot be null.");
}
this._id = changeVectorOrVectorsOrId;
this._before = beforeOrMetadataOrStart;
}
else if (TypeUtil_js_1.TypeUtil.isArray(changeVectorOrVectorsOrId)) {
this._changeVectors = changeVectorOrVectorsOrId;
this._metadataOnly = metadataOnly || false;
}
else if (TypeUtil_js_1.TypeUtil.isNumber(beforeOrMetadataOrStart)) {
if (!changeVectorOrVectorsOrId) {
(0, index_js_1.throwError)("InvalidArgumentException", "Id cannot be null.");
}
this._id = changeVectorOrVectorsOrId;
this._start = beforeOrMetadataOrStart;
this._pageSize = pageSize;
this._metadataOnly = metadataOnly || false;
}
else {
this._changeVector = changeVectorOrVectorsOrId;
this._metadataOnly = beforeOrMetadataOrStart || false;
}
this._conventions = conventions;
}
get id() {
return this._id;
}
get before() {
return this._before;
}
get changeVector() {
return this._changeVector;
}
get changeVectors() {
return this._changeVectors;
}
createRequest(node) {
let uri = node.url + "/databases/" + node.database + "/revisions?";
uri += this.getRequestQueryString();
return {
uri,
method: "GET"
};
}
getRequestQueryString() {
let uri = "";
if (this._id) {
uri += "&id=" + encodeURIComponent(this._id);
}
else if (this._changeVector) {
uri += "&changeVector=" + encodeURIComponent(this._changeVector);
}
else if (this._changeVectors) {
for (const changeVector of this._changeVectors) {
uri += "&changeVector=" + encodeURIComponent(changeVector);
}
}
if (this._before) {
uri += "&before=" + DateUtil_js_1.DateUtil.utc.stringify(this._before);
}
if (!TypeUtil_js_1.TypeUtil.isNullOrUndefined(this._start)) {
uri += "&start=" + this._start;
}
if (!TypeUtil_js_1.TypeUtil.isNullOrUndefined(this._pageSize)) {
uri += "&pageSize=" + this._pageSize;
}
if (this._metadataOnly) {
uri += "&metadataOnly=true";
}
return uri;
}
get isReadRequest() {
return true;
}
async setResponseAsync(bodyStream, fromCache) {
if (!bodyStream) {
this.result = null;
return;
}
let body = null;
this.result =
await GetDocumentsCommand_js_1.GetDocumentsCommand.parseDocumentsResultResponseAsync(bodyStream, this._conventions, b => body = b);
return body;
}
}
exports.GetRevisionsCommand = GetRevisionsCommand;
//# sourceMappingURL=GetRevisionsCommand.js.map