@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
91 lines (90 loc) • 3.79 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 CompositeQueryContinuationToken_exports = {};
__export(CompositeQueryContinuationToken_exports, {
convertRangeMappingToQueryRange: () => convertRangeMappingToQueryRange,
convertRangeMappingsToQueryRangesWithTokens: () => convertRangeMappingsToQueryRangesWithTokens,
convertSimplifiedRangeToQueryRange: () => convertSimplifiedRangeToQueryRange,
createCompositeQueryContinuationToken: () => createCompositeQueryContinuationToken,
parseBaseContinuationToken: () => parseBaseContinuationToken,
parseCompositeQueryContinuationToken: () => parseCompositeQueryContinuationToken,
serializeCompositeToken: () => serializeCompositeToken
});
module.exports = __toCommonJS(CompositeQueryContinuationToken_exports);
var import_QueryRange = require("../../routing/QueryRange.js");
function createCompositeQueryContinuationToken(rid, rangeMappings, offset, limit) {
if (!rangeMappings || rangeMappings.length === 0) {
throw new Error(
"Failed to create composite continuation token: No partition range mappings provided. This typically indicates an issue with query execution context initialization or partition key range resolution. Ensure the query is properly configured and the container has valid partition ranges."
);
}
return {
rid,
rangeMappings,
offset,
limit
};
}
function serializeCompositeToken(token) {
return JSON.stringify(token);
}
function parseCompositeQueryContinuationToken(tokenString) {
return JSON.parse(tokenString);
}
function parseBaseContinuationToken(tokenString) {
return JSON.parse(tokenString);
}
function convertRangeMappingToQueryRange(rangeMapping) {
if (!rangeMapping.partitionKeyRange) {
throw new Error(
"Failed to convert range mapping: Missing partition key range information. The QueryRangeMapping object must contain a valid partitionKeyRange with min and max boundaries. This may indicate an incomplete partition key range resolution during query setup."
);
}
const pkRange = rangeMapping.partitionKeyRange;
const simplifiedRange = {
min: pkRange.minInclusive,
max: pkRange.maxExclusive
};
return {
queryRange: simplifiedRange,
continuationToken: rangeMapping.continuationToken
};
}
function convertRangeMappingsToQueryRangesWithTokens(rangeMappings) {
return rangeMappings.map((mapping) => convertRangeMappingToQueryRange(mapping));
}
function convertSimplifiedRangeToQueryRange(simplifiedRange) {
return new import_QueryRange.QueryRange(
simplifiedRange.min,
simplifiedRange.max,
true,
// minInclusive = true (assumption)
false
// maxInclusive = false (max is exclusive, assumption)
);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
convertRangeMappingToQueryRange,
convertRangeMappingsToQueryRangesWithTokens,
convertSimplifiedRangeToQueryRange,
createCompositeQueryContinuationToken,
parseBaseContinuationToken,
parseCompositeQueryContinuationToken,
serializeCompositeToken
});