@@ -21,7 +21,7 @@ class BucketStorage {
2121 _init ();
2222 }
2323
24- _init () {}
24+ void _init () {}
2525
2626 // Use only for read statements
2727 Future <ResultSet > select (String query,
@@ -36,7 +36,8 @@ class BucketStorage {
3636 'SELECT name as bucket, cast(last_op as TEXT) as op_id FROM ps_buckets WHERE pending_delete = 0 AND name != \'\$ local\' ' );
3737 return [
3838 for (var row in rows)
39- BucketState (bucket: row['bucket' ], opId: row['op_id' ])
39+ BucketState (
40+ bucket: row['bucket' ] as String , opId: row['op_id' ] as String )
4041 ];
4142 }
4243
@@ -157,14 +158,16 @@ class BucketStorage {
157158 Checkpoint checkpoint) async {
158159 final rs = await select ("SELECT powersync_validate_checkpoint(?) as result" ,
159160 [jsonEncode (checkpoint)]);
160- final result = jsonDecode (rs[0 ]['result' ]);
161- if (result['valid' ]) {
161+ final result =
162+ jsonDecode (rs[0 ]['result' ] as String ) as Map <String , dynamic >;
163+ if (result['valid' ] as bool ) {
162164 return SyncLocalDatabaseResult (ready: true );
163165 } else {
164166 return SyncLocalDatabaseResult (
165167 checkpointValid: false ,
166168 ready: false ,
167- checkpointFailures: result['failed_buckets' ].cast <String >());
169+ checkpointFailures:
170+ (result['failed_buckets' ] as List ).cast <String >());
168171 }
169172 }
170173
@@ -232,7 +235,7 @@ class BucketStorage {
232235 // Nothing to update
233236 return false ;
234237 }
235- int seqBefore = rs.first['seq' ];
238+ int seqBefore = rs.first['seq' ] as int ;
236239 var opId = await checkpointCallback ();
237240
238241 return await writeTransaction ((tx) async {
@@ -244,7 +247,7 @@ class BucketStorage {
244247 .execute ('SELECT seq FROM sqlite_sequence WHERE name = \' ps_crud\' ' );
245248 assert (rs.isNotEmpty);
246249
247- int seqAfter = rs.first['seq' ];
250+ int seqAfter = rs.first['seq' ] as int ;
248251 if (seqAfter != seqBefore) {
249252 // New crud data may have been uploaded since we got the checkpoint. Abort.
250253 return false ;
@@ -362,12 +365,13 @@ class SyncBucketData {
362365 this .nextAfter});
363366
364367 SyncBucketData .fromJson (Map <String , dynamic > json)
365- : bucket = json['bucket' ],
366- hasMore = json['has_more' ] ?? false ,
367- after = json['after' ],
368- nextAfter = json['next_after' ],
369- data =
370- (json['data' ] as List ).map ((e) => OplogEntry .fromJson (e)).toList ();
368+ : bucket = json['bucket' ] as String ,
369+ hasMore = json['has_more' ] as bool ? ?? false ,
370+ after = json['after' ] as String ? ,
371+ nextAfter = json['next_after' ] as String ? ,
372+ data = (json['data' ] as List )
373+ .map ((e) => OplogEntry .fromJson (e as Map <String , dynamic >))
374+ .toList ();
371375
372376 Map <String , dynamic > toJson () {
373377 return {
@@ -407,16 +411,25 @@ class OplogEntry {
407411 required this .checksum});
408412
409413 OplogEntry .fromJson (Map <String , dynamic > json)
410- : opId = json['op_id' ],
411- op = OpType .fromJson (json['op' ]),
412- rowType = json['object_type' ],
413- rowId = json['object_id' ],
414- checksum = json['checksum' ],
415- data = json['data' ] is String ? json['data' ] : jsonEncode (json['data' ]),
416- subkey = json['subkey' ] is String ? json['subkey' ] : null ;
414+ : opId = json['op_id' ] as String ,
415+ op = OpType .fromJson (json['op' ] as String ),
416+ rowType = json['object_type' ] as String ? ,
417+ rowId = json['object_id' ] as String ? ,
418+ checksum = json['checksum' ] as int ,
419+ data = switch (json['data' ]) {
420+ String data => data,
421+ var other => jsonEncode (other),
422+ },
423+ subkey = switch (json['subkey' ]) {
424+ String subkey => subkey,
425+ _ => null ,
426+ };
417427
418428 Map <String , dynamic >? get parsedData {
419- return data == null ? null : jsonDecode (data! );
429+ return switch (data) {
430+ final data? => jsonDecode (data) as Map <String , dynamic >,
431+ null => null ,
432+ };
420433 }
421434
422435 /// Key to uniquely represent a source entry in a bucket.
@@ -463,16 +476,16 @@ class SyncLocalDatabaseResult {
463476
464477 @override
465478 int get hashCode {
466- return Object .hash (
467- ready, checkpointValid, const ListEquality ().hash (checkpointFailures));
479+ return Object .hash (ready, checkpointValid,
480+ const ListEquality < String ?> ().hash (checkpointFailures));
468481 }
469482
470483 @override
471484 bool operator == (Object other) {
472485 return other is SyncLocalDatabaseResult &&
473486 other.ready == ready &&
474487 other.checkpointValid == checkpointValid &&
475- const ListEquality ()
488+ const ListEquality < String ?> ()
476489 .equals (other.checkpointFailures, checkpointFailures);
477490 }
478491}
0 commit comments