parse 4.0.0-alpha.1 → 4.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +34 -30
  255. package/PATENTS +0 -37
@@ -5,88 +5,56 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.UnsetOp = exports.SetOp = exports.RemoveOp = exports.RelationOp = exports.Op = exports.IncrementOp = exports.AddUniqueOp = exports.AddOp = void 0;
7
7
  exports.opFromJSON = opFromJSON;
8
-
9
8
  var _arrayContainsObject = _interopRequireDefault(require("./arrayContainsObject"));
10
-
11
9
  var _decode = _interopRequireDefault(require("./decode"));
12
-
13
10
  var _encode = _interopRequireDefault(require("./encode"));
14
-
15
11
  var _ParseObject = _interopRequireDefault(require("./ParseObject"));
16
-
17
12
  var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
18
-
19
13
  var _unique = _interopRequireDefault(require("./unique"));
20
-
21
14
  function _interopRequireDefault(obj) {
22
15
  return obj && obj.__esModule ? obj : {
23
16
  default: obj
24
17
  };
25
18
  }
26
19
  /**
27
- * Copyright (c) 2015-present, Parse, LLC.
28
- * All rights reserved.
29
- *
30
- * This source code is licensed under the BSD-style license found in the
31
- * LICENSE file in the root directory of this source tree. An additional grant
32
- * of patent rights can be found in the PATENTS file in the same directory.
33
- *
34
20
  * @flow
35
21
  */
36
22
 
