parse 3.5.1 → 4.0.0-alpha.10
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/LICENSE +167 -25
- package/NOTICE +10 -0
- package/README.md +20 -7
- package/dist/parse.js +12838 -21190
- package/dist/parse.min.js +7 -6
- package/dist/parse.weapp.js +7921 -17062
- package/dist/parse.weapp.min.js +7 -6
- package/lib/browser/Analytics.js +2 -27
- package/lib/browser/AnonymousUtils.js +6 -42
- package/lib/browser/Cloud.js +12 -77
- package/lib/browser/CloudCode.js +0 -3
- package/lib/browser/CoreManager.js +46 -191
- package/lib/browser/CryptoController.js +2 -16
- package/lib/browser/EventEmitter.js +1 -8
- package/lib/browser/EventuallyQueue.js +277 -824
- package/lib/browser/FacebookUtils.js +6 -42
- package/lib/browser/IndexedDBStorageController.js +3 -14
- package/lib/browser/InstallationController.js +2 -20
- package/lib/browser/LiveQueryClient.js +105 -213
- package/lib/browser/LiveQuerySubscription.js +10 -39
- package/lib/browser/LocalDatastore.js +451 -1081
- package/lib/browser/LocalDatastoreController.js +145 -602
- package/lib/browser/LocalDatastoreController.react-native.js +137 -573
- package/lib/browser/LocalDatastoreUtils.js +2 -19
- package/lib/browser/ObjectStateMutations.js +18 -121
- package/lib/browser/OfflineQuery.js +61 -222
- package/lib/browser/Parse.js +12 -115
- package/lib/browser/ParseACL.js +33 -148
- package/lib/browser/ParseCLP.js +96 -314
- package/lib/browser/ParseConfig.js +18 -95
- package/lib/browser/ParseError.js +63 -99
- package/lib/browser/ParseFile.js +128 -685
- package/lib/browser/ParseGeoPoint.js +23 -89
- package/lib/browser/ParseHooks.js +1 -34
- package/lib/browser/ParseInstallation.js +4 -32
- package/lib/browser/ParseLiveQuery.js +96 -505
- package/lib/browser/ParseObject.js +665 -1845
- package/lib/browser/ParseOp.js +41 -287
- package/lib/browser/ParsePolygon.js +13 -70
- package/lib/browser/ParseQuery.js +403 -1504
- package/lib/browser/ParseRelation.js +12 -68
- package/lib/browser/ParseRole.js +13 -75
- package/lib/browser/ParseSchema.js +49 -208
- package/lib/browser/ParseSession.js +11 -69
- package/lib/browser/ParseUser.js +274 -1127
- package/lib/browser/Push.js +7 -50
- package/lib/browser/RESTController.js +28 -157
- package/lib/browser/SingleInstanceStateController.js +19 -144
- package/lib/browser/Socket.weapp.js +0 -10
- package/lib/browser/Storage.js +10 -80
- package/lib/browser/StorageController.browser.js +4 -24
- package/lib/browser/StorageController.default.js +4 -24
- package/lib/browser/StorageController.react-native.js +6 -40
- package/lib/browser/StorageController.weapp.js +5 -23
- package/lib/browser/TaskQueue.js +1 -29
- package/lib/browser/UniqueInstanceStateController.js +19 -149
- package/lib/browser/Xhr.weapp.js +0 -17
- package/lib/browser/arrayContainsObject.js +2 -23
- package/lib/browser/canBeSerialized.js +3 -40
- package/lib/browser/decode.js +3 -40
- package/lib/browser/encode.js +9 -77
- package/lib/browser/equals.js +2 -34
- package/lib/browser/escape.js +1 -15
- package/lib/browser/isRevocableSession.js +2 -18
- package/lib/browser/parseDate.js +2 -20
- package/lib/browser/promiseUtils.js +3 -21
- package/lib/browser/unique.js +3 -24
- package/lib/browser/unsavedChildren.js +6 -57
- package/lib/browser/uuid.js +3 -1
- package/lib/node/Analytics.js +1 -25
- package/lib/node/AnonymousUtils.js +5 -44
- package/lib/node/Cloud.js +10 -73
- package/lib/node/CloudCode.js +0 -3
- package/lib/node/CoreManager.js +47 -227
- package/lib/node/CryptoController.js +2 -16
- package/lib/node/EventEmitter.js +1 -8
- package/lib/node/EventuallyQueue.js +16 -123
- package/lib/node/FacebookUtils.js +5 -44
- package/lib/node/IndexedDBStorageController.js +3 -19
- package/lib/node/InstallationController.js +2 -22
- package/lib/node/LiveQueryClient.js +72 -154
- package/lib/node/LiveQuerySubscription.js +7 -26
- package/lib/node/LocalDatastore.js +19 -182
- package/lib/node/LocalDatastoreController.js +6 -45
- package/lib/node/LocalDatastoreController.react-native.js +6 -52
- package/lib/node/LocalDatastoreUtils.js +1 -13
- package/lib/node/ObjectStateMutations.js +18 -134
- package/lib/node/OfflineQuery.js +27 -151
- package/lib/node/Parse.js +11 -108
- package/lib/node/ParseACL.js +32 -157
- package/lib/node/ParseCLP.js +73 -302
- package/lib/node/ParseConfig.js +16 -91
- package/lib/node/ParseError.js +61 -74
- package/lib/node/ParseFile.js +55 -244
- package/lib/node/ParseGeoPoint.js +21 -89
- package/lib/node/ParseHooks.js +0 -35
- package/lib/node/ParseInstallation.js +1 -17
- package/lib/node/ParseLiveQuery.js +10 -43
- package/lib/node/ParseObject.js +234 -997
- package/lib/node/ParseOp.js +31 -262
- package/lib/node/ParsePolygon.js +12 -69
- package/lib/node/ParseQuery.js +169 -888
- package/lib/node/ParseRelation.js +11 -68
- package/lib/node/ParseRole.js +10 -64
- package/lib/node/ParseSchema.js +46 -229
- package/lib/node/ParseSession.js +8 -57
- package/lib/node/ParseUser.js +107 -583
- package/lib/node/Push.js +4 -44
- package/lib/node/RESTController.js +19 -169
- package/lib/node/SingleInstanceStateController.js +17 -137
- package/lib/node/Socket.weapp.js +0 -7
- package/lib/node/Storage.js +10 -90
- package/lib/node/StorageController.browser.js +4 -30
- package/lib/node/StorageController.default.js +5 -28
- package/lib/node/StorageController.react-native.js +6 -47
- package/lib/node/StorageController.weapp.js +6 -28
- package/lib/node/TaskQueue.js +1 -24
- package/lib/node/UniqueInstanceStateController.js +16 -140
- package/lib/node/Xhr.weapp.js +0 -15
- package/lib/node/arrayContainsObject.js +1 -19
- package/lib/node/canBeSerialized.js +2 -35
- package/lib/node/decode.js +1 -33
- package/lib/node/encode.js +3 -61
- package/lib/node/equals.js +0 -27
- package/lib/node/escape.js +1 -13
- package/lib/node/isRevocableSession.js +1 -12
- package/lib/node/parseDate.js +1 -14
- package/lib/node/promiseUtils.js +2 -14
- package/lib/node/unique.js +1 -18
- package/lib/node/unsavedChildren.js +2 -45
- package/lib/node/uuid.js +6 -1
- package/lib/react-native/Analytics.js +0 -9
- package/lib/react-native/AnonymousUtils.js +0 -10
- package/lib/react-native/Cloud.js +0 -26
- package/lib/react-native/CoreManager.js +2 -6
- package/lib/react-native/CryptoController.js +0 -2
- package/lib/react-native/EventEmitter.js +0 -2
- package/lib/react-native/EventuallyQueue.js +156 -711
- package/lib/react-native/FacebookUtils.js +0 -22
- package/lib/react-native/IndexedDBStorageController.js +0 -1
- package/lib/react-native/InstallationController.js +0 -6
- package/lib/react-native/LiveQueryClient.js +46 -157
- package/lib/react-native/LiveQuerySubscription.js +3 -27
- package/lib/react-native/LocalDatastore.js +281 -948
- package/lib/react-native/LocalDatastoreController.js +71 -552
- package/lib/react-native/LocalDatastoreController.react-native.js +91 -526
- package/lib/react-native/LocalDatastoreUtils.js +0 -1
- package/lib/react-native/ObjectStateMutations.js +2 -65
- package/lib/react-native/OfflineQuery.js +25 -196
- package/lib/react-native/Parse.js +0 -65
- package/lib/react-native/ParseACL.js +0 -44
- package/lib/react-native/ParseCLP.js +23 -161
- package/lib/react-native/ParseConfig.js +0 -42
- package/lib/react-native/ParseError.js +1 -21
- package/lib/react-native/ParseFile.js +55 -529
- package/lib/react-native/ParseGeoPoint.js +0 -17
- package/lib/react-native/ParseHooks.js +0 -30
- package/lib/react-native/ParseInstallation.js +1 -23
- package/lib/react-native/ParseLiveQuery.js +55 -472
- package/lib/react-native/ParseObject.js +245 -1246
- package/lib/react-native/ParseOp.js +1 -138
- package/lib/react-native/ParsePolygon.js +0 -24
- package/lib/react-native/ParseQuery.js +182 -874
- package/lib/react-native/ParseRelation.js +0 -25
- package/lib/react-native/ParseRole.js +1 -36
- package/lib/react-native/ParseSchema.js +3 -54
- package/lib/react-native/ParseSession.js +1 -40
- package/lib/react-native/ParseUser.js +95 -773
- package/lib/react-native/Push.js +0 -16
- package/lib/react-native/RESTController.js +12 -109
- package/lib/react-native/SingleInstanceStateController.js +0 -44
- package/lib/react-native/Socket.weapp.js +0 -10
- package/lib/react-native/Storage.js +0 -24
- package/lib/react-native/StorageController.browser.js +0 -2
- package/lib/react-native/StorageController.default.js +0 -1
- package/lib/react-native/StorageController.react-native.js +0 -2
- package/lib/react-native/TaskQueue.js +0 -15
- package/lib/react-native/UniqueInstanceStateController.js +0 -47
- package/lib/react-native/Xhr.weapp.js +0 -16
- package/lib/react-native/arrayContainsObject.js +0 -5
- package/lib/react-native/canBeSerialized.js +0 -18
- package/lib/react-native/decode.js +0 -21
- package/lib/react-native/encode.js +0 -25
- package/lib/react-native/equals.js +0 -18
- package/lib/react-native/escape.js +0 -1
- package/lib/react-native/isRevocableSession.js +0 -1
- package/lib/react-native/parseDate.js +0 -3
- package/lib/react-native/promiseUtils.js +0 -13
- package/lib/react-native/unique.js +0 -4
- package/lib/react-native/unsavedChildren.js +0 -21
- package/lib/react-native/uuid.js +3 -1
- package/lib/weapp/Analytics.js +2 -27
- package/lib/weapp/AnonymousUtils.js +6 -42
- package/lib/weapp/Cloud.js +12 -77
- package/lib/weapp/CloudCode.js +0 -3
- package/lib/weapp/CoreManager.js +46 -191
- package/lib/weapp/CryptoController.js +2 -16
- package/lib/weapp/EventEmitter.js +1 -8
- package/lib/weapp/EventuallyQueue.js +277 -824
- package/lib/weapp/FacebookUtils.js +6 -42
- package/lib/weapp/IndexedDBStorageController.js +3 -14
- package/lib/weapp/InstallationController.js +2 -20
- package/lib/weapp/LiveQueryClient.js +105 -213
- package/lib/weapp/LiveQuerySubscription.js +10 -39
- package/lib/weapp/LocalDatastore.js +451 -1081
- package/lib/weapp/LocalDatastoreController.js +145 -602
- package/lib/weapp/LocalDatastoreController.react-native.js +137 -573
- package/lib/weapp/LocalDatastoreUtils.js +2 -19
- package/lib/weapp/ObjectStateMutations.js +18 -121
- package/lib/weapp/OfflineQuery.js +61 -222
- package/lib/weapp/Parse.js +12 -115
- package/lib/weapp/ParseACL.js +33 -148
- package/lib/weapp/ParseCLP.js +96 -314
- package/lib/weapp/ParseConfig.js +18 -95
- package/lib/weapp/ParseError.js +63 -99
- package/lib/weapp/ParseFile.js +129 -686
- package/lib/weapp/ParseGeoPoint.js +23 -89
- package/lib/weapp/ParseHooks.js +1 -34
- package/lib/weapp/ParseInstallation.js +4 -32
- package/lib/weapp/ParseLiveQuery.js +96 -505
- package/lib/weapp/ParseObject.js +665 -1845
- package/lib/weapp/ParseOp.js +41 -287
- package/lib/weapp/ParsePolygon.js +13 -70
- package/lib/weapp/ParseQuery.js +403 -1504
- package/lib/weapp/ParseRelation.js +12 -68
- package/lib/weapp/ParseRole.js +13 -75
- package/lib/weapp/ParseSchema.js +49 -208
- package/lib/weapp/ParseSession.js +11 -69
- package/lib/weapp/ParseUser.js +274 -1127
- package/lib/weapp/Push.js +7 -50
- package/lib/weapp/RESTController.js +28 -157
- package/lib/weapp/SingleInstanceStateController.js +19 -144
- package/lib/weapp/Socket.weapp.js +0 -10
- package/lib/weapp/Storage.js +10 -80
- package/lib/weapp/StorageController.browser.js +4 -24
- package/lib/weapp/StorageController.default.js +4 -24
- package/lib/weapp/StorageController.react-native.js +6 -40
- package/lib/weapp/StorageController.weapp.js +5 -23
- package/lib/weapp/TaskQueue.js +1 -29
- package/lib/weapp/UniqueInstanceStateController.js +19 -149
- package/lib/weapp/Xhr.weapp.js +0 -17
- package/lib/weapp/arrayContainsObject.js +2 -23
- package/lib/weapp/canBeSerialized.js +3 -40
- package/lib/weapp/decode.js +3 -40
- package/lib/weapp/encode.js +9 -77
- package/lib/weapp/equals.js +2 -34
- package/lib/weapp/escape.js +1 -15
- package/lib/weapp/isRevocableSession.js +2 -18
- package/lib/weapp/parseDate.js +2 -20
- package/lib/weapp/promiseUtils.js +3 -21
- package/lib/weapp/unique.js +3 -24
- package/lib/weapp/unsavedChildren.js +6 -57
- package/lib/weapp/uuid.js +1 -6
- package/package.json +37 -30
- package/PATENTS +0 -37
package/lib/node/ParseObject.js
CHANGED
|
@@ -4,45 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
9
|
-
|
|
10
8
|
var _canBeSerialized = _interopRequireDefault(require("./canBeSerialized"));
|
|
11
|
-
|
|
12
9
|
var _decode = _interopRequireDefault(require("./decode"));
|
|
13
|
-
|
|
14
10
|
var _encode = _interopRequireDefault(require("./encode"));
|
|
15
|
-
|
|
16
11
|
var _escape = _interopRequireDefault(require("./escape"));
|
|
17
|
-
|
|
18
12
|
var _EventuallyQueue = _interopRequireDefault(require("./EventuallyQueue"));
|
|
19
|
-
|
|
20
13
|
var _ParseACL = _interopRequireDefault(require("./ParseACL"));
|
|
21
|
-
|
|
22
14
|
var _parseDate = _interopRequireDefault(require("./parseDate"));
|
|
23
|
-
|
|
24
15
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
25
|
-
|
|
26
16
|
var _ParseFile = _interopRequireDefault(require("./ParseFile"));
|
|
27
|
-
|
|
28
17
|
var _promiseUtils = require("./promiseUtils");
|
|
29
|
-
|
|
30
18
|
var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
|
|
31
|
-
|
|
32
19
|
var _ParseOp = require("./ParseOp");
|
|
33
|
-
|
|
34
20
|
var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
|
|
35
|
-
|
|
36
21
|
var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
|
|
37
|
-
|
|
38
22
|
var SingleInstanceStateController = _interopRequireWildcard(require("./SingleInstanceStateController"));
|
|
39
|
-
|
|
40
23
|
var _unique = _interopRequireDefault(require("./unique"));
|
|
41
|
-
|
|
42
24
|
var UniqueInstanceStateController = _interopRequireWildcard(require("./UniqueInstanceStateController"));
|
|
43
|
-
|
|
44
25
|
var _unsavedChildren = _interopRequireDefault(require("./unsavedChildren"));
|
|
45
|
-
|
|
46
26
|
function _getRequireWildcardCache(nodeInterop) {
|
|
47
27
|
if (typeof WeakMap !== "function") return null;
|
|
48
28
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -51,31 +31,24 @@ function _getRequireWildcardCache(nodeInterop) {
|
|
|
51
31
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
52
32
|
})(nodeInterop);
|
|
53
33
|
}
|
|
54
|
-
|
|
55
34
|
function _interopRequireWildcard(obj, nodeInterop) {
|
|
56
35
|
if (!nodeInterop && obj && obj.__esModule) {
|
|
57
36
|
return obj;
|
|
58
37
|
}
|
|
59
|
-
|
|
60
38
|
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
61
39
|
return {
|
|
62
40
|
default: obj
|
|
63
41
|
};
|
|
64
42
|
}
|
|
65
|
-
|
|
66
43
|
var cache = _getRequireWildcardCache(nodeInterop);
|
|
67
|
-
|
|
68
44
|
if (cache && cache.has(obj)) {
|
|
69
45
|
return cache.get(obj);
|
|
70
46
|
}
|
|
71
|
-
|
|
72
47
|
var newObj = {};
|
|
73
48
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
74
|
-
|
|
75
49
|
for (var key in obj) {
|
|
76
50
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
77
51
|
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
78
|
-
|
|
79
52
|
if (desc && (desc.get || desc.set)) {
|
|
80
53
|
Object.defineProperty(newObj, key, desc);
|
|
81
54
|
} else {
|
|
@@ -83,62 +56,20 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
83
56
|
}
|
|
84
57
|
}
|
|
85
58
|
}
|
|
86
|
-
|
|
87
59
|
newObj.default = obj;
|
|
88
|
-
|
|
89
60
|
if (cache) {
|
|
90
61
|
cache.set(obj, newObj);
|
|
91
62
|
}
|
|
92
|
-
|
|
93
63
|
return newObj;
|
|
94
64
|
}
|
|
95
|
-
|
|
96
65
|
function _interopRequireDefault(obj) {
|
|
97
66
|
return obj && obj.__esModule ? obj : {
|
|
98
67
|
default: obj
|
|
99
68
|
};
|
|
100
69
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (Object.getOwnPropertySymbols) {
|
|
106
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
107
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
108
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
109
|
-
})), keys.push.apply(keys, symbols);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return keys;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function _objectSpread(target) {
|
|
116
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
117
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
118
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
119
|
-
_defineProperty(target, key, source[key]);
|
|
120
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
121
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return target;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function _defineProperty(obj, key, value) {
|
|
129
|
-
if (key in obj) {
|
|
130
|
-
Object.defineProperty(obj, key, {
|
|
131
|
-
value: value,
|
|
132
|
-
enumerable: true,
|
|
133
|
-
configurable: true,
|
|
134
|
-
writable: true
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
obj[key] = value;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return obj;
|
|
141
|
-
}
|
|
70
|
+
/**
|
|
71
|
+
* @flow
|
|
72
|
+
*/
|
|
142
73
|
|
|
143
74
|
const uuidv4 = require('./uuid');
|
|
144
75
|
/*:: export type Pointer = {
|
|
@@ -146,45 +77,39 @@ const uuidv4 = require('./uuid');
|
|
|
146
77
|
className: string,
|
|
147
78
|
objectId: string,
|
|
148
79
|
};*/
|
|
149
|
-
|
|
150
80
|
/*:: type SaveParams = {
|
|
151
81
|
method: string,
|
|
152
82
|
path: string,
|
|
153
83
|
body: AttributeMap,
|
|
154
84
|
};*/
|
|
155
|
-
|
|
156
85
|
/*:: export type SaveOptions = FullOptions & {
|
|
157
86
|
cascadeSave?: boolean,
|
|
158
87
|
context?: AttributeMap,
|
|
159
88
|
};*/
|
|
160
89
|
// Mapping of class names to constructors, so we can populate objects from the
|
|
161
90
|
// server with appropriate subclasses of ParseObject
|
|
91
|
+
const classMap = {};
|
|
162
92
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
let objectCount = 0; // On web clients, objects are single-instance: any two objects with the same Id
|
|
93
|
+
// Global counter for generating unique Ids for non-single-instance objects
|
|
94
|
+
let objectCount = 0;
|
|
95
|
+
// On web clients, objects are single-instance: any two objects with the same Id
|
|
167
96
|
// will have the same attributes. However, this may be dangerous default
|
|
168
97
|
// behavior in a server scenario
|
|
169
|
-
|
|
170
98
|
let singleInstance = !_CoreManager.default.get('IS_NODE');
|
|
171
|
-
|
|
172
99
|
if (singleInstance) {
|
|
173
100
|
_CoreManager.default.setObjectStateController(SingleInstanceStateController);
|
|
174
101
|
} else {
|
|
175
102
|
_CoreManager.default.setObjectStateController(UniqueInstanceStateController);
|
|
176
103
|
}
|
|
177
|
-
|
|
178
104
|
function getServerUrlPath() {
|
|
179
105
|
let serverUrl = _CoreManager.default.get('SERVER_URL');
|
|
180
|
-
|
|
181
106
|
if (serverUrl[serverUrl.length - 1] !== '/') {
|
|
182
107
|
serverUrl += '/';
|
|
183
108
|
}
|
|
184
|
-
|
|
185
109
|
const url = serverUrl.replace(/https?:\/\//, '');
|
|
186
110
|
return url.substr(url.indexOf('/'));
|
|
187
111
|
}
|
|
112
|
+
|
|
188
113
|
/**
|
|
189
114
|
* Creates a new model with defined attributes.
|
|
190
115
|
*
|
|
@@ -203,145 +128,107 @@ function getServerUrlPath() {
|
|
|
203
128
|
*
|
|
204
129
|
* @alias Parse.Object
|
|
205
130
|
*/
|
|
206
|
-
|
|
207
|
-
|
|
208
131
|
class ParseObject {
|
|
209
132
|
/**
|
|
210
133
|
* @param {string} className The class name for the object
|
|
211
134
|
* @param {object} attributes The initial set of data to store in the object.
|
|
212
135
|
* @param {object} options The options for this object instance.
|
|
213
136
|
*/
|
|
214
|
-
constructor(className
|
|
215
|
-
/*: ?string | { className: string, [attr: string]: mixed }*/
|
|
216
|
-
, attributes
|
|
217
|
-
/*:: ?: { [attr: string]: mixed }*/
|
|
218
|
-
, options
|
|
219
|
-
/*:: ?: { ignoreValidation: boolean }*/
|
|
220
|
-
) {
|
|
137
|
+
constructor(className /*: ?string | { className: string, [attr: string]: mixed }*/, attributes /*:: ?: { [attr: string]: mixed }*/, options /*:: ?: { ignoreValidation: boolean }*/) {
|
|
221
138
|
// Enable legacy initializers
|
|
222
139
|
if (typeof this.initialize === 'function') {
|
|
223
140
|
this.initialize.apply(this, arguments);
|
|
224
141
|
}
|
|
225
|
-
|
|
226
142
|
let toSet = null;
|
|
227
143
|
this._objCount = objectCount++;
|
|
228
|
-
|
|
229
144
|
if (typeof className === 'string') {
|
|
230
145
|
this.className = className;
|
|
231
|
-
|
|
232
146
|
if (attributes && typeof attributes === 'object') {
|
|
233
147
|
toSet = attributes;
|
|
234
148
|
}
|
|
235
149
|
} else if (className && typeof className === 'object') {
|
|
236
150
|
this.className = className.className;
|
|
237
151
|
toSet = {};
|
|
238
|
-
|
|
239
152
|
for (const attr in className) {
|
|
240
153
|
if (attr !== 'className') {
|
|
241
154
|
toSet[attr] = className[attr];
|
|
242
155
|
}
|
|
243
156
|
}
|
|
244
|
-
|
|
245
157
|
if (attributes && typeof attributes === 'object') {
|
|
246
158
|
options = attributes;
|
|
247
159
|
}
|
|
248
160
|
}
|
|
249
|
-
|
|
250
161
|
if (toSet && !this.set(toSet, options)) {
|
|
251
162
|
throw new Error("Can't create an invalid Parse Object");
|
|
252
163
|
}
|
|
253
164
|
}
|
|
165
|
+
|
|
254
166
|
/**
|
|
255
167
|
* The ID of this object, unique within its class.
|
|
256
168
|
*
|
|
257
169
|
* @property {string} id
|
|
258
170
|
*/
|
|
259
|
-
|
|
260
171
|
/*:: id: ?string;*/
|
|
261
|
-
|
|
262
172
|
/*:: _localId: ?string;*/
|
|
263
|
-
|
|
264
173
|
/*:: _objCount: number;*/
|
|
265
|
-
|
|
266
174
|
/*:: className: string;*/
|
|
175
|
+
/* Prototype getters / setters */
|
|
267
176
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
get attributes()
|
|
272
|
-
/*: AttributeMap*/
|
|
273
|
-
{
|
|
177
|
+
get attributes() /*: AttributeMap*/{
|
|
274
178
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
275
|
-
|
|
276
179
|
return Object.freeze(stateController.estimateAttributes(this._getStateIdentifier()));
|
|
277
180
|
}
|
|
181
|
+
|
|
278
182
|
/**
|
|
279
183
|
* The first time this object was saved on the server.
|
|
280
184
|
*
|
|
281
185
|
* @property {Date} createdAt
|
|
282
186
|
* @returns {Date}
|
|
283
187
|
*/
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
get createdAt()
|
|
287
|
-
/*: ?Date*/
|
|
288
|
-
{
|
|
188
|
+
get createdAt() /*: ?Date*/{
|
|
289
189
|
return this._getServerData().createdAt;
|
|
290
190
|
}
|
|
191
|
+
|
|
291
192
|
/**
|
|
292
193
|
* The last time this object was updated on the server.
|
|
293
194
|
*
|
|
294
195
|
* @property {Date} updatedAt
|
|
295
196
|
* @returns {Date}
|
|
296
197
|
*/
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
get updatedAt()
|
|
300
|
-
/*: ?Date*/
|
|
301
|
-
{
|
|
198
|
+
get updatedAt() /*: ?Date*/{
|
|
302
199
|
return this._getServerData().updatedAt;
|
|
303
200
|
}
|
|
304
|
-
|
|
201
|
+
|
|
202
|
+
/* Private methods */
|
|
305
203
|
|
|
306
204
|
/**
|
|
307
205
|
* Returns a local or server Id used uniquely identify this object
|
|
308
206
|
*
|
|
309
207
|
* @returns {string}
|
|
310
208
|
*/
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
_getId()
|
|
314
|
-
/*: string*/
|
|
315
|
-
{
|
|
209
|
+
_getId() /*: string*/{
|
|
316
210
|
if (typeof this.id === 'string') {
|
|
317
211
|
return this.id;
|
|
318
212
|
}
|
|
319
|
-
|
|
320
213
|
if (typeof this._localId === 'string') {
|
|
321
214
|
return this._localId;
|
|
322
215
|
}
|
|
323
|
-
|
|
324
216
|
const localId = 'local' + uuidv4();
|
|
325
217
|
this._localId = localId;
|
|
326
218
|
return localId;
|
|
327
219
|
}
|
|
220
|
+
|
|
328
221
|
/**
|
|
329
222
|
* Returns a unique identifier used to pull data from the State Controller.
|
|
330
223
|
*
|
|
331
224
|
* @returns {Parse.Object|object}
|
|
332
225
|
*/
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
_getStateIdentifier()
|
|
336
|
-
/*: ParseObject | { id: string, className: string }*/
|
|
337
|
-
{
|
|
226
|
+
_getStateIdentifier() /*: ParseObject | { id: string, className: string }*/{
|
|
338
227
|
if (singleInstance) {
|
|
339
228
|
let id = this.id;
|
|
340
|
-
|
|
341
229
|
if (!id) {
|
|
342
230
|
id = this._getId();
|
|
343
231
|
}
|
|
344
|
-
|
|
345
232
|
return {
|
|
346
233
|
id: id,
|
|
347
234
|
className: this.className
|
|
@@ -350,74 +237,49 @@ class ParseObject {
|
|
|
350
237
|
return this;
|
|
351
238
|
}
|
|
352
239
|
}
|
|
353
|
-
|
|
354
|
-
_getServerData()
|
|
355
|
-
/*: AttributeMap*/
|
|
356
|
-
{
|
|
240
|
+
_getServerData() /*: AttributeMap*/{
|
|
357
241
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
358
|
-
|
|
359
242
|
return stateController.getServerData(this._getStateIdentifier());
|
|
360
243
|
}
|
|
361
|
-
|
|
362
244
|
_clearServerData() {
|
|
363
245
|
const serverData = this._getServerData();
|
|
364
|
-
|
|
365
246
|
const unset = {};
|
|
366
|
-
|
|
367
247
|
for (const attr in serverData) {
|
|
368
248
|
unset[attr] = undefined;
|
|
369
249
|
}
|
|
370
|
-
|
|
371
250
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
372
|
-
|
|
373
251
|
stateController.setServerData(this._getStateIdentifier(), unset);
|
|
374
252
|
}
|
|
375
|
-
|
|
376
|
-
_getPendingOps()
|
|
377
|
-
/*: Array<OpsMap>*/
|
|
378
|
-
{
|
|
253
|
+
_getPendingOps() /*: Array<OpsMap>*/{
|
|
379
254
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
380
|
-
|
|
381
255
|
return stateController.getPendingOps(this._getStateIdentifier());
|
|
382
256
|
}
|
|
257
|
+
|
|
383
258
|
/**
|
|
384
259
|
* @param {Array<string>} [keysToClear] - if specified, only ops matching
|
|
385
260
|
* these fields will be cleared
|
|
386
261
|
*/
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
_clearPendingOps(keysToClear
|
|
390
|
-
/*:: ?: Array<string>*/
|
|
391
|
-
) {
|
|
262
|
+
_clearPendingOps(keysToClear /*:: ?: Array<string>*/) {
|
|
392
263
|
const pending = this._getPendingOps();
|
|
393
|
-
|
|
394
264
|
const latest = pending[pending.length - 1];
|
|
395
265
|
const keys = keysToClear || Object.keys(latest);
|
|
396
266
|
keys.forEach(key => {
|
|
397
267
|
delete latest[key];
|
|
398
268
|
});
|
|
399
269
|
}
|
|
400
|
-
|
|
401
|
-
_getDirtyObjectAttributes()
|
|
402
|
-
/*: AttributeMap*/
|
|
403
|
-
{
|
|
270
|
+
_getDirtyObjectAttributes() /*: AttributeMap*/{
|
|
404
271
|
const attributes = this.attributes;
|
|
405
|
-
|
|
406
272
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
407
|
-
|
|
408
273
|
const objectCache = stateController.getObjectCache(this._getStateIdentifier());
|
|
409
274
|
const dirty = {};
|
|
410
|
-
|
|
411
275
|
for (const attr in attributes) {
|
|
412
276
|
const val = attributes[attr];
|
|
413
|
-
|
|
414
277
|
if (val && typeof val === 'object' && !(val instanceof ParseObject) && !(val instanceof _ParseFile.default) && !(val instanceof _ParseRelation.default)) {
|
|
415
278
|
// Due to the way browsers construct maps, the key order will not change
|
|
416
279
|
// unless the object is changed
|
|
417
280
|
try {
|
|
418
281
|
const json = (0, _encode.default)(val, false, true);
|
|
419
282
|
const stringified = JSON.stringify(json);
|
|
420
|
-
|
|
421
283
|
if (objectCache[attr] !== stringified) {
|
|
422
284
|
dirty[attr] = val;
|
|
423
285
|
}
|
|
@@ -428,43 +290,25 @@ class ParseObject {
|
|
|
428
290
|
}
|
|
429
291
|
}
|
|
430
292
|
}
|
|
431
|
-
|
|
432
293
|
return dirty;
|
|
433
294
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
/*:: ?: Array<any>*/
|
|
437
|
-
, offline
|
|
438
|
-
/*:: ?: boolean*/
|
|
439
|
-
)
|
|
440
|
-
/*: AttributeMap*/
|
|
441
|
-
{
|
|
442
|
-
const json
|
|
443
|
-
/*: { [key: string]: mixed }*/
|
|
444
|
-
= this.toJSON(seen, offline);
|
|
295
|
+
_toFullJSON(seen /*:: ?: Array<any>*/, offline /*:: ?: boolean*/) /*: AttributeMap*/{
|
|
296
|
+
const json /*: { [key: string]: mixed }*/ = this.toJSON(seen, offline);
|
|
445
297
|
json.__type = 'Object';
|
|
446
298
|
json.className = this.className;
|
|
447
299
|
return json;
|
|
448
300
|
}
|
|
449
|
-
|
|
450
|
-
_getSaveJSON()
|
|
451
|
-
/*: AttributeMap*/
|
|
452
|
-
{
|
|
301
|
+
_getSaveJSON() /*: AttributeMap*/{
|
|
453
302
|
const pending = this._getPendingOps();
|
|
454
|
-
|
|
455
303
|
const dirtyObjects = this._getDirtyObjectAttributes();
|
|
456
|
-
|
|
457
304
|
const json = {};
|
|
458
|
-
|
|
459
305
|
for (var attr in dirtyObjects) {
|
|
460
306
|
let isDotNotation = false;
|
|
461
|
-
|
|
462
307
|
for (let i = 0; i < pending.length; i += 1) {
|
|
463
308
|
for (const field in pending[i]) {
|
|
464
309
|
// Dot notation operations are handled later
|
|
465
310
|
if (field.includes('.')) {
|
|
466
311
|
const fieldName = field.split('.')[0];
|
|
467
|
-
|
|
468
312
|
if (fieldName === attr) {
|
|
469
313
|
isDotNotation = true;
|
|
470
314
|
break;
|
|
@@ -472,28 +316,19 @@ class ParseObject {
|
|
|
472
316
|
}
|
|
473
317
|
}
|
|
474
318
|
}
|
|
475
|
-
|
|
476
319
|
if (!isDotNotation) {
|
|
477
320
|
json[attr] = new _ParseOp.SetOp(dirtyObjects[attr]).toJSON();
|
|
478
321
|
}
|
|
479
322
|
}
|
|
480
|
-
|
|
481
323
|
for (attr in pending[0]) {
|
|
482
324
|
json[attr] = pending[0][attr].toJSON();
|
|
483
325
|
}
|
|
484
|
-
|
|
485
326
|
return json;
|
|
486
327
|
}
|
|
487
|
-
|
|
488
|
-
_getSaveParams()
|
|
489
|
-
/*: SaveParams*/
|
|
490
|
-
{
|
|
328
|
+
_getSaveParams() /*: SaveParams*/{
|
|
491
329
|
let method = this.id ? 'PUT' : 'POST';
|
|
492
|
-
|
|
493
330
|
const body = this._getSaveJSON();
|
|
494
|
-
|
|
495
331
|
let path = 'classes/' + this.className;
|
|
496
|
-
|
|
497
332
|
if (_CoreManager.default.get('ALLOW_CUSTOM_OBJECT_ID')) {
|
|
498
333
|
if (!this.createdAt) {
|
|
499
334
|
method = 'POST';
|
|
@@ -507,76 +342,54 @@ class ParseObject {
|
|
|
507
342
|
} else if (this.className === '_User') {
|
|
508
343
|
path = 'users';
|
|
509
344
|
}
|
|
510
|
-
|
|
511
345
|
return {
|
|
512
346
|
method,
|
|
513
347
|
body,
|
|
514
348
|
path
|
|
515
349
|
};
|
|
516
350
|
}
|
|
517
|
-
|
|
518
|
-
_finishFetch(serverData
|
|
519
|
-
/*: AttributeMap*/
|
|
520
|
-
) {
|
|
351
|
+
_finishFetch(serverData /*: AttributeMap*/) {
|
|
521
352
|
if (!this.id && serverData.objectId) {
|
|
522
353
|
this.id = serverData.objectId;
|
|
523
354
|
}
|
|
524
|
-
|
|
525
355
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
526
|
-
|
|
527
356
|
stateController.initializeState(this._getStateIdentifier());
|
|
528
357
|
const decoded = {};
|
|
529
|
-
|
|
530
358
|
for (const attr in serverData) {
|
|
531
359
|
if (attr === 'ACL') {
|
|
532
360
|
decoded[attr] = new _ParseACL.default(serverData[attr]);
|
|
533
361
|
} else if (attr !== 'objectId') {
|
|
534
362
|
decoded[attr] = (0, _decode.default)(serverData[attr]);
|
|
535
|
-
|
|
536
363
|
if (decoded[attr] instanceof _ParseRelation.default) {
|
|
537
364
|
decoded[attr]._ensureParentAndKey(this, attr);
|
|
538
365
|
}
|
|
539
366
|
}
|
|
540
367
|
}
|
|
541
|
-
|
|
542
368
|
if (decoded.createdAt && typeof decoded.createdAt === 'string') {
|
|
543
369
|
decoded.createdAt = (0, _parseDate.default)(decoded.createdAt);
|
|
544
370
|
}
|
|
545
|
-
|
|
546
371
|
if (decoded.updatedAt && typeof decoded.updatedAt === 'string') {
|
|
547
372
|
decoded.updatedAt = (0, _parseDate.default)(decoded.updatedAt);
|
|
548
373
|
}
|
|
549
|
-
|
|
550
374
|
if (!decoded.updatedAt && decoded.createdAt) {
|
|
551
375
|
decoded.updatedAt = decoded.createdAt;
|
|
552
376
|
}
|
|
553
|
-
|
|
554
377
|
stateController.commitServerChanges(this._getStateIdentifier(), decoded);
|
|
555
378
|
}
|
|
556
|
-
|
|
557
|
-
_setExisted(existed
|
|
558
|
-
/*: boolean*/
|
|
559
|
-
) {
|
|
379
|
+
_setExisted(existed /*: boolean*/) {
|
|
560
380
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
561
|
-
|
|
562
381
|
const state = stateController.getState(this._getStateIdentifier());
|
|
563
|
-
|
|
564
382
|
if (state) {
|
|
565
383
|
state.existed = existed;
|
|
566
384
|
}
|
|
567
385
|
}
|
|
568
|
-
|
|
569
|
-
_migrateId(serverId
|
|
570
|
-
/*: string*/
|
|
571
|
-
) {
|
|
386
|
+
_migrateId(serverId /*: string*/) {
|
|
572
387
|
if (this._localId && serverId) {
|
|
573
388
|
if (singleInstance) {
|
|
574
389
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
575
|
-
|
|
576
390
|
const oldState = stateController.removeState(this._getStateIdentifier());
|
|
577
391
|
this.id = serverId;
|
|
578
392
|
delete this._localId;
|
|
579
|
-
|
|
580
393
|
if (oldState) {
|
|
581
394
|
stateController.initializeState(this._getStateIdentifier(), oldState);
|
|
582
395
|
}
|
|
@@ -586,18 +399,10 @@ class ParseObject {
|
|
|
586
399
|
}
|
|
587
400
|
}
|
|
588
401
|
}
|
|
589
|
-
|
|
590
|
-
_handleSaveResponse(response
|
|
591
|
-
/*: AttributeMap*/
|
|
592
|
-
, status
|
|
593
|
-
/*: number*/
|
|
594
|
-
) {
|
|
402
|
+
_handleSaveResponse(response /*: AttributeMap*/, status /*: number*/) {
|
|
595
403
|
const changes = {};
|
|
596
|
-
|
|
597
404
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
598
|
-
|
|
599
405
|
const pending = stateController.popPendingState(this._getStateIdentifier());
|
|
600
|
-
|
|
601
406
|
for (var attr in pending) {
|
|
602
407
|
if (pending[attr] instanceof _ParseOp.RelationOp) {
|
|
603
408
|
changes[attr] = pending[attr].applyTo(undefined, this, attr);
|
|
@@ -606,7 +411,6 @@ class ParseObject {
|
|
|
606
411
|
changes[attr] = pending[attr].applyTo(undefined);
|
|
607
412
|
}
|
|
608
413
|
}
|
|
609
|
-
|
|
610
414
|
for (attr in response) {
|
|
611
415
|
if ((attr === 'createdAt' || attr === 'updatedAt') && typeof response[attr] === 'string') {
|
|
612
416
|
changes[attr] = (0, _parseDate.default)(response[attr]);
|
|
@@ -614,46 +418,42 @@ class ParseObject {
|
|
|
614
418
|
changes[attr] = new _ParseACL.default(response[attr]);
|
|
615
419
|
} else if (attr !== 'objectId') {
|
|
616
420
|
const val = (0, _decode.default)(response[attr]);
|
|
617
|
-
|
|
618
421
|
if (val && Object.getPrototypeOf(val) === Object.prototype) {
|
|
619
|
-
changes[attr] =
|
|
422
|
+
changes[attr] = {
|
|
423
|
+
...this.attributes[attr],
|
|
424
|
+
...val
|
|
425
|
+
};
|
|
620
426
|
} else {
|
|
621
427
|
changes[attr] = val;
|
|
622
428
|
}
|
|
623
|
-
|
|
624
429
|
if (changes[attr] instanceof _ParseOp.UnsetOp) {
|
|
625
430
|
changes[attr] = undefined;
|
|
626
431
|
}
|
|
627
432
|
}
|
|
628
433
|
}
|
|
629
|
-
|
|
630
434
|
if (changes.createdAt && !changes.updatedAt) {
|
|
631
435
|
changes.updatedAt = changes.createdAt;
|
|
632
436
|
}
|
|
633
|
-
|
|
634
437
|
this._migrateId(response.objectId);
|
|
635
|
-
|
|
636
438
|
if (status !== 201) {
|
|
637
439
|
this._setExisted(true);
|
|
638
440
|
}
|
|
639
|
-
|
|
640
441
|
stateController.commitServerChanges(this._getStateIdentifier(), changes);
|
|
641
442
|
}
|
|
642
|
-
|
|
643
443
|
_handleSaveError() {
|
|
644
444
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
645
|
-
|
|
646
445
|
stateController.mergeFirstPendingState(this._getStateIdentifier());
|
|
647
446
|
}
|
|
648
|
-
|
|
649
447
|
static _getClassMap() {
|
|
650
448
|
return classMap;
|
|
651
449
|
}
|
|
652
|
-
/** Public methods **/
|
|
653
450
|
|
|
451
|
+
/* Public methods */
|
|
654
452
|
|
|
655
|
-
initialize() {
|
|
453
|
+
initialize() {
|
|
454
|
+
// NOOP
|
|
656
455
|
}
|
|
456
|
+
|
|
657
457
|
/**
|
|
658
458
|
* Returns a JSON version of the object suitable for saving to Parse.
|
|
659
459
|
*
|
|
@@ -661,20 +461,11 @@ class ParseObject {
|
|
|
661
461
|
* @param offline
|
|
662
462
|
* @returns {object}
|
|
663
463
|
*/
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
toJSON(seen
|
|
667
|
-
/*: Array<any> | void*/
|
|
668
|
-
, offline
|
|
669
|
-
/*:: ?: boolean*/
|
|
670
|
-
)
|
|
671
|
-
/*: AttributeMap*/
|
|
672
|
-
{
|
|
464
|
+
toJSON(seen /*: Array<any> | void*/, offline /*:: ?: boolean*/) /*: AttributeMap*/{
|
|
673
465
|
const seenEntry = this.id ? this.className + ':' + this.id : this;
|
|
674
466
|
seen = seen || [seenEntry];
|
|
675
467
|
const json = {};
|
|
676
468
|
const attrs = this.attributes;
|
|
677
|
-
|
|
678
469
|
for (const attr in attrs) {
|
|
679
470
|
if ((attr === 'createdAt' || attr === 'updatedAt') && attrs[attr].toJSON) {
|
|
680
471
|
json[attr] = attrs[attr].toJSON();
|
|
@@ -682,38 +473,29 @@ class ParseObject {
|
|
|
682
473
|
json[attr] = (0, _encode.default)(attrs[attr], false, false, seen, offline);
|
|
683
474
|
}
|
|
684
475
|
}
|
|
685
|
-
|
|
686
476
|
const pending = this._getPendingOps();
|
|
687
|
-
|
|
688
477
|
for (const attr in pending[0]) {
|
|
689
478
|
json[attr] = pending[0][attr].toJSON(offline);
|
|
690
479
|
}
|
|
691
|
-
|
|
692
480
|
if (this.id) {
|
|
693
481
|
json.objectId = this.id;
|
|
694
482
|
}
|
|
695
|
-
|
|
696
483
|
return json;
|
|
697
484
|
}
|
|
485
|
+
|
|
698
486
|
/**
|
|
699
487
|
* Determines whether this ParseObject is equal to another ParseObject
|
|
700
488
|
*
|
|
701
489
|
* @param {object} other - An other object ot compare
|
|
702
490
|
* @returns {boolean}
|
|
703
491
|
*/
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
equals(other
|
|
707
|
-
/*: mixed*/
|
|
708
|
-
)
|
|
709
|
-
/*: boolean*/
|
|
710
|
-
{
|
|
492
|
+
equals(other /*: mixed*/) /*: boolean*/{
|
|
711
493
|
if (this === other) {
|
|
712
494
|
return true;
|
|
713
495
|
}
|
|
714
|
-
|
|
715
496
|
return other instanceof ParseObject && this.className === other.className && this.id === other.id && typeof this.id !== 'undefined';
|
|
716
497
|
}
|
|
498
|
+
|
|
717
499
|
/**
|
|
718
500
|
* Returns true if this object has been modified since its last
|
|
719
501
|
* save/refresh. If an attribute is specified, it returns true only if that
|
|
@@ -722,198 +504,142 @@ class ParseObject {
|
|
|
722
504
|
* @param {string} attr An attribute name (optional).
|
|
723
505
|
* @returns {boolean}
|
|
724
506
|
*/
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
dirty(attr
|
|
728
|
-
/*:: ?: string*/
|
|
729
|
-
)
|
|
730
|
-
/*: boolean*/
|
|
731
|
-
{
|
|
507
|
+
dirty(attr /*:: ?: string*/) /*: boolean*/{
|
|
732
508
|
if (!this.id) {
|
|
733
509
|
return true;
|
|
734
510
|
}
|
|
735
|
-
|
|
736
511
|
const pendingOps = this._getPendingOps();
|
|
737
|
-
|
|
738
512
|
const dirtyObjects = this._getDirtyObjectAttributes();
|
|
739
|
-
|
|
740
513
|
if (attr) {
|
|
741
514
|
if (dirtyObjects.hasOwnProperty(attr)) {
|
|
742
515
|
return true;
|
|
743
516
|
}
|
|
744
|
-
|
|
745
517
|
for (let i = 0; i < pendingOps.length; i++) {
|
|
746
518
|
if (pendingOps[i].hasOwnProperty(attr)) {
|
|
747
519
|
return true;
|
|
748
520
|
}
|
|
749
521
|
}
|
|
750
|
-
|
|
751
522
|
return false;
|
|
752
523
|
}
|
|
753
|
-
|
|
754
524
|
if (Object.keys(pendingOps[0]).length !== 0) {
|
|
755
525
|
return true;
|
|
756
526
|
}
|
|
757
|
-
|
|
758
527
|
if (Object.keys(dirtyObjects).length !== 0) {
|
|
759
528
|
return true;
|
|
760
529
|
}
|
|
761
|
-
|
|
762
530
|
return false;
|
|
763
531
|
}
|
|
532
|
+
|
|
764
533
|
/**
|
|
765
534
|
* Returns an array of keys that have been modified since last save/refresh
|
|
766
535
|
*
|
|
767
536
|
* @returns {string[]}
|
|
768
537
|
*/
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
dirtyKeys()
|
|
772
|
-
/*: Array<string>*/
|
|
773
|
-
{
|
|
538
|
+
dirtyKeys() /*: Array<string>*/{
|
|
774
539
|
const pendingOps = this._getPendingOps();
|
|
775
|
-
|
|
776
540
|
const keys = {};
|
|
777
|
-
|
|
778
541
|
for (let i = 0; i < pendingOps.length; i++) {
|
|
779
542
|
for (const attr in pendingOps[i]) {
|
|
780
543
|
keys[attr] = true;
|
|
781
544
|
}
|
|
782
545
|
}
|
|
783
|
-
|
|
784
546
|
const dirtyObjects = this._getDirtyObjectAttributes();
|
|
785
|
-
|
|
786
547
|
for (const attr in dirtyObjects) {
|
|
787
548
|
keys[attr] = true;
|
|
788
549
|
}
|
|
789
|
-
|
|
790
550
|
return Object.keys(keys);
|
|
791
551
|
}
|
|
552
|
+
|
|
792
553
|
/**
|
|
793
554
|
* Returns true if the object has been fetched.
|
|
794
555
|
*
|
|
795
556
|
* @returns {boolean}
|
|
796
557
|
*/
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
isDataAvailable()
|
|
800
|
-
/*: boolean*/
|
|
801
|
-
{
|
|
558
|
+
isDataAvailable() /*: boolean*/{
|
|
802
559
|
const serverData = this._getServerData();
|
|
803
|
-
|
|
804
560
|
return !!Object.keys(serverData).length;
|
|
805
561
|
}
|
|
562
|
+
|
|
806
563
|
/**
|
|
807
564
|
* Gets a Pointer referencing this Object.
|
|
808
565
|
*
|
|
809
566
|
* @returns {Pointer}
|
|
810
567
|
*/
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
toPointer()
|
|
814
|
-
/*: Pointer*/
|
|
815
|
-
{
|
|
568
|
+
toPointer() /*: Pointer*/{
|
|
816
569
|
if (!this.id) {
|
|
817
570
|
throw new Error('Cannot create a pointer to an unsaved ParseObject');
|
|
818
571
|
}
|
|
819
|
-
|
|
820
572
|
return {
|
|
821
573
|
__type: 'Pointer',
|
|
822
574
|
className: this.className,
|
|
823
575
|
objectId: this.id
|
|
824
576
|
};
|
|
825
577
|
}
|
|
578
|
+
|
|
826
579
|
/**
|
|
827
580
|
* Gets a Pointer referencing this Object.
|
|
828
581
|
*
|
|
829
582
|
* @returns {Pointer}
|
|
830
583
|
*/
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
toOfflinePointer()
|
|
834
|
-
/*: Pointer*/
|
|
835
|
-
{
|
|
584
|
+
toOfflinePointer() /*: Pointer*/{
|
|
836
585
|
if (!this._localId) {
|
|
837
586
|
throw new Error('Cannot create a offline pointer to a saved ParseObject');
|
|
838
587
|
}
|
|
839
|
-
|
|
840
588
|
return {
|
|
841
589
|
__type: 'Object',
|
|
842
590
|
className: this.className,
|
|
843
591
|
_localId: this._localId
|
|
844
592
|
};
|
|
845
593
|
}
|
|
594
|
+
|
|
846
595
|
/**
|
|
847
596
|
* Gets the value of an attribute.
|
|
848
597
|
*
|
|
849
598
|
* @param {string} attr The string name of an attribute.
|
|
850
599
|
* @returns {*}
|
|
851
600
|
*/
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
get(attr
|
|
855
|
-
/*: string*/
|
|
856
|
-
)
|
|
857
|
-
/*: mixed*/
|
|
858
|
-
{
|
|
601
|
+
get(attr /*: string*/) /*: mixed*/{
|
|
859
602
|
return this.attributes[attr];
|
|
860
603
|
}
|
|
604
|
+
|
|
861
605
|
/**
|
|
862
606
|
* Gets a relation on the given class for the attribute.
|
|
863
607
|
*
|
|
864
608
|
* @param {string} attr The attribute to get the relation for.
|
|
865
609
|
* @returns {Parse.Relation}
|
|
866
610
|
*/
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
relation(attr
|
|
870
|
-
/*: string*/
|
|
871
|
-
)
|
|
872
|
-
/*: ParseRelation*/
|
|
873
|
-
{
|
|
611
|
+
relation(attr /*: string*/) /*: ParseRelation*/{
|
|
874
612
|
const value = this.get(attr);
|
|
875
|
-
|
|
876
613
|
if (value) {
|
|
877
614
|
if (!(value instanceof _ParseRelation.default)) {
|
|
878
615
|
throw new Error('Called relation() on non-relation field ' + attr);
|
|
879
616
|
}
|
|
880
|
-
|
|
881
617
|
value._ensureParentAndKey(this, attr);
|
|
882
|
-
|
|
883
618
|
return value;
|
|
884
619
|
}
|
|
885
|
-
|
|
886
620
|
return new _ParseRelation.default(this, attr);
|
|
887
621
|
}
|
|
622
|
+
|
|
888
623
|
/**
|
|
889
624
|
* Gets the HTML-escaped value of an attribute.
|
|
890
625
|
*
|
|
891
626
|
* @param {string} attr The string name of an attribute.
|
|
892
627
|
* @returns {string}
|
|
893
628
|
*/
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
escape(attr
|
|
897
|
-
/*: string*/
|
|
898
|
-
)
|
|
899
|
-
/*: string*/
|
|
900
|
-
{
|
|
629
|
+
escape(attr /*: string*/) /*: string*/{
|
|
901
630
|
let val = this.attributes[attr];
|
|
902
|
-
|
|
903
631
|
if (val == null) {
|
|
904
632
|
return '';
|
|
905
633
|
}
|
|
906
|
-
|
|
907
634
|
if (typeof val !== 'string') {
|
|
908
635
|
if (typeof val.toString !== 'function') {
|
|
909
636
|
return '';
|
|
910
637
|
}
|
|
911
|
-
|
|
912
638
|
val = val.toString();
|
|
913
639
|
}
|
|
914
|
-
|
|
915
640
|
return (0, _escape.default)(val);
|
|
916
641
|
}
|
|
642
|
+
|
|
917
643
|
/**
|
|
918
644
|
* Returns <code>true</code> if the attribute contains a value that is not
|
|
919
645
|
* null or undefined.
|
|
@@ -921,21 +647,14 @@ class ParseObject {
|
|
|
921
647
|
* @param {string} attr The string name of the attribute.
|
|
922
648
|
* @returns {boolean}
|
|
923
649
|
*/
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
has(attr
|
|
927
|
-
/*: string*/
|
|
928
|
-
)
|
|
929
|
-
/*: boolean*/
|
|
930
|
-
{
|
|
650
|
+
has(attr /*: string*/) /*: boolean*/{
|
|
931
651
|
const attributes = this.attributes;
|
|
932
|
-
|
|
933
652
|
if (attributes.hasOwnProperty(attr)) {
|
|
934
653
|
return attributes[attr] != null;
|
|
935
654
|
}
|
|
936
|
-
|
|
937
655
|
return false;
|
|
938
656
|
}
|
|
657
|
+
|
|
939
658
|
/**
|
|
940
659
|
* Sets a hash of model attributes on the object.
|
|
941
660
|
*
|
|
@@ -966,20 +685,9 @@ class ParseObject {
|
|
|
966
685
|
* The only supported option is <code>error</code>.
|
|
967
686
|
* @returns {(ParseObject|boolean)} true if the set succeeded.
|
|
968
687
|
*/
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
set(key
|
|
972
|
-
/*: mixed*/
|
|
973
|
-
, value
|
|
974
|
-
/*: mixed*/
|
|
975
|
-
, options
|
|
976
|
-
/*:: ?: mixed*/
|
|
977
|
-
)
|
|
978
|
-
/*: ParseObject | boolean*/
|
|
979
|
-
{
|
|
688
|
+
set(key /*: mixed*/, value /*: mixed*/, options /*:: ?: mixed*/) /*: ParseObject | boolean*/{
|
|
980
689
|
let changes = {};
|
|
981
690
|
const newOps = {};
|
|
982
|
-
|
|
983
691
|
if (key && typeof key === 'object') {
|
|
984
692
|
changes = key;
|
|
985
693
|
options = value;
|
|
@@ -988,25 +696,20 @@ class ParseObject {
|
|
|
988
696
|
} else {
|
|
989
697
|
return this;
|
|
990
698
|
}
|
|
991
|
-
|
|
992
699
|
options = options || {};
|
|
993
700
|
let readonly = [];
|
|
994
|
-
|
|
995
701
|
if (typeof this.constructor.readOnlyAttributes === 'function') {
|
|
996
702
|
readonly = readonly.concat(this.constructor.readOnlyAttributes());
|
|
997
703
|
}
|
|
998
|
-
|
|
999
704
|
for (const k in changes) {
|
|
1000
705
|
if (k === 'createdAt' || k === 'updatedAt') {
|
|
1001
706
|
// This property is read-only, but for legacy reasons we silently
|
|
1002
707
|
// ignore it
|
|
1003
708
|
continue;
|
|
1004
709
|
}
|
|
1005
|
-
|
|
1006
710
|
if (readonly.indexOf(k) > -1) {
|
|
1007
711
|
throw new Error('Cannot modify readonly attribute: ' + k);
|
|
1008
712
|
}
|
|
1009
|
-
|
|
1010
713
|
if (options.unset) {
|
|
1011
714
|
newOps[k] = new _ParseOp.UnsetOp();
|
|
1012
715
|
} else if (changes[k] instanceof _ParseOp.Op) {
|
|
@@ -1027,46 +730,40 @@ class ParseObject {
|
|
|
1027
730
|
newOps[k] = new _ParseOp.SetOp(changes[k]);
|
|
1028
731
|
}
|
|
1029
732
|
}
|
|
733
|
+
const currentAttributes = this.attributes;
|
|
1030
734
|
|
|
1031
|
-
|
|
1032
|
-
|
|
735
|
+
// Calculate new values
|
|
1033
736
|
const newValues = {};
|
|
1034
|
-
|
|
1035
737
|
for (const attr in newOps) {
|
|
1036
738
|
if (newOps[attr] instanceof _ParseOp.RelationOp) {
|
|
1037
739
|
newValues[attr] = newOps[attr].applyTo(currentAttributes[attr], this, attr);
|
|
1038
740
|
} else if (!(newOps[attr] instanceof _ParseOp.UnsetOp)) {
|
|
1039
741
|
newValues[attr] = newOps[attr].applyTo(currentAttributes[attr]);
|
|
1040
742
|
}
|
|
1041
|
-
}
|
|
1042
|
-
|
|
743
|
+
}
|
|
1043
744
|
|
|
745
|
+
// Validate changes
|
|
1044
746
|
if (!options.ignoreValidation) {
|
|
1045
747
|
const validation = this.validate(newValues);
|
|
1046
|
-
|
|
1047
748
|
if (validation) {
|
|
1048
749
|
if (typeof options.error === 'function') {
|
|
1049
750
|
options.error(this, validation);
|
|
1050
751
|
}
|
|
1051
|
-
|
|
1052
752
|
return false;
|
|
1053
753
|
}
|
|
1054
|
-
}
|
|
1055
|
-
|
|
754
|
+
}
|
|
1056
755
|
|
|
756
|
+
// Consolidate Ops
|
|
1057
757
|
const pendingOps = this._getPendingOps();
|
|
1058
|
-
|
|
1059
758
|
const last = pendingOps.length - 1;
|
|
1060
|
-
|
|
1061
759
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
1062
|
-
|
|
1063
760
|
for (const attr in newOps) {
|
|
1064
761
|
const nextOp = newOps[attr].mergeWith(pendingOps[last][attr]);
|
|
1065
762
|
stateController.setPendingOp(this._getStateIdentifier(), attr, nextOp);
|
|
1066
763
|
}
|
|
1067
|
-
|
|
1068
764
|
return this;
|
|
1069
765
|
}
|
|
766
|
+
|
|
1070
767
|
/**
|
|
1071
768
|
* Remove an attribute from the model. This is a noop if the attribute doesn't
|
|
1072
769
|
* exist.
|
|
@@ -1075,19 +772,12 @@ class ParseObject {
|
|
|
1075
772
|
* @param options
|
|
1076
773
|
* @returns {(ParseObject | boolean)}
|
|
1077
774
|
*/
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
unset(attr
|
|
1081
|
-
/*: string*/
|
|
1082
|
-
, options
|
|
1083
|
-
/*:: ?: { [opt: string]: mixed }*/
|
|
1084
|
-
)
|
|
1085
|
-
/*: ParseObject | boolean*/
|
|
1086
|
-
{
|
|
775
|
+
unset(attr /*: string*/, options /*:: ?: { [opt: string]: mixed }*/) /*: ParseObject | boolean*/{
|
|
1087
776
|
options = options || {};
|
|
1088
777
|
options.unset = true;
|
|
1089
778
|
return this.set(attr, null, options);
|
|
1090
779
|
}
|
|
780
|
+
|
|
1091
781
|
/**
|
|
1092
782
|
* Atomically increments the value of the given attribute the next time the
|
|
1093
783
|
* object is saved. If no amount is specified, 1 is used by default.
|
|
@@ -1096,25 +786,16 @@ class ParseObject {
|
|
|
1096
786
|
* @param amount {Number} The amount to increment by (optional).
|
|
1097
787
|
* @returns {(ParseObject|boolean)}
|
|
1098
788
|
*/
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
increment(attr
|
|
1102
|
-
/*: string*/
|
|
1103
|
-
, amount
|
|
1104
|
-
/*:: ?: number*/
|
|
1105
|
-
)
|
|
1106
|
-
/*: ParseObject | boolean*/
|
|
1107
|
-
{
|
|
789
|
+
increment(attr /*: string*/, amount /*:: ?: number*/) /*: ParseObject | boolean*/{
|
|
1108
790
|
if (typeof amount === 'undefined') {
|
|
1109
791
|
amount = 1;
|
|
1110
792
|
}
|
|
1111
|
-
|
|
1112
793
|
if (typeof amount !== 'number') {
|
|
1113
794
|
throw new Error('Cannot increment by a non-numeric amount.');
|
|
1114
795
|
}
|
|
1115
|
-
|
|
1116
796
|
return this.set(attr, new _ParseOp.IncrementOp(amount));
|
|
1117
797
|
}
|
|
798
|
+
|
|
1118
799
|
/**
|
|
1119
800
|
* Atomically decrements the value of the given attribute the next time the
|
|
1120
801
|
* object is saved. If no amount is specified, 1 is used by default.
|
|
@@ -1123,25 +804,16 @@ class ParseObject {
|
|
|
1123
804
|
* @param amount {Number} The amount to decrement by (optional).
|
|
1124
805
|
* @returns {(ParseObject | boolean)}
|
|
1125
806
|
*/
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
decrement(attr
|
|
1129
|
-
/*: string*/
|
|
1130
|
-
, amount
|
|
1131
|
-
/*:: ?: number*/
|
|
1132
|
-
)
|
|
1133
|
-
/*: ParseObject | boolean*/
|
|
1134
|
-
{
|
|
807
|
+
decrement(attr /*: string*/, amount /*:: ?: number*/) /*: ParseObject | boolean*/{
|
|
1135
808
|
if (typeof amount === 'undefined') {
|
|
1136
809
|
amount = 1;
|
|
1137
810
|
}
|
|
1138
|
-
|
|
1139
811
|
if (typeof amount !== 'number') {
|
|
1140
812
|
throw new Error('Cannot decrement by a non-numeric amount.');
|
|
1141
813
|
}
|
|
1142
|
-
|
|
1143
814
|
return this.set(attr, new _ParseOp.IncrementOp(amount * -1));
|
|
1144
815
|
}
|
|
816
|
+
|
|
1145
817
|
/**
|
|
1146
818
|
* Atomically add an object to the end of the array associated with a given
|
|
1147
819
|
* key.
|
|
@@ -1150,17 +822,10 @@ class ParseObject {
|
|
|
1150
822
|
* @param item {} The item to add.
|
|
1151
823
|
* @returns {(ParseObject | boolean)}
|
|
1152
824
|
*/
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
add(attr
|
|
1156
|
-
/*: string*/
|
|
1157
|
-
, item
|
|
1158
|
-
/*: mixed*/
|
|
1159
|
-
)
|
|
1160
|
-
/*: ParseObject | boolean*/
|
|
1161
|
-
{
|
|
825
|
+
add(attr /*: string*/, item /*: mixed*/) /*: ParseObject | boolean*/{
|
|
1162
826
|
return this.set(attr, new _ParseOp.AddOp([item]));
|
|
1163
827
|
}
|
|
828
|
+
|
|
1164
829
|
/**
|
|
1165
830
|
* Atomically add the objects to the end of the array associated with a given
|
|
1166
831
|
* key.
|
|
@@ -1169,17 +834,10 @@ class ParseObject {
|
|
|
1169
834
|
* @param items {Object[]} The items to add.
|
|
1170
835
|
* @returns {(ParseObject | boolean)}
|
|
1171
836
|
*/
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
addAll(attr
|
|
1175
|
-
/*: string*/
|
|
1176
|
-
, items
|
|
1177
|
-
/*: Array<mixed>*/
|
|
1178
|
-
)
|
|
1179
|
-
/*: ParseObject | boolean*/
|
|
1180
|
-
{
|
|
837
|
+
addAll(attr /*: string*/, items /*: Array<mixed>*/) /*: ParseObject | boolean*/{
|
|
1181
838
|
return this.set(attr, new _ParseOp.AddOp(items));
|
|
1182
839
|
}
|
|
840
|
+
|
|
1183
841
|
/**
|
|
1184
842
|
* Atomically add an object to the array associated with a given key, only
|
|
1185
843
|
* if it is not already present in the array. The position of the insert is
|
|
@@ -1189,17 +847,10 @@ class ParseObject {
|
|
|
1189
847
|
* @param item {} The object to add.
|
|
1190
848
|
* @returns {(ParseObject | boolean)}
|
|
1191
849
|
*/
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
addUnique(attr
|
|
1195
|
-
/*: string*/
|
|
1196
|
-
, item
|
|
1197
|
-
/*: mixed*/
|
|
1198
|
-
)
|
|
1199
|
-
/*: ParseObject | boolean*/
|
|
1200
|
-
{
|
|
850
|
+
addUnique(attr /*: string*/, item /*: mixed*/) /*: ParseObject | boolean*/{
|
|
1201
851
|
return this.set(attr, new _ParseOp.AddUniqueOp([item]));
|
|
1202
852
|
}
|
|
853
|
+
|
|
1203
854
|
/**
|
|
1204
855
|
* Atomically add the objects to the array associated with a given key, only
|
|
1205
856
|
* if it is not already present in the array. The position of the insert is
|
|
@@ -1209,17 +860,10 @@ class ParseObject {
|
|
|
1209
860
|
* @param items {Object[]} The objects to add.
|
|
1210
861
|
* @returns {(ParseObject | boolean)}
|
|
1211
862
|
*/
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
addAllUnique(attr
|
|
1215
|
-
/*: string*/
|
|
1216
|
-
, items
|
|
1217
|
-
/*: Array<mixed>*/
|
|
1218
|
-
)
|
|
1219
|
-
/*: ParseObject | boolean*/
|
|
1220
|
-
{
|
|
863
|
+
addAllUnique(attr /*: string*/, items /*: Array<mixed>*/) /*: ParseObject | boolean*/{
|
|
1221
864
|
return this.set(attr, new _ParseOp.AddUniqueOp(items));
|
|
1222
865
|
}
|
|
866
|
+
|
|
1223
867
|
/**
|
|
1224
868
|
* Atomically remove all instances of an object from the array associated
|
|
1225
869
|
* with a given key.
|
|
@@ -1228,17 +872,10 @@ class ParseObject {
|
|
|
1228
872
|
* @param item {} The object to remove.
|
|
1229
873
|
* @returns {(ParseObject | boolean)}
|
|
1230
874
|
*/
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
remove(attr
|
|
1234
|
-
/*: string*/
|
|
1235
|
-
, item
|
|
1236
|
-
/*: mixed*/
|
|
1237
|
-
)
|
|
1238
|
-
/*: ParseObject | boolean*/
|
|
1239
|
-
{
|
|
875
|
+
remove(attr /*: string*/, item /*: mixed*/) /*: ParseObject | boolean*/{
|
|
1240
876
|
return this.set(attr, new _ParseOp.RemoveOp([item]));
|
|
1241
877
|
}
|
|
878
|
+
|
|
1242
879
|
/**
|
|
1243
880
|
* Atomically remove all instances of the objects from the array associated
|
|
1244
881
|
* with a given key.
|
|
@@ -1247,17 +884,10 @@ class ParseObject {
|
|
|
1247
884
|
* @param items {Object[]} The object to remove.
|
|
1248
885
|
* @returns {(ParseObject | boolean)}
|
|
1249
886
|
*/
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
removeAll(attr
|
|
1253
|
-
/*: string*/
|
|
1254
|
-
, items
|
|
1255
|
-
/*: Array<mixed>*/
|
|
1256
|
-
)
|
|
1257
|
-
/*: ParseObject | boolean*/
|
|
1258
|
-
{
|
|
887
|
+
removeAll(attr /*: string*/, items /*: Array<mixed>*/) /*: ParseObject | boolean*/{
|
|
1259
888
|
return this.set(attr, new _ParseOp.RemoveOp(items));
|
|
1260
889
|
}
|
|
890
|
+
|
|
1261
891
|
/**
|
|
1262
892
|
* Returns an instance of a subclass of Parse.Op describing what kind of
|
|
1263
893
|
* modification has been performed on this field since the last time it was
|
|
@@ -1265,95 +895,71 @@ class ParseObject {
|
|
|
1265
895
|
* object.op("x") would return an instance of Parse.Op.Increment.
|
|
1266
896
|
*
|
|
1267
897
|
* @param attr {String} The key.
|
|
1268
|
-
* @returns {Parse.Op} The operation, or undefined if none.
|
|
898
|
+
* @returns {Parse.Op | undefined} The operation, or undefined if none.
|
|
1269
899
|
*/
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
op(attr
|
|
1273
|
-
/*: string*/
|
|
1274
|
-
)
|
|
1275
|
-
/*: ?Op*/
|
|
1276
|
-
{
|
|
900
|
+
op(attr /*: string*/) /*: ?Op*/{
|
|
1277
901
|
const pending = this._getPendingOps();
|
|
1278
|
-
|
|
1279
902
|
for (let i = pending.length; i--;) {
|
|
1280
903
|
if (pending[i][attr]) {
|
|
1281
904
|
return pending[i][attr];
|
|
1282
905
|
}
|
|
1283
906
|
}
|
|
1284
907
|
}
|
|
908
|
+
|
|
1285
909
|
/**
|
|
1286
910
|
* Creates a new model with identical attributes to this one.
|
|
1287
911
|
*
|
|
1288
912
|
* @returns {Parse.Object}
|
|
1289
913
|
*/
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
clone()
|
|
1293
|
-
/*: any*/
|
|
1294
|
-
{
|
|
914
|
+
clone() /*: any*/{
|
|
1295
915
|
const clone = new this.constructor(this.className);
|
|
1296
916
|
let attributes = this.attributes;
|
|
1297
|
-
|
|
1298
917
|
if (typeof this.constructor.readOnlyAttributes === 'function') {
|
|
1299
|
-
const readonly = this.constructor.readOnlyAttributes() || [];
|
|
918
|
+
const readonly = this.constructor.readOnlyAttributes() || [];
|
|
919
|
+
// Attributes are frozen, so we have to rebuild an object,
|
|
1300
920
|
// rather than delete readonly keys
|
|
1301
|
-
|
|
1302
921
|
const copy = {};
|
|
1303
|
-
|
|
1304
922
|
for (const a in attributes) {
|
|
1305
923
|
if (readonly.indexOf(a) < 0) {
|
|
1306
924
|
copy[a] = attributes[a];
|
|
1307
925
|
}
|
|
1308
926
|
}
|
|
1309
|
-
|
|
1310
927
|
attributes = copy;
|
|
1311
928
|
}
|
|
1312
|
-
|
|
1313
929
|
if (clone.set) {
|
|
1314
930
|
clone.set(attributes);
|
|
1315
931
|
}
|
|
1316
|
-
|
|
1317
932
|
return clone;
|
|
1318
933
|
}
|
|
934
|
+
|
|
1319
935
|
/**
|
|
1320
936
|
* Creates a new instance of this object. Not to be confused with clone()
|
|
1321
937
|
*
|
|
1322
938
|
* @returns {Parse.Object}
|
|
1323
939
|
*/
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
newInstance()
|
|
1327
|
-
/*: any*/
|
|
1328
|
-
{
|
|
940
|
+
newInstance() /*: any*/{
|
|
1329
941
|
const clone = new this.constructor(this.className);
|
|
1330
942
|
clone.id = this.id;
|
|
1331
|
-
|
|
1332
943
|
if (singleInstance) {
|
|
1333
944
|
// Just return an object with the right id
|
|
1334
945
|
return clone;
|
|
1335
946
|
}
|
|
1336
|
-
|
|
1337
947
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
1338
|
-
|
|
1339
948
|
if (stateController) {
|
|
1340
949
|
stateController.duplicateState(this._getStateIdentifier(), clone._getStateIdentifier());
|
|
1341
950
|
}
|
|
1342
|
-
|
|
1343
951
|
return clone;
|
|
1344
952
|
}
|
|
953
|
+
|
|
1345
954
|
/**
|
|
1346
955
|
* Returns true if this object has never been saved to Parse.
|
|
1347
956
|
*
|
|
1348
957
|
* @returns {boolean}
|
|
1349
958
|
*/
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
isNew()
|
|
1353
|
-
/*: boolean*/
|
|
1354
|
-
{
|
|
959
|
+
isNew() /*: boolean*/{
|
|
1355
960
|
return !this.id;
|
|
1356
961
|
}
|
|
962
|
+
|
|
1357
963
|
/**
|
|
1358
964
|
* Returns true if this object was created by the Parse server when the
|
|
1359
965
|
* object might have already been there (e.g. in the case of a Facebook
|
|
@@ -1361,25 +967,18 @@ class ParseObject {
|
|
|
1361
967
|
*
|
|
1362
968
|
* @returns {boolean}
|
|
1363
969
|
*/
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
existed()
|
|
1367
|
-
/*: boolean*/
|
|
1368
|
-
{
|
|
970
|
+
existed() /*: boolean*/{
|
|
1369
971
|
if (!this.id) {
|
|
1370
972
|
return false;
|
|
1371
973
|
}
|
|
1372
|
-
|
|
1373
974
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
1374
|
-
|
|
1375
975
|
const state = stateController.getState(this._getStateIdentifier());
|
|
1376
|
-
|
|
1377
976
|
if (state) {
|
|
1378
977
|
return state.existed;
|
|
1379
978
|
}
|
|
1380
|
-
|
|
1381
979
|
return false;
|
|
1382
980
|
}
|
|
981
|
+
|
|
1383
982
|
/**
|
|
1384
983
|
* Returns true if this object exists on the Server
|
|
1385
984
|
*
|
|
@@ -1392,17 +991,10 @@ class ParseObject {
|
|
|
1392
991
|
* </ul>
|
|
1393
992
|
* @returns {Promise<boolean>} A boolean promise that is fulfilled if object exists.
|
|
1394
993
|
*/
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
async exists(options
|
|
1398
|
-
/*:: ?: RequestOptions*/
|
|
1399
|
-
)
|
|
1400
|
-
/*: Promise<boolean>*/
|
|
1401
|
-
{
|
|
994
|
+
async exists(options /*:: ?: RequestOptions*/) /*: Promise<boolean>*/{
|
|
1402
995
|
if (!this.id) {
|
|
1403
996
|
return false;
|
|
1404
997
|
}
|
|
1405
|
-
|
|
1406
998
|
try {
|
|
1407
999
|
const query = new _ParseQuery.default(this.className);
|
|
1408
1000
|
await query.get(this.id, options);
|
|
@@ -1411,22 +1003,19 @@ class ParseObject {
|
|
|
1411
1003
|
if (e.code === _ParseError.default.OBJECT_NOT_FOUND) {
|
|
1412
1004
|
return false;
|
|
1413
1005
|
}
|
|
1414
|
-
|
|
1415
1006
|
throw e;
|
|
1416
1007
|
}
|
|
1417
1008
|
}
|
|
1009
|
+
|
|
1418
1010
|
/**
|
|
1419
1011
|
* Checks if the model is currently in a valid state.
|
|
1420
1012
|
*
|
|
1421
1013
|
* @returns {boolean}
|
|
1422
1014
|
*/
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
isValid()
|
|
1426
|
-
/*: boolean*/
|
|
1427
|
-
{
|
|
1015
|
+
isValid() /*: boolean*/{
|
|
1428
1016
|
return !this.validate(this.attributes);
|
|
1429
1017
|
}
|
|
1018
|
+
|
|
1430
1019
|
/**
|
|
1431
1020
|
* You should not call this function directly unless you subclass
|
|
1432
1021
|
* <code>Parse.Object</code>, in which case you can override this method
|
|
@@ -1437,44 +1026,32 @@ class ParseObject {
|
|
|
1437
1026
|
* @returns {Parse.Error|boolean} False if the data is valid. An error object otherwise.
|
|
1438
1027
|
* @see Parse.Object#set
|
|
1439
1028
|
*/
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
validate(attrs
|
|
1443
|
-
/*: AttributeMap*/
|
|
1444
|
-
)
|
|
1445
|
-
/*: ParseError | boolean*/
|
|
1446
|
-
{
|
|
1029
|
+
validate(attrs /*: AttributeMap*/) /*: ParseError | boolean*/{
|
|
1447
1030
|
if (attrs.hasOwnProperty('ACL') && !(attrs.ACL instanceof _ParseACL.default)) {
|
|
1448
1031
|
return new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'ACL must be a Parse ACL.');
|
|
1449
1032
|
}
|
|
1450
|
-
|
|
1451
1033
|
for (const key in attrs) {
|
|
1452
1034
|
if (!/^[A-Za-z][0-9A-Za-z_.]*$/.test(key)) {
|
|
1453
1035
|
return new _ParseError.default(_ParseError.default.INVALID_KEY_NAME);
|
|
1454
1036
|
}
|
|
1455
1037
|
}
|
|
1456
|
-
|
|
1457
1038
|
return false;
|
|
1458
1039
|
}
|
|
1040
|
+
|
|
1459
1041
|
/**
|
|
1460
1042
|
* Returns the ACL for this object.
|
|
1461
1043
|
*
|
|
1462
1044
|
* @returns {Parse.ACL} An instance of Parse.ACL.
|
|
1463
1045
|
* @see Parse.Object#get
|
|
1464
1046
|
*/
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
getACL()
|
|
1468
|
-
/*: ?ParseACL*/
|
|
1469
|
-
{
|
|
1047
|
+
getACL() /*: ?ParseACL*/{
|
|
1470
1048
|
const acl = this.get('ACL');
|
|
1471
|
-
|
|
1472
1049
|
if (acl instanceof _ParseACL.default) {
|
|
1473
1050
|
return acl;
|
|
1474
1051
|
}
|
|
1475
|
-
|
|
1476
1052
|
return null;
|
|
1477
1053
|
}
|
|
1054
|
+
|
|
1478
1055
|
/**
|
|
1479
1056
|
* Sets the ACL to be used for this object.
|
|
1480
1057
|
*
|
|
@@ -1483,32 +1060,19 @@ class ParseObject {
|
|
|
1483
1060
|
* @returns {(ParseObject | boolean)} Whether the set passed validation.
|
|
1484
1061
|
* @see Parse.Object#set
|
|
1485
1062
|
*/
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
setACL(acl
|
|
1489
|
-
/*: ParseACL*/
|
|
1490
|
-
, options
|
|
1491
|
-
/*:: ?: mixed*/
|
|
1492
|
-
)
|
|
1493
|
-
/*: ParseObject | boolean*/
|
|
1494
|
-
{
|
|
1063
|
+
setACL(acl /*: ParseACL*/, options /*:: ?: mixed*/) /*: ParseObject | boolean*/{
|
|
1495
1064
|
return this.set('ACL', acl, options);
|
|
1496
1065
|
}
|
|
1066
|
+
|
|
1497
1067
|
/**
|
|
1498
1068
|
* Clears any (or specific) changes to this object made since the last call to save()
|
|
1499
1069
|
*
|
|
1500
1070
|
* @param {string} [keys] - specify which fields to revert
|
|
1501
1071
|
*/
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
revert(...keys)
|
|
1505
|
-
/*: void*/
|
|
1506
|
-
{
|
|
1072
|
+
revert(...keys /*: Array<string>*/) /*: void*/{
|
|
1507
1073
|
let keysToRevert;
|
|
1508
|
-
|
|
1509
1074
|
if (keys.length) {
|
|
1510
1075
|
keysToRevert = [];
|
|
1511
|
-
|
|
1512
1076
|
for (const key of keys) {
|
|
1513
1077
|
if (typeof key === 'string') {
|
|
1514
1078
|
keysToRevert.push(key);
|
|
@@ -1517,37 +1081,31 @@ class ParseObject {
|
|
|
1517
1081
|
}
|
|
1518
1082
|
}
|
|
1519
1083
|
}
|
|
1520
|
-
|
|
1521
1084
|
this._clearPendingOps(keysToRevert);
|
|
1522
1085
|
}
|
|
1086
|
+
|
|
1523
1087
|
/**
|
|
1524
1088
|
* Clears all attributes on a model
|
|
1525
1089
|
*
|
|
1526
1090
|
* @returns {(ParseObject | boolean)}
|
|
1527
1091
|
*/
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
clear()
|
|
1531
|
-
/*: ParseObject | boolean*/
|
|
1532
|
-
{
|
|
1092
|
+
clear() /*: ParseObject | boolean*/{
|
|
1533
1093
|
const attributes = this.attributes;
|
|
1534
1094
|
const erasable = {};
|
|
1535
1095
|
let readonly = ['createdAt', 'updatedAt'];
|
|
1536
|
-
|
|
1537
1096
|
if (typeof this.constructor.readOnlyAttributes === 'function') {
|
|
1538
1097
|
readonly = readonly.concat(this.constructor.readOnlyAttributes());
|
|
1539
1098
|
}
|
|
1540
|
-
|
|
1541
1099
|
for (const attr in attributes) {
|
|
1542
1100
|
if (readonly.indexOf(attr) < 0) {
|
|
1543
1101
|
erasable[attr] = true;
|
|
1544
1102
|
}
|
|
1545
1103
|
}
|
|
1546
|
-
|
|
1547
1104
|
return this.set(erasable, {
|
|
1548
1105
|
unset: true
|
|
1549
1106
|
});
|
|
1550
1107
|
}
|
|
1108
|
+
|
|
1551
1109
|
/**
|
|
1552
1110
|
* Fetch the model from the server. If the server's representation of the
|
|
1553
1111
|
* model differs from its current attributes, they will be overriden.
|
|
@@ -1565,31 +1123,20 @@ class ParseObject {
|
|
|
1565
1123
|
* @returns {Promise} A promise that is fulfilled when the fetch
|
|
1566
1124
|
* completes.
|
|
1567
1125
|
*/
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
fetch(options
|
|
1571
|
-
/*: RequestOptions*/
|
|
1572
|
-
)
|
|
1573
|
-
/*: Promise*/
|
|
1574
|
-
{
|
|
1126
|
+
fetch(options /*: RequestOptions*/) /*: Promise*/{
|
|
1575
1127
|
options = options || {};
|
|
1576
1128
|
const fetchOptions = {};
|
|
1577
|
-
|
|
1578
1129
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
1579
1130
|
fetchOptions.useMasterKey = options.useMasterKey;
|
|
1580
1131
|
}
|
|
1581
|
-
|
|
1582
1132
|
if (options.hasOwnProperty('sessionToken')) {
|
|
1583
1133
|
fetchOptions.sessionToken = options.sessionToken;
|
|
1584
1134
|
}
|
|
1585
|
-
|
|
1586
1135
|
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
1587
1136
|
fetchOptions.context = options.context;
|
|
1588
1137
|
}
|
|
1589
|
-
|
|
1590
1138
|
if (options.hasOwnProperty('include')) {
|
|
1591
1139
|
fetchOptions.include = [];
|
|
1592
|
-
|
|
1593
1140
|
if (Array.isArray(options.include)) {
|
|
1594
1141
|
options.include.forEach(key => {
|
|
1595
1142
|
if (Array.isArray(key)) {
|
|
@@ -1602,11 +1149,10 @@ class ParseObject {
|
|
|
1602
1149
|
fetchOptions.include.push(options.include);
|
|
1603
1150
|
}
|
|
1604
1151
|
}
|
|
1605
|
-
|
|
1606
1152
|
const controller = _CoreManager.default.getObjectController();
|
|
1607
|
-
|
|
1608
1153
|
return controller.fetch(this, true, fetchOptions);
|
|
1609
1154
|
}
|
|
1155
|
+
|
|
1610
1156
|
/**
|
|
1611
1157
|
* Fetch the model from the server. If the server's representation of the
|
|
1612
1158
|
* model differs from its current attributes, they will be overriden.
|
|
@@ -1625,19 +1171,12 @@ class ParseObject {
|
|
|
1625
1171
|
* @returns {Promise} A promise that is fulfilled when the fetch
|
|
1626
1172
|
* completes.
|
|
1627
1173
|
*/
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
fetchWithInclude(keys
|
|
1631
|
-
/*: String | Array<string | Array<string>>*/
|
|
1632
|
-
, options
|
|
1633
|
-
/*: RequestOptions*/
|
|
1634
|
-
)
|
|
1635
|
-
/*: Promise*/
|
|
1636
|
-
{
|
|
1174
|
+
fetchWithInclude(keys /*: String | Array<string | Array<string>>*/, options /*: RequestOptions*/) /*: Promise*/{
|
|
1637
1175
|
options = options || {};
|
|
1638
1176
|
options.include = keys;
|
|
1639
1177
|
return this.fetch(options);
|
|
1640
1178
|
}
|
|
1179
|
+
|
|
1641
1180
|
/**
|
|
1642
1181
|
* Saves this object to the server at some unspecified time in the future,
|
|
1643
1182
|
* even if Parse is currently inaccessible.
|
|
@@ -1662,25 +1201,18 @@ class ParseObject {
|
|
|
1662
1201
|
* @returns {Promise} A promise that is fulfilled when the save
|
|
1663
1202
|
* completes.
|
|
1664
1203
|
*/
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
async saveEventually(options
|
|
1668
|
-
/*: SaveOptions*/
|
|
1669
|
-
)
|
|
1670
|
-
/*: Promise*/
|
|
1671
|
-
{
|
|
1204
|
+
async saveEventually(options /*: SaveOptions*/) /*: Promise*/{
|
|
1672
1205
|
try {
|
|
1673
1206
|
await this.save(null, options);
|
|
1674
1207
|
} catch (e) {
|
|
1675
1208
|
if (e.message === 'XMLHttpRequest failed: "Unable to connect to the Parse API"') {
|
|
1676
1209
|
await _EventuallyQueue.default.save(this, options);
|
|
1677
|
-
|
|
1678
1210
|
_EventuallyQueue.default.poll();
|
|
1679
1211
|
}
|
|
1680
1212
|
}
|
|
1681
|
-
|
|
1682
1213
|
return this;
|
|
1683
1214
|
}
|
|
1215
|
+
|
|
1684
1216
|
/**
|
|
1685
1217
|
* Set a hash of model attributes, and save the model to the server.
|
|
1686
1218
|
* updatedAt will be updated when the request returns.
|
|
@@ -1744,23 +1276,11 @@ class ParseObject {
|
|
|
1744
1276
|
* @returns {Promise} A promise that is fulfilled when the save
|
|
1745
1277
|
* completes.
|
|
1746
1278
|
*/
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
save(arg1
|
|
1750
|
-
/*: ?string | { [attr: string]: mixed }*/
|
|
1751
|
-
, arg2
|
|
1752
|
-
/*: SaveOptions | mixed*/
|
|
1753
|
-
, arg3
|
|
1754
|
-
/*:: ?: SaveOptions*/
|
|
1755
|
-
)
|
|
1756
|
-
/*: Promise*/
|
|
1757
|
-
{
|
|
1279
|
+
save(arg1 /*: ?string | { [attr: string]: mixed }*/, arg2 /*: SaveOptions | mixed*/, arg3 /*:: ?: SaveOptions*/) /*: Promise*/{
|
|
1758
1280
|
let attrs;
|
|
1759
1281
|
let options;
|
|
1760
|
-
|
|
1761
1282
|
if (typeof arg1 === 'object' || typeof arg1 === 'undefined') {
|
|
1762
1283
|
attrs = arg1;
|
|
1763
|
-
|
|
1764
1284
|
if (typeof arg2 === 'object') {
|
|
1765
1285
|
options = arg2;
|
|
1766
1286
|
}
|
|
@@ -1769,43 +1289,34 @@ class ParseObject {
|
|
|
1769
1289
|
attrs[arg1] = arg2;
|
|
1770
1290
|
options = arg3;
|
|
1771
1291
|
}
|
|
1772
|
-
|
|
1773
1292
|
if (attrs) {
|
|
1774
1293
|
const validation = this.validate(attrs);
|
|
1775
|
-
|
|
1776
1294
|
if (validation) {
|
|
1777
1295
|
return Promise.reject(validation);
|
|
1778
1296
|
}
|
|
1779
|
-
|
|
1780
1297
|
this.set(attrs, options);
|
|
1781
1298
|
}
|
|
1782
|
-
|
|
1783
1299
|
options = options || {};
|
|
1784
1300
|
const saveOptions = {};
|
|
1785
|
-
|
|
1786
1301
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
1787
1302
|
saveOptions.useMasterKey = !!options.useMasterKey;
|
|
1788
1303
|
}
|
|
1789
|
-
|
|
1790
1304
|
if (options.hasOwnProperty('sessionToken') && typeof options.sessionToken === 'string') {
|
|
1791
1305
|
saveOptions.sessionToken = options.sessionToken;
|
|
1792
1306
|
}
|
|
1793
|
-
|
|
1794
1307
|
if (options.hasOwnProperty('installationId') && typeof options.installationId === 'string') {
|
|
1795
1308
|
saveOptions.installationId = options.installationId;
|
|
1796
1309
|
}
|
|
1797
|
-
|
|
1798
1310
|
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
1799
1311
|
saveOptions.context = options.context;
|
|
1800
1312
|
}
|
|
1801
|
-
|
|
1802
1313
|
const controller = _CoreManager.default.getObjectController();
|
|
1803
|
-
|
|
1804
1314
|
const unsaved = options.cascadeSave !== false ? (0, _unsavedChildren.default)(this) : null;
|
|
1805
1315
|
return controller.save(unsaved, saveOptions).then(() => {
|
|
1806
1316
|
return controller.save(this, saveOptions);
|
|
1807
1317
|
});
|
|
1808
1318
|
}
|
|
1319
|
+
|
|
1809
1320
|
/**
|
|
1810
1321
|
* Deletes this object from the server at some unspecified time in the future,
|
|
1811
1322
|
* even if Parse is currently inaccessible.
|
|
@@ -1828,25 +1339,18 @@ class ParseObject {
|
|
|
1828
1339
|
* @returns {Promise} A promise that is fulfilled when the destroy
|
|
1829
1340
|
* completes.
|
|
1830
1341
|
*/
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
async destroyEventually(options
|
|
1834
|
-
/*: RequestOptions*/
|
|
1835
|
-
)
|
|
1836
|
-
/*: Promise*/
|
|
1837
|
-
{
|
|
1342
|
+
async destroyEventually(options /*: RequestOptions*/) /*: Promise*/{
|
|
1838
1343
|
try {
|
|
1839
1344
|
await this.destroy(options);
|
|
1840
1345
|
} catch (e) {
|
|
1841
1346
|
if (e.message === 'XMLHttpRequest failed: "Unable to connect to the Parse API"') {
|
|
1842
1347
|
await _EventuallyQueue.default.destroy(this, options);
|
|
1843
|
-
|
|
1844
1348
|
_EventuallyQueue.default.poll();
|
|
1845
1349
|
}
|
|
1846
1350
|
}
|
|
1847
|
-
|
|
1848
1351
|
return this;
|
|
1849
1352
|
}
|
|
1353
|
+
|
|
1850
1354
|
/**
|
|
1851
1355
|
* Destroy this model on the server if it was already persisted.
|
|
1852
1356
|
*
|
|
@@ -1861,34 +1365,24 @@ class ParseObject {
|
|
|
1861
1365
|
* @returns {Promise} A promise that is fulfilled when the destroy
|
|
1862
1366
|
* completes.
|
|
1863
1367
|
*/
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
destroy(options
|
|
1867
|
-
/*: RequestOptions*/
|
|
1868
|
-
)
|
|
1869
|
-
/*: Promise*/
|
|
1870
|
-
{
|
|
1368
|
+
destroy(options /*: RequestOptions*/) /*: Promise*/{
|
|
1871
1369
|
options = options || {};
|
|
1872
1370
|
const destroyOptions = {};
|
|
1873
|
-
|
|
1874
1371
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
1875
1372
|
destroyOptions.useMasterKey = options.useMasterKey;
|
|
1876
1373
|
}
|
|
1877
|
-
|
|
1878
1374
|
if (options.hasOwnProperty('sessionToken')) {
|
|
1879
1375
|
destroyOptions.sessionToken = options.sessionToken;
|
|
1880
1376
|
}
|
|
1881
|
-
|
|
1882
1377
|
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
1883
1378
|
destroyOptions.context = options.context;
|
|
1884
1379
|
}
|
|
1885
|
-
|
|
1886
1380
|
if (!this.id) {
|
|
1887
1381
|
return Promise.resolve();
|
|
1888
1382
|
}
|
|
1889
|
-
|
|
1890
1383
|
return _CoreManager.default.getObjectController().destroy(this, destroyOptions);
|
|
1891
1384
|
}
|
|
1385
|
+
|
|
1892
1386
|
/**
|
|
1893
1387
|
* Asynchronously stores the object and every object it points to in the local datastore,
|
|
1894
1388
|
* recursively, using a default pin name: _default.
|
|
@@ -1905,13 +1399,10 @@ class ParseObject {
|
|
|
1905
1399
|
*
|
|
1906
1400
|
* @returns {Promise} A promise that is fulfilled when the pin completes.
|
|
1907
1401
|
*/
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
pin()
|
|
1911
|
-
/*: Promise<void>*/
|
|
1912
|
-
{
|
|
1402
|
+
pin() /*: Promise<void>*/{
|
|
1913
1403
|
return ParseObject.pinAllWithName(_LocalDatastoreUtils.DEFAULT_PIN, [this]);
|
|
1914
1404
|
}
|
|
1405
|
+
|
|
1915
1406
|
/**
|
|
1916
1407
|
* Asynchronously removes the object and every object it points to in the local datastore,
|
|
1917
1408
|
* recursively, using a default pin name: _default.
|
|
@@ -1922,13 +1413,10 @@ class ParseObject {
|
|
|
1922
1413
|
*
|
|
1923
1414
|
* @returns {Promise} A promise that is fulfilled when the unPin completes.
|
|
1924
1415
|
*/
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
unPin()
|
|
1928
|
-
/*: Promise<void>*/
|
|
1929
|
-
{
|
|
1416
|
+
unPin() /*: Promise<void>*/{
|
|
1930
1417
|
return ParseObject.unPinAllWithName(_LocalDatastoreUtils.DEFAULT_PIN, [this]);
|
|
1931
1418
|
}
|
|
1419
|
+
|
|
1932
1420
|
/**
|
|
1933
1421
|
* Asynchronously returns if the object is pinned
|
|
1934
1422
|
*
|
|
@@ -1938,21 +1426,16 @@ class ParseObject {
|
|
|
1938
1426
|
*
|
|
1939
1427
|
* @returns {Promise<boolean>} A boolean promise that is fulfilled if object is pinned.
|
|
1940
1428
|
*/
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
async isPinned()
|
|
1944
|
-
/*: Promise<boolean>*/
|
|
1945
|
-
{
|
|
1429
|
+
async isPinned() /*: Promise<boolean>*/{
|
|
1946
1430
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
1947
|
-
|
|
1948
1431
|
if (!localDatastore.isEnabled) {
|
|
1949
1432
|
return Promise.reject('Parse.enableLocalDatastore() must be called first');
|
|
1950
1433
|
}
|
|
1951
|
-
|
|
1952
1434
|
const objectKey = localDatastore.getKeyForObject(this);
|
|
1953
1435
|
const pin = await localDatastore.fromPinWithName(objectKey);
|
|
1954
1436
|
return pin.length > 0;
|
|
1955
1437
|
}
|
|
1438
|
+
|
|
1956
1439
|
/**
|
|
1957
1440
|
* Asynchronously stores the objects and every object they point to in the local datastore, recursively.
|
|
1958
1441
|
*
|
|
@@ -1969,15 +1452,10 @@ class ParseObject {
|
|
|
1969
1452
|
* @param {string} name Name of Pin.
|
|
1970
1453
|
* @returns {Promise} A promise that is fulfilled when the pin completes.
|
|
1971
1454
|
*/
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
pinWithName(name
|
|
1975
|
-
/*: string*/
|
|
1976
|
-
)
|
|
1977
|
-
/*: Promise<void>*/
|
|
1978
|
-
{
|
|
1455
|
+
pinWithName(name /*: string*/) /*: Promise<void>*/{
|
|
1979
1456
|
return ParseObject.pinAllWithName(name, [this]);
|
|
1980
1457
|
}
|
|
1458
|
+
|
|
1981
1459
|
/**
|
|
1982
1460
|
* Asynchronously removes the object and every object it points to in the local datastore, recursively.
|
|
1983
1461
|
*
|
|
@@ -1988,15 +1466,10 @@ class ParseObject {
|
|
|
1988
1466
|
* @param {string} name Name of Pin.
|
|
1989
1467
|
* @returns {Promise} A promise that is fulfilled when the unPin completes.
|
|
1990
1468
|
*/
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
unPinWithName(name
|
|
1994
|
-
/*: string*/
|
|
1995
|
-
)
|
|
1996
|
-
/*: Promise<void>*/
|
|
1997
|
-
{
|
|
1469
|
+
unPinWithName(name /*: string*/) /*: Promise<void>*/{
|
|
1998
1470
|
return ParseObject.unPinAllWithName(name, [this]);
|
|
1999
1471
|
}
|
|
1472
|
+
|
|
2000
1473
|
/**
|
|
2001
1474
|
* Asynchronously loads data from the local datastore into this object.
|
|
2002
1475
|
*
|
|
@@ -2009,38 +1482,28 @@ class ParseObject {
|
|
|
2009
1482
|
*
|
|
2010
1483
|
* @returns {Promise} A promise that is fulfilled when the fetch completes.
|
|
2011
1484
|
*/
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
async fetchFromLocalDatastore()
|
|
2015
|
-
/*: Promise<ParseObject>*/
|
|
2016
|
-
{
|
|
1485
|
+
async fetchFromLocalDatastore() /*: Promise<ParseObject>*/{
|
|
2017
1486
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2018
|
-
|
|
2019
1487
|
if (!localDatastore.isEnabled) {
|
|
2020
1488
|
throw new Error('Parse.enableLocalDatastore() must be called first');
|
|
2021
1489
|
}
|
|
2022
|
-
|
|
2023
1490
|
const objectKey = localDatastore.getKeyForObject(this);
|
|
2024
1491
|
const pinned = await localDatastore._serializeObject(objectKey);
|
|
2025
|
-
|
|
2026
1492
|
if (!pinned) {
|
|
2027
1493
|
throw new Error('Cannot fetch an unsaved ParseObject');
|
|
2028
1494
|
}
|
|
2029
|
-
|
|
2030
1495
|
const result = ParseObject.fromJSON(pinned);
|
|
2031
|
-
|
|
2032
1496
|
this._finishFetch(result.toJSON());
|
|
2033
|
-
|
|
2034
1497
|
return this;
|
|
2035
1498
|
}
|
|
2036
|
-
/** Static methods **/
|
|
2037
1499
|
|
|
1500
|
+
/* Static methods */
|
|
2038
1501
|
|
|
2039
1502
|
static _clearAllState() {
|
|
2040
1503
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
2041
|
-
|
|
2042
1504
|
stateController.clearAllState();
|
|
2043
1505
|
}
|
|
1506
|
+
|
|
2044
1507
|
/**
|
|
2045
1508
|
* Fetches the given list of Parse.Object.
|
|
2046
1509
|
* If any error is encountered, stops and calls the error handler.
|
|
@@ -2067,29 +1530,20 @@ class ParseObject {
|
|
|
2067
1530
|
* @static
|
|
2068
1531
|
* @returns {Parse.Object[]}
|
|
2069
1532
|
*/
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
static fetchAll(list
|
|
2073
|
-
/*: Array<ParseObject>*/
|
|
2074
|
-
, options
|
|
2075
|
-
/*: RequestOptions*/
|
|
2076
|
-
= {}) {
|
|
1533
|
+
static fetchAll(list /*: Array<ParseObject>*/, options /*: RequestOptions*/ = {}) {
|
|
2077
1534
|
const queryOptions = {};
|
|
2078
|
-
|
|
2079
1535
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
2080
1536
|
queryOptions.useMasterKey = options.useMasterKey;
|
|
2081
1537
|
}
|
|
2082
|
-
|
|
2083
1538
|
if (options.hasOwnProperty('sessionToken')) {
|
|
2084
1539
|
queryOptions.sessionToken = options.sessionToken;
|
|
2085
1540
|
}
|
|
2086
|
-
|
|
2087
1541
|
if (options.hasOwnProperty('include')) {
|
|
2088
1542
|
queryOptions.include = ParseObject.handleIncludeOptions(options);
|
|
2089
1543
|
}
|
|
2090
|
-
|
|
2091
1544
|
return _CoreManager.default.getObjectController().fetch(list, true, queryOptions);
|
|
2092
1545
|
}
|
|
1546
|
+
|
|
2093
1547
|
/**
|
|
2094
1548
|
* Fetches the given list of Parse.Object.
|
|
2095
1549
|
*
|
|
@@ -2119,19 +1573,12 @@ class ParseObject {
|
|
|
2119
1573
|
* @static
|
|
2120
1574
|
* @returns {Parse.Object[]}
|
|
2121
1575
|
*/
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
static fetchAllWithInclude(list
|
|
2125
|
-
/*: Array<ParseObject>*/
|
|
2126
|
-
, keys
|
|
2127
|
-
/*: String | Array<string | Array<string>>*/
|
|
2128
|
-
, options
|
|
2129
|
-
/*: RequestOptions*/
|
|
2130
|
-
) {
|
|
1576
|
+
static fetchAllWithInclude(list /*: Array<ParseObject>*/, keys /*: String | Array<string | Array<string>>*/, options /*: RequestOptions*/) {
|
|
2131
1577
|
options = options || {};
|
|
2132
1578
|
options.include = keys;
|
|
2133
1579
|
return ParseObject.fetchAll(list, options);
|
|
2134
1580
|
}
|
|
1581
|
+
|
|
2135
1582
|
/**
|
|
2136
1583
|
* Fetches the given list of Parse.Object if needed.
|
|
2137
1584
|
* If any error is encountered, stops and calls the error handler.
|
|
@@ -2162,19 +1609,12 @@ class ParseObject {
|
|
|
2162
1609
|
* @static
|
|
2163
1610
|
* @returns {Parse.Object[]}
|
|
2164
1611
|
*/
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
static fetchAllIfNeededWithInclude(list
|
|
2168
|
-
/*: Array<ParseObject>*/
|
|
2169
|
-
, keys
|
|
2170
|
-
/*: String | Array<string | Array<string>>*/
|
|
2171
|
-
, options
|
|
2172
|
-
/*: RequestOptions*/
|
|
2173
|
-
) {
|
|
1612
|
+
static fetchAllIfNeededWithInclude(list /*: Array<ParseObject>*/, keys /*: String | Array<string | Array<string>>*/, options /*: RequestOptions*/) {
|
|
2174
1613
|
options = options || {};
|
|
2175
1614
|
options.include = keys;
|
|
2176
1615
|
return ParseObject.fetchAllIfNeeded(list, options);
|
|
2177
1616
|
}
|
|
1617
|
+
|
|
2178
1618
|
/**
|
|
2179
1619
|
* Fetches the given list of Parse.Object if needed.
|
|
2180
1620
|
* If any error is encountered, stops and calls the error handler.
|
|
@@ -2193,32 +1633,22 @@ class ParseObject {
|
|
|
2193
1633
|
* @static
|
|
2194
1634
|
* @returns {Parse.Object[]}
|
|
2195
1635
|
*/
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
static fetchAllIfNeeded(list
|
|
2199
|
-
/*: Array<ParseObject>*/
|
|
2200
|
-
, options) {
|
|
1636
|
+
static fetchAllIfNeeded(list /*: Array<ParseObject>*/, options) {
|
|
2201
1637
|
options = options || {};
|
|
2202
1638
|
const queryOptions = {};
|
|
2203
|
-
|
|
2204
1639
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
2205
1640
|
queryOptions.useMasterKey = options.useMasterKey;
|
|
2206
1641
|
}
|
|
2207
|
-
|
|
2208
1642
|
if (options.hasOwnProperty('sessionToken')) {
|
|
2209
1643
|
queryOptions.sessionToken = options.sessionToken;
|
|
2210
1644
|
}
|
|
2211
|
-
|
|
2212
1645
|
if (options.hasOwnProperty('include')) {
|
|
2213
1646
|
queryOptions.include = ParseObject.handleIncludeOptions(options);
|
|
2214
1647
|
}
|
|
2215
|
-
|
|
2216
1648
|
return _CoreManager.default.getObjectController().fetch(list, false, queryOptions);
|
|
2217
1649
|
}
|
|
2218
|
-
|
|
2219
1650
|
static handleIncludeOptions(options) {
|
|
2220
1651
|
let include = [];
|
|
2221
|
-
|
|
2222
1652
|
if (Array.isArray(options.include)) {
|
|
2223
1653
|
options.include.forEach(key => {
|
|
2224
1654
|
if (Array.isArray(key)) {
|
|
@@ -2230,9 +1660,9 @@ class ParseObject {
|
|
|
2230
1660
|
} else {
|
|
2231
1661
|
include.push(options.include);
|
|
2232
1662
|
}
|
|
2233
|
-
|
|
2234
1663
|
return include;
|
|
2235
1664
|
}
|
|
1665
|
+
|
|
2236
1666
|
/**
|
|
2237
1667
|
* Destroy the given list of models on the server if it was already persisted.
|
|
2238
1668
|
*
|
|
@@ -2279,31 +1709,23 @@ class ParseObject {
|
|
|
2279
1709
|
* @returns {Promise} A promise that is fulfilled when the destroyAll
|
|
2280
1710
|
* completes.
|
|
2281
1711
|
*/
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
static destroyAll(list
|
|
2285
|
-
/*: Array<ParseObject>*/
|
|
2286
|
-
, options = {}) {
|
|
1712
|
+
static destroyAll(list /*: Array<ParseObject>*/, options = {}) {
|
|
2287
1713
|
const destroyOptions = {};
|
|
2288
|
-
|
|
2289
1714
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
2290
1715
|
destroyOptions.useMasterKey = options.useMasterKey;
|
|
2291
1716
|
}
|
|
2292
|
-
|
|
2293
1717
|
if (options.hasOwnProperty('sessionToken')) {
|
|
2294
1718
|
destroyOptions.sessionToken = options.sessionToken;
|
|
2295
1719
|
}
|
|
2296
|
-
|
|
2297
1720
|
if (options.hasOwnProperty('batchSize') && typeof options.batchSize === 'number') {
|
|
2298
1721
|
destroyOptions.batchSize = options.batchSize;
|
|
2299
1722
|
}
|
|
2300
|
-
|
|
2301
1723
|
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
2302
1724
|
destroyOptions.context = options.context;
|
|
2303
1725
|
}
|
|
2304
|
-
|
|
2305
1726
|
return _CoreManager.default.getObjectController().destroy(list, destroyOptions);
|
|
2306
1727
|
}
|
|
1728
|
+
|
|
2307
1729
|
/**
|
|
2308
1730
|
* Saves the given list of Parse.Object.
|
|
2309
1731
|
* If any error is encountered, stops and calls the error handler.
|
|
@@ -2322,33 +1744,23 @@ class ParseObject {
|
|
|
2322
1744
|
* @static
|
|
2323
1745
|
* @returns {Parse.Object[]}
|
|
2324
1746
|
*/
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
static saveAll(list
|
|
2328
|
-
/*: Array<ParseObject>*/
|
|
2329
|
-
, options
|
|
2330
|
-
/*: RequestOptions*/
|
|
2331
|
-
= {}) {
|
|
1747
|
+
static saveAll(list /*: Array<ParseObject>*/, options /*: RequestOptions*/ = {}) {
|
|
2332
1748
|
const saveOptions = {};
|
|
2333
|
-
|
|
2334
1749
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
2335
1750
|
saveOptions.useMasterKey = options.useMasterKey;
|
|
2336
1751
|
}
|
|
2337
|
-
|
|
2338
1752
|
if (options.hasOwnProperty('sessionToken')) {
|
|
2339
1753
|
saveOptions.sessionToken = options.sessionToken;
|
|
2340
1754
|
}
|
|
2341
|
-
|
|
2342
1755
|
if (options.hasOwnProperty('batchSize') && typeof options.batchSize === 'number') {
|
|
2343
1756
|
saveOptions.batchSize = options.batchSize;
|
|
2344
1757
|
}
|
|
2345
|
-
|
|
2346
1758
|
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
|
|
2347
1759
|
saveOptions.context = options.context;
|
|
2348
1760
|
}
|
|
2349
|
-
|
|
2350
1761
|
return _CoreManager.default.getObjectController().save(list, saveOptions);
|
|
2351
1762
|
}
|
|
1763
|
+
|
|
2352
1764
|
/**
|
|
2353
1765
|
* Creates a reference to a subclass of Parse.Object with the given id. This
|
|
2354
1766
|
* does not exist on Parse.Object, only on subclasses.
|
|
@@ -2363,15 +1775,12 @@ class ParseObject {
|
|
|
2363
1775
|
* @static
|
|
2364
1776
|
* @returns {Parse.Object} A Parse.Object reference.
|
|
2365
1777
|
*/
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
static createWithoutData(id
|
|
2369
|
-
/*: string*/
|
|
2370
|
-
) {
|
|
1778
|
+
static createWithoutData(id /*: string*/) {
|
|
2371
1779
|
const obj = new this();
|
|
2372
1780
|
obj.id = id;
|
|
2373
1781
|
return obj;
|
|
2374
1782
|
}
|
|
1783
|
+
|
|
2375
1784
|
/**
|
|
2376
1785
|
* Creates a new instance of a Parse Object from a JSON representation.
|
|
2377
1786
|
*
|
|
@@ -2382,60 +1791,42 @@ class ParseObject {
|
|
|
2382
1791
|
* @static
|
|
2383
1792
|
* @returns {Parse.Object} A Parse.Object reference
|
|
2384
1793
|
*/
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
static fromJSON(json
|
|
2388
|
-
/*: any*/
|
|
2389
|
-
, override
|
|
2390
|
-
/*:: ?: boolean*/
|
|
2391
|
-
, dirty
|
|
2392
|
-
/*:: ?: boolean*/
|
|
2393
|
-
) {
|
|
1794
|
+
static fromJSON(json /*: any*/, override /*:: ?: boolean*/, dirty /*:: ?: boolean*/) {
|
|
2394
1795
|
if (!json.className) {
|
|
2395
1796
|
throw new Error('Cannot create an object without a className');
|
|
2396
1797
|
}
|
|
2397
|
-
|
|
2398
1798
|
const constructor = classMap[json.className];
|
|
2399
1799
|
const o = constructor ? new constructor(json.className) : new ParseObject(json.className);
|
|
2400
1800
|
const otherAttributes = {};
|
|
2401
|
-
|
|
2402
1801
|
for (const attr in json) {
|
|
2403
1802
|
if (attr !== 'className' && attr !== '__type') {
|
|
2404
1803
|
otherAttributes[attr] = json[attr];
|
|
2405
|
-
|
|
2406
1804
|
if (dirty) {
|
|
2407
1805
|
o.set(attr, json[attr]);
|
|
2408
1806
|
}
|
|
2409
1807
|
}
|
|
2410
1808
|
}
|
|
2411
|
-
|
|
2412
1809
|
if (override) {
|
|
2413
1810
|
// id needs to be set before clearServerData can work
|
|
2414
1811
|
if (otherAttributes.objectId) {
|
|
2415
1812
|
o.id = otherAttributes.objectId;
|
|
2416
1813
|
}
|
|
2417
|
-
|
|
2418
1814
|
let preserved = null;
|
|
2419
|
-
|
|
2420
1815
|
if (typeof o._preserveFieldsOnFetch === 'function') {
|
|
2421
1816
|
preserved = o._preserveFieldsOnFetch();
|
|
2422
1817
|
}
|
|
2423
|
-
|
|
2424
1818
|
o._clearServerData();
|
|
2425
|
-
|
|
2426
1819
|
if (preserved) {
|
|
2427
1820
|
o._finishFetch(preserved);
|
|
2428
1821
|
}
|
|
2429
1822
|
}
|
|
2430
|
-
|
|
2431
1823
|
o._finishFetch(otherAttributes);
|
|
2432
|
-
|
|
2433
1824
|
if (json.objectId) {
|
|
2434
1825
|
o._setExisted(true);
|
|
2435
1826
|
}
|
|
2436
|
-
|
|
2437
1827
|
return o;
|
|
2438
1828
|
}
|
|
1829
|
+
|
|
2439
1830
|
/**
|
|
2440
1831
|
* Registers a subclass of Parse.Object with a specific class name.
|
|
2441
1832
|
* When objects of that class are retrieved from a query, they will be
|
|
@@ -2445,47 +1836,34 @@ class ParseObject {
|
|
|
2445
1836
|
* @param {string} className The class name of the subclass
|
|
2446
1837
|
* @param {Function} constructor The subclass
|
|
2447
1838
|
*/
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
static registerSubclass(className
|
|
2451
|
-
/*: string*/
|
|
2452
|
-
, constructor
|
|
2453
|
-
/*: any*/
|
|
2454
|
-
) {
|
|
1839
|
+
static registerSubclass(className /*: string*/, constructor /*: any*/) {
|
|
2455
1840
|
if (typeof className !== 'string') {
|
|
2456
1841
|
throw new TypeError('The first argument must be a valid class name.');
|
|
2457
1842
|
}
|
|
2458
|
-
|
|
2459
1843
|
if (typeof constructor === 'undefined') {
|
|
2460
1844
|
throw new TypeError('You must supply a subclass constructor.');
|
|
2461
1845
|
}
|
|
2462
|
-
|
|
2463
1846
|
if (typeof constructor !== 'function') {
|
|
2464
1847
|
throw new TypeError('You must register the subclass constructor. ' + 'Did you attempt to register an instance of the subclass?');
|
|
2465
1848
|
}
|
|
2466
|
-
|
|
2467
1849
|
classMap[className] = constructor;
|
|
2468
|
-
|
|
2469
1850
|
if (!constructor.className) {
|
|
2470
1851
|
constructor.className = className;
|
|
2471
1852
|
}
|
|
2472
1853
|
}
|
|
1854
|
+
|
|
2473
1855
|
/**
|
|
2474
1856
|
* Unegisters a subclass of Parse.Object with a specific class name.
|
|
2475
1857
|
*
|
|
2476
1858
|
* @param {string} className The class name of the subclass
|
|
2477
1859
|
*/
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
static unregisterSubclass(className
|
|
2481
|
-
/*: string*/
|
|
2482
|
-
) {
|
|
1860
|
+
static unregisterSubclass(className /*: string*/) {
|
|
2483
1861
|
if (typeof className !== 'string') {
|
|
2484
1862
|
throw new TypeError('The first argument must be a valid class name.');
|
|
2485
1863
|
}
|
|
2486
|
-
|
|
2487
1864
|
delete classMap[className];
|
|
2488
1865
|
}
|
|
1866
|
+
|
|
2489
1867
|
/**
|
|
2490
1868
|
* Creates a new subclass of Parse.Object for the given Parse class name.
|
|
2491
1869
|
*
|
|
@@ -2523,15 +1901,7 @@ class ParseObject {
|
|
|
2523
1901
|
* this method.
|
|
2524
1902
|
* @returns {Parse.Object} A new subclass of Parse.Object.
|
|
2525
1903
|
*/
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
static extend(className
|
|
2529
|
-
/*: any*/
|
|
2530
|
-
, protoProps
|
|
2531
|
-
/*: any*/
|
|
2532
|
-
, classProps
|
|
2533
|
-
/*: any*/
|
|
2534
|
-
) {
|
|
1904
|
+
static extend(className /*: any*/, protoProps /*: any*/, classProps /*: any*/) {
|
|
2535
1905
|
if (typeof className !== 'string') {
|
|
2536
1906
|
if (className && typeof className.className === 'string') {
|
|
2537
1907
|
return ParseObject.extend(className.className, className, protoProps);
|
|
@@ -2539,49 +1909,64 @@ class ParseObject {
|
|
|
2539
1909
|
throw new Error("Parse.Object.extend's first argument should be the className.");
|
|
2540
1910
|
}
|
|
2541
1911
|
}
|
|
2542
|
-
|
|
2543
1912
|
let adjustedClassName = className;
|
|
2544
|
-
|
|
2545
1913
|
if (adjustedClassName === 'User' && _CoreManager.default.get('PERFORM_USER_REWRITE')) {
|
|
2546
1914
|
adjustedClassName = '_User';
|
|
2547
1915
|
}
|
|
2548
|
-
|
|
2549
1916
|
let parentProto = ParseObject.prototype;
|
|
2550
|
-
|
|
2551
1917
|
if (this.hasOwnProperty('__super__') && this.__super__) {
|
|
2552
1918
|
parentProto = this.prototype;
|
|
2553
|
-
} else if (classMap[adjustedClassName]) {
|
|
2554
|
-
parentProto = classMap[adjustedClassName].prototype;
|
|
2555
1919
|
}
|
|
2556
|
-
|
|
2557
|
-
const ParseObjectSubclass = function (attributes, options) {
|
|
1920
|
+
let ParseObjectSubclass = function (attributes, options) {
|
|
2558
1921
|
this.className = adjustedClassName;
|
|
2559
|
-
this._objCount = objectCount++;
|
|
2560
|
-
|
|
1922
|
+
this._objCount = objectCount++;
|
|
1923
|
+
// Enable legacy initializers
|
|
2561
1924
|
if (typeof this.initialize === 'function') {
|
|
2562
1925
|
this.initialize.apply(this, arguments);
|
|
2563
1926
|
}
|
|
2564
|
-
|
|
1927
|
+
if (this._initializers) {
|
|
1928
|
+
for (const initializer of this._initializers) {
|
|
1929
|
+
initializer.apply(this, arguments);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
2565
1932
|
if (attributes && typeof attributes === 'object') {
|
|
2566
1933
|
if (!this.set(attributes || {}, options)) {
|
|
2567
1934
|
throw new Error("Can't create an invalid Parse Object");
|
|
2568
1935
|
}
|
|
2569
1936
|
}
|
|
2570
1937
|
};
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
1938
|
+
if (classMap[adjustedClassName]) {
|
|
1939
|
+
ParseObjectSubclass = classMap[adjustedClassName];
|
|
1940
|
+
} else {
|
|
1941
|
+
ParseObjectSubclass.extend = function (name, protoProps, classProps) {
|
|
1942
|
+
if (typeof name === 'string') {
|
|
1943
|
+
return ParseObject.extend.call(ParseObjectSubclass, name, protoProps, classProps);
|
|
1944
|
+
}
|
|
1945
|
+
return ParseObject.extend.call(ParseObjectSubclass, adjustedClassName, name, protoProps);
|
|
1946
|
+
};
|
|
1947
|
+
ParseObjectSubclass.createWithoutData = ParseObject.createWithoutData;
|
|
1948
|
+
ParseObjectSubclass.className = adjustedClassName;
|
|
1949
|
+
ParseObjectSubclass.__super__ = parentProto;
|
|
1950
|
+
ParseObjectSubclass.prototype = Object.create(parentProto, {
|
|
1951
|
+
constructor: {
|
|
1952
|
+
value: ParseObjectSubclass,
|
|
1953
|
+
enumerable: false,
|
|
1954
|
+
writable: true,
|
|
1955
|
+
configurable: true
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
2583
1959
|
if (protoProps) {
|
|
2584
1960
|
for (const prop in protoProps) {
|
|
1961
|
+
if (prop === 'initialize') {
|
|
1962
|
+
Object.defineProperty(ParseObjectSubclass.prototype, '_initializers', {
|
|
1963
|
+
value: [...(ParseObjectSubclass.prototype._initializers || []), protoProps[prop]],
|
|
1964
|
+
enumerable: false,
|
|
1965
|
+
writable: true,
|
|
1966
|
+
configurable: true
|
|
1967
|
+
});
|
|
1968
|
+
continue;
|
|
1969
|
+
}
|
|
2585
1970
|
if (prop !== 'className') {
|
|
2586
1971
|
Object.defineProperty(ParseObjectSubclass.prototype, prop, {
|
|
2587
1972
|
value: protoProps[prop],
|
|
@@ -2592,7 +1977,6 @@ class ParseObject {
|
|
|
2592
1977
|
}
|
|
2593
1978
|
}
|
|
2594
1979
|
}
|
|
2595
|
-
|
|
2596
1980
|
if (classProps) {
|
|
2597
1981
|
for (const prop in classProps) {
|
|
2598
1982
|
if (prop !== 'className') {
|
|
@@ -2605,19 +1989,10 @@ class ParseObject {
|
|
|
2605
1989
|
}
|
|
2606
1990
|
}
|
|
2607
1991
|
}
|
|
2608
|
-
|
|
2609
|
-
ParseObjectSubclass.extend = function (name, protoProps, classProps) {
|
|
2610
|
-
if (typeof name === 'string') {
|
|
2611
|
-
return ParseObject.extend.call(ParseObjectSubclass, name, protoProps, classProps);
|
|
2612
|
-
}
|
|
2613
|
-
|
|
2614
|
-
return ParseObject.extend.call(ParseObjectSubclass, adjustedClassName, name, protoProps);
|
|
2615
|
-
};
|
|
2616
|
-
|
|
2617
|
-
ParseObjectSubclass.createWithoutData = ParseObject.createWithoutData;
|
|
2618
1992
|
classMap[adjustedClassName] = ParseObjectSubclass;
|
|
2619
1993
|
return ParseObjectSubclass;
|
|
2620
1994
|
}
|
|
1995
|
+
|
|
2621
1996
|
/**
|
|
2622
1997
|
* Enable single instance objects, where any local objects with the same Id
|
|
2623
1998
|
* share the same attributes, and stay synchronized with each other.
|
|
@@ -2626,13 +2001,11 @@ class ParseObject {
|
|
|
2626
2001
|
*
|
|
2627
2002
|
* @static
|
|
2628
2003
|
*/
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
2004
|
static enableSingleInstance() {
|
|
2632
2005
|
singleInstance = true;
|
|
2633
|
-
|
|
2634
2006
|
_CoreManager.default.setObjectStateController(SingleInstanceStateController);
|
|
2635
2007
|
}
|
|
2008
|
+
|
|
2636
2009
|
/**
|
|
2637
2010
|
* Disable single instance objects, where any local objects with the same Id
|
|
2638
2011
|
* share the same attributes, and stay synchronized with each other.
|
|
@@ -2641,13 +2014,11 @@ class ParseObject {
|
|
|
2641
2014
|
*
|
|
2642
2015
|
* @static
|
|
2643
2016
|
*/
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
2017
|
static disableSingleInstance() {
|
|
2647
2018
|
singleInstance = false;
|
|
2648
|
-
|
|
2649
2019
|
_CoreManager.default.setObjectStateController(UniqueInstanceStateController);
|
|
2650
2020
|
}
|
|
2021
|
+
|
|
2651
2022
|
/**
|
|
2652
2023
|
* Asynchronously stores the objects and every object they point to in the local datastore,
|
|
2653
2024
|
* recursively, using a default pin name: _default.
|
|
@@ -2666,21 +2037,14 @@ class ParseObject {
|
|
|
2666
2037
|
* @returns {Promise} A promise that is fulfilled when the pin completes.
|
|
2667
2038
|
* @static
|
|
2668
2039
|
*/
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
static pinAll(objects
|
|
2672
|
-
/*: Array<ParseObject>*/
|
|
2673
|
-
)
|
|
2674
|
-
/*: Promise<void>*/
|
|
2675
|
-
{
|
|
2040
|
+
static pinAll(objects /*: Array<ParseObject>*/) /*: Promise<void>*/{
|
|
2676
2041
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2677
|
-
|
|
2678
2042
|
if (!localDatastore.isEnabled) {
|
|
2679
2043
|
return Promise.reject('Parse.enableLocalDatastore() must be called first');
|
|
2680
2044
|
}
|
|
2681
|
-
|
|
2682
2045
|
return ParseObject.pinAllWithName(_LocalDatastoreUtils.DEFAULT_PIN, objects);
|
|
2683
2046
|
}
|
|
2047
|
+
|
|
2684
2048
|
/**
|
|
2685
2049
|
* Asynchronously stores the objects and every object they point to in the local datastore, recursively.
|
|
2686
2050
|
*
|
|
@@ -2699,23 +2063,14 @@ class ParseObject {
|
|
|
2699
2063
|
* @returns {Promise} A promise that is fulfilled when the pin completes.
|
|
2700
2064
|
* @static
|
|
2701
2065
|
*/
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
static pinAllWithName(name
|
|
2705
|
-
/*: string*/
|
|
2706
|
-
, objects
|
|
2707
|
-
/*: Array<ParseObject>*/
|
|
2708
|
-
)
|
|
2709
|
-
/*: Promise<void>*/
|
|
2710
|
-
{
|
|
2066
|
+
static pinAllWithName(name /*: string*/, objects /*: Array<ParseObject>*/) /*: Promise<void>*/{
|
|
2711
2067
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2712
|
-
|
|
2713
2068
|
if (!localDatastore.isEnabled) {
|
|
2714
2069
|
return Promise.reject('Parse.enableLocalDatastore() must be called first');
|
|
2715
2070
|
}
|
|
2716
|
-
|
|
2717
2071
|
return localDatastore._handlePinAllWithName(name, objects);
|
|
2718
2072
|
}
|
|
2073
|
+
|
|
2719
2074
|
/**
|
|
2720
2075
|
* Asynchronously removes the objects and every object they point to in the local datastore,
|
|
2721
2076
|
* recursively, using a default pin name: _default.
|
|
@@ -2728,21 +2083,14 @@ class ParseObject {
|
|
|
2728
2083
|
* @returns {Promise} A promise that is fulfilled when the unPin completes.
|
|
2729
2084
|
* @static
|
|
2730
2085
|
*/
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
static unPinAll(objects
|
|
2734
|
-
/*: Array<ParseObject>*/
|
|
2735
|
-
)
|
|
2736
|
-
/*: Promise<void>*/
|
|
2737
|
-
{
|
|
2086
|
+
static unPinAll(objects /*: Array<ParseObject>*/) /*: Promise<void>*/{
|
|
2738
2087
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2739
|
-
|
|
2740
2088
|
if (!localDatastore.isEnabled) {
|
|
2741
2089
|
return Promise.reject('Parse.enableLocalDatastore() must be called first');
|
|
2742
2090
|
}
|
|
2743
|
-
|
|
2744
2091
|
return ParseObject.unPinAllWithName(_LocalDatastoreUtils.DEFAULT_PIN, objects);
|
|
2745
2092
|
}
|
|
2093
|
+
|
|
2746
2094
|
/**
|
|
2747
2095
|
* Asynchronously removes the objects and every object they point to in the local datastore, recursively.
|
|
2748
2096
|
*
|
|
@@ -2755,23 +2103,14 @@ class ParseObject {
|
|
|
2755
2103
|
* @returns {Promise} A promise that is fulfilled when the unPin completes.
|
|
2756
2104
|
* @static
|
|
2757
2105
|
*/
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
static unPinAllWithName(name
|
|
2761
|
-
/*: string*/
|
|
2762
|
-
, objects
|
|
2763
|
-
/*: Array<ParseObject>*/
|
|
2764
|
-
)
|
|
2765
|
-
/*: Promise<void>*/
|
|
2766
|
-
{
|
|
2106
|
+
static unPinAllWithName(name /*: string*/, objects /*: Array<ParseObject>*/) /*: Promise<void>*/{
|
|
2767
2107
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2768
|
-
|
|
2769
2108
|
if (!localDatastore.isEnabled) {
|
|
2770
2109
|
return Promise.reject('Parse.enableLocalDatastore() must be called first');
|
|
2771
2110
|
}
|
|
2772
|
-
|
|
2773
2111
|
return localDatastore._handleUnPinAllWithName(name, objects);
|
|
2774
2112
|
}
|
|
2113
|
+
|
|
2775
2114
|
/**
|
|
2776
2115
|
* Asynchronously removes all objects in the local datastore using a default pin name: _default.
|
|
2777
2116
|
*
|
|
@@ -2782,19 +2121,14 @@ class ParseObject {
|
|
|
2782
2121
|
* @returns {Promise} A promise that is fulfilled when the unPin completes.
|
|
2783
2122
|
* @static
|
|
2784
2123
|
*/
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
static unPinAllObjects()
|
|
2788
|
-
/*: Promise<void>*/
|
|
2789
|
-
{
|
|
2124
|
+
static unPinAllObjects() /*: Promise<void>*/{
|
|
2790
2125
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2791
|
-
|
|
2792
2126
|
if (!localDatastore.isEnabled) {
|
|
2793
2127
|
return Promise.reject('Parse.enableLocalDatastore() must be called first');
|
|
2794
2128
|
}
|
|
2795
|
-
|
|
2796
2129
|
return localDatastore.unPinWithName(_LocalDatastoreUtils.DEFAULT_PIN);
|
|
2797
2130
|
}
|
|
2131
|
+
|
|
2798
2132
|
/**
|
|
2799
2133
|
* Asynchronously removes all objects with the specified pin name.
|
|
2800
2134
|
* Deletes the pin name also.
|
|
@@ -2807,41 +2141,21 @@ class ParseObject {
|
|
|
2807
2141
|
* @returns {Promise} A promise that is fulfilled when the unPin completes.
|
|
2808
2142
|
* @static
|
|
2809
2143
|
*/
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
static unPinAllObjectsWithName(name
|
|
2813
|
-
/*: string*/
|
|
2814
|
-
)
|
|
2815
|
-
/*: Promise<void>*/
|
|
2816
|
-
{
|
|
2144
|
+
static unPinAllObjectsWithName(name /*: string*/) /*: Promise<void>*/{
|
|
2817
2145
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2818
|
-
|
|
2819
2146
|
if (!localDatastore.isEnabled) {
|
|
2820
2147
|
return Promise.reject('Parse.enableLocalDatastore() must be called first');
|
|
2821
2148
|
}
|
|
2822
|
-
|
|
2823
2149
|
return localDatastore.unPinWithName(_LocalDatastoreUtils.PIN_PREFIX + name);
|
|
2824
2150
|
}
|
|
2825
|
-
|
|
2826
2151
|
}
|
|
2827
|
-
|
|
2828
2152
|
const DefaultController = {
|
|
2829
|
-
fetch(target
|
|
2830
|
-
/*: ParseObject | Array<ParseObject>*/
|
|
2831
|
-
, forceFetch
|
|
2832
|
-
/*: boolean*/
|
|
2833
|
-
, options
|
|
2834
|
-
/*: RequestOptions*/
|
|
2835
|
-
)
|
|
2836
|
-
/*: Promise<Array<void> | ParseObject>*/
|
|
2837
|
-
{
|
|
2153
|
+
fetch(target /*: ParseObject | Array<ParseObject>*/, forceFetch /*: boolean*/, options /*: RequestOptions*/) /*: Promise<Array<void> | ParseObject>*/{
|
|
2838
2154
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2839
|
-
|
|
2840
2155
|
if (Array.isArray(target)) {
|
|
2841
2156
|
if (target.length < 1) {
|
|
2842
2157
|
return Promise.resolve([]);
|
|
2843
2158
|
}
|
|
2844
|
-
|
|
2845
2159
|
const objs = [];
|
|
2846
2160
|
const ids = [];
|
|
2847
2161
|
let className = null;
|
|
@@ -2851,140 +2165,100 @@ const DefaultController = {
|
|
|
2851
2165
|
if (error) {
|
|
2852
2166
|
return;
|
|
2853
2167
|
}
|
|
2854
|
-
|
|
2855
2168
|
if (!className) {
|
|
2856
2169
|
className = el.className;
|
|
2857
2170
|
}
|
|
2858
|
-
|
|
2859
2171
|
if (className !== el.className) {
|
|
2860
2172
|
error = new _ParseError.default(_ParseError.default.INVALID_CLASS_NAME, 'All objects should be of the same class');
|
|
2861
2173
|
}
|
|
2862
|
-
|
|
2863
2174
|
if (!el.id) {
|
|
2864
2175
|
error = new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'All objects must have an ID');
|
|
2865
2176
|
}
|
|
2866
|
-
|
|
2867
2177
|
if (forceFetch || !el.isDataAvailable()) {
|
|
2868
2178
|
ids.push(el.id);
|
|
2869
2179
|
objs.push(el);
|
|
2870
2180
|
}
|
|
2871
|
-
|
|
2872
2181
|
results.push(el);
|
|
2873
2182
|
});
|
|
2874
|
-
|
|
2875
2183
|
if (error) {
|
|
2876
2184
|
return Promise.reject(error);
|
|
2877
2185
|
}
|
|
2878
|
-
|
|
2879
2186
|
const query = new _ParseQuery.default(className);
|
|
2880
2187
|
query.containedIn('objectId', ids);
|
|
2881
|
-
|
|
2882
2188
|
if (options && options.include) {
|
|
2883
2189
|
query.include(options.include);
|
|
2884
2190
|
}
|
|
2885
|
-
|
|
2886
2191
|
query._limit = ids.length;
|
|
2887
2192
|
return query.find(options).then(async objects => {
|
|
2888
2193
|
const idMap = {};
|
|
2889
2194
|
objects.forEach(o => {
|
|
2890
2195
|
idMap[o.id] = o;
|
|
2891
2196
|
});
|
|
2892
|
-
|
|
2893
2197
|
for (let i = 0; i < objs.length; i++) {
|
|
2894
2198
|
const obj = objs[i];
|
|
2895
|
-
|
|
2896
2199
|
if (!obj || !obj.id || !idMap[obj.id]) {
|
|
2897
2200
|
if (forceFetch) {
|
|
2898
2201
|
return Promise.reject(new _ParseError.default(_ParseError.default.OBJECT_NOT_FOUND, 'All objects must exist on the server.'));
|
|
2899
2202
|
}
|
|
2900
2203
|
}
|
|
2901
2204
|
}
|
|
2902
|
-
|
|
2903
2205
|
if (!singleInstance) {
|
|
2904
2206
|
// If single instance objects are disabled, we need to replace the
|
|
2905
2207
|
for (let i = 0; i < results.length; i++) {
|
|
2906
2208
|
const obj = results[i];
|
|
2907
|
-
|
|
2908
2209
|
if (obj && obj.id && idMap[obj.id]) {
|
|
2909
2210
|
const id = obj.id;
|
|
2910
|
-
|
|
2911
2211
|
obj._finishFetch(idMap[id].toJSON());
|
|
2912
|
-
|
|
2913
2212
|
results[i] = idMap[id];
|
|
2914
2213
|
}
|
|
2915
2214
|
}
|
|
2916
2215
|
}
|
|
2917
|
-
|
|
2918
2216
|
for (const object of results) {
|
|
2919
2217
|
await localDatastore._updateObjectIfPinned(object);
|
|
2920
2218
|
}
|
|
2921
|
-
|
|
2922
2219
|
return Promise.resolve(results);
|
|
2923
2220
|
});
|
|
2924
2221
|
} else if (target instanceof ParseObject) {
|
|
2925
2222
|
if (!target.id) {
|
|
2926
2223
|
return Promise.reject(new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'Object does not have an ID'));
|
|
2927
2224
|
}
|
|
2928
|
-
|
|
2929
2225
|
const RESTController = _CoreManager.default.getRESTController();
|
|
2930
|
-
|
|
2931
2226
|
const params = {};
|
|
2932
|
-
|
|
2933
2227
|
if (options && options.include) {
|
|
2934
2228
|
params.include = options.include.join();
|
|
2935
2229
|
}
|
|
2936
|
-
|
|
2937
2230
|
return RESTController.request('GET', 'classes/' + target.className + '/' + target._getId(), params, options).then(async response => {
|
|
2938
2231
|
target._clearPendingOps();
|
|
2939
|
-
|
|
2940
2232
|
target._clearServerData();
|
|
2941
|
-
|
|
2942
2233
|
target._finishFetch(response);
|
|
2943
|
-
|
|
2944
2234
|
await localDatastore._updateObjectIfPinned(target);
|
|
2945
2235
|
return target;
|
|
2946
2236
|
});
|
|
2947
2237
|
}
|
|
2948
|
-
|
|
2949
2238
|
return Promise.resolve();
|
|
2950
2239
|
},
|
|
2951
|
-
|
|
2952
|
-
async destroy(target
|
|
2953
|
-
/*: ParseObject | Array<ParseObject>*/
|
|
2954
|
-
, options
|
|
2955
|
-
/*: RequestOptions*/
|
|
2956
|
-
)
|
|
2957
|
-
/*: Promise<Array<void> | ParseObject>*/
|
|
2958
|
-
{
|
|
2240
|
+
async destroy(target /*: ParseObject | Array<ParseObject>*/, options /*: RequestOptions*/) /*: Promise<Array<void> | ParseObject>*/{
|
|
2959
2241
|
const batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
|
|
2960
|
-
|
|
2961
2242
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
2962
|
-
|
|
2963
2243
|
const RESTController = _CoreManager.default.getRESTController();
|
|
2964
|
-
|
|
2965
2244
|
if (Array.isArray(target)) {
|
|
2966
2245
|
if (target.length < 1) {
|
|
2967
2246
|
return Promise.resolve([]);
|
|
2968
2247
|
}
|
|
2969
|
-
|
|
2970
2248
|
const batches = [[]];
|
|
2971
2249
|
target.forEach(obj => {
|
|
2972
2250
|
if (!obj.id) {
|
|
2973
2251
|
return;
|
|
2974
2252
|
}
|
|
2975
|
-
|
|
2976
2253
|
batches[batches.length - 1].push(obj);
|
|
2977
|
-
|
|
2978
2254
|
if (batches[batches.length - 1].length >= batchSize) {
|
|
2979
2255
|
batches.push([]);
|
|
2980
2256
|
}
|
|
2981
2257
|
});
|
|
2982
|
-
|
|
2983
2258
|
if (batches[batches.length - 1].length === 0) {
|
|
2984
2259
|
// If the last batch is empty, remove it
|
|
2985
2260
|
batches.pop();
|
|
2986
2261
|
}
|
|
2987
|
-
|
|
2988
2262
|
let deleteCompleted = Promise.resolve();
|
|
2989
2263
|
const errors = [];
|
|
2990
2264
|
batches.forEach(batch => {
|
|
@@ -3014,11 +2288,9 @@ const DefaultController = {
|
|
|
3014
2288
|
aggregate.errors = errors;
|
|
3015
2289
|
return Promise.reject(aggregate);
|
|
3016
2290
|
}
|
|
3017
|
-
|
|
3018
2291
|
for (const object of target) {
|
|
3019
2292
|
await localDatastore._destroyObjectIfPinned(object);
|
|
3020
2293
|
}
|
|
3021
|
-
|
|
3022
2294
|
return Promise.resolve(target);
|
|
3023
2295
|
});
|
|
3024
2296
|
} else if (target instanceof ParseObject) {
|
|
@@ -3027,50 +2299,30 @@ const DefaultController = {
|
|
|
3027
2299
|
return Promise.resolve(target);
|
|
3028
2300
|
});
|
|
3029
2301
|
}
|
|
3030
|
-
|
|
3031
2302
|
return Promise.resolve(target);
|
|
3032
2303
|
},
|
|
3033
|
-
|
|
3034
|
-
save(target
|
|
3035
|
-
/*: ParseObject | Array<ParseObject | ParseFile>*/
|
|
3036
|
-
, options
|
|
3037
|
-
/*: RequestOptions*/
|
|
3038
|
-
) {
|
|
2304
|
+
save(target /*: ParseObject | Array<ParseObject | ParseFile>*/, options /*: RequestOptions*/) {
|
|
3039
2305
|
const batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
|
|
3040
|
-
|
|
3041
2306
|
const localDatastore = _CoreManager.default.getLocalDatastore();
|
|
3042
|
-
|
|
3043
2307
|
const mapIdForPin = {};
|
|
3044
|
-
|
|
3045
2308
|
const RESTController = _CoreManager.default.getRESTController();
|
|
3046
|
-
|
|
3047
2309
|
const stateController = _CoreManager.default.getObjectStateController();
|
|
3048
|
-
|
|
3049
2310
|
const allowCustomObjectId = _CoreManager.default.get('ALLOW_CUSTOM_OBJECT_ID');
|
|
3050
|
-
|
|
3051
2311
|
options = options || {};
|
|
3052
2312
|
options.returnStatus = options.returnStatus || true;
|
|
3053
|
-
|
|
3054
2313
|
if (Array.isArray(target)) {
|
|
3055
2314
|
if (target.length < 1) {
|
|
3056
2315
|
return Promise.resolve([]);
|
|
3057
2316
|
}
|
|
3058
|
-
|
|
3059
2317
|
let unsaved = target.concat();
|
|
3060
|
-
|
|
3061
2318
|
for (let i = 0; i < target.length; i++) {
|
|
3062
2319
|
if (target[i] instanceof ParseObject) {
|
|
3063
2320
|
unsaved = unsaved.concat((0, _unsavedChildren.default)(target[i], true));
|
|
3064
2321
|
}
|
|
3065
2322
|
}
|
|
3066
|
-
|
|
3067
2323
|
unsaved = (0, _unique.default)(unsaved);
|
|
3068
|
-
const filesSaved
|
|
3069
|
-
/*: Array<
|
|
3070
|
-
= [];
|
|
3071
|
-
let pending
|
|
3072
|
-
/*: Array<ParseObject>*/
|
|
3073
|
-
= [];
|
|
2324
|
+
const filesSaved /*: Array<ParseFile>*/ = [];
|
|
2325
|
+
let pending /*: Array<ParseObject>*/ = [];
|
|
3074
2326
|
unsaved.forEach(el => {
|
|
3075
2327
|
if (el instanceof _ParseFile.default) {
|
|
3076
2328
|
filesSaved.push(el.save(options));
|
|
@@ -3089,7 +2341,6 @@ const DefaultController = {
|
|
|
3089
2341
|
if (allowCustomObjectId && Object.prototype.hasOwnProperty.call(el, 'id') && !el.id) {
|
|
3090
2342
|
throw new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'objectId must not be empty or null');
|
|
3091
2343
|
}
|
|
3092
|
-
|
|
3093
2344
|
if (batch.length < batchSize && (0, _canBeSerialized.default)(el)) {
|
|
3094
2345
|
batch.push(el);
|
|
3095
2346
|
} else {
|
|
@@ -3097,13 +2348,12 @@ const DefaultController = {
|
|
|
3097
2348
|
}
|
|
3098
2349
|
});
|
|
3099
2350
|
pending = nextPending;
|
|
3100
|
-
|
|
3101
2351
|
if (batch.length < 1) {
|
|
3102
2352
|
return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Tried to save a batch with a cycle.'));
|
|
3103
|
-
}
|
|
3104
|
-
// When every task is ready, the API request will execute
|
|
3105
|
-
|
|
2353
|
+
}
|
|
3106
2354
|
|
|
2355
|
+
// Queue up tasks for each object in the batch.
|
|
2356
|
+
// When every task is ready, the API request will execute
|
|
3107
2357
|
const batchReturned = new _promiseUtils.resolvingPromise();
|
|
3108
2358
|
const batchReady = [];
|
|
3109
2359
|
const batchTasks = [];
|
|
@@ -3119,16 +2369,14 @@ const DefaultController = {
|
|
|
3119
2369
|
const status = responses[index]._status;
|
|
3120
2370
|
delete responses[index]._status;
|
|
3121
2371
|
mapIdForPin[objectId] = obj._localId;
|
|
3122
|
-
|
|
3123
2372
|
obj._handleSaveResponse(responses[index].success, status);
|
|
3124
2373
|
} else {
|
|
3125
2374
|
if (!objectError && responses[index].hasOwnProperty('error')) {
|
|
3126
2375
|
const serverError = responses[index].error;
|
|
3127
|
-
objectError = new _ParseError.default(serverError.code, serverError.error);
|
|
3128
|
-
|
|
2376
|
+
objectError = new _ParseError.default(serverError.code, serverError.error);
|
|
2377
|
+
// Cancel the rest of the save
|
|
3129
2378
|
pending = [];
|
|
3130
2379
|
}
|
|
3131
|
-
|
|
3132
2380
|
obj._handleSaveError();
|
|
3133
2381
|
}
|
|
3134
2382
|
});
|
|
@@ -3139,7 +2387,6 @@ const DefaultController = {
|
|
|
3139
2387
|
return RESTController.request('POST', 'batch', {
|
|
3140
2388
|
requests: batch.map(obj => {
|
|
3141
2389
|
const params = obj._getSaveParams();
|
|
3142
|
-
|
|
3143
2390
|
params.path = getServerUrlPath() + params.path;
|
|
3144
2391
|
return params;
|
|
3145
2392
|
})
|
|
@@ -3152,42 +2399,36 @@ const DefaultController = {
|
|
|
3152
2399
|
if (objectError) {
|
|
3153
2400
|
return Promise.reject(objectError);
|
|
3154
2401
|
}
|
|
3155
|
-
|
|
3156
2402
|
for (const object of target) {
|
|
3157
|
-
|
|
3158
|
-
|
|
2403
|
+
// Make sure that it is a ParseObject before updating it into the localDataStore
|
|
2404
|
+
if (object instanceof ParseObject) {
|
|
2405
|
+
await localDatastore._updateLocalIdForObject(mapIdForPin[object.id], object);
|
|
2406
|
+
await localDatastore._updateObjectIfPinned(object);
|
|
2407
|
+
}
|
|
3159
2408
|
}
|
|
3160
|
-
|
|
3161
2409
|
return Promise.resolve(target);
|
|
3162
2410
|
});
|
|
3163
2411
|
});
|
|
3164
2412
|
} else if (target instanceof ParseObject) {
|
|
3165
2413
|
if (allowCustomObjectId && Object.prototype.hasOwnProperty.call(target, 'id') && !target.id) {
|
|
3166
2414
|
throw new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'objectId must not be empty or null');
|
|
3167
|
-
}
|
|
3168
|
-
|
|
3169
|
-
|
|
2415
|
+
}
|
|
2416
|
+
// generate _localId in case if cascadeSave=false
|
|
3170
2417
|
target._getId();
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
2418
|
+
const localId = target._localId;
|
|
2419
|
+
// copying target lets Flow guarantee the pointer isn't modified elsewhere
|
|
3174
2420
|
const targetCopy = target;
|
|
3175
|
-
|
|
3176
2421
|
const task = function () {
|
|
3177
2422
|
const params = targetCopy._getSaveParams();
|
|
3178
|
-
|
|
3179
2423
|
return RESTController.request(params.method, params.path, params.body, options).then(response => {
|
|
3180
2424
|
const status = response._status;
|
|
3181
2425
|
delete response._status;
|
|
3182
|
-
|
|
3183
2426
|
targetCopy._handleSaveResponse(response, status);
|
|
3184
2427
|
}, error => {
|
|
3185
2428
|
targetCopy._handleSaveError();
|
|
3186
|
-
|
|
3187
2429
|
return Promise.reject(error);
|
|
3188
2430
|
});
|
|
3189
2431
|
};
|
|
3190
|
-
|
|
3191
2432
|
stateController.pushPendingState(target._getStateIdentifier());
|
|
3192
2433
|
return stateController.enqueueTask(target._getStateIdentifier(), task).then(async () => {
|
|
3193
2434
|
await localDatastore._updateLocalIdForObject(localId, target);
|
|
@@ -3197,13 +2438,9 @@ const DefaultController = {
|
|
|
3197
2438
|
return Promise.reject(error);
|
|
3198
2439
|
});
|
|
3199
2440
|
}
|
|
3200
|
-
|
|
3201
2441
|
return Promise.resolve();
|
|
3202
2442
|
}
|
|
3203
|
-
|
|
3204
2443
|
};
|
|
3205
|
-
|
|
3206
2444
|
_CoreManager.default.setObjectController(DefaultController);
|
|
3207
|
-
|
|
3208
2445
|
var _default = ParseObject;
|
|
3209
2446
|
exports.default = _default;
|