cozy-client 51.6.1 → 52.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.
@@ -71,6 +71,8 @@ var _CozyLink = require("./CozyLink");
71
71
 
72
72
  var _ObservableQuery = _interopRequireDefault(require("./ObservableQuery"));
73
73
 
74
+ var _defaultPerformanceApi = require("./performances/defaultPerformanceApi");
75
+
74
76
  var _snapshots = require("./testing/snapshots");
75
77
 
76
78
  var _logger = _interopRequireDefault(require("./logger"));
@@ -159,6 +161,7 @@ var DOC_UPDATE = 'update';
159
161
  * @property {import("./types").AppMetadata} [appMetadata] - Metadata about the application that will be used in ensureCozyMetadata
160
162
  * @property {import("./types").ClientCapabilities} [capabilities] - Capabilities sent by the stack
161
163
  * @property {boolean} [store] - If set to false, the client will not instantiate a Redux store automatically. Use this if you want to merge cozy-client's store with your own redux store. See [here](https://docs.cozy.io/en/cozy-client/react-integration/#1b-use-your-own-redux-store) for more information.
164
+ * @property {import('./performances/types').PerformanceAPI} [performanceApi] - The performance API that can be used to measure performances
162
165
  */
163
166
 
164
167
  /**
@@ -238,12 +241,16 @@ var CozyClient = /*#__PURE__*/function () {
238
241
  _rawOptions$appMetada = rawOptions.appMetadata,
239
242
  appMetadata = _rawOptions$appMetada === void 0 ? {} : _rawOptions$appMetada,
240
243
  capabilities = rawOptions.capabilities,
241
- _options = (0, _objectWithoutProperties2.default)(rawOptions, ["link", "links", "schema", "appMetadata", "capabilities"]);
244
+ performanceApi = rawOptions.performanceApi,
245
+ _options = (0, _objectWithoutProperties2.default)(rawOptions, ["link", "links", "schema", "appMetadata", "capabilities", "performanceApi"]);
242
246
 
243
247
  if (link) {
244
248
  _logger.default.warn('`link` is deprecated, use `links`');
245
249
  }
250
+ /** @type {import('./performances/types').PerformanceAPI} */
251
+
246
252
 
253
+ this.performanceApi = performanceApi || _defaultPerformanceApi.defaultPerformanceApi;
247
254
  this.appMetadata = appMetadata;
248
255
  this.loginPromise = null;
249
256
  _options.uri = securiseUri(_options.uri);
@@ -263,7 +270,9 @@ var CozyClient = /*#__PURE__*/function () {
263
270
 
264
271
  return _this.emit.apply(_this, ['error'].concat(args));
265
272
  });
266
- this.setLinks(ensureArray(link || links || new _StackLink.default()));
273
+ this.setLinks(ensureArray(link || links || new _StackLink.default({
274
+ performanceApi: this.performanceApi
275
+ })));
267
276
  this.schema = new _Schema.default(schema, stackClient);
