parse 5.3.0 → 6.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +6 -5
  2. package/dist/parse.js +829 -884
  3. package/dist/parse.min.js +2 -2
  4. package/dist/parse.weapp.js +829 -882
  5. package/dist/parse.weapp.min.js +2 -2
  6. package/lib/browser/Cloud.js +12 -16
  7. package/lib/browser/CoreManager.js +3 -3
  8. package/lib/browser/FacebookUtils.js +1 -1
  9. package/lib/browser/LocalDatastoreController.react-native.js +1 -1
  10. package/lib/browser/OfflineQuery.js +5 -9
  11. package/lib/browser/Parse.js +1 -3
  12. package/lib/browser/ParseConfig.js +1 -1
  13. package/lib/browser/ParseFile.js +1 -2
  14. package/lib/browser/ParseHooks.js +7 -7
  15. package/lib/browser/ParseInstallation.js +3 -1
  16. package/lib/browser/ParseObject.js +160 -163
  17. package/lib/browser/ParseQuery.js +22 -89
  18. package/lib/browser/ParseSession.js +4 -6
  19. package/lib/browser/ParseUser.js +44 -58
  20. package/lib/browser/Push.js +2 -2
  21. package/lib/browser/RESTController.js +2 -2
  22. package/lib/browser/Storage.js +1 -1
  23. package/lib/browser/StorageController.default.js +2 -2
  24. package/lib/browser/StorageController.weapp.js +1 -1
  25. package/lib/node/Cloud.js +12 -16
  26. package/lib/node/CoreManager.js +3 -3
  27. package/lib/node/FacebookUtils.js +1 -1
  28. package/lib/node/LocalDatastoreController.react-native.js +1 -1
  29. package/lib/node/OfflineQuery.js +5 -9
  30. package/lib/node/Parse.js +1 -1
  31. package/lib/node/ParseConfig.js +1 -1
  32. package/lib/node/ParseFile.js +1 -2
  33. package/lib/node/ParseHooks.js +7 -7
  34. package/lib/node/ParseInstallation.js +3 -1
  35. package/lib/node/ParseObject.js +155 -158
  36. package/lib/node/ParseQuery.js +22 -89
  37. package/lib/node/ParseSession.js +4 -6
  38. package/lib/node/ParseUser.js +44 -58
  39. package/lib/node/Push.js +2 -2
  40. package/lib/node/RESTController.js +2 -2
  41. package/lib/node/Storage.js +1 -1
  42. package/lib/node/StorageController.default.js +2 -2
  43. package/lib/node/StorageController.weapp.js +1 -1
  44. package/lib/react-native/Cloud.js +4 -16
  45. package/lib/react-native/CoreManager.js +3 -3
  46. package/lib/react-native/LocalDatastoreController.react-native.js +1 -1
  47. package/lib/react-native/OfflineQuery.js +5 -5
  48. package/lib/react-native/ParseConfig.js +1 -1
  49. package/lib/react-native/ParseFile.js +1 -1
  50. package/lib/react-native/ParseHooks.js +7 -7
  51. package/lib/react-native/ParseInstallation.js +14 -6
  52. package/lib/react-native/ParseObject.js +147 -163
  53. package/lib/react-native/ParseQuery.js +21 -89
  54. package/lib/react-native/ParseRole.js +8 -2
  55. package/lib/react-native/ParseSession.js +4 -6
  56. package/lib/react-native/ParseUser.js +28 -63
  57. package/lib/react-native/Push.js +2 -2
  58. package/lib/react-native/RESTController.js +11 -10
  59. package/lib/react-native/Storage.js +1 -1
  60. package/lib/react-native/StorageController.default.js +2 -2
  61. package/lib/react-native/StorageController.weapp.js +1 -1
  62. package/lib/weapp/Cloud.js +12 -16
  63. package/lib/weapp/CoreManager.js +3 -3
  64. package/lib/weapp/FacebookUtils.js +1 -1
  65. package/lib/weapp/LocalDatastoreController.react-native.js +1 -1
  66. package/lib/weapp/OfflineQuery.js +5 -9
  67. package/lib/weapp/Parse.js +1 -1
  68. package/lib/weapp/ParseConfig.js +1 -1
  69. package/lib/weapp/ParseFile.js +1 -2
  70. package/lib/weapp/ParseHooks.js +7 -7
  71. package/lib/weapp/ParseInstallation.js +3 -1
  72. package/lib/weapp/ParseObject.js +160 -163
  73. package/lib/weapp/ParseQuery.js +22 -89
  74. package/lib/weapp/ParseSession.js +4 -6
  75. package/lib/weapp/ParseUser.js +44 -58
  76. package/lib/weapp/Push.js +2 -2
  77. package/lib/weapp/RESTController.js +2 -2
  78. package/lib/weapp/Storage.js +1 -1
  79. package/lib/weapp/StorageController.default.js +2 -2
  80. package/lib/weapp/StorageController.weapp.js +1 -1
  81. package/package.json +30 -28
