parse 6.1.0-alpha.2 → 6.1.0
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/README.md +0 -8
- package/dist/parse.js +27 -47
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +27 -47
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/CoreManager.js +1 -2
- package/lib/browser/CryptoController.js +0 -1
- package/lib/browser/EventEmitter.js +0 -1
- package/lib/browser/EventuallyQueue.js +0 -1
- package/lib/browser/IndexedDBStorageController.js +0 -1
- package/lib/browser/InstallationController.js +0 -1
- package/lib/browser/LocalDatastore.js +0 -1
- package/lib/browser/LocalDatastoreController.default.js +0 -1
- package/lib/browser/LocalDatastoreController.js +0 -1
- package/lib/browser/LocalDatastoreController.react-native.js +0 -1
- package/lib/browser/OfflineQuery.js +0 -1
- package/lib/browser/ParseInstallation.js +0 -1
- package/lib/browser/ParseQuery.js +19 -17
- package/lib/browser/RESTController.js +4 -3
- package/lib/browser/Socket.weapp.js +0 -1
- package/lib/browser/Storage.js +0 -1
- package/lib/browser/StorageController.browser.js +0 -1
- package/lib/browser/StorageController.default.js +0 -1
- package/lib/browser/StorageController.js +0 -1
- package/lib/browser/StorageController.react-native.js +0 -1
- package/lib/browser/StorageController.weapp.js +0 -1
- package/lib/browser/TaskQueue.js +0 -1
- package/lib/browser/WebSocketController.js +0 -1
- package/lib/browser/Xhr.weapp.js +0 -1
- package/lib/browser/uuid.js +0 -1
- package/lib/node/CoreManager.js +1 -2
- package/lib/node/CryptoController.js +0 -1
- package/lib/node/EventEmitter.js +0 -1
- package/lib/node/EventuallyQueue.js +0 -1
- package/lib/node/IndexedDBStorageController.js +0 -1
- package/lib/node/InstallationController.js +0 -1
- package/lib/node/LocalDatastore.js +0 -1
- package/lib/node/LocalDatastoreController.default.js +0 -1
- package/lib/node/LocalDatastoreController.js +0 -1
- package/lib/node/LocalDatastoreController.react-native.js +0 -1
- package/lib/node/OfflineQuery.js +0 -1
- package/lib/node/ParseInstallation.js +0 -1
- package/lib/node/RESTController.js +0 -1
- package/lib/node/Socket.weapp.js +0 -1
- package/lib/node/Storage.js +0 -1
- package/lib/node/StorageController.browser.js +0 -1
- package/lib/node/StorageController.default.js +0 -1
- package/lib/node/StorageController.js +0 -1
- package/lib/node/StorageController.react-native.js +0 -1
- package/lib/node/StorageController.weapp.js +0 -1
- package/lib/node/TaskQueue.js +0 -1
- package/lib/node/WebSocketController.js +0 -1
- package/lib/node/Xhr.weapp.js +0 -1
- package/lib/node/uuid.js +0 -1
- package/lib/react-native/CoreManager.js +1 -2
- package/lib/react-native/CryptoController.js +0 -1
- package/lib/react-native/EventEmitter.js +0 -1
- package/lib/react-native/EventuallyQueue.js +0 -1
- package/lib/react-native/IndexedDBStorageController.js +0 -1
- package/lib/react-native/InstallationController.js +0 -1
- package/lib/react-native/LocalDatastore.js +0 -1
- package/lib/react-native/LocalDatastoreController.default.js +0 -1
- package/lib/react-native/LocalDatastoreController.js +0 -1
- package/lib/react-native/LocalDatastoreController.react-native.js +0 -1
- package/lib/react-native/OfflineQuery.js +0 -1
- package/lib/react-native/ParseInstallation.js +0 -1
- package/lib/react-native/RESTController.js +0 -1
- package/lib/react-native/Socket.weapp.js +0 -1
- package/lib/react-native/Storage.js +0 -1
- package/lib/react-native/StorageController.browser.js +0 -1
- package/lib/react-native/StorageController.default.js +0 -1
- package/lib/react-native/StorageController.js +0 -1
- package/lib/react-native/StorageController.react-native.js +0 -1
- package/lib/react-native/StorageController.weapp.js +0 -1
- package/lib/react-native/TaskQueue.js +0 -1
- package/lib/react-native/WebSocketController.js +0 -1
- package/lib/react-native/Xhr.weapp.js +0 -1
- package/lib/react-native/uuid.js +0 -1
- package/lib/weapp/CoreManager.js +1 -2
- package/lib/weapp/CryptoController.js +0 -1
- package/lib/weapp/EventEmitter.js +0 -1
- package/lib/weapp/EventuallyQueue.js +0 -1
- package/lib/weapp/IndexedDBStorageController.js +0 -1
- package/lib/weapp/InstallationController.js +0 -1
- package/lib/weapp/LocalDatastore.js +0 -1
- package/lib/weapp/LocalDatastoreController.default.js +0 -1
- package/lib/weapp/LocalDatastoreController.js +0 -1
- package/lib/weapp/LocalDatastoreController.react-native.js +0 -1
- package/lib/weapp/OfflineQuery.js +0 -1
- package/lib/weapp/ParseInstallation.js +0 -1
- package/lib/weapp/ParseQuery.js +19 -17
- package/lib/weapp/RESTController.js +4 -3
- package/lib/weapp/Socket.weapp.js +0 -1
- package/lib/weapp/Storage.js +0 -1
- package/lib/weapp/StorageController.browser.js +0 -1
- package/lib/weapp/StorageController.default.js +0 -1
- package/lib/weapp/StorageController.js +0 -1
- package/lib/weapp/StorageController.react-native.js +0 -1
- package/lib/weapp/StorageController.weapp.js +0 -1
- package/lib/weapp/TaskQueue.js +0 -1
- package/lib/weapp/WebSocketController.js +0 -1
- package/lib/weapp/Xhr.weapp.js +0 -1
- package/lib/weapp/uuid.js +0 -1
- package/package.json +11 -9
- package/types/Analytics.d.ts +42 -0
- package/types/AnonymousUtils.d.ts +84 -0
- package/types/Cloud.d.ts +65 -0
- package/types/CloudCode.d.ts +307 -0
- package/types/CoreManager.d.ts +325 -0
- package/types/CryptoController.d.ts +5 -0
- package/types/EventEmitter.d.ts +5 -0
- package/types/EventuallyQueue.d.ts +168 -0
- package/types/FacebookUtils.d.ts +107 -0
- package/types/IndexedDBStorageController.d.ts +2 -0
- package/types/InstallationController.d.ts +10 -0
- package/types/LiveQueryClient.d.ts +128 -0
- package/types/LiveQuerySubscription.d.ts +103 -0
- package/types/LocalDatastore.d.ts +56 -0
- package/types/LocalDatastoreController.d.ts +2 -0
- package/types/LocalDatastoreController.default.d.ts +9 -0
- package/types/LocalDatastoreController.react-native.d.ts +9 -0
- package/types/LocalDatastoreUtils.d.ts +5 -0
- package/types/ObjectStateMutations.d.ts +28 -0
- package/types/OfflineQuery.d.ts +20 -0
- package/types/Parse.d.ts +633 -0
- package/types/ParseACL.d.ts +141 -0
- package/types/ParseCLP.d.ts +293 -0
- package/types/ParseConfig.d.ts +77 -0
- package/types/ParseError.d.ts +476 -0
- package/types/ParseFile.d.ts +192 -0
- package/types/ParseGeoPoint.d.ts +104 -0
- package/types/ParseHooks.d.ts +27 -0
- package/types/ParseInstallation.d.ts +179 -0
- package/types/ParseLiveQuery.d.ts +48 -0
- package/types/ParseObject.d.ts +1072 -0
- package/types/ParseOp.d.ts +78 -0
- package/types/ParsePolygon.d.ts +69 -0
- package/types/ParseQuery.d.ts +961 -0
- package/types/ParseRelation.d.ts +56 -0
- package/types/ParseRole.d.ts +79 -0
- package/types/ParseSchema.d.ts +286 -0
- package/types/ParseSession.d.ts +45 -0
- package/types/ParseUser.d.ts +517 -0
- package/types/Push.d.ts +62 -0
- package/types/RESTController.d.ts +35 -0
- package/types/SingleInstanceStateController.d.ts +24 -0
- package/types/Socket.weapp.d.ts +10 -0
- package/types/Storage.d.ts +14 -0
- package/types/StorageController.browser.d.ts +9 -0
- package/types/StorageController.d.ts +2 -0
- package/types/StorageController.default.d.ts +9 -0
- package/types/StorageController.react-native.d.ts +11 -0
- package/types/StorageController.weapp.d.ts +9 -0
- package/types/TaskQueue.d.ts +11 -0
- package/types/UniqueInstanceStateController.d.ts +20 -0
- package/types/WebSocketController.d.ts +2 -0
- package/types/Xhr.weapp.d.ts +29 -0
- package/types/arrayContainsObject.d.ts +2 -0
- package/types/canBeSerialized.d.ts +2 -0
- package/types/decode.d.ts +1 -0
- package/types/encode.d.ts +1 -0
- package/types/equals.d.ts +1 -0
- package/types/escape.d.ts +1 -0
- package/types/index.d.ts +66 -0
- package/types/isRevocableSession.d.ts +1 -0
- package/types/node.d.ts +3 -0
- package/types/parseDate.d.ts +1 -0
- package/types/promiseUtils.d.ts +9 -0
- package/types/react-native.d.ts +3 -0
- package/types/tests.ts +2256 -0
- package/types/tsconfig.json +25 -0
- package/types/unique.d.ts +1 -0
- package/types/unsavedChildren.d.ts +11 -0
- package/types/uuid.d.ts +2 -0
package/types/tests.ts
ADDED
|
@@ -0,0 +1,2256 @@
|
|
|
1
|
+
import Parse from 'parse';
|
|
2
|
+
import ParseNode from 'parse/node';
|
|
3
|
+
import ParseRN from 'parse/react-native';
|
|
4
|
+
|
|
5
|
+
class GameScore extends Parse.Object {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('GameScore');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class Game extends Parse.Object {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('Game');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function test_config() {
|
|
18
|
+
await Parse.Config.save({ foo: 'bar' }, { foo: true });
|
|
19
|
+
await Parse.Config.get({ useMasterKey: true });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function test_object() {
|
|
23
|
+
const game = new Game();
|
|
24
|
+
game
|
|
25
|
+
.save(null, {
|
|
26
|
+
useMasterKey: true,
|
|
27
|
+
sessionToken: 'sometoken',
|
|
28
|
+
cascadeSave: false,
|
|
29
|
+
})
|
|
30
|
+
.then(result => result)
|
|
31
|
+
.catch(error => error);
|
|
32
|
+
|
|
33
|
+
// $ExpectType boolean
|
|
34
|
+
game.isNew();
|
|
35
|
+
// $ExpectType Pointer
|
|
36
|
+
game.toPointer();
|
|
37
|
+
// $ExpectType string
|
|
38
|
+
game.toPointer().className;
|
|
39
|
+
|
|
40
|
+
await game.fetch({});
|
|
41
|
+
|
|
42
|
+
// Create a new instance of that class.
|
|
43
|
+
const gameScore = new GameScore();
|
|
44
|
+
|
|
45
|
+
gameScore.set('score', 1337);
|
|
46
|
+
gameScore.set('playerName', 'Sean Plott');
|
|
47
|
+
gameScore.set('cheatMode', false);
|
|
48
|
+
|
|
49
|
+
// Setting attrs using object
|
|
50
|
+
gameScore.set({
|
|
51
|
+
level: '10',
|
|
52
|
+
difficult: 15,
|
|
53
|
+
});
|
|
54
|
+
gameScore.get('score');
|
|
55
|
+
gameScore.get('playerName');
|
|
56
|
+
gameScore.get('cheatMode');
|
|
57
|
+
gameScore.increment('score');
|
|
58
|
+
gameScore.addUnique('skills', 'flying');
|
|
59
|
+
gameScore.addUnique('skills', 'kungfu');
|
|
60
|
+
gameScore.addAll('skills', ['kungfu']);
|
|
61
|
+
gameScore.addAllUnique('skills', ['kungfu']);
|
|
62
|
+
gameScore.remove('skills', 'flying');
|
|
63
|
+
gameScore.removeAll('skills', ['kungFu']);
|
|
64
|
+
game.set('gameScore', gameScore);
|
|
65
|
+
// $ExpectType ParseObject<Attributes>
|
|
66
|
+
Game.fromJSON(JSON.parse(JSON.stringify(game)), true);
|
|
67
|
+
|
|
68
|
+
const object = new Parse.Object('TestObject');
|
|
69
|
+
object.equals(gameScore);
|
|
70
|
+
await object.fetchWithInclude(['key1', 'key2']);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function test_errors() {
|
|
74
|
+
const error = new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'sdfds');
|
|
75
|
+
// $ExpectType number
|
|
76
|
+
error.code;
|
|
77
|
+
// $ExpectType string
|
|
78
|
+
error.message;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function test_query() {
|
|
82
|
+
const gameScore = new GameScore();
|
|
83
|
+
|
|
84
|
+
const query = new Parse.Query(GameScore);
|
|
85
|
+
query.equalTo('playerName', 'Dan Stemkoski');
|
|
86
|
+
query.notEqualTo('playerName', 'Michael Yabuti');
|
|
87
|
+
query.fullText('playerName', 'dan', {
|
|
88
|
+
language: 'en',
|
|
89
|
+
caseSensitive: false,
|
|
90
|
+
diacriticSensitive: true,
|
|
91
|
+
});
|
|
92
|
+
query.greaterThan('playerAge', 18);
|
|
93
|
+
await query.eachBatch(objs => {}, { batchSize: 10 });
|
|
94
|
+
await query.each(score => {});
|
|
95
|
+
query.hint('_id_');
|
|
96
|
+
query.explain(true);
|
|
97
|
+
query.limit(10);
|
|
98
|
+
query.skip(10);
|
|
99
|
+
|
|
100
|
+
// Sorts the results in ascending order by the score field
|
|
101
|
+
query.ascending('score');
|
|
102
|
+
|
|
103
|
+
// Sorts the results in descending order by the score field
|
|
104
|
+
query.descending('score');
|
|
105
|
+
|
|
106
|
+
// Restricts to wins < 50
|
|
107
|
+
query.lessThan('wins', 50);
|
|
108
|
+
|
|
109
|
+
// Restricts to wins <= 50
|
|
110
|
+
query.lessThanOrEqualTo('wins', 50);
|
|
111
|
+
|
|
112
|
+
// Restricts to wins > 50
|
|
113
|
+
query.greaterThan('wins', 50);
|
|
114
|
+
|
|
115
|
+
// Restricts to wins >= 50
|
|
116
|
+
query.greaterThanOrEqualTo('wins', 50);
|
|
117
|
+
|
|
118
|
+
query.containedBy('place', ['1', '2']);
|
|
119
|
+
// Finds scores from any of Jonathan, Dario, or Shawn
|
|
120
|
+
query.containedIn('playerName', ['Jonathan Walsh', 'Dario Wunsch', 'Shawn Simon']);
|
|
121
|
+
|
|
122
|
+
// Finds scores from anyone who is neither Jonathan, Dario, nor Shawn
|
|
123
|
+
query.notContainedIn('playerName', ['Jonathan Walsh', 'Dario Wunsch', 'Shawn Simon']);
|
|
124
|
+
|
|
125
|
+
// Finds objects that have the score set
|
|
126
|
+
query.exists('score');
|
|
127
|
+
|
|
128
|
+
// Finds objects that don't have the score set
|
|
129
|
+
query.doesNotExist('score');
|
|
130
|
+
query.matchesKeyInQuery('hometown', 'city', query);
|
|
131
|
+
query.doesNotMatchKeyInQuery('hometown', 'city', query);
|
|
132
|
+
query.select('score', 'playerName');
|
|
133
|
+
|
|
134
|
+
// Find objects where the array in arrayKey contains 2.
|
|
135
|
+
query.equalTo('arrayKey', 2);
|
|
136
|
+
|
|
137
|
+
// Find objects where the array in arrayKey contains all of the elements 2, 3, and 4.
|
|
138
|
+
query.containsAll('arrayKey', [2, 3, 4]);
|
|
139
|
+
query.containsAllStartingWith('arrayKey', ['2', '3', '4']);
|
|
140
|
+
|
|
141
|
+
query.startsWith('name', "Big Daddy's");
|
|
142
|
+
query.equalTo('score', gameScore);
|
|
143
|
+
query.exists('score');
|
|
144
|
+
query.include('score');
|
|
145
|
+
query.include('score', 'team');
|
|
146
|
+
query.include(['score.team']);
|
|
147
|
+
query.include('*');
|
|
148
|
+
query.includeAll();
|
|
149
|
+
query.sortByTextScore();
|
|
150
|
+
// Find objects that match the aggregation pipeline
|
|
151
|
+
await query.aggregate({
|
|
152
|
+
group: {
|
|
153
|
+
objectId: '$name',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
await query.aggregate({
|
|
158
|
+
count: 'total',
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
await query.aggregate({
|
|
162
|
+
lookup: {
|
|
163
|
+
from: 'Collection',
|
|
164
|
+
foreignField: 'id',
|
|
165
|
+
localField: 'id',
|
|
166
|
+
as: 'result',
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
await query.aggregate({
|
|
170
|
+
lookup: {
|
|
171
|
+
from: 'Target',
|
|
172
|
+
let: { foo: 'bar', baz: 123 },
|
|
173
|
+
pipeline: [],
|
|
174
|
+
as: 'result',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
await query.aggregate({
|
|
179
|
+
graphLookup: {
|
|
180
|
+
from: 'Target',
|
|
181
|
+
connectFromField: 'objectId',
|
|
182
|
+
connectToField: 'newId',
|
|
183
|
+
as: 'result',
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
await query.aggregate({
|
|
188
|
+
facet: {
|
|
189
|
+
foo: [
|
|
190
|
+
{
|
|
191
|
+
count: 'total',
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
bar: [
|
|
195
|
+
{
|
|
196
|
+
group: {
|
|
197
|
+
objectId: '$name',
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
await query.aggregate({
|
|
205
|
+
unwind: '$field',
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
await query.aggregate({
|
|
209
|
+
unwind: {
|
|
210
|
+
path: '$field',
|
|
211
|
+
includeArrayIndex: 'newIndex',
|
|
212
|
+
preserveNullAndEmptyArrays: true,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// Find objects with distinct key
|
|
217
|
+
await query.distinct('name');
|
|
218
|
+
|
|
219
|
+
const testQuery = Parse.Query.or(query, query);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function test_query_exclude() {
|
|
223
|
+
const gameScore = new GameScore();
|
|
224
|
+
|
|
225
|
+
const query = new Parse.Query(GameScore);
|
|
226
|
+
|
|
227
|
+
// Show all keys, except the specified key.
|
|
228
|
+
query.exclude('place');
|
|
229
|
+
|
|
230
|
+
const testQuery = Parse.Query.or(query, query);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function test_query_promise() {
|
|
234
|
+
// Test promise with a query
|
|
235
|
+
const findQuery = new Parse.Query('Test');
|
|
236
|
+
findQuery
|
|
237
|
+
.find()
|
|
238
|
+
.then(() => {
|
|
239
|
+
// success
|
|
240
|
+
})
|
|
241
|
+
.catch(() => {
|
|
242
|
+
// error
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const getQuery = new Parse.Query('Test');
|
|
246
|
+
try {
|
|
247
|
+
await getQuery.get('objectId');
|
|
248
|
+
} catch (error) {
|
|
249
|
+
// noop
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
await getQuery.map((score, index) => score.increment('score', index));
|
|
253
|
+
await getQuery.reduce((accum, score, index) => (accum += score.get('score')), 0);
|
|
254
|
+
await getQuery.reduce((accum, score, index) => (accum += score.get('score')), 0, {
|
|
255
|
+
batchSize: 200,
|
|
256
|
+
});
|
|
257
|
+
await getQuery.filter(scores => scores.get('score') > 0);
|
|
258
|
+
await getQuery.filter(scores => scores.get('score') > 0, { batchSize: 10 });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function test_live_query() {
|
|
262
|
+
const subscription = await new Parse.Query('Test').subscribe();
|
|
263
|
+
subscription.on('close', (object: Parse.Object) => {
|
|
264
|
+
// $ExpectType ParseObject<Attributes>
|
|
265
|
+
object;
|
|
266
|
+
});
|
|
267
|
+
subscription.on('create', (object: Parse.Object) => {
|
|
268
|
+
// $ExpectType ParseObject<Attributes>
|
|
269
|
+
object;
|
|
270
|
+
});
|
|
271
|
+
subscription.on('delete', (object: Parse.Object) => {
|
|
272
|
+
// $ExpectType ParseObject<Attributes>
|
|
273
|
+
object;
|
|
274
|
+
});
|
|
275
|
+
subscription.on('enter', (object: Parse.Object) => {
|
|
276
|
+
// $ExpectType ParseObject<Attributes>
|
|
277
|
+
object;
|
|
278
|
+
});
|
|
279
|
+
subscription.on('leave', (object: Parse.Object) => {
|
|
280
|
+
// $ExpectType ParseObject<Attributes>
|
|
281
|
+
object;
|
|
282
|
+
});
|
|
283
|
+
subscription.on('open', (object: Parse.Object) => {
|
|
284
|
+
// $ExpectType ParseObject<Attributes>
|
|
285
|
+
object;
|
|
286
|
+
});
|
|
287
|
+
subscription.on('update', (object: Parse.Object) => {
|
|
288
|
+
// $ExpectType ParseObject<Attributes>
|
|
289
|
+
object;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async function test_anonymous_utils() {
|
|
294
|
+
// $ExpectType boolean
|
|
295
|
+
Parse.AnonymousUtils.isLinked(new Parse.User());
|
|
296
|
+
// $ExpectType ParseUser<Attributes>
|
|
297
|
+
await Parse.AnonymousUtils.link(new Parse.User(), { useMasterKey: true, sessionToken: '' });
|
|
298
|
+
// $ExpectType ParseUser<Attributes>
|
|
299
|
+
await Parse.AnonymousUtils.logIn({ useMasterKey: true, sessionToken: '' });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function return_a_query(): Parse.Query {
|
|
303
|
+
return new Parse.Query(Game);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async function test_each() {
|
|
307
|
+
await new Parse.Query(Game).each(game => {
|
|
308
|
+
// $ExpectType Game
|
|
309
|
+
game;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async function test_file() {
|
|
314
|
+
const base64 = 'V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=';
|
|
315
|
+
let file = new Parse.File('myfile.txt', { base64 });
|
|
316
|
+
|
|
317
|
+
file = new Parse.File('nana', { uri: 'http://example.com/image.jps' });
|
|
318
|
+
|
|
319
|
+
const bytes = [0xbe, 0xef, 0xca, 0xfe];
|
|
320
|
+
file = new Parse.File('myfile.txt', bytes);
|
|
321
|
+
|
|
322
|
+
file = new Parse.File('myfile.zzz', new Blob(), 'image/png');
|
|
323
|
+
|
|
324
|
+
const src = file.url();
|
|
325
|
+
const secure = file.url({ forceSecure: true });
|
|
326
|
+
|
|
327
|
+
await file.save();
|
|
328
|
+
file.cancel();
|
|
329
|
+
await file.destroy();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function test_file_tags_and_metadata() {
|
|
333
|
+
const base64 = 'V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=';
|
|
334
|
+
const file = new Parse.File('myfile.txt', { base64 });
|
|
335
|
+
file.setTags({ ownerId: 42, status: 'okay' });
|
|
336
|
+
file.addTag('labes', 'one');
|
|
337
|
+
file.setMetadata({ contentType: 'plain/text', contentLength: 579 });
|
|
338
|
+
file.addMetadata('author', 'John Doe');
|
|
339
|
+
// $ExpectType Record<string, any>
|
|
340
|
+
file.tags();
|
|
341
|
+
// $ExpectType Record<string, any>
|
|
342
|
+
file.metadata();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function test_analytics() {
|
|
346
|
+
const dimensions = {
|
|
347
|
+
// Define ranges to bucket data points into meaningful segments
|
|
348
|
+
priceRange: '1000-1500',
|
|
349
|
+
// Did the user filter the query?
|
|
350
|
+
source: 'craigslist',
|
|
351
|
+
// Do searches happen more often on weekdays or weekends?
|
|
352
|
+
dayType: 'weekday',
|
|
353
|
+
};
|
|
354
|
+
// Send the dimensions to Parse along with the 'search' event
|
|
355
|
+
await Parse.Analytics.track('search', dimensions);
|
|
356
|
+
|
|
357
|
+
const codeString = '404';
|
|
358
|
+
await Parse.Analytics.track('error', { code: codeString });
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function test_relation() {
|
|
362
|
+
const game1 = new Game();
|
|
363
|
+
const game2 = new Game();
|
|
364
|
+
|
|
365
|
+
new Parse.User()
|
|
366
|
+
.relation<Game>('games')
|
|
367
|
+
.query()
|
|
368
|
+
.find()
|
|
369
|
+
.then((g: Game[]) => {})
|
|
370
|
+
.catch(error => error);
|
|
371
|
+
new Parse.User().relation('games').add(game1);
|
|
372
|
+
new Parse.User().relation('games').add([game1, game2]);
|
|
373
|
+
|
|
374
|
+
new Parse.User().relation('games').remove(game1);
|
|
375
|
+
new Parse.User().relation('games').remove([game1, game2]);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
async function test_user() {
|
|
379
|
+
const user = new Parse.User();
|
|
380
|
+
user.set('username', 'my name');
|
|
381
|
+
user.set('password', 'my pass');
|
|
382
|
+
user.set('email', 'email@example.com');
|
|
383
|
+
await user.signUp(null, { useMasterKey: true });
|
|
384
|
+
|
|
385
|
+
const anotherUser: Parse.User = Parse.User.fromJSON({});
|
|
386
|
+
anotherUser.set('email', 'email@example.com');
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function test_user_currentAsync() {
|
|
390
|
+
const asyncUser = await Parse.User.currentAsync();
|
|
391
|
+
if (asyncUser) {
|
|
392
|
+
asyncUser.set('email', 'email@example.com');
|
|
393
|
+
} else if (asyncUser === null) {
|
|
394
|
+
await Parse.User.logIn('email@example.com', 'my pass');
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async function test_user_acl_roles() {
|
|
399
|
+
const user = new Parse.User();
|
|
400
|
+
user.set('username', 'my name');
|
|
401
|
+
user.set('password', 'my pass');
|
|
402
|
+
user.set('email', 'email@example.com');
|
|
403
|
+
|
|
404
|
+
// other fields can be set just like with Parse.Object
|
|
405
|
+
user.set('phone', '415-392-0202');
|
|
406
|
+
|
|
407
|
+
const currentUser = Parse.User.current();
|
|
408
|
+
if (currentUser) {
|
|
409
|
+
// do stuff with the user
|
|
410
|
+
} else {
|
|
411
|
+
// show the signup or login page
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
Parse.User.become('session-token-here')
|
|
415
|
+
.then(
|
|
416
|
+
user => {
|
|
417
|
+
// The current user is now set to user.
|
|
418
|
+
},
|
|
419
|
+
error => {
|
|
420
|
+
// The token could not be validated.
|
|
421
|
+
}
|
|
422
|
+
)
|
|
423
|
+
.catch(error => error);
|
|
424
|
+
|
|
425
|
+
Parse.User.hydrate({})
|
|
426
|
+
.then(
|
|
427
|
+
user => {
|
|
428
|
+
// The current user is now set to user.
|
|
429
|
+
},
|
|
430
|
+
error => {
|
|
431
|
+
// The token could not be validated.
|
|
432
|
+
}
|
|
433
|
+
)
|
|
434
|
+
.catch(error => error);
|
|
435
|
+
|
|
436
|
+
const game = new Game();
|
|
437
|
+
game.set('gameScore', new GameScore());
|
|
438
|
+
game.setACL(new Parse.ACL(Parse.User.current()));
|
|
439
|
+
game
|
|
440
|
+
.save()
|
|
441
|
+
.then((game: Game) => {})
|
|
442
|
+
.catch(error => error);
|
|
443
|
+
await game.save(null, { useMasterKey: true });
|
|
444
|
+
game
|
|
445
|
+
.save({ score: '10' }, { useMasterKey: true })
|
|
446
|
+
.then(
|
|
447
|
+
game => {
|
|
448
|
+
// Update game then revert it to the last saved state.
|
|
449
|
+
game.set('score', '20');
|
|
450
|
+
game.revert('score');
|
|
451
|
+
game.revert('score', 'ACL');
|
|
452
|
+
game.revert();
|
|
453
|
+
},
|
|
454
|
+
error => {
|
|
455
|
+
// The save failed
|
|
456
|
+
}
|
|
457
|
+
)
|
|
458
|
+
.catch(error => error);
|
|
459
|
+
|
|
460
|
+
const groupACL = new Parse.ACL();
|
|
461
|
+
|
|
462
|
+
const userList: Parse.User[] = [Parse.User.current()!];
|
|
463
|
+
// userList is an array with the users we are sending this message to.
|
|
464
|
+
for (const userListItem of userList) {
|
|
465
|
+
groupACL.setReadAccess(userListItem, true);
|
|
466
|
+
groupACL.setWriteAccess(userListItem, true);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
groupACL.setPublicReadAccess(true);
|
|
470
|
+
|
|
471
|
+
game.setACL(groupACL);
|
|
472
|
+
|
|
473
|
+
Parse.User.requestPasswordReset('email@example.com')
|
|
474
|
+
.then(
|
|
475
|
+
data => {
|
|
476
|
+
// The current user is now set to user.
|
|
477
|
+
},
|
|
478
|
+
error => {
|
|
479
|
+
// The token could not be validated.
|
|
480
|
+
}
|
|
481
|
+
)
|
|
482
|
+
.catch(error => error);
|
|
483
|
+
|
|
484
|
+
Parse.User.requestEmailVerification('email@example.com')
|
|
485
|
+
.then(
|
|
486
|
+
data => {
|
|
487
|
+
// The current user is now set to user.
|
|
488
|
+
},
|
|
489
|
+
error => {
|
|
490
|
+
// The token could not be validated.
|
|
491
|
+
}
|
|
492
|
+
)
|
|
493
|
+
.catch(error => error);
|
|
494
|
+
|
|
495
|
+
// By specifying no write privileges for the ACL, we can ensure the role cannot be altered.
|
|
496
|
+
const role = new Parse.Role('Administrator', groupACL);
|
|
497
|
+
role.getUsers().add(userList[0]);
|
|
498
|
+
role.getRoles().add(role);
|
|
499
|
+
await role.save();
|
|
500
|
+
|
|
501
|
+
await Parse.User.logOut()
|
|
502
|
+
.then(data => {
|
|
503
|
+
// logged out
|
|
504
|
+
})
|
|
505
|
+
.catch(error => error);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
async function test_facebook_util() {
|
|
509
|
+
Parse.FacebookUtils.init({
|
|
510
|
+
appId: 'YOUR_APP_ID', // Facebook App ID
|
|
511
|
+
channelUrl: '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
|
|
512
|
+
cookie: true, // enable cookies to allow Parse to access the session
|
|
513
|
+
xfbml: true, // parse XFBML
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
await Parse.FacebookUtils.logIn(null, {
|
|
517
|
+
success: (user: Parse.User) => {
|
|
518
|
+
if (!user.existed()) {
|
|
519
|
+
alert('User signed up and logged in through Facebook!');
|
|
520
|
+
} else {
|
|
521
|
+
alert('User logged in through Facebook!');
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
error: (user: Parse.User, error: any) => {
|
|
525
|
+
alert('User cancelled the Facebook login or did not fully authorize.');
|
|
526
|
+
},
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
const user = Parse.User.current()!;
|
|
530
|
+
|
|
531
|
+
if (!Parse.FacebookUtils.isLinked(user)) {
|
|
532
|
+
await Parse.FacebookUtils.link(user, null, {
|
|
533
|
+
success: (user: any) => {
|
|
534
|
+
alert('Woohoo, user logged in with Facebook!');
|
|
535
|
+
},
|
|
536
|
+
error: (user: any, error: any) => {
|
|
537
|
+
alert('User cancelled the Facebook login or did not fully authorize.');
|
|
538
|
+
},
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
await Parse.FacebookUtils.unlink(user, {
|
|
543
|
+
success: (user: Parse.User) => {
|
|
544
|
+
alert('The user is no longer associated with their Facebook account.');
|
|
545
|
+
},
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
async function test_cloud_functions() {
|
|
550
|
+
// $ExpectType any
|
|
551
|
+
await Parse.Cloud.run('SomeFunction');
|
|
552
|
+
// $ExpectType any
|
|
553
|
+
await Parse.Cloud.run('SomeFunction', { something: 'whatever' });
|
|
554
|
+
// $ExpectType any
|
|
555
|
+
await Parse.Cloud.run('SomeFunction', null, { useMasterKey: true });
|
|
556
|
+
// ExpectType boolean
|
|
557
|
+
await Parse.Cloud.run<() => boolean>('SomeFunction');
|
|
558
|
+
// $ExpectType boolean
|
|
559
|
+
await Parse.Cloud.run<() => boolean>('SomeFunction', null);
|
|
560
|
+
// $ExpectType boolean
|
|
561
|
+
await Parse.Cloud.run<() => boolean>('SomeFunction', null, { useMasterKey: true });
|
|
562
|
+
// $ExpectType number
|
|
563
|
+
await Parse.Cloud.run<(params: { paramA: string }) => number>('SomeFunction', {
|
|
564
|
+
paramA: 'hello',
|
|
565
|
+
});
|
|
566
|
+
// $ExpectError
|
|
567
|
+
await Parse.Cloud.run<(params: { paramA: string }) => number>('SomeFunction');
|
|
568
|
+
await Parse.Cloud.run<(params: { paramA: string }) => number>('SomeFunction', {
|
|
569
|
+
// $ExpectError
|
|
570
|
+
paramZ: 'hello',
|
|
571
|
+
});
|
|
572
|
+
// $ExpectError
|
|
573
|
+
await Parse.Cloud.run<(params: { paramA: string }) => number>('SomeFunction', null, {
|
|
574
|
+
useMasterKey: true,
|
|
575
|
+
});
|
|
576
|
+
// $ExpectError
|
|
577
|
+
await Parse.Cloud.run<(params: string) => any>('SomeFunction', 'hello');
|
|
578
|
+
// Parse.Cloud.afterDelete('MyCustomClass', (request: Parse.Cloud.AfterDeleteRequest) => {
|
|
579
|
+
// // result
|
|
580
|
+
// });
|
|
581
|
+
// Parse.Cloud.afterSave('MyCustomClass', (request: Parse.Cloud.AfterSaveRequest) => {
|
|
582
|
+
// if (!request.context) {
|
|
583
|
+
// throw new Error('Request context should be defined');
|
|
584
|
+
// }
|
|
585
|
+
// // result
|
|
586
|
+
// });
|
|
587
|
+
// Parse.Cloud.beforeDelete('MyCustomClass', (request: Parse.Cloud.BeforeDeleteRequest) => {
|
|
588
|
+
// // result
|
|
589
|
+
// });
|
|
590
|
+
// Parse.Cloud.beforeDelete('MyCustomClass', async (request: Parse.Cloud.BeforeDeleteRequest) => {
|
|
591
|
+
// // result
|
|
592
|
+
// });
|
|
593
|
+
// interface BeforeSaveObject {
|
|
594
|
+
// immutable: boolean;
|
|
595
|
+
// }
|
|
596
|
+
// Parse.Cloud.beforeSave('MyCustomClass', request => {
|
|
597
|
+
// if (request.object.isNew()) {
|
|
598
|
+
// if (!request.object.has('immutable')) throw new Error('Field immutable is required');
|
|
599
|
+
// } else {
|
|
600
|
+
// const original = request.original;
|
|
601
|
+
// if (original == null) {
|
|
602
|
+
// // When the object is not new, request.original must be defined
|
|
603
|
+
// throw new Error('Original must me defined for an existing object');
|
|
604
|
+
// }
|
|
605
|
+
// if (original.get('immutable') !== request.object.get('immutable')) {
|
|
606
|
+
// throw new Error('This field cannot be changed');
|
|
607
|
+
// }
|
|
608
|
+
// }
|
|
609
|
+
// if (!request.context) {
|
|
610
|
+
// throw new Error('Request context should be defined');
|
|
611
|
+
// }
|
|
612
|
+
// });
|
|
613
|
+
// Parse.Cloud.beforeFind('MyCustomClass', (request: Parse.Cloud.BeforeFindRequest) => {
|
|
614
|
+
// const query = request.query; // the Parse.Query
|
|
615
|
+
// const user = request.user; // the user
|
|
616
|
+
// const isMaster = request.master; // if the query is run with masterKey
|
|
617
|
+
// const isCount = request.count; // if the query is a count operation (available on parse-server 2.4.0 or up)
|
|
618
|
+
// const isGet = request.isGet; // if the query is a get operation
|
|
619
|
+
// // All possible read preferences
|
|
620
|
+
// request.readPreference = Parse.Cloud.ReadPreferenceOption.Primary;
|
|
621
|
+
// request.readPreference = Parse.Cloud.ReadPreferenceOption.PrimaryPreferred;
|
|
622
|
+
// request.readPreference = Parse.Cloud.ReadPreferenceOption.Secondary;
|
|
623
|
+
// request.readPreference = Parse.Cloud.ReadPreferenceOption.SecondaryPreferred;
|
|
624
|
+
// request.readPreference = Parse.Cloud.ReadPreferenceOption.Nearest;
|
|
625
|
+
// });
|
|
626
|
+
// Parse.Cloud.beforeFind('MyCustomClass', (request: Parse.Cloud.BeforeFindRequest) => {
|
|
627
|
+
// const query = request.query; // the Parse.Query
|
|
628
|
+
// return new Parse.Query('QueryMe!');
|
|
629
|
+
// });
|
|
630
|
+
// Parse.Cloud.beforeFind('MyCustomClass', (request: Parse.Cloud.BeforeFindRequest) => {
|
|
631
|
+
// const query = request.query; // the Parse.Query
|
|
632
|
+
// return new Parse.Query('QueryMe, IN THE FUTURE!');
|
|
633
|
+
// });
|
|
634
|
+
// Parse.Cloud.afterFind('MyCustomClass', (request: Parse.Cloud.AfterFindRequest) => {
|
|
635
|
+
// return new Parse.Object('MyCustomClass');
|
|
636
|
+
// });
|
|
637
|
+
// Parse.Cloud.beforeLogin((request: Parse.Cloud.TriggerRequest) => {
|
|
638
|
+
// return Promise.resolve();
|
|
639
|
+
// });
|
|
640
|
+
// Parse.Cloud.afterLogin((request: Parse.Cloud.TriggerRequest) => {
|
|
641
|
+
// return Promise.resolve();
|
|
642
|
+
// });
|
|
643
|
+
// Parse.Cloud.afterLogout((request: Parse.Cloud.TriggerRequest) => {
|
|
644
|
+
// return Promise.resolve();
|
|
645
|
+
// });
|
|
646
|
+
// Parse.Cloud.beforeSaveFile((request: Parse.Cloud.FileTriggerRequest) => {
|
|
647
|
+
// return Promise.resolve(new Parse.File('myFile.txt', { base64: '' }));
|
|
648
|
+
// });
|
|
649
|
+
// Parse.Cloud.beforeSaveFile((request: Parse.Cloud.FileTriggerRequest) => {});
|
|
650
|
+
// Parse.Cloud.beforeDeleteFile((request: Parse.Cloud.FileTriggerRequest) => {});
|
|
651
|
+
// Parse.Cloud.afterDeleteFile((request: Parse.Cloud.FileTriggerRequest) => {});
|
|
652
|
+
// Parse.Cloud.define('AFunc', (request: Parse.Cloud.FunctionRequest) => {
|
|
653
|
+
// return 'Some result';
|
|
654
|
+
// });
|
|
655
|
+
// Parse.Cloud.define(
|
|
656
|
+
// 'AFunc',
|
|
657
|
+
// (request: Parse.Cloud.FunctionRequest) => {
|
|
658
|
+
// return 'Some result';
|
|
659
|
+
// },
|
|
660
|
+
// {
|
|
661
|
+
// requireUser: true,
|
|
662
|
+
// requireMaster: true,
|
|
663
|
+
// validateMasterKey: true,
|
|
664
|
+
// skipWithMasterKey: true,
|
|
665
|
+
// requireAnyUserRoles: ['a'],
|
|
666
|
+
// requireAllUserRoles: ['a'],
|
|
667
|
+
// fields: {
|
|
668
|
+
// name: {
|
|
669
|
+
// type: String,
|
|
670
|
+
// constant: true,
|
|
671
|
+
// default: true,
|
|
672
|
+
// options: [],
|
|
673
|
+
// error: 'invalid field.',
|
|
674
|
+
// },
|
|
675
|
+
// },
|
|
676
|
+
// requireUserKeys: {
|
|
677
|
+
// name: {
|
|
678
|
+
// type: String,
|
|
679
|
+
// constant: true,
|
|
680
|
+
// default: true,
|
|
681
|
+
// options: [],
|
|
682
|
+
// error: 'invalid field.',
|
|
683
|
+
// },
|
|
684
|
+
// },
|
|
685
|
+
// }
|
|
686
|
+
// );
|
|
687
|
+
// Parse.Cloud.define('AFunc', request => {
|
|
688
|
+
// // $ExpectType Params
|
|
689
|
+
// request.params;
|
|
690
|
+
// // $ExpectType any
|
|
691
|
+
// request.params.anything;
|
|
692
|
+
// });
|
|
693
|
+
// Parse.Cloud.define<() => void>('AFunc', request => {
|
|
694
|
+
// // $ExpectType {}
|
|
695
|
+
// request.params;
|
|
696
|
+
// });
|
|
697
|
+
// Parse.Cloud.define<(params: { something: string }) => number>('AFunc', request => {
|
|
698
|
+
// // $ExpectType { something: string; }
|
|
699
|
+
// request.params;
|
|
700
|
+
// // $ExpectError
|
|
701
|
+
// request.params.somethingElse;
|
|
702
|
+
// return 123;
|
|
703
|
+
// });
|
|
704
|
+
// // $ExpectError
|
|
705
|
+
// Parse.Cloud.define('AFunc');
|
|
706
|
+
// // $ExpectError
|
|
707
|
+
// Parse.Cloud.define<() => string>('AFunc', () => 123);
|
|
708
|
+
// // $ExpectError
|
|
709
|
+
// Parse.Cloud.define<(params: string) => number>('AFunc', () => 123);
|
|
710
|
+
// Parse.Cloud.job('AJob', (request: Parse.Cloud.JobRequest) => {
|
|
711
|
+
// request.message('Message to associate with this job run');
|
|
712
|
+
// });
|
|
713
|
+
await Parse.Cloud.startJob('AJob', {}).then(v => v);
|
|
714
|
+
await Parse.Cloud.getJobStatus('AJob').then(v => v);
|
|
715
|
+
await Parse.Cloud.getJobsData().then(v => v);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
class PlaceObject extends Parse.Object {}
|
|
719
|
+
|
|
720
|
+
function test_geo_points() {
|
|
721
|
+
let point = new Parse.GeoPoint();
|
|
722
|
+
// $ExpectError
|
|
723
|
+
point = new Parse.GeoPoint('40.0');
|
|
724
|
+
// $ExpectType ParseGeoPoint
|
|
725
|
+
point = new Parse.GeoPoint(40.0);
|
|
726
|
+
// $ExpectError
|
|
727
|
+
point = new Parse.GeoPoint([40.0, -30.0, 20.0]);
|
|
728
|
+
point = new Parse.GeoPoint([40.0, -30.0]);
|
|
729
|
+
point = new Parse.GeoPoint(40.0, -30.0);
|
|
730
|
+
point = new Parse.GeoPoint({ latitude: 40.0, longitude: -30.0 });
|
|
731
|
+
|
|
732
|
+
const userObject = Parse.User.current<Parse.User<{ location: Parse.GeoPoint }>>()!;
|
|
733
|
+
|
|
734
|
+
// User's location
|
|
735
|
+
const userGeoPoint = userObject.get('location');
|
|
736
|
+
|
|
737
|
+
// Create a query for places
|
|
738
|
+
const query = new Parse.Query(Parse.User);
|
|
739
|
+
// Interested in locations near user.
|
|
740
|
+
query.near('location', userGeoPoint);
|
|
741
|
+
// Limit what could be a lot of points.
|
|
742
|
+
query.limit(10);
|
|
743
|
+
|
|
744
|
+
const southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398);
|
|
745
|
+
const northeastOfSF = new Parse.GeoPoint(37.822802, -122.373962);
|
|
746
|
+
|
|
747
|
+
const query2 = new Parse.Query(PlaceObject);
|
|
748
|
+
query2.withinGeoBox('location', southwestOfSF, northeastOfSF);
|
|
749
|
+
|
|
750
|
+
const query3 = new Parse.Query('PlaceObject')
|
|
751
|
+
.find()
|
|
752
|
+
.then((o: Parse.Object[]) => {})
|
|
753
|
+
.catch(error => error);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
async function test_push() {
|
|
757
|
+
await Parse.Push.send(
|
|
758
|
+
{
|
|
759
|
+
channels: ['Gia nts', 'Mets'],
|
|
760
|
+
data: {
|
|
761
|
+
alert: 'The Giants won against the Mets 2-3.',
|
|
762
|
+
},
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
success: () => {
|
|
766
|
+
// Push was successful
|
|
767
|
+
},
|
|
768
|
+
error: (error: any) => {
|
|
769
|
+
// Handle error
|
|
770
|
+
},
|
|
771
|
+
}
|
|
772
|
+
);
|
|
773
|
+
|
|
774
|
+
const query = new Parse.Query(Parse.Installation);
|
|
775
|
+
query.equalTo('injuryReports', true);
|
|
776
|
+
|
|
777
|
+
await Parse.Push.send(
|
|
778
|
+
{
|
|
779
|
+
where: query, // Set our Installation query
|
|
780
|
+
data: {
|
|
781
|
+
alert: 'Willie Hayes injured by own pop fly.',
|
|
782
|
+
},
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
success() {
|
|
786
|
+
// Push was successful
|
|
787
|
+
},
|
|
788
|
+
error(error: any) {
|
|
789
|
+
// Handle error
|
|
790
|
+
},
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
async function test_batch_operations() {
|
|
796
|
+
const game1 = new Game();
|
|
797
|
+
const game2 = new Game();
|
|
798
|
+
const games = [game1, game2];
|
|
799
|
+
|
|
800
|
+
// Master key
|
|
801
|
+
await Parse.Object.saveAll(games, { useMasterKey: true });
|
|
802
|
+
await Parse.Object.destroyAll(games, { useMasterKey: true });
|
|
803
|
+
await Parse.Object.fetchAll(games, { useMasterKey: true });
|
|
804
|
+
await Parse.Object.fetchAllIfNeeded(games, { useMasterKey: true });
|
|
805
|
+
|
|
806
|
+
// Session token
|
|
807
|
+
await Parse.Object.saveAll(games, { sessionToken: '' });
|
|
808
|
+
await Parse.Object.destroyAll(games, { sessionToken: '' });
|
|
809
|
+
await Parse.Object.fetchAll(games, { sessionToken: '' });
|
|
810
|
+
await Parse.Object.fetchAllIfNeeded(games, { sessionToken: '' });
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
async function test_query_subscribe() {
|
|
814
|
+
// create new query from Game object type
|
|
815
|
+
const query = new Parse.Query(Game);
|
|
816
|
+
|
|
817
|
+
// create subscription to Game object
|
|
818
|
+
// Without a token
|
|
819
|
+
// $ExpectType LiveQuerySubscription
|
|
820
|
+
let subscription = await query.subscribe();
|
|
821
|
+
|
|
822
|
+
// With a session token
|
|
823
|
+
// $ExpectType LiveQuerySubscription
|
|
824
|
+
subscription = await query.subscribe(new Parse.User().getSessionToken());
|
|
825
|
+
|
|
826
|
+
// listen for new Game objects created on Parse server
|
|
827
|
+
subscription.on('create', (game: any) => {
|
|
828
|
+
console.log(game);
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
// unsubscribe
|
|
832
|
+
await subscription.unsubscribe();
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function test_serverURL() {
|
|
836
|
+
Parse.serverURL = 'http://localhost:1337/parse';
|
|
837
|
+
}
|
|
838
|
+
function test_polygon() {
|
|
839
|
+
const point = new Parse.GeoPoint(1, 2);
|
|
840
|
+
const polygon1 = new Parse.Polygon([
|
|
841
|
+
[0, 0],
|
|
842
|
+
[1, 0],
|
|
843
|
+
[1, 1],
|
|
844
|
+
[0, 1],
|
|
845
|
+
]);
|
|
846
|
+
const polygon2 = new Parse.Polygon([point, point, point]);
|
|
847
|
+
polygon1.equals(polygon2);
|
|
848
|
+
polygon1.containsPoint(point);
|
|
849
|
+
|
|
850
|
+
const query = new Parse.Query('TestObject');
|
|
851
|
+
query.polygonContains('key', point);
|
|
852
|
+
query.withinPolygon('key', [
|
|
853
|
+
[0, 0],
|
|
854
|
+
[1, 0],
|
|
855
|
+
[1, 1],
|
|
856
|
+
[0, 1],
|
|
857
|
+
]);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
async function test_local_datastore() {
|
|
861
|
+
Parse.enableLocalDatastore();
|
|
862
|
+
const name = 'test_pin';
|
|
863
|
+
const obj = new Parse.Object('TestObject');
|
|
864
|
+
await obj.pin();
|
|
865
|
+
await obj.unPin();
|
|
866
|
+
await obj.isPinned();
|
|
867
|
+
await obj.pinWithName(name);
|
|
868
|
+
await obj.unPinWithName(name);
|
|
869
|
+
await obj.fetchFromLocalDatastore();
|
|
870
|
+
|
|
871
|
+
await Parse.Object.pinAll([obj]);
|
|
872
|
+
await Parse.Object.unPinAll([obj]);
|
|
873
|
+
await Parse.Object.pinAllWithName(name, [obj]);
|
|
874
|
+
await Parse.Object.unPinAllWithName(name, [obj]);
|
|
875
|
+
await Parse.Object.unPinAllObjects();
|
|
876
|
+
await Parse.Object.unPinAllObjectsWithName(name);
|
|
877
|
+
// $ExpectType boolean
|
|
878
|
+
Parse.isLocalDatastoreEnabled();
|
|
879
|
+
// $ExpectType any
|
|
880
|
+
await Parse.dumpLocalDatastore();
|
|
881
|
+
|
|
882
|
+
const query = new Parse.Query('TestObject');
|
|
883
|
+
query.fromPin();
|
|
884
|
+
query.fromPinWithName(name);
|
|
885
|
+
query.fromLocalDatastore();
|
|
886
|
+
|
|
887
|
+
Parse.setLocalDatastoreController({});
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
async function test_from_network() {
|
|
891
|
+
const obj = new Parse.Object('TestObject');
|
|
892
|
+
await obj.save();
|
|
893
|
+
|
|
894
|
+
const query = new Parse.Query('TestObject');
|
|
895
|
+
query.fromNetwork();
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
async function test_cancel_query() {
|
|
899
|
+
const obj = new Parse.Object('TestObject');
|
|
900
|
+
await obj.save();
|
|
901
|
+
|
|
902
|
+
const query = new Parse.Query('TestObject');
|
|
903
|
+
await query.fromNetwork().find();
|
|
904
|
+
query.cancel();
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
type FieldType =
|
|
908
|
+
| string
|
|
909
|
+
| number
|
|
910
|
+
| boolean
|
|
911
|
+
| Date
|
|
912
|
+
| Parse.File
|
|
913
|
+
| Parse.GeoPoint
|
|
914
|
+
| any[]
|
|
915
|
+
| object
|
|
916
|
+
| Parse.Pointer
|
|
917
|
+
| Parse.Polygon
|
|
918
|
+
| Parse.Relation;
|
|
919
|
+
async function test_schema(
|
|
920
|
+
anyField: FieldType,
|
|
921
|
+
notString: Exclude<FieldType, string>,
|
|
922
|
+
notNumber: Exclude<FieldType, number>,
|
|
923
|
+
notboolean: Exclude<FieldType, boolean>,
|
|
924
|
+
notDate: Exclude<FieldType, Date>,
|
|
925
|
+
notFile: Exclude<FieldType, Parse.File>,
|
|
926
|
+
notGeopoint: Exclude<FieldType, Parse.GeoPoint[]>,
|
|
927
|
+
notArray: Exclude<FieldType, any[]>,
|
|
928
|
+
notObject: Exclude<FieldType, object>,
|
|
929
|
+
notPointer: Exclude<FieldType, Parse.Pointer>,
|
|
930
|
+
notPolygon: Exclude<FieldType, Parse.Polygon>
|
|
931
|
+
) {
|
|
932
|
+
// $ExpectType RestSchema[]
|
|
933
|
+
await Parse.Schema.all();
|
|
934
|
+
|
|
935
|
+
const schema = new Parse.Schema('TestSchema');
|
|
936
|
+
|
|
937
|
+
schema.addArray('arrayField');
|
|
938
|
+
schema.addArray('arrayField', { defaultValue: [1, 2, 3, 4] });
|
|
939
|
+
// $ExpectError
|
|
940
|
+
schema.addArray('arrayField', { defaultValue: notArray });
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* @todo Enable type check for default value
|
|
944
|
+
*/
|
|
945
|
+
schema.addField('defaultFieldString');
|
|
946
|
+
schema.addField('defaultFieldString', 'String', { defaultValue: anyField });
|
|
947
|
+
schema.addField('defaultFieldString', 'Number');
|
|
948
|
+
schema.addField('defaultFieldString', 'Relation');
|
|
949
|
+
// $ExpectError
|
|
950
|
+
schema.addField('defaultFieldString', 'String', 'Invalid Options');
|
|
951
|
+
|
|
952
|
+
schema.addString('field');
|
|
953
|
+
schema.addString('field', { defaultValue: 'some string', required: true });
|
|
954
|
+
// $ExpectError
|
|
955
|
+
schema.addString('field', { defaultValue: notString });
|
|
956
|
+
|
|
957
|
+
schema.addNumber('field');
|
|
958
|
+
schema.addNumber('field', { defaultValue: 0, required: true });
|
|
959
|
+
// $ExpectError
|
|
960
|
+
schema.addNumber('field', { defaultValue: notNumber });
|
|
961
|
+
|
|
962
|
+
schema.addBoolean('field');
|
|
963
|
+
schema.addBoolean('field', { defaultValue: true, required: true });
|
|
964
|
+
// $ExpectError
|
|
965
|
+
schema.addBoolean('field', { defaultValue: notboolean });
|
|
966
|
+
|
|
967
|
+
schema.addDate('field');
|
|
968
|
+
schema.addDate('field', { defaultValue: new Date(), required: true });
|
|
969
|
+
// $ExpectError
|
|
970
|
+
schema.addDate('field', { defaultValue: notDate });
|
|
971
|
+
|
|
972
|
+
schema.addFile('field');
|
|
973
|
+
schema.addFile('field', { defaultValue: new Parse.File('myfile', []), required: true });
|
|
974
|
+
// $ExpectError
|
|
975
|
+
schema.addFile('field', { defaultValue: notFile });
|
|
976
|
+
|
|
977
|
+
schema.addGeoPoint('field');
|
|
978
|
+
schema.addGeoPoint('field', { defaultValue: new Parse.GeoPoint(), required: true });
|
|
979
|
+
// $ExpectError
|
|
980
|
+
schema.addGeoPoint('field', { defaultValue: notGeopoint });
|
|
981
|
+
|
|
982
|
+
schema.addPolygon('field');
|
|
983
|
+
schema.addPolygon('field', { defaultValue: new Parse.Polygon([]), required: true });
|
|
984
|
+
// $ExpectError
|
|
985
|
+
schema.addPolygon('field', { defaultValue: notPolygon });
|
|
986
|
+
|
|
987
|
+
schema.addObject('field');
|
|
988
|
+
schema.addObject('field', { defaultValue: {}, required: true });
|
|
989
|
+
schema.addObject('field', { defaultValue: { abc: 'def' } });
|
|
990
|
+
// $ExpectError
|
|
991
|
+
schema.addObject('field', { defaultValue: notObject });
|
|
992
|
+
|
|
993
|
+
schema.addPointer('field', 'SomeClass');
|
|
994
|
+
// $ExpectError
|
|
995
|
+
schema.addPointer('field');
|
|
996
|
+
/**
|
|
997
|
+
* @todo Infer defaultValue type from targetClass
|
|
998
|
+
*/
|
|
999
|
+
schema.addPointer('field', '_User', {
|
|
1000
|
+
defaultValue: new Parse.User().toPointer(),
|
|
1001
|
+
required: true,
|
|
1002
|
+
});
|
|
1003
|
+
// $ExpectError
|
|
1004
|
+
schema.addPointer('field', { defaultValue: notPointer });
|
|
1005
|
+
|
|
1006
|
+
schema.addRelation('field', 'SomeClass');
|
|
1007
|
+
// $ExpectError
|
|
1008
|
+
schema.addRelation('field');
|
|
1009
|
+
// $ExpectError
|
|
1010
|
+
schema.addRelation('field', 'SomeClass', 'anything');
|
|
1011
|
+
|
|
1012
|
+
schema.addIndex('testIndex', { stringField: 'text' });
|
|
1013
|
+
schema.addIndex('testIndex', { stringField: 1 });
|
|
1014
|
+
schema.addIndex('testIndex', { stringField: -1 });
|
|
1015
|
+
// $ExpectError
|
|
1016
|
+
schema.addIndex('testIndex', { stringField: true });
|
|
1017
|
+
|
|
1018
|
+
schema.deleteField('defaultFieldString');
|
|
1019
|
+
schema.deleteIndex('testIndex');
|
|
1020
|
+
await schema.delete();
|
|
1021
|
+
// $ExpectType RestSchema
|
|
1022
|
+
await schema.get();
|
|
1023
|
+
await schema.purge();
|
|
1024
|
+
await schema.save();
|
|
1025
|
+
await schema.update();
|
|
1026
|
+
|
|
1027
|
+
function testGenericType() {
|
|
1028
|
+
interface iTestAttributes {
|
|
1029
|
+
arrField: any[];
|
|
1030
|
+
boolField: boolean;
|
|
1031
|
+
stringField: string;
|
|
1032
|
+
numField: number;
|
|
1033
|
+
dateField: Date;
|
|
1034
|
+
fileField: Parse.File;
|
|
1035
|
+
geoPointField: Parse.GeoPoint;
|
|
1036
|
+
polygonField: Parse.Polygon;
|
|
1037
|
+
objectField: object;
|
|
1038
|
+
relationField: Parse.Relation;
|
|
1039
|
+
pointerField: Parse.Pointer | Parse.Object;
|
|
1040
|
+
}
|
|
1041
|
+
class TestObject extends Parse.Object<iTestAttributes> {}
|
|
1042
|
+
|
|
1043
|
+
const schema = new Parse.Schema<TestObject>('TestObject');
|
|
1044
|
+
schema.addArray('arrField');
|
|
1045
|
+
schema.addBoolean('boolField');
|
|
1046
|
+
schema.addDate('dateField');
|
|
1047
|
+
schema.addFile('fileField');
|
|
1048
|
+
schema.addGeoPoint('geoPointField');
|
|
1049
|
+
schema.addNumber('numField');
|
|
1050
|
+
schema.addObject('objectField');
|
|
1051
|
+
schema.addPointer('pointerField', 'FooClass');
|
|
1052
|
+
schema.addPolygon('polygonField');
|
|
1053
|
+
schema.addRelation('relationField', 'FooClass');
|
|
1054
|
+
schema.addString('stringField');
|
|
1055
|
+
|
|
1056
|
+
// $ExpectError
|
|
1057
|
+
schema.addArray('wrong');
|
|
1058
|
+
// $ExpectError
|
|
1059
|
+
schema.addBoolean('wrong');
|
|
1060
|
+
// $ExpectError
|
|
1061
|
+
schema.addDate('wrong');
|
|
1062
|
+
// $ExpectError
|
|
1063
|
+
schema.addFile('wrong');
|
|
1064
|
+
// $ExpectError
|
|
1065
|
+
schema.addGeoPoint('wrong');
|
|
1066
|
+
// $ExpectError
|
|
1067
|
+
schema.addNumber('wrong');
|
|
1068
|
+
// $ExpectError
|
|
1069
|
+
schema.addObject('wrong');
|
|
1070
|
+
// $ExpectError
|
|
1071
|
+
schema.addPointer('wrong', 'FooClass');
|
|
1072
|
+
// $ExpectError
|
|
1073
|
+
schema.addPolygon('wrong');
|
|
1074
|
+
// $ExpectError
|
|
1075
|
+
schema.addRelation('wrong', 'FooClass');
|
|
1076
|
+
// $ExpectError
|
|
1077
|
+
schema.addString('wrong');
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function testObject() {
|
|
1082
|
+
function testConstructor() {
|
|
1083
|
+
// $ExpectType ParseObject<Attributes>
|
|
1084
|
+
new Parse.Object();
|
|
1085
|
+
|
|
1086
|
+
// $ExpectType ParseObject<Attributes>
|
|
1087
|
+
new Parse.Object('TestObject');
|
|
1088
|
+
|
|
1089
|
+
// $ExpectType ParseObject<{ example: number; }>
|
|
1090
|
+
new Parse.Object('TestObject', { example: 100 });
|
|
1091
|
+
|
|
1092
|
+
// $ExpectType ParseObject<{ example: boolean; }>
|
|
1093
|
+
new Parse.Object<{ example: boolean }>('TestObject', { example: true });
|
|
1094
|
+
|
|
1095
|
+
// $ExpectType ParseObject<{ example: string; }>
|
|
1096
|
+
new Parse.Object('TestObject', { example: 'hello' }, { ignoreValidation: true });
|
|
1097
|
+
|
|
1098
|
+
// $ExpectType ParseObject<{ example: string; }>
|
|
1099
|
+
new Parse.Object<{ example: string }>('TestObject');
|
|
1100
|
+
|
|
1101
|
+
// $ExpectType ParseObject<{ example: number; }>
|
|
1102
|
+
new Parse.Object<{ example: number }>('TestObject', { example: 100 });
|
|
1103
|
+
|
|
1104
|
+
// $ExpectError
|
|
1105
|
+
new Parse.Object<{ example: boolean }>('TestObject', { example: 'hello' });
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
function testStaticMethods() {
|
|
1109
|
+
async function testSaveAll(
|
|
1110
|
+
objUntyped: Parse.Object,
|
|
1111
|
+
objTyped: Parse.Object<{ example: string }>
|
|
1112
|
+
) {
|
|
1113
|
+
// $ExpectType ParseObject<Attributes>[]
|
|
1114
|
+
await Parse.Object.saveAll([objUntyped]);
|
|
1115
|
+
|
|
1116
|
+
// $ExpectType ParseObject<{ example: string; }>[]
|
|
1117
|
+
await Parse.Object.saveAll([objTyped]);
|
|
1118
|
+
|
|
1119
|
+
// $ExpectType [ParseObject<Attributes>, ParseObject<{ example: string; }>]
|
|
1120
|
+
await Parse.Object.saveAll<[typeof objUntyped, typeof objTyped]>([objUntyped, objTyped]);
|
|
1121
|
+
|
|
1122
|
+
// $ExpectError
|
|
1123
|
+
await Parse.Object.saveAll([123]);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function testAttributes(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: string }>) {
|
|
1128
|
+
// $ExpectType any
|
|
1129
|
+
objUntyped.attributes.whatever;
|
|
1130
|
+
|
|
1131
|
+
// $ExpectType string
|
|
1132
|
+
objTyped.attributes.example;
|
|
1133
|
+
|
|
1134
|
+
// $ExpectError
|
|
1135
|
+
objTyped.attributes.other;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
function testAdd(
|
|
1139
|
+
objUntyped: Parse.Object,
|
|
1140
|
+
objTyped: Parse.Object<{ stringList: string[]; thing: boolean }>
|
|
1141
|
+
) {
|
|
1142
|
+
// $ExpectType ParseObject<Attributes>
|
|
1143
|
+
objUntyped.add('whatever', 'hello');
|
|
1144
|
+
|
|
1145
|
+
// $ExpectType ParseObject<{ stringList: string[]; thing: boolean; }>
|
|
1146
|
+
objTyped.add('stringList', 'hello');
|
|
1147
|
+
|
|
1148
|
+
// $ExpectError
|
|
1149
|
+
objTyped.add('stringList', 100);
|
|
1150
|
+
|
|
1151
|
+
// $ExpectError
|
|
1152
|
+
objTyped.add('thing', true);
|
|
1153
|
+
|
|
1154
|
+
// $ExpectError
|
|
1155
|
+
objTyped.add('whatever', 'hello');
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
function testAddAll(
|
|
1159
|
+
objUntyped: Parse.Object,
|
|
1160
|
+
objTyped: Parse.Object<{ stringList: string[]; thing: boolean }>
|
|
1161
|
+
) {
|
|
1162
|
+
// $ExpectType ParseObject<Attributes>
|
|
1163
|
+
objUntyped.addAll('whatever', ['hello', 100]);
|
|
1164
|
+
|
|
1165
|
+
// $ExpectType ParseObject<{ stringList: string[]; thing: boolean; }>
|
|
1166
|
+
objTyped.addAll('stringList', ['hello']);
|
|
1167
|
+
|
|
1168
|
+
// $ExpectError
|
|
1169
|
+
objTyped.addAll('stringList', [100]);
|
|
1170
|
+
|
|
1171
|
+
// $ExpectError
|
|
1172
|
+
objTyped.addAll('thing', [true]);
|
|
1173
|
+
|
|
1174
|
+
// $ExpectError
|
|
1175
|
+
objTyped.addAll('whatever', ['hello']);
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
function testAddAllUnique(
|
|
1179
|
+
objUntyped: Parse.Object,
|
|
1180
|
+
objTyped: Parse.Object<{ stringList: string[]; thing: boolean }>
|
|
1181
|
+
) {
|
|
1182
|
+
// $ExpectType ParseObject<Attributes>
|
|
1183
|
+
objUntyped.addAllUnique('whatever', ['hello', 100]);
|
|
1184
|
+
|
|
1185
|
+
// $ExpectType ParseObject<{ stringList: string[]; thing: boolean; }>
|
|
1186
|
+
objTyped.addAllUnique('stringList', ['hello']);
|
|
1187
|
+
|
|
1188
|
+
// $ExpectError
|
|
1189
|
+
objTyped.addAllUnique('stringList', [100]);
|
|
1190
|
+
|
|
1191
|
+
// $ExpectError
|
|
1192
|
+
objTyped.addAllUnique('thing', [true]);
|
|
1193
|
+
|
|
1194
|
+
// $ExpectError
|
|
1195
|
+
objTyped.addAllUnique('whatever', ['hello']);
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
function testAddUnique(
|
|
1199
|
+
objUntyped: Parse.Object,
|
|
1200
|
+
objTyped: Parse.Object<{ stringList: string[]; thing: boolean }>
|
|
1201
|
+
) {
|
|
1202
|
+
// $ExpectType ParseObject<Attributes>
|
|
1203
|
+
objUntyped.addUnique('whatever', 'hello');
|
|
1204
|
+
|
|
1205
|
+
// $ExpectType ParseObject<{ stringList: string[]; thing: boolean; }>
|
|
1206
|
+
objTyped.addUnique('stringList', 'hello');
|
|
1207
|
+
|
|
1208
|
+
// $ExpectError
|
|
1209
|
+
objTyped.addUnique('stringList', 100);
|
|
1210
|
+
|
|
1211
|
+
// $ExpectError
|
|
1212
|
+
objTyped.addUnique('thing', true);
|
|
1213
|
+
|
|
1214
|
+
// $ExpectError
|
|
1215
|
+
objTyped.addUnique('whatever', 'hello');
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
function testDirty(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: string }>) {
|
|
1219
|
+
// $ExpectType boolean
|
|
1220
|
+
objUntyped.dirty();
|
|
1221
|
+
|
|
1222
|
+
// $ExpectType boolean
|
|
1223
|
+
objUntyped.dirty('whatever');
|
|
1224
|
+
|
|
1225
|
+
// $ExpectType boolean
|
|
1226
|
+
objTyped.dirty();
|
|
1227
|
+
|
|
1228
|
+
// $ExpectType boolean
|
|
1229
|
+
objTyped.dirty('example');
|
|
1230
|
+
|
|
1231
|
+
// $ExpectError
|
|
1232
|
+
objTyped.dirty('other');
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
function testEquals(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: string }>) {
|
|
1236
|
+
// $ExpectType boolean
|
|
1237
|
+
objUntyped.equals(objTyped);
|
|
1238
|
+
|
|
1239
|
+
// $ExpectType boolean
|
|
1240
|
+
objTyped.equals(objUntyped);
|
|
1241
|
+
|
|
1242
|
+
// $ExpectError
|
|
1243
|
+
objUntyped.equals('blah');
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function testEscape(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: string }>) {
|
|
1247
|
+
// $ExpectType string
|
|
1248
|
+
objUntyped.escape('whatever');
|
|
1249
|
+
|
|
1250
|
+
// $ExpectType string
|
|
1251
|
+
objTyped.escape('example');
|
|
1252
|
+
|
|
1253
|
+
// $ExpectError
|
|
1254
|
+
objTyped.escape('other');
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
async function testFetchWithInclude(
|
|
1258
|
+
objUntyped: Parse.Object,
|
|
1259
|
+
objTyped: Parse.Object<{ example: string }>
|
|
1260
|
+
) {
|
|
1261
|
+
// $ExpectType ParseObject<Attributes>
|
|
1262
|
+
await objUntyped.fetchWithInclude('whatever');
|
|
1263
|
+
|
|
1264
|
+
// $ExpectType ParseObject<Attributes>
|
|
1265
|
+
await objUntyped.fetchWithInclude(['whatever']);
|
|
1266
|
+
|
|
1267
|
+
// $ExpectType ParseObject<Attributes>
|
|
1268
|
+
await objUntyped.fetchWithInclude([['whatever']]);
|
|
1269
|
+
|
|
1270
|
+
// $ExpectError
|
|
1271
|
+
await objUntyped.fetchWithInclude([[['whatever']]]);
|
|
1272
|
+
|
|
1273
|
+
// $ExpectType ParseObject<{ example: string; }>
|
|
1274
|
+
await objTyped.fetchWithInclude('example');
|
|
1275
|
+
|
|
1276
|
+
// $ExpectType ParseObject<{ example: string; }>
|
|
1277
|
+
await objTyped.fetchWithInclude(['example']);
|
|
1278
|
+
|
|
1279
|
+
// $ExpectType ParseObject<{ example: string; }>
|
|
1280
|
+
await objTyped.fetchWithInclude([['example']]);
|
|
1281
|
+
|
|
1282
|
+
// $ExpectError
|
|
1283
|
+
await objTyped.fetchWithInclude([[['example']]]);
|
|
1284
|
+
|
|
1285
|
+
// $ExpectType ParseObject<{ example: string; }>[]
|
|
1286
|
+
await Parse.Object.fetchAllIfNeededWithInclude([objTyped], 'example');
|
|
1287
|
+
|
|
1288
|
+
// $ExpectError
|
|
1289
|
+
await Parse.Object.fetchAllIfNeededWithInclude([objTyped], 'notAnAttribute');
|
|
1290
|
+
|
|
1291
|
+
// $ExpectType ParseObject<{ example: string; }>[]
|
|
1292
|
+
await Parse.Object.fetchAllWithInclude([objTyped], 'example');
|
|
1293
|
+
|
|
1294
|
+
// $ExpectError
|
|
1295
|
+
await Parse.Object.fetchAllWithInclude([objTyped], 'notAnAttribute');
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
function testGet(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: number }>) {
|
|
1299
|
+
// $ExpectType any
|
|
1300
|
+
objUntyped.get('whatever');
|
|
1301
|
+
|
|
1302
|
+
// $ExpectType number
|
|
1303
|
+
objTyped.get('example');
|
|
1304
|
+
|
|
1305
|
+
// $ExpectError
|
|
1306
|
+
objTyped.get('other');
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
function testHas(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: number }>) {
|
|
1310
|
+
// $ExpectType boolean
|
|
1311
|
+
objUntyped.has('whatever');
|
|
1312
|
+
|
|
1313
|
+
// $ExpectType boolean
|
|
1314
|
+
objTyped.has('example');
|
|
1315
|
+
|
|
1316
|
+
// $ExpectError
|
|
1317
|
+
objTyped.has('other');
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function testIncrement(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: number }>) {
|
|
1321
|
+
// $ExpectType ParseObject<Attributes>
|
|
1322
|
+
objUntyped.increment('whatever');
|
|
1323
|
+
|
|
1324
|
+
// $ExpectType ParseObject<Attributes>
|
|
1325
|
+
objUntyped.increment('whatever', 10);
|
|
1326
|
+
|
|
1327
|
+
// $ExpectType ParseObject<{ example: number; }>
|
|
1328
|
+
objTyped.increment('example');
|
|
1329
|
+
|
|
1330
|
+
// $ExpectType ParseObject<{ example: number; }>
|
|
1331
|
+
objTyped.increment('example', 20);
|
|
1332
|
+
|
|
1333
|
+
// $ExpectError
|
|
1334
|
+
objTyped.increment('example', true);
|
|
1335
|
+
|
|
1336
|
+
// $ExpectError
|
|
1337
|
+
objTyped.increment('other');
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
function testDecrement(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: number }>) {
|
|
1341
|
+
// $ExpectType ParseObject<Attributes>
|
|
1342
|
+
objUntyped.decrement('whatever');
|
|
1343
|
+
|
|
1344
|
+
// $ExpectType ParseObject<Attributes>
|
|
1345
|
+
objUntyped.decrement('whatever', 10);
|
|
1346
|
+
|
|
1347
|
+
// $ExpectType ParseObject<{ example: number; }>
|
|
1348
|
+
objTyped.decrement('example');
|
|
1349
|
+
|
|
1350
|
+
// $ExpectType ParseObject<{ example: number; }>
|
|
1351
|
+
objTyped.decrement('example', 20);
|
|
1352
|
+
|
|
1353
|
+
// $ExpectError
|
|
1354
|
+
objTyped.decrement('example', true);
|
|
1355
|
+
|
|
1356
|
+
// $ExpectError
|
|
1357
|
+
objTyped.decrement('other');
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
function testNewInstance(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: number }>) {
|
|
1361
|
+
// $ExpectType ParseObject<Attributes>
|
|
1362
|
+
objUntyped.newInstance();
|
|
1363
|
+
|
|
1364
|
+
// $ExpectType ParseObject<{ example: number; }>
|
|
1365
|
+
objTyped.newInstance();
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
function testOp(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: number }>) {
|
|
1369
|
+
// $ExpectType Op | undefined
|
|
1370
|
+
objUntyped.op('whatever');
|
|
1371
|
+
|
|
1372
|
+
// $ExpectType Op | undefined
|
|
1373
|
+
objTyped.op('example');
|
|
1374
|
+
|
|
1375
|
+
// $ExpectError
|
|
1376
|
+
objTyped.op('other');
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
function testRelation(
|
|
1380
|
+
objUntyped: Parse.Object,
|
|
1381
|
+
objTyped: Parse.Object<{ example: number; rel: Parse.Relation }>
|
|
1382
|
+
) {
|
|
1383
|
+
// $ExpectType ParseRelation<ParseObject<Attributes>, ParseObject<Attributes>>
|
|
1384
|
+
objUntyped.relation('whatever');
|
|
1385
|
+
|
|
1386
|
+
// $ExpectType ParseRelation<ParseObject<{ example: number; rel: ParseRelation<ParseObject<Attributes>, ParseObject<Attributes>>; }>, ParseObject<Attributes>>
|
|
1387
|
+
objTyped.relation('rel');
|
|
1388
|
+
|
|
1389
|
+
// $ExpectError
|
|
1390
|
+
objTyped.relation('example');
|
|
1391
|
+
|
|
1392
|
+
// $ExpectError
|
|
1393
|
+
objTyped.relation('other');
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
function testRemove(
|
|
1397
|
+
objUntyped: Parse.Object,
|
|
1398
|
+
objTyped: Parse.Object<{ stringList: string[]; thing: boolean }>
|
|
1399
|
+
) {
|
|
1400
|
+
// $ExpectType ParseObject<Attributes>
|
|
1401
|
+
objUntyped.remove('whatever', 'hello');
|
|
1402
|
+
|
|
1403
|
+
// $ExpectType ParseObject<{ stringList: string[]; thing: boolean; }>
|
|
1404
|
+
objTyped.remove('stringList', 'hello');
|
|
1405
|
+
|
|
1406
|
+
// $ExpectError
|
|
1407
|
+
objTyped.remove('stringList', 100);
|
|
1408
|
+
|
|
1409
|
+
// $ExpectError
|
|
1410
|
+
objTyped.remove('thing', true);
|
|
1411
|
+
|
|
1412
|
+
// $ExpectError
|
|
1413
|
+
objTyped.remove('whatever', 'hello');
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
function testRemoveAll(
|
|
1417
|
+
objUntyped: Parse.Object,
|
|
1418
|
+
objTyped: Parse.Object<{ stringList: string[]; thing: boolean }>
|
|
1419
|
+
) {
|
|
1420
|
+
// $ExpectType ParseObject<Attributes>
|
|
1421
|
+
objUntyped.removeAll('whatever', ['hello', 100]);
|
|
1422
|
+
|
|
1423
|
+
// $ExpectType ParseObject<{ stringList: string[]; thing: boolean; }>
|
|
1424
|
+
objTyped.removeAll('stringList', ['hello']);
|
|
1425
|
+
|
|
1426
|
+
// $ExpectError
|
|
1427
|
+
objTyped.removeAll('stringList', [100]);
|
|
1428
|
+
|
|
1429
|
+
// $ExpectError
|
|
1430
|
+
objTyped.removeAll('thing', [true]);
|
|
1431
|
+
|
|
1432
|
+
// $ExpectError
|
|
1433
|
+
objTyped.removeAll('whatever', ['hello']);
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
function testRevert(
|
|
1437
|
+
objUntyped: Parse.Object,
|
|
1438
|
+
objTyped: Parse.Object<{ thingOne: number; thingTwo: boolean }>
|
|
1439
|
+
) {
|
|
1440
|
+
// $ExpectType void
|
|
1441
|
+
objUntyped.revert();
|
|
1442
|
+
|
|
1443
|
+
// $ExpectType void
|
|
1444
|
+
objUntyped.revert('whatever', 'more whatever');
|
|
1445
|
+
|
|
1446
|
+
// $ExpectType void
|
|
1447
|
+
objTyped.revert();
|
|
1448
|
+
|
|
1449
|
+
// $ExpectType void
|
|
1450
|
+
objTyped.revert('thingOne', 'thingTwo');
|
|
1451
|
+
|
|
1452
|
+
// $ExpectError
|
|
1453
|
+
objTyped.revert('other');
|
|
1454
|
+
}
|
|
1455
|
+
interface ObjectAttributes {
|
|
1456
|
+
example: boolean;
|
|
1457
|
+
someString: string;
|
|
1458
|
+
}
|
|
1459
|
+
interface OptionalObjectAttributes {
|
|
1460
|
+
example?: boolean | undefined;
|
|
1461
|
+
another?: string | undefined;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
async function testSave(
|
|
1465
|
+
objUntyped: Parse.Object,
|
|
1466
|
+
objTyped: Parse.Object<ObjectAttributes>,
|
|
1467
|
+
objTypedOptional: Parse.Object<OptionalObjectAttributes>
|
|
1468
|
+
) {
|
|
1469
|
+
// $ExpectType ParseObject<Attributes>
|
|
1470
|
+
await objUntyped.save({ whatever: 100 });
|
|
1471
|
+
|
|
1472
|
+
// $ExpectType ParseObject<Attributes>
|
|
1473
|
+
await objUntyped.save('whatever', 100);
|
|
1474
|
+
|
|
1475
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1476
|
+
await objTyped.save({ example: true });
|
|
1477
|
+
|
|
1478
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1479
|
+
await objTyped.save({ example: true, someString: 'hello' });
|
|
1480
|
+
|
|
1481
|
+
// $ExpectError
|
|
1482
|
+
await objTyped.save({ example: 'hello', someString: true });
|
|
1483
|
+
|
|
1484
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1485
|
+
await objTyped.save('example', true);
|
|
1486
|
+
|
|
1487
|
+
// $ExpectError
|
|
1488
|
+
await objTyped.save({ example: 'hello' });
|
|
1489
|
+
|
|
1490
|
+
// $ExpectError
|
|
1491
|
+
await objTyped.save({ wrongProp: 5 });
|
|
1492
|
+
|
|
1493
|
+
// $ExpectError
|
|
1494
|
+
await objTyped.save('example', 10);
|
|
1495
|
+
|
|
1496
|
+
// $ExpectError
|
|
1497
|
+
await objTyped.save('wrongProp', true);
|
|
1498
|
+
|
|
1499
|
+
// $ExpectError
|
|
1500
|
+
await objTyped.save({ example: undefined });
|
|
1501
|
+
|
|
1502
|
+
// $ExpectError
|
|
1503
|
+
await objTyped.save('example', undefined);
|
|
1504
|
+
|
|
1505
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1506
|
+
await objTyped.save({});
|
|
1507
|
+
|
|
1508
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1509
|
+
await objTyped.save();
|
|
1510
|
+
|
|
1511
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1512
|
+
await objTypedOptional.save({ example: undefined });
|
|
1513
|
+
|
|
1514
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1515
|
+
await objTypedOptional.save('example', undefined);
|
|
1516
|
+
|
|
1517
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1518
|
+
await objTypedOptional.save({});
|
|
1519
|
+
|
|
1520
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1521
|
+
await objTypedOptional.saveEventually({});
|
|
1522
|
+
|
|
1523
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1524
|
+
await objTypedOptional.destroyEventually({});
|
|
1525
|
+
|
|
1526
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1527
|
+
await objTypedOptional.saveEventually();
|
|
1528
|
+
|
|
1529
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1530
|
+
await objTypedOptional.destroyEventually();
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
function testSet(
|
|
1534
|
+
objUntyped: Parse.Object,
|
|
1535
|
+
objTyped: Parse.Object<ObjectAttributes>,
|
|
1536
|
+
objTypedOptional: Parse.Object<OptionalObjectAttributes>
|
|
1537
|
+
) {
|
|
1538
|
+
// $ExpectType ParseObject<Attributes>
|
|
1539
|
+
objUntyped.set('propA', 'some value');
|
|
1540
|
+
|
|
1541
|
+
// $ExpectType ParseObject<Attributes>
|
|
1542
|
+
objUntyped.set({ propA: undefined });
|
|
1543
|
+
|
|
1544
|
+
// $ExpectError
|
|
1545
|
+
objTyped.set({ example: false });
|
|
1546
|
+
|
|
1547
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1548
|
+
objTyped.set({ example: true, someString: 'abc' });
|
|
1549
|
+
|
|
1550
|
+
// $ExpectError
|
|
1551
|
+
objTyped.set({ example: 123, someString: 'abc' });
|
|
1552
|
+
|
|
1553
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1554
|
+
objTyped.set('example', true);
|
|
1555
|
+
|
|
1556
|
+
// $ExpectError
|
|
1557
|
+
objTyped.set({ example: 100 });
|
|
1558
|
+
|
|
1559
|
+
// $ExpectError
|
|
1560
|
+
objTyped.set({ other: 'something' });
|
|
1561
|
+
|
|
1562
|
+
// $ExpectError
|
|
1563
|
+
objTyped.set('example', 100);
|
|
1564
|
+
|
|
1565
|
+
// $ExpectError
|
|
1566
|
+
objTyped.set('other', 100);
|
|
1567
|
+
|
|
1568
|
+
// $ExpectError
|
|
1569
|
+
objTyped.set({ example: undefined });
|
|
1570
|
+
|
|
1571
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1572
|
+
objTyped.set({}); // Should this error?
|
|
1573
|
+
|
|
1574
|
+
// $ExpectType ParseObject<ObjectAttributes>
|
|
1575
|
+
objTyped.set('example', undefined); // Should this error?
|
|
1576
|
+
|
|
1577
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1578
|
+
objTypedOptional.set({ example: undefined });
|
|
1579
|
+
|
|
1580
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1581
|
+
objTypedOptional.set('example', undefined);
|
|
1582
|
+
|
|
1583
|
+
// $ExpectType ParseObject<OptionalObjectAttributes>
|
|
1584
|
+
objTypedOptional.set({});
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
interface AttributesAllTypes {
|
|
1588
|
+
someString: string;
|
|
1589
|
+
someNumber: number;
|
|
1590
|
+
someBoolean: boolean;
|
|
1591
|
+
someDate: Date;
|
|
1592
|
+
someJSONObject: AttributesAllTypes;
|
|
1593
|
+
someJSONArray: AttributesAllTypes[];
|
|
1594
|
+
someRegExp: RegExp;
|
|
1595
|
+
someUndefined: undefined;
|
|
1596
|
+
someNull: null;
|
|
1597
|
+
someParseObjectUntyped: Parse.Object;
|
|
1598
|
+
someParseObjectTyped: Parse.Object<AttributesAllTypes>;
|
|
1599
|
+
someParseACL: Parse.ACL;
|
|
1600
|
+
someParseGeoPoint: Parse.GeoPoint;
|
|
1601
|
+
someParsePolygon: Parse.Polygon;
|
|
1602
|
+
someParseRelation: Parse.Relation;
|
|
1603
|
+
someParseFile: Parse.File;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
function testToJSON(objUntyped: Parse.Object, objTyped: Parse.Object<AttributesAllTypes>) {
|
|
1607
|
+
// $ExpectType ToJSON<Attributes> & JSONBaseAttributes
|
|
1608
|
+
const JSONUntyped = objUntyped.toJSON();
|
|
1609
|
+
// $ExpectType string
|
|
1610
|
+
JSONUntyped.objectId;
|
|
1611
|
+
// $ExpectType string
|
|
1612
|
+
JSONUntyped.createdAt;
|
|
1613
|
+
// $ExpectType string
|
|
1614
|
+
JSONUntyped.updatedAt;
|
|
1615
|
+
// $ExpectType any
|
|
1616
|
+
JSONUntyped.anything;
|
|
1617
|
+
|
|
1618
|
+
// $ExpectType ToJSON<AttributesAllTypes> & JSONBaseAttributes
|
|
1619
|
+
const JSONTyped = objTyped.toJSON();
|
|
1620
|
+
// $ExpectType string
|
|
1621
|
+
JSONTyped.objectId;
|
|
1622
|
+
// $ExpectType string
|
|
1623
|
+
JSONTyped.createdAt;
|
|
1624
|
+
// $ExpectType string
|
|
1625
|
+
JSONTyped.updatedAt;
|
|
1626
|
+
// $ExpectType string
|
|
1627
|
+
JSONTyped.someString;
|
|
1628
|
+
// $ExpectType number
|
|
1629
|
+
JSONTyped.someNumber;
|
|
1630
|
+
// $ExpectType boolean
|
|
1631
|
+
JSONTyped.someBoolean;
|
|
1632
|
+
// $ExpectType { __type: "Date"; iso: string; }
|
|
1633
|
+
JSONTyped.someDate;
|
|
1634
|
+
// $ExpectType ToJSON<AttributesAllTypes>
|
|
1635
|
+
JSONTyped.someJSONObject;
|
|
1636
|
+
// $ExpectType ToJSON<AttributesAllTypes>[]
|
|
1637
|
+
JSONTyped.someJSONArray;
|
|
1638
|
+
// $ExpectType string
|
|
1639
|
+
JSONTyped.someRegExp;
|
|
1640
|
+
// $ExpectType undefined
|
|
1641
|
+
JSONTyped.someUndefined;
|
|
1642
|
+
// $ExpectType null
|
|
1643
|
+
JSONTyped.someNull;
|
|
1644
|
+
// $ExpectType Pointer | (ToJSON<Attributes> & JSONBaseAttributes)
|
|
1645
|
+
JSONTyped.someParseObjectUntyped;
|
|
1646
|
+
// $ExpectType Pointer | (ToJSON<AttributesAllTypes> & JSONBaseAttributes)
|
|
1647
|
+
JSONTyped.someParseObjectTyped;
|
|
1648
|
+
// $ExpectType ByIdMap
|
|
1649
|
+
JSONTyped.someParseACL;
|
|
1650
|
+
// $ExpectType { __type: string; latitude: number; longitude: number; }
|
|
1651
|
+
JSONTyped.someParseGeoPoint;
|
|
1652
|
+
// $ExpectType { __type: string; coordinates: Coordinates; }
|
|
1653
|
+
JSONTyped.someParsePolygon;
|
|
1654
|
+
// $ExpectType { __type: "Relation"; className: string | null; }
|
|
1655
|
+
JSONTyped.someParseRelation;
|
|
1656
|
+
// $ExpectType { __type: "File"; name?: string | undefined; url?: string | undefined; }
|
|
1657
|
+
JSONTyped.someParseFile;
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
function testUnset(objUntyped: Parse.Object, objTyped: Parse.Object<{ example: string }>) {
|
|
1661
|
+
// $ExpectType ParseObject<Attributes>
|
|
1662
|
+
objUntyped.unset('whatever');
|
|
1663
|
+
|
|
1664
|
+
// $ExpectType ParseObject<{ example: string; }>
|
|
1665
|
+
objTyped.unset('example');
|
|
1666
|
+
|
|
1667
|
+
// $ExpectError
|
|
1668
|
+
objTyped.unset('other');
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
function testValidate(obj: Parse.Object) {
|
|
1672
|
+
// Note: The attributes being validated don't necessarily have to match the current object's attributes
|
|
1673
|
+
|
|
1674
|
+
// $ExpectType ParseError | boolean
|
|
1675
|
+
obj.validate({ someAttrToValidate: 'hello' });
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
function testNullableArrays(objTyped: Parse.Object<{ stringList?: string[] | null }>) {
|
|
1679
|
+
// $ExpectType ParseObject<{ stringList?: string[] | null | undefined; }>
|
|
1680
|
+
objTyped.add('stringList', 'foo');
|
|
1681
|
+
|
|
1682
|
+
// $ExpectError
|
|
1683
|
+
objTyped.add('stringList', 4);
|
|
1684
|
+
|
|
1685
|
+
// $ExpectType ParseObject<{ stringList?: string[] | null | undefined; }>
|
|
1686
|
+
objTyped.addAll('stringList', ['foo']);
|
|
1687
|
+
|
|
1688
|
+
// $ExpectError
|
|
1689
|
+
objTyped.addAll('stringList', [4]);
|
|
1690
|
+
|
|
1691
|
+
// $ExpectType ParseObject<{ stringList?: string[] | null | undefined; }>
|
|
1692
|
+
objTyped.addAllUnique('stringList', ['foo', 'bar']);
|
|
1693
|
+
|
|
1694
|
+
// $ExpectError
|
|
1695
|
+
objTyped.addAllUnique('stringList', [4]);
|
|
1696
|
+
|
|
1697
|
+
// $ExpectType ParseObject<{ stringList?: string[] | null | undefined; }>
|
|
1698
|
+
objTyped.addUnique('stringList', 'foo');
|
|
1699
|
+
|
|
1700
|
+
// $ExpectError
|
|
1701
|
+
objTyped.addUnique('stringList', 4);
|
|
1702
|
+
|
|
1703
|
+
// $ExpectType ParseObject<{ stringList?: string[] | null | undefined; }>
|
|
1704
|
+
objTyped.remove('stringList', 'bar');
|
|
1705
|
+
|
|
1706
|
+
// $ExpectError
|
|
1707
|
+
objTyped.remove('stringList', 4);
|
|
1708
|
+
|
|
1709
|
+
// $ExpectType ParseObject<{ stringList?: string[] | null | undefined; }>
|
|
1710
|
+
objTyped.removeAll('stringList', ['bar']);
|
|
1711
|
+
|
|
1712
|
+
// $ExpectError
|
|
1713
|
+
objTyped.removeAll('stringList', [4]);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
function testInstallation() {
|
|
1718
|
+
function testConstructor() {
|
|
1719
|
+
// $ExpectType ParseInstallation<Attributes>
|
|
1720
|
+
new Parse.Installation();
|
|
1721
|
+
|
|
1722
|
+
// $ExpectType ParseInstallation<{ example: number; }>
|
|
1723
|
+
new Parse.Installation({ example: 100 });
|
|
1724
|
+
|
|
1725
|
+
// $ExpectType ParseInstallation<{ example: number; }>
|
|
1726
|
+
new Parse.Installation<{ example: number }>();
|
|
1727
|
+
|
|
1728
|
+
// $ExpectType ParseInstallation<{ example: number; }>
|
|
1729
|
+
new Parse.Installation<{ example: number }>({ example: 100 });
|
|
1730
|
+
|
|
1731
|
+
// $ExpectError
|
|
1732
|
+
new Parse.Installation<{ example: number }>({ example: 'hello' });
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
function testQuery() {
|
|
1737
|
+
function testConstructor() {
|
|
1738
|
+
// $ExpectType ParseQuery<ParseObject<Attributes>>
|
|
1739
|
+
new Parse.Query('TestObject');
|
|
1740
|
+
|
|
1741
|
+
// $ExpectType ParseQuery<ParseRole<Attributes>>
|
|
1742
|
+
new Parse.Query(Parse.Role);
|
|
1743
|
+
|
|
1744
|
+
// $ExpectType ParseQuery<ParseUser<Attributes>>
|
|
1745
|
+
new Parse.Query(Parse.User);
|
|
1746
|
+
|
|
1747
|
+
// $ExpectType ParseQuery<ParseObject<{ example: string; }>>
|
|
1748
|
+
new Parse.Query<Parse.Object<{ example: string }>>('TestObject');
|
|
1749
|
+
|
|
1750
|
+
// $ExpectType ParseQuery<ParseRole<{ name: string; }>>
|
|
1751
|
+
new Parse.Query<Parse.Role<{ name: string }>>(Parse.Role);
|
|
1752
|
+
|
|
1753
|
+
// $ExpectType ParseQuery<ParseUser<{ example: string; }>>
|
|
1754
|
+
new Parse.Query<Parse.User<{ example: string }>>(Parse.User);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
function testQueryMethodTypes() {
|
|
1758
|
+
class AnotherSubClass extends Parse.Object<{ x: any }> {
|
|
1759
|
+
constructor() {
|
|
1760
|
+
super('Another', { x: 'example' });
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
class MySubClass extends Parse.Object<{
|
|
1764
|
+
attribute1: string;
|
|
1765
|
+
attribute2: number;
|
|
1766
|
+
attribute3: AnotherSubClass;
|
|
1767
|
+
attribute4: string[];
|
|
1768
|
+
}> {}
|
|
1769
|
+
const query = new Parse.Query(MySubClass);
|
|
1770
|
+
|
|
1771
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1772
|
+
query.addAscending(['attribute1', 'attribute2', 'updatedAt']);
|
|
1773
|
+
|
|
1774
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1775
|
+
query.addAscending('attribute1', 'attribute2', 'updatedAt');
|
|
1776
|
+
|
|
1777
|
+
// $ExpectError
|
|
1778
|
+
query.addAscending(['attribute1', 'unexistenProp']);
|
|
1779
|
+
|
|
1780
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1781
|
+
query.addDescending(['attribute1', 'attribute2', 'createdAt']);
|
|
1782
|
+
// $ExpectError
|
|
1783
|
+
query.addDescending(['attribute1', 'unexistenProp']);
|
|
1784
|
+
|
|
1785
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1786
|
+
query.ascending(['attribute1', 'attribute2', 'objectId']);
|
|
1787
|
+
// $ExpectError
|
|
1788
|
+
query.ascending(['attribute1', 'nonexistentProp']);
|
|
1789
|
+
|
|
1790
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1791
|
+
query.containedBy('attribute1', ['a', 'b', 'c']);
|
|
1792
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1793
|
+
query.containedBy('attribute3', ['objectId1', 'objectId2', 'objectId3']);
|
|
1794
|
+
// $ExpectError
|
|
1795
|
+
query.containedBy('attribute2', ['a', 'b', 'c']);
|
|
1796
|
+
// $ExpectError
|
|
1797
|
+
query.containedBy('attribute1', [1, 2, 3]);
|
|
1798
|
+
// $ExpectError
|
|
1799
|
+
query.containedBy('nonexistentProp', ['a', 'b', 'c']);
|
|
1800
|
+
|
|
1801
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1802
|
+
query.containedIn('attribute1', ['a', 'b', 'c']);
|
|
1803
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1804
|
+
query.containedIn('attribute3', ['objectId1', 'objectId2', 'objectId3']);
|
|
1805
|
+
// $ExpectError
|
|
1806
|
+
query.containedIn('attribute2', ['a', 'b', 'c']);
|
|
1807
|
+
// $ExpectError
|
|
1808
|
+
query.containedIn('attribute1', [1, 2, 3]);
|
|
1809
|
+
// $ExpectError
|
|
1810
|
+
query.containedIn('nonexistentProp', ['a', 'b', 'c']);
|
|
1811
|
+
|
|
1812
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1813
|
+
query.contains('attribute1', 'a substring');
|
|
1814
|
+
// $ExpectError
|
|
1815
|
+
query.contains('nonexistentProp', 'a substring');
|
|
1816
|
+
|
|
1817
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1818
|
+
query.containsAll('attribute1', ['a', 'b', 'c']);
|
|
1819
|
+
// $ExpectError
|
|
1820
|
+
query.containsAll('nonexistentProp', ['a', 'b', 'c']);
|
|
1821
|
+
|
|
1822
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1823
|
+
query.containsAllStartingWith('attribute1', ['a', 'b', 'c']);
|
|
1824
|
+
// $ExpectError
|
|
1825
|
+
query.containsAllStartingWith('nonexistentProp', ['a', 'b', 'c']);
|
|
1826
|
+
|
|
1827
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1828
|
+
query.descending(['attribute1', 'attribute2', 'objectId']);
|
|
1829
|
+
// $ExpectError
|
|
1830
|
+
query.descending(['attribute1', 'nonexistentProp']);
|
|
1831
|
+
|
|
1832
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1833
|
+
query.doesNotExist('attribute1');
|
|
1834
|
+
// $ExpectError
|
|
1835
|
+
query.doesNotExist('nonexistentProp');
|
|
1836
|
+
|
|
1837
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1838
|
+
query.doesNotMatchKeyInQuery('attribute1', 'x', new Parse.Query(AnotherSubClass));
|
|
1839
|
+
// $ExpectError
|
|
1840
|
+
query.doesNotMatchKeyInQuery('unexistenProp', 'x', new Parse.Query(AnotherSubClass));
|
|
1841
|
+
// $ExpectError
|
|
1842
|
+
query.doesNotMatchKeyInQuery('attribute1', 'unknownKey', new Parse.Query(AnotherSubClass));
|
|
1843
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1844
|
+
query.doesNotMatchKeyInQuery('objectId', 'x', new Parse.Query(AnotherSubClass));
|
|
1845
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1846
|
+
query.doesNotMatchKeyInQuery('updatedAt', 'x', new Parse.Query(AnotherSubClass));
|
|
1847
|
+
|
|
1848
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1849
|
+
query.doesNotMatchQuery('attribute1', new Parse.Query('Example'));
|
|
1850
|
+
// $ExpectError
|
|
1851
|
+
query.doesNotMatchQuery('nonexistentProp', new Parse.Query('Example'));
|
|
1852
|
+
|
|
1853
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1854
|
+
query.endsWith('attribute1', 'asuffixstring');
|
|
1855
|
+
// $ExpectError
|
|
1856
|
+
query.endsWith('nonexistentProp', 'asuffixstring');
|
|
1857
|
+
|
|
1858
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1859
|
+
query.equalTo('attribute2', 0);
|
|
1860
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1861
|
+
query.equalTo('attribute3', new AnotherSubClass());
|
|
1862
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1863
|
+
query.equalTo('attribute3', new AnotherSubClass().toPointer());
|
|
1864
|
+
// $ExpectError
|
|
1865
|
+
query.equalTo('attribute1', new AnotherSubClass().toPointer());
|
|
1866
|
+
// $ExpectError
|
|
1867
|
+
query.equalTo('attribute2', 'a string value');
|
|
1868
|
+
// $ExpectError
|
|
1869
|
+
query.equalTo('nonexistentProp', 'any value');
|
|
1870
|
+
|
|
1871
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1872
|
+
query.equalTo('attribute4', 'a_string_value'); // Can query contents of array
|
|
1873
|
+
// Can query array itself if equal too (mongodb $eq matches the array exactly or the <field> contains an element that matches the array exactly)
|
|
1874
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1875
|
+
query.equalTo('attribute4', ['a_string_value']);
|
|
1876
|
+
|
|
1877
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1878
|
+
query.notEqualTo('attribute4', 'a_string_value');
|
|
1879
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1880
|
+
query.notEqualTo('attribute4', ['a_string_value']);
|
|
1881
|
+
|
|
1882
|
+
// $ExpectError
|
|
1883
|
+
query.equalTo('attribute4', 5);
|
|
1884
|
+
// $ExpectError
|
|
1885
|
+
query.notEqualTo('attribute4', 5);
|
|
1886
|
+
// $ExpectError
|
|
1887
|
+
query.equalTo('attribute4', [5]);
|
|
1888
|
+
// $ExpectError
|
|
1889
|
+
query.notEqualTo('attribute4', [5]);
|
|
1890
|
+
|
|
1891
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1892
|
+
query.exists('attribute1');
|
|
1893
|
+
// $ExpectError
|
|
1894
|
+
query.exists('nonexistentProp');
|
|
1895
|
+
|
|
1896
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1897
|
+
query.fullText('attribute1', 'full text');
|
|
1898
|
+
// $ExpectError
|
|
1899
|
+
query.fullText('nonexistentProp', 'full text');
|
|
1900
|
+
|
|
1901
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1902
|
+
query.greaterThan('attribute2', 1000);
|
|
1903
|
+
// $ExpectError
|
|
1904
|
+
query.greaterThan('attribute2', '1000');
|
|
1905
|
+
// $ExpectError
|
|
1906
|
+
query.greaterThan('nonexistentProp', 1000);
|
|
1907
|
+
|
|
1908
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1909
|
+
query.greaterThanOrEqualTo('attribute2', 1000);
|
|
1910
|
+
// $ExpectError
|
|
1911
|
+
query.greaterThanOrEqualTo('attribute2', '1000');
|
|
1912
|
+
// $ExpectError
|
|
1913
|
+
query.greaterThanOrEqualTo('nonexistentProp', 1000);
|
|
1914
|
+
|
|
1915
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1916
|
+
query.include(['attribute1', 'attribute2']);
|
|
1917
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1918
|
+
query.include('attribute1', 'attribute2');
|
|
1919
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1920
|
+
query.include<any>('attribute3.someProp');
|
|
1921
|
+
// $ExpectError
|
|
1922
|
+
query.include(['attribute1', 'nonexistentProp']);
|
|
1923
|
+
|
|
1924
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1925
|
+
query.exclude('attribute1', 'attribute2');
|
|
1926
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1927
|
+
query.exclude(['attribute1', 'attribute2']);
|
|
1928
|
+
// $ExpectError
|
|
1929
|
+
query.exclude('attribute1', 'nonexistentProp');
|
|
1930
|
+
|
|
1931
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1932
|
+
query.lessThan('attribute2', 1000);
|
|
1933
|
+
// $ExpectError
|
|
1934
|
+
query.lessThan('attribute2', '1000');
|
|
1935
|
+
// $ExpectError
|
|
1936
|
+
query.lessThan('nonexistentProp', 1000);
|
|
1937
|
+
|
|
1938
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1939
|
+
query.lessThanOrEqualTo('attribute2', 1000);
|
|
1940
|
+
// $ExpectError
|
|
1941
|
+
query.lessThanOrEqualTo('attribute2', '1000');
|
|
1942
|
+
// $ExpectError
|
|
1943
|
+
query.lessThanOrEqualTo('nonexistentProp', 1000);
|
|
1944
|
+
|
|
1945
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1946
|
+
query.matches('attribute1', /a regex/);
|
|
1947
|
+
// $ExpectError
|
|
1948
|
+
query.matches('nonexistentProp', /a regex/);
|
|
1949
|
+
|
|
1950
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1951
|
+
query.matchesKeyInQuery('attribute1', 'x', new Parse.Query(AnotherSubClass));
|
|
1952
|
+
// $ExpectError
|
|
1953
|
+
query.matchesKeyInQuery('nonexistentProp', 'x', new Parse.Query(AnotherSubClass));
|
|
1954
|
+
// $ExpectError
|
|
1955
|
+
query.matchesKeyInQuery('attribute1', 'unknownKey', new Parse.Query(AnotherSubClass));
|
|
1956
|
+
|
|
1957
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1958
|
+
query.matchesQuery('attribute1', new Parse.Query('Example'));
|
|
1959
|
+
// $ExpectError
|
|
1960
|
+
query.matchesQuery('nonexistentProp', new Parse.Query('Example'));
|
|
1961
|
+
|
|
1962
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1963
|
+
query.near('attribute1', new Parse.GeoPoint());
|
|
1964
|
+
// $ExpectError
|
|
1965
|
+
query.near('nonexistentProp', new Parse.GeoPoint());
|
|
1966
|
+
|
|
1967
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1968
|
+
query.notContainedIn('attribute2', [1, 2, 3]);
|
|
1969
|
+
// $ExpectError
|
|
1970
|
+
query.notContainedIn('attribute2', ['1', '2', '3']);
|
|
1971
|
+
// $ExpectError
|
|
1972
|
+
query.notContainedIn('nonexistentProp', [1, 2, 3]);
|
|
1973
|
+
|
|
1974
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1975
|
+
query.notEqualTo('attribute1', '1');
|
|
1976
|
+
// $ExpectError
|
|
1977
|
+
query.notEqualTo('attribute1', 1);
|
|
1978
|
+
// $ExpectError
|
|
1979
|
+
query.notEqualTo('nonexistentProp', 1);
|
|
1980
|
+
|
|
1981
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1982
|
+
query.polygonContains('attribute1', new Parse.GeoPoint());
|
|
1983
|
+
// $ExpectError
|
|
1984
|
+
query.polygonContains('nonexistentProp', new Parse.GeoPoint());
|
|
1985
|
+
|
|
1986
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1987
|
+
query.select('attribute1', 'attribute2');
|
|
1988
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1989
|
+
query.select(['attribute1', 'attribute2']);
|
|
1990
|
+
// $ExpectError
|
|
1991
|
+
query.select('attribute1', 'nonexistentProp');
|
|
1992
|
+
|
|
1993
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1994
|
+
query.startsWith('attribute1', 'prefix string');
|
|
1995
|
+
// $ExpectError
|
|
1996
|
+
query.startsWith('nonexistentProp', 'prefix string');
|
|
1997
|
+
|
|
1998
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
1999
|
+
query.watch('attribute1', 'attribute2');
|
|
2000
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
2001
|
+
query.watch(['attribute1', 'attribute2']);
|
|
2002
|
+
// $ExpectError
|
|
2003
|
+
query.watch('attribute1', 'nonexistentProp');
|
|
2004
|
+
|
|
2005
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
2006
|
+
query.withCount(true);
|
|
2007
|
+
|
|
2008
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
2009
|
+
query.withinGeoBox('attribute1', new Parse.GeoPoint(), new Parse.GeoPoint());
|
|
2010
|
+
// $ExpectError
|
|
2011
|
+
query.withinGeoBox('nonexistentProp', new Parse.GeoPoint(), new Parse.GeoPoint());
|
|
2012
|
+
|
|
2013
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
2014
|
+
query.withinKilometers('attribute1', new Parse.GeoPoint(), 100);
|
|
2015
|
+
// $ExpectError
|
|
2016
|
+
query.withinKilometers('nonexistentProp', new Parse.GeoPoint(), 100);
|
|
2017
|
+
|
|
2018
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
2019
|
+
query.withinMiles('attribute1', new Parse.GeoPoint(), 100);
|
|
2020
|
+
// $ExpectError
|
|
2021
|
+
query.withinMiles('nonexistentProp', new Parse.GeoPoint(), 100);
|
|
2022
|
+
|
|
2023
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
2024
|
+
query.withinPolygon('attribute1', [
|
|
2025
|
+
[12.3, 45.6],
|
|
2026
|
+
[-78.9, 10.1],
|
|
2027
|
+
]);
|
|
2028
|
+
// $ExpectError
|
|
2029
|
+
query.withinPolygon('nonexistentProp', [
|
|
2030
|
+
[12.3, 45.6],
|
|
2031
|
+
[-78.9, 10.1],
|
|
2032
|
+
]);
|
|
2033
|
+
|
|
2034
|
+
// $ExpectType ParseQuery<MySubClass>
|
|
2035
|
+
query.withinRadians('attribute1', new Parse.GeoPoint(), 100);
|
|
2036
|
+
// $ExpectError
|
|
2037
|
+
query.withinRadians('nonexistentProp', new Parse.GeoPoint(), 100);
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
async function testQueryMethods(
|
|
2041
|
+
queryUntyped: Parse.Query,
|
|
2042
|
+
queryTyped: Parse.Query<Parse.Object<{ example: string }>>
|
|
2043
|
+
) {
|
|
2044
|
+
// $ExpectType ParseObject<Attributes>
|
|
2045
|
+
await queryUntyped.get('objectId');
|
|
2046
|
+
|
|
2047
|
+
// $ExpectType ParseObject<Attributes>[]
|
|
2048
|
+
await queryUntyped.find();
|
|
2049
|
+
|
|
2050
|
+
// $ExpectType string[]
|
|
2051
|
+
await queryTyped.distinct('example');
|
|
2052
|
+
|
|
2053
|
+
// $ExpectType ParseObject<Attributes> | undefined
|
|
2054
|
+
await queryUntyped.first();
|
|
2055
|
+
|
|
2056
|
+
// $ExpectType ParseObject<{ example: string; }>
|
|
2057
|
+
await queryTyped.get('objectId');
|
|
2058
|
+
|
|
2059
|
+
// $ExpectType ParseObject<{ example: string; }>[]
|
|
2060
|
+
await queryTyped.find();
|
|
2061
|
+
|
|
2062
|
+
// $ExpectType ParseObject<{ example: string; }> | undefined
|
|
2063
|
+
await queryTyped.first();
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
function testRole() {
|
|
2068
|
+
function testConstructor(acl: Parse.ACL) {
|
|
2069
|
+
// $ExpectType ParseRole<{ example: string; }>
|
|
2070
|
+
new Parse.Role<{ example: string }>('TestRole', acl);
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
function testAttributes(roleUntyped: Parse.Role, roleTyped: Parse.Role<{ example: number }>) {
|
|
2074
|
+
// $ExpectType Attributes
|
|
2075
|
+
roleUntyped.attributes;
|
|
2076
|
+
|
|
2077
|
+
// $ExpectType { example: number; }
|
|
2078
|
+
roleTyped.attributes;
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
function testSession() {
|
|
2083
|
+
async function testConstructor() {
|
|
2084
|
+
// $ExpectType ParseSession<Attributes>
|
|
2085
|
+
const session = new Parse.Session();
|
|
2086
|
+
|
|
2087
|
+
// $ExpectType ParseSession<{ example: number; }>
|
|
2088
|
+
new Parse.Session({ example: 100 });
|
|
2089
|
+
|
|
2090
|
+
// $ExpectType ParseSession<{ example: number; }>
|
|
2091
|
+
new Parse.Session<{ example: number }>();
|
|
2092
|
+
|
|
2093
|
+
// $ExpectType ParseSession<{ example: number; }>
|
|
2094
|
+
new Parse.Session<{ example: number }>({ example: 100 });
|
|
2095
|
+
|
|
2096
|
+
// $ExpectError
|
|
2097
|
+
new Parse.Session<{ example: number }>({ example: 'hello' });
|
|
2098
|
+
|
|
2099
|
+
// $ExpectType boolean
|
|
2100
|
+
Parse.Session.isCurrentSessionRevocable();
|
|
2101
|
+
|
|
2102
|
+
// $ExpectType string[]
|
|
2103
|
+
Parse.Session.readOnlyAttributes();
|
|
2104
|
+
|
|
2105
|
+
// $ExpectType string
|
|
2106
|
+
session.getSessionToken();
|
|
2107
|
+
|
|
2108
|
+
// $ExpectType ParseSession<Attributes>
|
|
2109
|
+
await Parse.Session.current();
|
|
2110
|
+
|
|
2111
|
+
// $ExpectType ParseSession<{ example: string; }>
|
|
2112
|
+
await Parse.Session.current<Parse.Session<{ example: string }>>();
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
function testUser() {
|
|
2117
|
+
function testConstructor() {
|
|
2118
|
+
// $ExpectType ParseUser<Attributes>
|
|
2119
|
+
new Parse.User();
|
|
2120
|
+
|
|
2121
|
+
// $ExpectType ParseUser<{ example: number; }>
|
|
2122
|
+
new Parse.User({ example: 100 });
|
|
2123
|
+
|
|
2124
|
+
// $ExpectType ParseUser<{ example: number; }>
|
|
2125
|
+
new Parse.User<{ example: number }>();
|
|
2126
|
+
|
|
2127
|
+
// $ExpectType ParseUser<{ example: number; }>
|
|
2128
|
+
new Parse.User<{ example: number }>({ example: 100 });
|
|
2129
|
+
|
|
2130
|
+
// $ExpectError
|
|
2131
|
+
new Parse.User<{ example: number }>({ example: 'hello' });
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
async function testStatic() {
|
|
2135
|
+
const user = new Parse.User<{ field: 'hello' }>();
|
|
2136
|
+
|
|
2137
|
+
// $ExpectType ParseUser<{ field: "hello"; }> | null
|
|
2138
|
+
Parse.User.current<Parse.User<{ field: 'hello' }>>();
|
|
2139
|
+
|
|
2140
|
+
// $ExpectType ParseUser<{ field: "hello"; }> | null
|
|
2141
|
+
await Parse.User.currentAsync<Parse.User<{ field: 'hello' }>>();
|
|
2142
|
+
|
|
2143
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2144
|
+
await Parse.User.signUp<Parse.User<{ field: 'hello' }>>('username', 'password', {});
|
|
2145
|
+
|
|
2146
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2147
|
+
await Parse.User.become<Parse.User<{ field: 'hello' }>>('session-token');
|
|
2148
|
+
|
|
2149
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2150
|
+
await Parse.User.logIn<Parse.User<{ field: 'hello' }>>('username', 'password');
|
|
2151
|
+
|
|
2152
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2153
|
+
await Parse.User.logInWith<Parse.User<{ field: 'hello' }>>('provider', {});
|
|
2154
|
+
|
|
2155
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2156
|
+
await Parse.User.logInWithAdditionalAuth<Parse.User<{ field: 'hello' }>>(
|
|
2157
|
+
'username',
|
|
2158
|
+
'password',
|
|
2159
|
+
{}
|
|
2160
|
+
);
|
|
2161
|
+
|
|
2162
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2163
|
+
await Parse.User.loginAs<Parse.User<{ field: 'hello' }>>(user.id!);
|
|
2164
|
+
|
|
2165
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2166
|
+
await Parse.User.verifyPassword<Parse.User<{ field: 'hello' }>>('username', 'password');
|
|
2167
|
+
|
|
2168
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2169
|
+
await Parse.User.hydrate<Parse.User<{ field: 'hello' }>>(user);
|
|
2170
|
+
|
|
2171
|
+
// $ExpectType ParseUser<{ field: "hello"; }>
|
|
2172
|
+
await Parse.User.me<Parse.User<{ field: 'hello' }>>('session-token');
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
async function testAuthenticationProvider() {
|
|
2176
|
+
const authProvider: Parse.AuthProvider = {
|
|
2177
|
+
authenticate: () => {},
|
|
2178
|
+
getAuthType: () => 'customAuthorizationProvider',
|
|
2179
|
+
restoreAuthentication: () => false,
|
|
2180
|
+
deauthenticate: () => {},
|
|
2181
|
+
};
|
|
2182
|
+
const authData: Parse.AuthData = {
|
|
2183
|
+
id: 'some-user-authentication-id',
|
|
2184
|
+
access_token: 'some-access-token',
|
|
2185
|
+
expiration_date: new Date().toISOString(),
|
|
2186
|
+
};
|
|
2187
|
+
Parse.User._registerAuthenticationProvider(authProvider);
|
|
2188
|
+
|
|
2189
|
+
const user = await Parse.User.logInWith(
|
|
2190
|
+
authProvider,
|
|
2191
|
+
{ authData },
|
|
2192
|
+
{ sessionToken: 'some-session-token', useMasterKey: true }
|
|
2193
|
+
);
|
|
2194
|
+
const isLinked = user._isLinked(authProvider);
|
|
2195
|
+
const unlinkedUser = await user._unlinkFrom(authProvider);
|
|
2196
|
+
const linkedUser = await user.linkWith(authProvider, { authData });
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
function testEncryptingUser() {
|
|
2201
|
+
function testSecretKey() {
|
|
2202
|
+
Parse.secret = 'secret!';
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
function testEnableEncryptedUserKey() {
|
|
2206
|
+
Parse.encryptedUser = true;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
function testEnablingEncryptedUser() {
|
|
2210
|
+
Parse.enableEncryptedUser();
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
function testIsEncryptedUserEnabled() {
|
|
2214
|
+
Parse.isEncryptedUserEnabled();
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
function testEventuallyQueue() {
|
|
2219
|
+
async function test() {
|
|
2220
|
+
const obj = new Parse.Object('TestObject');
|
|
2221
|
+
// $ExpectType void
|
|
2222
|
+
await Parse.EventuallyQueue.clear();
|
|
2223
|
+
// $ExpectType Queue
|
|
2224
|
+
await Parse.EventuallyQueue.getQueue();
|
|
2225
|
+
// $ExpectType boolean
|
|
2226
|
+
Parse.EventuallyQueue.isPolling();
|
|
2227
|
+
// $ExpectType void
|
|
2228
|
+
await Parse.EventuallyQueue.save(obj);
|
|
2229
|
+
// $ExpectType void
|
|
2230
|
+
await Parse.EventuallyQueue.save(obj, {});
|
|
2231
|
+
// $ExpectType void
|
|
2232
|
+
await Parse.EventuallyQueue.destroy(obj);
|
|
2233
|
+
// $ExpectType void
|
|
2234
|
+
await Parse.EventuallyQueue.destroy(obj, {});
|
|
2235
|
+
// $ExpectType number
|
|
2236
|
+
await Parse.EventuallyQueue.length();
|
|
2237
|
+
// $ExpectType boolean
|
|
2238
|
+
await Parse.EventuallyQueue.sendQueue();
|
|
2239
|
+
// $ExpectType void
|
|
2240
|
+
Parse.EventuallyQueue.stopPoll();
|
|
2241
|
+
// $ExpectType void
|
|
2242
|
+
Parse.EventuallyQueue.poll();
|
|
2243
|
+
// $ExpectType void
|
|
2244
|
+
Parse.EventuallyQueue.poll(300);
|
|
2245
|
+
// $ExpectError
|
|
2246
|
+
Parse.EventuallyQueue.poll('300');
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
function LiveQueryEvents() {
|
|
2251
|
+
function testLiveQueryEvents() {
|
|
2252
|
+
Parse.LiveQuery.on('open', () => {});
|
|
2253
|
+
Parse.LiveQuery.on('close', () => {});
|
|
2254
|
+
Parse.LiveQuery.on('error', (error: any) => {});
|
|
2255
|
+
}
|
|
2256
|
+
}
|