Skip to content

Commit

Permalink
Merge branch 'main' into feature/simplify-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexios80 authored Sep 18, 2024
2 parents d3e0b1d + e20da05 commit 9649818
Show file tree
Hide file tree
Showing 36 changed files with 54 additions and 60 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: ${{ matrix.flutter-channel }}
# TODO: Use custom_lint from hosted when https://github.com/invertase/dart_custom_lint/pull/272 lands
- run: |
dart pub global activate puby
dart pub global activate -sgit https://github.com/Rexios80/dart_custom_lint --git-ref f62fe2e1dc03162d1bb55dbba7e6b37bc08d81a1 --git-path packages/custom_lint
puby link
dart format . --set-exit-if-changed
dart analyze --fatal-infos
custom_lint
test-hive:
runs-on: ubuntu-latest
Expand All @@ -45,8 +48,6 @@ jobs:
- uses: actions/checkout@v4
- uses: browser-actions/setup-chrome@v1
- uses: dart-lang/setup-dart@v1
with:
sdk: 3.4.0
- name: Install dependencies
run: dart pub get
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion hive/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:rexios_lints/dart/package.yaml
include: package:rexios_lints/dart/package_extra.yaml
2 changes: 1 addition & 1 deletion hive/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:rexios_lints/dart/core.yaml
include: package:rexios_lints/dart/core_extra.yaml
4 changes: 2 additions & 2 deletions hive/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies:
hive_ce: any

dev_dependencies:
rexios_lints: ^7.0.0
rexios_lints: ^8.2.0
hive_ce_generator: any
build_runner: any

