parse 4.1.0-alpha.2 → 4.1.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Parse JavaScript SDK v4.1.0-alpha.2
2
+ * Parse JavaScript SDK v4.1.0-alpha.3
3
3
  *
4
4
  * The source tree of this library can be found at
5
5
  * https://github.com/ParsePlatform/Parse-SDK-JS
@@ -531,7 +531,7 @@ var config /*: Config & { [key: string]: mixed }*/ = {
531
531
  SERVER_AUTH_TOKEN: null,
532
532
  LIVEQUERY_SERVER_URL: null,
533
533
  ENCRYPTED_KEY: null,
534
- VERSION: 'js' + "4.1.0-alpha.2",
534
+ VERSION: 'js' + "4.1.0-alpha.3",
535
535
  APPLICATION_ID: null,
536
536
  JAVASCRIPT_KEY: null,
537
537
  MASTER_KEY: null,
@@ -1853,21 +1853,25 @@ var LiveQueryClient = /*#__PURE__*/function (_EventEmitter) {
1853
1853
  }, {
1854
1854
  key: "subscribe",
1855
1855
  value: function (query /*: Object*/, sessionToken /*: ?string*/) /*: LiveQuerySubscription*/{
1856
- var _this2 = this;
1856
+ var _queryJSON$keys,
1857
+ _queryJSON$watch,
1858
+ _this2 = this;
1857
1859
  if (!query) {
1858
1860
  return;
1859
1861
  }
1860
1862
  var className = query.className;
1861
1863
  var queryJSON = query.toJSON();
1862
1864
  var where = queryJSON.where;
1863
- var fields = (0, _keys.default)(queryJSON) ? (0, _keys.default)(queryJSON).split(',') : undefined;
1865
+ var fields = (_queryJSON$keys = (0, _keys.default)(queryJSON)) === null || _queryJSON$keys === void 0 ? void 0 : _queryJSON$keys.split(',');
1866
+ var watch = (_queryJSON$watch = queryJSON.watch) === null || _queryJSON$watch === void 0 ? void 0 : _queryJSON$watch.split(',');
1864
1867
  var subscribeRequest = {
1865
1868
  op: OP_TYPES.SUBSCRIBE,
1866
1869
  requestId: this.requestId,
1867
1870
  query: {
1868
1871
  className: className,
1869
1872
  where: where,
1870
- fields: fields
1873
+ fields: fields,
1874
+ watch: watch
1871
1875
  }
1872
1876
  };
1873
1877
  if (sessionToken) {
@@ -11634,6 +11638,7 @@ var ParseQuery = /*#__PURE__*/function () {
11634
11638
  (0, _classCallCheck2.default)(this, ParseQuery);
11635
11639
  (0, _defineProperty2.default)(this, "className", void 0);
11636
11640
  (0, _defineProperty2.default)(this, "_where", void 0);
11641
+ (0, _defineProperty2.default)(this, "_watch", void 0);
11637
11642
  (0, _defineProperty2.default)(this, "_include", void 0);
11638
11643
  (0, _defineProperty2.default)(this, "_exclude", void 0);
11639
11644
  (0, _defineProperty2.default)(this, "_select", void 0);
@@ -11669,6 +11674,7 @@ var ParseQuery = /*#__PURE__*/function () {
11669
11674
  throw new TypeError('A ParseQuery must be constructed with a ParseObject or class name.');
11670
11675
  }
11671
11676
  this._where = {};
11677
+ this._watch = [];
11672
11678
  this._include = [];
11673
11679
  this._exclude = [];
11674
11680
  this._count = false;
@@ -11861,6 +11867,9 @@ var ParseQuery = /*#__PURE__*/function () {
11861
11867
  var params /*: QueryJSON*/ = {
11862
11868
  where: this._where
11863
11869
  };
11870
+ if (this._watch.length) {
11871
+ params.watch = this._watch.join(',');
11872
+ }
11864
11873
  if (this._include.length) {
11865
11874
  params.include = this._include.join(',');
11866
11875
  }
@@ -11930,6 +11939,9 @@ var ParseQuery = /*#__PURE__*/function () {
11930
11939
  if (json.where) {
11931
11940
  this._where = json.where;
11932
11941
  }
11942
+ if (json.watch) {
11943
+ this._watch = json.watch.split(',');
11944
+ }
11933
11945
  if (json.include) {
11934
11946
  this._include = json.include.split(',');
11935
11947
  }
@@ -13519,6 +13531,32 @@ var ParseQuery = /*#__PURE__*/function () {
13519
13531
  return this;
13520
13532
  }
13521
13533
 
13534
+ /**
13535
+ * Restricts live query to trigger only for watched fields.
13536
+ *
13537
+ * Requires Parse Server 6.0.0+
13538
+ *
13539
+ * @param {...string|Array<string>} keys The name(s) of the key(s) to watch.
13540
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
13541
+ */
13542
+ }, {
13543
+ key: "watch",
13544
+ value: function () /*: ParseQuery*/{
13545
+ var _this14 = this;
13546
+ for (var _len8 = arguments.length, keys = new Array(_len8), _key12 = 0; _key12 < _len8; _key12++) {
13547
+ keys[_key12] = arguments[_key12];
13548
+ }
13549
+ (0, _forEach.default)(keys).call(keys, function (key) {
13550
+ if ((0, _isArray.default)(key)) {
13551
+ var _context22;
13552
+ _this14._watch = (0, _concat.default)(_context22 = _this14._watch).call(_context22, key);
13553
+ } else {
13554
+ _this14._watch.push(key);
13555
+ }
13556
+ });
13557
+ return this;
13558
+ }
13559
+
13522
13560
  /**
13523
13561
  * Changes the read preference that the backend will use when performing the query to the database.
13524
13562
  *
@@ -13548,30 +13586,30 @@ var ParseQuery = /*#__PURE__*/function () {
13548
13586
  value: function () {
13549
13587
  var _subscribe = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(sessionToken /*:: ?: string*/) {
13550
13588
  var currentUser, liveQueryClient, subscription;
13551
- return _regenerator.default.wrap(function (_context22) {
13552
- while (1) switch (_context22.prev = _context22.next) {
13589
+ return _regenerator.default.wrap(function (_context23) {
13590
+ while (1) switch (_context23.prev = _context23.next) {
13553
13591
  case 0:
13554
- _context22.next = 2;
13592
+ _context23.next = 2;
13555
13593
  return _CoreManager.default.getUserController().currentUserAsync();
13556
13594
  case 2:
13557
- currentUser = _context22.sent;
13595
+ currentUser = _context23.sent;
13558
13596
  if (!sessionToken) {
13559
13597
  sessionToken = currentUser ? currentUser.getSessionToken() : undefined;
13560
13598
  }
13561
- _context22.next = 6;
13599
+ _context23.next = 6;
13562
13600
  return _CoreManager.default.getLiveQueryController().getDefaultLiveQueryClient();
13563
13601
  case 6:
13564
- liveQueryClient = _context22.sent;
13602
+ liveQueryClient = _context23.sent;
13565
13603
  if (liveQueryClient.shouldOpen()) {
13566
13604
  liveQueryClient.open();
13567
13605
  }
13568
13606
  subscription = liveQueryClient.subscribe(this, sessionToken);
13569
- return _context22.abrupt("return", subscription.subscribePromise.then(function () {
13607
+ return _context23.abrupt("return", subscription.subscribePromise.then(function () {
13570
13608
  return subscription;
13571
13609
  }));
13572
13610
  case 10:
13573
13611
  case "end":
13574
- return _context22.stop();
13612
+ return _context23.stop();
13575
13613
  }
13576
13614
  }, _callee7, this);
13577
13615
  }));
@@ -13653,7 +13691,7 @@ var ParseQuery = /*#__PURE__*/function () {
13653
13691
  }, {
13654
13692
  key: "cancel",
13655
13693
  value: function () /*: ParseQuery*/{
13656
- var _this14 = this;
13694
+ var _this15 = this;
13657
13695
  if (this._xhrRequest.task && typeof this._xhrRequest.task.abort === 'function') {
13658
13696
  this._xhrRequest.task._aborted = true;
13659
13697
  this._xhrRequest.task.abort();
@@ -13662,16 +13700,16 @@ var ParseQuery = /*#__PURE__*/function () {
13662
13700
  return this;
13663
13701
  }
13664
13702
  return this._xhrRequest.onchange = function () {
13665
- return _this14.cancel();
13703
+ return _this15.cancel();
13666
13704
  };
13667
13705
  }
13668
13706
  }, {
13669
13707
  key: "_setRequestTask",
13670
13708
  value: function (options) {
13671
- var _this15 = this;
13709
+ var _this16 = this;
13672
13710
  options.requestTask = function (task) {
13673
- _this15._xhrRequest.task = task;
13674
- _this15._xhrRequest.onchange();
13711
+ _this16._xhrRequest.task = task;
13712
+ _this16._xhrRequest.onchange();
13675
13713
  };
13676
13714
  }
13677
13715
  }], [{
@@ -13683,8 +13721,8 @@ var ParseQuery = /*#__PURE__*/function () {
13683
13721
  }, {
13684
13722
  key: "or",
13685
13723
  value: function () /*: ParseQuery*/{
13686
- for (var _len8 = arguments.length, queries = new Array(_len8), _key12 = 0; _key12 < _len8; _key12++) {
13687
- queries[_key12] = arguments[_key12];
13724
+ for (var _len9 = arguments.length, queries = new Array(_len9), _key13 = 0; _key13 < _len9; _key13++) {
13725
+ queries[_key13] = arguments[_key13];
13688
13726
  }
13689
13727
  var className = _getClassNameFromQueries(queries);
13690
13728
  var query = new ParseQuery(className);
@@ -13707,8 +13745,8 @@ var ParseQuery = /*#__PURE__*/function () {
13707
13745
  }, {
13708
13746
  key: "and",
13709
13747
  value: function () /*: ParseQuery*/{
13710
- for (var _len9 = arguments.length, queries = new Array(_len9), _key13 = 0; _key13 < _len9; _key13++) {
13711
- queries[_key13] = arguments[_key13];
13748
+ for (var _len10 = arguments.length, queries = new Array(_len10), _key14 = 0; _key14 < _len10; _key14++) {
13749
+ queries[_key14] = arguments[_key14];
13712
13750
  }
13713
13751
  var className = _getClassNameFromQueries(queries);
13714
13752
  var query = new ParseQuery(className);
@@ -13731,8 +13769,8 @@ var ParseQuery = /*#__PURE__*/function () {
13731
13769
  }, {
13732
13770
  key: "nor",
13733
13771
  value: function () /*: ParseQuery*/{
13734
- for (var _len10 = arguments.length, queries = new Array(_len10), _key14 = 0; _key14 < _len10; _key14++) {
13735
- queries[_key14] = arguments[_key14];
13772
+ for (var _len11 = arguments.length, queries = new Array(_len11), _key15 = 0; _key15 < _len11; _key15++) {
13773
+ queries[_key15] = arguments[_key15];
13736
13774
  }
13737
13775
  var className = _getClassNameFromQueries(queries);
13738
13776
  var query = new ParseQuery(className);