Skip to content

Commit 26b8698

Browse files
authored
refactor: Fix deprecations and other warnings (#810)
1 parent 60ca5a4 commit 26b8698

File tree

11 files changed

+111
-201
lines changed

11 files changed

+111
-201
lines changed

packages/dart/lib/src/network/parse_live_query.dart

+20-20
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Subscription<T extends ParseObject> {
3131
}
3232
}
3333

34-
enum LiveQueryClientEvent { CONNECTED, DISCONNECTED, USER_DISCONNECTED }
34+
enum LiveQueryClientEvent { connected, disconnected, userDisconnected }
3535

3636
class LiveQueryReconnectingController {
3737
LiveQueryReconnectingController(
@@ -50,16 +50,16 @@ class LiveQueryReconnectingController {
5050
}
5151
_eventStream.listen((LiveQueryClientEvent event) {
5252
switch (event) {
53-
case LiveQueryClientEvent.CONNECTED:
53+
case LiveQueryClientEvent.connected:
5454
_isConnected = true;
5555
_retryState = 0;
5656
_userDisconnected = false;
5757
break;
58-
case LiveQueryClientEvent.DISCONNECTED:
58+
case LiveQueryClientEvent.disconnected:
5959
_isConnected = false;
6060
_setReconnect();
6161
break;
62-
case LiveQueryClientEvent.USER_DISCONNECTED:
62+
case LiveQueryClientEvent.userDisconnected:
6363
_userDisconnected = true;
6464
Timer? currentTimer = _currentTimer;
6565
if (currentTimer != null) {
@@ -70,14 +70,14 @@ class LiveQueryReconnectingController {
7070
}
7171

7272
if (debug) {
73-
print('$DEBUG_TAG: $event');
73+
print('$debugTag: $event');
7474
}
7575
});
7676
ParseCoreData().appResumedStream?.listen((void _) => _setReconnect());
7777
}
7878

7979
static List<int> get retryInterval => ParseCoreData().liveListRetryIntervals;
80-
static const String DEBUG_TAG = 'LiveQueryReconnectingController';
80+
static const String debugTag = 'LiveQueryReconnectingController';
8181

8282
final Function _reconnect;
8383
final Stream<LiveQueryClientEvent> _eventStream;
@@ -99,7 +99,7 @@ class LiveQueryReconnectingController {
9999
_isConnected = false;
100100
}
101101
if (debug) {
102-
print('$DEBUG_TAG: $state');
102+
print('$debugTag: $state');
103103
}
104104
_setReconnect();
105105
}
@@ -116,7 +116,7 @@ class LiveQueryReconnectingController {
116116
_reconnect();
117117
});
118118
if (debug) {
119-
print('$DEBUG_TAG: Retrytimer set to ${retryInterval[_retryState]}ms');
119+
print('$debugTag: Retry timer set to ${retryInterval[_retryState]}ms');
120120
}
121121
if (_retryState < retryInterval.length - 1) {
122122
_retryState++;
@@ -188,13 +188,13 @@ class LiveQueryClient {
188188
if (webSocket != null) {
189189
return webSocket.readyState;
190190
}
191-
return parse_web_socket.WebSocket.CONNECTING;
191+
return parse_web_socket.WebSocket.connecting;
192192
}
193193

194194
Future<dynamic> disconnect({bool userInitialized = false}) async {
195195
parse_web_socket.WebSocket? webSocket = _webSocket;
196196
if (webSocket != null &&
197-
webSocket.readyState == parse_web_socket.WebSocket.OPEN) {
197+
webSocket.readyState == parse_web_socket.WebSocket.open) {
198198
if (_debug) {
199199
print('$_printConstLiveQuery: Socket closed');
200200
}
@@ -215,7 +215,7 @@ class LiveQueryClient {
215215
_connecting = false;
216216
if (userInitialized) {
217217
_clientEventStreamController.sink
218-
.add(LiveQueryClientEvent.USER_DISCONNECTED);
218+
.add(LiveQueryClientEvent.userDisconnected);
219219
}
220220
}
221221

@@ -224,7 +224,7 @@ class LiveQueryClient {
224224
{T? copyObject}) async {
225225
if (_webSocket == null) {
226226
await _clientEventStream.any((LiveQueryClientEvent event) =>
227-
event == LiveQueryClientEvent.CONNECTED);
227+
event == LiveQueryClientEvent.connected);
228228
}
229229
final int requestId = _requestIdGenerator();
230230
final Subscription<T> subscription =
@@ -272,7 +272,7 @@ class LiveQueryClient {
272272
await parse_web_socket.WebSocket.connect(_liveQueryURL);
273273
_webSocket = webSocket;
274274
_connecting = false;
275-
if (webSocket.readyState == parse_web_socket.WebSocket.OPEN) {
275+
if (webSocket.readyState == parse_web_socket.WebSocket.open) {
276276
if (_debug) {
277277
print('$_printConstLiveQuery: Socket opened');
278278
}
@@ -288,13 +288,13 @@ class LiveQueryClient {
288288
_handleMessage(message);
289289
}, onDone: () {
290290
_clientEventStreamController.sink
291-
.add(LiveQueryClientEvent.DISCONNECTED);
291+
.add(LiveQueryClientEvent.disconnected);
292292
if (_debug) {
293293
print('$_printConstLiveQuery: Done');
294294
}
295295
}, onError: (Object error) {
296296
_clientEventStreamController.sink
297-
.add(LiveQueryClientEvent.DISCONNECTED);
297+
.add(LiveQueryClientEvent.disconnected);
298298
if (_debug) {
299299
print(
300300
'$_printConstLiveQuery: Error: ${error.runtimeType.toString()}');
@@ -307,7 +307,7 @@ class LiveQueryClient {
307307
});
308308
} on Exception catch (e) {
309309
_connecting = false;
310-
_clientEventStreamController.sink.add(LiveQueryClientEvent.DISCONNECTED);
310+
_clientEventStreamController.sink.add(LiveQueryClientEvent.disconnected);
311311
if (_debug) {
312312
print('$_printConstLiveQuery: Error: ${e.toString()}');
313313
}
@@ -390,12 +390,12 @@ class LiveQueryClient {
390390

391391
Subscription? subscription;
392392
if (actionData.containsKey('op') && actionData['op'] == 'connected') {
393-
print('ReSubScription:$_requestSubscription');
393+
print('Re subscription:$_requestSubscription');
394394

395-
_requestSubscription.values.toList().forEach((Subscription subcription) {
396-
_subscribeLiveQuery(subcription);
395+
_requestSubscription.values.toList().forEach((Subscription subscription) {
396+
_subscribeLiveQuery(subscription);
397397
});
398-
_clientEventStreamController.sink.add(LiveQueryClientEvent.CONNECTED);
398+
_clientEventStreamController.sink.add(LiveQueryClientEvent.connected);
399399
return;
400400
}
401401
if (actionData.containsKey('requestId')) {

packages/dart/lib/src/network/parse_query.dart

+30-30
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class QueryBuilder<T extends ParseObject> {
1818
query += '{' + list[i].buildQueries(list[i].queries) + '}';
1919
}
2020
query += ']';
21-
queries.add(MapEntry<String, dynamic>(_NO_OPERATOR_NEEDED, query));
21+
queries.add(MapEntry<String, dynamic>(_noOperatorNeeded, query));
2222
}
2323

2424
factory QueryBuilder.copy(QueryBuilder<T> query) {
@@ -32,8 +32,8 @@ class QueryBuilder<T extends ParseObject> {
3232
return copy;
3333
}
3434

35-
static const String _NO_OPERATOR_NEEDED = 'NO_OP';
36-
static const String _SINGLE_QUERY = 'SINGLE_QUERY';
35+
static const String _noOperatorNeeded = 'NO_OP';
36+
static const String _singleQuery = 'SINGLE_QUERY';
3737

3838
T object;
3939
List<MapEntry<String, dynamic>> queries = <MapEntry<String, dynamic>>[];
@@ -103,10 +103,10 @@ class QueryBuilder<T extends ParseObject> {
103103
{bool caseSensitive = false}) {
104104
if (caseSensitive) {
105105
queries.add(MapEntry<String, dynamic>(
106-
_SINGLE_QUERY, '"$column":{"\$regex": "^$query"}'));
106+
_singleQuery, '"$column":{"\$regex": "^$query"}'));
107107
} else {
108108
queries.add(MapEntry<String, dynamic>(
109-
_SINGLE_QUERY, '"$column":{"\$regex": "^$query", "\$options": "i"}'));
109+
_singleQuery, '"$column":{"\$regex": "^$query", "\$options": "i"}'));
110110
}
111111
}
112112

@@ -115,17 +115,17 @@ class QueryBuilder<T extends ParseObject> {
115115
{bool caseSensitive = false}) {
116116
if (caseSensitive) {
117117
queries.add(MapEntry<String, dynamic>(
118-
_SINGLE_QUERY, '"$column":{"\$regex": "$query\$"}'));
118+
_singleQuery, '"$column":{"\$regex": "$query\$"}'));
119119
} else {
120-
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
121-
'"$column":{"\$regex": "$query\$", "\$options": "i"}'));
120+
queries.add(MapEntry<String, dynamic>(
121+
_singleQuery, '"$column":{"\$regex": "$query\$", "\$options": "i"}'));
122122
}
123123
}
124124

125125
/// Returns an object where the [String] column equals [value]
126126
void whereEqualTo(String column, dynamic value) {
127127
queries.add(_buildQueryWithColumnValueAndOperator(
128-
MapEntry<String, dynamic>(column, value), _NO_OPERATOR_NEEDED));
128+
MapEntry<String, dynamic>(column, value), _noOperatorNeeded));
129129
}
130130

131131
/// Returns an object where the [String] column contains a value less than
@@ -182,7 +182,7 @@ class QueryBuilder<T extends ParseObject> {
182182

183183
/// Retrieves related objets where [String] column is a relation field to the class [String] className
184184
void whereRelatedTo(String column, String className, String objectId) {
185-
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
185+
queries.add(MapEntry<String, dynamic>(_singleQuery,
186186
'"\$relatedTo":{"object":{"__type":"Pointer","className":"$className","objectId":"$objectId"},"key":"$column"}'));
187187
}
188188

@@ -216,20 +216,20 @@ class QueryBuilder<T extends ParseObject> {
216216
{bool caseSensitive = false}) {
217217
if (caseSensitive) {
218218
queries.add(MapEntry<String, dynamic>(
219-
_SINGLE_QUERY, '"$column":{"\$regex": "$value"}'));
219+
_singleQuery, '"$column":{"\$regex": "$value"}'));
220220
} else {
221221
queries.add(MapEntry<String, dynamic>(
222-
_SINGLE_QUERY, '"$column":{"\$regex": "$value", "\$options": "i"}'));
222+
_singleQuery, '"$column":{"\$regex": "$value", "\$options": "i"}'));
223223
}
224224
}
225225

