parse 3.5.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 +20 -7
  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 +18 -134
  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 +73 -302
  92. package/lib/node/ParseConfig.js +16 -91
  93. package/lib/node/ParseError.js +61 -74
  94. package/lib/node/ParseFile.js +55 -244
  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 +234 -997
  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 +19 -169
  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 +37 -30
  255. package/PATENTS +0 -37
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  const equalObjects = require('./equals').default;
4
-
5
4
  const decode = require('./decode').default;
6
-
7
5
  const ParseError = require('./ParseError').default;
8
-
9
6
  const ParsePolygon = require('./ParsePolygon').default;
10
-
11
7
  const ParseGeoPoint = require('./ParseGeoPoint').default;
12
8
  /**
13
9
  * contains -- Determines if an object is contained in a list with special handling for Parse pointers.
@@ -17,35 +13,35 @@ const ParseGeoPoint = require('./ParseGeoPoint').default;
17
13
  * @private
18
14
  * @returns {boolean}
19
15
  */
20
-
21
-
22
16
  function contains(haystack, needle) {
23
17
  if (needle && needle.__type && (needle.__type === 'Pointer' || needle.__type === 'Object')) {
24
18
  for (const i in haystack) {
25
19
  const ptr = haystack[i];
26
-
27
20
  if (typeof ptr === 'string' && ptr === needle.objectId) {
28
21
  return true;
29
22
  }
30
-
31
23
  if (ptr.className === needle.className && ptr.objectId === needle.objectId) {
32
24
  return true;
33
25
  }
34
26
  }
35
-
36
27
  return false;
37
28
  }
38
-
29
+ if (Array.isArray(needle)) {
30
+ for (const need of needle) {
31
+ if (contains(haystack, need)) {
32
+ return true;
33
+ }
34
+ }
35
+ }
39
36
  return haystack.indexOf(needle) > -1;
40
37
  }
41
-
42
38
  function transformObject(object) {
43
39
  if (object._toFullJSON) {
44
40
  return object._toFullJSON();
45
41
  }
46
-
47
42
  return object;
48
43
  }
44
+
49
45
  /**
50
46
  * matchesQuery -- Determines if an object would be returned by a Parse Query
51
47
  * It's a lightweight, where-clause only implementation of a full query engine.
@@ -59,35 +55,26 @@ function transformObject(object) {
59
55
  * @private
60
56
  * @returns {boolean}
61
57
  */
62
-
63
-
64
58
  function matchesQuery(className, object, objects, query) {
65
59
  if (object.className !== className) {
66
60
  return false;
67
61
  }
68
-
69
62
  let obj = object;
70
63
  let q = query;
71
-
72
64
  if (object.toJSON) {
73
65
  obj = object.toJSON();
74
66
  }
75
-
76
67
  if (query.toJSON) {
77
68
  q = query.toJSON().where;
78
69
  }
79
-
80
70
  obj.className = className;
81
-
82
71
  for (const field in q) {
83
72
  if (!matchesKeyConstraints(className, obj, objects, field, q[field])) {
84
73
  return false;
85
74
  }
86
75
  }
87
-
88
76
  return true;
89
77
  }
90
-
91
78
  function equalObjectsGeneric(obj, compareTo, eqlFn) {
92
79
  if (Array.isArray(obj)) {
93
80
  for (let i = 0; i < obj.length; i++) {
@@ -95,12 +82,11 @@ function equalObjectsGeneric(obj, compareTo, eqlFn) {
95
82
  return true;
96
83
  }
97
84
  }
98
-
99
85
  return false;
100
86
  }
101
-
102
87
  return eqlFn(obj, compareTo);
103
88
  }
89
+
104
90
  /**
105
91
  * @typedef RelativeTimeToDateResult
106
92
  * @property {string} status The conversion status, `error` if conversion failed or
@@ -110,7 +96,6 @@ function equalObjectsGeneric(obj, compareTo, eqlFn) {
110
96
  * @property {Date|undefined} result The converted date, or `undefined` if conversion
111
97
  * failed.
112
98
  */
113
-
114
99
  /**
115
100
  * Converts human readable relative date string, for example, 'in 10 days' to a date
116
101
  * relative to now.
@@ -119,109 +104,89 @@ function equalObjectsGeneric(obj, compareTo, eqlFn) {
119
104
  * @param {Date} [now=new Date()] The date from which add or subtract. Default is now.
120
105
  * @returns {RelativeTimeToDateResult}
121
106
  */
