UNPKG

@azure/cosmos

Version:
66 lines • 2.84 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. /** @hidden */ export function getLogicalPartitionRange(partitionKeyRange, minInclusive, maxExclusive) { return { partitionKeyRange, minInclusive: minInclusive ?? partitionKeyRange.minInclusive, maxExclusive: maxExclusive ?? partitionKeyRange.maxExclusive, }; } /** @hidden */ export 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 undefined; } return getLogicalPartitionRange(partitionKeyRange, intersectionMin, intersectionMax); } /** @hidden */ export function intersectPartitionKeyRanges(partitionKeyRanges, minInclusive, maxExclusive) { return partitionKeyRanges .map((partitionKeyRange) => intersectPartitionKeyRange(partitionKeyRange, minInclusive, maxExclusive)) .filter((range) => !!range); } /** @hidden */ export 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; } /** @hidden */ export function isPartitionRangeBounded(range) { return (range.minInclusive !== range.partitionKeyRange.minInclusive || range.maxExclusive !== range.partitionKeyRange.maxExclusive); } /** @hidden */ export function toEffectivePartitionKeyRange(range) { if (!isPartitionRangeBounded(range)) { return range.partitionKeyRange; } return { ...range.partitionKeyRange, minInclusive: range.minInclusive, maxExclusive: range.maxExclusive, }; } //# sourceMappingURL=logicalPartitionRange.js.map