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,10 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
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", {
|
|
@@ -13,88 +8,20 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
13
8
|
exports.default = void 0;
|
|
14
9
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
15
10
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/map"));
|
|
16
|
-
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
17
11
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/keys"));
|
|
18
12
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
19
13
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
20
14
|
var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/values"));
|
|
21
15
|
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
|
22
16
|
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
|
|
23
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
24
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
|
|
25
17
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
26
18
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
27
19
|
var _ParseObject = _interopRequireDefault(require("./ParseObject"));
|
|
28
20
|
var _LiveQuerySubscription = _interopRequireDefault(require("./LiveQuerySubscription"));
|
|
29
21
|
var _promiseUtils = require("./promiseUtils");
|
|
30
22
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
31
|
-
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
32
|
-
var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"];
|
|
33
|
-
if (!it) {
|
|
34
|
-
if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
35
|
-
if (it) o = it;
|
|
36
|
-
var i = 0;
|
|
37
|
-
var F = function () {};
|
|
38
|
-
return {
|
|
39
|
-
s: F,
|
|
40
|
-
n: function () {
|
|
41
|
-
if (i >= o.length) return {
|
|
42
|
-
done: true
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
done: false,
|
|
46
|
-
value: o[i++]
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
e: function (_e) {
|
|
50
|
-
throw _e;
|
|
51
|
-
},
|
|
52
|
-
f: F
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
56
|
-
}
|
|
57
|
-
var normalCompletion = true,
|
|
58
|
-
didErr = false,
|
|
59
|
-
err;
|
|
60
|
-
return {
|
|
61
|
-
s: function () {
|
|
62
|
-
it = it.call(o);
|
|
63
|
-
},
|
|
64
|
-
n: function () {
|
|
65
|
-
var step = it.next();
|
|
66
|
-
normalCompletion = step.done;
|
|
67
|
-
return step;
|
|
68
|
-
},
|
|
69
|
-
e: function (_e2) {
|
|
70
|
-
didErr = true;
|
|
71
|
-
err = _e2;
|
|
72
|
-
},
|
|
73
|
-
f: function () {
|
|
74
|
-
try {
|
|
75
|
-
if (!normalCompletion && it.return != null) it.return();
|
|
76
|
-
} finally {
|
|
77
|
-
if (didErr) throw err;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
83
|
-
var _context7;
|
|
84
|
-
if (!o) return;
|
|
85
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
86
|
-
var n = _sliceInstanceProperty(_context7 = Object.prototype.toString.call(o)).call(_context7, 8, -1);
|
|
87
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
88
|
-
if (n === "Map" || n === "Set") return _Array$from(o);
|
|
89
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
90
|
-
}
|
|
91
|
-
function _arrayLikeToArray(arr, len) {
|
|
92
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
93
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
94
|
-
return arr2;
|
|
95
|
-
}
|
|
96
23
|
// The LiveQuery client inner state
|
|
97
|
-
|
|
24
|
+
const CLIENT_STATE = {
|
|
98
25
|
INITIALIZED: 'initialized',
|
|
99
26
|
CONNECTING: 'connecting',
|
|
100
27
|
CONNECTED: 'connected',
|
|
@@ -104,7 +31,7 @@ var CLIENT_STATE = {
|
|
|
104
31
|
};
|
|
105
32
|
|
|
106
33
|
// The event type the LiveQuery client should sent to server
|
|
107
|
-
|
|
34
|
+
const OP_TYPES = {
|
|
108
35
|
CONNECT: 'connect',
|
|
109
36
|
SUBSCRIBE: 'subscribe',
|
|
110
37
|
UNSUBSCRIBE: 'unsubscribe',
|
|
@@ -112,7 +39,7 @@ var OP_TYPES = {
|
|
|
112
39
|
};
|
|
113
40
|
|
|
114
41
|
// The event we get back from LiveQuery server
|
|
115
|
-
|
|
42
|
+
const OP_EVENTS = {
|
|
116
43
|
CONNECTED: 'connected',
|
|
117
44
|
SUBSCRIBED: 'subscribed',
|
|
118
45
|
UNSUBSCRIBED: 'unsubscribed',
|
|
@@ -125,14 +52,14 @@ var OP_EVENTS = {
|
|
|
125
52
|
};
|
|
126
53
|
|
|
127
54
|
// The event the LiveQuery client should emit
|
|
128
|
-
|
|
55
|
+
const CLIENT_EMMITER_TYPES = {
|
|
129
56
|
CLOSE: 'close',
|
|
130
57
|
ERROR: 'error',
|
|
131
58
|
OPEN: 'open'
|
|
132
59
|
};
|
|
133
60
|
|
|
134
61
|
// The event the LiveQuery subscription should emit
|
|
135
|
-
|
|
62
|
+
const SUBSCRIPTION_EMMITER_TYPES = {
|
|
136
63
|
OPEN: 'open',
|
|
137
64
|
CLOSE: 'close',
|
|
138
65
|
ERROR: 'error',
|
|
@@ -142,7 +69,7 @@ var SUBSCRIPTION_EMMITER_TYPES = {
|
|
|
142
69
|
LEAVE: 'leave',
|
|
143
70
|
DELETE: 'delete'
|
|
144
71
|
};
|
|
145
|
-
|
|
72
|
+
const generateInterval = k => {
|
|
146
73
|
return Math.random() * Math.min(30, Math.pow(2, k) - 1) * 1000;
|
|
147
74
|
};
|
|
148
75
|
|
|
@@ -159,9 +86,8 @@ var generateInterval = function (k) {
|
|
|
159
86
|
* We expose three events to help you monitor the status of the LiveQueryClient.
|
|
160
87
|
*
|
|
161
88
|
* <pre>
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* let client = new LiveQueryClient({
|
|
89
|
+
* const LiveQueryClient = Parse.LiveQueryClient;
|
|
90
|
+
* const client = new LiveQueryClient({
|
|
165
91
|
* applicationId: '',
|
|
166
92
|
* serverURL: '',
|
|
167
93
|
* javascriptKey: '',
|
|
@@ -189,7 +115,7 @@ var generateInterval = function (k) {
|
|
|
189
115
|
*
|
|
190
116
|
* @alias Parse.LiveQueryClient
|
|
191
117
|
*/
|
|
192
|
-
|
|
118
|
+
class LiveQueryClient {
|
|
193
119
|
/**
|
|
194
120
|
* @param {object} options
|
|
195
121
|
* @param {string} options.applicationId - applicationId of your Parse app
|
|
@@ -199,15 +125,16 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
199
125
|
* @param {string} options.sessionToken (optional)
|
|
200
126
|
* @param {string} options.installationId (optional)
|
|
201
127
|
*/
|
|
202
|
-
|
|
128
|
+
constructor(_ref) {
|
|
203
129
|
var _this = this;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
130
|
+
let {
|
|
131
|
+
applicationId,
|
|
132
|
+
serverURL,
|
|
133
|
+
javascriptKey,
|
|
134
|
+
masterKey,
|
|
135
|
+
sessionToken,
|
|
136
|
+
installationId
|
|
137
|
+
} = _ref;
|
|
211
138
|
(0, _defineProperty2.default)(this, "attempts", void 0);
|
|
212
139
|
(0, _defineProperty2.default)(this, "id", void 0);
|
|
213
140
|
(0, _defineProperty2.default)(this, "requestId", void 0);
|
|
@@ -222,6 +149,10 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
222
149
|
(0, _defineProperty2.default)(this, "subscriptions", void 0);
|
|
223
150
|
(0, _defineProperty2.default)(this, "socket", void 0);
|
|
224
151
|
(0, _defineProperty2.default)(this, "state", void 0);
|
|
152
|
+
(0, _defineProperty2.default)(this, "reconnectHandle", void 0);
|
|
153
|
+
(0, _defineProperty2.default)(this, "emitter", void 0);
|
|
154
|
+
(0, _defineProperty2.default)(this, "on", void 0);
|
|
155
|
+
(0, _defineProperty2.default)(this, "emit", void 0);
|
|
225
156
|
if (!serverURL || (0, _indexOf.default)(serverURL).call(serverURL, 'ws') !== 0) {
|
|
226
157
|
throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
|
|
227
158
|
}
|
|
@@ -239,400 +170,335 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
239
170
|
this.connectPromise = (0, _promiseUtils.resolvingPromise)();
|
|
240
171
|
this.subscriptions = new _map.default();
|
|
241
172
|
this.state = CLIENT_STATE.INITIALIZED;
|
|
242
|
-
|
|
173
|
+
const EventEmitter = _CoreManager.default.getEventEmitter();
|
|
243
174
|
this.emitter = new EventEmitter();
|
|
244
|
-
this.on =
|
|
245
|
-
return _this.emitter.on(eventName, listener);
|
|
246
|
-
};
|
|
175
|
+
this.on = (eventName, listener) => this.emitter.on(eventName, listener);
|
|
247
176
|
this.emit = function (eventName) {
|
|
248
|
-
var _this$emitter, _context;
|
|
249
177
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
250
178
|
args[_key - 1] = arguments[_key];
|
|
251
179
|
}
|
|
252
|
-
return
|
|
180
|
+
return _this.emitter.emit(eventName, ...args);
|
|
253
181
|
};
|
|
254
182
|
// adding listener so process does not crash
|
|
255
183
|
// best practice is for developer to register their own listener
|
|
256
|
-
this.on('error',
|
|
184
|
+
this.on('error', () => {});
|
|
185
|
+
}
|
|
186
|
+
shouldOpen() {
|
|
187
|
+
return this.state === CLIENT_STATE.INITIALIZED || this.state === CLIENT_STATE.DISCONNECTED;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Subscribes to a ParseQuery
|
|
192
|
+
*
|
|
193
|
+
* If you provide the sessionToken, when the LiveQuery server gets ParseObject's
|
|
194
|
+
* updates from parse server, it'll try to check whether the sessionToken fulfills
|
|
195
|
+
* the ParseObject's ACL. The LiveQuery server will only send updates to clients whose
|
|
196
|
+
* sessionToken is fit for the ParseObject's ACL. You can check the LiveQuery protocol
|
|
197
|
+
* <a href="https://github.com/parse-community/parse-server/wiki/Parse-LiveQuery-Protocol-Specification">here</a> for more details. The subscription you get is the same subscription you get
|
|
198
|
+
* from our Standard API.
|
|
199
|
+
*
|
|
200
|
+
* @param {ParseQuery} query - the ParseQuery you want to subscribe to
|
|
201
|
+
* @param {string} sessionToken (optional)
|
|
202
|
+
* @returns {LiveQuerySubscription | undefined}
|
|
203
|
+
*/
|
|
204
|
+
subscribe(query, sessionToken) {
|
|
205
|
+
if (!query) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const className = query.className;
|
|
209
|
+
const queryJSON = query.toJSON();
|
|
210
|
+
const where = queryJSON.where;
|
|
211
|
+
const keys = (0, _keys.default)(queryJSON)?.split(',');
|
|
212
|
+
const watch = queryJSON.watch?.split(',');
|
|
213
|
+
const subscribeRequest = {
|
|
214
|
+
op: OP_TYPES.SUBSCRIBE,
|
|
215
|
+
requestId: this.requestId,
|
|
216
|
+
query: {
|
|
217
|
+
className,
|
|
218
|
+
where,
|
|
219
|
+
keys,
|
|
220
|
+
watch
|
|
221
|
+
},
|
|
222
|
+
sessionToken: undefined
|
|
223
|
+
};
|
|
224
|
+
if (sessionToken) {
|
|
225
|
+
subscribeRequest.sessionToken = sessionToken;
|
|
226
|
+
}
|
|
227
|
+
const subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken);
|
|
228
|
+
this.subscriptions.set(this.requestId, subscription);
|
|
229
|
+
this.requestId += 1;
|
|
230
|
+
this.connectPromise.then(() => {
|
|
231
|
+
this.socket.send((0, _stringify.default)(subscribeRequest));
|
|
232
|
+
}).catch(error => {
|
|
233
|
+
subscription.subscribePromise.reject(error);
|
|
234
|
+
});
|
|
235
|
+
return subscription;
|
|
257
236
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* After calling unsubscribe you'll stop receiving events from the subscription object.
|
|
240
|
+
*
|
|
241
|
+
* @param {object} subscription - subscription you would like to unsubscribe from.
|
|
242
|
+
* @returns {Promise | undefined}
|
|
243
|
+
*/
|
|
244
|
+
async unsubscribe(subscription) {
|
|
245
|
+
if (!subscription) {
|
|
246
|
+
return;
|
|
262
247
|
}
|
|
248
|
+
const unsubscribeRequest = {
|
|
249
|
+
op: OP_TYPES.UNSUBSCRIBE,
|
|
250
|
+
requestId: subscription.id
|
|
251
|
+
};
|
|
252
|
+
return this.connectPromise.then(() => {
|
|
253
|
+
return this.socket.send((0, _stringify.default)(unsubscribeRequest));
|
|
254
|
+
}).then(() => {
|
|
255
|
+
return subscription.unsubscribePromise;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
263
258
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
259
|
+
/**
|
|
260
|
+
* After open is called, the LiveQueryClient will try to send a connect request
|
|
261
|
+
* to the LiveQuery server.
|
|
262
|
+
*
|
|
263
|
+
*/
|
|
264
|
+
open() {
|
|
265
|
+
const WebSocketImplementation = _CoreManager.default.getWebSocketController();
|
|
266
|
+
if (!WebSocketImplementation) {
|
|
267
|
+
this.emit(CLIENT_EMMITER_TYPES.ERROR, 'Can not find WebSocket implementation');
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (this.state !== CLIENT_STATE.RECONNECTING) {
|
|
271
|
+
this.state = CLIENT_STATE.CONNECTING;
|
|
272
|
+
}
|
|
273
|
+
this.socket = new WebSocketImplementation(this.serverURL);
|
|
274
|
+
this.socket.closingPromise = (0, _promiseUtils.resolvingPromise)();
|
|
275
|
+
|
|
276
|
+
// Bind WebSocket callbacks
|
|
277
|
+
this.socket.onopen = () => {
|
|
278
|
+
this._handleWebSocketOpen();
|
|
279
|
+
};
|
|
280
|
+
this.socket.onmessage = event => {
|
|
281
|
+
this._handleWebSocketMessage(event);
|
|
282
|
+
};
|
|
283
|
+
this.socket.onclose = event => {
|
|
284
|
+
this.socket.closingPromise?.resolve(event);
|
|
285
|
+
this._handleWebSocketClose();
|
|
286
|
+
};
|
|
287
|
+
this.socket.onerror = error => {
|
|
288
|
+
this._handleWebSocketError(error);
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
resubscribe() {
|
|
292
|
+
var _context;
|
|
293
|
+
(0, _forEach.default)(_context = this.subscriptions).call(_context, (subscription, requestId) => {
|
|
294
|
+
const query = subscription.query;
|
|
295
|
+
const queryJSON = query.toJSON();
|
|
296
|
+
const where = queryJSON.where;
|
|
297
|
+
const fields = (0, _keys.default)(queryJSON) ? (0, _keys.default)(queryJSON).split(',') : undefined;
|
|
298
|
+
const className = query.className;
|
|
299
|
+
const sessionToken = subscription.sessionToken;
|
|
300
|
+
const subscribeRequest = {
|
|
293
301
|
op: OP_TYPES.SUBSCRIBE,
|
|
294
|
-
requestId
|
|
302
|
+
requestId,
|
|
295
303
|
query: {
|
|
296
|
-
className
|
|
297
|
-
where
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
304
|
+
className,
|
|
305
|
+
where,
|
|
306
|
+
fields
|
|
307
|
+
},
|
|
308
|
+
sessionToken: undefined
|
|
301
309
|
};
|
|
302
310
|
if (sessionToken) {
|
|
303
311
|
subscribeRequest.sessionToken = sessionToken;
|
|
304
312
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.requestId += 1;
|
|
308
|
-
this.connectPromise.then(function () {
|
|
309
|
-
_this2.socket.send((0, _stringify.default)(subscribeRequest));
|
|
310
|
-
}).catch(function (error) {
|
|
311
|
-
subscription.subscribePromise.reject(error);
|
|
313
|
+
this.connectPromise.then(() => {
|
|
314
|
+
this.socket.send((0, _stringify.default)(subscribeRequest));
|
|
312
315
|
});
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* After calling unsubscribe you'll stop receiving events from the subscription object.
|
|
318
|
-
*
|
|
319
|
-
* @param {object} subscription - subscription you would like to unsubscribe from.
|
|
320
|
-
* @returns {Promise | undefined}
|
|
321
|
-
*/
|
|
322
|
-
}, {
|
|
323
|
-
key: "unsubscribe",
|
|
324
|
-
value: function (subscription /*: Object*/) /*: ?Promise*/{
|
|
325
|
-
var _this3 = this;
|
|
326
|
-
if (!subscription) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
var unsubscribeRequest = {
|
|
330
|
-
op: OP_TYPES.UNSUBSCRIBE,
|
|
331
|
-
requestId: subscription.id
|
|
332
|
-
};
|
|
333
|
-
return this.connectPromise.then(function () {
|
|
334
|
-
return _this3.socket.send((0, _stringify.default)(unsubscribeRequest));
|
|
335
|
-
}).then(function () {
|
|
336
|
-
return subscription.unsubscribePromise;
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* After open is called, the LiveQueryClient will try to send a connect request
|
|
342
|
-
* to the LiveQuery server.
|
|
343
|
-
*
|
|
344
|
-
*/
|
|
345
|
-
}, {
|
|
346
|
-
key: "open",
|
|
347
|
-
value: function () {
|
|
348
|
-
var _this4 = this;
|
|
349
|
-
var WebSocketImplementation = _CoreManager.default.getWebSocketController();
|
|
350
|
-
if (!WebSocketImplementation) {
|
|
351
|
-
this.emit(CLIENT_EMMITER_TYPES.ERROR, 'Can not find WebSocket implementation');
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
if (this.state !== CLIENT_STATE.RECONNECTING) {
|
|
355
|
-
this.state = CLIENT_STATE.CONNECTING;
|
|
356
|
-
}
|
|
357
|
-
this.socket = new WebSocketImplementation(this.serverURL);
|
|
358
|
-
this.socket.closingPromise = (0, _promiseUtils.resolvingPromise)();
|
|
316
|
+
});
|
|
317
|
+
}
|
|
359
318
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
_this4._handleWebSocketClose();
|
|
370
|
-
};
|
|
371
|
-
this.socket.onerror = function (error) {
|
|
372
|
-
_this4._handleWebSocketError(error);
|
|
373
|
-
};
|
|
319
|
+
/**
|
|
320
|
+
* This method will close the WebSocket connection to this LiveQueryClient,
|
|
321
|
+
* cancel the auto reconnect and unsubscribe all subscriptions based on it.
|
|
322
|
+
*
|
|
323
|
+
* @returns {Promise | undefined} CloseEvent {@link https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close_event}
|
|
324
|
+
*/
|
|
325
|
+
async close() {
|
|
326
|
+
if (this.state === CLIENT_STATE.INITIALIZED || this.state === CLIENT_STATE.DISCONNECTED) {
|
|
327
|
+
return;
|
|
374
328
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
var queryJSON = query.toJSON();
|
|
383
|
-
var where = queryJSON.where;
|
|
384
|
-
var fields = (0, _keys.default)(queryJSON) ? (0, _keys.default)(queryJSON).split(',') : undefined;
|
|
385
|
-
var className = query.className;
|
|
386
|
-
var sessionToken = subscription.sessionToken;
|
|
387
|
-
var subscribeRequest = {
|
|
388
|
-
op: OP_TYPES.SUBSCRIBE,
|
|
389
|
-
requestId: requestId,
|
|
390
|
-
query: {
|
|
391
|
-
className: className,
|
|
392
|
-
where: where,
|
|
393
|
-
fields: fields
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
if (sessionToken) {
|
|
397
|
-
subscribeRequest.sessionToken = sessionToken;
|
|
398
|
-
}
|
|
399
|
-
_this5.connectPromise.then(function () {
|
|
400
|
-
_this5.socket.send((0, _stringify.default)(subscribeRequest));
|
|
401
|
-
});
|
|
402
|
-
});
|
|
329
|
+
this.state = CLIENT_STATE.DISCONNECTED;
|
|
330
|
+
this.socket?.close();
|
|
331
|
+
// Notify each subscription about the close
|
|
332
|
+
for (const subscription of (0, _values.default)(_context2 = this.subscriptions).call(_context2)) {
|
|
333
|
+
var _context2;
|
|
334
|
+
subscription.subscribed = false;
|
|
335
|
+
subscription.emit(SUBSCRIPTION_EMMITER_TYPES.CLOSE);
|
|
403
336
|
}
|
|
337
|
+
this._handleReset();
|
|
338
|
+
this.emit(CLIENT_EMMITER_TYPES.CLOSE);
|
|
339
|
+
return this.socket?.closingPromise;
|
|
340
|
+
}
|
|
404
341
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
this.
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
var subscription = _step.value;
|
|
426
|
-
subscription.subscribed = false;
|
|
427
|
-
subscription.emit(SUBSCRIPTION_EMMITER_TYPES.CLOSE);
|
|
428
|
-
}
|
|
429
|
-
} catch (err) {
|
|
430
|
-
_iterator.e(err);
|
|
431
|
-
} finally {
|
|
432
|
-
_iterator.f();
|
|
433
|
-
}
|
|
434
|
-
this._handleReset();
|
|
435
|
-
this.emit(CLIENT_EMMITER_TYPES.CLOSE);
|
|
436
|
-
return (_this$socket2 = this.socket) === null || _this$socket2 === void 0 ? void 0 : _this$socket2.closingPromise;
|
|
342
|
+
// ensure we start with valid state if connect is called again after close
|
|
343
|
+
_handleReset() {
|
|
344
|
+
this.attempts = 1;
|
|
345
|
+
this.id = 0;
|
|
346
|
+
this.requestId = 1;
|
|
347
|
+
this.connectPromise = (0, _promiseUtils.resolvingPromise)();
|
|
348
|
+
this.subscriptions = new _map.default();
|
|
349
|
+
}
|
|
350
|
+
_handleWebSocketOpen() {
|
|
351
|
+
this.attempts = 1;
|
|
352
|
+
const connectRequest = {
|
|
353
|
+
op: OP_TYPES.CONNECT,
|
|
354
|
+
applicationId: this.applicationId,
|
|
355
|
+
javascriptKey: this.javascriptKey,
|
|
356
|
+
masterKey: this.masterKey,
|
|
357
|
+
sessionToken: this.sessionToken,
|
|
358
|
+
installationId: undefined
|
|
359
|
+
};
|
|
360
|
+
if (this.additionalProperties) {
|
|
361
|
+
connectRequest.installationId = this.installationId;
|
|
437
362
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
this.id = 0;
|
|
445
|
-
this.requestId = 1;
|
|
446
|
-
this.connectPromise = (0, _promiseUtils.resolvingPromise)();
|
|
447
|
-
this.subscriptions = new _map.default();
|
|
363
|
+
this.socket.send((0, _stringify.default)(connectRequest));
|
|
364
|
+
}
|
|
365
|
+
_handleWebSocketMessage(event) {
|
|
366
|
+
let data = event.data;
|
|
367
|
+
if (typeof data === 'string') {
|
|
368
|
+
data = JSON.parse(data);
|
|
448
369
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
this.attempts = 1;
|
|
453
|
-
var connectRequest = {
|
|
454
|
-
op: OP_TYPES.CONNECT,
|
|
455
|
-
applicationId: this.applicationId,
|
|
456
|
-
javascriptKey: this.javascriptKey,
|
|
457
|
-
masterKey: this.masterKey,
|
|
458
|
-
sessionToken: this.sessionToken
|
|
459
|
-
};
|
|
460
|
-
if (this.additionalProperties) {
|
|
461
|
-
connectRequest.installationId = this.installationId;
|
|
462
|
-
}
|
|
463
|
-
this.socket.send((0, _stringify.default)(connectRequest));
|
|
370
|
+
let subscription = null;
|
|
371
|
+
if (data.requestId) {
|
|
372
|
+
subscription = this.subscriptions.get(data.requestId) || null;
|
|
464
373
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
374
|
+
const response = {
|
|
375
|
+
clientId: data.clientId,
|
|
376
|
+
installationId: data.installationId
|
|
377
|
+
};
|
|
378
|
+
switch (data.op) {
|
|
379
|
+
case OP_EVENTS.CONNECTED:
|
|
380
|
+
if (this.state === CLIENT_STATE.RECONNECTING) {
|
|
381
|
+
this.resubscribe();
|
|
382
|
+
}
|
|
383
|
+
this.emit(CLIENT_EMMITER_TYPES.OPEN);
|
|
384
|
+
this.id = data.clientId;
|
|
385
|
+
this.connectPromise.resolve();
|
|
386
|
+
this.state = CLIENT_STATE.CONNECTED;
|
|
387
|
+
break;
|
|
388
|
+
case OP_EVENTS.SUBSCRIBED:
|
|
389
|
+
if (subscription) {
|
|
390
|
+
subscription.subscribed = true;
|
|
391
|
+
subscription.subscribePromise.resolve();
|
|
392
|
+
(0, _setTimeout2.default)(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response), 200);
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
case OP_EVENTS.ERROR:
|
|
396
|
+
{
|
|
397
|
+
const parseError = new _ParseError.default(data.code, data.error);
|
|
398
|
+
if (!this.id) {
|
|
399
|
+
this.connectPromise.reject(parseError);
|
|
400
|
+
this.state = CLIENT_STATE.DISCONNECTED;
|
|
401
|
+
}
|
|
402
|
+
if (data.requestId) {
|
|
403
|
+
if (subscription) {
|
|
404
|
+
subscription.subscribePromise.reject(parseError);
|
|
405
|
+
(0, _setTimeout2.default)(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error), 200);
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
this.emit(CLIENT_EMMITER_TYPES.ERROR, data.error);
|
|
409
|
+
}
|
|
410
|
+
if (data.error === 'Additional properties not allowed') {
|
|
411
|
+
this.additionalProperties = false;
|
|
412
|
+
}
|
|
413
|
+
if (data.reconnect) {
|
|
414
|
+
this._handleReconnect();
|
|
484
415
|
}
|
|
485
|
-
this.emit(CLIENT_EMMITER_TYPES.OPEN);
|
|
486
|
-
this.id = data.clientId;
|
|
487
|
-
this.connectPromise.resolve();
|
|
488
|
-
this.state = CLIENT_STATE.CONNECTED;
|
|
489
416
|
break;
|
|
490
|
-
|
|
417
|
+
}
|
|
418
|
+
case OP_EVENTS.UNSUBSCRIBED:
|
|
419
|
+
{
|
|
491
420
|
if (subscription) {
|
|
492
|
-
|
|
493
|
-
subscription.
|
|
494
|
-
|
|
495
|
-
return subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response);
|
|
496
|
-
}, 200);
|
|
421
|
+
this.subscriptions.delete(data.requestId);
|
|
422
|
+
subscription.subscribed = false;
|
|
423
|
+
subscription.unsubscribePromise.resolve();
|
|
497
424
|
}
|
|
498
425
|
break;
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
this.state = CLIENT_STATE.DISCONNECTED;
|
|
505
|
-
}
|
|
506
|
-
if (data.requestId) {
|
|
507
|
-
if (subscription) {
|
|
508
|
-
subscription.subscribePromise.reject(parseError);
|
|
509
|
-
(0, _setTimeout2.default)(function () {
|
|
510
|
-
return subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error);
|
|
511
|
-
}, 200);
|
|
512
|
-
}
|
|
513
|
-
} else {
|
|
514
|
-
this.emit(CLIENT_EMMITER_TYPES.ERROR, data.error);
|
|
515
|
-
}
|
|
516
|
-
if (data.error === 'Additional properties not allowed') {
|
|
517
|
-
this.additionalProperties = false;
|
|
518
|
-
}
|
|
519
|
-
if (data.reconnect) {
|
|
520
|
-
this._handleReconnect();
|
|
521
|
-
}
|
|
522
|
-
break;
|
|
523
|
-
}
|
|
524
|
-
case OP_EVENTS.UNSUBSCRIBED:
|
|
525
|
-
{
|
|
526
|
-
if (subscription) {
|
|
527
|
-
this.subscriptions.delete(data.requestId);
|
|
528
|
-
subscription.subscribed = false;
|
|
529
|
-
subscription.unsubscribePromise.resolve();
|
|
530
|
-
}
|
|
426
|
+
}
|
|
427
|
+
default:
|
|
428
|
+
{
|
|
429
|
+
// create, update, enter, leave, delete cases
|
|
430
|
+
if (!subscription) {
|
|
531
431
|
break;
|
|
532
432
|
}
|
|
533
|
-
|
|
534
|
-
{
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
override = true;
|
|
542
|
-
delete data.original.__type;
|
|
543
|
-
// Check for removed fields
|
|
544
|
-
for (var field in data.original) {
|
|
545
|
-
if (!(field in data.object)) {
|
|
546
|
-
data.object[field] = undefined;
|
|
547
|
-
}
|
|
433
|
+
let override = false;
|
|
434
|
+
if (data.original) {
|
|
435
|
+
override = true;
|
|
436
|
+
delete data.original.__type;
|
|
437
|
+
// Check for removed fields
|
|
438
|
+
for (const field in data.original) {
|
|
439
|
+
if (!(field in data.object)) {
|
|
440
|
+
data.object[field] = undefined;
|
|
548
441
|
}
|
|
549
|
-
data.original = _ParseObject.default.fromJSON(data.original, false);
|
|
550
|
-
}
|
|
551
|
-
delete data.object.__type;
|
|
552
|
-
var parseObject = _ParseObject.default.fromJSON(data.object, !(subscription.query && subscription.query._select) ? override : false);
|
|
553
|
-
if (data.original) {
|
|
554
|
-
subscription.emit(data.op, parseObject, data.original, response);
|
|
555
|
-
} else {
|
|
556
|
-
subscription.emit(data.op, parseObject, response);
|
|
557
|
-
}
|
|
558
|
-
var localDatastore = _CoreManager.default.getLocalDatastore();
|
|
559
|
-
if (override && localDatastore.isEnabled) {
|
|
560
|
-
localDatastore._updateObjectIfPinned(parseObject).then(function () {});
|
|
561
442
|
}
|
|
443
|
+
data.original = _ParseObject.default.fromJSON(data.original, false);
|
|
562
444
|
}
|
|
563
|
-
|
|
445
|
+
delete data.object.__type;
|
|
446
|
+
const parseObject = _ParseObject.default.fromJSON(data.object, !(subscription.query && subscription.query._select) ? override : false);
|
|
447
|
+
if (data.original) {
|
|
448
|
+
subscription.emit(data.op, parseObject, data.original, response);
|
|
449
|
+
} else {
|
|
450
|
+
subscription.emit(data.op, parseObject, response);
|
|
451
|
+
}
|
|
452
|
+
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
453
|
+
if (override && localDatastore.isEnabled) {
|
|
454
|
+
localDatastore._updateObjectIfPinned(parseObject).then(() => {});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
564
457
|
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
|
|
458
|
+
}
|
|
459
|
+
_handleWebSocketClose() {
|
|
460
|
+
if (this.state === CLIENT_STATE.DISCONNECTED) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
this.state = CLIENT_STATE.CLOSED;
|
|
464
|
+
this.emit(CLIENT_EMMITER_TYPES.CLOSE);
|
|
465
|
+
// Notify each subscription about the close
|
|
466
|
+
for (const subscription of (0, _values.default)(_context3 = this.subscriptions).call(_context3)) {
|
|
467
|
+
var _context3;
|
|
468
|
+
subscription.emit(SUBSCRIPTION_EMMITER_TYPES.CLOSE);
|
|
469
|
+
}
|
|
470
|
+
this._handleReconnect();
|
|
471
|
+
}
|
|
472
|
+
_handleWebSocketError(error) {
|
|
473
|
+
this.emit(CLIENT_EMMITER_TYPES.ERROR, error);
|
|
474
|
+
for (const subscription of (0, _values.default)(_context4 = this.subscriptions).call(_context4)) {
|
|
568
475
|
var _context4;
|
|
569
|
-
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
this.state = CLIENT_STATE.CLOSED;
|
|
573
|
-
this.emit(CLIENT_EMMITER_TYPES.CLOSE);
|
|
574
|
-
// Notify each subscription about the close
|
|
575
|
-
var _iterator2 = _createForOfIteratorHelper((0, _values.default)(_context4 = this.subscriptions).call(_context4)),
|
|
576
|
-
_step2;
|
|
577
|
-
try {
|
|
578
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
579
|
-
var subscription = _step2.value;
|
|
580
|
-
subscription.emit(SUBSCRIPTION_EMMITER_TYPES.CLOSE);
|
|
581
|
-
}
|
|
582
|
-
} catch (err) {
|
|
583
|
-
_iterator2.e(err);
|
|
584
|
-
} finally {
|
|
585
|
-
_iterator2.f();
|
|
586
|
-
}
|
|
587
|
-
this._handleReconnect();
|
|
476
|
+
subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, error);
|
|
588
477
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
try {
|
|
597
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
598
|
-
var subscription = _step3.value;
|
|
599
|
-
subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, error);
|
|
600
|
-
}
|
|
601
|
-
} catch (err) {
|
|
602
|
-
_iterator3.e(err);
|
|
603
|
-
} finally {
|
|
604
|
-
_iterator3.f();
|
|
605
|
-
}
|
|
606
|
-
this._handleReconnect();
|
|
478
|
+
this._handleReconnect();
|
|
479
|
+
}
|
|
480
|
+
_handleReconnect() {
|
|
481
|
+
var _context5;
|
|
482
|
+
// if closed or currently reconnecting we stop attempting to reconnect
|
|
483
|
+
if (this.state === CLIENT_STATE.DISCONNECTED) {
|
|
484
|
+
return;
|
|
607
485
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
value: function () {
|
|
611
|
-
var _context6,
|
|
612
|
-
_this6 = this;
|
|
613
|
-
// if closed or currently reconnecting we stop attempting to reconnect
|
|
614
|
-
if (this.state === CLIENT_STATE.DISCONNECTED) {
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
this.state = CLIENT_STATE.RECONNECTING;
|
|
618
|
-
var time = generateInterval(this.attempts);
|
|
486
|
+
this.state = CLIENT_STATE.RECONNECTING;
|
|
487
|
+
const time = generateInterval(this.attempts);
|
|
619
488
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
489
|
+
// handle case when both close/error occur at frequent rates we ensure we do not reconnect unnecessarily.
|
|
490
|
+
// we're unable to distinguish different between close/error when we're unable to reconnect therefore
|
|
491
|
+
// we try to reconnect in both cases
|
|
492
|
+
// server side ws and browser WebSocket behave differently in when close/error get triggered
|
|
624
493
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
}
|
|
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);
|
|
494
|
+
if (this.reconnectHandle) {
|
|
495
|
+
clearTimeout(this.reconnectHandle);
|
|
633
496
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
497
|
+
this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context5 = () => {
|
|
498
|
+
this.attempts++;
|
|
499
|
+
this.connectPromise = (0, _promiseUtils.resolvingPromise)();
|
|
500
|
+
this.open();
|
|
501
|
+
}).call(_context5, this), time);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
var _default = exports.default = LiveQueryClient;
|