cozy-pouch-link 48.24.1 → 49.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.
Files changed (41) hide show
  1. package/dist/CozyPouchLink.js +593 -237
  2. package/dist/CozyPouchLink.spec.js +67 -42
  3. package/dist/PouchManager.js +317 -254
  4. package/dist/PouchManager.spec.js +91 -58
  5. package/dist/helpers.js +79 -0
  6. package/dist/helpers.spec.js +85 -1
  7. package/dist/jsonapi.js +54 -7
  8. package/dist/jsonapi.spec.js +57 -14
  9. package/dist/localStorage.js +646 -207
  10. package/dist/localStorage.spec.js +48 -0
  11. package/dist/mango.js +72 -20
  12. package/dist/mango.spec.js +1 -1
  13. package/dist/migrations/adapter.js +1 -1
  14. package/dist/platformWeb.js +120 -0
  15. package/dist/remote.js +39 -5
  16. package/dist/remote.spec.js +214 -0
  17. package/dist/replicateOnce.js +337 -0
  18. package/dist/startReplication.js +70 -45
  19. package/dist/startReplication.spec.js +374 -39
  20. package/dist/types.js +80 -0
  21. package/dist/utils.js +11 -2
  22. package/package.json +9 -5
  23. package/types/AccessToken.d.ts +16 -0
  24. package/types/CozyPouchLink.d.ts +228 -0
  25. package/types/PouchManager.d.ts +86 -0
  26. package/types/__tests__/fixtures.d.ts +48 -0
  27. package/types/__tests__/mocks.d.ts +4 -0
  28. package/types/helpers.d.ts +17 -0
  29. package/types/index.d.ts +1 -0
  30. package/types/jsonapi.d.ts +19 -0
  31. package/types/localStorage.d.ts +124 -0
  32. package/types/logger.d.ts +2 -0
  33. package/types/loop.d.ts +60 -0
  34. package/types/mango.d.ts +3 -0
  35. package/types/migrations/adapter.d.ts +18 -0
  36. package/types/platformWeb.d.ts +17 -0
  37. package/types/remote.d.ts +6 -0
  38. package/types/replicateOnce.d.ts +29 -0
  39. package/types/startReplication.d.ts +12 -0
  40. package/types/types.d.ts +104 -0
  41. package/types/utils.d.ts +3 -0
@@ -1,9 +1,20 @@
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
- exports.persistAdapterName = exports.getAdapterName = exports.destroyWarmedUpQueries = exports.getPersistedWarmedUpQueries = exports.persistWarmedUpQueries = exports.destroyDoctypeLastSequence = exports.destroyAllDoctypeLastSequence = exports.getDoctypeLastSequence = exports.getAllLastSequences = exports.persistDoctypeLastSequence = exports.destroySyncedDoctypes = exports.getPersistedSyncedDoctypes = exports.persistSyncedDoctypes = exports.destroyAllLastReplicatedDocID = exports.getLastReplicatedDocID = exports.getAllLastReplicatedDocID = exports.persistLastReplicatedDocID = exports.LOCALSTORAGE_ADAPTERNAME = exports.LOCALSTORAGE_LASTREPLICATEDDOCID_KEY = exports.LOCALSTORAGE_LASTSEQUENCES_KEY = exports.LOCALSTORAGE_WARMUPEDQUERIES_KEY = exports.LOCALSTORAGE_SYNCED_KEY = void 0;
8
+ exports.PouchLocalStorage = exports.LOCALSTORAGE_ADAPTERNAME = exports.LOCALSTORAGE_LASTREPLICATEDDOCID_KEY = exports.LOCALSTORAGE_LASTSEQUENCES_KEY = exports.LOCALSTORAGE_WARMUPEDQUERIES_KEY = exports.LOCALSTORAGE_SYNCED_KEY = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
7
18
  var LOCALSTORAGE_SYNCED_KEY = 'cozy-client-pouch-link-synced';
8
19
  exports.LOCALSTORAGE_SYNCED_KEY = LOCALSTORAGE_SYNCED_KEY;
9
20
  var LOCALSTORAGE_WARMUPEDQUERIES_KEY = 'cozy-client-pouch-link-warmupedqueries';
