@configurator/ravendb
Version:
RavenDB client for Node.js
47 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PutDocumentCommand = void 0;
const RavenCommand_1 = require("../../Http/RavenCommand");
const Exceptions_1 = require("../../Exceptions");
const HttpUtil_1 = require("../../Utility/HttpUtil");
class PutDocumentCommand extends RavenCommand_1.RavenCommand {
constructor(id, changeVector, document) {
super();
if (!id) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Id cannot be null or undefined.");
}
if (!document) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Document cannot be null or undefined.");
}
this._id = id;
this._changeVector = changeVector;
this._document = document;
}
get _serializer() {
const serializer = super._serializer;
serializer.replacerRules.length = 0;
return serializer;
}
createRequest(node) {
const uri = `${node.url}/databases/${node.database}/docs?id=${encodeURIComponent(this._id)}`;
const body = this._serializer.serialize(this._document);
const req = {
uri,
method: "PUT",
body,
headers: HttpUtil_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