cozy-pouch-link 57.4.0 → 57.6.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.
- package/dist/CozyPouchLink.js +221 -469
- package/dist/CozyPouchLink.spec.js +6 -147
- package/dist/PouchManager.js +43 -8
- package/dist/PouchManager.spec.js +21 -12
- package/dist/__mocks__/@op-engineering/op-sqlite.js +11 -0
- package/dist/db/dbInterface.js +190 -0
- package/dist/db/helpers.js +106 -0
- package/dist/db/pouchdb/getDocs.js +157 -0
- package/dist/db/pouchdb/getDocs.spec.js +63 -0
- package/dist/db/pouchdb/pouchdb.js +264 -0
- package/dist/db/pouchdb/pouchdb.spec.js +151 -0
- package/dist/db/sqlite/sql.js +418 -0
- package/dist/db/sqlite/sql.spec.js +363 -0
- package/dist/db/sqlite/sqliteDb.js +319 -0
- package/dist/errors.js +17 -2
- package/dist/helpers.js +21 -147
- package/dist/helpers.spec.js +1 -98
- package/dist/index.js +9 -1
- package/dist/jsonapi.js +49 -10
- package/dist/jsonapi.spec.js +105 -32
- package/dist/mango.js +146 -3
- package/dist/migrations/pouchdb.js +32 -0
- package/dist/replicateOnce.js +25 -23
- package/dist/types.js +5 -0
- package/dist/utils.js +33 -3
- package/package.json +4 -3
- package/types/CozyPouchLink.d.ts +4 -60
- package/types/PouchManager.d.ts +6 -1
- package/types/__mocks__/@op-engineering/op-sqlite.d.ts +1 -0
- package/types/db/dbInterface.d.ts +117 -0
- package/types/db/helpers.d.ts +3 -0
- package/types/db/pouchdb/getDocs.d.ts +18 -0
- package/types/db/pouchdb/pouchdb.d.ts +8 -0
- package/types/db/sqlite/sql.d.ts +45 -0
- package/types/db/sqlite/sqliteDb.d.ts +7 -0
- package/types/errors.d.ts +2 -0
- package/types/helpers.d.ts +1 -4
- package/types/index.d.ts +1 -0
- package/types/jsonapi.d.ts +2 -0
- package/types/mango.d.ts +19 -1
- package/types/migrations/pouchdb.d.ts +1 -0
- package/types/types.d.ts +2 -0
- package/types/utils.d.ts +3 -0
package/dist/CozyPouchLink.js
CHANGED
|
@@ -33,17 +33,15 @@ var _pouchdbBrowser = _interopRequireDefault(require("pouchdb-browser"));
|
|
|
33
33
|
|
|
34
34
|
var _pouchdbFind = _interopRequireDefault(require("pouchdb-find"));
|
|
35
35
|
|
|
36
|
-
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
37
|
-
|
|
38
36
|
var _defaults = _interopRequireDefault(require("lodash/defaults"));
|
|
39
37
|
|
|
40
38
|
var _zipWith = _interopRequireDefault(require("lodash/zipWith"));
|
|
41
39
|
|
|
42
40
|
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
43
41
|
|
|
44
|
-
var
|
|
42
|
+
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
45
43
|
|
|
46
|
-
var
|
|
44
|
+
var _helpers = _interopRequireDefault(require("./helpers"));
|
|
47
45
|
|
|
48
46
|
var jsonapi = _interopRequireWildcard(require("./jsonapi"));
|
|
49
47
|
|
|
@@ -61,6 +59,10 @@ var _utils = require("./utils");
|
|
|
61
59
|
|
|
62
60
|
var _errors = require("./errors");
|
|
63
61
|
|
|
62
|
+
var _pouchdb = _interopRequireDefault(require("./db/pouchdb/pouchdb"));
|
|
63
|
+
|
|
64
|
+
var _helpers2 = require("./db/helpers");
|
|
65
|
+
|
|
64
66
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
65
67
|
|
|
66
68
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -77,10 +79,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
77
79
|
|
|
78
80
|
_pouchdbBrowser.default.plugin(_pouchdbFind.default);
|
|
79
81
|
|
|
80
|
-
var find = _helpers.default.find,
|
|
81
|
-
allDocs = _helpers.default.allDocs,
|
|
82
|
-
withoutDesignDocuments = _helpers.default.withoutDesignDocuments;
|
|
83
|
-
|
|
84
82
|
var parseMutationResult = function parseMutationResult(original, res) {
|
|
85
83
|
if (!res.ok) {
|
|
86
84
|
throw new Error('Pouch response is not OK');
|
|
@@ -99,10 +97,6 @@ var addBasicAuth = function addBasicAuth(url, basicAuth) {
|
|
|
99
97
|
return url.replace('//', "//".concat(basicAuth));
|
|
100
98
|
};
|
|
101
99
|
|
|
102
|
-
var sanitized = function sanitized(doc) {
|
|
103
|
-
return (0, _omit.default)(doc, '_type');
|
|
104
|
-
};
|
|
105
|
-
|
|
106
100
|
var _getReplicationURL = function getReplicationURL(uri, token, doctype) {
|
|
107
101
|
var basicAuth = token.toBasicAuth();
|
|
108
102
|
var authenticatedURL = addBasicAuth(uri, basicAuth);
|
|
@@ -343,6 +337,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
343
337
|
var _this$options,
|
|
344
338
|
_this$options$pouch,
|
|
345
339
|
_this$options$pouch$o,
|
|
340
|
+
_this$options$platfor,
|
|
346
341
|
_this2 = this;
|
|
347
342
|
|
|
348
343
|
var markName, prefix, shouldDestroyDatabases, adapterName;
|
|
@@ -420,6 +415,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
420
415
|
return this.storage.persistAdapterName(adapterName);
|
|
421
416
|
|
|
422
417
|
case 26:
|
|
418
|
+
this.queryEngine = ((_this$options$platfor = this.options.platform) === null || _this$options$platfor === void 0 ? void 0 : _this$options$platfor.queryEngine) || _pouchdb.default;
|
|
423
419
|
this.pouches = new _PouchManager.default(this.doctypes, {
|
|
424
420
|
pouch: this.options.pouch,
|
|
425
421
|
getReplicationURL: this.getReplicationURL.bind(this),
|
|
@@ -432,12 +428,14 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
432
428
|
onDoctypeSyncEnd: this.handleDoctypeSyncEnd.bind(this),
|
|
433
429
|
prefix: prefix,
|
|
434
430
|
executeQuery: this.executeQuery.bind(this),
|
|
435
|
-
platform: this.options.platform
|
|
431
|
+
platform: this.options.platform,
|
|
432
|
+
queryEngine: this.queryEngine,
|
|
433
|
+
client: this.client
|
|
436
434
|
});
|
|
437
|
-
_context3.next =
|
|
435
|
+
_context3.next = 30;
|
|
438
436
|
return this.pouches.init();
|
|
439
437
|
|
|
440
|
-
case
|
|
438
|
+
case 30:
|
|
441
439
|
if (this.client && this.initialSync) {
|
|
442
440
|
this.startReplication();
|
|
443
441
|
}
|
|
@@ -447,7 +445,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
447
445
|
category: 'CozyPouchLink'
|
|
448
446
|
});
|
|
449
447
|
|
|
450
|
-
case
|
|
448
|
+
case 32:
|
|
451
449
|
case "end":
|
|
452
450
|
return _context3.stop();
|
|
453
451
|
}
|
|
@@ -707,10 +705,17 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
707
705
|
value: function getSyncInfo(doctype) {
|
|
708
706
|
return this.pouches.getSyncInfo(doctype);
|
|
709
707
|
}
|
|
708
|
+
}, {
|
|
709
|
+
key: "getQueryEngineFromDoctype",
|
|
710
|
+
value: function getQueryEngineFromDoctype(doctype) {
|
|
711
|
+
var dbName = (0, _utils.getDatabaseName)((0, _utils.getPrefix)(this.client.stackClient.uri), doctype);
|
|
712
|
+
return this.pouches.getQueryEngine(dbName, doctype);
|
|
713
|
+
}
|
|
710
714
|
}, {
|
|
711
715
|
key: "getPouch",
|
|
712
716
|
value: function getPouch(doctype) {
|
|
713
|
-
|
|
717
|
+
var dbName = (0, _utils.getDatabaseName)((0, _utils.getPrefix)(this.client.stackClient.uri), doctype);
|
|
718
|
+
return this.pouches.getPouch(dbName);
|
|
714
719
|
}
|
|
715
720
|
}, {
|
|
716
721
|
key: "supportsOperation",
|
|
@@ -908,73 +913,80 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
908
913
|
|
|
909
914
|
return getDbInfo;
|
|
910
915
|
}()
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
client using JSON-API format containing `attributes` and `meta`
|
|
920
|
-
attributes
|
|
921
|
-
Then the cozy-stack-client would normalize those documents by spreading
|
|
922
|
-
`attributes` and `meta` content into the document's root
|
|
923
|
-
So we don't need to store `attributes` and `meta` data into the Pouch
|
|
924
|
-
database as their data already exists in the document's root
|
|
925
|
-
Note that this is also the case for `links` and `relationships`
|
|
926
|
-
attributes, but we don't remove them for now. They are also part of the
|
|
927
|
-
JSON-API, but the normalization do not spread them in the document's
|
|
928
|
-
root, so we have to check their usefulnes first
|
|
929
|
-
*/
|
|
930
|
-
|
|
931
|
-
var sanitizedDoc = (0, _omit.default)(docWithoutType, ['attributes', 'meta']);
|
|
932
|
-
return sanitizedDoc;
|
|
933
|
-
}
|
|
916
|
+
/**
|
|
917
|
+
* We persist in the local Pouch database all the documents that do not
|
|
918
|
+
* exist on the remote Couch database.
|
|
919
|
+
*
|
|
920
|
+
* Those documents are computed by the cozy-stack then are sent to the
|
|
921
|
+
* client using JSON-API format
|
|
922
|
+
*/
|
|
923
|
+
|
|
934
924
|
}, {
|
|
935
925
|
key: "persistCozyData",
|
|
936
926
|
value: function () {
|
|
937
|
-
var _persistCozyData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(
|
|
927
|
+
var _persistCozyData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(doc) {
|
|
938
928
|
var forward,
|
|
939
929
|
markName,
|
|
940
930
|
sanitizedDoc,
|
|
931
|
+
engine,
|
|
932
|
+
resp,
|
|
941
933
|
oldDoc,
|
|
942
|
-
|
|
934
|
+
pouch,
|
|
943
935
|
_args9 = arguments;
|
|
944
936
|
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
945
937
|
while (1) {
|
|
946
938
|
switch (_context9.prev = _context9.next) {
|
|
947
939
|
case 0:
|
|
948
940
|
forward = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : doNothing;
|
|
949
|
-
markName = this.performanceApi.mark('persistCozyData');
|
|
950
|
-
|
|
941
|
+
markName = this.performanceApi.mark('persistCozyData'); // XXX - We don't need to store `attributes` and `meta` data into the Pouch
|
|
942
|
+
// database as their data already exists in the document's root, as its
|
|
943
|
+
// already done by cozy-stack-client.
|
|
944
|
+
|
|
945
|
+
sanitizedDoc = (0, jsonapi.sanitizeJsonApi)(doc);
|
|
946
|
+
_context9.prev = 3;
|
|
951
947
|
sanitizedDoc.cozyLocalOnly = true;
|
|
952
|
-
|
|
953
|
-
|
|
948
|
+
engine = this.getQueryEngineFromDoctype(doc._type);
|
|
949
|
+
_context9.next = 8;
|
|
950
|
+
return (0, _helpers2.getExistingDocument)(engine, sanitizedDoc._id);
|
|
954
951
|
|
|
955
|
-
case
|
|
956
|
-
|
|
952
|
+
case 8:
|
|
953
|
+
resp = _context9.sent;
|
|
954
|
+
oldDoc = (0, jsonapi.sanitizeJsonApi)(resp.data);
|
|
957
955
|
|
|
958
|
-
if (oldDoc) {
|
|
959
|
-
|
|
956
|
+
if (!(0, _helpers2.areDocsEqual)(oldDoc, sanitizedDoc)) {
|
|
957
|
+
_context9.next = 12;
|
|
958
|
+
break;
|
|
960
959
|
}
|
|
961
960
|
|
|
962
|
-
|
|
963
|
-
_context9.next = 11;
|
|
964
|
-
return db.put(sanitizedDoc);
|
|
961
|
+
return _context9.abrupt("return");
|
|
965
962
|
|
|
966
|
-
case
|
|
963
|
+
case 12:
|
|
964
|
+
sanitizedDoc._rev = oldDoc._rev;
|
|
965
|
+
pouch = this.getPouch(doc._type);
|
|
966
|
+
_context9.next = 16;
|
|
967
|
+
return pouch.put(sanitizedDoc);
|
|
968
|
+
|
|
969
|
+
case 16:
|
|
970
|
+
_context9.next = 21;
|
|
971
|
+
break;
|
|
972
|
+
|
|
973
|
+
case 18:
|
|
974
|
+
_context9.prev = 18;
|
|
975
|
+
_context9.t0 = _context9["catch"](3);
|
|
976
|
+
return _context9.abrupt("return", null);
|
|
977
|
+
|
|
978
|
+
case 21:
|
|
967
979
|
this.performanceApi.measure({
|
|
968
980
|
markName: markName,
|
|
969
981
|
category: 'CozyPouchLink'
|
|
970
982
|
});
|
|
971
983
|
|
|
972
|
-
case
|
|
984
|
+
case 22:
|
|
973
985
|
case "end":
|
|
974
986
|
return _context9.stop();
|
|
975
987
|
}
|
|
976
988
|
}
|
|
977
|
-
}, _callee9, this);
|
|
989
|
+
}, _callee9, this, [[3, 18]]);
|
|
978
990
|
}));
|
|
979
991
|
|
|
980
992
|
function persistCozyData(_x9) {
|
|
@@ -983,72 +995,6 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
983
995
|
|
|
984
996
|
return persistCozyData;
|
|
985
997
|
}()
|
|
986
|
-
/**
|
|
987
|
-
* Retrieve the existing document from Pouch
|
|
988
|
-
*
|
|
989
|
-
* @private
|
|
990
|
-
* @param {*} id - ID of the document to retrieve
|
|
991
|
-
* @param {*} type - Doctype of the document to retrieve
|
|
992
|
-
* @param {*} throwIfNotFound - If true the method will throw when the document is not found. Otherwise it will return null
|
|
993
|
-
* @returns {Promise<CozyClientDocument | null>}
|
|
994
|
-
*/
|
|
995
|
-
|
|
996
|
-
}, {
|
|
997
|
-
key: "getExistingDocument",
|
|
998
|
-
value: function () {
|
|
999
|
-
var _getExistingDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(id, type) {
|
|
1000
|
-
var throwIfNotFound,
|
|
1001
|
-
db,
|
|
1002
|
-
markName,
|
|
1003
|
-
existingDoc,
|
|
1004
|
-
_args10 = arguments;
|
|
1005
|
-
return _regenerator.default.wrap(function _callee10$(_context10) {
|
|
1006
|
-
while (1) {
|
|
1007
|
-
switch (_context10.prev = _context10.next) {
|
|
1008
|
-
case 0:
|
|
1009
|
-
throwIfNotFound = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : false;
|
|
1010
|
-
_context10.prev = 1;
|
|
1011
|
-
db = this.pouches.getPouch(type);
|
|
1012
|
-
markName = this.performanceApi.mark('db.get from getExistingDocument');
|
|
1013
|
-
_context10.next = 6;
|
|
1014
|
-
return db.get(id);
|
|
1015
|
-
|
|
1016
|
-
case 6:
|
|
1017
|
-
existingDoc = _context10.sent;
|
|
1018
|
-
this.performanceApi.measure({
|
|
1019
|
-
markName: markName,
|
|
1020
|
-
category: 'PouchDB'
|
|
1021
|
-
});
|
|
1022
|
-
return _context10.abrupt("return", existingDoc);
|
|
1023
|
-
|
|
1024
|
-
case 11:
|
|
1025
|
-
_context10.prev = 11;
|
|
1026
|
-
_context10.t0 = _context10["catch"](1);
|
|
1027
|
-
|
|
1028
|
-
if (!(_context10.t0.name === 'not_found' && !throwIfNotFound)) {
|
|
1029
|
-
_context10.next = 17;
|
|
1030
|
-
break;
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
return _context10.abrupt("return", null);
|
|
1034
|
-
|
|
1035
|
-
case 17:
|
|
1036
|
-
throw _context10.t0;
|
|
1037
|
-
|
|
1038
|
-
case 18:
|
|
1039
|
-
case "end":
|
|
1040
|
-
return _context10.stop();
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
}, _callee10, this, [[1, 11]]);
|
|
1044
|
-
}));
|
|
1045
|
-
|
|
1046
|
-
function getExistingDocument(_x10, _x11) {
|
|
1047
|
-
return _getExistingDocument.apply(this, arguments);
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
return getExistingDocument;
|
|
1051
|
-
}()
|
|
1052
998
|
/**
|
|
1053
999
|
*
|
|
1054
1000
|
* Check if there is warmup queries for this doctype
|
|
@@ -1061,34 +1007,34 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1061
1007
|
}, {
|
|
1062
1008
|
key: "needsToWaitWarmup",
|
|
1063
1009
|
value: function () {
|
|
1064
|
-
var _needsToWaitWarmup = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1065
|
-
return _regenerator.default.wrap(function
|
|
1010
|
+
var _needsToWaitWarmup = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(doctype) {
|
|
1011
|
+
return _regenerator.default.wrap(function _callee10$(_context10) {
|
|
1066
1012
|
while (1) {
|
|
1067
|
-
switch (
|
|
1013
|
+
switch (_context10.prev = _context10.next) {
|
|
1068
1014
|
case 0:
|
|
1069
1015
|
if (!(this.doctypesReplicationOptions && this.doctypesReplicationOptions[doctype] && this.doctypesReplicationOptions[doctype].warmupQueries)) {
|
|
1070
|
-
|
|
1016
|
+
_context10.next = 4;
|
|
1071
1017
|
break;
|
|
1072
1018
|
}
|
|
1073
1019
|
|
|
1074
|
-
|
|
1020
|
+
_context10.next = 3;
|
|
1075
1021
|
return this.pouches.areQueriesWarmedUp(doctype, this.doctypesReplicationOptions[doctype].warmupQueries);
|
|
1076
1022
|
|
|
1077
1023
|
case 3:
|
|
1078
|
-
return
|
|
1024
|
+
return _context10.abrupt("return", !_context10.sent);
|
|
1079
1025
|
|
|
1080
1026
|
case 4:
|
|
1081
|
-
return
|
|
1027
|
+
return _context10.abrupt("return", false);
|
|
1082
1028
|
|
|
1083
1029
|
case 5:
|
|
1084
1030
|
case "end":
|
|
1085
|
-
return
|
|
1031
|
+
return _context10.stop();
|
|
1086
1032
|
}
|
|
1087
1033
|
}
|
|
1088
|
-
},
|
|
1034
|
+
}, _callee10, this);
|
|
1089
1035
|
}));
|
|
1090
1036
|
|
|
1091
|
-
function needsToWaitWarmup(
|
|
1037
|
+
function needsToWaitWarmup(_x10) {
|
|
1092
1038
|
return _needsToWaitWarmup.apply(this, arguments);
|
|
1093
1039
|
}
|
|
1094
1040
|
|
|
@@ -1099,241 +1045,63 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1099
1045
|
value: function hasIndex(name) {
|
|
1100
1046
|
return Boolean(this.indexes[name]);
|
|
1101
1047
|
}
|
|
1102
|
-
/**
|
|
1103
|
-
* Create the PouchDB index if not existing
|
|
1104
|
-
*
|
|
1105
|
-
* @param {Array} fields - Fields to index
|
|
1106
|
-
* @param {object} indexOption - Options for the index
|
|
1107
|
-
* @param {object} [indexOption.partialFilter] - partialFilter
|
|
1108
|
-
* @param {string} [indexOption.indexName] - indexName
|
|
1109
|
-
* @param {string} [indexOption.doctype] - doctype
|
|
1110
|
-
* @returns {Promise<import('./types').PouchDbIndex>}
|
|
1111
|
-
*/
|
|
1112
|
-
|
|
1113
|
-
}, {
|
|
1114
|
-
key: "createIndex",
|
|
1115
|
-
value: function () {
|
|
1116
|
-
var _createIndex = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(fields) {
|
|
1117
|
-
var _ref5,
|
|
1118
|
-
partialFilter,
|
|
1119
|
-
indexName,
|
|
1120
|
-
doctype,
|
|
1121
|
-
absName,
|
|
1122
|
-
db,
|
|
1123
|
-
index,
|
|
1124
|
-
_args12 = arguments;
|
|
1125
|
-
|
|
1126
|
-
return _regenerator.default.wrap(function _callee12$(_context12) {
|
|
1127
|
-
while (1) {
|
|
1128
|
-
switch (_context12.prev = _context12.next) {
|
|
1129
|
-
case 0:
|
|
1130
|
-
_ref5 = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {}, partialFilter = _ref5.partialFilter, indexName = _ref5.indexName, doctype = _ref5.doctype;
|
|
1131
|
-
absName = "".concat(doctype, "/").concat(indexName);
|
|
1132
|
-
db = this.pouches.getPouch(doctype);
|
|
1133
|
-
_context12.next = 5;
|
|
1134
|
-
return db.createIndex({
|
|
1135
|
-
index: {
|
|
1136
|
-
fields: fields,
|
|
1137
|
-
ddoc: indexName,
|
|
1138
|
-
indexName: indexName,
|
|
1139
|
-
partial_filter_selector: partialFilter
|
|
1140
|
-
}
|
|
1141
|
-
});
|
|
1142
|
-
|
|
1143
|
-
case 5:
|
|
1144
|
-
index = _context12.sent;
|
|
1145
|
-
this.indexes[absName] = index;
|
|
1146
|
-
return _context12.abrupt("return", index);
|
|
1147
|
-
|
|
1148
|
-
case 8:
|
|
1149
|
-
case "end":
|
|
1150
|
-
return _context12.stop();
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
}, _callee12, this);
|
|
1154
|
-
}));
|
|
1155
|
-
|
|
1156
|
-
function createIndex(_x13) {
|
|
1157
|
-
return _createIndex.apply(this, arguments);
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
return createIndex;
|
|
1161
|
-
}()
|
|
1162
|
-
/**
|
|
1163
|
-
* Retrieve the PouchDB index if exist, undefined otherwise
|
|
1164
|
-
*
|
|
1165
|
-
* @param {string} doctype - The query's doctype
|
|
1166
|
-
* @param {import('./types').MangoQueryOptions} options - The find options
|
|
1167
|
-
* @param {string} indexName - The index name
|
|
1168
|
-
* @returns {import('./types').PouchDbIndex | undefined}
|
|
1169
|
-
*/
|
|
1170
|
-
|
|
1171
|
-
}, {
|
|
1172
|
-
key: "findExistingIndex",
|
|
1173
|
-
value: function findExistingIndex(doctype, options, indexName) {
|
|
1174
|
-
var absName = "".concat(doctype, "/").concat(indexName);
|
|
1175
|
-
return this.indexes[absName];
|
|
1176
|
-
}
|
|
1177
|
-
/**
|
|
1178
|
-
* Handle index creation if it is missing.
|
|
1179
|
-
*
|
|
1180
|
-
* When an index is missing, we first check if there is one with a different
|
|
1181
|
-
* name but the same definition. If there is none, we create the new index.
|
|
1182
|
-
*
|
|
1183
|
-
* /!\ Warning: this method is similar to DocumentCollection.handleMissingIndex()
|
|
1184
|
-
* If you edit this method, please check if the change is also needed in DocumentCollection
|
|
1185
|
-
*
|
|
1186
|
-
* @param {string} doctype The mango selector
|
|
1187
|
-
* @param {import('./types').MangoQueryOptions} options The find options
|
|
1188
|
-
* @returns {Promise<import('./types').PouchDbIndex>} index
|
|
1189
|
-
* @private
|
|
1190
|
-
*/
|
|
1191
|
-
|
|
1192
|
-
}, {
|
|
1193
|
-
key: "ensureIndex",
|
|
1194
|
-
value: function () {
|
|
1195
|
-
var _ensureIndex = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(doctype, options) {
|
|
1196
|
-
var indexedFields, partialFilter, indexName, existingIndex;
|
|
1197
|
-
return _regenerator.default.wrap(function _callee13$(_context13) {
|
|
1198
|
-
while (1) {
|
|
1199
|
-
switch (_context13.prev = _context13.next) {
|
|
1200
|
-
case 0:
|
|
1201
|
-
indexedFields = options.indexedFields, partialFilter = options.partialFilter;
|
|
1202
|
-
|
|
1203
|
-
if (!indexedFields) {
|
|
1204
|
-
indexedFields = (0, _mango.getIndexFields)(options);
|
|
1205
|
-
} else if (partialFilter) {
|
|
1206
|
-
// Some pouch adapters does not support partialIndex, e.g. with websql in react-native
|
|
1207
|
-
// Therefore, we need to force the indexing the partialIndex fields to ensure they will be
|
|
1208
|
-
// included in the actual index. Thanks to this, docs with missing fields will be excluded
|
|
1209
|
-
// from the index.
|
|
1210
|
-
// Note the $exists: false case should be handled in-memory.
|
|
1211
|
-
indexedFields = Array.from(new Set([].concat((0, _toConsumableArray2.default)(indexedFields), (0, _toConsumableArray2.default)(Object.keys(partialFilter))))); // FIXME: should properly handle n-level attributes
|
|
1212
|
-
|
|
1213
|
-
indexedFields = indexedFields.filter(function (field) {
|
|
1214
|
-
return field !== '$and' && field !== '$or';
|
|
1215
|
-
});
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
indexName = (0, _mango.getIndexNameFromFields)(indexedFields, partialFilter);
|
|
1219
|
-
existingIndex = this.findExistingIndex(doctype, options, indexName);
|
|
1220
|
-
|
|
1221
|
-
if (existingIndex) {
|
|
1222
|
-
_context13.next = 10;
|
|
1223
|
-
break;
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
_context13.next = 7;
|
|
1227
|
-
return this.createIndex(indexedFields, {
|
|
1228
|
-
partialFilter: partialFilter,
|
|
1229
|
-
indexName: indexName,
|
|
1230
|
-
doctype: doctype
|
|
1231
|
-
});
|
|
1232
|
-
|
|
1233
|
-
case 7:
|
|
1234
|
-
return _context13.abrupt("return", _context13.sent);
|
|
1235
|
-
|
|
1236
|
-
case 10:
|
|
1237
|
-
return _context13.abrupt("return", existingIndex);
|
|
1238
|
-
|
|
1239
|
-
case 11:
|
|
1240
|
-
case "end":
|
|
1241
|
-
return _context13.stop();
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}, _callee13, this);
|
|
1245
|
-
}));
|
|
1246
|
-
|
|
1247
|
-
function ensureIndex(_x14, _x15) {
|
|
1248
|
-
return _ensureIndex.apply(this, arguments);
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
return ensureIndex;
|
|
1252
|
-
}()
|
|
1253
1048
|
}, {
|
|
1254
1049
|
key: "executeQuery",
|
|
1255
1050
|
value: function () {
|
|
1256
|
-
var _executeQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1257
|
-
var doctype, selector, sort, fields, limit, id, ids, skip, indexedFields, partialFilter,
|
|
1258
|
-
|
|
1259
|
-
return _regenerator.default.wrap(function _callee14$(_context14) {
|
|
1051
|
+
var _executeQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(_ref5) {
|
|
1052
|
+
var doctype, selector, sort, fields, limit, id, ids, skip, indexedFields, partialFilter, engine, res, findSelector, findOpts;
|
|
1053
|
+
return _regenerator.default.wrap(function _callee11$(_context11) {
|
|
1260
1054
|
while (1) {
|
|
1261
|
-
switch (
|
|
1055
|
+
switch (_context11.prev = _context11.next) {
|
|
1262
1056
|
case 0:
|
|
1263
|
-
doctype =
|
|
1264
|
-
|
|
1265
|
-
db = this.getPouch(doctype);
|
|
1057
|
+
doctype = _ref5.doctype, selector = _ref5.selector, sort = _ref5.sort, fields = _ref5.fields, limit = _ref5.limit, id = _ref5.id, ids = _ref5.ids, skip = _ref5.skip, indexedFields = _ref5.indexedFields, partialFilter = _ref5.partialFilter;
|
|
1058
|
+
engine = this.getQueryEngineFromDoctype(doctype);
|
|
1266
1059
|
|
|
1267
1060
|
if (!id) {
|
|
1268
|
-
|
|
1061
|
+
_context11.next = 8;
|
|
1269
1062
|
break;
|
|
1270
1063
|
}
|
|
1271
1064
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
return db.get(id);
|
|
1065
|
+
_context11.next = 5;
|
|
1066
|
+
return engine.getById(id);
|
|
1275
1067
|
|
|
1276
|
-
case
|
|
1277
|
-
res =
|
|
1278
|
-
|
|
1279
|
-
markName: _markName,
|
|
1280
|
-
category: 'PouchDB'
|
|
1281
|
-
});
|
|
1282
|
-
withRows = false;
|
|
1283
|
-
_context14.next = 47;
|
|
1068
|
+
case 5:
|
|
1069
|
+
res = _context11.sent;
|
|
1070
|
+
_context11.next = 25;
|
|
1284
1071
|
break;
|
|
1285
1072
|
|
|
1286
|
-
case
|
|
1073
|
+
case 8:
|
|
1287
1074
|
if (!ids) {
|
|
1288
|
-
|
|
1075
|
+
_context11.next = 14;
|
|
1289
1076
|
break;
|
|
1290
1077
|
}
|
|
1291
1078
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
return allDocs(db, {
|
|
1295
|
-
include_docs: true,
|
|
1296
|
-
keys: ids
|
|
1297
|
-
});
|
|
1298
|
-
|
|
1299
|
-
case 16:
|
|
1300
|
-
res = _context14.sent;
|
|
1301
|
-
this.performanceApi.measure({
|
|
1302
|
-
markName: _markName2,
|
|
1303
|
-
category: 'PouchDB'
|
|
1304
|
-
});
|
|
1305
|
-
res = withoutDesignDocuments(res);
|
|
1306
|
-
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.
|
|
1079
|
+
_context11.next = 11;
|
|
1080
|
+
return engine.getByIds(ids);
|
|
1307
1081
|
|
|
1308
|
-
|
|
1309
|
-
|
|
1082
|
+
case 11:
|
|
1083
|
+
res = _context11.sent;
|
|
1084
|
+
_context11.next = 25;
|
|
1310
1085
|
break;
|
|
1311
1086
|
|
|
1312
|
-
case
|
|
1087
|
+
case 14:
|
|
1313
1088
|
if (!(!selector && !partialFilter && !fields && !sort)) {
|
|
1314
|
-
|
|
1089
|
+
_context11.next = 20;
|
|
1315
1090
|
break;
|
|
1316
1091
|
}
|
|
1317
1092
|
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
return allDocs(db, {
|
|
1093
|
+
_context11.next = 17;
|
|
1094
|
+
return engine.allDocs({
|
|
1321
1095
|
include_docs: true,
|
|
1322
1096
|
limit: limit
|
|
1323
1097
|
});
|
|
1324
1098
|
|
|
1325
|
-
case
|
|
1326
|
-
res =
|
|
1327
|
-
|
|
1328
|
-
markName: _markName3,
|
|
1329
|
-
category: 'PouchDB'
|
|
1330
|
-
});
|
|
1331
|
-
res = withoutDesignDocuments(res);
|
|
1332
|
-
withRows = true;
|
|
1333
|
-
_context14.next = 47;
|
|
1099
|
+
case 17:
|
|
1100
|
+
res = _context11.sent;
|
|
1101
|
+
_context11.next = 25;
|
|
1334
1102
|
break;
|
|
1335
1103
|
|
|
1336
|
-
case
|
|
1104
|
+
case 20:
|
|
1337
1105
|
findSelector = _helpers.default.normalizeFindSelector({
|
|
1338
1106
|
selector: selector,
|
|
1339
1107
|
sort: sort,
|
|
@@ -1347,53 +1115,37 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1347
1115
|
// _id is necessary for the store, and _rev is required for offline. See https://github.com/cozy/cozy-client/blob/95978d39546023920b0c01d689fed5dd41577a02/packages/cozy-client/src/CozyClient.js#L1153
|
|
1348
1116
|
fields: fields ? [].concat((0, _toConsumableArray2.default)(fields), ['_id', '_rev']) : undefined,
|
|
1349
1117
|
limit: limit,
|
|
1350
|
-
skip: skip
|
|
1118
|
+
skip: skip,
|
|
1119
|
+
doctype: doctype
|
|
1351
1120
|
};
|
|
1352
|
-
|
|
1353
|
-
return
|
|
1354
|
-
indexedFields: indexedFields,
|
|
1355
|
-
partialFilter: partialFilter
|
|
1356
|
-
}));
|
|
1121
|
+
_context11.next = 24;
|
|
1122
|
+
return engine.find(findOpts);
|
|
1357
1123
|
|
|
1358
|
-
case
|
|
1359
|
-
|
|
1360
|
-
findOpts.use_index = index.id;
|
|
1361
|
-
_markName4 = this.performanceApi.mark('find from executeQuery');
|
|
1362
|
-
_context14.next = 42;
|
|
1363
|
-
return find(db, findOpts);
|
|
1124
|
+
case 24:
|
|
1125
|
+
res = _context11.sent;
|
|
1364
1126
|
|
|
1365
|
-
case
|
|
1366
|
-
res
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
});
|
|
1371
|
-
res.offset = skip;
|
|
1372
|
-
res.limit = limit;
|
|
1373
|
-
withRows = true;
|
|
1127
|
+
case 25:
|
|
1128
|
+
if (res) {
|
|
1129
|
+
_context11.next = 27;
|
|
1130
|
+
break;
|
|
1131
|
+
}
|
|
1374
1132
|
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
res: res,
|
|
1378
|
-
withRows: withRows,
|
|
1379
|
-
doctype: doctype,
|
|
1380
|
-
client: this.client
|
|
1381
|
-
});
|
|
1382
|
-
this.performanceApi.measure({
|
|
1383
|
-
markName: markName,
|
|
1384
|
-
category: 'CozyPouchLink'
|
|
1133
|
+
return _context11.abrupt("return", {
|
|
1134
|
+
data: []
|
|
1385
1135
|
});
|
|
1386
|
-
return _context14.abrupt("return", jsonResult);
|
|
1387
1136
|
|
|
1388
|
-
case
|
|
1137
|
+
case 27:
|
|
1138
|
+
return _context11.abrupt("return", res);
|
|
1139
|
+
|
|
1140
|
+
case 28:
|
|
1389
1141
|
case "end":
|
|
1390
|
-
return
|
|
1142
|
+
return _context11.stop();
|
|
1391
1143
|
}
|
|
1392
1144
|
}
|
|
1393
|
-
},
|
|
1145
|
+
}, _callee11, this);
|
|
1394
1146
|
}));
|
|
1395
1147
|
|
|
1396
|
-
function executeQuery(
|
|
1148
|
+
function executeQuery(_x11) {
|
|
1397
1149
|
return _executeQuery.apply(this, arguments);
|
|
1398
1150
|
}
|
|
1399
1151
|
|
|
@@ -1402,59 +1154,59 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1402
1154
|
}, {
|
|
1403
1155
|
key: "executeMutation",
|
|
1404
1156
|
value: function () {
|
|
1405
|
-
var _executeMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1157
|
+
var _executeMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(mutation, options, result, forward) {
|
|
1406
1158
|
var markName, pouchRes, jsonResult;
|
|
1407
|
-
return _regenerator.default.wrap(function
|
|
1159
|
+
return _regenerator.default.wrap(function _callee12$(_context12) {
|
|
1408
1160
|
while (1) {
|
|
1409
|
-
switch (
|
|
1161
|
+
switch (_context12.prev = _context12.next) {
|
|
1410
1162
|
case 0:
|
|
1411
1163
|
markName = this.performanceApi.mark('executeMutation');
|
|
1412
|
-
|
|
1413
|
-
|
|
1164
|
+
_context12.t0 = mutation.mutationType;
|
|
1165
|
+
_context12.next = _context12.t0 === _cozyClient.MutationTypes.CREATE_DOCUMENT ? 4 : _context12.t0 === _cozyClient.MutationTypes.UPDATE_DOCUMENT ? 8 : _context12.t0 === _cozyClient.MutationTypes.UPDATE_DOCUMENTS ? 12 : _context12.t0 === _cozyClient.MutationTypes.DELETE_DOCUMENT ? 16 : _context12.t0 === _cozyClient.MutationTypes.ADD_REFERENCES_TO ? 20 : 24;
|
|
1414
1166
|
break;
|
|
1415
1167
|
|
|
1416
1168
|
case 4:
|
|
1417
|
-
|
|
1169
|
+
_context12.next = 6;
|
|
1418
1170
|
return this.createDocument(mutation);
|
|
1419
1171
|
|
|
1420
1172
|
case 6:
|
|
1421
|
-
pouchRes =
|
|
1422
|
-
return
|
|
1173
|
+
pouchRes = _context12.sent;
|
|
1174
|
+
return _context12.abrupt("break", 25);
|
|
1423
1175
|
|
|
1424
1176
|
case 8:
|
|
1425
|
-
|
|
1177
|
+
_context12.next = 10;
|
|
1426
1178
|
return this.updateDocument(mutation);
|
|
1427
1179
|
|
|
1428
1180
|
case 10:
|
|
1429
|
-
pouchRes =
|
|
1430
|
-
return
|
|
1181
|
+
pouchRes = _context12.sent;
|
|
1182
|
+
return _context12.abrupt("break", 25);
|
|
1431
1183
|
|
|
1432
1184
|
case 12:
|
|
1433
|
-
|
|
1185
|
+
_context12.next = 14;
|
|
1434
1186
|
return this.updateDocuments(mutation);
|
|
1435
1187
|
|
|
1436
1188
|
case 14:
|
|
1437
|
-
pouchRes =
|
|
1438
|
-
return
|
|
1189
|
+
pouchRes = _context12.sent;
|
|
1190
|
+
return _context12.abrupt("break", 25);
|
|
1439
1191
|
|
|
1440
1192
|
case 16:
|
|
1441
|
-
|
|
1193
|
+
_context12.next = 18;
|
|
1442
1194
|
return this.deleteDocument(mutation);
|
|
1443
1195
|
|
|
1444
1196
|
case 18:
|
|
1445
|
-
pouchRes =
|
|
1446
|
-
return
|
|
1197
|
+
pouchRes = _context12.sent;
|
|
1198
|
+
return _context12.abrupt("break", 25);
|
|
1447
1199
|
|
|
1448
1200
|
case 20:
|
|
1449
|
-
|
|
1201
|
+
_context12.next = 22;
|
|
1450
1202
|
return this.addReferencesTo(mutation);
|
|
1451
1203
|
|
|
1452
1204
|
case 22:
|
|
1453
|
-
pouchRes =
|
|
1454
|
-
return
|
|
1205
|
+
pouchRes = _context12.sent;
|
|
1206
|
+
return _context12.abrupt("break", 25);
|
|
1455
1207
|
|
|
1456
1208
|
case 24:
|
|
1457
|
-
return
|
|
1209
|
+
return _context12.abrupt("return", forward(mutation, options, result));
|
|
1458
1210
|
|
|
1459
1211
|
case 25:
|
|
1460
1212
|
jsonResult = jsonapi.fromPouchResult({
|
|
@@ -1467,17 +1219,17 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1467
1219
|
markName: markName,
|
|
1468
1220
|
category: 'CozyPouchLink'
|
|
1469
1221
|
});
|
|
1470
|
-
return
|
|
1222
|
+
return _context12.abrupt("return", jsonResult);
|
|
1471
1223
|
|
|
1472
1224
|
case 28:
|
|
1473
1225
|
case "end":
|
|
1474
|
-
return
|
|
1226
|
+
return _context12.stop();
|
|
1475
1227
|
}
|
|
1476
1228
|
}
|
|
1477
|
-
},
|
|
1229
|
+
}, _callee12, this);
|
|
1478
1230
|
}));
|
|
1479
1231
|
|
|
1480
|
-
function executeMutation(
|
|
1232
|
+
function executeMutation(_x12, _x13, _x14, _x15) {
|
|
1481
1233
|
return _executeMutation.apply(this, arguments);
|
|
1482
1234
|
}
|
|
1483
1235
|
|
|
@@ -1486,28 +1238,28 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1486
1238
|
}, {
|
|
1487
1239
|
key: "createDocument",
|
|
1488
1240
|
value: function () {
|
|
1489
|
-
var _createDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1241
|
+
var _createDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(mutation) {
|
|
1490
1242
|
var res;
|
|
1491
|
-
return _regenerator.default.wrap(function
|
|
1243
|
+
return _regenerator.default.wrap(function _callee13$(_context13) {
|
|
1492
1244
|
while (1) {
|
|
1493
|
-
switch (
|
|
1245
|
+
switch (_context13.prev = _context13.next) {
|
|
1494
1246
|
case 0:
|
|
1495
|
-
|
|
1247
|
+
_context13.next = 2;
|
|
1496
1248
|
return this.dbMethod('post', mutation);
|
|
1497
1249
|
|
|
1498
1250
|
case 2:
|
|
1499
|
-
res =
|
|
1500
|
-
return
|
|
1251
|
+
res = _context13.sent;
|
|
1252
|
+
return _context13.abrupt("return", parseMutationResult(mutation.document, res));
|
|
1501
1253
|
|
|
1502
1254
|
case 4:
|
|
1503
1255
|
case "end":
|
|
1504
|
-
return
|
|
1256
|
+
return _context13.stop();
|
|
1505
1257
|
}
|
|
1506
1258
|
}
|
|
1507
|
-
},
|
|
1259
|
+
}, _callee13, this);
|
|
1508
1260
|
}));
|
|
1509
1261
|
|
|
1510
|
-
function createDocument(
|
|
1262
|
+
function createDocument(_x16) {
|
|
1511
1263
|
return _createDocument.apply(this, arguments);
|
|
1512
1264
|
}
|
|
1513
1265
|
|
|
@@ -1516,28 +1268,28 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1516
1268
|
}, {
|
|
1517
1269
|
key: "updateDocument",
|
|
1518
1270
|
value: function () {
|
|
1519
|
-
var _updateDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1271
|
+
var _updateDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(mutation) {
|
|
1520
1272
|
var res;
|
|
1521
|
-
return _regenerator.default.wrap(function
|
|
1273
|
+
return _regenerator.default.wrap(function _callee14$(_context14) {
|
|
1522
1274
|
while (1) {
|
|
1523
|
-
switch (
|
|
1275
|
+
switch (_context14.prev = _context14.next) {
|
|
1524
1276
|
case 0:
|
|
1525
|
-
|
|
1277
|
+
_context14.next = 2;
|
|
1526
1278
|
return this.dbMethod('put', mutation);
|
|
1527
1279
|
|
|
1528
1280
|
case 2:
|
|
1529
|
-
res =
|
|
1530
|
-
return
|
|
1281
|
+
res = _context14.sent;
|
|
1282
|
+
return _context14.abrupt("return", parseMutationResult(mutation.document, res));
|
|
1531
1283
|
|
|
1532
1284
|
case 4:
|
|
1533
1285
|
case "end":
|
|
1534
|
-
return
|
|
1286
|
+
return _context14.stop();
|
|
1535
1287
|
}
|
|
1536
1288
|
}
|
|
1537
|
-
},
|
|
1289
|
+
}, _callee14, this);
|
|
1538
1290
|
}));
|
|
1539
1291
|
|
|
1540
|
-
function updateDocument(
|
|
1292
|
+
function updateDocument(_x17) {
|
|
1541
1293
|
return _updateDocument.apply(this, arguments);
|
|
1542
1294
|
}
|
|
1543
1295
|
|
|
@@ -1546,18 +1298,18 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1546
1298
|
}, {
|
|
1547
1299
|
key: "updateDocuments",
|
|
1548
1300
|
value: function () {
|
|
1549
|
-
var _updateDocuments = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1301
|
+
var _updateDocuments = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(mutation) {
|
|
1550
1302
|
var docs, bulkResponse, updatedDocs;
|
|
1551
|
-
return _regenerator.default.wrap(function
|
|
1303
|
+
return _regenerator.default.wrap(function _callee15$(_context15) {
|
|
1552
1304
|
while (1) {
|
|
1553
|
-
switch (
|
|
1305
|
+
switch (_context15.prev = _context15.next) {
|
|
1554
1306
|
case 0:
|
|
1555
1307
|
docs = mutation.documents;
|
|
1556
|
-
|
|
1308
|
+
_context15.next = 3;
|
|
1557
1309
|
return this.dbMethod('bulkDocs', mutation);
|
|
1558
1310
|
|
|
1559
1311
|
case 3:
|
|
1560
|
-
bulkResponse =
|
|
1312
|
+
bulkResponse = _context15.sent;
|
|
1561
1313
|
updatedDocs = (0, _zipWith.default)(bulkResponse, docs, function (bulkResult, originalDoc) {
|
|
1562
1314
|
return _objectSpread(_objectSpread({}, originalDoc), {}, {
|
|
1563
1315
|
_id: bulkResult.id,
|
|
@@ -1568,24 +1320,24 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1568
1320
|
if (!bulkResponse.find(function (x) {
|
|
1569
1321
|
return !x.ok;
|
|
1570
1322
|
})) {
|
|
1571
|
-
|
|
1323
|
+
_context15.next = 7;
|
|
1572
1324
|
break;
|
|
1573
1325
|
}
|
|
1574
1326
|
|
|
1575
1327
|
throw new _cozyClient.BulkEditError(bulkResponse, updatedDocs);
|
|
1576
1328
|
|
|
1577
1329
|
case 7:
|
|
1578
|
-
return
|
|
1330
|
+
return _context15.abrupt("return", updatedDocs);
|
|
1579
1331
|
|
|
1580
1332
|
case 8:
|
|
1581
1333
|
case "end":
|
|
1582
|
-
return
|
|
1334
|
+
return _context15.stop();
|
|
1583
1335
|
}
|
|
1584
1336
|
}
|
|
1585
|
-
},
|
|
1337
|
+
}, _callee15, this);
|
|
1586
1338
|
}));
|
|
1587
1339
|
|
|
1588
|
-
function updateDocuments(
|
|
1340
|
+
function updateDocuments(_x18) {
|
|
1589
1341
|
return _updateDocuments.apply(this, arguments);
|
|
1590
1342
|
}
|
|
1591
1343
|
|
|
@@ -1594,33 +1346,33 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1594
1346
|
}, {
|
|
1595
1347
|
key: "deleteDocument",
|
|
1596
1348
|
value: function () {
|
|
1597
|
-
var _deleteDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1349
|
+
var _deleteDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(mutation) {
|
|
1598
1350
|
var res, document;
|
|
1599
|
-
return _regenerator.default.wrap(function
|
|
1351
|
+
return _regenerator.default.wrap(function _callee16$(_context16) {
|
|
1600
1352
|
while (1) {
|
|
1601
|
-
switch (
|
|
1353
|
+
switch (_context16.prev = _context16.next) {
|
|
1602
1354
|
case 0:
|
|
1603
|
-
|
|
1355
|
+
_context16.next = 2;
|
|
1604
1356
|
return this.dbMethod('remove', mutation);
|
|
1605
1357
|
|
|
1606
1358
|
case 2:
|
|
1607
|
-
res =
|
|
1359
|
+
res = _context16.sent;
|
|
1608
1360
|
document = _objectSpread(_objectSpread({}, mutation.document), {}, {
|
|
1609
1361
|
_id: res.id,
|
|
1610
1362
|
_rev: res.rev,
|
|
1611
1363
|
_deleted: true
|
|
1612
1364
|
});
|
|
1613
|
-
return
|
|
1365
|
+
return _context16.abrupt("return", parseMutationResult(document, res));
|
|
1614
1366
|
|
|
1615
1367
|
case 5:
|
|
1616
1368
|
case "end":
|
|
1617
|
-
return
|
|
1369
|
+
return _context16.stop();
|
|
1618
1370
|
}
|
|
1619
1371
|
}
|
|
1620
|
-
},
|
|
1372
|
+
}, _callee16, this);
|
|
1621
1373
|
}));
|
|
1622
1374
|
|
|
1623
|
-
function deleteDocument(
|
|
1375
|
+
function deleteDocument(_x19) {
|
|
1624
1376
|
return _deleteDocument.apply(this, arguments);
|
|
1625
1377
|
}
|
|
1626
1378
|
|
|
@@ -1629,22 +1381,22 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1629
1381
|
}, {
|
|
1630
1382
|
key: "addReferencesTo",
|
|
1631
1383
|
value: function () {
|
|
1632
|
-
var _addReferencesTo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1633
|
-
return _regenerator.default.wrap(function
|
|
1384
|
+
var _addReferencesTo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17(mutation) {
|
|
1385
|
+
return _regenerator.default.wrap(function _callee17$(_context17) {
|
|
1634
1386
|
while (1) {
|
|
1635
|
-
switch (
|
|
1387
|
+
switch (_context17.prev = _context17.next) {
|
|
1636
1388
|
case 0:
|
|
1637
1389
|
throw new Error('addReferencesTo is not implemented in CozyPouchLink');
|
|
1638
1390
|
|
|
1639
1391
|
case 1:
|
|
1640
1392
|
case "end":
|
|
1641
|
-
return
|
|
1393
|
+
return _context17.stop();
|
|
1642
1394
|
}
|
|
1643
1395
|
}
|
|
1644
|
-
},
|
|
1396
|
+
}, _callee17);
|
|
1645
1397
|
}));
|
|
1646
1398
|
|
|
1647
|
-
function addReferencesTo(
|
|
1399
|
+
function addReferencesTo(_x20) {
|
|
1648
1400
|
return _addReferencesTo.apply(this, arguments);
|
|
1649
1401
|
}
|
|
1650
1402
|
|
|
@@ -1653,45 +1405,45 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1653
1405
|
}, {
|
|
1654
1406
|
key: "dbMethod",
|
|
1655
1407
|
value: function () {
|
|
1656
|
-
var _dbMethod = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1408
|
+
var _dbMethod = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18(method, mutation) {
|
|
1657
1409
|
var markName, doctype, doc, docs, db, res;
|
|
1658
|
-
return _regenerator.default.wrap(function
|
|
1410
|
+
return _regenerator.default.wrap(function _callee18$(_context18) {
|
|
1659
1411
|
while (1) {
|
|
1660
|
-
switch (
|
|
1412
|
+
switch (_context18.prev = _context18.next) {
|
|
1661
1413
|
case 0:
|
|
1662
1414
|
markName = this.performanceApi.mark("dbMethod ".concat(method));
|
|
1663
1415
|
doctype = (0, _cozyClient.getDoctypeFromOperation)(mutation);
|
|
1664
1416
|
doc = mutation.document, docs = mutation.documents;
|
|
1665
1417
|
db = this.getPouch(doctype);
|
|
1666
|
-
|
|
1418
|
+
_context18.prev = 4;
|
|
1667
1419
|
|
|
1668
1420
|
if (!docs) {
|
|
1669
|
-
|
|
1421
|
+
_context18.next = 11;
|
|
1670
1422
|
break;
|
|
1671
1423
|
}
|
|
1672
1424
|
|
|
1673
|
-
|
|
1425
|
+
_context18.next = 8;
|
|
1674
1426
|
return db[method](docs.map(function (doc) {
|
|
1675
|
-
return sanitized(doc);
|
|
1427
|
+
return (0, jsonapi.sanitized)(doc);
|
|
1676
1428
|
}));
|
|
1677
1429
|
|
|
1678
1430
|
case 8:
|
|
1679
|
-
res =
|
|
1680
|
-
|
|
1431
|
+
res = _context18.sent;
|
|
1432
|
+
_context18.next = 18;
|
|
1681
1433
|
break;
|
|
1682
1434
|
|
|
1683
1435
|
case 11:
|
|
1684
1436
|
if (!doc) {
|
|
1685
|
-
|
|
1437
|
+
_context18.next = 17;
|
|
1686
1438
|
break;
|
|
1687
1439
|
}
|
|
1688
1440
|
|
|
1689
|
-
|
|
1690
|
-
return db[method](sanitized(doc));
|
|
1441
|
+
_context18.next = 14;
|
|
1442
|
+
return db[method]((0, jsonapi.sanitized)(doc));
|
|
1691
1443
|
|
|
1692
1444
|
case 14:
|
|
1693
|
-
res =
|
|
1694
|
-
|
|
1445
|
+
res = _context18.sent;
|
|
1446
|
+
_context18.next = 18;
|
|
1695
1447
|
break;
|
|
1696
1448
|
|
|
1697
1449
|
case 17:
|
|
@@ -1702,28 +1454,28 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1702
1454
|
markName: markName,
|
|
1703
1455
|
category: 'PouchDB'
|
|
1704
1456
|
});
|
|
1705
|
-
return
|
|
1457
|
+
return _context18.abrupt("return", res);
|
|
1706
1458
|
|
|
1707
1459
|
case 22:
|
|
1708
|
-
|
|
1709
|
-
|
|
1460
|
+
_context18.prev = 22;
|
|
1461
|
+
_context18.t0 = _context18["catch"](4);
|
|
1710
1462
|
this.performanceApi.measure({
|
|
1711
1463
|
markName: markName,
|
|
1712
1464
|
measureName: "".concat(markName, " error"),
|
|
1713
1465
|
category: 'PouchDB',
|
|
1714
1466
|
color: 'error'
|
|
1715
1467
|
});
|
|
1716
|
-
throw new Error("Coud not apply mutation: ".concat(
|
|
1468
|
+
throw new Error("Coud not apply mutation: ".concat(_context18.t0.message));
|
|
1717
1469
|
|
|
1718
1470
|
case 26:
|
|
1719
1471
|
case "end":
|
|
1720
|
-
return
|
|
1472
|
+
return _context18.stop();
|
|
1721
1473
|
}
|
|
1722
1474
|
}
|
|
1723
|
-
},
|
|
1475
|
+
}, _callee18, this, [[4, 22]]);
|
|
1724
1476
|
}));
|
|
1725
1477
|
|
|
1726
|
-
function dbMethod(
|
|
1478
|
+
function dbMethod(_x21, _x22) {
|
|
1727
1479
|
return _dbMethod.apply(this, arguments);
|
|
1728
1480
|
}
|
|
1729
1481
|
|
|
@@ -1732,29 +1484,29 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1732
1484
|
}, {
|
|
1733
1485
|
key: "syncImmediately",
|
|
1734
1486
|
value: function () {
|
|
1735
|
-
var _syncImmediately = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1736
|
-
return _regenerator.default.wrap(function
|
|
1487
|
+
var _syncImmediately = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19() {
|
|
1488
|
+
return _regenerator.default.wrap(function _callee19$(_context19) {
|
|
1737
1489
|
while (1) {
|
|
1738
|
-
switch (
|
|
1490
|
+
switch (_context19.prev = _context19.next) {
|
|
1739
1491
|
case 0:
|
|
1740
1492
|
if (this.pouches) {
|
|
1741
|
-
|
|
1493
|
+
_context19.next = 3;
|
|
1742
1494
|
break;
|
|
1743
1495
|
}
|
|
1744
1496
|
|
|
1745
1497
|
_logger.default.warn('Cannot sync immediately, no PouchManager');
|
|
1746
1498
|
|
|
1747
|
-
return
|
|
1499
|
+
return _context19.abrupt("return");
|
|
1748
1500
|
|
|
1749
1501
|
case 3:
|
|
1750
1502
|
this.pouches.syncImmediately();
|
|
1751
1503
|
|
|
1752
1504
|
case 4:
|
|
1753
1505
|
case "end":
|
|
1754
|
-
return
|
|
1506
|
+
return _context19.stop();
|
|
1755
1507
|
}
|
|
1756
1508
|
}
|
|
1757
|
-
},
|
|
1509
|
+
}, _callee19, this);
|
|
1758
1510
|
}));
|
|
1759
1511
|
|
|
1760
1512
|
function syncImmediately() {
|