parse 5.1.1-alpha.1 → 5.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/parse.js +10186 -14918
  2. package/dist/parse.min.js +2 -2
  3. package/dist/parse.weapp.js +10180 -15057
  4. package/dist/parse.weapp.min.js +2 -2
  5. package/lib/browser/Analytics.js +7 -11
  6. package/lib/browser/AnonymousUtils.js +17 -22
  7. package/lib/browser/Cloud.js +24 -46
  8. package/lib/browser/CoreManager.js +71 -79
  9. package/lib/browser/CryptoController.js +14 -9
  10. package/lib/browser/EventEmitter.js +9 -2
  11. package/lib/browser/EventuallyQueue.js +156 -357
  12. package/lib/browser/FacebookUtils.js +23 -28
  13. package/lib/browser/IndexedDBStorageController.js +18 -14
  14. package/lib/browser/InstallationController.js +55 -121
  15. package/lib/browser/LiveQueryClient.js +312 -446
  16. package/lib/browser/LiveQuerySubscription.js +25 -28
  17. package/lib/browser/LocalDatastore.js +254 -578
  18. package/lib/browser/LocalDatastoreController.default.js +48 -227
  19. package/lib/browser/LocalDatastoreController.js +11 -1
  20. package/lib/browser/LocalDatastoreController.react-native.js +72 -164
  21. package/lib/browser/LocalDatastoreUtils.js +4 -12
  22. package/lib/browser/ObjectStateMutations.js +89 -95
  23. package/lib/browser/OfflineQuery.js +106 -198
  24. package/lib/browser/Parse.js +45 -61
  25. package/lib/browser/ParseACL.js +242 -288
  26. package/lib/browser/ParseCLP.js +372 -580
  27. package/lib/browser/ParseConfig.js +115 -138
  28. package/lib/browser/ParseError.js +85 -182
  29. package/lib/browser/ParseFile.js +296 -444
  30. package/lib/browser/ParseGeoPoint.js +121 -140
  31. package/lib/browser/ParseHooks.js +12 -14
  32. package/lib/browser/ParseInstallation.js +226 -354
  33. package/lib/browser/ParseLiveQuery.js +74 -148
  34. package/lib/browser/ParseObject.js +2017 -2622
  35. package/lib/browser/ParseOp.js +343 -484
  36. package/lib/browser/ParsePolygon.js +101 -120
  37. package/lib/browser/ParseQuery.js +1722 -2068
  38. package/lib/browser/ParseRelation.js +99 -118
  39. package/lib/browser/ParseRole.js +88 -144
  40. package/lib/browser/ParseSchema.js +372 -434
  41. package/lib/browser/ParseSession.js +62 -110
  42. package/lib/browser/ParseUser.js +942 -1270
  43. package/lib/browser/Push.js +16 -44
  44. package/lib/browser/RESTController.js +85 -124
  45. package/lib/browser/SingleInstanceStateController.js +57 -86
  46. package/lib/browser/Socket.weapp.js +50 -33
  47. package/lib/browser/Storage.js +23 -28
  48. package/lib/browser/StorageController.browser.js +16 -13
  49. package/lib/browser/StorageController.default.js +15 -14
  50. package/lib/browser/StorageController.js +14 -1
  51. package/lib/browser/StorageController.react-native.js +31 -30
  52. package/lib/browser/StorageController.weapp.js +19 -13
  53. package/lib/browser/TaskQueue.js +37 -49
  54. package/lib/browser/UniqueInstanceStateController.js +65 -86
  55. package/lib/browser/WebSocketController.js +11 -4
  56. package/lib/browser/Xhr.weapp.js +90 -78
  57. package/lib/browser/arrayContainsObject.js +3 -3
  58. package/lib/browser/canBeSerialized.js +10 -11
  59. package/lib/browser/decode.js +11 -11
  60. package/lib/browser/encode.js +11 -11
  61. package/lib/browser/equals.js +9 -10
  62. package/lib/browser/escape.js +2 -2
  63. package/lib/browser/isRevocableSession.js +1 -1
  64. package/lib/browser/parseDate.js +10 -10
  65. package/lib/browser/promiseUtils.js +19 -19
  66. package/lib/browser/unique.js +4 -4
  67. package/lib/browser/unsavedChildren.js +20 -21
  68. package/lib/browser/uuid.js +2 -4
  69. package/lib/node/Analytics.js +2 -6
  70. package/lib/node/AnonymousUtils.js +7 -12
  71. package/lib/node/Cloud.js +8 -12
  72. package/lib/node/CoreManager.js +59 -67
  73. package/lib/node/CryptoController.js +8 -3
  74. package/lib/node/EventEmitter.js +7 -1
  75. package/lib/node/EventuallyQueue.js +18 -37
  76. package/lib/node/FacebookUtils.js +1 -5
  77. package/lib/node/IndexedDBStorageController.js +14 -10
  78. package/lib/node/InstallationController.js +7 -8
  79. package/lib/node/LiveQueryClient.js +20 -32
  80. package/lib/node/LiveQuerySubscription.js +3 -4
  81. package/lib/node/LocalDatastore.js +20 -24
  82. package/lib/node/LocalDatastoreController.default.js +12 -11
  83. package/lib/node/LocalDatastoreController.js +14 -1
  84. package/lib/node/LocalDatastoreController.react-native.js +27 -22
  85. package/lib/node/LocalDatastoreUtils.js +4 -12
  86. package/lib/node/ObjectStateMutations.js +52 -36
  87. package/lib/node/OfflineQuery.js +37 -23
  88. package/lib/node/Parse.js +35 -49
  89. package/lib/node/ParseACL.js +18 -27
  90. package/lib/node/ParseCLP.js +38 -50
  91. package/lib/node/ParseConfig.js +7 -14
  92. package/lib/node/ParseError.js +457 -458
  93. package/lib/node/ParseFile.js +33 -66
  94. package/lib/node/ParseGeoPoint.js +22 -17
  95. package/lib/node/ParseHooks.js +0 -2
  96. package/lib/node/ParseInstallation.js +21 -8
  97. package/lib/node/ParseLiveQuery.js +6 -11
  98. package/lib/node/ParseObject.js +138 -167
  99. package/lib/node/ParseOp.js +32 -44
  100. package/lib/node/ParsePolygon.js +11 -17
  101. package/lib/node/ParseQuery.js +118 -164
  102. package/lib/node/ParseRelation.js +7 -16
  103. package/lib/node/ParseRole.js +7 -13
  104. package/lib/node/ParseSchema.js +26 -39
  105. package/lib/node/ParseSession.js +7 -8
  106. package/lib/node/ParseUser.js +70 -76
  107. package/lib/node/Push.js +5 -15
  108. package/lib/node/RESTController.js +21 -33
  109. package/lib/node/SingleInstanceStateController.js +41 -69
  110. package/lib/node/Socket.weapp.js +23 -2
  111. package/lib/node/Storage.js +11 -16
  112. package/lib/node/StorageController.browser.js +10 -8
  113. package/lib/node/StorageController.default.js +9 -9
  114. package/lib/node/StorageController.js +16 -1
  115. package/lib/node/StorageController.react-native.js +17 -17
  116. package/lib/node/StorageController.weapp.js +14 -8
  117. package/lib/node/TaskQueue.js +8 -11
  118. package/lib/node/UniqueInstanceStateController.js +40 -60
  119. package/lib/node/WebSocketController.js +15 -2
  120. package/lib/node/Xhr.weapp.js +11 -2
  121. package/lib/node/arrayContainsObject.js +1 -1
  122. package/lib/node/canBeSerialized.js +2 -2
  123. package/lib/node/decode.js +1 -1
  124. package/lib/node/encode.js +2 -2
  125. package/lib/node/equals.js +1 -1
  126. package/lib/node/escape.js +1 -1
  127. package/lib/node/isRevocableSession.js +1 -1
  128. package/lib/node/parseDate.js +1 -1
  129. package/lib/node/promiseUtils.js +7 -7
  130. package/lib/node/unique.js +2 -2
  131. package/lib/node/unsavedChildren.js +2 -2
  132. package/lib/node/uuid.js +2 -4
  133. package/lib/react-native/Analytics.js +2 -2
  134. package/lib/react-native/AnonymousUtils.js +3 -4
  135. package/lib/react-native/Cloud.js +0 -1
  136. package/lib/react-native/CoreManager.js +2 -3
  137. package/lib/react-native/CryptoController.js +6 -1
  138. package/lib/react-native/EventEmitter.js +6 -1
  139. package/lib/react-native/EventuallyQueue.js +1 -2
  140. package/lib/react-native/FacebookUtils.js +1 -2
  141. package/lib/react-native/IndexedDBStorageController.js +11 -5
  142. package/lib/react-native/InstallationController.js +1 -2
  143. package/lib/react-native/LiveQueryClient.js +51 -36
  144. package/lib/react-native/LiveQuerySubscription.js +2 -4
  145. package/lib/react-native/LocalDatastore.js +41 -17
  146. package/lib/react-native/LocalDatastoreController.default.js +6 -1
  147. package/lib/react-native/LocalDatastoreController.js +11 -1
  148. package/lib/react-native/LocalDatastoreController.react-native.js +16 -11
  149. package/lib/react-native/LocalDatastoreUtils.js +3 -6
  150. package/lib/react-native/ObjectStateMutations.js +30 -9
  151. package/lib/react-native/OfflineQuery.js +25 -20
  152. package/lib/react-native/Parse.js +24 -38
  153. package/lib/react-native/ParseACL.js +4 -6
  154. package/lib/react-native/ParseCLP.js +5 -7
  155. package/lib/react-native/ParseConfig.js +4 -6
  156. package/lib/react-native/ParseError.js +13 -31
  157. package/lib/react-native/ParseFile.js +10 -10
  158. package/lib/react-native/ParseGeoPoint.js +2 -4
  159. package/lib/react-native/ParseInstallation.js +13 -30
  160. package/lib/react-native/ParseLiveQuery.js +2 -4
  161. package/lib/react-native/ParseObject.js +81 -90
  162. package/lib/react-native/ParseOp.js +41 -79
  163. package/lib/react-native/ParsePolygon.js +2 -4
  164. package/lib/react-native/ParseQuery.js +87 -81
  165. package/lib/react-native/ParseRelation.js +2 -4
  166. package/lib/react-native/ParseRole.js +14 -31
  167. package/lib/react-native/ParseSchema.js +3 -5
  168. package/lib/react-native/ParseSession.js +12 -29
  169. package/lib/react-native/ParseUser.js +32 -51
  170. package/lib/react-native/RESTController.js +10 -4
  171. package/lib/react-native/SingleInstanceStateController.js +23 -37
  172. package/lib/react-native/Socket.weapp.js +9 -4
  173. package/lib/react-native/Storage.js +1 -2
  174. package/lib/react-native/StorageController.browser.js +6 -1
  175. package/lib/react-native/StorageController.default.js +6 -1
  176. package/lib/react-native/StorageController.js +13 -1
  177. package/lib/react-native/StorageController.react-native.js +11 -6
  178. package/lib/react-native/StorageController.weapp.js +6 -1
  179. package/lib/react-native/TaskQueue.js +8 -4
  180. package/lib/react-native/UniqueInstanceStateController.js +23 -37
  181. package/lib/react-native/WebSocketController.js +9 -1
  182. package/lib/react-native/Xhr.weapp.js +9 -4
  183. package/lib/react-native/unsavedChildren.js +3 -3
  184. package/lib/react-native/uuid.js +1 -2
  185. package/lib/weapp/Analytics.js +7 -11
  186. package/lib/weapp/AnonymousUtils.js +17 -22
  187. package/lib/weapp/Cloud.js +24 -46
  188. package/lib/weapp/CoreManager.js +71 -79
  189. package/lib/weapp/CryptoController.js +14 -9
  190. package/lib/weapp/EventEmitter.js +9 -2
  191. package/lib/weapp/EventuallyQueue.js +156 -357
  192. package/lib/weapp/FacebookUtils.js +23 -28
  193. package/lib/weapp/IndexedDBStorageController.js +18 -14
  194. package/lib/weapp/InstallationController.js +55 -121
  195. package/lib/weapp/LiveQueryClient.js +312 -446
  196. package/lib/weapp/LiveQuerySubscription.js +25 -28
  197. package/lib/weapp/LocalDatastore.js +254 -578
  198. package/lib/weapp/LocalDatastoreController.default.js +48 -227
  199. package/lib/weapp/LocalDatastoreController.js +11 -1
  200. package/lib/weapp/LocalDatastoreController.react-native.js +72 -164
  201. package/lib/weapp/LocalDatastoreUtils.js +4 -12
  202. package/lib/weapp/ObjectStateMutations.js +89 -95
  203. package/lib/weapp/OfflineQuery.js +106 -198
  204. package/lib/weapp/Parse.js +45 -60
  205. package/lib/weapp/ParseACL.js +242 -288
  206. package/lib/weapp/ParseCLP.js +372 -580
  207. package/lib/weapp/ParseConfig.js +115 -138
  208. package/lib/weapp/ParseError.js +85 -182
  209. package/lib/weapp/ParseFile.js +297 -446
  210. package/lib/weapp/ParseGeoPoint.js +121 -140
  211. package/lib/weapp/ParseHooks.js +12 -14
  212. package/lib/weapp/ParseInstallation.js +226 -354
  213. package/lib/weapp/ParseLiveQuery.js +74 -148
  214. package/lib/weapp/ParseObject.js +2017 -2622
  215. package/lib/weapp/ParseOp.js +343 -484
  216. package/lib/weapp/ParsePolygon.js +101 -120
  217. package/lib/weapp/ParseQuery.js +1722 -2068
  218. package/lib/weapp/ParseRelation.js +99 -118
  219. package/lib/weapp/ParseRole.js +88 -144
  220. package/lib/weapp/ParseSchema.js +372 -434
  221. package/lib/weapp/ParseSession.js +62 -110
  222. package/lib/weapp/ParseUser.js +942 -1270
  223. package/lib/weapp/Push.js +16 -44
  224. package/lib/weapp/RESTController.js +86 -125
  225. package/lib/weapp/SingleInstanceStateController.js +57 -86
  226. package/lib/weapp/Socket.weapp.js +50 -33
  227. package/lib/weapp/Storage.js +23 -28
  228. package/lib/weapp/StorageController.browser.js +16 -13
  229. package/lib/weapp/StorageController.default.js +15 -14
  230. package/lib/weapp/StorageController.js +14 -1
  231. package/lib/weapp/StorageController.react-native.js +31 -30
  232. package/lib/weapp/StorageController.weapp.js +19 -13
  233. package/lib/weapp/TaskQueue.js +37 -49
  234. package/lib/weapp/UniqueInstanceStateController.js +65 -86
  235. package/lib/weapp/WebSocketController.js +11 -4
  236. package/lib/weapp/Xhr.weapp.js +90 -78
  237. package/lib/weapp/arrayContainsObject.js +3 -3
  238. package/lib/weapp/canBeSerialized.js +10 -11
  239. package/lib/weapp/decode.js +11 -11
  240. package/lib/weapp/encode.js +11 -11
  241. package/lib/weapp/equals.js +9 -10
  242. package/lib/weapp/escape.js +2 -2
  243. package/lib/weapp/isRevocableSession.js +1 -1
  244. package/lib/weapp/parseDate.js +10 -10
  245. package/lib/weapp/promiseUtils.js +19 -19
  246. package/lib/weapp/unique.js +4 -4
  247. package/lib/weapp/unsavedChildren.js +20 -21
  248. package/lib/weapp/uuid.js +6 -8
  249. package/package.json +23 -30
@@ -6,20 +6,13 @@ _Object$defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = void 0;
9
- var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
11
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/toConsumableArray"));
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
13
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
15
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
16
- var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
17
10
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
18
11
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
19
12
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
20
13
  var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
21
- var _map2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
22
- var _filter2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
14
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
15
+ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
23
16
  var _keys2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/keys"));
24
17
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
25
18
  var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
@@ -37,33 +30,6 @@ var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
37
30
  var _ParseObject = _interopRequireDefault(require("./ParseObject"));
38
31
  var _OfflineQuery = _interopRequireDefault(require("./OfflineQuery"));
39
32
  var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
40
- /*
41
- * @flow
42
- */
43
- /*:: import type LiveQuerySubscription from './LiveQuerySubscription';*/
44
- /*:: import type { RequestOptions, FullOptions } from './RESTController';*/
45
- /*:: type BatchOptions = FullOptions & { batchSize?: number };*/
46
- /*:: export type WhereClause = {
47
- [attr: string]: mixed,
48
- };*/
49
- /*:: export type QueryJSON = {
50
- where: WhereClause,
51
- watch?: string,
52
- include?: string,
53
- excludeKeys?: string,
54
- keys?: string,
55
- limit?: number,
56
- skip?: number,
57
- order?: string,
58
- className?: string,
59
- count?: number,
60
- hint?: mixed,
61
- explain?: boolean,
62
- readPreference?: string,
63
- includeReadPreference?: string,
64
- subqueryReadPreference?: string,
65
- comment?: string,
66
- };*/
67
33
  /**
68
34
  * Converts a string into a regex that matches it.
69
35
  * Surrounding with \Q .. \E does this, we just need to escape any \E's in
@@ -73,7 +39,7 @@ var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
73
39
  * @private
74
40
  * @returns {string}
75
41
  */
