cozy-pouch-link 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.
@@ -148,6 +148,7 @@ var normalizeAll = function normalizeAll(client) {
148
148
  * @property {string[]} doctypes Doctypes to replicate
149
149
  * @property {Record<string, object>} doctypesReplicationOptions A mapping from doctypes to replication options. All pouch replication options can be used, as well as the "strategy" option that determines which way the replication is done (can be "sync", "fromRemote" or "toRemote")
150
150
  * @property {import('./types').LinkPlatform} platform Platform specific adapters and methods
151
+ * @property {import('cozy-client/src/performances/types').PerformanceAPI} [performanceApi] - The performance API that can be used to measure performances
151
152
  */
152
153
 
153
154
  /**
@@ -180,7 +181,8 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
180
181
  periodicSync = options.periodicSync,
181
182
  initialSync = options.initialSync,
182
183
  syncDebounceDelayInMs = options.syncDebounceDelayInMs,
183
- syncDebounceMaxDelayInMs = options.syncDebounceMaxDelayInMs;
184
+ syncDebounceMaxDelayInMs = options.syncDebounceMaxDelayInMs,
185
+ performanceApi = options.performanceApi;
184
186
  _this.options = options;
185
187
 
186
188
  if (!doctypes) {
@@ -201,6 +203,9 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
201
203
  _this.startReplicationDebounced = (0, _debounce.default)(_this._startReplication, syncDebounceDelayInMs || DEFAULT_DEBOUNCE_DELAY, {
202
204
  maxWait: syncDebounceMaxDelayInMs || MAX_DEBOUNCE_DELAY
203
205
  });
206
+ /** @type {import('cozy-client/src/performances/types').PerformanceAPI} */
207
+
208
+ _this.performanceApi = performanceApi || _cozyClient.defaultPerformanceApi;
204
209
  return _this;
205
210
  }