226-
/// Powerful search for containing whole words. This search is much quicker than regex and can search for whole words including wether they are case sensitive or not.
226+
/// Powerful search for containing whole words. This search is much quicker than regex and can search for whole words including whether they are case sensitive or not.
227227
/// This search can also order by the score of the search
228228
void whereContainsWholeWord(String column, String query,
229229
{bool caseSensitive = false,
230230
bool orderByScore = true,
231231
bool diacriticSensitive = false}) {
232-
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
232+
queries.add(MapEntry<String, dynamic>(_singleQuery,
233233
'"$column":{"\$text":{"\$search":{"\$term": "$query", "\$caseSensitive": $caseSensitive , "\$diacriticSensitive": $diacriticSensitive }}}'));
234234
if (orderByScore) {
235235
orderByAscending('\$score');
@@ -241,7 +241,7 @@ class QueryBuilder<T extends ParseObject> {
241241
void whereNear(String column, ParseGeoPoint point) {
242242
final double latitude = point.latitude;
243243
final double longitude = point.longitude;
244-
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
244+
queries.add(MapEntry<String, dynamic>(_singleQuery,
245245
'"$column":{"\$nearSphere":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude}}'));
246246
}
247247

@@ -251,7 +251,7 @@ class QueryBuilder<T extends ParseObject> {
251251
final double latitude = point.latitude;
252252
final double longitude = point.longitude;
253253

254-
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
254+
queries.add(MapEntry<String, dynamic>(_singleQuery,
255255
'"$column":{"\$nearSphere":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude},"\$maxDistanceInMiles":$maxDistance}'));
256256
}
257257

@@ -261,7 +261,7 @@ class QueryBuilder<T extends ParseObject> {
261261
final double latitude = point.latitude;
262262
final double longitude = point.longitude;
263263

264-
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
264+
queries.add(MapEntry<String, dynamic>(_singleQuery,
265265
'"$column":{"\$nearSphere":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude},"\$maxDistanceInKilometers":$maxDistance}'));
266266
}
267267

@@ -271,7 +271,7 @@ class QueryBuilder<T extends ParseObject> {
271271
final double latitude = point.latitude;
272272
final double longitude = point.longitude;
273273

274-
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
274+
queries.add(MapEntry<String, dynamic>(_singleQuery,
275275
'"$column":{"\$nearSphere":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude},"\$maxDistanceInRadians":$maxDistance}'));
276276
}
277277

@@ -284,7 +284,7 @@ class QueryBuilder<T extends ParseObject> {
284284
final double latitudeN = northeast.latitude;
285285
final double longitudeN = northeast.longitude;
286286

287-
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
287+
queries.add(MapEntry<String, dynamic>(_singleQuery,
288288
'"$column":{"\$within":{"\$box": [{"__type": "GeoPoint","latitude":$latitudeS,"longitude":$longitudeS},{"__type": "GeoPoint","latitude":$latitudeN,"longitude":$longitudeN}]}}'));
289289
}
290290

@@ -299,7 +299,7 @@ class QueryBuilder<T extends ParseObject> {
299299
dictionary['\$polygon'] = points.map((e) => e.toJson()).toList();
300300

301301
queries.add(MapEntry<String, dynamic>(
302-
_SINGLE_QUERY, '"$column":{"\$geoWithin":${jsonEncode(dictionary)}}'));
302+
_singleQuery, '"$column":{"\$geoWithin":${jsonEncode(dictionary)}}'));
303303
}
304304

305305
/// Add a constraint to the query that requires a particular key's value match another QueryBuilder
@@ -309,7 +309,7 @@ class QueryBuilder<T extends ParseObject> {
309309
query._buildQueryRelational(query.object.parseClassName);
310310

311311
queries.add(MapEntry<String, dynamic>(
312-
_SINGLE_QUERY, '"$column":{"\$inQuery":$inQuery}'));
312+
_singleQuery, '"$column":{"\$inQuery":$inQuery}'));
313313
}
314314

