ravendb
Version:
RavenDB client for Node.js
76 lines • 2.75 kB
JavaScript
import { RavenCommand } from "../../../Http/RavenCommand.js";
import { throwError } from "../../../Exceptions/index.js";
import { TypeUtil } from "../../../Utility/TypeUtil.js";
import { RaftIdGenerator } from "../../../Utility/RaftIdGenerator.js";
export class SetIndexesLockOperation {
_parameters;
constructor(paramsOrIndexName, mode) {
if (TypeUtil.isString(paramsOrIndexName)) {
const indexName = paramsOrIndexName;
if (!indexName) {
throwError("InvalidArgumentException", "IndexName cannot be null.");
}
this._parameters = {
indexNames: [indexName],
mode
};
}
else {
const parameters = paramsOrIndexName;
if (!parameters) {
throwError("InvalidArgumentException", "Parameters cannot be null.");
}
if (!parameters.indexNames || !parameters.indexNames.length) {
throwError("InvalidArgumentException", "IndexNames cannot be null or empty.");
}
this._parameters = parameters;
}
this._filterAutoIndexes();
}
_filterAutoIndexes() {
// Check for auto-indexes - we do not set lock for auto-indexes
if (this._parameters.indexNames.some(x => x.toLocaleLowerCase().startsWith("auto/"))) {
throwError("InvalidArgumentException", "Indexes list contains Auto-Indexes. " +
"Lock Mode is not set for Auto-Indexes.");
}
}
getCommand(conventions) {
return new SetIndexLockCommand(conventions, this._parameters);
}
get resultType() {
return "CommandResult";
}
}
export class SetIndexLockCommand extends RavenCommand {
_parameters;
constructor(conventions, parameters) {
super();
if (!conventions) {
throwError("InvalidArgumentException", "Conventions cannot be null");
}
if (!parameters) {
throwError("InvalidArgumentException", "Parameters cannot be null");
}
this._responseType = "Empty";
this._parameters = conventions.objectMapper.toObjectLiteral(parameters);
}
createRequest(node) {
const uri = node.url + "/databases/" + node.database + "/indexes/set-lock";
const body = this._serializer.serialize(this._parameters);
const headers = this._headers()
.typeAppJson().build();
return {
uri,
method: "POST",
body,
headers
};
}
get isReadRequest() {
return false;
}
getRaftUniqueRequestId() {
return RaftIdGenerator.newId();
}
}
//# sourceMappingURL=SetIndexesLockOperation.js.map