cozy-client 32.6.0 → 32.7.2

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.
@@ -2571,7 +2571,7 @@ var CozyClient = /*#__PURE__*/function () {
2571
2571
  CozyClient.hooks = CozyClient.hooks || {};
2572
2572
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2573
2573
 
2574
- CozyClient.version = "32.6.0";
2574
+ CozyClient.version = "32.7.2";
2575
2575
 
2576
2576
  _microee.default.mixin(CozyClient);
2577
2577
 
package/dist/StackLink.js CHANGED
@@ -45,6 +45,24 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
45
45
 
46
46
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
47
47
 
48
+ /**
49
+ *
50
+ * To know if cozy-client should use Document.find()
51
+ * or Document.all()
52
+ * Similar to what is done in CozyPouchLink executeQuery()
53
+ *
54
+ * @param {QueryDefinition} queryDefinition - QueryDefinition to check
55
+ * @returns {boolean} If has find options
56
+ *
57
+ */
58
+ var hasFindOptions = function hasFindOptions(queryDefinition) {
59
+ var selector = queryDefinition.selector,
60
+ partialFilter = queryDefinition.partialFilter,
61
+ sort = queryDefinition.sort,
62
+ fields = queryDefinition.fields;
63
+ if (selector || partialFilter || sort || fields) return true;
64
+ return false;
65
+ };
48
66
  /**
49
67
  * Returns full documents after a bulk update
50
68
  *
@@ -54,6 +72,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
54
72
  * @param {CozyClientDocument[]} originalDocuments - Documents that were updated
55
73
  * @returns {{ data: CozyClientDocument[] }} - Full documents with updated _id and _rev
56
74
  */
75
+
76
+
57
77
  var transformBulkDocsResponse = function transformBulkDocsResponse(bulkResponse, originalDocuments) {
58
78
  var updatedDocs = (0, _zipWith.default)(bulkResponse, originalDocuments, function (result, od) {
59
79
  return result.ok ? _objectSpread(_objectSpread({}, od), {}, {
@@ -126,6 +146,12 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
126
146
 
127
147
  return this.executeQuery(operation);
128
148
  }
149
+ /**
150
+ *
151
+ * @param {QueryDefinition} query - Query to execute
152
+ * @returns {Promise<ClientResponse>}
153
+ */
154
+
129
155
  }, {
130
156
  key: "executeQuery",
131
157
  value: function executeQuery(query) {
@@ -155,7 +181,11 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
155
181
  return collection.findReferencedBy(referenced, options);
156
182
  }
157
183
 
158
- return !selector && !options.sort ? collection.all(options) : collection.find(selector, options);
184
+ if (hasFindOptions(query)) {
185
+ return collection.find(selector, options);
186
+ } else {
187
+ return collection.all(options);
188
+ }
159
189
  }
160
190
  }, {
161
191
  key: "executeMutation",
@@ -46,6 +46,22 @@ describe('StackLink', () => {
46
46
  expect(stackClient.collection().all).toHaveBeenCalled()
47
47
  expect(stackClient.collection).toHaveBeenCalledWith('io.cozy.todos')
48
48
  })
49
+
50
+ it('should use find if a partialFilter is given', async () => {
51
+ const query = Q('io.cozy.todos').partialIndex({ trashed: false })
52
+ stackClient.collection().find.mockReset()
53
+ await link.request(query)
54
+ expect(stackClient.collection().find).toHaveBeenCalled()
55
+ expect(stackClient.collection).toHaveBeenCalledWith('io.cozy.todos')
56
+ })
57
+
58
+ it('should use find if fields are given', async () => {
59
+ const query = Q('io.cozy.todos').select(['trashed'])
60
+ stackClient.collection().find.mockReset()
61
+ await link.request(query)
62
+ expect(stackClient.collection().find).toHaveBeenCalled()
63
+ expect(stackClient.collection).toHaveBeenCalledWith('io.cozy.todos')
64
+ })
49
65
  })
50
66
 
51
67
  describe('reset', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "32.6.0",
3
+ "version": "32.7.2",
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.6.0",
21
+ "cozy-stack-client": "^32.7.1",
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": "317b8ddc16d21e825aa6e924ab2f8b26c19bb1a3"
76
+ "gitHead": "d3e04d99152e605270d6a387b1b709411587e0f2"
77
77
  }
@@ -17,9 +17,16 @@ export default class StackLink extends CozyLink {
17
17
  stackClient: any;
18
18
  registerClient(client: any): void;
19
19
  reset(): void;
20
- executeQuery(query: any): any;
20
+ /**
21
+ *
22
+ * @param {QueryDefinition} query - Query to execute
23
+ * @returns {Promise<ClientResponse>}
24
+ */
25
+ executeQuery(query: QueryDefinition): Promise<ClientResponse>;
21
26
  executeMutation(mutation: any, result: any, forward: any): Promise<any>;
22
27
  }
23
28
  import { CouchDBBulkResult } from "./types";
24
29
  import { CozyClientDocument } from "./types";
25
30
  import CozyLink from "./CozyLink";
31
+ import { QueryDefinition } from "./queries/dsl";
32
+ import { ClientResponse } from "./types";