parse 5.1.1-alpha.1 → 5.2.0-alpha.2
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/parse.js +10186 -14918
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +10180 -15057
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/Analytics.js +7 -11
- package/lib/browser/AnonymousUtils.js +17 -22
- package/lib/browser/Cloud.js +24 -46
- package/lib/browser/CoreManager.js +71 -79
- package/lib/browser/CryptoController.js +14 -9
- package/lib/browser/EventEmitter.js +9 -2
- package/lib/browser/EventuallyQueue.js +156 -357
- package/lib/browser/FacebookUtils.js +23 -28
- package/lib/browser/IndexedDBStorageController.js +18 -14
- package/lib/browser/InstallationController.js +55 -121
- package/lib/browser/LiveQueryClient.js +312 -446
- package/lib/browser/LiveQuerySubscription.js +25 -28
- package/lib/browser/LocalDatastore.js +254 -578
- package/lib/browser/LocalDatastoreController.default.js +48 -227
- package/lib/browser/LocalDatastoreController.js +11 -1
- package/lib/browser/LocalDatastoreController.react-native.js +72 -164
- package/lib/browser/LocalDatastoreUtils.js +4 -12
- package/lib/browser/ObjectStateMutations.js +89 -95
- package/lib/browser/OfflineQuery.js +106 -198
- package/lib/browser/Parse.js +45 -61
- package/lib/browser/ParseACL.js +242 -288
- package/lib/browser/ParseCLP.js +372 -580
- package/lib/browser/ParseConfig.js +115 -138
- package/lib/browser/ParseError.js +85 -182
- package/lib/browser/ParseFile.js +296 -444
- package/lib/browser/ParseGeoPoint.js +121 -140
- package/lib/browser/ParseHooks.js +12 -14
- package/lib/browser/ParseInstallation.js +226 -354
- package/lib/browser/ParseLiveQuery.js +74 -148
- package/lib/browser/ParseObject.js +2017 -2622
- package/lib/browser/ParseOp.js +343 -484
- package/lib/browser/ParsePolygon.js +101 -120
- package/lib/browser/ParseQuery.js +1722 -2068
- package/lib/browser/ParseRelation.js +99 -118
- package/lib/browser/ParseRole.js +88 -144
- package/lib/browser/ParseSchema.js +372 -434
- package/lib/browser/ParseSession.js +62 -110
- package/lib/browser/ParseUser.js +942 -1270
- package/lib/browser/Push.js +16 -44
- package/lib/browser/RESTController.js +85 -124
- package/lib/browser/SingleInstanceStateController.js +57 -86
- package/lib/browser/Socket.weapp.js +50 -33
- package/lib/browser/Storage.js +23 -28
- package/lib/browser/StorageController.browser.js +16 -13
- package/lib/browser/StorageController.default.js +15 -14
- package/lib/browser/StorageController.js +14 -1
- package/lib/browser/StorageController.react-native.js +31 -30
- package/lib/browser/StorageController.weapp.js +19 -13
- package/lib/browser/TaskQueue.js +37 -49
- package/lib/browser/UniqueInstanceStateController.js +65 -86
- package/lib/browser/WebSocketController.js +11 -4
- package/lib/browser/Xhr.weapp.js +90 -78
- package/lib/browser/arrayContainsObject.js +3 -3
- package/lib/browser/canBeSerialized.js +10 -11
- package/lib/browser/decode.js +11 -11
- package/lib/browser/encode.js +11 -11
- package/lib/browser/equals.js +9 -10
- package/lib/browser/escape.js +2 -2
- package/lib/browser/isRevocableSession.js +1 -1
- package/lib/browser/parseDate.js +10 -10
- package/lib/browser/promiseUtils.js +19 -19
- package/lib/browser/unique.js +4 -4
- package/lib/browser/unsavedChildren.js +20 -21
- package/lib/browser/uuid.js +2 -4
- package/lib/node/Analytics.js +2 -6
- package/lib/node/AnonymousUtils.js +7 -12
- package/lib/node/Cloud.js +8 -12
- package/lib/node/CoreManager.js +59 -67
- package/lib/node/CryptoController.js +8 -3
- package/lib/node/EventEmitter.js +7 -1
- package/lib/node/EventuallyQueue.js +18 -37
- package/lib/node/FacebookUtils.js +1 -5
- package/lib/node/IndexedDBStorageController.js +14 -10
- package/lib/node/InstallationController.js +7 -8
- package/lib/node/LiveQueryClient.js +20 -32
- package/lib/node/LiveQuerySubscription.js +3 -4
- package/lib/node/LocalDatastore.js +20 -24
- package/lib/node/LocalDatastoreController.default.js +12 -11
- package/lib/node/LocalDatastoreController.js +14 -1
- package/lib/node/LocalDatastoreController.react-native.js +27 -22
- package/lib/node/LocalDatastoreUtils.js +4 -12
- package/lib/node/ObjectStateMutations.js +52 -36
- package/lib/node/OfflineQuery.js +37 -23
- package/lib/node/Parse.js +35 -49
- package/lib/node/ParseACL.js +18 -27
- package/lib/node/ParseCLP.js +38 -50
- package/lib/node/ParseConfig.js +7 -14
- package/lib/node/ParseError.js +457 -458
- package/lib/node/ParseFile.js +33 -66
- package/lib/node/ParseGeoPoint.js +22 -17
- package/lib/node/ParseHooks.js +0 -2
- package/lib/node/ParseInstallation.js +21 -8
- package/lib/node/ParseLiveQuery.js +6 -11
- package/lib/node/ParseObject.js +138 -167
- package/lib/node/ParseOp.js +32 -44
- package/lib/node/ParsePolygon.js +11 -17
- package/lib/node/ParseQuery.js +118 -164
- package/lib/node/ParseRelation.js +7 -16
- package/lib/node/ParseRole.js +7 -13
- package/lib/node/ParseSchema.js +26 -39
- package/lib/node/ParseSession.js +7 -8
- package/lib/node/ParseUser.js +70 -76
- package/lib/node/Push.js +5 -15
- package/lib/node/RESTController.js +21 -33
- package/lib/node/SingleInstanceStateController.js +41 -69
- package/lib/node/Socket.weapp.js +23 -2
- package/lib/node/Storage.js +11 -16
- package/lib/node/StorageController.browser.js +10 -8
- package/lib/node/StorageController.default.js +9 -9
- package/lib/node/StorageController.js +16 -1
- package/lib/node/StorageController.react-native.js +17 -17
- package/lib/node/StorageController.weapp.js +14 -8
- package/lib/node/TaskQueue.js +8 -11
- package/lib/node/UniqueInstanceStateController.js +40 -60
- package/lib/node/WebSocketController.js +15 -2
- package/lib/node/Xhr.weapp.js +11 -2
- package/lib/node/arrayContainsObject.js +1 -1
- package/lib/node/canBeSerialized.js +2 -2
- package/lib/node/decode.js +1 -1
- package/lib/node/encode.js +2 -2
- package/lib/node/equals.js +1 -1
- package/lib/node/escape.js +1 -1
- package/lib/node/isRevocableSession.js +1 -1
- package/lib/node/parseDate.js +1 -1
- package/lib/node/promiseUtils.js +7 -7
- package/lib/node/unique.js +2 -2
- package/lib/node/unsavedChildren.js +2 -2
- package/lib/node/uuid.js +2 -4
- package/lib/react-native/Analytics.js +2 -2
- package/lib/react-native/AnonymousUtils.js +3 -4
- package/lib/react-native/Cloud.js +0 -1
- package/lib/react-native/CoreManager.js +2 -3
- package/lib/react-native/CryptoController.js +6 -1
- package/lib/react-native/EventEmitter.js +6 -1
- package/lib/react-native/EventuallyQueue.js +1 -2
- package/lib/react-native/FacebookUtils.js +1 -2
- package/lib/react-native/IndexedDBStorageController.js +11 -5
- package/lib/react-native/InstallationController.js +1 -2
- package/lib/react-native/LiveQueryClient.js +51 -36
- package/lib/react-native/LiveQuerySubscription.js +2 -4
- package/lib/react-native/LocalDatastore.js +41 -17
- package/lib/react-native/LocalDatastoreController.default.js +6 -1
- package/lib/react-native/LocalDatastoreController.js +11 -1
- package/lib/react-native/LocalDatastoreController.react-native.js +16 -11
- package/lib/react-native/LocalDatastoreUtils.js +3 -6
- package/lib/react-native/ObjectStateMutations.js +30 -9
- package/lib/react-native/OfflineQuery.js +25 -20
- package/lib/react-native/Parse.js +24 -38
- package/lib/react-native/ParseACL.js +4 -6
- package/lib/react-native/ParseCLP.js +5 -7
- package/lib/react-native/ParseConfig.js +4 -6
- package/lib/react-native/ParseError.js +13 -31
- package/lib/react-native/ParseFile.js +10 -10
- package/lib/react-native/ParseGeoPoint.js +2 -4
- package/lib/react-native/ParseInstallation.js +13 -30
- package/lib/react-native/ParseLiveQuery.js +2 -4
- package/lib/react-native/ParseObject.js +81 -90
- package/lib/react-native/ParseOp.js +41 -79
- package/lib/react-native/ParsePolygon.js +2 -4
- package/lib/react-native/ParseQuery.js +87 -81
- package/lib/react-native/ParseRelation.js +2 -4
- package/lib/react-native/ParseRole.js +14 -31
- package/lib/react-native/ParseSchema.js +3 -5
- package/lib/react-native/ParseSession.js +12 -29
- package/lib/react-native/ParseUser.js +32 -51
- package/lib/react-native/RESTController.js +10 -4
- package/lib/react-native/SingleInstanceStateController.js +23 -37
- package/lib/react-native/Socket.weapp.js +9 -4
- package/lib/react-native/Storage.js +1 -2
- package/lib/react-native/StorageController.browser.js +6 -1
- package/lib/react-native/StorageController.default.js +6 -1
- package/lib/react-native/StorageController.js +13 -1
- package/lib/react-native/StorageController.react-native.js +11 -6
- package/lib/react-native/StorageController.weapp.js +6 -1
- package/lib/react-native/TaskQueue.js +8 -4
- package/lib/react-native/UniqueInstanceStateController.js +23 -37
- package/lib/react-native/WebSocketController.js +9 -1
- package/lib/react-native/Xhr.weapp.js +9 -4
- package/lib/react-native/unsavedChildren.js +3 -3
- package/lib/react-native/uuid.js +1 -2
- package/lib/weapp/Analytics.js +7 -11
- package/lib/weapp/AnonymousUtils.js +17 -22
- package/lib/weapp/Cloud.js +24 -46
- package/lib/weapp/CoreManager.js +71 -79
- package/lib/weapp/CryptoController.js +14 -9
- package/lib/weapp/EventEmitter.js +9 -2
- package/lib/weapp/EventuallyQueue.js +156 -357
- package/lib/weapp/FacebookUtils.js +23 -28
- package/lib/weapp/IndexedDBStorageController.js +18 -14
- package/lib/weapp/InstallationController.js +55 -121
- package/lib/weapp/LiveQueryClient.js +312 -446
- package/lib/weapp/LiveQuerySubscription.js +25 -28
- package/lib/weapp/LocalDatastore.js +254 -578
- package/lib/weapp/LocalDatastoreController.default.js +48 -227
- package/lib/weapp/LocalDatastoreController.js +11 -1
- package/lib/weapp/LocalDatastoreController.react-native.js +72 -164
- package/lib/weapp/LocalDatastoreUtils.js +4 -12
- package/lib/weapp/ObjectStateMutations.js +89 -95
- package/lib/weapp/OfflineQuery.js +106 -198
- package/lib/weapp/Parse.js +45 -60
- package/lib/weapp/ParseACL.js +242 -288
- package/lib/weapp/ParseCLP.js +372 -580
- package/lib/weapp/ParseConfig.js +115 -138
- package/lib/weapp/ParseError.js +85 -182
- package/lib/weapp/ParseFile.js +297 -446
- package/lib/weapp/ParseGeoPoint.js +121 -140
- package/lib/weapp/ParseHooks.js +12 -14
- package/lib/weapp/ParseInstallation.js +226 -354
- package/lib/weapp/ParseLiveQuery.js +74 -148
- package/lib/weapp/ParseObject.js +2017 -2622
- package/lib/weapp/ParseOp.js +343 -484
- package/lib/weapp/ParsePolygon.js +101 -120
- package/lib/weapp/ParseQuery.js +1722 -2068
- package/lib/weapp/ParseRelation.js +99 -118
- package/lib/weapp/ParseRole.js +88 -144
- package/lib/weapp/ParseSchema.js +372 -434
- package/lib/weapp/ParseSession.js +62 -110
- package/lib/weapp/ParseUser.js +942 -1270
- package/lib/weapp/Push.js +16 -44
- package/lib/weapp/RESTController.js +86 -125
- package/lib/weapp/SingleInstanceStateController.js +57 -86
- package/lib/weapp/Socket.weapp.js +50 -33
- package/lib/weapp/Storage.js +23 -28
- package/lib/weapp/StorageController.browser.js +16 -13
- package/lib/weapp/StorageController.default.js +15 -14
- package/lib/weapp/StorageController.js +14 -1
- package/lib/weapp/StorageController.react-native.js +31 -30
- package/lib/weapp/StorageController.weapp.js +19 -13
- package/lib/weapp/TaskQueue.js +37 -49
- package/lib/weapp/UniqueInstanceStateController.js +65 -86
- package/lib/weapp/WebSocketController.js +11 -4
- package/lib/weapp/Xhr.weapp.js +90 -78
- package/lib/weapp/arrayContainsObject.js +3 -3
- package/lib/weapp/canBeSerialized.js +10 -11
- package/lib/weapp/decode.js +11 -11
- package/lib/weapp/encode.js +11 -11
- package/lib/weapp/equals.js +9 -10
- package/lib/weapp/escape.js +2 -2
- package/lib/weapp/isRevocableSession.js +1 -1
- package/lib/weapp/parseDate.js +10 -10
- package/lib/weapp/promiseUtils.js +19 -19
- package/lib/weapp/unique.js +4 -4
- package/lib/weapp/unsavedChildren.js +20 -21
- package/lib/weapp/uuid.js +6 -8
- package/package.json +23 -30
|
@@ -1,102 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
|
|
4
|
-
var _Array$from2 = 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$isArray2 = require("@babel/runtime-corejs3/core-js-stable/array/is-array");
|
|
8
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
9
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
10
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
11
6
|
value: true
|
|
12
7
|
});
|
|
13
8
|
exports.default = void 0;
|
|
14
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
|
|
15
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
16
10
|
var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
|
|
17
|
-
var
|
|
11
|
+
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
18
12
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
19
13
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
20
|
-
var _keys2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
21
14
|
var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/starts-with"));
|
|
22
|
-
var _keys3 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/keys"));
|
|
23
15
|
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
|
|
24
16
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
17
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
25
18
|
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
|
|
26
19
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
27
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/toConsumableArray"));
|
|
28
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
|
29
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
|
30
20
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
21
|
+
var _LocalDatastoreController = _interopRequireDefault(require("./LocalDatastoreController"));
|
|
31
22
|
var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
|
|
32
23
|
var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
|
|
33
|
-
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
34
|
-
var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"];
|
|
35
|
-
if (!it) {
|
|
36
|
-
if (_Array$isArray2(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
37
|
-
if (it) o = it;
|
|
38
|
-
var i = 0;
|
|
39
|
-
var F = function () {};
|
|
40
|
-
return {
|
|
41
|
-
s: F,
|
|
42
|
-
n: function () {
|
|
43
|
-
if (i >= o.length) return {
|
|
44
|
-
done: true
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
done: false,
|
|
48
|
-
value: o[i++]
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
e: function (_e) {
|
|
52
|
-
throw _e;
|
|
53
|
-
},
|
|
54
|
-
f: F
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
58
|
-
}
|
|
59
|
-
var normalCompletion = true,
|
|
60
|
-
didErr = false,
|
|
61
|
-
err;
|
|
62
|
-
return {
|
|
63
|
-
s: function () {
|
|
64
|
-
it = it.call(o);
|
|
65
|
-
},
|
|
66
|
-
n: function () {
|
|
67
|
-
var step = it.next();
|
|
68
|
-
normalCompletion = step.done;
|
|
69
|
-
return step;
|
|
70
|
-
},
|
|
71
|
-
e: function (_e2) {
|
|
72
|
-
didErr = true;
|
|
73
|
-
err = _e2;
|
|
74
|
-
},
|
|
75
|
-
f: function () {
|
|
76
|
-
try {
|
|
77
|
-
if (!normalCompletion && it.return != null) it.return();
|
|
78
|
-
} finally {
|
|
79
|
-
if (didErr) throw err;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
85
|
-
var _context16;
|
|
86
|
-
if (!o) return;
|
|
87
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
88
|
-
var n = _sliceInstanceProperty(_context16 = Object.prototype.toString.call(o)).call(_context16, 8, -1);
|
|
89
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
90
|
-
if (n === "Map" || n === "Set") return _Array$from2(o);
|
|
91
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
92
|
-
}
|
|
93
|
-
function _arrayLikeToArray(arr, len) {
|
|
94
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
95
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
96
|
-
return arr2;
|
|
97
|
-
} /**
|
|
98
|
-
* @flow
|
|
99
|
-
*/ /*:: import type ParseObject from './ParseObject';*/
|
|
100
24
|
/**
|
|
101
25
|
* Provides a local datastore which can be used to store and retrieve <code>Parse.Object</code>. <br />
|
|
102
26
|
* To enable this functionality, call <code>Parse.enableLocalDatastore()</code>.
|
|
@@ -117,206 +41,120 @@ function _arrayLikeToArray(arr, len) {
|
|
|
117
41
|
* @class Parse.LocalDatastore
|
|
118
42
|
* @static
|
|
119
43
|
*/
|
|
120
|
-
|
|
44
|
+
const LocalDatastore = {
|
|
121
45
|
isEnabled: false,
|
|
122
46
|
isSyncing: false,
|
|
123
|
-
fromPinWithName
|
|
124
|
-
|
|
47
|
+
fromPinWithName(name) {
|
|
48
|
+
const controller = _CoreManager.default.getLocalDatastoreController();
|
|
125
49
|
return controller.fromPinWithName(name);
|
|
126
50
|
},
|
|
127
|
-
pinWithName
|
|
128
|
-
|
|
51
|
+
async pinWithName(name, value) {
|
|
52
|
+
const controller = _CoreManager.default.getLocalDatastoreController();
|
|
129
53
|
return controller.pinWithName(name, value);
|
|
130
54
|
},
|
|
131
|
-
unPinWithName
|
|
132
|
-
|
|
55
|
+
async unPinWithName(name) {
|
|
56
|
+
const controller = _CoreManager.default.getLocalDatastoreController();
|
|
133
57
|
return controller.unPinWithName(name);
|
|
134
58
|
},
|
|
135
|
-
_getAllContents
|
|
136
|
-
|
|
59
|
+
_getAllContents() {
|
|
60
|
+
const controller = _CoreManager.default.getLocalDatastoreController();
|
|
137
61
|
return controller.getAllContents();
|
|
138
62
|
},
|
|
139
63
|
// Use for testing
|
|
140
|
-
_getRawStorage
|
|
141
|
-
|
|
64
|
+
async _getRawStorage() {
|
|
65
|
+
const controller = _CoreManager.default.getLocalDatastoreController();
|
|
142
66
|
return controller.getRawStorage();
|
|
143
67
|
},
|
|
144
|
-
_clear
|
|
145
|
-
|
|
68
|
+
async _clear() {
|
|
69
|
+
const controller = _CoreManager.default.getLocalDatastoreController();
|
|
146
70
|
return controller.clear();
|
|
147
71
|
},
|
|
148
72
|
// Pin the object and children recursively
|
|
149
73
|
// Saves the object and children key to Pin Name
|
|
150
|
-
_handlePinAllWithName
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
children[parentKey] = json;
|
|
172
|
-
for (objectKey in children) {
|
|
173
|
-
objectKeys.push(objectKey);
|
|
174
|
-
toPinPromises.push(_this.pinWithName(objectKey, [children[objectKey]]));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
} catch (err) {
|
|
178
|
-
_iterator.e(err);
|
|
179
|
-
} finally {
|
|
180
|
-
_iterator.f();
|
|
181
|
-
}
|
|
182
|
-
fromPinPromise = _this.fromPinWithName(pinName);
|
|
183
|
-
_context2.next = 8;
|
|
184
|
-
return _promise.default.all([fromPinPromise, toPinPromises]);
|
|
185
|
-
case 8:
|
|
186
|
-
_yield$Promise$all = _context2.sent;
|
|
187
|
-
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 1);
|
|
188
|
-
pinned = _yield$Promise$all2[0];
|
|
189
|
-
toPin = (0, _toConsumableArray2.default)(new _set.default((0, _concat.default)(_context = []).call(_context, (0, _toConsumableArray2.default)(pinned || []), objectKeys)));
|
|
190
|
-
return _context2.abrupt("return", _this.pinWithName(pinName, toPin));
|
|
191
|
-
case 13:
|
|
192
|
-
case "end":
|
|
193
|
-
return _context2.stop();
|
|
194
|
-
}
|
|
195
|
-
}, _callee);
|
|
196
|
-
}))();
|
|
74
|
+
async _handlePinAllWithName(name, objects) {
|
|
75
|
+
const pinName = this.getPinName(name);
|
|
76
|
+
const toPinPromises = [];
|
|
77
|
+
const objectKeys = [];
|
|
78
|
+
for (const parent of objects) {
|
|
79
|
+
const children = this._getChildren(parent);
|
|
80
|
+
const parentKey = this.getKeyForObject(parent);
|
|
81
|
+
const json = parent._toFullJSON(undefined, true);
|
|
82
|
+
if (parent._localId) {
|
|
83
|
+
json._localId = parent._localId;
|
|
84
|
+
}
|
|
85
|
+
children[parentKey] = json;
|
|
86
|
+
for (const objectKey in children) {
|
|
87
|
+
objectKeys.push(objectKey);
|
|
88
|
+
toPinPromises.push(this.pinWithName(objectKey, [children[objectKey]]));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const fromPinPromise = this.fromPinWithName(pinName);
|
|
92
|
+
const [pinned] = await _promise.default.all([fromPinPromise, toPinPromises]);
|
|
93
|
+
const toPin = [...new _set.default([...(pinned || []), ...objectKeys])];
|
|
94
|
+
return this.pinWithName(pinName, toPin);
|
|
197
95
|
},
|
|
198
96
|
// Removes object and children keys from pin name
|
|
199
97
|
// Keeps the object and children pinned
|
|
200
|
-
_handleUnPinAllWithName
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
objectKeys = (0, _toConsumableArray2.default)(new _set.default(objectKeys));
|
|
228
|
-
pinned = localDatastore[pinName] || [];
|
|
229
|
-
pinned = (0, _filter.default)(pinned).call(pinned, function (item) {
|
|
230
|
-
return !(0, _includes.default)(objectKeys).call(objectKeys, item);
|
|
231
|
-
});
|
|
232
|
-
if (pinned.length == 0) {
|
|
233
|
-
promises.push(_this2.unPinWithName(pinName));
|
|
234
|
-
delete localDatastore[pinName];
|
|
235
|
-
} else {
|
|
236
|
-
promises.push(_this2.pinWithName(pinName, pinned));
|
|
237
|
-
localDatastore[pinName] = pinned;
|
|
238
|
-
}
|
|
239
|
-
_iterator3 = _createForOfIteratorHelper(objectKeys);
|
|
240
|
-
_context4.prev = 13;
|
|
241
|
-
_iterator3.s();
|
|
242
|
-
case 15:
|
|
243
|
-
if ((_step3 = _iterator3.n()).done) {
|
|
244
|
-
_context4.next = 31;
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
objectKey = _step3.value;
|
|
248
|
-
hasReference = false;
|
|
249
|
-
_context4.t0 = (0, _keys3.default)(_regenerator.default).call(_regenerator.default, localDatastore);
|
|
250
|
-
case 19:
|
|
251
|
-
if ((_context4.t1 = _context4.t0()).done) {
|
|
252
|
-
_context4.next = 28;
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
key = _context4.t1.value;
|
|
256
|
-
if (!(key === _LocalDatastoreUtils.DEFAULT_PIN || (0, _startsWith.default)(key).call(key, _LocalDatastoreUtils.PIN_PREFIX))) {
|
|
257
|
-
_context4.next = 26;
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
pinnedObjects = localDatastore[key] || [];
|
|
261
|
-
if (!(0, _includes.default)(pinnedObjects).call(pinnedObjects, objectKey)) {
|
|
262
|
-
_context4.next = 26;
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
98
|
+
async _handleUnPinAllWithName(name, objects) {
|
|
99
|
+
const localDatastore = await this._getAllContents();
|
|
100
|
+
const pinName = this.getPinName(name);
|
|
101
|
+
const promises = [];
|
|
102
|
+
let objectKeys = [];
|
|
103
|
+
for (const parent of objects) {
|
|
104
|
+
const children = this._getChildren(parent);
|
|
105
|
+
const parentKey = this.getKeyForObject(parent);
|
|
106
|
+
objectKeys.push(parentKey, ...(0, _keys.default)(children));
|
|
107
|
+
}
|
|
108
|
+
objectKeys = [...new _set.default(objectKeys)];
|
|
109
|
+
let pinned = localDatastore[pinName] || [];
|
|
110
|
+
pinned = (0, _filter.default)(pinned).call(pinned, item => !(0, _includes.default)(objectKeys).call(objectKeys, item));
|
|
111
|
+
if (pinned.length == 0) {
|
|
112
|
+
promises.push(this.unPinWithName(pinName));
|
|
113
|
+
delete localDatastore[pinName];
|
|
114
|
+
} else {
|
|
115
|
+
promises.push(this.pinWithName(pinName, pinned));
|
|
116
|
+
localDatastore[pinName] = pinned;
|
|
117
|
+
}
|
|
118
|
+
for (const objectKey of objectKeys) {
|
|
119
|
+
let hasReference = false;
|
|
120
|
+
for (const key in localDatastore) {
|
|
121
|
+
if (key === _LocalDatastoreUtils.DEFAULT_PIN || (0, _startsWith.default)(key).call(key, _LocalDatastoreUtils.PIN_PREFIX)) {
|
|
122
|
+
const pinnedObjects = localDatastore[key] || [];
|
|
123
|
+
if ((0, _includes.default)(pinnedObjects).call(pinnedObjects, objectKey)) {
|
|
265
124
|
hasReference = true;
|
|
266
|
-
return _context4.abrupt("break", 28);
|
|
267
|
-
case 26:
|
|
268
|
-
_context4.next = 19;
|
|
269
|
-
break;
|
|
270
|
-
case 28:
|
|
271
|
-
if (!hasReference) {
|
|
272
|
-
promises.push(_this2.unPinWithName(objectKey));
|
|
273
|
-
}
|
|
274
|
-
case 29:
|
|
275
|
-
_context4.next = 15;
|
|
276
125
|
break;
|
|
277
|
-
|
|
278
|
-
_context4.next = 36;
|
|
279
|
-
break;
|
|
280
|
-
case 33:
|
|
281
|
-
_context4.prev = 33;
|
|
282
|
-
_context4.t2 = _context4["catch"](13);
|
|
283
|
-
_iterator3.e(_context4.t2);
|
|
284
|
-
case 36:
|
|
285
|
-
_context4.prev = 36;
|
|
286
|
-
_iterator3.f();
|
|
287
|
-
return _context4.finish(36);
|
|
288
|
-
case 39:
|
|
289
|
-
return _context4.abrupt("return", _promise.default.all(promises));
|
|
290
|
-
case 40:
|
|
291
|
-
case "end":
|
|
292
|
-
return _context4.stop();
|
|
126
|
+
}
|
|
293
127
|
}
|
|
294
|
-
}
|
|
295
|
-
|
|
128
|
+
}
|
|
129
|
+
if (!hasReference) {
|
|
130
|
+
promises.push(this.unPinWithName(objectKey));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return _promise.default.all(promises);
|
|
296
134
|
},
|
|
297
135
|
// Retrieve all pointer fields from object recursively
|
|
298
|
-
_getChildren
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
for (
|
|
136
|
+
_getChildren(object) {
|
|
137
|
+
const encountered = {};
|
|
138
|
+
const json = object._toFullJSON(undefined, true);
|
|
139
|
+
for (const key in json) {
|
|
302
140
|
if (json[key] && json[key].__type && json[key].__type === 'Object') {
|
|
303
141
|
this._traverse(json[key], encountered);
|
|
304
142
|
}
|
|
305
143
|
}
|
|
306
144
|
return encountered;
|
|
307
145
|
},
|
|
308
|
-
_traverse
|
|
146
|
+
_traverse(object, encountered) {
|
|
309
147
|
if (!object.objectId) {
|
|
310
148
|
return;
|
|
311
149
|
} else {
|
|
312
|
-
|
|
150
|
+
const objectKey = this.getKeyForObject(object);
|
|
313
151
|
if (encountered[objectKey]) {
|
|
314
152
|
return;
|
|
315
153
|
}
|
|
316
154
|
encountered[objectKey] = object;
|
|
317
155
|
}
|
|
318
|
-
for (
|
|
319
|
-
|
|
156
|
+
for (const key in object) {
|
|
157
|
+
let json = object[key];
|
|
320
158
|
if (!object[key]) {
|
|
321
159
|
json = object;
|
|
322
160
|
}
|
|
@@ -326,254 +164,134 @@ var LocalDatastore = {
|
|
|
326
164
|
}
|
|
327
165
|
},
|
|
328
166
|
// Transform keys in pin name to objects
|
|
329
|
-
_serializeObjectsFromPinName
|
|
330
|
-
var
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
return _context5.abrupt("return", allObjects);
|
|
352
|
-
case 7:
|
|
353
|
-
pinName = _this3.getPinName(name);
|
|
354
|
-
pinned = localDatastore[pinName];
|
|
355
|
-
if ((0, _isArray.default)(pinned)) {
|
|
356
|
-
_context5.next = 11;
|
|
357
|
-
break;
|
|
358
|
-
}
|
|
359
|
-
return _context5.abrupt("return", []);
|
|
360
|
-
case 11:
|
|
361
|
-
promises = (0, _map.default)(pinned).call(pinned, function (objectKey) {
|
|
362
|
-
return _this3.fromPinWithName(objectKey);
|
|
363
|
-
});
|
|
364
|
-
_context5.next = 14;
|
|
365
|
-
return _promise.default.all(promises);
|
|
366
|
-
case 14:
|
|
367
|
-
objects = _context5.sent;
|
|
368
|
-
objects = (0, _concat.default)(_ref = []).apply(_ref, (0, _toConsumableArray2.default)(objects));
|
|
369
|
-
return _context5.abrupt("return", (0, _filter.default)(objects).call(objects, function (object) {
|
|
370
|
-
return object != null;
|
|
371
|
-
}));
|
|
372
|
-
case 17:
|
|
373
|
-
case "end":
|
|
374
|
-
return _context5.stop();
|
|
375
|
-
}
|
|
376
|
-
}, _callee3);
|
|
377
|
-
}))();
|
|
167
|
+
async _serializeObjectsFromPinName(name) {
|
|
168
|
+
var _context;
|
|
169
|
+
const localDatastore = await this._getAllContents();
|
|
170
|
+
const allObjects = [];
|
|
171
|
+
for (const key in localDatastore) {
|
|
172
|
+
if ((0, _startsWith.default)(key).call(key, _LocalDatastoreUtils.OBJECT_PREFIX)) {
|
|
173
|
+
allObjects.push(localDatastore[key][0]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!name) {
|
|
177
|
+
return allObjects;
|
|
178
|
+
}
|
|
179
|
+
const pinName = this.getPinName(name);
|
|
180
|
+
const pinned = localDatastore[pinName];
|
|
181
|
+
if (!(0, _isArray.default)(pinned)) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
const promises = (0, _map.default)(pinned).call(pinned, objectKey => this.fromPinWithName(objectKey));
|
|
185
|
+
let objects = await _promise.default.all(promises);
|
|
186
|
+
objects = (0, _concat.default)(_context = []).call(_context, ...objects);
|
|
187
|
+
return (0, _filter.default)(objects).call(objects, object => object != null);
|
|
378
188
|
},
|
|
379
189
|
// Replaces object pointers with pinned pointers
|
|
380
190
|
// The object pointers may contain old data
|
|
381
191
|
// Uses Breadth First Search Algorithm
|
|
382
|
-
_serializeObject
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
uniqueId = 0;
|
|
409
|
-
meta[uniqueId] = root;
|
|
192
|
+
async _serializeObject(objectKey, localDatastore) {
|
|
193
|
+
let LDS = localDatastore;
|
|
194
|
+
if (!LDS) {
|
|
195
|
+
LDS = await this._getAllContents();
|
|
196
|
+
}
|
|
197
|
+
if (!LDS[objectKey] || LDS[objectKey].length === 0) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const root = LDS[objectKey][0];
|
|
201
|
+
const queue = [];
|
|
202
|
+
const meta = {};
|
|
203
|
+
let uniqueId = 0;
|
|
204
|
+
meta[uniqueId] = root;
|
|
205
|
+
queue.push(uniqueId);
|
|
206
|
+
while (queue.length !== 0) {
|
|
207
|
+
const nodeId = queue.shift();
|
|
208
|
+
const subTreeRoot = meta[nodeId];
|
|
209
|
+
for (const field in subTreeRoot) {
|
|
210
|
+
const value = subTreeRoot[field];
|
|
211
|
+
if (value.__type && value.__type === 'Object') {
|
|
212
|
+
const key = this.getKeyForObject(value);
|
|
213
|
+
if (LDS[key] && LDS[key].length > 0) {
|
|
214
|
+
const pointer = LDS[key][0];
|
|
215
|
+
uniqueId++;
|
|
216
|
+
meta[uniqueId] = pointer;
|
|
217
|
+
subTreeRoot[field] = pointer;
|
|
410
218
|
queue.push(uniqueId);
|
|
411
|
-
|
|
412
|
-
nodeId = queue.shift();
|
|
413
|
-
subTreeRoot = meta[nodeId];
|
|
414
|
-
for (field in subTreeRoot) {
|
|
415
|
-
value = subTreeRoot[field];
|
|
416
|
-
if (value.__type && value.__type === 'Object') {
|
|
417
|
-
key = _this4.getKeyForObject(value);
|
|
418
|
-
if (LDS[key] && LDS[key].length > 0) {
|
|
419
|
-
pointer = LDS[key][0];
|
|
420
|
-
uniqueId++;
|
|
421
|
-
meta[uniqueId] = pointer;
|
|
422
|
-
subTreeRoot[field] = pointer;
|
|
423
|
-
queue.push(uniqueId);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
return _context6.abrupt("return", root);
|
|
429
|
-
case 15:
|
|
430
|
-
case "end":
|
|
431
|
-
return _context6.stop();
|
|
219
|
+
}
|
|
432
220
|
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return root;
|
|
435
224
|
},
|
|
436
225
|
// Called when an object is save / fetched
|
|
437
226
|
// Update object pin value
|
|
438
|
-
_updateObjectIfPinned
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
return _context7.abrupt("return");
|
|
450
|
-
case 2:
|
|
451
|
-
objectKey = _this5.getKeyForObject(object);
|
|
452
|
-
_context7.next = 5;
|
|
453
|
-
return _this5.fromPinWithName(objectKey);
|
|
454
|
-
case 5:
|
|
455
|
-
pinned = _context7.sent;
|
|
456
|
-
if (!(!pinned || pinned.length === 0)) {
|
|
457
|
-
_context7.next = 8;
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
return _context7.abrupt("return");
|
|
461
|
-
case 8:
|
|
462
|
-
return _context7.abrupt("return", _this5.pinWithName(objectKey, [object._toFullJSON()]));
|
|
463
|
-
case 9:
|
|
464
|
-
case "end":
|
|
465
|
-
return _context7.stop();
|
|
466
|
-
}
|
|
467
|
-
}, _callee5);
|
|
468
|
-
}))();
|
|
227
|
+
async _updateObjectIfPinned(object) {
|
|
228
|
+
if (!this.isEnabled) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const objectKey = this.getKeyForObject(object);
|
|
232
|
+
const pinned = await this.fromPinWithName(objectKey);
|
|
233
|
+
if (!pinned || pinned.length === 0) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
return this.pinWithName(objectKey, [object._toFullJSON()]);
|
|
469
237
|
},
|
|
470
238
|
// Called when object is destroyed
|
|
471
239
|
// Unpin object and remove all references from pin names
|
|
472
240
|
// TODO: Destroy children?
|
|
473
|
-
_destroyObjectIfPinned
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
case 9:
|
|
498
|
-
promises = [_this6.unPinWithName(objectKey)];
|
|
499
|
-
delete localDatastore[objectKey];
|
|
500
|
-
for (key in localDatastore) {
|
|
501
|
-
if (key === _LocalDatastoreUtils.DEFAULT_PIN || (0, _startsWith.default)(key).call(key, _LocalDatastoreUtils.PIN_PREFIX)) {
|
|
502
|
-
pinned = localDatastore[key] || [];
|
|
503
|
-
if ((0, _includes.default)(pinned).call(pinned, objectKey)) {
|
|
504
|
-
pinned = (0, _filter.default)(pinned).call(pinned, function (item) {
|
|
505
|
-
return item !== objectKey;
|
|
506
|
-
});
|
|
507
|
-
if (pinned.length == 0) {
|
|
508
|
-
promises.push(_this6.unPinWithName(key));
|
|
509
|
-
delete localDatastore[key];
|
|
510
|
-
} else {
|
|
511
|
-
promises.push(_this6.pinWithName(key, pinned));
|
|
512
|
-
localDatastore[key] = pinned;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
return _context8.abrupt("return", _promise.default.all(promises));
|
|
518
|
-
case 13:
|
|
519
|
-
case "end":
|
|
520
|
-
return _context8.stop();
|
|
241
|
+
async _destroyObjectIfPinned(object) {
|
|
242
|
+
if (!this.isEnabled) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const localDatastore = await this._getAllContents();
|
|
246
|
+
const objectKey = this.getKeyForObject(object);
|
|
247
|
+
const pin = localDatastore[objectKey];
|
|
248
|
+
if (!pin) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const promises = [this.unPinWithName(objectKey)];
|
|
252
|
+
delete localDatastore[objectKey];
|
|
253
|
+
for (const key in localDatastore) {
|
|
254
|
+
if (key === _LocalDatastoreUtils.DEFAULT_PIN || (0, _startsWith.default)(key).call(key, _LocalDatastoreUtils.PIN_PREFIX)) {
|
|
255
|
+
let pinned = localDatastore[key] || [];
|
|
256
|
+
if ((0, _includes.default)(pinned).call(pinned, objectKey)) {
|
|
257
|
+
pinned = (0, _filter.default)(pinned).call(pinned, item => item !== objectKey);
|
|
258
|
+
if (pinned.length == 0) {
|
|
259
|
+
promises.push(this.unPinWithName(key));
|
|
260
|
+
delete localDatastore[key];
|
|
261
|
+
} else {
|
|
262
|
+
promises.push(this.pinWithName(key, pinned));
|
|
263
|
+
localDatastore[key] = pinned;
|
|
264
|
+
}
|
|
521
265
|
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return _promise.default.all(promises);
|
|
524
269
|
},
|
|
525
270
|
// Update pin and references of the unsaved object
|
|
526
|
-
_updateLocalIdForObject
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
if (!(!unsaved || unsaved.length === 0)) {
|
|
547
|
-
_context11.next = 9;
|
|
548
|
-
break;
|
|
549
|
-
}
|
|
550
|
-
return _context11.abrupt("return");
|
|
551
|
-
case 9:
|
|
552
|
-
promises = [_this7.unPinWithName(localKey), _this7.pinWithName(objectKey, unsaved)];
|
|
553
|
-
_context11.next = 12;
|
|
554
|
-
return _this7._getAllContents();
|
|
555
|
-
case 12:
|
|
556
|
-
localDatastore = _context11.sent;
|
|
557
|
-
for (key in localDatastore) {
|
|
558
|
-
if (key === _LocalDatastoreUtils.DEFAULT_PIN || (0, _startsWith.default)(key).call(key, _LocalDatastoreUtils.PIN_PREFIX)) {
|
|
559
|
-
pinned = localDatastore[key] || [];
|
|
560
|
-
if ((0, _includes.default)(pinned).call(pinned, localKey)) {
|
|
561
|
-
pinned = (0, _filter.default)(pinned).call(pinned, function (item) {
|
|
562
|
-
return item !== localKey;
|
|
563
|
-
});
|
|
564
|
-
pinned.push(objectKey);
|
|
565
|
-
promises.push(_this7.pinWithName(key, pinned));
|
|
566
|
-
localDatastore[key] = pinned;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
return _context11.abrupt("return", _promise.default.all(promises));
|
|
571
|
-
case 15:
|
|
572
|
-
case "end":
|
|
573
|
-
return _context11.stop();
|
|
271
|
+
async _updateLocalIdForObject(localId, object) {
|
|
272
|
+
if (!this.isEnabled) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const localKey = `${_LocalDatastoreUtils.OBJECT_PREFIX}${object.className}_${localId}`;
|
|
276
|
+
const objectKey = this.getKeyForObject(object);
|
|
277
|
+
const unsaved = await this.fromPinWithName(localKey);
|
|
278
|
+
if (!unsaved || unsaved.length === 0) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const promises = [this.unPinWithName(localKey), this.pinWithName(objectKey, unsaved)];
|
|
282
|
+
const localDatastore = await this._getAllContents();
|
|
283
|
+
for (const key in localDatastore) {
|
|
284
|
+
if (key === _LocalDatastoreUtils.DEFAULT_PIN || (0, _startsWith.default)(key).call(key, _LocalDatastoreUtils.PIN_PREFIX)) {
|
|
285
|
+
let pinned = localDatastore[key] || [];
|
|
286
|
+
if ((0, _includes.default)(pinned).call(pinned, localKey)) {
|
|
287
|
+
pinned = (0, _filter.default)(pinned).call(pinned, item => item !== localKey);
|
|
288
|
+
pinned.push(objectKey);
|
|
289
|
+
promises.push(this.pinWithName(key, pinned));
|
|
290
|
+
localDatastore[key] = pinned;
|
|
574
291
|
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return _promise.default.all(promises);
|
|
577
295
|
},
|
|
578
296
|
/**
|
|
579
297
|
* Updates Local Datastore from Server
|
|
@@ -586,117 +304,76 @@ var LocalDatastore = {
|
|
|
586
304
|
* @name Parse.LocalDatastore.updateFromServer
|
|
587
305
|
* @static
|
|
588
306
|
*/
|
|
589
|
-
updateFromServer
|
|
590
|
-
var
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
break;
|
|
648
|
-
case 23:
|
|
649
|
-
queryPromises = (0, _map.default)(_context12 = (0, _keys2.default)(pointersHash)).call(_context12, function (className) {
|
|
650
|
-
var objectIds = (0, _from.default)(pointersHash[className]);
|
|
651
|
-
var query = new _ParseQuery.default(className);
|
|
652
|
-
query.limit(objectIds.length);
|
|
653
|
-
if (objectIds.length === 1) {
|
|
654
|
-
query.equalTo('objectId', objectIds[0]);
|
|
655
|
-
} else {
|
|
656
|
-
query.containedIn('objectId', objectIds);
|
|
657
|
-
}
|
|
658
|
-
return (0, _find.default)(query).call(query);
|
|
659
|
-
});
|
|
660
|
-
_context13.prev = 24;
|
|
661
|
-
_context13.next = 27;
|
|
662
|
-
return _promise.default.all(queryPromises);
|
|
663
|
-
case 27:
|
|
664
|
-
responses = _context13.sent;
|
|
665
|
-
objects = (0, _concat.default)([]).apply([], responses);
|
|
666
|
-
pinPromises = (0, _map.default)(objects).call(objects, function (object) {
|
|
667
|
-
var objectKey = _this8.getKeyForObject(object);
|
|
668
|
-
return _this8.pinWithName(objectKey, object._toFullJSON());
|
|
669
|
-
});
|
|
670
|
-
_context13.next = 32;
|
|
671
|
-
return _promise.default.all(pinPromises);
|
|
672
|
-
case 32:
|
|
673
|
-
_this8.isSyncing = false;
|
|
674
|
-
_context13.next = 39;
|
|
675
|
-
break;
|
|
676
|
-
case 35:
|
|
677
|
-
_context13.prev = 35;
|
|
678
|
-
_context13.t0 = _context13["catch"](24);
|
|
679
|
-
console.error('Error syncing LocalDatastore: ', _context13.t0);
|
|
680
|
-
_this8.isSyncing = false;
|
|
681
|
-
case 39:
|
|
682
|
-
case "end":
|
|
683
|
-
return _context13.stop();
|
|
684
|
-
}
|
|
685
|
-
}, _callee8, null, [[24, 35]]);
|
|
686
|
-
}))();
|
|
307
|
+
async updateFromServer() {
|
|
308
|
+
var _context2;
|
|
309
|
+
if (!this.checkIfEnabled() || this.isSyncing) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const localDatastore = await this._getAllContents();
|
|
313
|
+
const keys = [];
|
|
314
|
+
for (const key in localDatastore) {
|
|
315
|
+
if ((0, _startsWith.default)(key).call(key, _LocalDatastoreUtils.OBJECT_PREFIX)) {
|
|
316
|
+
keys.push(key);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (keys.length === 0) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
this.isSyncing = true;
|
|
323
|
+
const pointersHash = {};
|
|
324
|
+
for (const key of keys) {
|
|
325
|
+
// Ignore the OBJECT_PREFIX
|
|
326
|
+
let [,, className, objectId] = key.split('_');
|
|
327
|
+
|
|
328
|
+
// User key is split into [ 'Parse', 'LDS', '', 'User', 'objectId' ]
|
|
329
|
+
if (key.split('_').length === 5 && key.split('_')[3] === 'User') {
|
|
330
|
+
className = '_User';
|
|
331
|
+
objectId = key.split('_')[4];
|
|
332
|
+
}
|
|
333
|
+
if ((0, _startsWith.default)(objectId).call(objectId, 'local')) {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (!(className in pointersHash)) {
|
|
337
|
+
pointersHash[className] = new _set.default();
|
|
338
|
+
}
|
|
339
|
+
pointersHash[className].add(objectId);
|
|
340
|
+
}
|
|
341
|
+
const queryPromises = (0, _map.default)(_context2 = (0, _keys.default)(pointersHash)).call(_context2, className => {
|
|
342
|
+
const objectIds = (0, _from.default)(pointersHash[className]);
|
|
343
|
+
const query = new _ParseQuery.default(className);
|
|
344
|
+
query.limit(objectIds.length);
|
|
345
|
+
if (objectIds.length === 1) {
|
|
346
|
+
query.equalTo('objectId', objectIds[0]);
|
|
347
|
+
} else {
|
|
348
|
+
query.containedIn('objectId', objectIds);
|
|
349
|
+
}
|
|
350
|
+
return (0, _find.default)(query).call(query);
|
|
351
|
+
});
|
|
352
|
+
try {
|
|
353
|
+
const responses = await _promise.default.all(queryPromises);
|
|
354
|
+
const objects = (0, _concat.default)([]).apply([], responses);
|
|
355
|
+
const pinPromises = (0, _map.default)(objects).call(objects, object => {
|
|
356
|
+
const objectKey = this.getKeyForObject(object);
|
|
357
|
+
return this.pinWithName(objectKey, object._toFullJSON());
|
|
358
|
+
});
|
|
359
|
+
await _promise.default.all(pinPromises);
|
|
360
|
+
this.isSyncing = false;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
console.error('Error syncing LocalDatastore: ', error);
|
|
363
|
+
this.isSyncing = false;
|
|
364
|
+
}
|
|
687
365
|
},
|
|
688
|
-
getKeyForObject
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
return (0, _concat.default)(_context14 = (0, _concat.default)(_context15 = "".concat(_LocalDatastoreUtils.OBJECT_PREFIX)).call(_context15, object.className, "_")).call(_context14, objectId);
|
|
366
|
+
getKeyForObject(object) {
|
|
367
|
+
const objectId = object.objectId || object._getId();
|
|
368
|
+
return `${_LocalDatastoreUtils.OBJECT_PREFIX}${object.className}_${objectId}`;
|
|
692
369
|
},
|
|
693
|
-
getPinName
|
|
370
|
+
getPinName(pinName) {
|
|
694
371
|
if (!pinName || pinName === _LocalDatastoreUtils.DEFAULT_PIN) {
|
|
695
372
|
return _LocalDatastoreUtils.DEFAULT_PIN;
|
|
696
373
|
}
|
|
697
374
|
return _LocalDatastoreUtils.PIN_PREFIX + pinName;
|
|
698
375
|
},
|
|
699
|
-
checkIfEnabled
|
|
376
|
+
checkIfEnabled() {
|
|
700
377
|
if (!this.isEnabled) {
|
|
701
378
|
console.error('Parse.enableLocalDatastore() must be called first');
|
|
702
379
|
}
|
|
@@ -704,7 +381,6 @@ var LocalDatastore = {
|
|
|
704
381
|
}
|
|
705
382
|
};
|
|
706
383
|
module.exports = LocalDatastore;
|
|
707
|
-
var _default = LocalDatastore;
|
|
708
|
-
|
|
709
|
-
_CoreManager.default.setLocalDatastoreController(require('./LocalDatastoreController'));
|
|
384
|
+
var _default = exports.default = LocalDatastore;
|
|
385
|
+
_CoreManager.default.setLocalDatastoreController(_LocalDatastoreController.default);
|
|
710
386
|
_CoreManager.default.setLocalDatastore(LocalDatastore);
|