122
-
123
-
124
107
  function relativeTimeToDate(text, now = new Date()) {
125
108
  text = text.toLowerCase();
126
- let parts = text.split(' '); // Filter out whitespace
109
+ let parts = text.split(' ');
127
110
 
111
+ // Filter out whitespace
128
112
  parts = parts.filter(part => part !== '');
129
113
  const future = parts[0] === 'in';
130
114
  const past = parts[parts.length - 1] === 'ago';
131
-
132
115
  if (!future && !past && text !== 'now') {
133
116
  return {
134
117
  status: 'error',
135
118
  info: "Time should either start with 'in' or end with 'ago'"
136
119
  };
137
120
  }
138
-
139
121
  if (future && past) {
140
122
  return {
141
123
  status: 'error',
142
124
  info: "Time cannot have both 'in' and 'ago'"
143
125
  };
144
- } // strip the 'ago' or 'in'
145
-
126
+ }
146
127
 
128
+ // strip the 'ago' or 'in'
147
129
  if (future) {
148
130
  parts = parts.slice(1);
149
131
  } else {
150
132
  // past
151
133
  parts = parts.slice(0, parts.length - 1);
152
134
  }
153
-
154
135
  if (parts.length % 2 !== 0 && text !== 'now') {
155
136
  return {
156
137
  status: 'error',
157
138
  info: 'Invalid time string. Dangling unit or number.'
158
139
  };
159
140
  }
160
-
161
141
  const pairs = [];
162
-
163
142
  while (parts.length) {
164
143
  pairs.push([parts.shift(), parts.shift()]);
165
144
  }
166
-
167
145
  let seconds = 0;
