cozy-client 32.3.1 → 32.4.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.
@@ -140,6 +140,7 @@ var DOC_UPDATE = 'update';
140
140
  * @property {object} [stackClient]
141
141
  * @property {boolean} [warningForCustomHandlers]
142
142
  * @property {boolean} [autoHydrate]
143
+ * @property {boolean} [backgroundFetching] - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
143
144
  * @property {object} [oauth]
144
145
  * @property {Function} [onTokenRefresh]
145
146
  * @property {Function} [onError] - Default callback if a query is errored
@@ -189,35 +190,38 @@ var CozyClient = /*#__PURE__*/function () {
189
190
  var rawOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
190
191
  (0, _classCallCheck2.default)(this, CozyClient);
191
192
  (0, _defineProperty2.default)(this, "fetchQueryAndGetFromState", /*#__PURE__*/function () {
192
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(query) {
193
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
194
+ var definition, options;
193
195
  return _regenerator.default.wrap(function _callee$(_context) {
194
196
  while (1) {
195
197
  switch (_context.prev = _context.next) {
196
198
  case 0:
197
- _context.prev = 0;
198
- _context.next = 3;
199
- return _this.query(query.definition, query.options);
199
+ definition = _ref.definition, options = _ref.options;
200
+ _context.prev = 1;
201
+ _context.next = 4;
202
+ return _this.query(definition, options);
200
203
 
201
- case 3:
202
- return _context.abrupt("return", _this.getQueryFromState(query.options.as));
204
+ case 4:
205
+ return _context.abrupt("return", _this.getQueryFromState(options.as));
203
206
 
204
- case 6:
205
- _context.prev = 6;
206
- _context.t0 = _context["catch"](0);
207
+ case 7:
208
+ _context.prev = 7;
209
+ _context.t0 = _context["catch"](1);
207
210
  throw _context.t0;
208
211
 
209
- case 9:
212
+ case 10:
210
213
  case "end":
211
214
  return _context.stop();
212
215
  }
213
216
  }
214
- }, _callee, null, [[0, 6]]);
217
+ }, _callee, null, [[1, 7]]);
215
218
  }));
216
219
 
217
220
  return function (_x) {
218
- return _ref.apply(this, arguments);
221
+ return _ref2.apply(this, arguments);
219
222
  };
220
223
  }());
224
+
221
225
  var link = rawOptions.link,
222
226
  links = rawOptions.links,
223
227
  _rawOptions$schema = rawOptions.schema,
