parse 5.1.0-alpha.2 → 5.1.0-alpha.4

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 (46) hide show
  1. package/README.md +13 -0
  2. package/dist/parse.js +774 -712
  3. package/dist/parse.min.js +2 -2
  4. package/dist/parse.weapp.js +760 -698
  5. package/dist/parse.weapp.min.js +2 -2
  6. package/lib/browser/CoreManager.js +1 -1
  7. package/lib/browser/LiveQueryClient.js +43 -35
  8. package/lib/browser/LiveQuerySubscription.js +15 -5
  9. package/lib/browser/LocalDatastoreController.default.js +248 -0
  10. package/lib/browser/LocalDatastoreController.js +1 -246
  11. package/lib/browser/Parse.js +18 -4
  12. package/lib/browser/ParseLiveQuery.js +32 -23
  13. package/lib/browser/Storage.js +1 -2
  14. package/lib/browser/StorageController.js +3 -0
  15. package/lib/browser/WebSocketController.js +13 -0
  16. package/lib/node/CoreManager.js +1 -1
  17. package/lib/node/LiveQueryClient.js +2 -5
  18. package/lib/node/LiveQuerySubscription.js +2 -2
  19. package/lib/node/LocalDatastoreController.default.js +67 -0
  20. package/lib/node/LocalDatastoreController.js +1 -65
  21. package/lib/node/Parse.js +18 -4
  22. package/lib/node/ParseLiveQuery.js +2 -3
  23. package/lib/node/Storage.js +1 -2
  24. package/lib/node/StorageController.js +3 -0
  25. package/lib/node/WebSocketController.js +10 -0
  26. package/lib/react-native/CoreManager.js +1 -1
  27. package/lib/react-native/LiveQueryClient.js +28 -20
  28. package/lib/react-native/LiveQuerySubscription.js +14 -5
  29. package/lib/react-native/LocalDatastoreController.default.js +91 -0
  30. package/lib/react-native/LocalDatastoreController.js +1 -91
  31. package/lib/react-native/Parse.js +14 -4
  32. package/lib/react-native/ParseLiveQuery.js +11 -2
  33. package/lib/react-native/Storage.js +1 -2
  34. package/lib/react-native/StorageController.js +1 -0
  35. package/lib/react-native/WebSocketController.js +5 -0
  36. package/lib/weapp/CoreManager.js +1 -1
  37. package/lib/weapp/LiveQueryClient.js +43 -35
  38. package/lib/weapp/LiveQuerySubscription.js +15 -5
  39. package/lib/weapp/LocalDatastoreController.default.js +248 -0
  40. package/lib/weapp/LocalDatastoreController.js +1 -246
  41. package/lib/weapp/Parse.js +18 -4
  42. package/lib/weapp/ParseLiveQuery.js +32 -23
  43. package/lib/weapp/Storage.js +1 -2
  44. package/lib/weapp/StorageController.js +3 -0
  45. package/lib/weapp/WebSocketController.js +13 -0
  46. package/package.json +1 -1
@@ -13,13 +13,13 @@ _Object$defineProperty(exports, "__esModule", {
13
13
  exports.default = void 0;
14
14
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
15
15
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/map"));
16
+ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
16
17
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/keys"));
17
18
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
18
19
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
19
20
  var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/values"));
20
21
  var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
21
22
  var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
22
- var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
23
23
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
24
24
  var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
25
25
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
@@ -80,10 +80,10 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
80
80
  };
81
81
  }
82
82
  function _unsupportedIterableToArray(o, minLen) {
83
- var _context6;
83
+ var _context7;
84
84
  if (!o) return;
85
85
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
86
- var n = _sliceInstanceProperty(_context6 = Object.prototype.toString.call(o)).call(_context6, 8, -1);
86
+ var n = _sliceInstanceProperty(_context7 = Object.prototype.toString.call(o)).call(_context7, 8, -1);
87
87
  if (n === "Object" && o.constructor) n = o.constructor.name;
88
88
  if (n === "Map" || n === "Set") return _Array$from(o);
89
89
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
@@ -92,7 +92,7 @@ function _arrayLikeToArray(arr, len) {
92
92
  if (len == null || len > arr.length) len = arr.length;
93
93
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
94
94
  return arr2;
95
- } /* global WebSocket */
95
+ }
96
96
  // The LiveQuery client inner state
