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