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