ravendb
Version:
RavenDB client for Node.js
46 lines • 1.55 kB
JavaScript
import { RavenCommand } from "../../Http/RavenCommand.js";
import { throwError } from "../../Exceptions/index.js";
import { RaftIdGenerator } from "../../Utility/RaftIdGenerator.js";
export class NextIdentityForCommand extends RavenCommand {
_id;
_raftUniqueRequestId = RaftIdGenerator.newId();
constructor(id) {
super();
if (!id) {
throwError("InvalidArgumentException", "Id cannot be null");
}
this._id = id;
}
get isReadRequest() {
return false;
}
createRequest(node) {
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;
}
}
//# sourceMappingURL=NextIdentityForCommand.js.map