From 801b9de2523adf9a6e2722d5ef5fdd5164c231c1 Mon Sep 17 00:00:00 2001 From: gmpassos Date: Sun, 3 Mar 2024 18:54:28 -0300 Subject: [PATCH 1/4] v1.6.5 - `EntityAccessRules`: - Fix `toJsonEncodable` to allow rules to be applied to sub-entities. - `APIResponse` extension on `Future` and `FutureOr`: - Added `payloadAsyncOr`. - async_extension: ^1.2.7 - reflection_factory: ^2.3.1 - postgres: ^2.6.4 - googleapis_auth: ^1.5.0 --- CHANGELOG.md | 13 +++++++++++++ lib/src/bones_api_base.dart | 2 +- lib/src/bones_api_entity_rules.dart | 10 ++++++++-- lib/src/bones_api_extension.dart | 4 ++++ pubspec.yaml | 10 +++++----- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 854f1e9..1d18539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## 1.6.5 + +- `EntityAccessRules`: + - Fix `toJsonEncodable` to allow rules to be applied to sub-entities. + +- `APIResponse` extension on `Future` and `FutureOr`: + - Added `payloadAsyncOr`. + +- async_extension: ^1.2.7 +- reflection_factory: ^2.3.1 +- postgres: ^2.6.4 +- googleapis_auth: ^1.5.0 + ## 1.6.4 - `EntityReference`: diff --git a/lib/src/bones_api_base.dart b/lib/src/bones_api_base.dart index 56d7efe..f6970e2 100644 --- a/lib/src/bones_api_base.dart +++ b/lib/src/bones_api_base.dart @@ -42,7 +42,7 @@ typedef APILogger = void Function(APIRoot apiRoot, String type, String? message, /// Bones API Library class. class BonesAPI { // ignore: constant_identifier_names - static const String VERSION = '1.6.4'; + static const String VERSION = '1.6.5'; static bool _boot = false; diff --git a/lib/src/bones_api_entity_rules.dart b/lib/src/bones_api_entity_rules.dart index 72dc598..c52a39f 100644 --- a/lib/src/bones_api_entity_rules.dart +++ b/lib/src/bones_api_entity_rules.dart @@ -6,7 +6,6 @@ import 'bones_api_base.dart'; import 'bones_api_entity_reference.dart'; import 'bones_api_extension.dart'; import 'bones_api_types.dart'; -import 'bones_api_utils_json.dart'; abstract class EntityRules> { final bool? _innocuous; @@ -463,7 +462,14 @@ class EntityAccessRules extends EntityRules { Object? map; if (enc == null) { - map = Json.toJson(o, toEncodable: ReflectionFactory.toJsonEncodable); + var classReflection = + ReflectionFactory().getRegisterClassReflection(o.runtimeType); + + if (classReflection != null) { + map = classReflection.toMapFromFields(o); + } else { + map = j.toJson(o, autoResetEntityCache: false); + } } else { map = enc(o, j); } diff --git a/lib/src/bones_api_extension.dart b/lib/src/bones_api_extension.dart index 77ea1d1..5a52785 100644 --- a/lib/src/bones_api_extension.dart +++ b/lib/src/bones_api_extension.dart @@ -1017,6 +1017,8 @@ extension ListOfStringExtension on List { extension FutureOrAPIResponseExtension on FutureOr> { FutureOr get payloadAsync => then((r) => r.payload); + FutureOr payloadAsyncOr(T? def) => then((r) => r.payload ?? def); + FutureOr get statusAsync => then((r) => r.status); FutureOr> get headersAsync => then((r) => r.headers); @@ -1037,6 +1039,8 @@ extension FutureOrAPIResponseExtension on FutureOr> { extension FutureAPIResponseExtension on Future> { Future get payloadAsync => then((r) => r.payload); + Future payloadAsyncOr(T? def) => then((r) => r.payload ?? def); + Future get statusAsync => then((r) => r.status); Future> get headersAsync => then((r) => r.headers); diff --git a/pubspec.yaml b/pubspec.yaml index 998a2f0..973f4bb 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.6.4 +version: 1.6.5 homepage: https://github.com/Colossus-Services/bones_api environment: @@ -10,9 +10,9 @@ executables: bones_api: dependencies: - async_extension: ^1.2.5 + async_extension: ^1.2.7 async_events: ^1.1.0 - reflection_factory: ^2.3.0 + reflection_factory: ^2.3.1 statistics: ^1.1.0 swiss_knife: ^3.2.0 data_serializer: ^1.1.0 @@ -38,7 +38,7 @@ dependencies: logging: ^1.2.0 collection: ^1.18.0 mime: ^1.0.5 - postgres: ^2.6.3 + postgres: ^2.6.4 mysql1: ^0.20.0 gcloud: ^0.8.12 yaml: ^3.1.2 @@ -47,7 +47,7 @@ dependencies: archive: ^3.4.10 stream_channel: ^2.1.2 http: ^1.2.1 - googleapis_auth: ^1.4.1 + googleapis_auth: ^1.5.0 crclib: ^3.0.0 dev_dependencies: From b5bca9b16b1209bff78dbe9ce8462a693726b423 Mon Sep 17 00:00:00 2001 From: gmpassos Date: Sun, 3 Mar 2024 18:56:46 -0300 Subject: [PATCH 2/4] reflection --- test/bones_api_test.reflection.g.dart | 4 ++-- test/bones_api_test_entities.reflection.g.dart | 4 ++-- test/bones_api_test_modules.reflection.g.dart | 4 ++-- test/bones_api_test_utils_test.reflection.g.dart | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/bones_api_test.reflection.g.dart b/test/bones_api_test.reflection.g.dart index 6b36648..baf0818 100644 --- a/test/bones_api_test.reflection.g.dart +++ b/test/bones_api_test.reflection.g.dart @@ -1,6 +1,6 @@ // // GENERATED CODE - DO NOT MODIFY BY HAND! -// BUILDER: reflection_factory/2.3.0 +// BUILDER: reflection_factory/2.3.1 // BUILD COMMAND: dart run build_runner build // @@ -20,7 +20,7 @@ typedef __TI = TypeInfo; typedef __PR = ParameterReflection; mixin __ReflectionMixin { - static final Version _version = Version.parse('2.3.0'); + static final Version _version = Version.parse('2.3.1'); Version get reflectionFactoryVersion => _version; diff --git a/test/bones_api_test_entities.reflection.g.dart b/test/bones_api_test_entities.reflection.g.dart index c3d16e3..24cb1b5 100644 --- a/test/bones_api_test_entities.reflection.g.dart +++ b/test/bones_api_test_entities.reflection.g.dart @@ -1,6 +1,6 @@ // // GENERATED CODE - DO NOT MODIFY BY HAND! -// BUILDER: reflection_factory/2.3.0 +// BUILDER: reflection_factory/2.3.1 // BUILD COMMAND: dart run build_runner build // @@ -20,7 +20,7 @@ typedef __TI = TypeInfo; typedef __PR = ParameterReflection; mixin __ReflectionMixin { - static final Version _version = Version.parse('2.3.0'); + static final Version _version = Version.parse('2.3.1'); Version get reflectionFactoryVersion => _version; diff --git a/test/bones_api_test_modules.reflection.g.dart b/test/bones_api_test_modules.reflection.g.dart index 9ab2f5a..42bbb03 100644 --- a/test/bones_api_test_modules.reflection.g.dart +++ b/test/bones_api_test_modules.reflection.g.dart @@ -1,6 +1,6 @@ // // GENERATED CODE - DO NOT MODIFY BY HAND! -// BUILDER: reflection_factory/2.3.0 +// BUILDER: reflection_factory/2.3.1 // BUILD COMMAND: dart run build_runner build // @@ -20,7 +20,7 @@ typedef __TI = TypeInfo; typedef __PR = ParameterReflection; mixin __ReflectionMixin { - static final Version _version = Version.parse('2.3.0'); + static final Version _version = Version.parse('2.3.1'); Version get reflectionFactoryVersion => _version; diff --git a/test/bones_api_test_utils_test.reflection.g.dart b/test/bones_api_test_utils_test.reflection.g.dart index d9e8267..585a361 100644 --- a/test/bones_api_test_utils_test.reflection.g.dart +++ b/test/bones_api_test_utils_test.reflection.g.dart @@ -1,6 +1,6 @@ // // GENERATED CODE - DO NOT MODIFY BY HAND! -// BUILDER: reflection_factory/2.3.0 +// BUILDER: reflection_factory/2.3.1 // BUILD COMMAND: dart run build_runner build // @@ -20,7 +20,7 @@ typedef __TI = TypeInfo; typedef __PR = ParameterReflection; mixin __ReflectionMixin { - static final Version _version = Version.parse('2.3.0'); + static final Version _version = Version.parse('2.3.1'); Version get reflectionFactoryVersion => _version; From 1fb25e1707c9282dd432c97acb83a77ad65d2cec Mon Sep 17 00:00:00 2001 From: gmpassos Date: Sun, 3 Mar 2024 19:08:07 -0300 Subject: [PATCH 3/4] - `LoggerHandler`: - `flushMessages`: added parameter `delay`. --- lib/src/bones_api_logging.dart | 7 +++++-- lib/src/bones_api_logging_generic.dart | 3 ++- lib/src/bones_api_logging_io.dart | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/src/bones_api_logging.dart b/lib/src/bones_api_logging.dart index 41925fb..980c191 100644 --- a/lib/src/bones_api_logging.dart +++ b/lib/src/bones_api_logging.dart @@ -73,7 +73,9 @@ extension LoggerExntesion on logging.Logger { return handler; } - FutureOr flushMessages() => handler.flushMessages(); + FutureOr flushMessages( + {Duration? delay = const Duration(milliseconds: 20)}) => + handler.flushMessages(delay: delay); static final Set _dbLoggers = {}; @@ -313,7 +315,8 @@ abstract class LoggerHandler { void printMessage(logging.Level level, String message); - FutureOr flushMessages(); + FutureOr flushMessages( + {Duration? delay = const Duration(milliseconds: 20)}); void logAll() { logging.hierarchicalLoggingEnabled = true; diff --git a/lib/src/bones_api_logging_generic.dart b/lib/src/bones_api_logging_generic.dart index ad939bd..2ecae02 100644 --- a/lib/src/bones_api_logging_generic.dart +++ b/lib/src/bones_api_logging_generic.dart @@ -14,7 +14,8 @@ class LoggerHandlerGeneric extends LoggerHandler { } @override - bool flushMessages() => false; + bool flushMessages({Duration? delay = const Duration(milliseconds: 20)}) => + false; } LoggerHandler createLoggerHandler(Logger logger) { diff --git a/lib/src/bones_api_logging_io.dart b/lib/src/bones_api_logging_io.dart index 76b6c13..9da8be7 100644 --- a/lib/src/bones_api_logging_io.dart +++ b/lib/src/bones_api_logging_io.dart @@ -69,9 +69,19 @@ class LoggerHandlerIO extends LoggerHandler { } @override - FutureOr flushMessages() { - if (_printMessageQueue.isEmpty) return false; - return _scheduleFlushPrintMessageQueue(); + FutureOr flushMessages( + {Duration? delay = const Duration(milliseconds: 20)}) { + if (_printMessageQueue.isEmpty) { + if (delay == null) return false; + + return Future.delayed(delay).then((_) { + if (_printMessageQueue.isEmpty) return false; + return _scheduleFlushPrintMessageQueue(); + }); + } + + return _scheduleFlushPrintMessageQueue( + delay: delay ?? Duration(milliseconds: 20)); } @override From 4fb71a9ebd03df42e6964b1d10fa303c44a884ff Mon Sep 17 00:00:00 2001 From: gmpassos Date: Sun, 3 Mar 2024 19:08:58 -0300 Subject: [PATCH 4/4] - `LoggerHandler`: - `flushMessages`: added parameter `delay`. --- CHANGELOG.md | 3 +++ lib/src/bones_api_server.dart | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d18539..145cce5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - `APIResponse` extension on `Future` and `FutureOr`: - Added `payloadAsyncOr`. +- `LoggerHandler`: + - `flushMessages`: added parameter `delay`. + - async_extension: ^1.2.7 - reflection_factory: ^2.3.1 - postgres: ^2.6.4 diff --git a/lib/src/bones_api_server.dart b/lib/src/bones_api_server.dart index 7f3c7a5..2093731 100644 --- a/lib/src/bones_api_server.dart +++ b/lib/src/bones_api_server.dart @@ -945,7 +945,7 @@ class APIServer extends _APIServerBase { } } - await _log.flushMessages(); + await _log.flushMessages(delay: Duration(milliseconds: 50)); return true; }