cozy-client 29.2.0 → 30.0.0

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 = "29.2.0";
2553
+ CozyClient.version = "30.0.0";
2554
2554
 
2555
2555
  _microee.default.mixin(CozyClient);
2556
2556
 
@@ -29,6 +29,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
29
29
  * @property {Array} [indexedFields]
30
30
  * @property {Array} [sort]
31
31
  * @property {object} [selector]
32
+ * @property {object} [partialFilter]
33
+ * @property {Array} [fields]
32
34
  */
33
35
 
34
36
  /**
@@ -155,6 +157,42 @@ var QueryDefinition = /*#__PURE__*/function () {
155
157
  console.info("The use of the $ne operator is more efficient with a partial index.\n\n Selector: ".concat(selector));
156
158
  }
157
159
  }
160
+ /**
161
+ * Check if the selected fields are all included in the selectors
162
+ *
163
+ * @param {PartialQueryDefinition} obj - A partial QueryDefinition to check
164
+ */
165
+
166
+ }, {
167
+ key: "checkSelectFields",
168
+ value: function checkSelectFields(_ref2) {
169
+ var fields = _ref2.fields,
170
+ selector = _ref2.selector,
171
+ partialFilter = _ref2.partialFilter;
172
+
173
+ var _fields = this.fields || fields;
174
+
175
+ var _selector = this.selector || selector;
176
+
177
+ var _partialFilter = this.partialFilter || partialFilter;
178
+
179
+ if (!_fields || !_selector && !_partialFilter) {
180
+ return;
181
+ }
182
+
183
+ var mergedSelector = _objectSpread(_objectSpread({}, _selector), _partialFilter);
184
+
185
+ var selectorAttributes = Object.keys(mergedSelector);
186
+ var hasEveryFieldsInSelector = selectorAttributes.every(function (attribute) {
187
+ return _fields.includes(attribute);
188
+ });
189
+
190
+ if (!hasEveryFieldsInSelector) {
191
+ throw new Error("The .select should includes all the fields used in where or partialIndex.\n Please fix this query: fields: ".concat(JSON.stringify(this.toDefinition())));
192
+ }
193
+
194
+ return;
195
+ }
158
196
  /**
159
197
  * Query a single document on its id.
160
198
  *
@@ -202,6 +240,9 @@ var QueryDefinition = /*#__PURE__*/function () {
202
240
  selector: selector
203
241
  });
204
242
  this.checkSelector(selector);
243
+ this.checkSelectFields({
244
+ selector: selector
245
+ });
205
246
  return new QueryDefinition(_objectSpread(_objectSpread({}, this.toDefinition()), {}, {
206
247
  selector: selector
207
248
  }));
@@ -216,6 +257,9 @@ var QueryDefinition = /*#__PURE__*/function () {
216
257
  }, {
217
258
  key: "select",
218
259
  value: function select(fields) {
260
+ this.checkSelectFields({
261
+ fields: fields
262
+ });
219
263
  return new QueryDefinition(_objectSpread(_objectSpread({}, this.toDefinition()), {}, {
220
264
  fields: fields
221
265
  }));
@@ -250,6 +294,9 @@ var QueryDefinition = /*#__PURE__*/function () {
250
294
  }, {
251
295
  key: "partialIndex",
252
296
  value: function partialIndex(partialFilter) {
297
+ this.checkSelectFields({
298
+ partialFilter: partialFilter
299
+ });
253
300
  return new QueryDefinition(_objectSpread(_objectSpread({}, this.toDefinition()), {}, {
254
301
  partialFilter: partialFilter
255
302
  }));
@@ -107,4 +107,43 @@ describe('QueryDefinition', () => {
107
107
  Q('io.cozy.files').where({ _id: { $ne: 'io.cozy.root-id' } })
108
108
  expect(console.info).toHaveBeenCalledTimes(1)
109
109
  })
110
+
111
+ it('should throw an error when there is a select without all the fields in selector', () => {
112
+ const query = () =>
113
+ Q('io.cozy.files')
114
+ .where({ name: 'saymyname' })
115
+ .select(['size'])
116
+ expect(() => query()).toThrow()
117
+ })
118
+ it('should throw an error when there is a select without all the fields in partial index', () => {
119
+ const query = () =>
120
+ Q('io.cozy.files')
121
+ .where({ size: 42 })
122
+ .partialIndex({ name: { $exists: true } })
123
+ .select(['size'])
124
+ expect(() => query()).toThrow()
125
+ })
126
+ it('should throw an error when there is a select without all the fields in nor selector nor partial index', () => {
127
+ const query = () =>
128
+ Q('io.cozy.files')
129
+ .where({ size: 42 })
130
+ .partialIndex({ name: { $exists: true } })
131
+ .select(['date'])
132
+ expect(() => query()).toThrow()
133
+ })
134
+ it('should not throw when there is a select with all the fields in selector and partial index', () => {
135
+ const query = () =>
136
+ Q('io.cozy.files')
137
+ .where(
138
+ {
139
+ size: 42
140
+ },
141
+ {
142
+ date: '2021-01-01'
143
+ }
144
+ )
145
+ .partialIndex({ name: { $exists: true } })
146
+ .select(['date', 'size', 'name', 'trashed'])
147
+ expect(() => query()).not.toThrow()
148
+ })
110
149
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "29.2.0",
3
+ "version": "30.0.0",
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": "^29.2.0",
21
+ "cozy-stack-client": "^30.0.0",
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": "50cc3d6b5b6bdcbc231fe2a584fc17415d177bd6"
76
+ "gitHead": "eb60edf72cb815882e8adb04e52a70c31f090e67"
77
77
  }
@@ -68,6 +68,8 @@ export type PartialQueryDefinition = {
68
68
  indexedFields?: any[];
69
69
  sort?: any[];
70
70
  selector?: object;
71
+ partialFilter?: object;
72
+ fields?: any[];
71
73
  };
72
74
  export type MangoSelector = any;
73
75
  export type MangoPartialFilter = any;
@@ -78,6 +80,8 @@ import { Doctype } from "../types";
78
80
  * @property {Array} [indexedFields]
79
81
  * @property {Array} [sort]
80
82
  * @property {object} [selector]
83
+ * @property {object} [partialFilter]
84
+ * @property {Array} [fields]
81
85
  */
82
86
  /**
83
87
  * @typedef {object} MangoSelector
@@ -162,6 +166,12 @@ export class QueryDefinition {
162
166
  * @returns {void}
163
167
  */
164
168
  checkSelector(selector: MangoSelector): void;
169
+ /**
170
+ * Check if the selected fields are all included in the selectors
171
+ *
172
+ * @param {PartialQueryDefinition} obj - A partial QueryDefinition to check
173
+ */
174
+ checkSelectFields({ fields, selector, partialFilter }: PartialQueryDefinition): void;
165
175
  /**
166
176
  * Query a single document on its id.
167
177
  *