UNPKG

@configurator/ravendb

Version:
50 lines 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CompareExchangeResult = void 0; const Exceptions_1 = require("../../../Exceptions"); const TypeUtil_1 = require("../../../Utility/TypeUtil"); const ObjectUtil_1 = require("../../../Utility/ObjectUtil"); class CompareExchangeResult { static parseFromObject(response, conventions, clazz) { if (!response.Index) { (0, Exceptions_1.throwError)("InvalidOperationException", "Response is invalid. Index is missing"); } const val = response.Value.Object || null; return CompareExchangeResult._create(val, response.Index, response.Successful, conventions, clazz); } static _create(val, index, successful, conventions, clazz) { if (clazz) { conventions.tryRegisterJsType(clazz); } if (!val) { const emptyExchangeResult = new CompareExchangeResult(); emptyExchangeResult.index = index; emptyExchangeResult.value = null; emptyExchangeResult.successful = successful; return emptyExchangeResult; } let result = null; if (TypeUtil_1.TypeUtil.isPrimitive(val)) { result = val; } else { let rawValue = val; const entityType = conventions.getJsTypeByDocumentType(clazz); if (conventions.entityFieldNameConvention) { rawValue = ObjectUtil_1.ObjectUtil.transformObjectKeys(rawValue, { defaultTransform: conventions.entityFieldNameConvention, recursive: true, arrayRecursive: true }); } result = conventions.deserializeEntityFromJson(entityType, rawValue); } const exchangeResult = new CompareExchangeResult(); exchangeResult.index = index; exchangeResult.value = result; exchangeResult.successful = successful; return exchangeResult; } } exports.CompareExchangeResult = CompareExchangeResult; //# sourceMappingURL=CompareExchangeResult.js.map