parse 5.2.0-alpha.1 → 5.2.0-alpha.3

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