ravendb
Version:
RavenDB client for Node.js
50 lines • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NextIdentityForCommand = void 0;
const RavenCommand_js_1 = require("../../Http/RavenCommand.js");
const index_js_1 = require("../../Exceptions/index.js");
const RaftIdGenerator_js_1 = require("../../Utility/RaftIdGenerator.js");
class NextIdentityForCommand extends RavenCommand_js_1.RavenCommand {
_id;
_raftUniqueRequestId = RaftIdGenerator_js_1.RaftIdGenerator.newId();
constructor(id) {
super();
if (!id) {
(0, index_js_1.throwError)("InvalidArgumentException", "Id cannot be null");
}
this._id = id;
}
get isReadRequest() {
return false;
}
createRequest(node) {
RavenCommand_js_1.RavenCommand.ensureIsNotNullOrEmpty(this._id, "id");
const uri = node.url + "/databases/" + node.database + "/identity/next?name=" + encodeURIComponent(this._id);
return {
method: "POST",
uri
};
}
async setResponseAsync(bodyStream, fromCache) {
if (!bodyStream) {
this._throwInvalidResponse();
}
let body = null;
const results = await this._defaultPipeline(_ => body = _).process(bodyStream);
if (!results["newIdentityValue"]) {
this._throwInvalidResponse();
}
this.result = results["newIdentityValue"];
return body;
}
getRaftUniqueRequestId() {
return this._raftUniqueRequestId;
}
prepareToBroadcast(conventions) {
const copy = new NextIdentityForCommand(this._id);
copy._raftUniqueRequestId = this._raftUniqueRequestId;
return copy;
}
}
exports.NextIdentityForCommand = NextIdentityForCommand;
//# sourceMappingURL=NextIdentityForCommand.js.map