206
211
  /**
@@ -355,7 +360,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
355
360
  var _onLogin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
356
361
  var _this2 = this;
357
362
 
358
- var prefix, shouldDestroyDatabases, adapter;
363
+ var markName, prefix, shouldDestroyDatabases, adapter;
359
364
  return _regenerator.default.wrap(function _callee3$(_context3) {
360
365
  while (1) {
361
366
  switch (_context3.prev = _context3.next) {
@@ -370,11 +375,12 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
370
375
  return _context3.abrupt("return");
371
376
 
372
377
  case 3:
378
+ markName = this.performanceApi.mark('onLogin');
373
379
  prefix = (0, _utils.getPrefix)(this.client.stackClient.uri);
374
380
  shouldDestroyDatabases = this.pouches && this.pouches.options && this.pouches.options.prefix !== prefix;
375
381
 
376
382
  if (!shouldDestroyDatabases) {
377
- _context3.next = 15;
383
+ _context3.next = 16;
378
384
  break;
379
385
  }
380
386
 
@@ -382,47 +388,47 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
382
388
  _logger.default.info('PouchLink: URI changed, destroy pouches');
383
389
  }
384
390
 
385
- _context3.prev = 7;
386
- _context3.next = 10;
391
+ _context3.prev = 8;
392
+ _context3.next = 11;
387
393
  return this.pouches.destroy();
388
394
 
389
- case 10:
390
- _context3.next = 15;
395
+ case 11:
396
+ _context3.next = 16;
391
397
  break;
392
398
 
393
- case 12:
394
- _context3.prev = 12;
395
- _context3.t0 = _context3["catch"](7);
399
+ case 13:
400
+ _context3.prev = 13;
401
+ _context3.t0 = _context3["catch"](8);
396
402
 
397
403
  _logger.default.warn('Error while destroying pouch DBs', _context3.t0);
398
404
 
399
- case 15:
405
+ case 16:
400
406
  if (prefix) {
401
- _context3.next = 17;
407
+ _context3.next = 18;
402
408
  break;
403
409
  }
404
410
 
405
411
  throw new Error('PouchLink: Prefix is required');
406
412
 
407
- case 17:
413
+ case 18:
408
414
  if (process.env.NODE_ENV !== 'production') {
409
415
  _logger.default.log('Create pouches with ' + prefix + ' prefix');
410
416
  }
411
417
 
412
- _context3.next = 20;
418
+ _context3.next = 21;
413
419
  return this.storage.getAdapterName();
414
420
 
415
- case 20:
421
+ case 21:
416
422
  if (_context3.sent) {
417
- _context3.next = 24;
423
+ _context3.next = 25;
418
424
  break;
419
425
  }
420
426
 
421
427
  adapter = (0, _get.default)(this.options, 'pouch.options.adapter');
422
- _context3.next = 24;
428
+ _context3.next = 25;
423
429
  return this.storage.persistAdapterName(adapter);
424
430
 
425
- case 24:
431
+ case 25:
426
432
  this.pouches = new _PouchManager.default(this.doctypes, {
427
433
  pouch: this.options.pouch,
428
434
  getReplicationURL: this.getReplicationURL.bind(this),
@@ -437,20 +443,25 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
437
443
  executeQuery: this.executeQuery.bind(this),
438
444
  platform: this.options.platform
439
445
  });
440
- _context3.next = 27;
446
+ _context3.next = 28;
441
447
  return this.pouches.init();
442
448
 
443
- case 27:
449
+ case 28:
444
450
  if (this.client && this.initialSync) {
445
451
  this.startReplication();
446
452
  }
447
453
 
448
- case 28:
454
+ this.performanceApi.measure({
455
+ markName: markName,
456
+ category: 'CozyPouchLink'
457
+ });
458
+
459
+ case 30:
449
460
  case "end":
450
461
  return _context3.stop();
451
462
  }
452
463
  }
453
- }, _callee3, this, [[7, 12]]);
464
+ }, _callee3, this, [[8, 13]]);
454
465
  }));
455
466
 
456
467
  function onLogin() {
@@ -685,7 +696,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
685
696
  }, {
686
697
  key: "request",
687
698
  value: function () {
688
- var _request = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(operation) {
699
+ var _request = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(operation, options) {
689
700
  var result,
690
701
  forward,
691
702
  doctype,
@@ -694,12 +705,21 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
694
705
  while (1) {
695
706
  switch (_context6.prev = _context6.next) {
696
707
  case 0:
697
- result = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : null;
698
- forward = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : doNothing;
708
+ result = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : null;
709
+ forward = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : doNothing;
710
+
711
+ if (!(options !== null && options !== void 0 && options.forceStack)) {
712
+ _context6.next = 4;
713
+ break;
714
+ }
715
+
716
+ return _context6.abrupt("return", forward(operation, options));
717
+
718
+ case 4:
699
719
  doctype = (0, _cozyClient.getDoctypeFromOperation)(operation);
700
720
 
701
721
  if (this.pouches) {
702
- _context6.next = 6;
722
+ _context6.next = 8;
703
723
  break;
704
724
  }
705
725
 
@@ -707,11 +727,11 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
707
727
  _logger.default.info("Tried to access local ".concat(doctype, " but Cozy Pouch is not initialized yet. Forwarding the operation to next link"));
708
728
  }
709
729
 
710
- return _context6.abrupt("return", forward(operation));
730
+ return _context6.abrupt("return", forward(operation, options));
711
731
 
712
- case 6:
732
+ case 8:
713
733
  if (!(this.pouches.getSyncStatus(doctype) === 'not_synced')) {
714
- _context6.next = 9;
734
+ _context6.next = 11;
715
735
  break;
716
736
  }
717
737
 
@@ -719,15 +739,15 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
719
739
  _logger.default.info("Tried to access local ".concat(doctype, " but Cozy Pouch is not synced yet. Forwarding the operation to next link"));
720
740
  }
721
741
 
722
- return _context6.abrupt("return", forward(operation));
742
+ return _context6.abrupt("return", forward(operation, options));
723
743
 
724
- case 9:
725
- _context6.next = 11;
744
+ case 11:
745
+ _context6.next = 13;
726
746
  return this.needsToWaitWarmup(doctype);
727
747
 
728
- case 11:
748
+ case 13:
729
749
  if (!_context6.sent) {
730
- _context6.next = 14;
750
+ _context6.next = 16;
731
751
  break;
732
752
  }
733
753
 
@@ -735,11 +755,11 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
735
755
  _logger.default.info("Tried to access local ".concat(doctype, " but not warmuped yet. Forwarding the operation to next link"));
736
756
  }
737
757
 
738
- return _context6.abrupt("return", forward(operation));
758
+ return _context6.abrupt("return", forward(operation, options));
739
759
 
740
- case 14:
760
+ case 16:
741
761
  if (this.supportsOperation(operation)) {
742
- _context6.next = 17;
762
+ _context6.next = 19;
743
763
  break;
744
764
  }
745
765
 
@@ -747,20 +767,20 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
747
767
  _logger.default.info("The doctype '".concat(doctype, "' is not supported. Forwarding the operation to next link"));
748
768
  }
749
769
 
750
- return _context6.abrupt("return", forward(operation));
770
+ return _context6.abrupt("return", forward(operation, options));
751
771
 
752
- case 17:
772
+ case 19:
753
773
  if (!operation.mutationType) {
754
- _context6.next = 21;
774
+ _context6.next = 23;
755
775
  break;
756
776
  }
757
777
 
758
- return _context6.abrupt("return", this.executeMutation(operation, result, forward));
778
+ return _context6.abrupt("return", this.executeMutation(operation, options, result, forward));
759
779
 
760
- case 21:
780
+ case 23:
761
781
  return _context6.abrupt("return", this.executeQuery(operation));
762
782
 
763
- case 22:
783
+ case 24:
764
784
  case "end":
765
785
  return _context6.stop();
766
786
  }
@@ -768,7 +788,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
768
788
  }, _callee6, this);
769
789
  }));
770
790
 
771
- function request(_x4) {
791
+ function request(_x4, _x5) {
772
792
  return _request.apply(this, arguments);
773
793
  }
774
794
 
@@ -811,7 +831,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
811
831
  }, _callee7, this);
812
832
  }));
813
833
 
814
- function getChanges(_x5, _x6) {
834
+ function getChanges(_x6, _x7) {
815
835
  return _getChanges.apply(this, arguments);
816
836
  }
817
837
 
@@ -853,7 +873,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
853
873
  }, _callee8, this);
854
874
  }));
855
875
 
856
- function getDbInfo(_x7) {
876
+ function getDbInfo(_x8) {
857
877
  return _getDbInfo.apply(this, arguments);
858
878
  }
859
879
 
@@ -887,6 +907,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
887
907
  value: function () {
888
908
  var _persistCozyData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(data) {
889
909
  var forward,
910
+ markName,
890
911
  sanitizedDoc,
891
912
  oldDoc,
892
913
  db,
@@ -896,12 +917,13 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
896
917
  switch (_context9.prev = _context9.next) {
897
918
  case 0:
898
919
  forward = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : doNothing;
920
+ markName = this.performanceApi.mark('persistCozyData');
899
921
  sanitizedDoc = this.sanitizeJsonApi(data);
900
922
  sanitizedDoc.cozyLocalOnly = true;
901
- _context9.next = 5;
923
+ _context9.next = 6;
902
924
  return this.getExistingDocument(data._id, data._type);
903
925
 
904
- case 5:
926
+ case 6:
905
927
  oldDoc = _context9.sent;
906
928
 
907
929
  if (oldDoc) {
@@ -909,10 +931,16 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
909
931
  }
910
932
 
911
933
  db = this.pouches.getPouch(data._type);
912
- _context9.next = 10;
934
+ _context9.next = 11;
913
935
  return db.put(sanitizedDoc);
914
936
 
915
- case 10:
937
+ case 11:
938
+ this.performanceApi.measure({
939
+ markName: markName,
940
+ category: 'CozyPouchLink'
941
+ });
942
+
943
+ case 12:
916
944
  case "end":
917
945
  return _context9.stop();
918
946
  }
@@ -920,7 +948,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
920
948
  }, _callee9, this);
921
949
  }));
922
950
 
923
- function persistCozyData(_x8) {
951
+ function persistCozyData(_x9) {
924
952
  return _persistCozyData.apply(this, arguments);
925
953
  }
926
954
 
@@ -942,6 +970,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
942
970
  var _getExistingDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(id, type) {
943
971
  var throwIfNotFound,
944
972
  db,
973
+ markName,
945
974
  existingDoc,
946
975
  _args10 = arguments;
947
976
  return _regenerator.default.wrap(function _callee10$(_context10) {
@@ -951,36 +980,41 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
951
980
  throwIfNotFound = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : false;
952
981
  _context10.prev = 1;
953
982
  db = this.pouches.getPouch(type);
954
- _context10.next = 5;
983
+ markName = this.performanceApi.mark('db.get from getExistingDocument');
984
+ _context10.next = 6;
955
985
  return db.get(id);
956
986
 
957
- case 5:
987
+ case 6:
958
988
  existingDoc = _context10.sent;
989
+ this.performanceApi.measure({
990
+ markName: markName,
991
+ category: 'PouchDB'
992
+ });
959
993
  return _context10.abrupt("return", existingDoc);
960
994
 
961
- case 9:
962
- _context10.prev = 9;
995
+ case 11:
996
+ _context10.prev = 11;
963
997
  _context10.t0 = _context10["catch"](1);
964
998
 
965
999
  if (!(_context10.t0.name === 'not_found' && !throwIfNotFound)) {
966
- _context10.next = 15;
1000
+ _context10.next = 17;
967
1001
  break;
968
1002
  }
969
1003
 
970
1004
  return _context10.abrupt("return", null);
971
1005
 
972
- case 15:
1006
+ case 17:
973
1007
  throw _context10.t0;
974
1008
 
975
- case 16:
1009
+ case 18:
976
1010
  case "end":
977
1011
  return _context10.stop();
978
1012
  }
979
1013
  }
980
- }, _callee10, this, [[1, 9]]);
1014
+ }, _callee10, this, [[1, 11]]);
981
1015
  }));
982
1016
 
983
- function getExistingDocument(_x9, _x10) {
1017
+ function getExistingDocument(_x10, _x11) {
984
1018
  return _getExistingDocument.apply(this, arguments);
985
1019
  }
986
1020
 
@@ -1025,7 +1059,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1025
1059
  }, _callee11, this);
1026
1060
  }));
1027
1061
 
1028
- function needsToWaitWarmup(_x11) {
1062
+ function needsToWaitWarmup(_x12) {
1029
1063
  return _needsToWaitWarmup.apply(this, arguments);
1030
1064
  }
1031
1065
 
@@ -1090,7 +1124,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1090
1124
  }, _callee12, this);
1091
1125
  }));
1092
1126
 
1093
- function createIndex(_x12) {
1127
+ function createIndex(_x13) {
1094
1128
  return _createIndex.apply(this, arguments);
1095
1129
  }
1096
1130
 
@@ -1181,7 +1215,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1181
1215
  }, _callee13, this);
1182
1216
  }));
1183
1217
 
1184
- function ensureIndex(_x13, _x14) {
1218
+ function ensureIndex(_x14, _x15) {
1185
1219
  return _ensureIndex.apply(this, arguments);
1186
1220
  }
1187
1221
 
@@ -1191,69 +1225,86 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1191
1225
  key: "executeQuery",
1192
1226
  value: function () {
1193
1227
  var _executeQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(_ref3) {
1194
- var doctype, selector, sort, fields, limit, id, ids, skip, indexedFields, partialFilter, db, res, withRows, findSelector, findOpts, index;
1228
+ var doctype, selector, sort, fields, limit, id, ids, skip, indexedFields, partialFilter, markName, db, res, withRows, _markName, _markName2, _markName3, findSelector, findOpts, index, _markName4, jsonResult;
1229
+
1195
1230
  return _regenerator.default.wrap(function _callee14$(_context14) {
1196
1231
  while (1) {
1197
1232
  switch (_context14.prev = _context14.next) {
1198
1233
  case 0:
1199
1234
  doctype = _ref3.doctype, selector = _ref3.selector, sort = _ref3.sort, fields = _ref3.fields, limit = _ref3.limit, id = _ref3.id, ids = _ref3.ids, skip = _ref3.skip, indexedFields = _ref3.indexedFields, partialFilter = _ref3.partialFilter;
1235
+ markName = this.performanceApi.mark('executeQuery');
1200
1236
  db = this.getPouch(doctype);
1201
1237
 
1202
1238
  if (!id) {
1203
- _context14.next = 9;
1239
+ _context14.next = 12;
1204
1240
  break;
1205
1241
  }
1206
1242
 
1207
- _context14.next = 5;
1243
+ _markName = this.performanceApi.mark('db.get from executeQuery');
1244
+ _context14.next = 7;
1208
1245
  return db.get(id);
1209
1246
 
1210
- case 5:
1247
+ case 7:
1211
1248
  res = _context14.sent;
1249
+ this.performanceApi.measure({
1250
+ markName: _markName,
1251
+ category: 'PouchDB'
1252
+ });
1212
1253
  withRows = false;
1213
- _context14.next = 38;
1254
+ _context14.next = 47;
1214
1255
  break;
1215
1256
 
1216
- case 9:
1257
+ case 12:
1217
1258
  if (!ids) {
1218
- _context14.next = 18;
1259
+ _context14.next = 23;
1219
1260
  break;
1220
1261
  }
1221
1262
 
1222
- _context14.next = 12;
1263
+ _markName2 = this.performanceApi.mark('allDocs from executeQuery with ids');
1264
+ _context14.next = 16;
1223
1265
  return allDocs(db, {
1224
1266
  include_docs: true,
1225
1267
  keys: ids
1226
1268
  });
1227
1269
 
1228
- case 12:
1270
+ case 16:
1229
1271
  res = _context14.sent;
1272
+ this.performanceApi.measure({
1273
+ markName: _markName2,
1274
+ category: 'PouchDB'
1275
+ });
1230
1276
  res = withoutDesignDocuments(res);
1231
1277
  res.total_rows = null; // pouch indicates the total number of docs in res.total_rows, even though we use "keys". Setting it to null avoids cozy-client thinking there are more docs to fetch.
1232
1278
 
1233
1279
  withRows = true;
1234
- _context14.next = 38;
1280
+ _context14.next = 47;
1235
1281
  break;
1236
1282
 
1237
- case 18:
1283
+ case 23:
1238
1284
  if (!(!selector && !partialFilter && !fields && !sort)) {
1239
- _context14.next = 26;
1285
+ _context14.next = 33;
1240
1286
  break;
1241
1287
  }
1242
1288
 
1243
- _context14.next = 21;
1289
+ _markName3 = this.performanceApi.mark('allDocs from executeQuery');
1290
+ _context14.next = 27;
1244
1291
  return allDocs(db, {
1245
1292
  include_docs: true,
1246
1293
  limit: limit
1247
1294
  });
1248
1295
 
1249
- case 21:
1296
+ case 27:
1250
1297
  res = _context14.sent;
1298
+ this.performanceApi.measure({
1299
+ markName: _markName3,
1300
+ category: 'PouchDB'
1301
+ });
1251
1302
  res = withoutDesignDocuments(res);
1252
1303
  withRows = true;
1253
- _context14.next = 38;
1304
+ _context14.next = 47;
1254
1305
  break;
1255
1306
 
1256
- case 26:
1307
+ case 33:
1257
1308
  findSelector = _helpers.default.normalizeFindSelector({
1258
1309
  selector: selector,
1259
1310
  sort: sort,
@@ -1269,33 +1320,43 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1269
1320
  limit: limit,
1270
1321
  skip: skip
1271
1322
  };
1272
- _context14.next = 30;
1323
+ _context14.next = 37;
1273
1324
  return this.ensureIndex(doctype, _objectSpread(_objectSpread({}, findOpts), {}, {
1274
1325
  indexedFields: indexedFields,
1275
1326
  partialFilter: partialFilter
1276
1327
  }));
1277
1328
 
1278
- case 30:
1329
+ case 37:
1279
1330
  index = _context14.sent;
1280
1331
  findOpts.use_index = index.id;
1281
- _context14.next = 34;
1332
+ _markName4 = this.performanceApi.mark('find from executeQuery');
1333
+ _context14.next = 42;
1282
1334
  return find(db, findOpts);
1283
1335
 
1284
- case 34:
1336
+ case 42:
1285
1337
  res = _context14.sent;
1338
+ this.performanceApi.measure({
1339
+ markName: _markName4,
1340
+ category: 'PouchDB'
1341
+ });
1286
1342
  res.offset = skip;
1287
1343
  res.limit = limit;
1288
1344
  withRows = true;
1289
1345
 
1290
- case 38:
1291
- return _context14.abrupt("return", jsonapi.fromPouchResult({
1346
+ case 47:
1347
+ jsonResult = jsonapi.fromPouchResult({
1292
1348
  res: res,
1293
1349
  withRows: withRows,
1294
1350
  doctype: doctype,
1295
1351
  client: this.client
1296
- }));
1352
+ });
1353
+ this.performanceApi.measure({
1354
+ markName: markName,
1355
+ category: 'CozyPouchLink'
1356
+ });
1357
+ return _context14.abrupt("return", jsonResult);
1297
1358
 
1298
- case 39:
1359
+ case 50:
1299
1360
  case "end":
1300
1361
  return _context14.stop();
1301
1362
  }
@@ -1303,7 +1364,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1303
1364
  }, _callee14, this);
1304
1365
  }));
1305
1366
 
1306
- function executeQuery(_x15) {
1367
+ function executeQuery(_x16) {
1307
1368
  return _executeQuery.apply(this, arguments);
1308
1369
  }
1309
1370
 
@@ -1312,68 +1373,74 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1312
1373
  }, {
1313
1374
  key: "executeMutation",
1314
1375
  value: function () {
1315
- var _executeMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(mutation, result, forward) {
1316
- var pouchRes;
1376
+ var _executeMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(mutation, options, result, forward) {
1377
+ var markName, pouchRes, jsonResult;
1317
1378
  return _regenerator.default.wrap(function _callee15$(_context15) {
1318
1379
  while (1) {
1319
1380
  switch (_context15.prev = _context15.next) {
1320
1381
  case 0:
1382
+ markName = this.performanceApi.mark('executeMutation');
1321
1383
  _context15.t0 = mutation.mutationType;
1322
- _context15.next = _context15.t0 === _cozyClient.MutationTypes.CREATE_DOCUMENT ? 3 : _context15.t0 === _cozyClient.MutationTypes.UPDATE_DOCUMENT ? 7 : _context15.t0 === _cozyClient.MutationTypes.UPDATE_DOCUMENTS ? 11 : _context15.t0 === _cozyClient.MutationTypes.DELETE_DOCUMENT ? 15 : _context15.t0 === _cozyClient.MutationTypes.ADD_REFERENCES_TO ? 19 : 23;
1384
+ _context15.next = _context15.t0 === _cozyClient.MutationTypes.CREATE_DOCUMENT ? 4 : _context15.t0 === _cozyClient.MutationTypes.UPDATE_DOCUMENT ? 8 : _context15.t0 === _cozyClient.MutationTypes.UPDATE_DOCUMENTS ? 12 : _context15.t0 === _cozyClient.MutationTypes.DELETE_DOCUMENT ? 16 : _context15.t0 === _cozyClient.MutationTypes.ADD_REFERENCES_TO ? 20 : 24;
1323
1385
  break;
1324
1386
 
1325
- case 3:
1326
- _context15.next = 5;
1387
+ case 4:
1388
+ _context15.next = 6;
1327
1389
  return this.createDocument(mutation);
1328
1390
 
1329
- case 5:
1391
+ case 6:
1330
1392
  pouchRes = _context15.sent;
1331
- return _context15.abrupt("break", 24);
1393
+ return _context15.abrupt("break", 25);
1332
1394
 
1333
- case 7:
1334
- _context15.next = 9;
1395
+ case 8:
1396
+ _context15.next = 10;
1335
1397
  return this.updateDocument(mutation);
1336
1398
 
1337
- case 9:
1399
+ case 10:
1338
1400
  pouchRes = _context15.sent;
1339
- return _context15.abrupt("break", 24);
1401
+ return _context15.abrupt("break", 25);
1340
1402
 
1341
- case 11:
1342
- _context15.next = 13;
1403
+ case 12:
1404
+ _context15.next = 14;
1343
1405
  return this.updateDocuments(mutation);
1344
1406
 
1345
- case 13:
1407
+ case 14:
1346
1408
  pouchRes = _context15.sent;
1347
- return _context15.abrupt("break", 24);
1409
+ return _context15.abrupt("break", 25);
1348
1410
 
1349
- case 15:
1350
- _context15.next = 17;
1411
+ case 16:
1412
+ _context15.next = 18;
1351
1413
  return this.deleteDocument(mutation);
1352
1414
 
1353
- case 17:
1415
+ case 18:
1354
1416
  pouchRes = _context15.sent;
1355
- return _context15.abrupt("break", 24);
1417
+ return _context15.abrupt("break", 25);
1356
1418
 
1357
- case 19:
1358
- _context15.next = 21;
1419
+ case 20:
1420
+ _context15.next = 22;
1359
1421
  return this.addReferencesTo(mutation);
1360
1422
 
1361
- case 21:
1423
+ case 22:
1362
1424
  pouchRes = _context15.sent;
1363
- return _context15.abrupt("break", 24);
1364
-
1365
- case 23:
1366
- return _context15.abrupt("return", forward(mutation, result));
1425
+ return _context15.abrupt("break", 25);
1367
1426
 
1368
1427
  case 24:
1369
- return _context15.abrupt("return", jsonapi.fromPouchResult({
1428
+ return _context15.abrupt("return", forward(mutation, options, result));
1429
+
1430
+ case 25:
1431
+ jsonResult = jsonapi.fromPouchResult({
1370
1432
  res: pouchRes,
1371
1433
  withRows: false,
1372
1434
  doctype: (0, _cozyClient.getDoctypeFromOperation)(mutation),
1373
1435
  client: this.client
1374
- }));
1436
+ });
1437
+ this.performanceApi.measure({
1438
+ markName: markName,
1439
+ category: 'CozyPouchLink'
1440
+ });
1441
+ return _context15.abrupt("return", jsonResult);
1375
1442
 
1376
- case 25:
1443
+ case 28:
1377
1444
  case "end":
1378
1445
  return _context15.stop();
1379
1446
  }
@@ -1381,7 +1448,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1381
1448
  }, _callee15, this);
1382
1449
  }));
1383
1450
 
1384
- function executeMutation(_x16, _x17, _x18) {
1451
+ function executeMutation(_x17, _x18, _x19, _x20) {
1385
1452
  return _executeMutation.apply(this, arguments);
1386
1453
  }
1387
1454
 
@@ -1411,7 +1478,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1411
1478
  }, _callee16, this);
1412
1479
  }));
1413
1480
 
1414
- function createDocument(_x19) {
1481
+ function createDocument(_x21) {
1415
1482
  return _createDocument.apply(this, arguments);
1416
1483
  }
1417
1484
 
@@ -1441,7 +1508,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1441
1508
  }, _callee17, this);
1442
1509
  }));
1443
1510
 
1444
- function updateDocument(_x20) {
1511
+ function updateDocument(_x22) {
1445
1512
  return _updateDocument.apply(this, arguments);
1446
1513
  }
1447
1514
 
@@ -1489,7 +1556,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1489
1556
  }, _callee18, this);
1490
1557
  }));
1491
1558
 
1492
- function updateDocuments(_x21) {
1559
+ function updateDocuments(_x23) {
1493
1560
  return _updateDocuments.apply(this, arguments);
1494
1561
  }
1495
1562
 
@@ -1524,7 +1591,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1524
1591
  }, _callee19, this);
1525
1592
  }));
1526
1593
 
1527
- function deleteDocument(_x22) {
1594
+ function deleteDocument(_x24) {
1528
1595
  return _deleteDocument.apply(this, arguments);
1529
1596
  }
1530
1597
 
@@ -1548,7 +1615,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1548
1615
  }, _callee20);
1549
1616
  }));
1550
1617
 
1551
- function addReferencesTo(_x23) {
1618
+ function addReferencesTo(_x25) {
1552
1619
  return _addReferencesTo.apply(this, arguments);
1553
1620
  }
1554
1621
 
@@ -1558,65 +1625,76 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
1558
1625
  key: "dbMethod",
1559
1626
  value: function () {
1560
1627
  var _dbMethod = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee21(method, mutation) {
1561
- var doctype, doc, docs, db, res;
1628
+ var markName, doctype, doc, docs, db, res;
1562
1629
  return _regenerator.default.wrap(function _callee21$(_context21) {
1563
1630
  while (1) {
1564
1631
  switch (_context21.prev = _context21.next) {
1565
1632
  case 0:
1633
+ markName = this.performanceApi.mark("dbMethod ".concat(method));
1566
1634
  doctype = (0, _cozyClient.getDoctypeFromOperation)(mutation);
1567
1635
  doc = mutation.document, docs = mutation.documents;
1568
1636
  db = this.getPouch(doctype);
1569
- _context21.prev = 3;
1637
+ _context21.prev = 4;
1570
1638
 
1571
1639
  if (!docs) {
1572
- _context21.next = 10;
1640
+ _context21.next = 11;
1573
1641
  break;
1574
1642
  }
1575
1643
 
1576
- _context21.next = 7;
1644
+ _context21.next = 8;
1577
1645
  return db[method](docs.map(function (doc) {
1578
1646
  return sanitized(doc);
1579
1647
  }));
1580
1648
 
1581
- case 7:
1649
+ case 8:
1582
1650
  res = _context21.sent;
1583
- _context21.next = 17;
1651
+ _context21.next = 18;
1584
1652
  break;
1585
1653
 
1586
- case 10:
1654
+ case 11:
1587
1655
  if (!doc) {
1588
- _context21.next = 16;
1656
+ _context21.next = 17;
1589
1657
  break;
1590
1658
  }
1591
1659
 
1592
- _context21.next = 13;
1660
+ _context21.next = 14;
1593
1661
  return db[method](sanitized(doc));
1594
1662
 
1595
- case 13:
1663
+ case 14:
1596
1664
  res = _context21.sent;
1597
- _context21.next = 17;
1665
+ _context21.next = 18;
1598
1666
  break;
1599
1667
 
1600
- case 16:
1668
+ case 17:
1601
1669
  throw new Error('A mutation should either have document or documents member.');
1602
1670
 
1603
- case 17:
1671
+ case 18:
1672
+ this.performanceApi.measure({
1673
+ markName: markName,
1674
+ category: 'PouchDB'
1675
+ });
1604
1676
  return _context21.abrupt("return", res);
1605
1677
 
1606
- case 20:
1607
- _context21.prev = 20;
1608
- _context21.t0 = _context21["catch"](3);
1678
+ case 22:
1679
+ _context21.prev = 22;
1680
+ _context21.t0 = _context21["catch"](4);
1681
+ this.performanceApi.measure({
1682
+ markName: markName,
1683
+ measureName: "".concat(markName, " error"),
1684
+ category: 'PouchDB',
1685
+ color: 'error'
1686
+ });
1609
1687
  throw new Error("Coud not apply mutation: ".concat(_context21.t0.message));
1610
1688
 
1611
- case 23:
1689
+ case 26:
1612
1690
  case "end":
1613
1691
  return _context21.stop();
1614
1692
  }
1615
1693
  }
1616
- }, _callee21, this, [[3, 20]]);
1694
+ }, _callee21, this, [[4, 22]]);
1617
1695
  }));
1618
1696
 
1619
- function dbMethod(_x24, _x25) {
1697
+ function dbMethod(_x26, _x27) {
1620
1698
  return _dbMethod.apply(this, arguments);
1621
1699
  }
1622
1700
 
@@ -98,7 +98,7 @@ describe('CozyPouchLink', () => {
98
98
  await setup()
99
99
  const query = Q(TODO_DOCTYPE)
100
100
  expect.assertions(1)
101
- await link.request(query, null, () => {
101
+ await link.request(query, null, null, () => {
102
102
  expect(true).toBe(true)
103
103
  })
104
104
  })
@@ -111,7 +111,7 @@ describe('CozyPouchLink', () => {
111
111
  })
112
112
  const query = Q(TODO_DOCTYPE)
113
113
  expect.assertions(1)
114
- await link.request(query, null, () => {
114
+ await link.request(query, null, null, () => {
115
115
  expect(true).toBe(true)
116
116
  })
117
117
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-pouch-link",
3
- "version": "51.6.1",
3
+ "version": "52.0.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "url": "git+https://github.com/cozy/cozy-client.git"
14
14
  },
15
15
  "dependencies": {
16
- "cozy-client": "^51.6.1",
16
+ "cozy-client": "^52.0.0",
17
17
  "pouchdb-browser": "^7.2.2",
18
18
  "pouchdb-find": "^7.2.2"
19
19
  },
@@ -39,5 +39,5 @@
39
39
  "typecheck": "tsc -p tsconfig.json"
40
40
  },
41
41
  "sideEffects": false,
42
- "gitHead": "b46c9c9248b140429972790624fa46b1b547226f"
42
+ "gitHead": "5b59b97a76e9191e67f3c3ce885358f47df8a4e1"
43
43
  }
@@ -36,6 +36,10 @@ export type PouchLinkOptions = {
36
36
  * Platform specific adapters and methods
37
37
  */
