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.
Files changed (43) hide show
  1. package/dist/CozyPouchLink.js +221 -469
  2. package/dist/CozyPouchLink.spec.js +6 -147
  3. package/dist/PouchManager.js +43 -8
  4. package/dist/PouchManager.spec.js +21 -12
  5. package/dist/__mocks__/@op-engineering/op-sqlite.js +11 -0
  6. package/dist/db/dbInterface.js +190 -0
  7. package/dist/db/helpers.js +106 -0
  8. package/dist/db/pouchdb/getDocs.js +157 -0
  9. package/dist/db/pouchdb/getDocs.spec.js +63 -0
  10. package/dist/db/pouchdb/pouchdb.js +264 -0
  11. package/dist/db/pouchdb/pouchdb.spec.js +151 -0
  12. package/dist/db/sqlite/sql.js +418 -0
  13. package/dist/db/sqlite/sql.spec.js +363 -0
  14. package/dist/db/sqlite/sqliteDb.js +319 -0
  15. package/dist/errors.js +17 -2
  16. package/dist/helpers.js +21 -147
  17. package/dist/helpers.spec.js +1 -98
  18. package/dist/index.js +9 -1
  19. package/dist/jsonapi.js +49 -10
  20. package/dist/jsonapi.spec.js +105 -32
  21. package/dist/mango.js +146 -3
  22. package/dist/migrations/pouchdb.js +32 -0
  23. package/dist/replicateOnce.js +25 -23
  24. package/dist/types.js +5 -0
  25. package/dist/utils.js +33 -3
  26. package/package.json +4 -3
  27. package/types/CozyPouchLink.d.ts +4 -60
  28. package/types/PouchManager.d.ts +6 -1
  29. package/types/__mocks__/@op-engineering/op-sqlite.d.ts +1 -0
  30. package/types/db/dbInterface.d.ts +117 -0
  31. package/types/db/helpers.d.ts +3 -0
  32. package/types/db/pouchdb/getDocs.d.ts +18 -0
  33. package/types/db/pouchdb/pouchdb.d.ts +8 -0
  34. package/types/db/sqlite/sql.d.ts +45 -0
  35. package/types/db/sqlite/sqliteDb.d.ts +7 -0
  36. package/types/errors.d.ts +2 -0
  37. package/types/helpers.d.ts +1 -4
  38. package/types/index.d.ts +1 -0
  39. package/types/jsonapi.d.ts +2 -0
  40. package/types/mango.d.ts +19 -1
  41. package/types/migrations/pouchdb.d.ts +1 -0
  42. package/types/types.d.ts +2 -0
  43. package/types/utils.d.ts +3 -0
package/dist/mango.js CHANGED
@@ -5,7 +5,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.getIndexFields = exports.getIndexNameFromFields = exports.makeKeyFromPartialFilter = void 0;
8
+ exports.getIndexName = exports.getIndexFields = exports.findExistingIndex = exports.createIndex = exports.getIndexFieldsFromFind = exports.getIndexNameFromFields = exports.makeKeyFromPartialFilter = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
9
13
 
10
14
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
15
 
@@ -13,6 +17,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
13
17
 
14
18
  var _head = _interopRequireDefault(require("lodash/head"));
15
19
 
20
+ var indexes = {};
16
21
  /**
17
22
  * Process a partial filter to generate a string key
18
23
  *
@@ -22,6 +27,7 @@ var _head = _interopRequireDefault(require("lodash/head"));
22
27
  * @param {object} condition - An object representing the partial filter or a sub-condition of the partial filter
23
28
  * @returns {string} - The string key of the processed partial filter
24
29
  */