@@ -13,220 +24,648 @@ exports.LOCALSTORAGE_LASTSEQUENCES_KEY = LOCALSTORAGE_LASTSEQUENCES_KEY;
13
24
  var LOCALSTORAGE_LASTREPLICATEDDOCID_KEY = 'cozy-client-pouch-link-lastreplicateddocid';
14
25
  exports.LOCALSTORAGE_LASTREPLICATEDDOCID_KEY = LOCALSTORAGE_LASTREPLICATEDDOCID_KEY;
15
26
  var LOCALSTORAGE_ADAPTERNAME = 'cozy-client-pouch-link-adaptername';
16
- /**
17
- * Persist the last replicated doc id for a doctype
18
- *
19
- * @param {string} doctype - The replicated doctype
20
- * @param {string} id - The docid
21
- */
22
-
23
27
  exports.LOCALSTORAGE_ADAPTERNAME = LOCALSTORAGE_ADAPTERNAME;
24
28
 
25
- var persistLastReplicatedDocID = function persistLastReplicatedDocID(doctype, id) {
26
- var docids = getAllLastReplicatedDocID();
27
- docids[doctype] = id;
28
- window.localStorage.setItem(LOCALSTORAGE_LASTREPLICATEDDOCID_KEY, JSON.stringify(docids));
29
- };
30
-
31
- exports.persistLastReplicatedDocID = persistLastReplicatedDocID;
32
-
33
- var getAllLastReplicatedDocID = function getAllLastReplicatedDocID() {
34
- var item = window.localStorage.getItem(LOCALSTORAGE_LASTREPLICATEDDOCID_KEY);
35
- return item ? JSON.parse(item) : {};
36
- };
37
- /**
38
- * Get the last replicated doc id for a doctype
39
- *
40
- * @param {string} doctype - The doctype
41
- * @returns {string} The last replicated docid
42
- */
43
-
44
-
45
- exports.getAllLastReplicatedDocID = getAllLastReplicatedDocID;
46
-
47
- var getLastReplicatedDocID = function getLastReplicatedDocID(doctype) {
48
- var docids = getAllLastSequences();
49
- return docids[doctype];
50
- };
51
- /**
52
- * Destroy all the replicated doc id
53
- */
54
-
55
-
56
- exports.getLastReplicatedDocID = getLastReplicatedDocID;
57
-
58
- var destroyAllLastReplicatedDocID = function destroyAllLastReplicatedDocID() {
59
- window.localStorage.removeItem(LOCALSTORAGE_LASTREPLICATEDDOCID_KEY);
60
- };
61
- /**
62
- * Persist the synchronized doctypes
63
- *
64
- * @typedef {object} SyncInfo
65
- * @property {string} Date
66
- *
67
- * @param {Record<string, SyncInfo>} syncedDoctypes - The sync doctypes
68
- */
69
-
70
-
71
- exports.destroyAllLastReplicatedDocID = destroyAllLastReplicatedDocID;
72
-
73
- var persistSyncedDoctypes = function persistSyncedDoctypes(syncedDoctypes) {
74
- window.localStorage.setItem(LOCALSTORAGE_SYNCED_KEY, JSON.stringify(syncedDoctypes));
75
- };
76
- /**
77
- * Get the persisted doctypes
78
- *
79
- * @returns {object} The synced doctypes
80
- */
81
-
82
-
83
- exports.persistSyncedDoctypes = persistSyncedDoctypes;
84
-
85
- var getPersistedSyncedDoctypes = function getPersistedSyncedDoctypes() {
86
- var item = window.localStorage.getItem(LOCALSTORAGE_SYNCED_KEY);
87
- var parsed = item ? JSON.parse(item) : {};
88
-
89
- if (typeof parsed !== 'object') {
90
- return {};
29
+ var PouchLocalStorage = /*#__PURE__*/function () {
30
+ function PouchLocalStorage(storageEngine) {
31
+ (0, _classCallCheck2.default)(this, PouchLocalStorage);
32
+ checkStorageEngine(storageEngine);
33
+ this.storageEngine = storageEngine;
91
34
  }
92
-
93
- return parsed;
94
- };
95
- /**
96
- * Destroy the synced doctypes
97
- *
98
- */
99
-
100
-
101
- exports.getPersistedSyncedDoctypes = getPersistedSyncedDoctypes;
102
-
103
- var destroySyncedDoctypes = function destroySyncedDoctypes() {
104
- window.localStorage.removeItem(LOCALSTORAGE_SYNCED_KEY);
105
- };
35
+ /**
36
+ * Persist the last replicated doc id for a doctype
37
+ *
38
+ * @param {string} doctype - The replicated doctype
39
+ * @param {string} id - The docid
40
+ *
41
+ * @returns {Promise<void>}
42
+ */
43
+
44
+
45
+ (0, _createClass2.default)(PouchLocalStorage, [{
46
+ key: "persistLastReplicatedDocID",
47
+ value: function () {
48
+ var _persistLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(doctype, id) {
49
+ var docids;
50
+ return _regenerator.default.wrap(function _callee$(_context) {
51
+ while (1) {
52
+ switch (_context.prev = _context.next) {
53
+ case 0:
54
+ _context.next = 2;
55
+ return this.getAllLastReplicatedDocID();
56
+
57
+ case 2:
58
+ docids = _context.sent;
59
+ docids[doctype] = id;
60
+ _context.next = 6;
61
+ return this.storageEngine.setItem(LOCALSTORAGE_LASTREPLICATEDDOCID_KEY, JSON.stringify(docids));
62
+
63
+ case 6:
64
+ case "end":
65
+ return _context.stop();
66
+ }
67
+ }
68
+ }, _callee, this);
69
+ }));
70
+
71
+ function persistLastReplicatedDocID(_x, _x2) {
72
+ return _persistLastReplicatedDocID.apply(this, arguments);
73
+ }
74
+
75
+ return persistLastReplicatedDocID;
76
+ }()
77
+ /**
78
+ * @returns {Promise<Record<string, string>>}
79
+ */
80
+
81
+ }, {
82
+ key: "getAllLastReplicatedDocID",
83
+ value: function () {
84
+ var _getAllLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
85
+ var item;
86
+ return _regenerator.default.wrap(function _callee2$(_context2) {
87
+ while (1) {
88
+ switch (_context2.prev = _context2.next) {
89
+ case 0:
90
+ _context2.next = 2;
91
+ return this.storageEngine.getItem(LOCALSTORAGE_LASTREPLICATEDDOCID_KEY);
92
+
93
+ case 2:
94
+ item = _context2.sent;
95
+ return _context2.abrupt("return", item ? JSON.parse(item) : {});
96
+
97
+ case 4:
98
+ case "end":
99
+ return _context2.stop();
100
+ }
101
+ }
102
+ }, _callee2, this);
103
+ }));
104
+
105
+ function getAllLastReplicatedDocID() {
106
+ return _getAllLastReplicatedDocID.apply(this, arguments);
107
+ }
108
+
109
+ return getAllLastReplicatedDocID;
110
+ }()
111
+ /**
112
+ * Get the last replicated doc id for a doctype
113
+ *
114
+ * @param {string} doctype - The doctype
115
+ * @returns {Promise<string>} The last replicated docid
116
+ */
117
+
118
+ }, {
119
+ key: "getLastReplicatedDocID",
120
+ value: function () {
121
+ var _getLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(doctype) {
122
+ var docids;
123
+ return _regenerator.default.wrap(function _callee3$(_context3) {
124
+ while (1) {
125
+ switch (_context3.prev = _context3.next) {
126
+ case 0:
127
+ _context3.next = 2;
128
+ return this.getAllLastReplicatedDocID();
129
+
130
+ case 2:
131
+ docids = _context3.sent;
132
+ return _context3.abrupt("return", docids[doctype]);
133
+
134
+ case 4:
135
+ case "end":
136
+ return _context3.stop();
137
+ }
138
+ }
139
+ }, _callee3, this);
140
+ }));
141
+
142
+ function getLastReplicatedDocID(_x3) {
143
+ return _getLastReplicatedDocID.apply(this, arguments);
144
+ }
145
+
146
+ return getLastReplicatedDocID;
147
+ }()
148
+ /**
149
+ * Destroy all the replicated doc id
150
+ *
151
+ * @returns {Promise<void>}
152
+ */
153
+
154
+ }, {
155
+ key: "destroyAllLastReplicatedDocID",
156
+ value: function () {
157
+ var _destroyAllLastReplicatedDocID = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
158
+ return _regenerator.default.wrap(function _callee4$(_context4) {
159
+ while (1) {
160
+ switch (_context4.prev = _context4.next) {
161
+ case 0:
162
+ _context4.next = 2;
163
+ return this.storageEngine.removeItem(LOCALSTORAGE_LASTREPLICATEDDOCID_KEY);
164
+
165
+ case 2:
166
+ case "end":
167
+ return _context4.stop();
168
+ }
169
+ }
170
+ }, _callee4, this);
171
+ }));
172
+
173
+ function destroyAllLastReplicatedDocID() {
174
+ return _destroyAllLastReplicatedDocID.apply(this, arguments);
175
+ }
176
+
177
+ return destroyAllLastReplicatedDocID;
178
+ }()
179
+ /**
180
+ * Persist the synchronized doctypes
181
+ *
182
+ * @param {Record<string, import("./types").SyncInfo>} syncedDoctypes - The sync doctypes
183
+ *
184
+ * @returns {Promise<void>}
185
+ */
186
+
187
+ }, {
188
+ key: "persistSyncedDoctypes",
189
+ value: function () {
190
+ var _persistSyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(syncedDoctypes) {
191
+ return _regenerator.default.wrap(function _callee5$(_context5) {
192
+ while (1) {
193
+ switch (_context5.prev = _context5.next) {
194
+ case 0:
195
+ _context5.next = 2;
196
+ return this.storageEngine.setItem(LOCALSTORAGE_SYNCED_KEY, JSON.stringify(syncedDoctypes));
197
+
198
+ case 2:
199
+ case "end":
200
+ return _context5.stop();
201
+ }
202
+ }
203
+ }, _callee5, this);
204
+ }));
205
+
206
+ function persistSyncedDoctypes(_x4) {
207
+ return _persistSyncedDoctypes.apply(this, arguments);
208
+ }
209
+
210
+ return persistSyncedDoctypes;
211
+ }()
212
+ /**
213
+ * Get the persisted doctypes
214
+ *
215
+ * @returns {Promise<object>} The synced doctypes
216
+ */
217
+
218
+ }, {
219
+ key: "getPersistedSyncedDoctypes",
220
+ value: function () {
221
+ var _getPersistedSyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
222
+ var item, parsed;
223
+ return _regenerator.default.wrap(function _callee6$(_context6) {
224
+ while (1) {
225
+ switch (_context6.prev = _context6.next) {
226
+ case 0:
227
+ _context6.next = 2;
228
+ return this.storageEngine.getItem(LOCALSTORAGE_SYNCED_KEY);
229
+
230
+ case 2:
231
+ item = _context6.sent;
232
+ parsed = item ? JSON.parse(item) : {};
233
+
234
+ if (!(typeof parsed !== 'object')) {
235
+ _context6.next = 6;
236
+ break;
237
+ }
238
+
239
+ return _context6.abrupt("return", {});
240
+
241
+ case 6:
242
+ return _context6.abrupt("return", parsed);
243
+
244
+ case 7:
245
+ case "end":
246
+ return _context6.stop();
247
+ }
248
+ }
249
+ }, _callee6, this);
250
+ }));
251
+
252
+ function getPersistedSyncedDoctypes() {
253
+ return _getPersistedSyncedDoctypes.apply(this, arguments);
254
+ }
255
+
256
+ return getPersistedSyncedDoctypes;
257
+ }()
258
+ /**
259
+ * Destroy the synced doctypes
260
+ *
261
+ * @returns {Promise<void>}
262
+ */
263
+
264
+ }, {
265
+ key: "destroySyncedDoctypes",
266
+ value: function () {
267
+ var _destroySyncedDoctypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() {
268
+ return _regenerator.default.wrap(function _callee7$(_context7) {
269
+ while (1) {
270
+ switch (_context7.prev = _context7.next) {
271
+ case 0:
272
+ _context7.next = 2;
273
+ return this.storageEngine.removeItem(LOCALSTORAGE_SYNCED_KEY);
274
+
275
+ case 2:
276
+ case "end":
277
+ return _context7.stop();
278
+ }
279
+ }
280
+ }, _callee7, this);
281
+ }));
282
+
283
+ function destroySyncedDoctypes() {
284
+ return _destroySyncedDoctypes.apply(this, arguments);
285
+ }
286
+
287
+ return destroySyncedDoctypes;
288
+ }()
289
+ /**
290
+ * Persist the last CouchDB sequence for a synced doctype
291
+ *
292
+ * @param {string} doctype - The synced doctype
293
+ * @param {string} sequence - The sequence hash
294
+ *
295
+ * @returns {Promise<void>}
296
+ */
297
+
298
+ }, {
299
+ key: "persistDoctypeLastSequence",
300
+ value: function () {
301
+ var _persistDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(doctype, sequence) {
302
+ var seqs;
303
+ return _regenerator.default.wrap(function _callee8$(_context8) {
304
+ while (1) {
305
+ switch (_context8.prev = _context8.next) {
306
+ case 0:
307
+ _context8.next = 2;
308
+ return this.getAllLastSequences();
309
+
310
+ case 2:
311
+ seqs = _context8.sent;
312
+ seqs[doctype] = sequence;
313
+ _context8.next = 6;
314
+ return this.storageEngine.setItem(LOCALSTORAGE_LASTSEQUENCES_KEY, JSON.stringify(seqs));
315
+
316
+ case 6:
317
+ case "end":
318
+ return _context8.stop();
319
+ }
320
+ }
321
+ }, _callee8, this);
322
+ }));
323
+
324
+ function persistDoctypeLastSequence(_x5, _x6) {
325
+ return _persistDoctypeLastSequence.apply(this, arguments);
326
+ }
327
+
328
+ return persistDoctypeLastSequence;
329
+ }()
330
+ /**
331
+ * @returns {Promise<object>}
332
+ */
333
+
334
+ }, {
335
+ key: "getAllLastSequences",
336
+ value: function () {
337
+ var _getAllLastSequences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9() {
338
+ var item;
339
+ return _regenerator.default.wrap(function _callee9$(_context9) {
340
+ while (1) {
341
+ switch (_context9.prev = _context9.next) {
342
+ case 0:
343
+ _context9.next = 2;
344
+ return this.storageEngine.getItem(LOCALSTORAGE_LASTSEQUENCES_KEY);
345
+
346
+ case 2:
347
+ item = _context9.sent;
348
+ return _context9.abrupt("return", item ? JSON.parse(item) : {});
349
+
350
+ case 4:
351
+ case "end":
352
+ return _context9.stop();
353
+ }
354
+ }
355
+ }, _callee9, this);
356
+ }));
357
+
358
+ function getAllLastSequences() {
359
+ return _getAllLastSequences.apply(this, arguments);
360
+ }
361
+
362
+ return getAllLastSequences;
363
+ }()
364
+ /**
365
+ * Get the last CouchDB sequence for a doctype
366
+ *
367
+ * @param {string} doctype - The doctype
368
+ *
369
+ * @returns {Promise<string>} the last sequence
370
+ */
371
+
372
+ }, {
373
+ key: "getDoctypeLastSequence",
374
+ value: function () {
375
+ var _getDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(doctype) {
376
+ var seqs;
377
+ return _regenerator.default.wrap(function _callee10$(_context10) {
378
+ while (1) {
379
+ switch (_context10.prev = _context10.next) {
380
+ case 0:
381
+ _context10.next = 2;
382
+ return this.getAllLastSequences();
383
+
384
+ case 2:
385
+ seqs = _context10.sent;
386
+ return _context10.abrupt("return", seqs[doctype]);
387
+
388
+ case 4:
389
+ case "end":
390
+ return _context10.stop();
391
+ }
392
+ }
393
+ }, _callee10, this);
394
+ }));
395
+
396
+ function getDoctypeLastSequence(_x7) {
397
+ return _getDoctypeLastSequence.apply(this, arguments);
398
+ }
399
+
400
+ return getDoctypeLastSequence;
401
+ }()
402
+ /**
403
+ * Destroy all the last sequence
404
+ *
405
+ * @returns {Promise<void>}
406
+ */
407
+
408
+ }, {
409
+ key: "destroyAllDoctypeLastSequence",
410
+ value: function () {
411
+ var _destroyAllDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11() {
412
+ return _regenerator.default.wrap(function _callee11$(_context11) {
413
+ while (1) {
414
+ switch (_context11.prev = _context11.next) {
415
+ case 0:
416
+ _context11.next = 2;
417
+ return this.storageEngine.removeItem(LOCALSTORAGE_LASTSEQUENCES_KEY);
418
+
419
+ case 2:
420
+ case "end":
421
+ return _context11.stop();
422
+ }
423
+ }
424
+ }, _callee11, this);
425
+ }));
426
+
427
+ function destroyAllDoctypeLastSequence() {
428
+ return _destroyAllDoctypeLastSequence.apply(this, arguments);
429
+ }
430
+
431
+ return destroyAllDoctypeLastSequence;
432
+ }()
433
+ /**
434
+ * Destroy the last sequence for a doctype
435
+ *
436
+ * @param {string} doctype - The doctype
437
+ *
438
+ * @returns {Promise<void>}
439
+ */
440
+
441
+ }, {
442
+ key: "destroyDoctypeLastSequence",
443
+ value: function () {
444
+ var _destroyDoctypeLastSequence = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(doctype) {
445
+ var seqs;
446
+ return _regenerator.default.wrap(function _callee12$(_context12) {
447
+ while (1) {
448
+ switch (_context12.prev = _context12.next) {
449
+ case 0:
450
+ _context12.next = 2;
451
+ return this.getAllLastSequences();
452
+
453
+ case 2:
454
+ seqs = _context12.sent;
455
+ delete seqs[doctype];
456
+ _context12.next = 6;
457
+ return this.storageEngine.setItem(LOCALSTORAGE_LASTSEQUENCES_KEY, JSON.stringify(seqs));
458
+
459
+ case 6:
460
+ case "end":
461
+ return _context12.stop();
462
+ }
463
+ }
464
+ }, _callee12, this);
465
+ }));
466
+
467
+ function destroyDoctypeLastSequence(_x8) {
468
+ return _destroyDoctypeLastSequence.apply(this, arguments);
469
+ }
470
+
471
+ return destroyDoctypeLastSequence;
472
+ }()
473
+ /**
474
+ * Persist the warmed up queries
475
+ *
476
+ * @param {object} warmedUpQueries - The warmedup queries
477
+ *
478
+ * @returns {Promise<void>}
479
+ */
480
+
481
+ }, {
482
+ key: "persistWarmedUpQueries",
483
+ value: function () {
484
+ var _persistWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(warmedUpQueries) {
485
+ return _regenerator.default.wrap(function _callee13$(_context13) {
486
+ while (1) {
487
+ switch (_context13.prev = _context13.next) {
488
+ case 0:
489
+ _context13.next = 2;
490
+ return this.storageEngine.setItem(LOCALSTORAGE_WARMUPEDQUERIES_KEY, JSON.stringify(warmedUpQueries));
491
+
492
+ case 2:
493
+ case "end":
494
+ return _context13.stop();
495
+ }
496
+ }
497
+ }, _callee13, this);
498
+ }));
499
+
500
+ function persistWarmedUpQueries(_x9) {
501
+ return _persistWarmedUpQueries.apply(this, arguments);
502
+ }
503
+
504
+ return persistWarmedUpQueries;
505
+ }()
506
+ /**
507
+ * Get the warmed up queries
508
+ *
509
+ * @returns {Promise<object>} the warmed up queries
510
+ */
511
+
512
+ }, {
513
+ key: "getPersistedWarmedUpQueries",
514
+ value: function () {
515
+ var _getPersistedWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14() {
516
+ var item;
517
+ return _regenerator.default.wrap(function _callee14$(_context14) {
518
+ while (1) {
519
+ switch (_context14.prev = _context14.next) {
520
+ case 0:
521
+ _context14.next = 2;
522
+ return this.storageEngine.getItem(LOCALSTORAGE_WARMUPEDQUERIES_KEY);
523
+
524
+ case 2:
525
+ item = _context14.sent;
526
+
527
+ if (item) {
528
+ _context14.next = 5;
529
+ break;
530
+ }
531
+
532
+ return _context14.abrupt("return", {});
533
+
534
+ case 5:
535
+ return _context14.abrupt("return", JSON.parse(item));
536
+
537
+ case 6:
538
+ case "end":
539
+ return _context14.stop();
540
+ }
541
+ }
542
+ }, _callee14, this);
543
+ }));
544
+
545
+ function getPersistedWarmedUpQueries() {
546
+ return _getPersistedWarmedUpQueries.apply(this, arguments);
547
+ }
548
+
549
+ return getPersistedWarmedUpQueries;
550
+ }()
551
+ /**
552
+ * Destroy the warmed queries
553
+ *
554
+ * @returns {Promise<void>}
555
+ */
556
+
557
+ }, {
558
+ key: "destroyWarmedUpQueries",
559
+ value: function () {
560
+ var _destroyWarmedUpQueries = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15() {
561
+ return _regenerator.default.wrap(function _callee15$(_context15) {
562
+ while (1) {
563
+ switch (_context15.prev = _context15.next) {
564
+ case 0:
565
+ _context15.next = 2;
566
+ return this.storageEngine.removeItem(LOCALSTORAGE_WARMUPEDQUERIES_KEY);
567
+
568
+ case 2:
569
+ case "end":
570
+ return _context15.stop();
571
+ }
572
+ }
573
+ }, _callee15, this);
574
+ }));
575
+
576
+ function destroyWarmedUpQueries() {
577
+ return _destroyWarmedUpQueries.apply(this, arguments);
578
+ }
579
+
580
+ return destroyWarmedUpQueries;
581
+ }()
582
+ /**
583
+ * Get the adapter name
584
+ *
585
+ * @returns {Promise<string>} The adapter name
586
+ */
587
+
588
+ }, {
589
+ key: "getAdapterName",
590
+ value: function () {
591
+ var _getAdapterName = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16() {
592
+ return _regenerator.default.wrap(function _callee16$(_context16) {
593
+ while (1) {
594
+ switch (_context16.prev = _context16.next) {
595
+ case 0:
596
+ _context16.next = 2;
597
+ return this.storageEngine.getItem(LOCALSTORAGE_ADAPTERNAME);
598
+
599
+ case 2:
600
+ return _context16.abrupt("return", _context16.sent);
601
+
602
+ case 3:
603
+ case "end":
604
+ return _context16.stop();
605
+ }
606
+ }
607
+ }, _callee16, this);
608
+ }));
609
+
610
+ function getAdapterName() {
611
+ return _getAdapterName.apply(this, arguments);
612
+ }
613
+
614
+ return getAdapterName;
615
+ }()
616
+ /**
617
+ * Persist the adapter name
618
+ *
619
+ * @param {string} adapter - The adapter name
620
+ *
621
+ * @returns {Promise<void>}
622
+ */
623
+
624
+ }, {
625
+ key: "persistAdapterName",
626
+ value: function () {
627
+ var _persistAdapterName = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17(adapter) {
628
+ return _regenerator.default.wrap(function _callee17$(_context17) {
629
+ while (1) {
630
+ switch (_context17.prev = _context17.next) {
631
+ case 0:
632
+ _context17.next = 2;
633
+ return this.storageEngine.setItem(LOCALSTORAGE_ADAPTERNAME, adapter);
634
+
635
+ case 2:
636
+ case "end":
637
+ return _context17.stop();
638
+ }
639
+ }
640
+ }, _callee17, this);
641
+ }));
642
+
643
+ function persistAdapterName(_x10) {
644
+ return _persistAdapterName.apply(this, arguments);
645
+ }
646
+
647
+ return persistAdapterName;
648
+ }()
649
+ }]);
650
+ return PouchLocalStorage;
651
+ }();
106
652
  /**
107
- * Persist the last CouchDB sequence for a synced doctype
653
+ * Throw if the given storage engine does not implement the expected Interface
108
654
  *
109
- * @param {string} doctype - The synced doctype
110
- * @param {string} sequence - The sequence hash
655
+ * @param {*} storageEngine - Object containing storage access methods
111
656
  */
