Skip to content

Commit

Permalink
Fix Regression isar#977 - Web not registering DateTimeAdapter (isar#983)
Browse files Browse the repository at this point in the history
Regression was caused in isar#956 (4dbcd76) where `HiveImpl` no longer
called `_registerDefaultAdapters`, assuming that it would happen in
`init`, which is not necessary for web.

Also remove `HiveImpl.debug` and `HiveImpl.test`.

`HiveImpl.test` was masking some odd legacy behavior in tests, so this
fixes the test.
`HiveImpl.debug` is not used anywhere, and its funcationality can be
accomplished using `init`
  • Loading branch information
shroff authored May 27, 2022
1 parent ba3465b commit 579c341
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
14 changes: 1 addition & 13 deletions hive/lib/src/hive_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,10 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
String? homePath;

/// Not part of public API
HiveImpl();

/// Not part of public API
@visibleForTesting
HiveImpl.debug(this._managerOverride) {
HiveImpl() {
_registerDefaultAdapters();
}

/// Not part of public API
@visibleForTesting
HiveImpl.test() : _managerOverride = BackendManager.select() {
registerAdapter(DateTimeAdapter<DateTime>(), internal: true);
registerAdapter(BigIntAdapter(), internal: true);
}

/// either returns the preferred [BackendManagerInterface] or the
/// platform default fallback
BackendManagerInterface get _manager =>
Expand All @@ -67,7 +56,6 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
}) {
homePath = path;
_managerOverride = BackendManager.select(backendPreference);
_registerDefaultAdapters();
}

Future<BoxBase<E>> _openBox<E>(
Expand Down
2 changes: 1 addition & 1 deletion hive/test/integration/recovery_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Future _performTest(bool lazy) async {
framesSetLengthOffset(frames, frameBytes);

var dir = await getTempDir();
var hive = HiveImpl.test();
var hive = HiveImpl();
hive.init(dir.path);

for (var i = 0; i < bytes.length; i++) {
Expand Down
7 changes: 4 additions & 3 deletions hive/test/tests/frames.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:hive/hive.dart';
import 'package:hive/src/adapters/date_time_adapter.dart';
import 'package:hive/src/binary/binary_writer_impl.dart';
import 'package:hive/src/binary/frame.dart';
import 'package:hive/src/hive_impl.dart';
Expand All @@ -12,7 +13,7 @@ export '../generated/frame_values_encrypted.g.dart';
export '../generated/frames.g.dart';
export '../generated/frames_encrypted.g.dart';

TypeRegistry get testRegistry => HiveImpl.test();
TypeRegistry get testRegistry => HiveImpl();

class _HiveAesCipherStaticIV extends HiveAesCipher {
_HiveAesCipherStaticIV() : super(Uint8List.fromList(List.filled(32, 1)));
Expand Down Expand Up @@ -78,8 +79,8 @@ List<Frame> get testFrames => <Frame>[
'Map': {'Key': 'Val', 'Key2': 2}
}),
Frame('DateTime test', [
DateTime.fromMillisecondsSinceEpoch(0),
DateTime.fromMillisecondsSinceEpoch(1566656623020),
DateTimeWithoutTZ.fromMillisecondsSinceEpoch(0),
DateTimeWithoutTZ.fromMillisecondsSinceEpoch(1566656623020),
]),
Frame('BigInt Test',
BigInt.parse('1234567890123456789012345678901234567890'))
Expand Down

0 comments on commit 579c341

Please sign in to comment.