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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/LICENSE +167 -25
  2. package/NOTICE +10 -0
  3. package/README.md +6 -5
  4. package/dist/parse.js +12838 -21190
  5. package/dist/parse.min.js +7 -6
  6. package/dist/parse.weapp.js +7921 -17062
  7. package/dist/parse.weapp.min.js +7 -6
  8. package/lib/browser/Analytics.js +2 -27
  9. package/lib/browser/AnonymousUtils.js +6 -42
  10. package/lib/browser/Cloud.js +12 -77
  11. package/lib/browser/CloudCode.js +0 -3
  12. package/lib/browser/CoreManager.js +46 -191
  13. package/lib/browser/CryptoController.js +2 -16
  14. package/lib/browser/EventEmitter.js +1 -8
  15. package/lib/browser/EventuallyQueue.js +277 -824
  16. package/lib/browser/FacebookUtils.js +6 -42
  17. package/lib/browser/IndexedDBStorageController.js +3 -14
  18. package/lib/browser/InstallationController.js +2 -20
  19. package/lib/browser/LiveQueryClient.js +105 -213
  20. package/lib/browser/LiveQuerySubscription.js +10 -39
  21. package/lib/browser/LocalDatastore.js +451 -1081
  22. package/lib/browser/LocalDatastoreController.js +145 -602
  23. package/lib/browser/LocalDatastoreController.react-native.js +137 -573
  24. package/lib/browser/LocalDatastoreUtils.js +2 -19
  25. package/lib/browser/ObjectStateMutations.js +18 -121
  26. package/lib/browser/OfflineQuery.js +61 -222
  27. package/lib/browser/Parse.js +12 -115
  28. package/lib/browser/ParseACL.js +33 -148
  29. package/lib/browser/ParseCLP.js +96 -314
  30. package/lib/browser/ParseConfig.js +18 -95
  31. package/lib/browser/ParseError.js +63 -99
  32. package/lib/browser/ParseFile.js +128 -685
  33. package/lib/browser/ParseGeoPoint.js +23 -89
  34. package/lib/browser/ParseHooks.js +1 -34
  35. package/lib/browser/ParseInstallation.js +4 -32
  36. package/lib/browser/ParseLiveQuery.js +96 -505
  37. package/lib/browser/ParseObject.js +665 -1845
  38. package/lib/browser/ParseOp.js +41 -287
  39. package/lib/browser/ParsePolygon.js +13 -70
  40. package/lib/browser/ParseQuery.js +403 -1504
  41. package/lib/browser/ParseRelation.js +12 -68
  42. package/lib/browser/ParseRole.js +13 -75
  43. package/lib/browser/ParseSchema.js +49 -208
  44. package/lib/browser/ParseSession.js +11 -69
  45. package/lib/browser/ParseUser.js +274 -1127
  46. package/lib/browser/Push.js +7 -50
  47. package/lib/browser/RESTController.js +28 -157
  48. package/lib/browser/SingleInstanceStateController.js +19 -144
  49. package/lib/browser/Socket.weapp.js +0 -10
  50. package/lib/browser/Storage.js +10 -80
  51. package/lib/browser/StorageController.browser.js +4 -24
  52. package/lib/browser/StorageController.default.js +4 -24
  53. package/lib/browser/StorageController.react-native.js +6 -40
  54. package/lib/browser/StorageController.weapp.js +5 -23
  55. package/lib/browser/TaskQueue.js +1 -29
  56. package/lib/browser/UniqueInstanceStateController.js +19 -149
  57. package/lib/browser/Xhr.weapp.js +0 -17
  58. package/lib/browser/arrayContainsObject.js +2 -23
  59. package/lib/browser/canBeSerialized.js +3 -40
  60. package/lib/browser/decode.js +3 -40
  61. package/lib/browser/encode.js +9 -77
  62. package/lib/browser/equals.js +2 -34
  63. package/lib/browser/escape.js +1 -15
  64. package/lib/browser/isRevocableSession.js +2 -18
  65. package/lib/browser/parseDate.js +2 -20
  66. package/lib/browser/promiseUtils.js +3 -21
  67. package/lib/browser/unique.js +3 -24
  68. package/lib/browser/unsavedChildren.js +6 -57
  69. package/lib/browser/uuid.js +3 -1
  70. package/lib/node/Analytics.js +1 -25
  71. package/lib/node/AnonymousUtils.js +5 -44
  72. package/lib/node/Cloud.js +10 -73
  73. package/lib/node/CloudCode.js +0 -3
  74. package/lib/node/CoreManager.js +47 -227
  75. package/lib/node/CryptoController.js +2 -16
  76. package/lib/node/EventEmitter.js +1 -8
  77. package/lib/node/EventuallyQueue.js +16 -123
  78. package/lib/node/FacebookUtils.js +5 -44
  79. package/lib/node/IndexedDBStorageController.js +3 -19
  80. package/lib/node/InstallationController.js +2 -22
  81. package/lib/node/LiveQueryClient.js +72 -154
  82. package/lib/node/LiveQuerySubscription.js +7 -26
  83. package/lib/node/LocalDatastore.js +19 -182
  84. package/lib/node/LocalDatastoreController.js +6 -45
  85. package/lib/node/LocalDatastoreController.react-native.js +6 -52
  86. package/lib/node/LocalDatastoreUtils.js +1 -13
  87. package/lib/node/ObjectStateMutations.js +13 -100
  88. package/lib/node/OfflineQuery.js +27 -151
  89. package/lib/node/Parse.js +11 -108
  90. package/lib/node/ParseACL.js +32 -157
  91. package/lib/node/ParseCLP.js +69 -269
  92. package/lib/node/ParseConfig.js +16 -91
  93. package/lib/node/ParseError.js +61 -74
  94. package/lib/node/ParseFile.js +49 -212
  95. package/lib/node/ParseGeoPoint.js +21 -89
  96. package/lib/node/ParseHooks.js +0 -35
  97. package/lib/node/ParseInstallation.js +1 -17
  98. package/lib/node/ParseLiveQuery.js +10 -43
  99. package/lib/node/ParseObject.js +229 -964
  100. package/lib/node/ParseOp.js +31 -262
  101. package/lib/node/ParsePolygon.js +12 -69
  102. package/lib/node/ParseQuery.js +169 -888
  103. package/lib/node/ParseRelation.js +11 -68
  104. package/lib/node/ParseRole.js +10 -64
  105. package/lib/node/ParseSchema.js +46 -229
  106. package/lib/node/ParseSession.js +8 -57
  107. package/lib/node/ParseUser.js +107 -583
  108. package/lib/node/Push.js +4 -44
  109. package/lib/node/RESTController.js +18 -127
  110. package/lib/node/SingleInstanceStateController.js +17 -137
  111. package/lib/node/Socket.weapp.js +0 -7
  112. package/lib/node/Storage.js +10 -90
  113. package/lib/node/StorageController.browser.js +4 -30
  114. package/lib/node/StorageController.default.js +5 -28
  115. package/lib/node/StorageController.react-native.js +6 -47
  116. package/lib/node/StorageController.weapp.js +6 -28
  117. package/lib/node/TaskQueue.js +1 -24
  118. package/lib/node/UniqueInstanceStateController.js +16 -140
  119. package/lib/node/Xhr.weapp.js +0 -15
  120. package/lib/node/arrayContainsObject.js +1 -19
  121. package/lib/node/canBeSerialized.js +2 -35
  122. package/lib/node/decode.js +1 -33
  123. package/lib/node/encode.js +3 -61
  124. package/lib/node/equals.js +0 -27
  125. package/lib/node/escape.js +1 -13
  126. package/lib/node/isRevocableSession.js +1 -12
  127. package/lib/node/parseDate.js +1 -14
  128. package/lib/node/promiseUtils.js +2 -14
  129. package/lib/node/unique.js +1 -18
  130. package/lib/node/unsavedChildren.js +2 -45
  131. package/lib/node/uuid.js +6 -1
  132. package/lib/react-native/Analytics.js +0 -9
  133. package/lib/react-native/AnonymousUtils.js +0 -10
  134. package/lib/react-native/Cloud.js +0 -26
  135. package/lib/react-native/CoreManager.js +2 -6
  136. package/lib/react-native/CryptoController.js +0 -2
  137. package/lib/react-native/EventEmitter.js +0 -2
  138. package/lib/react-native/EventuallyQueue.js +156 -711
  139. package/lib/react-native/FacebookUtils.js +0 -22
  140. package/lib/react-native/IndexedDBStorageController.js +0 -1
  141. package/lib/react-native/InstallationController.js +0 -6
  142. package/lib/react-native/LiveQueryClient.js +46 -157
  143. package/lib/react-native/LiveQuerySubscription.js +3 -27
  144. package/lib/react-native/LocalDatastore.js +281 -948
  145. package/lib/react-native/LocalDatastoreController.js +71 -552
  146. package/lib/react-native/LocalDatastoreController.react-native.js +91 -526
  147. package/lib/react-native/LocalDatastoreUtils.js +0 -1
  148. package/lib/react-native/ObjectStateMutations.js +2 -65
  149. package/lib/react-native/OfflineQuery.js +25 -196
  150. package/lib/react-native/Parse.js +0 -65
  151. package/lib/react-native/ParseACL.js +0 -44
  152. package/lib/react-native/ParseCLP.js +23 -161
  153. package/lib/react-native/ParseConfig.js +0 -42
  154. package/lib/react-native/ParseError.js +1 -21
  155. package/lib/react-native/ParseFile.js +55 -529
  156. package/lib/react-native/ParseGeoPoint.js +0 -17
  157. package/lib/react-native/ParseHooks.js +0 -30
  158. package/lib/react-native/ParseInstallation.js +1 -23
  159. package/lib/react-native/ParseLiveQuery.js +55 -472
  160. package/lib/react-native/ParseObject.js +245 -1246
  161. package/lib/react-native/ParseOp.js +1 -138
  162. package/lib/react-native/ParsePolygon.js +0 -24
  163. package/lib/react-native/ParseQuery.js +182 -874
  164. package/lib/react-native/ParseRelation.js +0 -25
  165. package/lib/react-native/ParseRole.js +1 -36
  166. package/lib/react-native/ParseSchema.js +3 -54
  167. package/lib/react-native/ParseSession.js +1 -40
  168. package/lib/react-native/ParseUser.js +95 -773
  169. package/lib/react-native/Push.js +0 -16
  170. package/lib/react-native/RESTController.js +12 -109
  171. package/lib/react-native/SingleInstanceStateController.js +0 -44
  172. package/lib/react-native/Socket.weapp.js +0 -10
  173. package/lib/react-native/Storage.js +0 -24
  174. package/lib/react-native/StorageController.browser.js +0 -2
  175. package/lib/react-native/StorageController.default.js +0 -1
  176. package/lib/react-native/StorageController.react-native.js +0 -2
  177. package/lib/react-native/TaskQueue.js +0 -15
  178. package/lib/react-native/UniqueInstanceStateController.js +0 -47
  179. package/lib/react-native/Xhr.weapp.js +0 -16
  180. package/lib/react-native/arrayContainsObject.js +0 -5
  181. package/lib/react-native/canBeSerialized.js +0 -18
  182. package/lib/react-native/decode.js +0 -21
  183. package/lib/react-native/encode.js +0 -25
  184. package/lib/react-native/equals.js +0 -18
  185. package/lib/react-native/escape.js +0 -1
  186. package/lib/react-native/isRevocableSession.js +0 -1
  187. package/lib/react-native/parseDate.js +0 -3
  188. package/lib/react-native/promiseUtils.js +0 -13
  189. package/lib/react-native/unique.js +0 -4
  190. package/lib/react-native/unsavedChildren.js +0 -21
  191. package/lib/react-native/uuid.js +3 -1
  192. package/lib/weapp/Analytics.js +2 -27
  193. package/lib/weapp/AnonymousUtils.js +6 -42
  194. package/lib/weapp/Cloud.js +12 -77
  195. package/lib/weapp/CloudCode.js +0 -3
  196. package/lib/weapp/CoreManager.js +46 -191
  197. package/lib/weapp/CryptoController.js +2 -16
  198. package/lib/weapp/EventEmitter.js +1 -8
  199. package/lib/weapp/EventuallyQueue.js +277 -824
  200. package/lib/weapp/FacebookUtils.js +6 -42
  201. package/lib/weapp/IndexedDBStorageController.js +3 -14
  202. package/lib/weapp/InstallationController.js +2 -20
  203. package/lib/weapp/LiveQueryClient.js +105 -213
  204. package/lib/weapp/LiveQuerySubscription.js +10 -39
  205. package/lib/weapp/LocalDatastore.js +451 -1081
  206. package/lib/weapp/LocalDatastoreController.js +145 -602
  207. package/lib/weapp/LocalDatastoreController.react-native.js +137 -573
  208. package/lib/weapp/LocalDatastoreUtils.js +2 -19
  209. package/lib/weapp/ObjectStateMutations.js +18 -121
  210. package/lib/weapp/OfflineQuery.js +61 -222
  211. package/lib/weapp/Parse.js +12 -115
  212. package/lib/weapp/ParseACL.js +33 -148
  213. package/lib/weapp/ParseCLP.js +96 -314
  214. package/lib/weapp/ParseConfig.js +18 -95
  215. package/lib/weapp/ParseError.js +63 -99
  216. package/lib/weapp/ParseFile.js +129 -686
  217. package/lib/weapp/ParseGeoPoint.js +23 -89
  218. package/lib/weapp/ParseHooks.js +1 -34
  219. package/lib/weapp/ParseInstallation.js +4 -32
  220. package/lib/weapp/ParseLiveQuery.js +96 -505
  221. package/lib/weapp/ParseObject.js +665 -1845
  222. package/lib/weapp/ParseOp.js +41 -287
  223. package/lib/weapp/ParsePolygon.js +13 -70
  224. package/lib/weapp/ParseQuery.js +403 -1504
  225. package/lib/weapp/ParseRelation.js +12 -68
  226. package/lib/weapp/ParseRole.js +13 -75
  227. package/lib/weapp/ParseSchema.js +49 -208
  228. package/lib/weapp/ParseSession.js +11 -69
  229. package/lib/weapp/ParseUser.js +274 -1127
  230. package/lib/weapp/Push.js +7 -50
  231. package/lib/weapp/RESTController.js +28 -157
  232. package/lib/weapp/SingleInstanceStateController.js +19 -144
  233. package/lib/weapp/Socket.weapp.js +0 -10
  234. package/lib/weapp/Storage.js +10 -80
  235. package/lib/weapp/StorageController.browser.js +4 -24
  236. package/lib/weapp/StorageController.default.js +4 -24
  237. package/lib/weapp/StorageController.react-native.js +6 -40
  238. package/lib/weapp/StorageController.weapp.js +5 -23
  239. package/lib/weapp/TaskQueue.js +1 -29
  240. package/lib/weapp/UniqueInstanceStateController.js +19 -149
  241. package/lib/weapp/Xhr.weapp.js +0 -17
  242. package/lib/weapp/arrayContainsObject.js +2 -23
  243. package/lib/weapp/canBeSerialized.js +3 -40
  244. package/lib/weapp/decode.js +3 -40
  245. package/lib/weapp/encode.js +9 -77
  246. package/lib/weapp/equals.js +2 -34
  247. package/lib/weapp/escape.js +1 -15
  248. package/lib/weapp/isRevocableSession.js +2 -18
  249. package/lib/weapp/parseDate.js +2 -20
  250. package/lib/weapp/promiseUtils.js +3 -21
  251. package/lib/weapp/unique.js +3 -24
  252. package/lib/weapp/unsavedChildren.js +6 -57
  253. package/lib/weapp/uuid.js +1 -6
  254. package/package.json +35 -31
  255. package/PATENTS +0 -37
