UNPKG

@azure/cosmos

Version:
76 lines (75 loc) 3.04 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 OrderedDistinctEndpointComponent_exports = {}; __export(OrderedDistinctEndpointComponent_exports, { OrderedDistinctEndpointComponent: () => OrderedDistinctEndpointComponent }); module.exports = __toCommonJS(OrderedDistinctEndpointComponent_exports); var import_hashObject = require("../../utils/hashObject.js"); var import_parallelQueryResult = require("../parallelQueryResult.js"); var import_PartitionRangeUtils = require("../PartitionRangeUtils.js"); class OrderedDistinctEndpointComponent { constructor(executionContext, hashedLastResult) { this.executionContext = executionContext; this.hashedLastResult = hashedLastResult; } hashedLastResult; hasMoreResults() { return this.executionContext.hasMoreResults(); } async fetchMore(diagnosticNode) { const buffer = []; const response = await this.executionContext.fetchMore(diagnosticNode); if (!response || !response.result || !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; for (const item of dataToProcess) { if (item) { const hashedResult = await (0, import_hashObject.hashObject)(item); if (hashedResult !== this.hashedLastResult) { buffer.push(item); this.hashedLastResult = hashedResult; } } } const updatedPartitionKeyRangeMap = await (0, import_PartitionRangeUtils.processDistinctQueryAndUpdateRangeMap)( dataToProcess, partitionKeyRangeMap, import_hashObject.hashObject ); const result = (0, import_parallelQueryResult.createParallelQueryResult)( buffer, updatedPartitionKeyRangeMap, updatedContinuationRanges, orderByItems ); return { result, headers: response.headers }; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { OrderedDistinctEndpointComponent });