UNPKG

@azure/cosmos

Version:
148 lines (147 loc) 6.44 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 buildChangeFeedIterator_exports = {}; __export(buildChangeFeedIterator_exports, { buildChangeFeedIterator: () => buildChangeFeedIterator }); module.exports = __toCommonJS(buildChangeFeedIterator_exports); var import_routing = require("../../routing/index.js"); var import_ChangeFeedStartFrom = require("./ChangeFeedStartFrom.js"); var import_ChangeFeedStartFromBeginning = require("./ChangeFeedStartFromBeginning.js"); var import_ChangeFeedStartFromContinuation = require("./ChangeFeedStartFromContinuation.js"); var import_ChangeFeedStartFromNow = require("./ChangeFeedStartFromNow.js"); var import_ChangeFeedStartFromTime = require("./ChangeFeedStartFromTime.js"); var import_ChangeFeedEnums = require("./ChangeFeedEnums.js"); var import_ChangeFeedForPartitionKey = require("./ChangeFeedForPartitionKey.js"); var import_request = require("../../request/index.js"); var import_ChangeFeedForEpkRange = require("./ChangeFeedForEpkRange.js"); var import_common = require("../../common/index.js"); var import_changeFeedUtils = require("./changeFeedUtils.js"); var import_typeChecks = require("../../utils/typeChecks.js"); async function buildChangeFeedIterator(cfOptions, clientContext, container, partitionKeyRangeCache) { const url = container.url; const path = (0, import_common.getPathFromLink)(url, import_common.ResourceType.item); const id = (0, import_common.getIdFromLink)(url); let changeFeedStartFrom = cfOptions.changeFeedStartFrom; if (changeFeedStartFrom === void 0) { changeFeedStartFrom = import_ChangeFeedStartFrom.ChangeFeedStartFrom.Now(); } if (changeFeedStartFrom instanceof import_ChangeFeedStartFromContinuation.ChangeFeedStartFromContinuation) { const continuationToken = changeFeedStartFrom.getCfResourceJson(); const resourceType = changeFeedStartFrom.getResourceType(); const internalCfOptions = (0, import_changeFeedUtils.buildInternalChangeFeedOptions)( cfOptions, changeFeedStartFrom.getCfResource() ); if (resourceType === import_ChangeFeedEnums.ChangeFeedResourceType.PartitionKey && (0, import_typeChecks.isPartitionKey)(continuationToken.partitionKey)) { return new import_ChangeFeedForPartitionKey.ChangeFeedForPartitionKey( clientContext, container, id, path, continuationToken.partitionKey, internalCfOptions ); } else if (resourceType === import_ChangeFeedEnums.ChangeFeedResourceType.FeedRange) { return new import_ChangeFeedForEpkRange.ChangeFeedForEpkRange( clientContext, container, partitionKeyRangeCache, id, path, url, internalCfOptions, void 0 ); } else { throw new import_request.ErrorResponse("Invalid continuation token."); } } else if (changeFeedStartFrom instanceof import_ChangeFeedStartFromNow.ChangeFeedStartFromNow || changeFeedStartFrom instanceof import_ChangeFeedStartFromTime.ChangeFeedStartFromTime || changeFeedStartFrom instanceof import_ChangeFeedStartFromBeginning.ChangeFeedStartFromBeginning) { const startFromNow = changeFeedStartFrom instanceof import_ChangeFeedStartFromNow.ChangeFeedStartFromNow ? true : false; const startTime = startFromNow ? void 0 : (0, import_changeFeedUtils.fetchStartTime)(changeFeedStartFrom); const internalCfOptions = (0, import_changeFeedUtils.buildInternalChangeFeedOptions)( cfOptions, void 0, startTime, startFromNow ); const cfResource = changeFeedStartFrom.getCfResource(); if ((0, import_typeChecks.isPartitionKey)(cfResource)) { const partitionKey = cfResource; const partitionKeyDefinition = await container.getPartitionKeyDefinition(); if (partitionKeyDefinition !== void 0 && (0, import_typeChecks.isPrefixPartitionKey)(partitionKey, partitionKeyDefinition.resource)) { const effectiveEPKRange = await (0, import_changeFeedUtils.getEPKRangeForPrefixPartitionKey)( partitionKey ); return new import_ChangeFeedForEpkRange.ChangeFeedForEpkRange( clientContext, container, partitionKeyRangeCache, id, path, url, internalCfOptions, effectiveEPKRange ); } return new import_ChangeFeedForPartitionKey.ChangeFeedForPartitionKey( clientContext, container, id, path, cfResource, internalCfOptions ); } else { let internalCfResource; if (cfResource === void 0) { internalCfResource = new import_routing.QueryRange( import_common.Constants.EffectivePartitionKeyConstants.MinimumInclusiveEffectivePartitionKey, import_common.Constants.EffectivePartitionKeyConstants.MaximumExclusiveEffectivePartitionKey, true, false ); } else if ((0, import_changeFeedUtils.isEpkRange)(cfResource)) { internalCfResource = new import_routing.QueryRange( cfResource.minInclusive, cfResource.maxExclusive, true, false ); } else { throw new import_request.ErrorResponse("Invalid feed range."); } return new import_ChangeFeedForEpkRange.ChangeFeedForEpkRange( clientContext, container, partitionKeyRangeCache, id, path, url, internalCfOptions, internalCfResource ); } } else { throw new import_request.ErrorResponse("Invalid change feed start location."); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { buildChangeFeedIterator });