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