38
38
  platform: import('./types').LinkPlatform;
39
+ /**
40
+ * - The performance API that can be used to measure performances
41
+ */
42
+ performanceApi?: any;
39
43
  };
40
44
  /**
41
45
  * @typedef {import('cozy-client/src/types').CozyClientDocument} CozyClientDocument
@@ -52,6 +56,7 @@ export type PouchLinkOptions = {
52
56
  * @property {string[]} doctypes Doctypes to replicate
53
57
  * @property {Record<string, object>} doctypesReplicationOptions A mapping from doctypes to replication options. All pouch replication options can be used, as well as the "strategy" option that determines which way the replication is done (can be "sync", "fromRemote" or "toRemote")
54
58
  * @property {import('./types').LinkPlatform} platform Platform specific adapters and methods
59
+ * @property {import('cozy-client/src/performances/types').PerformanceAPI} [performanceApi] - The performance API that can be used to measure performances
55
60
  */
56
61
  /**
57
62
  * Link to be passed to a `CozyClient` instance to support CouchDB. It instantiates
@@ -86,6 +91,8 @@ declare class PouchLink extends CozyLink {
86
91
  replicationStatus: Record<string, ReplicationStatus>;
87
92
  /** @private */
88
93
  private startReplicationDebounced;
94
+ /** @type {import('cozy-client/src/performances/types').PerformanceAPI} */
95
+ performanceApi: any;
89
96
  getReplicationURL(doctype: any): string;
90
97
  registerClient(client: any): Promise<void>;
91
98
  client: any;
@@ -268,7 +275,7 @@ declare class PouchLink extends CozyLink {
268
275
  skip: any;
269
276
  next: boolean;
270
277
  }>;
271
- executeMutation(mutation: any, result: any, forward: any): Promise<any>;
278
+ executeMutation(mutation: any, options: any, result: any, forward: any): Promise<any>;
272
279
  createDocument(mutation: any): Promise<any>;
273
280
  updateDocument(mutation: any): Promise<any>;
274
281
  updateDocuments(mutation: any): Promise<any[]>;