@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
93 lines (92 loc) • 4.08 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 logicalPartitionRange_exports = {};
__export(logicalPartitionRange_exports, {
getLogicalPartitionRange: () => getLogicalPartitionRange,
getUncoveredPartitionKeyRanges: () => getUncoveredPartitionKeyRanges,
intersectPartitionKeyRange: () => intersectPartitionKeyRange,
intersectPartitionKeyRanges: () => intersectPartitionKeyRanges,
isPartitionRangeBounded: () => isPartitionRangeBounded,
toEffectivePartitionKeyRange: () => toEffectivePartitionKeyRange
});
module.exports = __toCommonJS(logicalPartitionRange_exports);
function getLogicalPartitionRange(partitionKeyRange, minInclusive, maxExclusive) {
return {
partitionKeyRange,
minInclusive: minInclusive ?? partitionKeyRange.minInclusive,
maxExclusive: maxExclusive ?? partitionKeyRange.maxExclusive
};
}
function intersectPartitionKeyRange(partitionKeyRange, minInclusive, maxExclusive) {
const intersectionMin = partitionKeyRange.minInclusive > minInclusive ? partitionKeyRange.minInclusive : minInclusive;
const intersectionMax = partitionKeyRange.maxExclusive < maxExclusive ? partitionKeyRange.maxExclusive : maxExclusive;
if (intersectionMin >= intersectionMax) {
return void 0;
}
return getLogicalPartitionRange(partitionKeyRange, intersectionMin, intersectionMax);
}
function intersectPartitionKeyRanges(partitionKeyRanges, minInclusive, maxExclusive) {
return partitionKeyRanges.map(
(partitionKeyRange) => intersectPartitionKeyRange(partitionKeyRange, minInclusive, maxExclusive)
).filter((range) => !!range);
}
function getUncoveredPartitionKeyRanges(partitionKeyRanges, coveredRanges, minInclusive, maxExclusive) {
const sortedCoveredRanges = [...coveredRanges].map((range) => ({
minInclusive: range.minInclusive < minInclusive ? minInclusive : range.minInclusive,
maxExclusive: range.maxExclusive > maxExclusive ? maxExclusive : range.maxExclusive
})).filter((range) => range.minInclusive < range.maxExclusive).sort((left, right) => left.minInclusive.localeCompare(right.minInclusive));
const uncoveredRanges = [];
let cursor = minInclusive;
for (const range of sortedCoveredRanges) {
if (cursor < range.minInclusive) {
uncoveredRanges.push(
...intersectPartitionKeyRanges(partitionKeyRanges, cursor, range.minInclusive)
);
}
if (range.maxExclusive > cursor) {
cursor = range.maxExclusive;
}
}
if (cursor < maxExclusive) {
uncoveredRanges.push(...intersectPartitionKeyRanges(partitionKeyRanges, cursor, maxExclusive));
}
return uncoveredRanges;
}
function isPartitionRangeBounded(range) {
return range.minInclusive !== range.partitionKeyRange.minInclusive || range.maxExclusive !== range.partitionKeyRange.maxExclusive;
}
function toEffectivePartitionKeyRange(range) {
if (!isPartitionRangeBounded(range)) {
return range.partitionKeyRange;
}
return {
...range.partitionKeyRange,
minInclusive: range.minInclusive,
maxExclusive: range.maxExclusive
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getLogicalPartitionRange,
getUncoveredPartitionKeyRanges,
intersectPartitionKeyRange,
intersectPartitionKeyRanges,
isPartitionRangeBounded,
toEffectivePartitionKeyRange
});
//# sourceMappingURL=logicalPartitionRange.js.map