112
657
 
113
658
 
114
- exports.destroySyncedDoctypes = destroySyncedDoctypes;
115
-
116
- var persistDoctypeLastSequence = function persistDoctypeLastSequence(doctype, sequence) {
117
- var seqs = getAllLastSequences();
118
- seqs[doctype] = sequence;
119
- window.localStorage.setItem(LOCALSTORAGE_LASTSEQUENCES_KEY, JSON.stringify(seqs));
120
- };
659
+ exports.PouchLocalStorage = PouchLocalStorage;
121
660
 
122
- exports.persistDoctypeLastSequence = persistDoctypeLastSequence;
661
+ var checkStorageEngine = function checkStorageEngine(storageEngine) {
662
+ var requiredMethods = ['setItem', 'getItem', 'removeItem'];
663
+ var missingMethods = requiredMethods.filter(function (requiredMethod) {
664
+ return !storageEngine[requiredMethod];
665
+ });
123
666
 
124
- var getAllLastSequences = function getAllLastSequences() {
125
- var item = window.localStorage.getItem(LOCALSTORAGE_LASTSEQUENCES_KEY);
126
- return item ? JSON.parse(item) : {};
127
- };
128
- /**
129
- * Get the last CouchDB sequence for a doctype
130
- *
131
- * @param {string} doctype - The doctype
132
- * @returns {string} the last sequence
133
- */
134
-
135
-
136
- exports.getAllLastSequences = getAllLastSequences;
137
-
138
- var getDoctypeLastSequence = function getDoctypeLastSequence(doctype) {
139
- var seqs = getAllLastSequences();
140
- return seqs[doctype];
141
- };
142
- /**
143
- * Destroy all the last sequence
144
- */
145
-
146
-
147
- exports.getDoctypeLastSequence = getDoctypeLastSequence;
148
-
149
- var destroyAllDoctypeLastSequence = function destroyAllDoctypeLastSequence() {
150
- window.localStorage.removeItem(LOCALSTORAGE_LASTSEQUENCES_KEY);
151
- };
152
- /**
153
- * Destroy the last sequence for a doctype
154
- *
155
- * @param {string} doctype - The doctype
156
- */
157
-
158
-
159
- exports.destroyAllDoctypeLastSequence = destroyAllDoctypeLastSequence;
160
-
161
- var destroyDoctypeLastSequence = function destroyDoctypeLastSequence(doctype) {
162
- var seqs = getAllLastSequences();
163
- delete seqs[doctype];
164
- window.localStorage.setItem(LOCALSTORAGE_LASTSEQUENCES_KEY, JSON.stringify(seqs));
165
- };
166
- /**
167
- * Persist the warmed up queries
168
- *
169
- * @param {object} warmedUpQueries - The warmedup queries
170
- */
171
-
172
-
173
- exports.destroyDoctypeLastSequence = destroyDoctypeLastSequence;
174
-
175
- var persistWarmedUpQueries = function persistWarmedUpQueries(warmedUpQueries) {
176
- window.localStorage.setItem(LOCALSTORAGE_WARMUPEDQUERIES_KEY, JSON.stringify(warmedUpQueries));
177
- };
178
- /**
179
- * Get the warmed up queries
180
- *
181
- * @returns {object} the warmed up queries
182
- */
183
-
184
-
185
- exports.persistWarmedUpQueries = persistWarmedUpQueries;
186
-
187
- var getPersistedWarmedUpQueries = function getPersistedWarmedUpQueries() {
188
- var item = window.localStorage.getItem(LOCALSTORAGE_WARMUPEDQUERIES_KEY);
189
-
190
- if (!item) {
191
- return {};
667
+ if (missingMethods.length > 0) {
668
+ var missingMethodsString = missingMethods.join(', ');
669
+ throw new Error("Provided storageEngine is missing the following methods: ".concat(missingMethodsString));
192
670
  }
193
-
194
- return JSON.parse(item);
195
- };
196
- /**
197
- * Destroy the warmed queries
198
- *
199
- */
200
-
201
-
202
- exports.getPersistedWarmedUpQueries = getPersistedWarmedUpQueries;
203
-
204
- var destroyWarmedUpQueries = function destroyWarmedUpQueries() {
205
- window.localStorage.removeItem(LOCALSTORAGE_WARMUPEDQUERIES_KEY);
206
- };
207
- /**
208
- * Get the adapter name
209
- *
210
- * @returns {string} The adapter name
211
- */
212
-
213
-
214
- exports.destroyWarmedUpQueries = destroyWarmedUpQueries;
215
-
216
- var getAdapterName = function getAdapterName() {
217
- return window.localStorage.getItem(LOCALSTORAGE_ADAPTERNAME);
218
- };
219
- /**
220
- * Persist the adapter name
221
- *
222
- * @param {string} adapter - The adapter name
223
- */
224
-
225
-
226
- exports.getAdapterName = getAdapterName;
227
-
228
- var persistAdapterName = function persistAdapterName(adapter) {
229
- window.localStorage.setItem(LOCALSTORAGE_ADAPTERNAME, adapter);
230
- };
231
-
232
- exports.persistAdapterName = persistAdapterName;
671
+ };