@configurator/ravendb
Version:
RavenDB client for Node.js
49 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeadDocumentCommand = void 0;
const StatusCode_1 = require("../../Http/StatusCode");
const RavenCommand_1 = require("../../Http/RavenCommand");
const Exceptions_1 = require("../../Exceptions");
const HttpUtil_1 = require("../../Utility/HttpUtil");
const Constants_1 = require("../../Constants");
class HeadDocumentCommand extends RavenCommand_1.RavenCommand {
constructor(id, changeVector) {
super();
if (!id) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Id cannot be null.");
}
this._id = id;
this._changeVector = changeVector;
this._responseType = "Empty";
}
get isReadRequest() {
return false;
}
createRequest(node) {
const uri = node.url + "/databases/" + node.database + "/docs?id=" + encodeURIComponent(this._id);
const headers = this._headers()
.typeAppJson();
if (this._changeVector) {
headers.with(Constants_1.HEADERS.IF_NONE_MATCH, this._changeVector);
}
return {
method: "HEAD",
uri,
headers: headers.build()
};
}
async processResponse(cache, response, bodyStream, url) {
if (response.status === StatusCode_1.StatusCodes.NotModified) {
this.result = this._changeVector;
return "Automatic";
}
if (response.status === StatusCode_1.StatusCodes.NotFound) {
this.result = null;
return "Automatic";
}
this.result = (0, HttpUtil_1.getRequiredEtagHeader)(response);
return "Automatic";
}
}
exports.HeadDocumentCommand = HeadDocumentCommand;
//# sourceMappingURL=HeadDocumentCommand.js.map