97
97
  var CLIENT_STATE = {
98
98
  INITIALIZED: 'initialized',
@@ -200,6 +200,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
200
200
  * @param {string} options.installationId (optional)
201
201
  */
202
202
  function LiveQueryClient(_ref) {
203
+ var _this = this;
203
204
  var applicationId = _ref.applicationId,
204
205
  serverURL = _ref.serverURL,
205
206
  javascriptKey = _ref.javascriptKey,
@@ -240,8 +241,16 @@ var LiveQueryClient = /*#__PURE__*/function () {
240
241
  this.state = CLIENT_STATE.INITIALIZED;
241
242
  var EventEmitter = _CoreManager.default.getEventEmitter();
242
243
  this.emitter = new EventEmitter();
243
- this.on = this.emitter.on;
244
- this.emit = this.emitter.emit;
244
+ this.on = function (eventName, listener) {
245
+ return _this.emitter.on(eventName, listener);
246
+ };
247
+ this.emit = function (eventName) {
248
+ var _this$emitter, _context;
249
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
250
+ args[_key - 1] = arguments[_key];
251
+ }
252
+ return (_this$emitter = _this.emitter).emit.apply(_this$emitter, (0, _concat.default)(_context = [eventName]).call(_context, args));
253
+ };
245
254
  // adding listener so process does not crash
246
255
  // best practice is for developer to register their own listener
247
256
  this.on('error', function () {});
@@ -271,7 +280,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
271
280
  value: function (query /*: Object*/, sessionToken /*: ?string*/) /*: LiveQuerySubscription*/{
272
281
  var _queryJSON$keys,
273
282
  _queryJSON$watch,
274
- _this = this;
283
+ _this2 = this;
275
284
  if (!query) {
276
285
  return;
277
286
  }
@@ -297,7 +306,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
297
306
  this.subscriptions.set(this.requestId, subscription);
298
307
  this.requestId += 1;
299
308
  this.connectPromise.then(function () {
300
- _this.socket.send((0, _stringify.default)(subscribeRequest));
309
+ _this2.socket.send((0, _stringify.default)(subscribeRequest));
301
310
  }).catch(function (error) {
302
311
  subscription.subscribePromise.reject(error);
303
312
  });
@@ -313,7 +322,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
313
322
  }, {
314
323
  key: "unsubscribe",
315
324
  value: function (subscription /*: Object*/) /*: ?Promise*/{
316
- var _this2 = this;
325
+ var _this3 = this;
317
326
  if (!subscription) {
318
327
  return;
319
328
  }
@@ -322,7 +331,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
322
331
  requestId: subscription.id
323
332
  };
324
333
  return this.connectPromise.then(function () {
325
- return _this2.socket.send((0, _stringify.default)(unsubscribeRequest));
334
+ return _this3.socket.send((0, _stringify.default)(unsubscribeRequest));
326
335
  }).then(function () {
327
336
  return subscription.unsubscribePromise;
328
337
  });
@@ -336,7 +345,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
336
345
  }, {
337
346
  key: "open",
338
347
  value: function () {
339
- var _this3 = this;
348
+ var _this4 = this;
340
349
  var WebSocketImplementation = _CoreManager.default.getWebSocketController();
341
350
  if (!WebSocketImplementation) {
342
351
  this.emit(CLIENT_EMMITER_TYPES.ERROR, 'Can not find WebSocket implementation');
@@ -350,25 +359,25 @@ var LiveQueryClient = /*#__PURE__*/function () {
350
359
 
351
360
  // Bind WebSocket callbacks
352
361
  this.socket.onopen = function () {
353
- _this3._handleWebSocketOpen();
362
+ _this4._handleWebSocketOpen();
354
363
  };
355
364
  this.socket.onmessage = function (event) {
356
- _this3._handleWebSocketMessage(event);
365
+ _this4._handleWebSocketMessage(event);
357
366
  };
358
367
  this.socket.onclose = function (event) {
359
- _this3.socket.closingPromise.resolve(event);
360
- _this3._handleWebSocketClose();
368
+ _this4.socket.closingPromise.resolve(event);
369
+ _this4._handleWebSocketClose();
361
370
  };
362
371
  this.socket.onerror = function (error) {
363
- _this3._handleWebSocketError(error);
372
+ _this4._handleWebSocketError(error);
364
373
  };
365
374
  }
366
375
  }, {
367
376
  key: "resubscribe",
368
377
  value: function () {
369
- var _context,
370
- _this4 = this;
371
- (0, _forEach.default)(_context = this.subscriptions).call(_context, function (subscription, requestId) {
378
+ var _context2,
379
+ _this5 = this;
380
+ (0, _forEach.default)(_context2 = this.subscriptions).call(_context2, function (subscription, requestId) {
372
381
  var query = subscription.query;
373
382
  var queryJSON = query.toJSON();
374
383
  var where = queryJSON.where;
@@ -387,8 +396,8 @@ var LiveQueryClient = /*#__PURE__*/function () {
387
396
  if (sessionToken) {
388
397
  subscribeRequest.sessionToken = sessionToken;
389
398
  }
390
- _this4.connectPromise.then(function () {
391
- _this4.socket.send((0, _stringify.default)(subscribeRequest));
399
+ _this5.connectPromise.then(function () {
400
+ _this5.socket.send((0, _stringify.default)(subscribeRequest));
392
401
  });
393
402
  });
394
403
  }
@@ -402,14 +411,14 @@ var LiveQueryClient = /*#__PURE__*/function () {
402
411
  }, {
403
412
  key: "close",
404
413
  value: function () /*: ?Promise*/{
405
- var _this$socket, _this$socket2, _context2;
414
+ var _this$socket, _this$socket2, _context3;
406
415
  if (this.state === CLIENT_STATE.INITIALIZED || this.state === CLIENT_STATE.DISCONNECTED) {
407
416
  return;
408
417
  }
409
418
  this.state = CLIENT_STATE.DISCONNECTED;
410
419
  (_this$socket = this.socket) === null || _this$socket === void 0 ? void 0 : _this$socket.close();
411
420
  // Notify each subscription about the close
412
- var _iterator = _createForOfIteratorHelper((0, _values.default)(_context2 = this.subscriptions).call(_context2)),
421
+ var _iterator = _createForOfIteratorHelper((0, _values.default)(_context3 = this.subscriptions).call(_context3)),
413
422
  _step;
414
423
  try {
415
424
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -556,14 +565,14 @@ var LiveQueryClient = /*#__PURE__*/function () {
556
565
  }, {
557
566
  key: "_handleWebSocketClose",
558
567
  value: function () {
559
- var _context3;
568
+ var _context4;
560
569
  if (this.state === CLIENT_STATE.DISCONNECTED) {
561
570
  return;
562
571
  }
563
572
  this.state = CLIENT_STATE.CLOSED;
564
573
  this.emit(CLIENT_EMMITER_TYPES.CLOSE);
565
574
  // Notify each subscription about the close
566
- var _iterator2 = _createForOfIteratorHelper((0, _values.default)(_context3 = this.subscriptions).call(_context3)),
575
+ var _iterator2 = _createForOfIteratorHelper((0, _values.default)(_context4 = this.subscriptions).call(_context4)),
567
576
  _step2;
568
577
  try {
569
578
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
@@ -580,9 +589,9 @@ var LiveQueryClient = /*#__PURE__*/function () {
580
589
  }, {
581
590
  key: "_handleWebSocketError",
582
591
  value: function (error /*: any*/) {
583
- var _context4;
592
+ var _context5;
584
593
  this.emit(CLIENT_EMMITER_TYPES.ERROR, error);
585
- var _iterator3 = _createForOfIteratorHelper((0, _values.default)(_context4 = this.subscriptions).call(_context4)),
594
+ var _iterator3 = _createForOfIteratorHelper((0, _values.default)(_context5 = this.subscriptions).call(_context5)),
586
595
  _step3;
587
596
  try {
588
597
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
@@ -599,8 +608,8 @@ var LiveQueryClient = /*#__PURE__*/function () {
599
608
  }, {
600
609
  key: "_handleReconnect",
601
610
  value: function () {
602
- var _context5,
603
- _this5 = this;
611
+ var _context6,
612
+ _this6 = this;
604
613
  // if closed or currently reconnecting we stop attempting to reconnect
605
614
  if (this.state === CLIENT_STATE.DISCONNECTED) {
606
615
  return;
@@ -616,15 +625,14 @@ var LiveQueryClient = /*#__PURE__*/function () {
616
625
  if (this.reconnectHandle) {
617
626
  clearTimeout(this.reconnectHandle);
618
627
  }
619
- this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context5 = function () {
620
- _this5.attempts++;
621
- _this5.connectPromise = (0, _promiseUtils.resolvingPromise)();
622
- _this5.open();
623
- }).call(_context5, this), time);
628
+ this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context6 = function () {
629
+ _this6.attempts++;
630
+ _this6.connectPromise = (0, _promiseUtils.resolvingPromise)();
631
+ _this6.open();
632
+ }).call(_context6, this), time);
624
633
  }
625
634
  }]);
626
635
  return LiveQueryClient;
627
636
  }();
628
- _CoreManager.default.setWebSocketController(require('./Socket.weapp'));
629
637
  var _default = LiveQueryClient;
630
638
  exports.default = _default;
@@ -6,6 +6,7 @@ _Object$defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = void 0;
9
+ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
9
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
10
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
11
12
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
@@ -99,6 +100,7 @@ var Subscription = /*#__PURE__*/function () {
99
100
  * @param {string} sessionToken - optional session token
100
101
  */
101
102
  function Subscription(id, query, sessionToken) {
103
+ var _this = this;
102
104
  (0, _classCallCheck2.default)(this, Subscription);
103
105
  this.id = id;
104
106
  this.query = query;
@@ -108,8 +110,16 @@ var Subscription = /*#__PURE__*/function () {
108
110
  this.subscribed = false;
109
111
  var EventEmitter = _CoreManager.default.getEventEmitter();
110
112
  this.emitter = new EventEmitter();
111
- this.on = this.emitter.on;
112
- this.emit = this.emitter.emit;
113
+ this.on = function (eventName, listener) {
114
+ return _this.emitter.on(eventName, listener);
115
+ };
116
+ this.emit = function (eventName) {
117
+ var _this$emitter, _context;
118
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
119
+ args[_key - 1] = arguments[_key];
120
+ }
121
+ return (_this$emitter = _this.emitter).emit.apply(_this$emitter, (0, _concat.default)(_context = [eventName]).call(_context, args));
122
+ };
113
123
  // adding listener so process does not crash
114
124
  // best practice is for developer to register their own listener
115
125
  this.on('error', function () {});
@@ -123,10 +133,10 @@ var Subscription = /*#__PURE__*/function () {
123
133
  (0, _createClass2.default)(Subscription, [{
124
134
  key: "unsubscribe",
125
135
  value: function () /*: Promise*/{
126
- var _this = this;
136
+ var _this2 = this;
127
137
  return _CoreManager.default.getLiveQueryController().getDefaultLiveQueryClient().then(function (liveQueryClient) {
128
- _this.emit('close');
129
- return liveQueryClient.unsubscribe(_this);
138
+ _this2.emit('close');
139
+ return liveQueryClient.unsubscribe(_this2);
130
140
  });
131
141
  }
132
142
  }]);
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+
3
+ var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
4
+ var _Array$from = require("@babel/runtime-corejs3/core-js-stable/array/from");
5
+ var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
6
+ var _getIteratorMethod = require("@babel/runtime-corejs3/core-js/get-iterator-method");
7
+ var _Array$isArray = require("@babel/runtime-corejs3/core-js-stable/array/is-array");
8
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
9
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
10
+ var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
11
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
12
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
13
+ var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
15
+ var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
16
+ var _Storage = _interopRequireDefault(require("./Storage"));
17
+ function _createForOfIteratorHelper(o, allowArrayLike) {
18
+ var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"];
19
+ if (!it) {
20
+ if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
21
+ if (it) o = it;
22
+ var i = 0;
23
+ var F = function () {};
24
+ return {
25
+ s: F,
26
+ n: function () {
27
+ if (i >= o.length) return {
28
+ done: true
29
+ };
30
+ return {
31
+ done: false,
32
+ value: o[i++]
33
+ };
34
+ },
35
+ e: function (_e) {
36
+ throw _e;
37
+ },
38
+ f: F
39
+ };
40
+ }
41
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
42
+ }
43
+ var normalCompletion = true,
44
+ didErr = false,
45
+ err;
46
+ return {
47
+ s: function () {
48
+ it = it.call(o);
49
+ },
50
+ n: function () {
51
+ var step = it.next();
52
+ normalCompletion = step.done;
53
+ return step;
54
+ },
55
+ e: function (_e2) {
56
+ didErr = true;
57
+ err = _e2;
58
+ },
59
+ f: function () {
60
+ try {
61
+ if (!normalCompletion && it.return != null) it.return();
62
+ } finally {
63
+ if (didErr) throw err;
64
+ }
65
+ }
66
+ };
67
+ }
68
+ function _unsupportedIterableToArray(o, minLen) {
69
+ var _context7;
70
+ if (!o) return;
71
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
72
+ var n = _sliceInstanceProperty(_context7 = Object.prototype.toString.call(o)).call(_context7, 8, -1);
73
+ if (n === "Object" && o.constructor) n = o.constructor.name;
74
+ if (n === "Map" || n === "Set") return _Array$from(o);
75
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
76
+ }
77
+ function _arrayLikeToArray(arr, len) {
78
+ if (len == null || len > arr.length) len = arr.length;
79
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
80
+ return arr2;
81
+ } /**
82
+ * @flow
83
+ */
84
+ var LocalDatastoreController = {
85
+ fromPinWithName: function (name /*: string*/) /*: Array<Object>*/{
86
+ return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
87
+ var values, objects;
88
+ return _regenerator.default.wrap(function (_context) {
89
+ while (1) switch (_context.prev = _context.next) {
90
+ case 0:
91
+ _context.next = 2;
92
+ return _Storage.default.getItemAsync(name);
93
+ case 2:
94
+ values = _context.sent;
95
+ if (values) {
96
+ _context.next = 5;
97
+ break;
98
+ }
99
+ return _context.abrupt("return", []);
100
+ case 5:
101
+ objects = JSON.parse(values);
102
+ return _context.abrupt("return", objects);
103
+ case 7:
104
+ case "end":
105
+ return _context.stop();
106
+ }
107
+ }, _callee);
108
+ }))();
109
+ },
110
+ pinWithName: function (name /*: string*/, value /*: any*/) {
111
+ var values = (0, _stringify.default)(value);
112
+ return _Storage.default.setItemAsync(name, values);
113
+ },
114
+ unPinWithName: function (name /*: string*/) {
115
+ return _Storage.default.removeItemAsync(name);
116
+ },
117
+ getAllContents: function () /*: Object*/{
118
+ return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
119
+ var keys;
120
+ return _regenerator.default.wrap(function (_context3) {
121
+ while (1) switch (_context3.prev = _context3.next) {
122
+ case 0:
123
+ _context3.next = 2;
124
+ return _Storage.default.getAllKeysAsync();
125
+ case 2:
126
+ keys = _context3.sent;
127
+ return _context3.abrupt("return", (0, _reduce.default)(keys).call(keys, /*#__PURE__*/function () {
128
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(previousPromise, key) {
129
+ var LDS, value;
130
+ return _regenerator.default.wrap(function (_context2) {
131
+ while (1) switch (_context2.prev = _context2.next) {
132
+ case 0:
133
+ _context2.next = 2;
134
+ return previousPromise;
135
+ case 2:
136
+ LDS = _context2.sent;
137
+ if (!(0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
138
+ _context2.next = 8;
139
+ break;
140
+ }
141
+ _context2.next = 6;
142
+ return _Storage.default.getItemAsync(key);
143
+ case 6:
144
+ value = _context2.sent;
145
+ try {
146
+ LDS[key] = JSON.parse(value);
147
+ } catch (error) {
148
+ console.error('Error getAllContents: ', error);
149
+ }
150
+ case 8:
151
+ return _context2.abrupt("return", LDS);
152
+ case 9:
153
+ case "end":
154
+ return _context2.stop();
155
+ }
156
+ }, _callee2);
157
+ }));
158
+ return function () {
159
+ return _ref.apply(this, arguments);
160
+ };
161
+ }(), _promise.default.resolve({})));
162
+ case 4:
163
+ case "end":
164
+ return _context3.stop();
165
+ }
166
+ }, _callee3);
167
+ }))();
168
+ },
169
+ // Used for testing
170
+ getRawStorage: function () /*: Object*/{
171
+ return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
172
+ var keys;
173
+ return _regenerator.default.wrap(function (_context5) {
174
+ while (1) switch (_context5.prev = _context5.next) {
175
+ case 0:
176
+ _context5.next = 2;
177
+ return _Storage.default.getAllKeysAsync();
178
+ case 2:
179
+ keys = _context5.sent;
180
+ return _context5.abrupt("return", (0, _reduce.default)(keys).call(keys, /*#__PURE__*/function () {
181
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(previousPromise, key) {
182
+ var LDS, value;
183
+ return _regenerator.default.wrap(function (_context4) {
184
+ while (1) switch (_context4.prev = _context4.next) {
185
+ case 0:
186
+ _context4.next = 2;
187
+ return previousPromise;
188
+ case 2:
189
+ LDS = _context4.sent;
190
+ _context4.next = 5;
191
+ return _Storage.default.getItemAsync(key);
192
+ case 5:
193
+ value = _context4.sent;
194
+ LDS[key] = value;
195
+ return _context4.abrupt("return", LDS);
196
+ case 8:
197
+ case "end":
198
+ return _context4.stop();
199
+ }
200
+ }, _callee4);
201
+ }));
202
+ return function () {
203
+ return _ref2.apply(this, arguments);
204
+ };
205
+ }(), _promise.default.resolve({})));
206
+ case 4:
207
+ case "end":
208
+ return _context5.stop();
209
+ }
210
+ }, _callee5);
211
+ }))();
212
+ },
213
+ clear: function () /*: Promise*/{
214
+ var _this = this;
215
+ return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
216
+ var keys, toRemove, _iterator, _step, key, promises;
217
+ return _regenerator.default.wrap(function (_context6) {
218
+ while (1) switch (_context6.prev = _context6.next) {
219
+ case 0:
220
+ _context6.next = 2;
221
+ return _Storage.default.getAllKeysAsync();
222
+ case 2:
223
+ keys = _context6.sent;
224
+ toRemove = [];
225
+ _iterator = _createForOfIteratorHelper(keys);
226
+ try {
227
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
228
+ key = _step.value;
229
+ if ((0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
230
+ toRemove.push(key);
231
+ }
232
+ }
233
+ } catch (err) {
234
+ _iterator.e(err);
235
+ } finally {
236
+ _iterator.f();
237
+ }
238
+ promises = (0, _map.default)(toRemove).call(toRemove, _this.unPinWithName);
239
+ return _context6.abrupt("return", _promise.default.all(promises));
240
+ case 8:
241
+ case "end":
242
+ return _context6.stop();
243
+ }
244
+ }, _callee6);
245
+ }))();
246
+ }
247
+ };
248
+ module.exports = LocalDatastoreController;