@configurator/ravendb
Version:
RavenDB client for Node.js
55 lines • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetCompareExchangeValueCommand = exports.GetCompareExchangeValueOperation = void 0;
const RavenCommand_1 = require("../../../Http/RavenCommand");
const Exceptions_1 = require("../../../Exceptions");
const CompareExchangeValueResultParser_1 = require("./CompareExchangeValueResultParser");
const GetCompareExchangeValuesOperation_1 = require("./GetCompareExchangeValuesOperation");
class GetCompareExchangeValueOperation {
constructor(key, clazz, materializeMetadata = true) {
this._key = key;
this._clazz = clazz;
this._materializeMetadata = materializeMetadata;
}
getCommand(store, conventions, cache) {
return new GetCompareExchangeValueCommand(this._key, this._materializeMetadata, conventions, this._clazz);
}
get resultType() {
return "CommandResult";
}
}
exports.GetCompareExchangeValueOperation = GetCompareExchangeValueOperation;
class GetCompareExchangeValueCommand extends RavenCommand_1.RavenCommand {
constructor(key, materializeMetadata, conventions, clazz) {
super();
if (!key) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "The key argument must have value");
}
this._key = key;
this._clazz = clazz;
this._materializeMetadata = materializeMetadata;
this._conventions = conventions;
}
get isReadRequest() {
return true;
}
createRequest(node) {
const uri = node.url + "/databases/" + node.database + "/cmpxchg?key=" + encodeURIComponent(this._key);
return { uri };
}
async setResponseAsync(bodyStream, fromCache) {
if (!bodyStream) {
return null;
}
let body = null;
const results = await this._pipeline()
.collectBody(x => body = x)
.parseJsonSync()
.process(bodyStream);
const localObject = GetCompareExchangeValuesOperation_1.GetCompareExchangeValuesCommand.mapToLocalObject(results);
this.result = CompareExchangeValueResultParser_1.CompareExchangeValueResultParser.getValue(localObject, this._materializeMetadata, this._conventions, this._clazz);
return body;
}
}
exports.GetCompareExchangeValueCommand = GetCompareExchangeValueCommand;
//# sourceMappingURL=GetCompareExchangeValueOperation.js.map