Skip to content

Commit

Permalink
feat(b-altoke-local-database): brick creation (#397)
Browse files Browse the repository at this point in the history
* feat(b-altoke-local-database): Create interface reference

* feat(b-altoke-local-database): create implementation on top of Drift

* feat(b-altoke-local-database): create implementation on top of Isar

* feat(t-local-database-alternative): create local DB alternative helper

* feat(b-altoke-local-database): brick setup

* chore(b-altoke-local-database): base scope setup

* docs(b-altoke-local-database): update READMEs

* refactor(b-altoke-local-database): drop unnecessary refs prefix

* chore(b-altoke-local-database): ignore generated files

* refactor(b-altoke-local-database): drop unnecessary refs prefix

* feat(b-altoke-local-database): use latest version of Drift

* chore(b-altoke-app): update deps for internal example

* chore(b-altoke-app): internal local DB example

* fix(b-altoke-app): use compatible version of `collection`

* fix(b-altoke-app): ignore tasks internal example for brick

* feat(b-altoke-app): more flexible code gen setup

* chore(b-altoke-local-database): create brick

* chore: source gen

* chore: source gen

* fix(b-altoke-database): proper data validity check

* build(b-altoke-database): add `meta` dep

* feat(b-altoke-database): task as data class

* fix(b-altoke-database): drop const constructor for testing

* test(b-altoke-database): add testing

* fix(b-altoke-database): store trimmed description

* feat(b-altoke-local-database): add Hive-based implementation

* docs(b-altoke-local-database): add Hive support details

* test(b-altoke-local-database): fix Hive tests

* test(b-altoke-local-database): ensure test coverage

* docs(b-altoke-local-database): update Hive support details

* test(b-altoke-local-database): ensure test coverage

* feat(b-altoke-local-database): Sembast implementation

* ci: install SQLite on Windows

* chore: update local spellcheck setup

* chore: locate SQLite DLL

* chore: locate SQLite DLL

* ci: temporary remove Windows from testing OSs

* ci: ignore tests related to SQLite on Windows

* ci: ignore tests related to SQLite on Windows

* ci: ignore tests related to SQLite on Windows and log setup

* ci: use proper steps order

* chore: update template

* chore: update templates

* chore: update templates

* fix(b-altoke-app): ignore tasks internal example for brick

* chore: cover TODOs

* fix(b-altoke-local-database): fix template replacements

* fix(b-altoke-local-database): use proper target dirs

* chore(t-monorepo-elements): register local database brick

* chore: use latest local DB alternatives

* test(b-altoke-local-database): add E2E tests
  • Loading branch information
mrverdant13 authored Nov 25, 2024
1 parent a0d3502 commit 4de6d7d
Show file tree
Hide file tree
Showing 202 changed files with 10,486 additions and 93 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cspell:ignore longpaths
# cspell:ignore choco,longpaths
name: ci

on:
Expand Down Expand Up @@ -57,6 +57,13 @@ jobs:
git config --system core.longpaths true
- name: Check out repository
uses: actions/checkout@v4
- name: Ignore tests related to SQLite on Windows
if: matrix.os == 'windows-latest'
run: |
echo "ignore:
- '**/*drift*'
" >> ./melos_overrides.yaml
type ./melos_overrides.yaml
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ Create an entity, **_al toque_** (_quickly_).
- **Testing:**\
Tests with 100% coverage.

### 🧱 Altoke Local Database

Create a local database, **_al toque_** (_quickly_).

#### Features

- **Data persistence:**\
Supported with one of the following alternatives:
- [`drift` (SQLite)][pub_package_drift]
- [`hive`][pub_package_hive]
- [`isar`][pub_package_isar]
- [`sembast`][pub_package_sembast]

- **Strict lint rules:**\
Enforced by [`very_good_analysis`][pub_package_very_good_analysis] for [native Dart & Flutter rules][docs_dart_and_flutter_linter_rules_link].

- **Testing:**\
Tests with 100% coverage.

### 🧱 Altoke Reactive Caches

Create a package that provides general-purpose caches, **_al toque_** (_quickly_).
Expand Down Expand Up @@ -186,10 +205,10 @@ Create a storage, **_al toque_** (_quickly_).
[pub_package_dart_mappable]: https://pub.dev/packages/dart_mappable
[pub_package_equatable]: https://pub.dev/packages/equatable
[pub_package_freezed]: https://pub.dev/packages/freezed
[pub_package_drift]: https://pub.dev/packages/drift
[pub_package_hive]: https://pub.dev/packages/hive
[pub_package_isar]: https://pub.dev/packages/isar
[pub_package_sembast]: https://pub.dev/packages/sembast
[pub_package_drift]: https://pub.dev/packages/drift
<!-- BRICK LINKS -->

<!-- EDITABLE -->
Expand Down
20 changes: 20 additions & 0 deletions bricks/altoke_app/brick-gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,25 @@
"from": "An Altoke App.",
"to": "{{projectDescription}}"
}
],
"lineDeletions": [
{
"filePath": "brick/__brick__/{{projectName.snakeCase()}}/packages/app/lib/l10n/arb/app_en.arb",
"ranges": [
{
"start": 51,
"end": 158
}
]
},
{
"filePath": "brick/__brick__/{{projectName.snakeCase()}}/packages/app/lib/l10n/arb/app_es.arb",
"ranges": [
{
"start": 51,
"end": 158
}
]
}
]
}
2 changes: 2 additions & 0 deletions bricks/altoke_app/brick/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Generated source files
/**/__brick__/**/*.gr.dart
/**/__brick__/**/*.g.dart
/**/__brick__/**/external/**
/**/__brick__/**/tasks/**
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ targets:
provider_name_suffix: Pod
provider_family_name_suffix: Pod
generate_for:
- lib/**/state/**_pod.dart
- lib/**/**_pod.dart
- lib/**/**_pods.dart
- lib/**/pod.dart
- lib/**/pods.dart
- lib/routing/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ AND the initialization process is completed
THEN the initialized app should be shown
''',
(tester) async {
await tester.pumpWidget(const
ProviderScope(child:MyApp(),
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith((_) async {}),
],
child: const MyApp(),
),
);
expect(find.byType(AppInitializing), findsOneWidget);
Expand All @@ -34,8 +38,8 @@ THEN the uninitialized errored app should be shown
├─ THAT allows the user to retry the initialization process
''',
(tester) async {
await tester.pumpWidget(const
ProviderScope(
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith(
(ref) async {
Expand All @@ -44,8 +48,9 @@ ProviderScope(
throw Exception('error');
}
},
),],
child:MyApp(),
),
],
child: const MyApp(),
),
);
expect(find.byType(AppInitializing), findsOneWidget);
Expand All @@ -68,8 +73,12 @@ WHEN the app is built
THEN the counter screen should be shown
''',
(tester) async {
await tester.pumpWidget(const
ProviderScope(child:MyApp(),
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith((_) async {}),
],
child: const MyApp(),
),
);
await tester.pumpAndSettle();
Expand All @@ -85,8 +94,12 @@ AND the initialization process is completed
THEN the initialized app should be shown
''',
(tester) async {
await tester.pumpWidget(const
ProviderScope(child:MyApp(),
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith((_) async {}),
],
child: const MyApp(),
),
);
expect(find.byType(AppInitializing), findsOneWidget);
Expand All @@ -105,8 +118,8 @@ THEN the uninitialized errored app should be shown
├─ THAT allows the user to retry the initialization process
''',
(tester) async {
await tester.pumpWidget(const
ProviderScope(
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith(
(ref) async {
Expand All @@ -115,8 +128,9 @@ ProviderScope(
throw Exception('error');
}
},
),],
child:MyApp(),
),
],
child: const MyApp(),
),
);
expect(find.byType(AppInitializing), findsOneWidget);
Expand All @@ -139,8 +153,12 @@ WHEN the app is built
THEN the counter screen should be shown
''',
(tester) async {
await tester.pumpWidget(const
ProviderScope(child:MyApp(),
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith((_) async {}),
],
child: const MyApp(),
),
);
await tester.pumpAndSettle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ THEN the home screen should be shown
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith((_) async {}),
routerConfigPod.overrideWithValue(
AppRouter().config(
// ignore: use_named_constants
Expand All @@ -39,6 +40,7 @@ THEN the home screen should be shown
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith((_) async {}),
routerConfigPod.overrideWithValue(
GoRouter(
routes: $appRoutes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ THEN the counter screen should be shown
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith((_) async {}),
routerConfigPod.overrideWithValue(
AppRouter().config(
deepLinkBuilder: (_) => const DeepLink.path('/counter'),
Expand All @@ -38,6 +39,7 @@ THEN the counter screen should be shown
await tester.pumpWidget(
ProviderScope(
overrides: [
asyncInitializationPod.overrideWith((_) async {}),
routerConfigPod.overrideWithValue(
GoRouter(
routes: $appRoutes,
Expand Down
2 changes: 1 addition & 1 deletion bricks/altoke_app/brick/hooks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:
sdk: ">=3.5.1 <4.0.0"

dependencies:
collection: ^1.19.0
collection: ^1.18.0
mason: ^0.1.0-dev.59
path: ^1.9.0
shell:
Expand Down
5 changes: 4 additions & 1 deletion bricks/altoke_app/reference/packages/app/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ targets:
provider_name_suffix: Pod
provider_family_name_suffix: Pod
generate_for:
- lib/**/state/**_pod.dart
- lib/**/**_pod.dart
- lib/**/**_pods.dart
- lib/**/pod.dart
- lib/**/pods.dart
- lib/routing/router.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
/*remove-start*/
import 'package:altoke_app/external/external.dart';
/*remove-end*/
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'async_initialization_pod.g.dart';

/*w 2v w*/
/*remove-start*/
// coverage:ignore-start
/*remove-end*/
@Riverpod(
dependencies: [],
/*w 1v 2> w*/
/*remove-start*/
// coverage:ignore-end
/*remove-end*/
dependencies: [
/*remove-start*/
asyncApplicationDocumentsDirectory,
asyncDriftLocalDatabase,
asyncHiveInitialization,
asyncIsar,
/*remove-end*/
],
)
Future<void> asyncInitialization(Ref ref) async {
// Run async initialization.
/*remove-start*/
// coverage:ignore-start
await ref.watch(asyncApplicationDocumentsDirectoryPod.future);
await ref.watch(asyncDriftLocalDatabasePod.future);
await ref.watch(asyncApplicationDocumentsDirectoryPod.future);
await ref.watch(asyncHiveInitializationPod.future);
await ref.watch(asyncApplicationDocumentsDirectoryPod.future);
await ref.watch(asyncIsarPod.future);
// coverage:ignore-end
/*remove-end*/
/*w 1v w*/
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'database_pod.dart';
export 'directories_pods.dart';
Loading

0 comments on commit 4de6d7d

Please sign in to comment.