@@ -125,8 +125,12 @@ class ParseObject {
125
125
  options = attributes;
126
126
  }
127
127
  }
128
- if (toSet && !this.set(toSet, options)) {
129
- throw new Error("Can't create an invalid Parse Object");
128
+ if (toSet) {
129
+ try {
130
+ this.set(toSet, options);
131
+ } catch (_) {
132
+ throw new Error("Can't create an invalid Parse Object");
133
+ }
130
134
  }
131
135
  }
132
136
 
@@ -247,7 +251,7 @@ class ParseObject {
247
251
  if (objectCache[attr] !== stringified) {
248
252
  dirty[attr] = val;
249
253
  }
250
- } catch (e) {
254
+ } catch (_) {
251
255
  // Error occurred, possibly by a nested unsaved pointer in a mutable container
252
256
  // No matter how it happened, it indicates a change in the attribute
253
257
  dirty[attr] = val;
@@ -411,6 +415,40 @@ class ParseObject {
411
415
  static _getClassMap() {
412
416
  return classMap;
413
417
  }
418
+ static _getRequestOptions(options = {}) {
419
+ const requestOptions = {};
420
+ const {
421
+ hasOwn
422
+ } = Object;
423
+ if (hasOwn(options, 'useMasterKey')) {
424
+ requestOptions.useMasterKey = !!options.useMasterKey;
425
+ }
426
+ if (hasOwn(options, 'sessionToken') && typeof options.sessionToken === 'string') {
427
+ requestOptions.sessionToken = options.sessionToken;
428
+ }
429
+ if (hasOwn(options, 'installationId') && typeof options.installationId === 'string') {
430
+ requestOptions.installationId = options.installationId;
431
+ }
432
+ if (hasOwn(options, 'transaction') && typeof options.transaction === 'boolean') {
433
+ requestOptions.transaction = options.transaction;
434
+ }
435
+ if (hasOwn(options, 'batchSize') && typeof options.batchSize === 'number') {
436
+ requestOptions.batchSize = options.batchSize;
437
+ }
438
+ if (hasOwn(options, 'context') && typeof options.context === 'object') {
439
+ requestOptions.context = options.context;
440
+ }
441
+ if (hasOwn(options, 'include')) {
442
+ requestOptions.include = ParseObject.handleIncludeOptions(options);
443
+ }
444
+ if (hasOwn(options, 'usePost')) {
445
+ requestOptions.usePost = options.usePost;
446
+ }
447
+ if (hasOwn(options, 'json')) {
448
+ requestOptions.json = options.json;
449
+ }
450
+ return requestOptions;
451
+ }
414
452
 
415
453
  /* Public methods */
416
454
 
@@ -477,11 +515,11 @@ class ParseObject {
477
515
  const pendingOps = this._getPendingOps();
478
516
  const dirtyObjects = this._getDirtyObjectAttributes();
479
517
  if (attr) {
480
- if (dirtyObjects.hasOwnProperty(attr)) {
518
+ if (Object.hasOwn(dirtyObjects, attr)) {
481
519
  return true;
482
520
  }
483
521
  for (let i = 0; i < pendingOps.length; i++) {
484
- if (pendingOps[i].hasOwnProperty(attr)) {
522
+ if (Object.hasOwn(pendingOps[i], attr)) {
485
523
  return true;
486
524
  }
487
525
  }
@@ -615,7 +653,7 @@ class ParseObject {
615
653
  */
616
654
  has(attr) {
617
655
  const attributes = this.attributes;
618
- if (attributes.hasOwnProperty(attr)) {
656
+ if (Object.hasOwn(attributes, attr)) {
619
657
  return attributes[attr] != null;
620
658
  }
621
659
  return false;
@@ -649,7 +687,7 @@ class ParseObject {
649
687
  * @param {(string|object)} value The value to give it.
650
688
  * @param {object} options A set of options for the set.
651
689
  * The only supported option is <code>error</code>.
652
- * @returns {(ParseObject|boolean)} true if the set succeeded.
690
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
653
691
  */
654
692
  set(key, value, options) {
655
693
  let changes = {};
@@ -710,12 +748,9 @@ class ParseObject {
710
748
 
711
749
  // Validate changes
712
750
  if (!options.ignoreValidation) {
713
- const validation = this.validate(newValues);
714
- if (validation) {
715
- if (typeof options.error === 'function') {
716
- options.error(this, validation);
717
- }
718
- return false;
751
+ const validationError = this.validate(newValues);
752
+ if (validationError) {
753
+ throw validationError;
719
754
  }
720
755
  }
721
756
 
@@ -736,7 +771,7 @@ class ParseObject {
736
771
  *
737
772
  * @param {string} attr The string name of an attribute.
738
773
  * @param options
739
- * @returns {(ParseObject | boolean)}
774
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
740
775
  */
741
776
  unset(attr, options) {
742
777
  options = options || {};
@@ -750,7 +785,7 @@ class ParseObject {
750
785
  *
751
786
  * @param attr {String} The key.
752
787
  * @param amount {Number} The amount to increment by (optional).
753
- * @returns {(ParseObject|boolean)}
788
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
754
789
  */
755
790
  increment(attr, amount) {
756
791
  if (typeof amount === 'undefined') {
@@ -768,7 +803,7 @@ class ParseObject {
768
803
  *
769
804
  * @param attr {String} The key.
770
805
  * @param amount {Number} The amount to decrement by (optional).
771
- * @returns {(ParseObject | boolean)}
806
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
772
807
  */
773
808
  decrement(attr, amount) {
774
809
  if (typeof amount === 'undefined') {
@@ -786,7 +821,7 @@ class ParseObject {
786
821
  *
787
822
  * @param attr {String} The key.
788
823
  * @param item {} The item to add.
789
- * @returns {(ParseObject | boolean)}
824
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
790
825
  */
791
826
  add(attr, item) {
792
827
  return this.set(attr, new _ParseOp.AddOp([item]));
@@ -798,7 +833,7 @@ class ParseObject {
798
833
  *
799
834
  * @param attr {String} The key.
800
835
  * @param items {Object[]} The items to add.
801
- * @returns {(ParseObject | boolean)}
836
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
802
837
  */
803
838
  addAll(attr, items) {
804
839
  return this.set(attr, new _ParseOp.AddOp(items));
@@ -811,7 +846,7 @@ class ParseObject {
811
846
  *
812
847
  * @param attr {String} The key.
813
848
  * @param item {} The object to add.
814
- * @returns {(ParseObject | boolean)}
849
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
815
850
  */
816
851
  addUnique(attr, item) {
817
852
  return this.set(attr, new _ParseOp.AddUniqueOp([item]));
@@ -824,7 +859,7 @@ class ParseObject {
824
859
  *
825
860
  * @param attr {String} The key.
826
861
  * @param items {Object[]} The objects to add.
827
- * @returns {(ParseObject | boolean)}
862
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
828
863
  */
829
864
  addAllUnique(attr, items) {
830
865
  return this.set(attr, new _ParseOp.AddUniqueOp(items));
@@ -836,7 +871,7 @@ class ParseObject {
836
871
  *
837
872
  * @param attr {String} The key.
838
873
  * @param item {} The object to remove.
839
- * @returns {(ParseObject | boolean)}
874
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
840
875
  */
841
876
  remove(attr, item) {
842
877
  return this.set(attr, new _ParseOp.RemoveOp([item]));
@@ -848,7 +883,7 @@ class ParseObject {
848
883
  *
849
884
  * @param attr {String} The key.
850
885
  * @param items {Object[]} The object to remove.
851
- * @returns {(ParseObject | boolean)}
886
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
852
887
  */
853
888
  removeAll(attr, items) {
854
889
  return this.set(attr, new _ParseOp.RemoveOp(items));
@@ -994,12 +1029,12 @@ class ParseObject {
994
1029
  * @see Parse.Object#set
995
1030
  */
996
1031
  validate(attrs) {
997
- if (attrs.hasOwnProperty('ACL') && !(attrs.ACL instanceof _ParseACL.default)) {
1032
+ if (Object.hasOwn(attrs, 'ACL') && !(attrs.ACL instanceof _ParseACL.default)) {
998
1033
  return new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'ACL must be a Parse ACL.');
999
1034
  }
1000
1035
  for (const key in attrs) {
1001
1036
  if (!/^[A-Za-z][0-9A-Za-z_.]*$/.test(key)) {
1002
- return new _ParseError.default(_ParseError.default.INVALID_KEY_NAME);
1037
+ return new _ParseError.default(_ParseError.default.INVALID_KEY_NAME, `Invalid key name: "${key}"`);
1003
1038
  }
1004
1039
  }
1005
1040
  return false;
@@ -1024,7 +1059,7 @@ class ParseObject {
1024
1059
  *
1025
1060
  * @param {Parse.ACL} acl An instance of Parse.ACL.
1026
1061
  * @param {object} options
1027
- * @returns {(ParseObject | boolean)} Whether the set passed validation.
1062
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
1028
1063
  * @see Parse.Object#set
1029
1064
  */
1030
1065
  setACL(acl, options) {
@@ -1054,7 +1089,7 @@ class ParseObject {
1054
1089
  /**
1055
1090
  * Clears all attributes on a model
1056
1091
  *
1057
- * @returns {(ParseObject | boolean)}
1092
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
1058
1093
  */
1059
1094
  clear() {
1060
1095
  const attributes = this.attributes;
@@ -1091,31 +1126,7 @@ class ParseObject {
1091
1126
  * completes.
1092
1127
  */
1093
1128
  fetch(options) {
1094
- options = options || {};
1095
- const fetchOptions = {};
1096
- if (options.hasOwnProperty('useMasterKey')) {
1097
- fetchOptions.useMasterKey = options.useMasterKey;
1098
- }
1099
- if (options.hasOwnProperty('sessionToken')) {
1100
- fetchOptions.sessionToken = options.sessionToken;
1101
- }
1102
- if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1103
- fetchOptions.context = options.context;
1104
- }
1105
- if (options.hasOwnProperty('include')) {
1106
- fetchOptions.include = [];
1107
- if (Array.isArray(options.include)) {
1108
- options.include.forEach(key => {
1109
- if (Array.isArray(key)) {
1110
- fetchOptions.include = fetchOptions.include.concat(key);
1111
- } else {
1112
- fetchOptions.include.push(key);
1113
- }
1114
- });
1115
- } else {
1116
- fetchOptions.include.push(options.include);
1117
- }
1118
- }
1129
+ const fetchOptions = ParseObject._getRequestOptions(options);
1119
1130
  const controller = _CoreManager.default.getObjectController();
1120
1131
  return controller.fetch(this, true, fetchOptions);
1121
1132
  }
@@ -1243,7 +1254,7 @@ class ParseObject {
1243
1254
  * @returns {Promise} A promise that is fulfilled when the save
1244
1255
  * completes.
1245
1256
  */
1246
- save(arg1, arg2, arg3) {
1257
+ async save(arg1, arg2, arg3) {
1247
1258
  let attrs;
1248
1259
  let options;
1249
1260
  if (typeof arg1 === 'object' || typeof arg1 === 'undefined') {
@@ -1258,30 +1269,21 @@ class ParseObject {
1258
1269
  }
1259
1270
  options = options || {};
1260
1271
  if (attrs) {
1261
- let validationError;
1262
- options.error = (_, validation) => {
1263
- validationError = validation;
1264
- };
1265
- const success = this.set(attrs, options);
1266
- if (!success) {
1267
- return Promise.reject(validationError);
1268
- }
1269
- }
1270
- const saveOptions = {};
1271
- if (options.hasOwnProperty('useMasterKey')) {
1272
- saveOptions.useMasterKey = !!options.useMasterKey;
1273
- }
1274
- if (options.hasOwnProperty('sessionToken') && typeof options.sessionToken === 'string') {
1275
- saveOptions.sessionToken = options.sessionToken;
1276
- }
1277
- if (options.hasOwnProperty('installationId') && typeof options.installationId === 'string') {
1278
- saveOptions.installationId = options.installationId;
1279
- }
1280
- if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1281
- saveOptions.context = options.context;
1272
+ this.set(attrs, options);
1282
1273
  }
1274
+ const saveOptions = ParseObject._getRequestOptions(options);
1283
1275
  const controller = _CoreManager.default.getObjectController();
1284
1276
  const unsaved = options.cascadeSave !== false ? (0, _unsavedChildren.default)(this) : null;
1277
+ if (unsaved && unsaved.length && options.transaction === true && unsaved.some(el => el instanceof ParseObject)) {
1278
+ const unsavedFiles = [];
1279
+ const unsavedObjects = [];
1280
+ unsaved.forEach(el => {
1281
+ if (el instanceof _ParseFile.default) unsavedFiles.push(el);else unsavedObjects.push(el);
1282
+ });
1283
+ unsavedObjects.push(this);
1284
+ const filePromise = unsavedFiles.length ? controller.save(unsavedFiles, saveOptions) : Promise.resolve();
1285
+ return filePromise.then(() => controller.save(unsavedObjects, saveOptions)).then(savedOjbects => savedOjbects.pop());
1286
+ }
1285
1287
  return controller.save(unsaved, saveOptions).then(() => {
1286
1288
  return controller.save(this, saveOptions);
1287
1289
  });
@@ -1336,20 +1338,10 @@ class ParseObject {
1336
1338
  * completes.
1337
1339
  */
1338
1340
  destroy(options) {
1339
- options = options || {};
1340
- const destroyOptions = {};
1341
- if (options.hasOwnProperty('useMasterKey')) {
1342
- destroyOptions.useMasterKey = options.useMasterKey;
1343
- }
1344
- if (options.hasOwnProperty('sessionToken')) {
1345
- destroyOptions.sessionToken = options.sessionToken;
1346
- }
1347
- if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1348
- destroyOptions.context = options.context;
1349
- }
1350
1341
  if (!this.id) {
1351
1342
  return Promise.resolve();
1352
1343
  }
1344
+ const destroyOptions = ParseObject._getRequestOptions(options);
1353
1345
  return _CoreManager.default.getObjectController().destroy(this, destroyOptions);
1354
1346
  }
1355
1347
 
@@ -1501,17 +1493,8 @@ class ParseObject {
1501
1493
  * @returns {Parse.Object[]}
1502
1494
  */
1503
1495
  static fetchAll(list, options = {}) {
1504
- const queryOptions = {};
1505
- if (options.hasOwnProperty('useMasterKey')) {
1506
- queryOptions.useMasterKey = options.useMasterKey;
1507
- }
1508
- if (options.hasOwnProperty('sessionToken')) {
1509
- queryOptions.sessionToken = options.sessionToken;
1510
- }
1511
- if (options.hasOwnProperty('include')) {
1512
- queryOptions.include = ParseObject.handleIncludeOptions(options);
1513
- }
1514
- return _CoreManager.default.getObjectController().fetch(list, true, queryOptions);
1496
+ const fetchOptions = ParseObject._getRequestOptions(options);
1497
+ return _CoreManager.default.getObjectController().fetch(list, true, fetchOptions);
1515
1498
  }
1516
1499
 
1517
1500
  /**
@@ -1600,22 +1583,21 @@ class ParseObject {
1600
1583
  *
1601
1584
  * @param {Array} list A list of <code>Parse.Object</code>.
1602
1585
  * @param {object} options
1586
+ * Valid options are:<ul>
1587
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1588
+ * be used for this request.
1589
+ * <li>sessionToken: A valid session token, used for making a request on
1590
+ * behalf of a specific user.
1591
+ * <li>include: The name(s) of the key(s) to include. Can be a string, an array of strings,
1592
+ * or an array of array of strings.
1593
+ * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
1594
+ * </ul>
1603
1595
  * @static
1604
1596
  * @returns {Parse.Object[]}
1605
1597
  */
1606
1598
  static fetchAllIfNeeded(list, options) {
1607
- options = options || {};
1608
- const queryOptions = {};
1609
- if (options.hasOwnProperty('useMasterKey')) {
1610
- queryOptions.useMasterKey = options.useMasterKey;
1611
- }
1612
- if (options.hasOwnProperty('sessionToken')) {
1613
- queryOptions.sessionToken = options.sessionToken;
1614
- }
1615
- if (options.hasOwnProperty('include')) {
1616
- queryOptions.include = ParseObject.handleIncludeOptions(options);
1617
- }
1618
- return _CoreManager.default.getObjectController().fetch(list, false, queryOptions);
1599
+ const fetchOptions = ParseObject._getRequestOptions(options);
1600
+ return _CoreManager.default.getObjectController().fetch(list, false, fetchOptions);
1619
1601
  }
1620
1602
  static handleIncludeOptions(options) {
1621
1603
  let include = [];
@@ -1675,24 +1657,21 @@ class ParseObject {
1675
1657
  *
1676
1658
  * @param {Array} list A list of <code>Parse.Object</code>.
1677
1659
  * @param {object} options
1660
+ * Valid options are:<ul>
1661
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1662
+ * be used for this request.
1663
+ * <li>sessionToken: A valid session token, used for making a request on
1664
+ * behalf of a specific user.
1665
+ * <li>context: A dictionary that is accessible in Cloud Code `beforeDelete` and `afterDelete` triggers.
1666
+ * <li>transaction: Set to true to enable transactions
1667
+ * <li>batchSize: How many objects to yield in each batch (default: 20)
1668
+ * </ul>
1678
1669
  * @static
1679
1670
  * @returns {Promise} A promise that is fulfilled when the destroyAll
1680
1671
  * completes.
1681
1672
  */
1682
1673
  static destroyAll(list, options = {}) {
1683
- const destroyOptions = {};
1684
- if (options.hasOwnProperty('useMasterKey')) {
1685
- destroyOptions.useMasterKey = options.useMasterKey;
1686
- }
1687
- if (options.hasOwnProperty('sessionToken')) {
1688
- destroyOptions.sessionToken = options.sessionToken;
1689
- }
1690
- if (options.hasOwnProperty('batchSize') && typeof options.batchSize === 'number') {
1691
- destroyOptions.batchSize = options.batchSize;
1692
- }
1693
- if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1694
- destroyOptions.context = options.context;
1695
- }
1674
+ const destroyOptions = ParseObject._getRequestOptions(options);
1696
1675
  return _CoreManager.default.getObjectController().destroy(list, destroyOptions);
1697
1676
  }
1698
1677
 
@@ -1711,23 +1690,22 @@ class ParseObject {
1711
1690
  *
1712
1691
  * @param {Array} list A list of <code>Parse.Object</code>.
1713
1692
  * @param {object} options
1693
+ * Valid options are:
1694
+ * <ul>
1695
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1696
+ * be used for this request.
1697
+ * <li>sessionToken: A valid session token, used for making a request on
1698
+ * behalf of a specific user.
1699
+ * <li>cascadeSave: If `false`, nested objects will not be saved (default is `true`).
1700
+ * <li>context: A dictionary that is accessible in Cloud Code `beforeSave` and `afterSave` triggers.
1701
+ * <li>transaction: Set to true to enable transactions
1702
+ * <li>batchSize: How many objects to yield in each batch (default: 20)
1703
+ * </ul>
1714
1704
  * @static
1715
1705
  * @returns {Parse.Object[]}
1716
1706
  */
1717
1707
  static saveAll(list, options = {}) {
1718
- const saveOptions = {};
1719
- if (options.hasOwnProperty('useMasterKey')) {
1720
- saveOptions.useMasterKey = options.useMasterKey;
1721
- }
1722
- if (options.hasOwnProperty('sessionToken')) {
1723
- saveOptions.sessionToken = options.sessionToken;
1724
- }
1725
- if (options.hasOwnProperty('batchSize') && typeof options.batchSize === 'number') {
1726
- saveOptions.batchSize = options.batchSize;
1727
- }
1728
- if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1729
- saveOptions.context = options.context;
1730
- }
1708
+ const saveOptions = ParseObject._getRequestOptions(options);
1731
1709
  return _CoreManager.default.getObjectController().save(list, saveOptions);
1732
1710
  }
1733
1711
 
@@ -1884,7 +1862,7 @@ class ParseObject {
1884
1862
  adjustedClassName = '_User';
1885
1863
  }
1886
1864
  let parentProto = ParseObject.prototype;
1887
- if (this.hasOwnProperty('__super__') && this.__super__) {
1865
+ if (Object.hasOwn(this, '__super__') && this.__super__) {
1888
1866
  parentProto = this.prototype;
1889
1867
  }
1890
1868
  let ParseObjectSubclass = function (attributes, options) {
@@ -1900,7 +1878,9 @@ class ParseObject {
1900
1878
  }
1901
1879
  }
1902
1880
  if (attributes && typeof attributes === 'object') {
1903
- if (!this.set(attributes || {}, options)) {
1881
+ try {
1882
+ this.set(attributes || {}, options);
1883
+ } catch (_) {
1904
1884
  throw new Error("Can't create an invalid Parse Object");
1905
1885
  }
1906
1886
  }
@@ -2209,10 +2189,12 @@ const DefaultController = {
2209
2189
  return Promise.resolve(undefined);
2210
2190
  },
2211
2191
  async destroy(target, options) {
2212
- const batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
2192
+ if (options && options.batchSize && options.transaction) throw new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'You cannot use both transaction and batchSize options simultaneously.');
2193
+ let batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
2213
2194
  const localDatastore = _CoreManager.default.getLocalDatastore();
2214
2195
  const RESTController = _CoreManager.default.getRESTController();
2215
2196
  if (Array.isArray(target)) {
2197
+ if (options && options.transaction && target.length > 1) batchSize = target.length;
2216
2198
  if (target.length < 1) {
2217
2199
  return Promise.resolve([]);
2218
2200
  }
@@ -2233,18 +2215,23 @@ const DefaultController = {
2233
2215
  let deleteCompleted = Promise.resolve();
2234
2216
  const errors = [];
2235
2217
  batches.forEach(batch => {
2218
+ const requests = batch.map(obj => {
2219
+ return {
2220
+ method: 'DELETE',
2221
+ path: getServerUrlPath() + 'classes/' + obj.className + '/' + obj._getId(),
2222
+ body: {}
2223
+ };
2224
+ });
2225
+ const body = options && options.transaction && requests.length > 1 ? {
2226
+ requests,
2227
+ transaction: true
2228
+ } : {
2229
+ requests
2230
+ };
2236
2231
  deleteCompleted = deleteCompleted.then(() => {
2237
- return RESTController.request('POST', 'batch', {
2238
- requests: batch.map(obj => {
2239
- return {
2240
- method: 'DELETE',
2241
- path: getServerUrlPath() + 'classes/' + obj.className + '/' + obj._getId(),
2242
- body: {}
2243
- };
2244
- })
2245
- }, options).then(results => {
2232
+ return RESTController.request('POST', 'batch', body, options).then(results => {
2246
2233
  for (let i = 0; i < results.length; i++) {
2247
- if (results[i] && results[i].hasOwnProperty('error')) {
2234
+ if (results[i] && Object.hasOwn(results[i], 'error')) {
2248
2235
  const err = new _ParseError.default(results[i].error.code, results[i].error.error);
2249
2236
  err.object = batch[i];
2250
2237
  errors.push(err);
@@ -2273,7 +2260,8 @@ const DefaultController = {
2273
2260
  return Promise.resolve(target);
2274
2261
  },
2275
2262
  save(target, options) {
2276
- const batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
2263
+ if (options && options.batchSize && options.transaction) return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'You cannot use both transaction and batchSize options simultaneously.'));
2264
+ let batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
2277
2265
  const localDatastore = _CoreManager.default.getLocalDatastore();
2278
2266
  const mapIdForPin = {};
2279
2267
  const RESTController = _CoreManager.default.getRESTController();
@@ -2302,6 +2290,10 @@ const DefaultController = {
2302
2290
  pending.push(el);
2303
2291
  }
2304
2292
  });
2293
+ if (options && options.transaction && pending.length > 1) {
2294
+ if (pending.some(el => !(0, _canBeSerialized.default)(el))) return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Tried to save a transactional batch containing an object with unserializable attributes.'));
2295
+ batchSize = pending.length;
2296
+ }
2305
2297
  return Promise.all(filesSaved).then(() => {
2306
2298
  let objectError = null;
2307
2299
  return (0, _promiseUtils.continueWhile)(() => {
@@ -2310,7 +2302,7 @@ const DefaultController = {
2310
2302
  const batch = [];
2311
2303
  const nextPending = [];
2312
2304
  pending.forEach(el => {
2313
- if (allowCustomObjectId && Object.prototype.hasOwnProperty.call(el, 'id') && !el.id) {
2305
+ if (allowCustomObjectId && Object.hasOwn(el, 'id') && !el.id) {
2314
2306
  throw new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'objectId must not be empty or null');
2315
2307
  }
2316
2308
  if (batch.length < batchSize && (0, _canBeSerialized.default)(el)) {
@@ -2336,7 +2328,7 @@ const DefaultController = {
2336
2328
  batchTasks.push(stateController.enqueueTask(obj._getStateIdentifier(), function () {
2337
2329
  ready.resolve();
2338
2330
  return batchReturned.then(responses => {
2339
- if (responses[index].hasOwnProperty('success')) {
2331
+ if (Object.hasOwn(responses[index], 'success')) {
2340
2332
  const objectId = responses[index].success.objectId;
2341
2333
  const status = responses[index]._status;
2342
2334
  delete responses[index]._status;
@@ -2345,7 +2337,7 @@ const DefaultController = {
2345
2337
  mapIdForPin[objectId] = obj._localId;
2346
2338
  obj._handleSaveResponse(responses[index].success, status);
2347
2339
  } else {
2348
- if (!objectError && responses[index].hasOwnProperty('error')) {
2340
+ if (!objectError && Object.hasOwn(responses[index], 'error')) {
2349
2341
  const serverError = responses[index].error;
2350
2342
  objectError = new _ParseError.default(serverError.code, serverError.error);
2351
2343
  // Cancel the rest of the save
@@ -2358,13 +2350,18 @@ const DefaultController = {
2358
2350
  });
2359
2351
  (0, _promiseUtils.when)(batchReady).then(() => {
2360
2352
  // Kick off the batch request
2361
- return RESTController.request('POST', 'batch', {
2362
- requests: batch.map(obj => {
2363
- const params = obj._getSaveParams();
2364
- params.path = getServerUrlPath() + params.path;
2365
- return params;
2366
- })
2367
- }, options);
2353
+ const requests = batch.map(obj => {
2354
+ const params = obj._getSaveParams();
2355
+ params.path = getServerUrlPath() + params.path;
2356
+ return params;
2357
+ });
2358
+ const body = options && options.transaction && requests.length > 1 ? {
2359
+ requests,
2360
+ transaction: true
2361
+ } : {
2362
+ requests
2363
+ };
2364
+ return RESTController.request('POST', 'batch', body, options);
2368
2365
  }).then(batchReturned.resolve, error => {
2369
2366
  batchReturned.reject(new _ParseError.default(_ParseError.default.INCORRECT_TYPE, error.message));
2370
2367
  });
@@ -2384,7 +2381,7 @@ const DefaultController = {
2384
2381
  });
2385
2382
  });
2386
2383
  } else if (target instanceof ParseObject) {
2387
- if (allowCustomObjectId && Object.prototype.hasOwnProperty.call(target, 'id') && !target.id) {
2384
+ if (allowCustomObjectId && Object.hasOwn(target, 'id') && !target.id) {
2388
2385
  throw new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'objectId must not be empty or null');
2389
2386
  }
2390
2387
  // generate _localId in case if cascadeSave=false