ravendb
Version:
RavenDB client for Node.js
81 lines • 3.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyGetCompareExchangeValueOperation = void 0;
const index_js_1 = require("../../../../Exceptions/index.js");
const GetRequest_js_1 = require("../../../Commands/MultiGet/GetRequest.js");
const TypeUtil_js_1 = require("../../../../Utility/TypeUtil.js");
const CompareExchangeValueResultParser_js_1 = require("../../../Operations/CompareExchange/CompareExchangeValueResultParser.js");
const GetCompareExchangeValuesOperation_js_1 = require("../../../Operations/CompareExchange/GetCompareExchangeValuesOperation.js");
class LazyGetCompareExchangeValueOperation {
_clusterSession;
_clazz;
_conventions;
_key;
_result;
_requiresRetry;
constructor(clusterSession, clazz, conventions, key) {
if (!clusterSession) {
(0, index_js_1.throwError)("InvalidArgumentException", "Cluster Session cannot be null");
}
if (!conventions) {
(0, index_js_1.throwError)("InvalidArgumentException", "Conventions cannot be null");
}
if (!key) {
(0, index_js_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, index_js_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_js_1.TypeUtil.NOOP, this._clazz);
return null;
}
const request = new GetRequest_js_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_js_1.GetCompareExchangeValuesCommand.mapToLocalObject(results);
const value = CompareExchangeValueResultParser_js_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_js_1.TypeUtil.NOOP, this._clazz);
}
}
exports.LazyGetCompareExchangeValueOperation = LazyGetCompareExchangeValueOperation;
//# sourceMappingURL=LazyGetCompareExchangeValueOperation.js.map