ravendb
Version:
RavenDB client for Node.js
54 lines • 1.95 kB
JavaScript
import { RavenCommand } from "../../Http/RavenCommand.js";
import { StringUtil } from "../../Utility/StringUtil.js";
import { throwError } from "../../Exceptions/index.js";
import { StatusCodes } from "../../Http/StatusCode.js";
import { getRequiredEtagHeader } from "../../Utility/HttpUtil.js";
import { HEADERS } from "../../Constants.js";
export class HeadAttachmentCommand extends RavenCommand {
_documentId;
_name;
_changeVector;
get isReadRequest() {
return false;
}
constructor(documentId, name, changeVector) {
super();
if (StringUtil.isNullOrWhitespace(documentId)) {
throwError("InvalidArgumentException", "DocumentId cannot be null or empty");
}
if (StringUtil.isNullOrWhitespace(name)) {
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[HEADERS.IF_NONE_MATCH] = `"${this._changeVector}"`;
}
return req;
}
async processResponse(cache, response, bodyStream, url) {
if (response.status === StatusCodes.NotModified) {
this.result = this._changeVector;
return "Automatic";
}
if (response.status === StatusCodes.NotFound) {
this.result = null;
return "Automatic";
}
this.result = getRequiredEtagHeader(response);
return "Automatic";
}
}
//# sourceMappingURL=HeadAttachmentCommand.js.map