parse 4.0.1 → 4.1.0-alpha.2

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