ravendb
Version:
RavenDB client for Node.js
47 lines • 1.59 kB
JavaScript
import { StatusCodes } from "../../Http/StatusCode.js";
import { RavenCommand } from "../../Http/RavenCommand.js";
import { throwError } from "../../Exceptions/index.js";
import { getRequiredEtagHeader } from "../../Utility/HttpUtil.js";
import { HEADERS } from "../../Constants.js";
export class HeadDocumentCommand extends RavenCommand {
_id;
_changeVector;
constructor(id, changeVector) {
super();
if (!id) {
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(HEADERS.IF_NONE_MATCH, this._changeVector);
}
return {
method: "HEAD",
uri,
headers: headers.build()
};
}
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=HeadDocumentCommand.js.map