268
277
  /**
269
278
  * @type {import("./types").ClientCapabilities}
@@ -1264,6 +1273,7 @@ var CozyClient = /*#__PURE__*/function () {
1264
1273
  update,
1265
1274
  executeFromStore,
1266
1275
  options,
1276
+ markQuery,
1267
1277
  queryId,
1268
1278
  existingQuery,
1269
1279
  shouldFetch,
@@ -1278,53 +1288,54 @@ var CozyClient = /*#__PURE__*/function () {
1278
1288
  case 0:
1279
1289
  _ref5 = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
1280
1290
  update = _ref5.update, executeFromStore = _ref5.executeFromStore, options = (0, _objectWithoutProperties2.default)(_ref5, ["update", "executeFromStore"]);
1291
+ markQuery = this.performanceApi.mark("client.query(".concat(queryDefinition.doctype, ")"));
1281
1292
  this.ensureStore();
1282
1293
  queryId = options.as || this.queryIdGenerator.generateId(queryDefinition);
1283
1294
  existingQuery = this.getQueryFromState(queryId, options);
1284
1295
 
1285
1296
  if (!(options.enabled !== undefined)) {
1286
- _context8.next = 8;
1297
+ _context8.next = 9;
1287
1298
  break;
1288
1299
  }
1289
1300
 
1290
1301
  if (!('boolean' !== typeof options.enabled)) {
1291
- _context8.next = 8;
1302
+ _context8.next = 9;
1292
1303
  break;
1293
1304
  }
1294
1305
 
1295
1306
  throw new Error("option.enabled should be a boolean for this query: ".concat(JSON.stringify(queryDefinition)));
1296
1307
 
1297
- case 8:
1308
+ case 9:
1298
1309
  if (!options.fetchPolicy) {
1299
- _context8.next = 14;
1310
+ _context8.next = 15;
1300
1311
  break;
1301
1312
  }
1302
1313
 
1303
1314
  if (options.as) {
1304
- _context8.next = 11;
1315
+ _context8.next = 12;
1305
1316
  break;
1306
1317
  }
1307
1318
 
1308
1319
  throw new Error('Cannot use `fetchPolicy` without naming the query, please use `as` to name the query');
1309
1320
 
1310
- case 11:
1321
+ case 12:
1311
1322
  shouldFetch = options.fetchPolicy(existingQuery);
1312
1323
 
1313
1324
  if (shouldFetch) {
1314
- _context8.next = 14;
1325
+ _context8.next = 15;
1315
1326
  break;
1316
1327
  }
1317
1328
 
1318
1329
  return _context8.abrupt("return");
1319
1330
 
1320
- case 14:
1331
+ case 15:
1321
1332
  if (!(existingQuery && Object.keys(existingQuery).length > 0)) {
1322
- _context8.next = 17;
1333
+ _context8.next = 18;
1323
1334
  break;
1324
1335
  }
1325
1336
 
1326
1337
  if (!(existingQuery.fetchStatus === 'loading')) {
1327
- _context8.next = 17;
1338
+ _context8.next = 18;
1328
1339
  break;
1329
1340
  }
1330
1341
 
@@ -1332,9 +1343,9 @@ var CozyClient = /*#__PURE__*/function () {
1332
1343
  return (0, _jsonStableStringify.default)(queryDefinition);
1333
1344
  }));
1334
1345
 
1335
- case 17:
1346
+ case 18:
1336
1347
  this.ensureQueryExists(queryId, queryDefinition, options);
1337
- _context8.prev = 18;
1348
+ _context8.prev = 19;
1338
1349
  backgroundFetching = options.backgroundFetching !== undefined ? options.backgroundFetching : this.options.backgroundFetching;
