contentful-export 7.19.158 → 7.19.159

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.
@@ -178,41 +178,54 @@ function pagedGet({
178
178
  aggregatedResponse = null,
179
179
  query = null
180
180
  }) {
181
- let queryLimit = query && query.limit;
182
- if (queryLimit && aggregatedResponse) {
183
- if (skip + pageLimit > queryLimit) {
184
- // this means the total we are about to fetch is > our limit
185
- queryLimit = queryLimit % pageLimit;
186
- }
187
- }
188
- const fullQuery = Object.assign({}, {
181
+ const userQueryLimit = query && query.limit;
182
+ const fetchedTotal = aggregatedResponse && aggregatedResponse.items.length;
183
+ const limit = userQueryLimit ? Math.min(pageLimit, userQueryLimit - fetchedTotal) : pageLimit;
184
+ const requestQuery = Object.assign({}, {
189
185
  skip,
190
186
  order: 'sys.createdAt,sys.id'
191
187
  }, query, {
192
- limit: queryLimit && queryLimit < pageLimit ? queryLimit : pageLimit
188
+ limit
193
189
  });
194
- return source[method](fullQuery).then(response => {
190
+ return source[method](requestQuery).then(response => {
195
191
  if (!aggregatedResponse) {
196
192
  aggregatedResponse = response;
197
193
  } else {
198
194
  aggregatedResponse.items = aggregatedResponse.items.concat(response.items);
199
195
  }
200
- const total = queryLimit && queryLimit < response.total ? queryLimit : response.total;
201
- const page = Math.ceil(skip / pageLimit) + 1;
202
- const pages = Math.ceil(total / pageLimit);
203
- _contentfulBatchLibs.logEmitter.emit('info', `Fetched ${aggregatedResponse.items.length} of ${total} items (Page ${page}/${pages})`);
204
- if (skip + pageLimit < total) {
205
- return pagedGet({
206
- source,
207
- method,
208
- skip: skip + pageLimit,
209
- aggregatedResponse,
210
- query
211
- });
196
+ const totalItemsLength = aggregatedResponse.items.length;
197
+ const total = response.total;
198
+ logPagingStatus(response, requestQuery, userQueryLimit);
199
+ const gotAllQueryLimitedItems = userQueryLimit && totalItemsLength >= userQueryLimit;
200
+ const gotAllItems = totalItemsLength >= total;
201
+ const gotNoItems = totalItemsLength <= 0;
202
+ if (gotAllQueryLimitedItems || gotAllItems || gotNoItems) {
203
+ return aggregatedResponse;
212
204
  }
213
- return aggregatedResponse;
205
+ return pagedGet({
206
+ source,
207
+ method,
208
+ skip: skip + response.items.length,
209
+ aggregatedResponse,
210
+ query
211
+ });
214
212
  });
215
213
  }
214
+ function logPagingStatus(response, requestQuery, userLimit) {
215
+ const {
216
+ total,
217
+ limit,
218
+ items
219
+ } = response;
220
+ const pagedItemsLength = items.length;
221
+
222
+ // sometimes our pageLimit or queryLimit of 1000 is overridden by the API (like in locales)
223
+ const imposedLimit = limit || requestQuery.limit;
224
+ const limitedTotal = userLimit ? Math.min(userLimit, total) : total;
225
+ const page = Math.ceil(requestQuery.skip / imposedLimit) + 1;
226
+ const pages = Math.ceil(limitedTotal / imposedLimit);
227
+ _contentfulBatchLibs.logEmitter.emit('info', `Fetched ${pagedItemsLength} of ${total} items (Page ${page}/${pages})`);
228
+ }
216
229
  function extractItems(response) {
217
230
  return response.items;
218
231
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentful-export",
3
- "version": "7.19.158",
3
+ "version": "7.19.159",
4
4
  "description": "this tool allows you to export a space to a JSON dump",
5
5
  "main": "dist/index.js",
6
6
  "types": "types.d.ts",
@@ -46,9 +46,9 @@
46
46
  "bfj": "^8.0.0",
47
47
  "bluebird": "^3.3.3",
48
48
  "cli-table3": "^0.6.0",
49
- "contentful": "^11.0.3",
49
+ "contentful": "^11.1.4",
50
50
  "contentful-batch-libs": "^9.4.1",
51
- "contentful-management": "^11.0.1",
51
+ "contentful-management": "^11.36.0",
52
52
  "date-fns": "^4.1.0",
53
53
  "figures": "^3.2.0",
54
54
  "jsonwebtoken": "^9.0.0",