ravendb
Version:
RavenDB client for Node.js
51 lines • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeadDocumentCommand = void 0;
const StatusCode_js_1 = require("../../Http/StatusCode.js");
const RavenCommand_js_1 = require("../../Http/RavenCommand.js");
const index_js_1 = require("../../Exceptions/index.js");
const HttpUtil_js_1 = require("../../Utility/HttpUtil.js");
const Constants_js_1 = require("../../Constants.js");
class HeadDocumentCommand extends RavenCommand_js_1.RavenCommand {
_id;
_changeVector;
constructor(id, changeVector) {
super();
if (!id) {
(0, index_js_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_js_1.HEADERS.IF_NONE_MATCH, this._changeVector);
}
return {
method: "HEAD",
uri,
headers: headers.build()
};
}
async processResponse(cache, response, bodyStream, url) {
if (response.status === StatusCode_js_1.StatusCodes.NotModified) {
this.result = this._changeVector;
return "Automatic";
}
if (response.status === StatusCode_js_1.StatusCodes.NotFound) {
this.result = null;
return "Automatic";
}
this.result = (0, HttpUtil_js_1.getRequiredEtagHeader)(response);
return "Automatic";
}
}
exports.HeadDocumentCommand = HeadDocumentCommand;
//# sourceMappingURL=HeadDocumentCommand.js.map