30
+
25
31
  var makeKeyFromPartialFilter = function makeKeyFromPartialFilter(condition) {
26
32
  if (typeof condition !== 'object' || condition === null) {
27
33
  return String(condition);
@@ -92,7 +98,7 @@ var defaultSelector = {
92
98
  }
93
99
  };
94
100
 
95
- var getIndexFields = function getIndexFields(
101
+ var getIndexFieldsFromFind = function getIndexFieldsFromFind(
96
102
  /** @type {import('./types').MangoQueryOptions} */
97
103
  _ref3) {
98
104
  var _ref3$selector = _ref3.selector,
@@ -104,5 +110,142 @@ _ref3) {
104
110
  return (0, _head.default)(Object.keys(sortOption));
105
111
  })), (0, _toConsumableArray2.default)(selector ? Object.keys(selector) : []), (0, _toConsumableArray2.default)(partialFilter ? Object.keys(partialFilter) : []))));
106
112
  };
113
+ /**
114
+ * Create the PouchDB index if not existing
115
+ *
116
+ * @param {object} db - The pouch db
117
+ * @param {Array} fields - Fields to index
118
+ * @param {object} indexOption - Options for the index
119
+ * @param {object} [indexOption.partialFilter] - partialFilter
120
+ * @param {string} [indexOption.indexName] - indexName
121
+ * @param {string} [indexOption.doctype] - doctype
122
+ * @returns {Promise<import('./types').PouchDbIndex>}
123
+ */
124
+
125
+
126
+ exports.getIndexFieldsFromFind = getIndexFieldsFromFind;
127
+
128
+ var createIndex = /*#__PURE__*/function () {
129
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(db, fields) {
130
+ var _ref5,
131
+ partialFilter,
132
+ indexName,
133
+ doctype,
134
+ absName,
135
+ index,
136
+ _args = arguments;
137
+
138
+ return _regenerator.default.wrap(function _callee$(_context) {
139
+ while (1) {
140
+ switch (_context.prev = _context.next) {
141
+ case 0:
142
+ _ref5 = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, partialFilter = _ref5.partialFilter, indexName = _ref5.indexName, doctype = _ref5.doctype;
143
+ absName = "".concat(doctype, "/").concat(indexName);
144
+ _context.next = 4;
145
+ return db.createIndex({
146
+ index: {
147
+ fields: fields,
148
+ ddoc: indexName,
149
+ indexName: indexName,
150
+ partial_filter_selector: partialFilter
151
+ }
152
+ });
153
+
154
+ case 4:
155
+ index = _context.sent;
156
+ indexes[absName] = index;
157
+ return _context.abrupt("return", index);
158
+
159
+ case 7:
160
+ case "end":
161
+ return _context.stop();
162
+ }
163
+ }
164
+ }, _callee);
165
+ }));
166
+
167
+ return function createIndex(_x, _x2) {
168
+ return _ref4.apply(this, arguments);
169
+ };
170
+ }();
171
+ /**
172
+ * Retrieve the PouchDB index if exist, undefined otherwise
173
+ *
174
+ * @param {string} doctype - The query's doctype
175
+ * @param {import('./types').MangoQueryOptions} options - The find options
176
+ * @param {string} indexName - The index name
177
+ * @returns {import('./types').PouchDbIndex | undefined}
178
+ */
179
+
180
+
181
+ exports.createIndex = createIndex;
182
+
183
+ var findExistingIndex = function findExistingIndex(doctype, options, indexName) {
184
+ var absName = "".concat(doctype, "/").concat(indexName);
185
+ return indexes[absName];
186
+ };
187
+
188
+ exports.findExistingIndex = findExistingIndex;
189
+
190
+ var getIndexFields = function getIndexFields(_ref6) {
191
+ var selector = _ref6.selector,
192
+ sort = _ref6.sort,
193
+ partialFilter = _ref6.partialFilter,
194
+ indexedFields = _ref6.indexedFields;
195
+ var fieldsToIndex = indexedFields;
196
+
197
+ if (!indexedFields) {
198
+ fieldsToIndex = getIndexFieldsFromFind({
199
+ selector: selector,
200
+ sort: sort,
201
+ partialFilter: partialFilter
202
+ });
203
+ } else if (partialFilter) {
204
+ // Some pouch adapters does not support partialIndex, e.g. with websql in react-native
205
+ // Therefore, we need to force the indexing the partialIndex fields to ensure they will be
206
+ // included in the actual index. Thanks to this, docs with missing fields will be excluded
207
+ // from the index.
208
+ // Note the $exists: false case should be handled in-memory.
209
+ fieldsToIndex = Array.from(new Set([].concat((0, _toConsumableArray2.default)(indexedFields), (0, _toConsumableArray2.default)(Object.keys(partialFilter))))); // FIXME: should properly handle n-level attributes
210
+
211
+ fieldsToIndex = indexedFields.filter(function (field) {
212
+ return field !== '$and' && field !== '$or';
213
+ });
214
+ }
215
+
216
+ return fieldsToIndex;
217
+ };
218
+
219
+ exports.getIndexFields = getIndexFields;
220
+
221
+ var getIndexName = function getIndexName(_ref7) {
222
+ var selector = _ref7.selector,
223
+ sort = _ref7.sort,
224
+ indexedFields = _ref7.indexedFields,
225
+ partialFilter = _ref7.partialFilter;
226
+ var fieldsToIndex = indexedFields;
227
+
228
+ if (!indexedFields) {
229
+ fieldsToIndex = getIndexFieldsFromFind({
230
+ selector: selector,
231
+ sort: sort,
232
+ partialFilter: partialFilter
233
+ });
234
+ } else if (partialFilter) {
235
+ // Some pouch adapters does not support partialIndex, e.g. with websql in react-native
236
+ // Therefore, we need to force the indexing the partialIndex fields to ensure they will be
237
+ // included in the actual index. Thanks to this, docs with missing fields will be excluded
238
+ // from the index.
239
+ // Note the $exists: false case should be handled in-memory.
240
+ fieldsToIndex = Array.from(new Set([].concat((0, _toConsumableArray2.default)(indexedFields), (0, _toConsumableArray2.default)(Object.keys(partialFilter))))); // FIXME: should properly handle n-level attributes
241
+
242
+ fieldsToIndex = indexedFields.filter(function (field) {
243
+ return field !== '$and' && field !== '$or';
244
+ });
245
+ }
246
+
247
+ var indexName = getIndexNameFromFields(fieldsToIndex, partialFilter);
248
+ return indexName;
249
+ };
107
250
 