76
- function quote(s /*: string*/) /*: string*/{
42
+ function quote(s) {
77
43
  return '\\Q' + s.replace('\\E', '\\E\\\\E\\Q') + '\\E';
78
44
  }
79
45
 
@@ -85,9 +51,9 @@ function quote(s /*: string*/) /*: string*/{
85
51
  * @private
86
52
  * @returns {string}
87
53
  */
88
- function _getClassNameFromQueries(queries /*: Array<ParseQuery>*/) /*: ?string*/{
89
- var className = null;
90
- (0, _forEach.default)(queries).call(queries, function (q) {
54
+ function _getClassNameFromQueries(queries) {
55
+ let className = null;
56
+ (0, _forEach.default)(queries).call(queries, q => {
91
57
  if (!className) {
92
58
  className = q.className;
93
59
  }
@@ -103,26 +69,26 @@ function _getClassNameFromQueries(queries /*: Array<ParseQuery>*/) /*: ?string*/
103
69
  * making sure that the data object contains keys for all objects that have
104
70
  * been requested with a select, so that our cached state updates correctly.
105
71
  */
106
- function handleSelectResult(data /*: any*/, select /*: Array<string>*/) {
107
- var serverDataMask = {};
108
- (0, _forEach.default)(select).call(select, function (field) {
109
- var hasSubObjectSelect = (0, _indexOf.default)(field).call(field, '.') !== -1;
72
+ function handleSelectResult(data, select) {
73
+ const serverDataMask = {};
74
+ (0, _forEach.default)(select).call(select, field => {
75
+ const hasSubObjectSelect = (0, _indexOf.default)(field).call(field, '.') !== -1;
110
76
  if (!hasSubObjectSelect && !data.hasOwnProperty(field)) {
111
77
  // this field was selected, but is missing from the retrieved data
112
78
  data[field] = undefined;
113
79
  } else if (hasSubObjectSelect) {
114
80
  // this field references a sub-object,
115
81
  // so we need to walk down the path components
116
- var pathComponents = field.split('.');
117
- var _obj = data;
118
- var serverMask = serverDataMask;
119
- (0, _forEach.default)(pathComponents).call(pathComponents, function (component, index, arr) {
82
+ const pathComponents = field.split('.');
83
+ let obj = data;
84
+ let serverMask = serverDataMask;
85
+ (0, _forEach.default)(pathComponents).call(pathComponents, (component, index, arr) => {
120
86
  // add keys if the expected data is missing
121
- if (_obj && !_obj.hasOwnProperty(component)) {
122
- _obj[component] = undefined;
87
+ if (obj && !obj.hasOwnProperty(component)) {
88
+ obj[component] = undefined;
123
89
  }
124
- if (_obj && (0, _typeof2.default)(_obj) === 'object') {
125
- _obj = _obj[component];
90
+ if (obj && typeof obj === 'object') {
91
+ obj = obj[component];
126
92
  }
127
93
 
128
94
  //add this path component to the server mask so we can fill it in later if needed
@@ -141,7 +107,7 @@ function handleSelectResult(data /*: any*/, select /*: Array<string>*/) {
141
107
  // missing selected keys to sub-objects, but we still need to add in the
142
108
  // data for any previously retrieved sub-objects that were not selected.
143
109
 
144
- var serverData = _CoreManager.default.getObjectStateController().getServerData({
110
+ const serverData = _CoreManager.default.getObjectStateController().getServerData({
145
111
  id: data.objectId,
146
112
  className: data.className
147
113
  });
@@ -151,23 +117,23 @@ function handleSelectResult(data /*: any*/, select /*: Array<string>*/) {
151
117
  function copyMissingDataWithMask(src, dest, mask, copyThisLevel) {
152
118
  //copy missing elements at this level
153
119
  if (copyThisLevel) {
154
- for (var _key in src) {
155
- if (src.hasOwnProperty(_key) && !dest.hasOwnProperty(_key)) {
156
- dest[_key] = src[_key];
120
+ for (const key in src) {
121
+ if (src.hasOwnProperty(key) && !dest.hasOwnProperty(key)) {
122
+ dest[key] = src[key];
157
123
  }
158
124
  }
159
125
  }
160
- for (var _key2 in mask) {
161
- if (dest[_key2] !== undefined && dest[_key2] !== null && src !== undefined && src !== null) {
126
+ for (const key in mask) {
127
+ if (dest[key] !== undefined && dest[key] !== null && src !== undefined && src !== null) {
162
128
  //traverse into objects as needed
163
- copyMissingDataWithMask(src[_key2], dest[_key2], mask[_key2], true);
129
+ copyMissingDataWithMask(src[key], dest[key], mask[key], true);
164
130
  }
165
131
  }
166
132
  }
167
133
  function handleOfflineSort(a, b, sorts) {
168
- var order = sorts[0];
169
- var operator = (0, _slice.default)(order).call(order, 0, 1);
170
- var isDescending = operator === '-';
134
+ let order = sorts[0];
135
+ const operator = (0, _slice.default)(order).call(order, 0, 1);
136
+ const isDescending = operator === '-';
171
137
  if (isDescending) {
172
138
  order = order.substring(1);
173
139
  }
@@ -178,10 +144,10 @@ function handleOfflineSort(a, b, sorts) {
178
144
  order = 'updatedAt';
179
145
  }
180
146
  if (!/^[A-Za-z][0-9A-Za-z_]*$/.test(order) || order === 'password') {
181
- throw new _ParseError.default(_ParseError.default.INVALID_KEY_NAME, "Invalid Key: ".concat(order));
147
+ throw new _ParseError.default(_ParseError.default.INVALID_KEY_NAME, `Invalid Key: ${order}`);
182
148
  }
183
- var field1 = a.get(order);
184
- var field2 = b.get(order);
149
+ const field1 = a.get(order);
150
+ const field2 = b.get(order);
185
151
  if (field1 < field2) {
186
152
  return isDescending ? 1 : -1;
187
153
  }
@@ -189,7 +155,7 @@ function handleOfflineSort(a, b, sorts) {
189
155
  return isDescending ? -1 : 1;
190
156
  }
191
157
  if (sorts.length > 1) {
192
- var remainingSorts = (0, _slice.default)(sorts).call(sorts, 1);
158
+ const remainingSorts = (0, _slice.default)(sorts).call(sorts, 1);
193
159
  return handleOfflineSort(a, b, remainingSorts);
194
160
  }
195
161
  return 0;
@@ -237,12 +203,11 @@ function handleOfflineSort(a, b, sorts) {
237
203
  *
238
204
  * @alias Parse.Query
239
205
  */
240
- var ParseQuery = /*#__PURE__*/function () {
206
+ class ParseQuery {
241
207
  /**
242
208
  * @param {(string | Parse.Object)} objectClass An instance of a subclass of Parse.Object, or a Parse className string.
243
209
  */
244
- function ParseQuery(objectClass /*: string | ParseObject*/) {
245
- (0, _classCallCheck2.default)(this, ParseQuery);
210
+ constructor(objectClass) {
246
211
  /**
247
212
  * @property {string} className
248
213
  */
@@ -275,11 +240,12 @@ var ParseQuery = /*#__PURE__*/function () {
275
240
  } else if (objectClass instanceof _ParseObject.default) {
276
241
  this.className = objectClass.className;
277
242
  } else if (typeof objectClass === 'function') {
278
- if (typeof objectClass.className === 'string') {
279
- this.className = objectClass.className;
243
+ const objClass = objectClass;
244
+ if (typeof objClass.className === 'string') {
245
+ this.className = objClass.className;
280
246
  } else {
281
- var _obj2 = new objectClass();
282
- this.className = _obj2.className;
247
+ const obj = new objClass();
248
+ this.className = obj.className;
283
249
  }
284
250
  } else {
285
251
  throw new TypeError('A ParseQuery must be constructed with a ParseObject or class name.');
@@ -299,7 +265,7 @@ var ParseQuery = /*#__PURE__*/function () {
299
265
  this._extraOptions = {};
300
266
  this._xhrRequest = {
301
267
  task: null,
302
- onchange: function () {}
268
+ onchange: () => {}
303
269
  };
304
270
  this._comment = null;
305
271
  }
@@ -310,2121 +276,1809 @@ var ParseQuery = /*#__PURE__*/function () {
310
276
  * @param {Array} queries
311
277
  * @returns {Parse.Query} Returns the query, so you can chain this call.
312
278
  */
313
- (0, _createClass2.default)(ParseQuery, [{
314
- key: "_orQuery",
315
- value: function (queries /*: Array<ParseQuery>*/) /*: ParseQuery*/{
316
- var queryJSON = (0, _map2.default)(queries).call(queries, function (q) {
317
- return q.toJSON().where;
318
- });
319
- this._where.$or = queryJSON;
320
- return this;
279
+ _orQuery(queries) {
280
+ const queryJSON = (0, _map.default)(queries).call(queries, q => {
281
+ return q.toJSON().where;
282
+ });
283
+ this._where.$or = queryJSON;
284
+ return this;
285
+ }
286
+
287
+ /**
288
+ * Adds constraint that all of the passed in queries match.
289
+ *
290
+ * @param {Array} queries
291
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
292
+ */
293
+ _andQuery(queries) {
294
+ const queryJSON = (0, _map.default)(queries).call(queries, q => {
295
+ return q.toJSON().where;
296
+ });
297
+ this._where.$and = queryJSON;
298
+ return this;
299
+ }
300
+
301
+ /**
302
+ * Adds constraint that none of the passed in queries match.
303
+ *
304
+ * @param {Array} queries
305
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
306
+ */
307
+ _norQuery(queries) {
308
+ const queryJSON = (0, _map.default)(queries).call(queries, q => {
309
+ return q.toJSON().where;
310
+ });
311
+ this._where.$nor = queryJSON;
312
+ return this;
313
+ }
314
+
315
+ /**
316
+ * Helper for condition queries
317
+ *
318
+ * @param key
319
+ * @param condition
320
+ * @param value
321
+ * @returns {Parse.Query}
322
+ */
323
+ _addCondition(key, condition, value) {
324
+ if (!this._where[key] || typeof this._where[key] === 'string') {
325
+ this._where[key] = {};
321
326
  }
327
+ this._where[key][condition] = (0, _encode.default)(value, false, true);
328
+ return this;
329
+ }
322
330
 
323
- /**
324
- * Adds constraint that all of the passed in queries match.
325
- *
326
- * @param {Array} queries
327
- * @returns {Parse.Query} Returns the query, so you can chain this call.
328
- */
329
- }, {
330
- key: "_andQuery",
331
- value: function (queries /*: Array<ParseQuery>*/) /*: ParseQuery*/{
332
- var queryJSON = (0, _map2.default)(queries).call(queries, function (q) {
333
- return q.toJSON().where;
331
+ /**
332
+ * Converts string for regular expression at the beginning
333
+ *
334
+ * @param string
335
+ * @returns {string}
336
+ */
337
+ _regexStartWith(string) {
338
+ return '^' + quote(string);
339
+ }
340
+ async _handleOfflineQuery(params) {
341
+ var _context;
342
+ _OfflineQuery.default.validateQuery(this);
343
+ const localDatastore = _CoreManager.default.getLocalDatastore();
344
+ const objects = await localDatastore._serializeObjectsFromPinName(this._localDatastorePinName);
345
+ let results = (0, _filter.default)(_context = (0, _map.default)(objects).call(objects, (json, index, arr) => {
346
+ const object = _ParseObject.default.fromJSON(json, false);
347
+ if (json._localId && !json.objectId) {
348
+ object._localId = json._localId;
349
+ }
350
+ if (!_OfflineQuery.default.matchesQuery(this.className, object, arr, this)) {
351
+ return null;
352
+ }
353
+ return object;
354
+ })).call(_context, object => object !== null);
355
+ if ((0, _keys2.default)(params)) {
356
+ let keys = (0, _keys2.default)(params).split(',');
357
+ keys = (0, _concat.default)(keys).call(keys, ['className', 'objectId', 'createdAt', 'updatedAt', 'ACL']);
358
+ results = (0, _map.default)(results).call(results, object => {
359
+ var _context2;
360
+ const json = object._toFullJSON();
361
+ (0, _forEach.default)(_context2 = (0, _keys.default)(json)).call(_context2, key => {
362
+ if (!(0, _includes.default)(keys).call(keys, key)) {
363
+ delete json[key];
364
+ }
365
+ });
366
+ return _ParseObject.default.fromJSON(json, false);
334
367
  });
335
- this._where.$and = queryJSON;
336
- return this;
337
368
  }
338
-
339
- /**
340
- * Adds constraint that none of the passed in queries match.
341
- *
342
- * @param {Array} queries
343
- * @returns {Parse.Query} Returns the query, so you can chain this call.
344
- */
345
- }, {
346
- key: "_norQuery",
347
- value: function (queries /*: Array<ParseQuery>*/) /*: ParseQuery*/{
348
- var queryJSON = (0, _map2.default)(queries).call(queries, function (q) {
349
- return q.toJSON().where;
369
+ if (params.order) {
370
+ const sorts = params.order.split(',');
371
+ (0, _sort.default)(results).call(results, (a, b) => {
372
+ return handleOfflineSort(a, b, sorts);
350
373
  });
351
- this._where.$nor = queryJSON;
352
- return this;
353
374
  }
354
-
355
- /**
356
- * Helper for condition queries
357
- *
358
- * @param key
359
- * @param condition
360
- * @param value
361
- * @returns {Parse.Query}
362
- */
363
- }, {
364
- key: "_addCondition",
365
- value: function (key /*: string*/, condition /*: string*/, value /*: mixed*/) /*: ParseQuery*/{
366
- if (!this._where[key] || typeof this._where[key] === 'string') {
367
- this._where[key] = {};
368
- }
369
- this._where[key][condition] = (0, _encode.default)(value, false, true);
370
- return this;
375
+ let count; // count total before applying limit/skip
376
+ if (params.count) {
377
+ count = results.length; // total count from response
371
378
  }
372
-
373
- /**
374
- * Converts string for regular expression at the beginning
375
- *
376
- * @param string
377
- * @returns {string}
378
- */
379
- }, {
380
- key: "_regexStartWith",
381
- value: function (string /*: string*/) /*: string*/{
382
- return '^' + quote(string);
383
- }
384
- }, {
385
- key: "_handleOfflineQuery",
386
- value: function () {
387
- var _handleOfflineQuery2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(params /*: any*/) {
388
- var _context,
389
- _this2 = this;
390
- var localDatastore, objects, results, keys, alwaysSelectedKeys, sorts, count, limit;
391
- return _regenerator.default.wrap(function (_context3) {
392
- while (1) switch (_context3.prev = _context3.next) {
393
- case 0:
394
- _OfflineQuery.default.validateQuery(this);
395
- localDatastore = _CoreManager.default.getLocalDatastore();
396
- _context3.next = 4;
397
- return localDatastore._serializeObjectsFromPinName(this._localDatastorePinName);
398
- case 4:
399
- objects = _context3.sent;
400
- results = (0, _filter2.default)(_context = (0, _map2.default)(objects).call(objects, function (json, index, arr) {
401
- var object = _ParseObject.default.fromJSON(json, false);
402
- if (json._localId && !json.objectId) {
403
- object._localId = json._localId;
404
- }
405
- if (!_OfflineQuery.default.matchesQuery(_this2.className, object, arr, _this2)) {
406
- return null;
407
- }
408
- return object;
409
- })).call(_context, function (object) {
410
- return object !== null;
411
- });
412
- if ((0, _keys2.default)(params)) {
413
- keys = (0, _keys2.default)(params).split(',');
414
- alwaysSelectedKeys = ['className', 'objectId', 'createdAt', 'updatedAt', 'ACL'];
415
- keys = (0, _concat.default)(keys).call(keys, alwaysSelectedKeys);
416
- results = (0, _map2.default)(results).call(results, function (object) {
417
- var _context2;
418
- var json = object._toFullJSON();
419
- (0, _forEach.default)(_context2 = (0, _keys.default)(json)).call(_context2, function (key) {
420
- if (!(0, _includes.default)(keys).call(keys, key)) {
421
- delete json[key];
422
- }
423
- });
424
- return _ParseObject.default.fromJSON(json, false);
425
- });
426
- }
427
- if (params.order) {
428
- sorts = params.order.split(',');
429
- (0, _sort.default)(results).call(results, function (a, b) {
430
- return handleOfflineSort(a, b, sorts);
431
- });
432
- }
433
- // count total before applying limit/skip
434
- if (params.count) {
435
- count = results.length; // total count from response
436
- }
437
-
438
- if (params.skip) {
439
- if (params.skip >= results.length) {
440
- results = [];
441
- } else {
442
- results = (0, _splice.default)(results).call(results, params.skip, results.length);
443
- }
444
- }
445
- limit = results.length;
446
- if (params.limit !== 0 && params.limit < results.length) {
447
- limit = params.limit;
448
- }
449
- results = (0, _splice.default)(results).call(results, 0, limit);
450
- if (!(typeof count === 'number')) {
451
- _context3.next = 15;
452
- break;
453
- }
454
- return _context3.abrupt("return", {
455
- results: results,
456
- count: count
457
- });
458
- case 15:
459
- return _context3.abrupt("return", results);
460
- case 16:
461
- case "end":
462
- return _context3.stop();
463
- }
464
- }, _callee, this);
465
- }));
466
- function _handleOfflineQuery() {
467
- return _handleOfflineQuery2.apply(this, arguments);
379
+ if (params.skip) {
380
+ if (params.skip >= results.length) {
381
+ results = [];
382
+ } else {
383
+ results = (0, _splice.default)(results).call(results, params.skip, results.length);
468
384
  }
469
- return _handleOfflineQuery;
470
- }()
471
- /**
472
- * Returns a JSON representation of this query.
473
- *
474
- * @returns {object} The JSON representation of the query.
475
- */
476
- }, {
477
- key: "toJSON",
478
- value: function () /*: QueryJSON*/{
479
- var params /*: QueryJSON*/ = {
480
- where: this._where
385
+ }
386
+ let limit = results.length;
387
+ if (params.limit !== 0 && params.limit < results.length) {
388
+ limit = params.limit;
389
+ }
390
+ results = (0, _splice.default)(results).call(results, 0, limit);
391
+ if (typeof count === 'number') {
392
+ return {
393
+ results,
394
+ count
481
395
  };
482
- if (this._watch.length) {
483
- params.watch = this._watch.join(',');
484
- }
485
- if (this._include.length) {
486
- params.include = this._include.join(',');
487
- }
488
- if (this._exclude.length) {
489
- params.excludeKeys = this._exclude.join(',');
490
- }
491
- if (this._select) {
492
- params.keys = this._select.join(',');
493
- }
494
- if (this._count) {
495
- params.count = 1;
496
- }
497
- if (this._limit >= 0) {
498
- params.limit = this._limit;
499
- }
500
- if (this._skip > 0) {
501
- params.skip = this._skip;
502
- }
503
- if (this._order) {
504
- params.order = this._order.join(',');
505
- }
506
- if (this._readPreference) {
507
- params.readPreference = this._readPreference;
508
- }
509
- if (this._includeReadPreference) {
510
- params.includeReadPreference = this._includeReadPreference;
511
- }
512
- if (this._subqueryReadPreference) {
513
- params.subqueryReadPreference = this._subqueryReadPreference;
514
- }
515
- if (this._hint) {
516
- params.hint = this._hint;
517
- }
518
- if (this._explain) {
519
- params.explain = true;
520
- }
521
- if (this._comment) {
522
- params.comment = this._comment;
523
- }
524
- for (var _key3 in this._extraOptions) {
525
- params[_key3] = this._extraOptions[_key3];
526
- }
527
- return params;
528
396
  }
397
+ return results;
398
+ }
529
399
 
530
- /**
531
- * Return a query with conditions from json, can be useful to send query from server side to client
532
- * Not static, all query conditions was set before calling this method will be deleted.
533
- * For example on the server side we have
534
- * var query = new Parse.Query("className");
535
- * query.equalTo(key: value);
536
- * query.limit(100);
537
- * ... (others queries)
538
- * Create JSON representation of Query Object
539
- * var jsonFromServer = query.fromJSON();
540
- *
541
- * On client side getting query:
542
- * var query = new Parse.Query("className");
543
- * query.fromJSON(jsonFromServer);
544
- *
545
- * and continue to query...
546
- * query.skip(100).find().then(...);
547
- *
548
- * @param {QueryJSON} json from Parse.Query.toJSON() method
549
- * @returns {Parse.Query} Returns the query, so you can chain this call.
550
- */
551
- }, {
552
- key: "withJSON",
553
- value: function (json /*: QueryJSON*/) /*: ParseQuery*/{
554
- if (json.where) {
555
- this._where = json.where;
556
- }
557
- if (json.watch) {
558
- this._watch = json.watch.split(',');
559
- }
560
- if (json.include) {
561
- this._include = json.include.split(',');
562
- }
563
- if ((0, _keys2.default)(json)) {
564
- this._select = (0, _keys2.default)(json).split(',');
565
- }
566
- if (json.excludeKeys) {
567
- this._exclude = json.excludeKeys.split(',');
568
- }
569
- if (json.count) {
570
- this._count = json.count === 1;
571
- }
572
- if (json.limit) {
573
- this._limit = json.limit;
574
- }
575
- if (json.skip) {
576
- this._skip = json.skip;
577
- }
578
- if (json.order) {
579
- this._order = json.order.split(',');
580
- }
581
- if (json.readPreference) {
582
- this._readPreference = json.readPreference;
583
- }
584
- if (json.includeReadPreference) {
585
- this._includeReadPreference = json.includeReadPreference;
586
- }
587
- if (json.subqueryReadPreference) {
588
- this._subqueryReadPreference = json.subqueryReadPreference;
589
- }
590
- if (json.hint) {
591
- this._hint = json.hint;
592
- }
593
- if (json.explain) {
594
- this._explain = !!json.explain;
595
- }
596
- if (json.comment) {
597
- this._comment = json.comment;
598
- }
599
- for (var _key4 in json) {
600
- if (json.hasOwnProperty(_key4)) {
601
- var _context4;
602
- if ((0, _indexOf.default)(_context4 = ['where', 'include', 'keys', 'count', 'limit', 'skip', 'order', 'readPreference', 'includeReadPreference', 'subqueryReadPreference', 'hint', 'explain', 'comment']).call(_context4, _key4) === -1) {
603
- this._extraOptions[_key4] = json[_key4];
604
- }
605
- }
606
- }
607
- return this;
400
+ /**
401
+ * Returns a JSON representation of this query.
402
+ *
403
+ * @returns {object} The JSON representation of the query.
404
+ */
405
+ toJSON() {
406
+ const params = {
407
+ where: this._where
408
+ };
409
+ if (this._watch.length) {
410
+ params.watch = this._watch.join(',');
608
411
  }
609
-
610
- /**
611
- * Static method to restore Parse.Query by json representation
612
- * Internally calling Parse.Query.withJSON
613
- *
614
- * @param {string} className
615
- * @param {QueryJSON} json from Parse.Query.toJSON() method
616
- * @returns {Parse.Query} new created query
617
- */
618
- }, {
619
- key: "get",
620
- value:
621
- /**
622
- * Constructs a Parse.Object whose id is already known by fetching data from
623
- * the server. Unlike the <code>first</code> method, it never returns undefined.
624
- *
625
- * @param {string} objectId The id of the object to be fetched.
626
- * @param {object} options
627
- * Valid options are:<ul>
628
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
629
- * be used for this request.
630
- * <li>sessionToken: A valid session token, used for making a request on
631
- * behalf of a specific user.
632
- * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
633
- * <li>json: Return raw json without converting to Parse.Object
634
- * </ul>
635
- * @returns {Promise} A promise that is resolved with the result when
636
- * the query completes.
637
- */
638
- function (objectId /*: string*/, options /*:: ?: FullOptions*/) /*: Promise<ParseObject>*/{
639
- this.equalTo('objectId', objectId);
640
- var firstOptions = {};
641
- if (options && options.hasOwnProperty('useMasterKey')) {
642
- firstOptions.useMasterKey = options.useMasterKey;
643
- }
644
- if (options && options.hasOwnProperty('sessionToken')) {
645
- firstOptions.sessionToken = options.sessionToken;
646
- }
647
- if (options && options.hasOwnProperty('context') && (0, _typeof2.default)(options.context) === 'object') {
648
- firstOptions.context = options.context;
649
- }
650
- if (options && options.hasOwnProperty('json')) {
651
- firstOptions.json = options.json;
652
- }
653
- return this.first(firstOptions).then(function (response) {
654
- if (response) {
655
- return response;
656
- }
657
- var errorObject = new _ParseError.default(_ParseError.default.OBJECT_NOT_FOUND, 'Object not found.');
658
- return _promise.default.reject(errorObject);
659
- });
412
+ if (this._include.length) {
413
+ params.include = this._include.join(',');
660
414
  }
661
-
662
- /**
663
- * Retrieves a list of ParseObjects that satisfy this query.
664
- *
665
- * @param {object} options Valid options
666
- * are:<ul>
667
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
668
- * be used for this request.
669
- * <li>sessionToken: A valid session token, used for making a request on
670
- * behalf of a specific user.
671
- * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
672
- * <li>json: Return raw json without converting to Parse.Object
673
- * </ul>
674
- * @returns {Promise} A promise that is resolved with the results when
675
- * the query completes.
676
- */
677
- }, {
678
- key: "find",
679
- value: function (options /*:: ?: FullOptions*/) /*: Promise<Array<ParseObject>>*/{
680
- var _this3 = this;
681
- options = options || {};
682
- var findOptions = {};
683
- if (options.hasOwnProperty('useMasterKey')) {
684
- findOptions.useMasterKey = options.useMasterKey;
685
- }
686
- if (options.hasOwnProperty('sessionToken')) {
687
- findOptions.sessionToken = options.sessionToken;
688
- }
689
- if (options.hasOwnProperty('context') && (0, _typeof2.default)(options.context) === 'object') {
690
- findOptions.context = options.context;
691
- }
692
- this._setRequestTask(findOptions);
693
- var controller = _CoreManager.default.getQueryController();
694
- var select = this._select;
695
- if (this._queriesLocalDatastore) {
696
- return this._handleOfflineQuery(this.toJSON());
697
- }
698
- return (0, _find.default)(controller).call(controller, this.className, this.toJSON(), findOptions).then(function (response) {
699
- var _context5;
700
- // Return generic object when explain is used
701
- if (_this3._explain) {
702
- return response.results;
703
- }
704
- var results = (0, _map2.default)(_context5 = response.results).call(_context5, function (data) {
705
- // In cases of relations, the server may send back a className
706
- // on the top level of the payload
707
- var override = response.className || _this3.className;
708
- if (!data.className) {
709
- data.className = override;
710
- }
711
-
712
- // Make sure the data object contains keys for all objects that
713
- // have been requested with a select, so that our cached state
714
- // updates correctly.
715
- if (select) {
716
- handleSelectResult(data, select);
717
- }
718
- if (options.json) {
719
- return data;
720
- } else {
721
- return _ParseObject.default.fromJSON(data, !select);
722
- }
723
- });
724
- var count = response.count;
725
- if (typeof count === 'number') {
726
- return {
727
- results: results,
728
- count: count
729
- };
730
- } else {
731
- return results;
732
- }
733
- });
415
+ if (this._exclude.length) {
416
+ params.excludeKeys = this._exclude.join(',');
734
417
  }
735
-
736
- /**
737
- * Retrieves a complete list of ParseObjects that satisfy this query.
738
- * Using `eachBatch` under the hood to fetch all the valid objects.
739
- *
740
- * @param {object} options Valid options are:<ul>
741
- * <li>batchSize: How many objects to yield in each batch (default: 100)
742
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
743
- * be used for this request.
744
- * <li>sessionToken: A valid session token, used for making a request on
745
- * behalf of a specific user.
746
- * </ul>
747
- * @returns {Promise} A promise that is resolved with the results when
748
- * the query completes.
749
- */
750
- }, {
751
- key: "findAll",
752
- value: function () {
753
- var _findAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(options /*:: ?: BatchOptions*/) {
754
- var result;
755
- return _regenerator.default.wrap(function (_context7) {
756
- while (1) switch (_context7.prev = _context7.next) {
757
- case 0:
758
- result /*: ParseObject[]*/ = [];
759
- _context7.next = 3;
760
- return this.eachBatch(function (objects /*: ParseObject[]*/) {
761
- var _context6;
762
- result = (0, _concat.default)(_context6 = []).call(_context6, (0, _toConsumableArray2.default)(result), (0, _toConsumableArray2.default)(objects));
763
- }, options);
764
- case 3:
765
- return _context7.abrupt("return", result);
766
- case 4:
767
- case "end":
768
- return _context7.stop();
769
- }
770
- }, _callee2, this);
771
- }));
772
- function findAll() {
773
- return _findAll.apply(this, arguments);
774
- }
775
- return findAll;
776
- }()
777
- /**
778
- * Counts the number of objects that match this query.
779
- *
780
- * @param {object} options
781
- * Valid options are:<ul>
782
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
783
- * be used for this request.
784
- * <li>sessionToken: A valid session token, used for making a request on
785
- * behalf of a specific user.
786
- * </ul>
787
- * @returns {Promise} A promise that is resolved with the count when
788
- * the query completes.
789
- */
790
- }, {
791
- key: "count",
792
- value: function (options /*:: ?: FullOptions*/) /*: Promise<number>*/{
793
- options = options || {};
794
- var findOptions = {};
795
- if (options.hasOwnProperty('useMasterKey')) {
796
- findOptions.useMasterKey = options.useMasterKey;
797
- }
798
- if (options.hasOwnProperty('sessionToken')) {
799
- findOptions.sessionToken = options.sessionToken;
800
- }
801
- this._setRequestTask(findOptions);
802
- var controller = _CoreManager.default.getQueryController();
803
- var params = this.toJSON();
804
- params.limit = 0;
418
+ if (this._select) {
419
+ params.keys = this._select.join(',');
420
+ }
421
+ if (this._count) {
805
422
  params.count = 1;
806
- return (0, _find.default)(controller).call(controller, this.className, params, findOptions).then(function (result) {
807
- return result.count;
808
- });
809
423
  }
810
-
811
- /**
812
- * Executes a distinct query and returns unique values
813
- *
814
- * @param {string} key A field to find distinct values
815
- * @param {object} options
816
- * Valid options are:<ul>
817
- * <li>sessionToken: A valid session token, used for making a request on
818
- * behalf of a specific user.
819
- * </ul>
820
- * @returns {Promise} A promise that is resolved with the query completes.
821
- */
822
- }, {
823
- key: "distinct",
824
- value: function (key /*: string*/, options /*:: ?: FullOptions*/) /*: Promise<Array<mixed>>*/{
825
- options = options || {};
826
- var distinctOptions = {};
827
- distinctOptions.useMasterKey = true;
828
- if (options.hasOwnProperty('sessionToken')) {
829
- distinctOptions.sessionToken = options.sessionToken;
830
- }
831
- this._setRequestTask(distinctOptions);
832
- var controller = _CoreManager.default.getQueryController();
833
- var params = {
834
- distinct: key,
835
- where: this._where,
836
- hint: this._hint
837
- };
838
- return controller.aggregate(this.className, params, distinctOptions).then(function (results) {
839
- return results.results;
840
- });
424
+ if (this._limit >= 0) {
425
+ params.limit = this._limit;
426
+ }
427
+ if (this._skip > 0) {
428
+ params.skip = this._skip;
429
+ }
430
+ if (this._order) {
431
+ params.order = this._order.join(',');
841
432
  }
433
+ if (this._readPreference) {
434
+ params.readPreference = this._readPreference;
435
+ }
436
+ if (this._includeReadPreference) {
437
+ params.includeReadPreference = this._includeReadPreference;
438
+ }
439
+ if (this._subqueryReadPreference) {
440
+ params.subqueryReadPreference = this._subqueryReadPreference;
441
+ }
442
+ if (this._hint) {
443
+ params.hint = this._hint;
444
+ }
445
+ if (this._explain) {
446
+ params.explain = true;
447
+ }
448
+ if (this._comment) {
449
+ params.comment = this._comment;
450
+ }
451
+ for (const key in this._extraOptions) {
452
+ params[key] = this._extraOptions[key];
453
+ }
454
+ return params;
455
+ }
842
456
 
843
- /**
844
- * Executes an aggregate query and returns aggregate results
845
- *
846
- * @param {(Array|object)} pipeline Array or Object of stages to process query
847
- * @param {object} options Valid options are:<ul>
848
- * <li>sessionToken: A valid session token, used for making a request on
849
- * behalf of a specific user.
850
- * </ul>
851
- * @returns {Promise} A promise that is resolved with the query completes.
852
- */
853
- }, {
854
- key: "aggregate",
855
- value: function (pipeline /*: mixed*/, options /*:: ?: FullOptions*/) /*: Promise<Array<mixed>>*/{
856
- options = options || {};
857
- var aggregateOptions = {};
858
- aggregateOptions.useMasterKey = true;
859
- if (options.hasOwnProperty('sessionToken')) {
860
- aggregateOptions.sessionToken = options.sessionToken;
861
- }
862
- this._setRequestTask(aggregateOptions);
863
- var controller = _CoreManager.default.getQueryController();
864
- if (!(0, _isArray.default)(pipeline) && (0, _typeof2.default)(pipeline) !== 'object') {
865
- throw new Error('Invalid pipeline must be Array or Object');
866
- }
867
- if ((0, _keys.default)(this._where || {}).length) {
868
- if (!(0, _isArray.default)(pipeline)) {
869
- pipeline = [pipeline];
457
+ /**
458
+ * Return a query with conditions from json, can be useful to send query from server side to client
459
+ * Not static, all query conditions was set before calling this method will be deleted.
460
+ * For example on the server side we have
461
+ * var query = new Parse.Query("className");
462
+ * query.equalTo(key: value);
463
+ * query.limit(100);
464
+ * ... (others queries)
465
+ * Create JSON representation of Query Object
466
+ * var jsonFromServer = query.fromJSON();
467
+ *
468
+ * On client side getting query:
469
+ * var query = new Parse.Query("className");
470
+ * query.fromJSON(jsonFromServer);
471
+ *
472
+ * and continue to query...
473
+ * query.skip(100).find().then(...);
474
+ *
475
+ * @param {QueryJSON} json from Parse.Query.toJSON() method
476
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
477
+ */
478
+ withJSON(json) {
479
+ if (json.where) {
480
+ this._where = json.where;
481
+ }
482
+ if (json.watch) {
483
+ this._watch = json.watch.split(',');
484
+ }
485
+ if (json.include) {
486
+ this._include = json.include.split(',');
487
+ }
488
+ if ((0, _keys2.default)(json)) {
489
+ this._select = (0, _keys2.default)(json).split(',');
490
+ }
491
+ if (json.excludeKeys) {
492
+ this._exclude = json.excludeKeys.split(',');
493
+ }
494
+ if (json.count) {
495
+ this._count = json.count === 1;
496
+ }
497
+ if (json.limit) {
498
+ this._limit = json.limit;
499
+ }
500
+ if (json.skip) {
501
+ this._skip = json.skip;
502
+ }
503
+ if (json.order) {
504
+ this._order = json.order.split(',');
505
+ }
506
+ if (json.readPreference) {
507
+ this._readPreference = json.readPreference;
508
+ }
509
+ if (json.includeReadPreference) {
510
+ this._includeReadPreference = json.includeReadPreference;
511
+ }
512
+ if (json.subqueryReadPreference) {
513
+ this._subqueryReadPreference = json.subqueryReadPreference;
514
+ }
515
+ if (json.hint) {
516
+ this._hint = json.hint;
517
+ }
518
+ if (json.explain) {
519
+ this._explain = !!json.explain;
520
+ }
521
+ if (json.comment) {
522
+ this._comment = json.comment;
523
+ }
524
+ for (const key in json) {
525
+ if (json.hasOwnProperty(key)) {
526
+ var _context3;
527
+ if ((0, _indexOf.default)(_context3 = ['where', 'include', 'keys', 'count', 'limit', 'skip', 'order', 'readPreference', 'includeReadPreference', 'subqueryReadPreference', 'hint', 'explain', 'comment']).call(_context3, key) === -1) {
528
+ this._extraOptions[key] = json[key];
870
529
  }
871
- pipeline.unshift({
872
- $match: this._where
873
- });
874
530
  }
875
- var params = {
876
- pipeline: pipeline,
877
- hint: this._hint,
878
- explain: this._explain,
879
- readPreference: this._readPreference
880
- };
881
- return controller.aggregate(this.className, params, aggregateOptions).then(function (results) {
882
- return results.results;
883
- });
884
531
  }
532
+ return this;
533
+ }
885
534
 
886
- /**
887
- * Retrieves at most one Parse.Object that satisfies this query.
888
- *
889
- * Returns the object if there is one, otherwise undefined.
890
- *
891
- * @param {object} options Valid options are:<ul>
892
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
893
- * be used for this request.
894
- * <li>sessionToken: A valid session token, used for making a request on
895
- * behalf of a specific user.
896
- * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
897
- * <li>json: Return raw json without converting to Parse.Object
898
- * </ul>
899
- * @returns {Promise} A promise that is resolved with the object when
900
- * the query completes.
901
- */
902
- }, {
903
- key: "first",
904
- value: function (options /*:: ?: FullOptions*/) /*: Promise<ParseObject | void>*/{
905
- var _this4 = this;
906
- options = options || {};
907
- var findOptions = {};
908
- if (options.hasOwnProperty('useMasterKey')) {
909
- findOptions.useMasterKey = options.useMasterKey;
910
- }
911
- if (options.hasOwnProperty('sessionToken')) {
912
- findOptions.sessionToken = options.sessionToken;
913
- }
914
- if (options.hasOwnProperty('context') && (0, _typeof2.default)(options.context) === 'object') {
915
- findOptions.context = options.context;
916
- }
917
- this._setRequestTask(findOptions);
918
- var controller = _CoreManager.default.getQueryController();
919
- var params = this.toJSON();
920
- params.limit = 1;
921
- var select = this._select;
922
- if (this._queriesLocalDatastore) {
923
- return this._handleOfflineQuery(params).then(function (objects) {
924
- if (!objects[0]) {
925
- return undefined;
926
- }
927
- return objects[0];
928
- });
535
+ /**
536
+ * Static method to restore Parse.Query by json representation
537
+ * Internally calling Parse.Query.withJSON
538
+ *
539
+ * @param {string} className
540
+ * @param {QueryJSON} json from Parse.Query.toJSON() method
541
+ * @returns {Parse.Query} new created query
542
+ */
543
+ static fromJSON(className, json) {
544
+ const query = new ParseQuery(className);
545
+ return query.withJSON(json);
546
+ }
547
+
548
+ /**
549
+ * Constructs a Parse.Object whose id is already known by fetching data from
550
+ * the server. Unlike the <code>first</code> method, it never returns undefined.
551
+ *
552
+ * @param {string} objectId The id of the object to be fetched.
553
+ * @param {object} options
554
+ * Valid options are:<ul>
555
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
556
+ * be used for this request.
557
+ * <li>sessionToken: A valid session token, used for making a request on
558
+ * behalf of a specific user.
559
+ * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
560
+ * <li>json: Return raw json without converting to Parse.Object
561
+ * </ul>
562
+ * @returns {Promise} A promise that is resolved with the result when
563
+ * the query completes.
564
+ */
565
+ get(objectId, options) {
566
+ this.equalTo('objectId', objectId);
567
+ const firstOptions = {};
568
+ if (options && options.hasOwnProperty('useMasterKey')) {
569
+ firstOptions.useMasterKey = options.useMasterKey;
570
+ }
571
+ if (options && options.hasOwnProperty('sessionToken')) {
572
+ firstOptions.sessionToken = options.sessionToken;
573
+ }
574
+ if (options && options.hasOwnProperty('context') && typeof options.context === 'object') {
575
+ firstOptions.context = options.context;
576
+ }
577
+ if (options && options.hasOwnProperty('json')) {
578
+ firstOptions.json = options.json;
579
+ }
580
+ return this.first(firstOptions).then(response => {
581
+ if (response) {
582
+ return response;
929
583
  }
930
- return (0, _find.default)(controller).call(controller, this.className, params, findOptions).then(function (response) {
931
- var objects = response.results;
932
- if (!objects[0]) {
933
- return undefined;
934
- }
935
- if (!objects[0].className) {
936
- objects[0].className = _this4.className;
584
+ const errorObject = new _ParseError.default(_ParseError.default.OBJECT_NOT_FOUND, 'Object not found.');
585
+ return _promise.default.reject(errorObject);
586
+ });
587
+ }
588
+
589
+ /**
590
+ * Retrieves a list of ParseObjects that satisfy this query.
591
+ *
592
+ * @param {object} options Valid options
593
+ * are:<ul>
594
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
595
+ * be used for this request.
596
+ * <li>sessionToken: A valid session token, used for making a request on
597
+ * behalf of a specific user.
598
+ * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
599
+ * <li>json: Return raw json without converting to Parse.Object
600
+ * </ul>
601
+ * @returns {Promise} A promise that is resolved with the results when
602
+ * the query completes.
603
+ */
604
+ find(options) {
605
+ options = options || {};
606
+ const findOptions = {};
607
+ if (options.hasOwnProperty('useMasterKey')) {
608
+ findOptions.useMasterKey = options.useMasterKey;
609
+ }
610
+ if (options.hasOwnProperty('sessionToken')) {
611
+ findOptions.sessionToken = options.sessionToken;
612
+ }
613
+ if (options.hasOwnProperty('context') && typeof options.context === 'object') {
614
+ findOptions.context = options.context;
615
+ }
616
+ this._setRequestTask(findOptions);
617
+ const controller = _CoreManager.default.getQueryController();
618
+ const select = this._select;
619
+ if (this._queriesLocalDatastore) {
620
+ return this._handleOfflineQuery(this.toJSON());
621
+ }
622
+ return (0, _find.default)(controller).call(controller, this.className, this.toJSON(), findOptions).then(response => {
623
+ // Return generic object when explain is used
624
+ if (this._explain) {
625
+ return response.results;
626
+ }
627
+ const results = response.results?.map(data => {
628
+ // In cases of relations, the server may send back a className
629
+ // on the top level of the payload
630
+ const override = response.className || this.className;
631
+ if (!data.className) {
632
+ data.className = override;
937
633
  }
938
634
 
939
635
  // Make sure the data object contains keys for all objects that
940
636
  // have been requested with a select, so that our cached state
941
637
  // updates correctly.
942
638
  if (select) {
943
- handleSelectResult(objects[0], select);
639
+ handleSelectResult(data, select);
944
640
  }
945
641
  if (options.json) {
946
- return objects[0];
642
+ return data;
947
643
  } else {
948
- return _ParseObject.default.fromJSON(objects[0], !select);
644
+ return _ParseObject.default.fromJSON(data, !select);
949
645
  }
950
646
  });
951
- }
952
-
953
- /**
954
- * Iterates over objects matching a query, calling a callback for each batch.
955
- * If the callback returns a promise, the iteration will not continue until
956
- * that promise has been fulfilled. If the callback returns a rejected
957
- * promise, then iteration will stop with that error. The items are processed
958
- * in an unspecified order. The query may not have any sort order, and may
959
- * not use limit or skip.
960
- *
961
- * @param {Function} callback Callback that will be called with each result
962
- * of the query.
963
- * @param {object} options Valid options are:<ul>
964
- * <li>batchSize: How many objects to yield in each batch (default: 100)
965
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
966
- * be used for this request.
967
- * <li>sessionToken: A valid session token, used for making a request on
968
- * behalf of a specific user.
969
- * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
970
- * </ul>
971
- * @returns {Promise} A promise that will be fulfilled once the
972
- * iteration has completed.
973
- */
974
- }, {
975
- key: "eachBatch",
976
- value: function (callback /*: (objs: Array<ParseObject>) => Promise<*>*/, options /*:: ?: BatchOptions*/) /*: Promise<void>*/{
977
- options = options || {};
978
- if (this._order || this._skip || this._limit >= 0) {
979
- return _promise.default.reject('Cannot iterate on a query with sort, skip, or limit.');
980
- }
981
- var query = new ParseQuery(this.className);
982
- query._limit = options.batchSize || 100;
983
- query._include = (0, _toConsumableArray2.default)(this._include);
984
- query._exclude = (0, _toConsumableArray2.default)(this._exclude);
985
- if (this._select) {
986
- query._select = (0, _toConsumableArray2.default)(this._select);
987
- }
988
- query._hint = this._hint;
989
- query._where = {};
990
- for (var _attr in this._where) {
991
- var val = this._where[_attr];
992
- if ((0, _isArray.default)(val)) {
993
- query._where[_attr] = (0, _map2.default)(val).call(val, function (v) {
994
- return v;
995
- });
996
- } else if (val && (0, _typeof2.default)(val) === 'object') {
997
- var conditionMap = {};
998
- query._where[_attr] = conditionMap;
999
- for (var cond in val) {
1000
- conditionMap[cond] = val[cond];
1001
- }
1002
- } else {
1003
- query._where[_attr] = val;
1004
- }
1005
- }
1006
- query.ascending('objectId');
1007
- var findOptions = {};
1008
- if (options.hasOwnProperty('useMasterKey')) {
1009
- findOptions.useMasterKey = options.useMasterKey;
1010
- }
1011
- if (options.hasOwnProperty('sessionToken')) {
1012
- findOptions.sessionToken = options.sessionToken;
1013
- }
1014
- if (options.hasOwnProperty('context') && (0, _typeof2.default)(options.context) === 'object') {
1015
- findOptions.context = options.context;
1016
- }
1017
- if (options.hasOwnProperty('json')) {
1018
- findOptions.json = options.json;
647
+ const count = response.count;
648
+ if (typeof count === 'number') {
649
+ return {
650
+ results,
651
+ count
652
+ };
653
+ } else {
654
+ return results;
1019
655
  }
1020
- var finished = false;
1021
- var previousResults = [];
1022
- return (0, _promiseUtils.continueWhile)(function () {
1023
- return !finished;
1024
- }, /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
1025
- var _yield$Promise$all, _yield$Promise$all2, results;
1026
- return _regenerator.default.wrap(function (_context8) {
1027
- while (1) switch (_context8.prev = _context8.next) {
1028
- case 0:
1029
- _context8.next = 2;
1030
- return _promise.default.all([(0, _find.default)(query).call(query, findOptions), _promise.default.resolve(previousResults.length > 0 && callback(previousResults))]);
1031
- case 2:
1032
- _yield$Promise$all = _context8.sent;
1033
- _yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 1);
1034
- results = _yield$Promise$all2[0];
1035
- if (!(results.length >= query._limit)) {
1036
- _context8.next = 10;
1037
- break;
1038
- }
1039
- query.greaterThan('objectId', results[results.length - 1].id);
1040
- previousResults = results;
1041
- _context8.next = 17;
1042
- break;
1043
- case 10:
1044
- if (!(results.length > 0)) {
1045
- _context8.next = 16;
1046
- break;
1047
- }
1048
- _context8.next = 13;
1049
- return _promise.default.resolve(callback(results));
1050
- case 13:
1051
- finished = true;
1052
- _context8.next = 17;
1053
- break;
1054
- case 16:
1055
- finished = true;
1056
- case 17:
1057
- case "end":
1058
- return _context8.stop();
1059
- }
1060
- }, _callee3);
1061
- })));
1062
- }
1063
-
1064
- /**
1065
- * Iterates over each result of a query, calling a callback for each one. If
1066
- * the callback returns a promise, the iteration will not continue until
1067
- * that promise has been fulfilled. If the callback returns a rejected
1068
- * promise, then iteration will stop with that error. The items are
1069
- * processed in an unspecified order. The query may not have any sort order,
1070
- * and may not use limit or skip.
1071
- *
1072
- * @param {Function} callback Callback that will be called with each result
1073
- * of the query.
1074
- * @param {object} options Valid options are:<ul>
1075
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1076
- * be used for this request.
1077
- * <li>sessionToken: A valid session token, used for making a request on
1078
- * behalf of a specific user.
1079
- * <li>json: Return raw json without converting to Parse.Object
1080
- * </ul>
1081
- * @returns {Promise} A promise that will be fulfilled once the
1082
- * iteration has completed.
1083
- */
1084
- }, {
1085
- key: "each",
1086
- value: function (callback /*: (obj: ParseObject) => any*/, options /*:: ?: BatchOptions*/) /*: Promise<void>*/{
1087
- return this.eachBatch(function (results) {
1088
- var callbacksDone = _promise.default.resolve();
1089
- (0, _forEach.default)(results).call(results, function (result) {
1090
- callbacksDone = callbacksDone.then(function () {
1091
- return callback(result);
1092
- });
1093
- });
1094
- return callbacksDone;
1095
- }, options);
1096
- }
656
+ });
657
+ }
1097
658
 
1098
- /**
1099
- * Adds a hint to force index selection. (https://docs.mongodb.com/manual/reference/operator/meta/hint/)
1100
- *
1101
- * @param {(string|object)} value String or Object of index that should be used when executing query
1102
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1103
- */
1104
- }, {
1105
- key: "hint",
1106
- value: function (value /*: mixed*/) /*: ParseQuery*/{
1107
- if (typeof value === 'undefined') {
1108
- delete this._hint;
1109
- }
1110
- this._hint = value;
1111
- return this;
1112
- }
659
+ /**
660
+ * Retrieves a complete list of ParseObjects that satisfy this query.
661
+ * Using `eachBatch` under the hood to fetch all the valid objects.
662
+ *
663
+ * @param {object} options Valid options are:<ul>
664
+ * <li>batchSize: How many objects to yield in each batch (default: 100)
665
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
666
+ * be used for this request.
667
+ * <li>sessionToken: A valid session token, used for making a request on
668
+ * behalf of a specific user.
669
+ * </ul>
670
+ * @returns {Promise} A promise that is resolved with the results when
671
+ * the query completes.
672
+ */
673
+ async findAll(options) {
674
+ let result = [];
675
+ await this.eachBatch(objects => {
676
+ result = [...result, ...objects];
677
+ }, options);
678
+ return result;
679
+ }
1113
680
 
1114
- /**
1115
- * Investigates the query execution plan. Useful for optimizing queries. (https://docs.mongodb.com/manual/reference/operator/meta/explain/)
1116
- *
1117
- * @param {boolean} explain Used to toggle the information on the query plan.
1118
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1119
- */
1120
- }, {
1121
- key: "explain",
1122
- value: function () /*: ParseQuery*/{
1123
- var _explain /*: boolean*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1124
- if (typeof _explain !== 'boolean') {
1125
- throw new Error('You can only set explain to a boolean value');
1126
- }
1127
- this._explain = _explain;
1128
- return this;
1129
- }
681
+ /**
682
+ * Counts the number of objects that match this query.
683
+ *
684
+ * @param {object} options
685
+ * @param {boolean} [options.useMasterKey]
686
+ * @param {string} [options.sessionToken]
687
+ * Valid options are:<ul>
688
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
689
+ * be used for this request.
690
+ * <li>sessionToken: A valid session token, used for making a request on
691
+ * behalf of a specific user.
692
+ * </ul>
693
+ * @returns {Promise} A promise that is resolved with the count when
694
+ * the query completes.
695
+ */
696
+ count(options) {
697
+ options = options || {};
698
+ const findOptions = {};
699
+ if (options.hasOwnProperty('useMasterKey')) {
700
+ findOptions.useMasterKey = options.useMasterKey;
701
+ }
702
+ if (options.hasOwnProperty('sessionToken')) {
703
+ findOptions.sessionToken = options.sessionToken;
704
+ }
705
+ this._setRequestTask(findOptions);
706
+ const controller = _CoreManager.default.getQueryController();
707
+ const params = this.toJSON();
708
+ params.limit = 0;
709
+ params.count = 1;
710
+ return (0, _find.default)(controller).call(controller, this.className, params, findOptions).then(result => {
711
+ return result.count;
712
+ });
713
+ }
1130
714
 
1131
- /**
1132
- * Iterates over each result of a query, calling a callback for each one. If
1133
- * the callback returns a promise, the iteration will not continue until
1134
- * that promise has been fulfilled. If the callback returns a rejected
1135
- * promise, then iteration will stop with that error. The items are
1136
- * processed in an unspecified order. The query may not have any sort order,
1137
- * and may not use limit or skip.
1138
- *
1139
- * @param {Function} callback Callback <ul>
1140
- * <li>currentObject: The current Parse.Object being processed in the array.</li>
1141
- * <li>index: The index of the current Parse.Object being processed in the array.</li>
1142
- * <li>query: The query map was called upon.</li>
1143
- * </ul>
1144
- * @param {object} options Valid options are:<ul>
1145
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1146
- * be used for this request.
1147
- * <li>sessionToken: A valid session token, used for making a request on
1148
- * behalf of a specific user.
1149
- * </ul>
1150
- * @returns {Promise} A promise that will be fulfilled once the
1151
- * iteration has completed.
1152
- */
1153
- }, {
1154
- key: "map",
1155
- value: function () {
1156
- var _map = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(callback /*: (currentObject: ParseObject, index: number, query: ParseQuery) => any*/, options /*:: ?: BatchOptions*/) {
1157
- var _this5 = this;
1158
- var array, index;
1159
- return _regenerator.default.wrap(function (_context9) {
1160
- while (1) switch (_context9.prev = _context9.next) {
1161
- case 0:
1162
- array = [];
1163
- index = 0;
1164
- _context9.next = 4;
1165
- return this.each(function (object) {
1166
- return _promise.default.resolve(callback(object, index, _this5)).then(function (result) {
1167
- array.push(result);
1168
- index += 1;
1169
- });
1170
- }, options);
1171
- case 4:
1172
- return _context9.abrupt("return", array);
1173
- case 5:
1174
- case "end":
1175
- return _context9.stop();
1176
- }
1177
- }, _callee4, this);
1178
- }));
1179
- function map() {
1180
- return _map.apply(this, arguments);
1181
- }
1182
- return map;
1183
- }()
1184
- /**
1185
- * Iterates over each result of a query, calling a callback for each one. If
1186
- * the callback returns a promise, the iteration will not continue until
1187
- * that promise has been fulfilled. If the callback returns a rejected
1188
- * promise, then iteration will stop with that error. The items are
1189
- * processed in an unspecified order. The query may not have any sort order,
1190
- * and may not use limit or skip.
1191
- *
1192
- * @param {Function} callback Callback <ul>
1193
- * <li>accumulator: The accumulator accumulates the callback's return values. It is the accumulated value previously returned in the last invocation of the callback.</li>
1194
- * <li>currentObject: The current Parse.Object being processed in the array.</li>
1195
- * <li>index: The index of the current Parse.Object being processed in the array.</li>
1196
- * </ul>
1197
- * @param {*} initialValue A value to use as the first argument to the first call of the callback. If no initialValue is supplied, the first object in the query will be used and skipped.
1198
- * @param {object} options Valid options are:<ul>
1199
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1200
- * be used for this request.
1201
- * <li>sessionToken: A valid session token, used for making a request on
1202
- * behalf of a specific user.
1203
- * </ul>
1204
- * @returns {Promise} A promise that will be fulfilled once the
1205
- * iteration has completed.
1206
- */
1207
- }, {
1208
- key: "reduce",
1209
- value: function () {
1210
- var _reduce = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(callback /*: (accumulator: any, currentObject: ParseObject, index: number) => any*/, initialValue /*: any*/, options /*:: ?: BatchOptions*/) {
1211
- var accumulator, index;
1212
- return _regenerator.default.wrap(function (_context10) {
1213
- while (1) switch (_context10.prev = _context10.next) {
1214
- case 0:
1215
- accumulator = initialValue;
1216
- index = 0;
1217
- _context10.next = 4;
1218
- return this.each(function (object) {
1219
- // If no initial value was given, we take the first object from the query
1220
- // as the initial value and don't call the callback with it.
1221
- if (index === 0 && initialValue === undefined) {
1222
- accumulator = object;
1223
- index += 1;
1224
- return;
1225
- }
1226
- return _promise.default.resolve(callback(accumulator, object, index)).then(function (result) {
1227
- accumulator = result;
1228
- index += 1;
1229
- });
1230
- }, options);
1231
- case 4:
1232
- if (!(index === 0 && initialValue === undefined)) {
1233
- _context10.next = 6;
1234
- break;
1235
- }
1236
- throw new TypeError('Reducing empty query result set with no initial value');
1237
- case 6:
1238
- return _context10.abrupt("return", accumulator);
1239
- case 7:
1240
- case "end":
1241
- return _context10.stop();
1242
- }
1243
- }, _callee5, this);
1244
- }));
1245
- function reduce() {
1246
- return _reduce.apply(this, arguments);
1247
- }
1248
- return reduce;
1249
- }()
1250
- /**
1251
- * Iterates over each result of a query, calling a callback for each one. If
1252
- * the callback returns a promise, the iteration will not continue until
1253
- * that promise has been fulfilled. If the callback returns a rejected
1254
- * promise, then iteration will stop with that error. The items are
1255
- * processed in an unspecified order. The query may not have any sort order,
1256
- * and may not use limit or skip.
1257
- *
1258
- * @param {Function} callback Callback <ul>
1259
- * <li>currentObject: The current Parse.Object being processed in the array.</li>
1260
- * <li>index: The index of the current Parse.Object being processed in the array.</li>
1261
- * <li>query: The query filter was called upon.</li>
1262
- * </ul>
1263
- * @param {object} options Valid options are:<ul>
1264
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1265
- * be used for this request.
1266
- * <li>sessionToken: A valid session token, used for making a request on
1267
- * behalf of a specific user.
1268
- * </ul>
1269
- * @returns {Promise} A promise that will be fulfilled once the
1270
- * iteration has completed.
1271
- */
1272
- }, {
1273
- key: "filter",
1274
- value: function () {
1275
- var _filter = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(callback /*: (currentObject: ParseObject, index: number, query: ParseQuery) => boolean*/, options /*:: ?: BatchOptions*/) {
1276
- var _this6 = this;
1277
- var array, index;
1278
- return _regenerator.default.wrap(function (_context11) {
1279
- while (1) switch (_context11.prev = _context11.next) {
1280
- case 0:
1281
- array = [];
1282
- index = 0;
1283
- _context11.next = 4;
1284
- return this.each(function (object) {
1285
- return _promise.default.resolve(callback(object, index, _this6)).then(function (flag) {
1286
- if (flag) {
1287
- array.push(object);
1288
- }
1289
- index += 1;
1290
- });
1291
- }, options);
1292
- case 4:
1293
- return _context11.abrupt("return", array);
1294
- case 5:
1295
- case "end":
1296
- return _context11.stop();
1297
- }
1298
- }, _callee6, this);
1299
- }));
1300
- function filter() {
1301
- return _filter.apply(this, arguments);
1302
- }
1303
- return filter;
1304
- }()
1305
- /* Query Conditions */
1306
- /**
1307
- * Adds a constraint to the query that requires a particular key's value to
1308
- * be equal to the provided value.
1309
- *
1310
- * @param {string} key The key to check.
1311
- * @param value The value that the Parse.Object must contain.
1312
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1313
- */
1314
- }, {
1315
- key: "equalTo",
1316
- value: function (key /*: string | { [key: string]: any }*/, value /*: ?mixed*/) /*: ParseQuery*/{
1317
- var _this7 = this;
1318
- if (key && (0, _typeof2.default)(key) === 'object') {
1319
- var _context12;
1320
- (0, _forEach.default)(_context12 = (0, _entries.default)(key)).call(_context12, function (_ref2) {
1321
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
1322
- k = _ref3[0],
1323
- val = _ref3[1];
1324
- return _this7.equalTo(k, val);
1325
- });
1326
- return this;
1327
- }
1328
- if (typeof value === 'undefined') {
1329
- return this.doesNotExist(key);
1330
- }
1331
- this._where[key] = (0, _encode.default)(value, false, true);
1332
- return this;
1333
- }
1334
-
1335
- /**
1336
- * Adds a constraint to the query that requires a particular key's value to
1337
- * be not equal to the provided value.
1338
- *
1339
- * @param {string} key The key to check.
1340
- * @param value The value that must not be equalled.
1341
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1342
- */
1343
- }, {
1344
- key: "notEqualTo",
1345
- value: function (key /*: string | { [key: string]: any }*/, value /*: ?mixed*/) /*: ParseQuery*/{
1346
- var _this8 = this;
1347
- if (key && (0, _typeof2.default)(key) === 'object') {
1348
- var _context13;
1349
- (0, _forEach.default)(_context13 = (0, _entries.default)(key)).call(_context13, function (_ref4) {
1350
- var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
1351
- k = _ref5[0],
1352
- val = _ref5[1];
1353
- return _this8.notEqualTo(k, val);
1354
- });
1355
- return this;
1356
- }
1357
- return this._addCondition(key, '$ne', value);
1358
- }
1359
-
1360
- /**
1361
- * Adds a constraint to the query that requires a particular key's value to
1362
- * be less than the provided value.
1363
- *
1364
- * @param {string} key The key to check.
1365
- * @param value The value that provides an upper bound.
1366
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1367
- */
1368
- }, {
1369
- key: "lessThan",
1370
- value: function (key /*: string*/, value /*: mixed*/) /*: ParseQuery*/{
1371
- return this._addCondition(key, '$lt', value);
1372
- }
1373
-
1374
- /**
1375
- * Adds a constraint to the query that requires a particular key's value to
1376
- * be greater than the provided value.
1377
- *
1378
- * @param {string} key The key to check.
1379
- * @param value The value that provides an lower bound.
1380
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1381
- */
1382
- }, {
1383
- key: "greaterThan",
1384
- value: function (key /*: string*/, value /*: mixed*/) /*: ParseQuery*/{
1385
- return this._addCondition(key, '$gt', value);
1386
- }
1387
-
1388
- /**
1389
- * Adds a constraint to the query that requires a particular key's value to
1390
- * be less than or equal to the provided value.
1391
- *
1392
- * @param {string} key The key to check.
1393
- * @param value The value that provides an upper bound.
1394
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1395
- */
1396
- }, {
1397
- key: "lessThanOrEqualTo",
1398
- value: function (key /*: string*/, value /*: mixed*/) /*: ParseQuery*/{
1399
- return this._addCondition(key, '$lte', value);
1400
- }
1401
-
1402
- /**
1403
- * Adds a constraint to the query that requires a particular key's value to
1404
- * be greater than or equal to the provided value.
1405
- *
1406
- * @param {string} key The key to check.
1407
- * @param {*} value The value that provides an lower bound.
1408
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1409
- */
1410
- }, {
1411
- key: "greaterThanOrEqualTo",
1412
- value: function (key /*: string*/, value /*: mixed*/) /*: ParseQuery*/{
1413
- return this._addCondition(key, '$gte', value);
1414
- }
1415
-
1416
- /**
1417
- * Adds a constraint to the query that requires a particular key's value to
1418
- * be contained in the provided list of values.
1419
- *
1420
- * @param {string} key The key to check.
1421
- * @param {Array<*>} value The values that will match.
1422
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1423
- */
1424
- }, {
1425
- key: "containedIn",
1426
- value: function (key /*: string*/, value /*: Array<mixed>*/) /*: ParseQuery*/{
1427
- return this._addCondition(key, '$in', value);
1428
- }
1429
-
1430
- /**
1431
- * Adds a constraint to the query that requires a particular key's value to
1432
- * not be contained in the provided list of values.
1433
- *
1434
- * @param {string} key The key to check.
1435
- * @param {Array<*>} value The values that will not match.
1436
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1437
- */
1438
- }, {
1439
- key: "notContainedIn",
1440
- value: function (key /*: string*/, value /*: Array<mixed>*/) /*: ParseQuery*/{
1441
- return this._addCondition(key, '$nin', value);
1442
- }
1443
-
1444
- /**
1445
- * Adds a constraint to the query that requires a particular key's value to
1446
- * be contained by the provided list of values. Get objects where all array elements match.
1447
- *
1448
- * @param {string} key The key to check.
1449
- * @param {Array} values The values that will match.
1450
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1451
- */
1452
- }, {
1453
- key: "containedBy",
1454
- value: function (key /*: string*/, values /*: Array<mixed>*/) /*: ParseQuery*/{
1455
- return this._addCondition(key, '$containedBy', values);
1456
- }
1457
-
1458
- /**
1459
- * Adds a constraint to the query that requires a particular key's value to
1460
- * contain each one of the provided list of values.
1461
- *
1462
- * @param {string} key The key to check. This key's value must be an array.
1463
- * @param {Array} values The values that will match.
1464
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1465
- */
1466
- }, {
1467
- key: "containsAll",
1468
- value: function (key /*: string*/, values /*: Array<mixed>*/) /*: ParseQuery*/{
1469
- return this._addCondition(key, '$all', values);
1470
- }
1471
-
1472
- /**
1473
- * Adds a constraint to the query that requires a particular key's value to
1474
- * contain each one of the provided list of values starting with given strings.
1475
- *
1476
- * @param {string} key The key to check. This key's value must be an array.
1477
- * @param {Array<string>} values The string values that will match as starting string.
1478
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1479
- */
1480
- }, {
1481
- key: "containsAllStartingWith",
1482
- value: function (key /*: string*/, values /*: Array<string>*/) /*: ParseQuery*/{
1483
- var _this = this;
1484
- if (!(0, _isArray.default)(values)) {
1485
- values = [values];
1486
- }
1487
- var regexObject = (0, _map2.default)(values).call(values, function (value) {
1488
- return {
1489
- $regex: _this._regexStartWith(value)
1490
- };
1491
- });
1492
- return this.containsAll(key, regexObject);
1493
- }
715
+ /**
716
+ * Executes a distinct query and returns unique values
717
+ *
718
+ * @param {string} key A field to find distinct values
719
+ * @param {object} options
720
+ * @param {string} [options.sessionToken] A valid session token, used for making a request on behalf of a specific user.
721
+ * @returns {Promise} A promise that is resolved with the query completes.
722
+ */
723
+ distinct(key, options) {
724
+ options = options || {};
725
+ const distinctOptions = {
726
+ useMasterKey: true
727
+ };
728
+ if (options.hasOwnProperty('sessionToken')) {
729
+ distinctOptions.sessionToken = options.sessionToken;
730
+ }
731
+ this._setRequestTask(distinctOptions);
732
+ const controller = _CoreManager.default.getQueryController();
733
+ const params = {
734
+ distinct: key,
735
+ where: this._where,
736
+ hint: this._hint
737
+ };
738
+ return controller.aggregate(this.className, params, distinctOptions).then(results => {
739
+ return results.results;
740
+ });
741
+ }
1494
742
 
1495
- /**
1496
- * Adds a constraint for finding objects that contain the given key.
1497
- *
1498
- * @param {string} key The key that should exist.
1499
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1500
- */
1501
- }, {
1502
- key: "exists",
1503
- value: function (key /*: string*/) /*: ParseQuery*/{
1504
- return this._addCondition(key, '$exists', true);
743
+ /**
744
+ * Executes an aggregate query and returns aggregate results
745
+ *
746
+ * @param {(Array|object)} pipeline Array or Object of stages to process query
747
+ * @param {object} options
748
+ * @param {string} [options.sessionToken] A valid session token, used for making a request on behalf of a specific user.
749
+ * @returns {Promise} A promise that is resolved with the query completes.
750
+ */
751
+ aggregate(pipeline, options) {
752
+ options = options || {};
753
+ const aggregateOptions = {
754
+ useMasterKey: true
755
+ };
756
+ if (options.hasOwnProperty('sessionToken')) {
757
+ aggregateOptions.sessionToken = options.sessionToken;
1505
758
  }
1506
-
1507
- /**
1508
- * Adds a constraint for finding objects that do not contain a given key.
1509
- *
1510
- * @param {string} key The key that should not exist
1511
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1512
- */
1513
- }, {
1514
- key: "doesNotExist",
1515
- value: function (key /*: string*/) /*: ParseQuery*/{
1516
- return this._addCondition(key, '$exists', false);
759
+ this._setRequestTask(aggregateOptions);
760
+ const controller = _CoreManager.default.getQueryController();
761
+ if (!(0, _isArray.default)(pipeline) && typeof pipeline !== 'object') {
762
+ throw new Error('Invalid pipeline must be Array or Object');
1517
763
  }
1518
-
1519
- /**
1520
- * Adds a regular expression constraint for finding string values that match
1521
- * the provided regular expression.
1522
- * This may be slow for large datasets.
1523
- *
1524
- * @param {string} key The key that the string to match is stored in.
1525
- * @param {RegExp} regex The regular expression pattern to match.
1526
- * @param {string} modifiers The regular expression mode.
1527
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1528
- */
1529
- }, {
1530
- key: "matches",
1531
- value: function (key /*: string*/, regex /*: RegExp*/, modifiers /*: string*/) /*: ParseQuery*/{
1532
- this._addCondition(key, '$regex', regex);
1533
- if (!modifiers) {
1534
- modifiers = '';
1535
- }
1536
- if (regex.ignoreCase) {
1537
- modifiers += 'i';
1538
- }
1539
- if (regex.multiline) {
1540
- modifiers += 'm';
764
+ if ((0, _keys.default)(this._where || {}).length) {
765
+ if (!(0, _isArray.default)(pipeline)) {
766
+ pipeline = [pipeline];
1541
767
  }
1542
- if (modifiers.length) {
1543
- this._addCondition(key, '$options', modifiers);
1544
- }
1545
- return this;
1546
- }
1547
-
1548
- /**
1549
- * Adds a constraint that requires that a key's value matches a Parse.Query
1550
- * constraint.
1551
- *
1552
- * @param {string} key The key that the contains the object to match the
1553
- * query.
1554
- * @param {Parse.Query} query The query that should match.
1555
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1556
- */
1557
- }, {
1558
- key: "matchesQuery",
1559
- value: function (key /*: string*/, query /*: ParseQuery*/) /*: ParseQuery*/{
1560
- var queryJSON = query.toJSON();
1561
- queryJSON.className = query.className;
1562
- return this._addCondition(key, '$inQuery', queryJSON);
1563
- }
1564
-
1565
- /**
1566
- * Adds a constraint that requires that a key's value not matches a
1567
- * Parse.Query constraint.
1568
- *
1569
- * @param {string} key The key that the contains the object to match the
1570
- * query.
1571
- * @param {Parse.Query} query The query that should not match.
1572
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1573
- */
1574
- }, {
1575
- key: "doesNotMatchQuery",
1576
- value: function (key /*: string*/, query /*: ParseQuery*/) /*: ParseQuery*/{
1577
- var queryJSON = query.toJSON();
1578
- queryJSON.className = query.className;
1579
- return this._addCondition(key, '$notInQuery', queryJSON);
1580
- }
1581
-
1582
- /**
1583
- * Adds a constraint that requires that a key's value matches a value in
1584
- * an object returned by a different Parse.Query.
1585
- *
1586
- * @param {string} key The key that contains the value that is being
1587
- * matched.
1588
- * @param {string} queryKey The key in the objects returned by the query to
1589
- * match against.
1590
- * @param {Parse.Query} query The query to run.
1591
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1592
- */
1593
- }, {
1594
- key: "matchesKeyInQuery",
1595
- value: function (key /*: string*/, queryKey /*: string*/, query /*: ParseQuery*/) /*: ParseQuery*/{
1596
- var queryJSON = query.toJSON();
1597
- queryJSON.className = query.className;
1598
- return this._addCondition(key, '$select', {
1599
- key: queryKey,
1600
- query: queryJSON
768
+ pipeline.unshift({
769
+ $match: this._where
1601
770
  });
1602
771
  }
772
+ const params = {
773
+ pipeline,
774
+ hint: this._hint,
775
+ explain: this._explain,
776
+ readPreference: this._readPreference
777
+ };
778
+ return controller.aggregate(this.className, params, aggregateOptions).then(results => {
779
+ return results.results;
780
+ });
781
+ }
1603
782
 
1604
- /**
1605
- * Adds a constraint that requires that a key's value not match a value in
1606
- * an object returned by a different Parse.Query.
1607
- *
1608
- * @param {string} key The key that contains the value that is being
1609
- * excluded.
1610
- * @param {string} queryKey The key in the objects returned by the query to
1611
- * match against.
1612
- * @param {Parse.Query} query The query to run.
1613
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1614
- */
1615
- }, {
1616
- key: "doesNotMatchKeyInQuery",
1617
- value: function (key /*: string*/, queryKey /*: string*/, query /*: ParseQuery*/) /*: ParseQuery*/{
1618
- var queryJSON = query.toJSON();
1619
- queryJSON.className = query.className;
1620
- return this._addCondition(key, '$dontSelect', {
1621
- key: queryKey,
1622
- query: queryJSON
783
+ /**
784
+ * Retrieves at most one Parse.Object that satisfies this query.
785
+ *
786
+ * Returns the object if there is one, otherwise undefined.
787
+ *
788
+ * @param {object} options Valid options are:<ul>
789
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
790
+ * be used for this request.
791
+ * <li>sessionToken: A valid session token, used for making a request on
792
+ * behalf of a specific user.
793
+ * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
794
+ * <li>json: Return raw json without converting to Parse.Object
795
+ * </ul>
796
+ * @returns {Promise} A promise that is resolved with the object when
797
+ * the query completes.
798
+ */
799
+ first() {
800
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
801
+ const findOptions = {};
802
+ if (options.hasOwnProperty('useMasterKey')) {
803
+ findOptions.useMasterKey = options.useMasterKey;
804
+ }
805
+ if (options.hasOwnProperty('sessionToken')) {
806
+ findOptions.sessionToken = options.sessionToken;
807
+ }
808
+ if (options.hasOwnProperty('context') && typeof options.context === 'object') {
809
+ findOptions.context = options.context;
810
+ }
811
+ this._setRequestTask(findOptions);
812
+ const controller = _CoreManager.default.getQueryController();
813
+ const params = this.toJSON();
814
+ params.limit = 1;
815
+ const select = this._select;
816
+ if (this._queriesLocalDatastore) {
817
+ return this._handleOfflineQuery(params).then(objects => {
818
+ if (!objects[0]) {
819
+ return undefined;
820
+ }
821
+ return objects[0];
1623
822
  });
1624
823
  }
1625
-
1626
- /**
1627
- * Adds a constraint for finding string values that contain a provided
1628
- * string. This may be slow for large datasets.
1629
- *
1630
- * @param {string} key The key that the string to match is stored in.
1631
- * @param {string} substring The substring that the value must contain.
1632
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1633
- */
1634
- }, {
1635
- key: "contains",
1636
- value: function (key /*: string*/, substring /*: string*/) /*: ParseQuery*/{
1637
- if (typeof substring !== 'string') {
1638
- throw new Error('The value being searched for must be a string.');
1639
- }
1640
- return this._addCondition(key, '$regex', quote(substring));
1641
- }
1642
-
1643
- /**
1644
- * Adds a constraint for finding string values that contain a provided
1645
- * string. This may be slow for large datasets. Requires Parse-Server > 2.5.0
1646
- *
1647
- * In order to sort you must use select and ascending ($score is required)
1648
- * <pre>
1649
- * query.fullText('field', 'term');
1650
- * query.ascending('$score');
1651
- * query.select('$score');
1652
- * </pre>
1653
- *
1654
- * To retrieve the weight / rank
1655
- * <pre>
1656
- * object->get('score');
1657
- * </pre>
1658
- *
1659
- * You can define optionals by providing an object as a third parameter
1660
- * <pre>
1661
- * query.fullText('field', 'term', { language: 'es', diacriticSensitive: true });
1662
- * </pre>
1663
- *
1664
- * @param {string} key The key that the string to match is stored in.
1665
- * @param {string} value The string to search
1666
- * @param {object} options (Optional)
1667
- * @param {string} options.language The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer.
1668
- * @param {boolean} options.caseSensitive A boolean flag to enable or disable case sensitive search.
1669
- * @param {boolean} options.diacriticSensitive A boolean flag to enable or disable diacritic sensitive search.
1670
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1671
- */
1672
- }, {
1673
- key: "fullText",
1674
- value: function (key /*: string*/, value /*: string*/, options /*: ?Object*/) /*: ParseQuery*/{
1675
- options = options || {};
1676
- if (!key) {
1677
- throw new Error('A key is required.');
1678
- }
1679
- if (!value) {
1680
- throw new Error('A search term is required');
1681
- }
1682
- if (typeof value !== 'string') {
1683
- throw new Error('The value being searched for must be a string.');
824
+ return (0, _find.default)(controller).call(controller, this.className, params, findOptions).then(response => {
825
+ const objects = response.results;
826
+ if (!objects[0]) {
827
+ return undefined;
1684
828
  }
1685
- var fullOptions = {};
1686
- fullOptions.$term = value;
1687
- for (var option in options) {
1688
- switch (option) {
1689
- case 'language':
1690
- fullOptions.$language = options[option];
1691
- break;
1692
- case 'caseSensitive':
1693
- fullOptions.$caseSensitive = options[option];
1694
- break;
1695
- case 'diacriticSensitive':
1696
- fullOptions.$diacriticSensitive = options[option];
1697
- break;
1698
- default:
1699
- throw new Error("Unknown option: ".concat(option));
1700
- }
829
+ if (!objects[0].className) {
830
+ objects[0].className = this.className;
1701
831
  }
1702
- return this._addCondition(key, '$text', {
1703
- $search: fullOptions
1704
- });
1705
- }
1706
-
1707
- /**
1708
- * Method to sort the full text search by text score
1709
- *
1710
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1711
- */
1712
- }, {
1713
- key: "sortByTextScore",
1714
- value: function () {
1715
- this.ascending('$score');
1716
- this.select(['$score']);
1717
- return this;
1718
- }
1719
832
 
1720
- /**
1721
- * Adds a constraint for finding string values that start with a provided
1722
- * string. This query will use the backend index, so it will be fast even
1723
- * for large datasets.
1724
- *
1725
- * @param {string} key The key that the string to match is stored in.
1726
- * @param {string} prefix The substring that the value must start with.
1727
- * @param {string} modifiers The regular expression mode.
1728
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1729
- */
1730
- }, {
1731
- key: "startsWith",
1732
- value: function (key /*: string*/, prefix /*: string*/, modifiers /*: string*/) /*: ParseQuery*/{
1733
- if (typeof prefix !== 'string') {
1734
- throw new Error('The value being searched for must be a string.');
833
+ // Make sure the data object contains keys for all objects that
834
+ // have been requested with a select, so that our cached state
835
+ // updates correctly.
836
+ if (select) {
837
+ handleSelectResult(objects[0], select);
1735
838
  }
1736
- return this.matches(key, this._regexStartWith(prefix), modifiers);
1737
- }
1738
-
1739
- /**
1740
- * Adds a constraint for finding string values that end with a provided
1741
- * string. This will be slow for large datasets.
1742
- *
1743
- * @param {string} key The key that the string to match is stored in.
1744
- * @param {string} suffix The substring that the value must end with.
1745
- * @param {string} modifiers The regular expression mode.
1746
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1747
- */
1748
- }, {
1749
- key: "endsWith",
1750
- value: function (key /*: string*/, suffix /*: string*/, modifiers /*: string*/) /*: ParseQuery*/{
1751
- if (typeof suffix !== 'string') {
1752
- throw new Error('The value being searched for must be a string.');
839
+ if (options.json) {
840
+ return objects[0];
841
+ } else {
842
+ return _ParseObject.default.fromJSON(objects[0], !select);
1753
843
  }
1754
- return this.matches(key, quote(suffix) + '$', modifiers);
1755
- }
844
+ });
845
+ }
1756
846
 
1757
- /**
1758
- * Adds a proximity based constraint for finding objects with key point
1759
- * values near the point given.
1760
- *
1761
- * @param {string} key The key that the Parse.GeoPoint is stored in.
1762
- * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
1763
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1764
- */
1765
- }, {
1766
- key: "near",
1767
- value: function (key /*: string*/, point /*: ParseGeoPoint*/) /*: ParseQuery*/{
1768
- if (!(point instanceof _ParseGeoPoint.default)) {
1769
- // Try to cast it as a GeoPoint
1770
- point = new _ParseGeoPoint.default(point);
847
+ /**
848
+ * Iterates over objects matching a query, calling a callback for each batch.
849
+ * If the callback returns a promise, the iteration will not continue until
850
+ * that promise has been fulfilled. If the callback returns a rejected
851
+ * promise, then iteration will stop with that error. The items are processed
852
+ * in an unspecified order. The query may not have any sort order, and may
853
+ * not use limit or skip.
854
+ *
855
+ * @param {Function} callback Callback that will be called with each result
856
+ * of the query.
857
+ * @param {object} options Valid options are:<ul>
858
+ * <li>batchSize: How many objects to yield in each batch (default: 100)
859
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
860
+ * be used for this request.
861
+ * <li>sessionToken: A valid session token, used for making a request on
862
+ * behalf of a specific user.
863
+ * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
864
+ * </ul>
865
+ * @returns {Promise} A promise that will be fulfilled once the
866
+ * iteration has completed.
867
+ */
868
+ eachBatch(callback, options) {
869
+ options = options || {};
870
+ if (this._order || this._skip || this._limit >= 0) {
871
+ return _promise.default.reject('Cannot iterate on a query with sort, skip, or limit.');
872
+ }
873
+ const query = new ParseQuery(this.className);
874
+ query._limit = options.batchSize || 100;
875
+ query._include = [...this._include];
876
+ query._exclude = [...this._exclude];
877
+ if (this._select) {
878
+ query._select = [...this._select];
879
+ }
880
+ query._hint = this._hint;
881
+ query._where = {};
882
+ for (const attr in this._where) {
883
+ const val = this._where[attr];
884
+ if ((0, _isArray.default)(val)) {
885
+ query._where[attr] = (0, _map.default)(val).call(val, v => {
886
+ return v;
887
+ });
888
+ } else if (val && typeof val === 'object') {
889
+ const conditionMap = {};
890
+ query._where[attr] = conditionMap;
891
+ for (const cond in val) {
892
+ conditionMap[cond] = val[cond];
893
+ }
894
+ } else {
895
+ query._where[attr] = val;
896
+ }
897
+ }
898
+ query.ascending('objectId');
899
+ const findOptions = {};
900
+ if (options.hasOwnProperty('useMasterKey')) {
901
+ findOptions.useMasterKey = options.useMasterKey;
902
+ }
903
+ if (options.hasOwnProperty('sessionToken')) {
904
+ findOptions.sessionToken = options.sessionToken;
905
+ }
906
+ if (options.hasOwnProperty('context') && typeof options.context === 'object') {
907
+ findOptions.context = options.context;
908
+ }
909
+ if (options.hasOwnProperty('json')) {
910
+ findOptions.json = options.json;
911
+ }
912
+ let finished = false;
913
+ let previousResults = [];
914
+ return (0, _promiseUtils.continueWhile)(() => {
915
+ return !finished;
916
+ }, async () => {
917
+ const [results] = await _promise.default.all([(0, _find.default)(query).call(query, findOptions), _promise.default.resolve(previousResults.length > 0 && callback(previousResults))]);
918
+ if (results.length >= query._limit) {
919
+ query.greaterThan('objectId', results[results.length - 1].id);
920
+ previousResults = results;
921
+ } else if (results.length > 0) {
922
+ await _promise.default.resolve(callback(results));
923
+ finished = true;
924
+ } else {
925
+ finished = true;
1771
926
  }
1772
- return this._addCondition(key, '$nearSphere', point);
1773
- }
927
+ });
928
+ }
1774
929
 
1775
- /**
1776
- * Adds a proximity based constraint for finding objects with key point
1777
- * values near the point given and within the maximum distance given.
1778
- *
1779
- * @param {string} key The key that the Parse.GeoPoint is stored in.
1780
- * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
1781
- * @param {number} maxDistance Maximum distance (in radians) of results to return.
1782
- * @param {boolean} sorted A Bool value that is true if results should be
1783
- * sorted by distance ascending, false is no sorting is required,
1784
- * defaults to true.
1785
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1786
- */
1787
- }, {
1788
- key: "withinRadians",
1789
- value: function (key /*: string*/, point /*: ParseGeoPoint*/, maxDistance /*: number*/, sorted /*: boolean*/) /*: ParseQuery*/{
1790
- if (sorted || sorted === undefined) {
1791
- this.near(key, point);
1792
- return this._addCondition(key, '$maxDistance', maxDistance);
1793
- } else {
1794
- return this._addCondition(key, '$geoWithin', {
1795
- $centerSphere: [[point.longitude, point.latitude], maxDistance]
930
+ /**
931
+ * Iterates over each result of a query, calling a callback for each one. If
932
+ * the callback returns a promise, the iteration will not continue until
933
+ * that promise has been fulfilled. If the callback returns a rejected
934
+ * promise, then iteration will stop with that error. The items are
935
+ * processed in an unspecified order. The query may not have any sort order,
936
+ * and may not use limit or skip.
937
+ *
938
+ * @param {Function} callback Callback that will be called with each result
939
+ * of the query.
940
+ * @param {object} options Valid options are:<ul>
941
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
942
+ * be used for this request.
943
+ * <li>sessionToken: A valid session token, used for making a request on
944
+ * behalf of a specific user.
945
+ * <li>json: Return raw json without converting to Parse.Object
946
+ * </ul>
947
+ * @returns {Promise} A promise that will be fulfilled once the
948
+ * iteration has completed.
949
+ */
950
+ each(callback, options) {
951
+ return this.eachBatch(results => {
952
+ let callbacksDone = _promise.default.resolve();
953
+ (0, _forEach.default)(results).call(results, result => {
954
+ callbacksDone = callbacksDone.then(() => {
955
+ return callback(result);
1796
956
  });
1797
- }
1798
- }
957
+ });
958
+ return callbacksDone;
959
+ }, options);
960
+ }
1799
961
 
1800
- /**
1801
- * Adds a proximity based constraint for finding objects with key point
1802
- * values near the point given and within the maximum distance given.
1803
- * Radius of earth used is 3958.8 miles.
1804
- *
1805
- * @param {string} key The key that the Parse.GeoPoint is stored in.
1806
- * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
1807
- * @param {number} maxDistance Maximum distance (in miles) of results to return.
1808
- * @param {boolean} sorted A Bool value that is true if results should be
1809
- * sorted by distance ascending, false is no sorting is required,
1810
- * defaults to true.
1811
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1812
- */
1813
- }, {
1814
- key: "withinMiles",
1815
- value: function (key /*: string*/, point /*: ParseGeoPoint*/, maxDistance /*: number*/, sorted /*: boolean*/) /*: ParseQuery*/{
1816
- return this.withinRadians(key, point, maxDistance / 3958.8, sorted);
962
+ /**
963
+ * Adds a hint to force index selection. (https://docs.mongodb.com/manual/reference/operator/meta/hint/)
964
+ *
965
+ * @param {(string|object)} value String or Object of index that should be used when executing query
966
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
967
+ */
968
+ hint(value) {
969
+ if (typeof value === 'undefined') {
970
+ delete this._hint;
1817
971
  }
972
+ this._hint = value;
973
+ return this;
974
+ }
1818
975
 
1819
- /**
1820
- * Adds a proximity based constraint for finding objects with key point
1821
- * values near the point given and within the maximum distance given.
1822
- * Radius of earth used is 6371.0 kilometers.
1823
- *
1824
- * @param {string} key The key that the Parse.GeoPoint is stored in.
1825
- * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
1826
- * @param {number} maxDistance Maximum distance (in kilometers) of results to return.
1827
- * @param {boolean} sorted A Bool value that is true if results should be
1828
- * sorted by distance ascending, false is no sorting is required,
1829
- * defaults to true.
1830
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1831
- */
1832
- }, {
1833
- key: "withinKilometers",
1834
- value: function (key /*: string*/, point /*: ParseGeoPoint*/, maxDistance /*: number*/, sorted /*: boolean*/) /*: ParseQuery*/{
1835
- return this.withinRadians(key, point, maxDistance / 6371.0, sorted);
976
+ /**
977
+ * Investigates the query execution plan. Useful for optimizing queries. (https://docs.mongodb.com/manual/reference/operator/meta/explain/)
978
+ *
979
+ * @param {boolean} explain Used to toggle the information on the query plan.
980
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
981
+ */
982
+ explain() {
983
+ let explain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
984
+ if (typeof explain !== 'boolean') {
985
+ throw new Error('You can only set explain to a boolean value');
1836
986
  }
987
+ this._explain = explain;
988
+ return this;
989
+ }
1837
990
 
1838
- /**
1839
- * Adds a constraint to the query that requires a particular key's
1840
- * coordinates be contained within a given rectangular geographic bounding
1841
- * box.
1842
- *
1843
- * @param {string} key The key to be constrained.
1844
- * @param {Parse.GeoPoint} southwest
1845
- * The lower-left inclusive corner of the box.
1846
- * @param {Parse.GeoPoint} northeast
1847
- * The upper-right inclusive corner of the box.
1848
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1849
- */
1850
- }, {
1851
- key: "withinGeoBox",
1852
- value: function (key /*: string*/, southwest /*: ParseGeoPoint*/, northeast /*: ParseGeoPoint*/) /*: ParseQuery*/{
1853
- if (!(southwest instanceof _ParseGeoPoint.default)) {
1854
- southwest = new _ParseGeoPoint.default(southwest);
1855
- }
1856
- if (!(northeast instanceof _ParseGeoPoint.default)) {
1857
- northeast = new _ParseGeoPoint.default(northeast);
1858
- }
1859
- this._addCondition(key, '$within', {
1860
- $box: [southwest, northeast]
991
+ /**
992
+ * Iterates over each result of a query, calling a callback for each one. If
993
+ * the callback returns a promise, the iteration will not continue until
994
+ * that promise has been fulfilled. If the callback returns a rejected
995
+ * promise, then iteration will stop with that error. The items are
996
+ * processed in an unspecified order. The query may not have any sort order,
997
+ * and may not use limit or skip.
998
+ *
999
+ * @param {Function} callback Callback <ul>
1000
+ * <li>currentObject: The current Parse.Object being processed in the array.</li>
1001
+ * <li>index: The index of the current Parse.Object being processed in the array.</li>
1002
+ * <li>query: The query map was called upon.</li>
1003
+ * </ul>
1004
+ * @param {object} options Valid options are:<ul>
1005
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1006
+ * be used for this request.
1007
+ * <li>sessionToken: A valid session token, used for making a request on
1008
+ * behalf of a specific user.
1009
+ * </ul>
1010
+ * @returns {Promise} A promise that will be fulfilled once the
1011
+ * iteration has completed.
1012
+ */
1013
+ async map(callback, options) {
1014
+ const array = [];
1015
+ let index = 0;
1016
+ await this.each(object => {
1017
+ return _promise.default.resolve(callback(object, index, this)).then(result => {
1018
+ array.push(result);
1019
+ index += 1;
1861
1020
  });
1862
- return this;
1863
- }
1021
+ }, options);
1022
+ return array;
1023
+ }
1864
1024
 
1865
- /**
1866
- * Adds a constraint to the query that requires a particular key's
1867
- * coordinates be contained within and on the bounds of a given polygon.
1868
- * Supports closed and open (last point is connected to first) paths
1869
- *
1870
- * Polygon must have at least 3 points
1871
- *
1872
- * @param {string} key The key to be constrained.
1873
- * @param {Array} points Array of Coordinates / GeoPoints
1874
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1875
- */
1876
- }, {
1877
- key: "withinPolygon",
1878
- value: function (key /*: string*/, points /*: Array<Array<number>>*/) /*: ParseQuery*/{
1879
- return this._addCondition(key, '$geoWithin', {
1880
- $polygon: points
1025
+ /**
1026
+ * Iterates over each result of a query, calling a callback for each one. If
1027
+ * the callback returns a promise, the iteration will not continue until
1028
+ * that promise has been fulfilled. If the callback returns a rejected
1029
+ * promise, then iteration will stop with that error. The items are
1030
+ * processed in an unspecified order. The query may not have any sort order,
1031
+ * and may not use limit or skip.
1032
+ *
1033
+ * @param {Function} callback Callback <ul>
1034
+ * <li>accumulator: The accumulator accumulates the callback's return values. It is the accumulated value previously returned in the last invocation of the callback.</li>
1035
+ * <li>currentObject: The current Parse.Object being processed in the array.</li>
1036
+ * <li>index: The index of the current Parse.Object being processed in the array.</li>
1037
+ * </ul>
1038
+ * @param {*} initialValue A value to use as the first argument to the first call of the callback. If no initialValue is supplied, the first object in the query will be used and skipped.
1039
+ * @param {object} options Valid options are:<ul>
1040
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1041
+ * be used for this request.
1042
+ * <li>sessionToken: A valid session token, used for making a request on
1043
+ * behalf of a specific user.
1044
+ * </ul>
1045
+ * @returns {Promise} A promise that will be fulfilled once the
1046
+ * iteration has completed.
1047
+ */
1048
+ async reduce(callback, initialValue, options) {
1049
+ let accumulator = initialValue;
1050
+ let index = 0;
1051
+ await this.each(object => {
1052
+ // If no initial value was given, we take the first object from the query
1053
+ // as the initial value and don't call the callback with it.
1054
+ if (index === 0 && initialValue === undefined) {
1055
+ accumulator = object;
1056
+ index += 1;
1057
+ return;
1058
+ }
1059
+ return _promise.default.resolve(callback(accumulator, object, index)).then(result => {
1060
+ accumulator = result;
1061
+ index += 1;
1881
1062
  });
1063
+ }, options);
1064
+ if (index === 0 && initialValue === undefined) {
1065
+ // Match Array.reduce behavior: "Calling reduce() on an empty array
1066
+ // without an initialValue will throw a TypeError".
1067
+ throw new TypeError('Reducing empty query result set with no initial value');
1882
1068
  }
1069
+ return accumulator;
1070
+ }
1883
1071
 
1884
- /**
1885
- * Add a constraint to the query that requires a particular key's
1886
- * coordinates that contains a ParseGeoPoint
1887
- *
1888
- * @param {string} key The key to be constrained.
1889
- * @param {Parse.GeoPoint} point
1890
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1891
- */
1892
- }, {
1893
- key: "polygonContains",
1894
- value: function (key /*: string*/, point /*: ParseGeoPoint*/) /*: ParseQuery*/{
1895
- return this._addCondition(key, '$geoIntersects', {
1896
- $point: point
1072
+ /**
1073
+ * Iterates over each result of a query, calling a callback for each one. If
1074
+ * the callback returns a promise, the iteration will not continue until
1075
+ * that promise has been fulfilled. If the callback returns a rejected
1076
+ * promise, then iteration will stop with that error. The items are
1077
+ * processed in an unspecified order. The query may not have any sort order,
1078
+ * and may not use limit or skip.
1079
+ *
1080
+ * @param {Function} callback Callback <ul>
1081
+ * <li>currentObject: The current Parse.Object being processed in the array.</li>
1082
+ * <li>index: The index of the current Parse.Object being processed in the array.</li>
1083
+ * <li>query: The query filter was called upon.</li>
1084
+ * </ul>
1085
+ * @param {object} options Valid options are:<ul>
1086
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1087
+ * be used for this request.
1088
+ * <li>sessionToken: A valid session token, used for making a request on
1089
+ * behalf of a specific user.
1090
+ * </ul>
1091
+ * @returns {Promise} A promise that will be fulfilled once the
1092
+ * iteration has completed.
1093
+ */
1094
+ async filter(callback, options) {
1095
+ const array = [];
1096
+ let index = 0;
1097
+ await this.each(object => {
1098
+ return _promise.default.resolve(callback(object, index, this)).then(flag => {
1099
+ if (flag) {
1100
+ array.push(object);
1101
+ }
1102
+ index += 1;
1897
1103
  });
1898
- }
1899
-
1900
- /* Query Orderings */
1104
+ }, options);
1105
+ return array;
1106
+ }
1901
1107
 
1902
- /**
1903
- * Sorts the results in ascending order by the given key.
1904
- *
1905
- * @param {(string|string[])} keys The key to order by, which is a
1906
- * string of comma separated values, or an Array of keys, or multiple keys.
1907
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1908
- */
1909
- }, {
1910
- key: "ascending",
1911
- value: function () /*: ParseQuery*/{
1912
- this._order = [];
1913
- for (var _len = arguments.length, keys = new Array(_len), _key5 = 0; _key5 < _len; _key5++) {
1914
- keys[_key5] = arguments[_key5];
1915
- }
1916
- return this.addAscending.apply(this, keys);
1917
- }
1108
+ /* Query Conditions */
1918
1109
 
1919
- /**
1920
- * Sorts the results in ascending order by the given key,
1921
- * but can also add secondary sort descriptors without overwriting _order.
1922
- *
1923
- * @param {(string|string[])} keys The key to order by, which is a
1924
- * string of comma separated values, or an Array of keys, or multiple keys.
1925
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1926
- */
1927
- }, {
1928
- key: "addAscending",
1929
- value: function () /*: ParseQuery*/{
1930
- var _this9 = this;
1931
- if (!this._order) {
1932
- this._order = [];
1933
- }
1934
- for (var _len2 = arguments.length, keys = new Array(_len2), _key6 = 0; _key6 < _len2; _key6++) {
1935
- keys[_key6] = arguments[_key6];
1936
- }
1937
- (0, _forEach.default)(keys).call(keys, function (key) {
1938
- var _context14;
1939
- if ((0, _isArray.default)(key)) {
1940
- key = key.join();
1941
- }
1942
- _this9._order = (0, _concat.default)(_context14 = _this9._order).call(_context14, key.replace(/\s/g, '').split(','));
1110
+ /**
1111
+ * Adds a constraint to the query that requires a particular key's value to
1112
+ * be equal to the provided value.
1113
+ *
1114
+ * @param {string} key The key to check.
1115
+ * @param value The value that the Parse.Object must contain.
1116
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1117
+ */
1118
+ equalTo(key, value) {
1119
+ if (key && typeof key === 'object') {
1120
+ var _context4;
1121
+ (0, _forEach.default)(_context4 = (0, _entries.default)(key)).call(_context4, _ref => {
1122
+ let [k, val] = _ref;
1123
+ return this.equalTo(k, val);
1943
1124
  });
1944
1125
  return this;
1945
1126
  }
1946
-
1947
- /**
1948
- * Sorts the results in descending order by the given key.
1949
- *
1950
- * @param {(string|string[])} keys The key to order by, which is a
1951
- * string of comma separated values, or an Array of keys, or multiple keys.
1952
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1953
- */
1954
- }, {
1955
- key: "descending",
1956
- value: function () /*: ParseQuery*/{
1957
- this._order = [];
1958
- for (var _len3 = arguments.length, keys = new Array(_len3), _key7 = 0; _key7 < _len3; _key7++) {
1959
- keys[_key7] = arguments[_key7];
1960
- }
1961
- return this.addDescending.apply(this, keys);
1127
+ if (typeof value === 'undefined') {
1128
+ return this.doesNotExist(key);
1962
1129
  }
1130
+ this._where[key] = (0, _encode.default)(value, false, true);
1131
+ return this;
1132
+ }
1963
1133
 
1964
- /**
1965
- * Sorts the results in descending order by the given key,
1966
- * but can also add secondary sort descriptors without overwriting _order.
1967
- *
1968
- * @param {(string|string[])} keys The key to order by, which is a
1969
- * string of comma separated values, or an Array of keys, or multiple keys.
1970
- * @returns {Parse.Query} Returns the query, so you can chain this call.
1971
- */
1972
- }, {
1973
- key: "addDescending",
1974
- value: function () /*: ParseQuery*/{
1975
- var _this10 = this;
1976
- if (!this._order) {
1977
- this._order = [];
1978
- }
1979
- for (var _len4 = arguments.length, keys = new Array(_len4), _key8 = 0; _key8 < _len4; _key8++) {
1980
- keys[_key8] = arguments[_key8];
1981
- }
1982
- (0, _forEach.default)(keys).call(keys, function (key) {
1983
- var _context15, _context16;
1984
- if ((0, _isArray.default)(key)) {
1985
- key = key.join();
1986
- }
1987
- _this10._order = (0, _concat.default)(_context15 = _this10._order).call(_context15, (0, _map2.default)(_context16 = key.replace(/\s/g, '').split(',')).call(_context16, function (k) {
1988
- return '-' + k;
1989
- }));
1134
+ /**
1135
+ * Adds a constraint to the query that requires a particular key's value to
1136
+ * be not equal to the provided value.
1137
+ *
1138
+ * @param {string} key The key to check.
1139
+ * @param value The value that must not be equalled.
1140
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1141
+ */
1142
+ notEqualTo(key, value) {
1143
+ if (key && typeof key === 'object') {
1144
+ var _context5;
1145
+ (0, _forEach.default)(_context5 = (0, _entries.default)(key)).call(_context5, _ref2 => {
1146
+ let [k, val] = _ref2;
1147
+ return this.notEqualTo(k, val);
1990
1148
  });
1991
1149
  return this;
1992
1150
  }
1151
+ return this._addCondition(key, '$ne', value);
1152
+ }
1993
1153
 
1994
- /* Query Options */
1154
+ /**
1155
+ * Adds a constraint to the query that requires a particular key's value to
1156
+ * be less than the provided value.
1157
+ *
1158
+ * @param {string} key The key to check.
1159
+ * @param value The value that provides an upper bound.
1160
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1161
+ */
1162
+ lessThan(key, value) {
1163
+ return this._addCondition(key, '$lt', value);
1164
+ }
1995
1165
 
1996
- /**
1997
- * Sets the number of results to skip before returning any results.
1998
- * This is useful for pagination.
1999
- * Default is to skip zero results.
2000
- *
2001
- * @param {number} n the number of results to skip.
2002
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2003
- */
2004
- }, {
2005
- key: "skip",
2006
- value: function (n /*: number*/) /*: ParseQuery*/{
2007
- if (typeof n !== 'number' || n < 0) {
2008
- throw new Error('You can only skip by a positive number');
2009
- }
2010
- this._skip = n;
2011
- return this;
2012
- }
1166
+ /**
1167
+ * Adds a constraint to the query that requires a particular key's value to
1168
+ * be greater than the provided value.
1169
+ *
1170
+ * @param {string} key The key to check.
1171
+ * @param value The value that provides an lower bound.
1172
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1173
+ */
1174
+ greaterThan(key, value) {
1175
+ return this._addCondition(key, '$gt', value);
1176
+ }
2013
1177
 
2014
- /**
2015
- * Sets the limit of the number of results to return. The default limit is 100.
2016
- *
2017
- * @param {number} n the number of results to limit to.
2018
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2019
- */
2020
- }, {
2021
- key: "limit",
2022
- value: function (n /*: number*/) /*: ParseQuery*/{
2023
- if (typeof n !== 'number') {
2024
- throw new Error('You can only set the limit to a numeric value');
2025
- }
2026
- this._limit = n;
2027
- return this;
1178
+ /**
1179
+ * Adds a constraint to the query that requires a particular key's value to
1180
+ * be less than or equal to the provided value.
1181
+ *
1182
+ * @param {string} key The key to check.
1183
+ * @param value The value that provides an upper bound.
1184
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1185
+ */
1186
+ lessThanOrEqualTo(key, value) {
1187
+ return this._addCondition(key, '$lte', value);
1188
+ }
1189
+
1190
+ /**
1191
+ * Adds a constraint to the query that requires a particular key's value to
1192
+ * be greater than or equal to the provided value.
1193
+ *
1194
+ * @param {string} key The key to check.
1195
+ * @param {*} value The value that provides an lower bound.
1196
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1197
+ */
1198
+ greaterThanOrEqualTo(key, value) {
1199
+ return this._addCondition(key, '$gte', value);
1200
+ }
1201
+
1202
+ /**
1203
+ * Adds a constraint to the query that requires a particular key's value to
1204
+ * be contained in the provided list of values.
1205
+ *
1206
+ * @param {string} key The key to check.
1207
+ * @param {Array<*>} value The values that will match.
1208
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1209
+ */
1210
+ containedIn(key, value) {
1211
+ return this._addCondition(key, '$in', value);
1212
+ }
1213
+
1214
+ /**
1215
+ * Adds a constraint to the query that requires a particular key's value to
1216
+ * not be contained in the provided list of values.
1217
+ *
1218
+ * @param {string} key The key to check.
1219
+ * @param {Array<*>} value The values that will not match.
1220
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1221
+ */
1222
+ notContainedIn(key, value) {
1223
+ return this._addCondition(key, '$nin', value);
1224
+ }
1225
+
1226
+ /**
1227
+ * Adds a constraint to the query that requires a particular key's value to
1228
+ * be contained by the provided list of values. Get objects where all array elements match.
1229
+ *
1230
+ * @param {string} key The key to check.
1231
+ * @param {Array} values The values that will match.
1232
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1233
+ */
1234
+ containedBy(key, values) {
1235
+ return this._addCondition(key, '$containedBy', values);
1236
+ }
1237
+
1238
+ /**
1239
+ * Adds a constraint to the query that requires a particular key's value to
1240
+ * contain each one of the provided list of values.
1241
+ *
1242
+ * @param {string} key The key to check. This key's value must be an array.
1243
+ * @param {Array} values The values that will match.
1244
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1245
+ */
1246
+ containsAll(key, values) {
1247
+ return this._addCondition(key, '$all', values);
1248
+ }
1249
+
1250
+ /**
1251
+ * Adds a constraint to the query that requires a particular key's value to
1252
+ * contain each one of the provided list of values starting with given strings.
1253
+ *
1254
+ * @param {string} key The key to check. This key's value must be an array.
1255
+ * @param {Array<string>} values The string values that will match as starting string.
1256
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1257
+ */
1258
+ containsAllStartingWith(key, values) {
1259
+ if (!(0, _isArray.default)(values)) {
1260
+ values = [values];
2028
1261
  }
1262
+ const regexObject = (0, _map.default)(values).call(values, value => {
1263
+ return {
1264
+ $regex: this._regexStartWith(value)
1265
+ };
1266
+ });
1267
+ return this.containsAll(key, regexObject);
1268
+ }
2029
1269
 
2030
- /**
2031
- * Sets the flag to include with response the total number of objects satisfying this query,
2032
- * despite limits/skip. Might be useful for pagination.
2033
- * Note that result of this query will be wrapped as an object with
2034
- * `results`: holding {ParseObject} array and `count`: integer holding total number
2035
- *
2036
- * @param {boolean} includeCount false - disable, true - enable.
2037
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2038
- */
2039
- }, {
2040
- key: "withCount",
2041
- value: function () /*: ParseQuery*/{
2042
- var includeCount /*: boolean*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2043
- if (typeof includeCount !== 'boolean') {
2044
- throw new Error('You can only set withCount to a boolean value');
2045
- }
2046
- this._count = includeCount;
2047
- return this;
1270
+ /**
1271
+ * Adds a constraint for finding objects that contain the given key.
1272
+ *
1273
+ * @param {string} key The key that should exist.
1274
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1275
+ */
1276
+ exists(key) {
1277
+ return this._addCondition(key, '$exists', true);
1278
+ }
1279
+
1280
+ /**
1281
+ * Adds a constraint for finding objects that do not contain a given key.
1282
+ *
1283
+ * @param {string} key The key that should not exist
1284
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1285
+ */
1286
+ doesNotExist(key) {
1287
+ return this._addCondition(key, '$exists', false);
1288
+ }
1289
+
1290
+ /**
1291
+ * Adds a regular expression constraint for finding string values that match
1292
+ * the provided regular expression.
1293
+ * This may be slow for large datasets.
1294
+ *
1295
+ * @param {string} key The key that the string to match is stored in.
1296
+ * @param {RegExp | string} regex The regular expression pattern to match.
1297
+ * @param {string} modifiers The regular expression mode.
1298
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1299
+ */
1300
+ matches(key, regex, modifiers) {
1301
+ this._addCondition(key, '$regex', regex);
1302
+ if (!modifiers) {
1303
+ modifiers = '';
2048
1304
  }
2049
- /**
2050
- * Includes nested Parse.Objects for the provided key. You can use dot
2051
- * notation to specify which fields in the included object are also fetched.
2052
- *
2053
- * You can include all nested Parse.Objects by passing in '*'.
2054
- * Requires Parse Server 3.0.0+
2055
- * <pre>query.include('*');</pre>
2056
- *
2057
- * @param {...string|Array<string>} keys The name(s) of the key(s) to include.
2058
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2059
- */
2060
- }, {
2061
- key: "include",
2062
- value: function () /*: ParseQuery*/{
2063
- var _this11 = this;
2064
- for (var _len5 = arguments.length, keys = new Array(_len5), _key9 = 0; _key9 < _len5; _key9++) {
2065
- keys[_key9] = arguments[_key9];
1305
+ if (typeof regex !== 'string') {
1306
+ if (regex.ignoreCase) {
1307
+ modifiers += 'i';
2066
1308
  }
2067
- (0, _forEach.default)(keys).call(keys, function (key) {
2068
- if ((0, _isArray.default)(key)) {
2069
- var _context17;
2070
- _this11._include = (0, _concat.default)(_context17 = _this11._include).call(_context17, key);
2071
- } else {
2072
- _this11._include.push(key);
2073
- }
2074
- });
2075
- return this;
1309
+ if (regex.multiline) {
1310
+ modifiers += 'm';
1311
+ }
1312
+ }
1313
+ if (modifiers.length) {
1314
+ this._addCondition(key, '$options', modifiers);
2076
1315
  }
1316
+ return this;
1317
+ }
2077
1318
 
2078
- /**
2079
- * Includes all nested Parse.Objects one level deep.
2080
- *
2081
- * Requires Parse Server 3.0.0+
2082
- *
2083
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2084
- */
2085
- }, {
2086
- key: "includeAll",
2087
- value: function () /*: ParseQuery*/{
2088
- return this.include('*');
1319
+ /**
1320
+ * Adds a constraint that requires that a key's value matches a Parse.Query
1321
+ * constraint.
1322
+ *
1323
+ * @param {string} key The key that the contains the object to match the
1324
+ * query.
1325
+ * @param {Parse.Query} query The query that should match.
1326
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1327
+ */
1328
+ matchesQuery(key, query) {
1329
+ const queryJSON = query.toJSON();
1330
+ queryJSON.className = query.className;
1331
+ return this._addCondition(key, '$inQuery', queryJSON);
1332
+ }
1333
+
1334
+ /**
1335
+ * Adds a constraint that requires that a key's value not matches a
1336
+ * Parse.Query constraint.
1337
+ *
1338
+ * @param {string} key The key that the contains the object to match the
1339
+ * query.
1340
+ * @param {Parse.Query} query The query that should not match.
1341
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1342
+ */
1343
+ doesNotMatchQuery(key, query) {
1344
+ const queryJSON = query.toJSON();
1345
+ queryJSON.className = query.className;
1346
+ return this._addCondition(key, '$notInQuery', queryJSON);
1347
+ }
1348
+
1349
+ /**
1350
+ * Adds a constraint that requires that a key's value matches a value in
1351
+ * an object returned by a different Parse.Query.
1352
+ *
1353
+ * @param {string} key The key that contains the value that is being
1354
+ * matched.
1355
+ * @param {string} queryKey The key in the objects returned by the query to
1356
+ * match against.
1357
+ * @param {Parse.Query} query The query to run.
1358
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1359
+ */
1360
+ matchesKeyInQuery(key, queryKey, query) {
1361
+ const queryJSON = query.toJSON();
1362
+ queryJSON.className = query.className;
1363
+ return this._addCondition(key, '$select', {
1364
+ key: queryKey,
1365
+ query: queryJSON
1366
+ });
1367
+ }
1368
+
1369
+ /**
1370
+ * Adds a constraint that requires that a key's value not match a value in
1371
+ * an object returned by a different Parse.Query.
1372
+ *
1373
+ * @param {string} key The key that contains the value that is being
1374
+ * excluded.
1375
+ * @param {string} queryKey The key in the objects returned by the query to
1376
+ * match against.
1377
+ * @param {Parse.Query} query The query to run.
1378
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1379
+ */
1380
+ doesNotMatchKeyInQuery(key, queryKey, query) {
1381
+ const queryJSON = query.toJSON();
1382
+ queryJSON.className = query.className;
1383
+ return this._addCondition(key, '$dontSelect', {
1384
+ key: queryKey,
1385
+ query: queryJSON
1386
+ });
1387
+ }
1388
+
1389
+ /**
1390
+ * Adds a constraint for finding string values that contain a provided
1391
+ * string. This may be slow for large datasets.
1392
+ *
1393
+ * @param {string} key The key that the string to match is stored in.
1394
+ * @param {string} substring The substring that the value must contain.
1395
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1396
+ */
1397
+ contains(key, substring) {
1398
+ if (typeof substring !== 'string') {
1399
+ throw new Error('The value being searched for must be a string.');
2089
1400
  }
1401
+ return this._addCondition(key, '$regex', quote(substring));
1402
+ }
2090
1403
 
2091
- /**
2092
- * Restricts the fields of the returned Parse.Objects to include only the
2093
- * provided keys. If this is called multiple times, then all of the keys
2094
- * specified in each of the calls will be included.
2095
- *
2096
- * @param {...string|Array<string>} keys The name(s) of the key(s) to include.
2097
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2098
- */
2099
- }, {
2100
- key: "select",
2101
- value: function () /*: ParseQuery*/{
2102
- var _this12 = this;
2103
- if (!this._select) {
2104
- this._select = [];
2105
- }
2106
- for (var _len6 = arguments.length, keys = new Array(_len6), _key10 = 0; _key10 < _len6; _key10++) {
2107
- keys[_key10] = arguments[_key10];
2108
- }
2109
- (0, _forEach.default)(keys).call(keys, function (key) {
2110
- if ((0, _isArray.default)(key)) {
2111
- var _context18;
2112
- _this12._select = (0, _concat.default)(_context18 = _this12._select).call(_context18, key);
2113
- } else {
2114
- _this12._select.push(key);
2115
- }
2116
- });
2117
- return this;
1404
+ /**
1405
+ * Adds a constraint for finding string values that contain a provided
1406
+ * string. This may be slow for large datasets. Requires Parse-Server > 2.5.0
1407
+ *
1408
+ * In order to sort you must use select and ascending ($score is required)
1409
+ * <pre>
1410
+ * query.fullText('field', 'term');
1411
+ * query.ascending('$score');
1412
+ * query.select('$score');
1413
+ * </pre>
1414
+ *
1415
+ * To retrieve the weight / rank
1416
+ * <pre>
1417
+ * object->get('score');
1418
+ * </pre>
1419
+ *
1420
+ * You can define optionals by providing an object as a third parameter
1421
+ * <pre>
1422
+ * query.fullText('field', 'term', { language: 'es', diacriticSensitive: true });
1423
+ * </pre>
1424
+ *
1425
+ * @param {string} key The key that the string to match is stored in.
1426
+ * @param {string} value The string to search
1427
+ * @param {object} options (Optional)
1428
+ * @param {string} options.language The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer.
1429
+ * @param {boolean} options.caseSensitive A boolean flag to enable or disable case sensitive search.
1430
+ * @param {boolean} options.diacriticSensitive A boolean flag to enable or disable diacritic sensitive search.
1431
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1432
+ */
1433
+ fullText(key, value) {
1434
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1435
+ options = options || {};
1436
+ if (!key) {
1437
+ throw new Error('A key is required.');
1438
+ }
1439
+ if (!value) {
1440
+ throw new Error('A search term is required');
1441
+ }
1442
+ if (typeof value !== 'string') {
1443
+ throw new Error('The value being searched for must be a string.');
1444
+ }
1445
+ const fullOptions = {};
1446
+ fullOptions.$term = value;
1447
+ for (const option in options) {
1448
+ switch (option) {
1449
+ case 'language':
1450
+ fullOptions.$language = options[option];
1451
+ break;
1452
+ case 'caseSensitive':
1453
+ fullOptions.$caseSensitive = options[option];
1454
+ break;
1455
+ case 'diacriticSensitive':
1456
+ fullOptions.$diacriticSensitive = options[option];
1457
+ break;
1458
+ default:
1459
+ throw new Error(`Unknown option: ${option}`);
1460
+ }
1461
+ }
1462
+ return this._addCondition(key, '$text', {
1463
+ $search: fullOptions
1464
+ });
1465
+ }
1466
+
1467
+ /**
1468
+ * Method to sort the full text search by text score
1469
+ *
1470
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1471
+ */
1472
+ sortByTextScore() {
1473
+ this.ascending('$score');
1474
+ this.select(['$score']);
1475
+ return this;
1476
+ }
1477
+
1478
+ /**
1479
+ * Adds a constraint for finding string values that start with a provided
1480
+ * string. This query will use the backend index, so it will be fast even
1481
+ * for large datasets.
1482
+ *
1483
+ * @param {string} key The key that the string to match is stored in.
1484
+ * @param {string} prefix The substring that the value must start with.
1485
+ * @param {string} modifiers The regular expression mode.
1486
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1487
+ */
1488
+ startsWith(key, prefix, modifiers) {
1489
+ if (typeof prefix !== 'string') {
1490
+ throw new Error('The value being searched for must be a string.');
2118
1491
  }
1492
+ return this.matches(key, this._regexStartWith(prefix), modifiers);
1493
+ }
2119
1494
 
2120
- /**
2121
- * Restricts the fields of the returned Parse.Objects to all keys except the
2122
- * provided keys. Exclude takes precedence over select and include.
2123
- *
2124
- * Requires Parse Server 3.6.0+
2125
- *
2126
- * @param {...string|Array<string>} keys The name(s) of the key(s) to exclude.
2127
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2128
- */
2129
- }, {
2130
- key: "exclude",
2131
- value: function () /*: ParseQuery*/{
2132
- var _this13 = this;
2133
- for (var _len7 = arguments.length, keys = new Array(_len7), _key11 = 0; _key11 < _len7; _key11++) {
2134
- keys[_key11] = arguments[_key11];
2135
- }
2136
- (0, _forEach.default)(keys).call(keys, function (key) {
2137
- if ((0, _isArray.default)(key)) {
2138
- var _context19;
2139
- _this13._exclude = (0, _concat.default)(_context19 = _this13._exclude).call(_context19, key);
2140
- } else {
2141
- _this13._exclude.push(key);
2142
- }
2143
- });
2144
- return this;
1495
+ /**
1496
+ * Adds a constraint for finding string values that end with a provided
1497
+ * string. This will be slow for large datasets.
1498
+ *
1499
+ * @param {string} key The key that the string to match is stored in.
1500
+ * @param {string} suffix The substring that the value must end with.
1501
+ * @param {string} modifiers The regular expression mode.
1502
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1503
+ */
1504
+ endsWith(key, suffix, modifiers) {
1505
+ if (typeof suffix !== 'string') {
1506
+ throw new Error('The value being searched for must be a string.');
2145
1507
  }
1508
+ return this.matches(key, quote(suffix) + '$', modifiers);
1509
+ }
2146
1510
 
2147
- /**
2148
- * Restricts live query to trigger only for watched fields.
2149
- *
2150
- * Requires Parse Server 6.0.0+
2151
- *
2152
- * @param {...string|Array<string>} keys The name(s) of the key(s) to watch.
2153
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2154
- */
2155
- }, {
2156
- key: "watch",
2157
- value: function () /*: ParseQuery*/{
2158
- var _this14 = this;
2159
- for (var _len8 = arguments.length, keys = new Array(_len8), _key12 = 0; _key12 < _len8; _key12++) {
2160
- keys[_key12] = arguments[_key12];
2161
- }
2162
- (0, _forEach.default)(keys).call(keys, function (key) {
2163
- if ((0, _isArray.default)(key)) {
2164
- var _context20;
2165
- _this14._watch = (0, _concat.default)(_context20 = _this14._watch).call(_context20, key);
2166
- } else {
2167
- _this14._watch.push(key);
2168
- }
1511
+ /**
1512
+ * Adds a proximity based constraint for finding objects with key point
1513
+ * values near the point given.
1514
+ *
1515
+ * @param {string} key The key that the Parse.GeoPoint is stored in.
1516
+ * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
1517
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1518
+ */
1519
+ near(key, point) {
1520
+ if (!(point instanceof _ParseGeoPoint.default)) {
1521
+ // Try to cast it as a GeoPoint
1522
+ point = new _ParseGeoPoint.default(point);
1523
+ }
1524
+ return this._addCondition(key, '$nearSphere', point);
1525
+ }
1526
+
1527
+ /**
1528
+ * Adds a proximity based constraint for finding objects with key point
1529
+ * values near the point given and within the maximum distance given.
1530
+ *
1531
+ * @param {string} key The key that the Parse.GeoPoint is stored in.
1532
+ * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
1533
+ * @param {number} maxDistance Maximum distance (in radians) of results to return.
1534
+ * @param {boolean} sorted A Bool value that is true if results should be
1535
+ * sorted by distance ascending, false is no sorting is required,
1536
+ * defaults to true.
1537
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1538
+ */
1539
+ withinRadians(key, point, maxDistance, sorted) {
1540
+ if (sorted || sorted === undefined) {
1541
+ this.near(key, point);
1542
+ return this._addCondition(key, '$maxDistance', maxDistance);
1543
+ } else {
1544
+ return this._addCondition(key, '$geoWithin', {
1545
+ $centerSphere: [[point.longitude, point.latitude], maxDistance]
2169
1546
  });
2170
- return this;
2171
1547
  }
1548
+ }
2172
1549
 
2173
- /**
2174
- * Changes the read preference that the backend will use when performing the query to the database.
2175
- *
2176
- * @param {string} readPreference The read preference for the main query.
2177
- * @param {string} includeReadPreference The read preference for the queries to include pointers.
2178
- * @param {string} subqueryReadPreference The read preference for the sub queries.
2179
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2180
- */
2181
- }, {
2182
- key: "readPreference",
2183
- value: function (_readPreference /*: string*/, includeReadPreference /*:: ?: string*/, subqueryReadPreference /*:: ?: string*/) /*: ParseQuery*/{
2184
- this._readPreference = _readPreference;
2185
- this._includeReadPreference = includeReadPreference;
2186
- this._subqueryReadPreference = subqueryReadPreference;
2187
- return this;
1550
+ /**
1551
+ * Adds a proximity based constraint for finding objects with key point
1552
+ * values near the point given and within the maximum distance given.
1553
+ * Radius of earth used is 3958.8 miles.
1554
+ *
1555
+ * @param {string} key The key that the Parse.GeoPoint is stored in.
1556
+ * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
1557
+ * @param {number} maxDistance Maximum distance (in miles) of results to return.
1558
+ * @param {boolean} sorted A Bool value that is true if results should be
1559
+ * sorted by distance ascending, false is no sorting is required,
1560
+ * defaults to true.
1561
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1562
+ */
1563
+ withinMiles(key, point, maxDistance, sorted) {
1564
+ return this.withinRadians(key, point, maxDistance / 3958.8, sorted);
1565
+ }
1566
+
1567
+ /**
1568
+ * Adds a proximity based constraint for finding objects with key point
1569
+ * values near the point given and within the maximum distance given.
1570
+ * Radius of earth used is 6371.0 kilometers.
1571
+ *
1572
+ * @param {string} key The key that the Parse.GeoPoint is stored in.
1573
+ * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
1574
+ * @param {number} maxDistance Maximum distance (in kilometers) of results to return.
1575
+ * @param {boolean} sorted A Bool value that is true if results should be
1576
+ * sorted by distance ascending, false is no sorting is required,
1577
+ * defaults to true.
1578
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1579
+ */
1580
+ withinKilometers(key, point, maxDistance, sorted) {
1581
+ return this.withinRadians(key, point, maxDistance / 6371.0, sorted);
1582
+ }
1583
+
1584
+ /**
1585
+ * Adds a constraint to the query that requires a particular key's
1586
+ * coordinates be contained within a given rectangular geographic bounding
1587
+ * box.
1588
+ *
1589
+ * @param {string} key The key to be constrained.
1590
+ * @param {Parse.GeoPoint} southwest
1591
+ * The lower-left inclusive corner of the box.
1592
+ * @param {Parse.GeoPoint} northeast
1593
+ * The upper-right inclusive corner of the box.
1594
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1595
+ */
1596
+ withinGeoBox(key, southwest, northeast) {
1597
+ if (!(southwest instanceof _ParseGeoPoint.default)) {
1598
+ southwest = new _ParseGeoPoint.default(southwest);
2188
1599
  }
1600
+ if (!(northeast instanceof _ParseGeoPoint.default)) {
1601
+ northeast = new _ParseGeoPoint.default(northeast);
1602
+ }
1603
+ this._addCondition(key, '$within', {
1604
+ $box: [southwest, northeast]
1605
+ });
1606
+ return this;
1607
+ }
2189
1608
 
2190
- /**
2191
- * Subscribe this query to get liveQuery updates
2192
- *
2193
- * @param {string} sessionToken (optional) Defaults to the currentUser
2194
- * @returns {Promise<LiveQuerySubscription>} Returns the liveQuerySubscription, it's an event emitter
2195
- * which can be used to get liveQuery updates.
2196
- */
2197
- }, {
2198
- key: "subscribe",
2199
- value: function () {
2200
- var _subscribe = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(sessionToken /*:: ?: string*/) {
2201
- var currentUser, liveQueryClient, subscription;
2202
- return _regenerator.default.wrap(function (_context21) {
2203
- while (1) switch (_context21.prev = _context21.next) {
2204
- case 0:
2205
- _context21.next = 2;
2206
- return _CoreManager.default.getUserController().currentUserAsync();
2207
- case 2:
2208
- currentUser = _context21.sent;
2209
- if (!sessionToken) {
2210
- sessionToken = currentUser ? currentUser.getSessionToken() : undefined;
2211
- }
2212
- _context21.next = 6;
2213
- return _CoreManager.default.getLiveQueryController().getDefaultLiveQueryClient();
2214
- case 6:
2215
- liveQueryClient = _context21.sent;
2216
- if (liveQueryClient.shouldOpen()) {
2217
- liveQueryClient.open();
2218
- }
2219
- subscription = liveQueryClient.subscribe(this, sessionToken);
2220
- return _context21.abrupt("return", subscription.subscribePromise.then(function () {
2221
- return subscription;
2222
- }));
2223
- case 10:
2224
- case "end":
2225
- return _context21.stop();
2226
- }
2227
- }, _callee7, this);
2228
- }));
2229
- function subscribe() {
2230
- return _subscribe.apply(this, arguments);
2231
- }
2232
- return subscribe;
2233
- }()
2234
- /**
2235
- * Constructs a Parse.Query that is the OR of the passed in queries. For
2236
- * example:
2237
- * <pre>var compoundQuery = Parse.Query.or(query1, query2, query3);</pre>
2238
- *
2239
- * will create a compoundQuery that is an or of the query1, query2, and
2240
- * query3.
2241
- *
2242
- * @param {...Parse.Query} queries The list of queries to OR.
2243
- * @static
2244
- * @returns {Parse.Query} The query that is the OR of the passed in queries.
2245
- */
2246
- }, {
2247
- key: "fromNetwork",
2248
- value:
2249
- /**
2250
- * Change the source of this query to the server.
2251
- *
2252
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2253
- */
2254
- function () /*: ParseQuery*/{
2255
- this._queriesLocalDatastore = false;
2256
- this._localDatastorePinName = null;
2257
- return this;
1609
+ /**
1610
+ * Adds a constraint to the query that requires a particular key's
1611
+ * coordinates be contained within and on the bounds of a given polygon.
1612
+ * Supports closed and open (last point is connected to first) paths
1613
+ *
1614
+ * Polygon must have at least 3 points
1615
+ *
1616
+ * @param {string} key The key to be constrained.
1617
+ * @param {Array} points Array of Coordinates / GeoPoints
1618
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1619
+ */
1620
+ withinPolygon(key, points) {
1621
+ return this._addCondition(key, '$geoWithin', {
1622
+ $polygon: points
1623
+ });
1624
+ }
1625
+
1626
+ /**
1627
+ * Add a constraint to the query that requires a particular key's
1628
+ * coordinates that contains a ParseGeoPoint
1629
+ *
1630
+ * @param {string} key The key to be constrained.
1631
+ * @param {Parse.GeoPoint} point
1632
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1633
+ */
1634
+ polygonContains(key, point) {
1635
+ return this._addCondition(key, '$geoIntersects', {
1636
+ $point: point
1637
+ });
1638
+ }
1639
+
1640
+ /* Query Orderings */
1641
+
1642
+ /**
1643
+ * Sorts the results in ascending order by the given key.
1644
+ *
1645
+ * @param {(string|string[])} keys The key to order by, which is a
1646
+ * string of comma separated values, or an Array of keys, or multiple keys.
1647
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1648
+ */
1649
+ ascending() {
1650
+ this._order = [];
1651
+ for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
1652
+ keys[_key] = arguments[_key];
2258
1653
  }
1654
+ return this.addAscending.apply(this, keys);
1655
+ }
2259
1656
 
2260
- /**
2261
- * Changes the source of this query to all pinned objects.
2262
- *
2263
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2264
- */
2265
- }, {
2266
- key: "fromLocalDatastore",
2267
- value: function () /*: ParseQuery*/{
2268
- return this.fromPinWithName(null);
1657
+ /**
1658
+ * Sorts the results in ascending order by the given key,
1659
+ * but can also add secondary sort descriptors without overwriting _order.
1660
+ *
1661
+ * @param {(string|string[])} keys The key to order by, which is a
1662
+ * string of comma separated values, or an Array of keys, or multiple keys.
1663
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1664
+ */
1665
+ addAscending() {
1666
+ if (!this._order) {
1667
+ this._order = [];
1668
+ }
1669
+ for (var _len2 = arguments.length, keys = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1670
+ keys[_key2] = arguments[_key2];
2269
1671
  }
1672
+ (0, _forEach.default)(keys).call(keys, key => {
1673
+ var _context6;
1674
+ if ((0, _isArray.default)(key)) {
1675
+ key = key.join();
1676
+ }
1677
+ this._order = (0, _concat.default)(_context6 = this._order).call(_context6, key.replace(/\s/g, '').split(','));
1678
+ });
1679
+ return this;
1680
+ }
2270
1681
 
2271
- /**
2272
- * Changes the source of this query to the default group of pinned objects.
2273
- *
2274
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2275
- */
2276
- }, {
2277
- key: "fromPin",
2278
- value: function () /*: ParseQuery*/{
2279
- return this.fromPinWithName(_LocalDatastoreUtils.DEFAULT_PIN);
1682
+ /**
1683
+ * Sorts the results in descending order by the given key.
1684
+ *
1685
+ * @param {(string|string[])} keys The key to order by, which is a
1686
+ * string of comma separated values, or an Array of keys, or multiple keys.
1687
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1688
+ */
1689
+ descending() {
1690
+ this._order = [];
1691
+ for (var _len3 = arguments.length, keys = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1692
+ keys[_key3] = arguments[_key3];
2280
1693
  }
1694
+ return this.addDescending.apply(this, keys);
1695
+ }
2281
1696
 
2282
- /**
2283
- * Changes the source of this query to a specific group of pinned objects.
2284
- *
2285
- * @param {string} name The name of query source.
2286
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2287
- */
2288
- }, {
2289
- key: "fromPinWithName",
2290
- value: function (name /*:: ?: string*/) /*: ParseQuery*/{
2291
- var localDatastore = _CoreManager.default.getLocalDatastore();
2292
- if (localDatastore.checkIfEnabled()) {
2293
- this._queriesLocalDatastore = true;
2294
- this._localDatastorePinName = name;
1697
+ /**
1698
+ * Sorts the results in descending order by the given key,
1699
+ * but can also add secondary sort descriptors without overwriting _order.
1700
+ *
1701
+ * @param {(string|string[])} keys The key to order by, which is a
1702
+ * string of comma separated values, or an Array of keys, or multiple keys.
1703
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1704
+ */
1705
+ addDescending() {
1706
+ if (!this._order) {
1707
+ this._order = [];
1708
+ }
1709
+ for (var _len4 = arguments.length, keys = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1710
+ keys[_key4] = arguments[_key4];
1711
+ }
1712
+ (0, _forEach.default)(keys).call(keys, key => {
1713
+ var _context7, _context8;
1714
+ if ((0, _isArray.default)(key)) {
1715
+ key = key.join();
2295
1716
  }
2296
- return this;
1717
+ this._order = (0, _concat.default)(_context7 = this._order).call(_context7, (0, _map.default)(_context8 = key.replace(/\s/g, '').split(',')).call(_context8, k => {
1718
+ return '-' + k;
1719
+ }));
1720
+ });
1721
+ return this;
1722
+ }
1723
+
1724
+ /* Query Options */
1725
+
1726
+ /**
1727
+ * Sets the number of results to skip before returning any results.
1728
+ * This is useful for pagination.
1729
+ * Default is to skip zero results.
1730
+ *
1731
+ * @param {number} n the number of results to skip.
1732
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1733
+ */
1734
+ skip(n) {
1735
+ if (typeof n !== 'number' || n < 0) {
1736
+ throw new Error('You can only skip by a positive number');
2297
1737
  }
1738
+ this._skip = n;
1739
+ return this;
1740
+ }
2298
1741
 
2299
- /**
2300
- * Cancels the current network request (if any is running).
2301
- *
2302
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2303
- */
2304
- }, {
2305
- key: "cancel",
2306
- value: function () /*: ParseQuery*/{
2307
- var _this15 = this;
2308
- if (this._xhrRequest.task && typeof this._xhrRequest.task.abort === 'function') {
2309
- this._xhrRequest.task._aborted = true;
2310
- this._xhrRequest.task.abort();
2311
- this._xhrRequest.task = null;
2312
- this._xhrRequest.onchange = function () {};
2313
- return this;
2314
- }
2315
- return this._xhrRequest.onchange = function () {
2316
- return _this15.cancel();
2317
- };
1742
+ /**
1743
+ * Sets the limit of the number of results to return. The default limit is 100.
1744
+ *
1745
+ * @param {number} n the number of results to limit to.
1746
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1747
+ */
1748
+ limit(n) {
1749
+ if (typeof n !== 'number') {
1750
+ throw new Error('You can only set the limit to a numeric value');
2318
1751
  }
2319
- }, {
2320
- key: "_setRequestTask",
2321
- value: function (options) {
2322
- var _this16 = this;
2323
- options.requestTask = function (task) {
2324
- _this16._xhrRequest.task = task;
2325
- _this16._xhrRequest.onchange();
2326
- };
1752
+ this._limit = n;
1753
+ return this;
1754
+ }
1755
+
1756
+ /**
1757
+ * Sets the flag to include with response the total number of objects satisfying this query,
1758
+ * despite limits/skip. Might be useful for pagination.
1759
+ * Note that result of this query will be wrapped as an object with
1760
+ * `results`: holding {ParseObject} array and `count`: integer holding total number
1761
+ *
1762
+ * @param {boolean} includeCount false - disable, true - enable.
1763
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1764
+ */
1765
+ withCount() {
1766
+ let includeCount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1767
+ if (typeof includeCount !== 'boolean') {
1768
+ throw new Error('You can only set withCount to a boolean value');
2327
1769
  }
1770
+ this._count = includeCount;
1771
+ return this;
1772
+ }
1773
+ /**
1774
+ * Includes nested Parse.Objects for the provided key. You can use dot
1775
+ * notation to specify which fields in the included object are also fetched.
1776
+ *
1777
+ * You can include all nested Parse.Objects by passing in '*'.
1778
+ * Requires Parse Server 3.0.0+
1779
+ * <pre>query.include('*');</pre>
1780
+ *
1781
+ * @param {...string|Array<string>} keys The name(s) of the key(s) to include.
1782
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1783
+ */
1784
+ include() {
1785
+ for (var _len5 = arguments.length, keys = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1786
+ keys[_key5] = arguments[_key5];
1787
+ }
1788
+ (0, _forEach.default)(keys).call(keys, key => {
1789
+ if ((0, _isArray.default)(key)) {
1790
+ var _context9;
1791
+ this._include = (0, _concat.default)(_context9 = this._include).call(_context9, key);
1792
+ } else {
1793
+ this._include.push(key);
1794
+ }
1795
+ });
1796
+ return this;
1797
+ }
2328
1798
 
2329
- /**
2330
- * Sets a comment to the query so that the query
2331
- *can be identified when using a the profiler for MongoDB.
2332
- *
2333
- * @param {string} value a comment can make your profile data easier to interpret and trace.
2334
- * @returns {Parse.Query} Returns the query, so you can chain this call.
2335
- */
2336
- }, {
2337
- key: "comment",
2338
- value: function (value /*: string*/) /*: ParseQuery*/{
2339
- if (value == null) {
2340
- delete this._comment;
2341
- return this;
1799
+ /**
1800
+ * Includes all nested Parse.Objects one level deep.
1801
+ *
1802
+ * Requires Parse Server 3.0.0+
1803
+ *
1804
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1805
+ */
1806
+ includeAll() {
1807
+ return this.include('*');
1808
+ }
1809
+
1810
+ /**
1811
+ * Restricts the fields of the returned Parse.Objects to include only the
1812
+ * provided keys. If this is called multiple times, then all of the keys
1813
+ * specified in each of the calls will be included.
1814
+ *
1815
+ * @param {...string|Array<string>} keys The name(s) of the key(s) to include.
1816
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1817
+ */
1818
+ select() {
1819
+ if (!this._select) {
1820
+ this._select = [];
1821
+ }
1822
+ for (var _len6 = arguments.length, keys = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1823
+ keys[_key6] = arguments[_key6];
1824
+ }
1825
+ (0, _forEach.default)(keys).call(keys, key => {
1826
+ if ((0, _isArray.default)(key)) {
1827
+ var _context10;
1828
+ this._select = (0, _concat.default)(_context10 = this._select).call(_context10, key);
1829
+ } else {
1830
+ this._select.push(key);
2342
1831
  }
2343
- if (typeof value !== 'string') {
2344
- throw new Error('The value of a comment to be sent with this query must be a string.');
1832
+ });
1833
+ return this;
1834
+ }
1835
+
1836
+ /**
1837
+ * Restricts the fields of the returned Parse.Objects to all keys except the
1838
+ * provided keys. Exclude takes precedence over select and include.
1839
+ *
1840
+ * Requires Parse Server 3.6.0+
1841
+ *
1842
+ * @param {...string|Array<string>} keys The name(s) of the key(s) to exclude.
1843
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1844
+ */
1845
+ exclude() {
1846
+ for (var _len7 = arguments.length, keys = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
1847
+ keys[_key7] = arguments[_key7];
1848
+ }
1849
+ (0, _forEach.default)(keys).call(keys, key => {
1850
+ if ((0, _isArray.default)(key)) {
1851
+ var _context11;
1852
+ this._exclude = (0, _concat.default)(_context11 = this._exclude).call(_context11, key);
1853
+ } else {
1854
+ this._exclude.push(key);
2345
1855
  }
2346
- this._comment = value;
2347
- return this;
1856
+ });
1857
+ return this;
1858
+ }
1859
+
1860
+ /**
1861
+ * Restricts live query to trigger only for watched fields.
1862
+ *
1863
+ * Requires Parse Server 6.0.0+
1864
+ *
1865
+ * @param {...string|Array<string>} keys The name(s) of the key(s) to watch.
1866
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1867
+ */
1868
+ watch() {
1869
+ for (var _len8 = arguments.length, keys = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
1870
+ keys[_key8] = arguments[_key8];
2348
1871
  }
2349
- }], [{
2350
- key: "fromJSON",
2351
- value: function (className /*: string*/, json /*: QueryJSON*/) /*: ParseQuery*/{
2352
- var query = new ParseQuery(className);
2353
- return query.withJSON(json);
2354
- }
2355
- }, {
2356
- key: "or",
2357
- value: function () /*: ParseQuery*/{
2358
- for (var _len9 = arguments.length, queries = new Array(_len9), _key13 = 0; _key13 < _len9; _key13++) {
2359
- queries[_key13] = arguments[_key13];
1872
+ (0, _forEach.default)(keys).call(keys, key => {
1873
+ if ((0, _isArray.default)(key)) {
1874
+ var _context12;
1875
+ this._watch = (0, _concat.default)(_context12 = this._watch).call(_context12, key);
1876
+ } else {
1877
+ this._watch.push(key);
2360
1878
  }
2361
- var className = _getClassNameFromQueries(queries);
2362
- var query = new ParseQuery(className);
2363
- query._orQuery(queries);
2364
- return query;
1879
+ });
1880
+ return this;
1881
+ }
1882
+
1883
+ /**
1884
+ * Changes the read preference that the backend will use when performing the query to the database.
1885
+ *
1886
+ * @param {string} readPreference The read preference for the main query.
1887
+ * @param {string} includeReadPreference The read preference for the queries to include pointers.
1888
+ * @param {string} subqueryReadPreference The read preference for the sub queries.
1889
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1890
+ */
1891
+ readPreference(readPreference, includeReadPreference, subqueryReadPreference) {
1892
+ this._readPreference = readPreference;
1893
+ this._includeReadPreference = includeReadPreference || null;
1894
+ this._subqueryReadPreference = subqueryReadPreference || null;
1895
+ return this;
1896
+ }
1897
+
1898
+ /**
1899
+ * Subscribe this query to get liveQuery updates
1900
+ *
1901
+ * @param {string} sessionToken (optional) Defaults to the currentUser
1902
+ * @returns {Promise<LiveQuerySubscription>} Returns the liveQuerySubscription, it's an event emitter
1903
+ * which can be used to get liveQuery updates.
1904
+ */
1905
+ async subscribe(sessionToken) {
1906
+ const currentUser = await _CoreManager.default.getUserController().currentUserAsync();
1907
+ if (!sessionToken) {
1908
+ sessionToken = currentUser ? currentUser.getSessionToken() || undefined : undefined;
1909
+ }
1910
+ const liveQueryClient = await _CoreManager.default.getLiveQueryController().getDefaultLiveQueryClient();
1911
+ if (liveQueryClient.shouldOpen()) {
1912
+ liveQueryClient.open();
1913
+ }
1914
+ const subscription = liveQueryClient.subscribe(this, sessionToken);
1915
+ return subscription.subscribePromise.then(() => {
1916
+ return subscription;
1917
+ });
1918
+ }
1919
+
1920
+ /**
1921
+ * Constructs a Parse.Query that is the OR of the passed in queries. For
1922
+ * example:
1923
+ * <pre>var compoundQuery = Parse.Query.or(query1, query2, query3);</pre>
1924
+ *
1925
+ * will create a compoundQuery that is an or of the query1, query2, and
1926
+ * query3.
1927
+ *
1928
+ * @param {...Parse.Query} queries The list of queries to OR.
1929
+ * @static
1930
+ * @returns {Parse.Query} The query that is the OR of the passed in queries.
1931
+ */
1932
+ static or() {
1933
+ for (var _len9 = arguments.length, queries = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
1934
+ queries[_key9] = arguments[_key9];
1935
+ }
1936
+ const className = _getClassNameFromQueries(queries);
1937
+ const query = new ParseQuery(className);
1938
+ query._orQuery(queries);
1939
+ return query;
1940
+ }
1941
+
1942
+ /**
1943
+ * Constructs a Parse.Query that is the AND of the passed in queries. For
1944
+ * example:
1945
+ * <pre>var compoundQuery = Parse.Query.and(query1, query2, query3);</pre>
1946
+ *
1947
+ * will create a compoundQuery that is an and of the query1, query2, and
1948
+ * query3.
1949
+ *
1950
+ * @param {...Parse.Query} queries The list of queries to AND.
1951
+ * @static
1952
+ * @returns {Parse.Query} The query that is the AND of the passed in queries.
1953
+ */
1954
+ static and() {
1955
+ for (var _len10 = arguments.length, queries = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
1956
+ queries[_key10] = arguments[_key10];
1957
+ }
1958
+ const className = _getClassNameFromQueries(queries);
1959
+ const query = new ParseQuery(className);
1960
+ query._andQuery(queries);
1961
+ return query;
1962
+ }
1963
+
1964
+ /**
1965
+ * Constructs a Parse.Query that is the NOR of the passed in queries. For
1966
+ * example:
1967
+ * <pre>const compoundQuery = Parse.Query.nor(query1, query2, query3);</pre>
1968
+ *
1969
+ * will create a compoundQuery that is a nor of the query1, query2, and
1970
+ * query3.
1971
+ *
1972
+ * @param {...Parse.Query} queries The list of queries to NOR.
1973
+ * @static
1974
+ * @returns {Parse.Query} The query that is the NOR of the passed in queries.
1975
+ */
1976
+ static nor() {
1977
+ for (var _len11 = arguments.length, queries = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
1978
+ queries[_key11] = arguments[_key11];
1979
+ }
1980
+ const className = _getClassNameFromQueries(queries);
1981
+ const query = new ParseQuery(className);
1982
+ query._norQuery(queries);
1983
+ return query;
1984
+ }
1985
+
1986
+ /**
1987
+ * Change the source of this query to the server.
1988
+ *
1989
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
1990
+ */
1991
+ fromNetwork() {
1992
+ this._queriesLocalDatastore = false;
1993
+ this._localDatastorePinName = null;
1994
+ return this;
1995
+ }
1996
+
1997
+ /**
1998
+ * Changes the source of this query to all pinned objects.
1999
+ *
2000
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
2001
+ */
2002
+ fromLocalDatastore() {
2003
+ return this.fromPinWithName(null);
2004
+ }
2005
+
2006
+ /**
2007
+ * Changes the source of this query to the default group of pinned objects.
2008
+ *
2009
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
2010
+ */
2011
+ fromPin() {
2012
+ return this.fromPinWithName(_LocalDatastoreUtils.DEFAULT_PIN);
2013
+ }
2014
+
2015
+ /**
2016
+ * Changes the source of this query to a specific group of pinned objects.
2017
+ *
2018
+ * @param {string} name The name of query source.
2019
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
2020
+ */
2021
+ fromPinWithName(name) {
2022
+ const localDatastore = _CoreManager.default.getLocalDatastore();
2023
+ if (localDatastore.checkIfEnabled()) {
2024
+ this._queriesLocalDatastore = true;
2025
+ this._localDatastorePinName = name;
2365
2026
  }
2027
+ return this;
2028
+ }
2366
2029
 
2367
- /**
2368
- * Constructs a Parse.Query that is the AND of the passed in queries. For
2369
- * example:
2370
- * <pre>var compoundQuery = Parse.Query.and(query1, query2, query3);</pre>
2371
- *
2372
- * will create a compoundQuery that is an and of the query1, query2, and
2373
- * query3.
2374
- *
2375
- * @param {...Parse.Query} queries The list of queries to AND.
2376
- * @static
2377
- * @returns {Parse.Query} The query that is the AND of the passed in queries.
2378
- */
2379
- }, {
2380
- key: "and",
2381
- value: function () /*: ParseQuery*/{
2382
- for (var _len10 = arguments.length, queries = new Array(_len10), _key14 = 0; _key14 < _len10; _key14++) {
2383
- queries[_key14] = arguments[_key14];
2384
- }
2385
- var className = _getClassNameFromQueries(queries);
2386
- var query = new ParseQuery(className);
2387
- query._andQuery(queries);
2388
- return query;
2030
+ /**
2031
+ * Cancels the current network request (if any is running).
2032
+ *
2033
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
2034
+ */
2035
+ cancel() {
2036
+ if (this._xhrRequest.task && typeof this._xhrRequest.task.abort === 'function') {
2037
+ this._xhrRequest.task._aborted = true;
2038
+ this._xhrRequest.task.abort();
2039
+ this._xhrRequest.task = null;
2040
+ this._xhrRequest.onchange = () => {};
2041
+ return this;
2389
2042
  }
2043
+ this._xhrRequest.onchange = () => this.cancel();
2044
+ return this;
2045
+ }
2046
+ _setRequestTask(options) {
2047
+ options.requestTask = task => {
2048
+ this._xhrRequest.task = task;
2049
+ this._xhrRequest.onchange();
2050
+ };
2051
+ }
2390
2052
 
2391
- /**
2392
- * Constructs a Parse.Query that is the NOR of the passed in queries. For
2393
- * example:
2394
- * <pre>const compoundQuery = Parse.Query.nor(query1, query2, query3);</pre>
2395
- *
2396
- * will create a compoundQuery that is a nor of the query1, query2, and
2397
- * query3.
2398
- *
2399
- * @param {...Parse.Query} queries The list of queries to NOR.
2400
- * @static
2401
- * @returns {Parse.Query} The query that is the NOR of the passed in queries.
2402
- */
2403
- }, {
2404
- key: "nor",
2405
- value: function () /*: ParseQuery*/{
2406
- for (var _len11 = arguments.length, queries = new Array(_len11), _key15 = 0; _key15 < _len11; _key15++) {
2407
- queries[_key15] = arguments[_key15];
2408
- }
2409
- var className = _getClassNameFromQueries(queries);
2410
- var query = new ParseQuery(className);
2411
- query._norQuery(queries);
2412
- return query;
2413
- }
2414
- }]);
2415
- return ParseQuery;
2416
- }();
2417
- var DefaultController = {
2418
- find: function (className /*: string*/, params /*: QueryJSON*/, options /*: RequestOptions*/) /*: Promise<Array<ParseObject>>*/{
2419
- var RESTController = _CoreManager.default.getRESTController();
2053
+ /**
2054
+ * Sets a comment to the query so that the query
2055
+ * can be identified when using a the profiler for MongoDB.
2056
+ *
2057
+ * @param {string} value a comment can make your profile data easier to interpret and trace.
2058
+ * @returns {Parse.Query} Returns the query, so you can chain this call.
2059
+ */
2060
+ comment(value) {
2061
+ if (value == null) {
2062
+ delete this._comment;
2063
+ return this;
2064
+ }
2065
+ if (typeof value !== 'string') {
2066
+ throw new Error('The value of a comment to be sent with this query must be a string.');
2067
+ }
2068
+ this._comment = value;
2069
+ return this;
2070
+ }
2071
+ }
2072
+ const DefaultController = {
2073
+ find(className, params, options) {
2074
+ const RESTController = _CoreManager.default.getRESTController();
2420
2075
  return RESTController.request('GET', 'classes/' + className, params, options);
2421
2076
  },
2422
- aggregate: function (className /*: string*/, params /*: any*/, options /*: RequestOptions*/) /*: Promise<Array<mixed>>*/{
2423
- var RESTController = _CoreManager.default.getRESTController();
2077
+ aggregate(className, params, options) {
2078
+ const RESTController = _CoreManager.default.getRESTController();
2424
2079
  return RESTController.request('GET', 'aggregate/' + className, params, options);
2425
2080
  }
2426
2081
  };
2427
2082
  _CoreManager.default.setParseQuery(ParseQuery);
2428
2083
  _CoreManager.default.setQueryController(DefaultController);
2429
- var _default = ParseQuery;
2430
- exports.default = _default;
2084
+ var _default = exports.default = ParseQuery;