@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
102 lines (101 loc) • 3.39 kB
JavaScript
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 ParallelQueryRangeStrategy_exports = {};
__export(ParallelQueryRangeStrategy_exports, {
ParallelQueryRangeStrategy: () => ParallelQueryRangeStrategy
});
module.exports = __toCommonJS(ParallelQueryRangeStrategy_exports);
var import_PartitionRangeManager = require("../PartitionRangeManager.js");
class ParallelQueryRangeStrategy {
getStrategyType() {
return "ParallelQuery";
}
validateContinuationToken(continuationToken) {
if (!continuationToken) {
return false;
}
try {
const parsed = JSON.parse(continuationToken);
if (!parsed || !Array.isArray(parsed.rangeMappings)) {
return false;
}
for (const rangeMapping of parsed.rangeMappings) {
if (!rangeMapping || !rangeMapping.partitionKeyRange) {
return false;
}
}
return true;
} catch {
return false;
}
}
filterPartitionRanges(targetRanges, continuationRanges) {
if (!targetRanges || targetRanges.length === 0) {
return { rangeTokenPairs: [] };
}
if (!continuationRanges || continuationRanges.length === 0) {
const rangeTokenPairs2 = targetRanges.map((range) => ({
range,
continuationToken: void 0,
filteringCondition: void 0
}));
return { rangeTokenPairs: rangeTokenPairs2 };
}
const rangeTokenPairs = [];
let lastProcessedRange = null;
continuationRanges.sort((a, b) => {
return a.range.minInclusive.localeCompare(b.range.minInclusive);
});
for (const range of continuationRanges) {
lastProcessedRange = range.range;
if (range && !(0, import_PartitionRangeManager.isPartitionExhausted)(range.continuationToken)) {
rangeTokenPairs.push({
range: range.range,
continuationToken: range.continuationToken,
filteringCondition: range.filteringCondition
});
}
}
if (lastProcessedRange) {
for (const targetRange of targetRanges) {
if (targetRange.minInclusive >= lastProcessedRange.maxExclusive) {
rangeTokenPairs.push({
range: targetRange,
continuationToken: void 0,
filteringCondition: void 0
});
}
}
} else {
for (const targetRange of targetRanges) {
rangeTokenPairs.push({
range: targetRange,
continuationToken: void 0,
filteringCondition: void 0
});
}
}
return {
rangeTokenPairs
};
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ParallelQueryRangeStrategy
});