cozy-client 32.2.1 → 32.2.4

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.
@@ -2550,7 +2550,7 @@ var CozyClient = /*#__PURE__*/function () {
2550
2550
  CozyClient.hooks = CozyClient.hooks || {};
2551
2551
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2552
2552
 
2553
- CozyClient.version = "32.2.1";
2553
+ CozyClient.version = "32.2.4";
2554
2554
 
2555
2555
  _microee.default.mixin(CozyClient);
2556
2556
 
@@ -120,8 +120,20 @@ var sortAndLimitDocsIds = function sortAndLimitDocsIds(queryState, documents, id
120
120
  evaluatedIds = sorter(docs).map(_helpers.properId);
121
121
  }
122
122
 
123
- if (queryState.definition.limit) {
124
- evaluatedIds = queryState.definition.limit ? evaluatedIds.slice(0, count * fetchedPagesCount) : evaluatedIds;
123
+ var limit = queryState.definition.limit;
124
+
125
+ if (limit) {
126
+ var sliceCount;
127
+
128
+ if (count < limit) {
129
+ // When there are less results than the limit, this is either the first
130
+ // or last paginated query.
131
+ sliceCount = fetchedPagesCount > 1 ? limit * (fetchedPagesCount - 1) + count : count;
132
+ } else {
133
+ sliceCount = limit * fetchedPagesCount;
134
+ }
135
+
136
+ evaluatedIds = evaluatedIds.slice(0, sliceCount);
125
137
  }
126
138
 
127
139
  return evaluatedIds;
@@ -427,4 +427,36 @@ describe('sortAndLimitDocsIds', () => {
427
427
  )
428
428
  expect(ids2).toEqual(['doc2', 'doc1'])
429
429
  })
430
+
431
+ it('should correctly handle count inferior to limit', () => {
432
+ const query1 = Q('io.cozy.files')
433
+ .sortBy([{ name: 'asc' }])
434
+ .limitBy(2)
435
+
436
+ const ids1 = sortAndLimitDocsIds(
437
+ { definition: query1.toDefinition() },
438
+ docs,
439
+ ['doc1', 'doc2'],
440
+ {
441
+ count: 1,
442
+ fetchedPagesCount: 1
443
+ }
444
+ )
445
+ expect(ids1.length).toEqual(1)
446
+
447
+ const query2 = Q('io.cozy.files')
448
+ .sortBy([{ name: 'asc' }])
449
+ .limitBy(2)
450
+
451
+ const ids2 = sortAndLimitDocsIds(
452
+ { definition: query2.toDefinition() },
453
+ docs,
454
+ ['doc1', 'doc2', 'doc3'],
455
+ {
456
+ count: 1,
457
+ fetchedPagesCount: 2
458
+ }
459
+ )
460
+ expect(ids2.length).toEqual(3)
461
+ })
430
462
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "32.2.1",
3
+ "version": "32.2.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "@types/jest": "^26.0.20",
19
19
  "@types/lodash": "^4.14.170",
20
20
  "btoa": "^1.2.1",
21
- "cozy-stack-client": "^32.2.0",
21
+ "cozy-stack-client": "^32.2.4",
22
22
  "json-stable-stringify": "^1.0.1",
23
23
  "lodash": "^4.17.13",
24
24
  "microee": "^0.0.6",
@@ -73,5 +73,5 @@
73
73
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
74
74
  },
75
75
  "sideEffects": false,
76
- "gitHead": "b6bd07dbec672e74ca16f7fff56b09c9611d841a"
76
+ "gitHead": "8ec78eb5a028f8df4908e283d0d48572d475ab3f"
77
77
  }