UNPKG

@azure/cosmos

Version:
88 lines (87 loc) 3.48 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var OffsetLimitEndpointComponent_exports = {}; __export(OffsetLimitEndpointComponent_exports, { OffsetLimitEndpointComponent: () => OffsetLimitEndpointComponent }); module.exports = __toCommonJS(OffsetLimitEndpointComponent_exports); var import_headerUtils = require("../headerUtils.js"); var import_parallelQueryResult = require("../parallelQueryResult.js"); var import_PartitionRangeUtils = require("../PartitionRangeUtils.js"); class OffsetLimitEndpointComponent { constructor(executionContext, offset, limit) { this.executionContext = executionContext; this.offset = offset; this.limit = limit; } hasMoreResults() { return (this.offset > 0 || this.limit > 0) && this.executionContext.hasMoreResults(); } async fetchMore(diagnosticNode) { const aggregateHeaders = (0, import_headerUtils.getInitialHeader)(); const buffer = []; const response = await this.executionContext.fetchMore(diagnosticNode); if (!response) { return { result: void 0, headers: aggregateHeaders }; } (0, import_headerUtils.mergeHeaders)(aggregateHeaders, response.headers); if (response.result === void 0 || !Array.isArray(response.result.buffer) || response.result.buffer.length === 0) { return { result: response.result, headers: response.headers }; } const parallelResult = response.result; const dataToProcess = parallelResult.buffer; const partitionKeyRangeMap = parallelResult.partitionKeyRangeMap; const updatedContinuationRanges = parallelResult.updatedContinuationRanges; const orderByItems = parallelResult.orderByItems; const initialOffset = this.offset; const initialLimit = this.limit; const filteredOrderByItems = []; let itemIndex = 0; for (const item of dataToProcess) { if (this.offset > 0) { this.offset--; } else if (this.limit > 0) { buffer.push(item); if (orderByItems && itemIndex < orderByItems.length) { filteredOrderByItems.push(orderByItems[itemIndex]); } this.limit--; } itemIndex++; } const updatedPartitionKeyRangeMap = (0, import_PartitionRangeUtils.calculateOffsetLimitForPartitionRanges)( partitionKeyRangeMap, initialOffset, initialLimit ); const result = (0, import_parallelQueryResult.createParallelQueryResult)( buffer, updatedPartitionKeyRangeMap, updatedContinuationRanges, filteredOrderByItems.length > 0 ? filteredOrderByItems : void 0 ); return { result, headers: aggregateHeaders }; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { OffsetLimitEndpointComponent });