UNPKG

@azure/cosmos

Version:
98 lines (97 loc) 3.23 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 QueryRange_exports = {}; __export(QueryRange_exports, { QueryRange: () => QueryRange }); module.exports = __toCommonJS(QueryRange_exports); var import_common = require("../common/index.js"); class QueryRange { min; max; isMinInclusive; isMaxInclusive; /** * Represents a QueryRange. * * @param rangeMin - min * @param rangeMin - max * @param isMinInclusive - isMinInclusive * @param isMaxInclusive - isMaxInclusive * @hidden */ constructor(rangeMin, rangeMax, isMinInclusive, isMaxInclusive) { this.min = rangeMin; this.max = rangeMax; this.isMinInclusive = isMinInclusive; this.isMaxInclusive = isMaxInclusive; } overlaps(other) { const range1 = this; const range2 = other; if (range1 === void 0 || range2 === void 0) { return false; } if (range1.isEmpty() || range2.isEmpty()) { return false; } if (range1.min <= range2.max || range2.min <= range1.max) { if (range1.min === range2.max && !(range1.isMinInclusive && range2.isMaxInclusive) || range2.min === range1.max && !(range2.isMinInclusive && range1.isMaxInclusive)) { return false; } return true; } return false; } isFullRange() { return this.min === import_common.Constants.EffectivePartitionKeyConstants.MinimumInclusiveEffectivePartitionKey && this.max === import_common.Constants.EffectivePartitionKeyConstants.MaximumExclusiveEffectivePartitionKey && this.isMinInclusive === true && this.isMaxInclusive === false; } isEmpty() { return !(this.isMinInclusive && this.isMaxInclusive) && this.min === this.max; } /** * Parse a QueryRange from a partitionKeyRange * @returns QueryRange * @hidden */ static parsePartitionKeyRange(partitionKeyRange) { return new QueryRange( partitionKeyRange[import_common.Constants.PartitionKeyRange.MinInclusive], partitionKeyRange[import_common.Constants.PartitionKeyRange.MaxExclusive], true, false ); } /** * Parse a QueryRange from a dictionary * @returns QueryRange * @hidden */ static parseFromDict(queryRangeDict) { return new QueryRange( queryRangeDict.min, queryRangeDict.max, queryRangeDict.isMinInclusive, queryRangeDict.isMaxInclusive ); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { QueryRange });