@@ -1,54 +1,31 @@
1
1
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: true
5
4
  });
6
5
  exports.default = void 0;
7
-
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
-
6
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
7
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
10
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
15
-
16
11
  var _canBeSerialized = _interopRequireDefault(require("./canBeSerialized"));
17
-
18
12
  var _decode = _interopRequireDefault(require("./decode"));
19
-
20
13
  var _encode = _interopRequireDefault(require("./encode"));
21
-
22
14
  var _escape2 = _interopRequireDefault(require("./escape"));
23
-
24
15
  var _EventuallyQueue = _interopRequireDefault(require("./EventuallyQueue"));
25
-
26
16
  var _ParseACL = _interopRequireDefault(require("./ParseACL"));
27
-
28
17
  var _parseDate = _interopRequireDefault(require("./parseDate"));
29
-
30
18
  var _ParseError = _interopRequireDefault(require("./ParseError"));
31
-
32
19
  var _ParseFile = _interopRequireDefault(require("./ParseFile"));
33
-
34
20
  var _promiseUtils = require("./promiseUtils");
35
-
36
21
  var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
37
-
38
22
  var _ParseOp = require("./ParseOp");
39
-
40
23
  var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
41
-
42
24
  var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
43
-
44
25
  var SingleInstanceStateController = _interopRequireWildcard(require("./SingleInstanceStateController"));
45
-
46
26
  var _unique = _interopRequireDefault(require("./unique"));
47
-
48
27
  var UniqueInstanceStateController = _interopRequireWildcard(require("./UniqueInstanceStateController"));
49
-
50
28
  var _unsavedChildren = _interopRequireDefault(require("./unsavedChildren"));
51
-
52
29
  function _getRequireWildcardCache(nodeInterop) {
53
30
  if (typeof WeakMap !== "function") return null;
54
31
  var cacheBabelInterop = new WeakMap();
@@ -57,31 +34,24 @@ function _getRequireWildcardCache(nodeInterop) {
57
34
  return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
58
35
  })(nodeInterop);
59
36
  }
60
-
61
37
  function _interopRequireWildcard(obj, nodeInterop) {
62
38
  if (!nodeInterop && obj && obj.__esModule) {
63
39
  return obj;
64
40
  }
65
-
66
41
  if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
67
42
  return {
68
43
  default: obj
69
44
  };
70
45
  }
71
-
72
46
  var cache = _getRequireWildcardCache(nodeInterop);
73
-
74
47
  if (cache && cache.has(obj)) {
75
48
  return cache.get(obj);
76
49
  }
77
-
78
50
  var newObj = {};
79
51
  var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
80
-
81
52
  for (var key in obj) {
82
53
  if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
83
54
  var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
84
-
85
55
  if (desc && (desc.get || desc.set)) {
86
56
  Object.defineProperty(newObj, key, desc);
87
57
  } else {
@@ -89,498 +59,62 @@ function _interopRequireWildcard(obj, nodeInterop) {
89
59
  }
90
60
  }
91
61
  }
92
-
93
62
  newObj.default = obj;
94
-
95
63
  if (cache) {
96
64
  cache.set(obj, newObj);
97
65
  }
98
-
99
66
  return newObj;
100
67
  }
101
-
102
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
103
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
104
- if (it) return (it = it.call(o)).next.bind(it);
105
-
106
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
107
- if (it) o = it;
108
- var i = 0;
109
- return function () {
110
- if (i >= o.length) return {
111
- done: true
112
- };
113
- return {
114
- done: false,
115
- value: o[i++]
116
- };
117
- };
118
- }
119
-
120
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
121
- }
122
-
123
- function _unsupportedIterableToArray(o, minLen) {
124
- if (!o) return;
125
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
126
- var n = Object.prototype.toString.call(o).slice(8, -1);
127
- if (n === "Object" && o.constructor) n = o.constructor.name;
128
- if (n === "Map" || n === "Set") return Array.from(o);
129
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
130
- }
131
-
132
- function _arrayLikeToArray(arr, len) {
133
- if (len == null || len > arr.length) len = arr.length;
134
-
135
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
136
- arr2[i] = arr[i];
137
- }
138
-
139
- return arr2;
140
- }
141
-
142
- function _regeneratorRuntime() {
143
- "use strict";
144
-
145
- _regeneratorRuntime = function () {
146
- return exports;
147
- };
148
-
149
- var exports = {},
150
- Op = Object.prototype,
151
- hasOwn = Op.hasOwnProperty,
152
- $Symbol = "function" == typeof Symbol ? Symbol : {},
153
- iteratorSymbol = $Symbol.iterator || "@@iterator",
154
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
155
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
156
-
157
- function define(obj, key, value) {
158
- return Object.defineProperty(obj, key, {
159
- value: value,
160
- enumerable: !0,
161
- configurable: !0,
162
- writable: !0
163
- }), obj[key];
164
- }
165
-
166
- try {
167
- define({}, "");
168
- } catch (err) {
169
- define = function (obj, key, value) {
170
- return obj[key] = value;
171
- };
172
- }
173
-
174
- function wrap(innerFn, outerFn, self, tryLocsList) {
175
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
176
- generator = Object.create(protoGenerator.prototype),
177
- context = new Context(tryLocsList || []);
178
- return generator._invoke = function (innerFn, self, context) {
179
- var state = "suspendedStart";
180
- return function (method, arg) {
181
- if ("executing" === state) throw new Error("Generator is already running");
182
-
183
- if ("completed" === state) {
184
- if ("throw" === method) throw arg;
185
- return doneResult();
186
- }
187
-
188
- for (context.method = method, context.arg = arg;;) {
189
- var delegate = context.delegate;
190
-
191
- if (delegate) {
192
- var delegateResult = maybeInvokeDelegate(delegate, context);
193
-
194
- if (delegateResult) {
195
- if (delegateResult === ContinueSentinel) continue;
196
- return delegateResult;
197
- }
198
- }
199
-
200
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
201
- if ("suspendedStart" === state) throw state = "completed", context.arg;
202
- context.dispatchException(context.arg);
203
- } else "return" === context.method && context.abrupt("return", context.arg);
204
- state = "executing";
205
- var record = tryCatch(innerFn, self, context);
206
-
207
- if ("normal" === record.type) {
208
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
209
- return {
210
- value: record.arg,
211
- done: context.done
212
- };
213
- }
214
-
215
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
216
- }
217
- };
218
- }(innerFn, self, context), generator;
219
- }
220
-
221
- function tryCatch(fn, obj, arg) {
222
- try {
223
- return {
224
- type: "normal",
225
- arg: fn.call(obj, arg)
226
- };
227
- } catch (err) {
228
- return {
229
- type: "throw",
230
- arg: err
231
- };
232
- }
233
- }
234
-
235
- exports.wrap = wrap;
236
- var ContinueSentinel = {};
237
-
238
- function Generator() {}
239
-
240
- function GeneratorFunction() {}
241
-
242
- function GeneratorFunctionPrototype() {}
243
-
244
- var IteratorPrototype = {};
245
- define(IteratorPrototype, iteratorSymbol, function () {
246
- return this;
247
- });
248
- var getProto = Object.getPrototypeOf,
249
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
250
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
251
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
252
-
253
- function defineIteratorMethods(prototype) {
254
- ["next", "throw", "return"].forEach(function (method) {
255
- define(prototype, method, function (arg) {
256
- return this._invoke(method, arg);
257
- });
258
- });
259
- }
260
-
261
- function AsyncIterator(generator, PromiseImpl) {
262
- function invoke(method, arg, resolve, reject) {
263
- var record = tryCatch(generator[method], generator, arg);
264
-
265
- if ("throw" !== record.type) {
266
- var result = record.arg,
267
- value = result.value;
268
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
269
- invoke("next", value, resolve, reject);
270
- }, function (err) {
271
- invoke("throw", err, resolve, reject);
272
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
273
- result.value = unwrapped, resolve(result);
274
- }, function (error) {
275
- return invoke("throw", error, resolve, reject);
276
- });
277
- }
278
-
279
- reject(record.arg);
280
- }
281
-
282
- var previousPromise;
283
-
284
- this._invoke = function (method, arg) {
285
- function callInvokeWithMethodAndArg() {
286
- return new PromiseImpl(function (resolve, reject) {
287
- invoke(method, arg, resolve, reject);
288
- });
289
- }
290
-
291
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
292
- };
293
- }
294
-
295
- function maybeInvokeDelegate(delegate, context) {
296
- var method = delegate.iterator[context.method];
297
-
298
- if (undefined === method) {
299
- if (context.delegate = null, "throw" === context.method) {
300
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
301
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
302
- }
303
-
304
- return ContinueSentinel;
305
- }
306
-
307
- var record = tryCatch(method, delegate.iterator, context.arg);
308
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
309
- var info = record.arg;
310
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
311
- }
312
-
313
- function pushTryEntry(locs) {
314
- var entry = {
315
- tryLoc: locs[0]
316
- };
317
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
318
- }
319
-
320
- function resetTryEntry(entry) {
321
- var record = entry.completion || {};
322
- record.type = "normal", delete record.arg, entry.completion = record;
323
- }
324
-
325
- function Context(tryLocsList) {
326
- this.tryEntries = [{
327
- tryLoc: "root"
328
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
329
- }
330
-
331
- function values(iterable) {
332
- if (iterable) {
333
- var iteratorMethod = iterable[iteratorSymbol];
334
- if (iteratorMethod) return iteratorMethod.call(iterable);
335
- if ("function" == typeof iterable.next) return iterable;
336
-
337
- if (!isNaN(iterable.length)) {
338
- var i = -1,
339
- next = function next() {
340
- for (; ++i < iterable.length;) {
341
- if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
342
- }
343
-
344
- return next.value = undefined, next.done = !0, next;
345
- };
346
-
347
- return next.next = next;
348
- }
349
- }
350
-
351
- return {
352
- next: doneResult
353
- };
354
- }
355
-
356
- function doneResult() {
357
- return {
358
- value: undefined,
359
- done: !0
360
- };
361
- }
362
-
363
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
364
- var ctor = "function" == typeof genFun && genFun.constructor;
365
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
366
- }, exports.mark = function (genFun) {
367
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
368
- }, exports.awrap = function (arg) {
369
- return {
370
- __await: arg
371
- };
372
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
373
- return this;
374
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
375
- void 0 === PromiseImpl && (PromiseImpl = Promise);
376
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
377
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
378
- return result.done ? result.value : iter.next();
379
- });
380
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
381
- return this;
382
- }), define(Gp, "toString", function () {
383
- return "[object Generator]";
384
- }), exports.keys = function (object) {
385
- var keys = [];
386
-
387
- for (var key in object) {
388
- keys.push(key);
389
- }
390
-
391
- return keys.reverse(), function next() {
392
- for (; keys.length;) {
393
- var key = keys.pop();
394
- if (key in object) return next.value = key, next.done = !1, next;
395
- }
396
-
397
- return next.done = !0, next;
398
- };
399
- }, exports.values = values, Context.prototype = {
400
- constructor: Context,
401
- reset: function (skipTempReset) {
402
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
403
- "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
404
- }
405
- },
406
- stop: function () {
407
- this.done = !0;
408
- var rootRecord = this.tryEntries[0].completion;
409
- if ("throw" === rootRecord.type) throw rootRecord.arg;
410
- return this.rval;
411
- },
412
- dispatchException: function (exception) {
413
- if (this.done) throw exception;
414
- var context = this;
415
-
416
- function handle(loc, caught) {
417
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
418
- }
419
-
420
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
421
- var entry = this.tryEntries[i],
422
- record = entry.completion;
423
- if ("root" === entry.tryLoc) return handle("end");
424
-
425
- if (entry.tryLoc <= this.prev) {
426
- var hasCatch = hasOwn.call(entry, "catchLoc"),
427
- hasFinally = hasOwn.call(entry, "finallyLoc");
428
-
429
- if (hasCatch && hasFinally) {
430
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
431
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
432
- } else if (hasCatch) {
433
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
434
- } else {
435
- if (!hasFinally) throw new Error("try statement without catch or finally");
436
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
437
- }
438
- }
439
- }
440
- },
441
- abrupt: function (type, arg) {
442
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
443
- var entry = this.tryEntries[i];
444
-
445
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
446
- var finallyEntry = entry;
447
- break;
448
- }
449
- }
450
-
451
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
452
- var record = finallyEntry ? finallyEntry.completion : {};
453
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
454
- },
455
- complete: function (record, afterLoc) {
456
- if ("throw" === record.type) throw record.arg;
457
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
458
- },
459
- finish: function (finallyLoc) {
460
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
461
- var entry = this.tryEntries[i];
462
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
463
- }
464
- },
465
- catch: function (tryLoc) {
466
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
467
- var entry = this.tryEntries[i];
468
-
469
- if (entry.tryLoc === tryLoc) {
470
- var record = entry.completion;
471
-
472
- if ("throw" === record.type) {
473
- var thrown = record.arg;
474
- resetTryEntry(entry);
475
- }
476
-
477
- return thrown;
478
- }
479
- }
480
-
481
- throw new Error("illegal catch attempt");
482
- },
483
- delegateYield: function (iterable, resultName, nextLoc) {
484
- return this.delegate = {
485
- iterator: values(iterable),
486
- resultName: resultName,
487
- nextLoc: nextLoc
488
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
489
- }
490
- }, exports;
491
- }
492
-
493
- function ownKeys(object, enumerableOnly) {
494
- var keys = Object.keys(object);
495
-
496
- if (Object.getOwnPropertySymbols) {
497
- var symbols = Object.getOwnPropertySymbols(object);
498
- enumerableOnly && (symbols = symbols.filter(function (sym) {
499
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
500
- })), keys.push.apply(keys, symbols);
501
- }
502
-
503
- return keys;
504
- }
505
-
506
- function _objectSpread(target) {
507
- for (var i = 1; i < arguments.length; i++) {
508
- var source = null != arguments[i] ? arguments[i] : {};
509
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
510
- (0, _defineProperty2.default)(target, key, source[key]);
511
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
512
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
513
- });
514
- }
515
-
516
- return target;
517
- }
518
-
519
68
  var uuidv4 = require('./uuid');
