ravendb
Version:
RavenDB client for Node.js
58 lines • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeadAttachmentCommand = void 0;
const RavenCommand_js_1 = require("../../Http/RavenCommand.js");
const StringUtil_js_1 = require("../../Utility/StringUtil.js");
const index_js_1 = require("../../Exceptions/index.js");
const StatusCode_js_1 = require("../../Http/StatusCode.js");
const HttpUtil_js_1 = require("../../Utility/HttpUtil.js");
const Constants_js_1 = require("../../Constants.js");
class HeadAttachmentCommand extends RavenCommand_js_1.RavenCommand {
_documentId;
_name;
_changeVector;
get isReadRequest() {
return false;
}
constructor(documentId, name, changeVector) {
super();
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(documentId)) {
(0, index_js_1.throwError)("InvalidArgumentException", "DocumentId cannot be null or empty");
}
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(name)) {
(0, index_js_1.throwError)("InvalidArgumentException", "Name cannot be null or empty");
}
this._documentId = documentId;
this._name = name;
this._changeVector = changeVector;
this._responseType = "Empty";
}
createRequest(node) {
const uri = node.url
+ "/databases/" + node.database
+ "/attachments?id=" + encodeURIComponent(this._documentId)
+ "&name=" + encodeURIComponent(this._name);
const req = {
method: "HEAD",
uri
};
if (this._changeVector) {
req.headers[Constants_js_1.HEADERS.IF_NONE_MATCH] = `"${this._changeVector}"`;
}
return req;
}
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.HeadAttachmentCommand = HeadAttachmentCommand;
//# sourceMappingURL=HeadAttachmentCommand.js.map