parse 4.0.1 → 4.1.0-alpha.1

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