parse 5.1.0-alpha.3 → 5.1.0-alpha.5
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 +101 -68
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +101 -68
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/CoreManager.js +1 -1
- package/lib/browser/LiveQueryClient.js +42 -32
- package/lib/browser/LiveQuerySubscription.js +15 -5
- package/lib/browser/ParseLiveQuery.js +32 -23
- package/lib/browser/RESTController.js +6 -2
- package/lib/node/CoreManager.js +1 -1
- package/lib/node/LiveQueryClient.js +2 -2
- package/lib/node/LiveQuerySubscription.js +2 -2
- package/lib/node/ParseLiveQuery.js +2 -3
- package/lib/node/RESTController.js +5 -2
- package/lib/react-native/CoreManager.js +1 -1
- package/lib/react-native/LiveQueryClient.js +28 -19
- package/lib/react-native/LiveQuerySubscription.js +14 -5
- package/lib/react-native/ParseLiveQuery.js +11 -2
- package/lib/react-native/RESTController.js +5 -2
- package/lib/weapp/CoreManager.js +1 -1
- package/lib/weapp/LiveQueryClient.js +42 -32
- package/lib/weapp/LiveQuerySubscription.js +15 -5
- package/lib/weapp/ParseLiveQuery.js +32 -23
- package/lib/weapp/RESTController.js +6 -2
- package/package.json +1 -1
|
@@ -187,7 +187,7 @@ var config /*: Config & { [key: string]: mixed }*/ = {
|
|
|
187
187
|
SERVER_AUTH_TOKEN: null,
|
|
188
188
|
LIVEQUERY_SERVER_URL: null,
|
|
189
189
|
ENCRYPTED_KEY: null,
|
|
190
|
-
VERSION: 'js' + "5.1.0-alpha.
|
|
190
|
+
VERSION: 'js' + "5.1.0-alpha.5",
|
|
191
191
|
APPLICATION_ID: null,
|
|
192
192
|
JAVASCRIPT_KEY: null,
|
|
193
193
|
MASTER_KEY: null,
|
|
@@ -13,6 +13,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
13
13
|
exports.default = void 0;
|
|
14
14
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
15
15
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/map"));
|
|
16
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
16
17
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/keys"));
|
|
17
18
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
18
19
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
@@ -79,10 +80,10 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
79
80
|
};
|
|
80
81
|
}
|
|
81
82
|
function _unsupportedIterableToArray(o, minLen) {
|
|
82
|
-
var
|
|
83
|
+
var _context7;
|
|
83
84
|
if (!o) return;
|
|
84
85
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
85
|
-
var n = _sliceInstanceProperty(
|
|
86
|
+
var n = _sliceInstanceProperty(_context7 = Object.prototype.toString.call(o)).call(_context7, 8, -1);
|
|
86
87
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
87
88
|
if (n === "Map" || n === "Set") return _Array$from(o);
|
|
88
89
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
@@ -199,6 +200,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
199
200
|
* @param {string} options.installationId (optional)
|
|
200
201
|
*/
|
|
201
202
|
function LiveQueryClient(_ref) {
|
|
203
|
+
var _this = this;
|
|
202
204
|
var applicationId = _ref.applicationId,
|
|
203
205
|
serverURL = _ref.serverURL,
|
|
204
206
|
javascriptKey = _ref.javascriptKey,
|
|
@@ -239,8 +241,16 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
239
241
|
this.state = CLIENT_STATE.INITIALIZED;
|
|
240
242
|
var EventEmitter = _CoreManager.default.getEventEmitter();
|
|
241
243
|
this.emitter = new EventEmitter();
|
|
242
|
-
this.on =
|
|
243
|
-
|
|
244
|
+
this.on = function (eventName, listener) {
|
|
245
|
+
return _this.emitter.on(eventName, listener);
|
|
246
|
+
};
|
|
247
|
+
this.emit = function (eventName) {
|
|
248
|
+
var _this$emitter, _context;
|
|
249
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
250
|
+
args[_key - 1] = arguments[_key];
|
|
251
|
+
}
|
|
252
|
+
return (_this$emitter = _this.emitter).emit.apply(_this$emitter, (0, _concat.default)(_context = [eventName]).call(_context, args));
|
|
253
|
+
};
|
|
244
254
|
// adding listener so process does not crash
|
|
245
255
|
// best practice is for developer to register their own listener
|
|
246
256
|
this.on('error', function () {});
|
|
@@ -270,7 +280,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
270
280
|
value: function (query /*: Object*/, sessionToken /*: ?string*/) /*: LiveQuerySubscription*/{
|
|
271
281
|
var _queryJSON$keys,
|
|
272
282
|
_queryJSON$watch,
|
|
273
|
-
|
|
283
|
+
_this2 = this;
|
|
274
284
|
if (!query) {
|
|
275
285
|
return;
|
|
276
286
|
}
|
|
@@ -296,7 +306,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
296
306
|
this.subscriptions.set(this.requestId, subscription);
|
|
297
307
|
this.requestId += 1;
|
|
298
308
|
this.connectPromise.then(function () {
|
|
299
|
-
|
|
309
|
+
_this2.socket.send((0, _stringify.default)(subscribeRequest));
|
|
300
310
|
}).catch(function (error) {
|
|
301
311
|
subscription.subscribePromise.reject(error);
|
|
302
312
|
});
|
|
@@ -312,7 +322,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
312
322
|
}, {
|
|
313
323
|
key: "unsubscribe",
|
|
314
324
|
value: function (subscription /*: Object*/) /*: ?Promise*/{
|
|
315
|
-
var
|
|
325
|
+
var _this3 = this;
|
|
316
326
|
if (!subscription) {
|
|
317
327
|
return;
|
|
318
328
|
}
|
|
@@ -321,7 +331,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
321
331
|
requestId: subscription.id
|
|
322
332
|
};
|
|
323
333
|
return this.connectPromise.then(function () {
|
|
324
|
-
return
|
|
334
|
+
return _this3.socket.send((0, _stringify.default)(unsubscribeRequest));
|
|
325
335
|
}).then(function () {
|
|
326
336
|
return subscription.unsubscribePromise;
|
|
327
337
|
});
|
|
@@ -335,7 +345,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
335
345
|
}, {
|
|
336
346
|
key: "open",
|
|
337
347
|
value: function () {
|
|
338
|
-
var
|
|
348
|
+
var _this4 = this;
|
|
339
349
|
var WebSocketImplementation = _CoreManager.default.getWebSocketController();
|
|
340
350
|
if (!WebSocketImplementation) {
|
|
341
351
|
this.emit(CLIENT_EMMITER_TYPES.ERROR, 'Can not find WebSocket implementation');
|
|
@@ -349,25 +359,25 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
349
359
|
|
|
350
360
|
// Bind WebSocket callbacks
|
|
351
361
|
this.socket.onopen = function () {
|
|
352
|
-
|
|
362
|
+
_this4._handleWebSocketOpen();
|
|
353
363
|
};
|
|
354
364
|
this.socket.onmessage = function (event) {
|
|
355
|
-
|
|
365
|
+
_this4._handleWebSocketMessage(event);
|
|
356
366
|
};
|
|
357
367
|
this.socket.onclose = function (event) {
|
|
358
|
-
|
|
359
|
-
|
|
368
|
+
_this4.socket.closingPromise.resolve(event);
|
|
369
|
+
_this4._handleWebSocketClose();
|
|
360
370
|
};
|
|
361
371
|
this.socket.onerror = function (error) {
|
|
362
|
-
|
|
372
|
+
_this4._handleWebSocketError(error);
|
|
363
373
|
};
|
|
364
374
|
}
|
|
365
375
|
}, {
|
|
366
376
|
key: "resubscribe",
|
|
367
377
|
value: function () {
|
|
368
|
-
var
|
|
369
|
-
|
|
370
|
-
(0, _forEach.default)(
|
|
378
|
+
var _context2,
|
|
379
|
+
_this5 = this;
|
|
380
|
+
(0, _forEach.default)(_context2 = this.subscriptions).call(_context2, function (subscription, requestId) {
|
|
371
381
|
var query = subscription.query;
|
|
372
382
|
var queryJSON = query.toJSON();
|
|
373
383
|
var where = queryJSON.where;
|
|
@@ -386,8 +396,8 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
386
396
|
if (sessionToken) {
|
|
387
397
|
subscribeRequest.sessionToken = sessionToken;
|
|
388
398
|
}
|
|
389
|
-
|
|
390
|
-
|
|
399
|
+
_this5.connectPromise.then(function () {
|
|
400
|
+
_this5.socket.send((0, _stringify.default)(subscribeRequest));
|
|
391
401
|
});
|
|
392
402
|
});
|
|
393
403
|
}
|
|
@@ -401,14 +411,14 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
401
411
|
}, {
|
|
402
412
|
key: "close",
|
|
403
413
|
value: function () /*: ?Promise*/{
|
|
404
|
-
var _this$socket, _this$socket2,
|
|
414
|
+
var _this$socket, _this$socket2, _context3;
|
|
405
415
|
if (this.state === CLIENT_STATE.INITIALIZED || this.state === CLIENT_STATE.DISCONNECTED) {
|
|
406
416
|
return;
|
|
407
417
|
}
|
|
408
418
|
this.state = CLIENT_STATE.DISCONNECTED;
|
|
409
419
|
(_this$socket = this.socket) === null || _this$socket === void 0 ? void 0 : _this$socket.close();
|
|
410
420
|
// Notify each subscription about the close
|
|
411
|
-
var _iterator = _createForOfIteratorHelper((0, _values.default)(
|
|
421
|
+
var _iterator = _createForOfIteratorHelper((0, _values.default)(_context3 = this.subscriptions).call(_context3)),
|
|
412
422
|
_step;
|
|
413
423
|
try {
|
|
414
424
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
@@ -555,14 +565,14 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
555
565
|
}, {
|
|
556
566
|
key: "_handleWebSocketClose",
|
|
557
567
|
value: function () {
|
|
558
|
-
var
|
|
568
|
+
var _context4;
|
|
559
569
|
if (this.state === CLIENT_STATE.DISCONNECTED) {
|
|
560
570
|
return;
|
|
561
571
|
}
|
|
562
572
|
this.state = CLIENT_STATE.CLOSED;
|
|
563
573
|
this.emit(CLIENT_EMMITER_TYPES.CLOSE);
|
|
564
574
|
// Notify each subscription about the close
|
|
565
|
-
var _iterator2 = _createForOfIteratorHelper((0, _values.default)(
|
|
575
|
+
var _iterator2 = _createForOfIteratorHelper((0, _values.default)(_context4 = this.subscriptions).call(_context4)),
|
|
566
576
|
_step2;
|
|
567
577
|
try {
|
|
568
578
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
@@ -579,9 +589,9 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
579
589
|
}, {
|
|
580
590
|
key: "_handleWebSocketError",
|
|
581
591
|
value: function (error /*: any*/) {
|
|
582
|
-
var
|
|
592
|
+
var _context5;
|
|
583
593
|
this.emit(CLIENT_EMMITER_TYPES.ERROR, error);
|
|
584
|
-
var _iterator3 = _createForOfIteratorHelper((0, _values.default)(
|
|
594
|
+
var _iterator3 = _createForOfIteratorHelper((0, _values.default)(_context5 = this.subscriptions).call(_context5)),
|
|
585
595
|
_step3;
|
|
586
596
|
try {
|
|
587
597
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
@@ -598,8 +608,8 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
598
608
|
}, {
|
|
599
609
|
key: "_handleReconnect",
|
|
600
610
|
value: function () {
|
|
601
|
-
var
|
|
602
|
-
|
|
611
|
+
var _context6,
|
|
612
|
+
_this6 = this;
|
|
603
613
|
// if closed or currently reconnecting we stop attempting to reconnect
|
|
604
614
|
if (this.state === CLIENT_STATE.DISCONNECTED) {
|
|
605
615
|
return;
|
|
@@ -615,11 +625,11 @@ var LiveQueryClient = /*#__PURE__*/function () {
|
|
|
615
625
|
if (this.reconnectHandle) {
|
|
616
626
|
clearTimeout(this.reconnectHandle);
|
|
617
627
|
}
|
|
618
|
-
this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}).call(
|
|
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);
|
|
623
633
|
}
|
|
624
634
|
}]);
|
|
625
635
|
return LiveQueryClient;
|
|
@@ -6,6 +6,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
9
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
10
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
|
|
11
12
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
@@ -99,6 +100,7 @@ var Subscription = /*#__PURE__*/function () {
|
|
|
99
100
|
* @param {string} sessionToken - optional session token
|
|
100
101
|
*/
|
|
101
102
|
function Subscription(id, query, sessionToken) {
|
|
103
|
+
var _this = this;
|
|
102
104
|
(0, _classCallCheck2.default)(this, Subscription);
|
|
103
105
|
this.id = id;
|
|
104
106
|
this.query = query;
|
|
@@ -108,8 +110,16 @@ var Subscription = /*#__PURE__*/function () {
|
|
|
108
110
|
this.subscribed = false;
|
|
109
111
|
var EventEmitter = _CoreManager.default.getEventEmitter();
|
|
110
112
|
this.emitter = new EventEmitter();
|
|
111
|
-
this.on =
|
|
112
|
-
|
|
113
|
+
this.on = function (eventName, listener) {
|
|
114
|
+
return _this.emitter.on(eventName, listener);
|
|
115
|
+
};
|
|
116
|
+
this.emit = function (eventName) {
|
|
117
|
+
var _this$emitter, _context;
|
|
118
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
119
|
+
args[_key - 1] = arguments[_key];
|
|
120
|
+
}
|
|
121
|
+
return (_this$emitter = _this.emitter).emit.apply(_this$emitter, (0, _concat.default)(_context = [eventName]).call(_context, args));
|
|
122
|
+
};
|
|
113
123
|
// adding listener so process does not crash
|
|
114
124
|
// best practice is for developer to register their own listener
|
|
115
125
|
this.on('error', function () {});
|
|
@@ -123,10 +133,10 @@ var Subscription = /*#__PURE__*/function () {
|
|
|
123
133
|
(0, _createClass2.default)(Subscription, [{
|
|
124
134
|
key: "unsubscribe",
|
|
125
135
|
value: function () /*: Promise*/{
|
|
126
|
-
var
|
|
136
|
+
var _this2 = this;
|
|
127
137
|
return _CoreManager.default.getLiveQueryController().getDefaultLiveQueryClient().then(function (liveQueryClient) {
|
|
128
|
-
|
|
129
|
-
return liveQueryClient.unsubscribe(
|
|
138
|
+
_this2.emit('close');
|
|
139
|
+
return liveQueryClient.unsubscribe(_this2);
|
|
130
140
|
});
|
|
131
141
|
}
|
|
132
142
|
}]);
|
|
@@ -6,9 +6,10 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
|
|
10
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
9
11
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
10
12
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
11
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
|
|
12
13
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
|
13
14
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
|
14
15
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
@@ -52,12 +53,20 @@ function getLiveQueryClient() /*: Promise<LiveQueryClient>*/{
|
|
|
52
53
|
*/
|
|
53
54
|
var LiveQuery = /*#__PURE__*/function () {
|
|
54
55
|
function LiveQuery() {
|
|
56
|
+
var _this = this;
|
|
55
57
|
(0, _classCallCheck2.default)(this, LiveQuery);
|
|
56
58
|
var EventEmitter = _CoreManager.default.getEventEmitter();
|
|
57
59
|
this.emitter = new EventEmitter();
|
|
58
|
-
this.on =
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
this.on = function (eventName, listener) {
|
|
61
|
+
return _this.emitter.on(eventName, listener);
|
|
62
|
+
};
|
|
63
|
+
this.emit = function (eventName) {
|
|
64
|
+
var _this$emitter, _context;
|
|
65
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
66
|
+
args[_key - 1] = arguments[_key];
|
|
67
|
+
}
|
|
68
|
+
return (_this$emitter = _this.emitter).emit.apply(_this$emitter, (0, _concat.default)(_context = [eventName]).call(_context, args));
|
|
69
|
+
};
|
|
61
70
|
// adding listener so process does not crash
|
|
62
71
|
// best practice is for developer to register their own listener
|
|
63
72
|
this.on('error', function () {});
|
|
@@ -72,17 +81,17 @@ var LiveQuery = /*#__PURE__*/function () {
|
|
|
72
81
|
value: function () {
|
|
73
82
|
var _open = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
74
83
|
var liveQueryClient;
|
|
75
|
-
return _regenerator.default.wrap(function (
|
|
76
|
-
while (1) switch (
|
|
84
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
85
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
77
86
|
case 0:
|
|
78
|
-
|
|
87
|
+
_context2.next = 2;
|
|
79
88
|
return getLiveQueryClient();
|
|
80
89
|
case 2:
|
|
81
|
-
liveQueryClient =
|
|
90
|
+
liveQueryClient = _context2.sent;
|
|
82
91
|
liveQueryClient.open();
|
|
83
92
|
case 4:
|
|
84
93
|
case "end":
|
|
85
|
-
return
|
|
94
|
+
return _context2.stop();
|
|
86
95
|
}
|
|
87
96
|
}, _callee);
|
|
88
97
|
}));
|
|
@@ -103,17 +112,17 @@ var LiveQuery = /*#__PURE__*/function () {
|
|
|
103
112
|
value: function () {
|
|
104
113
|
var _close = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
105
114
|
var liveQueryClient;
|
|
106
|
-
return _regenerator.default.wrap(function (
|
|
107
|
-
while (1) switch (
|
|
115
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
116
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
108
117
|
case 0:
|
|
109
|
-
|
|
118
|
+
_context3.next = 2;
|
|
110
119
|
return getLiveQueryClient();
|
|
111
120
|
case 2:
|
|
112
|
-
liveQueryClient =
|
|
121
|
+
liveQueryClient = _context3.sent;
|
|
113
122
|
liveQueryClient.close();
|
|
114
123
|
case 4:
|
|
115
124
|
case "end":
|
|
116
|
-
return
|
|
125
|
+
return _context3.stop();
|
|
117
126
|
}
|
|
118
127
|
}, _callee2);
|
|
119
128
|
}));
|
|
@@ -135,26 +144,26 @@ var DefaultLiveQueryController = {
|
|
|
135
144
|
getDefaultLiveQueryClient: function () /*: Promise<LiveQueryClient>*/{
|
|
136
145
|
return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
137
146
|
var _yield$Promise$all, _yield$Promise$all2, currentUser, installationId, sessionToken, liveQueryServerURL, serverURL, protocol, host, applicationId, javascriptKey, masterKey, LiveQuery;
|
|
138
|
-
return _regenerator.default.wrap(function (
|
|
139
|
-
while (1) switch (
|
|
147
|
+
return _regenerator.default.wrap(function (_context4) {
|
|
148
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
140
149
|
case 0:
|
|
141
150
|
if (!defaultLiveQueryClient) {
|
|
142
|
-
|
|
151
|
+
_context4.next = 2;
|
|
143
152
|
break;
|
|
144
153
|
}
|
|
145
|
-
return
|
|
154
|
+
return _context4.abrupt("return", defaultLiveQueryClient);
|
|
146
155
|
case 2:
|
|
147
|
-
|
|
156
|
+
_context4.next = 4;
|
|
148
157
|
return _promise.default.all([_CoreManager.default.getUserController().currentUserAsync(), _CoreManager.default.getInstallationController().currentInstallationId()]);
|
|
149
158
|
case 4:
|
|
150
|
-
_yield$Promise$all =
|
|
159
|
+
_yield$Promise$all = _context4.sent;
|
|
151
160
|
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 2);
|
|
152
161
|
currentUser = _yield$Promise$all2[0];
|
|
153
162
|
installationId = _yield$Promise$all2[1];
|
|
154
163
|
sessionToken = currentUser ? currentUser.getSessionToken() : undefined;
|
|
155
164
|
liveQueryServerURL = _CoreManager.default.get('LIVEQUERY_SERVER_URL');
|
|
156
165
|
if (!(liveQueryServerURL && (0, _indexOf.default)(liveQueryServerURL).call(liveQueryServerURL, 'ws') !== 0)) {
|
|
157
|
-
|
|
166
|
+
_context4.next = 12;
|
|
158
167
|
break;
|
|
159
168
|
}
|
|
160
169
|
throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
|
|
@@ -188,10 +197,10 @@ var DefaultLiveQueryController = {
|
|
|
188
197
|
defaultLiveQueryClient.on('close', function () {
|
|
189
198
|
LiveQuery.emit('close');
|
|
190
199
|
});
|
|
191
|
-
return
|
|
200
|
+
return _context4.abrupt("return", defaultLiveQueryClient);
|
|
192
201
|
case 22:
|
|
193
202
|
case "end":
|
|
194
|
-
return
|
|
203
|
+
return _context4.stop();
|
|
195
204
|
}
|
|
196
205
|
}, _callee3);
|
|
197
206
|
}))();
|
|
@@ -14,6 +14,7 @@ var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/ty
|
|
|
14
14
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
15
15
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
16
16
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
17
|
+
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
17
18
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
18
19
|
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
|
19
20
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
@@ -138,11 +139,14 @@ var RESTController = {
|
|
|
138
139
|
var response;
|
|
139
140
|
try {
|
|
140
141
|
response = JSON.parse(xhr.responseText);
|
|
142
|
+
var availableHeaders = typeof xhr.getAllResponseHeaders === 'function' ? xhr.getAllResponseHeaders() : "";
|
|
141
143
|
headers = {};
|
|
142
|
-
if (typeof xhr.getResponseHeader === 'function' &&
|
|
144
|
+
if (typeof xhr.getResponseHeader === 'function' && (availableHeaders === null || availableHeaders === void 0 ? void 0 : (0, _indexOf.default)(availableHeaders).call(availableHeaders, 'access-control-expose-headers')) >= 0) {
|
|
143
145
|
var responseHeaders = xhr.getResponseHeader('access-control-expose-headers').split(', ');
|
|
144
146
|
(0, _forEach.default)(responseHeaders).call(responseHeaders, function (header) {
|
|
145
|
-
|
|
147
|
+
if ((0, _indexOf.default)(availableHeaders).call(availableHeaders, header.toLowerCase()) >= 0) {
|
|
148
|
+
headers[header] = xhr.getResponseHeader(header.toLowerCase());
|
|
149
|
+
}
|
|
146
150
|
});
|
|
147
151
|
}
|
|
148
152
|
} catch (e) {
|
package/lib/node/CoreManager.js
CHANGED
|
@@ -183,7 +183,7 @@ const config /*: Config & { [key: string]: mixed }*/ = {
|
|
|
183
183
|
SERVER_AUTH_TOKEN: null,
|
|
184
184
|
LIVEQUERY_SERVER_URL: null,
|
|
185
185
|
ENCRYPTED_KEY: null,
|
|
186
|
-
VERSION: 'js' + "5.1.0-alpha.
|
|
186
|
+
VERSION: 'js' + "5.1.0-alpha.5",
|
|
187
187
|
APPLICATION_ID: null,
|
|
188
188
|
JAVASCRIPT_KEY: null,
|
|
189
189
|
MASTER_KEY: null,
|
|
@@ -161,8 +161,8 @@ class LiveQueryClient {
|
|
|
161
161
|
this.state = CLIENT_STATE.INITIALIZED;
|
|
162
162
|
const EventEmitter = _CoreManager.default.getEventEmitter();
|
|
163
163
|
this.emitter = new EventEmitter();
|
|
164
|
-
this.on = this.emitter.on;
|
|
165
|
-
this.emit = this.emitter.emit;
|
|
164
|
+
this.on = (eventName, listener) => this.emitter.on(eventName, listener);
|
|
165
|
+
this.emit = (eventName, ...args) => this.emitter.emit(eventName, ...args);
|
|
166
166
|
// adding listener so process does not crash
|
|
167
167
|
// best practice is for developer to register their own listener
|
|
168
168
|
this.on('error', () => {});
|
|
@@ -108,8 +108,8 @@ class Subscription {
|
|
|
108
108
|
this.subscribed = false;
|
|
109
109
|
const EventEmitter = _CoreManager.default.getEventEmitter();
|
|
110
110
|
this.emitter = new EventEmitter();
|
|
111
|
-
this.on = this.emitter.on;
|
|
112
|
-
this.emit = this.emitter.emit;
|
|
111
|
+
this.on = (eventName, listener) => this.emitter.on(eventName, listener);
|
|
112
|
+
this.emit = (eventName, ...args) => this.emitter.emit(eventName, ...args);
|
|
113
113
|
// adding listener so process does not crash
|
|
114
114
|
// best practice is for developer to register their own listener
|
|
115
115
|
this.on('error', () => {});
|
|
@@ -50,9 +50,8 @@ class LiveQuery {
|
|
|
50
50
|
constructor() {
|
|
51
51
|
const EventEmitter = _CoreManager.default.getEventEmitter();
|
|
52
52
|
this.emitter = new EventEmitter();
|
|
53
|
-
this.on = this.emitter.on;
|
|
54
|
-
this.emit = this.emitter.emit;
|
|
55
|
-
|
|
53
|
+
this.on = (eventName, listener) => this.emitter.on(eventName, listener);
|
|
54
|
+
this.emit = (eventName, ...args) => this.emitter.emit(eventName, ...args);
|
|
56
55
|
// adding listener so process does not crash
|
|
57
56
|
// best practice is for developer to register their own listener
|
|
58
57
|
this.on('error', () => {});
|
|
@@ -105,11 +105,14 @@ const RESTController = {
|
|
|
105
105
|
let response;
|
|
106
106
|
try {
|
|
107
107
|
response = JSON.parse(xhr.responseText);
|
|
108
|
+
const availableHeaders = typeof xhr.getAllResponseHeaders === 'function' ? xhr.getAllResponseHeaders() : "";
|
|
108
109
|
headers = {};
|
|
109
|
-
if (typeof xhr.getResponseHeader === 'function' &&
|
|
110
|
+
if (typeof xhr.getResponseHeader === 'function' && (availableHeaders === null || availableHeaders === void 0 ? void 0 : availableHeaders.indexOf('access-control-expose-headers')) >= 0) {
|
|
110
111
|
const responseHeaders = xhr.getResponseHeader('access-control-expose-headers').split(', ');
|
|
111
112
|
responseHeaders.forEach(header => {
|
|
112
|
-
|
|
113
|
+
if (availableHeaders.indexOf(header.toLowerCase()) >= 0) {
|
|
114
|
+
headers[header] = xhr.getResponseHeader(header.toLowerCase());
|
|
115
|
+
}
|
|
113
116
|
});
|
|
114
117
|
}
|
|
115
118
|
} catch (e) {
|
|
@@ -55,6 +55,7 @@ var generateInterval = function (k) {
|
|
|
55
55
|
};
|
|
56
56
|
var LiveQueryClient = function () {
|
|
57
57
|
function LiveQueryClient(_ref) {
|
|
58
|
+
var _this = this;
|
|
58
59
|
var applicationId = _ref.applicationId,
|
|
59
60
|
serverURL = _ref.serverURL,
|
|
60
61
|
javascriptKey = _ref.javascriptKey,
|
|
@@ -81,8 +82,16 @@ var LiveQueryClient = function () {
|
|
|
81
82
|
this.state = CLIENT_STATE.INITIALIZED;
|
|
82
83
|
var EventEmitter = _CoreManager.default.getEventEmitter();
|
|
83
84
|
this.emitter = new EventEmitter();
|
|
84
|
-
this.on =
|
|
85
|
-
|
|
85
|
+
this.on = function (eventName, listener) {
|
|
86
|
+
return _this.emitter.on(eventName, listener);
|
|
87
|
+
};
|
|
88
|
+
this.emit = function (eventName) {
|
|
89
|
+
var _this$emitter;
|
|
90
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
91
|
+
args[_key - 1] = arguments[_key];
|
|
92
|
+
}
|
|
93
|
+
return (_this$emitter = _this.emitter).emit.apply(_this$emitter, [eventName].concat(args));
|
|
94
|
+
};
|
|
86
95
|
this.on('error', function () {});
|
|
87
96
|
}
|
|
88
97
|
(0, _createClass2.default)(LiveQueryClient, [{
|
|
@@ -95,7 +104,7 @@ var LiveQueryClient = function () {
|
|
|
95
104
|
value: function (query, sessionToken) {
|
|
96
105
|
var _queryJSON$keys,
|
|
97
106
|
_queryJSON$watch,
|
|
98
|
-
|
|
107
|
+
_this2 = this;
|
|
99
108
|
if (!query) {
|
|
100
109
|
return;
|
|
101
110
|
}
|
|
@@ -121,7 +130,7 @@ var LiveQueryClient = function () {
|
|
|
121
130
|
this.subscriptions.set(this.requestId, subscription);
|
|
122
131
|
this.requestId += 1;
|
|
123
132
|
this.connectPromise.then(function () {
|
|
124
|
-
|
|
133
|
+
_this2.socket.send(JSON.stringify(subscribeRequest));
|
|
125
134
|
}).catch(function (error) {
|
|
126
135
|
subscription.subscribePromise.reject(error);
|
|
127
136
|
});
|
|
@@ -130,7 +139,7 @@ var LiveQueryClient = function () {
|
|
|
130
139
|
}, {
|
|
131
140
|
key: "unsubscribe",
|
|
132
141
|
value: function (subscription) {
|
|
133
|
-
var
|
|
142
|
+
var _this3 = this;
|
|
134
143
|
if (!subscription) {
|
|
135
144
|
return;
|
|
136
145
|
}
|
|
@@ -139,7 +148,7 @@ var LiveQueryClient = function () {
|
|
|
139
148
|
requestId: subscription.id
|
|
140
149
|
};
|
|
141
150
|
return this.connectPromise.then(function () {
|
|
142
|
-
return
|
|
151
|
+
return _this3.socket.send(JSON.stringify(unsubscribeRequest));
|
|
143
152
|
}).then(function () {
|
|
144
153
|
return subscription.unsubscribePromise;
|
|
145
154
|
});
|
|
@@ -147,7 +156,7 @@ var LiveQueryClient = function () {
|
|
|
147
156
|
}, {
|
|
148
157
|
key: "open",
|
|
149
158
|
value: function () {
|
|
150
|
-
var
|
|
159
|
+
var _this4 = this;
|
|
151
160
|
var WebSocketImplementation = _CoreManager.default.getWebSocketController();
|
|
152
161
|
if (!WebSocketImplementation) {
|
|
153
162
|
this.emit(CLIENT_EMMITER_TYPES.ERROR, 'Can not find WebSocket implementation');
|
|
@@ -159,23 +168,23 @@ var LiveQueryClient = function () {
|
|
|
159
168
|
this.socket = new WebSocketImplementation(this.serverURL);
|
|
160
169
|
this.socket.closingPromise = (0, _promiseUtils.resolvingPromise)();
|
|
161
170
|
this.socket.onopen = function () {
|
|
162
|
-
|
|
171
|
+
_this4._handleWebSocketOpen();
|
|
163
172
|
};
|
|
164
173
|
this.socket.onmessage = function (event) {
|
|
165
|
-
|
|
174
|
+
_this4._handleWebSocketMessage(event);
|
|
166
175
|
};
|
|
167
176
|
this.socket.onclose = function (event) {
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
_this4.socket.closingPromise.resolve(event);
|
|
178
|
+
_this4._handleWebSocketClose();
|
|
170
179
|
};
|
|
171
180
|
this.socket.onerror = function (error) {
|
|
172
|
-
|
|
181
|
+
_this4._handleWebSocketError(error);
|
|
173
182
|
};
|
|
174
183
|
}
|
|
175
184
|
}, {
|
|
176
185
|
key: "resubscribe",
|
|
177
186
|
value: function () {
|
|
178
|
-
var
|
|
187
|
+
var _this5 = this;
|
|
179
188
|
this.subscriptions.forEach(function (subscription, requestId) {
|
|
180
189
|
var query = subscription.query;
|
|
181
190
|
var queryJSON = query.toJSON();
|
|
@@ -195,8 +204,8 @@ var LiveQueryClient = function () {
|
|
|
195
204
|
if (sessionToken) {
|
|
196
205
|
subscribeRequest.sessionToken = sessionToken;
|
|
197
206
|
}
|
|
198
|
-
|
|
199
|
-
|
|
207
|
+
_this5.connectPromise.then(function () {
|
|
208
|
+
_this5.socket.send(JSON.stringify(subscribeRequest));
|
|
200
209
|
});
|
|
201
210
|
});
|
|
202
211
|
}
|
|
@@ -365,7 +374,7 @@ var LiveQueryClient = function () {
|
|
|
365
374
|
}, {
|
|
366
375
|
key: "_handleReconnect",
|
|
367
376
|
value: function () {
|
|
368
|
-
var
|
|
377
|
+
var _this6 = this;
|
|
369
378
|
if (this.state === CLIENT_STATE.DISCONNECTED) {
|
|
370
379
|
return;
|
|
371
380
|
}
|
|
@@ -375,9 +384,9 @@ var LiveQueryClient = function () {
|
|
|
375
384
|
clearTimeout(this.reconnectHandle);
|
|
376
385
|
}
|
|
377
386
|
this.reconnectHandle = setTimeout(function () {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
387
|
+
_this6.attempts++;
|
|
388
|
+
_this6.connectPromise = (0, _promiseUtils.resolvingPromise)();
|
|
389
|
+
_this6.open();
|
|
381
390
|
}.bind(this), time);
|
|
382
391
|
}
|
|
383
392
|
}]);
|