1339
1350
  this.dispatch((0, _store.loadQuery)(queryId, {
1340
1351
  backgroundFetching: backgroundFetching
@@ -1342,55 +1353,65 @@ var CozyClient = /*#__PURE__*/function () {
1342
1353
  requestFn = executeFromStore ? function () {
1343
1354
  return Promise.resolve((0, _store.executeQueryFromState)(_this4.store.getState(), queryDefinition));
1344
1355
  } : function () {
1345
- return _this4.requestQuery(queryDefinition);
1356
+ return _this4.requestQuery(queryDefinition, options);
1346
1357
  };
1347
- _context8.next = 24;
1358
+ _context8.next = 25;
1348
1359
  return this._promiseCache.exec(requestFn, function () {
1349
1360
  return (0, _jsonStableStringify.default)(queryDefinition);
1350
1361
  });
1351
1362
 
1352
- case 24:
1363
+ case 25:
1353
1364
  response = _context8.sent;
1354
1365
  this.dispatch((0, _store.receiveQueryResult)(queryId, response, {
1355
1366
  update: update,
1356
1367
  backgroundFetching: backgroundFetching
1357
1368
  }));
1369
+ this.performanceApi.measure({
1370
+ markName: markQuery,
1371
+ measureName: "".concat(markQuery, " success"),
1372
+ color: 'primary'
1373
+ });
1358
1374
  return _context8.abrupt("return", response);
1359
1375
 
1360
- case 29:
1361
- _context8.prev = 29;
1362
- _context8.t0 = _context8["catch"](18);
1376
+ case 31:
1377
+ _context8.prev = 31;
1378
+ _context8.t0 = _context8["catch"](19);
1379
+ this.performanceApi.measure({
1380
+ markName: markQuery,
1381
+ measureName: "".concat(markQuery, " error"),
1382
+ color: 'error'
1383
+ });
1363
1384
  this.dispatch((0, _store.receiveQueryError)(queryId, _context8.t0)); // specific onError
1364
1385
 
1365
1386
  if (!options.onError) {
1366
- _context8.next = 36;
1387
+ _context8.next = 39;
1367
1388
  break;
1368
1389
  }
1369
1390
 
1370
1391
  options.onError(_context8.t0); // defaulted onError
1371
1392
 
1372
- _context8.next = 41;
1393
+ _context8.next = 44;
1373
1394
  break;
1374
1395
 
1375
- case 36:
1396
+ case 39:
1376
1397
  if (!this.options.onError) {
1377
- _context8.next = 40;
1398
+ _context8.next = 43;
1378
1399
  break;
1379
1400
  }
1380
1401
 
1381
1402
  this.options.onError(_context8.t0);
1382
- _context8.next = 41;
1403
+ _context8.next = 44;
1383
1404
  break;
1384
1405
 
1385
- case 40:
1406
+ case 43:
1386
1407
  throw _context8.t0;
1387
1408
 
1388
- case 41:
1409
+ case 44:
1389
1410
  case "end":
1390
1411
  return _context8.stop();
1391
1412
  }
1392
1413
  }
1393
- }, _callee8, this, [[18, 29]]);
1414
+ }, _callee8, this, [[19, 31]]);
1394
1415
  }));
1395
1416
 
1396
1417
  function query(_x9) {
@@ -1544,7 +1565,7 @@ var CozyClient = /*#__PURE__*/function () {
1544
1565
  this.dispatch((0, _store.initMutation)(mutationId, mutationDefinition));
1545
1566
  _context10.prev = 5;
1546
1567
  _context10.next = 8;
1547
- return this.requestMutation(mutationDefinition);
1568
+ return this.requestMutation(mutationDefinition, options);
1548
1569
 
1549
1570
  case 8:
1550
1571
  response = _context10.sent;
@@ -1585,14 +1606,14 @@ var CozyClient = /*#__PURE__*/function () {
1585
1606
  }, {
1586
1607
  key: "requestQuery",
1587
1608
  value: function () {
1588
- var _requestQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(definition) {
1609
+ var _requestQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(definition, options) {
1589
1610
  var mainResponse, withIncluded;
1590
1611
  return _regenerator.default.wrap(function _callee11$(_context11) {
1591
1612
  while (1) {
1592
1613
  switch (_context11.prev = _context11.next) {
1593
1614
  case 0:
1594
1615
  _context11.next = 2;
1595
- return this.chain.request(definition);
1616
+ return this.chain.request(definition, options);
1596
1617
 
1597
1618
  case 2:
1598
1619
  mainResponse = _context11.sent;
@@ -1623,7 +1644,7 @@ var CozyClient = /*#__PURE__*/function () {
1623
1644
  }, _callee11, this);
1624
1645
  }));
1625
1646
 
1626
- function requestQuery(_x12) {
1647
+ function requestQuery(_x12, _x13) {
1627
1648
  return _requestQuery.apply(this, arguments);
1628
1649
  }
1629
1650
 
@@ -1724,7 +1745,7 @@ var CozyClient = /*#__PURE__*/function () {
1724
1745
  }, _callee12, this, [[12, 22, 25, 28]]);
1725
1746
  }));
1726
1747
 
1727
- function persistVirtualDocuments(_x13, _x14) {
1748
+ function persistVirtualDocuments(_x14, _x15) {
1728
1749
  return _persistVirtualDocuments.apply(this, arguments);
1729
1750
  }
1730
1751
 
@@ -1773,7 +1794,7 @@ var CozyClient = /*#__PURE__*/function () {
1773
1794
  }, _callee13, this);
1774
1795
  }));
