parse 4.0.0-alpha.1 → 4.0.0-alpha.11

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