37
-
38
- function opFromJSON(json
39
- /*: { [key: string]: any }*/
40
- )
41
- /*: ?Op*/
42
- {
23
+ function opFromJSON(json /*: { [key: string]: any }*/) /*: ?Op*/{
43
24
  if (!json || !json.__op) {
44
25
  return null;
45
26
  }
46
-
47
27
  switch (json.__op) {
48
28
  case 'Delete':
49
29
  return new UnsetOp();
50
-
51
30
  case 'Increment':
52
31
  return new IncrementOp(json.amount);
53
-
54
32
  case 'Add':
55
33
  return new AddOp((0, _decode.default)(json.objects));
56
-
57
34
  case 'AddUnique':
58
35
  return new AddUniqueOp((0, _decode.default)(json.objects));
59
-
60
36
  case 'Remove':
61
37
  return new RemoveOp((0, _decode.default)(json.objects));
62
-
63
38
  case 'AddRelation':
64
39
  {
65
40
  const toAdd = (0, _decode.default)(json.objects);
66
-
67
41
  if (!Array.isArray(toAdd)) {
68
42
  return new RelationOp([], []);
69
43
  }
70
-
71
44
  return new RelationOp(toAdd, []);
72
45
  }
73
-
74
46
  case 'RemoveRelation':
75
47
  {
76
48
  const toRemove = (0, _decode.default)(json.objects);
77
-
78
49
  if (!Array.isArray(toRemove)) {
79
50
  return new RelationOp([], []);
80
51
  }
81
-
82
52
  return new RelationOp([], toRemove);
83
53
  }
84
-
85
54
  case 'Batch':
86
55
  {
87
56
  let toAdd = [];
88
57
  let toRemove = [];
89
-
90
58
  for (let i = 0; i < json.ops.length; i++) {
91
59
  if (json.ops[i].__op === 'AddRelation') {
92
60
  toAdd = toAdd.concat((0, _decode.default)(json.ops[i].objects));
@@ -94,240 +62,140 @@ function opFromJSON(json
94
62
  toRemove = toRemove.concat((0, _decode.default)(json.ops[i].objects));
95
63
  }
96
64
  }
97
-
98
65
  return new RelationOp(toAdd, toRemove);
99
66
  }
100
67
  }
101
-
102
68
  return null;
103
69
  }
104
-
105
70
  class Op {
106
71
  // Empty parent class
107
- applyTo()
108
- /*: mixed*/
109
- {}
110
- /* eslint-disable-line no-unused-vars */
111
-
112
-
113
- mergeWith()
114
- /*: ?Op*/
115
- {}
116
- /* eslint-disable-line no-unused-vars */
117
-
118
-
119
- toJSON()
120
- /*: mixed*/
121
- {}
122
-
72
+ applyTo() /*: mixed*/{} /* eslint-disable-line no-unused-vars */
73
+ mergeWith() /*: ?Op*/{} /* eslint-disable-line no-unused-vars */
74
+ toJSON() /*: mixed*/{}
123
75
  }
124
-
125
76
  exports.Op = Op;
126
-
127
77
  class SetOp extends Op {
128
78
  /*:: _value: ?mixed;*/
129
- constructor(value
130
- /*: mixed*/
131
- ) {
79
+ constructor(value /*: mixed*/) {
132
80
  super();
133
81
  this._value = value;
134
82
  }
135
-
136
- applyTo()
137
- /*: mixed*/
138
- {
83
+ applyTo() /*: mixed*/{
139
84
  return this._value;
140
85
  }
141
-
142
- mergeWith()
143
- /*: SetOp*/
144
- {
86
+ mergeWith() /*: SetOp*/{
145
87
  return new SetOp(this._value);
146
88
  }
147
-
148
- toJSON(offline
149
- /*:: ?: boolean*/
150
- ) {
89
+ toJSON(offline /*:: ?: boolean*/) {
151
90
  return (0, _encode.default)(this._value, false, true, undefined, offline);
152
91
  }
153
-
154
92
  }
155
-
156
93
  exports.SetOp = SetOp;
157
-
158
94
  class UnsetOp extends Op {
159
95
  applyTo() {
160
96
  return undefined;
161
97
  }
162
-
163
- mergeWith()
164
- /*: UnsetOp*/
165
- {
98
+ mergeWith() /*: UnsetOp*/{
166
99
  return new UnsetOp();
167
100
  }
168
-
169
- toJSON()
170
- /*: { __op: string }*/
171
- {
101
+ toJSON() /*: { __op: string }*/{
172
102
  return {
173
103
  __op: 'Delete'
174
104
  };
175
105
  }
176
-
177
106
  }
178
-
179
107
  exports.UnsetOp = UnsetOp;
180
-
181
108
  class IncrementOp extends Op {
182
109
  /*:: _amount: number;*/
183
- constructor(amount
184
- /*: number*/
185
- ) {
110
+ constructor(amount /*: number*/) {
186
111
  super();
187
-
188
112
  if (typeof amount !== 'number') {
189
113
  throw new TypeError('Increment Op must be initialized with a numeric amount.');
190
114
  }
191
-
192
115
  this._amount = amount;
193
116
  }
194
-
195
- applyTo(value
196
- /*: ?mixed*/
197
- )
198
- /*: number*/
199
- {
117
+ applyTo(value /*: ?mixed*/) /*: number*/{
200
118
  if (typeof value === 'undefined') {
201
119
  return this._amount;
202
120
  }
203
-
204
121
  if (typeof value !== 'number') {
205
122
  throw new TypeError('Cannot increment a non-numeric value.');
206
123
  }
207
-
208
124
  return this._amount + value;
209
125
  }
210
-
211
- mergeWith(previous
212
- /*: Op*/
213
- )
214
- /*: Op*/
215
- {
126
+ mergeWith(previous /*: Op*/) /*: Op*/{
216
127
  if (!previous) {
217
128
  return this;
218
129
  }
219
-
220
130
  if (previous instanceof SetOp) {
221
131
  return new SetOp(this.applyTo(previous._value));
222
132
  }
223
-
224
133
  if (previous instanceof UnsetOp) {
225
134
  return new SetOp(this._amount);
226
135
  }
227
-
228
136
  if (previous instanceof IncrementOp) {
229
137
  return new IncrementOp(this.applyTo(previous._amount));
230
138
  }
231
-
232
139
  throw new Error('Cannot merge Increment Op with the previous Op');
233
140
  }
234
-
235
- toJSON()
236
- /*: { __op: string, amount: number }*/
237
- {
141
+ toJSON() /*: { __op: string, amount: number }*/{
238
142
  return {
239
143
  __op: 'Increment',
240
144
  amount: this._amount
241
145
  };
242
146
  }
243
-
244
147
  }
245
-
246
148
  exports.IncrementOp = IncrementOp;
247
-
248
149
  class AddOp extends Op {
249
150
  /*:: _value: Array<mixed>;*/
250
- constructor(value
251
- /*: mixed | Array<mixed>*/
252
- ) {
151
+ constructor(value /*: mixed | Array<mixed>*/) {
253
152
  super();
254
153
  this._value = Array.isArray(value) ? value : [value];
255
154
  }
256
-
257
- applyTo(value
258
- /*: mixed*/
259
- )
260
- /*: Array<mixed>*/
261
- {
155
+ applyTo(value /*: mixed*/) /*: Array<mixed>*/{
262
156
  if (value == null) {
263
157
  return this._value;
264
158
  }
265
-
266
159
  if (Array.isArray(value)) {
267
160
  return value.concat(this._value);
268
161
  }
269
-
270
162
  throw new Error('Cannot add elements to a non-array value');
271
163
  }
272
-
273
- mergeWith(previous
274
- /*: Op*/
275
- )
276
- /*: Op*/
277
- {
164
+ mergeWith(previous /*: Op*/) /*: Op*/{
278
165
  if (!previous) {
279
166
  return this;
280
167
  }
281
-
282
168
  if (previous instanceof SetOp) {
283
169
  return new SetOp(this.applyTo(previous._value));
284
170
  }
285
-
286
171
  if (previous instanceof UnsetOp) {
287
172
  return new SetOp(this._value);
288
173
  }
289
-
290
174
  if (previous instanceof AddOp) {
291
175
  return new AddOp(this.applyTo(previous._value));
292
176
  }
293
-
294
177
  throw new Error('Cannot merge Add Op with the previous Op');
295
178
  }
296
-
297
- toJSON()
298
- /*: { __op: string, objects: mixed }*/
299
- {
179
+ toJSON() /*: { __op: string, objects: mixed }*/{
300
180
  return {
301
181
  __op: 'Add',
302
182
  objects: (0, _encode.default)(this._value, false, true)
303
183
  };
304
184
  }
305
-
306
185
  }
307
-
308
186
  exports.AddOp = AddOp;
309
-
310
187
  class AddUniqueOp extends Op {
311
188
  /*:: _value: Array<mixed>;*/
312
- constructor(value
313
- /*: mixed | Array<mixed>*/
314
- ) {
189
+ constructor(value /*: mixed | Array<mixed>*/) {
315
190
  super();
316
191
  this._value = (0, _unique.default)(Array.isArray(value) ? value : [value]);
317
192
  }
318
-
319
- applyTo(value
320
- /*: mixed | Array<mixed>*/
321
- )
322
- /*: Array<mixed>*/
323
- {
193
+ applyTo(value /*: mixed | Array<mixed>*/) /*: Array<mixed>*/{
324
194
  if (value == null) {
325
195
  return this._value || [];
326
196
  }
327
-
328
197
  if (Array.isArray(value)) {
329
198
  const toAdd = [];
330
-
331
199
  this._value.forEach(v => {
332
200
  if (v instanceof _ParseObject.default) {
333
201
  if (!(0, _arrayContainsObject.default)(value, v)) {
@@ -339,80 +207,52 @@ class AddUniqueOp extends Op {
339
207
  }
340
208
  }
341
209
  });
342
-
343
210
  return value.concat(toAdd);
344
211
  }
345
-
346
212
  throw new Error('Cannot add elements to a non-array value');
347
213
  }
348
-
349
- mergeWith(previous
350
- /*: Op*/
351
- )
352
- /*: Op*/
353
- {
214
+ mergeWith(previous /*: Op*/) /*: Op*/{
354
215
  if (!previous) {
355
216
  return this;
356
217
  }
357
-
358
218
  if (previous instanceof SetOp) {
359
219
  return new SetOp(this.applyTo(previous._value));
360
220
  }
361
-
362
221
  if (previous instanceof UnsetOp) {
363
222
  return new SetOp(this._value);
364
223
  }
365
-
366
224
  if (previous instanceof AddUniqueOp) {
367
225
  return new AddUniqueOp(this.applyTo(previous._value));
368
226
  }
369
-
370
227
  throw new Error('Cannot merge AddUnique Op with the previous Op');
371
228
  }
372
-
373
- toJSON()
374
- /*: { __op: string, objects: mixed }*/
375
- {
229
+ toJSON() /*: { __op: string, objects: mixed }*/{
376
230
  return {
377
231
  __op: 'AddUnique',
378
232
  objects: (0, _encode.default)(this._value, false, true)
379
233
  };
380
234
  }
381
-
382
235
  }
383
-
384
236
  exports.AddUniqueOp = AddUniqueOp;
385
-
386
237
  class RemoveOp extends Op {
387
238
  /*:: _value: Array<mixed>;*/
388
- constructor(value
389
- /*: mixed | Array<mixed>*/
390
- ) {
239
+ constructor(value /*: mixed | Array<mixed>*/) {
391
240
  super();
392
241
  this._value = (0, _unique.default)(Array.isArray(value) ? value : [value]);
393
242
  }
394
-
395
- applyTo(value
396
- /*: mixed | Array<mixed>*/
397
- )
398
- /*: Array<mixed>*/
399
- {
243
+ applyTo(value /*: mixed | Array<mixed>*/) /*: Array<mixed>*/{
400
244
  if (value == null) {
401
245
  return [];
402
246
  }
403
-
404
247
  if (Array.isArray(value)) {
405
248
  // var i = value.indexOf(this._value);
406
249
  const removed = value.concat([]);
407
-
408
250
  for (let i = 0; i < this._value.length; i++) {
409
251
  let index = removed.indexOf(this._value[i]);
410
-
411
252
  while (index > -1) {
412
253
  removed.splice(index, 1);
413
254
  index = removed.indexOf(this._value[i]);
414
255
  }
415
-
416
256
  if (this._value[i] instanceof _ParseObject.default && this._value[i].id) {
417
257
  for (let j = 0; j < removed.length; j++) {
418
258
  if (removed[j] instanceof _ParseObject.default && this._value[i].id === removed[j].id) {
@@ -422,33 +262,22 @@ class RemoveOp extends Op {
422
262
  }
423
263
  }
424
264
  }
425
-
426
265
  return removed;
427
266
  }
428
-
429
267
  throw new Error('Cannot remove elements from a non-array value');
430
268
  }
431
-
432
- mergeWith(previous
433
- /*: Op*/
434
- )
435
- /*: Op*/
436
- {
269
+ mergeWith(previous /*: Op*/) /*: Op*/{
437
270
  if (!previous) {
438
271
  return this;
439
272
  }
440
-
441
273
  if (previous instanceof SetOp) {
442
274
  return new SetOp(this.applyTo(previous._value));
443
275
  }
444
-
445
276
  if (previous instanceof UnsetOp) {
446
277
  return new UnsetOp();
447
278
  }
448
-
449
279
  if (previous instanceof RemoveOp) {
450
280
  const uniques = previous._value.concat([]);
451
-
452
281
  for (let i = 0; i < this._value.length; i++) {
453
282
  if (this._value[i] instanceof _ParseObject.default) {
454
283
  if (!(0, _arrayContainsObject.default)(uniques, this._value[i])) {
@@ -460,100 +289,62 @@ class RemoveOp extends Op {
460
289
  }
461
290
  }
462
291
  }
463
-
464
292
  return new RemoveOp(uniques);
465
293
  }
466
-
467
294
  throw new Error('Cannot merge Remove Op with the previous Op');
468
295
  }
469
-
470
- toJSON()
471
- /*: { __op: string, objects: mixed }*/
472
- {
296
+ toJSON() /*: { __op: string, objects: mixed }*/{
473
297
  return {
474
298
  __op: 'Remove',
475
299
  objects: (0, _encode.default)(this._value, false, true)
476
300
  };
477
301
  }
478
-
479
302
  }
480
-
481
303
  exports.RemoveOp = RemoveOp;
482
-
483
304
  class RelationOp extends Op {
484
305
  /*:: _targetClassName: ?string;*/
485
-
486
306
  /*:: relationsToAdd: Array<string>;*/
487
-
488
307
  /*:: relationsToRemove: Array<string>;*/
489
- constructor(adds
490
- /*: Array<ParseObject | string>*/
491
- , removes
492
- /*: Array<ParseObject | string>*/
493
- ) {
308
+ constructor(adds /*: Array<ParseObject | string>*/, removes /*: Array<ParseObject | string>*/) {
494
309
  super();
495
310
  this._targetClassName = null;
496
-
497
311
  if (Array.isArray(adds)) {
498
312
  this.relationsToAdd = (0, _unique.default)(adds.map(this._extractId, this));
499
313
  }
500
-
501
314
  if (Array.isArray(removes)) {
502
315
  this.relationsToRemove = (0, _unique.default)(removes.map(this._extractId, this));
503
316
  }
504
317
  }
505
-
506
- _extractId(obj
507
- /*: string | ParseObject*/
508
- )
509
- /*: string*/
510
- {
318
+ _extractId(obj /*: string | ParseObject*/) /*: string*/{
511
319
  if (typeof obj === 'string') {
512
320
  return obj;
513
321
  }
514
-
515
322
  if (!obj.id) {
516
323
  throw new Error('You cannot add or remove an unsaved Parse Object from a relation');
517
324
  }
518
-
519
325
  if (!this._targetClassName) {
520
326
  this._targetClassName = obj.className;
521
327
  }
522
-
523
328
  if (this._targetClassName !== obj.className) {
524
329
  throw new Error('Tried to create a Relation with 2 different object types: ' + this._targetClassName + ' and ' + obj.className + '.');
525
330
  }
526
-
527
331
  return obj.id;
528
332
  }
529
-
530
- applyTo(value
531
- /*: mixed*/
532
- , object
533
- /*:: ?: { className: string, id: ?string }*/
534
- , key
535
- /*:: ?: string*/
536
- )
537
- /*: ?ParseRelation*/
538
- {
333
+ applyTo(value /*: mixed*/, object /*:: ?: { className: string, id: ?string }*/, key /*:: ?: string*/) /*: ?ParseRelation*/{
539
334
  if (!value) {
540
335
  if (!object || !key) {
541
336
  throw new Error('Cannot apply a RelationOp without either a previous value, or an object and a key');
542
337
  }
543
-
544
338
  const parent = new _ParseObject.default(object.className);
545
-
546
339
  if (object.id && object.id.indexOf('local') === 0) {
547
340
  parent._localId = object.id;
548
341
  } else if (object.id) {
549
342
  parent.id = object.id;
550
343
  }
551
-
552
344
  const relation = new _ParseRelation.default(parent, key);
553
345
  relation.targetClassName = this._targetClassName;
554
346
  return relation;
555
347
  }
556
-
557
348
  if (value instanceof _ParseRelation.default) {
558
349
  if (this._targetClassName) {
559
350
  if (value.targetClassName) {
@@ -564,18 +355,12 @@ class RelationOp extends Op {
564
355
  value.targetClassName = this._targetClassName;
565
356
  }
566
357
  }
567
-
568
358
  return value;
569
359
  } else {
570
360
  throw new Error('Relation cannot be applied to a non-relation field');
571
361
  }
572
362
  }
573
-
574
- mergeWith(previous
575
- /*: Op*/
576
- )
577
- /*: Op*/
578
- {
363
+ mergeWith(previous /*: Op*/) /*: Op*/{
579
364
  if (!previous) {
580
365
  return this;
581
366
  } else if (previous instanceof UnsetOp) {
@@ -586,18 +371,15 @@ class RelationOp extends Op {
586
371
  if (previous._targetClassName && previous._targetClassName !== this._targetClassName) {
587
372
  throw new Error('Related object must be of class ' + previous._targetClassName + ', but ' + (this._targetClassName || 'null') + ' was passed in.');
588
373
  }
589
-
590
374
  const newAdd = previous.relationsToAdd.concat([]);
591
375
  this.relationsToRemove.forEach(r => {
592
376
  const index = newAdd.indexOf(r);
593
-
594
377
  if (index > -1) {
595
378
  newAdd.splice(index, 1);
596
379
  }
597
380
  });
598
381
  this.relationsToAdd.forEach(r => {
599
382
  const index = newAdd.indexOf(r);
600
-
601
383
  if (index < 0) {
602
384
  newAdd.push(r);
603
385
  }
@@ -605,14 +387,12 @@ class RelationOp extends Op {
605
387
  const newRemove = previous.relationsToRemove.concat([]);
606
388
  this.relationsToAdd.forEach(r => {
607
389
  const index = newRemove.indexOf(r);
608
-
609
390
  if (index > -1) {
610
391
  newRemove.splice(index, 1);
611
392
  }
612
393
  });
613
394
  this.relationsToRemove.forEach(r => {
614
395
  const index = newRemove.indexOf(r);
615
-
616
396
  if (index < 0) {
617
397
  newRemove.push(r);
618
398
  }
@@ -621,13 +401,9 @@ class RelationOp extends Op {
621
401
  newRelation._targetClassName = this._targetClassName;
622
402
  return newRelation;
623
403
  }
624
-
625
404
  throw new Error('Cannot merge Relation Op with the previous Op');
626
405
  }
627
-
628
- toJSON()
629
- /*: { __op?: string, objects?: mixed, ops?: mixed }*/
630
- {
406
+ toJSON() /*: { __op?: string, objects?: mixed, ops?: mixed }*/{
631
407
  const idToPointer = id => {
632
408
  return {
633
409
  __type: 'Pointer',
@@ -635,11 +411,9 @@ class RelationOp extends Op {
635
411
  objectId: id
636
412
  };
637
413
  };
638
-
639
414
  let adds = null;
640
415
  let removes = null;
641
416
  let pointers = null;
642
-
643
417
  if (this.relationsToAdd.length > 0) {
644
418
  pointers = this.relationsToAdd.map(idToPointer);
645
419
  adds = {
@@ -647,7 +421,6 @@ class RelationOp extends Op {
647
421
  objects: pointers
648
422
  };
649
423
  }
650
-
651
424
  if (this.relationsToRemove.length > 0) {
652
425
  pointers = this.relationsToRemove.map(idToPointer);
653
426
  removes = {
@@ -655,17 +428,13 @@ class RelationOp extends Op {
655
428
  objects: pointers
656
429
  };
657
430
  }
658
-
659
431
  if (adds && removes) {
660
432
  return {
661
433
  __op: 'Batch',
662
434
  ops: [adds, removes]
663
435
  };
664
436
  }
665
-
666
437
  return adds || removes || {};
667
438
  }
668
-
669
439
  }
670
-
671
440
  exports.RelationOp = RelationOp;