1775
1796
 
1776
- function persistVirtualDocument(_x15, _x16) {
1797
+ function persistVirtualDocument(_x16, _x17) {
1777
1798
  return _persistVirtualDocument.apply(this, arguments);
1778
1799
  }
1779
1800
 
@@ -1889,7 +1910,7 @@ var CozyClient = /*#__PURE__*/function () {
1889
1910
  }, _callee14);
1890
1911
  }));
1891
1912
 
1892
- function fetchRelationships(_x17, _x18) {
1913
+ function fetchRelationships(_x18, _x19) {
1893
1914
  return _fetchRelationships.apply(this, arguments);
1894
1915
  }
1895
1916
 
@@ -1898,7 +1919,7 @@ var CozyClient = /*#__PURE__*/function () {
1898
1919
  }, {
1899
1920
  key: "requestMutation",
1900
1921
  value: function () {
1901
- var _requestMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(definition) {
1922
+ var _requestMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(definition, options) {
1902
1923
  var _this6 = this;
1903
1924
 
1904
1925
  var _definition, first, rest, firstResponse;
@@ -1928,7 +1949,7 @@ var CozyClient = /*#__PURE__*/function () {
1928
1949
  return _context15.abrupt("return", firstResponse);
1929
1950
 
1930
1951
  case 8:
1931
- return _context15.abrupt("return", this.chain.request(definition));
1952
+ return _context15.abrupt("return", this.chain.request(definition, options));
1932
1953
 
1933
1954
  case 9:
1934
1955
  case "end":
@@ -1938,7 +1959,7 @@ var CozyClient = /*#__PURE__*/function () {
1938
1959
  }, _callee15, this);
1939
1960
  }));
1940
1961
 
1941
- function requestMutation(_x19) {
1962
+ function requestMutation(_x20, _x21) {
1942
1963
  return _requestMutation.apply(this, arguments);
1943
1964
  }
1944
1965
 
@@ -2224,7 +2245,7 @@ var CozyClient = /*#__PURE__*/function () {
2224
2245
  }, _callee16, this);
2225
2246
  }));
2226
2247
 
2227
- function startOAuthFlow(_x20) {
2248
+ function startOAuthFlow(_x22) {
2228
2249
  return _startOAuthFlow.apply(this, arguments);
2229
2250
  }
2230
2251
 
@@ -2420,7 +2441,7 @@ var CozyClient = /*#__PURE__*/function () {
2420
2441
  key: "ensureStore",
2421
2442
  value: function ensureStore() {
2422
2443
  if (!this.store) {
2423
- this.setStore((0, _store.createStore)());
2444
+ this.setStore((0, _store.createStore)(this.performanceApi));
2424
2445
  }
2425
2446
  }
2426
2447
  /**
@@ -2552,7 +2573,7 @@ var CozyClient = /*#__PURE__*/function () {
2552
2573
  }, {
2553
2574
  key: "reducer",
2554
2575
  value: function reducer() {
2555
- return _store.default;
2576
+ return (0, _store.default)(this.performanceApi);
2556
2577
  }
2557
2578
  }, {
2558
2579
  key: "dispatch",
@@ -2708,7 +2729,9 @@ var CozyClient = /*#__PURE__*/function () {
2708
2729
  }, {
2709
2730
  key: "setLinks",
2710
2731
  value: function setLinks(links) {
2711
- this.links = links ? links : [new _StackLink.default()];
2732
+ this.links = links ? links : [new _StackLink.default({
2733
+ performanceApi: this.performanceApi
2734
+ })];
2712
2735
  this.registerClientOnLinks();
2713
2736
  this.chain = (0, _CozyLink.chain)(this.links);
2714
2737
 
@@ -2763,7 +2786,7 @@ var CozyClient = /*#__PURE__*/function () {
2763
2786
  }, _callee21, this);
2764
2787
  }));
2765
2788
 
2766
- function getSettings(_x21, _x22) {
2789
+ function getSettings(_x23, _x24) {
2767
2790
  return _getSettings2.apply(this, arguments);
2768
2791
  }
2769
2792
 
@@ -2801,7 +2824,7 @@ var CozyClient = /*#__PURE__*/function () {
2801
2824
  }, _callee22, this);
2802
2825
  }));
