cozy-pouch-link 55.0.0 → 56.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.
- package/dist/CozyPouchLink.js +36 -8
- package/dist/PouchManager.js +27 -5
- package/dist/PouchManager.spec.js +1 -1
- package/dist/helpers.js +1 -1
- package/package.json +3 -3
- package/types/CozyPouchLink.d.ts +11 -2
- package/types/PouchManager.d.ts +11 -3
package/dist/CozyPouchLink.js
CHANGED
|
@@ -551,12 +551,20 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
551
551
|
}, {
|
|
552
552
|
key: "_startReplication",
|
|
553
553
|
value: function _startReplication() {
|
|
554
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
555
|
+
_ref2$waitForReplicat = _ref2.waitForReplications,
|
|
556
|
+
waitForReplications = _ref2$waitForReplicat === void 0 ? true : _ref2$waitForReplicat;
|
|
557
|
+
|
|
554
558
|
this.client.emit('pouchlink:sync:start');
|
|
555
559
|
|
|
556
560
|
if (this.periodicSync) {
|
|
561
|
+
// FIXME: this API is kind of weird, one should be able to manually replicate
|
|
562
|
+
// even if a periodicSync is enabled
|
|
557
563
|
this.pouches.startReplicationLoop();
|
|
558
564
|
} else {
|
|
559
|
-
this.pouches.replicateOnce(
|
|
565
|
+
this.pouches.replicateOnce({
|
|
566
|
+
waitForReplications: waitForReplications
|
|
567
|
+
});
|
|
560
568
|
}
|
|
561
569
|
|
|
562
570
|
if (this.options.onStartReplication) {
|
|
@@ -570,14 +578,26 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
570
578
|
* Emits pouchlink:sync:start event when the replication begins
|
|
571
579
|
*
|
|
572
580
|
* @public
|
|
581
|
+
*
|
|
582
|
+
* @param {object} options - The options
|
|
583
|
+
* @param {boolean|null} [options.waitForReplications=true] - Whether the others replication process should be waited
|
|
573
584
|
* @returns {void}
|
|
574
585
|
*/
|
|
575
586
|
|
|
576
587
|
}, {
|
|
577
588
|
key: "startReplication",
|
|
578
589
|
value: function startReplication() {
|
|
579
|
-
|
|
580
|
-
|
|
590
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
591
|
+
_ref3$waitForReplicat = _ref3.waitForReplications,
|
|
592
|
+
waitForReplications = _ref3$waitForReplicat === void 0 ? true : _ref3$waitForReplicat;
|
|
593
|
+
|
|
594
|
+
if (!waitForReplications) {
|
|
595
|
+
this.startReplicationDebounced.cancel();
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
return this._startReplication({
|
|
599
|
+
waitForReplications: waitForReplications
|
|
600
|
+
});
|
|
581
601
|
}
|
|
582
602
|
/**
|
|
583
603
|
* Debounced version of startReplication() method
|
|
@@ -585,17 +605,25 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
585
605
|
* Debounce delay can be configured through constructor's `syncDebounceDelayInMs` option
|
|
586
606
|
*
|
|
587
607
|
* @public
|
|
608
|
+
* @param {object} options - The options
|
|
609
|
+
* @param {boolean|null} [options.waitForReplications=true] - Whether the others replication process should be waited
|
|
588
610
|
* @returns {void}
|
|
589
611
|
*/
|
|
590
612
|
|
|
591
613
|
}, {
|
|
592
614
|
key: "startReplicationWithDebounce",
|
|
593
615
|
value: function startReplicationWithDebounce() {
|
|
616
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
617
|
+
_ref4$waitForReplicat = _ref4.waitForReplications,
|
|
618
|
+
waitForReplications = _ref4$waitForReplicat === void 0 ? true : _ref4$waitForReplicat;
|
|
619
|
+
|
|
594
620
|
if (this.periodicSync) {
|
|
595
621
|
throw new Error('createDebounceableReplication cannot be called when periodic sync is configured');
|
|
596
622
|
}
|
|
597
623
|
|
|
598
|
-
return this.startReplicationDebounced(
|
|
624
|
+
return this.startReplicationDebounced({
|
|
625
|
+
waitForReplications: waitForReplications
|
|
626
|
+
});
|
|
599
627
|
}
|
|
600
628
|
/**
|
|
601
629
|
* User of the link can call this to stop ongoing replications.
|
|
@@ -1086,7 +1114,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1086
1114
|
key: "createIndex",
|
|
1087
1115
|
value: function () {
|
|
1088
1116
|
var _createIndex = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(fields) {
|
|
1089
|
-
var
|
|
1117
|
+
var _ref5,
|
|
1090
1118
|
partialFilter,
|
|
1091
1119
|
indexName,
|
|
1092
1120
|
doctype,
|
|
@@ -1099,7 +1127,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1099
1127
|
while (1) {
|
|
1100
1128
|
switch (_context12.prev = _context12.next) {
|
|
1101
1129
|
case 0:
|
|
1102
|
-
|
|
1130
|
+
_ref5 = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {}, partialFilter = _ref5.partialFilter, indexName = _ref5.indexName, doctype = _ref5.doctype;
|
|
1103
1131
|
absName = "".concat(doctype, "/").concat(indexName);
|
|
1104
1132
|
db = this.pouches.getPouch(doctype);
|
|
1105
1133
|
_context12.next = 5;
|
|
@@ -1225,14 +1253,14 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
1225
1253
|
}, {
|
|
1226
1254
|
key: "executeQuery",
|
|
1227
1255
|
value: function () {
|
|
1228
|
-
var _executeQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(
|
|
1256
|
+
var _executeQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(_ref6) {
|
|
1229
1257
|
var doctype, selector, sort, fields, limit, id, ids, skip, indexedFields, partialFilter, markName, db, res, withRows, _markName, _markName2, _markName3, findSelector, findOpts, index, _markName4, jsonResult;
|
|
1230
1258
|
|
|
1231
1259
|
return _regenerator.default.wrap(function _callee14$(_context14) {
|
|
1232
1260
|
while (1) {
|
|
1233
1261
|
switch (_context14.prev = _context14.next) {
|
|
1234
1262
|
case 0:
|
|
1235
|
-
doctype =
|
|
1263
|
+
doctype = _ref6.doctype, selector = _ref6.selector, sort = _ref6.sort, fields = _ref6.fields, limit = _ref6.limit, id = _ref6.id, ids = _ref6.ids, skip = _ref6.skip, indexedFields = _ref6.indexedFields, partialFilter = _ref6.partialFilter;
|
|
1236
1264
|
markName = this.performanceApi.mark('executeQuery');
|
|
1237
1265
|
db = this.getPouch(doctype);
|
|
1238
1266
|
|
package/dist/PouchManager.js
CHANGED
|
@@ -329,19 +329,41 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
329
329
|
|
|
330
330
|
this.replicationLoop.scheduleImmediateTask();
|
|
331
331
|
}
|
|
332
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Starts replication
|
|
334
|
+
*
|
|
335
|
+
* @param {object} options - The options
|
|
336
|
+
* @param {boolean|null} [options.waitForReplications=true] - Whether the others replication process should be waited
|
|
337
|
+
* @returns {Promise<any>} the replication result
|
|
338
|
+
*/
|
|
333
339
|
|
|
334
340
|
}, {
|
|
335
341
|
key: "replicateOnce",
|
|
336
342
|
value: function () {
|
|
337
343
|
var _replicateOnce2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
|
|
344
|
+
var _ref,
|
|
345
|
+
_ref$waitForReplicati,
|
|
346
|
+
waitForReplications,
|
|
347
|
+
_args5 = arguments;
|
|
348
|
+
|
|
338
349
|
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
339
350
|
while (1) {
|
|
340
351
|
switch (_context5.prev = _context5.next) {
|
|
341
352
|
case 0:
|
|
353
|
+
_ref = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {}, _ref$waitForReplicati = _ref.waitForReplications, waitForReplications = _ref$waitForReplicati === void 0 ? true : _ref$waitForReplicati;
|
|
354
|
+
|
|
355
|
+
if (!waitForReplications) {
|
|
356
|
+
_context5.next = 4;
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
_context5.next = 4;
|
|
361
|
+
return this.waitForCurrentReplications();
|
|
362
|
+
|
|
363
|
+
case 4:
|
|
342
364
|
return _context5.abrupt("return", (0, _replicateOnce3.replicateOnce)(this));
|
|
343
365
|
|
|
344
|
-
case
|
|
366
|
+
case 5:
|
|
345
367
|
case "end":
|
|
346
368
|
return _context5.stop();
|
|
347
369
|
}
|
|
@@ -395,7 +417,7 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
395
417
|
return Promise.resolve();
|
|
396
418
|
}
|
|
397
419
|
|
|
398
|
-
return
|
|
420
|
+
return (0, _utils.allSettled)(Object.values(this.replications));
|
|
399
421
|
}
|
|
400
422
|
}, {
|
|
401
423
|
key: "getPouch",
|
|
@@ -506,7 +528,7 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
506
528
|
_context9.prev = 1;
|
|
507
529
|
_context9.next = 4;
|
|
508
530
|
return Promise.all(queries.map( /*#__PURE__*/function () {
|
|
509
|
-
var
|
|
531
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(query) {
|
|
510
532
|
var def;
|
|
511
533
|
return _regenerator.default.wrap(function _callee8$(_context8) {
|
|
512
534
|
while (1) {
|
|
@@ -534,7 +556,7 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
534
556
|
}));
|
|
535
557
|
|
|
536
558
|
return function (_x4) {
|
|
537
|
-
return
|
|
559
|
+
return _ref2.apply(this, arguments);
|
|
538
560
|
};
|
|
539
561
|
}()));
|
|
540
562
|
|
|
@@ -247,7 +247,7 @@ describe('PouchManager', () => {
|
|
|
247
247
|
})
|
|
248
248
|
|
|
249
249
|
it('should instanciate pouch with options', async () => {
|
|
250
|
-
const pouchOptions = { adapter: '
|
|
250
|
+
const pouchOptions = { adapter: 'sqlite', location: 'default' }
|
|
251
251
|
const options = { ...managerOptions, pouch: { options: pouchOptions } }
|
|
252
252
|
const manager = new PouchManager(['io.cozy.todos'], options)
|
|
253
253
|
await manager.init()
|
package/dist/helpers.js
CHANGED
|
@@ -34,7 +34,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
34
34
|
var helpers = {}; // https://github.com/pouchdb/pouchdb/issues/7011
|
|
35
35
|
|
|
36
36
|
var LIMIT_BUG = 999;
|
|
37
|
-
var ADAPTERS_WITH_LIMIT_BUG = ['
|
|
37
|
+
var ADAPTERS_WITH_LIMIT_BUG = ['websql'];
|
|
38
38
|
|
|
39
39
|
helpers.isAdapterBugged = function (adapterName) {
|
|
40
40
|
return ADAPTERS_WITH_LIMIT_BUG.includes(adapterName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-pouch-link",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "56.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": "^
|
|
16
|
+
"cozy-client": "^56.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": "
|
|
42
|
+
"gitHead": "1c6c85248b511c0f8a3a64556190abcc9925d361"
|
|
43
43
|
}
|
package/types/CozyPouchLink.d.ts
CHANGED
|
@@ -147,18 +147,27 @@ declare class PouchLink extends CozyLink {
|
|
|
147
147
|
* Emits pouchlink:sync:start event when the replication begins
|
|
148
148
|
*
|
|
149
149
|
* @public
|
|
150
|
+
*
|
|
151
|
+
* @param {object} options - The options
|
|
152
|
+
* @param {boolean|null} [options.waitForReplications=true] - Whether the others replication process should be waited
|
|
150
153
|
* @returns {void}
|
|
151
154
|
*/
|
|
152
|
-
public startReplication(
|
|
155
|
+
public startReplication({ waitForReplications }?: {
|
|
156
|
+
waitForReplications: boolean | null;
|
|
157
|
+
}): void;
|
|
153
158
|
/**
|
|
154
159
|
* Debounced version of startReplication() method
|
|
155
160
|
*
|
|
156
161
|
* Debounce delay can be configured through constructor's `syncDebounceDelayInMs` option
|
|
157
162
|
*
|
|
158
163
|
* @public
|
|
164
|
+
* @param {object} options - The options
|
|
165
|
+
* @param {boolean|null} [options.waitForReplications=true] - Whether the others replication process should be waited
|
|
159
166
|
* @returns {void}
|
|
160
167
|
*/
|
|
161
|
-
public startReplicationWithDebounce(
|
|
168
|
+
public startReplicationWithDebounce({ waitForReplications }?: {
|
|
169
|
+
waitForReplications: boolean | null;
|
|
170
|
+
}): void;
|
|
162
171
|
/**
|
|
163
172
|
* User of the link can call this to stop ongoing replications.
|
|
164
173
|
* Typically, it can be used when the applications loses focus.
|
package/types/PouchManager.d.ts
CHANGED
|
@@ -30,8 +30,16 @@ declare class PouchManager {
|
|
|
30
30
|
startReplicationLoop(): Promise<Loop | void>;
|
|
31
31
|
/** Stop periodic syncing of the pouches */
|
|
32
32
|
stopReplicationLoop(): void;
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Starts replication
|
|
35
|
+
*
|
|
36
|
+
* @param {object} options - The options
|
|
37
|
+
* @param {boolean|null} [options.waitForReplications=true] - Whether the others replication process should be waited
|
|
38
|
+
* @returns {Promise<any>} the replication result
|
|
39
|
+
*/
|
|
40
|
+
replicateOnce({ waitForReplications }?: {
|
|
41
|
+
waitForReplications: boolean | null;
|
|
42
|
+
}): Promise<any>;
|
|
35
43
|
executeQuery: any;
|
|
36
44
|
/** @type {import('./types').CancelablePromise[]} - Stores replication promises */
|
|
37
45
|
replications: import('./types').CancelablePromise[];
|
|
@@ -53,7 +61,7 @@ declare class PouchManager {
|
|
|
53
61
|
syncImmediately(): void;
|
|
54
62
|
handleReplicationError(err: any): void;
|
|
55
63
|
cancelCurrentReplications(): void;
|
|
56
|
-
waitForCurrentReplications(): Promise<void> | Promise<
|
|
64
|
+
waitForCurrentReplications(): Promise<void> | Promise<(import("./utils").FulfilledPromise | import("./utils").RejectedPromise)[]>;
|
|
57
65
|
getPouch(doctype: any): any;
|
|
58
66
|
/**
|
|
59
67
|
* Update the Sync info for the specifed doctype
|