UNPKG

ravendb

Version:
125 lines 5.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LazyGetCompareExchangeValuesOperation = void 0; const index_js_1 = require("../../../../Exceptions/index.js"); const TypeUtil_js_1 = require("../../../../Utility/TypeUtil.js"); const GetRequest_js_1 = require("../../../Commands/MultiGet/GetRequest.js"); const StringUtil_js_1 = require("../../../../Utility/StringUtil.js"); const CompareExchangeValueResultParser_js_1 = require("../../../Operations/CompareExchange/CompareExchangeValueResultParser.js"); const StringBuilder_js_1 = require("../../../../Utility/StringBuilder.js"); const GetCompareExchangeValuesOperation_js_1 = require("../../../Operations/CompareExchange/GetCompareExchangeValuesOperation.js"); class LazyGetCompareExchangeValuesOperation { _clusterSession; _clazz; _conventions; _startsWith; _start; _pageSize; _keys; _result; _requiresRetry; constructor(clusterSession, clazz, conventions, keysOrStartsWith, start, pageSize) { if (!clusterSession) { (0, index_js_1.throwError)("InvalidArgumentException", "ClusterSession cannot be null"); } if (!conventions) { (0, index_js_1.throwError)("InvalidArgumentException", "Conventions cannot be null"); } this._clusterSession = clusterSession; this._clazz = clazz; this._conventions = conventions; if (TypeUtil_js_1.TypeUtil.isArray(keysOrStartsWith)) { this._keys = keysOrStartsWith; this._start = 0; this._pageSize = 0; this._startsWith = null; } else { this._startsWith = keysOrStartsWith; this._start = start; this._pageSize = pageSize; this._keys = null; } } get result() { return this._result; } get queryResult() { (0, index_js_1.throwError)("NotImplementedException"); return null; } get requiresRetry() { return this._requiresRetry; } createRequest() { let pathBuilder; if (this._keys) { for (const key of this._keys) { if (this._clusterSession.isTracked(key)) { continue; } if (!pathBuilder) { pathBuilder = new StringBuilder_js_1.StringBuilder("?"); } pathBuilder.append("&key=").append(encodeURIComponent(key)); } } else { pathBuilder = new StringBuilder_js_1.StringBuilder("?"); if (StringUtil_js_1.StringUtil.isNullOrEmpty(this._startsWith)) { pathBuilder.append("&startsWith=").append(encodeURIComponent(this._startsWith)); } pathBuilder.append("&start=").append((this._start || 0).toString()); pathBuilder.append("&pageSize=").append((this._pageSize || 0).toString()); } if (!pathBuilder) { this._result = this._clusterSession.getCompareExchangeValuesFromSessionInternal(this._keys, TypeUtil_js_1.TypeUtil.NOOP, this._clazz); return null; } const request = new GetRequest_js_1.GetRequest(); request.url = "/cmpxchg"; request.method = "GET"; request.query = pathBuilder.toString(); 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); if (this._clusterSession.session.noTracking) { const result = {}; for (const kvp of Object.entries(CompareExchangeValueResultParser_js_1.CompareExchangeValueResultParser.getValues(localObject, false, this._conventions))) { if (!kvp[1].value) { result[kvp[0]] = this._clusterSession.registerMissingCompareExchangeValue(kvp[0]).getValue(this._clazz, this._conventions); continue; } result[kvp[0]] = this._clusterSession.registerCompareExchangeValue(kvp[1]).getValue(this._clazz, this._conventions); } this._result = result; return; } for (const kvp of Object.entries(CompareExchangeValueResultParser_js_1.CompareExchangeValueResultParser.getValues(localObject, false, this._conventions))) { if (!kvp[1]) { continue; } this._clusterSession.registerCompareExchangeValue(kvp[1]); } } if (this._keys) { for (const key of this._keys) { if (this._clusterSession.isTracked(key)) { continue; } this._clusterSession.registerMissingCompareExchangeValue(key); } } this._result = this._clusterSession.getCompareExchangeValuesFromSessionInternal(this._keys, TypeUtil_js_1.TypeUtil.NOOP, this._clazz); } } exports.LazyGetCompareExchangeValuesOperation = LazyGetCompareExchangeValuesOperation; //# sourceMappingURL=LazyGetCompareExchangeValuesOperation.js.map