@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
48 lines • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnorderedDistinctEndpointComponent = void 0;
const hashObject_js_1 = require("../../utils/hashObject.js");
const parallelQueryResult_js_1 = require("../parallelQueryResult.js");
const headerUtils_js_1 = require("../headerUtils.js");
/** @hidden */
class UnorderedDistinctEndpointComponent {
executionContext;
hashedResults;
constructor(executionContext) {
this.executionContext = executionContext;
this.hashedResults = new Set();
}
hasMoreResults() {
const result = this.executionContext.hasMoreResults();
return result;
}
async fetchMore(diagnosticNode) {
const buffer = [];
const response = await this.executionContext.fetchMore(diagnosticNode);
if (!response) {
const result = (0, parallelQueryResult_js_1.createParallelQueryResult)([], new Map(), {}, undefined);
return { result, headers: (0, headerUtils_js_1.getInitialHeader)() };
}
if (response.result === undefined ||
!Array.isArray(response.result.buffer) ||
response.result.buffer.length === 0) {
const result = (0, parallelQueryResult_js_1.createParallelQueryResult)([], new Map(), {}, undefined);
return { result, headers: response.headers };
}
const parallelResult = response.result;
const dataToProcess = parallelResult.buffer;
for (const item of dataToProcess) {
if (item) {
const hashedResult = await (0, hashObject_js_1.hashObject)(item);
if (!this.hashedResults.has(hashedResult)) {
buffer.push(item);
this.hashedResults.add(hashedResult);
}
}
}
const result = (0, parallelQueryResult_js_1.createParallelQueryResult)(buffer, new Map(), undefined, undefined);
return { result, headers: response.headers };
}
}
exports.UnorderedDistinctEndpointComponent = UnorderedDistinctEndpointComponent;
//# sourceMappingURL=UnorderedDistinctEndpointComponent.js.map