UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

96 lines (93 loc) 2.9 kB
/** * @package @bitrix24/b24jssdk * @version 1.0.4 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ import { AbstractAction } from './abstract-action.mjs'; import { Result } from '../result.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class AbstractBatch extends AbstractAction { static { __name(this, "AbstractBatch"); } _addBatchErrorsIfAny(response, result) { if (!response.isSuccess) { for (const [index, error] of response.errors) { result.addError(error, index); } } } _processBatchResponse(response, calls, options) { const isArrayCall = Array.isArray(calls); if (options.returnAjaxResult) { return this._createBatchResultWithAjax(response, isArrayCall); } else { return this._createBatchResultSimple(response, isArrayCall); } } // region BatchResultWithAjax //// _createBatchResultWithAjax(response, isArrayCall) { return isArrayCall ? this._createBatchArrayResult(response) : this._createBatchObjectResult(response); } _createBatchArrayResult(response) { const result = new Result(); this._addBatchErrorsIfAny(response, result); const dataResult = []; for (const [_index, data] of response.getData().result) { dataResult.push(data); } return result.setData(dataResult); } _createBatchObjectResult(response) { const result = new Result(); this._addBatchErrorsIfAny(response, result); const dataResult = {}; for (const [index, data] of response.getData().result) { dataResult[index] = data; } return result.setData(dataResult); } // endregion //// // region BatchResultSimple //// _createBatchResultSimple(response, isArrayCall) { const result = new Result(); this._addBatchErrorsIfAny(response, result); return result.setData( this._extractBatchSimpleData(response, isArrayCall) ); } _extractBatchSimpleData(response, isArrayCall) { if (isArrayCall) { const dataResult = []; for (const [_index, data] of response.getData().result) { if (data.isSuccess) { dataResult.push(data.getData().result); } } return dataResult; } else { const dataResult = {}; for (const [index, data] of response.getData().result) { if (data.isSuccess) { dataResult[index] = data.getData().result; } } return dataResult; } } // endregion //// chunkArray(array, chunkSize = 50) { const result = []; for (let i = 0; i < array.length; i += chunkSize) { const chunk = array.slice(i, i + chunkSize); result.push(chunk); } return result; } } export { AbstractBatch }; //# sourceMappingURL=abstract-batch.mjs.map