UNPKG

@azure/cosmos

Version:
125 lines (124 loc) • 5.6 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 ParallelQueryContinuationTokenManager_exports = {}; __export(ParallelQueryContinuationTokenManager_exports, { ParallelQueryContinuationTokenManager: () => ParallelQueryContinuationTokenManager }); module.exports = __toCommonJS(ParallelQueryContinuationTokenManager_exports); var import_BaseContinuationTokenManager = require("./BaseContinuationTokenManager.js"); var import_CompositeQueryContinuationToken = require("../../documents/ContinuationToken/CompositeQueryContinuationToken.js"); var import_PartitionRangeManager = require("../PartitionRangeManager.js"); class ParallelQueryContinuationTokenManager extends import_BaseContinuationTokenManager.BaseContinuationTokenManager { processRangesForPagination(pageSize, _isResponseEmpty, workRemains) { const result = this.partitionManager.processParallelRanges(pageSize); if (!result || !result.processedRangeMappings || result.processedRangeMappings.length === 0) { return { endIndex: 0, processedRanges: [] }; } const processedMappings = new Set(result.processedRangeMappings); const observedMappings = Array.from(this.partitionManager.getPartitionKeyRangeMap().values()); const hasUnprocessedMappings = result.processedRanges.length < this.partitionManager.getPartitionKeyRangeMap().size; const pageMappings = observedMappings.map( (mapping) => processedMappings.has(mapping) ? mapping : { ...mapping, continuationToken: mapping.previousContinuationToken, isActive: true } ); const hasActiveRange = this.rangeList.some( (mapping) => (0, import_PartitionRangeManager.isPartitionRangeActive)(mapping.continuationToken, mapping.isActive) ) || pageMappings.some( (mapping) => (0, import_PartitionRangeManager.isPartitionRangeActive)(mapping.continuationToken, mapping.isActive) ); if (!hasActiveRange && !workRemains && !hasUnprocessedMappings) { this.rangeList.length = 0; return { endIndex: result.endIndex, processedRanges: result.processedRanges }; } const rangeMappings = pageMappings.map( (mapping) => (0, import_CompositeQueryContinuationToken.convertRangeMappingToQueryRange)(mapping) ); this.updateRangeList(rangeMappings); if (result.lastPartitionBeforeCutoff && result.lastPartitionBeforeCutoff.mapping) { if (result.lastPartitionBeforeCutoff.mapping.offset !== void 0) { this.offset = result.lastPartitionBeforeCutoff.mapping.offset; } if (result.lastPartitionBeforeCutoff.mapping.limit !== void 0) { this.limit = result.lastPartitionBeforeCutoff.mapping.limit; } } return { endIndex: result.endIndex, processedRanges: result.processedRanges }; } getCurrentContinuationToken() { if (this.rangeList.length === 0) { return void 0; } return { rid: this.collectionLink, rangeMappings: this.rangeList, offset: this.offset, limit: this.limit }; } getSerializationFunction() { return import_CompositeQueryContinuationToken.serializeCompositeToken; } processQuerySpecificResponse(responseResult) { for (const mapping of responseResult.partitionKeyRangeMap.values()) { const range = (0, import_CompositeQueryContinuationToken.convertRangeMappingToQueryRange)(mapping); const existingRangeIndex = this.rangeList.findIndex( (existingRange) => existingRange.queryRange.min === range.queryRange.min && existingRange.queryRange.max === range.queryRange.max ); if (!(0, import_PartitionRangeManager.isPartitionRangeActive)(mapping.continuationToken, mapping.isActive)) { if (existingRangeIndex >= 0) { range.isActive = false; this.rangeList[existingRangeIndex] = range; } else { range.isActive = false; this.rangeList.push(range); } } else if (existingRangeIndex >= 0) { this.rangeList[existingRangeIndex] = range; } else { this.rangeList.push(range); } } } performQuerySpecificDataTrim(_processedRanges, _endIndex) { } clearQuerySpecificState() { } preserveInactiveRangeCoverage() { return true; } 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); } } } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ParallelQueryContinuationTokenManager }); //# sourceMappingURL=ParallelQueryContinuationTokenManager.js.map