@configurator/ravendb
Version:
RavenDB client for Node.js
75 lines • 3.51 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyGetCompareExchangeValueOperation = void 0;
const Exceptions_1 = require("../../../../Exceptions");
const GetRequest_1 = require("../../../Commands/MultiGet/GetRequest");
const TypeUtil_1 = require("../../../../Utility/TypeUtil");
const CompareExchangeValueResultParser_1 = require("../../../Operations/CompareExchange/CompareExchangeValueResultParser");
const GetCompareExchangeValuesOperation_1 = require("../../../Operations/CompareExchange/GetCompareExchangeValuesOperation");
class LazyGetCompareExchangeValueOperation {
constructor(clusterSession, clazz, conventions, key) {
if (!clusterSession) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Cluster Session cannot be null");
}
if (!conventions) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Conventions cannot be null");
}
if (!key) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Key cannot be null");
}
this._clusterSession = clusterSession;
this._clazz = clazz;
this._conventions = conventions;
this._key = key;
}
get result() {
return this._result;
}
get queryResult() {
(0, Exceptions_1.throwError)("NotImplementedException", "Not implemented");
return null;
}
get requiresRetry() {
return this._requiresRetry;
}
createRequest() {
if (this._clusterSession.isTracked(this._key)) {
this._result = this._clusterSession.getCompareExchangeValueFromSessionInternal(this._key, TypeUtil_1.TypeUtil.NOOP, this._clazz);
return null;
}
const request = new GetRequest_1.GetRequest();
request.url = "/cmpxchg";
request.method = "GET";
request.query = "?key=" + encodeURIComponent(this._key);
return request;
}
async handleResponseAsync(response) {
if (response.forceRetry) {
this._result = null;
this._requiresRetry = true;
return;
}
if (response.result) {
const results = JSON.parse(response.result);
const localObject = GetCompareExchangeValuesOperation_1.GetCompareExchangeValuesCommand.mapToLocalObject(results);
const value = CompareExchangeValueResultParser_1.CompareExchangeValueResultParser.getValue(localObject, false, this._conventions, null);
if (this._clusterSession.session.noTracking) {
if (!value) {
this._result = this._clusterSession.registerMissingCompareExchangeValue(this._key).getValue(this._clazz, this._conventions);
return;
}
this._result = this._clusterSession.registerCompareExchangeValue(value).getValue(this._clazz, this._conventions);
return;
}
if (value) {
this._clusterSession.registerCompareExchangeValue(value);
}
}
if (!this._clusterSession.isTracked(this._key)) {
this._clusterSession.registerMissingCompareExchangeValue(this._key);
}
this._result = this._clusterSession.getCompareExchangeValueFromSessionInternal(this._key, TypeUtil_1.TypeUtil.NOOP, this._clazz);
}
}
exports.LazyGetCompareExchangeValueOperation = LazyGetCompareExchangeValueOperation;
//# sourceMappingURL=LazyGetCompareExchangeValueOperation.js.map