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.
- package/README.md +6 -5
- package/dist/parse.js +829 -884
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +829 -882
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/Cloud.js +12 -16
- package/lib/browser/CoreManager.js +3 -3
- package/lib/browser/FacebookUtils.js +1 -1
- package/lib/browser/LocalDatastoreController.react-native.js +1 -1
- package/lib/browser/OfflineQuery.js +5 -9
- package/lib/browser/Parse.js +1 -3
- package/lib/browser/ParseConfig.js +1 -1
- package/lib/browser/ParseFile.js +1 -2
- package/lib/browser/ParseHooks.js +7 -7
- package/lib/browser/ParseInstallation.js +3 -1
- package/lib/browser/ParseObject.js +160 -163
- package/lib/browser/ParseQuery.js +22 -89
- package/lib/browser/ParseSession.js +4 -6
- package/lib/browser/ParseUser.js +44 -58
- package/lib/browser/Push.js +2 -2
- package/lib/browser/RESTController.js +2 -2
- package/lib/browser/Storage.js +1 -1
- package/lib/browser/StorageController.default.js +2 -2
- package/lib/browser/StorageController.weapp.js +1 -1
- package/lib/node/Cloud.js +12 -16
- package/lib/node/CoreManager.js +3 -3
- package/lib/node/FacebookUtils.js +1 -1
- package/lib/node/LocalDatastoreController.react-native.js +1 -1
- package/lib/node/OfflineQuery.js +5 -9
- package/lib/node/Parse.js +1 -1
- package/lib/node/ParseConfig.js +1 -1
- package/lib/node/ParseFile.js +1 -2
- package/lib/node/ParseHooks.js +7 -7
- package/lib/node/ParseInstallation.js +3 -1
- package/lib/node/ParseObject.js +155 -158
- package/lib/node/ParseQuery.js +22 -89
- package/lib/node/ParseSession.js +4 -6
- package/lib/node/ParseUser.js +44 -58
- package/lib/node/Push.js +2 -2
- package/lib/node/RESTController.js +2 -2
- package/lib/node/Storage.js +1 -1
- package/lib/node/StorageController.default.js +2 -2
- package/lib/node/StorageController.weapp.js +1 -1
- package/lib/react-native/Cloud.js +4 -16
- package/lib/react-native/CoreManager.js +3 -3
- package/lib/react-native/LocalDatastoreController.react-native.js +1 -1
- package/lib/react-native/OfflineQuery.js +5 -5
- package/lib/react-native/ParseConfig.js +1 -1
- package/lib/react-native/ParseFile.js +1 -1
- package/lib/react-native/ParseHooks.js +7 -7
- package/lib/react-native/ParseInstallation.js +14 -6
- package/lib/react-native/ParseObject.js +147 -163
- package/lib/react-native/ParseQuery.js +21 -89
- package/lib/react-native/ParseRole.js +8 -2
- package/lib/react-native/ParseSession.js +4 -6
- package/lib/react-native/ParseUser.js +28 -63
- package/lib/react-native/Push.js +2 -2
- package/lib/react-native/RESTController.js +11 -10
- package/lib/react-native/Storage.js +1 -1
- package/lib/react-native/StorageController.default.js +2 -2
- package/lib/react-native/StorageController.weapp.js +1 -1
- package/lib/weapp/Cloud.js +12 -16
- package/lib/weapp/CoreManager.js +3 -3
- package/lib/weapp/FacebookUtils.js +1 -1
- package/lib/weapp/LocalDatastoreController.react-native.js +1 -1
- package/lib/weapp/OfflineQuery.js +5 -9
- package/lib/weapp/Parse.js +1 -1
- package/lib/weapp/ParseConfig.js +1 -1
- package/lib/weapp/ParseFile.js +1 -2
- package/lib/weapp/ParseHooks.js +7 -7
- package/lib/weapp/ParseInstallation.js +3 -1
- package/lib/weapp/ParseObject.js +160 -163
- package/lib/weapp/ParseQuery.js +22 -89
- package/lib/weapp/ParseSession.js +4 -6
- package/lib/weapp/ParseUser.js +44 -58
- package/lib/weapp/Push.js +2 -2
- package/lib/weapp/RESTController.js +2 -2
- package/lib/weapp/Storage.js +1 -1
- package/lib/weapp/StorageController.default.js +2 -2
- package/lib/weapp/StorageController.weapp.js +1 -1
- package/package.json +30 -28
|
@@ -17,8 +17,9 @@ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-
|
|
|
17
17
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
18
18
|
var _getPrototypeOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of"));
|
|
19
19
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
20
|
-
var
|
|
20
|
+
var _some = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/some"));
|
|
21
21
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
22
|
+
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
|
|
22
23
|
var _create = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/create"));
|
|
23
24
|
var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
|
|
24
25
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
@@ -147,8 +148,12 @@ class ParseObject {
|
|
|
147
148
|
options = attributes;
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
|
-
if (toSet
|
|
151
|
-
|
|
151
|
+
if (toSet) {
|
|
152
|
+
try {
|
|
153
|
+
this.set(toSet, options);
|
|
154
|
+
} catch (_) {
|
|
155
|
+
throw new Error("Can't create an invalid Parse Object");
|
|
156
|
+
}
|
|
152
157
|
}
|
|
153
158
|
}
|
|
154
159
|
/* Prototype getters / setters */
|
|
@@ -262,7 +267,7 @@ class ParseObject {
|
|
|
262
267
|
if (objectCache[attr] !== stringified) {
|
|
263
268
|
dirty[attr] = val;
|
|
264
269
|
}
|
|
265
|
-
} catch (
|
|
270
|
+
} catch (_) {
|
|
266
271
|
// Error occurred, possibly by a nested unsaved pointer in a mutable container
|
|
267
272
|
// No matter how it happened, it indicates a change in the attribute
|
|
268
273
|
dirty[attr] = val;
|
|
@@ -426,6 +431,41 @@ class ParseObject {
|
|
|
426
431
|
static _getClassMap() {
|
|
427
432
|
return classMap;
|
|
428
433
|
}
|
|
434
|
+
static _getRequestOptions() {
|
|
435
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
436
|
+
const requestOptions = {};
|
|
437
|
+
const {
|
|
438
|
+
hasOwn
|
|
439
|
+
} = Object;
|
|
440
|
+
if (hasOwn(options, 'useMasterKey')) {
|
|
441
|
+
requestOptions.useMasterKey = !!options.useMasterKey;
|
|
442
|
+
}
|
|
443
|
+
if (hasOwn(options, 'sessionToken') && typeof options.sessionToken === 'string') {
|
|
444
|
+
requestOptions.sessionToken = options.sessionToken;
|
|
445
|
+
}
|
|
446
|
+
if (hasOwn(options, 'installationId') && typeof options.installationId === 'string') {
|
|
447
|
+
requestOptions.installationId = options.installationId;
|
|
448
|
+
}
|
|
449
|
+
if (hasOwn(options, 'transaction') && typeof options.transaction === 'boolean') {
|
|
450
|
+
requestOptions.transaction = options.transaction;
|
|
451
|
+
}
|
|
452
|
+
if (hasOwn(options, 'batchSize') && typeof options.batchSize === 'number') {
|
|
453
|
+
requestOptions.batchSize = options.batchSize;
|
|
454
|
+
}
|
|
455
|
+
if (hasOwn(options, 'context') && typeof options.context === 'object') {
|
|
456
|
+
requestOptions.context = options.context;
|
|
457
|
+
}
|
|
458
|
+
if (hasOwn(options, 'include')) {
|
|
459
|
+
requestOptions.include = ParseObject.handleIncludeOptions(options);
|
|
460
|
+
}
|
|
461
|
+
if (hasOwn(options, 'usePost')) {
|
|
462
|
+
requestOptions.usePost = options.usePost;
|
|
463
|
+
}
|
|
464
|
+
if (hasOwn(options, 'json')) {
|
|
465
|
+
requestOptions.json = options.json;
|
|
466
|
+
}
|
|
467
|
+
return requestOptions;
|
|
468
|
+
}
|
|
429
469
|
|
|
430
470
|
/* Public methods */
|
|
431
471
|
|
|
@@ -492,11 +532,11 @@ class ParseObject {
|
|
|
492
532
|
const pendingOps = this._getPendingOps();
|
|
493
533
|
const dirtyObjects = this._getDirtyObjectAttributes();
|
|
494
534
|
if (attr) {
|
|
495
|
-
if (
|
|
535
|
+
if (Object.hasOwn(dirtyObjects, attr)) {
|
|
496
536
|
return true;
|
|
497
537
|
}
|
|
498
538
|
for (let i = 0; i < pendingOps.length; i++) {
|
|
499
|
-
if (pendingOps[i]
|
|
539
|
+
if (Object.hasOwn(pendingOps[i], attr)) {
|
|
500
540
|
return true;
|
|
501
541
|
}
|
|
502
542
|
}
|
|
@@ -630,7 +670,7 @@ class ParseObject {
|
|
|
630
670
|
*/
|
|
631
671
|
has(attr) {
|
|
632
672
|
const attributes = this.attributes;
|
|
633
|
-
if (
|
|
673
|
+
if (Object.hasOwn(attributes, attr)) {
|
|
634
674
|
return attributes[attr] != null;
|
|
635
675
|
}
|
|
636
676
|
return false;
|
|
@@ -664,7 +704,7 @@ class ParseObject {
|
|
|
664
704
|
* @param {(string|object)} value The value to give it.
|
|
665
705
|
* @param {object} options A set of options for the set.
|
|
666
706
|
* The only supported option is <code>error</code>.
|
|
667
|
-
* @returns {
|
|
707
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
668
708
|
*/
|
|
669
709
|
set(key, value, options) {
|
|
670
710
|
let changes = {};
|
|
@@ -725,12 +765,9 @@ class ParseObject {
|
|
|
725
765
|
|
|
726
766
|
// Validate changes
|
|
727
767
|
if (!options.ignoreValidation) {
|
|
728
|
-
const
|
|
729
|
-
if (
|
|
730
|
-
|
|
731
|
-
options.error(this, validation);
|
|
732
|
-
}
|
|
733
|
-
return false;
|
|
768
|
+
const validationError = this.validate(newValues);
|
|
769
|
+
if (validationError) {
|
|
770
|
+
throw validationError;
|
|
734
771
|
}
|
|
735
772
|
}
|
|
736
773
|
|
|
@@ -751,7 +788,7 @@ class ParseObject {
|
|
|
751
788
|
*
|
|
752
789
|
* @param {string} attr The string name of an attribute.
|
|
753
790
|
* @param options
|
|
754
|
-
* @returns {
|
|
791
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
755
792
|
*/
|
|
756
793
|
unset(attr, options) {
|
|
757
794
|
options = options || {};
|
|
@@ -765,7 +802,7 @@ class ParseObject {
|
|
|
765
802
|
*
|
|
766
803
|
* @param attr {String} The key.
|
|
767
804
|
* @param amount {Number} The amount to increment by (optional).
|
|
768
|
-
* @returns {
|
|
805
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
769
806
|
*/
|
|
770
807
|
increment(attr, amount) {
|
|
771
808
|
if (typeof amount === 'undefined') {
|
|
@@ -783,7 +820,7 @@ class ParseObject {
|
|
|
783
820
|
*
|
|
784
821
|
* @param attr {String} The key.
|
|
785
822
|
* @param amount {Number} The amount to decrement by (optional).
|
|
786
|
-
* @returns {
|
|
823
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
787
824
|
*/
|
|
788
825
|
decrement(attr, amount) {
|
|
789
826
|
if (typeof amount === 'undefined') {
|
|
@@ -801,7 +838,7 @@ class ParseObject {
|
|
|
801
838
|
*
|
|
802
839
|
* @param attr {String} The key.
|
|
803
840
|
* @param item {} The item to add.
|
|
804
|
-
* @returns {
|
|
841
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
805
842
|
*/
|
|
806
843
|
add(attr, item) {
|
|
807
844
|
return this.set(attr, new _ParseOp.AddOp([item]));
|
|
@@ -813,7 +850,7 @@ class ParseObject {
|
|
|
813
850
|
*
|
|
814
851
|
* @param attr {String} The key.
|
|
815
852
|
* @param items {Object[]} The items to add.
|
|
816
|
-
* @returns {
|
|
853
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
817
854
|
*/
|
|
818
855
|
addAll(attr, items) {
|
|
819
856
|
return this.set(attr, new _ParseOp.AddOp(items));
|
|
@@ -826,7 +863,7 @@ class ParseObject {
|
|
|
826
863
|
*
|
|
827
864
|
* @param attr {String} The key.
|
|
828
865
|
* @param item {} The object to add.
|
|
829
|
-
* @returns {
|
|
866
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
830
867
|
*/
|
|
831
868
|
addUnique(attr, item) {
|
|
832
869
|
return this.set(attr, new _ParseOp.AddUniqueOp([item]));
|
|
@@ -839,7 +876,7 @@ class ParseObject {
|
|
|
839
876
|
*
|
|
840
877
|
* @param attr {String} The key.
|
|
841
878
|
* @param items {Object[]} The objects to add.
|
|
842
|
-
* @returns {
|
|
879
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
843
880
|
*/
|
|
844
881
|
addAllUnique(attr, items) {
|
|
845
882
|
return this.set(attr, new _ParseOp.AddUniqueOp(items));
|
|
@@ -851,7 +888,7 @@ class ParseObject {
|
|
|
851
888
|
*
|
|
852
889
|
* @param attr {String} The key.
|
|
853
890
|
* @param item {} The object to remove.
|
|
854
|
-
* @returns {
|
|
891
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
855
892
|
*/
|
|
856
893
|
remove(attr, item) {
|
|
857
894
|
return this.set(attr, new _ParseOp.RemoveOp([item]));
|
|
@@ -863,7 +900,7 @@ class ParseObject {
|
|
|
863
900
|
*
|
|
864
901
|
* @param attr {String} The key.
|
|
865
902
|
* @param items {Object[]} The object to remove.
|
|
866
|
-
* @returns {
|
|
903
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
867
904
|
*/
|
|
868
905
|
removeAll(attr, items) {
|
|
869
906
|
return this.set(attr, new _ParseOp.RemoveOp(items));
|
|
@@ -1009,12 +1046,12 @@ class ParseObject {
|
|
|
1009
1046
|
* @see Parse.Object#set
|
|
1010
1047
|
*/
|
|
1011
1048
|
validate(attrs) {
|
|
1012
|
-
if (
|
|
1049
|
+
if (Object.hasOwn(attrs, 'ACL') && !(attrs.ACL instanceof _ParseACL.default)) {
|
|
1013
1050
|
return new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'ACL must be a Parse ACL.');
|
|
1014
1051
|
}
|
|
1015
1052
|
for (const key in attrs) {
|
|
1016
1053
|
if (!/^[A-Za-z][0-9A-Za-z_.]*$/.test(key)) {
|
|
1017
|
-
return new _ParseError.default(_ParseError.default.INVALID_KEY_NAME);
|
|
1054
|
+
return new _ParseError.default(_ParseError.default.INVALID_KEY_NAME, `Invalid key name: "${key}"`);
|
|
1018
1055
|
}
|
|
1019
1056
|
}
|
|
1020
1057
|
return false;
|
|
@@ -1039,7 +1076,7 @@ class ParseObject {
|
|
|
1039
1076
|
*
|
|
1040
1077
|
* @param {Parse.ACL} acl An instance of Parse.ACL.
|
|
1041
1078
|
* @param {object} options
|
|
1042
|
-
* @returns {
|
|
1079
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
1043
1080
|
* @see Parse.Object#set
|
|
1044
1081
|
*/
|
|
1045
1082
|
setACL(acl, options) {
|
|
@@ -1072,7 +1109,7 @@ class ParseObject {
|
|
|
1072
1109
|
/**
|
|
1073
1110
|
* Clears all attributes on a model
|
|
1074
1111
|
*
|
|
1075
|
-
* @returns {
|
|
1112
|
+
* @returns {Parse.Object} Returns the object, so you can chain this call.
|
|
1076
1113
|
*/
|
|
1077
1114
|
clear() {
|
|
1078
1115
|
const attributes = this.attributes;
|
|
@@ -1109,33 +1146,7 @@ class ParseObject {
|
|
|
1109
1146
|
* completes.
|
|
1110
1147
|
*/
|
|
1111
1148
|
fetch(options) {
|
|
1112
|
-
|
|
1113
|
-
const fetchOptions = {};
|
|
1114
|
-
if (options.hasOwnProperty('useMasterKey')) {
|
|
1115
|
-
fetchOptions.useMasterKey = options.useMasterKey;
|
|
1116
|
-
}
|
|
1117
|
-
if (options.hasOwnProperty('sessionToken')) {
|
|
1118
|
-
fetchOptions.sessionToken = options.sessionToken;
|
|
1119
|
-
}
|
|
1120
|
-
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
1121
|
-
fetchOptions.context = options.context;
|
|
1122
|
-
}
|
|
1123
|
-
if (options.hasOwnProperty('include')) {
|
|
1124
|
-
fetchOptions.include = [];
|
|
1125
|
-
if ((0, _isArray.default)(options.include)) {
|
|
1126
|
-
var _context;
|
|
1127
|
-
(0, _forEach.default)(_context = options.include).call(_context, key => {
|
|
1128
|
-
if ((0, _isArray.default)(key)) {
|
|
1129
|
-
var _context2;
|
|
1130
|
-
fetchOptions.include = (0, _concat.default)(_context2 = fetchOptions.include).call(_context2, key);
|
|
1131
|
-
} else {
|
|
1132
|
-
fetchOptions.include.push(key);
|
|
1133
|
-
}
|
|
1134
|
-
});
|
|
1135
|
-
} else {
|
|
1136
|
-
fetchOptions.include.push(options.include);
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1149
|
+
const fetchOptions = ParseObject._getRequestOptions(options);
|
|
1139
1150
|
const controller = _CoreManager.default.getObjectController();
|
|
1140
1151
|
return controller.fetch(this, true, fetchOptions);
|
|
1141
1152
|
}
|
|
@@ -1263,7 +1274,7 @@ class ParseObject {
|
|
|
1263
1274
|
* @returns {Promise} A promise that is fulfilled when the save
|
|
1264
1275
|
* completes.
|
|
1265
1276
|
*/
|
|
1266
|
-
save(arg1, arg2, arg3) {
|
|
1277
|
+
async save(arg1, arg2, arg3) {
|
|
1267
1278
|
let attrs;
|
|
1268
1279
|
let options;
|
|
1269
1280
|
if (typeof arg1 === 'object' || typeof arg1 === 'undefined') {
|
|
@@ -1278,30 +1289,21 @@ class ParseObject {
|
|
|
1278
1289
|
}
|
|
1279
1290
|
options = options || {};
|
|
1280
1291
|
if (attrs) {
|
|
1281
|
-
|
|
1282
|
-
options.error = (_, validation) => {
|
|
1283
|
-
validationError = validation;
|
|
1284
|
-
};
|
|
1285
|
-
const success = this.set(attrs, options);
|
|
1286
|
-
if (!success) {
|
|
1287
|
-
return _promise.default.reject(validationError);
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
const saveOptions = {};
|
|
1291
|
-
if (options.hasOwnProperty('useMasterKey')) {
|
|
1292
|
-
saveOptions.useMasterKey = !!options.useMasterKey;
|
|
1293
|
-
}
|
|
1294
|
-
if (options.hasOwnProperty('sessionToken') && typeof options.sessionToken === 'string') {
|
|
1295
|
-
saveOptions.sessionToken = options.sessionToken;
|
|
1296
|
-
}
|
|
1297
|
-
if (options.hasOwnProperty('installationId') && typeof options.installationId === 'string') {
|
|
1298
|
-
saveOptions.installationId = options.installationId;
|
|
1299
|
-
}
|
|
1300
|
-
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
1301
|
-
saveOptions.context = options.context;
|
|
1292
|
+
this.set(attrs, options);
|
|
1302
1293
|
}
|
|
1294
|
+
const saveOptions = ParseObject._getRequestOptions(options);
|
|
1303
1295
|
const controller = _CoreManager.default.getObjectController();
|
|
1304
1296
|
const unsaved = options.cascadeSave !== false ? (0, _unsavedChildren.default)(this) : null;
|
|
1297
|
+
if (unsaved && unsaved.length && options.transaction === true && (0, _some.default)(unsaved).call(unsaved, el => el instanceof ParseObject)) {
|
|
1298
|
+
const unsavedFiles = [];
|
|
1299
|
+
const unsavedObjects = [];
|
|
1300
|
+
(0, _forEach.default)(unsaved).call(unsaved, el => {
|
|
1301
|
+
if (el instanceof _ParseFile.default) unsavedFiles.push(el);else unsavedObjects.push(el);
|
|
1302
|
+
});
|
|
1303
|
+
unsavedObjects.push(this);
|
|
1304
|
+
const filePromise = unsavedFiles.length ? controller.save(unsavedFiles, saveOptions) : _promise.default.resolve();
|
|
1305
|
+
return filePromise.then(() => controller.save(unsavedObjects, saveOptions)).then(savedOjbects => savedOjbects.pop());
|
|
1306
|
+
}
|
|
1305
1307
|
return controller.save(unsaved, saveOptions).then(() => {
|
|
1306
1308
|
return controller.save(this, saveOptions);
|
|
1307
1309
|
});
|
|
@@ -1356,20 +1358,10 @@ class ParseObject {
|
|
|
1356
1358
|
* completes.
|
|
1357
1359
|
*/
|
|
1358
1360
|
destroy(options) {
|
|
1359
|
-
options = options || {};
|
|
1360
|
-
const destroyOptions = {};
|
|
1361
|
-
if (options.hasOwnProperty('useMasterKey')) {
|
|
1362
|
-
destroyOptions.useMasterKey = options.useMasterKey;
|
|
1363
|
-
}
|
|
1364
|
-
if (options.hasOwnProperty('sessionToken')) {
|
|
1365
|
-
destroyOptions.sessionToken = options.sessionToken;
|
|
1366
|
-
}
|
|
1367
|
-
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
1368
|
-
destroyOptions.context = options.context;
|
|
1369
|
-
}
|
|
1370
1361
|
if (!this.id) {
|
|
1371
1362
|
return _promise.default.resolve();
|
|
1372
1363
|
}
|
|
1364
|
+
const destroyOptions = ParseObject._getRequestOptions(options);
|
|
1373
1365
|
return _CoreManager.default.getObjectController().destroy(this, destroyOptions);
|
|
1374
1366
|
}
|
|
1375
1367
|
|
|
@@ -1522,17 +1514,8 @@ class ParseObject {
|
|
|
1522
1514
|
*/
|
|
1523
1515
|
static fetchAll(list) {
|
|
1524
1516
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1525
|
-
const
|
|
1526
|
-
|
|
1527
|
-
queryOptions.useMasterKey = options.useMasterKey;
|
|
1528
|
-
}
|
|
1529
|
-
if (options.hasOwnProperty('sessionToken')) {
|
|
1530
|
-
queryOptions.sessionToken = options.sessionToken;
|
|
1531
|
-
}
|
|
1532
|
-
if (options.hasOwnProperty('include')) {
|
|
1533
|
-
queryOptions.include = ParseObject.handleIncludeOptions(options);
|
|
1534
|
-
}
|
|
1535
|
-
return _CoreManager.default.getObjectController().fetch(list, true, queryOptions);
|
|
1517
|
+
const fetchOptions = ParseObject._getRequestOptions(options);
|
|
1518
|
+
return _CoreManager.default.getObjectController().fetch(list, true, fetchOptions);
|
|
1536
1519
|
}
|
|
1537
1520
|
|
|
1538
1521
|
/**
|
|
@@ -1621,28 +1604,27 @@ class ParseObject {
|
|
|
1621
1604
|
*
|
|
1622
1605
|
* @param {Array} list A list of <code>Parse.Object</code>.
|
|
1623
1606
|
* @param {object} options
|
|
1607
|
+
* Valid options are:<ul>
|
|
1608
|
+
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
|
1609
|
+
* be used for this request.
|
|
1610
|
+
* <li>sessionToken: A valid session token, used for making a request on
|
|
1611
|
+
* behalf of a specific user.
|
|
1612
|
+
* <li>include: The name(s) of the key(s) to include. Can be a string, an array of strings,
|
|
1613
|
+
* or an array of array of strings.
|
|
1614
|
+
* <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
|
|
1615
|
+
* </ul>
|
|
1624
1616
|
* @static
|
|
1625
1617
|
* @returns {Parse.Object[]}
|
|
1626
1618
|
*/
|
|
1627
1619
|
static fetchAllIfNeeded(list, options) {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
if (options.hasOwnProperty('useMasterKey')) {
|
|
1631
|
-
queryOptions.useMasterKey = options.useMasterKey;
|
|
1632
|
-
}
|
|
1633
|
-
if (options.hasOwnProperty('sessionToken')) {
|
|
1634
|
-
queryOptions.sessionToken = options.sessionToken;
|
|
1635
|
-
}
|
|
1636
|
-
if (options.hasOwnProperty('include')) {
|
|
1637
|
-
queryOptions.include = ParseObject.handleIncludeOptions(options);
|
|
1638
|
-
}
|
|
1639
|
-
return _CoreManager.default.getObjectController().fetch(list, false, queryOptions);
|
|
1620
|
+
const fetchOptions = ParseObject._getRequestOptions(options);
|
|
1621
|
+
return _CoreManager.default.getObjectController().fetch(list, false, fetchOptions);
|
|
1640
1622
|
}
|
|
1641
1623
|
static handleIncludeOptions(options) {
|
|
1642
1624
|
let include = [];
|
|
1643
1625
|
if ((0, _isArray.default)(options.include)) {
|
|
1644
|
-
var
|
|
1645
|
-
(0, _forEach.default)(
|
|
1626
|
+
var _context;
|
|
1627
|
+
(0, _forEach.default)(_context = options.include).call(_context, key => {
|
|
1646
1628
|
if ((0, _isArray.default)(key)) {
|
|
1647
1629
|
include = (0, _concat.default)(include).call(include, key);
|
|
1648
1630
|
} else {
|
|
@@ -1697,25 +1679,22 @@ class ParseObject {
|
|
|
1697
1679
|
*
|
|
1698
1680
|
* @param {Array} list A list of <code>Parse.Object</code>.
|
|
1699
1681
|
* @param {object} options
|
|
1682
|
+
* Valid options are:<ul>
|
|
1683
|
+
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
|
1684
|
+
* be used for this request.
|
|
1685
|
+
* <li>sessionToken: A valid session token, used for making a request on
|
|
1686
|
+
* behalf of a specific user.
|
|
1687
|
+
* <li>context: A dictionary that is accessible in Cloud Code `beforeDelete` and `afterDelete` triggers.
|
|
1688
|
+
* <li>transaction: Set to true to enable transactions
|
|
1689
|
+
* <li>batchSize: How many objects to yield in each batch (default: 20)
|
|
1690
|
+
* </ul>
|
|
1700
1691
|
* @static
|
|
1701
1692
|
* @returns {Promise} A promise that is fulfilled when the destroyAll
|
|
1702
1693
|
* completes.
|
|
1703
1694
|
*/
|
|
1704
1695
|
static destroyAll(list) {
|
|
1705
1696
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1706
|
-
const destroyOptions =
|
|
1707
|
-
if (options.hasOwnProperty('useMasterKey')) {
|
|
1708
|
-
destroyOptions.useMasterKey = options.useMasterKey;
|
|
1709
|
-
}
|
|
1710
|
-
if (options.hasOwnProperty('sessionToken')) {
|
|
1711
|
-
destroyOptions.sessionToken = options.sessionToken;
|
|
1712
|
-
}
|
|
1713
|
-
if (options.hasOwnProperty('batchSize') && typeof options.batchSize === 'number') {
|
|
1714
|
-
destroyOptions.batchSize = options.batchSize;
|
|
1715
|
-
}
|
|
1716
|
-
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
1717
|
-
destroyOptions.context = options.context;
|
|
1718
|
-
}
|
|
1697
|
+
const destroyOptions = ParseObject._getRequestOptions(options);
|
|
1719
1698
|
return _CoreManager.default.getObjectController().destroy(list, destroyOptions);
|
|
1720
1699
|
}
|
|
1721
1700
|
|
|
@@ -1734,24 +1713,23 @@ class ParseObject {
|
|
|
1734
1713
|
*
|
|
1735
1714
|
* @param {Array} list A list of <code>Parse.Object</code>.
|
|
1736
1715
|
* @param {object} options
|
|
1716
|
+
* Valid options are:
|
|
1717
|
+
* <ul>
|
|
1718
|
+
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
|
1719
|
+
* be used for this request.
|
|
1720
|
+
* <li>sessionToken: A valid session token, used for making a request on
|
|
1721
|
+
* behalf of a specific user.
|
|
1722
|
+
* <li>cascadeSave: If `false`, nested objects will not be saved (default is `true`).
|
|
1723
|
+
* <li>context: A dictionary that is accessible in Cloud Code `beforeSave` and `afterSave` triggers.
|
|
1724
|
+
* <li>transaction: Set to true to enable transactions
|
|
1725
|
+
* <li>batchSize: How many objects to yield in each batch (default: 20)
|
|
1726
|
+
* </ul>
|
|
1737
1727
|
* @static
|
|
1738
1728
|
* @returns {Parse.Object[]}
|
|
1739
1729
|
*/
|
|
1740
1730
|
static saveAll(list) {
|
|
1741
1731
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1742
|
-
const saveOptions =
|
|
1743
|
-
if (options.hasOwnProperty('useMasterKey')) {
|
|
1744
|
-
saveOptions.useMasterKey = options.useMasterKey;
|
|
1745
|
-
}
|
|
1746
|
-
if (options.hasOwnProperty('sessionToken')) {
|
|
1747
|
-
saveOptions.sessionToken = options.sessionToken;
|
|
1748
|
-
}
|
|
1749
|
-
if (options.hasOwnProperty('batchSize') && typeof options.batchSize === 'number') {
|
|
1750
|
-
saveOptions.batchSize = options.batchSize;
|
|
1751
|
-
}
|
|
1752
|
-
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
1753
|
-
saveOptions.context = options.context;
|
|
1754
|
-
}
|
|
1732
|
+
const saveOptions = ParseObject._getRequestOptions(options);
|
|
1755
1733
|
return _CoreManager.default.getObjectController().save(list, saveOptions);
|
|
1756
1734
|
}
|
|
1757
1735
|
|
|
@@ -1908,7 +1886,7 @@ class ParseObject {
|
|
|
1908
1886
|
adjustedClassName = '_User';
|
|
1909
1887
|
}
|
|
1910
1888
|
let parentProto = ParseObject.prototype;
|
|
1911
|
-
if (
|
|
1889
|
+
if (Object.hasOwn(this, '__super__') && this.__super__) {
|
|
1912
1890
|
parentProto = this.prototype;
|
|
1913
1891
|
}
|
|
1914
1892
|
let ParseObjectSubclass = function (attributes, options) {
|
|
@@ -1924,7 +1902,9 @@ class ParseObject {
|
|
|
1924
1902
|
}
|
|
1925
1903
|
}
|
|
1926
1904
|
if (attributes && typeof attributes === 'object') {
|
|
1927
|
-
|
|
1905
|
+
try {
|
|
1906
|
+
this.set(attributes || {}, options);
|
|
1907
|
+
} catch (_) {
|
|
1928
1908
|
throw new Error("Can't create an invalid Parse Object");
|
|
1929
1909
|
}
|
|
1930
1910
|
}
|
|
@@ -2233,10 +2213,12 @@ const DefaultController = {
|
|
|
2233
2213
|
return _promise.default.resolve(undefined);
|
|
2234
2214
|
},
|
|
2235
2215
|
async destroy(target, options) {
|
|
2236
|
-
|
|
2216
|
+
if (options && options.batchSize && options.transaction) throw new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'You cannot use both transaction and batchSize options simultaneously.');
|
|
2217
|
+
let batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
|
|
2237
2218
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2238
2219
|
const RESTController = _CoreManager.default.getRESTController();
|
|
2239
2220
|
if ((0, _isArray.default)(target)) {
|
|
2221
|
+
if (options && options.transaction && target.length > 1) batchSize = target.length;
|
|
2240
2222
|
if (target.length < 1) {
|
|
2241
2223
|
return _promise.default.resolve([]);
|
|
2242
2224
|
}
|
|
@@ -2257,18 +2239,23 @@ const DefaultController = {
|
|
|
2257
2239
|
let deleteCompleted = _promise.default.resolve();
|
|
2258
2240
|
const errors = [];
|
|
2259
2241
|
(0, _forEach.default)(batches).call(batches, batch => {
|
|
2242
|
+
const requests = (0, _map.default)(batch).call(batch, obj => {
|
|
2243
|
+
return {
|
|
2244
|
+
method: 'DELETE',
|
|
2245
|
+
path: getServerUrlPath() + 'classes/' + obj.className + '/' + obj._getId(),
|
|
2246
|
+
body: {}
|
|
2247
|
+
};
|
|
2248
|
+
});
|
|
2249
|
+
const body = options && options.transaction && requests.length > 1 ? {
|
|
2250
|
+
requests,
|
|
2251
|
+
transaction: true
|
|
2252
|
+
} : {
|
|
2253
|
+
requests
|
|
2254
|
+
};
|
|
2260
2255
|
deleteCompleted = deleteCompleted.then(() => {
|
|
2261
|
-
return RESTController.request('POST', 'batch', {
|
|
2262
|
-
requests: (0, _map.default)(batch).call(batch, obj => {
|
|
2263
|
-
return {
|
|
2264
|
-
method: 'DELETE',
|
|
2265
|
-
path: getServerUrlPath() + 'classes/' + obj.className + '/' + obj._getId(),
|
|
2266
|
-
body: {}
|
|
2267
|
-
};
|
|
2268
|
-
})
|
|
2269
|
-
}, options).then(results => {
|
|
2256
|
+
return RESTController.request('POST', 'batch', body, options).then(results => {
|
|
2270
2257
|
for (let i = 0; i < results.length; i++) {
|
|
2271
|
-
if (results[i] && results[i]
|
|
2258
|
+
if (results[i] && Object.hasOwn(results[i], 'error')) {
|
|
2272
2259
|
const err = new _ParseError.default(results[i].error.code, results[i].error.error);
|
|
2273
2260
|
err.object = batch[i];
|
|
2274
2261
|
errors.push(err);
|
|
@@ -2297,7 +2284,8 @@ const DefaultController = {
|
|
|
2297
2284
|
return _promise.default.resolve(target);
|
|
2298
2285
|
},
|
|
2299
2286
|
save(target, options) {
|
|
2300
|
-
|
|
2287
|
+
if (options && options.batchSize && options.transaction) return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'You cannot use both transaction and batchSize options simultaneously.'));
|
|
2288
|
+
let batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
|
|
2301
2289
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2302
2290
|
const mapIdForPin = {};
|
|
2303
2291
|
const RESTController = _CoreManager.default.getRESTController();
|
|
@@ -2326,6 +2314,10 @@ const DefaultController = {
|
|
|
2326
2314
|
pending.push(el);
|
|
2327
2315
|
}
|
|
2328
2316
|
});
|
|
2317
|
+
if (options && options.transaction && pending.length > 1) {
|
|
2318
|
+
if ((0, _some.default)(pending).call(pending, el => !(0, _canBeSerialized.default)(el))) return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Tried to save a transactional batch containing an object with unserializable attributes.'));
|
|
2319
|
+
batchSize = pending.length;
|
|
2320
|
+
}
|
|
2329
2321
|
return _promise.default.all(filesSaved).then(() => {
|
|
2330
2322
|
let objectError = null;
|
|
2331
2323
|
return (0, _promiseUtils.continueWhile)(() => {
|
|
@@ -2334,7 +2326,7 @@ const DefaultController = {
|
|
|
2334
2326
|
const batch = [];
|
|
2335
2327
|
const nextPending = [];
|
|
2336
2328
|
(0, _forEach.default)(pending).call(pending, el => {
|
|
2337
|
-
if (allowCustomObjectId && Object.
|
|
2329
|
+
if (allowCustomObjectId && Object.hasOwn(el, 'id') && !el.id) {
|
|
2338
2330
|
throw new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'objectId must not be empty or null');
|
|
2339
2331
|
}
|
|
2340
2332
|
if (batch.length < batchSize && (0, _canBeSerialized.default)(el)) {
|
|
@@ -2360,7 +2352,7 @@ const DefaultController = {
|
|
|
2360
2352
|
batchTasks.push(stateController.enqueueTask(obj._getStateIdentifier(), function () {
|
|
2361
2353
|
ready.resolve();
|
|
2362
2354
|
return batchReturned.then(responses => {
|
|
2363
|
-
if (responses[index]
|
|
2355
|
+
if (Object.hasOwn(responses[index], 'success')) {
|
|
2364
2356
|
const objectId = responses[index].success.objectId;
|
|
2365
2357
|
const status = responses[index]._status;
|
|
2366
2358
|
delete responses[index]._status;
|
|
@@ -2369,7 +2361,7 @@ const DefaultController = {
|
|
|
2369
2361
|
mapIdForPin[objectId] = obj._localId;
|
|
2370
2362
|
obj._handleSaveResponse(responses[index].success, status);
|
|
2371
2363
|
} else {
|
|
2372
|
-
if (!objectError && responses[index]
|
|
2364
|
+
if (!objectError && Object.hasOwn(responses[index], 'error')) {
|
|
2373
2365
|
const serverError = responses[index].error;
|
|
2374
2366
|
objectError = new _ParseError.default(serverError.code, serverError.error);
|
|
2375
2367
|
// Cancel the rest of the save
|
|
@@ -2382,13 +2374,18 @@ const DefaultController = {
|
|
|
2382
2374
|
});
|
|
2383
2375
|
(0, _promiseUtils.when)(batchReady).then(() => {
|
|
2384
2376
|
// Kick off the batch request
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2377
|
+
const requests = (0, _map.default)(batch).call(batch, obj => {
|
|
2378
|
+
const params = obj._getSaveParams();
|
|
2379
|
+
params.path = getServerUrlPath() + params.path;
|
|
2380
|
+
return params;
|
|
2381
|
+
});
|
|
2382
|
+
const body = options && options.transaction && requests.length > 1 ? {
|
|
2383
|
+
requests,
|
|
2384
|
+
transaction: true
|
|
2385
|
+
} : {
|
|
2386
|
+
requests
|
|
2387
|
+
};
|
|
2388
|
+
return RESTController.request('POST', 'batch', body, options);
|
|
2392
2389
|
}).then(batchReturned.resolve, error => {
|
|
2393
2390
|
batchReturned.reject(new _ParseError.default(_ParseError.default.INCORRECT_TYPE, error.message));
|
|
2394
2391
|
});
|
|
@@ -2408,7 +2405,7 @@ const DefaultController = {
|
|
|
2408
2405
|
});
|
|
2409
2406
|
});
|
|
2410
2407
|
} else if (target instanceof ParseObject) {
|
|
2411
|
-
if (allowCustomObjectId && Object.
|
|
2408
|
+
if (allowCustomObjectId && Object.hasOwn(target, 'id') && !target.id) {
|
|
2412
2409
|
throw new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'objectId must not be empty or null');
|
|
2413
2410
|
}
|
|
2414
2411
|
// generate _localId in case if cascadeSave=false
|