168
-
169
146
  for (const [num, interval] of pairs) {
170
147
  const val = Number(num);
171
-
172
148
  if (!Number.isInteger(val)) {
173
149
  return {
174
150
  status: 'error',
175
151
  info: `'${num}' is not an integer.`
176
152
  };
177
153
  }
178
-
179
154
  switch (interval) {
180
155
  case 'yr':
181
156
  case 'yrs':
182
157
  case 'year':
183
158
  case 'years':
184
159
  seconds += val * 31536000; // 365 * 24 * 60 * 60
185
-
186
160
  break;
187
-
188
161
  case 'wk':
189
162
  case 'wks':
190
163
  case 'week':
191
164
  case 'weeks':
192
165
  seconds += val * 604800; // 7 * 24 * 60 * 60
193
-
194
166
  break;
195
-
196
167
  case 'd':
197
168
  case 'day':
198
169
  case 'days':
199
170
  seconds += val * 86400; // 24 * 60 * 60
200
-
201
171
  break;
202
-
203
172
  case 'hr':
204
173
  case 'hrs':
205
174
  case 'hour':
206
175
  case 'hours':
207
176
  seconds += val * 3600; // 60 * 60
208
-
209
177
  break;
210
-
211
178
  case 'min':
212
179
  case 'mins':
213
180
  case 'minute':
214
181
  case 'minutes':
215
182
  seconds += val * 60;
216
183
  break;
217
-
218
184
  case 'sec':
219
185
  case 'secs':
220
186
  case 'second':
221
187
  case 'seconds':
222
188
  seconds += val;
223
189
  break;
224
-
225
190
  default:
226
191
  return {
227
192
  status: 'error',
@@ -229,9 +194,7 @@ function relativeTimeToDate(text, now = new Date()) {
229
194
  };
230
195
  }
231
196
  }
232
-
233
197
  const milliseconds = seconds * 1000;
234
-
235
198
  if (future) {
236
199
  return {
237
200
  status: 'success',
@@ -252,6 +215,7 @@ function relativeTimeToDate(text, now = new Date()) {
252
215
  };
253
216
  }
254
217
  }
218
+
255
219
  /**
256
220
  * Determines whether an object matches a single key's constraints
257
221
  *
@@ -263,13 +227,10 @@ function relativeTimeToDate(text, now = new Date()) {
263
227
  * @private
264
228
  * @returns {boolean}
265
229
  */
266
-
267
-
268
230
  function matchesKeyConstraints(className, object, objects, key, constraints) {
269
231
  if (constraints === null) {
270
232
  return false;
271
233
  }
272
-
273
234
  if (key.indexOf('.') >= 0) {
274
235
  // Key references a subobject
275
236
  const keyComponents = key.split('.');
@@ -277,306 +238,235 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
277
238
  const keyRemainder = keyComponents.slice(1).join('.');
278
239
  return matchesKeyConstraints(className, object[subObjectKey] || {}, objects, keyRemainder, constraints);
279
240
  }
280
-
281
241
  let i;
282
-
283
242
  if (key === '$or') {
284
243
  for (i = 0; i < constraints.length; i++) {
285
244
  if (matchesQuery(className, object, objects, constraints[i])) {
286
245
  return true;
287
246
  }
288
247
  }
289
-
290
248
  return false;
291
249
  }
292
-
293
250
  if (key === '$and') {
294
251
  for (i = 0; i < constraints.length; i++) {
295
252
  if (!matchesQuery(className, object, objects, constraints[i])) {
296
253
  return false;
297
254
  }
298
255
  }
299
-
300
256
  return true;
301
257
  }
302
-
303
258
  if (key === '$nor') {
304
259
  for (i = 0; i < constraints.length; i++) {
305
260
  if (matchesQuery(className, object, objects, constraints[i])) {
306
261
  return false;
307
262
  }
308
263
  }
309
-
310
264
  return true;
311
265
  }
312
-
313
266
  if (key === '$relatedTo') {
314
267
  // Bail! We can't handle relational queries locally
315
268
  return false;
316
269
  }
317
-
318
270
  if (!/^[A-Za-z][0-9A-Za-z_]*$/.test(key)) {
319
271
  throw new ParseError(ParseError.INVALID_KEY_NAME, `Invalid Key: ${key}`);
320
- } // Equality (or Array contains) cases
321
-
322
-
272
+ }
273
+ // Equality (or Array contains) cases
323
274
  if (typeof constraints !== 'object') {
324
275
  if (Array.isArray(object[key])) {
325
276
  return object[key].indexOf(constraints) > -1;
326
277
  }
327
-
328
278
  return object[key] === constraints;
329
279
  }
330
-
331
280
  let compareTo;
332
-
333
281
  if (constraints.__type) {
334
282
  if (constraints.__type === 'Pointer') {
335
283
  return equalObjectsGeneric(object[key], constraints, function (obj, ptr) {
336
284
  return typeof obj !== 'undefined' && ptr.className === obj.className && ptr.objectId === obj.objectId;
337
285
  });
338
286
  }
339
-
340
287
  return equalObjectsGeneric(decode(object[key]), decode(constraints), equalObjects);
341
- } // More complex cases
342
-
343
-
288
+ }
289
+ // More complex cases
344
290
  for (const condition in constraints) {
345
291
  compareTo = constraints[condition];
346
-
347
292
  if (compareTo.__type) {
348
293
  compareTo = decode(compareTo);
349
- } // is it a $relativeTime? convert to date
350
-
351
-
294
+ }
295
+ // is it a $relativeTime? convert to date
352
296
  if (compareTo['$relativeTime']) {
353
297
  const parserResult = relativeTimeToDate(compareTo['$relativeTime']);
354
-
355
298
  if (parserResult.status !== 'success') {
356
299
  throw new ParseError(ParseError.INVALID_JSON, `bad $relativeTime (${key}) value. ${parserResult.info}`);
357
300
  }
358
-
359
301
  compareTo = parserResult.result;
360
- } // Compare Date Object or Date String
361
-
362
-
302
+ }
303
+ // Compare Date Object or Date String
363
304
  if (toString.call(compareTo) === '[object Date]' || typeof compareTo === 'string' && new Date(compareTo) !== 'Invalid Date' && !isNaN(new Date(compareTo))) {
364
305
  object[key] = new Date(object[key].iso ? object[key].iso : object[key]);
365
306
  }
