@boostercloud/framework-provider-azure 3.4.3-debug.3 → 3.4.3-debug.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,28 +46,35 @@ async function search(cosmosDb, config, containerName, filters, limit, afterCurs
46
46
  });
47
47
  // Use Cosmos DB's continuation token pagination
48
48
  const feedOptions = {};
49
- if (limit) {
50
- feedOptions.maxItemCount = limit;
51
- }
49
+ // Track cumulative offset for cursor.id calculation
50
+ let cumulativeOffset = 0;
52
51
  // Extract continuation token from the cursor (backward compatibility)
53
52
  if (afterCursor === null || afterCursor === void 0 ? void 0 : afterCursor.continuationToken) {
54
53
  feedOptions.continuationToken = afterCursor.continuationToken;
54
+ // Extract cumulative id from cursor for tracking position across pages
55
+ cumulativeOffset = afterCursor.id && !isNaN(parseInt(afterCursor.id)) ? parseInt(afterCursor.id) : 0;
55
56
  logger.debug('PAGINATION DEBUG - Using provided continuation token:', {
56
57
  continuationToken: afterCursor.continuationToken,
58
+ cumulativeOffset,
57
59
  feedOptions,
58
60
  });
59
61
  }
60
- else if (!canUseContinuationToken || hasLegacyCursor) {
62
+ // Azure Cosmos DB requires maxItemCount when using continuation tokens
63
+ // Always set maxItemCount when limit is provided or when using continuation token
64
+ if (limit || (afterCursor === null || afterCursor === void 0 ? void 0 : afterCursor.continuationToken)) {
65
+ feedOptions.maxItemCount = limit !== null && limit !== void 0 ? limit : 100;
66
+ }
67
+ if (!(afterCursor === null || afterCursor === void 0 ? void 0 : afterCursor.continuationToken) && (!canUseContinuationToken || hasLegacyCursor)) {
61
68
  // Legacy cursor format - fallback to OFFSET for backward compatibility
62
69
  const offset = (afterCursor === null || afterCursor === void 0 ? void 0 : afterCursor.id) ? parseInt(afterCursor.id) : 0;
63
- let legacyQuery = `${finalQuery} OFFSET ${offset}`;
64
- if (limit) {
65
- legacyQuery += ` LIMIT ${limit} `;
66
- }
70
+ // Azure Cosmos DB requires LIMIT when using OFFSET
71
+ const effectiveLimit = limit !== null && limit !== void 0 ? limit : 100;
72
+ const legacyQuery = `${finalQuery} OFFSET ${offset} LIMIT ${effectiveLimit} `;
67
73
  const legacyQuerySpec = { ...querySpec, query: legacyQuery };
68
74
  logger.debug('PAGINATION DEBUG - Using LEGACY OFFSET/LIMIT approach:', {
69
75
  reason: !canUseContinuationToken ? 'DISTINCT query detected' : 'Legacy numeric cursor detected',
70
76
  offset,
77
+ effectiveLimit,
71
78
  legacyQuery,
72
79
  legacyQuerySpec,
73
80
  });
@@ -99,13 +106,24 @@ async function search(cosmosDb, config, containerName, filters, limit, afterCurs
99
106
  const finalResources = processResources(resources || []);
100
107
  let cursor;
101
108
  if (continuationToken) {
102
- cursor = { continuationToken };
103
- logger.debug('PAGINATION DEBUG - Setting cursor with continuation token:', cursor);
109
+ // Store both continuation token AND cumulative id for proper position tracking
110
+ const newCumulativeId = cumulativeOffset + finalResources.length;
111
+ cursor = { continuationToken, id: newCumulativeId.toString() };
112
+ logger.debug('PAGINATION DEBUG - Setting cursor with continuation token:', {
113
+ cursor,
114
+ previousOffset: cumulativeOffset,
115
+ currentPageSize: finalResources.length,
116
+ newCumulativeId,
117
+ });
104
118
  }
105
119
  else if (finalResources.length > 0) {
106
- const currentOffset = (afterCursor === null || afterCursor === void 0 ? void 0 : afterCursor.id) && !isNaN(parseInt(afterCursor.id)) ? parseInt(afterCursor.id) : 0;
107
- cursor = { id: (currentOffset + finalResources.length).toString() }; // Use the length of the results to calculate the next id
108
- logger.debug('PAGINATION DEBUG - No continuation token, setting fallback cursor:', cursor);
120
+ // Last page - use cumulative offset for final cursor position
121
+ cursor = { id: (cumulativeOffset + finalResources.length).toString() };
122
+ logger.debug('PAGINATION DEBUG - No continuation token, setting fallback cursor:', {
123
+ cursor,
124
+ previousOffset: cumulativeOffset,
125
+ currentPageSize: finalResources.length,
126
+ });
109
127
  }
110
128
  else {
111
129
  logger.debug('PAGINATION DEBUG - No continuation token and no resources, no cursor set');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boostercloud/framework-provider-azure",
3
- "version": "3.4.3-debug.3",
3
+ "version": "3.4.3-debug.5",
4
4
  "description": "Handle Booster's integration with Azure",
5
5
  "keywords": [
6
6
  "framework-provider-azure"