UNPKG

ravendb

Version:
121 lines 4.91 kB
import { throwError } from "../../../../Exceptions/index.js"; import { TypeUtil } from "../../../../Utility/TypeUtil.js"; import { GetRequest } from "../../../Commands/MultiGet/GetRequest.js"; import { StringUtil } from "../../../../Utility/StringUtil.js"; import { CompareExchangeValueResultParser } from "../../../Operations/CompareExchange/CompareExchangeValueResultParser.js"; import { StringBuilder } from "../../../../Utility/StringBuilder.js"; import { GetCompareExchangeValuesCommand } from "../../../Operations/CompareExchange/GetCompareExchangeValuesOperation.js"; export class LazyGetCompareExchangeValuesOperation { _clusterSession; _clazz; _conventions; _startsWith; _start; _pageSize; _keys; _result; _requiresRetry; constructor(clusterSession, clazz, conventions, keysOrStartsWith, start, pageSize) { if (!clusterSession) { throwError("InvalidArgumentException", "ClusterSession cannot be null"); } if (!conventions) { throwError("InvalidArgumentException", "Conventions cannot be null"); } this._clusterSession = clusterSession; this._clazz = clazz; this._conventions = conventions; if (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() { 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("?"); } pathBuilder.append("&key=").append(encodeURIComponent(key)); } } else { pathBuilder = new StringBuilder("?"); if (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.NOOP, this._clazz); return null; } const request = new 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 = GetCompareExchangeValuesCommand.mapToLocalObject(results); if (this._clusterSession.session.noTracking) { const result = {}; for (const kvp of Object.entries(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.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.NOOP, this._clazz); } } //# sourceMappingURL=LazyGetCompareExchangeValuesOperation.js.map