From a7bd4e36f9d52ddf37c0eebd252abec5c21ffb99 Mon Sep 17 00:00:00 2001 From: "Graciliano M. P." Date: Sun, 18 Oct 2026 05:29:46 -0300 Subject: [PATCH] v1.27.2: APICronStoreDB.buildRepositories returns List It can be added to a provider's list of DBSQLEntityRepository with no cast, and still to a list of EntityRepository (lists are covariant). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 ++++++ lib/src/bones_api_base.dart | 2 +- lib/src/bones_api_cron_store.dart | 31 ++++++++++++++------------ pubspec.yaml | 2 +- test/bones_api_cron_db_tests_base.dart | 13 ++++++++++- test/bones_api_cron_test.dart | 11 +++++++++ 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc3453d..29a64fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.27.2 + +- `APICronStoreDB.buildRepositories` returns `List` + (was `List>`): it can be added to a provider's + list of `DBSQLEntityRepository` with no cast, and still to a list of + `EntityRepository` (lists are covariant). + ## 1.27.1 - Cron time zones: the full `timezone` database is used diff --git a/lib/src/bones_api_base.dart b/lib/src/bones_api_base.dart index 80757d4..436e5b0 100644 --- a/lib/src/bones_api_base.dart +++ b/lib/src/bones_api_base.dart @@ -51,7 +51,7 @@ typedef APILogger = /// Bones API Library class. class BonesAPI { // ignore: constant_identifier_names - static const String VERSION = '1.27.1'; + static const String VERSION = '1.27.2'; static bool _boot = false; diff --git a/lib/src/bones_api_cron_store.dart b/lib/src/bones_api_cron_store.dart index 9f70684..8914c85 100644 --- a/lib/src/bones_api_cron_store.dart +++ b/lib/src/bones_api_cron_store.dart @@ -516,20 +516,23 @@ class APICronStoreDB extends APICronStore { /// The repositories of the cron tables for [adapter], to be returned by /// [DBRelationalEntityRepositoryProvider.buildRepositories]. - static List> buildRepositories( - DBSQLAdapter adapter, - ) => [ - DBSQLEntityRepository( - adapter, - runsTable, - apiCronJobRunEntityHandler, - ), - DBSQLEntityRepository( - adapter, - locksTable, - apiCronJobLockEntityHandler, - ), - ]; + /// + /// A `List`: it can be added to a list of + /// [DBSQLEntityRepository] or of [EntityRepository] (the list is + /// covariant), with no cast. + static List buildRepositories(DBSQLAdapter adapter) => + [ + DBSQLEntityRepository( + adapter, + runsTable, + apiCronJobRunEntityHandler, + ), + DBSQLEntityRepository( + adapter, + locksTable, + apiCronJobLockEntityHandler, + ), + ]; /// An [APICronStoreDB] with the repositories of the cron entities known by /// the entity handlers (registered with [buildRepositories]), or `null`. diff --git a/pubspec.yaml b/pubspec.yaml index 8108ba2..84471db 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bones_api description: Bones_API - A powerful API backend framework for Dart. It comes with a built-in HTTP Server, route handler, entity handler, SQL translator, and DB adapters. -version: 1.27.1 +version: 1.27.2 homepage: https://github.com/Colossus-Services/bones_api environment: diff --git a/test/bones_api_cron_db_tests_base.dart b/test/bones_api_cron_db_tests_base.dart index c6bd1de..9c8ec02 100644 --- a/test/bones_api_cron_db_tests_base.dart +++ b/test/bones_api_cron_db_tests_base.dart @@ -18,7 +18,9 @@ class CronDBProvider @override FutureOr buildAdapter() => adapterCreator(this); - List>? _repositories; + /// SQL repositories (no cast: see [APICronStoreDB.buildRepositories]), + /// returned as the generic list of the override. + List? _repositories; @override List> buildRepositories(DBAdapter adapter) => @@ -117,6 +119,15 @@ void runCronStoreDBTests( // Each test with its own job names (the tables are shared): setUp(() => job = 'job${++jobCount}'); + test('buildRepositories: the SQL repositories of the cron tables', () { + var repositories = provider._repositories!; + expect(repositories.map((r) => r.tableName), [ + APICronStoreDB.runsTable, + APICronStoreDB.locksTable, + ]); + expect(repositories.map((r) => r.type), [APICronJobRun, APICronJobLock]); + }); + test('tryResolve: the registered repositories', () async { var resolved = APICronStoreDB.tryResolve()!; var t = _utc(2026, 10, 18, 10); diff --git a/test/bones_api_cron_test.dart b/test/bones_api_cron_test.dart index 79c449c..5d13a61 100644 --- a/test/bones_api_cron_test.dart +++ b/test/bones_api_cron_test.dart @@ -988,6 +988,17 @@ void main() { expect(APICronStoreDB.tryResolve(), isNull); }); + test('APICronStoreDB.buildRepositories: SQL repositories, no cast', () { + // Both kinds of provider lists, with no cast (checked by the compiler): + List Function(DBSQLAdapter) sql = + APICronStoreDB.buildRepositories; + List> Function(DBSQLAdapter) generic = + APICronStoreDB.buildRepositories; + expect(sql, same(generic)); + // No repository built here: it would register the cron entities for + // the other tests (see `bones_api_cron_db_tests_base.dart`). + }); + test('APIAuthentication.system', () { var auth = APIAuthentication.system('cron:x'); expect(auth.isSystem, isTrue);