366
-
367
307
  switch (condition) {
368
308
  case '$lt':
369
309
  if (object[key] >= compareTo) {
370
310
  return false;
371
311
  }
372
-
373
312
  break;
374
-
375
313
  case '$lte':
376
314
  if (object[key] > compareTo) {
377
315
  return false;
378
316
  }
379
-
380
317
  break;
381
-
382
318
  case '$gt':
383
319
  if (object[key] <= compareTo) {
384
320
  return false;
385
321
  }
386
-
387
322
  break;
388
-
389
323
  case '$gte':
390
324
  if (object[key] < compareTo) {
391
325
  return false;
392
326
  }
393
-
394
327
  break;
395
-
396
328
  case '$ne':
397
329
  if (equalObjects(object[key], compareTo)) {
398
330
  return false;
399
331
  }
400
-
401
332
  break;
402
-
403
333
  case '$in':
404
334
  if (!contains(compareTo, object[key])) {
405
335
  return false;
406
336
  }
407
-
408
337
  break;
409
-
410
338
  case '$nin':
411
339
  if (contains(compareTo, object[key])) {
412
340
  return false;
413
341
  }
414
-
415
342
  break;
416
-
417
343
  case '$all':
418
344
  for (i = 0; i < compareTo.length; i++) {
419
345
  if (object[key].indexOf(compareTo[i]) < 0) {
420
346
  return false;
421
347
  }
422
348
  }
423
-
424
349
  break;
425
-
426
350
  case '$exists':
427
351
  {
428
352
  const propertyExists = typeof object[key] !== 'undefined';
429
353
  const existenceIsRequired = constraints['$exists'];
430
-
431
354
  if (typeof constraints['$exists'] !== 'boolean') {
432
355
  // The SDK will never submit a non-boolean for $exists, but if someone
433
356
  // tries to submit a non-boolean for $exits outside the SDKs, just ignore it.
434
357
  break;
435
358
  }
436
-
437
359
  if (!propertyExists && existenceIsRequired || propertyExists && !existenceIsRequired) {
438
360
  return false;
439
361
  }
440
-
441
362
  break;
442
363
  }
443
-
444
364
  case '$regex':
445
365
  {
446
366
  if (typeof compareTo === 'object') {
447
367
  return compareTo.test(object[key]);
448
- } // JS doesn't support perl-style escaping
449
-
450
-
368
+ }
369
+ // JS doesn't support perl-style escaping
451
370
  let expString = '';
452
371
  let escapeEnd = -2;
453
372
  let escapeStart = compareTo.indexOf('\\Q');
454
-
455
373
  while (escapeStart > -1) {
456
374
  // Add the unescaped portion
457
375
  expString += compareTo.substring(escapeEnd + 2, escapeStart);
458
376
  escapeEnd = compareTo.indexOf('\\E', escapeStart);
459
-
460
377
  if (escapeEnd > -1) {
461
378
  expString += compareTo.substring(escapeStart + 2, escapeEnd).replace(/\\\\\\\\E/g, '\\E').replace(/\W/g, '\\$&');
462
379
  }
463
-
464
380
  escapeStart = compareTo.indexOf('\\Q', escapeEnd);
465
381
  }
466
-
467
382
  expString += compareTo.substring(Math.max(escapeStart, escapeEnd + 2));
468
383
  let modifiers = constraints.$options || '';
469
- modifiers = modifiers.replace('x', '').replace('s', ''); // Parse Server / Mongo support x and s modifiers but JS RegExp doesn't
470
-
384
+ modifiers = modifiers.replace('x', '').replace('s', '');
385
+ // Parse Server / Mongo support x and s modifiers but JS RegExp doesn't
471
386
  const exp = new RegExp(expString, modifiers);
472
-
473
387
  if (!exp.test(object[key])) {
474
388
  return false;
475
389
  }
476
-
477
390
  break;
478
391
  }
479
-
480
392
  case '$nearSphere':
481
393
  {
482
394
  if (!compareTo || !object[key]) {
483
395
  return false;
484
396
  }
485
-
486
397
  const distance = compareTo.radiansTo(object[key]);
487
398
  const max = constraints.$maxDistance || Infinity;
488
399
  return distance <= max;
489
400
  }
490
-
491
401
  case '$within':
492
402
  {
493
403
  if (!compareTo || !object[key]) {
494
404
  return false;
495
405
  }
496
-
497
406
  const southWest = compareTo.$box[0];
498
407
  const northEast = compareTo.$box[1];
499
-
500
408
  if (southWest.latitude > northEast.latitude || southWest.longitude > northEast.longitude) {
501
409
  // Invalid box, crosses the date line
502
410
  return false;
503
411
  }
504
-
505
412
  return object[key].latitude > southWest.latitude && object[key].latitude < northEast.latitude && object[key].longitude > southWest.longitude && object[key].longitude < northEast.longitude;
506
413
  }
507
-
508
414
  case '$options':
509
415
  // Not a query type, but a way to add options to $regex. Ignore and
510
416
  // avoid the default
511
417
  break;
512
-
513
418
  case '$maxDistance':
514
419
  // Not a query type, but a way to add a cap to $nearSphere. Ignore and
515
420
  // avoid the default
516
421
  break;
517
-
518
422
  case '$select':
