cozy-pouch-link 49.8.0 → 50.1.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/PouchManager.js +3 -7
- package/dist/PouchManager.spec.js +13 -17
- package/dist/files.js +1 -0
- package/dist/localStorage.js +183 -155
- package/dist/platformWeb.js +109 -67
- package/dist/replicateOnce.js +4 -50
- package/dist/startReplication.js +11 -3
- package/dist/utils.js +57 -2
- package/package.json +3 -3
- package/types/PouchManager.d.ts +1 -1
- package/types/files.d.ts +0 -0
- package/types/localStorage.d.ts +13 -5
- package/types/platformWeb.d.ts +8 -3
- package/types/replicateOnce.d.ts +0 -28
- package/types/utils.d.ts +29 -0
package/dist/PouchManager.js
CHANGED
|
@@ -180,18 +180,14 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
180
180
|
|
|
181
181
|
case 6:
|
|
182
182
|
_context2.next = 8;
|
|
183
|
-
return this.storage.
|
|
183
|
+
return this.storage.destroy();
|
|
184
184
|
|
|
185
185
|
case 8:
|
|
186
|
-
_context2.
|
|
187
|
-
return this.storage.destroyAllLastReplicatedDocID();
|
|
188
|
-
|
|
189
|
-
case 10:
|
|
190
|
-
return _context2.abrupt("return", Promise.all(Object.values(this.pouches).map(function (pouch) {
|
|
186
|
+
return _context2.abrupt("return", (0, _utils.allSettled)(Object.values(this.pouches).map(function (pouch) {
|
|
191
187
|
return pouch.destroy();
|
|
192
188
|
})));
|
|
193
189
|
|
|
194
|
-
case
|
|
190
|
+
case 9:
|
|
195
191
|
case "end":
|
|
196
192
|
return _context2.stop();
|
|
197
193
|
}
|
|
@@ -19,11 +19,7 @@ jest.mock('./remote', () => ({
|
|
|
19
19
|
|
|
20
20
|
import * as rep from './startReplication'
|
|
21
21
|
import PouchDB from 'pouchdb-browser'
|
|
22
|
-
import {
|
|
23
|
-
LOCALSTORAGE_SYNCED_KEY,
|
|
24
|
-
LOCALSTORAGE_WARMUPEDQUERIES_KEY,
|
|
25
|
-
PouchLocalStorage
|
|
26
|
-
} from './localStorage'
|
|
22
|
+
import { LOCALSTORAGE_STORAGE_KEYS, PouchLocalStorage } from './localStorage'
|
|
27
23
|
import { platformWeb } from './platformWeb'
|
|
28
24
|
|
|
29
25
|
import { fetchRemoteLastSequence, fetchRemoteInstance } from './remote'
|
|
@@ -267,7 +263,7 @@ describe('PouchManager', () => {
|
|
|
267
263
|
})
|
|
268
264
|
|
|
269
265
|
it('should return an empty array if local storage contains something that is not an array', async () => {
|
|
270
|
-
localStorage.__STORE__[
|
|
266
|
+
localStorage.__STORE__[LOCALSTORAGE_STORAGE_KEYS.SYNCED] = 'true'
|
|
271
267
|
expect(await ls.getPersistedSyncedDoctypes()).toEqual({})
|
|
272
268
|
})
|
|
273
269
|
|
|
@@ -275,7 +271,7 @@ describe('PouchManager', () => {
|
|
|
275
271
|
const persistedSyncedDoctypes = {
|
|
276
272
|
'io.cozy.todos': { date: '2021-08-11T13:48:06.085Z' }
|
|
277
273
|
}
|
|
278
|
-
localStorage.__STORE__[
|
|
274
|
+
localStorage.__STORE__[LOCALSTORAGE_STORAGE_KEYS.SYNCED] = JSON.stringify(
|
|
279
275
|
persistedSyncedDoctypes
|
|
280
276
|
)
|
|
281
277
|
expect(await ls.getPersistedSyncedDoctypes()).toEqual(
|
|
@@ -291,7 +287,7 @@ describe('PouchManager', () => {
|
|
|
291
287
|
manager.syncedDoctypes = ['io.cozy.todos']
|
|
292
288
|
ls.persistSyncedDoctypes(manager.syncedDoctypes)
|
|
293
289
|
|
|
294
|
-
expect(localStorage.__STORE__[
|
|
290
|
+
expect(localStorage.__STORE__[LOCALSTORAGE_STORAGE_KEYS.SYNCED]).toEqual(
|
|
295
291
|
JSON.stringify(manager.syncedDoctypes)
|
|
296
292
|
)
|
|
297
293
|
})
|
|
@@ -318,7 +314,7 @@ describe('PouchManager', () => {
|
|
|
318
314
|
await manager.init()
|
|
319
315
|
|
|
320
316
|
await manager.updateSyncInfo('io.cozy.todos')
|
|
321
|
-
expect(localStorage.__STORE__[
|
|
317
|
+
expect(localStorage.__STORE__[LOCALSTORAGE_STORAGE_KEYS.SYNCED]).toEqual(
|
|
322
318
|
JSON.stringify({
|
|
323
319
|
'io.cozy.todos': {
|
|
324
320
|
date: '2021-08-01T00:00:00.000Z',
|
|
@@ -357,7 +353,7 @@ describe('PouchManager', () => {
|
|
|
357
353
|
await ls.destroySyncedDoctypes()
|
|
358
354
|
|
|
359
355
|
expect(localStorage.removeItem).toHaveBeenLastCalledWith(
|
|
360
|
-
|
|
356
|
+
LOCALSTORAGE_STORAGE_KEYS.SYNCED
|
|
361
357
|
)
|
|
362
358
|
})
|
|
363
359
|
it('should reset syncedDoctypes', async () => {
|
|
@@ -376,9 +372,9 @@ describe('PouchManager', () => {
|
|
|
376
372
|
|
|
377
373
|
it('should return the list of queries if local storage contains ones', async () => {
|
|
378
374
|
const persistedQueries = [query().options.as]
|
|
379
|
-
localStorage.__STORE__[
|
|
380
|
-
|
|
381
|
-
)
|
|
375
|
+
localStorage.__STORE__[
|
|
376
|
+
LOCALSTORAGE_STORAGE_KEYS.WARMUPEDQUERIES
|
|
377
|
+
] = JSON.stringify(persistedQueries)
|
|
382
378
|
expect(await ls.getPersistedWarmedUpQueries()).toEqual(persistedQueries)
|
|
383
379
|
})
|
|
384
380
|
})
|
|
@@ -390,9 +386,9 @@ describe('PouchManager', () => {
|
|
|
390
386
|
manager.warmedUpQueries = { 'io.cozy.todos': ['query1', 'query2'] }
|
|
391
387
|
await ls.persistWarmedUpQueries(manager.warmedUpQueries)
|
|
392
388
|
|
|
393
|
-
expect(
|
|
394
|
-
|
|
395
|
-
)
|
|
389
|
+
expect(
|
|
390
|
+
localStorage.__STORE__[LOCALSTORAGE_STORAGE_KEYS.WARMUPEDQUERIES]
|
|
391
|
+
).toEqual(JSON.stringify(manager.warmedUpQueries))
|
|
396
392
|
})
|
|
397
393
|
})
|
|
398
394
|
|
|
@@ -438,7 +434,7 @@ describe('PouchManager', () => {
|
|
|
438
434
|
manager.clearWarmedUpQueries()
|
|
439
435
|
|
|
440
436
|
expect(localStorage.removeItem).toHaveBeenLastCalledWith(
|
|
441
|
-
|
|
437
|
+
LOCALSTORAGE_STORAGE_KEYS.WARMUPEDQUERIES
|
|
442
438
|
)
|
|
443
439
|
})
|
|
444
440
|
it('should reset warmedupQueries', () => {
|
package/dist/files.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/localStorage.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.PouchLocalStorage = exports.
|
|
8
|
+
exports.PouchLocalStorage = exports.LOCALSTORAGE_STORAGE_KEYS = void 0;
|
|
9
9
|
|
|
10
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
11
|
|
|
@@ -15,16 +15,14 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
15
15
|
|
|
16
16
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
17
|
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
exports.
|
|
26
|
-
var LOCALSTORAGE_ADAPTERNAME = 'cozy-client-pouch-link-adaptername';
|
|
27
|
-
exports.LOCALSTORAGE_ADAPTERNAME = LOCALSTORAGE_ADAPTERNAME;
|
|
18
|
+
var LOCALSTORAGE_STORAGE_KEYS = {
|
|
19
|
+
SYNCED: 'cozy-client-pouch-link-synced',
|
|
20
|
+
WARMUPEDQUERIES: 'cozy-client-pouch-link-warmupedqueries',
|
|
21
|
+
LASTSEQUENCES: 'cozy-client-pouch-link-lastreplicationsequence',
|
|
22
|
+
LASTREPLICATEDDOCID: 'cozy-client-pouch-link-lastreplicateddocid',
|
|
23
|
+
ADAPTERNAME: 'cozy-client-pouch-link-adaptername'
|
|
24
|
+
};
|
|
25
|
+
exports.LOCALSTORAGE_STORAGE_KEYS = LOCALSTORAGE_STORAGE_KEYS;
|
|
28
26
|
|
|
29
27
|
var PouchLocalStorage = /*#__PURE__*/function () {
|
|
30
28
|
function PouchLocalStorage(storageEngine) {
|
|
@@ -33,39 +31,69 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
33
31
|
this.storageEngine = storageEngine;
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @param {string} doctype - The replicated doctype
|
|
39
|
-
* @param {string} id - The docid
|
|
34
|
+
* Destroy the storage data
|
|
40
35
|
*
|
|
41
36
|
* @returns {Promise<void>}
|
|
42
37
|
*/
|
|
43
38
|
|
|
44
39
|
|
|
45
40
|
(0, _createClass2.default)(PouchLocalStorage, [{
|
|
46
|
-
key: "
|
|
41
|
+
key: "destroy",
|
|
47
42
|
value: function () {
|
|
48
|
-
var
|
|
49
|
-
var docids;
|
|
43
|
+
var _destroy = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
50
44
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
51
45
|
while (1) {
|
|
52
46
|
switch (_context.prev = _context.next) {
|
|
53
47
|
case 0:
|
|
54
|
-
|
|
48
|
+
this.storageEngine.destroy();
|
|
49
|
+
|
|
50
|
+
case 1:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, _callee, this);
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
function destroy() {
|
|
59
|
+
return _destroy.apply(this, arguments);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return destroy;
|
|
63
|
+
}()
|
|
64
|
+
/**
|
|
65
|
+
* Persist the last replicated doc id for a doctype
|
|
66
|
+
*
|
|
67
|
+
* @param {string} doctype - The replicated doctype
|
|
68
|
+
* @param {string} id - The docid
|
|
69
|
+
*
|
|
70
|
+
* @returns {Promise<void>}
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
}, {
|
|
74
|
+
key: "persistLastReplicatedDocID",
|
|
75
|
+
value: function () {
|
|
76
|
+
var _persistLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(doctype, id) {
|
|
77
|
+
var docids;
|
|
78
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
79
|
+
while (1) {
|
|
80
|
+
switch (_context2.prev = _context2.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
_context2.next = 2;
|
|
55
83
|
return this.getAllLastReplicatedDocID();
|
|
56
84
|
|
|
57
85
|
case 2:
|
|
58
|
-
docids =
|
|
86
|
+
docids = _context2.sent;
|
|
59
87
|
docids[doctype] = id;
|
|
60
|
-
|
|
61
|
-
return this.storageEngine.setItem(
|
|
88
|
+
_context2.next = 6;
|
|
89
|
+
return this.storageEngine.setItem(LOCALSTORAGE_STORAGE_KEYS.LASTREPLICATEDDOCID, JSON.stringify(docids));
|
|
62
90
|
|
|
63
91
|
case 6:
|
|
64
92
|
case "end":
|
|
65
|
-
return
|
|
93
|
+
return _context2.stop();
|
|
66
94
|
}
|
|
67
95
|
}
|
|
68
|
-
},
|
|
96
|
+
}, _callee2, this);
|
|
69
97
|
}));
|
|
70
98
|
|
|
71
99
|
function persistLastReplicatedDocID(_x, _x2) {
|
|
@@ -81,25 +109,25 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
81
109
|
}, {
|
|
82
110
|
key: "getAllLastReplicatedDocID",
|
|
83
111
|
value: function () {
|
|
84
|
-
var _getAllLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
112
|
+
var _getAllLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
85
113
|
var item;
|
|
86
|
-
return _regenerator.default.wrap(function
|
|
114
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
87
115
|
while (1) {
|
|
88
|
-
switch (
|
|
116
|
+
switch (_context3.prev = _context3.next) {
|
|
89
117
|
case 0:
|
|
90
|
-
|
|
91
|
-
return this.storageEngine.getItem(
|
|
118
|
+
_context3.next = 2;
|
|
119
|
+
return this.storageEngine.getItem(LOCALSTORAGE_STORAGE_KEYS.LASTREPLICATEDDOCID);
|
|
92
120
|
|
|
93
121
|
case 2:
|
|
94
|
-
item =
|
|
95
|
-
return
|
|
122
|
+
item = _context3.sent;
|
|
123
|
+
return _context3.abrupt("return", item ? JSON.parse(item) : {});
|
|
96
124
|
|
|
97
125
|
case 4:
|
|
98
126
|
case "end":
|
|
99
|
-
return
|
|
127
|
+
return _context3.stop();
|
|
100
128
|
}
|
|
101
129
|
}
|
|
102
|
-
},
|
|
130
|
+
}, _callee3, this);
|
|
103
131
|
}));
|
|
104
132
|
|
|
105
133
|
function getAllLastReplicatedDocID() {
|
|
@@ -118,25 +146,25 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
118
146
|
}, {
|
|
119
147
|
key: "getLastReplicatedDocID",
|
|
120
148
|
value: function () {
|
|
121
|
-
var _getLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
149
|
+
var _getLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(doctype) {
|
|
122
150
|
var docids;
|
|
123
|
-
return _regenerator.default.wrap(function
|
|
151
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
124
152
|
while (1) {
|
|
125
|
-
switch (
|
|
153
|
+
switch (_context4.prev = _context4.next) {
|
|
126
154
|
case 0:
|
|
127
|
-
|
|
155
|
+
_context4.next = 2;
|
|
128
156
|
return this.getAllLastReplicatedDocID();
|
|
129
157
|
|
|
130
158
|
case 2:
|
|
131
|
-
docids =
|
|
132
|
-
return
|
|
159
|
+
docids = _context4.sent;
|
|
160
|
+
return _context4.abrupt("return", docids[doctype]);
|
|
133
161
|
|
|
134
162
|
case 4:
|
|
135
163
|
case "end":
|
|
136
|
-
return
|
|
164
|
+
return _context4.stop();
|
|
137
165
|
}
|
|
138
166
|
}
|
|
139
|
-
},
|
|
167
|
+
}, _callee4, this);
|
|
140
168
|
}));
|
|
141
169
|
|
|
142
170
|
function getLastReplicatedDocID(_x3) {
|
|
@@ -154,20 +182,20 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
154
182
|
}, {
|
|
155
183
|
key: "destroyAllLastReplicatedDocID",
|
|
156
184
|
value: function () {
|
|
157
|
-
var _destroyAllLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
158
|
-
return _regenerator.default.wrap(function
|
|
185
|
+
var _destroyAllLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
|
|
186
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
159
187
|
while (1) {
|
|
160
|
-
switch (
|
|
188
|
+
switch (_context5.prev = _context5.next) {
|
|
161
189
|
case 0:
|
|
162
|
-
|
|
163
|
-
return this.storageEngine.removeItem(
|
|
190
|
+
_context5.next = 2;
|
|
191
|
+
return this.storageEngine.removeItem(LOCALSTORAGE_STORAGE_KEYS.LASTREPLICATEDDOCID);
|
|
164
192
|
|
|
165
193
|
case 2:
|
|
166
194
|
case "end":
|
|
167
|
-
return
|
|
195
|
+
return _context5.stop();
|
|
168
196
|
}
|
|
169
197
|
}
|
|
170
|
-
},
|
|
198
|
+
}, _callee5, this);
|
|
171
199
|
}));
|
|
172
200
|
|
|
173
201
|
function destroyAllLastReplicatedDocID() {
|
|
@@ -187,20 +215,20 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
187
215
|
}, {
|
|
188
216
|
key: "persistSyncedDoctypes",
|
|
189
217
|
value: function () {
|
|
190
|
-
var _persistSyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
191
|
-
return _regenerator.default.wrap(function
|
|
218
|
+
var _persistSyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(syncedDoctypes) {
|
|
219
|
+
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
192
220
|
while (1) {
|
|
193
|
-
switch (
|
|
221
|
+
switch (_context6.prev = _context6.next) {
|
|
194
222
|
case 0:
|
|
195
|
-
|
|
196
|
-
return this.storageEngine.setItem(
|
|
223
|
+
_context6.next = 2;
|
|
224
|
+
return this.storageEngine.setItem(LOCALSTORAGE_STORAGE_KEYS.SYNCED, JSON.stringify(syncedDoctypes));
|
|
197
225
|
|
|
198
226
|
case 2:
|
|
199
227
|
case "end":
|
|
200
|
-
return
|
|
228
|
+
return _context6.stop();
|
|
201
229
|
}
|
|
202
230
|
}
|
|
203
|
-
},
|
|
231
|
+
}, _callee6, this);
|
|
204
232
|
}));
|
|
205
233
|
|
|
206
234
|
function persistSyncedDoctypes(_x4) {
|
|
@@ -218,35 +246,35 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
218
246
|
}, {
|
|
219
247
|
key: "getPersistedSyncedDoctypes",
|
|
220
248
|
value: function () {
|
|
221
|
-
var _getPersistedSyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
249
|
+
var _getPersistedSyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() {
|
|
222
250
|
var item, parsed;
|
|
223
|
-
return _regenerator.default.wrap(function
|
|
251
|
+
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
224
252
|
while (1) {
|
|
225
|
-
switch (
|
|
253
|
+
switch (_context7.prev = _context7.next) {
|
|
226
254
|
case 0:
|
|
227
|
-
|
|
228
|
-
return this.storageEngine.getItem(
|
|
255
|
+
_context7.next = 2;
|
|
256
|
+
return this.storageEngine.getItem(LOCALSTORAGE_STORAGE_KEYS.SYNCED);
|
|
229
257
|
|
|
230
258
|
case 2:
|
|
231
|
-
item =
|
|
259
|
+
item = _context7.sent;
|
|
232
260
|
parsed = item ? JSON.parse(item) : {};
|
|
233
261
|
|
|
234
262
|
if (!(typeof parsed !== 'object')) {
|
|
235
|
-
|
|
263
|
+
_context7.next = 6;
|
|
236
264
|
break;
|
|
237
265
|
}
|
|
238
266
|
|
|
239
|
-
return
|
|
267
|
+
return _context7.abrupt("return", {});
|
|
240
268
|
|
|
241
269
|
case 6:
|
|
242
|
-
return
|
|
270
|
+
return _context7.abrupt("return", parsed);
|
|
243
271
|
|
|
244
272
|
case 7:
|
|
245
273
|
case "end":
|
|
246
|
-
return
|
|
274
|
+
return _context7.stop();
|
|
247
275
|
}
|
|
248
276
|
}
|
|
249
|
-
},
|
|
277
|
+
}, _callee7, this);
|
|
250
278
|
}));
|
|
251
279
|
|
|
252
280
|
function getPersistedSyncedDoctypes() {
|
|
@@ -264,20 +292,20 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
264
292
|
}, {
|
|
265
293
|
key: "destroySyncedDoctypes",
|
|
266
294
|
value: function () {
|
|
267
|
-
var _destroySyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
268
|
-
return _regenerator.default.wrap(function
|
|
295
|
+
var _destroySyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8() {
|
|
296
|
+
return _regenerator.default.wrap(function _callee8$(_context8) {
|
|
269
297
|
while (1) {
|
|
270
|
-
switch (
|
|
298
|
+
switch (_context8.prev = _context8.next) {
|
|
271
299
|
case 0:
|
|
272
|
-
|
|
273
|
-
return this.storageEngine.removeItem(
|
|
300
|
+
_context8.next = 2;
|
|
301
|
+
return this.storageEngine.removeItem(LOCALSTORAGE_STORAGE_KEYS.SYNCED);
|
|
274
302
|
|
|
275
303
|
case 2:
|
|
276
304
|
case "end":
|
|
277
|
-
return
|
|
305
|
+
return _context8.stop();
|
|
278
306
|
}
|
|
279
307
|
}
|
|
280
|
-
},
|
|
308
|
+
}, _callee8, this);
|
|
281
309
|
}));
|
|
282
310
|
|
|
283
311
|
function destroySyncedDoctypes() {
|
|
@@ -298,27 +326,27 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
298
326
|
}, {
|
|
299
327
|
key: "persistDoctypeLastSequence",
|
|
300
328
|
value: function () {
|
|
301
|
-
var _persistDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
329
|
+
var _persistDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(doctype, sequence) {
|
|
302
330
|
var seqs;
|
|
303
|
-
return _regenerator.default.wrap(function
|
|
331
|
+
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
304
332
|
while (1) {
|
|
305
|
-
switch (
|
|
333
|
+
switch (_context9.prev = _context9.next) {
|
|
306
334
|
case 0:
|
|
307
|
-
|
|
335
|
+
_context9.next = 2;
|
|
308
336
|
return this.getAllLastSequences();
|
|
309
337
|
|
|
310
338
|
case 2:
|
|
311
|
-
seqs =
|
|
339
|
+
seqs = _context9.sent;
|
|
312
340
|
seqs[doctype] = sequence;
|
|
313
|
-
|
|
314
|
-
return this.storageEngine.setItem(
|
|
341
|
+
_context9.next = 6;
|
|
342
|
+
return this.storageEngine.setItem(LOCALSTORAGE_STORAGE_KEYS.LASTSEQUENCES, JSON.stringify(seqs));
|
|
315
343
|
|
|
316
344
|
case 6:
|
|
317
345
|
case "end":
|
|
318
|
-
return
|
|
346
|
+
return _context9.stop();
|
|
319
347
|
}
|
|
320
348
|
}
|
|
321
|
-
},
|
|
349
|
+
}, _callee9, this);
|
|
322
350
|
}));
|
|
323
351
|
|
|
324
352
|
function persistDoctypeLastSequence(_x5, _x6) {
|
|
@@ -334,25 +362,25 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
334
362
|
}, {
|
|
335
363
|
key: "getAllLastSequences",
|
|
336
364
|
value: function () {
|
|
337
|
-
var _getAllLastSequences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
365
|
+
var _getAllLastSequences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10() {
|
|
338
366
|
var item;
|
|
339
|
-
return _regenerator.default.wrap(function
|
|
367
|
+
return _regenerator.default.wrap(function _callee10$(_context10) {
|
|
340
368
|
while (1) {
|
|
341
|
-
switch (
|
|
369
|
+
switch (_context10.prev = _context10.next) {
|
|
342
370
|
case 0:
|
|
343
|
-
|
|
344
|
-
return this.storageEngine.getItem(
|
|
371
|
+
_context10.next = 2;
|
|
372
|
+
return this.storageEngine.getItem(LOCALSTORAGE_STORAGE_KEYS.LASTSEQUENCES);
|
|
345
373
|
|
|
346
374
|
case 2:
|
|
347
|
-
item =
|
|
348
|
-
return
|
|
375
|
+
item = _context10.sent;
|
|
376
|
+
return _context10.abrupt("return", item ? JSON.parse(item) : {});
|
|
349
377
|
|
|
350
378
|
case 4:
|
|
351
379
|
case "end":
|
|
352
|
-
return
|
|
380
|
+
return _context10.stop();
|
|
353
381
|
}
|
|
354
382
|
}
|
|
355
|
-
},
|
|
383
|
+
}, _callee10, this);
|
|
356
384
|
}));
|
|
357
385
|
|
|
358
386
|
function getAllLastSequences() {
|
|
@@ -372,25 +400,25 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
372
400
|
}, {
|
|
373
401
|
key: "getDoctypeLastSequence",
|
|
374
402
|
value: function () {
|
|
375
|
-
var _getDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
403
|
+
var _getDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(doctype) {
|
|
376
404
|
var seqs;
|
|
377
|
-
return _regenerator.default.wrap(function
|
|
405
|
+
return _regenerator.default.wrap(function _callee11$(_context11) {
|
|
378
406
|
while (1) {
|
|
379
|
-
switch (
|
|
407
|
+
switch (_context11.prev = _context11.next) {
|
|
380
408
|
case 0:
|
|
381
|
-
|
|
409
|
+
_context11.next = 2;
|
|
382
410
|
return this.getAllLastSequences();
|
|
383
411
|
|
|
384
412
|
case 2:
|
|
385
|
-
seqs =
|
|
386
|
-
return
|
|
413
|
+
seqs = _context11.sent;
|
|
414
|
+
return _context11.abrupt("return", seqs[doctype]);
|
|
387
415
|
|
|
388
416
|
case 4:
|
|
389
417
|
case "end":
|
|
390
|
-
return
|
|
418
|
+
return _context11.stop();
|
|
391
419
|
}
|
|
392
420
|
}
|
|
393
|
-
},
|
|
421
|
+
}, _callee11, this);
|
|
394
422
|
}));
|
|
395
423
|
|
|
396
424
|
function getDoctypeLastSequence(_x7) {
|
|
@@ -408,20 +436,20 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
408
436
|
}, {
|
|
409
437
|
key: "destroyAllDoctypeLastSequence",
|
|
410
438
|
value: function () {
|
|
411
|
-
var _destroyAllDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
412
|
-
return _regenerator.default.wrap(function
|
|
439
|
+
var _destroyAllDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12() {
|
|
440
|
+
return _regenerator.default.wrap(function _callee12$(_context12) {
|
|
413
441
|
while (1) {
|
|
414
|
-
switch (
|
|
442
|
+
switch (_context12.prev = _context12.next) {
|
|
415
443
|
case 0:
|
|
416
|
-
|
|
417
|
-
return this.storageEngine.removeItem(
|
|
444
|
+
_context12.next = 2;
|
|
445
|
+
return this.storageEngine.removeItem(LOCALSTORAGE_STORAGE_KEYS.LASTSEQUENCES);
|
|
418
446
|
|
|
419
447
|
case 2:
|
|
420
448
|
case "end":
|
|
421
|
-
return
|
|
449
|
+
return _context12.stop();
|
|
422
450
|
}
|
|
423
451
|
}
|
|
424
|
-
},
|
|
452
|
+
}, _callee12, this);
|
|
425
453
|
}));
|
|
426
454
|
|
|
427
455
|
function destroyAllDoctypeLastSequence() {
|
|
@@ -441,27 +469,27 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
441
469
|
}, {
|
|
442
470
|
key: "destroyDoctypeLastSequence",
|
|
443
471
|
value: function () {
|
|
444
|
-
var _destroyDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
472
|
+
var _destroyDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(doctype) {
|
|
445
473
|
var seqs;
|
|
446
|
-
return _regenerator.default.wrap(function
|
|
474
|
+
return _regenerator.default.wrap(function _callee13$(_context13) {
|
|
447
475
|
while (1) {
|
|
448
|
-
switch (
|
|
476
|
+
switch (_context13.prev = _context13.next) {
|
|
449
477
|
case 0:
|
|
450
|
-
|
|
478
|
+
_context13.next = 2;
|
|
451
479
|
return this.getAllLastSequences();
|
|
452
480
|
|
|
453
481
|
case 2:
|
|
454
|
-
seqs =
|
|
482
|
+
seqs = _context13.sent;
|
|
455
483
|
delete seqs[doctype];
|
|
456
|
-
|
|
457
|
-
return this.storageEngine.setItem(
|
|
484
|
+
_context13.next = 6;
|
|
485
|
+
return this.storageEngine.setItem(LOCALSTORAGE_STORAGE_KEYS.LASTSEQUENCES, JSON.stringify(seqs));
|
|
458
486
|
|
|
459
487
|
case 6:
|
|
460
488
|
case "end":
|
|
461
|
-
return
|
|
489
|
+
return _context13.stop();
|
|
462
490
|
}
|
|
463
491
|
}
|
|
464
|
-
},
|
|
492
|
+
}, _callee13, this);
|
|
465
493
|
}));
|
|
466
494
|
|
|
467
495
|
function destroyDoctypeLastSequence(_x8) {
|
|
@@ -481,20 +509,20 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
481
509
|
}, {
|
|
482
510
|
key: "persistWarmedUpQueries",
|
|
483
511
|
value: function () {
|
|
484
|
-
var _persistWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
485
|
-
return _regenerator.default.wrap(function
|
|
512
|
+
var _persistWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(warmedUpQueries) {
|
|
513
|
+
return _regenerator.default.wrap(function _callee14$(_context14) {
|
|
486
514
|
while (1) {
|
|
487
|
-
switch (
|
|
515
|
+
switch (_context14.prev = _context14.next) {
|
|
488
516
|
case 0:
|
|
489
|
-
|
|
490
|
-
return this.storageEngine.setItem(
|
|
517
|
+
_context14.next = 2;
|
|
518
|
+
return this.storageEngine.setItem(LOCALSTORAGE_STORAGE_KEYS.WARMUPEDQUERIES, JSON.stringify(warmedUpQueries));
|
|
491
519
|
|
|
492
520
|
case 2:
|
|
493
521
|
case "end":
|
|
494
|
-
return
|
|
522
|
+
return _context14.stop();
|
|
495
523
|
}
|
|
496
524
|
}
|
|
497
|
-
},
|
|
525
|
+
}, _callee14, this);
|
|
498
526
|
}));
|
|
499
527
|
|
|
500
528
|
function persistWarmedUpQueries(_x9) {
|
|
@@ -512,34 +540,34 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
512
540
|
}, {
|
|
513
541
|
key: "getPersistedWarmedUpQueries",
|
|
514
542
|
value: function () {
|
|
515
|
-
var _getPersistedWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
543
|
+
var _getPersistedWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15() {
|
|
516
544
|
var item;
|
|
517
|
-
return _regenerator.default.wrap(function
|
|
545
|
+
return _regenerator.default.wrap(function _callee15$(_context15) {
|
|
518
546
|
while (1) {
|
|
519
|
-
switch (
|
|
547
|
+
switch (_context15.prev = _context15.next) {
|
|
520
548
|
case 0:
|
|
521
|
-
|
|
522
|
-
return this.storageEngine.getItem(
|
|
549
|
+
_context15.next = 2;
|
|
550
|
+
return this.storageEngine.getItem(LOCALSTORAGE_STORAGE_KEYS.WARMUPEDQUERIES);
|
|
523
551
|
|
|
524
552
|
case 2:
|
|
525
|
-
item =
|
|
553
|
+
item = _context15.sent;
|
|
526
554
|
|
|
527
555
|
if (item) {
|
|
528
|
-
|
|
556
|
+
_context15.next = 5;
|
|
529
557
|
break;
|
|
530
558
|
}
|
|
531
559
|
|
|
532
|
-
return
|
|
560
|
+
return _context15.abrupt("return", {});
|
|
533
561
|
|
|
534
562
|
case 5:
|
|
535
|
-
return
|
|
563
|
+
return _context15.abrupt("return", JSON.parse(item));
|
|
536
564
|
|
|
537
565
|
case 6:
|
|
538
566
|
case "end":
|
|
539
|
-
return
|
|
567
|
+
return _context15.stop();
|
|
540
568
|
}
|
|
541
569
|
}
|
|
542
|
-
},
|
|
570
|
+
}, _callee15, this);
|
|
543
571
|
}));
|
|
544
572
|
|
|
545
573
|
function getPersistedWarmedUpQueries() {
|
|
@@ -557,20 +585,20 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
557
585
|
}, {
|
|
558
586
|
key: "destroyWarmedUpQueries",
|
|
559
587
|
value: function () {
|
|
560
|
-
var _destroyWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
561
|
-
return _regenerator.default.wrap(function
|
|
588
|
+
var _destroyWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16() {
|
|
589
|
+
return _regenerator.default.wrap(function _callee16$(_context16) {
|
|
562
590
|
while (1) {
|
|
563
|
-
switch (
|
|
591
|
+
switch (_context16.prev = _context16.next) {
|
|
564
592
|
case 0:
|
|
565
|
-
|
|
566
|
-
return this.storageEngine.removeItem(
|
|
593
|
+
_context16.next = 2;
|
|
594
|
+
return this.storageEngine.removeItem(LOCALSTORAGE_STORAGE_KEYS.WARMUPEDQUERIES);
|
|
567
595
|
|
|
568
596
|
case 2:
|
|
569
597
|
case "end":
|
|
570
|
-
return
|
|
598
|
+
return _context16.stop();
|
|
571
599
|
}
|
|
572
600
|
}
|
|
573
|
-
},
|
|
601
|
+
}, _callee16, this);
|
|
574
602
|
}));
|
|
575
603
|
|
|
576
604
|
function destroyWarmedUpQueries() {
|
|
@@ -588,23 +616,23 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
588
616
|
}, {
|
|
589
617
|
key: "getAdapterName",
|
|
590
618
|
value: function () {
|
|
591
|
-
var _getAdapterName = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
592
|
-
return _regenerator.default.wrap(function
|
|
619
|
+
var _getAdapterName = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17() {
|
|
620
|
+
return _regenerator.default.wrap(function _callee17$(_context17) {
|
|
593
621
|
while (1) {
|
|
594
|
-
switch (
|
|
622
|
+
switch (_context17.prev = _context17.next) {
|
|
595
623
|
case 0:
|
|
596
|
-
|
|
597
|
-
return this.storageEngine.getItem(
|
|
624
|
+
_context17.next = 2;
|
|
625
|
+
return this.storageEngine.getItem(LOCALSTORAGE_STORAGE_KEYS.ADAPTERNAME);
|
|
598
626
|
|
|
599
627
|
case 2:
|
|
600
|
-
return
|
|
628
|
+
return _context17.abrupt("return", _context17.sent);
|
|
601
629
|
|
|
602
630
|
case 3:
|
|
603
631
|
case "end":
|
|
604
|
-
return
|
|
632
|
+
return _context17.stop();
|
|
605
633
|
}
|
|
606
634
|
}
|
|
607
|
-
},
|
|
635
|
+
}, _callee17, this);
|
|
608
636
|
}));
|
|
609
637
|
|
|
610
638
|
function getAdapterName() {
|
|
@@ -624,20 +652,20 @@ var PouchLocalStorage = /*#__PURE__*/function () {
|
|
|
624
652
|
}, {
|
|
625
653
|
key: "persistAdapterName",
|
|
626
654
|
value: function () {
|
|
627
|
-
var _persistAdapterName = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
628
|
-
return _regenerator.default.wrap(function
|
|
655
|
+
var _persistAdapterName = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18(adapter) {
|
|
656
|
+
return _regenerator.default.wrap(function _callee18$(_context18) {
|
|
629
657
|
while (1) {
|
|
630
|
-
switch (
|
|
658
|
+
switch (_context18.prev = _context18.next) {
|
|
631
659
|
case 0:
|
|
632
|
-
|
|
633
|
-
return this.storageEngine.setItem(
|
|
660
|
+
_context18.next = 2;
|
|
661
|
+
return this.storageEngine.setItem(LOCALSTORAGE_STORAGE_KEYS.ADAPTERNAME, adapter);
|
|
634
662
|
|
|
635
663
|
case 2:
|
|
636
664
|
case "end":
|
|
637
|
-
return
|
|
665
|
+
return _context18.stop();
|
|
638
666
|
}
|
|
639
667
|
}
|
|
640
|
-
},
|
|
668
|
+
}, _callee18, this);
|
|
641
669
|
}));
|
|
642
670
|
|
|
643
671
|
function persistAdapterName(_x10) {
|
package/dist/platformWeb.js
CHANGED
|
@@ -13,6 +13,8 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
13
13
|
|
|
14
14
|
var _pouchdbBrowser = _interopRequireDefault(require("pouchdb-browser"));
|
|
15
15
|
|
|
16
|
+
var _localStorage = require("./localStorage");
|
|
17
|
+
|
|
16
18
|
var events = {
|
|
17
19
|
addEventListener: function addEventListener(eventName, handler) {
|
|
18
20
|
document.addEventListener(eventName, handler);
|
|
@@ -21,84 +23,96 @@ var events = {
|
|
|
21
23
|
document.removeEventListener(eventName, handler);
|
|
22
24
|
}
|
|
23
25
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
26
|
+
|
|
27
|
+
var getItem = /*#__PURE__*/function () {
|
|
28
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(key) {
|
|
29
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
30
|
+
while (1) {
|
|
31
|
+
switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
return _context.abrupt("return", window.localStorage.getItem(key));
|
|
34
|
+
|
|
35
|
+
case 1:
|
|
36
|
+
case "end":
|
|
37
|
+
return _context.stop();
|
|
37
38
|
}
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
39
|
+
}
|
|
40
|
+
}, _callee);
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
return function getItem(_x) {
|
|
44
|
+
return _ref.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
}();
|
|
47
|
+
|
|
48
|
+
var setItem = /*#__PURE__*/function () {
|
|
49
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(key, value) {
|
|
50
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
51
|
+
while (1) {
|
|
52
|
+
switch (_context2.prev = _context2.next) {
|
|
53
|
+
case 0:
|
|
54
|
+
return _context2.abrupt("return", window.localStorage.setItem(key, value));
|
|
55
|
+
|
|
56
|
+
case 1:
|
|
57
|
+
case "end":
|
|
58
|
+
return _context2.stop();
|
|
59
59
|
}
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
60
|
+
}
|
|
61
|
+
}, _callee2);
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
return function setItem(_x2, _x3) {
|
|
65
|
+
return _ref2.apply(this, arguments);
|
|
66
|
+
};
|
|
67
|
+
}();
|
|
68
|
+
|
|
69
|
+
var removeItem = /*#__PURE__*/function () {
|
|
70
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(key) {
|
|
71
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
72
|
+
while (1) {
|
|
73
|
+
switch (_context3.prev = _context3.next) {
|
|
74
|
+
case 0:
|
|
75
|
+
return _context3.abrupt("return", window.localStorage.removeItem(key));
|
|
76
|
+
|
|
77
|
+
case 1:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context3.stop();
|
|
81
80
|
}
|
|
82
|
-
}
|
|
83
|
-
})
|
|
81
|
+
}
|
|
82
|
+
}, _callee3);
|
|
83
|
+
}));
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
return function removeItem(_x4) {
|
|
86
|
+
return _ref3.apply(this, arguments);
|
|
87
|
+
};
|
|
88
|
+
}();
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
var destroy = /*#__PURE__*/function () {
|
|
91
|
+
var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
|
|
92
|
+
var _i, _Object$values, key;
|
|
92
93
|
|
|
93
|
-
var isOnline = /*#__PURE__*/function () {
|
|
94
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
|
|
95
94
|
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
96
95
|
while (1) {
|
|
97
96
|
switch (_context4.prev = _context4.next) {
|
|
98
97
|
case 0:
|
|
99
|
-
|
|
98
|
+
_i = 0, _Object$values = Object.values(_localStorage.LOCALSTORAGE_STORAGE_KEYS);
|
|
100
99
|
|
|
101
100
|
case 1:
|
|
101
|
+
if (!(_i < _Object$values.length)) {
|
|
102
|
+
_context4.next = 8;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
key = _Object$values[_i];
|
|
107
|
+
_context4.next = 5;
|
|
108
|
+
return removeItem(key);
|
|
109
|
+
|
|
110
|
+
case 5:
|
|
111
|
+
_i++;
|
|
112
|
+
_context4.next = 1;
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
case 8:
|
|
102
116
|
case "end":
|
|
103
117
|
return _context4.stop();
|
|
104
118
|
}
|
|
@@ -106,8 +120,36 @@ var isOnline = /*#__PURE__*/function () {
|
|
|
106
120
|
}, _callee4);
|
|
107
121
|
}));
|
|
108
122
|
|
|
123
|
+
return function destroy() {
|
|
124
|
+
return _ref4.apply(this, arguments);
|
|
125
|
+
};
|
|
126
|
+
}();
|
|
127
|
+
|
|
128
|
+
var storage = {
|
|
129
|
+
getItem: getItem,
|
|
130
|
+
setItem: setItem,
|
|
131
|
+
removeItem: removeItem,
|
|
132
|
+
destroy: destroy
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
var isOnline = /*#__PURE__*/function () {
|
|
136
|
+
var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
|
|
137
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
138
|
+
while (1) {
|
|
139
|
+
switch (_context5.prev = _context5.next) {
|
|
140
|
+
case 0:
|
|
141
|
+
return _context5.abrupt("return", window.navigator.onLine);
|
|
142
|
+
|
|
143
|
+
case 1:
|
|
144
|
+
case "end":
|
|
145
|
+
return _context5.stop();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, _callee5);
|
|
149
|
+
}));
|
|
150
|
+
|
|
109
151
|
return function isOnline() {
|
|
110
|
-
return
|
|
152
|
+
return _ref5.apply(this, arguments);
|
|
111
153
|
};
|
|
112
154
|
}();
|
|
113
155
|
|
package/dist/replicateOnce.js
CHANGED
|
@@ -27,6 +27,8 @@ var _remote = require("./remote");
|
|
|
27
27
|
|
|
28
28
|
var _startReplication = require("./startReplication");
|
|
29
29
|
|
|
30
|
+
var _utils = require("./utils");
|
|
31
|
+
|
|
30
32
|
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; } } }; }
|
|
31
33
|
|
|
32
34
|
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); }
|
|
@@ -164,7 +166,7 @@ var replicateOnce = /*#__PURE__*/function () {
|
|
|
164
166
|
promises = Object.values(pouchManager.replications);
|
|
165
167
|
_context2.prev = 9;
|
|
166
168
|
_context2.next = 12;
|
|
167
|
-
return allSettled(promises);
|
|
169
|
+
return (0, _utils.allSettled)(promises);
|
|
168
170
|
|
|
169
171
|
case 12:
|
|
170
172
|
res = _context2.sent;
|
|
@@ -285,53 +287,5 @@ var replicateOnce = /*#__PURE__*/function () {
|
|
|
285
287
|
return _ref.apply(this, arguments);
|
|
286
288
|
};
|
|
287
289
|
}();
|
|
288
|
-
/**
|
|
289
|
-
* @typedef {object} FulfilledPromise
|
|
290
|
-
* @property {'fulfilled'} status - The status of the promise
|
|
291
|
-
* @property {undefined} reason - The Error rejected by the promise (undefined when fulfilled)
|
|
292
|
-
* @property {any} value - The resolved value of the promise
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* @typedef {object} RejectedPromise
|
|
297
|
-
* @property {'rejected'} status - The status of the promise
|
|
298
|
-
* @property {Error} reason - The Error rejected by the promise
|
|
299
|
-
* @property {undefined} value - The resolved value of the promise (undefined when rejected)
|
|
300
|
-
*/
|
|
301
290
|
|
|
302
|
-
|
|
303
|
-
* Takes an iterable of promises as input and returns a single Promise.
|
|
304
|
-
* This returned promise fulfills when all of the input's promises settle (including
|
|
305
|
-
* when an empty iterable is passed), with an array of objects that describe the
|
|
306
|
-
* outcome of each promise.
|
|
307
|
-
*
|
|
308
|
-
* @param {Promise[]} promises - Promise to be awaited
|
|
309
|
-
* @returns {Promise<(FulfilledPromise|RejectedPromise)[]>}
|
|
310
|
-
*/
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
exports.replicateOnce = replicateOnce;
|
|
314
|
-
|
|
315
|
-
var allSettled = function allSettled(promises) {
|
|
316
|
-
return Promise.all(promises.map(function (promise) {
|
|
317
|
-
return promise.then(function (value) {
|
|
318
|
-
return (
|
|
319
|
-
/** @type {FulfilledPromise} */
|
|
320
|
-
{
|
|
321
|
-
status: 'fulfilled',
|
|
322
|
-
value: value
|
|
323
|
-
}
|
|
324
|
-
);
|
|
325
|
-
}).catch(function (
|
|
326
|
-
/** @type {Error} */
|
|
327
|
-
reason) {
|
|
328
|
-
return (
|
|
329
|
-
/** @type {RejectedPromise} */
|
|
330
|
-
{
|
|
331
|
-
status: 'rejected',
|
|
332
|
-
reason: reason
|
|
333
|
-
}
|
|
334
|
-
);
|
|
335
|
-
});
|
|
336
|
-
}));
|
|
337
|
-
};
|
|
291
|
+
exports.replicateOnce = replicateOnce;
|
package/dist/startReplication.js
CHANGED
|
@@ -101,7 +101,12 @@ var startReplication = function startReplication(pouch, replicationOptions, getR
|
|
|
101
101
|
while (1) {
|
|
102
102
|
switch (_context.prev = _context.next) {
|
|
103
103
|
case 0:
|
|
104
|
-
|
|
104
|
+
// For the first remote->local replication, we manually replicate all docs
|
|
105
|
+
// as it avoids to replicate all revs history, which can lead to
|
|
106
|
+
// performances issues
|
|
107
|
+
_logger.default.info("PouchManager: Start first replication for ".concat(doctype));
|
|
108
|
+
|
|
109
|
+
_context.next = 3;
|
|
105
110
|
return replicateAllDocs({
|
|
106
111
|
db: pouch,
|
|
107
112
|
baseUrl: url,
|
|
@@ -109,8 +114,11 @@ var startReplication = function startReplication(pouch, replicationOptions, getR
|
|
|
109
114
|
storage: storage
|
|
110
115
|
});
|
|
111
116
|
|
|
112
|
-
case
|
|
117
|
+
case 3:
|
|
113
118
|
docs = _context.sent;
|
|
119
|
+
|
|
120
|
+
_logger.default.info("PouchManager: End first replication for ".concat(doctype));
|
|
121
|
+
|
|
114
122
|
end = new Date();
|
|
115
123
|
|
|
116
124
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -119,7 +127,7 @@ var startReplication = function startReplication(pouch, replicationOptions, getR
|
|
|
119
127
|
|
|
120
128
|
return _context.abrupt("return", resolve(docs));
|
|
121
129
|
|
|
122
|
-
case
|
|
130
|
+
case 8:
|
|
123
131
|
case "end":
|
|
124
132
|
return _context.stop();
|
|
125
133
|
}
|
package/dist/utils.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.formatAggregatedError = exports.getPrefix = exports.getDatabaseName = void 0;
|
|
6
|
+
exports.allSettled = exports.formatAggregatedError = exports.getPrefix = exports.getDatabaseName = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Get the database name based on prefix and doctype
|
|
@@ -38,5 +38,60 @@ var formatAggregatedError = function formatAggregatedError(aggregatedError) {
|
|
|
38
38
|
});
|
|
39
39
|
return strings.join('\n');
|
|
40
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {object} FulfilledPromise
|
|
43
|
+
* @property {'fulfilled'} status - The status of the promise
|
|
44
|
+
* @property {undefined} reason - The Error rejected by the promise (undefined when fulfilled)
|
|
45
|
+
* @property {any} value - The resolved value of the promise
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {object} RejectedPromise
|
|
50
|
+
* @property {'rejected'} status - The status of the promise
|
|
51
|
+
* @property {Error} reason - The Error rejected by the promise
|
|
52
|
+
* @property {undefined} value - The resolved value of the promise (undefined when rejected)
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Takes an iterable of promises as input and returns a single Promise.
|
|
57
|
+
* This returned promise fulfills when all of the input's promises settle (including
|
|
58
|
+
* when an empty iterable is passed), with an array of objects that describe the
|
|
59
|
+
* outcome of each promise.
|
|
60
|
+
* This implementation is useful for env with no support of the native Promise.allSettled,
|
|
61
|
+
* typically react-native 0.66
|
|
62
|
+
*
|
|
63
|
+
* @param {Promise[]} promises - Promise to be awaited
|
|
64
|
+
* @returns {Promise<(FulfilledPromise|RejectedPromise)[]>}
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
exports.formatAggregatedError = formatAggregatedError;
|
|
69
|
+
|
|
70
|
+
var allSettled = function allSettled(promises) {
|
|
71
|
+
var proms = promises.filter(function (p) {
|
|
72
|
+
return !!p;
|
|
73
|
+
});
|
|
74
|
+
return Promise.all(proms.map(function (promise) {
|
|
75
|
+
return promise.then(function (value) {
|
|
76
|
+
return (
|
|
77
|
+
/** @type {FulfilledPromise} */
|
|
78
|
+
{
|
|
79
|
+
status: 'fulfilled',
|
|
80
|
+
value: value
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
}).catch(function (
|
|
84
|
+
/** @type {Error} */
|
|
85
|
+
reason) {
|
|
86
|
+
return (
|
|
87
|
+
/** @type {RejectedPromise} */
|
|
88
|
+
{
|
|
89
|
+
status: 'rejected',
|
|
90
|
+
reason: reason
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
}));
|
|
95
|
+
};
|
|
41
96
|
|
|
42
|
-
exports.
|
|
97
|
+
exports.allSettled = allSettled;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-pouch-link",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "50.1.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": "^50.1.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": "eabd164250195c878b7f40fb22c41e8b89503ea2"
|
|
43
43
|
}
|
package/types/PouchManager.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ declare class PouchManager {
|
|
|
37
37
|
replications: import('./types').CancelablePromise[];
|
|
38
38
|
addListeners(): void;
|
|
39
39
|
removeListeners(): void;
|
|
40
|
-
destroy(): Promise<
|
|
40
|
+
destroy(): Promise<(import("./utils").FulfilledPromise | import("./utils").RejectedPromise)[]>;
|
|
41
41
|
/**
|
|
42
42
|
* Via a call to info() we ensure the database exist on the
|
|
43
43
|
* remote side. This is done only once since after the first
|
package/types/files.d.ts
ADDED
|
File without changes
|
package/types/localStorage.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export namespace LOCALSTORAGE_STORAGE_KEYS {
|
|
2
|
+
const SYNCED: string;
|
|
3
|
+
const WARMUPEDQUERIES: string;
|
|
4
|
+
const LASTSEQUENCES: string;
|
|
5
|
+
const LASTREPLICATEDDOCID: string;
|
|
6
|
+
const ADAPTERNAME: string;
|
|
7
|
+
}
|
|
6
8
|
export class PouchLocalStorage {
|
|
7
9
|
constructor(storageEngine: any);
|
|
8
10
|
storageEngine: any;
|
|
11
|
+
/**
|
|
12
|
+
* Destroy the storage data
|
|
13
|
+
*
|
|
14
|
+
* @returns {Promise<void>}
|
|
15
|
+
*/
|
|
16
|
+
destroy(): Promise<void>;
|
|
9
17
|
/**
|
|
10
18
|
* Persist the last replicated doc id for a doctype
|
|
11
19
|
*
|
package/types/platformWeb.d.ts
CHANGED
|
@@ -5,13 +5,18 @@ export namespace platformWeb {
|
|
|
5
5
|
export { isOnline };
|
|
6
6
|
}
|
|
7
7
|
declare namespace storage {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export { getItem };
|
|
9
|
+
export { setItem };
|
|
10
|
+
export { removeItem };
|
|
11
|
+
export { destroy };
|
|
11
12
|
}
|
|
12
13
|
declare namespace events {
|
|
13
14
|
function addEventListener(eventName: any, handler: any): void;
|
|
14
15
|
function removeEventListener(eventName: any, handler: any): void;
|
|
15
16
|
}
|
|
16
17
|
declare function isOnline(): Promise<boolean>;
|
|
18
|
+
declare function getItem(key: any): Promise<string>;
|
|
19
|
+
declare function setItem(key: any, value: any): Promise<void>;
|
|
20
|
+
declare function removeItem(key: any): Promise<void>;
|
|
21
|
+
declare function destroy(): Promise<void>;
|
|
17
22
|
export {};
|
package/types/replicateOnce.d.ts
CHANGED
|
@@ -1,29 +1 @@
|
|
|
1
1
|
export function replicateOnce(pouchManager: import('./PouchManager').default): Promise<any>;
|
|
2
|
-
export type FulfilledPromise = {
|
|
3
|
-
/**
|
|
4
|
-
* - The status of the promise
|
|
5
|
-
*/
|
|
6
|
-
status: 'fulfilled';
|
|
7
|
-
/**
|
|
8
|
-
* - The Error rejected by the promise (undefined when fulfilled)
|
|
9
|
-
*/
|
|
10
|
-
reason: undefined;
|
|
11
|
-
/**
|
|
12
|
-
* - The resolved value of the promise
|
|
13
|
-
*/
|
|
14
|
-
value: any;
|
|
15
|
-
};
|
|
16
|
-
export type RejectedPromise = {
|
|
17
|
-
/**
|
|
18
|
-
* - The status of the promise
|
|
19
|
-
*/
|
|
20
|
-
status: 'rejected';
|
|
21
|
-
/**
|
|
22
|
-
* - The Error rejected by the promise
|
|
23
|
-
*/
|
|
24
|
-
reason: Error;
|
|
25
|
-
/**
|
|
26
|
-
* - The resolved value of the promise (undefined when rejected)
|
|
27
|
-
*/
|
|
28
|
-
value: undefined;
|
|
29
|
-
};
|
package/types/utils.d.ts
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
1
|
export function getDatabaseName(prefix: string, doctype: string): string;
|
|
2
2
|
export function getPrefix(uri: string): string;
|
|
3
3
|
export function formatAggregatedError(aggregatedError: any): any;
|
|
4
|
+
export function allSettled(promises: Promise<any>[]): Promise<(FulfilledPromise | RejectedPromise)[]>;
|
|
5
|
+
export type FulfilledPromise = {
|
|
6
|
+
/**
|
|
7
|
+
* - The status of the promise
|
|
8
|
+
*/
|
|
9
|
+
status: 'fulfilled';
|
|
10
|
+
/**
|
|
11
|
+
* - The Error rejected by the promise (undefined when fulfilled)
|
|
12
|
+
*/
|
|
13
|
+
reason: undefined;
|
|
14
|
+
/**
|
|
15
|
+
* - The resolved value of the promise
|
|
16
|
+
*/
|
|
17
|
+
value: any;
|
|
18
|
+
};
|
|
19
|
+
export type RejectedPromise = {
|
|
20
|
+
/**
|
|
21
|
+
* - The status of the promise
|
|
22
|
+
*/
|
|
23
|
+
status: 'rejected';
|
|
24
|
+
/**
|
|
25
|
+
* - The Error rejected by the promise
|
|
26
|
+
*/
|
|
27
|
+
reason: Error;
|
|
28
|
+
/**
|
|
29
|
+
* - The resolved value of the promise (undefined when rejected)
|
|
30
|
+
*/
|
|
31
|
+
value: undefined;
|
|
32
|
+
};
|