@@ -225,15 +229,15 @@ var CozyClient = /*#__PURE__*/function () {
225
229
  _rawOptions$appMetada = rawOptions.appMetadata,
226
230
  appMetadata = _rawOptions$appMetada === void 0 ? {} : _rawOptions$appMetada,
227
231
  capabilities = rawOptions.capabilities,
228
- options = (0, _objectWithoutProperties2.default)(rawOptions, ["link", "links", "schema", "appMetadata", "capabilities"]);
232
+ _options = (0, _objectWithoutProperties2.default)(rawOptions, ["link", "links", "schema", "appMetadata", "capabilities"]);
229
233
 
230
234
  if (link) {
231
235
  console.warn('`link` is deprecated, use `links`');
232
236
  }
233
237
 
234
238
  this.appMetadata = appMetadata;
235
- options.uri = securiseUri(options.uri);
236
- this.options = options;
239
+ _options.uri = securiseUri(_options.uri);
240
+ this.options = _options;
237
241
  this.queryIdGenerator = new _queries.QueryIDGenerator();
238
242
  this.isLogged = false;
239
243
  this.instanceOptions = {}; // Bind handlers
@@ -266,7 +270,7 @@ var CozyClient = /*#__PURE__*/function () {
266
270
  } catch (err) {// not a critical error, we may be in node or the instance options are not on the default HTML element
267
271
  }
268
272
 
269
- if (options.uri && options.token) {
273
+ if (_options.uri && _options.token) {
270
274
  this.login();
271
275
  }
272
276
  /**
@@ -276,7 +280,7 @@ var CozyClient = /*#__PURE__*/function () {
276
280
 
277
281
  this.storeAccesors = null;
278
282
 
279
- if (options.store !== false) {
283
+ if (_options.store !== false) {
280
284
  this.ensureStore();
281
285
  }
282
286
  /**
@@ -873,8 +877,11 @@ var CozyClient = /*#__PURE__*/function () {
873
877
  * - Can only be called with documents from the same doctype
874
878
  * - Does not support automatic creation of references
875
879
  *
876
- * @param {CozyClientDocument[]} docs
877
- * @param {Object} mutationOptions
880
+ * @param {CozyClientDocument[]} docs - Documents from the same doctype
881
+ * @param {Object} mutationOptions - Mutation Options
882
+ * @param {string} [mutationOptions.as] - Mutation id
883
+ * @param {Function} [mutationOptions.update] - Function to update the document
884
+ * @param {Function} [mutationOptions.updateQueries] - Function to update queries
878
885
  * @returns {Promise<void>}
879
886
  */
880
887
 
@@ -948,6 +955,13 @@ var CozyClient = /*#__PURE__*/function () {
948
955
 
949
956
  return saveAll;
950
957
  }()
958
+ /**
959
+ * @param {CozyClientDocument} document - Document that will be saved
960
+ * @param {object} [options={event: DOC_CREATION}] - Event
961
+ * @param {string} [options.event] - Mutation type
962
+ * @returns {CozyClientDocument}
963
+ */
964
+
951
965
  }, {
952
966
  key: "ensureCozyMetadata",
953
967
  value: function ensureCozyMetadata(document) {
@@ -1032,7 +1046,7 @@ var CozyClient = /*#__PURE__*/function () {
1032
1046
  * ```
1033
1047
  *
1034
1048
  *
1035
- * @param {object} document - Document to create
1049
+ * @param {CozyClientDocument} document - Document to create
1036
1050
  * @param {ReferenceMap} [referencesByName] - References to the created document. The
1037
1051
  * relationship class associated to each reference list should support references, otherwise this
1038
1052
  * method will throw.
@@ -1074,10 +1088,10 @@ var CozyClient = /*#__PURE__*/function () {
1074
1088
  return [saveMutation, function (response) {
1075
1089
  var doc = _this3.hydrateDocument(response.data);
1076
1090
 
1077
- return Object.entries(referencesByName).map(function (_ref2) {
1078
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
1079
- relName = _ref3[0],
1080
- references = _ref3[1];
1091
+ return Object.entries(referencesByName).map(function (_ref3) {
1092
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
1093
+ relName = _ref4[0],
1094
+ references = _ref4[1];
1081
1095
 
1082
1096
  var relationship = doc[relName];
1083
1097
  return relationship.addReferences(references);
@@ -1214,12 +1228,13 @@ var CozyClient = /*#__PURE__*/function () {
1214
1228
  var _query = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(queryDefinition) {
1215
1229
  var _this4 = this;
1216
1230
 
1217
- var _ref4,
1231
+ var _ref5,
1218
1232
  update,
1219
1233
  options,
1220
1234
  queryId,
1221
1235
  existingQuery,
1222
1236
  shouldFetch,
1237
+ backgroundFetching,
1223
1238
  response,
1224
1239
  _args8 = arguments;
1225
1240
 
@@ -1227,8 +1242,8 @@ var CozyClient = /*#__PURE__*/function () {
1227
1242
  while (1) {
1228
1243
  switch (_context8.prev = _context8.next) {
1229
1244
  case 0:
1230
- _ref4 = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
1231
- update = _ref4.update, options = (0, _objectWithoutProperties2.default)(_ref4, ["update"]);
1245
+ _ref5 = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
1246
+ update = _ref5.update, options = (0, _objectWithoutProperties2.default)(_ref5, ["update"]);
1232
1247
  this.ensureStore();
1233
1248
  queryId = options.as || this.queryIdGenerator.generateId(queryDefinition);
1234
1249
  existingQuery = this.getQueryFromState(queryId);
@@ -1273,55 +1288,59 @@ var CozyClient = /*#__PURE__*/function () {
1273
1288
  case 14:
1274
1289
  this.ensureQueryExists(queryId, queryDefinition, options);
1275
1290
  _context8.prev = 15;
1276
- this.dispatch((0, _store.loadQuery)(queryId));
1277
- _context8.next = 19;
1291
+ backgroundFetching = options.backgroundFetching !== undefined ? options.backgroundFetching : this.options.backgroundFetching;
1292
+ this.dispatch((0, _store.loadQuery)(queryId, {
1293
+ backgroundFetching: backgroundFetching
1294
+ }));
1295
+ _context8.next = 20;
1278
1296
  return this._promiseCache.exec(function () {
1279
1297
  return _this4.requestQuery(queryDefinition);
1280
1298
  }, function () {
1281
1299
  return (0, _jsonStableStringify.default)(queryDefinition);
1282
1300
  });
1283
1301
 
1284
- case 19:
1302
+ case 20:
1285
1303
  response = _context8.sent;
1286
1304
  this.dispatch((0, _store.receiveQueryResult)(queryId, response, {
1287
- update: update
1305
+ update: update,
1306
+ backgroundFetching: backgroundFetching
1288
1307
  }));
1289
1308
  return _context8.abrupt("return", response);
1290
1309
 
1291
- case 24:
1292
- _context8.prev = 24;
1310
+ case 25:
1311
+ _context8.prev = 25;
1293
1312
  _context8.t0 = _context8["catch"](15);
1294
1313
  this.dispatch((0, _store.receiveQueryError)(queryId, _context8.t0)); // specific onError
1295
1314
 
1296
1315
  if (!options.onError) {
1297
- _context8.next = 31;
1316
+ _context8.next = 32;
1298
1317
  break;
1299
1318
  }
1300
1319
 
1301
1320
  options.onError(_context8.t0); // defaulted onError
1302
1321
 
1303
- _context8.next = 36;
1322
+ _context8.next = 37;
1304
1323
  break;
1305
1324
 
1306
- case 31:
1325
+ case 32:
1307
1326
  if (!this.options.onError) {
1308
- _context8.next = 35;
1327
+ _context8.next = 36;
1309
1328
  break;
1310
1329
  }
1311
1330
 
1312
1331
  this.options.onError(_context8.t0);
1313
- _context8.next = 36;
1332
+ _context8.next = 37;
1314
1333
  break;
1315
1334
 
1316
- case 35:
1335
+ case 36:
1317
1336
  throw _context8.t0;
1318
1337
 
1319
- case 36:
1338
+ case 37:
1320
1339
  case "end":
1321
1340
  return _context8.stop();
1322
1341
  }
1323
1342
  }
1324
- }, _callee8, this, [[15, 24]]);
1343
+ }, _callee8, this, [[15, 25]]);
1325
1344
  }));
1326
1345
 
1327
1346
  function query(_x9) {
@@ -1446,7 +1465,7 @@ var CozyClient = /*#__PURE__*/function () {
1446
1465
  key: "mutate",
1447
1466
  value: function () {
1448
1467
  var _mutate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(mutationDefinition) {
1449
- var _ref5,
1468
+ var _ref6,
1450
1469
  update,
1451
1470
  updateQueries,
1452
1471
  options,
@@ -1458,8 +1477,8 @@ var CozyClient = /*#__PURE__*/function () {
1458
1477
  while (1) {
1459
1478
  switch (_context10.prev = _context10.next) {
1460
1479
  case 0:
1461
- _ref5 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {};
1462
- update = _ref5.update, updateQueries = _ref5.updateQueries, options = (0, _objectWithoutProperties2.default)(_ref5, ["update", "updateQueries"]);
1480
+ _ref6 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {};
1481
+ update = _ref6.update, updateQueries = _ref6.updateQueries, options = (0, _objectWithoutProperties2.default)(_ref6, ["update", "updateQueries"]);
1463
1482
  this.ensureStore();
1464
1483
  mutationId = options.as || this.queryIdGenerator.generateId(mutationDefinition);
1465
1484
  this.dispatch((0, _store.initMutation)(mutationId, mutationDefinition));
@@ -1928,6 +1947,8 @@ var CozyClient = /*#__PURE__*/function () {
1928
1947
  * Has a behavior close to <Query /> or useQuery
1929
1948
  *
1930
1949
  * @param {object} query - Query with definition and options
1950
+ * @param {QueryDefinition} query.definition - Query Definition
1951
+ * @param {QueryOptions} query.options - Query Options
1931
1952
  * @returns {Promise<QueryState>} Query state
1932
1953
  */
1933
1954
 
@@ -2050,12 +2071,12 @@ var CozyClient = /*#__PURE__*/function () {
2050
2071
  key: "authorize",
2051
2072
  value: function () {
2052
2073
  var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16() {
2053
- var _ref6,
2054
- _ref6$openURLCallback,
2074
+ var _ref7,
2075
+ _ref7$openURLCallback,
2055
2076
  openURLCallback,
2056
- _ref6$sessionCode,
2077
+ _ref7$sessionCode,
2057
2078
  sessionCode,
2058
- _ref6$pkceCodes,
2079
+ _ref7$pkceCodes,
2059
2080
  pkceCodes,
2060
2081
  codeVerifier,
2061
2082
  codeChallenge,
@@ -2072,7 +2093,7 @@ var CozyClient = /*#__PURE__*/function () {
2072
2093
  while (1) {
2073
2094
  switch (_context16.prev = _context16.next) {
2074
2095
  case 0:
2075
- _ref6 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, _ref6$openURLCallback = _ref6.openURLCallback, openURLCallback = _ref6$openURLCallback === void 0 ? _mobile.authFunction : _ref6$openURLCallback, _ref6$sessionCode = _ref6.sessionCode, sessionCode = _ref6$sessionCode === void 0 ? undefined : _ref6$sessionCode, _ref6$pkceCodes = _ref6.pkceCodes, pkceCodes = _ref6$pkceCodes === void 0 ? {} : _ref6$pkceCodes;
2096
+ _ref7 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, _ref7$openURLCallback = _ref7.openURLCallback, openURLCallback = _ref7$openURLCallback === void 0 ? _mobile.authFunction : _ref7$openURLCallback, _ref7$sessionCode = _ref7.sessionCode, sessionCode = _ref7$sessionCode === void 0 ? undefined : _ref7$sessionCode, _ref7$pkceCodes = _ref7.pkceCodes, pkceCodes = _ref7$pkceCodes === void 0 ? {} : _ref7$pkceCodes;
2076
2097
  _context16.prev = 1;
2077
2098
  codeVerifier = pkceCodes.codeVerifier, codeChallenge = pkceCodes.codeChallenge;
2078
2099
  stackClient = this.getStackClient();
@@ -2169,9 +2190,9 @@ var CozyClient = /*#__PURE__*/function () {
2169
2190
  }, {
2170
2191
  key: "setStore",
2171
2192
  value: function setStore(store) {
2172
- var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2173
- _ref7$force = _ref7.force,
2174
- force = _ref7$force === void 0 ? false : _ref7$force;
2193
+ var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2194
+ _ref8$force = _ref8.force,
2195
+ force = _ref8$force === void 0 ? false : _ref8$force;
2175
2196
 
2176
2197
  if (store === undefined) {
2177
2198
  throw new Error('Store is undefined');
@@ -2365,10 +2386,10 @@ var CozyClient = /*#__PURE__*/function () {
2365
2386
  var _this10 = this;
2366
2387
 
2367
2388
  this.ensureStore();
2368
- Object.entries(data).forEach(function (_ref8) {
2369
- var _ref9 = (0, _slicedToArray2.default)(_ref8, 2),
2370
- doctype = _ref9[0],
2371
- data = _ref9[1];
2389
+ Object.entries(data).forEach(function (_ref9) {
2390
+ var _ref10 = (0, _slicedToArray2.default)(_ref9, 2),
2391
+ doctype = _ref10[0],
2392
+ data = _ref10[1];
2372
2393
 
2373
2394
  _this10.dispatch((0, _store.receiveQueryResult)(null, {
2374
2395
  data: data
@@ -2550,7 +2571,7 @@ var CozyClient = /*#__PURE__*/function () {
2550
2571
  CozyClient.hooks = CozyClient.hooks || {};
2551
2572
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2552
2573
 
2553
- CozyClient.version = "32.3.1";
2574
+ CozyClient.version = "32.4.0";
2554
2575
 
2555
2576
  _microee.default.mixin(CozyClient);
2556
2577
 
@@ -28,7 +28,8 @@ import {
28
28
  receiveMutationResult,
29
29
  receiveMutationError,
30
30
  getQueryFromState,
31
- getRawQueryFromState
31
+ getRawQueryFromState,
32
+ loadQuery
32
33
  } from './store'
33
34
  import { HasManyFiles, Association, HasMany } from './associations'
34
35
  import mapValues from 'lodash/mapValues'
@@ -1417,6 +1418,44 @@ describe('CozyClient', () => {
1417
1418
  )
1418
1419
  })
1419
1420
 
1421
+ it('should dispatch a LOAD_QUERY action', async () => {
1422
+ requestHandler.mockResolvedValueOnce(fakeResponse)
1423
+ getQueryFromState.mockReturnValueOnce({
1424
+ fetchStatus: 'loaded'
1425
+ })
1426
+ await client.query(query, { as: 'allTodos' })
1427
+ expect(client.store.dispatch.mock.calls[1][0]).toEqual(
1428
+ loadQuery('allTodos', {})
1429
+ )
1430
+ })
1431
+
1432
+ it('should dispatch a LOAD_QUERY action providing backgroundFetching when set', async () => {
1433
+ requestHandler.mockResolvedValueOnce(fakeResponse)
1434
+ getQueryFromState.mockReturnValueOnce({
1435
+ fetchStatus: 'loaded'
1436
+ })
1437
+ await client.query(query, { as: 'allTodos', backgroundFetching: true })
1438
+ expect(client.store.dispatch.mock.calls[1][0]).toEqual(
1439
+ loadQuery('allTodos', { backgroundFetching: true })
1440
+ )
1441
+ })
1442
+
1443
+ it('should dispatch a RECEIVE_QUERY_RESULT action providing backgroundFetching when set', async () => {
1444
+ requestHandler.mockResolvedValueOnce(fakeResponse)
1445
+ getQueryFromState.mockReturnValueOnce({
1446
+ fetchStatus: 'loaded'
1447
+ })
1448
+ query.skip = 100
1449
+ await client.query(query, { as: 'allTodos', backgroundFetching: true })
1450
+ const dispatchCalls = client.store.dispatch.mock.calls
1451
+ const lastDispatchCall = dispatchCalls[dispatchCalls.length - 1]
1452
+ expect(lastDispatchCall[0]).toEqual(
1453
+ receiveQueryResult('allTodos', fakeResponse, {
1454
+ backgroundFetching: true
1455
+ })
1456
+ )
1457
+ })
1458
+
1420
1459
  it('should dispatch a RECEIVE_QUERY_RESULT action if query has skip', async () => {
1421
1460
  requestHandler.mockResolvedValueOnce(fakeResponse)
1422
1461
  getQueryFromState.mockReturnValueOnce({
@@ -192,6 +192,7 @@ describe('Query', () => {
192
192
  fetchStatus: 'pending',
193
193
  hasMore: false,
194
194
  id: '1',
195
+ isFetching: null,
195
196
  lastError: null,
196
197
  lastFetch: null,
197
198
  lastUpdate: null,
@@ -27,7 +27,7 @@ var win = typeof window !== 'undefined' ? window : null;
27
27
  /**
28
28
  * Open a SafariView Controller and resolve with the URL containing the token
29
29
  *
30
- * @param {string} url
30
+ * @param {string} url - Url containing access_code and state
31
31
  * @returns {Promise}
32
32
  */
33
33
 
@@ -65,7 +65,7 @@ var authenticateWithSafari = function authenticateWithSafari(url) {
65
65
  /**
66
66
  * Opens an InAppBrowser and resolves with the URL containing the token
67
67
  *
68
- * @param {string} url
68
+ * @param {string} url - Url containing access_code and state
69
69
  * @returns {Promise}
70
70
  */
71
71
 
@@ -93,7 +93,7 @@ var getClassNameForExecutedTimesQuery = function getClassNameForExecutedTimesQue
93
93
  }
94
94
  };
95
95
  /**
96
- * @param {{ queryState: QueryState }} props
96
+ * @param {{ queryState: QueryState }} props - Query state containing fetchStatus, lastError
97
97
  */
98
98
 
99
99
 
@@ -106,7 +106,7 @@ var FetchStatus = function FetchStatus(props) {
106
106
  }, fetchStatus, fetchStatus === 'failed' ? " - ".concat(lastError) : null);
107
107
  };
108
108
  /**
109
- * @param {{ queryState: QueryState }} props
109
+ * @param {{ queryState: QueryState }} props - Query state containing definition
110
110
  */
111
111
 
112
112
 
@@ -17,6 +17,8 @@ var _logger = _interopRequireDefault(require("../logger"));
17
17
 
18
18
  var _storeAttestation = require("./store-attestation");
19
19
 
20
+ var _typedefs = require("./typedefs");
21
+
20
22
  /**
21
23
  * Request a challenge from the Stack that can be used to request the app attestation from the app store
22
24
  *
@@ -13,7 +13,9 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
13
13
 
14
14
  var _reactNativeGoogleSafetynet = _interopRequireDefault(require("react-native-google-safetynet"));
15
15
 
16
- //@ts-ignore
16
+ var _typedefs = require("./typedefs");
17
+
18
+ //@ts-ignore next-line
17
19
 
18
20
  /**
19
21
  * Retrieve the app's attestation from the Google Play store
@@ -13,7 +13,9 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
13
13
 
14
14
  var _reactNativeIos11Devicecheck = _interopRequireDefault(require("react-native-ios11-devicecheck"));
15
15
 
16
- //@ts-ignore
16
+ var _typedefs = require("./typedefs");
17
+
18
+ //@ts-ignore next-line
17
19
 
18
20
  /**
19
21
  * Retrieve the app's attestation from the Apple AppStore
@@ -11,6 +11,8 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
11
11
 
12
12
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
13
 
14
+ var _typedefs = require("./typedefs");
15
+
14
16
  /**
15
17
  * Retrieve the app's attestation from the app's store
16
18
  * /!\ This is a mock implementation that should never be called
@@ -1,3 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
1
8
  /**
2
9
  * @typedef {string} jws - A JSON Web Signature
3
10
  */
@@ -17,4 +24,5 @@
17
24
  * @typedef {object} CertificationConfig - Configuration to access the stores certification API
18
25
  * @property {string} androidSafetyNetApiKey
19
26
  */
20
- "use strict";
27
+ var _default = {};
28
+ exports.default = _default;
@@ -78,6 +78,7 @@ describe('use query', () => {
78
78
  'id',
79
79
  'definition',
80
80
  'fetchStatus',
81
+ 'isFetching',
81
82
  'lastFetch',
82
83
  'lastUpdate',
83
84
  'lastErrorUpdate',
package/dist/manifest.js CHANGED
@@ -38,9 +38,9 @@ function isPartnershipValid(partnership) {
38
38
  return Boolean(partnership && partnership.description);
39
39
  }
40
40
  /**
41
- * Normalize app manifest, retrocompatibility for old manifests
41
+ * Normalize app manifest, retro-compatibility for old manifests
42
42
  *
43
- * @param {Manifest} manifest
43
+ * @param {Manifest} manifest - app manifest to normalize
44
44
  * @returns {Manifest}
45
45
  */
46
46
 
@@ -1,6 +1,6 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`queries reducer should init correctly 1`] = `
3
+ exports[`queries reducer INIT_QUERY should init correctly 1`] = `
4
4
  Object {
5
5
  "a": Object {
6
6
  "bookmark": null,
@@ -26,6 +26,7 @@ Object {
26
26
  "fetchedPagesCount": 0,
27
27
  "hasMore": false,
28
28
  "id": "a",
29
+ "isFetching": null,
29
30
  "lastError": null,
30
31
  "lastErrorUpdate": null,
31
32
  "lastFetch": null,
@@ -64,6 +65,7 @@ Object {
64
65
  "fetchedPagesCount": 1,
65
66
  "hasMore": false,
66
67
  "id": "a",
68
+ "isFetching": null,
67
69
  "lastError": null,
68
70
  "lastErrorUpdate": null,
69
71
  "lastFetch": 1337,
@@ -101,6 +103,7 @@ Object {
101
103
  "fetchedPagesCount": 1,
102
104
  "hasMore": false,
103
105
  "id": "a",
106
+ "isFetching": null,
104
107
  "lastError": null,
105
108
  "lastErrorUpdate": null,
106
109
  "lastFetch": 1337,
@@ -138,6 +141,7 @@ Object {
138
141
  "fetchedPagesCount": 0,
139
142
  "hasMore": false,
140
143
  "id": "b",
144
+ "isFetching": null,
141
145
  "lastError": null,
142
146
  "lastErrorUpdate": null,
143
147
  "lastFetch": null,
@@ -175,6 +179,7 @@ Object {
175
179
  "fetchedPagesCount": 1,
176
180
  "hasMore": false,
177
181
  "id": "a",
182
+ "isFetching": null,
178
183
  "lastError": null,
179
184
  "lastErrorUpdate": null,
180
185
  "lastFetch": 1337,
@@ -209,6 +214,7 @@ Object {
209
214
  "fetchedPagesCount": 0,
210
215
  "hasMore": false,
211
216
  "id": "b",
217
+ "isFetching": null,
212
218
  "lastError": null,
213
219
  "lastErrorUpdate": null,
214
220
  "lastFetch": null,
@@ -252,6 +258,7 @@ Object {
252
258
  "fetchedPagesCount": 1,
253
259
  "hasMore": false,
254
260
  "id": "a",
261
+ "isFetching": null,
255
262
  "lastError": null,
256
263
  "lastErrorUpdate": null,
257
264
  "lastFetch": 1337,
@@ -284,6 +291,7 @@ Object {
284
291
  "fetchedPagesCount": 0,
285
292
  "hasMore": false,
286
293
  "id": "b",
294
+ "isFetching": null,
287
295
  "lastError": null,
288
296
  "lastErrorUpdate": null,
289
297
  "lastFetch": null,
@@ -322,6 +330,7 @@ Object {
322
330
  "fetchedPagesCount": 1,
323
331
  "hasMore": false,
324
332
  "id": "a",
333
+ "isFetching": null,
325
334
  "lastError": null,
326
335
  "lastErrorUpdate": null,
327
336
  "lastFetch": 1337,
@@ -355,6 +364,7 @@ Object {
355
364
  "fetchedPagesCount": 0,
356
365
  "hasMore": false,
357
366
  "id": "b",
367
+ "isFetching": null,
358
368
  "lastError": null,
359
369
  "lastErrorUpdate": null,
360
370
  "lastFetch": null,
@@ -392,6 +402,7 @@ Object {
392
402
  "fetchedPagesCount": 1,
393
403
  "hasMore": false,
394
404
  "id": "a",
405
+ "isFetching": null,
395
406
  "lastError": null,
396
407
  "lastErrorUpdate": null,
397
408
  "lastFetch": 1337,
@@ -424,6 +435,7 @@ Object {
424
435
  "fetchedPagesCount": 0,
425
436
  "hasMore": false,
426
437
  "id": "b",
438
+ "isFetching": null,
427
439
  "lastError": null,
428
440
  "lastErrorUpdate": null,
429
441
  "lastFetch": null,
@@ -463,6 +475,7 @@ Object {
463
475
  "fetchedPagesCount": 0,
464
476
  "hasMore": false,
465
477
  "id": "a",
478
+ "isFetching": null,
466
479
  "lastError": null,
467
480
  "lastErrorUpdate": null,
468
481
  "lastFetch": null,
@@ -493,6 +506,7 @@ Object {
493
506
  "fetchedPagesCount": 0,
494
507
  "hasMore": false,
495
508
  "id": "b",
509
+ "isFetching": null,
496
510
  "lastError": null,
497
511
  "lastErrorUpdate": null,
498
512
  "lastFetch": 1337,
@@ -530,6 +544,7 @@ Object {
530
544
  "fetchedPagesCount": 2,
531
545
  "hasMore": false,
532
546
  "id": "a",
547
+ "isFetching": null,
533
548
  "lastError": null,
534
549
  "lastErrorUpdate": null,
535
550
  "lastFetch": 1337,
@@ -564,6 +579,7 @@ Object {
564
579
  "fetchedPagesCount": 0,
565
580
  "hasMore": false,
566
581
  "id": "b",
582
+ "isFetching": null,
567
583
  "lastError": null,
568
584
  "lastErrorUpdate": null,
569
585
  "lastFetch": null,
@@ -605,6 +621,7 @@ Object {
605
621
  "fetchedPagesCount": 1,
606
622
  "hasMore": false,
607
623
  "id": "a",
624
+ "isFetching": null,
608
625
  "lastError": null,
609
626
  "lastErrorUpdate": null,
610
627
  "lastFetch": 1337,
@@ -637,6 +654,7 @@ Object {
637
654
  "fetchedPagesCount": 0,
638
655
  "hasMore": false,
639
656
  "id": "b",
657
+ "isFetching": null,
640
658
  "lastError": null,
641
659
  "lastErrorUpdate": null,
642
660
  "lastFetch": null,
@@ -84,6 +84,7 @@ var queryInitialState = {
84
84
  id: null,
85
85
  definition: null,
86
86
  fetchStatus: 'pending',
87
+ isFetching: null,
87
88
  lastFetch: null,
88
89
  lastUpdate: null,
89
90
  lastErrorUpdate: null,
@@ -187,10 +188,6 @@ var query = function query() {
187
188
  id: action.queryId,
188
189
  definition: action.queryDefinition,
189
190
  options: action.options,
190
- // When the query is new, we set "fetchStatus" to "loading"
191
- // directly since we know it will be loaded right away.
192
- // This way, the loadQuery action will have no effect, and
193
- // we save an additional render.
194
191
  fetchStatus: state.lastUpdate ? state.fetchStatus : 'pending'
195
192
  });
196
193
 
@@ -199,6 +196,13 @@ var query = function query() {
199
196
  return state;
200
197
  }
201
198
 
199
+ if (state.fetchStatus === 'loaded' && action.backgroundFetching) {
200
+ return _objectSpread(_objectSpread({}, state), {}, {
201
+ fetchStatus: 'loaded',
202
+ isFetching: true
203
+ });
204
+ }
205
+
202
206
  return _objectSpread(_objectSpread({}, state), {}, {
203
207
  fetchStatus: 'loading'
204
208
  });
@@ -212,6 +216,7 @@ var query = function query() {
212
216
  if (!response.data) {
213
217
  return _objectSpread(_objectSpread({}, state), {}, {
214
218
  fetchStatus: 'loaded',
219
+ isFetching: action.backgroundFetching ? false : null,
215
220
  lastFetch: Date.now(),
216
221
  lastUpdate: Date.now()
217
222
  });
@@ -221,6 +226,7 @@ var query = function query() {
221
226
 
222
227
  var common = _objectSpread({
223
228
  fetchStatus: 'loaded',
229
+ isFetching: action.backgroundFetching ? false : null,
224
230
  lastFetch: Date.now(),
225
231
  lastUpdate: Date.now()
226
232
  }, executionStatsEnabled && {
@@ -254,6 +260,7 @@ var query = function query() {
254
260
  return _objectSpread(_objectSpread({}, state), {}, {
255
261
  id: action.queryId,
256
262
  fetchStatus: 'failed',
263
+ isFetching: action.backgroundFetching ? false : null,
257
264
  lastError: action.error,
258
265
  lastErrorUpdate: Date.now()
259
266
  });
@@ -566,6 +573,7 @@ var _default = queries;
566
573
  * @param {string} queryId Name/id of the query
567
574
  * @param {QueryDefinition} queryDefinition - Definition of the created query
568
575
  * @param {QueryOptions} [options] - Options for the created query
576
+ * @returns {object} Redux action to dispatch
569
577
  */
570
578
 
571
579
  exports.default = _default;
@@ -584,15 +592,32 @@ var initQuery = function initQuery(queryId, queryDefinition) {
584
592
  options: options
585
593
  };
586
594
  };
595
+ /**
596
+ * Update the fetchStatus when the query is loading
597
+ *
598
+ * @param {string} queryId - id of the query
599
+ * @param {QueryOptions} [options] - Options for the created query
600
+ * @returns {object} Redux action to dispatch
601
+ */
602
+
587
603
 
588
604
  exports.initQuery = initQuery;
589
605
 
590
- var loadQuery = function loadQuery(queryId) {
591
- return {
606
+ var loadQuery = function loadQuery(queryId, options) {
607
+ return _objectSpread({
592
608
  type: LOAD_QUERY,
593
609
  queryId: queryId
594
- };
610
+ }, options);
595
611
  };
612
+ /**
613
+ * Update the fetchStatus when the query is loading
614
+ *
615
+ * @param {string} queryId - id of the query
616
+ * @param {object} response - The action response
617
+ * @param {QueryOptions} [options] - Options for the created query
618
+ * @returns {object} Redux action to dispatch
619
+ */
620
+
596
621
 
597
622
  exports.loadQuery = loadQuery;
598
623
 
@@ -604,15 +629,25 @@ var receiveQueryResult = function receiveQueryResult(queryId, response) {
604
629
  response: response
605
630
  }, options);
606
631
  };
632
+ /**
633
+ * Update the fetchStatus when the query is loading
634
+ *
635
+ * @param {string} queryId - id of the query
636
+ * @param {object} error - The action error
637
+ * @param {QueryOptions} [options] - Options for the created query
638
+ * @returns {object} Redux action to dispatch
639
+ */
640
+
607
641
 
608
642
  exports.receiveQueryResult = receiveQueryResult;
609
643
 
610
644
  var receiveQueryError = function receiveQueryError(queryId, error) {
611
- return {
645
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
646
+ return _objectSpread({
612
647
  type: RECEIVE_QUERY_ERROR,
613
648
  queryId: queryId,
614
649
  error: error
615
- };
650
+ }, options);
616
651
  }; // selectors
617
652
 
618
653
 
@@ -4,14 +4,18 @@ import queries, {
4
4
  convert$gtNullSelectors,
5
5
  makeSorterFromDefinition,
6
6
  mergeSelectorAndPartialIndex,
7
- sortAndLimitDocsIds
7
+ sortAndLimitDocsIds,
8
+ loadQuery,
9
+ receiveQueryError
8
10
  } from './queries'
9
11
  import { Q } from '../queries/dsl'
10
12
  import { TODO_1, TODO_2, TODO_3 } from '../__tests__/fixtures'
11
13
 
12
14
  describe('queries reducer', () => {
13
15
  let state
14
-
16
+ const response = {
17
+ data: [TODO_1, TODO_2]
18
+ }
15
19
  const applyAction = action => {
16
20
  state = queries(state, action)
17
21
  }
@@ -23,35 +27,116 @@ describe('queries reducer', () => {
23
27
  Date.now.mockRestore()
24
28
  })
25
29
 
26
- it('should init correctly', () => {
27
- const qdef = Q('io.cozy.todos')
28
- applyAction(initQuery('a', qdef))
29
- expect(state).toMatchSnapshot()
30
+ describe('INIT_QUERY', () => {
31
+ it('should init correctly', () => {
32
+ const qdef = Q('io.cozy.todos')
33
+ applyAction(initQuery('a', qdef))
34
+ expect(state).toMatchSnapshot()
35
+ })
36
+
37
+ test('init should have no effect after receiveQueryResult', () => {
38
+ const qdef = Q('io.cozy.todos')
39
+ applyAction(initQuery('a', qdef))
40
+ applyAction(receiveQueryResult('a', response))
41
+ let state1 = state
42
+ applyAction(initQuery('a', qdef))
43
+ expect(state1).toBe(state)
44
+ })
45
+
46
+ test('init should not set status to loading after receiveQueryResult', () => {
47
+ const qdef = Q('io.cozy.todos')
48
+ applyAction(initQuery('a', qdef))
49
+ applyAction(receiveQueryResult('a', response))
50
+ applyAction(initQuery('a', qdef))
51
+ expect(state.a.fetchStatus).toBe('loaded')
52
+ })
30
53
  })
31
54
 
32
- test('init should have no effect after receiveQueryResult', () => {
33
- const qdef = Q('io.cozy.todos')
34
- applyAction(initQuery('a', qdef))
35
- applyAction(
36
- receiveQueryResult('a', {
37
- data: [TODO_1, TODO_2]
38
- })
39
- )
40
- let state1 = state
41
- applyAction(initQuery('a', qdef))
42
- expect(state1).toBe(state)
55
+ describe('LOAD_QUERY', () => {
56
+ it('should set isFetching to true and not changing fetchStatus when query has been loaded and background fetching activated', () => {
57
+ // Given
58
+ const queryDefinition = Q('io.cozy.todos')
59
+ applyAction(initQuery('a', queryDefinition))
60
+ applyAction(receiveQueryResult('a', response))
61
+ expect(state.a.fetchStatus).toBe('loaded')
62
+
63
+ // When
64
+ applyAction(loadQuery('a', { backgroundFetching: true }))
65
+
66
+ // Then
67
+ expect(state.a.fetchStatus).toBe('loaded')
68
+ expect(state.a.isFetching).toBe(true)
69
+ })
70
+
71
+ it('should not set isFetching and keep changing fetchStatus when query has been loaded and background fetching deactivated', () => {
72
+ // Given
73
+ const queryDefinition = Q('io.cozy.todos')
74
+ applyAction(initQuery('a', queryDefinition))
75
+ applyAction(receiveQueryResult('a', response))
76
+ expect(state.a.fetchStatus).toBe('loaded')
77
+
78
+ // When
79
+ applyAction(loadQuery('a'))
80
+
81
+ // Then
82
+ expect(state.a.fetchStatus).toBe('loading')
83
+ expect(state.a.isFetching).toBe(null)
84
+ })
43
85
  })
44
86
 
45
- test('init should not set status to loading after receiveQueryResult', () => {
46
- const qdef = Q('io.cozy.todos')
47
- applyAction(initQuery('a', qdef))
48
- applyAction(
49
- receiveQueryResult('a', {
50
- data: [TODO_1, TODO_2]
51
- })
52
- )
53
- applyAction(initQuery('a', qdef))
54
- expect(state.a.fetchStatus).toBe('loaded')
87
+ describe('RECEIVE_QUERY_RESULT', () => {
88
+ it('should set isFetching to false when query has been re-fetched correctly and background fetching activated', () => {
89
+ // Given
90
+ const queryDefinition = Q('io.cozy.todos')
91
+ applyAction(initQuery('a', queryDefinition))
92
+
93
+ // When
94
+ applyAction(
95
+ receiveQueryResult('a', response, { backgroundFetching: true })
96
+ )
97
+
98
+ // Then
99
+ expect(state.a.isFetching).toBe(false)
100
+ })
101
+
102
+ it('should set isFetching to false when query has been re-fetched correctly and background fetching deactivated', () => {
103
+ // Given
104
+ const queryDefinition = Q('io.cozy.todos')
105
+ applyAction(initQuery('a', queryDefinition))
106
+
107
+ // When
108
+ applyAction(receiveQueryResult('a', response))
109
+
110
+ // Then
111
+ expect(state.a.isFetching).toBe(null)
112
+ })
113
+ })
114
+
115
+ describe('RECEIVE_QUERY_ERROR', () => {
116
+ it('should set isFetching to false when query is in error and background fetching activated', () => {
117
+ // Given
118
+ const queryDefinition = Q('io.cozy.todos')
119
+ applyAction(initQuery('a', queryDefinition))
120
+ const error = {}
121
+
122
+ // When
123
+ applyAction(receiveQueryError('a', error, { backgroundFetching: true }))
124
+
125
+ // Then
126
+ expect(state.a.isFetching).toBe(false)
127
+ })
128
+ it('should not set isFetching when query is in error and background fetching deactivated', () => {
129
+ // Given
130
+ const queryDefinition = Q('io.cozy.todos')
131
+ applyAction(initQuery('a', queryDefinition))
132
+ const error = {}
133
+
134
+ // When
135
+ applyAction(receiveQueryError('a', error))
136
+
137
+ // Then
138
+ expect(state.a.isFetching).toBe(null)
139
+ })
55
140
  })
56
141
 
57
142
  describe('updates', () => {
@@ -397,6 +397,7 @@ describe('Store', () => {
397
397
  definition: null,
398
398
  id: 'allTodos',
399
399
  fetchStatus: 'pending',
400
+ isFetching: null,
400
401
  lastFetch: null,
401
402
  lastUpdate: null,
402
403
  lastError: null,
package/dist/types.js CHANGED
@@ -61,6 +61,7 @@ var _dsl = require("./queries/dsl");
61
61
  * @property {string} id
62
62
  * @property {QueryDefinition} definition
63
63
  * @property {QueryFetchStatus} fetchStatus
64
+ * @property {boolean} isFetching
64
65
  * @property {number} lastFetch
65
66
  * @property {number} lastUpdate
66
67
  * @property {number} lastErrorUpdate
@@ -89,6 +90,7 @@ var _dsl = require("./queries/dsl");
89
90
  * @property {string} [update] - Does not seem to be used
90
91
  * @property {Function} [onError] - Callback when the query is errored
91
92
  * @property {boolean} [enabled=true] - If set to false, the query won't be executed
93
+ * @property {boolean} [backgroundFetching] - If set to true, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
92
94
  * @property {object} [hydrated=true] - Whether documents should be returned already hydrated
93
95
  * @property {object} [singleDocData] - If true, the "data" returned will be
94
96
  * a single doc instead of an array for single doc queries. Defaults to false for backward
@@ -158,6 +160,7 @@ var _dsl = require("./queries/dsl");
158
160
  * @property {boolean} [_deleted] - When the document has been deleted
159
161
  * @property {ReferencedByRelationship} [relationships] - Relationships of the document
160
162
  * @property {Reference[]} [referenced_by] - referenced by of another document
163
+ * @property {object} [cozyMetadata] - Cozy Metadata
161
164
  */
162
165
 
163
166
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "32.3.1",
3
+ "version": "32.4.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": "^32.2.5",
21
+ "cozy-stack-client": "^32.3.3",
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": "c277d63f38e9f9d529ae27b6b3d0f62a783d201c"
76
+ "gitHead": "4076034cefef149c77dd0393650e4aeea59ebffd"
77
77
  }
@@ -8,6 +8,10 @@ export type ClientOptions = {
8
8
  stackClient?: object;
9
9
  warningForCustomHandlers?: boolean;
10
10
  autoHydrate?: boolean;
11
+ /**
12
+ * - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
13
+ */
14
+ backgroundFetching?: boolean;
11
15
  oauth?: object;
12
16
  onTokenRefresh?: Function;
13
17
  /**
@@ -41,6 +45,7 @@ export type ClientOptions = {
41
45
  * @property {object} [stackClient]
42
46
  * @property {boolean} [warningForCustomHandlers]
43
47
  * @property {boolean} [autoHydrate]
48
+ * @property {boolean} [backgroundFetching] - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
44
49
  * @property {object} [oauth]
45
50
  * @property {Function} [onTokenRefresh]
46
51
  * @property {Function} [onError] - Default callback if a query is errored
@@ -148,6 +153,10 @@ declare class CozyClient {
148
153
  stackClient?: object;
149
154
  warningForCustomHandlers?: boolean;
150
155
  autoHydrate?: boolean;
156
+ /**
157
+ * - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
158
+ */
159
+ backgroundFetching?: boolean;
151
160
  oauth?: object;
152
161
  onTokenRefresh?: Function;
153
162
  /**
@@ -331,14 +340,27 @@ declare class CozyClient {
331
340
  * - Can only be called with documents from the same doctype
332
341
  * - Does not support automatic creation of references
333
342
  *
334
- * @param {CozyClientDocument[]} docs
335
- * @param {Object} mutationOptions
343
+ * @param {CozyClientDocument[]} docs - Documents from the same doctype
344
+ * @param {Object} mutationOptions - Mutation Options
345
+ * @param {string} [mutationOptions.as] - Mutation id
346
+ * @param {Function} [mutationOptions.update] - Function to update the document
347
+ * @param {Function} [mutationOptions.updateQueries] - Function to update queries
336
348
  * @returns {Promise<void>}
337
349
  */
338
- saveAll(docs: CozyClientDocument[], mutationOptions?: any): Promise<void>;
339
- ensureCozyMetadata(document: any, options?: {
340
- event: string;
341
- }): any;
350
+ saveAll(docs: CozyClientDocument[], mutationOptions?: {
351
+ as?: string;
352
+ update?: Function;
353
+ updateQueries?: Function;
354
+ }): Promise<void>;
355
+ /**
356
+ * @param {CozyClientDocument} document - Document that will be saved
357
+ * @param {object} [options={event: DOC_CREATION}] - Event
358
+ * @param {string} [options.event] - Mutation type
359
+ * @returns {CozyClientDocument}
360
+ */
361
+ ensureCozyMetadata(document: CozyClientDocument, options?: {
362
+ event?: string;
363
+ }): CozyClientDocument;
342
364
  /**
343
365
  * Dehydrates and adds metadata before saving a document
344
366
  *
@@ -360,14 +382,14 @@ declare class CozyClient {
360
382
  * ```
361
383
  *
362
384
  *
363
- * @param {object} document - Document to create
385
+ * @param {CozyClientDocument} document - Document to create
364
386
  * @param {ReferenceMap} [referencesByName] - References to the created document. The
365
387
  * relationship class associated to each reference list should support references, otherwise this
366
388
  * method will throw.
367
389
  *
368
390
  * @returns {Mutation[]|Mutation} One or more mutation to execute
369
391
  */
370
- getDocumentSavePlan(document: object, referencesByName?: ReferenceMap): Mutation[] | Mutation;
392
+ getDocumentSavePlan(document: CozyClientDocument, referencesByName?: ReferenceMap): Mutation[] | Mutation;
371
393
  triggerHook(name: any, document: any): void;
372
394
  /**
373
395
  * Destroys a document. {before,after}:destroy hooks will be fired.
@@ -542,9 +564,14 @@ declare class CozyClient {
542
564
  * Has a behavior close to <Query /> or useQuery
543
565
  *
544
566
  * @param {object} query - Query with definition and options
567
+ * @param {QueryDefinition} query.definition - Query Definition
568
+ * @param {QueryOptions} query.options - Query Options
545
569
  * @returns {Promise<QueryState>} Query state
546
570
  */
547
- fetchQueryAndGetFromState: (query: object) => Promise<QueryState>;
571
+ fetchQueryAndGetFromState: ({ definition, options }: {
572
+ definition: QueryDefinition;
573
+ options: QueryOptions;
574
+ }) => Promise<QueryState>;
548
575
  /**
549
576
  * Performs a complete OAuth flow using a Cordova webview
550
577
  * or React Native WebView for auth.
@@ -1,2 +1,3 @@
1
1
  export function certifyFlagship(certificationConfig: CertificationConfig, client: CozyClient): Promise<void>;
2
+ import { CertificationConfig } from "./typedefs";
2
3
  import CozyClient from "../CozyClient";
@@ -1 +1,3 @@
1
1
  export function getAppAttestationFromStore(nonce: string, certificationConfig: CertificationConfig): Promise<AttestationResult>;
2
+ import { CertificationConfig } from "./typedefs";
3
+ import { AttestationResult } from "./typedefs";
@@ -7,3 +7,5 @@
7
7
  * @returns {Promise<AttestationResult>} the app's attestation
8
8
  */
9
9
  export function getAppAttestationFromStore(nonce: string, certificationConfig: CertificationConfig): Promise<AttestationResult>;
10
+ import { CertificationConfig } from "./typedefs";
11
+ import { AttestationResult } from "./typedefs";
@@ -1 +1,3 @@
1
1
  export function getAppAttestationFromStore(nonce: string, certificationConfig: CertificationConfig): Promise<AttestationResult>;
2
+ import { CertificationConfig } from "./typedefs";
3
+ import { AttestationResult } from "./typedefs";
@@ -1,15 +1,17 @@
1
+ declare var _default: {};
2
+ export default _default;
1
3
  /**
2
4
  * - A JSON Web Signature
3
5
  */
4
- type jws = string;
6
+ export type jws = string;
5
7
  /**
6
8
  * - A JSON Web Signature
7
9
  */
8
- type base64string = string;
10
+ export type base64string = string;
9
11
  /**
10
12
  * - An app attestation from the app store
11
13
  */
12
- type AttestationResult = {
14
+ export type AttestationResult = {
13
15
  platform: string;
14
16
  attestation: jws | base64string;
15
17
  keyId?: string;
@@ -17,6 +19,6 @@ type AttestationResult = {
17
19
  /**
18
20
  * - Configuration to access the stores certification API
19
21
  */
20
- type CertificationConfig = {
22
+ export type CertificationConfig = {
21
23
  androidSafetyNetApiKey: string;
22
24
  };
@@ -3,9 +3,9 @@ export function sanitizeCategories(categories: any): any;
3
3
  export function areTermsValid(terms: any): boolean;
4
4
  export function isPartnershipValid(partnership: any): boolean;
5
5
  /**
6
- * Normalize app manifest, retrocompatibility for old manifests
6
+ * Normalize app manifest, retro-compatibility for old manifests
7
7
  *
8
- * @param {Manifest} manifest
8
+ * @param {Manifest} manifest - app manifest to normalize
9
9
  * @returns {Manifest}
10
10
  */
11
11
  export function sanitize(manifest: Manifest): Manifest;
@@ -8,26 +8,10 @@ export function convert$gtNullSelectors(selector: any): object;
8
8
  export function mergeSelectorAndPartialIndex(queryDefinition: object): object;
9
9
  export function makeSorterFromDefinition(definition: QueryDefinition): (arg0: Array<CozyClientDocument>) => Array<CozyClientDocument>;
10
10
  export default queries;
11
- export function initQuery(queryId: string, queryDefinition: QueryDefinition, options?: QueryOptions): {
12
- type: string;
13
- queryId: string;
14
- queryDefinition: QueryDefinition;
15
- options: QueryOptions;
16
- };
17
- export function loadQuery(queryId: any): {
18
- type: string;
19
- queryId: any;
20
- };
21
- export function receiveQueryResult(queryId: any, response: any, options?: {}): {
22
- type: string;
23
- queryId: any;
24
- response: any;
25
- };
26
- export function receiveQueryError(queryId: any, error: any): {
27
- type: string;
28
- queryId: any;
29
- error: any;
30
- };
11
+ export function initQuery(queryId: string, queryDefinition: QueryDefinition, options?: QueryOptions): object;
12
+ export function loadQuery(queryId: string, options?: QueryOptions): object;
13
+ export function receiveQueryResult(queryId: string, response: object, options?: QueryOptions): object;
14
+ export function receiveQueryError(queryId: string, error: object, options?: QueryOptions): object;
31
15
  export function getQueryFromSlice(state: any, queryId: any, documents: any): any;
32
16
  export class QueryIDGenerator {
33
17
  idCounter: number;
package/types/types.d.ts CHANGED
@@ -35,6 +35,7 @@ export type QueryState = {
35
35
  id: string;
36
36
  definition: QueryDefinition;
37
37
  fetchStatus: QueryFetchStatus;
38
+ isFetching: boolean;
38
39
  lastFetch: number;
39
40
  lastUpdate: number;
40
41
  lastErrorUpdate: number;
@@ -73,6 +74,10 @@ export type QueryOptions = {
73
74
  * - If set to false, the query won't be executed
74
75
  */
75
76
  enabled?: boolean;
77
+ /**
78
+ * - If set to true, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
79
+ */
80
+ backgroundFetching?: boolean;
76
81
  /**
77
82
  * - Whether documents should be returned already hydrated
78
83
  */
@@ -164,6 +169,10 @@ export type CozyClientDocument = {
164
169
  * - referenced by of another document
165
170
  */
166
171
  referenced_by?: Reference[];
172
+ /**
173
+ * - Cozy Metadata
174
+ */
175
+ cozyMetadata?: object;
167
176
  };
168
177
  /**
169
178
  * - An io.cozy.files document