108
- exports.getIndexFields = getIndexFields;
251
+ exports.getIndexName = getIndexName;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.destroyOldDatabases = void 0;
7
+
8
+ var _utils = require("../utils");
9
+
10
+ var destroyOldDatabases = function destroyOldDatabases(PouchDB, doctypes, prefix) {
11
+ if (doctypes) {
12
+ doctypes.forEach(function (doctype) {
13
+ // Check an old version of the db exist for this doctype
14
+ var db = new PouchDB((0, _utils.getOldDatabaseName)(prefix, doctype), {
15
+ skip_setup: true // Skip the db creation
16
+
17
+ });
18
+
19
+ if (db && db.info) {
20
+ db.info().then(function () {
21
+ // The database exists: destroy it
22
+ db.destroy();
23
+ }).catch(function (err) {
24
+ // No database found, nothing to do
25
+ return;
26
+ });
27
+ }
28
+ });
29
+ }
30
+ };
31
+
32
+ exports.destroyOldDatabases = destroyOldDatabases;
@@ -43,7 +43,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
43
43
  */
44
44
  var replicateOnce = /*#__PURE__*/function () {
45
45
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pouchManager) {
46
- var doctypes, promises, res, zippedDoctypes, successZippedDoctypes, failedZippedDoctypes, blockingErrors, unblockingErrors, _iterator, _step, unblockingError, doctype, errors, reasons, doctypeUpdated, doctypeFailed;
46
+ var doctypes, promises, res, zippedDoctypes, successZippedDoctypes, failedZippedDoctypes, blockingErrors, unblockingErrors, _iterator, _step, unblockingError, _doctype, errors, reasons, doctypeUpdated, doctypeFailed;
47
47
 
48
48
  return _regenerator.default.wrap(function _callee2$(_context2) {
49
49
  while (1) {
@@ -67,12 +67,14 @@ var replicateOnce = /*#__PURE__*/function () {
67
67
 
68
68
 
69
69
  pouchManager.replications = (0, _map.default)(pouchManager.pouches, /*#__PURE__*/function () {
70
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(pouch, doctype) {
71
- var getReplicationURL, initialReplication, replicationFilter, seq, lastSeq, replicationOptions, res;
70
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(pouch, dbName) {
71
+ var doctype, getReplicationURL, initialReplication, replicationFilter, seq, lastSeq, replicationOptions, res;
72
72
  return _regenerator.default.wrap(function _callee$(_context) {
73
73
  while (1) {
74
74
  switch (_context.prev = _context.next) {
75
75
  case 0:
76
+ doctype = (0, _utils.getDoctypeFromDatabaseName)(dbName);
77
+
76
78
  _logger.default.info('PouchManager: Starting replication for ' + doctype);
77
79
 
78
80
  getReplicationURL = function getReplicationURL() {
@@ -88,30 +90,30 @@ var replicateOnce = /*#__PURE__*/function () {
88
90
  seq = '';
89
91
 
90
92
  if (!initialReplication) {
91
- _context.next = 13;
93
+ _context.next = 14;
92
94
  break;
93
95
  }
94
96
 
95
- _context.next = 8;
97
+ _context.next = 9;
96
98
  return (0, _remote.fetchRemoteLastSequence)(getReplicationURL());
97
99
 
98
- case 8:
100
+ case 9:
99
101
  lastSeq = _context.sent;
100
- _context.next = 11;
102
+ _context.next = 12;
101
103
  return pouchManager.storage.persistDoctypeLastSequence(doctype, lastSeq);
102
104
 
103
- case 11:
104
- _context.next = 16;
105
+ case 12:
106
+ _context.next = 17;
105
107
  break;
106
108
 
107
- case 13:
108
- _context.next = 15;
109
+ case 14:
110
+ _context.next = 16;
109
111
  return pouchManager.storage.getDoctypeLastSequence(doctype);
110
112
 
111
- case 15:
113
+ case 16:
112
114
  seq = _context.sent;
113
115
 
114
- case 16:
116
+ case 17:
115
117
  replicationOptions = (0, _get.default)(pouchManager.doctypesReplicationOptions, doctype, {});
116
118
  replicationOptions.initialReplication = initialReplication;
117
119
  replicationOptions.filter = replicationFilter;
@@ -122,25 +124,25 @@ var replicateOnce = /*#__PURE__*/function () {
122
124
  pouchManager.options.onDoctypeSyncStart(doctype);
123
125
  }
124
126
 
125
- _context.next = 24;
127
+ _context.next = 25;
126
128
  return (0, _startReplication.startReplication)(pouch, replicationOptions, getReplicationURL, pouchManager.storage);
127
129
 
128
- case 24:
130
+ case 25:
129
131
  res = _context.sent;
130
132
 
131
133
  if (!seq) {
132
- _context.next = 28;
134
+ _context.next = 29;
133
135
  break;
134
136
  }
135
137
 
136
- _context.next = 28;
138
+ _context.next = 29;
137
139
  return pouchManager.storage.destroyDoctypeLastSequence(doctype);
138
140
 
139
- case 28:
140
- _context.next = 30;
141
+ case 29:
142
+ _context.next = 31;
141
143
  return pouchManager.updateSyncInfo(doctype);
142
144
 
143
- case 30:
145
+ case 31:
144
146
  pouchManager.checkToWarmupDoctype(doctype, replicationOptions);
145
147
 
146
148
  if (pouchManager.options.onDoctypeSyncEnd) {
@@ -149,7 +151,7 @@ var replicateOnce = /*#__PURE__*/function () {
149
151
 
150
152
  return _context.abrupt("return", res);
151
153
 
152
- case 33:
154
+ case 34:
153
155
  case "end":
154
156
  return _context.stop();
155
157
  }
@@ -209,10 +211,10 @@ var replicateOnce = /*#__PURE__*/function () {
209
211
  }
210
212
 
211
213
  unblockingError = _step.value;
212
- doctype = unblockingError[0]; // @ts-ignore
214
+ _doctype = unblockingError[0]; // @ts-ignore
213
215
 
214
216
  _context2.next = 28;
215
- return pouchManager.updateSyncInfo(doctype, 'not_complete');
217
+ return pouchManager.updateSyncInfo(_doctype, 'not_complete');
216
218
 
217
219
  case 28:
218
220
  _context2.next = 23;
package/dist/types.js CHANGED
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.default = void 0;
7
9
 
10
+ var _dbInterface = _interopRequireDefault(require("./db/dbInterface"));
11
+
8
12
  /**
9
13
  * @typedef {Object} Cancelable
10
14
  * @property {Function} [cancel] - Cancel the promise
@@ -39,6 +43,7 @@ exports.default = void 0;
39
43
  * @typedef {object} LinkPlatform
40
44
  * @property {LocalStorage} storage Methods to access local storage
41
45
  * @property {any} pouchAdapter PouchDB class (can be pouchdb-core or pouchdb-browser)
46
+ * @property { DatabaseQueryEngine } queryEngine
42
47
  * @property {function(): Promise<boolean>} isOnline Method that check if the app is connected to internet
43
48
  */
44
49
 
package/dist/utils.js CHANGED
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.allSettled = exports.formatAggregatedError = exports.getPrefix = exports.getDatabaseName = void 0;
7
-
6
+ exports.allSettled = exports.formatAggregatedError = exports.getPrefix = exports.getDoctypeFromDatabaseName = exports.getOldDatabaseName = exports.getDatabaseName = exports.DATABASE_NAME_SEPARATOR = void 0;
7
+ var DATABASE_NAME_SEPARATOR = '__doctype__';
8
8
  /**
9
9
  * Get the database name based on prefix and doctype
10
10
  *
@@ -13,9 +13,39 @@ exports.allSettled = exports.formatAggregatedError = exports.getPrefix = exports
13
13
  *
14
14
  * @returns {string} The database name
15
15
  */
16
+
17
+ exports.DATABASE_NAME_SEPARATOR = DATABASE_NAME_SEPARATOR;
18
+
16
19
  var getDatabaseName = function getDatabaseName(prefix, doctype) {
20
+ return "".concat(prefix).concat(DATABASE_NAME_SEPARATOR).concat(doctype);
21
+ };
22
+ /**
23
+ * Get the old database name, based on prefix and doctype
24
+ * Used for migration purposes
25
+ *
26
+ * @param {string} prefix - The URL prefix
27
+ * @param {string} doctype - The database doctype
28
+ *
29
+ * @returns {string} The database name
30
+ */
31
+
32
+
33
+ exports.getDatabaseName = getDatabaseName;
34
+
35
+ var getOldDatabaseName = function getOldDatabaseName(prefix, doctype) {
17
36
  return "".concat(prefix, "_").concat(doctype);
18
37
  };
38
+
39
+ exports.getOldDatabaseName = getOldDatabaseName;
40
+
41
+ var getDoctypeFromDatabaseName = function getDoctypeFromDatabaseName(dbName) {
42
+ if (!dbName) {
43
+ return null;
44
+ }
45
+
46
+ var tokens = dbName.split(DATABASE_NAME_SEPARATOR);
47
+ return tokens[tokens.length - 1];
48
+ };
19
49
  /**
20
50
  * Get the URI prefix
21
51
  *
@@ -24,7 +54,7 @@ var getDatabaseName = function getDatabaseName(prefix, doctype) {
24
54
  */
25
55
 
26
56
 
27
- exports.getDatabaseName = getDatabaseName;
57
+ exports.getDoctypeFromDatabaseName = getDoctypeFromDatabaseName;
28
58
 
29
59
  var getPrefix = function getPrefix(uri) {
30
60
  return uri.replace(/^https?:\/\//, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-pouch-link",
3
- "version": "57.4.0",
3
+ "version": "57.6.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": "^57.4.0",
16
+ "cozy-client": "^57.6.0",
17
17
  "pouchdb-browser": "^7.2.2",
18
18
  "pouchdb-find": "^7.2.2"
19
19
  },
@@ -30,6 +30,7 @@
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@cozy/minilog": "1.0.0",
33
+ "@op-engineering/op-sqlite": "*",
33
34
  "cozy-device-helper": ">=2.1.0"
34
35
  },
35
36
  "scripts": {
@@ -39,5 +40,5 @@
39
40
  "typecheck": "tsc -p tsconfig.json"
40
41
  },
41
42
  "sideEffects": false,
42
- "gitHead": "97e956957de48f36a29d0d55adf3cb0e248f0141"
43
+ "gitHead": "5a646c30c51b7a93ea7e65d309425799487b1968"
43
44
  }
@@ -125,6 +125,7 @@ declare class PouchLink extends CozyLink {
125
125
  plugins?: Array<object>;
126
126
  }): Promise<void>;
127
127
  onLogin(): Promise<void>;
128
+ queryEngine: import("./db/dbInterface").default | typeof PouchDBQueryEngine;
128
129
  pouches: PouchManager;
129
130
  /**
130
131
  * Receives PouchDB updates (documents grouped by doctype).
@@ -180,6 +181,7 @@ declare class PouchLink extends CozyLink {
180
181
  public stopReplication(): void;
181
182
  onSyncError(error: any): Promise<void>;
182
183
  getSyncInfo(doctype: any): import("./types").SyncInfo;
184
+ getQueryEngineFromDoctype(doctype: any): any;
183
185
  getPouch(doctype: any): any;
184
186
  supportsOperation(operation: any): boolean;
185
187
  /**
@@ -199,17 +201,6 @@ declare class PouchLink extends CozyLink {
199
201
  * @returns {Promise<import('./types').PouchDBInfo>} The db info
200
202
  */
201
203
  getDbInfo(doctype: string): Promise<import('./types').PouchDBInfo>;
202
- sanitizeJsonApi(data: any): Pick<Pick<any, string | number | symbol>, string | number | symbol>;
203
- /**
204
- * Retrieve the existing document from Pouch
205
- *
206
- * @private
207
- * @param {*} id - ID of the document to retrieve
208
- * @param {*} type - Doctype of the document to retrieve
209
- * @param {*} throwIfNotFound - If true the method will throw when the document is not found. Otherwise it will return null
210
- * @returns {Promise<CozyClientDocument | null>}
211
- */
212
- private getExistingDocument;
213
204
  /**
214
205
  *
215
206
  * Check if there is warmup queries for this doctype
@@ -220,45 +211,6 @@ declare class PouchLink extends CozyLink {
220
211
  */
221
212
  needsToWaitWarmup(doctype: string): Promise<boolean>;
222
213
  hasIndex(name: any): boolean;
223
- /**
224
- * Create the PouchDB index if not existing
225
- *
226
- * @param {Array} fields - Fields to index
227
- * @param {object} indexOption - Options for the index
228
- * @param {object} [indexOption.partialFilter] - partialFilter
229
- * @param {string} [indexOption.indexName] - indexName
230
- * @param {string} [indexOption.doctype] - doctype
231
- * @returns {Promise<import('./types').PouchDbIndex>}
232
- */
233
- createIndex(fields: any[], { partialFilter, indexName, doctype }?: {
234
- partialFilter: object;
235
- indexName: string;
236
- doctype: string;
237
- }): Promise<import('./types').PouchDbIndex>;
238
- /**
239
- * Retrieve the PouchDB index if exist, undefined otherwise
240
- *
241
- * @param {string} doctype - The query's doctype
242
- * @param {import('./types').MangoQueryOptions} options - The find options
243
- * @param {string} indexName - The index name
244
- * @returns {import('./types').PouchDbIndex | undefined}
245
- */
246
- findExistingIndex(doctype: string, options: import('./types').MangoQueryOptions, indexName: string): import('./types').PouchDbIndex | undefined;
247
- /**
248
- * Handle index creation if it is missing.
249
- *
250
- * When an index is missing, we first check if there is one with a different
251
- * name but the same definition. If there is none, we create the new index.
252
- *
253
- * /!\ Warning: this method is similar to DocumentCollection.handleMissingIndex()
254
- * If you edit this method, please check if the change is also needed in DocumentCollection
255
- *
256
- * @param {string} doctype The mango selector
257
- * @param {import('./types').MangoQueryOptions} options The find options
258
- * @returns {Promise<import('./types').PouchDbIndex>} index
259
- * @private
260
- */
261
- private ensureIndex;
262
214
  executeQuery({ doctype, selector, sort, fields, limit, id, ids, skip, indexedFields, partialFilter }: {
263
215
  doctype: any;
264
216
  selector: any;
@@ -270,16 +222,7 @@ declare class PouchLink extends CozyLink {
270
222
  skip: any;
271
223
  indexedFields: any;
272
224
  partialFilter: any;
273
- }): Promise<{
274
- data: any;
275
- meta: {
276
- count: any;
277
- };
278
- skip: any;
279
- next: boolean;
280
- } | {
281
- data: any;
282
- }>;
225
+ }): Promise<any>;
283
226
  executeMutation(mutation: any, options: any, result: any, forward: any): Promise<any>;
284
227
  createDocument(mutation: any): Promise<any>;
285
228
  updateDocument(mutation: any): Promise<any>;
@@ -291,4 +234,5 @@ declare class PouchLink extends CozyLink {
291
234
  }
292
235
  import { CozyLink } from "cozy-client";
293
236
  import { PouchLocalStorage } from "./localStorage";
237
+ import PouchDBQueryEngine from "./db/pouchdb/pouchdb";
294
238
  import PouchManager from "./PouchManager";
@@ -10,9 +10,12 @@ declare class PouchManager {
10
10
  options: any;
11
11
  doctypes: any;
12
12
  storage: PouchLocalStorage;
13
+ queryEngine: any;
14
+ client: any;
13
15
  PouchDB: any;
14
16
  isOnline: any;
15
17
  events: any;
18
+ dbQueryEngines: Map<any, any>;
16
19
  init(): Promise<void>;
17
20
  pouches: import("lodash").Dictionary<any>;
18
21
  /** @type {Record<string, import('./types').SyncInfo>} - Stores synchronization info per doctype */
@@ -62,7 +65,9 @@ declare class PouchManager {
62
65
  handleReplicationError(err: any): void;
63
66
  cancelCurrentReplications(): void;
64
67
  waitForCurrentReplications(): Promise<void> | Promise<(import("./utils").FulfilledPromise | import("./utils").RejectedPromise)[]>;
65
- getPouch(doctype: any): any;
68
+ getPouch(dbName: any): any;
69
+ setQueryEngine(name: any, doctype: any): any;
70
+ getQueryEngine(name: any, doctype: any): any;
66
71
  /**
67
72
  * Update the Sync info for the specifed doctype
68
73
  *
@@ -0,0 +1 @@
1
+ export function open(): void;