UNPKG

@azure/cosmos

Version:
57 lines 2.62 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { BaseContinuationTokenManager } from "./BaseContinuationTokenManager.js"; import { serializeCompositeToken, convertRangeMappingToQueryRange, } from "../../documents/ContinuationToken/CompositeQueryContinuationToken.js"; /** * Manages continuation tokens for parallel queries using multi-range aggregation. * Uses CompositeQueryContinuationToken for range tracking across multiple partitions. * @internal */ export class ParallelQueryContinuationTokenManager extends BaseContinuationTokenManager { processRangesForPagination(pageSize, _isResponseEmpty) { const result = this.partitionManager.processParallelRanges(pageSize); if (!result || !result.processedRangeMappings || result.processedRangeMappings.length === 0) { return { endIndex: 0, processedRanges: [] }; } const rangeMappings = result.processedRangeMappings.map((mapping) => convertRangeMappingToQueryRange(mapping)); this.updateRangeList(rangeMappings); if (result.lastPartitionBeforeCutoff && result.lastPartitionBeforeCutoff.mapping) { this.offset = result.lastPartitionBeforeCutoff.mapping.offset; this.limit = result.lastPartitionBeforeCutoff.mapping.limit; } return { endIndex: result.endIndex, processedRanges: result.processedRanges }; } getCurrentContinuationToken() { if (this.rangeList.length === 0) { return undefined; } return { rid: this.collectionLink, rangeMappings: this.rangeList, offset: this.offset, limit: this.limit, }; } getSerializationFunction() { return serializeCompositeToken; } processQuerySpecificResponse(_responseResult) { // Parallel queries don't need additional response processing } performQuerySpecificDataTrim(_processedRanges, _endIndex) { // Parallel queries don't need additional cleanup } updateRangeList(rangeMappings) { for (const newRange of rangeMappings) { const existingRangeIndex = this.rangeList.findIndex((existingRange) => existingRange.queryRange.min === newRange.queryRange.min && existingRange.queryRange.max === newRange.queryRange.max); if (existingRangeIndex >= 0) { this.rangeList[existingRangeIndex] = newRange; } else { this.rangeList.push(newRange); } } } } //# sourceMappingURL=ParallelQueryContinuationTokenManager.js.map