parse 8.0.4-alpha.1 → 8.1.0-alpha.1

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.
@@ -17,7 +17,7 @@ const config = {
17
17
  SERVER_URL: 'https://api.parse.com/1',
18
18
  LIVEQUERY_SERVER_URL: null,
19
19
  ENCRYPTED_KEY: null,
20
- VERSION: 'js' + "8.0.4-alpha.1",
20
+ VERSION: 'js' + "8.1.0-alpha.1",
21
21
  APPLICATION_ID: null,
22
22
  JAVASCRIPT_KEY: null,
23
23
  MAINTENANCE_KEY: null,
@@ -13,6 +13,7 @@ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-
13
13
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
14
14
  var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/values"));
15
15
  var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
16
+ var _map2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
16
17
  var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
17
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
18
19
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
@@ -35,7 +36,8 @@ const OP_TYPES = {
35
36
  CONNECT: 'connect',
36
37
  SUBSCRIBE: 'subscribe',
37
38
  UNSUBSCRIBE: 'unsubscribe',
38
- ERROR: 'error'
39
+ ERROR: 'error',
40
+ QUERY: 'query'
39
41
  };
40
42
 
41
43
  // The event we get back from LiveQuery server
@@ -48,7 +50,8 @@ const OP_EVENTS = {
48
50
  UPDATE: 'update',
49
51
  ENTER: 'enter',
50
52
  LEAVE: 'leave',
51
- DELETE: 'delete'
53
+ DELETE: 'delete',
54
+ RESULT: 'result'
52
55
  };
53
56
 
54
57
  // The event the LiveQuery client should emit
@@ -67,7 +70,8 @@ const SUBSCRIPTION_EMMITER_TYPES = {
67
70
  UPDATE: 'update',
68
71
  ENTER: 'enter',
69
72
  LEAVE: 'leave',
70
- DELETE: 'delete'
73
+ DELETE: 'delete',
74
+ RESULT: 'result'
71
75
  };
72
76
 
73
77
  // Exponentially-growing random delay
@@ -119,13 +123,15 @@ const generateInterval = k => {
119
123
  */
120
124
  class LiveQueryClient {
121
125
  /**
122
- * @param {object} options
123
- * @param {string} options.applicationId - applicationId of your Parse app
124
- * @param {string} options.serverURL - <b>the URL of your LiveQuery server</b>
125
- * @param {string} options.javascriptKey (optional)
126
- * @param {string} options.masterKey (optional) Your Parse Master Key. (Node.js only!)
127
- * @param {string} options.sessionToken (optional)
128
- * @param {string} options.installationId (optional)
126
+ * Creates a new LiveQueryClient instance.
127
+ *
128
+ * @param options - Configuration options for the LiveQuery client
129
+ * @param options.applicationId - The applicationId of your Parse app
130
+ * @param options.serverURL - The URL of your LiveQuery server (must start with 'ws' or 'wss')
131
+ * @param options.javascriptKey - (Optional) The JavaScript key for your Parse app
132
+ * @param options.masterKey - (Optional) Your Parse Master Key (Node.js only!)
133
+ * @param options.sessionToken - (Optional) Session token for authenticated requests
134
+ * @param options.installationId - (Optional) Installation ID for the client
129
135
  */
130
136
  constructor(_ref) {
131
137
  var _this = this;
@@ -226,7 +232,7 @@ class LiveQueryClient {
226
232
  if (sessionToken) {
227
233
  subscribeRequest.sessionToken = sessionToken;
228
234
  }
229
- const subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken);
235
+ const subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken, this);
230
236
  this.subscriptions.set(this.requestId, subscription);
231
237
  this.requestId += 1;
232
238
  this.connectPromise.then(() => {
@@ -428,6 +434,20 @@ class LiveQueryClient {
428
434
  }
429
435
  break;
430
436
  }
437
+ case OP_EVENTS.RESULT:
438
+ {
439
+ if (subscription) {
440
+ var _context3;
441
+ const objects = (0, _map2.default)(_context3 = data.results).call(_context3, json => {
442
+ if (!json.className && subscription.query) {
443
+ json.className = subscription.query.className;
444
+ }
445
+ return _ParseObject.default.fromJSON(json, false);
446
+ });
447
+ subscription.emit(SUBSCRIPTION_EMMITER_TYPES.RESULT, objects);
448
+ }
449
+ break;
450
+ }
431
451
  default:
432
452
  {
433
453
  // create, update, enter, leave, delete cases
@@ -467,22 +487,22 @@ class LiveQueryClient {
467
487
  this.state = CLIENT_STATE.CLOSED;
468
488
  this.emit(CLIENT_EMMITER_TYPES.CLOSE);
469
489
  // Notify each subscription about the close
470
- for (const subscription of (0, _values.default)(_context3 = this.subscriptions).call(_context3)) {
471
- var _context3;
490
+ for (const subscription of (0, _values.default)(_context4 = this.subscriptions).call(_context4)) {
491
+ var _context4;
472
492
  subscription.emit(SUBSCRIPTION_EMMITER_TYPES.CLOSE);
473
493
  }
474
494
  this._handleReconnect();
475
495
  }
476
496
  _handleWebSocketError(error) {
477
497
  this.emit(CLIENT_EMMITER_TYPES.ERROR, error);
478
- for (const subscription of (0, _values.default)(_context4 = this.subscriptions).call(_context4)) {
479
- var _context4;
498
+ for (const subscription of (0, _values.default)(_context5 = this.subscriptions).call(_context5)) {
499
+ var _context5;
480
500
  subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, error);
481
501
  }
482
502
  this._handleReconnect();
483
503
  }
484
504
  _handleReconnect() {
485
- var _context5;
505
+ var _context6;
486
506
  // if closed or currently reconnecting we stop attempting to reconnect
487
507
  if (this.state === CLIENT_STATE.DISCONNECTED) {
488
508
  return;
@@ -497,11 +517,11 @@ class LiveQueryClient {
497
517
  if (this.reconnectHandle) {
498
518
  clearTimeout(this.reconnectHandle);
499
519
  }
500
- this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context5 = () => {
520
+ this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context6 = () => {
501
521
  this.attempts++;
502
522
  this.connectPromise = (0, _promiseUtils.resolvingPromise)();
503
523
  this.open();
504
- }).call(_context5, this), time);
524
+ }).call(_context6, this), time);
505
525
  }
506
526
  }
507
527
  var _default = exports.default = LiveQueryClient;
@@ -6,6 +6,7 @@ _Object$defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = void 0;
9
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
9
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
10
11
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
11
12
  var _promiseUtils = require("./promiseUtils");
@@ -96,8 +97,9 @@ class LiveQuerySubscription {
96
97
  * @param {string | number} id - subscription id
97
98
  * @param {string} query - query to subscribe to
98
99
  * @param {string} sessionToken - optional session token
100
+ * @param {object} client - LiveQueryClient instance
99
101
  */
100
- constructor(id, query, sessionToken) {
102
+ constructor(id, query, sessionToken, client) {
101
103
  var _this = this;
102
104
  (0, _defineProperty2.default)(this, "id", void 0);
103
105
  (0, _defineProperty2.default)(this, "query", void 0);
@@ -105,12 +107,14 @@ class LiveQuerySubscription {
105
107
  (0, _defineProperty2.default)(this, "subscribePromise", void 0);
106
108
  (0, _defineProperty2.default)(this, "unsubscribePromise", void 0);
107
109
  (0, _defineProperty2.default)(this, "subscribed", void 0);
110
+ (0, _defineProperty2.default)(this, "client", void 0);
108
111
  (0, _defineProperty2.default)(this, "emitter", void 0);
109
112
  (0, _defineProperty2.default)(this, "on", void 0);
110
113
  (0, _defineProperty2.default)(this, "emit", void 0);
111
114
  this.id = id;
112
115
  this.query = query;
113
116
  this.sessionToken = sessionToken;
117
+ this.client = client;
114
118
  this.subscribePromise = (0, _promiseUtils.resolvingPromise)();
115
119
  this.unsubscribePromise = (0, _promiseUtils.resolvingPromise)();
116
120
  this.subscribed = false;
@@ -139,5 +143,20 @@ class LiveQuerySubscription {
139
143
  return liveQueryClient.unsubscribe(this);
140
144
  });
141
145
  }
146
+
147
+ /**
148
+ * Execute a query on this subscription.
149
+ * The results will be delivered via the 'result' event.
150
+ */
151
+ find() {
152
+ if (this.client) {
153
+ this.client.connectPromise.then(() => {
154
+ this.client.socket.send((0, _stringify.default)({
155
+ op: 'query',
156
+ requestId: this.id
157
+ }));
158
+ });
159
+ }
160
+ }
142
161
  }
143
162
  var _default = exports.default = LiveQuerySubscription;
@@ -14,7 +14,7 @@ const config = {
14
14
  SERVER_URL: 'https://api.parse.com/1',
15
15
  LIVEQUERY_SERVER_URL: null,
16
16
  ENCRYPTED_KEY: null,
17
- VERSION: 'js' + "8.0.4-alpha.1",
17
+ VERSION: 'js' + "8.1.0-alpha.1",
18
18
  APPLICATION_ID: null,
19
19
  JAVASCRIPT_KEY: null,
20
20
  MAINTENANCE_KEY: null,
@@ -29,7 +29,8 @@ const OP_TYPES = {
29
29
  CONNECT: 'connect',
30
30
  SUBSCRIBE: 'subscribe',
31
31
  UNSUBSCRIBE: 'unsubscribe',
32
- ERROR: 'error'
32
+ ERROR: 'error',
33
+ QUERY: 'query'
33
34
  };
34
35
 
35
36
  // The event we get back from LiveQuery server
@@ -42,7 +43,8 @@ const OP_EVENTS = {
42
43
  UPDATE: 'update',
43
44
  ENTER: 'enter',
44
45
  LEAVE: 'leave',
45
- DELETE: 'delete'
46
+ DELETE: 'delete',
47
+ RESULT: 'result'
46
48
  };
47
49
 
48
50
  // The event the LiveQuery client should emit
@@ -61,7 +63,8 @@ const SUBSCRIPTION_EMMITER_TYPES = {
61
63
  UPDATE: 'update',
62
64
  ENTER: 'enter',
63
65
  LEAVE: 'leave',
64
- DELETE: 'delete'
66
+ DELETE: 'delete',
67
+ RESULT: 'result'
65
68
  };
66
69
 
67
70
  // Exponentially-growing random delay
@@ -113,13 +116,15 @@ const generateInterval = k => {
113
116
  */
114
117
  class LiveQueryClient {
115
118
  /**
116
- * @param {object} options
117
- * @param {string} options.applicationId - applicationId of your Parse app
118
- * @param {string} options.serverURL - <b>the URL of your LiveQuery server</b>
119
- * @param {string} options.javascriptKey (optional)
120
- * @param {string} options.masterKey (optional) Your Parse Master Key. (Node.js only!)
121
- * @param {string} options.sessionToken (optional)
122
- * @param {string} options.installationId (optional)
119
+ * Creates a new LiveQueryClient instance.
120
+ *
121
+ * @param options - Configuration options for the LiveQuery client
122
+ * @param options.applicationId - The applicationId of your Parse app
123
+ * @param options.serverURL - The URL of your LiveQuery server (must start with 'ws' or 'wss')
124
+ * @param options.javascriptKey - (Optional) The JavaScript key for your Parse app
125
+ * @param options.masterKey - (Optional) Your Parse Master Key (Node.js only!)
126
+ * @param options.sessionToken - (Optional) Session token for authenticated requests
127
+ * @param options.installationId - (Optional) Installation ID for the client
123
128
  */
124
129
  constructor({
125
130
  applicationId,
@@ -196,7 +201,7 @@ class LiveQueryClient {
196
201
  if (sessionToken) {
197
202
  subscribeRequest.sessionToken = sessionToken;
198
203
  }
199
- const subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken);
204
+ const subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken, this);
200
205
  this.subscriptions.set(this.requestId, subscription);
201
206
  this.requestId += 1;
202
207
  this.connectPromise.then(() => {
@@ -399,6 +404,19 @@ class LiveQueryClient {
399
404
  }
400
405
  break;
401
406
  }
407
+ case OP_EVENTS.RESULT:
408
+ {
409
+ if (subscription) {
410
+ const objects = data.results.map(json => {
411
+ if (!json.className && subscription.query) {
412
+ json.className = subscription.query.className;
413
+ }
414
+ return _ParseObject.default.fromJSON(json, false);
415
+ });
416
+ subscription.emit(SUBSCRIPTION_EMMITER_TYPES.RESULT, objects);
417
+ }
418
+ break;
419
+ }
402
420
  default:
403
421
  {
404
422
  // create, update, enter, leave, delete cases
@@ -98,11 +98,13 @@ class LiveQuerySubscription {
98
98
  * @param {string | number} id - subscription id
99
99
  * @param {string} query - query to subscribe to
100
100
  * @param {string} sessionToken - optional session token
101
+ * @param {object} client - LiveQueryClient instance
101
102
  */
102
- constructor(id, query, sessionToken) {
103
+ constructor(id, query, sessionToken, client) {
103
104
  this.id = id;
104
105
  this.query = query;
105
106
  this.sessionToken = sessionToken;
107
+ this.client = client;
106
108
  this.subscribePromise = (0, _promiseUtils.resolvingPromise)();
107
109
  this.unsubscribePromise = (0, _promiseUtils.resolvingPromise)();
108
110
  this.subscribed = false;
@@ -126,5 +128,20 @@ class LiveQuerySubscription {
126
128
  return liveQueryClient.unsubscribe(this);
127
129
  });
128
130
  }
131
+
132
+ /**
133
+ * Execute a query on this subscription.
134
+ * The results will be delivered via the 'result' event.
135
+ */
136
+ find() {
137
+ if (this.client) {
138
+ this.client.connectPromise.then(() => {
139
+ this.client.socket.send(JSON.stringify({
140
+ op: 'query',
141
+ requestId: this.id
142
+ }));
143
+ });
144
+ }
145
+ }
129
146
  }
130
147
  var _default = exports.default = LiveQuerySubscription;
@@ -10,7 +10,7 @@ var config = {
10
10
  SERVER_URL: 'https://api.parse.com/1',
11
11
  LIVEQUERY_SERVER_URL: null,
12
12
  ENCRYPTED_KEY: null,
13
- VERSION: 'js' + "8.0.4-alpha.1",
13
+ VERSION: 'js' + "8.1.0-alpha.1",
14
14
  APPLICATION_ID: null,
15
15
  JAVASCRIPT_KEY: null,
16
16
  MAINTENANCE_KEY: null,
@@ -23,7 +23,8 @@ var OP_TYPES = {
23
23
  CONNECT: 'connect',
24
24
  SUBSCRIBE: 'subscribe',
25
25
  UNSUBSCRIBE: 'unsubscribe',
26
- ERROR: 'error'
26
+ ERROR: 'error',
27
+ QUERY: 'query'
27
28
  };
28
29
  var OP_EVENTS = {
29
30
  CONNECTED: 'connected',
@@ -34,7 +35,8 @@ var OP_EVENTS = {
34
35
  UPDATE: 'update',
35
36
  ENTER: 'enter',
36
37
  LEAVE: 'leave',
37
- DELETE: 'delete'
38
+ DELETE: 'delete',
39
+ RESULT: 'result'
38
40
  };
39
41
  var CLIENT_EMMITER_TYPES = {
40
42
  CLOSE: 'close',
@@ -49,7 +51,8 @@ var SUBSCRIPTION_EMMITER_TYPES = {
49
51
  UPDATE: 'update',
50
52
  ENTER: 'enter',
51
53
  LEAVE: 'leave',
52
- DELETE: 'delete'
54
+ DELETE: 'delete',
55
+ RESULT: 'result'
53
56
  };
54
57
  var generateInterval = function (k) {
55
58
  return Math.random() * Math.min(30, Math.pow(2, k) - 1) * 1000;
@@ -128,7 +131,7 @@ var LiveQueryClient = function () {
128
131
  if (sessionToken) {
129
132
  subscribeRequest.sessionToken = sessionToken;
130
133
  }
131
- var subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken);
134
+ var subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken, this);
132
135
  this.subscriptions.set(this.requestId, subscription);
133
136
  this.requestId += 1;
134
137
  this.connectPromise.then(function () {
@@ -339,6 +342,19 @@ var LiveQueryClient = function () {
339
342
  }
340
343
  break;
341
344
  }
345
+ case OP_EVENTS.RESULT:
346
+ {
347
+ if (subscription) {
348
+ var objects = data.results.map(function (json) {
349
+ if (!json.className && subscription.query) {
350
+ json.className = subscription.query.className;
351
+ }
352
+ return _ParseObject.default.fromJSON(json, false);
353
+ });
354
+ subscription.emit(SUBSCRIPTION_EMMITER_TYPES.RESULT, objects);
355
+ }
356
+ break;
357
+ }
342
358
  default:
343
359
  {
344
360
  if (!subscription) {
@@ -8,12 +8,13 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
8
8
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
9
9
  var _promiseUtils = require("./promiseUtils");
10
10
  var LiveQuerySubscription = function () {
11
- function LiveQuerySubscription(id, query, sessionToken) {
11
+ function LiveQuerySubscription(id, query, sessionToken, client) {
12
12
  var _this = this;
13
13
  (0, _classCallCheck2.default)(this, LiveQuerySubscription);
14
14
  this.id = id;
15
15
  this.query = query;
16
16
  this.sessionToken = sessionToken;
17
+ this.client = client;
17
18
  this.subscribePromise = (0, _promiseUtils.resolvingPromise)();
18
19
  this.unsubscribePromise = (0, _promiseUtils.resolvingPromise)();
19
20
  this.subscribed = false;
@@ -40,6 +41,19 @@ var LiveQuerySubscription = function () {
40
41
  return liveQueryClient.unsubscribe(_this2);
41
42
  });
42
43
  }
44
+ }, {
45
+ key: "find",
46
+ value: function () {
47
+ var _this3 = this;
48
+ if (this.client) {
49
+ this.client.connectPromise.then(function () {
50
+ _this3.client.socket.send(JSON.stringify({
51
+ op: 'query',
52
+ requestId: _this3.id
53
+ }));
54
+ });
55
+ }
56
+ }
43
57
  }]);
44
58
  }();
45
59
  var _default = exports.default = LiveQuerySubscription;
@@ -17,7 +17,7 @@ const config = {
17
17
  SERVER_URL: 'https://api.parse.com/1',
18
18
  LIVEQUERY_SERVER_URL: null,
19
19
  ENCRYPTED_KEY: null,
20
- VERSION: 'js' + "8.0.4-alpha.1",
20
+ VERSION: 'js' + "8.1.0-alpha.1",
21
21
  APPLICATION_ID: null,
22
22
  JAVASCRIPT_KEY: null,
23
23
  MAINTENANCE_KEY: null,
@@ -13,6 +13,7 @@ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-
13
13
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
14
14
  var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/values"));
15
15
  var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
16
+ var _map2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
16
17
  var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
17
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
18
19
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
@@ -35,7 +36,8 @@ const OP_TYPES = {
35
36
  CONNECT: 'connect',
36
37
  SUBSCRIBE: 'subscribe',
37
38
  UNSUBSCRIBE: 'unsubscribe',
38
- ERROR: 'error'
39
+ ERROR: 'error',
40
+ QUERY: 'query'
39
41
  };
40
42
 
41
43
  // The event we get back from LiveQuery server
@@ -48,7 +50,8 @@ const OP_EVENTS = {
48
50
  UPDATE: 'update',
49
51
  ENTER: 'enter',
50
52
  LEAVE: 'leave',
51
- DELETE: 'delete'
53
+ DELETE: 'delete',
54
+ RESULT: 'result'
52
55
  };
53
56
 
54
57
  // The event the LiveQuery client should emit
@@ -67,7 +70,8 @@ const SUBSCRIPTION_EMMITER_TYPES = {
67
70
  UPDATE: 'update',
68
71
  ENTER: 'enter',
69
72
  LEAVE: 'leave',
70
- DELETE: 'delete'
73
+ DELETE: 'delete',
74
+ RESULT: 'result'
71
75
  };
72
76
 
73
77
  // Exponentially-growing random delay
@@ -119,13 +123,15 @@ const generateInterval = k => {
119
123
  */
120
124
  class LiveQueryClient {
121
125
  /**
122
- * @param {object} options
123
- * @param {string} options.applicationId - applicationId of your Parse app
124
- * @param {string} options.serverURL - <b>the URL of your LiveQuery server</b>
125
- * @param {string} options.javascriptKey (optional)
126
- * @param {string} options.masterKey (optional) Your Parse Master Key. (Node.js only!)
127
- * @param {string} options.sessionToken (optional)
128
- * @param {string} options.installationId (optional)
126
+ * Creates a new LiveQueryClient instance.
127
+ *
128
+ * @param options - Configuration options for the LiveQuery client
129
+ * @param options.applicationId - The applicationId of your Parse app
130
+ * @param options.serverURL - The URL of your LiveQuery server (must start with 'ws' or 'wss')
131
+ * @param options.javascriptKey - (Optional) The JavaScript key for your Parse app
132
+ * @param options.masterKey - (Optional) Your Parse Master Key (Node.js only!)
133
+ * @param options.sessionToken - (Optional) Session token for authenticated requests
134
+ * @param options.installationId - (Optional) Installation ID for the client
129
135
  */
130
136
  constructor(_ref) {
131
137
  var _this = this;
@@ -226,7 +232,7 @@ class LiveQueryClient {
226
232
  if (sessionToken) {
227
233
  subscribeRequest.sessionToken = sessionToken;
228
234
  }
229
- const subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken);
235
+ const subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken, this);
230
236
  this.subscriptions.set(this.requestId, subscription);
231
237
  this.requestId += 1;
232
238
  this.connectPromise.then(() => {
@@ -428,6 +434,20 @@ class LiveQueryClient {
428
434
  }
429
435
  break;
430
436
  }
437
+ case OP_EVENTS.RESULT:
438
+ {
439
+ if (subscription) {
440
+ var _context3;
441
+ const objects = (0, _map2.default)(_context3 = data.results).call(_context3, json => {
442
+ if (!json.className && subscription.query) {
443
+ json.className = subscription.query.className;
444
+ }
445
+ return _ParseObject.default.fromJSON(json, false);
446
+ });
447
+ subscription.emit(SUBSCRIPTION_EMMITER_TYPES.RESULT, objects);
448
+ }
449
+ break;
450
+ }
431
451
  default:
432
452
  {
433
453
  // create, update, enter, leave, delete cases
@@ -467,22 +487,22 @@ class LiveQueryClient {
467
487
  this.state = CLIENT_STATE.CLOSED;
468
488
  this.emit(CLIENT_EMMITER_TYPES.CLOSE);
469
489
  // Notify each subscription about the close
470
- for (const subscription of (0, _values.default)(_context3 = this.subscriptions).call(_context3)) {
471
- var _context3;
490
+ for (const subscription of (0, _values.default)(_context4 = this.subscriptions).call(_context4)) {
491
+ var _context4;
472
492
  subscription.emit(SUBSCRIPTION_EMMITER_TYPES.CLOSE);
473
493
  }
474
494
  this._handleReconnect();
475
495
  }
476
496
  _handleWebSocketError(error) {
477
497
  this.emit(CLIENT_EMMITER_TYPES.ERROR, error);
478
- for (const subscription of (0, _values.default)(_context4 = this.subscriptions).call(_context4)) {
479
- var _context4;
498
+ for (const subscription of (0, _values.default)(_context5 = this.subscriptions).call(_context5)) {
499
+ var _context5;
480
500
  subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, error);
481
501
  }
482
502
  this._handleReconnect();
483
503
  }
484
504
  _handleReconnect() {
485
- var _context5;
505
+ var _context6;
486
506
  // if closed or currently reconnecting we stop attempting to reconnect
487
507
  if (this.state === CLIENT_STATE.DISCONNECTED) {
488
508
  return;
@@ -497,11 +517,11 @@ class LiveQueryClient {
497
517
  if (this.reconnectHandle) {
498
518
  clearTimeout(this.reconnectHandle);
499
519
  }
500
- this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context5 = () => {
520
+ this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context6 = () => {
501
521
  this.attempts++;
502
522
  this.connectPromise = (0, _promiseUtils.resolvingPromise)();
503
523
  this.open();
504
- }).call(_context5, this), time);
524
+ }).call(_context6, this), time);
505
525
  }
506
526
  }
507
527
  var _default = exports.default = LiveQueryClient;
@@ -6,6 +6,7 @@ _Object$defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = void 0;
9
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
9
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
10
11
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
11
12
  var _promiseUtils = require("./promiseUtils");
@@ -96,8 +97,9 @@ class LiveQuerySubscription {
96
97
  * @param {string | number} id - subscription id
97
98
  * @param {string} query - query to subscribe to
98
99
  * @param {string} sessionToken - optional session token
100
+ * @param {object} client - LiveQueryClient instance
99
101
  */
100
- constructor(id, query, sessionToken) {
102
+ constructor(id, query, sessionToken, client) {
101
103
  var _this = this;
102
104
  (0, _defineProperty2.default)(this, "id", void 0);
103
105
  (0, _defineProperty2.default)(this, "query", void 0);
@@ -105,12 +107,14 @@ class LiveQuerySubscription {
105
107
  (0, _defineProperty2.default)(this, "subscribePromise", void 0);
106
108
  (0, _defineProperty2.default)(this, "unsubscribePromise", void 0);
107
109
  (0, _defineProperty2.default)(this, "subscribed", void 0);
110
+ (0, _defineProperty2.default)(this, "client", void 0);
108
111
  (0, _defineProperty2.default)(this, "emitter", void 0);
109
112
  (0, _defineProperty2.default)(this, "on", void 0);
110
113
  (0, _defineProperty2.default)(this, "emit", void 0);
111
114
  this.id = id;
112
115
  this.query = query;
113
116
  this.sessionToken = sessionToken;
117
+ this.client = client;
114
118
  this.subscribePromise = (0, _promiseUtils.resolvingPromise)();
115
119
  this.unsubscribePromise = (0, _promiseUtils.resolvingPromise)();
116
120
  this.subscribed = false;
@@ -139,5 +143,20 @@ class LiveQuerySubscription {
139
143
  return liveQueryClient.unsubscribe(this);
140
144
  });
141
145
  }
146
+
147
+ /**
148
+ * Execute a query on this subscription.
149
+ * The results will be delivered via the 'result' event.
150
+ */
151
+ find() {
152
+ if (this.client) {
153
+ this.client.connectPromise.then(() => {
154
+ this.client.socket.send((0, _stringify.default)({
155
+ op: 'query',
156
+ requestId: this.id
157
+ }));
158
+ });
159
+ }
160
+ }
142
161
  }
143
162
  var _default = exports.default = LiveQuerySubscription;