Expand All @@ -15,4 +15,4 @@ dependency_overrides:
hive_ce:
path: ../
hive_ce_generator:
path: ../../hive_generator
path: ../../hive_generator
5 changes: 0 additions & 5 deletions hive/lib/src/backend/js/native/backend_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class BackendManager implements BackendManagerInterface {
final objectStoreName = collection == null ? 'box' : name;

final request = indexedDB!.open(databaseName, 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent e) {
final db = (e.target as IDBOpenDBRequest).result as IDBDatabase;
if (!db.objectStoreNames.contains(objectStoreName)) {
Expand All @@ -40,7 +39,6 @@ class BackendManager implements BackendManagerInterface {
'Creating objectStore $objectStoreName in database $databaseName...',
);
final request = indexedDB!.open(databaseName, db.version + 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent e) {
final db = (e.target as IDBOpenDBRequest).result as IDBDatabase;
if (!db.objectStoreNames.contains(objectStoreName)) {
Expand Down Expand Up @@ -68,7 +66,6 @@ class BackendManager implements BackendManagerInterface {
await indexedDB!.deleteDatabase(databaseName).asFuture();
} else {
final request = indexedDB!.open(databaseName, 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent e) {
final db = (e.target as IDBOpenDBRequest).result as IDBDatabase;
if (db.objectStoreNames.contains(objectStoreName)) {
Expand All @@ -92,15 +89,13 @@ class BackendManager implements BackendManagerInterface {
var exists = true;
if (collection == null) {
final request = indexedDB!.open(databaseName, 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent e) {
(e.target as IDBOpenDBRequest).transaction!.abort();
exists = false;
}.toJS;
await request.asFuture();
} else {
final request = indexedDB!.open(collection, 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent e) {
final db = (e.target as IDBOpenDBRequest).result as IDBDatabase;
exists = db.objectStoreNames.contains(objectStoreName);
Expand Down
1 change: 0 additions & 1 deletion hive/lib/src/backend/js/native/storage_backend_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class StorageBackendJs extends StorageBackend {
await indexDB.deleteDatabase(_db.name).asFuture();
} else {
final request = indexDB.open(_db.name, 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent e) {
final db = (e.target as IDBOpenDBRequest).result as IDBDatabase;
if (db.objectStoreNames.contains(objectStoreName)) {
Expand Down
4 changes: 0 additions & 4 deletions hive/lib/src/backend/js/native/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ extension IDBRequestExtension on IDBRequest {
/// TODO: Document this!
Future<T> asFuture<T extends JSAny?>() {
final completer = Completer<T>();
// ignore: avoid_types_on_closure_parameters
onsuccess = (Event e) {
completer.complete(result as T);
}.toJS;
// ignore: avoid_types_on_closure_parameters
onerror = (Event e) {
completer.completeError(error!);
}.toJS;
Expand All @@ -26,7 +24,6 @@ extension IDBObjectStoreExtension on IDBObjectStore {
Stream<IDBCursorWithValue> iterate() {
final controller = StreamController<IDBCursorWithValue>();
final request = openCursor();
// ignore: avoid_types_on_closure_parameters
request.onsuccess = (Event e) {
final cursor = (e.target as IDBRequest).result as IDBCursorWithValue?;
if (cursor == null) {
Expand All @@ -36,7 +33,6 @@ extension IDBObjectStoreExtension on IDBObjectStore {
controller.add(cursor);
cursor.continue_();
}.toJS;
// ignore: avoid_types_on_closure_parameters
request.onerror = (Event e) {
controller.addError(request.error!);
}.toJS;
Expand Down
24 changes: 13 additions & 11 deletions hive/lib/src/backend/vm/read_write_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,39 @@ class ReadWriteSync {
Future _writeTask = Future.value();

/// Run operation with read lock
Future<T> syncRead<T>(Future<T> Function() task) {
Future<T> syncRead<T>(Future<T> Function() task) async {
final previousTask = _readTask;

final completer = Completer();
final completer = Completer<void>();
_readTask = completer.future;

return previousTask.then((_) => task()).whenComplete(completer.complete);
await previousTask;
return task().whenComplete(completer.complete);
}

/// Run operation with write lock
Future<T> syncWrite<T>(Future<T> Function() task) {
Future<T> syncWrite<T>(Future<T> Function() task) async {
final previousTask = _writeTask;

final completer = Completer();
final completer = Completer<void>();
_writeTask = completer.future;

return previousTask.then((_) => task()).whenComplete(completer.complete);
await previousTask;
return task().whenComplete(completer.complete);
}

/// Run operation with read and write lock
Future<T> syncReadWrite<T>(FutureOr<T> Function() task) {
Future<T> syncReadWrite<T>(Future<T> Function() task) async {
final previousReadTask = _readTask;
final previousWriteTask = _writeTask;

final completer = Completer();
final completer = Completer<void>();
final future = completer.future;
_readTask = future;
_writeTask = future;

return previousReadTask.then((_) {
return previousWriteTask.then((_) => task());
}).whenComplete(completer.complete);
await previousReadTask;
await previousWriteTask;
return task().whenComplete(completer.complete);
}
}
3 changes: 0 additions & 3 deletions hive/lib/src/box/keystore.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// ignore_for_file: invalid_use_of_protected_member
// ignore_for_file: invalid_use_of_visible_for_testing_member

import 'dart:collection';

import 'package:hive_ce/hive.dart';
Expand Down
3 changes: 0 additions & 3 deletions hive/lib/src/box/lazy_box_impl.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// ignore_for_file: invalid_use_of_protected_member
// ignore_for_file: invalid_use_of_visible_for_testing_member

import 'package:hive_ce/hive.dart';
import 'package:hive_ce/src/binary/frame.dart';
import 'package:hive_ce/src/box/box_base_impl.dart';
Expand Down
6 changes: 2 additions & 4 deletions hive/lib/src/box_collection/box_collection_indexed_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class BoxCollection implements implementation.BoxCollection {
HiveCipher? key,
}) async {
final request = window.self.indexedDB.open(name, 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent event) {
final db = (event.target as IDBOpenDBRequest).result as IDBDatabase;
for (final name in boxNames) {
Expand Down Expand Up @@ -94,7 +93,6 @@ class BoxCollection implements implementation.BoxCollection {
unawaited(fun(txn));
}
final completer = Completer<void>();
// ignore: avoid_types_on_closure_parameters
txn.oncomplete = (Event e) {
completer.complete();
}.toJS;
Expand Down Expand Up @@ -180,8 +178,8 @@ class CollectionBox<V> implements implementation.CollectionBox<V> {
@override
Future<void> put(String key, V val, [Object? transaction]) async {
IDBTransaction? txn;
if (transaction is IDBTransaction) {
txn = transaction;
if ((transaction as JSAny?).isA<IDBTransaction>()) {
txn = transaction as IDBTransaction;
}
if (val == null) {
return delete(key, txn);
Expand Down
3 changes: 1 addition & 2 deletions hive/lib/src/hive_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
completer.completeError(error, stackTrace);
rethrow;
} finally {
// ignore: unawaited_futures
_openingBoxes.remove(name);
unawaited(_openingBoxes.remove(name));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion hive/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
dev_dependencies:
test: ^1.17.12
mocktail: ^1.0.4
rexios_lints: ^7.0.0
rexios_lints: ^8.2.0
path: ^1.7.0
pointycastle: ^3.4.0
build_runner: ^2.1.2
2 changes: 1 addition & 1 deletion hive/test/integration/date_time_adapter_upgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {
});

test('uses DateTimeWithTimeZoneAdapter for writing new values', () {
final result = registry.findAdapterForValue(DateTime.now())!;
final result = registry.findAdapterForValue(DateTime.timestamp())!;
expect(result, isNotNull);
expect(result.adapter, isA<DateTimeWithTimezoneAdapter>());
});
Expand Down
2 changes: 2 additions & 0 deletions hive/test/tests/adapters/date_time_adapter_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// This is a test
// ignore_for_file: prefer_timestamps
import 'package:hive_ce/src/adapters/date_time_adapter.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
Expand Down
4 changes: 2 additions & 2 deletions hive/test/tests/backend/js/backend_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:web/web.dart';

Future<IDBDatabase> _openDb() {
final request = window.self.indexedDB.open('testBox', 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent e) {
final db = (e.target as IDBOpenDBRequest).result as IDBDatabase;
if (!db.objectStoreNames.contains('box')) {
Expand All @@ -32,7 +31,8 @@ void main() {

test('returns false', () async {
final backendManager = BackendManager.select();
final boxName = 'notexists-${DateTime.now().millisecondsSinceEpoch}';
final boxName =
'notexists-${DateTime.timestamp().millisecondsSinceEpoch}';
expect(await backendManager.boxExists(boxName, null, null), isFalse);
});
});
Expand Down
1 change: 0 additions & 1 deletion hive/test/tests/backend/js/storage_backend_js_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ StorageBackendJs _getBackend({

Future<IDBDatabase> _openDb([String name = 'testBox']) async {
final request = window.self.indexedDB.open(name, 1);
// ignore: avoid_types_on_closure_parameters
request.onupgradeneeded = (IDBVersionChangeEvent e) {
final db = (e.target as IDBOpenDBRequest).result as IDBDatabase;
if (!db.objectStoreNames.contains('box')) {
Expand Down
6 changes: 3 additions & 3 deletions hive/test/tests/backend/vm/read_write_sync_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Future _asyncRead(
history.add('startread$id');
await Future.delayed(Duration(milliseconds: 10));
if (throwError!) {
throw 'error$id'; // ignore: only_throw_errors
throw 'error$id';
}
history.add('stopread$id');
});
Expand All @@ -27,7 +27,7 @@ Future _asyncWrite(
history.add('startwrite$id');
await Future.delayed(Duration(milliseconds: 10));
if (throwError!) {
throw 'error$id'; // ignore: only_throw_errors
throw 'error$id';
}
history.add('stopwrite$id');
});
Expand All @@ -43,7 +43,7 @@ Future _asyncReadWrite(
history.add('startreadwrite$id');
await Future.delayed(Duration(milliseconds: 10));
if (throwError!) {
throw 'error$id'; // ignore: only_throw_errors
throw 'error$id';
}
history.add('stopreadwrite$id');
});
Expand Down
2 changes: 2 additions & 0 deletions hive/test/tests/backend/vm/storage_backend_vm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ void main() {

group('StorageBackendVm', () {
test('.path returns path for of open box file', () {
// This is a test
// ignore: do_not_use_raw_paths
final file = File('some/path');
final backend = _getBackend(file: file);
expect(backend.path, 'some/path');
Expand Down
4 changes: 3 additions & 1 deletion hive/test/tests/hive_impl_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// This is a test
// ignore_for_file: prefer_async_await
@TestOn('vm')
library;

Expand Down Expand Up @@ -39,7 +41,7 @@ void main() {
expect(hive.homePath, 'MYPATH');

expect(
hive.findAdapterForValue(DateTime.now())!.adapter,
hive.findAdapterForValue(DateTime.timestamp())!.adapter,
isA<DateTimeWithTimezoneAdapter>(),
);
expect(hive.findAdapterForTypeId(16)!.adapter, isA<DateTimeAdapter>());
Expand Down
2 changes: 1 addition & 1 deletion hive_flutter/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:rexios_lints/flutter/package.yaml
include: package:rexios_lints/flutter/package_extra.yaml
2 changes: 1 addition & 1 deletion hive_flutter/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:rexios_lints/flutter/core.yaml
include: package:rexios_lints/flutter/core_extra.yaml
2 changes: 1 addition & 1 deletion hive_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
path: ../../hive_flutter

dev_dependencies:
rexios_lints: ^7.0.0
rexios_lints: ^8.2.0
build_runner: ^2.4.0
hive_ce_generator:
path: ../../hive_generator
Expand Down
2 changes: 2 additions & 0 deletions hive_flutter/lib/src/adapters/color_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ColorAdapter extends TypeAdapter<Color> {
Color read(BinaryReader reader) => Color(reader.readInt());

@override
// TODO: Merge https://github.com/IO-Design-Team/hive_ce/pull/27 when Flutter 3.26 lands
// ignore: deprecated_member_use
void write(BinaryWriter writer, Color obj) => writer.writeInt(obj.value);

@override
Expand Down
1 change: 0 additions & 1 deletion hive_flutter/lib/src/watch_box_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class _WatchBoxBuilderState extends State<WatchBoxBuilder> {
}

@override
// ignore: deprecated_member_use
void didUpdateWidget(WatchBoxBuilder oldWidget) {
super.didUpdateWidget(oldWidget);

Expand Down
2 changes: 1 addition & 1 deletion hive_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ dependencies:

dev_dependencies:
test: ^1.21.1
rexios_lints: ^7.0.0
rexios_lints: ^8.2.0
mockito: ^5.4.1
build_runner: ^2.1.11
3 changes: 3 additions & 0 deletions hive_flutter/test/adapters/color_adapter_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// TODO: Remove with https://github.com/IO-Design-Team/hive_ce/pull/27
// ignore_for_file: deprecated_member_use

import 'dart:ui' show Color;

import 'package:hive_ce_flutter/adapters.dart';
Expand Down
1 change: 1 addition & 0 deletions hive_flutter/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export 'mocks.mocks.dart';
MockSpec<BinaryWriter>(onMissingStub: OnMissingStub.returnDefault),
],
)
// This is for mock generation
// ignore: prefer_typing_uninitialized_variables, unused_element
var _mocks;
2 changes: 1 addition & 1 deletion hive_generator/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:rexios_lints/dart/package.yaml
include: package:rexios_lints/dart/package_extra.yaml
2 changes: 1 addition & 1 deletion hive_generator/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:rexios_lints/dart/core.yaml
include: package:rexios_lints/dart/core_extra.yaml
1 change: 1 addition & 0 deletions hive_generator/example/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ targets:
- unnecessary_const
- require_trailing_commas
- unnecessary_breaks
- document_ignores
2 changes: 1 addition & 1 deletion hive_generator/example/lib/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ConstructorDefaults {
this.b = '42',
this.c = true,
DateTime? d,
}) : d = d ?? DateTime.now();
}) : d = d ?? DateTime.timestamp();

@HiveField(0)
final int a;
Expand Down
Loading

0 comments on commit 9649818

Please sign in to comment.