519
423
  {
520
424
  const subQueryObjects = objects.filter((obj, index, arr) => {
521
425
  return matchesQuery(compareTo.query.className, obj, arr, compareTo.query.where);
522
426
  });
523
-
524
427
  for (let i = 0; i < subQueryObjects.length; i += 1) {
525
428
  const subObject = transformObject(subQueryObjects[i]);
526
429
  return equalObjects(object[key], subObject[compareTo.key]);
527
430
  }
528
-
529
431
  return false;
530
432
  }
531
-
532
433
  case '$dontSelect':
533
434
  {
534
435
  const subQueryObjects = objects.filter((obj, index, arr) => {
535
436
  return matchesQuery(compareTo.query.className, obj, arr, compareTo.query.where);
536
437
  });
537
-
538
438
  for (let i = 0; i < subQueryObjects.length; i += 1) {
539
439
  const subObject = transformObject(subQueryObjects[i]);
540
440
  return !equalObjects(object[key], subObject[compareTo.key]);
541
441
  }
542
-
543
442
  return false;
544
443
  }
545
-
546
444
  case '$inQuery':
547
445
  {
548
446
  const subQueryObjects = objects.filter((obj, index, arr) => {
549
447
  return matchesQuery(compareTo.className, obj, arr, compareTo.where);
550
448
  });
551
-
552
449
  for (let i = 0; i < subQueryObjects.length; i += 1) {
553
450
  const subObject = transformObject(subQueryObjects[i]);
554
-
555
451
  if (object[key].className === subObject.className && object[key].objectId === subObject.objectId) {
556
452
  return true;
557
453
  }
558
454
  }
559
-
560
455
  return false;
561
456
  }
562
-
563
457
  case '$notInQuery':
564
458
  {
565
459
  const subQueryObjects = objects.filter((obj, index, arr) => {
566
460
  return matchesQuery(compareTo.className, obj, arr, compareTo.where);
567
461
  });
568
-
569
462
  for (let i = 0; i < subQueryObjects.length; i += 1) {
570
463
  const subObject = transformObject(subQueryObjects[i]);
571
-
572
464
  if (object[key].className === subObject.className && object[key].objectId === subObject.objectId) {
573
465
  return false;
574
466
  }
575
467
  }
576
-
577
468
  return true;
578
469
  }
579
-
580
470
  case '$containedBy':
581
471
  {
582
472
  for (const value of object[key]) {
@@ -584,10 +474,8 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
584
474
  return false;
585
475
  }
586
476
  }
587
-
588
477
  return true;
589
478
  }
590
-
591
479
  case '$geoWithin':
592
480
  {
593
481
  if (compareTo.$polygon) {
@@ -595,7 +483,6 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
595
483
  const polygon = new ParsePolygon(points);
596
484
  return polygon.containsPoint(object[key]);
597
485
  }
598
-
599
486
  if (compareTo.$centerSphere) {
600
487
  const [WGS84Point, maxDistance] = compareTo.$centerSphere;
601
488
  const centerPoint = new ParseGeoPoint({
@@ -606,34 +493,25 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
606
493
  const distance = point.radiansTo(centerPoint);
607
494
  return distance <= maxDistance;
608
495
  }
609
-
610
496
  break;
611
497
  }
612
-
613
498
  case '$geoIntersects':
614
499
  {
615
500
  const polygon = new ParsePolygon(object[key].coordinates);
616
501
  const point = new ParseGeoPoint(compareTo.$point);
617
502
  return polygon.containsPoint(point);
618
503
  }
619
-
620
504
  default:
621
505
  return false;
622
506
  }
623
507
  }
624
-
625
508
  return true;
626
509
  }
627
-
628
- function validateQuery(query
629
- /*: any*/
630
- ) {
510
+ function validateQuery(query /*: any*/) {
631
511
  let q = query;
632
-
633
512
  if (query.toJSON) {
634
513
  q = query.toJSON().where;
635
514
  }
636
-
637
515
  const specialQuerykeys = ['$and', '$or', '$nor', '_rperm', '_wperm', '_perishable_token', '_email_verify_token', '_email_verify_token_expires_at', '_account_lockout_expires_at', '_failed_login_count'];
638
516
  Object.keys(q).forEach(key => {
639
517
  if (q && q[key] && q[key].$regex) {
@@ -643,13 +521,11 @@ function validateQuery(query
643
521
  }
644
522
  }
645
523
  }
646
-
647
524
  if (specialQuerykeys.indexOf(key) < 0 && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
648
525
  throw new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: ${key}`);
649
526
  }
650
527
  });
651
528
  }
652
-
653
529
  const OfflineQuery = {
654
530
  matchesQuery: matchesQuery,
655
531
  validateQuery: validateQuery