ravendb
Version:
RavenDB client for Node.js
47 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PutDocumentCommand = void 0;
const RavenCommand_js_1 = require("../../Http/RavenCommand.js");
const index_js_1 = require("../../Exceptions/index.js");
const HttpUtil_js_1 = require("../../Utility/HttpUtil.js");
class PutDocumentCommand extends RavenCommand_js_1.RavenCommand {
_id;
_changeVector;
_document;
constructor(id, changeVector, document) {
super();
if (!id) {
(0, index_js_1.throwError)("InvalidArgumentException", "Id cannot be null or undefined.");
}
if (!document) {
(0, index_js_1.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: HttpUtil_js_1.HeadersBuilder.create()
.typeAppJson()
.build()
};
this._addChangeVectorIfNotNull(this._changeVector, req);
return req;
}
async setResponseAsync(bodyStream, fromCache) {
return this._parseResponseDefaultAsync(bodyStream);
}
get isReadRequest() {
return false;
}
}
exports.PutDocumentCommand = PutDocumentCommand;
//# sourceMappingURL=PutDocumentCommand.js.map