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