ravendb
Version:
RavenDB client for Node.js
43 lines • 1.49 kB
JavaScript
import { RavenCommand } from "../../Http/RavenCommand.js";
import { throwError } from "../../Exceptions/index.js";
import { HeadersBuilder } from "../../Utility/HttpUtil.js";
export class PutDocumentCommand extends RavenCommand {
_id;
_changeVector;
_document;
constructor(id, changeVector, document) {
super();
if (!id) {
throwError("InvalidArgumentException", "Id cannot be null or undefined.");
}
if (!document) {
throwError("InvalidArgumentException", "Document cannot be null or undefined.");
}
this._id = id;
this._changeVector = changeVector;
this._document = document;
}
createRequest(node) {
const uri = `${node.url}/databases/${node.database}/docs?id=${encodeURIComponent(this._id)}`;
// we don't use conventions here on purpose
// doc that's got here should already have proper casing
const body = JSON.stringify(this._document);
const req = {
uri,
method: "PUT",
body,
headers: HeadersBuilder.create()
.typeAppJson()
.build()
};
this._addChangeVectorIfNotNull(this._changeVector, req);
return req;
}
async setResponseAsync(bodyStream, fromCache) {
return this._parseResponseDefaultAsync(bodyStream);
}
get isReadRequest() {
return false;
}
}
//# sourceMappingURL=PutDocumentCommand.js.map