2803
2826
 
2804
- function saveAfterFetchSettings(_x23, _x24, _x25) {
2827
+ function saveAfterFetchSettings(_x25, _x26, _x27) {
2805
2828
  return _saveAfterFetchSettings2.apply(this, arguments);
2806
2829
  }
2807
2830
 
@@ -2858,7 +2881,7 @@ var CozyClient = /*#__PURE__*/function () {
2858
2881
  }, _callee23, this, [[0, 10]]);
2859
2882
  }));
2860
2883
 
2861
- function resetQuery(_x26) {
2884
+ function resetQuery(_x28) {
2862
2885
  return _resetQuery2.apply(this, arguments);
2863
2886
  }
2864
2887
 
@@ -2933,7 +2956,7 @@ var CozyClient = /*#__PURE__*/function () {
2933
2956
  }, _callee24);
2934
2957
  }));
2935
2958
 
2936
- function fromOldOAuthClient(_x27, _x28) {
2959
+ function fromOldOAuthClient(_x29, _x30) {
2937
2960
  return _fromOldOAuthClient.apply(this, arguments);
2938
2961
  }
2939
2962
 
@@ -3026,7 +3049,7 @@ var CozyClient = /*#__PURE__*/function () {
3026
3049
  CozyClient.hooks = CozyClient.hooks || {};
3027
3050
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3028
3051
 
3029
- CozyClient.version = "51.6.1";
3052
+ CozyClient.version = "52.0.0";
3030
3053
 
3031
3054
  _microee.default.mixin(CozyClient);
3032
3055
 
@@ -64,13 +64,13 @@ describe('CozyClient initialization', () => {
64
64
 
65
65
  beforeEach(() => {
66
66
  links = [
67
- new CozyLink((operation, result = '', forward) => {
68
- return forward(operation, result + 'foo')
67
+ new CozyLink((operation, options, result = '', forward) => {
68
+ return forward(operation, options, result + 'foo')
69
69
  }),
70
- new CozyLink((operation, result, forward) => {
71
- return forward(operation, result + 'bar')
70
+ new CozyLink((operation, options, result, forward) => {
71
+ return forward(operation, options, result + 'bar')
72
72
  }),
73
- (operation, result) => {
73
+ (operation, options, result) => {
74
74
  return result + 'baz'
75
75
  }
76
76
  ]
@@ -475,13 +475,13 @@ describe('CozyClient logout', () => {
475
475
 
476
476
  beforeEach(() => {
477
477
  links = [
478
- new CozyLink((operation, result = '', forward) => {
479
- return forward(operation, result + 'foo')
478
+ new CozyLink((operation, options, result = '', forward) => {
479
+ return forward(operation, options, result + 'foo')
480
480
  }),
481
- new CozyLink((operation, result, forward) => {
482
- return forward(operation, result + 'bar')
481
+ new CozyLink((operation, options, result, forward) => {
482
+ return forward(operation, options, result + 'bar')
483
483
  }),
484
- (operation, result) => {
484
+ (operation, options, result) => {
485
485
  return result + 'baz'
486
486
  }
487
487
  ]
@@ -632,13 +632,13 @@ describe('CozyClient login', () => {
632
632
 
633
633
  beforeEach(() => {
634
634
  links = [
635
- new CozyLink((operation, result = '', forward) => {
636
- return forward(operation, result + 'foo')
635
+ new CozyLink((operation, options, result = '', forward) => {
636
+ return forward(operation, options, result + 'foo')
637
637
  }),
638
- new CozyLink((operation, result, forward) => {
639
- return forward(operation, result + 'bar')
638
+ new CozyLink((operation, options, result, forward) => {
639
+ return forward(operation, options, result + 'bar')
640
640
  }),
641
- (operation, result) => {
641
+ (operation, options, result) => {
642
642
  return result + 'baz'
643
643
  }
644
644
  ]
package/dist/CozyLink.js CHANGED
@@ -33,6 +33,7 @@ var CozyLink = /*#__PURE__*/function () {
33
33
  * Request the given operation from the link
34
34
  *
35
35
  * @param {any} operation - The operation to request
36
+ * @param {any} options - The request options
36
37
  * @param {any} result - The result from the previous request of the chain
37
38
  * @param {any} forward - The next request of the chain
38
39
  * @returns {Promise<any>}
@@ -42,7 +43,7 @@ var CozyLink = /*#__PURE__*/function () {
42
43
  (0, _createClass2.default)(CozyLink, [{
43
44
  key: "request",
44
45
  value: function () {
45
- var _request = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(operation, result, forward) {
46
+ var _request = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(operation, options, result, forward) {
46
47
  return _regenerator.default.wrap(function _callee$(_context) {
47
48
  while (1) {
48
49
  switch (_context.prev = _context.next) {
@@ -57,7 +58,7 @@ var CozyLink = /*#__PURE__*/function () {
57
58
  }, _callee);
58
59
  }));
59
60
 
60
- function request(_x, _x2, _x3) {
61
+ function request(_x, _x2, _x3, _x4) {
61
62
  return _request.apply(this, arguments);
62
63
  }
63
64
 
@@ -89,7 +90,7 @@ var CozyLink = /*#__PURE__*/function () {
89
90
  }, _callee2);
90
91
  }));
91
92
 
92
- function persistCozyData(_x4, _x5) {
93
+ function persistCozyData(_x5, _x6) {
93
94
  return _persistCozyData.apply(this, arguments);
94
95
  }
95
96
 
@@ -135,7 +136,7 @@ var toLink = function toLink(handler) {
135
136
  return typeof handler === 'function' ? new CozyLink(handler) : handler;
136
137
  };
137
138
 
138
- var defaultLinkRequestHandler = function defaultLinkRequestHandler(operation, result) {
139
+ var defaultLinkRequestHandler = function defaultLinkRequestHandler(operation, options, result) {
139
140
  if (result) return result;else if (operation.execute) return operation.execute();else throw new Error("No link could handle operation ".concat(JSON.stringify(operation)));
140
141
  };
141
142
 
@@ -151,12 +152,12 @@ var chain = function chain(links) {
151
152
  exports.chain = chain;
152
153
 
153
154
  var concat = function concat(firstLink, nextLink) {
154
- var requestHandler = function requestHandler(operation, result, forward) {
155
- var nextForward = function nextForward(op, res) {
156
- return nextLink.request(op, res, forward);
155
+ var requestHandler = function requestHandler(operation, options, result, forward) {
156
+ var nextForward = function nextForward(op, opts, res) {
157
+ return nextLink.request(op, opts, res, forward);
157
158
  };
158
159
 
159
- return firstLink.request(operation, result, nextForward);
160
+ return firstLink.request(operation, options, result, nextForward);
160
161
  };
161
162
 
162
163
  var persistHandler = function persistHandler(data, forward) {
@@ -3,13 +3,13 @@ import CozyLink, { chain } from './CozyLink'
3
3
  describe('CozyLink', () => {
4
4
  it('should be chainable', () => {
5
5
  const link = chain([
6
- new CozyLink((operation, result = '', forward) => {
7
- return forward(operation, result + 'foo')
6
+ new CozyLink((operation, options, result = '', forward) => {
7
+ return forward(operation, options, result + 'foo')
8
8
  }),
9
- new CozyLink((operation, result, forward) => {
10
- return forward(operation, result + 'bar')
9
+ new CozyLink((operation, options, result, forward) => {
10
+ return forward(operation, options, result + 'bar')
11
11
  }),
12
- (operation, result) => {
12
+ (operation, options, result) => {
13
13
  return result + 'baz'
14
14
  }
15
15
  ])
@@ -19,8 +19,8 @@ describe('CozyLink', () => {
19
19
  describe('default last link', () => {
20
20
  it('should throw an error when called without result', () => {
21
21
  const link = chain([
22
- new CozyLink((operation, result = '', forward) => {
23
- return forward(operation)
22
+ new CozyLink((operation, options, result = '', forward) => {
23
+ return forward(operation, options)
24
24
  })
25
25
  ])
26
26
  expect(() =>
@@ -28,10 +28,10 @@ describe('CozyLink', () => {
28
28
  ).toThrowErrorMatchingSnapshot()
29
29
  })
30
30
 
31
- it('should return the final result if tehre is one', () => {
31
+ it('should return the final result if there is one', () => {
32
32
  const link = chain([
33
- new CozyLink((operation, result, forward) => {
34
- return forward(operation, 'foo')
33
+ new CozyLink((operation, options, result, forward) => {
34
+ return forward(operation, options, 'foo')
35
35
  })
36
36
  ])
37
37
 
@@ -40,8 +40,8 @@ describe('CozyLink', () => {
40
40
 
41
41
  it('should call the custom execution function', () => {
42
42
  const link = chain([
43
- new CozyLink((operation, result = '', forward) => {
44
- return forward(operation)
43
+ new CozyLink((operation, options, result = '', forward) => {
44
+ return forward(operation, options)
45
45
  })
46
46
  ])
47
47
  const spyFn = jest.fn(() => 'bar')
package/dist/StackLink.js CHANGED
@@ -39,6 +39,8 @@ var _logger = _interopRequireDefault(require("./logger"));
39
39
 
40
40
  var _utils = require("./utils");
41
41
 
42
+ var _defaultPerformanceApi = require("./performances/defaultPerformanceApi");
43
+
42
44
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
43
45
 
44
46
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
@@ -99,6 +101,7 @@ var transformBulkDocsResponse = function transformBulkDocsResponse(bulkResponse,
99
101
  * @property {object} [stackClient] - A StackClient
100
102
  * @property {object} [client] - A StackClient (deprecated)
101
103
  * @property {import('cozy-pouch-link/dist/types').LinkPlatform} [platform] - Platform specific adapters and methods
104
+ * @property {import('./performances/types').PerformanceAPI} [performanceApi] - The performance API that can be used to measure performances
102
105
  */
103
106
 
104
107
  /**
@@ -122,7 +125,8 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
122
125
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
123
126
  client = _ref.client,
124
127
  stackClient = _ref.stackClient,
125
- platform = _ref.platform;
128
+ platform = _ref.platform,
129
+ performanceApi = _ref.performanceApi;
126
130
 
127
131
  (0, _classCallCheck2.default)(this, StackLink);
128
132
  _this = _super.call(this);
@@ -133,6 +137,9 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
133
137
 
134
138
  _this.stackClient = stackClient || client;
135
139
  _this.isOnline = platform === null || platform === void 0 ? void 0 : platform.isOnline;
140
+ /** @type {import('./performances/types').PerformanceAPI} */
141
+
142
+ _this.performanceApi = performanceApi || _defaultPerformanceApi.defaultPerformanceApi;
136
143
  return _this;
137
144
  }
138
145
 
@@ -168,12 +175,12 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
168
175
  }, {
169
176
  key: "request",
170
177
  value: function () {
171
- var _request = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(operation, result, forward) {
178
+ var _request = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(operation, options, result, forward) {
172
179
  return _regenerator.default.wrap(function _callee2$(_context2) {
173
180
  while (1) {
174
181
  switch (_context2.prev = _context2.next) {
175
182
  case 0:
176
- _context2.t0 = this.isOnline;
183
+ _context2.t0 = !(options !== null && options !== void 0 && options.forceStack) && this.isOnline;
177
184
 
178
185
  if (!_context2.t0) {
179
186
  _context2.next = 5;
@@ -192,7 +199,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
192
199
  break;
193
200
  }
194
201
 
195
- return _context2.abrupt("return", forward(operation));
202
+ return _context2.abrupt("return", forward(operation, options));
196
203
 
197
204
  case 7:
198
205
  _context2.prev = 7;
@@ -203,7 +210,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
203
210
  }
204
211
 
205
212
  _context2.next = 11;
206
- return this.executeMutation(operation, result, forward);
213
+ return this.executeMutation(operation, options, result, forward);
207
214
 
208
215
  case 11:
209
216
  return _context2.abrupt("return", _context2.sent);
@@ -219,12 +226,12 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
219
226
  _context2.prev = 17;
220
227
  _context2.t1 = _context2["catch"](7);
221
228
 
222
- if (!(0, _utils.isReactNativeOfflineError)(_context2.t1)) {
229
+ if (!(!(options !== null && options !== void 0 && options.forceStack) && (0, _utils.isReactNativeOfflineError)(_context2.t1))) {
223
230
  _context2.next = 21;
224
231
  break;
225
232
  }
226
233
 
227
- return _context2.abrupt("return", forward(operation));
234
+ return _context2.abrupt("return", forward(operation, options));
228
235
 
229
236
  case 21:
230
237
  throw _context2.t1;
@@ -237,7 +244,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
237
244
  }, _callee2, this, [[7, 17]]);
238
245
  }));
239
246
 
240
- function request(_x, _x2, _x3) {
247
+ function request(_x, _x2, _x3, _x4) {
241
248
  return _request.apply(this, arguments);
242
249
  }
243
250
 
@@ -261,7 +268,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
261
268
  }, _callee3);
262
269
  }));
263
270
 
264
- function persistCozyData(_x4, _x5) {
271
+ function persistCozyData(_x5, _x6) {
265
272
  return _persistCozyData.apply(this, arguments);
266
273
  }
267
274
 
@@ -312,7 +319,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
312
319
  }, {
313
320
  key: "executeMutation",
314
321
  value: function () {
315
- var _executeMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(mutation, result, forward) {
322
+ var _executeMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(mutation, options, result, forward) {
316
323
  var mutationType, doc, docs, props, updateAllResp;
317
324
  return _regenerator.default.wrap(function _callee4$(_context4) {
318
325
  while (1) {
@@ -372,7 +379,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
372
379
  return _context4.abrupt("return", this.stackClient.collection(_const.DOCTYPE_FILES).upload(props.file, props.dirPath));
373
380
 
374
381
  case 24:
375
- return _context4.abrupt("return", forward(mutation, result));
382
+ return _context4.abrupt("return", forward(mutation, options, result));
376
383
 
377
384
  case 25:
378
385
  case "end":
@@ -382,7 +389,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
382
389
  }, _callee4, this);
383
390
  }));
384
391
 
385
- function executeMutation(_x6, _x7, _x8) {
392
+ function executeMutation(_x7, _x8, _x9, _x10) {
386
393
  return _executeMutation.apply(this, arguments);
387
394
  }
388
395