ravendb
Version:
RavenDB client for Node.js
77 lines • 3.22 kB
JavaScript
import { throwError } from "../../../../Exceptions/index.js";
import { GetRequest } from "../../../Commands/MultiGet/GetRequest.js";
import { TypeUtil } from "../../../../Utility/TypeUtil.js";
import { CompareExchangeValueResultParser } from "../../../Operations/CompareExchange/CompareExchangeValueResultParser.js";
import { GetCompareExchangeValuesCommand } from "../../../Operations/CompareExchange/GetCompareExchangeValuesOperation.js";
export class LazyGetCompareExchangeValueOperation {
_clusterSession;
_clazz;
_conventions;
_key;
_result;
_requiresRetry;
constructor(clusterSession, clazz, conventions, key) {
if (!clusterSession) {
throwError("InvalidArgumentException", "Cluster Session cannot be null");
}
if (!conventions) {
throwError("InvalidArgumentException", "Conventions cannot be null");
}
if (!key) {
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() {
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.NOOP, this._clazz);
return null;
}
const request = new 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 = GetCompareExchangeValuesCommand.mapToLocalObject(results);
const value = 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.NOOP, this._clazz);
}
}
//# sourceMappingURL=LazyGetCompareExchangeValueOperation.js.map