315315
///Add a constraint to the query that requires a particular key's value does not match another QueryBuilder
@@ -319,7 +319,7 @@ class QueryBuilder<T extends ParseObject> {
319319
query._buildQueryRelational(query.object.parseClassName);
320320

321321
queries.add(MapEntry<String, dynamic>(
322-
_SINGLE_QUERY, '"$column":{"\$notInQuery":$inQuery}'));
322+
_singleQuery, '"$column":{"\$notInQuery":$inQuery}'));
323323
}
324324

325325
/// Add a constraint to the query that requires a particular key's value matches a value for a key in the results of another ParseQuery.
@@ -339,7 +339,7 @@ class QueryBuilder<T extends ParseObject> {
339339
query._buildQueryRelationalKey(query.object.parseClassName, keyInQuery);
340340

341341
queries.add(MapEntry<String, dynamic>(
342-
_SINGLE_QUERY, '"$column":{"\$select":$inQuery}'));
342+
_singleQuery, '"$column":{"\$select":$inQuery}'));
343343
}
344344

345345
/// Add a constraint to the query that requires a particular key's value does not match any value for a key in the results of another ParseQuery
@@ -359,7 +359,7 @@ class QueryBuilder<T extends ParseObject> {
359359
query._buildQueryRelationalKey(query.object.parseClassName, keyInQuery);
360360

361361
queries.add(MapEntry<String, dynamic>(
362-
_SINGLE_QUERY, '"$column":{"\$dontSelect":$inQuery}'));
362+
_singleQuery, '"$column":{"\$dontSelect":$inQuery}'));
363363
}
364364

