@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
86 lines (82 loc) • 2.74 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 2.2.0
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
;
const sdkError = require('../../sdk-error.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
function assertArrayFilter(filter, action) {
if (filter === void 0 || Array.isArray(filter)) {
return;
}
throw new sdkError.SdkError({
code: "JSSDK_ACTION_V3_LIST_FILTER_NOT_ARRAY",
description: `${action}: \`filter\` must be the restApi:v3 array form, e.g. [['id', '>', 100]] or FilterV3.build(...). The restApi:v2 object dialect ({ '>id': 100 }) cannot be used here, because keyset pagination extends the filter with a cursor condition.`,
status: 500
});
}
__name(assertArrayFilter, "assertArrayFilter");
class KeysetPaginationError extends Error {
static {
__name(this, "KeysetPaginationError");
}
errors;
messages;
constructor(errors, messages) {
super(messages.join("; "));
this.name = "KeysetPaginationError";
this.errors = errors;
this.messages = messages;
}
}
async function* keysetPaginate(b24, logger, strategy) {
let cursor = strategy.initialCursor;
let maxPageSize = 0;
while (true) {
const response = await b24.actions.v3.call.make({
method: strategy.method,
params: strategy.buildParams(cursor),
requestId: strategy.requestId
});
if (!response.isSuccess) {
logger.error(strategy.errorLabel, {
method: strategy.method,
requestId: strategy.requestId,
messages: response.getErrorMessages()
}).catch(() => {
});
throw new KeysetPaginationError(response.errors, response.getErrorMessages());
}
const responseData = response.getData();
if (!responseData) {
break;
}
const resultData = responseData.result[strategy.customKeyForResult];
if (!Array.isArray(resultData) || resultData.length === 0) {
break;
}
yield resultData;
maxPageSize = Math.max(maxPageSize, resultData.length);
if (resultData.length < maxPageSize) {
break;
}
const lastItem = resultData[resultData.length - 1];
const next = lastItem ? strategy.readNextCursor(lastItem) : null;
if (next === null || next === void 0) {
logger.warning(strategy.noCursorWarning).catch(() => {
});
break;
}
cursor = next;
}
}
__name(keysetPaginate, "keysetPaginate");
exports.KeysetPaginationError = KeysetPaginationError;
exports.assertArrayFilter = assertArrayFilter;
exports.keysetPaginate = keysetPaginate;
//# sourceMappingURL=_keyset-paginate.cjs.map