520
-
521
69
  var classMap = {};
522
70
  var objectCount = 0;
523
71
  var singleInstance = !_CoreManager.default.get('IS_NODE');
524
-
525
72
  if (singleInstance) {
526
73
  _CoreManager.default.setObjectStateController(SingleInstanceStateController);
527
74
  } else {
528
75
  _CoreManager.default.setObjectStateController(UniqueInstanceStateController);
529
76
  }
530
-
531
77
  function getServerUrlPath() {
532
78
  var serverUrl = _CoreManager.default.get('SERVER_URL');
533
-
534
79
  if (serverUrl[serverUrl.length - 1] !== '/') {
535
80
  serverUrl += '/';
536
81
  }
537
-
538
82
  var url = serverUrl.replace(/https?:\/\//, '');
539
83
  return url.substr(url.indexOf('/'));
540
84
  }
541
-
542
85
  var ParseObject = function () {
543
86
  function ParseObject(className, attributes, options) {
544
87
  (0, _classCallCheck2.default)(this, ParseObject);
545
-
546
88
  if (typeof this.initialize === 'function') {
547
89
  this.initialize.apply(this, arguments);
548
90
  }
549
-
550
91
  var toSet = null;
551
92
  this._objCount = objectCount++;
552
-
553
93
  if (typeof className === 'string') {
554
94
  this.className = className;
555
-
556
95
  if (attributes && typeof attributes === 'object') {
557
96
  toSet = attributes;
558
97
  }
559
98
  } else if (className && typeof className === 'object') {
560
99
  this.className = className.className;
561
100
  toSet = {};
562
-
563
101
  for (var _attr in className) {
564
102
  if (_attr !== 'className') {
565
103
  toSet[_attr] = className[_attr];
566
104
  }
567
105
  }
568
-
569
106
  if (attributes && typeof attributes === 'object') {
570
107
  options = attributes;
571
108
  }
572
109
  }
573
-
574
110
  if (toSet && !this.set(toSet, options)) {
575
111
  throw new Error("Can't create an invalid Parse Object");
576
112
  }
577
113
  }
578
-
579
114
  (0, _createClass2.default)(ParseObject, [{
580
115
  key: "attributes",
581
116
  get: function () {
582
117
  var stateController = _CoreManager.default.getObjectStateController();
583
-
584
118
  return Object.freeze(stateController.estimateAttributes(this._getStateIdentifier()));
585
119
  }
586
120
  }, {
@@ -599,11 +133,9 @@ var ParseObject = function () {
599
133
  if (typeof this.id === 'string') {
600
134
  return this.id;
601
135
  }
602
-
603
136
  if (typeof this._localId === 'string') {
604
137
  return this._localId;
605
138
  }
606
-
607
139
  var localId = 'local' + uuidv4();
608
140
  this._localId = localId;
609
141
  return localId;
@@ -613,11 +145,9 @@ var ParseObject = function () {
613
145
  value: function () {
614
146
  if (singleInstance) {
615
147
  var id = this.id;
616
-
617
148
  if (!id) {
618
149
  id = this._getId();
619
150
  }
620
-
621
151
  return {
622
152
  id: id,
623
153
  className: this.className
@@ -630,36 +160,29 @@ var ParseObject = function () {
630
160
  key: "_getServerData",
631
161
  value: function () {
632
162
  var stateController = _CoreManager.default.getObjectStateController();
633
-
634
163
  return stateController.getServerData(this._getStateIdentifier());
635
164
  }
636
165
  }, {
637
166
  key: "_clearServerData",
638
167
  value: function () {
639
168
  var serverData = this._getServerData();
640
-
641
169
  var unset = {};
642
-
643
170
  for (var _attr2 in serverData) {
644
171
  unset[_attr2] = undefined;
645
172
  }
646
-
647
173
  var stateController = _CoreManager.default.getObjectStateController();
648
-
649
174
  stateController.setServerData(this._getStateIdentifier(), unset);
650
175
  }
651
176
  }, {
652
177
  key: "_getPendingOps",
653
178
  value: function () {
654
179
  var stateController = _CoreManager.default.getObjectStateController();
655
-
656
180
  return stateController.getPendingOps(this._getStateIdentifier());
657
181
  }
658
182
  }, {
659
183
  key: "_clearPendingOps",
660
184
  value: function (keysToClear) {
661
185
  var pending = this._getPendingOps();
662
-
663
186
  var latest = pending[pending.length - 1];
664
187
  var keys = keysToClear || Object.keys(latest);
665
188
  keys.forEach(function (key) {
@@ -670,20 +193,15 @@ var ParseObject = function () {
670
193
  key: "_getDirtyObjectAttributes",
671
194
  value: function () {
672
195
  var attributes = this.attributes;
673
-
674
196
  var stateController = _CoreManager.default.getObjectStateController();
675
-
676
197
  var objectCache = stateController.getObjectCache(this._getStateIdentifier());
677
198
  var dirty = {};
678
-
679
199
  for (var _attr3 in attributes) {
680
200
  var val = attributes[_attr3];
681
-
682
201
  if (val && typeof val === 'object' && !(val instanceof ParseObject) && !(val instanceof _ParseFile.default) && !(val instanceof _ParseRelation.default)) {
683
202
  try {
684
203
  var json = (0, _encode.default)(val, false, true);
685
204
  var stringified = JSON.stringify(json);
686
-
687
205
  if (objectCache[_attr3] !== stringified) {
688
206
  dirty[_attr3] = val;
689
207
  }
@@ -692,7 +210,6 @@ var ParseObject = function () {
692
210
  }
693
211
  }
694
212
  }
695
-
696
213
  return dirty;
697
214
  }
698
215
  }, {
@@ -707,19 +224,14 @@ var ParseObject = function () {
707
224
  key: "_getSaveJSON",
708
225
  value: function () {
709
226
  var pending = this._getPendingOps();
710
-
711
227
  var dirtyObjects = this._getDirtyObjectAttributes();
712
-
713
228
  var json = {};
714
-
715
229
  for (var attr in dirtyObjects) {
716
230
  var isDotNotation = false;
717
-
718
231
  for (var i = 0; i < pending.length; i += 1) {
719
232
  for (var field in pending[i]) {
720
233
  if (field.includes('.')) {
721
234
  var fieldName = field.split('.')[0];
722
-
723
235
  if (fieldName === attr) {
724
236
  isDotNotation = true;
725
237
  break;
@@ -727,27 +239,21 @@ var ParseObject = function () {
727
239
  }
728
240
  }
729
241
  }
730
-
731
242
  if (!isDotNotation) {
732
243
  json[attr] = new _ParseOp.SetOp(dirtyObjects[attr]).toJSON();
733
244
  }
734
245
  }
735
-
736
246
  for (attr in pending[0]) {
737
247
  json[attr] = pending[0][attr].toJSON();
738
248
  }
739
-
740
249
  return json;
741
250
  }
742
251
  }, {
743
252
  key: "_getSaveParams",
744
253
  value: function () {
745
254
  var method = this.id ? 'PUT' : 'POST';
746
-
747
255
  var body = this._getSaveJSON();
748
-
749
256
  var path = 'classes/' + this.className;
750
-
751
257
  if (_CoreManager.default.get('ALLOW_CUSTOM_OBJECT_ID')) {
752
258
  if (!this.createdAt) {
753
259
  method = 'POST';
@@ -761,7 +267,6 @@ var ParseObject = function () {
761
267
  } else if (this.className === '_User') {
762
268
  path = 'users';
763
269
  }
764
-
765
270
  return {
766
271
  method: method,
767
272
  body: body,
@@ -774,45 +279,35 @@ var ParseObject = function () {
774
279
  if (!this.id && serverData.objectId) {
775
280
  this.id = serverData.objectId;
776
281
  }
777
-
778
282
  var stateController = _CoreManager.default.getObjectStateController();
779
-
780
283
  stateController.initializeState(this._getStateIdentifier());
781
284
  var decoded = {};
782
-
783
285
  for (var _attr4 in serverData) {
784
286
  if (_attr4 === 'ACL') {
785
287
  decoded[_attr4] = new _ParseACL.default(serverData[_attr4]);
786
288
  } else if (_attr4 !== 'objectId') {
787
289
  decoded[_attr4] = (0, _decode.default)(serverData[_attr4]);
788
-
789
290
  if (decoded[_attr4] instanceof _ParseRelation.default) {
790
291
  decoded[_attr4]._ensureParentAndKey(this, _attr4);
791
292
  }
792
293
  }
793
294
  }
794
-
795
295
  if (decoded.createdAt && typeof decoded.createdAt === 'string') {
796
296
  decoded.createdAt = (0, _parseDate.default)(decoded.createdAt);
797
297
  }
798
-
799
298
  if (decoded.updatedAt && typeof decoded.updatedAt === 'string') {
800
299
  decoded.updatedAt = (0, _parseDate.default)(decoded.updatedAt);
801
300
  }
802
-
803
301
  if (!decoded.updatedAt && decoded.createdAt) {
804
302
  decoded.updatedAt = decoded.createdAt;
805
303
  }
806
-
807
304
  stateController.commitServerChanges(this._getStateIdentifier(), decoded);
808
305
  }
809
306
  }, {
810
307
  key: "_setExisted",
811
308
  value: function (existed) {
812
309
  var stateController = _CoreManager.default.getObjectStateController();
813
-
814
310
  var state = stateController.getState(this._getStateIdentifier());
815
-
816
311
  if (state) {
817
312
  state.existed = existed;
818
313
  }
@@ -823,11 +318,9 @@ var ParseObject = function () {
823
318
  if (this._localId && serverId) {
824
319
  if (singleInstance) {
825
320
  var stateController = _CoreManager.default.getObjectStateController();
826
-
827
321
  var oldState = stateController.removeState(this._getStateIdentifier());
828
322
  this.id = serverId;
829
323
  delete this._localId;
830
-
831
324
  if (oldState) {
832
325
  stateController.initializeState(this._getStateIdentifier(), oldState);
833
326
  }
@@ -841,11 +334,8 @@ var ParseObject = function () {
841
334
  key: "_handleSaveResponse",
842
335
  value: function (response, status) {
843
336
  var changes = {};
844
-
845
337
  var stateController = _CoreManager.default.getObjectStateController();
846
-
847
338
  var pending = stateController.popPendingState(this._getStateIdentifier());
848
-
849
339
  for (var attr in pending) {
850
340
  if (pending[attr] instanceof _ParseOp.RelationOp) {
851
341
  changes[attr] = pending[attr].applyTo(undefined, this, attr);
@@ -853,7 +343,6 @@ var ParseObject = function () {
853
343
  changes[attr] = pending[attr].applyTo(undefined);
854
344
  }
855
345
  }
856
-
857
346
  for (attr in response) {
858
347
  if ((attr === 'createdAt' || attr === 'updatedAt') && typeof response[attr] === 'string') {
859
348
  changes[attr] = (0, _parseDate.default)(response[attr]);
@@ -861,36 +350,29 @@ var ParseObject = function () {
861
350
  changes[attr] = new _ParseACL.default(response[attr]);
862
351
  } else if (attr !== 'objectId') {
863
352
  var val = (0, _decode.default)(response[attr]);
864
-
865
353
  if (val && Object.getPrototypeOf(val) === Object.prototype) {
866
- changes[attr] = _objectSpread(_objectSpread({}, this.attributes[attr]), val);
354
+ changes[attr] = Object.assign({}, this.attributes[attr], val);
867
355
  } else {
868
356
  changes[attr] = val;
869
357
  }
870
-
871
358
  if (changes[attr] instanceof _ParseOp.UnsetOp) {
872
359
  changes[attr] = undefined;
873
360
  }
874
361
  }
875
362
  }
876
-
877
363
  if (changes.createdAt && !changes.updatedAt) {
878
364
  changes.updatedAt = changes.createdAt;
879
365
  }
880
-
881
366
  this._migrateId(response.objectId);
882
-
883
367
  if (status !== 201) {
884
368
  this._setExisted(true);
885
369
  }
886
-
887
370
  stateController.commitServerChanges(this._getStateIdentifier(), changes);
888
371
  }
889
372
  }, {
890
373
  key: "_handleSaveError",
891
374
  value: function () {
892
375
  var stateController = _CoreManager.default.getObjectStateController();
893
-
894
376
  stateController.mergeFirstPendingState(this._getStateIdentifier());
895
377
  }
896
378
  }, {
@@ -903,7 +385,6 @@ var ParseObject = function () {
903
385
  seen = seen || [seenEntry];
904
386
  var json = {};
905
387
  var attrs = this.attributes;
906
-
907
388
  for (var _attr5 in attrs) {
908
389
  if ((_attr5 === 'createdAt' || _attr5 === 'updatedAt') && attrs[_attr5].toJSON) {
909
390
  json[_attr5] = attrs[_attr5].toJSON();
@@ -911,17 +392,13 @@ var ParseObject = function () {
911
392
  json[_attr5] = (0, _encode.default)(attrs[_attr5], false, false, seen, offline);
912
393
  }
913
394
  }
914
-
915
395
  var pending = this._getPendingOps();
916
-
917
396
  for (var _attr6 in pending[0]) {
918
397
  json[_attr6] = pending[0][_attr6].toJSON(offline);
919
398
  }
920
-
921
399
  if (this.id) {
922
400
  json.objectId = this.id;
923
401
  }
924
-
925
402
  return json;
926
403
  }
927
404
  }, {
@@ -930,7 +407,6 @@ var ParseObject = function () {
930
407
  if (this === other) {
931
408
  return true;
932
409
  }
933
-
934
410
  return other instanceof ParseObject && this.className === other.className && this.id === other.id && typeof this.id !== 'undefined';
935
411
  }
936
412
  }, {
@@ -939,61 +415,47 @@ var ParseObject = function () {
939
415
  if (!this.id) {
940
416
  return true;
941
417
  }
942
-
943
418
  var pendingOps = this._getPendingOps();
944
-
945
419
  var dirtyObjects = this._getDirtyObjectAttributes();
946
-
947
420
  if (attr) {
948
421
  if (dirtyObjects.hasOwnProperty(attr)) {
949
422
  return true;
950
423
  }
951
-
952
424
  for (var i = 0; i < pendingOps.length; i++) {
953
425
  if (pendingOps[i].hasOwnProperty(attr)) {
954
426
  return true;
955
427
  }
956
428
  }
957
-
958
429
  return false;
959
430
  }
960
-
961
431
  if (Object.keys(pendingOps[0]).length !== 0) {
962
432
  return true;
963
433
  }
964
-
965
434
  if (Object.keys(dirtyObjects).length !== 0) {
966
435
  return true;
967
436
  }
968
-
969
437
  return false;
970
438
  }
971
439
  }, {
972
440
  key: "dirtyKeys",
973
441
  value: function () {
974
442
  var pendingOps = this._getPendingOps();
975
-
976
443
  var keys = {};
977
-
978
444
  for (var i = 0; i < pendingOps.length; i++) {
979
445
  for (var _attr7 in pendingOps[i]) {
980
446
  keys[_attr7] = true;
981
447
  }
982
448
  }
983
-
984
449
  var dirtyObjects = this._getDirtyObjectAttributes();
985
-
986
450
  for (var _attr8 in dirtyObjects) {
987
451
  keys[_attr8] = true;
988
452
  }
989
-
990
453
  return Object.keys(keys);
991
454
  }
992
455
  }, {
993
456
  key: "isDataAvailable",
994
457
  value: function () {
995
458
  var serverData = this._getServerData();
996
-
997
459
  return !!Object.keys(serverData).length;
998
460
  }
999
461
  }, {
@@ -1002,7 +464,6 @@ var ParseObject = function () {
1002
464
  if (!this.id) {
1003
465
  throw new Error('Cannot create a pointer to an unsaved ParseObject');
1004
466
  }
1005
-
1006
467
  return {
1007
468
  __type: 'Pointer',
1008
469
  className: this.className,
@@ -1015,7 +476,6 @@ var ParseObject = function () {
1015
476
  if (!this._localId) {
1016
477
  throw new Error('Cannot create a offline pointer to a saved ParseObject');
1017
478
  }
1018
-
1019
479
  return {
1020
480
  __type: 'Object',
1021
481
  className: this.className,
@@ -1031,47 +491,37 @@ var ParseObject = function () {
1031
491
  key: "relation",
1032
492
  value: function (attr) {
1033
493
  var value = this.get(attr);
1034
-
1035
494
  if (value) {
1036
495
  if (!(value instanceof _ParseRelation.default)) {
1037
496
  throw new Error('Called relation() on non-relation field ' + attr);
1038
497
  }
1039
-
1040
498
  value._ensureParentAndKey(this, attr);
1041
-
1042
499
  return value;
1043
500
  }
1044
-
1045
501
  return new _ParseRelation.default(this, attr);
1046
502
  }
1047
503
  }, {
1048
504
  key: "escape",
1049
505
  value: function (attr) {
1050
506
  var val = this.attributes[attr];
1051
-
1052
507
  if (val == null) {
1053
508
  return '';
1054
509
  }
1055
-
1056
510
  if (typeof val !== 'string') {
1057
511
  if (typeof val.toString !== 'function') {
1058
512
  return '';
1059
513
  }
1060
-
1061
514
  val = val.toString();
1062
515
  }
1063
-
1064
516
  return (0, _escape2.default)(val);
1065
517
  }
1066
518
  }, {
1067
519
  key: "has",
1068
520
  value: function (attr) {
1069
521
  var attributes = this.attributes;
1070
-
1071
522
  if (attributes.hasOwnProperty(attr)) {
1072
523
  return attributes[attr] != null;
1073
524
  }
1074
-
1075
525
  return false;
1076
526
  }
1077
527
  }, {
@@ -1079,7 +529,6 @@ var ParseObject = function () {
1079
529
  value: function (key, value, options) {
1080
530
  var changes = {};
1081
531
  var newOps = {};
1082
-
1083
532
  if (key && typeof key === 'object') {
1084
533
  changes = key;
1085
534
  options = value;
@@ -1088,23 +537,18 @@ var ParseObject = function () {
1088
537
  } else {
1089
538
  return this;
1090
539
  }
1091
-
1092
540
  options = options || {};
1093
541
  var readonly = [];
1094
-
1095
542
  if (typeof this.constructor.readOnlyAttributes === 'function') {
1096
543
  readonly = readonly.concat(this.constructor.readOnlyAttributes());
1097
544
  }
1098
-
1099
545
  for (var k in changes) {
1100
546
  if (k === 'createdAt' || k === 'updatedAt') {
1101
547
  continue;
1102
548
  }
1103
-
1104
549
  if (readonly.indexOf(k) > -1) {
1105
550
  throw new Error('Cannot modify readonly attribute: ' + k);
1106
551
  }
1107
-
1108
552
  if (options.unset) {
1109
553
  newOps[k] = new _ParseOp.UnsetOp();
1110
554
  } else if (changes[k] instanceof _ParseOp.Op) {
@@ -1125,10 +569,8 @@ var ParseObject = function () {
1125
569
  newOps[k] = new _ParseOp.SetOp(changes[k]);
1126
570
  }
1127
571
  }
1128
-
1129
572
  var currentAttributes = this.attributes;
1130
573
  var newValues = {};
1131
-
1132
574
  for (var _attr9 in newOps) {
1133
575
  if (newOps[_attr9] instanceof _ParseOp.RelationOp) {
1134
576
  newValues[_attr9] = newOps[_attr9].applyTo(currentAttributes[_attr9], this, _attr9);
@@ -1136,31 +578,22 @@ var ParseObject = function () {
1136
578
  newValues[_attr9] = newOps[_attr9].applyTo(currentAttributes[_attr9]);
1137
579
  }
1138
580
  }
1139
-
1140
581
  if (!options.ignoreValidation) {
1141
582
  var validation = this.validate(newValues);
1142
-
1143
583
  if (validation) {
1144
584
  if (typeof options.error === 'function') {
1145
585
  options.error(this, validation);
1146
586
  }
1147
-
1148
587
  return false;
1149
588
  }
1150
589
  }
1151
-
1152
590
  var pendingOps = this._getPendingOps();
1153
-
1154
591
  var last = pendingOps.length - 1;
1155
-
1156
592
  var stateController = _CoreManager.default.getObjectStateController();
1157
-
1158
593
  for (var _attr10 in newOps) {
1159
594
  var nextOp = newOps[_attr10].mergeWith(pendingOps[last][_attr10]);
1160
-
1161
595
  stateController.setPendingOp(this._getStateIdentifier(), _attr10, nextOp);
1162
596
  }
1163
-
1164
597
  return this;
1165
598
  }
1166
599
  }, {
@@ -1176,11 +609,9 @@ var ParseObject = function () {
1176
609
  if (typeof amount === 'undefined') {
1177
610
  amount = 1;
1178
611
  }
1179
-
1180
612
  if (typeof amount !== 'number') {
1181
613
  throw new Error('Cannot increment by a non-numeric amount.');
1182
614
  }
1183
-
1184
615
  return this.set(attr, new _ParseOp.IncrementOp(amount));
1185
616
  }
1186
617
  }, {
@@ -1189,11 +620,9 @@ var ParseObject = function () {
1189
620
  if (typeof amount === 'undefined') {
1190
621
  amount = 1;
1191
622
  }
1192
-
1193
623
  if (typeof amount !== 'number') {
1194
624
  throw new Error('Cannot decrement by a non-numeric amount.');
1195
625
  }
1196
-
1197
626
  return this.set(attr, new _ParseOp.IncrementOp(amount * -1));
1198
627
  }
1199
628
  }, {
@@ -1230,7 +659,6 @@ var ParseObject = function () {
1230
659
  key: "op",
1231
660
  value: function (attr) {
1232
661
  var pending = this._getPendingOps();
1233
-
1234
662
  for (var i = pending.length; i--;) {
1235
663
  if (pending[i][attr]) {
1236
664
  return pending[i][attr];
@@ -1242,24 +670,19 @@ var ParseObject = function () {
1242
670
  value: function clone() {
1243
671
  var clone = new this.constructor(this.className);
1244
672
  var attributes = this.attributes;
1245
-
1246
673
  if (typeof this.constructor.readOnlyAttributes === 'function') {
1247
674
  var readonly = this.constructor.readOnlyAttributes() || [];
1248
675
  var copy = {};
1249
-
1250
676
  for (var a in attributes) {
1251
677
  if (readonly.indexOf(a) < 0) {
1252
678
  copy[a] = attributes[a];
1253
679
  }
1254
680
  }
1255
-
1256
681
  attributes = copy;
1257
682
  }
1258
-
1259
683
  if (clone.set) {
1260
684
  clone.set(attributes);
1261
685
  }
1262
-
1263
686
  return clone;
1264
687
  }
1265
688
  }, {
@@ -1267,17 +690,13 @@ var ParseObject = function () {
1267
690
  value: function () {
1268
691
  var clone = new this.constructor(this.className);
1269
692
  clone.id = this.id;
1270
-
1271
693
  if (singleInstance) {
1272
694
  return clone;
1273
695
  }
1274
-
1275
696
  var stateController = _CoreManager.default.getObjectStateController();
1276
-
1277
697
  if (stateController) {
1278
698
  stateController.duplicateState(this._getStateIdentifier(), clone._getStateIdentifier());
1279
699
  }
1280
-
1281
700
  return clone;
1282
701
  }
1283
702
  }, {
@@ -1291,62 +710,36 @@ var ParseObject = function () {
1291
710
  if (!this.id) {
1292
711
  return false;
1293
712
  }
1294
-
1295
713
  var stateController = _CoreManager.default.getObjectStateController();
1296
-
1297
714
  var state = stateController.getState(this._getStateIdentifier());
1298
-
1299
715
  if (state) {
1300
716
  return state.existed;
1301
717
  }
1302
-
1303
718
  return false;
1304
719
  }
1305
720
  }, {
1306
721
  key: "exists",
1307
- value: function (options) {
1308
- var query;
1309
- return _regeneratorRuntime().async(function (_context) {
1310
- while (1) {
1311
- switch (_context.prev = _context.next) {
1312
- case 0:
1313
- if (this.id) {
1314
- _context.next = 2;
1315
- break;
1316
- }
1317
-
1318
- return _context.abrupt("return", false);
1319
-
1320
- case 2:
1321
- _context.prev = 2;
1322
- query = new _ParseQuery.default(this.className);
1323
- _context.next = 6;
1324
- return _regeneratorRuntime().awrap(query.get(this.id, options));
1325
-
1326
- case 6:
1327
- return _context.abrupt("return", true);
1328
-
1329
- case 9:
1330
- _context.prev = 9;
1331
- _context.t0 = _context["catch"](2);
1332
-
1333
- if (!(_context.t0.code === _ParseError.default.OBJECT_NOT_FOUND)) {
1334
- _context.next = 13;
1335
- break;
1336
- }
1337
-
1338
- return _context.abrupt("return", false);
1339
-
1340
- case 13:
1341
- throw _context.t0;
1342
-
1343
- case 14:
1344
- case "end":
1345
- return _context.stop();
722
+ value: function () {
723
+ var _exists = (0, _asyncToGenerator2.default)(function* (options) {
724
+ if (!this.id) {
725
+ return false;
726
+ }
727
+ try {
728
+ var query = new _ParseQuery.default(this.className);
729
+ yield query.get(this.id, options);
730
+ return true;
731
+ } catch (e) {
732
+ if (e.code === _ParseError.default.OBJECT_NOT_FOUND) {
733
+ return false;
1346
734
  }
735
+ throw e;
1347
736
  }
1348
- }, null, this, [[2, 9]], Promise);
1349
- }
737
+ });
738
+ function exists() {
739
+ return _exists.apply(this, arguments);
740
+ }
741
+ return exists;
742
+ }()
1350
743
  }, {
1351
744
  key: "isValid",
1352
745
  value: function () {
@@ -1358,24 +751,20 @@ var ParseObject = function () {
1358
751
  if (attrs.hasOwnProperty('ACL') && !(attrs.ACL instanceof _ParseACL.default)) {
1359
752
  return new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'ACL must be a Parse ACL.');
1360
753
  }
1361
-
1362
754
  for (var _key in attrs) {
1363
755
  if (!/^[A-Za-z][0-9A-Za-z_.]*$/.test(_key)) {
1364
756
  return new _ParseError.default(_ParseError.default.INVALID_KEY_NAME);
1365
757
  }
1366
758
  }
1367
-
1368
759
  return false;
1369
760
  }
1370
761
  }, {
1371
762
  key: "getACL",
1372
763
  value: function () {
1373
764
  var acl = this.get('ACL');
1374
-
1375
765
  if (acl instanceof _ParseACL.default) {
1376
766
  return acl;
1377
767
  }
1378
-
1379
768
  return null;
1380
769
  }
1381
770
  }, {
@@ -1387,17 +776,12 @@ var ParseObject = function () {
1387
776
  key: "revert",
1388
777
  value: function () {
1389
778
  var keysToRevert;
1390
-
1391
779
  for (var _len = arguments.length, keys = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
1392
780
  keys[_key2] = arguments[_key2];
1393
781
  }
1394
-
1395
782
  if (keys.length) {
1396
783
  keysToRevert = [];
1397
-
1398
- for (var _iterator = _createForOfIteratorHelperLoose(keys), _step; !(_step = _iterator()).done;) {
1399
- var _key3 = _step.value;
1400
-
784
+ for (var _key3 of keys) {
1401
785
  if (typeof _key3 === 'string') {
1402
786
  keysToRevert.push(_key3);
1403
787
  } else {
@@ -1405,7 +789,6 @@ var ParseObject = function () {
1405
789
  }
1406
790
  }
1407
791
  }
1408
-
1409
792
  this._clearPendingOps(keysToRevert);
1410
793
  }
1411
794
  }, {
@@ -1414,17 +797,14 @@ var ParseObject = function () {
1414
797
  var attributes = this.attributes;
1415
798
  var erasable = {};
1416
799
  var readonly = ['createdAt', 'updatedAt'];
1417
-
1418
800
  if (typeof this.constructor.readOnlyAttributes === 'function') {
1419
801
  readonly = readonly.concat(this.constructor.readOnlyAttributes());
1420
802
  }
1421
-
1422
803
  for (var _attr11 in attributes) {
1423
804
  if (readonly.indexOf(_attr11) < 0) {
1424
805
  erasable[_attr11] = true;
1425
806
  }
1426
807
  }
1427
-
1428
808
  return this.set(erasable, {
1429
809
  unset: true
1430
810
  });
@@ -1434,22 +814,17 @@ var ParseObject = function () {
1434
814
  value: function (options) {
1435
815
  options = options || {};
1436
816
  var fetchOptions = {};
1437
-
1438
817
  if (options.hasOwnProperty('useMasterKey')) {
1439
818
  fetchOptions.useMasterKey = options.useMasterKey;
1440
819
  }
1441
-
1442
820
  if (options.hasOwnProperty('sessionToken')) {
1443
821
  fetchOptions.sessionToken = options.sessionToken;
1444
822
  }
1445
-
1446
823
  if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1447
824
  fetchOptions.context = options.context;
1448
825
  }
1449
-
1450
826
  if (options.hasOwnProperty('include')) {
1451
827
  fetchOptions.include = [];
1452
-
1453
828
  if (Array.isArray(options.include)) {
1454
829
  options.include.forEach(function (key) {
1455
830
  if (Array.isArray(key)) {
@@ -1462,9 +837,7 @@ var ParseObject = function () {
1462
837
  fetchOptions.include.push(options.include);
1463
838
  }
1464
839
  }
1465
-
1466
840
  var controller = _CoreManager.default.getObjectController();
1467
-
1468
841
  return controller.fetch(this, true, fetchOptions);
1469
842
  }
1470
843
  }, {
@@ -1476,55 +849,31 @@ var ParseObject = function () {
1476
849
  }
1477
850
  }, {
1478
851
  key: "saveEventually",
1479
- value: function (options) {
1480
- return _regeneratorRuntime().async(function (_context2) {
1481
- while (1) {
1482
- switch (_context2.prev = _context2.next) {
1483
- case 0:
1484
- _context2.prev = 0;
1485
- _context2.next = 3;
1486
- return _regeneratorRuntime().awrap(this.save(null, options));
1487
-
1488
- case 3:
1489
- _context2.next = 11;
1490
- break;
1491
-
1492
- case 5:
1493
- _context2.prev = 5;
1494
- _context2.t0 = _context2["catch"](0);
1495
-
1496
- if (!(_context2.t0.message === 'XMLHttpRequest failed: "Unable to connect to the Parse API"')) {
1497
- _context2.next = 11;
1498
- break;
1499
- }
1500
-
1501
- _context2.next = 10;
1502
- return _regeneratorRuntime().awrap(_EventuallyQueue.default.save(this, options));
1503
-
1504
- case 10:
1505
- _EventuallyQueue.default.poll();
1506
-
1507
- case 11:
1508
- return _context2.abrupt("return", this);
1509
-
1510
- case 12:
1511
- case "end":
1512
- return _context2.stop();
852
+ value: function () {
853
+ var _saveEventually = (0, _asyncToGenerator2.default)(function* (options) {
854
+ try {
855
+ yield this.save(null, options);
856
+ } catch (e) {
857
+ if (e.message === 'XMLHttpRequest failed: "Unable to connect to the Parse API"') {
858
+ yield _EventuallyQueue.default.save(this, options);
859
+ _EventuallyQueue.default.poll();
1513
860
  }
1514
861
  }
1515
- }, null, this, [[0, 5]], Promise);
1516
- }
862
+ return this;
863
+ });
864
+ function saveEventually() {
865
+ return _saveEventually.apply(this, arguments);
866
+ }
867
+ return saveEventually;
868
+ }()
1517
869
  }, {
1518
870
  key: "save",
1519
871
  value: function (arg1, arg2, arg3) {
1520
872
  var _this = this;
1521
-
1522
873
  var attrs;
1523
874
  var options;
1524
-
1525
875
  if (typeof arg1 === 'object' || typeof arg1 === 'undefined') {
1526
876
  attrs = arg1;
1527
-
1528
877
  if (typeof arg2 === 'object') {
1529
878
  options = arg2;
1530
879
  }
@@ -1533,38 +882,28 @@ var ParseObject = function () {
1533
882
  attrs[arg1] = arg2;
1534
883
  options = arg3;
1535
884
  }
1536
-
1537
885
  if (attrs) {
1538
886
  var validation = this.validate(attrs);
1539
-
1540
887
  if (validation) {
1541
888
  return Promise.reject(validation);
1542
889
  }
1543
-
1544
890
  this.set(attrs, options);
1545
891
  }
1546
-
1547
892
  options = options || {};
1548
893
  var saveOptions = {};
1549
-
1550
894
  if (options.hasOwnProperty('useMasterKey')) {
1551
895
  saveOptions.useMasterKey = !!options.useMasterKey;
1552
896
  }
1553
-
1554
897
  if (options.hasOwnProperty('sessionToken') && typeof options.sessionToken === 'string') {
1555
898
  saveOptions.sessionToken = options.sessionToken;
1556
899
  }
1557
-
1558
900
  if (options.hasOwnProperty('installationId') && typeof options.installationId === 'string') {
1559
901
  saveOptions.installationId = options.installationId;
1560
902
  }
1561
-
1562
903
  if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1563
904
  saveOptions.context = options.context;
1564
905
  }
1565
-
1566
906
  var controller = _CoreManager.default.getObjectController();
1567
-
1568
907
  var unsaved = options.cascadeSave !== false ? (0, _unsavedChildren.default)(this) : null;
1569
908
  return controller.save(unsaved, saveOptions).then(function () {
1570
909
  return controller.save(_this, saveOptions);
@@ -1572,66 +911,40 @@ var ParseObject = function () {
1572
911
  }
1573
912
  }, {
1574
913
  key: "destroyEventually",
1575
- value: function (options) {
1576
- return _regeneratorRuntime().async(function (_context3) {
1577
- while (1) {
1578
- switch (_context3.prev = _context3.next) {
1579
- case 0:
1580
- _context3.prev = 0;
1581
- _context3.next = 3;
1582
- return _regeneratorRuntime().awrap(this.destroy(options));
1583
-
1584
- case 3:
1585
- _context3.next = 11;
1586
- break;
1587
-
1588
- case 5:
1589
- _context3.prev = 5;
1590
- _context3.t0 = _context3["catch"](0);
1591
-
1592
- if (!(_context3.t0.message === 'XMLHttpRequest failed: "Unable to connect to the Parse API"')) {
1593
- _context3.next = 11;
1594
- break;
1595
- }
1596
-
1597
- _context3.next = 10;
1598
- return _regeneratorRuntime().awrap(_EventuallyQueue.default.destroy(this, options));
1599
-
1600
- case 10:
1601
- _EventuallyQueue.default.poll();
1602
-
1603
- case 11:
1604
- return _context3.abrupt("return", this);
1605
-
1606
- case 12:
1607
- case "end":
1608
- return _context3.stop();
914
+ value: function () {
915
+ var _destroyEventually = (0, _asyncToGenerator2.default)(function* (options) {
916
+ try {
917
+ yield this.destroy(options);
918
+ } catch (e) {
919
+ if (e.message === 'XMLHttpRequest failed: "Unable to connect to the Parse API"') {
920
+ yield _EventuallyQueue.default.destroy(this, options);
921
+ _EventuallyQueue.default.poll();
1609
922
  }
1610
923
  }
1611
- }, null, this, [[0, 5]], Promise);
1612
- }
924
+ return this;
925
+ });
926
+ function destroyEventually() {
927
+ return _destroyEventually.apply(this, arguments);
928
+ }
929
+ return destroyEventually;
930
+ }()
1613
931
  }, {
1614
932
  key: "destroy",
1615
933
  value: function (options) {
1616
934
  options = options || {};
1617
935
  var destroyOptions = {};
1618
-
1619
936
  if (options.hasOwnProperty('useMasterKey')) {
1620
937
  destroyOptions.useMasterKey = options.useMasterKey;
1621
938
  }
1622
-
1623
939
  if (options.hasOwnProperty('sessionToken')) {
1624
940
  destroyOptions.sessionToken = options.sessionToken;
1625
941
  }
1626
-
1627
942
  if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1628
943
  destroyOptions.context = options.context;
1629
944
  }
1630
-
1631
945
  if (!this.id) {
1632
946
  return Promise.resolve();
1633
947
  }
1634
-
1635
948
  return _CoreManager.default.getObjectController().destroy(this, destroyOptions);
1636
949
  }
1637
950
  }, {
@@ -1647,36 +960,20 @@ var ParseObject = function () {
1647
960
  }, {
1648
961
  key: "isPinned",
1649
962
  value: function () {
1650
- var localDatastore, objectKey, pin;
1651
- return _regeneratorRuntime().async(function (_context4) {
1652
- while (1) {
1653
- switch (_context4.prev = _context4.next) {
1654
- case 0:
1655
- localDatastore = _CoreManager.default.getLocalDatastore();
1656
-
1657
- if (localDatastore.isEnabled) {
1658
- _context4.next = 3;
1659
- break;
1660
- }
1661
-
1662
- return _context4.abrupt("return", Promise.reject('Parse.enableLocalDatastore() must be called first'));
1663
-
1664
- case 3:
1665
- objectKey = localDatastore.getKeyForObject(this);
1666
- _context4.next = 6;
1667
- return _regeneratorRuntime().awrap(localDatastore.fromPinWithName(objectKey));
1668
-
1669
- case 6:
1670
- pin = _context4.sent;
1671
- return _context4.abrupt("return", pin.length > 0);
1672
-
1673
- case 8:
1674
- case "end":
1675
- return _context4.stop();
1676
- }
963
+ var _isPinned = (0, _asyncToGenerator2.default)(function* () {
964
+ var localDatastore = _CoreManager.default.getLocalDatastore();
965
+ if (!localDatastore.isEnabled) {
966
+ return Promise.reject('Parse.enableLocalDatastore() must be called first');
1677
967
  }
1678
- }, null, this, null, Promise);
1679
- }
968
+ var objectKey = localDatastore.getKeyForObject(this);
969
+ var pin = yield localDatastore.fromPinWithName(objectKey);
970
+ return pin.length > 0;
971
+ });
972
+ function isPinned() {
973
+ return _isPinned.apply(this, arguments);
974
+ }
975
+ return isPinned;
976
+ }()
1680
977
  }, {
1681
978
  key: "pinWithName",
1682
979
  value: function (name) {
@@ -1690,49 +987,25 @@ var ParseObject = function () {
1690
987
  }, {
1691
988
  key: "fetchFromLocalDatastore",
1692
989
  value: function () {
1693
- var localDatastore, objectKey, pinned, result;
1694
- return _regeneratorRuntime().async(function (_context5) {
1695
- while (1) {
1696
- switch (_context5.prev = _context5.next) {
1697
- case 0:
1698
- localDatastore = _CoreManager.default.getLocalDatastore();
1699
-
1700
- if (localDatastore.isEnabled) {
1701
- _context5.next = 3;
1702
- break;
1703
- }
1704
-
1705
- throw new Error('Parse.enableLocalDatastore() must be called first');
1706
-
1707
- case 3:
1708
- objectKey = localDatastore.getKeyForObject(this);
1709
- _context5.next = 6;
1710
- return _regeneratorRuntime().awrap(localDatastore._serializeObject(objectKey));
1711
-
1712
- case 6:
1713
- pinned = _context5.sent;
1714
-
1715
- if (pinned) {
1716
- _context5.next = 9;
1717
- break;
1718
- }
1719
-
1720
- throw new Error('Cannot fetch an unsaved ParseObject');
1721
-
1722
- case 9:
1723
- result = ParseObject.fromJSON(pinned);
1724
-
1725
- this._finishFetch(result.toJSON());
1726
-
1727
- return _context5.abrupt("return", this);
1728
-
1729
- case 12:
1730
- case "end":
1731
- return _context5.stop();
1732
- }
990
+ var _fetchFromLocalDatastore = (0, _asyncToGenerator2.default)(function* () {
991
+ var localDatastore = _CoreManager.default.getLocalDatastore();
992
+ if (!localDatastore.isEnabled) {
993
+ throw new Error('Parse.enableLocalDatastore() must be called first');
1733
994
  }
1734
- }, null, this, null, Promise);
1735
- }
995
+ var objectKey = localDatastore.getKeyForObject(this);
996
+ var pinned = yield localDatastore._serializeObject(objectKey);
997
+ if (!pinned) {
998
+ throw new Error('Cannot fetch an unsaved ParseObject');
999
+ }
1000
+ var result = ParseObject.fromJSON(pinned);
1001
+ this._finishFetch(result.toJSON());
1002
+ return this;
1003
+ });
1004
+ function fetchFromLocalDatastore() {
1005
+ return _fetchFromLocalDatastore.apply(this, arguments);
1006
+ }
1007
+ return fetchFromLocalDatastore;
1008
+ }()
1736
1009
  }], [{
1737
1010
  key: "_getClassMap",
1738
1011
  value: function () {
@@ -1742,7 +1015,6 @@ var ParseObject = function () {
1742
1015
  key: "_clearAllState",
1743
1016
  value: function () {
1744
1017
  var stateController = _CoreManager.default.getObjectStateController();
1745
-
1746
1018
  stateController.clearAllState();
1747
1019
  }
1748
1020
  }, {
@@ -1750,19 +1022,15 @@ var ParseObject = function () {
1750
1022
  value: function (list) {
1751
1023
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1752
1024
  var queryOptions = {};
1753
-
1754
1025
  if (options.hasOwnProperty('useMasterKey')) {
1755
1026
  queryOptions.useMasterKey = options.useMasterKey;
1756
1027
  }
1757
-
1758
1028
  if (options.hasOwnProperty('sessionToken')) {
1759
1029
  queryOptions.sessionToken = options.sessionToken;
1760
1030
  }
1761
-
1762
1031
  if (options.hasOwnProperty('include')) {
1763
1032
  queryOptions.include = ParseObject.handleIncludeOptions(options);
1764
1033
  }
1765
-
1766
1034
  return _CoreManager.default.getObjectController().fetch(list, true, queryOptions);
1767
1035
  }
1768
1036
  }, {
@@ -1784,26 +1052,21 @@ var ParseObject = function () {
1784
1052
  value: function (list, options) {
1785
1053
  options = options || {};
1786
1054
  var queryOptions = {};
1787
-
1788
1055
  if (options.hasOwnProperty('useMasterKey')) {
1789
1056
  queryOptions.useMasterKey = options.useMasterKey;
1790
1057
  }
1791
-
1792
1058
  if (options.hasOwnProperty('sessionToken')) {
1793
1059
  queryOptions.sessionToken = options.sessionToken;
1794
1060
  }
1795
-
1796
1061
  if (options.hasOwnProperty('include')) {
1797
1062
  queryOptions.include = ParseObject.handleIncludeOptions(options);
1798
1063
  }
1799
-
1800
1064
  return _CoreManager.default.getObjectController().fetch(list, false, queryOptions);
1801
1065
  }
1802
1066
  }, {
1803
1067
  key: "handleIncludeOptions",
1804
1068
  value: function (options) {
1805
1069
  var include = [];
1806
-
1807
1070
  if (Array.isArray(options.include)) {
1808
1071
  options.include.forEach(function (key) {
1809
1072
  if (Array.isArray(key)) {
@@ -1815,7 +1078,6 @@ var ParseObject = function () {
1815
1078
  } else {
1816
1079
  include.push(options.include);
1817
1080
  }
1818
-
1819
1081
  return include;
1820
1082
  }
1821
1083
  }, {
@@ -1823,23 +1085,18 @@ var ParseObject = function () {
1823
1085
  value: function (list) {
1824
1086
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1825
1087
  var destroyOptions = {};
1826
-
1827
1088
  if (options.hasOwnProperty('useMasterKey')) {
1828
1089
  destroyOptions.useMasterKey = options.useMasterKey;
1829
1090
  }
1830
-
1831
1091
  if (options.hasOwnProperty('sessionToken')) {
1832
1092
  destroyOptions.sessionToken = options.sessionToken;
1833
1093
  }
1834
-
1835
1094
  if (options.hasOwnProperty('batchSize') && typeof options.batchSize === 'number') {
1836
1095
  destroyOptions.batchSize = options.batchSize;
1837
1096
  }
1838
-
1839
1097
  if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1840
1098
  destroyOptions.context = options.context;
1841
1099
  }
1842
-
1843
1100
  return _CoreManager.default.getObjectController().destroy(list, destroyOptions);
1844
1101
  }
1845
1102
  }, {
@@ -1847,23 +1104,18 @@ var ParseObject = function () {
1847
1104
  value: function (list) {
1848
1105
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1849
1106
  var saveOptions = {};
1850
-
1851
1107
  if (options.hasOwnProperty('useMasterKey')) {
1852
1108
  saveOptions.useMasterKey = options.useMasterKey;
1853
1109
  }
1854
-
1855
1110
  if (options.hasOwnProperty('sessionToken')) {
1856
1111
  saveOptions.sessionToken = options.sessionToken;
1857
1112
  }
1858
-
1859
1113
  if (options.hasOwnProperty('batchSize') && typeof options.batchSize === 'number') {
1860
1114
  saveOptions.batchSize = options.batchSize;
1861
1115
  }
1862
-
1863
1116
  if (options.hasOwnProperty('context') && typeof options.context === 'object') {
1864
1117
  saveOptions.context = options.context;
1865
1118
  }
1866
-
1867
1119
  return _CoreManager.default.getObjectController().save(list, saveOptions);
1868
1120
  }
1869
1121
  }, {
@@ -1879,45 +1131,34 @@ var ParseObject = function () {
1879
1131
  if (!json.className) {
1880
1132
  throw new Error('Cannot create an object without a className');
1881
1133
  }
1882
-
1883
1134
  var constructor = classMap[json.className];
1884
1135
  var o = constructor ? new constructor(json.className) : new ParseObject(json.className);
1885
1136
  var otherAttributes = {};
1886
-
1887
1137
  for (var _attr12 in json) {
1888
1138
  if (_attr12 !== 'className' && _attr12 !== '__type') {
1889
1139
  otherAttributes[_attr12] = json[_attr12];
1890
-
1891
1140
  if (dirty) {
1892
1141
  o.set(_attr12, json[_attr12]);
1893
1142
  }
1894
1143
  }
1895
1144
  }
1896
-
1897
1145
  if (override) {
1898
1146
  if (otherAttributes.objectId) {
1899
1147
  o.id = otherAttributes.objectId;
1900
1148
  }
1901
-
1902
1149
  var preserved = null;
1903
-
1904
1150
  if (typeof o._preserveFieldsOnFetch === 'function') {
1905
1151
  preserved = o._preserveFieldsOnFetch();
1906
1152
  }
1907
-
1908
1153
  o._clearServerData();
1909
-
1910
1154
  if (preserved) {
1911
1155
  o._finishFetch(preserved);
1912
1156
  }
1913
1157
  }
1914
-
1915
1158
  o._finishFetch(otherAttributes);
1916
-
1917
1159
  if (json.objectId) {
1918
1160
  o._setExisted(true);
1919
1161
  }
1920
-
1921
1162
  return o;
1922
1163
  }
1923
1164
  }, {
@@ -1926,17 +1167,13 @@ var ParseObject = function () {
1926
1167
  if (typeof className !== 'string') {
1927
1168
  throw new TypeError('The first argument must be a valid class name.');
1928
1169
  }
1929
-
1930
1170
  if (typeof constructor === 'undefined') {
1931
1171
  throw new TypeError('You must supply a subclass constructor.');
1932
1172
  }
1933
-
1934
1173
  if (typeof constructor !== 'function') {
1935
1174
  throw new TypeError('You must register the subclass constructor. ' + 'Did you attempt to register an instance of the subclass?');
1936
1175
  }
1937
-
1938
1176
  classMap[className] = constructor;
1939
-
1940
1177
  if (!constructor.className) {
1941
1178
  constructor.className = className;
1942
1179
  }
@@ -1947,7 +1184,6 @@ var ParseObject = function () {
1947
1184
  if (typeof className !== 'string') {
1948
1185
  throw new TypeError('The first argument must be a valid class name.');
1949
1186
  }
1950
-
1951
1187
  delete classMap[className];
1952
1188
  }
1953
1189
  }, {
@@ -1960,49 +1196,63 @@ var ParseObject = function () {
1960
1196
  throw new Error("Parse.Object.extend's first argument should be the className.");
1961
1197
  }
1962
1198
  }
1963
-
1964
1199
  var adjustedClassName = className;
1965
-
1966
1200
  if (adjustedClassName === 'User' && _CoreManager.default.get('PERFORM_USER_REWRITE')) {
1967
1201
  adjustedClassName = '_User';
1968
1202
  }
1969
-
1970
1203
  var parentProto = ParseObject.prototype;
1971
-
1972
1204
  if (this.hasOwnProperty('__super__') && this.__super__) {
1973
1205
  parentProto = this.prototype;
1974
- } else if (classMap[adjustedClassName]) {
1975
- parentProto = classMap[adjustedClassName].prototype;
1976
1206
  }
1977
-
1978
1207
  var ParseObjectSubclass = function (attributes, options) {
1979
1208
  this.className = adjustedClassName;
1980
1209
  this._objCount = objectCount++;
1981
-
1982
1210
  if (typeof this.initialize === 'function') {
1983
1211
  this.initialize.apply(this, arguments);
1984
1212
  }
1985
-
1213
+ if (this._initializers) {
1214
+ for (var initializer of this._initializers) {
1215
+ initializer.apply(this, arguments);
1216
+ }
1217
+ }
1986
1218
  if (attributes && typeof attributes === 'object') {
1987
1219
  if (!this.set(attributes || {}, options)) {
1988
1220
  throw new Error("Can't create an invalid Parse Object");
1989
1221
  }
1990
1222
  }
1991
1223
  };
1992
-
1993
- ParseObjectSubclass.className = adjustedClassName;
1994
- ParseObjectSubclass.__super__ = parentProto;
1995
- ParseObjectSubclass.prototype = Object.create(parentProto, {
1996
- constructor: {
1997
- value: ParseObjectSubclass,
1998
- enumerable: false,
1999
- writable: true,
2000
- configurable: true
2001
- }
2002
- });
2003
-
1224
+ if (classMap[adjustedClassName]) {
1225
+ ParseObjectSubclass = classMap[adjustedClassName];
1226
+ } else {
1227
+ ParseObjectSubclass.extend = function (name, protoProps, classProps) {
1228
+ if (typeof name === 'string') {
1229
+ return ParseObject.extend.call(ParseObjectSubclass, name, protoProps, classProps);
1230
+ }
1231
+ return ParseObject.extend.call(ParseObjectSubclass, adjustedClassName, name, protoProps);
1232
+ };
1233
+ ParseObjectSubclass.createWithoutData = ParseObject.createWithoutData;
1234
+ ParseObjectSubclass.className = adjustedClassName;
1235
+ ParseObjectSubclass.__super__ = parentProto;
1236
+ ParseObjectSubclass.prototype = Object.create(parentProto, {
1237
+ constructor: {
1238
+ value: ParseObjectSubclass,
1239
+ enumerable: false,
1240
+ writable: true,
1241
+ configurable: true
1242
+ }
1243
+ });
1244
+ }
2004
1245
  if (protoProps) {
2005
1246
  for (var prop in protoProps) {
1247
+ if (prop === 'initialize') {
1248
+ Object.defineProperty(ParseObjectSubclass.prototype, '_initializers', {
1249
+ value: [].concat((0, _toConsumableArray2.default)(ParseObjectSubclass.prototype._initializers || []), [protoProps[prop]]),
1250
+ enumerable: false,
1251
+ writable: true,
1252
+ configurable: true
1253
+ });
1254
+ continue;
1255
+ }
2006
1256
  if (prop !== 'className') {
2007
1257
  Object.defineProperty(ParseObjectSubclass.prototype, prop, {
2008
1258
  value: protoProps[prop],
@@ -2013,7 +1263,6 @@ var ParseObject = function () {
2013
1263
  }
2014
1264
  }
2015
1265
  }
2016
-
2017
1266
  if (classProps) {
2018
1267
  for (var _prop in classProps) {
2019
1268
  if (_prop !== 'className') {
@@ -2026,16 +1275,6 @@ var ParseObject = function () {
2026
1275
  }
2027
1276
  }
2028
1277
  }
2029
-
2030
- ParseObjectSubclass.extend = function (name, protoProps, classProps) {
2031
- if (typeof name === 'string') {
2032
- return ParseObject.extend.call(ParseObjectSubclass, name, protoProps, classProps);
2033
- }
2034
-
2035
- return ParseObject.extend.call(ParseObjectSubclass, adjustedClassName, name, protoProps);
2036
- };
2037
-
2038
- ParseObjectSubclass.createWithoutData = ParseObject.createWithoutData;
2039
1278
  classMap[adjustedClassName] = ParseObjectSubclass;
2040
1279
  return ParseObjectSubclass;
2041
1280
  }
@@ -2043,95 +1282,78 @@ var ParseObject = function () {
2043
1282
  key: "enableSingleInstance",
2044
1283
  value: function () {
2045
1284
  singleInstance = true;
2046
-
2047
1285
  _CoreManager.default.setObjectStateController(SingleInstanceStateController);
2048
1286
  }
2049
1287
  }, {
2050
1288
  key: "disableSingleInstance",
2051
1289
  value: function () {
2052
1290
  singleInstance = false;
2053
-
2054
1291
  _CoreManager.default.setObjectStateController(UniqueInstanceStateController);
2055
1292
  }
2056
1293
  }, {
2057
1294
  key: "pinAll",
2058
1295
  value: function (objects) {
2059
1296
  var localDatastore = _CoreManager.default.getLocalDatastore();
2060
-
2061
1297
  if (!localDatastore.isEnabled) {
2062
1298
  return Promise.reject('Parse.enableLocalDatastore() must be called first');
2063
1299
  }
2064
-
2065
1300
  return ParseObject.pinAllWithName(_LocalDatastoreUtils.DEFAULT_PIN, objects);
2066
1301
  }
2067
1302
  }, {
2068
1303
  key: "pinAllWithName",
2069
1304
  value: function (name, objects) {
2070
1305
  var localDatastore = _CoreManager.default.getLocalDatastore();
2071
-
2072
1306
  if (!localDatastore.isEnabled) {
2073
1307
  return Promise.reject('Parse.enableLocalDatastore() must be called first');
2074
1308
  }
2075
-
2076
1309
  return localDatastore._handlePinAllWithName(name, objects);
2077
1310
  }
2078
1311
  }, {
2079
1312
  key: "unPinAll",
2080
1313
  value: function (objects) {
2081
1314
  var localDatastore = _CoreManager.default.getLocalDatastore();
2082
-
2083
1315
  if (!localDatastore.isEnabled) {
2084
1316
  return Promise.reject('Parse.enableLocalDatastore() must be called first');
2085
1317
  }
2086
-
2087
1318
  return ParseObject.unPinAllWithName(_LocalDatastoreUtils.DEFAULT_PIN, objects);
2088
1319
  }
2089
1320
  }, {
2090
1321
  key: "unPinAllWithName",
2091
1322
  value: function (name, objects) {
2092
1323
  var localDatastore = _CoreManager.default.getLocalDatastore();
2093
-
2094
1324
  if (!localDatastore.isEnabled) {
2095
1325
  return Promise.reject('Parse.enableLocalDatastore() must be called first');
2096
1326
  }
2097
-
2098
1327
  return localDatastore._handleUnPinAllWithName(name, objects);
2099
1328
  }
2100
1329
  }, {
2101
1330
  key: "unPinAllObjects",
2102
1331
  value: function () {
2103
1332
  var localDatastore = _CoreManager.default.getLocalDatastore();
2104
-
2105
1333
  if (!localDatastore.isEnabled) {
2106
1334
  return Promise.reject('Parse.enableLocalDatastore() must be called first');
2107
1335
  }
2108
-
2109
1336
  return localDatastore.unPinWithName(_LocalDatastoreUtils.DEFAULT_PIN);
2110
1337
  }
2111
1338
  }, {
2112
1339
  key: "unPinAllObjectsWithName",
2113
1340
  value: function (name) {
2114
1341
  var localDatastore = _CoreManager.default.getLocalDatastore();
2115
-
2116
1342
  if (!localDatastore.isEnabled) {
2117
1343
  return Promise.reject('Parse.enableLocalDatastore() must be called first');
2118
1344
  }
2119
-
2120
1345
  return localDatastore.unPinWithName(_LocalDatastoreUtils.PIN_PREFIX + name);
2121
1346
  }
2122
1347
  }]);
2123
1348
  return ParseObject;
2124
1349
  }();
2125
-
2126
1350
  var DefaultController = {
2127
1351
  fetch: function (target, forceFetch, options) {
2128
1352
  var localDatastore = _CoreManager.default.getLocalDatastore();
2129
-
2130
1353
  if (Array.isArray(target)) {
2131
1354
  if (target.length < 1) {
2132
1355
  return Promise.resolve([]);
2133
1356
  }
2134
-
2135
1357
  var objs = [];
2136
1358
  var ids = [];
2137
1359
  var className = null;
@@ -2141,330 +1363,175 @@ var DefaultController = {
2141
1363
  if (error) {
2142
1364
  return;
2143
1365
  }
2144
-
2145
1366
  if (!className) {
2146
1367
  className = el.className;
2147
1368
  }
2148
-
2149
1369
  if (className !== el.className) {
2150
1370
  error = new _ParseError.default(_ParseError.default.INVALID_CLASS_NAME, 'All objects should be of the same class');
2151
1371
  }
2152
-
2153
1372
  if (!el.id) {
2154
1373
  error = new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'All objects must have an ID');
2155
1374
  }
2156
-
2157
1375
  if (forceFetch || !el.isDataAvailable()) {
2158
1376
  ids.push(el.id);
2159
1377
  objs.push(el);
2160
1378
  }
2161
-
2162
1379
  results.push(el);
2163
1380
  });
2164
-
2165
1381
  if (error) {
2166
1382
  return Promise.reject(error);
2167
1383
  }
2168
-
2169
1384
  var query = new _ParseQuery.default(className);
2170
1385
  query.containedIn('objectId', ids);
2171
-
2172
1386
  if (options && options.include) {
2173
1387
  query.include(options.include);
2174
1388
  }
2175
-
2176
1389
  query._limit = ids.length;
2177
- return query.find(options).then(function (objects) {
2178
- var idMap, i, obj, _i, _obj, id, _iterator2, _step2, object;
2179
-
2180
- return _regeneratorRuntime().async(function (_context6) {
2181
- while (1) {
2182
- switch (_context6.prev = _context6.next) {
2183
- case 0:
2184
- idMap = {};
2185
- objects.forEach(function (o) {
2186
- idMap[o.id] = o;
2187
- });
2188
- i = 0;
2189
-
2190
- case 3:
2191
- if (!(i < objs.length)) {
2192
- _context6.next = 11;
2193
- break;
2194
- }
2195
-
2196
- obj = objs[i];
2197
-
2198
- if (!(!obj || !obj.id || !idMap[obj.id])) {
2199
- _context6.next = 8;
2200
- break;
2201
- }
2202
-
2203
- if (!forceFetch) {
2204
- _context6.next = 8;
2205
- break;
2206
- }
2207
-
2208
- return _context6.abrupt("return", Promise.reject(new _ParseError.default(_ParseError.default.OBJECT_NOT_FOUND, 'All objects must exist on the server.')));
2209
-
2210
- case 8:
2211
- i++;
2212
- _context6.next = 3;
2213
- break;
2214
-
2215
- case 11:
2216
- if (!singleInstance) {
2217
- for (_i = 0; _i < results.length; _i++) {
2218
- _obj = results[_i];
2219
-
2220
- if (_obj && _obj.id && idMap[_obj.id]) {
2221
- id = _obj.id;
2222
-
2223
- _obj._finishFetch(idMap[id].toJSON());
2224
-
2225
- results[_i] = idMap[id];
2226
- }
2227
- }
2228
- }
2229
-
2230
- _iterator2 = _createForOfIteratorHelperLoose(results);
2231
-
2232
- case 13:
2233
- if ((_step2 = _iterator2()).done) {
2234
- _context6.next = 19;
2235
- break;
2236
- }
2237
-
2238
- object = _step2.value;
2239
- _context6.next = 17;
2240
- return _regeneratorRuntime().awrap(localDatastore._updateObjectIfPinned(object));
2241
-
2242
- case 17:
2243
- _context6.next = 13;
2244
- break;
2245
-
2246
- case 19:
2247
- return _context6.abrupt("return", Promise.resolve(results));
2248
-
2249
- case 20:
2250
- case "end":
2251
- return _context6.stop();
1390
+ return query.find(options).then(function () {
1391
+ var _ref = (0, _asyncToGenerator2.default)(function* (objects) {
1392
+ var idMap = {};
1393
+ objects.forEach(function (o) {
1394
+ idMap[o.id] = o;
1395
+ });
1396
+ for (var i = 0; i < objs.length; i++) {
1397
+ var obj = objs[i];
1398
+ if (!obj || !obj.id || !idMap[obj.id]) {
1399
+ if (forceFetch) {
1400
+ return Promise.reject(new _ParseError.default(_ParseError.default.OBJECT_NOT_FOUND, 'All objects must exist on the server.'));
1401
+ }
2252
1402
  }
2253
1403
  }
2254
- }, null, null, null, Promise);
2255
- });
1404
+ if (!singleInstance) {
1405
+ for (var _i = 0; _i < results.length; _i++) {
1406
+ var _obj = results[_i];
1407
+ if (_obj && _obj.id && idMap[_obj.id]) {
1408
+ var id = _obj.id;
1409
+ _obj._finishFetch(idMap[id].toJSON());
1410
+ results[_i] = idMap[id];
1411
+ }
1412
+ }
1413
+ }
1414
+ for (var object of results) {
1415
+ yield localDatastore._updateObjectIfPinned(object);
1416
+ }
1417
+ return Promise.resolve(results);
1418
+ });
1419
+ return function () {
1420
+ return _ref.apply(this, arguments);
1421
+ };
1422
+ }());
2256
1423
  } else if (target instanceof ParseObject) {
2257
1424
  if (!target.id) {
2258
1425
  return Promise.reject(new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'Object does not have an ID'));
2259
1426
  }
2260
-
2261
1427
  var RESTController = _CoreManager.default.getRESTController();
2262
-
2263
1428
  var params = {};
2264
-
2265
1429
  if (options && options.include) {
2266
1430
  params.include = options.include.join();
2267
1431
  }
2268
-
2269
- return RESTController.request('GET', 'classes/' + target.className + '/' + target._getId(), params, options).then(function (response) {
2270
- return _regeneratorRuntime().async(function (_context7) {
2271
- while (1) {
2272
- switch (_context7.prev = _context7.next) {
2273
- case 0:
2274
- target._clearPendingOps();
2275
-
2276
- target._clearServerData();
2277
-
2278
- target._finishFetch(response);
2279
-
2280
- _context7.next = 5;
2281
- return _regeneratorRuntime().awrap(localDatastore._updateObjectIfPinned(target));
2282
-
2283
- case 5:
2284
- return _context7.abrupt("return", target);
2285
-
2286
- case 6:
2287
- case "end":
2288
- return _context7.stop();
2289
- }
2290
- }
2291
- }, null, null, null, Promise);
2292
- });
1432
+ return RESTController.request('GET', 'classes/' + target.className + '/' + target._getId(), params, options).then(function () {
1433
+ var _ref2 = (0, _asyncToGenerator2.default)(function* (response) {
1434
+ target._clearPendingOps();
1435
+ target._clearServerData();
1436
+ target._finishFetch(response);
1437
+ yield localDatastore._updateObjectIfPinned(target);
1438
+ return target;
1439
+ });
1440
+ return function () {
1441
+ return _ref2.apply(this, arguments);
1442
+ };
1443
+ }());
2293
1444
  }
2294
-
2295
1445
  return Promise.resolve();
2296
1446
  },
2297
- destroy: function (target, options) {
2298
- var batchSize, localDatastore, RESTController, batches, deleteCompleted, errors;
2299
- return _regeneratorRuntime().async(function (_context10) {
2300
- while (1) {
2301
- switch (_context10.prev = _context10.next) {
2302
- case 0:
2303
- batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
2304
- localDatastore = _CoreManager.default.getLocalDatastore();
2305
- RESTController = _CoreManager.default.getRESTController();
2306
-
2307
- if (!Array.isArray(target)) {
2308
- _context10.next = 15;
2309
- break;
2310
- }
2311
-
2312
- if (!(target.length < 1)) {
2313
- _context10.next = 6;
2314
- break;
2315
- }
2316
-
2317
- return _context10.abrupt("return", Promise.resolve([]));
2318
-
2319
- case 6:
2320
- batches = [[]];
2321
- target.forEach(function (obj) {
2322
- if (!obj.id) {
2323
- return;
2324
- }
2325
-
2326
- batches[batches.length - 1].push(obj);
2327
-
2328
- if (batches[batches.length - 1].length >= batchSize) {
2329
- batches.push([]);
1447
+ destroy: function () {
1448
+ var _destroy = (0, _asyncToGenerator2.default)(function* (target, options) {
1449
+ var batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
1450
+ var localDatastore = _CoreManager.default.getLocalDatastore();
1451
+ var RESTController = _CoreManager.default.getRESTController();
1452
+ if (Array.isArray(target)) {
1453
+ if (target.length < 1) {
1454
+ return Promise.resolve([]);
1455
+ }
1456
+ var batches = [[]];
1457
+ target.forEach(function (obj) {
1458
+ if (!obj.id) {
1459
+ return;
1460
+ }
1461
+ batches[batches.length - 1].push(obj);
1462
+ if (batches[batches.length - 1].length >= batchSize) {
1463
+ batches.push([]);
1464
+ }
1465
+ });
1466
+ if (batches[batches.length - 1].length === 0) {
1467
+ batches.pop();
1468
+ }
1469
+ var deleteCompleted = Promise.resolve();
1470
+ var errors = [];
1471
+ batches.forEach(function (batch) {
1472
+ deleteCompleted = deleteCompleted.then(function () {
1473
+ return RESTController.request('POST', 'batch', {
1474
+ requests: batch.map(function (obj) {
1475
+ return {
1476
+ method: 'DELETE',
1477
+ path: getServerUrlPath() + 'classes/' + obj.className + '/' + obj._getId(),
1478
+ body: {}
1479
+ };
1480
+ })
1481
+ }, options).then(function (results) {
1482
+ for (var i = 0; i < results.length; i++) {
1483
+ if (results[i] && results[i].hasOwnProperty('error')) {
1484
+ var err = new _ParseError.default(results[i].error.code, results[i].error.error);
1485
+ err.object = batch[i];
1486
+ errors.push(err);
1487
+ }
2330
1488
  }
2331
1489
  });
2332
-
2333
- if (batches[batches.length - 1].length === 0) {
2334
- batches.pop();
2335
- }
2336
-
2337
- deleteCompleted = Promise.resolve();
2338
- errors = [];
2339
- batches.forEach(function (batch) {
2340
- deleteCompleted = deleteCompleted.then(function () {
2341
- return RESTController.request('POST', 'batch', {
2342
- requests: batch.map(function (obj) {
2343
- return {
2344
- method: 'DELETE',
2345
- path: getServerUrlPath() + 'classes/' + obj.className + '/' + obj._getId(),
2346
- body: {}
2347
- };
2348
- })
2349
- }, options).then(function (results) {
2350
- for (var i = 0; i < results.length; i++) {
2351
- if (results[i] && results[i].hasOwnProperty('error')) {
2352
- var err = new _ParseError.default(results[i].error.code, results[i].error.error);
2353
- err.object = batch[i];
2354
- errors.push(err);
2355
- }
2356
- }
2357
- });
2358
- });
2359
- });
2360
- return _context10.abrupt("return", deleteCompleted.then(function () {
2361
- var aggregate, _iterator3, _step3, object;
2362
-
2363
- return _regeneratorRuntime().async(function (_context8) {
2364
- while (1) {
2365
- switch (_context8.prev = _context8.next) {
2366
- case 0:
2367
- if (!errors.length) {
2368
- _context8.next = 4;
2369
- break;
2370
- }
2371
-
2372
- aggregate = new _ParseError.default(_ParseError.default.AGGREGATE_ERROR);
2373
- aggregate.errors = errors;
2374
- return _context8.abrupt("return", Promise.reject(aggregate));
2375
-
2376
- case 4:
2377
- _iterator3 = _createForOfIteratorHelperLoose(target);
2378
-
2379
- case 5:
2380
- if ((_step3 = _iterator3()).done) {
2381
- _context8.next = 11;
2382
- break;
2383
- }
2384
-
2385
- object = _step3.value;
2386
- _context8.next = 9;
2387
- return _regeneratorRuntime().awrap(localDatastore._destroyObjectIfPinned(object));
2388
-
2389
- case 9:
2390
- _context8.next = 5;
2391
- break;
2392
-
2393
- case 11:
2394
- return _context8.abrupt("return", Promise.resolve(target));
2395
-
2396
- case 12:
2397
- case "end":
2398
- return _context8.stop();
2399
- }
2400
- }
2401
- }, null, null, null, Promise);
2402
- }));
2403
-
2404
- case 15:
2405
- if (!(target instanceof ParseObject)) {
2406
- _context10.next = 17;
2407
- break;
2408
- }
2409
-
2410
- return _context10.abrupt("return", RESTController.request('DELETE', 'classes/' + target.className + '/' + target._getId(), {}, options).then(function () {
2411
- return _regeneratorRuntime().async(function (_context9) {
2412
- while (1) {
2413
- switch (_context9.prev = _context9.next) {
2414
- case 0:
2415
- _context9.next = 2;
2416
- return _regeneratorRuntime().awrap(localDatastore._destroyObjectIfPinned(target));
2417
-
2418
- case 2:
2419
- return _context9.abrupt("return", Promise.resolve(target));
2420
-
2421
- case 3:
2422
- case "end":
2423
- return _context9.stop();
2424
- }
2425
- }
2426
- }, null, null, null, Promise);
2427
- }));
2428
-
2429
- case 17:
2430
- return _context10.abrupt("return", Promise.resolve(target));
2431
-
2432
- case 18:
2433
- case "end":
2434
- return _context10.stop();
2435
- }
2436
- }
2437
- }, null, null, null, Promise);
2438
- },
1490
+ });
1491
+ });
1492
+ return deleteCompleted.then((0, _asyncToGenerator2.default)(function* () {
1493
+ if (errors.length) {
1494
+ var aggregate = new _ParseError.default(_ParseError.default.AGGREGATE_ERROR);
1495
+ aggregate.errors = errors;
1496
+ return Promise.reject(aggregate);
1497
+ }
1498
+ for (var object of target) {
1499
+ yield localDatastore._destroyObjectIfPinned(object);
1500
+ }
1501
+ return Promise.resolve(target);
1502
+ }));
1503
+ } else if (target instanceof ParseObject) {
1504
+ return RESTController.request('DELETE', 'classes/' + target.className + '/' + target._getId(), {}, options).then((0, _asyncToGenerator2.default)(function* () {
1505
+ yield localDatastore._destroyObjectIfPinned(target);
1506
+ return Promise.resolve(target);
1507
+ }));
1508
+ }
1509
+ return Promise.resolve(target);
1510
+ });
1511
+ function destroy() {
1512
+ return _destroy.apply(this, arguments);
1513
+ }
1514
+ return destroy;
1515
+ }(),
2439
1516
  save: function (target, options) {
2440
1517
  var batchSize = options && options.batchSize ? options.batchSize : _CoreManager.default.get('REQUEST_BATCH_SIZE');
2441
-
2442
1518
  var localDatastore = _CoreManager.default.getLocalDatastore();
2443
-
2444
1519
  var mapIdForPin = {};
2445
-
2446
1520
  var RESTController = _CoreManager.default.getRESTController();
2447
-
2448
1521
  var stateController = _CoreManager.default.getObjectStateController();
2449
-
2450
1522
  var allowCustomObjectId = _CoreManager.default.get('ALLOW_CUSTOM_OBJECT_ID');
2451
-
2452
1523
  options = options || {};
2453
1524
  options.returnStatus = options.returnStatus || true;
2454
-
2455
1525
  if (Array.isArray(target)) {
2456
1526
  if (target.length < 1) {
2457
1527
  return Promise.resolve([]);
2458
1528
  }
2459
-
2460
1529
  var unsaved = target.concat();
2461
-
2462
1530
  for (var i = 0; i < target.length; i++) {
2463
1531
  if (target[i] instanceof ParseObject) {
2464
1532
  unsaved = unsaved.concat((0, _unsavedChildren.default)(target[i], true));
2465
1533
  }
2466
1534
  }
2467
-
2468
1535
  unsaved = (0, _unique.default)(unsaved);
2469
1536
  var filesSaved = [];
2470
1537
  var pending = [];
@@ -2486,7 +1553,6 @@ var DefaultController = {
2486
1553
  if (allowCustomObjectId && Object.prototype.hasOwnProperty.call(el, 'id') && !el.id) {
2487
1554
  throw new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'objectId must not be empty or null');
2488
1555
  }
2489
-
2490
1556
  if (batch.length < batchSize && (0, _canBeSerialized.default)(el)) {
2491
1557
  batch.push(el);
2492
1558
  } else {
@@ -2494,18 +1560,15 @@ var DefaultController = {
2494
1560
  }
2495
1561
  });
2496
1562
  pending = nextPending;
2497
-
2498
1563
  if (batch.length < 1) {
2499
1564
  return Promise.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Tried to save a batch with a cycle.'));
2500
1565
  }
2501
-
2502
1566
  var batchReturned = new _promiseUtils.resolvingPromise();
2503
1567
  var batchReady = [];
2504
1568
  var batchTasks = [];
2505
1569
  batch.forEach(function (obj, index) {
2506
1570
  var ready = new _promiseUtils.resolvingPromise();
2507
1571
  batchReady.push(ready);
2508
-
2509
1572
  var task = function task() {
2510
1573
  ready.resolve();
2511
1574
  return batchReturned.then(function (responses) {
@@ -2514,7 +1577,6 @@ var DefaultController = {
2514
1577
  var status = responses[index]._status;
2515
1578
  delete responses[index]._status;
2516
1579
  mapIdForPin[objectId] = obj._localId;
2517
-
2518
1580
  obj._handleSaveResponse(responses[index].success, status);
2519
1581
  } else {
2520
1582
  if (!objectError && responses[index].hasOwnProperty('error')) {
@@ -2522,12 +1584,10 @@ var DefaultController = {
2522
1584
  objectError = new _ParseError.default(serverError.code, serverError.error);
2523
1585
  pending = [];
2524
1586
  }
2525
-
2526
1587
  obj._handleSaveError();
2527
1588
  }
2528
1589
  });
2529
1590
  };
2530
-
2531
1591
  stateController.pushPendingState(obj._getStateIdentifier());
2532
1592
  batchTasks.push(stateController.enqueueTask(obj._getStateIdentifier(), task));
2533
1593
  });
@@ -2535,7 +1595,6 @@ var DefaultController = {
2535
1595
  return RESTController.request('POST', 'batch', {
2536
1596
  requests: batch.map(function (obj) {
2537
1597
  var params = obj._getSaveParams();
2538
-
2539
1598
  params.path = getServerUrlPath() + params.path;
2540
1599
  return params;
2541
1600
  })
@@ -2544,109 +1603,49 @@ var DefaultController = {
2544
1603
  batchReturned.reject(new _ParseError.default(_ParseError.default.INCORRECT_TYPE, error.message));
2545
1604
  });
2546
1605
  return (0, _promiseUtils.when)(batchTasks);
2547
- }).then(function _callee5() {
2548
- var _iterator4, _step4, object;
2549
-
2550
- return _regeneratorRuntime().async(function _callee5$(_context11) {
2551
- while (1) {
2552
- switch (_context11.prev = _context11.next) {
2553
- case 0:
2554
- if (!objectError) {
2555
- _context11.next = 2;
2556
- break;
2557
- }
2558
-
2559
- return _context11.abrupt("return", Promise.reject(objectError));
2560
-
2561
- case 2:
2562
- _iterator4 = _createForOfIteratorHelperLoose(target);
2563
-
2564
- case 3:
2565
- if ((_step4 = _iterator4()).done) {
2566
- _context11.next = 11;
2567
- break;
2568
- }
2569
-
2570
- object = _step4.value;
2571
- _context11.next = 7;
2572
- return _regeneratorRuntime().awrap(localDatastore._updateLocalIdForObject(mapIdForPin[object.id], object));
2573
-
2574
- case 7:
2575
- _context11.next = 9;
2576
- return _regeneratorRuntime().awrap(localDatastore._updateObjectIfPinned(object));
2577
-
2578
- case 9:
2579
- _context11.next = 3;
2580
- break;
2581
-
2582
- case 11:
2583
- return _context11.abrupt("return", Promise.resolve(target));
2584
-
2585
- case 12:
2586
- case "end":
2587
- return _context11.stop();
2588
- }
1606
+ }).then((0, _asyncToGenerator2.default)(function* () {
1607
+ if (objectError) {
1608
+ return Promise.reject(objectError);
1609
+ }
1610
+ for (var object of target) {
1611
+ if (object instanceof ParseObject) {
1612
+ yield localDatastore._updateLocalIdForObject(mapIdForPin[object.id], object);
1613
+ yield localDatastore._updateObjectIfPinned(object);
2589
1614
  }
2590
- }, null, null, null, Promise);
2591
- });
1615
+ }
1616
+ return Promise.resolve(target);
1617
+ }));
2592
1618
  });
2593
1619
  } else if (target instanceof ParseObject) {
2594
1620
  if (allowCustomObjectId && Object.prototype.hasOwnProperty.call(target, 'id') && !target.id) {
2595
1621
  throw new _ParseError.default(_ParseError.default.MISSING_OBJECT_ID, 'objectId must not be empty or null');
2596
1622
  }
2597
-
2598
1623
  target._getId();
2599
-
2600
1624
  var localId = target._localId;
2601
1625
  var targetCopy = target;
2602
-
2603
1626
  var task = function task() {
2604
1627
  var params = targetCopy._getSaveParams();
2605
-
2606
1628
  return RESTController.request(params.method, params.path, params.body, options).then(function (response) {
2607
1629
  var status = response._status;
2608
1630
  delete response._status;
2609
-
2610
1631
  targetCopy._handleSaveResponse(response, status);
2611
1632
  }, function (error) {
2612
1633
  targetCopy._handleSaveError();
2613
-
2614
1634
  return Promise.reject(error);
2615
1635
  });
2616
1636
  };
2617
-
2618
1637
  stateController.pushPendingState(target._getStateIdentifier());
2619
- return stateController.enqueueTask(target._getStateIdentifier(), task).then(function _callee6() {
2620
- return _regeneratorRuntime().async(function _callee6$(_context12) {
2621
- while (1) {
2622
- switch (_context12.prev = _context12.next) {
2623
- case 0:
2624
- _context12.next = 2;
2625
- return _regeneratorRuntime().awrap(localDatastore._updateLocalIdForObject(localId, target));
2626
-
2627
- case 2:
2628
- _context12.next = 4;
2629
- return _regeneratorRuntime().awrap(localDatastore._updateObjectIfPinned(target));
2630
-
2631
- case 4:
2632
- return _context12.abrupt("return", target);
2633
-
2634
- case 5:
2635
- case "end":
2636
- return _context12.stop();
2637
- }
2638
- }
2639
- }, null, null, null, Promise);
2640
- }, function (error) {
1638
+ return stateController.enqueueTask(target._getStateIdentifier(), task).then((0, _asyncToGenerator2.default)(function* () {
1639
+ yield localDatastore._updateLocalIdForObject(localId, target);
1640
+ yield localDatastore._updateObjectIfPinned(target);
1641
+ return target;
1642
+ }), function (error) {
2641
1643
  return Promise.reject(error);
2642
1644
  });
2643
1645
  }
2644
-
2645
1646
  return Promise.resolve();
2646
1647
  }
2647
1648
  };
2648
-
2649
1649
  _CoreManager.default.setObjectController(DefaultController);
2650
-
2651
1650
  var _default = ParseObject;
2652
1651
  exports.default = _default;