365365
/// Finishes the query and calls the server
@@ -445,9 +445,9 @@ class QueryBuilder<T extends ParseObject> {
445445
final dynamic value =
446446
convertValueToCorrectType(parseEncode(columnAndValue.value));
447447

448-
if (queryOperator == _NO_OPERATOR_NEEDED) {
448+
if (queryOperator == _noOperatorNeeded) {
449449
return MapEntry<String, dynamic>(
450-
_NO_OPERATOR_NEEDED, '"$key": ${jsonEncode(value)}');
450+
_noOperatorNeeded, '"$key": ${jsonEncode(value)}');
451451
} else {
452452
String queryString = '"$key":';
453453
final Map<String, dynamic> queryOperatorAndValueMap = <String, dynamic>{};
@@ -470,15 +470,15 @@ class QueryBuilder<T extends ParseObject> {
470470
// Run through each query
471471
for (final MapEntry<String, dynamic> query in queries) {
472472
// Add queries that don't need sanitizing
473-
if (query.key == _NO_OPERATOR_NEEDED || query.key == _SINGLE_QUERY) {
473+
if (query.key == _noOperatorNeeded || query.key == _singleQuery) {
474474
sanitizedQueries
475-
.add(MapEntry<String, dynamic>(_NO_OPERATOR_NEEDED, query.value));
475+
.add(MapEntry<String, dynamic>(_noOperatorNeeded, query.value));
476476
}
477477

478478
// Check if query with same column name has been sanitized
479479
if (!keysAlreadyCompacted.contains(query.key) &&
480-
query.key != _NO_OPERATOR_NEEDED &&
481-
query.key != _SINGLE_QUERY) {
480+
query.key != _noOperatorNeeded &&
481+
query.key != _singleQuery) {
482482
// If not, check that it now has
483483
keysAlreadyCompacted.add(query.key);
484484

packages/dart/lib/src/network/parse_websocket_html.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import 'package:web_socket_channel/web_socket_channel.dart';
88
class WebSocket {
99
WebSocket._(this._webSocket);
1010

11-
static const int CONNECTING = 0;
12-
static const int OPEN = 1;
13-
static const int CLOSING = 2;
14-
static const int CLOSED = 3;
11+
static const int connecting = 0;
12+
static const int open = 1;
13+
static const int closing = 2;
14+
static const int closed = 3;
1515

1616
final html.WebSocket _webSocket;
1717

packages/dart/lib/src/network/parse_websocket_io.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import 'package:web_socket_channel/web_socket_channel.dart';
88
class WebSocket {
99
WebSocket._(this._webSocket);
1010

11-
static const int CONNECTING = 0;
12-
static const int OPEN = 1;
13-
static const int CLOSING = 2;
14-
static const int CLOSED = 3;
11+
static const int connecting = 0;
12+
static const int open = 1;
13+
static const int closing = 2;
14+
static const int closed = 3;
1515

1616
final io.WebSocket _webSocket;
1717

0 commit comments

Comments
 (0)